1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9452],{64063:function(e){e.exports=function equal(e,t){if(e===t)return!0;if(e&&t&&"object"==typeof e&&"object"==typeof t){if(e.constructor!==t.constructor)return!1;if(Array.isArray(e)){if((r=e.length)!=t.length)return!1;for(n=r;0!=n--;)if(!equal(e[n],t[n]))return!1;return!0}if(e.constructor===RegExp)return e.source===t.source&&e.flags===t.flags;if(e.valueOf!==Object.prototype.valueOf)return e.valueOf()===t.valueOf();if(e.toString!==Object.prototype.toString)return e.toString()===t.toString();if((r=(a=Object.keys(e)).length)!==Object.keys(t).length)return!1;for(n=r;0!=n--;)if(!Object.prototype.hasOwnProperty.call(t,a[n]))return!1;for(n=r;0!=n--;){var r,n,a,o=a[n];if(!equal(e[o],t[o]))return!1}return!0}return e!=e&&t!=t}},9452:function(e,t,r){function groq(e){for(var t=arguments.length,r=Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];let a=e.length-1;return e.slice(0,a).reduce((e,t,n)=>e+t+r[n],"")+e[a]}r.r(t),r.d(t,{groq:function(){return groq},groqStore:function(){return groqStore}});var n,a=r(64063);let Path=class Path{constructor(e){this.pattern=e,this.patternRe=function(e){let t=[];for(let r of e.split("."))"*"===r?t.push("[^.]+"):"**"===r?t.push(".*"):t.push(r.replace(/[.*+?^${}()|[\]\\]/g,"\\$&"));return new RegExp("^".concat(t.join("."),"$"))}(e)}matches(e){return this.patternRe.test(e)}toJSON(){return this.pattern}};let StreamValue=class StreamValue{constructor(e){this.type="stream",this.generator=e,this.ticker=null,this.isDone=!1,this.data=[]}isArray(){return!0}async get(){let e=[];for await(let t of this)e.push(await t.get());return e}async *[Symbol.asyncIterator](){let e=0;for(;;){for(;e<this.data.length;e++)yield this.data[e];if(this.isDone)return;await this._nextTick()}}_nextTick(){let e;if(this.ticker)return this.ticker;let setupTicker=()=>{this.ticker=new Promise(t=>{e=t})},tick=()=>{e(),setupTicker()},fetch=async()=>{for await(let e of this.generator())this.data.push(e),tick();this.isDone=!0,tick()};return setupTicker(),fetch(),this.ticker}};let o=/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?(Z|([-+]\d{2}:\d{2}))$/;function addLeadingZero(e,t){let r=e.toString();for(;r.length<t;)r="0".concat(r);return r}let StaticValue=class StaticValue{constructor(e,t){this.data=e,this.type=t}isArray(){return"array"===this.type}async get(){return this.data}[Symbol.asyncIterator](){if(Array.isArray(this.data))return function*(e){for(let t of e)yield fromJS(t)}(this.data);throw Error("Cannot iterate over: ".concat(this.type))}};let i=new StaticValue(null,"null"),s=new StaticValue(!0,"boolean"),c=new StaticValue(!1,"boolean");let DateTime=class DateTime{constructor(e){this.date=e}static parseToValue(e){let t=o.test(e)?new Date(e):null;return t?new StaticValue(new DateTime(t),"datetime"):i}equals(e){return this.date.getTime()==e.date.getTime()}add(e){let t=new Date(this.date.getTime());return t.setTime(t.getTime()+1e3*e),new DateTime(t)}difference(e){return(this.date.getTime()-e.date.getTime())/1e3}compareTo(e){return this.date.getTime()-e.date.getTime()}toString(){return function(e){let t=addLeadingZero(e.getUTCFullYear(),4),r=addLeadingZero(e.getUTCMonth()+1,2),n=addLeadingZero(e.getUTCDate(),2),a=addLeadingZero(e.getUTCHours(),2),o=addLeadingZero(e.getUTCMinutes(),2),i=addLeadingZero(e.getUTCSeconds(),2),s="",c=e.getMilliseconds();return 0!=c&&(s=".".concat(addLeadingZero(c,3))),"".concat(t,"-").concat(r,"-").concat(n,"T").concat(a,":").concat(o,":").concat(i).concat(s,"Z")}(this.date)}toJSON(){return this.toString()}};function fromNumber(e){return Number.isFinite(e)?new StaticValue(e,"number"):i}function fromString(e){return new StaticValue(e,"string")}function fromDateTime(e){return new StaticValue(e,"datetime")}function fromJS(e){return e&&"function"==typeof e.next?new StreamValue(async function*(){for await(let t of e)yield fromJS(t)}):null==e?i:new StaticValue(e,getType(e))}function getType(e){return null==e?"null":Array.isArray(e)?"array":e instanceof Path?"path":e instanceof DateTime?"datetime":typeof e}function isEqual(e,t){return"string"===e.type&&"string"===t.type||"boolean"===e.type&&"boolean"===t.type||"null"===e.type&&"null"===t.type||"number"===e.type&&"number"===t.type?e.data===t.data:"datetime"===e.type&&"datetime"===t.type&&e.data.equals(t.data)}let u=/([^!@#$%^&*(),\\/?";:{}|[\]+<>\s-])+/g,p=/([^!@#$%^&(),\\/?";:{}|[\]+<>\s-])+/g,l=/(\b\.+|\.+\b)/g;function matchTokenize(e){return e.replace(l,"").match(u)||[]}function matchPatternRegex(e){let t=e.replace(l,"").match(p)||[];return t.map(e=>RegExp("^".concat(e.slice(0,1024).replace(/\*/g,".*"),"$"),"i"))}async function gatherText(e,t){if("string"===e.type)return t(e.data),!0;if(e.isArray()){let r=!0;for await(let n of e)"string"===n.type?t(n.data):r=!1;return r}return!1}let f={datetime:1,number:2,string:3,boolean:4};function partialCompare(e,t){let r=getType(e),n=getType(t);if(r!==n)return null;switch(r){case"number":case"boolean":return e-t;case"string":if(e<t)return -1;if(e>t)return 1;return 0;case"datetime":return e.compareTo(t);default:return null}}let y={"==":function(e,t){return isEqual(e,t)?s:c},"!=":function(e,t){return isEqual(e,t)?c:s},">":function(e,t){if("stream"===e.type||"stream"===t.type)return i;let r=partialCompare(e.data,t.data);return null===r?i:r>0?s:c},">=":function(e,t){if("stream"===e.type||"stream"===t.type)return i;let r=partialCompare(e.data,t.data);return null===r?i:r>=0?s:c},"<":function(e,t){if("stream"===e.type||"stream"===t.type)return i;let r=partialCompare(e.data,t.data);return null===r?i:r<0?s:c},"<=":function(e,t){if("stream"===e.type||"stream"===t.type)return i;let r=partialCompare(e.data,t.data);return null===r?i:r<=0?s:c},in:async function(e,t){if("path"===t.type)return"string"!==e.type?i:t.data.matches(e.data)?s:c;if(t.isArray()){for await(let r of t)if(isEqual(e,r))return s;return c}return i},match:async function(e,t){var r,n;let a=[],o=[];await gatherText(e,e=>{a=a.concat(matchTokenize(e))});let i=await gatherText(t,e=>{o=o.concat(function(e){let t=matchPatternRegex(e);return t.map(e=>t=>t.some(t=>e.test(t)))}(e))});if(!i)return c;let u=(r=a,n=o,0!==r.length&&0!==n.length&&n.every(e=>e(r)));return u?s:c},"+":function(e,t){return"datetime"===e.type&&"number"===t.type?fromDateTime(e.data.add(t.data)):"number"===e.type&&"number"===t.type?fromNumber(e.data+t.data):"string"===e.type&&"string"===t.type?fromString(e.data+t.data):"object"===e.type&&"object"===t.type?fromJS({...e.data,...t.data}):"array"===e.type&&"array"===t.type?fromJS(e.data.concat(t.data)):e.isArray()&&t.isArray()?new StreamValue(async function*(){for await(let t of e)yield t;for await(let e of t)yield e}):i},"-":function(e,t){return"datetime"===e.type&&"number"===t.type?fromDateTime(e.data.add(-t.data)):"datetime"===e.type&&"datetime"===t.type?fromNumber(e.data.difference(t.data)):"number"===e.type&&"number"===t.type?fromNumber(e.data-t.data):i},"*":numericOperator((e,t)=>e*t),"/":numericOperator((e,t)=>e/t),"%":numericOperator((e,t)=>e%t),"**":numericOperator((e,t)=>Math.pow(e,t))};function numericOperator(e){return function(t,r){if("number"===t.type&&"number"===r.type){let n=e(t.data,r.data);return fromNumber(n)}return i}}let Scope=class Scope{constructor(e,t,r,n,a){this.isHidden=!1,this.params=e,this.source=t,this.value=r,this.context=n,this.parent=a}createNested(e){return this.isHidden?new Scope(this.params,this.source,e,this.context,this.parent):new Scope(this.params,this.source,e,this.context,this)}createHidden(e){let t=this.createNested(e);return t.isHidden=!0,t}};function evaluate(e,t){let r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:evaluate,n=d[e.type];return n(e,t,r)}function promiselessApply(e,t){return"then"in e?e.then(t):t(e)}let d={This:(e,t)=>t.value,Selector(){throw Error("Selectors can not be evaluated")},Everything:(e,t)=>
1t.source,Parameter(e,t){let{name:r}=e;return fromJS(t.params[r])},Context(e,t){let{key:r}=e;if("before"===r||"after"===r){let e=t.context[r];return e||i}throw Error("unknown context key: ".concat(r))},Parent(e,t){let{n:r}=e,n=t;for(let e=0;e<r;e++){if(!n.parent)return i;n=n.parent}return n.value},OpCall(e,t,r){let{op:n,left:a,right:o}=e,i=y[n];if(!i)throw Error("Unknown operator: ".concat(n));let s=r(a,t),c=r(o,t);return"then"in s||"then"in c?(async()=>i(await s,await c))():i(s,c)},async Select(e,t,r){let{alternatives:n,fallback:a}=e;for(let e of n){let n=await r(e.condition,t);if("boolean"===n.type&&!0===n.data)return r(e.value,t)}return a?r(a,t):i},async InRange(e,t,r){let{base:n,left:a,right:o,isInclusive:u}=e,p=await r(n,t),l=await r(a,t),f=await r(o,t),y=partialCompare(await p.get(),await l.get());if(null===y)return i;let d=partialCompare(await p.get(),await f.get());return null===d?i:u?y>=0&&d<=0?s:c:y>=0&&d<0?s:c},async Filter(e,t,r){let{base:n,expr:a}=e,o=await r(n,t);return o.isArray()?new StreamValue(async function*(){for await(let e of o){let n=t.createNested(e),o=await r(a,n);"boolean"===o.type&&!0===o.data&&(yield e)}}):i},async Projection(e,t,r){let{base:n,expr:a}=e,o=await r(n,t);if("object"!==o.type)return i;let s=t.createNested(o);return r(a,s)},FuncCall(e,t,r){let{func:n,args:a}=e;return n(a,t,r)},async PipeFuncCall(e,t,r){let{func:n,base:a,args:o}=e,i=await r(a,t);return n(i,o,t,r)},async AccessAttribute(e,t,r){let{base:n,name:a}=e,o=t.value;return(n&&(o=await r(n,t)),"object"===o.type&&o.data.hasOwnProperty(a))?fromJS(o.data[a]):i},async AccessElement(e,t,r){let{base:n,index:a}=e,o=await r(n,t);if(!o.isArray())return i;let s=await o.get(),c=a<0?a+s.length:a;return fromJS(s[c])},async Slice(e,t,r){let{base:n,left:a,right:o,isInclusive:s}=e,c=await r(n,t);if(!c.isArray())return i;let u=await c.get(),p=a,l=o;return p<0&&(p=u.length+p),l<0&&(l=u.length+l),s&&l++,p<0&&(p=0),l<0&&(l=0),fromJS(u.slice(p,l))},async Deref(e,t,r){let{base:n}=e,a=await r(n,t);if(!t.source.isArray()||"object"!==a.type)return i;let o=a.data._ref;if("string"!=typeof o)return i;for await(let e of t.source)if("object"===e.type&&o===e.data._id)return e;return i},Value(e){let{value:t}=e;return fromJS(t)},Group(e,t,r){let{base:n}=e;return r(n,t)},async Object(e,t,r){let{attributes:n}=e,a={};for(let e of n){let n=e.type;switch(e.type){case"ObjectAttributeValue":{let n=await r(e.value,t);a[e.name]=await n.get();break}case"ObjectConditionalSplat":{let n=await r(e.condition,t);if("boolean"!==n.type||!1===n.data)continue;let o=await r(e.value,t);"object"===o.type&&Object.assign(a,o.data);break}case"ObjectSplat":{let n=await r(e.value,t);"object"===n.type&&Object.assign(a,n.data);break}default:throw Error("Unknown node type: ".concat(n))}}return fromJS(a)},Array(e,t,r){let{elements:n}=e;return new StreamValue(async function*(){for(let e of n){let n=await r(e.value,t);if(e.isSplat){if(n.isArray())for await(let e of n)yield e}else yield n}})},Tuple(){throw Error("tuples can not be evaluated")},async Or(e,t,r){let{left:n,right:a}=e,o=await r(n,t),u=await r(a,t);return"boolean"===o.type&&!0===o.data||"boolean"===u.type&&!0===u.data?s:"boolean"!==o.type||"boolean"!==u.type?i:c},async And(e,t,r){let{left:n,right:a}=e,o=await r(n,t),u=await r(a,t);return"boolean"===o.type&&!1===o.data||"boolean"===u.type&&!1===u.data?c:"boolean"!==o.type||"boolean"!==u.type?i:s},async Not(e,t,r){let{base:n}=e,a=await r(n,t);return"boolean"!==a.type?i:a.data?c:s},Neg(e,t,r){let{base:n}=e;return promiselessApply(r(n,t),e=>"number"!==e.type?i:fromNumber(-e.data))},Pos(e,t,r){let{base:n}=e;return promiselessApply(r(n,t),e=>"number"!==e.type?i:fromNumber(e.data))},Asc:()=>i,Desc:()=>i,async ArrayCoerce(e,t,r){let{base:n}=e,a=await r(n,t);return a.isArray()?a:i},async Map(e,t,r){let{base:n,expr:a}=e,o=await r(n,t);return o.isArray()?new StreamValue(async function*(){for await(let e of o){let n=t.createHidden(e);yield await r(a,n)}}):i},async FlatMap(e,t,r){let{base:n,expr:a}=e,o=await r(n,t);return o.isArray()?new StreamValue(async function*(){for await(let e of o){let n=t.createHidden(e),o=await r(a,n);if(o.isArray())for await(let e of o)yield e;else yield o}}):i}},h=new Scope({},i,i,{timestamp:new Date(0),identity:"me",before:null,after:null},null);function tryConstantEvaluate(e){return!function canConstantEvaluate(e){switch(e.type){case"Group":case"Value":case"Parameter":return!0;case"Pos":case"Neg":return canConstantEvaluate(e.base);case"OpCall":switch(e.op){case"+":case"-":case"*":case"/":case"%":case"**":return canConstantEvaluate(e.left)&&canConstantEvaluate(e.right);default:return!1}default:return!1}}(e)?null:function constantEvaluate(e){let t=evaluate(e,h,constantEvaluate);if("then"in t)throw Error("BUG: constant evaluate should never return a promise");return t}(e)}async function portableTextContent(e){if("object"===e.type)return blockText(e.data);if(e.isArray()){let t=await arrayText(e);if(t.length>0)return t.join("\n\n")}return null}async function arrayText(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:[];for await(let r of e)if("object"===r.type){let e=blockText(r.data);null!==e&&t.push(e)}else r.isArray()&&await arrayText(r,t);return t}function blockText(e){if("string"!=typeof e._type)return null;let t=e.children;if(!Array.isArray(t))return null;let r="";for(let e of t)e&&"object"==typeof e&&"string"==typeof e._type&&"span"===e._type&&"string"==typeof e.text&&(r+=e.text);return r}async function evaluateScore(e,t,r){if("OpCall"===e.type&&"match"===e.op)return evaluateMatchScore(e.left,e.right,t,r);if("FuncCall"===e.type&&"boost"===e.name){let n=await evaluateScore(e.args[0],t,r),a=await r(e.args[1],t);return"number"===a.type&&n>0?n+a.data:0}switch(e.type){case"Or":{let n=await evaluateScore(e.left,t,r),a=await evaluateScore(e.right,t,r);return n+a}case"And":{let n=await evaluateScore(e.left,t,r),a=await evaluateScore(e.right,t,r);if(0===n||0===a)return 0;return n+a}default:{let n=await r(e,t);return"boolean"===n.type&&!0===n.data?1:0}}}async function evaluateMatchScore(e,t,r,n){let a=await n(e,r),o=await n(t,r),i=[],s=[];await gatherText(a,e=>{i=i.concat(matchTokenize(e))});let c=await gatherText(o,e=>{s=s.concat(matchPatternRegex(e))});if(!c||0===i.length||0===s.length)return 0;let u=0;for(let e of s){let t=i.reduce((t,r)=>t+(e.test(r)?1:0),0);u+=2.2*t/(t+1.2)}return u}let m={};m.anywhere=async function(){throw Error("not implemented")}
1,m.anywhere.arity=1,m.coalesce=async function(e,t,r){for(let n of e){let e=await r(n,t);if("null"!==e.type)return e}return i},m.count=async function(e,t,r){let n=await r(e[0],t);if(!n.isArray())return i;let a=0;for await(let e of n)a++;return fromNumber(a)},m.count.arity=1,m.dateTime=async function(e,t,r){let n=await r(e[0],t);return"datetime"===n.type?n:"string"!==n.type?i:DateTime.parseToValue(n.data)},m.dateTime.arity=1,m.defined=async function(e,t,r){let n=await r(e[0],t);return"null"===n.type?c:s},m.defined.arity=1,m.identity=async function(e,t){return fromString(t.context.identity)},m.identity.arity=0,m.length=async function(e,t,r){let n=await r(e[0],t);if("string"===n.type)return fromNumber(function(e){let t=0;for(let r=0;r<e.length;r++){let n=e.charCodeAt(r);(!(n>=55296)||!(n<=56319))&&t++}return t}(n.data));if(n.isArray()){let e=0;for await(let t of n)e++;return fromNumber(e)}return i},m.length.arity=1,m.path=async function(e,t,r){var n;let a=await r(e[0],t);return"string"!==a.type?i:(n=new Path(a.data),new StaticValue(n,"path"))},m.path.arity=1,m.string=async function(e,t,r){let n=await r(e[0],t);switch(n.type){case"number":case"string":case"boolean":case"datetime":return fromString("".concat(n.data));default:return i}},m.string.arity=1,m.references=async function(e,t,r){let n=new Set;for(let a of e){let e=await r(a,t);if("string"===e.type)n.add(e.data);else if(e.isArray())for await(let t of e)"string"===t.type&&n.add(t.data)}if(0===n.size)return c;let a=await t.value.get();return!function hasReference(e,t){switch(getType(e)){case"array":for(let r of e)if(hasReference(r,t))return!0;break;case"object":if(e._ref)return t.has(e._ref);for(let r of Object.values(e))if(hasReference(r,t))return!0}return!1}(a,n)?c:s},m.references.arity=e=>e>=1,m.round=async function(e,t,r){let n=await r(e[0],t);if("number"!==n.type)return i;let a=n.data,o=0;if(2===e.length){let n=await r(e[1],t);if("number"!==n.type||n.data<0||!Number.isInteger(n.data))return i;o=n.data}return 0===o?a<0?fromNumber(-Math.round(-a)):fromNumber(Math.round(a)):fromNumber(Number(a.toFixed(o)))},m.round.arity=e=>e>=1&&e<=2,m.now=async function(e,t){return fromString(t.context.timestamp.toISOString())},m.now.arity=0,m.boost=async function(){throw Error("unexpected boost call")},m.boost.arity=2;let b={};b.lower=async function(e,t,r){let n=await r(e[0],t);return"string"!==n.type?i:fromString(n.data.toLowerCase())},b.lower.arity=1,b.upper=async function(e,t,r){let n=await r(e[0],t);return"string"!==n.type?i:fromString(n.data.toUpperCase())},b.upper.arity=1,b.split=async function(e,t,r){let n=await r(e[0],t);if("string"!==n.type)return i;let a=await r(e[1],t);return"string"!==a.type?i:0===n.data.length?fromJS([]):0===a.data.length?fromJS(Array.from(n.data)):fromJS(n.data.split(a.data))},b.split.arity=2,m.lower=b.lower,m.upper=b.upper,b.startsWith=async function(e,t,r){let n=await r(e[0],t);if("string"!==n.type)return i;let a=await r(e[1],t);return"string"!==a.type?i:n.data.startsWith(a.data)?s:c},b.startsWith.arity=2;let g={};g.join=async function(e,t,r){let n=await r(e[0],t);if(!n.isArray())return i;let a=await r(e[1],t);if("string"!==a.type)return i;let o="",s=!1;for await(let e of n){switch(s&&(o+=a.data),e.type){case"number":case"string":case"boolean":case"datetime":o+="".concat(e.data);break;default:return i}s=!0}return fromJS(o)},g.join.arity=2,g.compact=async function(e,t,r){let n=await r(e[0],t);return n.isArray()?new StreamValue(async function*(){for await(let e of n)"null"!==e.type&&(yield e)}):i},g.compact.arity=1,g.unique=async function(e,t,r){let n=await r(e[0],t);return n.isArray()?new StreamValue(async function*(){let e=new Set;for await(let t of n)switch(t.type){case"number":case"string":case"boolean":case"datetime":e.has(t.data)||(e.add(t.data),yield t);break;default:yield t}}):i},g.unique.arity=1;let w={};w.text=async function(e,t,r){let n=await r(e[0],t),a=await portableTextContent(n);return null===a?i:fromString(a)},w.text.arity=1;let k={};k.projectId=async function(e,t){return t.context.sanity?fromString(t.context.sanity.projectId):i},k.dataset=async function(e,t){return t.context.sanity?fromString(t.context.sanity.dataset):i};let S={};S.order=async function(e,t,r,n){if(await !0,!e.isArray())return i;let a=[],o=[],s=0;for(let e of t){let t="asc";"Desc"===e.type?(t="desc",e=e.base):"Asc"===e.type&&(e=e.base),a.push(e),o.push(t),s++}let c=[],u=0;for await(let t of e){let e=r.createNested(t),o=[await t.get(),u];for(let t=0;t<s;t++){let r=await n(a[t],e);o.push(await r.get())}c.push(o),u++}return c.sort((e,t)=>
1{for(let r=0;r<s;r++){let n=function(e,t){let r=getType(e),n=getType(t),a=f[r]||100,o=f[n]||100;if(a!==o)return a-o;let i=partialCompare(e,t);return null===i&&(i=0),i}(e[r+2],t[r+2]);if("desc"===o[r]&&(n=-n),0!==n)return n}return e[1]-t[1]}),fromJS(c.map(e=>e[0]))},S.order.arity=e=>e>=1,S.score=async function(e,t,r,n){if(!e.isArray())return i;let a=[],o=[];for await(let i of e){if("object"!==i.type){a.push(await i.get());continue}let e=r.createNested(i),s="number"==typeof i.data._score?i.data._score:0;for(let r of t)s+=await evaluateScore(r,e,n);let c=Object.assign({},i.data,{_score:s});o.push(c)}return o.sort((e,t)=>t._score-e._score),fromJS(o)},S.score.arity=e=>e>=1;let v={};v.operation=async function(e,t){let r=null!==t.context.before,n=null!==t.context.after;return r&&n?fromString("update"):n?fromString("create"):r?fromString("delete"):i},v.changedAny=()=>{throw Error("not implemented")},v.changedAny.arity=1,v.changedAny.mode="delta",v.changedOnly=()=>{throw Error("not implemented")},v.changedOnly.arity=1,v.changedOnly.mode="delta";let E={};E.changedAny=()=>{throw Error("not implemented")},E.changedAny.arity=3,E.changedOnly=()=>{throw Error("not implemented")},E.changedOnly.arity=3;let x={};x.min=async function(e,t,r){let n;let a=await r(e[0],t);if(!a.isArray())return i;for await(let e of a)if("null"!==e.type){if("number"!==e.type)return i;(void 0===n||e.data<n)&&(n=e.data)}return fromJS(n)},x.min.arity=1,x.max=async function(e,t,r){let n;let a=await r(e[0],t);if(!a.isArray())return i;for await(let e of a)if("null"!==e.type){if("number"!==e.type)return i;(void 0===n||e.data>n)&&(n=e.data)}return fromJS(n)},x.max.arity=1,x.sum=async function(e,t,r){let n=await r(e[0],t);if(!n.isArray())return i;let a=0;for await(let e of n)if("null"!==e.type){if("number"!==e.type)return i;a+=e.data}return fromJS(a)},x.sum.arity=1,x.avg=async function(e,t,r){let n=await r(e[0],t);if(!n.isArray())return i;let a=0,o=0;for await(let e of n)if("null"!==e.type){if("number"!==e.type)return i;a+=e.data,o++}return 0===o?i:fromJS(a/o)},x.avg.arity=1;let A={global:m,string:b,array:g,pt:w,delta:v,diff:E,sanity:k,math:x};let MarkProcessor=class MarkProcessor{constructor(e,t,r){this.allowBoost=!1,this.string=e,this.marks=t,this.index=0,this.parseOptions=r}hasMark(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.index+e<this.marks.length}getMark(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:0;return this.marks[this.index+e]}shift(){this.index+=1}process(e){let t=this.marks[this.index];this.shift();let r=e[t.name];if(!r)throw Error("Unknown handler: ".concat(t.name));return r.call(e,this,t)}processString(){return this.shift(),this.processStringEnd()}processStringEnd(){let e=this.marks[this.index-1],t=this.marks[this.index];return this.shift(),this.string.slice(e.position,t.position)}slice(e){let t=this.marks[this.index].position;return this.string.slice(t,t+e)}};let j=/^([\t\n\v\f\r \u0085\u00A0]|(\/\/[^\n]*\n))+/,_=/^\d+/,P=/^[a-zA-Z_][a-zA-Z_0-9]*/;function parseExpr(e,t,r){let n,a,o=t;switch(e[t]){case"+":{let r=parseExpr(e,skipWS(e,t+1),10);if("error"===r.type)return r;n=[{name:"pos",position:o}].concat(r.marks),t=r.position;break}case"-":{let r=parseExpr(e,skipWS(e,t+1),8);if("error"===r.type)return r;n=[{name:"neg",position:o}].concat(r.marks),t=r.position;break}case"(":{let r=parseExpr(e,skipWS(e,t+1),0);if("error"===r.type)return r;switch(t=skipWS(e,r.position),e[t]){case",":for(n=[{name:"tuple",position:o}].concat(r.marks),t=skipWS(e,t+1);;){if("error"===(r=parseExpr(e,t,0)).type)return r;if(t=skipWS(e,r.position),","!==e[t])break;t=skipWS(e,t+1)}if(")"!==e[t])return{type:"error",position:t};t++,n.push({name:"tuple_end",position:t});break;case")":t++,n=[{name:"group",position:o}].concat(r.marks);break;default:return{type:"error",position:t}}break}case"!":{let r=parseExpr(e,skipWS(e,t+1),10);if("error"===r.type)return r;n=[{name:"not",position:o}].concat(r.marks),t=r.position;break}case"{":{let r=parseObject(e,t);if("error"===r.type)return r;n=r.marks,t=r.position;break}case"[":if(n=[{name:"array",position:t}],t=skipWS(e,t+1),"]"!==e[t])for(;;){"..."===e.slice(t,t+3)&&(n.push({name:"array_splat",position:t}),t=skipWS(e,t+3));let r=parseExpr(e,t,0);if("error"===r.type)return r;if(n=n.concat(r.marks),t=skipWS(e,t=r.position),","!==e[t]||(t=skipWS(e,t+1),"]"===e[t]))break}if("]"!==e[t])return{type:"error",position:t};t++,n.push({name:"array_end",position:t});break;case"'":case'"':{let r=function(e,t){let r=e[t];t+=1;let n=[{name:"str",position:t}];e:for(;;t++){if(t>e.length)return{type:"error",position:t};switch(e[t]){case r:n.push({name:"str_end",position:t}),t++;break e;case"\\":n.push({name:"str_pause",position:t}),"u"===e[t+1]?"{"===e[t+2]?(n.push({name:"unicode_hex",position:t+3}),t=e.indexOf("}",t+3),n.push({name:"unicode_hex_end",position:t})):(n.push({name:"unicode_hex",position:t+2}),n.push({name:"unicode_hex_end",position:t+6}),t+=5):(n.push({name:"single_escape",position:t+1}),t+=1),n.push({name:"str_start",position:t+1})}}return{type:"success",marks:n,position:t}}(e,t);if("error"===r.type)return r;n=r.marks,t=r.position;break}case"^":for(t++,n=[];"."===e[t]&&"^"===e[t+1];)n.push({name:"dblparent",position:o}),t+=2;n.push({name:"parent",position:o});break;case"@":n=[{name:"this",position:o}],t++;break;case"*":n=[{name:"everything",position:o}],t++;break;case"$":{let r=parseRegex(e,t+1,P);r&&(t+=1+r,n=[{name:"param",position:o},{name:"ident",position:o+1},{name:"ident_end",position:t}]);break}default:{let r=parseRegex(e,t,_);if(r){let a="integer";if("."===e[t+=r]){let r=parseRegex(e,t+1,_);r&&(a="float",t+=1+r)}if("e"===e[t]||"E"===e[t]){a="sci",("+"===e[++t]||"-"===e[t])&&t++;let r=parseRegex(e,t,_);if(!r)return{type:"error",position:t};t+=r}n=[{name:a,position:o},{name:a+"_end",position:t}];break}let a=parseRegex(e,t,P);if(a)switch(e[t+=a]){case":":case"(":{let r=parseFuncCall(e,o,t);if("error"===r.type)return r;n=r.marks,t=r.position;break}default:n=[{name:"this_attr",position:o},{name:"ident",position:o},{name:"ident_end",position:t}]}}}if(!n)return{type:"error",position:t};let i=12;t:for(;;){let s=skipWS(e,t);if(s===e.length){t=s;break}if("success"===(a=parseTraversal(e,s)).type){for(n.unshift({name:"traverse",position:o});"success"===a.type;)n=n.concat(a.marks),a=parseTraversal(e,skipWS(e,t=a.position));n.push({name:"traversal_end",position:t});continue}switch(e[s]){case"=":switch(e[s+1]){case">":{if(r>1||i<=1)break t;let a=parseExpr(e,skipWS(e,s+2),1);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"pair",position:o}),t=a.position,i=1;break}case"=":{if(r>4||i<=4)break t;let a=parseExpr(e,skipWS(e,s+2),5);if("error"===a.type)return a;n.unshift({name:"comp",position:o}),n.push({name:"op",position:s},{name:"op_end",position:s+2}),n=n.concat(a.marks),t=a.position,i=4;break}default:break t}break;case"+":{if(r>6||i<6)break t;let a=parseExpr(e,skipWS(e,s+1),7);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"add",position:o}),t=a.position,i=6;break}case"-":{if(r>6||i<6)break t;let a=parseExpr(e,skipWS(e,s+1),7);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"sub",position:o}),t=a.position,i=6;break}case"*":{if("*"===e[s+1]){if(r>8||i<=8)break t;let a=parseExpr(e,skipWS(e,s+2),8);
1if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"pow",position:o}),t=a.position,i=8;break}if(r>7||i<7)break t;let a=parseExpr(e,skipWS(e,s+1),8);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"mul",position:o}),t=a.position,i=7;break}case"/":{if(r>7||i<7)break t;let a=parseExpr(e,skipWS(e,s+1),8);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"div",position:o}),t=a.position,i=7;break}case"%":{if(r>7||i<7)break t;let a=parseExpr(e,skipWS(e,s+1),8);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"mod",position:o}),t=a.position,i=7;break}case"<":case">":{if(r>4||i<=4)break t;let a=s+1;"="===e[a]&&a++;let c=parseExpr(e,skipWS(e,a),5);if("error"===c.type)return c;n.unshift({name:"comp",position:o}),n.push({name:"op",position:s},{name:"op_end",position:a}),n=n.concat(c.marks),t=c.position,i=4;break}case"|":if("|"===e[s+1]){if(r>2||i<2)break t;let a=parseExpr(e,skipWS(e,s+2),3);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"or",position:o}),t=a.position,i=2}else{if(r>11||i<11)break t;let a=skipWS(e,s+1),c=parseRegex(e,a,P);if(!c)return{type:"error",position:a};if("("===e[t=a+c]||":"===e[t]){let r=parseFuncCall(e,a,t);if("error"===r.type)return r;(n=n.concat(r.marks)).unshift({name:"pipecall",position:o}),t=r.position,i=11}}break;case"&":{if("&"!=e[s+1]||r>3||i<3)break t;let a=parseExpr(e,skipWS(e,s+2),4);if("error"===a.type)return a;(n=n.concat(a.marks)).unshift({name:"and",position:o}),t=a.position,i=3;break}case"!":{if("="!==e[s+1]||r>4||i<4)break t;let a=parseExpr(e,skipWS(e,s+2),5);if("error"===a.type)return a;n.unshift({name:"comp",position:o}),n.push({name:"op",position:s},{name:"op_end",position:s+2}),n=n.concat(a.marks),t=a.position,i=4;break}case"d":if("desc"!==e.slice(s,s+4)||r>4||i<4)break t;n.unshift({name:"desc",position:o}),t=s+4,i=4;break;case"a":if("asc"!==e.slice(s,s+3)||r>4||i<4)break t;n.unshift({name:"asc",position:o}),t=s+3,i=4;break;default:switch(function(e,t,r){let n=r.exec(e.slice(t));return n?n[0]:null}(e,s,P)){case"in":{if(r>4||i<=4)break t;t=skipWS(e,s+2);let a=!1;"("===e[t]&&(a=!0,t=skipWS(e,t+1));let c=t,u=parseExpr(e,t,5);if("error"===u.type)return u;if(t=skipWS(e,u.position),"."===e[t]&&"."===e[t+1]){let r="inc_range";"."===e[t+2]?(r="exc_range",t=skipWS(e,t+3)):t=skipWS(e,t+2);let a=parseExpr(e,t,5);if("error"===a.type)return a;n.unshift({name:"in_range",position:o}),n=n.concat({name:r,position:c},u.marks,a.marks),t=a.position}else n.unshift({name:"comp",position:o}),n.push({name:"op",position:s},{name:"op_end",position:s+2}),n=n.concat(u.marks);if(a){if(t=skipWS(e,t),")"!==e[t])return{type:"error",position:t};t++}i=4;break}case"match":{if(r>4||i<=4)break t;let a=parseExpr(e,skipWS(e,s+5),5);if("error"===a.type)return a;n.unshift({name:"comp",position:o}),n.push({name:"op",position:s},{name:"op_end",position:s+5}),n=n.concat(a.marks),t=a.position,i=4;break}default:break t}}}return{type:"success",marks:n,position:t,failPosition:(null==a?void 0:a.type)==="error"&&a.position}}function parseTraversal(e,t){let r=t;switch(e[t]){case".":{let n=t=skipWS(e,t+1),a=parseRegex(e,t,P);if(!a)return{type:"error",position:t};return{type:"success",marks:[{name:"attr_access",position:r},{name:"ident",position:n},{name:"ident_end",position:t+=a}],position:t}}case"-":if(">"!==e[t+1])break;let n=[{name:"deref",position:r}],a=skipWS(e,t+=2),o=parseRegex(e,a,P);return o&&(t=a+o,n.push({name:"deref_attr",position:a},{name:"ident",position:a},{name:"ident_end",position:t})),{type:"success",marks:n,position:t};case"[":{if(t=skipWS(e,t+1),"]"===e[t])return{type:"success",marks:[{name:"array_postfix",position:r}],position:t+1};let n=t,a=parseExpr(e,t,0);if("error"===a.type)return a;
1if(t=skipWS(e,a.position),"."===e[t]&&"."===e[t+1]){let o="inc_range";"."===e[t+2]?(o="exc_range",t+=3):t+=2,t=skipWS(e,t);let i=parseExpr(e,t,0);if("error"===i.type)return i;if(t=skipWS(e,i.position),"]"!==e[t])return{type:"error",position:t};return{type:"success",marks:[{name:"slice",position:r},{name:o,position:n}].concat(a.marks,i.marks),position:t+1}}if("]"!==e[t])return{type:"error",position:t};return{type:"success",marks:[{name:"square_bracket",position:r}].concat(a.marks),position:t+1}}case"|":if(t=skipWS(e,t+1),"{"===e[t]){let n=parseObject(e,t);if("error"===n.type)return n;return n.marks.unshift({name:"projection",position:r}),n}break;case"{":{let n=parseObject(e,t);if("error"===n.type)return n;return n.marks.unshift({name:"projection",position:r}),n}}return{type:"error",position:t}}function parseFuncCall(e,t,r){let n=[];if(n.push({name:"func_call",position:t}),":"===e[r]&&":"===e[r+1]){n.push({name:"namespace",position:t}),n.push({name:"ident",position:t},{name:"ident_end",position:r}),r=skipWS(e,r+2);let a=parseRegex(e,r,P);if(!a||(n.push({name:"ident",position:r},{name:"ident_end",position:r+a}),r=skipWS(e,r+a),"("!==e[r]))return{type:"error",position:r};r=skipWS(e,++r)}else n.push({name:"ident",position:t},{name:"ident_end",position:r}),r=skipWS(e,r+1);let a=r;if(")"!==e[r])for(;;){let t=parseExpr(e,r,0);if("error"===t.type)return t;if(n=n.concat(t.marks),a=t.position,r=skipWS(e,t.position),","!==e[r]||(r=skipWS(e,r+1),")"===e[r]))break}return")"!==e[r]?{type:"error",position:r}:(n.push({name:"func_args_end",position:a}),{type:"success",marks:n,position:r+1})}function parseObject(e,t){let r=[{name:"object",position:t}];for(t=skipWS(e,t+1);"}"!==e[t];){let n=t;if("..."===e.slice(t,t+3)){if(t=skipWS(e,t+3),"}"!==e[t]&&","!==e[t]){let a=parseExpr(e,t,0);if("error"===a.type)return a;r.push({name:"object_splat",position:n}),r=r.concat(a.marks),t=a.position}else r.push({name:"object_splat_this",position:n})}else{let a=parseExpr(e,t,0);if("error"===a.type)return a;let o=skipWS(e,a.position);if("str"===a.marks[0].name&&":"===e[o]){let i=parseExpr(e,skipWS(e,o+1),0);if("error"===i.type)return i;r.push({name:"object_pair",position:n}),r=r.concat(a.marks,i.marks),t=i.position}else r=r.concat({name:"object_expr",position:t},a.marks),t=a.position}if(t=skipWS(e,t),","!==e[t])break;t=skipWS(e,t+1)}return"}"!==e[t]?{type:"error",position:t}:(t++,r.push({name:"object_end",position:t}),{type:"success",marks:r,position:t})}function skipWS(e,t){return t+parseRegex(e,t,j)}function parseRegex(e,t,r){let n=r.exec(e.slice(t));return n?n[0].length:0}function join(e,t){return r=>t(e(r))}function map(e){return t=>({type:"Map",base:t,expr:e({type:"This"})})}function traverseArray(e,t){if(!t)return{type:"a-a",build:e};switch(t.type){case"a-a":return{type:"a-a",build:join(e,t.build)};case"a-b":return{type:"a-b",build:join(e,t.build)};case"b-b":return{type:"a-a",build:join(e,map(t.build))};case"b-a":var r;return{type:"a-a",build:join(e,(r=t.build,e=>({type:"FlatMap",base:e,expr:r({type:"This"})})))};default:throw Error("unknown type: ".concat(t.type))}}function traversePlain(e,t){if(!t)return{type:"b-b",build:e};switch(t.type){case"a-a":case"b-a":return{type:"b-a",build:join(e,t.build)};case"a-b":case"b-b":return{type:"b-b",build:join(e,t.build)};default:throw Error("unknown type: ".concat(t.type))}}let O={"'":"'",'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:"\n",r:"\r",t:" "};let GroqQueryError=class GroqQueryError extends Error{constructor(){super(...arguments),this.name="GroqQueryError"}};let T={group(e){let t=e.process(T);return{type:"Group",base:t}},everything:()=>({type:"Everything"}),this:()=>({type:"This"}),parent:()=>({type:"Parent",n:1}),dblparent(e){let t=e.process(T);return{type:"Parent",n:t.n+1}},traverse(e){let t=e.process(T),r=[];for(;"traversal_end"!==e.getMark().name;)r.push(e.process(I));e.shift();let n=null;for(let e=r.length-1;e>=0;e--)n=r[e](n);if(("Everything"===t.type||"Array"===t.type||"PipeFuncCall"===t.type)&&(n=traverseArray(e=>e,n)),null===n)throw Error("BUG: unexpected empty traversal");return n.build(t)},this_attr(e){let t=e.processString();return"null"===t?{type:"Value",value:null}:"true"===t?{type:"Value",value:!0}:"false"===t?{type:"Value",value:!1}:{type:"AccessAttribute",name:t}},neg(e){let t=e.process(T);return{type:"Neg",base:t}},pos(e){let t=e.process(T);return{type:"Pos",base:t}},add(e){let t=e.process(T),r=e.process(T);return{type:"OpCall",op:"+",left:t,right:r}},sub(e){let t=e.process(T),r=e.process(T);return{type:"OpCall",op:"-",left:t,right:r}},mul(e){let t=e.process(T),r=e.process(T);return{type:"OpCall",op:"*",left:t,right:r}},div(e){let t=e.process(T),r=e.process(T);return{type:"OpCall",op:"/",left:t,right:r}},mod(e){let t=e.process(T),r=e.process(T);return{type:"OpCall",op:"%",left:t,right:r}},pow(e){let t=e.process(T),r=e.process(T);return{type:"OpCall",op:"**",left:t,right:r}}
1,comp(e){let t=e.process(T),r=e.processString(),n=e.process(T);return{type:"OpCall",op:r,left:t,right:n}},in_range(e){let t=e.process(T),r="inc_range"===e.getMark().name;e.shift();let n=e.process(T),a=e.process(T);return{type:"InRange",base:t,left:n,right:a,isInclusive:r}},str(e){let t="";t:for(;e.hasMark();){let r=e.getMark();switch(r.name){case"str_end":t+=e.processStringEnd();break t;case"str_pause":t+=e.processStringEnd();break;case"str_start":e.shift();break;case"single_escape":{let r=e.slice(1);e.shift(),t+=O[r];break}case"unicode_hex":e.shift(),t+=function(e){let t=parseInt(e,16);return String.fromCharCode(t)}(e.processStringEnd());break;default:throw Error("unexpected mark: ".concat(r.name))}}return{type:"Value",value:t}},integer(e){let t=e.processStringEnd();return{type:"Value",value:Number(t)}},float(e){let t=e.processStringEnd();return{type:"Value",value:Number(t)}},sci(e){let t=e.processStringEnd();return{type:"Value",value:Number(t)}},object(e){let t=[];for(;"object_end"!==e.getMark().name;)t.push(e.process(C));return e.shift(),{type:"Object",attributes:t}},array(e){let t=[];for(;"array_end"!==e.getMark().name;){let r=!1;"array_splat"===e.getMark().name&&(r=!0,e.shift());let n=e.process(T);t.push({type:"ArrayElement",value:n,isSplat:r})}return e.shift(),{type:"Array",elements:t}},tuple(e){let t=[];for(;"tuple_end"!==e.getMark().name;)t.push(e.process(T));return e.shift(),{type:"Tuple",members:t}},func_call(e){let t="global";"namespace"===e.getMark().name&&(e.shift(),t=e.processString());let r=e.processString();if("global"===t&&"select"===r){let t={type:"Select",alternatives:[]};for(;"func_args_end"!==e.getMark().name;)if("pair"===e.getMark().name){if(t.fallback)throw new GroqQueryError("unexpected argument to select()");e.shift();let r=e.process(T),n=e.process(T);t.alternatives.push({type:"SelectAlternative",condition:r,value:n})}else{if(t.fallback)throw new GroqQueryError("unexpected argument to select()");let r=e.process(T);t.fallback=r}return e.shift(),t}let n=[];for(;"func_args_end"!==e.getMark().name;){var a,o;(a=t,o=n.length,"diff"==a&&2==o&&["changedAny","changedOnly"].includes(r))?(e.process(W),n.push({type:"Selector"})):n.push(e.process(T))}if(e.shift(),"global"===t&&("before"===r||"after"===r)&&"delta"===e.parseOptions.mode)return{type:"Context",key:r};if("global"===t&&"boost"===r&&!e.allowBoost)throw new GroqQueryError("unexpected boost");let i=A[t];if(!i)throw new GroqQueryError("Undefined namespace: ".concat(t));let s=i[r];if(!s||(void 0!==s.arity&&validateArity(r,s.arity,n.length),void 0!==s.mode&&s.mode!==e.parseOptions.mode))throw new GroqQueryError("Undefined function: ".concat(r));return{type:"FuncCall",func:s,name:r,args:n}},pipecall(e){let t=e.process(T);e.shift();let r="global";if("namespace"===e.getMark().name&&(e.shift(),r=e.processString()),"global"!==r)throw new GroqQueryError("Undefined namespace: ".concat(r));let n=e.processString(),a=[],o=e.allowBoost;for("score"===n&&(e.allowBoost=!0);;){let t=e.getMark().name;if("func_args_end"===t)break;if("order"===n){if("asc"===t){e.shift(),a.push({type:"Asc",base:e.process(T)});continue}if("desc"===t){e.shift(),a.push({type:"Desc",base:e.process(T)});continue}}a.push(e.process(T))}e.shift(),e.allowBoost=o;let i=S[n];if(!i)throw new GroqQueryError("Undefined pipe function: ".concat(n));return i.arity&&validateArity(n,i.arity,a.length),{type:"PipeFuncCall",func:i,base:t,name:n,args:a}},pair(e){throw new GroqQueryError("unexpected =>")},and(e){let t=e.process(T),r=e.process(T);return{type:"And",left:t,right:r}},or(e){let t=e.process(T),r=e.process(T);return{type:"Or",left:t,right:r}},not(e){let t=e.process(T);return{type:"Not",base:t}},asc(e){throw new GroqQueryError("unexpected asc")},desc(e){throw new GroqQueryError("unexpected desc")},param(e){let t=e.processString();return e.parseOptions.params&&e.parseOptions.params.hasOwnProperty(t)?{type:"Value",value:e.parseOptions.params[t]}:{type:"Parameter",name:t}}},C={object_expr(e){if("pair"===e.getMark().name){e.shift();let t=e.process(T),r=e.process(T);return{type:"ObjectConditionalSplat",condition:t,value:r}}let t=e.process(T);return{type:"ObjectAttributeValue",name:function extractPropertyKey(e){if("AccessAttribute"===e.type&&!e.base)return e.name;if("Deref"===e.type||"Map"===e.type||"Projection"===e.type||"Slice"===e.type||"Filter"===e.type||"AccessElement"===e.type||"ArrayCoerce"===e.type)return extractPropertyKey(e.base);throw new GroqQueryError("Cannot determine property key for type: ".concat(e.type))}(t),value:t}},object_pair(e){let t=e.process(T);if("Value"!==t.type)throw Error("name must be string");let r=e.process(T);return{type:"ObjectAttributeValue",name:t.value,value:r}},object_splat(e){let t=e.process(T);return{type:"ObjectSplat",value:t}},object_splat_this:()=>({type:"ObjectSplat",value:{type:"This"}})},I={square_bracket(e){let t=e.process(T),r=tryConstantEvaluate(t);return r&&"number"===r.type?e=>(function(e,t){if(!t)return{type:"a-b",build:e};switch(t.type){case"a-a":case"b-a":return{type:"a-a",build:join(e,t.build)};case"a-b":case"b-b":return{type:"a-b",build:join(e,t.build)};default:throw Error("unknown type: ".concat(t.type))}})(e=>({type:"AccessElement",base:e,index:r.data}),e):r&&"string"===r.type?e=>traversePlain(e=>({type:"AccessAttribute",base:e,name:r.data}),e):e=>traverseArray(e=>({type:"Filter",base:e,expr:t}),e)},slice(e){let t="inc_range"===e.getMark().name;e.shift();let r=e.process(T),n=e.process(T),a=tryConstantEvaluate(r),o=tryConstantEvaluate(n);if(!a||!o||"number"!==a.type||"number"!==o.type)throw new GroqQueryError("slicing must use constant numbers");return e=>traverseArray(e=>({type:"Slice",base:e,left:a.data,right:o.data,isInclusive:t}),e)},projection(e){let t=e.process(T);return e=>(function(e,t){if(!t)return{type:"b-b",build:e};switch(t.type){case"a-a":return{type:"a-a",build:join(map(e),t.build)};case"a-b":return{type:"a-b",build:join(map(e),t.build)};case"b-a":return{type:"b-a",build:join(e,t.build)};case"b-b":return{type:"b-b",build:join(e,t.build)};default:throw Error("unknown type: ".concat(t.type))}})(e=>({type:"Projection",base:e,expr:t}),e)},attr_access(e){let t=e.processString();return e=>traversePlain(e=>({type:"AccessAttribute",base:e,name:t}),e)},deref(e){let t=null;"deref_attr"===e.getMark().name&&(e.shift(),t=e.processString());let wrap=e=>t?{type:"AccessAttribute",base:e,name:t}:e;return e=>traversePlain(e=>wrap({type:"Deref",base:e}),e)},array_postfix:e=>e=>traverseArray(e=>({type:"ArrayCoerce",base:e}),e)},W={group:e=>(e.process(W),null),everything(){throw Error("Invalid selector syntax")},this(){throw Error("Invalid selector syntax")},parent(){throw Error("Invalid selector syntax")},dblparent(e){throw Error("Invalid selector syntax")},traverse(e){for(e.process(W);"traversal_end"!==e.getMark().name;)e.process(I);return e.shift(),null},this_attr:e=>(e.processString(),null),neg(e){throw Error("Invalid selector syntax")},pos(e){throw Error("Invalid selector syntax")},add(e){throw Error("Invalid selector syntax")},sub(e){throw Error("Invalid selector syntax")},mul(e){throw Error("Invalid selector syntax")},div(e){throw Error("Invalid selector syntax")},mod(e){throw Error("Invalid selector syntax")},pow(e){throw Error("Invalid selector syntax")},comp(e){throw Error("Invalid selector syntax")},in_range(e){throw Error("Invalid selector syntax")},str(e){throw Error("Invalid selector syntax")},integer(e){throw Error("Invalid selector syntax")},float(e){throw Error("Invalid selector syntax")},sci(e){throw Error("Invalid selector syntax")},object(e){throw Error("Invalid selector syntax")},array(e){throw Error("Invalid selector syntax")},tuple(e){throw Error("Invalid selector syntax")},func_call(e,t){let r=T.func_call(e,t);if("anywhere"===r.name&&1===r.args.length)return null;throw Error("Invalid selector syntax")},pipecall(e){throw Error("Invalid selector syntax")},pair(e){throw Error("Invalid selector syntax")},and(e){throw Error("Invalid selector syntax")},or(e){throw Error("Invalid selector syntax")},not(e){throw Error("Invalid selector syntax")},asc(e){throw Error("Invalid selector syntax")},desc(e){throw Error("Invalid selector syntax")},param(e){throw Error("Invalid selector syntax")}};function validateArity(e,t,r){if("number"==typeof t){if(r!==t)throw new GroqQueryError("Incorrect number of arguments to function ".concat(e,"(). Expected ").concat(t,", got ").concat(r,"."))}else if(t&&!t(r))throw new GroqQueryError("Incorrect number of arguments to function ".concat(e,"()."))}
1let GroqSyntaxError=class GroqSyntaxError extends Error{constructor(e){super("Syntax error in GROQ query at position ".concat(e)),this.name="GroqSyntaxError",this.position=e}};var R=["Value","Copy","Blank","ReturnIntoArray","ReturnIntoObject","ReturnIntoObjectSameKey","PushField","PushElement","PushParent","Pop","PushFieldCopy","PushFieldBlank","PushElementCopy","PushElementBlank","ReturnIntoObjectPop","ReturnIntoObjectSameKeyPop","ReturnIntoArrayPop","ObjectSetFieldValue","ObjectCopyField","ObjectDeleteField","ArrayAppendValue","ArrayAppendSlice","StringAppendString","StringAppendSlice"],V=function(){function Patcher(e,t,r){this.i=0,this.inputStack=[],this.outputStack=[],this.model=e,this.root=t,this.patch=r}return Patcher.prototype.read=function(){return this.patch[this.i++]},Patcher.prototype.process=function(){for(this.inputStack.push({value:this.root}),this.outputStack.push({value:this.root});this.i<this.patch.length;){var e=this.read(),t=R[e];if(!t)throw Error("Unknown opcode: "+e);this["process"+t].apply(this)}var r=this.outputStack.pop();return this.finalizeOutput(r)},Patcher.prototype.inputEntry=function(){return this.inputStack[this.inputStack.length-1]},Patcher.prototype.inputKey=function(e,t){return e.keys||(e.keys=this.model.objectGetKeys(e.value).sort()),e.keys[t]},Patcher.prototype.outputEntry=function(){return this.outputStack[this.outputStack.length-1]},Patcher.prototype.outputArray=function(){var e=this.outputEntry();return e.writeValue||(e.writeValue=this.model.copyArray(e.value)),e.writeValue},Patcher.prototype.outputObject=function(){var e=this.outputEntry();return e.writeValue||(e.writeValue=this.model.copyObject(e.value)),e.writeValue},Patcher.prototype.outputString=function(){var e=this.outputEntry();return e.writeValue||(e.writeValue=this.model.copyString(e.value)),e.writeValue},Patcher.prototype.finalizeOutput=function(e){return e.writeValue?this.model.finalize(e.writeValue):e.value},Patcher.prototype.processValue=function(){var e=this.model.wrap(this.read());this.outputStack.push({value:e})},Patcher.prototype.processCopy=function(){var e=this.inputEntry();this.outputStack.push({value:e.value})},Patcher.prototype.processBlank=function(){this.outputStack.push({value:null})},Patcher.prototype.processReturnIntoArray=function(){var e=this.outputStack.pop(),t=this.finalizeOutput(e),r=this.outputArray();this.model.arrayAppendValue(r,t)},Patcher.prototype.processReturnIntoObject=function(){var e=this.read(),t=this.outputStack.pop(),r=this.finalizeOutput(t);r=this.model.markChanged(r);var n=this.outputObject();this.model.objectSetField(n,e,r)},Patcher.prototype.processReturnIntoObjectSameKey=function(){var e=this.inputEntry(),t=this.outputStack.pop(),r=this.finalizeOutput(t),n=this.outputObject();this.model.objectSetField(n,e.key,r)},Patcher.prototype.processPushField=function(){var e=this.read(),t=this.inputEntry(),r=this.inputKey(t,e),n=this.model.objectGetField(t.value,r);this.inputStack.push({value:n,key:r})},Patcher.prototype.processPushElement=function(){var e=this.read(),t=this.inputEntry(),r=this.model.arrayGetElement(t.value,e);this.inputStack.push({value:r})},Patcher.prototype.processPop=function(){this.inputStack.pop()},Patcher.prototype.processPushFieldCopy=function(){this.processPushField(),this.processCopy()},Patcher.prototype.processPushFieldBlank=function(){this.processPushField(),this.processBlank()},Patcher.prototype.processPushElementCopy=function(){this.processPushElement(),this.processCopy()},Patcher.prototype.processPushElementBlank=function(){this.processPushElement(),this.processBlank()},Patcher.prototype.processReturnIntoObjectPop=function(){this.processReturnIntoObject(),this.processPop()},Patcher.prototype.processReturnIntoObjectSameKeyPop=function(){this.processReturnIntoObjectSameKey(),this.processPop()},Patcher.prototype.processReturnIntoArrayPop=function(){this.processReturnIntoArray(),this.processPop()},Patcher.prototype.processObjectSetFieldValue=function(){this.processValue(),this.processReturnIntoObject()},Patcher.prototype.processObjectCopyField=function(){this.processPushField(),this.processCopy(),this.processReturnIntoObjectSameKey(),this.processPop()},Patcher.prototype.processObjectDeleteField=function(){var e=this.read(),t=this.inputEntry(),r=this.inputKey(t,e),n=this.outputObject();this.model.objectDeleteField(n,r)},Patcher.prototype.processArrayAppendValue=function(){var e=this.model.wrap(this.read()),t=this.outputArray();this.model.arrayAppendValue(t,e)},Patcher.prototype.processArrayAppendSlice=function(){var e=this.read(),t=this.read(),r=this.outputArray(),n=this.inputEntry().value;this.model.arrayAppendSlice(r,n,e,t)},Patcher.prototype.processStringAppendString=function(){var e=this.model.wrap(this.read()),t=this.outputString();this.model.stringAppendValue(t,e)},Patcher.prototype.processStringAppendSlice=function(){var e=this.read(),t=this.read(),r=this.outputString(),n=this.inputEntry().value;this.model.stringAppendSlice(r,n,e,t)},Patcher}();function utf8resolveIndex(e,t,r){void 0===r&&(r=0);var n=r,a=0;for(a=r;n<t;a++){var o,i=(o=e.codePointAt(a))>>
116?4:o>>11?3:o>>7?2:1;4===i&&a++,n+=i}return a}var q={wrap:function(e){return e},finalize:function(e){return Array.isArray(e)?e:e.data},markChanged:function(e){return e},objectGetKeys:function(e){return Object.keys(e)},objectGetField:function(e,t){return e[t]},arrayGetElement:function(e,t){return e[t]},copyObject:function(e){var t={type:"object",data:{}};if(null!==e)for(var r=0,n=Object.entries(e);r<n.length;r++){var a=n[r],o=a[0],i=a[1];t.data[o]=i}return t},copyArray:function(e){return null===e?[]:e.slice()},copyString:function(e){return{type:"string",data:null===e?"":e}},objectSetField:function(e,t,r){e.data[t]=r},objectDeleteField:function(e,t){delete e.data[t]},arrayAppendValue:function(e,t){e.push(t)},arrayAppendSlice:function(e,t,r,n){e.push.apply(e,t.slice(r,n))},stringAppendSlice:function(e,t,r,n){var a=utf8resolveIndex(t,r),o=utf8resolveIndex(t,n,a);e.data+=t.slice(a,o)},stringAppendValue:function(e,t){e.data+=t}};let isNativeBrowserEventSource=e=>"undefined"!=typeof window&&e.addEventListener===window.EventSource.prototype.addEventListener,isPolyfillEventSource=e=>!isNativeBrowserEventSource(e),addEventSourceListener=(e,t,r)=>{isPolyfillEventSource(e)?e.addEventListener(t,r):e.addEventListener(t,r,!1)},encodeQueryString=e=>{let{query:t,params:r={},options:n={}}=e,a=new URLSearchParams,{tag:o,...i}=n;for(let[e,n]of(o&&a.set("tag",o),a.set("query",t),Object.entries(r)))a.set("$".concat(e),JSON.stringify(n));for(let[e,t]of Object.entries(i))t&&a.set(e,"".concat(t));return"?".concat(a)};function getPublishedId(e){return e._id.startsWith("drafts.")?e._id.slice(7):e._id}function applyPatchWithoutRev(e,t){let r={...e};return delete r._rev,new V(q,r,t).process()}function noop(){return Promise.resolve()}let getDocuments=async function(e){var t,r;let n,a,{projectId:o,dataset:i,token:s,documentLimit:c,includeTypes:u=[],requestTagPrefix:p}=e,l=new URL("https://".concat(o,".api.sanity.io/v1/data/export/").concat(i));p&&l.searchParams.set("tag",p),u.length>0&&l.searchParams.set("types",null==u?void 0:u.join(","));let f=await fetch(l,{credentials:"include",headers:s?{Authorization:"Bearer ".concat(s)}:void 0});if(200!==f.status)throw Error("Error streaming dataset: ".concat("object"==typeof(t=await f.json())&&"error"in t&&"message"in t?t.message||t.error:"<unknown error>"));let y=function(e){let t;if(!e)throw Error("Failed to read body from response");let r=!1;function cancel(){r=!0,t&&t.cancel()}return new ReadableStream({start(n){t=e.getReader();let a=new TextDecoder,o="";async function processResult(e){if(e.done){if(r)return;if(0===(o=o.trim()).length){n.close();return}n.enqueue(JSON.parse(o)),n.close();return}o+=a.decode(e.value,{stream:!0});let i=o.split("\n");for(let e=0;e<i.length-1;++e){let t=i[e].trim();if(0!==t.length)try{n.enqueue(JSON.parse(t))}catch(e){n.error(e),cancel();return}}if(o=i[i.length-1],t)try{processResult(await t.read())}catch(e){n.error(e)}}t.read().then(processResult).catch(e=>n.error(e))},cancel})}(f.body),d=y.getReader(),h=[];do{if((r=a=(n=await d.read()).value)&&"error"in r&&"object"==typeof r.error&&null!==r.error&&"description"in r.error&&"string"==typeof r.error.description&&!("_id"in r))throw Error("Error streaming dataset: ".concat(a.error));if(a&&!a._id.startsWith("_.")&&h.push(a),c&&h.length>c)throw d.cancel("Reached document limit"),Error("Error streaming dataset: Reached limit of ".concat(c," documents. Try using the includeTypes option to reduce the amount of documents, or increase the limit."))}while(!n.done);return h};function groqStore(e){var t;!function(){let e=["EventSource","ReadableStream","fetch"].filter(e=>!(e in window));if(e.length>0)throw Error("Browser not supported. Missing browser APIs: ".concat(e.join(", ")))}();let r=null!=(t=e.EventSource)?t:window.EventSource;if(e.token){if(!e.EventSource)throw Error("When the `token` option is used the `EventSource` option must also be provided.");if(e.EventSource===window.EventSource)throw Error("When the `token` option is used the `EventSource` option must also be provided. EventSource cannot be `window.EventSource`, as it does not support passing a token.")}return function(e,t){let r,o=[],i=function(e,t,r){var n,a={},o=a.noTrailing,i=void 0!==o&&o,s=a.noLeading,c=void 0!==s&&s,u=a.debounceMode,p=void 0===u?void 0:u,l=!1,f=0;function clearExistingTimeout(){n&&clearTimeout(n)}function wrapper(){for(var r=arguments.length,a=Array(r),o=0;o<r;o++)a[o]=arguments[o];var s=this,u=Date.now()-f;function exec(){f=Date.now(),t.apply(s,a)}function clear(){n=void 0}!l&&(c||!p||n||exec(),clearExistingTimeout(),void 0===p&&u>e?c?(f=Date.now(),i||(n=setTimeout(p?clear:exec,e))):exec():!0!==i&&(n=setTimeout(p?clear:exec,void 0===p?e-u:e)))}return wrapper.cancel=function(e){var t=(e||{}).upcomingOnly;clearExistingTimeout(),l=!(void 0!==t&&t)},wrapper}
1(e.subscriptionThrottleMs||50,function(){s.forEach(executeQuerySubscription)}),s=[];async function loadDataset(){r||(r=function(e,t,r){let n,a,o,i,s,c,{getDocuments:u,EventSource:p}=r,{projectId:l,dataset:f,listen:y,overlayDrafts:d,documentLimit:h,token:m,includeTypes:b,requestTagPrefix:g}=e,onUpdate=e=>{n=void 0,o=void 0,a=void 0;let r=d?function(e){let t=new Map;return e.forEach(e=>{let r=t.get(getPublishedId(e));e._id.startsWith("drafts.")?t.set(getPublishedId(e),{...e,_id:getPublishedId(e),_originalId:e._id}):r||t.set(e._id,{...e,_originalId:e._id})}),Array.from(t.values())}(e):e;r.sort((e,t)=>{var r,n;return(r=e._id)>(n=t._id)?1:r<n?-1:0}),t(r)};if(!y){let e=u({projectId:l,dataset:f,documentLimit:h,token:m,includeTypes:b,requestTagPrefix:g}).then(onUpdate).then(noop);return{unsubscribe:noop,loaded:e}}let w=new Map,k=[],S=new Promise((e,t)=>{s=e,c=t}),onOpen=async()=>{let e=await u({projectId:l,dataset:f,documentLimit:h,token:m,includeTypes:b,requestTagPrefix:g});(i=function(e,t){let r=new Map;return t.forEach(e=>{let t=r.get(e.documentId)||[];t.push(e),r.set(e.documentId,t)}),r.forEach((t,r)=>{let n=e.find(e=>e._id===r);if(!n){console.warn("Received mutation for missing document %s",r);return}let a=!1,o=n;t.forEach(e=>{(a=a||e.previousRev===n._rev)&&e.effects&&(o=applyPatchWithoutRev(o,e.effects.apply))}),e.splice(e.indexOf(n),1,o)}),e}(e,k)).forEach(e=>w.set(e._id,e)),onUpdate(i),s()},v=function(e,t,r){var n;let{projectId:a,dataset:o,token:i,includeTypes:s,requestTagPrefix:c}=t,u=c?{tag:c,effectFormat:"mendoza"}:{effectFormat:"mendoza"},p=encodeQueryString(Array.isArray(s)&&s.length>0?{query:"*[_type in $includeTypes]",params:{includeTypes:s},options:u}:{query:"*",options:u}),l="https://".concat(a,".api.sanity.io/v1/data/listen/").concat(o).concat(p),f=new e(l,{withCredentials:!0,headers:i?{Authorization:"Bearer ".concat(i)}:void 0});return addEventSourceListener(f,"welcome",r.open),addEventSourceListener(f,"mutation",(n=r.next,e=>{let t;try{t=JSON.parse(e.data)}catch(e){return}n(t)})),addEventSourceListener(f,"channelError",e=>{let t;f.close();try{t=JSON.parse(e.data)}catch(e){r.error(Error("Unknown error parsing listener message"));return}r.error(Error(t.message||t.error||"Listener returned HTTP ".concat(t.statusCode)))}),addEventSourceListener(f,"error",e=>{let t="undefined"!=typeof window&&window.location.origin,n="object"==typeof e&&null!==e&&"message"in e?" (".concat(e.message,")"):"";r.error(Error("Error establishing listener - check that the project ID and dataset are correct".concat(t?", and that the CORS-origin (".concat(t,") is allowed"):"").concat(n)))}),{unsubscribe:()=>Promise.resolve(f.close())}}(p,e,{next:e=>{i?(applyMutation(e),scheduleUpdate(i,e)):k.push(e)},open:onOpen,error:e=>c(e)}),scheduleUpdate=(e,t)=>{clearTimeout(o),a!==t.transactionId&&n?(onUpdate(n),a=void 0):(a=t.transactionId,n=e.slice()),o=setTimeout(onUpdate,25,e.slice())},applyMutation=e=>{if(!e.effects||e.documentId.startsWith("_."))return;let t=w.get(e.documentId)||null;replaceDocument(e.documentId,applyPatchWithoutRev(t,e.effects.apply))},replaceDocument=(e,t)=>{let r=w.get(e),n=i||[],a=r?n.indexOf(r):-1;-1===a&&t?(n.push(t),w.set(e,t)):t?(n.splice(a,1,t),w.set(e,t)):(n.splice(a,1),w.delete(e))};return{unsubscribe:v.unsubscribe,loaded:S}}(e,e=>{o=e,i()},t)),await r.loaded}async function query(e,t){await loadDataset();let r=function(e){let t,r,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=(t=0,t=skipWS(e,0),"error"===(r=parseExpr(e,t,0)).type?r:(t=skipWS(e,r.position))!==e.length?(r.failPosition&&(t=r.failPosition-1),{type:"error",position:t}):(delete r.position,delete r.failPosition,r));if("error"===a.type)throw new GroqSyntaxError(a.position);let o=new MarkProcessor(e,a.marks,n);return o.process(T)}(e,{params:t}),n=await function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=fromJS(t.root),n=fromJS(t.dataset),a={...t.params},o=new Scope(a,n,r,{timestamp:t.timestamp||new Date,identity:void 0===t.identity?"me":t.identity,sanity:t.sanity,after:t.after?fromJS(t.after):null,before:t.before?fromJS(t.before):null},null);return evaluate(e,o)}(r,{dataset:o,params:t});return n.get()}function executeQuerySubscription(e){return query(e.query,e.params).then(t=>{"previousResult"in e&&a(e.previousResult,t)||(e.previousResult=t,e.callback(void 0,t))}).catch(t=>{e.callback(t)})}return{query,getDocument:async function(e){var t,r;
1return await loadDataset(),query(groq(n||(t=["*[_id == $id][0]"],r||(r=t.slice(0)),n=Object.freeze(Object.defineProperties(t,{raw:{value:Object.freeze(r)}})))),{id:e})},getDocuments:async function(e){await loadDataset();let t=e.map(e=>'*[_id == "'.concat(e,'"][0]')).join(",\n");return query("[".concat(t,"]"))},subscribe:function(t,r,n){if(!e.listen)throw Error("Cannot use `subscribe()` without `listen: true`");let a={query:t,params:r,callback:n};s.push(a);let o=!1;return executeQuerySubscription(a),{unsubscribe:()=>(o||(o=!0,s.splice(s.indexOf(a),1)),Promise.resolve())}},close:function(){return i.cancel(),r?r.unsubscribe():Promise.resolve()}}}(e,{EventSource:r,getDocuments})}}}]);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.