@malloy-publisher/server 0.0.193 → 0.0.194
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/build.ts +1 -0
- package/dist/app/api-doc.yaml +41 -5
- package/dist/app/assets/{HomePage-Di9MU3lS.js → HomePage-DbZS0N7G.js} +1 -1
- package/dist/app/assets/MainPage-CBuWkbmr.js +2 -0
- package/dist/app/assets/{ModelPage-Dx2mHWeT.js → ModelPage-Bt37smot.js} +1 -1
- package/dist/app/assets/{PackagePage-Q386Py9t.js → PackagePage-DLZe50WG.js} +1 -1
- package/dist/app/assets/{ProjectPage-WR7wPQB-.js → ProjectPage-FQTEPXP4.js} +1 -1
- package/dist/app/assets/{RouteError-stRGU4aW.js → RouteError-DefbDO7F.js} +1 -1
- package/dist/app/assets/{WorkbookPage-D3iX0djH.js → WorkbookPage-CkAo16ar.js} +1 -1
- package/dist/app/assets/{core-QH4HZQVz.es-CqlQLZdl.js → core-BrfQApxh.es-DnvCX4oH.js} +14 -14
- package/dist/app/assets/index-5eLCcNmP.css +1 -0
- package/dist/app/assets/{index-CVHzPJwN.js → index-Bu0ub036.js} +53 -53
- package/dist/app/assets/index-CkzK3JIl.js +40 -0
- package/dist/app/assets/index-CoA6HIGS.js +1742 -0
- package/dist/app/assets/{index.umd-Bp8OIhfV.js → index.umd-B6Ms2PpL.js} +1 -1
- package/dist/app/index.html +2 -2
- package/dist/server.mjs +140 -1
- package/package.json +2 -1
- package/src/config.ts +7 -2
- package/src/dto/connection.dto.spec.ts +51 -0
- package/src/dto/connection.dto.ts +41 -0
- package/src/service/connection.ts +2 -0
- package/src/service/connection_config.spec.ts +123 -0
- package/src/service/connection_config.ts +48 -0
- package/src/service/db_utils.spec.ts +161 -0
- package/src/service/db_utils.ts +131 -0
- package/dist/app/assets/MainPage-yZQo2HSL.js +0 -2
- package/dist/app/assets/index-CMlGQMcl.css +0 -1
- package/dist/app/assets/index-DavAceYD.js +0 -1276
- package/dist/app/assets/index-Y3Y-VRna.js +0 -676
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import{a4 as Ni}from"./index-Bu0ub036.js";function Mi(u,M){for(var z=0;z<M.length;z++){const V=M[z];if(typeof V!="string"&&!Array.isArray(V)){for(const g in V)if(g!=="default"&&!(g in u)){const l=Object.getOwnPropertyDescriptor(V,g);l&&Object.defineProperty(u,g,l.get?l:{enumerable:!0,get:()=>V[g]})}}}return Object.freeze(Object.defineProperty(u,Symbol.toStringTag,{value:"Module"}))}var pt={},Rt={},Mr;function vn(){if(Mr)return Rt;Mr=1,Object.defineProperty(Rt,"__esModule",{value:!0}),Rt.Tag=void 0,Rt.interfaceFromTag=M,Rt.interfaceFromDict=z;class u{get parent(){return this._parent}get root(){let g=this;for(;g._parent!==void 0;)g=g._parent;return g}static id(g){let l=u.ids.get(g);return l===void 0&&(l=u.nextTagId,u.ids.set(g,l),u.nextTagId+=1),l}peek(g=0){const l=" ".repeat(g);let f=`#${u.id(this)}`;if(this.properties===void 0&&this.eq&&typeof this.eq=="string")return f+`=${this.eq}`;if(f+=" {",this.eq!==void 0&&(Array.isArray(this.eq)?f+=`
|
|
2
|
+
${l} =: [
|
|
3
|
+
${l} ${this.eq.map(c=>c.peek(g+4)).join(`
|
|
4
|
+
${l} `)}
|
|
5
|
+
${l} ]`:f+=`
|
|
6
|
+
${l} =: ${this.eq}`),this.properties)for(const c in this.properties)f+=`
|
|
7
|
+
${l} ${c}: ${this.properties[c].peek(g+2)}`;return f+=`
|
|
8
|
+
${l}}`,f}constructor(g={},l){if(this._read=!1,l!==void 0&&(this._parent=l),g.eq!==void 0&&(Array.isArray(g.eq)?this.eq=g.eq.map(f=>f instanceof u?f:new u(f,this)):this.eq=g.eq),g.properties){this.properties={};for(const[f,c]of Object.entries(g.properties))this.properties[f]=c instanceof u?c:new u(c,this)}g.deleted&&(this.deleted=g.deleted),g.prefix&&(this.prefix=g.prefix)}static withPrefix(g){return new u({prefix:g})}tag(...g){return this.find(g)}text(...g){var l;const f=(l=this.find(g))===null||l===void 0?void 0:l.getEq();if(!(f===void 0||Array.isArray(f)))return f instanceof Date?f.toISOString():String(f)}scalarType(...g){var l;const f=g.length>0?(l=this.find(g))===null||l===void 0?void 0:l.getEq():this.getEq();if(!(f===void 0||Array.isArray(f)))return f instanceof Date?"date":typeof f}numeric(...g){var l;const f=(l=this.find(g))===null||l===void 0?void 0:l.getEq();if(typeof f=="number")return f;if(typeof f=="string"){const c=Number.parseFloat(f);if(!Number.isNaN(c))return c}}boolean(...g){var l;const f=(l=this.find(g))===null||l===void 0?void 0:l.getEq();if(typeof f=="boolean")return f}isTrue(...g){var l;return((l=this.find(g))===null||l===void 0?void 0:l.getEq())===!0}isFalse(...g){var l;return((l=this.find(g))===null||l===void 0?void 0:l.getEq())===!1}date(...g){var l;const f=(l=this.find(g))===null||l===void 0?void 0:l.getEq();if(f instanceof Date)return f}bare(...g){const l=this.find(g);if(l!==void 0)return!l.hasProperties()}getEq(){return this.eq}getProperty(g){var l;return(l=this.properties)===null||l===void 0?void 0:l[g]}getArrayElement(g){if(Array.isArray(this.eq)&&g<this.eq.length)return this.eq[g]}get dict(){var g;return(g=this.properties)!==null&&g!==void 0?g:{}}*entries(){if(this.properties)for(const g in this.properties)yield[g,this.properties[g]]}*keys(){if(this.properties)for(const g in this.properties)yield g}hasProperties(){return this.properties!==void 0&&Object.keys(this.properties).length>0}array(...g){const l=this.find(g);if(l===void 0)return;const f=l.getEq();if(Array.isArray(f))return f.map((c,s)=>l.getArrayElement(s))}textArray(...g){const l=this.find(g);if(l===void 0)return;const f=l.getEq();if(Array.isArray(f))return f.reduce((c,s,d)=>{const e=l.getArrayElement(d),w=e?.getEq();return w===void 0||Array.isArray(w)?c:w instanceof Date?c.concat(w.toISOString()):c.concat(String(w))},[])}numericArray(...g){const l=this.find(g);if(l===void 0)return;const f=l.getEq();if(Array.isArray(f))return f.reduce((c,s,d)=>{const e=l.getArrayElement(d),w=e?.getEq();if(typeof w=="number")return c.concat(w);if(typeof w=="string"){const E=Number.parseFloat(w);if(!Number.isNaN(E))return c.concat(E)}return c},[])}getProperties(){return this.properties===void 0&&(this.properties={}),this.properties}clone(g){this._read=!0;const l=new u({},g);if(l.prefix=this.prefix,l.deleted=this.deleted,l.location=this.location,l._clonedFrom=this,this.eq!==void 0&&(Array.isArray(this.eq)?l.eq=this.eq.map(f=>f.clone(l)):l.eq=this.eq instanceof Date?new Date(this.eq):this.eq),this.properties){l.properties={};for(const[f,c]of Object.entries(this.properties))l.properties[f]=c.clone(l)}return l}toJSON(){const g={};if(this.eq!==void 0&&(Array.isArray(this.eq)?g.eq=this.eq.map(l=>l.toJSON()):g.eq=this.eq),this.properties!==void 0){g.properties={};for(const[l,f]of Object.entries(this.properties))g.properties[l]=f.toJSON()}return this.deleted&&(g.deleted=!0),this.prefix&&(g.prefix=this.prefix),this.location&&(g.location=this.location),g}validateReferences(){const g=[];return this.collectReferenceErrors(g,[]),g}collectReferenceErrors(g,l){if(this.properties)for(const[f,c]of Object.entries(this.properties))c.deleted||c.collectReferenceErrors(g,[...l,f]);Array.isArray(this.eq)&&this.eq.forEach((f,c)=>{f.collectReferenceErrors(g,[...l,`[${c}]`])})}static escapeString(g){return g.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}static escapeProp(g){return g.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static quoteAndEscape(g,l=!1){return g.match(/^[0-9A-Za-z_]+$/)?g:l?`\`${u.escapeProp(g)}\``:`"${u.escapeString(g)}"`}static serializeScalar(g){return typeof g=="boolean"?g?"@true":"@false":g instanceof Date?`@${g.toISOString()}`:typeof g=="number"?String(g):u.quoteAndEscape(g)}toString(){var g;let l=(g=this.prefix)!==null&&g!==void 0?g:"# ";function f(d){var e;const w=Object.keys((e=d.properties)!==null&&e!==void 0?e:{});for(let E=0;E<w.length;E++)s(w[E],d.properties[w[E]]),E<w.length-1&&(l+=" ")}function c(d,e=!1){if(d.eq!==void 0)if(e||(l+=" = "),Array.isArray(d.eq)){l+="[";for(let w=0;w<d.eq.length;w++)c(d.eq[w],!0),w!==d.eq.length-1&&(l+=", ");l+="]"}else l+=u.serializeScalar(d.eq);if(d.properties){const w=Object.keys(d.properties);!e&&w.length===1&&!w.some(E=>{var x;return((x=d.properties)!==null&&x!==void 0?x:{})[E].deleted})&&d.eq===void 0?(l+=".",f(d)):((!e||d.eq!==void 0)&&(l+=" "),l+="{ ",f(d),l+=" }")}}function s(d,e){if(e.deleted){l+=`-${u.quoteAndEscape(d,!0)}`;return}l+=u.quoteAndEscape(d,!0),c(e)}return f(this),l+=`
|
|
9
|
+
`,l}find(g){let l=this;for(const f of g){let c;if(typeof f=="number"?c=l.getArrayElement(f):c=l.getProperty(f),c===void 0)return;c.markRead(),l=c}return l.deleted?void 0:l}markRead(){this._read=!0,this._clonedFrom&&(this._clonedFrom._read=!0)}get wasRead(){return this._read}*walk(g=[]){if(this.properties)for(const[l,f]of Object.entries(this.properties)){if(f.deleted)continue;const c=[...g,l];yield{path:c,tag:f},yield*f.walk(c)}if(Array.isArray(this.eq))for(let l=0;l<this.eq.length;l++){const f=[...g,l.toString()];yield{path:f,tag:this.eq[l]},yield*this.eq[l].walk(f)}}resetReadTracking(){this._read=!1;for(const{tag:g}of this.walk())g._read=!1}getUnreadProperties(g=[]){const l=[];if(this.properties)for(const[f,c]of Object.entries(this.properties)){if(c.deleted)continue;const s=[...g,f];c._read?l.push(...c.getUnreadProperties(s)):l.push(s)}return l}has(...g){return this.find(g)!==void 0}set(g,l=null){let f=this,c,s;for(const d of g)if(c=f,s=d,typeof d=="number"){if(f.eq===void 0||!Array.isArray(f.eq))f.eq=Array.from({length:d+1}).map(()=>new u({},f));else if(f.eq.length<=d){const e=f.eq,w=Array.from({length:d+1}).map((E,x)=>x<e.length?e[x]:new u({},f));f.eq=w}f=f.eq[d]}else{const e=f.properties;e===void 0?(f.properties={[d]:new u({},f)},f=f.properties[d]):d in e?(f=e[d],f.deleted&&(f.deleted=!1)):(e[d]=new u({},f),f=e[d])}if(l===null)f.eq=void 0;else if(l instanceof u){const d=l.clone(c);c&&s!==void 0&&(typeof s=="number"&&Array.isArray(c.eq)?c.eq[s]=d:typeof s=="string"&&c.properties&&(c.properties[s]=d))}else typeof l=="string"||typeof l=="number"||typeof l=="boolean"||l instanceof Date?f.eq=l:Array.isArray(l)&&(f.eq=l.map(d=>new u({eq:d},f)));return this}delete(...g){return this.remove(g,!1)}unset(...g){return this.remove(g,!0)}remove(g,l=!1){var f;let c=this;for(const d of g.slice(0,g.length-1))if(typeof d=="number"){if(c.eq===void 0||!Array.isArray(c.eq)){if(!l)return this;c.eq=Array.from({length:d}).map(()=>new u({},c))}else if(c.eq.length<=d){if(!l)return this;const e=c.eq,w=Array.from({length:d}).map((E,x)=>x<e.length?e[x]:new u({},c));c.eq=w}c=c.eq[d]}else{const e=c.properties;if(e===void 0){if(!l)return this;c.properties={[d]:new u({},c)},c=c.properties[d]}else if(d in e)c=e[d];else{if(!l)return this;e[d]=new u({},c),c=e[d]}}const s=g[g.length-1];return typeof s=="string"?c.properties&&s in c.properties?delete c.properties[s]:l&&((f=c.properties)!==null&&f!==void 0||(c.properties={}),c.properties[s]=new u({deleted:!0},c)):Array.isArray(c.eq)&&c.eq.splice(s,1),this}}Rt.Tag=u,u.ids=new Map,u.nextTagId=1e3;function M(V){const g={};return V.eq!==void 0&&(Array.isArray(V.eq)?g.eq=V.eq.map(l=>M(l)):g.eq=V.eq),V.properties!==void 0&&(g.properties=z(V.properties)),V.deleted&&(g.deleted=!0),g}function z(V){const g={};for(const[l,f]of Object.entries(V))g[l]=M(f);return g}return Rt}var Ft={},kr={},qt={},jr;function Jt(){if(jr)return qt;jr=1,Object.defineProperty(qt,"__esModule",{value:!0}),qt.formatRef=u,qt.isRef=M,qt.isDataNode=z,qt.isEnvRef=V;function u(g){let l="$";for(let c=0;c<g.linkUps;c++)l+="^";let f=!0;for(const c of g.linkTo)typeof c=="string"?((!f||g.linkUps>0)&&(l+="."),l+=c,f=!1):l+=`[${c}]`;return l}function M(g){return typeof g=="object"&&g!==null&&"linkTo"in g&&"linkUps"in g&&!Array.isArray(g)&&!(g instanceof Date)}function z(g){return typeof g=="object"&&g!==null&&!M(g)}function V(g){return typeof g=="object"&&g!==null&&"env"in g&&!Array.isArray(g)&&!(g instanceof Date)}return qt}var $t={},Ur;function wn(){if(Ur)return $t;Ur=1,Object.defineProperty($t,"__esModule",{value:!0}),$t.MotValue=$t.Mot=void 0,$t.buildMot=d;const u=Jt();class M{text(...w){return this.get(...w)._text()}numeric(...w){return this.get(...w)._numeric()}boolean(...w){return this.get(...w)._boolean()}date(...w){return this.get(...w)._date()}valueType(...w){return this.get(...w)._valueType()}values(...w){return this.get(...w)._values()}texts(...w){const E=this.get(...w)._values();if(!E)return;const x=[];for(const G of E){const oe=G._text();if(oe===void 0)return;x.push(oe)}return x}numerics(...w){const E=this.get(...w)._values();if(!E)return;const x=[];for(const G of E){const oe=G._numeric();if(oe===void 0)return;x.push(oe)}return x}booleans(...w){const E=this.get(...w)._values();if(!E)return;const x=[];for(const G of E){const oe=G._boolean();if(oe===void 0)return;x.push(oe)}return x}dates(...w){const E=this.get(...w)._values();if(!E)return;const x=[];for(const G of E){const oe=G._date();if(oe===void 0)return;x.push(oe)}return x}has(...w){return this.get(...w).exists}}$t.Mot=M;class z extends M{constructor(w,E,x=!0){super(),this.isRef=!1,this._val=w,this._props=E,this.exists=x}_text(){return this._val?.type==="string"?this._val.value:void 0}_numeric(){return this._val?.type==="number"?this._val.value:void 0}_boolean(){return this._val?.type==="boolean"?this._val.value:void 0}_date(){return this._val?.type==="date"?this._val.value:void 0}_values(){return this._val?.type==="array"?this._val.value:void 0}_valueType(){return this._val?.type}get keys(){return this._props.keys()}get entries(){return this._props.entries()}get(...w){let E=this;for(const x of w){if(typeof x=="number"){const G=E.values();if(!G||!Number.isInteger(x)||x<0||x>=G.length)return f;E=G[x]}else E===this?E=this._props.get(x)??f:E=E.get(x);if(!E.exists)return f}return E}}$t.MotValue=z;class V extends M{constructor(w,E){super(),this.exists=!0,this.isRef=!0,this._target=E}_text(){return this._target.text()}_numeric(){return this._target.numeric()}_boolean(){return this._target.boolean()}_date(){return this._target.date()}_values(){return this._target.values()}_valueType(){return this._target.valueType()}get keys(){return this._target.keys}get entries(){return this._target.entries}get(...w){return this._target.get(...w)}}const g={[Symbol.iterator]:()=>({next:()=>({done:!0,value:void 0})})};class l extends M{constructor(){super(...arguments),this.exists=!1,this.isRef=!1}_text(){}_numeric(){}_boolean(){}_date(){}_values(){}_valueType(){}get keys(){return g}get entries(){return g}get(...w){return this}}const f=new l,c={createMot(e,w){return new z(e,w)},createRefMot(e,w){return new V(e,w)},undefinedMot:f};function s(e,w,E,x){let G,oe;if(e.linkUps===0)G=w,oe=[];else{const N=E.length-e.linkUps;if(N<0||N>=E.length)return;G=E[N],oe=E.slice(0,N)}let C=G,R=oe,P=G;for(let N=0;N<e.linkTo.length;N++){if((0,u.isRef)(C)){if(x.has(C))return;x.add(C);const Ee=s(C,w,R,x);if(x.delete(C),!Ee)return;C=Ee.target,R=Ee.ancestors,P=C,N--;continue}const ye=C,Se=e.linkTo[N];if(typeof Se=="string"){if(!ye.properties||!(Se in ye.properties))return;N>0&&(R=[...R,P]),P=ye,C=ye.properties[Se]}else{if(!ye.eq||!Array.isArray(ye.eq)||Se>=ye.eq.length)return;N>0&&(R=[...R,P]),P=ye,C=ye.eq[Se]}}if((0,u.isRef)(C)){if(x.has(C))return;x.add(C);const N=s(C,w,R,x);return x.delete(C),N}return{target:C,ancestors:R}}function d(e,w){const E=w?.env,x=w?.factory??c,G=x.undefinedMot,oe=new Map;function C(N,ye,Se){if(N.deleted)return G;if(oe.has(N))return oe.get(N);const Ee=new Map,xe=P(N.eq,ye,Se,N),ve=x.createMot(xe,Ee);if(oe.set(N,ve),N.properties)for(const[$e,D]of Object.entries(N.properties)){const B=R(D,ye,Se,N);B.exists&&Ee.set($e,B)}return ve}function R(N,ye,Se,Ee){if((0,u.isRef)(N)){const ve=new Set;ve.add(N);const $e=s(N,ye,Se,ve);if(!$e||$e.target.deleted)return G;const D=C($e.target,ye,$e.ancestors);return x.createRefMot(N,D)}const xe=N;return xe.deleted?G:C(xe,ye,[...Se,Ee])}function P(N,ye,Se,Ee){if(N!==void 0){if((0,u.isEnvRef)(N)){const xe=E?E[N.env]:void 0;return xe===void 0?void 0:{type:"string",value:xe}}if(Array.isArray(N)){const xe=[...Se,Ee],ve=[];for(const $e of N)ve.push(R($e,ye,xe,Ee));return{type:"array",value:ve}}if(typeof N=="string")return{type:"string",value:N};if(typeof N=="number")return{type:"number",value:N};if(typeof N=="boolean")return{type:"boolean",value:N};if(N instanceof Date)return{type:"date",value:N}}}return C(e,e,[e])}return $t}var yt={},ir={},Qr;function ji(){if(Qr)return ir;Qr=1,Object.defineProperty(ir,"__esModule",{value:!0}),ir.parse=V;class u{constructor(l){this.input=l,this.pos=0}peekChar(){return this.pos<this.input.length?this.input[this.pos]:void 0}advance(l){this.pos+=l}startsWith(l){return this.input.startsWith(l,this.pos)}eatChar(l){return this.peekChar()===l?(this.advance(1),!0):!1}expectChar(l){if(!this.eatChar(l))throw this.errorPoint(`Expected '${l}'`)}position(){const l=this.input.substring(0,this.pos),f=(l.match(/\n/g)||[]).length,c=l.lastIndexOf(`
|
|
10
|
+
`),s=this.pos-(c===-1?0:c+1);return{line:f,column:s,offset:this.pos}}errorPoint(l){const f=this.position();return{code:"tag-parse-syntax-error",message:l,begin:f,end:f}}errorSpan(l,f){return{code:"tag-parse-syntax-error",message:l,begin:f,end:this.position()}}skipWs(){for(;;){for(;this.pos<this.input.length;){const l=this.input[this.pos];if(l===" "||l===" "||l==="\r"||l===`
|
|
11
|
+
`)this.pos++;else break}if(this.peekChar()==="#")for(;this.pos<this.input.length;){const l=this.input[this.pos];if(l==="\r"||l===`
|
|
12
|
+
`)break;this.pos++}else break}}skipWsAndCommas(){for(this.skipWs();this.peekChar()===",";)this.advance(1),this.skipWs()}parseStatements(){const l=[];for(this.skipWsAndCommas();this.pos<this.input.length;)l.push(this.parseStatement()),this.skipWsAndCommas();return l}parseStatement(){const l=this.position();if(this.startsWith("-..."))return this.advance(4),{kind:"clearAll",span:{begin:l,end:this.position()}};if(this.peekChar()==="-")return this.advance(1),{kind:"define",path:this.parsePropName(),deleted:!0,span:{begin:l,end:this.position()}};const f=this.parsePropName();this.skipWs();const c=this.peekChar();if(c===":"&&this.startsWith(":=")){this.advance(2),this.skipWs();const s=this.parseEqValue();if(this.skipWs(),this.peekChar()==="{"){const d=this.parsePropertiesBlock();return{kind:"assignBoth",path:f,value:s,properties:d,span:{begin:l,end:this.position()}}}return{kind:"assignBoth",path:f,value:s,properties:null,span:{begin:l,end:this.position()}}}if(c==="="){if(this.advance(1),this.skipWs(),this.peekChar()==="{")throw this.errorPoint("'=' requires a value; use ': { ... }' to replace properties");const s=this.parseEqValue();if(this.skipWs(),this.peekChar()==="{"){const d=this.parsePropertiesBlock();return{kind:"setEq",path:f,value:s,properties:d,span:{begin:l,end:this.position()}}}return{kind:"setEq",path:f,value:s,properties:null,span:{begin:l,end:this.position()}}}if(c===":"){this.advance(1),this.skipWs();const s=this.parsePropertiesBlock();return{kind:"replaceProperties",path:f,properties:s,span:{begin:l,end:this.position()}}}if(c==="{"){const s=this.parsePropertiesBlock();return{kind:"updateProperties",path:f,properties:s,span:{begin:l,end:this.position()}}}return{kind:"define",path:f,deleted:!1,span:{begin:l,end:this.position()}}}parsePropName(){const f=[this.parseIdentifier()];for(;this.peekChar()===".";)this.advance(1),f.push(this.parseIdentifier());return f}parseIdentifier(){return this.peekChar()==="`"?this.parseBacktickString():this.parseBareString()}parseEqValue(l=!0){const f=this.peekChar();if(l&&f==="[")return{kind:"array",elements:this.parseArray()};if(this.startsWith("<<<"))return{kind:"scalar",value:{kind:"string",value:this.parseHeredoc()}};if(f==="@")return{kind:"scalar",value:this.parseAtValue()};if(f==="$")return{kind:"scalar",value:this.parseReference()};if(f==='"')return this.startsWith('"""')?{kind:"scalar",value:{kind:"string",value:this.parseTripleString()}}:{kind:"scalar",value:{kind:"string",value:this.parseDoubleQuotedString()}};if(f==="'")return this.startsWith("'''")?{kind:"scalar",value:{kind:"string",value:this.parseTripleSingleQuotedString()}}:{kind:"scalar",value:{kind:"string",value:this.parseSingleQuotedString()}};if(f!==void 0&&(f==="-"||f>="0"&&f<="9"||f==="."))return this.parseNumberOrString();if(f!==void 0&&M(f))return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}};throw this.errorPoint("Expected a value")}parseAtValue(){const l=this.position();if(this.expectChar("@"),this.startsWith("true")&&!this.isBareCharAt(4))return this.advance(4),{kind:"boolean",value:!0};if(this.startsWith("false")&&!this.isBareCharAt(5))return this.advance(5),{kind:"boolean",value:!1};if(this.startsWith("none")&&!this.isBareCharAt(4))return this.advance(4),{kind:"none"};if(this.startsWith("env."))return this.advance(4),{kind:"env",name:this.parseIdentifier()};const f=this.peekChar();if(f!==void 0&&f>="0"&&f<="9")return this.parseDate(l);const c=this.pos;for(;this.pos<this.input.length&&M(this.input[this.pos]);)this.pos++;const s=this.pos>c?this.input.substring(c,this.pos):"";throw this.errorSpan(`Illegal constant @${s}; expected @true, @false, @none, @env.NAME, or @date`,l)}isBareCharAt(l){const f=this.pos+l;return f<this.input.length&&M(this.input[f])}parseDate(l){const f=this.pos;if(this.consumeDigits(4,l),this.expectChar("-"),this.consumeDigits(2,l),this.expectChar("-"),this.consumeDigits(2,l),this.peekChar()==="T"){if(this.advance(1),this.consumeDigits(2,l),this.expectChar(":"),this.consumeDigits(2,l),this.peekChar()===":"&&(this.advance(1),this.consumeDigits(2,l),this.peekChar()===".")){this.advance(1);const d=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.pos++;if(this.pos===d)throw this.errorSpan("Expected fractional digits in date",l)}const s=this.peekChar();s==="Z"?this.advance(1):(s==="+"||s==="-")&&(this.advance(1),this.consumeDigits(2,l),this.peekChar()===":"&&this.advance(1),this.consumeDigits(2,l))}return{kind:"date",value:this.input.substring(f,this.pos)}}consumeDigits(l,f){for(let c=0;c<l;c++){const s=this.peekChar();if(s===void 0||s<"0"||s>"9")throw this.errorSpan("Expected digit",f);this.advance(1)}}parseNumberOrString(){const l=this.pos,f=this.position(),c=this.peekChar()==="-";c&&this.advance(1);let s=!1,d=!1;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)s=!0,this.advance(1);if(this.peekChar()==="."){d=!0,this.advance(1);const G=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===G)return this.pos=l,this.parseIntegerOrBare(l,c)}if(!s&&!d){if(this.pos=l,c)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}const e=this.peekChar();if(e==="e"||e==="E"){this.advance(1);const G=this.peekChar();(G==="+"||G==="-")&&this.advance(1);const oe=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===oe)throw this.errorSpan("Expected exponent digits",f)}const w=this.peekChar();if(w!==void 0&&M(w)&&!(w>="0"&&w<="9")){if(this.pos=l,c)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}const E=this.input.substring(l,this.pos),x=parseFloat(E);if(isNaN(x))throw this.errorSpan(`Invalid number: ${E}`,f);return{kind:"scalar",value:{kind:"number",value:x}}}parseIntegerOrBare(l,f){this.pos=l;const c=this.position();f&&this.advance(1);const s=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===s){if(this.pos=l,f)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}if(!f){const E=this.peekChar();if(E!==void 0&&M(E)&&!(E>="0"&&E<="9"))return this.pos=l,{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}const d=this.peekChar();if(d==="e"||d==="E"){this.advance(1);const E=this.peekChar();(E==="+"||E==="-")&&this.advance(1);const x=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===x)throw this.errorSpan("Expected exponent digits",c)}const e=this.input.substring(l,this.pos),w=parseFloat(e);if(isNaN(w))throw this.errorSpan(`Invalid number: ${e}`,c);return{kind:"scalar",value:{kind:"number",value:w}}}parseBareString(){const l=this.pos;for(;this.pos<this.input.length&&M(this.input[this.pos]);)this.pos++;if(this.pos===l)throw this.errorPoint("Expected an identifier");return this.input.substring(l,this.pos)}parseDoubleQuotedString(){const l=this.position();this.expectChar('"');let f="";for(;;){const c=this.peekChar();if(c===void 0||c==="\r"||c===`
|
|
13
|
+
`)throw this.errorSpan("Unterminated string",l);if(c==='"')return this.advance(1),f;c==="\\"?(this.advance(1),f+=this.parseEscapeChar()):(this.advance(1),f+=c)}}parseSingleQuotedString(){const l=this.position();this.expectChar("'");let f="";for(;;){const c=this.peekChar();if(c===void 0||c==="\r"||c===`
|
|
14
|
+
`)throw this.errorSpan("Unterminated string",l);if(c==="'")return this.advance(1),f;if(c==="\\"){this.advance(1),f+="\\";const s=this.peekChar();if(s===void 0||s==="\r"||s===`
|
|
15
|
+
`)throw this.errorSpan("Unterminated string",l);this.advance(1),f+=s}else this.advance(1),f+=c}}parseTripleSingleQuotedString(){const l=this.position();if(!this.startsWith("'''"))throw this.errorPoint("Expected triple-single-quoted string");this.advance(3);let f="";for(;;){if(this.startsWith("'''"))return this.advance(3),f;const c=this.peekChar();if(c===void 0)throw this.errorSpan("Unterminated triple-single-quoted string",l);if(c==="\\"){this.advance(1),f+="\\";const s=this.peekChar();if(s===void 0)throw this.errorSpan("Unterminated triple-single-quoted string",l);this.advance(1),f+=s}else this.advance(1),f+=c}}parseBacktickString(){const l=this.position();this.expectChar("`");let f="";for(;;){const c=this.peekChar();if(c===void 0||c==="\r"||c===`
|
|
16
|
+
`)throw this.errorSpan("Unterminated backtick string",l);if(c==="`")return this.advance(1),f;c==="\\"?(this.advance(1),f+=this.parseEscapeChar()):(this.advance(1),f+=c)}}parseTripleString(){const l=this.position();if(!this.startsWith('"""'))throw this.errorPoint("Expected triple-quoted string");this.advance(3);let f="";for(;;){if(this.startsWith('"""'))return this.advance(3),f;const c=this.peekChar();if(c===void 0)throw this.errorSpan("Unterminated triple-quoted string",l);c==="\\"?(this.advance(1),f+=this.parseEscapeChar()):(this.advance(1),f+=c)}}parseEscapeChar(){const l=this.peekChar();if(l===void 0)throw this.errorPoint("Unterminated escape sequence");switch(l){case"b":return this.advance(1),"\b";case"f":return this.advance(1),"\f";case"n":return this.advance(1),`
|
|
17
|
+
`;case"r":return this.advance(1),"\r";case"t":return this.advance(1)," ";case"u":{const f=this.position();this.advance(1);const c=this.pos;for(let e=0;e<4;e++){const w=this.peekChar();if(w===void 0||!z(w))throw this.errorSpan("Expected 4 hex digits in \\uXXXX",f);this.advance(1)}const s=this.input.substring(c,this.pos),d=parseInt(s,16);return String.fromCharCode(d)}default:return this.advance(1),l}}parseHeredoc(){const l=this.position();for(this.advance(3);this.pos<this.input.length;){const e=this.input[this.pos];if(e===" "||e===" ")this.pos++;else break}if(this.pos<this.input.length&&this.input[this.pos]==="\r"&&this.advance(1),this.pos>=this.input.length||this.input[this.pos]!==`
|
|
18
|
+
`)throw this.errorSpan("Expected newline after <<<",l);this.advance(1);const f=[];let c=!1;for(;this.pos<this.input.length;){const e=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
19
|
+
`;)this.pos++;let w=this.input.substring(e,this.pos);if(w.endsWith("\r")&&(w=w.substring(0,w.length-1)),this.pos<this.input.length&&this.input[this.pos]===`
|
|
20
|
+
`&&this.advance(1),w.trim()===">>>"){c=!0;break}f.push(w)}if(!c)throw this.errorSpan("Unterminated heredoc (expected >>>)",l);if(f.length===0)return"";let s=0;for(const e of f){const w=e.trimStart();if(w.length>0){s=e.length-w.length;break}}return f.map(e=>e.trimStart().length===0?"":s<=e.length?e.substring(s):e).join(`
|
|
21
|
+
`)+`
|
|
22
|
+
`}parseArray(){const l=this.position();if(this.expectChar("["),this.skipWs(),this.eatChar("]"))return[];const f=[];for(f.push(this.parseArrayElement());;){if(this.skipWs(),this.eatChar("]"))return f;if(this.eatChar(",")){if(this.skipWs(),this.peekChar()==="]")return this.advance(1),f;f.push(this.parseArrayElement())}else throw this.pos>=this.input.length?this.errorSpan("Unclosed '['",l):this.errorPoint("Expected ',' or ']' in array")}}parseArrayElement(){this.skipWs();const l=this.position(),f=this.peekChar();if(f==="{")return{value:null,properties:this.parsePropertiesBlock(),span:{begin:l,end:this.position()}};if(f==="["){const s=this.parseArray();if(this.skipWs(),this.peekChar()==="{"){const d=this.parsePropertiesBlock();return{value:{kind:"array",elements:s},properties:d,span:{begin:l,end:this.position()}}}return{value:{kind:"array",elements:s},properties:null,span:{begin:l,end:this.position()}}}const c=this.parseEqValue(!1);if(this.skipWs(),this.peekChar()==="{"){const s=this.parsePropertiesBlock();return{value:c,properties:s,span:{begin:l,end:this.position()}}}return{value:c,properties:null,span:{begin:l,end:this.position()}}}parsePropertiesBlock(){const l=this.position();this.expectChar("{");const f=[];for(;;){if(this.skipWsAndCommas(),this.eatChar("}"))return f;if(this.pos>=this.input.length)throw this.errorSpan("Unclosed '{'",l);f.push(this.parseStatement())}}parseReference(){this.expectChar("$");let l=0;for(;this.peekChar()==="^";)this.advance(1),l++;if(l>0){if(this.peekChar()!==".")return{kind:"reference",ups:l,path:[]};this.advance(1)}const f=[],c=this.parseIdentifier();if(f.push({kind:"name",name:c}),this.peekChar()==="["){this.advance(1),this.skipWs();const s=this.parseRefIndex();f.push({kind:"index",index:s}),this.skipWs(),this.expectChar("]")}for(;this.peekChar()===".";){this.advance(1);const s=this.parseIdentifier();if(f.push({kind:"name",name:s}),this.peekChar()==="["){this.advance(1),this.skipWs();const d=this.parseRefIndex();f.push({kind:"index",index:d}),this.skipWs(),this.expectChar("]")}}return{kind:"reference",ups:l,path:f}}parseRefIndex(){const l=this.position(),f=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.pos++;if(this.pos===f)throw this.errorPoint("Expected array index");const c=parseInt(this.input.substring(f,this.pos),10);if(isNaN(c))throw this.errorSpan("Invalid array index",l);return c}}function M(g){const l=g.charCodeAt(0);return l>=48&&l<=57||l>=65&&l<=90||l>=97&&l<=122||l===95||l>=192&&l<=591||l>=7680&&l<=7935}function z(g){const l=g.charCodeAt(0);return l>=48&&l<=57||l>=65&&l<=70||l>=97&&l<=102}function V(g){return new u(g).parseStatements()}return ir}var Ct={},vt={},Br;function _n(){if(Br)return vt;Br=1,Object.defineProperty(vt,"__esModule",{value:!0}),vt.clonePropertyValue=vt.cloneValue=void 0,vt.cloneNode=M,vt.cloneMotlyNode=z;const u=Jt();function M(V){const g={};if(V.deleted&&(g.deleted=!0),V.eq!==void 0&&(V.eq instanceof Date?g.eq=new Date(V.eq.getTime()):Array.isArray(V.eq)?g.eq=V.eq.map(z):(0,u.isEnvRef)(V.eq)?g.eq={env:V.eq.env}:g.eq=V.eq),V.properties){const l={};for(const f of Object.keys(V.properties))l[f]=z(V.properties[f]);g.properties=l}return V.location&&(g.location={parseId:V.location.parseId,begin:{...V.location.begin},end:{...V.location.end}}),g}function z(V){return(0,u.isRef)(V)?{linkTo:[...V.linkTo],linkUps:V.linkUps}:M(V)}return vt.cloneValue=M,vt.clonePropertyValue=z,vt}var Wr;function Ui(){if(Wr)return Ct;Wr=1,Object.defineProperty(Ct,"__esModule",{value:!0}),Ct.flatten=z,Ct.chunk=l,Ct.topoSort=w,Ct.executeChunked=E;const u=Jt(),M=_n();function z(p,v){const m=[];return V(p,[],v.parseId,m),m}function V(p,v,m,b){for(const A of p)g(A,v,m,b)}function g(p,v,m,b){switch(p.kind){case"setEq":{const A=[...v,...p.path];if(p.value.kind==="scalar"&&p.value.value.kind==="reference"){const L=p.value.value;b.push({path:A,op:{kind:"link",ups:L.ups,refPath:L.path},span:p.span,parseId:m})}else b.push({path:A,op:{kind:"setValue",value:p.value},span:p.span,parseId:m}),p.properties!==null&&V(p.properties,A,m,b);break}case"assignBoth":{const A=[...v,...p.path];if(p.value.kind==="scalar"&&p.value.value.kind==="reference"){const L=p.value.value;b.push({path:A,op:{kind:"clone",ups:L.ups,refPath:L.path},span:p.span,parseId:m}),p.properties!==null&&(b.push({path:A,op:{kind:"clearProperties"},span:p.span,parseId:m}),V(p.properties,A,m,b))}else b.push({path:A,op:{kind:"assignValue",value:p.value},span:p.span,parseId:m}),p.properties!==null&&V(p.properties,A,m,b);break}case"replaceProperties":{const A=[...v,...p.path];b.push({path:A,op:{kind:"clearProperties"},span:p.span,parseId:m}),V(p.properties,A,m,b);break}case"updateProperties":{const A=[...v,...p.path];b.push({path:A,op:{kind:"define"},span:p.span,parseId:m}),V(p.properties,A,m,b);break}case"define":{const A=[...v,...p.path];b.push({path:A,op:{kind:p.deleted?"delete":"define"},span:p.span,parseId:m});break}case"clearAll":{b.push({path:[...v],op:{kind:"clearAll"},span:p.span,parseId:m});break}}}function l(p){const v=p.length;if(v===0)return{splits:[0],deps:[]};const m=new Map;for(let ae=0;ae<v;ae++)m.set(f(p[ae].path),ae);const b=new Set([0,v]),A=new Set,L=[];for(let ae=0;ae<v;ae++){const le=p[ae],Fe=f(le.path);if(le.op.kind==="link"||le.op.kind==="clone"){const Ue=d(le.path,le.op.ups,le.op.refPath);if(!c(A,Ue)){L.push({refIdx:ae,targetKey:Ue}),b.add(ae),b.add(ae+1);const rt=s(m,Ue);rt>ae&&b.add(rt)}}A.add(Fe)}const U=Array.from(b).sort((ae,le)=>ae-le),K=U.length-1,F=Array.from({length:K},()=>new Set);for(const{refIdx:ae,targetKey:le}of L){const Fe=e(U,ae),Ue=s(m,le);if(Ue!==-1){const Ne=e(U,Ue);Ne!==Fe&&F[Fe].add(Ne)}const rt=f(p[ae].path);for(let Ne=ae+1;Ne<v;Ne++){const ze=f(p[Ne].path);if(ze===rt||ze.startsWith(rt+"\0")){const He=e(U,Ne);He!==Fe&&F[He].add(Fe)}}}const H=F.map(ae=>Array.from(ae));return{splits:U,deps:H}}function f(p){return p.join("\0")}function c(p,v){for(const m of p)if(m===v||m.startsWith(v+"\0"))return!0;return!1}function s(p,v){let m=-1;for(const[b,A]of p)(b===v||b.startsWith(v+"\0")||v.startsWith(b+"\0"))&&(m=Math.max(m,A));return m}function d(p,v,m){const b=[];if(v>0){const A=Math.max(0,p.length-1-v);for(let L=0;L<A;L++)b.push(p[L])}for(const A of m)A.kind==="name"?b.push(A.name):b.push(`[${A.index}]`);return b.join("\0")}function e(p,v){let m=0,b=p.length-2;for(;m<b;){const A=m+b+1>>1;p[A]<=v?m=A:b=A-1}return m}function w(p){const v=p.length,m=new Array(v).fill(0),b=Array.from({length:v},()=>[]);for(let F=0;F<v;F++)for(const H of p[F])b[H].push(F),m[F]++;const A=[];for(let F=0;F<v;F++)m[F]===0&&A.push(F);const L=[];let U=0;for(;U<A.length;){const F=A[U++];L.push(F);for(const H of b[F])--m[H]===0&&A.push(H)}const K=[];if(L.length<v){const F=new Set(L);for(let H=0;H<v;H++)F.has(H)||K.push(H)}return{order:L,cycles:K}}function E(p,v,m,b,A){const L=[],U=[];for(const K of m){const F=v[K],H=v[K+1];for(let ae=F;ae<H;ae++)G(p[ae],b,A,L,U)}return x(L,U),L}function x(p,v){if(v.length<2)return;const m=new Map;for(const U of v)m.set(U.sourcePath,U);const b=new Set,A=new Set;for(const U of v){if(A.has(U.sourcePath))continue;const K=[],F=new Set;let H=U;for(;H&&!F.has(H.sourcePath)&&!A.has(H.sourcePath);)K.push(H),F.add(H.sourcePath),H=m.get(H.targetPath);if(H&&F.has(H.sourcePath)){const ae=H.sourcePath,le=[];let Fe=!1;for(const O of K)O.sourcePath===ae&&(Fe=!0),Fe&&le.push(O);const Ue=O=>O.replace(/\0/g,"."),rt=le.map(O=>Ue(O.sourcePath)),Ne=le.map(O=>`$${Ue(O.targetPath)}`);let ze=rt[0];for(let O=0;O<Ne.length;O++)ze+=` clones ${Ne[O]}`,O<Ne.length-1&&(ze+=`, ${rt[O+1]}`);for(const O of le)b.add(O.errorIndex);const He=le[0].errorIndex,Je={line:0,column:0,offset:0};p[He]={code:"circular-reference",message:`Circular clone dependency: ${ze}`,begin:Je,end:Je}}for(const ae of K)A.add(ae.sourcePath)}const L=Array.from(b).sort((U,K)=>K-U);for(const U of L)p[U].code!=="circular-reference"&&p.splice(U,1)}function G(p,v,m,b,A){const L={parseId:p.parseId,options:m};switch(p.op.kind){case"setValue":oe(p.path,p.op.value,v,L,p.span,b);break;case"assignValue":C(p.path,p.op.value,v,L,p.span,b);break;case"clearProperties":R(p.path,v,L,p.span,b);break;case"clearAll":P(p.path,v,L,p.span,b);break;case"define":N(p.path,v,L,p.span,b);break;case"delete":ye(p.path,v,L,p.span,b);break;case"link":Se(p.path,p.op.ups,p.op.refPath,v,L,p.span,b);break;case"clone":Ee(p.path,p.op.ups,p.op.refPath,v,L,p.span,b,A);break}}function oe(p,v,m,b,A,L){if(p.length===0){ne(m,v,b,L);return}const U=Q(m,p,b,A,L);if(!U)return;const[K,F]=U,H=X(F);H[K]===void 0&&(H[K]={});const ae=$(H,K);$e(ae,b,A),ne(ae,v,b,L)}function C(p,v,m,b,A,L){if(p.length===0){delete m.properties,m.location=ve(b,A),ne(m,v,b,L);return}const U=Q(m,p,b,A,L);if(!U)return;const[K,F]=U,H={};H.location=ve(b,A),ne(H,v,b,L),X(F)[K]=H}function R(p,v,m,b,A){if(p.length===0){delete v.properties;return}const L=Q(v,p,m,b,A);if(!L)return;const[U,K]=L,F=X(K),H=F[U];if(H!==void 0&&!(0,u.isRef)(H))delete H.properties;else{const ae={};ae.location=ve(m,b),F[U]=ae}}function P(p,v,m,b,A){if(p.length===0){delete v.eq,v.properties={};return}const L=Q(v,p,m,b,A);if(!L)return;const[U,K]=L,F=X(K),H=F[U];H!==void 0&&!(0,u.isRef)(H)?(delete H.eq,H.properties={}):F[U]={}}function N(p,v,m,b,A){const L=Q(v,p,m,b,A);if(!L)return;const[U,K]=L,F=X(K);if(F[U]===void 0){const H={};H.location=ve(m,b),F[U]=H}}function ye(p,v,m,b,A){const L=Q(v,p,m,b,A);if(!L)return;const[U,K]=L,F={deleted:!0};F.location=ve(m,b),X(K)[U]=F}function Se(p,v,m,b,A,L,U){A.options.disableReferences&&U.push({code:"ref-not-allowed",message:"References are not allowed in this session. Use := for cloning.",begin:L.begin,end:L.end});const K=Q(b,p,A,L,U);if(!K)return;const[F,H]=K;X(H)[F]=Ae(v,m)}function Ee(p,v,m,b,A,L,U,K){const F=Q(b,p,A,L,U);if(!F)return;const[H,ae]=F;let le;try{le=pe(b,p,v,m)}catch(Fe){if(Fe&&typeof Fe=="object"&&"code"in Fe){const Ue=U.length;U.push(Fe),K.push({sourcePath:f(p),targetPath:d(p,v,m),errorIndex:Ue})}return}tt(le,0,U),le.location=ve(A,L),X(ae)[H]=le}function xe(p,v,m,b){switch(p.kind){case"setEq":D(v,p.path,p.value,p.properties,m,b,p.span);break;case"assignBoth":B(v,p.path,p.value,p.properties,m,b,p.span);break;case"replaceProperties":Y(v,p.path,p.properties,m,b,p.span);break;case"updateProperties":j(v,p.path,p.properties,m,b,p.span);break;case"define":W(v,p.path,p.deleted,m,b,p.span);break;case"clearAll":delete v.eq,v.properties={};break}}function ve(p,v){return{parseId:p.parseId,begin:v.begin,end:v.end}}function $e(p,v,m){p.location||(p.location=ve(v,m))}function D(p,v,m,b,A,L,U){if(m.kind==="scalar"&&m.value.kind==="reference"){if(L.options.disableReferences&&A.push({code:"ref-not-allowed",message:"References are not allowed in this session. Use := for cloning.",begin:U.begin,end:U.end}),b!==null){const ze={line:0,column:0,offset:0};A.push({code:"ref-with-properties",message:"Cannot add properties to a reference. Did you mean := (clone)?",begin:ze,end:ze})}const Ue=Q(p,v,L,U,A);if(!Ue)return;const[rt,Ne]=Ue;X(Ne)[rt]=Ae(m.value.ups,m.value.path);return}const K=Q(p,v,L,U,A);if(!K)return;const[F,H]=K,ae=X(H);let le=ae[F];le===void 0&&(le={},ae[F]=le);const Fe=$(ae,F);if($e(Fe,L,U),ne(Fe,m,L,A),b!==null)for(const Ue of b)xe(Ue,Fe,A,L)}function B(p,v,m,b,A,L,U){if(m.kind==="scalar"&&m.value.kind==="reference"){let K;try{K=pe(p,v,m.value.ups,m.value.path)}catch(le){le&&typeof le=="object"&&"code"in le&&A.push(le);return}if(tt(K,0,A),b!==null){K.properties={};for(const le of b)xe(le,K,A,L)}K.location=ve(L,U);const F=Q(p,v,L,U,A);if(!F)return;const[H,ae]=F;X(ae)[H]=K}else{const K={};if(K.location=ve(L,U),ne(K,m,L,A),b!==null)for(const le of b)xe(le,K,A,L);const F=Q(p,v,L,U,A);if(!F)return;const[H,ae]=F;X(ae)[H]=K}}function Y(p,v,m,b,A,L){const U=Q(p,v,A,L,b);if(!U)return;const[K,F]=U,H={},ae=X(F),le=ae[K];le!==void 0&&!(0,u.isRef)(le)&&(H.eq=le.eq,le.location&&(H.location=le.location)),H.location||(H.location=ve(A,L));for(const Fe of m)xe(Fe,H,b,A);ae[K]=H}function j(p,v,m,b,A,L){const U=Q(p,v,A,L,b);if(!U)return;const[K,F]=U,H=X(F);if(H[K]!==void 0&&(0,u.isRef)(H[K])){b.push({code:"write-through-link",message:`Cannot write through link reference "${K}"`,begin:L.begin,end:L.end});return}H[K]===void 0&&(H[K]={});const ae=$(H,K);$e(ae,A,L);for(const le of m)xe(le,ae,b,A)}function W(p,v,m,b,A,L){const U=Q(p,v,A,L,b);if(!U)return;const[K,F]=U,H=X(F);if(m){const ae={deleted:!0};ae.location=ve(A,L),H[K]=ae}else if(H[K]===void 0){const ae={};ae.location=ve(A,L),H[K]=ae}}function Q(p,v,m,b,A){let L=p;for(let U=0;U<v.length-1;U++){const K=v[U],F=X(L);if(F[K]!==void 0&&(0,u.isRef)(F[K]))return A.push({code:"write-through-link",message:`Cannot write through link reference "${K}"`,begin:b.begin,end:b.end}),null;if(F[K]===void 0){const H={};H.location=ve(m,b),F[K]=H}L=$(F,K),$e(L,m,b)}return[v[v.length-1],L]}function ne(p,v,m,b){if(v.kind==="array")p.eq=re(v.elements,b,m);else{const A=v.value;switch(A.kind){case"string":p.eq=A.value;break;case"number":p.eq=A.value;break;case"boolean":p.eq=A.value;break;case"date":p.eq=new Date(A.value);break;case"reference":throw new Error("References should be handled before calling setEqSlot");case"env":p.eq={env:A.name};break;case"none":delete p.eq;break}}}function re(p,v,m){return p.map(b=>he(b,v,m))}function he(p,v,m){if(p.value!==null&&p.value.kind==="scalar"&&p.value.value.kind==="reference"){if(m.options.disableReferences&&v.push({code:"ref-not-allowed",message:"References are not allowed in this session. Use := for cloning.",begin:p.span.begin,end:p.span.end}),p.properties!==null){const A={line:0,column:0,offset:0};v.push({code:"ref-with-properties",message:"Cannot add properties to a reference. Did you mean := (clone)?",begin:A,end:A})}return Ae(p.value.value.ups,p.value.value.path)}const b={};if(b.location=ve(m,p.span),p.value!==null&&ne(b,p.value,m,v),p.properties!==null)for(const A of p.properties)xe(A,b,v,m);return b}function Ae(p,v){return{linkTo:v.map(m=>m.kind==="name"?m.name:m.index),linkUps:p}}function _e(p,v){let m="$";for(let A=0;A<p;A++)m+="^";let b=!0;for(const A of v)A.kind==="name"?((!b||p>0)&&(m+="."),m+=A.name,b=!1):m+=`[${A.index}]`;return m}function pe(p,v,m,b){const A=_e(m,b);let L;if(m===0)L=p;else{const K=v.length-1-m;if(K<0)throw ge(`Clone reference ${A} goes ${m} level(s) up but only ${v.length-1} ancestor(s) available`);L=p;for(let F=0;F<K;F++){if(!L.properties)throw ge(`Clone reference ${A} could not be resolved: path segment "${v[F]}" not found`);const H=L.properties[v[F]];if(H===void 0)throw ge(`Clone reference ${A} could not be resolved: path segment "${v[F]}" not found`);if((0,u.isRef)(H)){const ae=Ve(p,H);if(!ae)throw ge(`Clone reference ${A} could not be resolved: path segment "${v[F]}" is an unresolvable link reference`);L=ae;continue}L=H}}let U=L;for(const K of b)if(K.kind==="name"){if(!U.properties)throw ge(`Clone reference ${A} could not be resolved: property "${K.name}" not found`);const F=U.properties[K.name];if(F===void 0)throw ge(`Clone reference ${A} could not be resolved: property "${K.name}" not found`);if((0,u.isRef)(F)){const H=Ve(p,F);if(!H)throw ge(`Clone reference ${A} could not be resolved: property "${K.name}" is an unresolvable link reference`);U=H;continue}U=F}else{if(!U.eq||!Array.isArray(U.eq))throw ge(`Clone reference ${A} could not be resolved: index [${K.index}] used on non-array`);if(K.index>=U.eq.length)throw ge(`Clone reference ${A} could not be resolved: index [${K.index}] out of bounds (array length ${U.eq.length})`);const F=U.eq[K.index];if((0,u.isRef)(F)){const H=Ve(p,F);if(!H)throw ge(`Clone reference ${A} could not be resolved: index [${K.index}] is an unresolvable link reference`);U=H;continue}U=F}return(0,M.cloneNode)(U)}function ge(p){const v={line:0,column:0,offset:0};return{code:"unresolved-clone-reference",message:p,begin:v,end:v}}function Ve(p,v,m){m||(m=new Set);const b=(0,u.formatRef)(v);if(m.has(b)||(m.add(b),v.linkUps>0))return null;let A=p;for(const L of v.linkTo){if(A===void 0)return null;if((0,u.isRef)(A)){const K=Ve(p,A,m);if(!K)return null;A=K}const U=A;if(typeof L=="string"){if(!U.properties||!(L in U.properties))return null;A=U.properties[L]}else{if(!U.eq||!Array.isArray(U.eq)||L>=U.eq.length)return null;A=U.eq[L]}}return A!==void 0&&(0,u.isRef)(A)?Ve(p,A,m):A??null}function tt(p,v,m){if(p.eq!==void 0&&Array.isArray(p.eq))for(let b=0;b<p.eq.length;b++)at(p.eq,b,v+1,m);if(p.properties)for(const b of Object.keys(p.properties))it(p.properties,b,v+1,m)}function at(p,v,m,b){const A=p[v];if((0,u.isRef)(A)){if(A.linkUps>0&&A.linkUps>m){const L={line:0,column:0,offset:0};b.push({code:"clone-reference-out-of-scope",message:`Cloned reference "${(0,u.formatRef)(A)}" escapes the clone boundary (${A.linkUps} level(s) up from depth ${m})`,begin:L,end:L}),p[v]={}}}else tt(A,m,b)}function it(p,v,m,b){const A=p[v];if((0,u.isRef)(A)){if(A.linkUps>0&&A.linkUps>m){const L={line:0,column:0,offset:0};b.push({code:"clone-reference-out-of-scope",message:`Cloned reference "${(0,u.formatRef)(A)}" escapes the clone boundary (${A.linkUps} level(s) up from depth ${m})`,begin:L,end:L}),p[v]={}}}else tt(A,m,b)}function X(p){return p.properties||(p.properties={}),p.properties}function $(p,v){const m=p[v];if((0,u.isRef)(m)){const b={};return p[v]=b,b}return m}return Ct}var Gt={},Gr;function Qi(){if(Gr)return Gt;Gr=1,Object.defineProperty(Gt,"__esModule",{value:!0}),Gt.validateReferences=z,Gt.validateSchema=d;const u=Jt();function M(D,B,Y,j,W){const Q={code:B,message:Y,path:j};W?.location&&(Q.location=W.location),D.push(Q)}function z(D){const B=[];return V(D,[],[D],D,B),B}function V(D,B,Y,j,W){if(D.eq!==void 0&&Array.isArray(D.eq)&&g(D.eq,B,Y,D,j,W),D.properties)for(const Q of Object.keys(D.properties)){const ne=D.properties[Q];if(B.push(Q),(0,u.isRef)(ne)){const re=l(ne,Y,j);if(re!==null){const he={message:re,path:[...B],code:"unresolved-reference"};D.location&&(he.location=D.location),W.push(he)}}else Y.push(D),V(ne,B,Y,j,W),Y.pop();B.pop()}}function g(D,B,Y,j,W,Q){for(let ne=0;ne<D.length;ne++){const re=D[ne],he=`[${ne}]`;if(B.push(he),(0,u.isRef)(re)){const Ae=l(re,Y,W);Ae!==null&&Q.push({message:Ae,path:[...B],code:"unresolved-reference"})}else Y.push(j),V(re,B,Y,W,Q),Y.pop();B.pop()}}function l(D,B,Y){const j=(0,u.formatRef)(D);let W;if(D.linkUps===0)W=Y;else{const Q=B.length-D.linkUps;if(Q<0||Q>=B.length)return`Reference "${j}" goes ${D.linkUps} level(s) up but only ${B.length} ancestor(s) available`;W=B[Q]}return f(W,D.linkTo,j)}function f(D,B,Y){let j=D;for(const W of B){if(j==="terminal")return`Reference "${Y}" could not be resolved: cannot follow path through a link`;if(typeof W=="string"){if(!j.properties)return`Reference "${Y}" could not be resolved: property "${W}" not found (node has no properties)`;const Q=j.properties[W];if(Q===void 0)return`Reference "${Y}" could not be resolved: property "${W}" not found`;(0,u.isRef)(Q)?j="terminal":j=Q}else{if(j.eq===void 0||!Array.isArray(j.eq))return`Reference "${Y}" could not be resolved: index [${W}] used on non-array`;if(W>=j.eq.length)return`Reference "${Y}" could not be resolved: index [${W}] out of bounds (array length ${j.eq.length})`;const Q=j.eq[W];(0,u.isRef)(Q)?j="terminal":j=Q}}return null}const c=64,s={string:{properties:{VALUE:{eq:"string"}}},number:{properties:{VALUE:{eq:"number"}}},integer:{properties:{VALUE:{eq:"integer"}}},boolean:{properties:{VALUE:{eq:"boolean"}}},date:{properties:{VALUE:{eq:"date"}}},flag:{properties:{ADDITIONAL:{eq:"reject"}}},tag:{properties:{ADDITIONAL:{eq:"accept"}}},any:{properties:{ADDITIONAL:{eq:"accept"}}}};function d(D,B){const Y=[],j=e(B,Y);return E(D,B,j,[],Y,0),Y}function e(D,B){const Y={...s},j=w(D,"TYPES");if(j?.properties){for(const[W,Q]of Object.entries(j.properties))if(!(0,u.isRef)(Q)){if(W in s){B.push({message:`Type "${W}" cannot shadow pre-loaded type`,path:["TYPES",W],code:"invalid-schema"});continue}Y[W]=Q}}return Y}function w(D,B){if(!D.properties)return;const Y=D.properties[B];if(!(Y===void 0||(0,u.isRef)(Y)))return Y}function E(D,B,Y,j,W,Q){if(Q>c){M(W,"invalid-schema","Maximum validation depth exceeded (possible recursive type cycle)",[...j],D);return}const ne=w(B,"ONEOF");if(ne&&Array.isArray(ne.eq)){xe(D,ne.eq,Y,j,W,Q);return}const re=w(B,"VALUE");re&&x(D,re,Y,j,W),N(D,B,Y,j,W,Q)}function x(D,B,Y,j,W,Q){const ne=typeof B.eq=="string"?B.eq:void 0;if(!ne)return;const re=D.eq;switch(ne){case"string":if(typeof re!="string"){M(W,"wrong-type",`Expected string, got ${G(re)}`,[...j],D);return}oe(re,B,j,W,D);break;case"number":if(typeof re!="number"){M(W,"wrong-type",`Expected number, got ${G(re)}`,[...j],D);return}C(re,B,j,W,D);break;case"integer":if(typeof re!="number"||!Number.isInteger(re)){M(W,"wrong-type",`Expected integer, got ${G(re)}`,[...j],D);return}C(re,B,j,W,D);break;case"boolean":if(typeof re!="boolean"){M(W,"wrong-type",`Expected boolean, got ${G(re)}`,[...j],D);return}R(re,B,j,W,D);break;case"date":if(!(re instanceof Date)){M(W,"wrong-type",`Expected date, got ${G(re)}`,[...j],D);return}R(re,B,j,W,D);break;default:{const he=Y[ne];if(!he){M(W,"invalid-schema",`Unknown VALUE type "${ne}"`,[...j],D);return}const Ae=w(he,"VALUE");if(!Ae){M(W,"invalid-schema",`Type "${ne}" cannot be used as a VALUE type (no VALUE constraint)`,[...j],D);return}x(D,Ae,Y,j,W)}}}function G(D){return D===void 0?"no value":D instanceof Date?"date":Array.isArray(D)?"array":typeof D}function oe(D,B,Y,j,W){R(D,B,Y,j,W);const Q=w(B,"MATCHES");if(Q&&typeof Q.eq=="string")try{new RegExp(Q.eq).test(D)||M(j,"pattern-mismatch",`Value "${D}" does not match pattern "${Q.eq}"`,[...Y],W)}catch(he){M(j,"invalid-schema",`Invalid regex pattern "${Q.eq}": ${he}`,[...Y],W)}const ne=w(B,"MIN_LENGTH");ne&&typeof ne.eq=="number"&&D.length<ne.eq&&M(j,"length-violation",`String length ${D.length} is less than minimum ${ne.eq}`,[...Y],W);const re=w(B,"MAX_LENGTH");re&&typeof re.eq=="number"&&D.length>re.eq&&M(j,"length-violation",`String length ${D.length} exceeds maximum ${re.eq}`,[...Y],W)}function C(D,B,Y,j,W){R(D,B,Y,j,W);const Q=w(B,"MIN");Q&&typeof Q.eq=="number"&&D<Q.eq&&M(j,"out-of-range",`Value ${D} is less than minimum ${Q.eq}`,[...Y],W);const ne=w(B,"MAX");ne&&typeof ne.eq=="number"&&D>ne.eq&&M(j,"out-of-range",`Value ${D} exceeds maximum ${ne.eq}`,[...Y],W)}function R(D,B,Y,j,W){const Q=w(B,"ENUM");if(!Q||!Array.isArray(Q.eq))return;if(!Q.eq.some(re=>{if((0,u.isRef)(re))return!1;const he=re.eq;return he instanceof Date&&D instanceof Date?he.getTime()===D.getTime():he===D})){const re=Q.eq.filter(he=>!(0,u.isRef)(he)).map(he=>String(he.eq));M(j,"invalid-enum-value",`Value does not match any allowed enum value. Allowed: [${re.join(", ")}]`,[...Y],W)}}function P(D){if(!D.properties)return{kind:"reject"};const B=D.properties.ADDITIONAL;return B===void 0?{kind:"reject"}:(0,u.isRef)(B)?{kind:"reject"}:typeof B.eq=="string"?B.eq==="reject"?{kind:"reject"}:B.eq==="accept"?{kind:"accept"}:{kind:"type",typeName:B.eq}:B.properties&&Object.keys(B.properties).some(j=>j==="VALUE"||j==="REQUIRED"||j==="OPTIONAL"||j==="ADDITIONAL"||j==="ONEOF")?{kind:"inline",constraint:B}:{kind:"accept"}}function N(D,B,Y,j,W,Q){const ne=w(B,"REQUIRED")?.properties,re=w(B,"OPTIONAL")?.properties,he=P(B),Ae=D.properties;if(ne)for(const[_e,pe]of Object.entries(ne)){if((0,u.isRef)(pe))continue;const ge=[...j,_e],Ve=Ae?.[_e];Ve===void 0?M(W,"missing-required",`Missing required property "${_e}"`,ge,D):ye(Ve,pe,Y,ge,W,Q)}if(re&&Ae)for(const[_e,pe]of Object.entries(re)){if((0,u.isRef)(pe))continue;const ge=Ae[_e];ge!==void 0&&ye(ge,pe,Y,[...j,_e],W,Q)}if(Ae){const _e=new Set;if(ne)for(const pe of Object.keys(ne))_e.add(pe);if(re)for(const pe of Object.keys(re))_e.add(pe);for(const pe of Object.keys(Ae)){if(_e.has(pe))continue;const ge=[...j,pe];switch(he.kind){case"reject":{const Ve=Ae[pe];M(W,"unknown-property",`Unknown property "${pe}"`,ge,(0,u.isRef)(Ve)?void 0:Ve);break}case"accept":break;case"type":ye(Ae[pe],{eq:he.typeName},Y,ge,W,Q);break;case"inline":{const Ve=Ae[pe];(0,u.isRef)(Ve)?M(W,"wrong-type","Expected a value but found a link",ge):E(Ve,he.constraint,Y,ge,W,Q+1);break}}}}ve(ne,re,Ae,j,W),$e(ne,re,Ae,j,W)}function ye(D,B,Y,j,W,Q){if((0,u.isRef)(D)){M(W,"wrong-type","Expected a value but found a link",[...j]);return}const ne=typeof B.eq=="string"?B.eq:void 0;if(ne){Se(D,ne,Y,j,W,Q);return}E(D,B,Y,j,W,Q+1)}function Se(D,B,Y,j,W,Q){if(B.endsWith("[]")){Ee(D,B.slice(0,-2),Y,j,W,Q);return}const ne=Y[B];if(!ne){M(W,"invalid-schema",`Unknown type "${B}" in schema`,[...j],D);return}if(Array.isArray(ne.eq)){xe(D,ne.eq,Y,j,W,Q);return}E(D,ne,Y,j,W,Q+1)}function Ee(D,B,Y,j,W,Q){if(!Array.isArray(D.eq)){M(W,"wrong-type",`Expected ${B}[], got ${G(D.eq)}`,[...j],D);return}for(let ne=0;ne<D.eq.length;ne++){const re=[...j,`[${ne}]`],he=D.eq[ne];(0,u.isRef)(he)?M(W,"wrong-type",`Expected ${B}, got reference`,re):Se(he,B,Y,re,W,Q)}}function xe(D,B,Y,j,W,Q){const ne=[];let re,he;for(const _e of B){if((0,u.isRef)(_e))continue;const pe=typeof _e.eq=="string"?_e.eq:void 0;if(!pe)continue;ne.push(pe);const ge=[];if(Se(D,pe,Y,j,ge,Q),ge.length===0)return;(!re||ge.length<re.length)&&(re=ge,he=pe)}let Ae=`Value does not match any type in oneOf: [${ne.join(", ")}]`;if(re&&re.length>0&&ne.length>1){const _e=re.map(pe=>pe.message).join("; ");Ae+=`. Closest match "${he}": ${_e}`}M(W,"wrong-type",Ae,[...j],D)}function ve(D,B,Y,j,W){if(!Y)return;const Q={};function ne(re){if(re)for(const[he,Ae]of Object.entries(re)){if((0,u.isRef)(Ae))continue;const _e=w(Ae,"EXCLUSIVE");if(!_e)continue;let pe;if(typeof _e.eq=="string")pe=[_e.eq];else if(Array.isArray(_e.eq))pe=_e.eq.filter(ge=>!(0,u.isRef)(ge)).map(ge=>String(ge.eq));else continue;for(const ge of pe)Q[ge]||(Q[ge]=[]),Q[ge].push(he)}}ne(D),ne(B);for(const[re,he]of Object.entries(Q)){const Ae=he.filter(_e=>Y[_e]!==void 0);Ae.length>1&&M(W,"exclusive-violation",`Properties [${Ae.join(", ")}] are mutually exclusive (group "${re}")`,[...j])}}function $e(D,B,Y,j,W){if(!Y)return;function Q(ne){if(ne)for(const[re,he]of Object.entries(ne)){if((0,u.isRef)(he)||Y[re]===void 0)continue;const Ae=w(he,"REQUIRES");if(!(!Ae||!Array.isArray(Ae.eq)))for(const _e of Ae.eq){if((0,u.isRef)(_e))continue;const pe=typeof _e.eq=="string"?_e.eq:void 0;pe&&Y[pe]===void 0&&M(W,"requires-violation",`Property "${re}" requires "${pe}" to be present`,[...j,re])}}}Q(D),Q(B)}return Gt}var zr;function Bi(){if(zr)return yt;zr=1,Object.defineProperty(yt,"__esModule",{value:!0}),yt.MOTLYSchema=yt.MOTLYResult=yt.MOTLYSession=void 0;const u=ji(),M=Ui(),z=Qi(),V=_n(),g=wn();class l{constructor(e){this.accumulated=[],this.nextParseId=0,this.finished=!1,this.disposed=!1,this.options=e??{}}parse(e){if(this.ensureAlive(),this.finished)throw new Error("MOTLYSession is spent after finish() — create a new session");const w=this.nextParseId++;try{const E=(0,u.parse)(e);return this.accumulated.push({stmts:E,parseId:w}),{parseId:w,errors:[]}}catch(E){if(s(E))return{parseId:w,errors:[E]};throw E}}finish(){if(this.ensureAlive(),this.finished)throw new Error("finish() has already been called on this session");this.finished=!0;const e=[],w={},E=[];for(const{stmts:R,parseId:P}of this.accumulated){const N={parseId:P,options:{disableReferences:this.options.disableReferences}};E.push(...(0,M.flatten)(R,N))}const{splits:x,deps:G}=(0,M.chunk)(E),{order:oe}=(0,M.topoSort)(G),C=(0,M.executeChunked)(E,x,oe,w,this.options);if(e.push(...C),!this.options.disableReferences){const R=(0,z.validateReferences)(w);for(const P of R)e.push({code:P.code,message:P.message,begin:{line:0,column:0,offset:0},end:{line:0,column:0,offset:0}})}return new f(w,e)}dispose(){this.disposed=!0}ensureAlive(){if(this.disposed)throw new Error("MOTLYSession has been disposed")}}yt.MOTLYSession=l;class f{constructor(e,w){this.value=e,this.errors=w}getValue(){return(0,V.cloneNode)(this.value)}getMot(e){const w=this.getValue();return(0,g.buildMot)(w,e)}}yt.MOTLYResult=f;class c{constructor(e){this.tree=e}static parse(e){const w={disableReferences:!0},E={parseId:0,options:w};try{const x=(0,u.parse)(e),G={},oe=(0,M.flatten)(x,E),{splits:C,deps:R}=(0,M.chunk)(oe),{order:P}=(0,M.topoSort)(R),N=(0,M.executeChunked)(oe,C,P,G,w);return{schema:new c(G),errors:N}}catch(x){if(s(x))return{schema:new c({}),errors:[x]};throw x}}validate(e){return(0,z.validateSchema)(e,this.tree)}}yt.MOTLYSchema=c;function s(d){return typeof d=="object"&&d!==null&&"code"in d&&"message"in d&&"begin"in d&&"end"in d}return yt}var Yr;function Wi(){return Yr||(Yr=1,(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.MOTLYSchema=u.MOTLYResult=u.MOTLYSession=u.MotValue=u.Mot=u.formatRef=u.isEnvRef=u.isDataNode=u.isRef=void 0;var M=Jt();Object.defineProperty(u,"isRef",{enumerable:!0,get:function(){return M.isRef}}),Object.defineProperty(u,"isDataNode",{enumerable:!0,get:function(){return M.isDataNode}}),Object.defineProperty(u,"isEnvRef",{enumerable:!0,get:function(){return M.isEnvRef}}),Object.defineProperty(u,"formatRef",{enumerable:!0,get:function(){return M.formatRef}});var z=wn();Object.defineProperty(u,"Mot",{enumerable:!0,get:function(){return z.Mot}}),Object.defineProperty(u,"MotValue",{enumerable:!0,get:function(){return z.MotValue}});var V=Bi();Object.defineProperty(u,"MOTLYSession",{enumerable:!0,get:function(){return V.MOTLYSession}}),Object.defineProperty(u,"MOTLYResult",{enumerable:!0,get:function(){return V.MOTLYResult}}),Object.defineProperty(u,"MOTLYSchema",{enumerable:!0,get:function(){return V.MOTLYSchema}})})(kr)),kr}var Kr;function Gi(){if(Kr)return Ft;Kr=1;var u={};Object.defineProperty(Ft,"__esModule",{value:!0}),Ft.TagParser=void 0,Ft.parseTag=s,Ft.parseAnnotation=d;const M=Wi(),z=vn();function V(e){const w=e.search(/[ \n]/);return w>0?e.slice(w):""}function g(e){return{code:e.code,message:e.message,line:e.begin.line,offset:e.begin.column}}function l(e,w){const E=w.get(e.parseId);if(E)return{url:E.url,range:{start:{line:E.startLine+e.begin.line,character:e.begin.line===0?E.startColumn+e.begin.column:e.begin.column},end:{line:E.startLine+e.end.line,character:e.end.line===0?E.startColumn+e.end.column:e.end.column}}}}function f(e,w,E){if((0,M.isRef)(e))return new z.Tag({deleted:!0},w);const x=new z.Tag({},w);if(e.location&&E&&(x.location=l(e.location,E)),e.eq!==void 0)if(Array.isArray(e.eq))x.eq=e.eq.map(G=>f(G,x,E));else if((0,M.isEnvRef)(e.eq)){const G=u[e.eq.env];G!==void 0&&(x.eq=G)}else e.eq instanceof Date?x.eq=new Date(e.eq):x.eq=e.eq;if(e.properties!==void 0){x.properties={};for(const[G,oe]of Object.entries(e.properties))x.properties[G]=f(oe,x,E)}return e.deleted&&(x.deleted=!0),x}class c{constructor(){this.origins=new Map,this.session=new M.MOTLYSession}parse(w,E){return this.parseSource(w,0,E)}parseAnnotation(w,E){const x=V(w),G=w.length-x.length;return this.parseSource(x,G,E)}parseSource(w,E,x){const{parseId:G,errors:oe}=this.session.parse(w);x&&this.origins.set(G,{url:x.url,startLine:x.startLine,startColumn:x.startColumn+E});const C=oe.map(g);return{tag:new z.Tag,log:C}}finish(){const E=this.session.finish().getValue();return this.session.dispose(),f(E,void 0,this.origins)}}Ft.TagParser=c;function s(e){const w=new c;if(typeof e=="string"){const{log:x}=w.parse(e);return{tag:w.finish(),log:x}}const E=[];for(let x=0;x<e.length;x++){const G=w.parse(e[x]);for(const oe of G.log)E.push({...oe,line:x+oe.line})}return{tag:w.finish(),log:E}}function d(e){const w=new c;if(typeof e=="string"){const{log:x}=w.parseAnnotation(e);return{tag:w.finish(),log:x}}const E=[];for(let x=0;x<e.length;x++){const G=w.parseAnnotation(e[x]);for(const oe of G.log)E.push({...oe,line:x+oe.line})}return{tag:w.finish(),log:E}}return Ft}var sr={},Hr;function zi(){if(Hr)return sr;Hr=1,Object.defineProperty(sr,"__esModule",{value:!0}),sr.parseString=M;var u;(function(z){z[z.Normal=0]="Normal",z[z.ReverseVirgule=1]="ReverseVirgule",z[z.Unicode=2]="Unicode"})(u||(u={}));function M(z,V=""){let g=z.slice(V.length),l=u.Normal;V.length&&(g=g.slice(0,-V.length));let f="",c="";for(const s of g)switch(l){case u.Normal:{s==="\\"?l=u.ReverseVirgule:f+=s;break}case u.ReverseVirgule:{let d=s;if(s==="u"){l=u.Unicode,c="";continue}s==="b"?d="\b":s==="f"?d="\f":s==="n"?d=`
|
|
23
|
+
`:s==="r"?d="\r":s==="t"&&(d=" "),f+=d,l=u.Normal;break}case u.Unicode:"ABCDEFabcdef0123456789".includes(s)?(c+=s,c.length===4&&(f+=String.fromCharCode(parseInt(c,16)),l=u.Normal)):l=u.Normal}return f}return sr}var Jr;function Yi(){return Jr||(Jr=1,(function(u){var M=pt&&pt.__createBinding||(Object.create?(function(f,c,s,d){d===void 0&&(d=s);var e=Object.getOwnPropertyDescriptor(c,s);(!e||("get"in e?!c.__esModule:e.writable||e.configurable))&&(e={enumerable:!0,get:function(){return c[s]}}),Object.defineProperty(f,d,e)}):(function(f,c,s,d){d===void 0&&(d=s),f[d]=c[s]})),z=pt&&pt.__setModuleDefault||(Object.create?(function(f,c){Object.defineProperty(f,"default",{enumerable:!0,value:c})}):function(f,c){f.default=c}),V=pt&&pt.__exportStar||function(f,c){for(var s in f)s!=="default"&&!Object.prototype.hasOwnProperty.call(c,s)&&M(c,f,s)},g=pt&&pt.__importStar||(function(){var f=function(c){return f=Object.getOwnPropertyNames||function(s){var d=[];for(var e in s)Object.prototype.hasOwnProperty.call(s,e)&&(d[d.length]=e);return d},f(c)};return function(c){if(c&&c.__esModule)return c;var s={};if(c!=null)for(var d=f(c),e=0;e<d.length;e++)d[e]!=="default"&&M(s,c,d[e]);return z(s,c),s}})();Object.defineProperty(u,"__esModule",{value:!0}),u.ParseUtil=u.TagParser=u.parseAnnotation=u.parseTag=void 0,V(vn(),u);var l=Gi();Object.defineProperty(u,"parseTag",{enumerable:!0,get:function(){return l.parseTag}}),Object.defineProperty(u,"parseAnnotation",{enumerable:!0,get:function(){return l.parseAnnotation}}),Object.defineProperty(u,"TagParser",{enumerable:!0,get:function(){return l.TagParser}}),u.ParseUtil=g(zi())})(pt)),pt}var Pt={},dt={},Xr;function Nt(){if(Xr)return dt;Xr=1,Object.defineProperty(dt,"__esModule",{value:!0}),dt.isChainOp=u,dt.isStringCondition=M,dt.isStringFilter=z,dt.isBooleanFilter=V,dt.isNumberFilter=g,dt.isTemporalFilter=l,dt.isFilterExpression=f,dt.isFilterable=c;function u(s){return["and","or",","].includes(s)}function M(s){return["starts","ends","contains","="].includes(s.operator)}function z(s){return typeof s=="object"&&s!==null&&"operator"in s&&typeof s.operator=="string"&&["starts","ends","contains","=","~","null","empty","and","or",",","()"].includes(s.operator)}function V(s){return typeof s=="object"&&s!==null&&"operator"in s&&typeof s.operator=="string"&&["null","true","false","=false","=true"].includes(s.operator)}function g(s){return typeof s=="object"&&s!==null&&"operator"in s&&typeof s.operator=="string"&&["range","<=",">=","!=","=",">","<","and","or","()","null"].includes(s.operator)}function l(s){return typeof s=="object"&&s!==null&&"operator"in s&&typeof s.operator=="string"&&["literal","before","after","to","for","in","and","or","in_last","this","last","next","()","null"].includes(s.operator)}function f(s){return typeof s=="object"&&s!==null&&"operator"in s}function c(s){return["string","number","boolean","timestamp","timestamptz","date"].includes(s)}return dt}var zt={},Zr;function Ki(){return Zr||(Zr=1,Object.defineProperty(zt,"__esModule",{value:!0}),zt.BooleanFilterExpression=void 0,zt.BooleanFilterExpression={parse(u){var M;if(u.match(/^\s*$/))return{parsed:null,log:[]};const z={parsed:null,log:[]};let V=u.toLowerCase().trim().replace(/\s\s+/," "),g=!1;if(V.startsWith("not ")&&(g=!0,V=V.slice(4)),V==="true")z.parsed={operator:"true"};else if(V==="=true")z.parsed={operator:"=true"};else if(V==="false")z.parsed={operator:"false"};else if(V==="=false")z.parsed={operator:"=false"};else if(V==="null")z.parsed={operator:"null"};else{const l=u.match(/[^\s]/),f=l&&(M=l.index)!==null&&M!==void 0?M:0;z.log=[{message:`Illegal boolean filter '${V}'. Must be one of true,=true,false,=false,null`,severity:"error",startIndex:f,endIndex:f+u.length-1}]}return g&&z.parsed&&(z.parsed.not=!0),z},unparse(u){return u===null?"":(u.not?"not ":"")+u.operator}}),zt}var Sr={},ot={},en;function lr(){if(en)return ot;en=1,Object.defineProperty(ot,"__esModule",{value:!0}),ot.maybeNot=M,ot.unescape=z,ot.escape=V,ot.matchOp=l,ot.conjoin=c,ot.joinNumbers=s,ot.mkRange=d,ot.mkValues=e,ot.numNot=w,ot.temporalNot=E,ot.joinTemporal=x,ot.timeLiteral=G,ot.mkUnits=oe;const u=Nt();function M(C){const[R,P]=C;return R&&P&&(0,u.isStringFilter)(P)?{...P,not:!0}:P}function z(C){return C.replace(/\\(.)/g,"$1")}function V(C){const R=C.toLowerCase();return R==="null"||R==="empty"?"\\"+C:C.replace(/([,; |()\\%_-])/g,"\\$1")}function g(C){let R=!1,P=!1,N=0,ye=!1;const Se=C.length;for(let Ee=0;Ee<Se;Ee+=1){const xe=C[Ee];if(xe===" "||xe===" "){N+=1;continue}N=0,xe==="%"?(ye=!0,Ee===0&&(R=!0),P=!0):(P=!1,xe==="\\"?Ee+=1:xe==="_"&&(ye=!0))}return{hasLike:ye,percentEnd:P&&Se>1,percentStart:R&&Se>1,endSpace:N}}function l(C){let R=C.trimStart();const{hasLike:P,percentEnd:N,percentStart:ye,endSpace:Se}=g(R);if(Se>0&&(R=R.slice(0,-Se)),P){if(ye&&N){const Ee=R.slice(1,-1);if(!g(Ee).hasLike&&Ee.length>0)return{operator:"contains",values:[z(Ee)]}}else if(N){const Ee=R.slice(0,-1);if(!g(Ee).hasLike)return{operator:"starts",values:[z(Ee)]}}else if(ye){const Ee=R.slice(1);if(!g(Ee).hasLike)return{operator:"ends",values:[z(Ee)]}}return{operator:"~",escaped_values:[R]}}return R.toLowerCase()==="null"?{operator:"null"}:R.toLowerCase()==="empty"?{operator:"empty"}:{operator:"=",values:[z(R)]}}function f(C,R){var P,N;return C.operator===R.operator&&((P=C.not)!==null&&P!==void 0?P:!1)===((N=R.not)!==null&&N!==void 0?N:!1)}function c(C,R,P){if(R=R.toLowerCase(),(0,u.isStringFilter)(C)&&(0,u.isStringFilter)(P)){if(R===","){if(C.operator==="~"&&f(C,P))return{...C,escaped_values:[...C.escaped_values,...P.escaped_values]};if((0,u.isStringCondition)(C)&&f(C,P))return{...C,values:[...C.values,...P.values]}}const N=R===","?",":R==="|"?"or":R===";"?"and":void 0;if(N)return C.operator===N?{...C,members:[...C.members,P]}:{operator:N,members:[C,P]}}return null}function s(C,R,P){if(R=R.toLowerCase(),(0,u.isNumberFilter)(C)&&(0,u.isNumberFilter)(P)){if(R==="or"&&C.operator==="="&&f(C,P)){const N={operator:"=",values:[...C.values,...P.values]};return C.not&&(N.not=!0),N}if(R==="and"||R==="or")return C.operator===R?{...C,members:[...C.members,P]}:{operator:R,members:[C,P]}}return null}function d(C,R,P,N){return{operator:"range",startValue:R,startOperator:C==="("?">":">=",endValue:P,endOperator:N===")"?"<":"<="}}function e(C,R){return{values:[C,...R]}}function w(C,R){return(0,u.isNumberFilter)(C)&&R?C.operator==="="?{operator:"!=",values:C.values}:C.operator==="!="?{operator:"=",values:C.values}:{...C,not:!0}:C}function E(C,R){if((0,u.isTemporalFilter)(C)&&R){if("not"in C){const P={...C};return C.not?delete P.not:P.not=!0,P}return{...C,not:!0}}return C}function x(C,R,P){return R=R.toLowerCase(),(0,u.isTemporalFilter)(C)&&(0,u.isTemporalFilter)(P)&&(R==="and"||R==="or")?C.operator===R?{...C,members:[...C.members,P]}:{operator:R,members:[C,P]}:null}function G(C,R){const P={moment:"literal",literal:C};return R&&(P.units=R),P}function oe(C){switch(C.toLowerCase()){case"second":case"seconds":return"second";case"minute":case"minutes":return"minute";case"hour":case"hours":return"hour";case"day":case"days":return"day";case"week":case"weeks":return"week";case"month":case"months":return"month";case"quarter":case"quarters":return"quarter";case"year":case"years":return"year"}}return ot}var Er,tn;function Hi(){if(tn)return Er;tn=1;const{numNot:u,mkRange:M,joinNumbers:z,mkValues:V}=lr();function g(s,d){function e(){this.constructor=s}e.prototype=d.prototype,s.prototype=new e}function l(s,d,e,w){var E=Error.call(this,s);return Object.setPrototypeOf&&Object.setPrototypeOf(E,l.prototype),E.expected=d,E.found=e,E.location=w,E.name="SyntaxError",E}g(l,Error);function f(s,d,e){return e=e||" ",s.length>d?s:(d-=s.length,e+=e.repeat(d),s+e.slice(0,d))}l.prototype.format=function(s){var d="Error: "+this.message;if(this.location){var e=null,w;for(w=0;w<s.length;w++)if(s[w].source===this.location.source){e=s[w].text.split(/\r\n|\n|\r/g);break}var E=this.location.start,x=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(E):E,G=this.location.source+":"+x.line+":"+x.column;if(e){var oe=this.location.end,C=f("",x.line.toString().length," "),R=e[E.line-1],P=E.line===oe.line?oe.column:R.length+1,N=P-E.column||1;d+=`
|
|
24
|
+
--> `+G+`
|
|
25
|
+
`+C+` |
|
|
26
|
+
`+x.line+" | "+R+`
|
|
27
|
+
`+C+" | "+f("",E.column-1," ")+f("",N,"^")}else d+=`
|
|
28
|
+
at `+G}return d},l.buildMessage=function(s,d){var e={literal:function(R){return'"'+E(R.text)+'"'},class:function(R){var P=R.parts.map(function(N){return Array.isArray(N)?x(N[0])+"-"+x(N[1]):x(N)});return"["+(R.inverted?"^":"")+P.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(R){return R.description}};function w(R){return R.charCodeAt(0).toString(16).toUpperCase()}function E(R){return R.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(P){return"\\x0"+w(P)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(P){return"\\x"+w(P)})}function x(R){return R.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(P){return"\\x0"+w(P)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(P){return"\\x"+w(P)})}function G(R){return e[R.type](R)}function oe(R){var P=R.map(G),N,ye;if(P.sort(),P.length>0){for(N=1,ye=1;N<P.length;N++)P[N-1]!==P[N]&&(P[ye]=P[N],ye++);P.length=ye}switch(P.length){case 1:return P[0];case 2:return P[0]+" or "+P[1];default:return P.slice(0,-1).join(", ")+", or "+P[P.length-1]}}function C(R){return R?'"'+E(R)+'"':"end of input"}return"Expected "+oe(s)+" but "+C(d)+" found."};function c(s,d){d=d!==void 0?d:{};var e={},w=d.grammarSource,E={numberFilter:Mt},x=Mt,G="(",oe=")",C="!=",R=",",P="=",N="<=",ye=">=",Se="[",Ee="]",xe="-",ve=".",$e="not",D="null",B="and",Y="or",j="to",W=/^[<>]/,Q=/^[0-9]/,ne=/^[Ee]/,re=/^[+\-]/,he=/^[a-zA-Z]/,Ae=/^[ \t]/,_e=Ke("(",!1),pe=Ke(")",!1),ge=Ke("!=",!1),Ve=Ke(",",!1),tt=Ke("=",!1),at=Ke("<=",!1),it=Ke(">=",!1),X=_t(["<",">"],!1,!1),$=Ke("[",!1),p=Ke("]",!1),v=Ke("-",!1),m=_t([["0","9"]],!1,!1),b=Ke(".",!1),A=_t(["E","e"],!1,!1),L=_t(["+","-"],!1,!1),U=Ke("not",!0),K=Ke("null",!0),F=Ke("and",!0),H=Ke("or",!0),ae=Ke("to",!0),le=_t([["a","z"],["A","Z"]],!1,!1),Fe=ur("whitespace"),Ue=_t([" "," "],!1,!1),rt=function(S,q){return q.reduce((ee,[,se,,be])=>z(ee,se,be),S)},Ne=function(S,q){return u(q,S)},ze=function(S){return S},He=function(){return{operator:"null"}},Je=function(S){return{operator:"()",expr:S}},O=function(S,q,ee,se){return M(S,q,ee,se)},te=function(S,q){return{operator:"!=",...V(S,q.map(ee=>ee[3]))}},Re=function(S,q){return{operator:"=",...V(S,q.map(ee=>ee[3]))}},de=function(S,q){return{operator:S,values:[q]}},De=function(S,q){return{operator:"=",...V(S,q.map(ee=>ee[3]))}},Ye=function(){return"["},ut=function(){return"("},lt=function(){return"]"},kt=function(){return")"},k=function(S){return S},t=function(){return"or"},a=function(){return"and"},y=function(){return"not"},h=d.peg$currPos|0,J=[{line:1,column:1}],me=h,Le=d.peg$maxFailExpected||[],Z=d.peg$silentFails|0,Me;if(d.startRule){if(!(d.startRule in E))throw new Error(`Can't start parsing from rule "`+d.startRule+'".');x=E[d.startRule]}function Ke(S,q){return{type:"literal",text:S,ignoreCase:q}}function _t(S,q,ee){return{type:"class",parts:S,inverted:q,ignoreCase:ee}}function fr(){return{type:"end"}}function ur(S){return{type:"other",description:S}}function Xt(S){var q=J[S],ee;if(q)return q;if(S>=J.length)ee=J.length-1;else for(ee=S;!J[--ee];);for(q=J[ee],q={line:q.line,column:q.column};ee<S;)s.charCodeAt(ee)===10?(q.line++,q.column=1):q.column++,ee++;return J[S]=q,q}function Zt(S,q,ee){var se=Xt(S),be=Xt(q),ie={source:w,start:{offset:S,line:se.line,column:se.column},end:{offset:q,line:be.line,column:be.column}};return ie}function ke(S){h<me||(h>me&&(me=h,Le=[]),Le.push(S))}function cr(S,q,ee){return new l(l.buildMessage(S,q),S,q,ee)}function Mt(){var S,q,ee,se,be,ie,ue,we;if(S=h,q=jt(),q!==e){for(ee=[],se=h,be=je(),ie=tr(),ie!==e?(ue=je(),we=jt(),we!==e?(be=[be,ie,ue,we],se=be):(h=se,se=e)):(h=se,se=e);se!==e;)ee.push(se),se=h,be=je(),ie=tr(),ie!==e?(ue=je(),we=jt(),we!==e?(be=[be,ie,ue,we],se=be):(h=se,se=e)):(h=se,se=e);S=rt(q,ee)}else h=S,S=e;return S}function jt(){var S,q,ee;return S=h,q=hr(),q!==e?(je(),ee=er(),ee!==e?S=Ne(q,ee):(h=S,S=e)):(h=S,S=e),S===e&&(S=h,q=er(),q!==e&&(q=ze(q)),S=q),S}function er(){var S,q,ee,se,be,ie,ue,we,Ie,Qe;if(S=h,q=gr(),q!==e&&(q=He()),S=q,S===e&&(S=h,s.charCodeAt(h)===40?(q=G,h++):(q=e,Z===0&&ke(_e)),q!==e?(ee=je(),se=Mt(),se!==e?(be=je(),s.charCodeAt(h)===41?(ie=oe,h++):(ie=e,Z===0&&ke(pe)),ie!==e?S=Je(se):(h=S,S=e)):(h=S,S=e)):(h=S,S=e),S===e&&(S=h,q=pr(),q!==e?(ee=je(),se=ft(),se!==e?(be=je(),ie=vr(),ie!==e?(ue=je(),we=ft(),we!==e?(Ie=je(),Qe=dr(),Qe!==e?S=O(q,se,we,Qe):(h=S,S=e)):(h=S,S=e)):(h=S,S=e)):(h=S,S=e)):(h=S,S=e),S===e))){if(S=h,s.substr(h,2)===C?(q=C,h+=2):(q=e,Z===0&&ke(ge)),q!==e)if(ee=je(),se=ft(),se!==e){for(be=[],ie=h,ue=je(),s.charCodeAt(h)===44?(we=R,h++):(we=e,Z===0&&ke(Ve)),we!==e?(Ie=je(),Qe=ft(),Qe!==e?(ue=[ue,we,Ie,Qe],ie=ue):(h=ie,ie=e)):(h=ie,ie=e);ie!==e;)be.push(ie),ie=h,ue=je(),s.charCodeAt(h)===44?(we=R,h++):(we=e,Z===0&&ke(Ve)),we!==e?(Ie=je(),Qe=ft(),Qe!==e?(ue=[ue,we,Ie,Qe],ie=ue):(h=ie,ie=e)):(h=ie,ie=e);S=te(se,be)}else h=S,S=e;else h=S,S=e;if(S===e){if(S=h,s.charCodeAt(h)===61?(q=P,h++):(q=e,Z===0&&ke(tt)),q!==e)if(ee=je(),se=ft(),se!==e){for(be=[],ie=h,ue=je(),s.charCodeAt(h)===44?(we=R,h++):(we=e,Z===0&&ke(Ve)),we!==e?(Ie=je(),Qe=ft(),Qe!==e?(ue=[ue,we,Ie,Qe],ie=ue):(h=ie,ie=e)):(h=ie,ie=e);ie!==e;)be.push(ie),ie=h,ue=je(),s.charCodeAt(h)===44?(we=R,h++):(we=e,Z===0&&ke(Ve)),we!==e?(Ie=je(),Qe=ft(),Qe!==e?(ue=[ue,we,Ie,Qe],ie=ue):(h=ie,ie=e)):(h=ie,ie=e);S=Re(se,be)}else h=S,S=e;else h=S,S=e;if(S===e&&(S=h,q=h,s.substr(h,2)===N?(ee=N,h+=2):(ee=e,Z===0&&ke(at)),ee===e&&(s.substr(h,2)===ye?(ee=ye,h+=2):(ee=e,Z===0&&ke(it)),ee===e&&(ee=s.charAt(h),W.test(ee)?h++:(ee=e,Z===0&&ke(X)))),ee!==e?q=s.substring(q,h):q=ee,q!==e?(ee=je(),se=ft(),se!==e?S=de(q,se):(h=S,S=e)):(h=S,S=e),S===e))if(S=h,q=ft(),q!==e){for(ee=[],se=h,be=je(),s.charCodeAt(h)===44?(ie=R,h++):(ie=e,Z===0&&ke(Ve)),ie!==e?(ue=je(),we=ft(),we!==e?(be=[be,ie,ue,we],se=be):(h=se,se=e)):(h=se,se=e);se!==e;)ee.push(se),se=h,be=je(),s.charCodeAt(h)===44?(ie=R,h++):(ie=e,Z===0&&ke(Ve)),ie!==e?(ue=je(),we=ft(),we!==e?(be=[be,ie,ue,we],se=be):(h=se,se=e)):(h=se,se=e);S=De(q,ee)}else h=S,S=e}}return S}function pr(){var S,q;return S=h,s.charCodeAt(h)===91?(q=Se,h++):(q=e,Z===0&&ke($)),q!==e&&(q=Ye()),S=q,S===e&&(S=h,s.charCodeAt(h)===40?(q=G,h++):(q=e,Z===0&&ke(_e)),q!==e&&(q=ut()),S=q),S}function dr(){var S,q;return S=h,s.charCodeAt(h)===93?(q=Ee,h++):(q=e,Z===0&&ke(p)),q!==e&&(q=lt()),S=q,S===e&&(S=h,s.charCodeAt(h)===41?(q=oe,h++):(q=e,Z===0&&ke(pe)),q!==e&&(q=kt()),S=q),S}function ft(){var S,q,ee,se,be,ie,ue,we,Ie,Qe;if(S=h,q=h,ee=h,s.charCodeAt(h)===45?(se=xe,h++):(se=e,Z===0&&ke(v)),se===e&&(se=null),be=h,ie=[],ue=s.charAt(h),Q.test(ue)?h++:(ue=e,Z===0&&ke(m)),ue!==e)for(;ue!==e;)ie.push(ue),ue=s.charAt(h),Q.test(ue)?h++:(ue=e,Z===0&&ke(m));else ie=e;if(ie!==e){for(s.charCodeAt(h)===46?(ue=ve,h++):(ue=e,Z===0&&ke(b)),ue===e&&(ue=null),we=[],Ie=s.charAt(h),Q.test(Ie)?h++:(Ie=e,Z===0&&ke(m));Ie!==e;)we.push(Ie),Ie=s.charAt(h),Q.test(Ie)?h++:(Ie=e,Z===0&&ke(m));ie=[ie,ue,we],be=ie}else h=be,be=e;if(be===e){for(be=h,ie=[],ue=s.charAt(h),Q.test(ue)?h++:(ue=e,Z===0&&ke(m));ue!==e;)ie.push(ue),ue=s.charAt(h),Q.test(ue)?h++:(ue=e,Z===0&&ke(m));if(s.charCodeAt(h)===46?(ue=ve,h++):(ue=e,Z===0&&ke(b)),ue!==e){if(we=[],Ie=s.charAt(h),Q.test(Ie)?h++:(Ie=e,Z===0&&ke(m)),Ie!==e)for(;Ie!==e;)we.push(Ie),Ie=s.charAt(h),Q.test(Ie)?h++:(Ie=e,Z===0&&ke(m));else we=e;we!==e?(ie=[ie,ue,we],be=ie):(h=be,be=e)}else h=be,be=e}if(be!==e){if(ie=h,ue=s.charAt(h),ne.test(ue)?h++:(ue=e,Z===0&&ke(A)),ue!==e){if(we=s.charAt(h),re.test(we)?h++:(we=e,Z===0&&ke(L)),we===e&&(we=null),Ie=[],Qe=s.charAt(h),Q.test(Qe)?h++:(Qe=e,Z===0&&ke(m)),Qe!==e)for(;Qe!==e;)Ie.push(Qe),Qe=s.charAt(h),Q.test(Qe)?h++:(Qe=e,Z===0&&ke(m));else Ie=e;Ie!==e?(ue=[ue,we,Ie],ie=ue):(h=ie,ie=e)}else h=ie,ie=e;ie===e&&(ie=null),se=[se,be,ie],ee=se}else h=ee,ee=e;return ee!==e?q=s.substring(q,h):q=ee,q!==e&&(q=k(q)),S=q,S}function tr(){var S,q;return S=h,q=yr(),q!==e&&(q=t()),S=q,S===e&&(S=h,q=mr(),q!==e&&(q=a()),S=q),S}function hr(){var S,q,ee,se;return S=h,q=s.substr(h,3),q.toLowerCase()===$e?h+=3:(q=e,Z===0&&ke(U)),q!==e?(ee=h,Z++,se=St(),Z--,se===e?ee=void 0:(h=ee,ee=e),ee!==e?S=y():(h=S,S=e)):(h=S,S=e),S}function gr(){var S,q,ee,se;return S=h,q=s.substr(h,4),q.toLowerCase()===D?h+=4:(q=e,Z===0&&ke(K)),q!==e?(ee=h,Z++,se=St(),Z--,se===e?ee=void 0:(h=ee,ee=e),ee!==e?(q=[q,ee],S=q):(h=S,S=e)):(h=S,S=e),S}function mr(){var S,q,ee,se;return S=h,q=s.substr(h,3),q.toLowerCase()===B?h+=3:(q=e,Z===0&&ke(F)),q!==e?(ee=h,Z++,se=St(),Z--,se===e?ee=void 0:(h=ee,ee=e),ee!==e?(q=[q,ee],S=q):(h=S,S=e)):(h=S,S=e),S}function yr(){var S,q,ee,se;return S=h,q=s.substr(h,2),q.toLowerCase()===Y?h+=2:(q=e,Z===0&&ke(H)),q!==e?(ee=h,Z++,se=St(),Z--,se===e?ee=void 0:(h=ee,ee=e),ee!==e?(q=[q,ee],S=q):(h=S,S=e)):(h=S,S=e),S}function vr(){var S,q,ee,se;return S=h,q=s.substr(h,2),q.toLowerCase()===j?h+=2:(q=e,Z===0&&ke(ae)),q!==e?(ee=h,Z++,se=St(),Z--,se===e?ee=void 0:(h=ee,ee=e),ee!==e?(q=[q,ee],S=q):(h=S,S=e)):(h=S,S=e),S}function St(){var S;return S=s.charAt(h),he.test(S)?h++:(S=e,Z===0&&ke(le)),S}function je(){var S,q;for(Z++,S=[],q=s.charAt(h),Ae.test(q)?h++:(q=e,Z===0&&ke(Ue));q!==e;)S.push(q),q=s.charAt(h),Ae.test(q)?h++:(q=e,Z===0&&ke(Ue));return Z--,q=e,Z===0&&ke(Fe),S}if(Me=x(),d.peg$library)return{peg$result:Me,peg$currPos:h,peg$FAILED:e,peg$maxFailExpected:Le,peg$maxFailPos:me};if(Me!==e&&h===s.length)return Me;throw Me!==e&&h<s.length&&ke(fr()),cr(Le,me<s.length?s.charAt(me):null,me<s.length?Zt(me,me+1):Zt(me,me))}return Er={StartRules:["numberFilter"],SyntaxError:l,parse:c},Er}var ar={},rn;function Cr(){if(rn)return ar;rn=1,Object.defineProperty(ar,"__esModule",{value:!0}),ar.run_parser=z;const u=Nt();function M(V){return V instanceof Error&&"location"in V}function z(V,g){try{const l=g(V);return(0,u.isFilterExpression)(l)?{parsed:l,log:[]}:{parsed:null,log:[]}}catch(l){if(M(l)){const f=l.location,c=f?f.start.offset:0,s=f?f.end.offset-1:V.length-1;return{parsed:null,log:[{message:l.message,startIndex:c,endIndex:Math.max(c,s),severity:"error"}]}}throw l}}return ar}var nn;function Ji(){return nn||(nn=1,(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.NumberFilterExpression=void 0;const M=Nt(),z=Hi(),V=Cr();u.NumberFilterExpression={parse(g){if(g.match(/^\s*$/))return{parsed:null,log:[]};const l=(0,V.run_parser)(g,z.parse);return l.parsed&&(0,M.isNumberFilter)(l.parsed)?{parsed:l.parsed,log:[]}:{parsed:null,log:l.log}},unparse(g){if(g===null)return"";switch(g.operator){case"=":return g.values.join(", ");case"!=":return"!= "+g.values.join(", ");case">":case"<":case"<=":case">=":return g.not?g.values.map(l=>g.operator==="="?`not ${l}`:`not ${g.operator} ${l}`).join(", "):g.values.map(l=>`${g.operator} ${l}`).join(", ");case"range":{const l=g.startOperator===">"?"(":"[",f=g.endOperator==="<"?")":"]",c=`${l}${g.startValue} to ${g.endValue}${f}`;return g.not?`not ${c}`:c}case"null":return g.not?"not null":"null";case"and":case"or":return g.members.map(l=>u.NumberFilterExpression.unparse(l)).join(` ${g.operator} `);case"()":{const l="("+u.NumberFilterExpression.unparse(g.expr)+")";return g.not?"not "+l:l}}return`no unparse for ${JSON.stringify(g)}`}}})(Sr)),Sr}var Or={},Rr,sn;function Xi(){if(sn)return Rr;sn=1;const{conjoin:u,maybeNot:M,matchOp:z}=lr();function V(c,s){function d(){this.constructor=c}d.prototype=s.prototype,c.prototype=new d}function g(c,s,d,e){var w=Error.call(this,c);return Object.setPrototypeOf&&Object.setPrototypeOf(w,g.prototype),w.expected=s,w.found=d,w.location=e,w.name="SyntaxError",w}V(g,Error);function l(c,s,d){return d=d||" ",c.length>s?c:(s-=c.length,d+=d.repeat(s),c+d.slice(0,s))}g.prototype.format=function(c){var s="Error: "+this.message;if(this.location){var d=null,e;for(e=0;e<c.length;e++)if(c[e].source===this.location.source){d=c[e].text.split(/\r\n|\n|\r/g);break}var w=this.location.start,E=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(w):w,x=this.location.source+":"+E.line+":"+E.column;if(d){var G=this.location.end,oe=l("",E.line.toString().length," "),C=d[w.line-1],R=w.line===G.line?G.column:C.length+1,P=R-w.column||1;s+=`
|
|
29
|
+
--> `+x+`
|
|
30
|
+
`+oe+` |
|
|
31
|
+
`+E.line+" | "+C+`
|
|
32
|
+
`+oe+" | "+l("",w.column-1," ")+l("",P,"^")}else s+=`
|
|
33
|
+
at `+x}return s},g.buildMessage=function(c,s){var d={literal:function(C){return'"'+w(C.text)+'"'},class:function(C){var R=C.parts.map(function(P){return Array.isArray(P)?E(P[0])+"-"+E(P[1]):E(P)});return"["+(C.inverted?"^":"")+R.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(C){return C.description}};function e(C){return C.charCodeAt(0).toString(16).toUpperCase()}function w(C){return C.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(R){return"\\x0"+e(R)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(R){return"\\x"+e(R)})}function E(C){return C.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(R){return"\\x0"+e(R)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(R){return"\\x"+e(R)})}function x(C){return d[C.type](C)}function G(C){var R=C.map(x),P,N;if(R.sort(),R.length>0){for(P=1,N=1;P<R.length;P++)R[P-1]!==R[P]&&(R[N]=R[P],N++);R.length=N}switch(R.length){case 1:return R[0];case 2:return R[0]+" or "+R[1];default:return R.slice(0,-1).join(", ")+", or "+R[R.length-1]}}function oe(C){return C?'"'+w(C)+'"':"end of input"}return"Expected "+G(c)+" but "+oe(s)+" found."};function f(c,s){s=s!==void 0?s:{};var d={},e=s.grammarSource,w={stringFilter:Ue},E=Ue,x="-",G="(",oe=")",C="\\",R=",",P=";",N="|",ye=/^[^\n,;()|]/,Se=/^[ \t]/,Ee=A("-",!1),xe=A("(",!1),ve=A(")",!1),$e=F("match string"),D=A("\\",!1),B=U(),Y=L([`
|
|
34
|
+
`,",",";","(",")","|"],!0,!1),j=A(",",!1),W=A(";",!1),Q=A("|",!1),ne=F("whitespace"),re=L([" "," "],!1,!1),he=function(O,te){return te.reduce((Re,[,de,,De])=>u(Re,de,De),O)},Ae=function(O){return M([!0,O])},_e=function(O){return O},pe=function(O){return{operator:"()",expr:O}},ge=function(O){return z(O)},Ve=function(O){return O},tt=function(){return","},at=function(){return";"},it=function(){return"|"},X=s.peg$currPos|0,$=[{line:1,column:1}],p=X,v=s.peg$maxFailExpected||[],m=s.peg$silentFails|0,b;if(s.startRule){if(!(s.startRule in w))throw new Error(`Can't start parsing from rule "`+s.startRule+'".');E=w[s.startRule]}function A(O,te){return{type:"literal",text:O,ignoreCase:te}}function L(O,te,Re){return{type:"class",parts:O,inverted:te,ignoreCase:Re}}function U(){return{type:"any"}}function K(){return{type:"end"}}function F(O){return{type:"other",description:O}}function H(O){var te=$[O],Re;if(te)return te;if(O>=$.length)Re=$.length-1;else for(Re=O;!$[--Re];);for(te=$[Re],te={line:te.line,column:te.column};Re<O;)c.charCodeAt(Re)===10?(te.line++,te.column=1):te.column++,Re++;return $[O]=te,te}function ae(O,te,Re){var de=H(O),De=H(te),Ye={source:e,start:{offset:O,line:de.line,column:de.column},end:{offset:te,line:De.line,column:De.column}};return Ye}function le(O){X<p||(X>p&&(p=X,v=[]),v.push(O))}function Fe(O,te,Re){return new g(g.buildMessage(O,te),O,te,Re)}function Ue(){var O,te,Re,de,De,Ye,ut,lt;if(O=X,Je(),te=rt(),te!==d){for(Re=[],de=X,De=Je(),Ye=He(),Ye!==d?(ut=Je(),lt=rt(),lt!==d?(De=[De,Ye,ut,lt],de=De):(X=de,de=d)):(X=de,de=d);de!==d;)Re.push(de),de=X,De=Je(),Ye=He(),Ye!==d?(ut=Je(),lt=rt(),lt!==d?(De=[De,Ye,ut,lt],de=De):(X=de,de=d)):(X=de,de=d);O=he(te,Re)}else X=O,O=d;return O}function rt(){var O,te,Re;return O=X,c.charCodeAt(X)===45?(te=x,X++):(te=d,m===0&&le(Ee)),te!==d?(Je(),Re=Ne(),Re!==d?O=Ae(Re):(X=O,O=d)):(X=O,O=d),O===d&&(O=X,te=Ne(),te!==d&&(te=_e(te)),O=te),O}function Ne(){var O,te,Re,de;return O=X,c.charCodeAt(X)===40?(te=G,X++):(te=d,m===0&&le(xe)),te!==d?(Je(),Re=Ue(),Re!==d?(Je(),c.charCodeAt(X)===41?(de=oe,X++):(de=d,m===0&&le(ve)),de!==d?O=pe(Re):(X=O,O=d)):(X=O,O=d)):(X=O,O=d),O===d&&(O=X,te=ze(),te!==d&&(te=ge(te)),O=te),O}function ze(){var O,te,Re,de,De,Ye;if(m++,O=X,te=X,Re=[],de=X,c.charCodeAt(X)===92?(De=C,X++):(De=d,m===0&&le(D)),De!==d?(c.length>X?(Ye=c.charAt(X),X++):(Ye=d,m===0&&le(B)),Ye!==d?(De=[De,Ye],de=De):(X=de,de=d)):(X=de,de=d),de===d&&(de=c.charAt(X),ye.test(de)?X++:(de=d,m===0&&le(Y))),de!==d)for(;de!==d;)Re.push(de),de=X,c.charCodeAt(X)===92?(De=C,X++):(De=d,m===0&&le(D)),De!==d?(c.length>X?(Ye=c.charAt(X),X++):(Ye=d,m===0&&le(B)),Ye!==d?(De=[De,Ye],de=De):(X=de,de=d)):(X=de,de=d),de===d&&(de=c.charAt(X),ye.test(de)?X++:(de=d,m===0&&le(Y)));else Re=d;return Re!==d?te=c.substring(te,X):te=Re,te!==d&&(te=Ve(te)),O=te,m--,O===d&&(te=d,m===0&&le($e)),O}function He(){var O,te;return O=X,c.charCodeAt(X)===44?(te=R,X++):(te=d,m===0&&le(j)),te!==d&&(te=tt()),O=te,O===d&&(O=X,c.charCodeAt(X)===59?(te=P,X++):(te=d,m===0&&le(W)),te!==d&&(te=at()),O=te,O===d&&(O=X,c.charCodeAt(X)===124?(te=N,X++):(te=d,m===0&&le(Q)),te!==d&&(te=it()),O=te)),O}function Je(){var O,te;for(m++,O=[],te=c.charAt(X),Se.test(te)?X++:(te=d,m===0&&le(re));te!==d;)O.push(te),te=c.charAt(X),Se.test(te)?X++:(te=d,m===0&&le(re));return m--,te=d,m===0&&le(ne),O}if(b=E(),s.peg$library)return{peg$result:b,peg$currPos:X,peg$FAILED:d,peg$maxFailExpected:v,peg$maxFailPos:p};if(b!==d&&X===c.length)return b;throw b!==d&&X<c.length&&le(K()),Fe(v,p<c.length?c.charAt(p):null,p<c.length?ae(p,p+1):ae(p,p))}return Rr={StartRules:["stringFilter"],SyntaxError:g,parse:f},Rr}var an;function Zi(){return an||(an=1,(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.StringFilterExpression=void 0;const M=Nt(),z=Xi(),V=lr(),g=Cr();u.StringFilterExpression={parse(l){if(l.match(/^\s*$/))return{parsed:null,log:[]};const f=(0,g.run_parser)(l,z.parse);return f.parsed&&(0,M.isStringFilter)(f.parsed)?{parsed:f.parsed,log:[]}:{parsed:null,log:f.log}},unparse(l){if(l===null)return"";switch(l.operator){case"=":return l.not?l.values.map(f=>"-"+(0,V.escape)(f)).join(", "):l.values.map(f=>(0,V.escape)(f)).join(", ");case"~":return l.not?l.escaped_values.map(f=>"-"+f).join(", "):l.escaped_values.join(", ");case"starts":return l.not?l.values.map(f=>"-"+(0,V.escape)(f)+"%").join(", "):l.values.map(f=>(0,V.escape)(f)+"%").join(", ");case"ends":return l.not?l.values.map(f=>"-%"+(0,V.escape)(f)).join(", "):l.values.map(f=>"%"+(0,V.escape)(f)).join(", ");case"contains":return l.not?l.values.map(f=>"-%"+(0,V.escape)(f)+"%").join(", "):l.values.map(f=>"%"+(0,V.escape)(f)+"%").join(", ");case"or":return l.members.map(f=>u.StringFilterExpression.unparse(f)).join(" | ");case"and":return l.members.map(f=>u.StringFilterExpression.unparse(f)).join("; ");case",":return l.members.map(f=>u.StringFilterExpression.unparse(f)).join(", ");case"()":{const f="("+u.StringFilterExpression.unparse(l.expr)+")";return l.not?"-"+f:f}case"null":return l.not?"-null":"null";case"empty":return l.not?"-empty":"empty"}}}})(Or)),Or}var Fr={},qr,on;function es(){if(on)return qr;on=1;const{temporalNot:u,joinTemporal:M,timeLiteral:z,mkUnits:V}=lr();function g(s,d){function e(){this.constructor=s}e.prototype=d.prototype,s.prototype=new e}function l(s,d,e,w){var E=Error.call(this,s);return Object.setPrototypeOf&&Object.setPrototypeOf(E,l.prototype),E.expected=d,E.found=e,E.location=w,E.name="SyntaxError",E}g(l,Error);function f(s,d,e){return e=e||" ",s.length>d?s:(d-=s.length,e+=e.repeat(d),s+e.slice(0,d))}l.prototype.format=function(s){var d="Error: "+this.message;if(this.location){var e=null,w;for(w=0;w<s.length;w++)if(s[w].source===this.location.source){e=s[w].text.split(/\r\n|\n|\r/g);break}var E=this.location.start,x=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(E):E,G=this.location.source+":"+x.line+":"+x.column;if(e){var oe=this.location.end,C=f("",x.line.toString().length," "),R=e[E.line-1],P=E.line===oe.line?oe.column:R.length+1,N=P-E.column||1;d+=`
|
|
35
|
+
--> `+G+`
|
|
36
|
+
`+C+` |
|
|
37
|
+
`+x.line+" | "+R+`
|
|
38
|
+
`+C+" | "+f("",E.column-1," ")+f("",N,"^")}else d+=`
|
|
39
|
+
at `+G}return d},l.buildMessage=function(s,d){var e={literal:function(R){return'"'+E(R.text)+'"'},class:function(R){var P=R.parts.map(function(N){return Array.isArray(N)?x(N[0])+"-"+x(N[1]):x(N)});return"["+(R.inverted?"^":"")+P.join("")+"]"},any:function(){return"any character"},end:function(){return"end of input"},other:function(R){return R.description}};function w(R){return R.charCodeAt(0).toString(16).toUpperCase()}function E(R){return R.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(P){return"\\x0"+w(P)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(P){return"\\x"+w(P)})}function x(R){return R.replace(/\\/g,"\\\\").replace(/\]/g,"\\]").replace(/\^/g,"\\^").replace(/-/g,"\\-").replace(/\0/g,"\\0").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/[\x00-\x0F]/g,function(P){return"\\x0"+w(P)}).replace(/[\x10-\x1F\x7F-\x9F]/g,function(P){return"\\x"+w(P)})}function G(R){return e[R.type](R)}function oe(R){var P=R.map(G),N,ye;if(P.sort(),P.length>0){for(N=1,ye=1;N<P.length;N++)P[N-1]!==P[N]&&(P[ye]=P[N],ye++);P.length=ye}switch(P.length){case 1:return P[0];case 2:return P[0]+" or "+P[1];default:return P.slice(0,-1).join(", ")+", or "+P[P.length-1]}}function C(R){return R?'"'+E(R)+'"':"end of input"}return"Expected "+oe(s)+" but "+C(d)+" found."};function c(s,d){d=d!==void 0?d:{};var e={},w=d.grammarSource,E={temporalFilter:wr},x=wr,G="(",oe=")",C="second",R="minute",P="hour",N="day",ye="week",Se="month",Ee="quarter",xe="year",ve="s",$e="-",D=":",B="not",Y="null",j="to",W="now",Q="last",ne="this",re="next",he="ago",Ae="from",_e="before",pe="after",ge="through",Ve="starting",tt="for",at="today",it="yesterday",X="tomorrow",$="and",p="or",v="monday",m="tuesday",b="wednesday",A="thursday",L="friday",U="saturday",K="sunday",F=/^[0-9]/,H=/^[ Tt]/,ae=/^[.,]/,le=/^[Ww]/,Fe=/^[Kk]/,Ue=/^[Qq]/,rt=/^[1234]/,Ne=/^[a-zA-Z]/,ze=/^[ \t]/,He=Oe("(",!1),Je=Oe(")",!1),O=mt([["0","9"]],!1,!1),te=Oe("second",!0),Re=Oe("minute",!0),de=Oe("hour",!0),De=Oe("day",!0),Ye=Oe("week",!0),ut=Oe("month",!0),lt=Oe("quarter",!0),kt=Oe("year",!0),k=Oe("s",!0),t=Oe("-",!1),a=mt([" ","T","t"],!1,!1),y=Oe(":",!1),h=mt([".",","],!1,!1),J=mt(["W","w"],!1,!1),me=mt(["K","k"],!1,!1),Le=mt(["Q","q"],!1,!1),Z=mt(["1","2","3","4"],!1,!1),Me=Oe("not",!0),Ke=Oe("null",!0),_t=Oe("to",!0),fr=Oe("now",!0),ur=Oe("last",!0),Xt=Oe("this",!0),Zt=Oe("next",!0),ke=Oe("ago",!0),cr=Oe("from",!0),Mt=Oe("before",!0),jt=Oe("after",!0),er=Oe("through",!0),pr=Oe("starting",!0),dr=Oe("for",!0),ft=Oe("today",!0),tr=Oe("yesterday",!0),hr=Oe("tomorrow",!0),gr=Oe("and",!0),mr=Oe("or",!0),yr=Oe("monday",!0),vr=Oe("tuesday",!0),St=Oe("wednesday",!0),je=Oe("thursday",!0),S=Oe("friday",!0),q=Oe("saturday",!0),ee=Oe("sunday",!0),se=mt([["a","z"],["A","Z"]],!1,!1),be=Pr("optional whitespace"),ie=mt([" "," "],!1,!1),ue=Pr("whitespace"),we=function(n,o){return o.reduce((i,[,_,,fe])=>M(i,_,fe),n)},Ie=function(n){return u(n,!0)},Qe=function(n){return n},Tn=function(){return{operator:"null"}},$n=function(n){return{operator:"()",expr:n}},kn=function(n){return{operator:"before",before:n}},Sn=function(n){return{operator:"before",before:n,not:!0}},En=function(n){return{operator:"after",after:n}},On=function(n){return{operator:"after",after:n,not:!0}},Rn=function(n,o){return{operator:n,...o}},Fn=function(n,o){return{operator:"to",fromMoment:n,toMoment:o}},qn=function(n,o){return{...o,operator:"for",begin:n}},Cn=function(n){return{operator:"in",in:n}},Pn=function(n){return{operator:"in_last",...n}},xn=function(){return"last"},Vn=function(){return"next"},In=function(n,o){return{units:o,n}},Ln=function(n){return n},Dn=function(n){return V(n)},Nn=function(){return{moment:"now"}},Mn=function(){return{moment:"today"}},jn=function(){return{moment:"yesterday"}},Un=function(){return{moment:"tomorrow"}},Qn=function(n){return{moment:"ago",...n}},Bn=function(n){return{moment:"from_now",...n}},Wn=function(n){return{moment:n.toLowerCase(),which:"next"}},Gn=function(n){return{moment:n.toLowerCase(),which:"last"}},zn=function(n,o){return{moment:n,units:o}},Yn=function(n){return{moment:n.toLowerCase(),which:"last"}},Kn=function(n){return n},Hn=function(){return"this"},Jn=function(){return"next"},Xn=function(){return"last"},Zn=function(n){return z(n)},ei=function(n){return z(n,"week")},ti=function(n){return z(n,"quarter")},ri=function(n){return z(n,"minute")},ni=function(n){return z(n,"hour")},ii=function(n){return z(n,"day")},si=function(n){return z(n,"month")},ai=function(n){return z(n,"year")},oi=function(n){return n},li=function(){return"or"},fi=function(){return"and"},r=d.peg$currPos|0,Lt=[{line:1,column:1}],ct=r,rr=d.peg$maxFailExpected||[],T=d.peg$silentFails|0,Ut;if(d.startRule){if(!(d.startRule in E))throw new Error(`Can't start parsing from rule "`+d.startRule+'".');x=E[d.startRule]}function Oe(n,o){return{type:"literal",text:n,ignoreCase:o}}function mt(n,o,i){return{type:"class",parts:n,inverted:o,ignoreCase:i}}function ui(){return{type:"end"}}function Pr(n){return{type:"other",description:n}}function xr(n){var o=Lt[n],i;if(o)return o;if(n>=Lt.length)i=Lt.length-1;else for(i=n;!Lt[--i];);for(o=Lt[i],o={line:o.line,column:o.column};i<n;)s.charCodeAt(i)===10?(o.line++,o.column=1):o.column++,i++;return Lt[n]=o,o}function Vr(n,o,i){var _=xr(n),fe=xr(o),ce={source:w,start:{offset:n,line:_.line,column:_.column},end:{offset:o,line:fe.line,column:fe.column}};return ce}function I(n){r<ct||(r>ct&&(ct=r,rr=[]),rr.push(n))}function ci(n,o,i){return new l(l.buildMessage(n,o),n,o,i)}function wr(){var n,o,i,_,fe,ce,Te,qe;if(n=r,o=_r(),o!==e){for(i=[],_=r,fe=Dt(),ce=Dr(),ce!==e?(Te=Dt(),qe=_r(),qe!==e?(fe=[fe,ce,Te,qe],_=fe):(r=_,_=e)):(r=_,_=e);_!==e;)i.push(_),_=r,fe=Dt(),ce=Dr(),ce!==e?(Te=Dt(),qe=_r(),qe!==e?(fe=[fe,ce,Te,qe],_=fe):(r=_,_=e)):(r=_,_=e);n=we(o,i)}else r=n,n=e;return n}function _r(){var n,o,i,_;return n=r,o=mi(),o!==e?(i=st(),i!==e?(_=Ir(),_!==e?n=Ie(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=Ir(),o!==e&&(o=Qe(o)),n=o),n}function Ir(){var n,o,i,_,fe,ce;return n=r,o=yi(),o!==e&&(o=Tn()),n=o,n===e&&(n=r,s.charCodeAt(r)===40?(o=G,r++):(o=e,T===0&&I(He)),o!==e?(i=Dt(),_=wr(),_!==e?(fe=Dt(),s.charCodeAt(r)===41?(ce=oe,r++):(ce=e,T===0&&I(Je)),ce!==e?n=$n(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=bi(),o!==e?(i=st(),i!==e?(_=At(),_!==e?n=kn(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=ki(),o!==e?(i=st(),i!==e?(_=At(),_!==e?n=Sn(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=Ti(),o!==e?(i=st(),i!==e?(_=At(),_!==e?n=En(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=$i(),o!==e?(i=st(),i!==e?(_=At(),_!==e?n=On(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=pi(),o!==e?(i=st(),i!==e?(_=Qt(),_!==e?n=Rn(o,_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=At(),o!==e?(i=st(),i!==e?(_=vi(),_!==e?(fe=st(),fe!==e?(ce=At(),ce!==e?n=Fn(o,ce):(r=n,n=e)):(r=n,n=e)):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=At(),o!==e?(i=st(),i!==e?(_=Si(),_!==e?(fe=st(),fe!==e?(ce=Qt(),ce!==e?n=qn(o,ce):(r=n,n=e)):(r=n,n=e)):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=At(),o!==e&&(o=Cn(o)),n=o,n===e&&(n=r,o=Qt(),o!==e&&(o=Pn(o)),n=o)))))))))),n}function pi(){var n,o;return n=r,o=br(),o!==e&&(o=xn()),n=o,n===e&&(n=r,o=Tr(),o!==e&&(o=Vn()),n=o),n}function Qt(){var n,o,i,_;return n=r,o=di(),o!==e?(i=st(),i!==e?(_=Lr(),_!==e?n=In(o,_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n}function di(){var n,o,i,_;if(n=r,o=r,i=[],_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e)for(;_!==e;)i.push(_),_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O));else i=e;return i!==e?o=s.substring(o,r):o=i,o!==e&&(o=Ln(o)),n=o,n}function Lr(){var n,o,i,_,fe;return n=r,o=r,i=s.substr(r,6),i.toLowerCase()===C?r+=6:(i=e,T===0&&I(te)),i===e&&(i=s.substr(r,6),i.toLowerCase()===R?r+=6:(i=e,T===0&&I(Re)),i===e&&(i=s.substr(r,4),i.toLowerCase()===P?r+=4:(i=e,T===0&&I(de)),i===e&&(i=s.substr(r,3),i.toLowerCase()===N?r+=3:(i=e,T===0&&I(De)),i===e&&(i=s.substr(r,4),i.toLowerCase()===ye?r+=4:(i=e,T===0&&I(Ye)),i===e&&(i=s.substr(r,5),i.toLowerCase()===Se?r+=5:(i=e,T===0&&I(ut)),i===e&&(i=s.substr(r,7),i.toLowerCase()===Ee?r+=7:(i=e,T===0&&I(lt)),i===e&&(i=s.substr(r,4),i.toLowerCase()===xe?r+=4:(i=e,T===0&&I(kt))))))))),i!==e?o=s.substring(o,r):o=i,o!==e?(i=s.charAt(r),i.toLowerCase()===ve?r++:(i=e,T===0&&I(k)),i===e&&(i=null),_=r,T++,fe=Be(),T--,fe===e?_=void 0:(r=_,_=e),_!==e?n=Dn(o):(r=n,n=e)):(r=n,n=e),n}function At(){var n,o,i,_,fe,ce;return n=r,o=Nr(),o!==e&&(o=Nn()),n=o,n===e&&(n=r,o=Ei(),o!==e&&(o=Mn()),n=o,n===e&&(n=r,o=Oi(),o!==e&&(o=jn()),n=o,n===e&&(n=r,o=Ri(),o!==e&&(o=Un()),n=o,n===e&&(n=r,o=Qt(),o!==e?(i=st(),i!==e?(_=_i(),_!==e?n=Qn(o):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=Qt(),o!==e?(i=st(),i!==e?(_=Ai(),_!==e?(fe=st(),fe!==e?(ce=Nr(),ce!==e?n=Bn(o):(r=n,n=e)):(r=n,n=e)):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=Tr(),o!==e?(i=st(),i!==e?(_=Ar(),_!==e?n=Wn(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=br(),o!==e?(i=st(),i!==e?(_=Ar(),_!==e?n=Gn(_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=hi(),o!==e?(i=st(),i!==e?(_=Lr(),_!==e?n=zn(o,_):(r=n,n=e)):(r=n,n=e)):(r=n,n=e),n===e&&(n=r,o=Ar(),o!==e&&(o=Yn(o)),n=o,n===e&&(n=r,o=gi(),o!==e&&(o=Kn(o)),n=o)))))))))),n}function hi(){var n,o;return n=r,o=wi(),o!==e&&(o=Hn()),n=o,n===e&&(n=r,o=Tr(),o!==e&&(o=Jn()),n=o,n===e&&(n=r,o=br(),o!==e&&(o=Xn()),n=o)),n}function gi(){var n,o,i,_,fe,ce,Te,qe,Ce,Pe,Xe,We,Ge,nt,Ze,et,bt,ht,gt,nr,Bt,Wt,Et,Ot,$r,Tt;if(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e)if(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e)if(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e)if(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e)if(s.charCodeAt(r)===45?(qe=$e,r++):(qe=e,T===0&&I(t)),qe!==e)if(Ce=s.charAt(r),F.test(Ce)?r++:(Ce=e,T===0&&I(O)),Ce!==e)if(Pe=s.charAt(r),F.test(Pe)?r++:(Pe=e,T===0&&I(O)),Pe!==e)if(s.charCodeAt(r)===45?(Xe=$e,r++):(Xe=e,T===0&&I(t)),Xe!==e)if(We=s.charAt(r),F.test(We)?r++:(We=e,T===0&&I(O)),We!==e)if(Ge=s.charAt(r),F.test(Ge)?r++:(Ge=e,T===0&&I(O)),Ge!==e)if(nt=s.charAt(r),H.test(nt)?r++:(nt=e,T===0&&I(a)),nt!==e)if(Ze=s.charAt(r),F.test(Ze)?r++:(Ze=e,T===0&&I(O)),Ze!==e)if(et=s.charAt(r),F.test(et)?r++:(et=e,T===0&&I(O)),et!==e)if(s.charCodeAt(r)===58?(bt=D,r++):(bt=e,T===0&&I(y)),bt!==e)if(ht=s.charAt(r),F.test(ht)?r++:(ht=e,T===0&&I(O)),ht!==e)if(gt=s.charAt(r),F.test(gt)?r++:(gt=e,T===0&&I(O)),gt!==e)if(s.charCodeAt(r)===58?(nr=D,r++):(nr=e,T===0&&I(y)),nr!==e)if(Bt=s.charAt(r),F.test(Bt)?r++:(Bt=e,T===0&&I(O)),Bt!==e)if(Wt=s.charAt(r),F.test(Wt)?r++:(Wt=e,T===0&&I(O)),Wt!==e){if(Et=r,Ot=s.charAt(r),ae.test(Ot)?r++:(Ot=e,T===0&&I(h)),Ot!==e){for($r=[],Tt=s.charAt(r),F.test(Tt)?r++:(Tt=e,T===0&&I(O));Tt!==e;)$r.push(Tt),Tt=s.charAt(r),F.test(Tt)?r++:(Tt=e,T===0&&I(O));Ot=[Ot,$r],Et=Ot}else r=Et,Et=e;Et===e&&(Et=null),_=[_,fe,ce,Te,qe,Ce,Pe,Xe,We,Ge,nt,Ze,et,bt,ht,gt,nr,Bt,Wt,Et],i=_}else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;else r=i,i=e;return i!==e?o=s.substring(o,r):o=i,o!==e&&(o=Zn(o)),n=o,n===e&&(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e?(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e?(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e?(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e?(s.charCodeAt(r)===45?(qe=$e,r++):(qe=e,T===0&&I(t)),qe!==e?(Ce=s.charAt(r),F.test(Ce)?r++:(Ce=e,T===0&&I(O)),Ce!==e?(Pe=s.charAt(r),F.test(Pe)?r++:(Pe=e,T===0&&I(O)),Pe!==e?(s.charCodeAt(r)===45?(Xe=$e,r++):(Xe=e,T===0&&I(t)),Xe!==e?(We=s.charAt(r),F.test(We)?r++:(We=e,T===0&&I(O)),We!==e?(Ge=s.charAt(r),F.test(Ge)?r++:(Ge=e,T===0&&I(O)),Ge!==e?(s.charCodeAt(r)===45?(nt=$e,r++):(nt=e,T===0&&I(t)),nt!==e?(Ze=s.charAt(r),le.test(Ze)?r++:(Ze=e,T===0&&I(J)),Ze!==e?(et=s.charAt(r),Fe.test(et)?r++:(et=e,T===0&&I(me)),et!==e?(_=[_,fe,ce,Te,qe,Ce,Pe,Xe,We,Ge,nt,Ze,et],i=_):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=ei(o)),n=o,n===e&&(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e?(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e?(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e?(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e?(s.charCodeAt(r)===45?(qe=$e,r++):(qe=e,T===0&&I(t)),qe!==e?(Ce=s.charAt(r),Ue.test(Ce)?r++:(Ce=e,T===0&&I(Le)),Ce!==e?(Pe=s.charAt(r),rt.test(Pe)?r++:(Pe=e,T===0&&I(Z)),Pe!==e?(_=[_,fe,ce,Te,qe,Ce,Pe],i=_):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=ti(o)),n=o,n===e&&(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e?(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e?(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e?(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e?(s.charCodeAt(r)===45?(qe=$e,r++):(qe=e,T===0&&I(t)),qe!==e?(Ce=s.charAt(r),F.test(Ce)?r++:(Ce=e,T===0&&I(O)),Ce!==e?(Pe=s.charAt(r),F.test(Pe)?r++:(Pe=e,T===0&&I(O)),Pe!==e?(s.charCodeAt(r)===45?(Xe=$e,r++):(Xe=e,T===0&&I(t)),Xe!==e?(We=s.charAt(r),F.test(We)?r++:(We=e,T===0&&I(O)),We!==e?(Ge=s.charAt(r),F.test(Ge)?r++:(Ge=e,T===0&&I(O)),Ge!==e?(nt=s.charAt(r),H.test(nt)?r++:(nt=e,T===0&&I(a)),nt!==e?(Ze=s.charAt(r),F.test(Ze)?r++:(Ze=e,T===0&&I(O)),Ze!==e?(et=s.charAt(r),F.test(et)?r++:(et=e,T===0&&I(O)),et!==e?(s.charCodeAt(r)===58?(bt=D,r++):(bt=e,T===0&&I(y)),bt!==e?(ht=s.charAt(r),F.test(ht)?r++:(ht=e,T===0&&I(O)),ht!==e?(gt=s.charAt(r),F.test(gt)?r++:(gt=e,T===0&&I(O)),gt!==e?(_=[_,fe,ce,Te,qe,Ce,Pe,Xe,We,Ge,nt,Ze,et,bt,ht,gt],i=_):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=ri(o)),n=o,n===e&&(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e?(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e?(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e?(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e?(s.charCodeAt(r)===45?(qe=$e,r++):(qe=e,T===0&&I(t)),qe!==e?(Ce=s.charAt(r),F.test(Ce)?r++:(Ce=e,T===0&&I(O)),Ce!==e?(Pe=s.charAt(r),F.test(Pe)?r++:(Pe=e,T===0&&I(O)),Pe!==e?(s.charCodeAt(r)===45?(Xe=$e,r++):(Xe=e,T===0&&I(t)),Xe!==e?(We=s.charAt(r),F.test(We)?r++:(We=e,T===0&&I(O)),We!==e?(Ge=s.charAt(r),F.test(Ge)?r++:(Ge=e,T===0&&I(O)),Ge!==e?(nt=s.charAt(r),H.test(nt)?r++:(nt=e,T===0&&I(a)),nt!==e?(Ze=s.charAt(r),F.test(Ze)?r++:(Ze=e,T===0&&I(O)),Ze!==e?(et=s.charAt(r),F.test(et)?r++:(et=e,T===0&&I(O)),et!==e?(_=[_,fe,ce,Te,qe,Ce,Pe,Xe,We,Ge,nt,Ze,et],i=_):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=ni(o)),n=o,n===e&&(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e?(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e?(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e?(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e?(s.charCodeAt(r)===45?(qe=$e,r++):(qe=e,T===0&&I(t)),qe!==e?(Ce=s.charAt(r),F.test(Ce)?r++:(Ce=e,T===0&&I(O)),Ce!==e?(Pe=s.charAt(r),F.test(Pe)?r++:(Pe=e,T===0&&I(O)),Pe!==e?(s.charCodeAt(r)===45?(Xe=$e,r++):(Xe=e,T===0&&I(t)),Xe!==e?(We=s.charAt(r),F.test(We)?r++:(We=e,T===0&&I(O)),We!==e?(Ge=s.charAt(r),F.test(Ge)?r++:(Ge=e,T===0&&I(O)),Ge!==e?(_=[_,fe,ce,Te,qe,Ce,Pe,Xe,We,Ge],i=_):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=ii(o)),n=o,n===e&&(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e?(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e?(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e?(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e?(s.charCodeAt(r)===45?(qe=$e,r++):(qe=e,T===0&&I(t)),qe!==e?(Ce=s.charAt(r),F.test(Ce)?r++:(Ce=e,T===0&&I(O)),Ce!==e?(Pe=s.charAt(r),F.test(Pe)?r++:(Pe=e,T===0&&I(O)),Pe!==e?(_=[_,fe,ce,Te,qe,Ce,Pe],i=_):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=si(o)),n=o,n===e&&(n=r,o=r,i=r,_=s.charAt(r),F.test(_)?r++:(_=e,T===0&&I(O)),_!==e?(fe=s.charAt(r),F.test(fe)?r++:(fe=e,T===0&&I(O)),fe!==e?(ce=s.charAt(r),F.test(ce)?r++:(ce=e,T===0&&I(O)),ce!==e?(Te=s.charAt(r),F.test(Te)?r++:(Te=e,T===0&&I(O)),Te!==e?(_=[_,fe,ce,Te],i=_):(r=i,i=e)):(r=i,i=e)):(r=i,i=e)):(r=i,i=e),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=ai(o)),n=o))))))),n}function Ar(){var n,o,i;return n=r,o=r,i=Ci(),i===e&&(i=Pi(),i===e&&(i=xi(),i===e&&(i=Vi(),i===e&&(i=Ii(),i===e&&(i=Li(),i===e&&(i=Di())))))),i!==e?o=s.substring(o,r):o=i,o!==e&&(o=oi(o)),n=o,n}function Dr(){var n,o;return n=r,o=qi(),o!==e&&(o=li()),n=o,n===e&&(n=r,o=Fi(),o!==e&&(o=fi()),n=o),n}function mi(){var n,o,i,_;return n=r,o=s.substr(r,3),o.toLowerCase()===B?r+=3:(o=e,T===0&&I(Me)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function yi(){var n,o,i,_;return n=r,o=s.substr(r,4),o.toLowerCase()===Y?r+=4:(o=e,T===0&&I(Ke)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function vi(){var n,o,i,_;return n=r,o=s.substr(r,2),o.toLowerCase()===j?r+=2:(o=e,T===0&&I(_t)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Nr(){var n,o,i,_;return n=r,o=s.substr(r,3),o.toLowerCase()===W?r+=3:(o=e,T===0&&I(fr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function br(){var n,o,i,_;return n=r,o=s.substr(r,4),o.toLowerCase()===Q?r+=4:(o=e,T===0&&I(ur)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function wi(){var n,o,i,_;return n=r,o=s.substr(r,4),o.toLowerCase()===ne?r+=4:(o=e,T===0&&I(Xt)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Tr(){var n,o,i,_;return n=r,o=s.substr(r,4),o.toLowerCase()===re?r+=4:(o=e,T===0&&I(Zt)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function _i(){var n,o,i,_;return n=r,o=s.substr(r,3),o.toLowerCase()===he?r+=3:(o=e,T===0&&I(ke)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Ai(){var n,o,i,_;return n=r,o=s.substr(r,4),o.toLowerCase()===Ae?r+=4:(o=e,T===0&&I(cr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function bi(){var n,o,i,_;return n=r,o=s.substr(r,6),o.toLowerCase()===_e?r+=6:(o=e,T===0&&I(Mt)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Ti(){var n,o,i,_;return n=r,o=s.substr(r,5),o.toLowerCase()===pe?r+=5:(o=e,T===0&&I(jt)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function $i(){var n,o,i,_;return n=r,o=s.substr(r,7),o.toLowerCase()===ge?r+=7:(o=e,T===0&&I(er)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function ki(){var n,o,i,_;return n=r,o=s.substr(r,8),o.toLowerCase()===Ve?r+=8:(o=e,T===0&&I(pr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Si(){var n,o,i,_;return n=r,o=s.substr(r,3),o.toLowerCase()===tt?r+=3:(o=e,T===0&&I(dr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Ei(){var n,o,i,_;return n=r,o=s.substr(r,5),o.toLowerCase()===at?r+=5:(o=e,T===0&&I(ft)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Oi(){var n,o,i,_;return n=r,o=s.substr(r,9),o.toLowerCase()===it?r+=9:(o=e,T===0&&I(tr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Ri(){var n,o,i,_;return n=r,o=s.substr(r,8),o.toLowerCase()===X?r+=8:(o=e,T===0&&I(hr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Fi(){var n,o,i,_;return n=r,o=s.substr(r,3),o.toLowerCase()===$?r+=3:(o=e,T===0&&I(gr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function qi(){var n,o,i,_;return n=r,o=s.substr(r,2),o.toLowerCase()===p?r+=2:(o=e,T===0&&I(mr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Ci(){var n,o,i,_;return n=r,o=s.substr(r,6),o.toLowerCase()===v?r+=6:(o=e,T===0&&I(yr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Pi(){var n,o,i,_;return n=r,o=s.substr(r,7),o.toLowerCase()===m?r+=7:(o=e,T===0&&I(vr)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function xi(){var n,o,i,_;return n=r,o=s.substr(r,9),o.toLowerCase()===b?r+=9:(o=e,T===0&&I(St)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Vi(){var n,o,i,_;return n=r,o=s.substr(r,8),o.toLowerCase()===A?r+=8:(o=e,T===0&&I(je)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Ii(){var n,o,i,_;return n=r,o=s.substr(r,6),o.toLowerCase()===L?r+=6:(o=e,T===0&&I(S)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Li(){var n,o,i,_;return n=r,o=s.substr(r,8),o.toLowerCase()===U?r+=8:(o=e,T===0&&I(q)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Di(){var n,o,i,_;return n=r,o=s.substr(r,6),o.toLowerCase()===K?r+=6:(o=e,T===0&&I(ee)),o!==e?(i=r,T++,_=Be(),T--,_===e?i=void 0:(r=i,i=e),i!==e?(o=[o,i],n=o):(r=n,n=e)):(r=n,n=e),n}function Be(){var n;return n=s.charAt(r),Ne.test(n)?r++:(n=e,T===0&&I(se)),n}function Dt(){var n,o;for(T++,n=[],o=s.charAt(r),ze.test(o)?r++:(o=e,T===0&&I(ie));o!==e;)n.push(o),o=s.charAt(r),ze.test(o)?r++:(o=e,T===0&&I(ie));return T--,o=e,T===0&&I(be),n}function st(){var n,o;if(T++,n=[],o=s.charAt(r),ze.test(o)?r++:(o=e,T===0&&I(ie)),o!==e)for(;o!==e;)n.push(o),o=s.charAt(r),ze.test(o)?r++:(o=e,T===0&&I(ie));else n=e;return T--,n===e&&(o=e,T===0&&I(ue)),n}if(Ut=x(),d.peg$library)return{peg$result:Ut,peg$currPos:r,peg$FAILED:e,peg$maxFailExpected:rr,peg$maxFailPos:ct};if(Ut!==e&&r===s.length)return Ut;throw Ut!==e&&r<s.length&&I(ui()),ci(rr,ct<s.length?s.charAt(ct):null,ct<s.length?Vr(ct,ct+1):Vr(ct,ct))}return qr={StartRules:["temporalFilter"],SyntaxError:l,parse:c},qr}var ln;function ts(){return ln||(ln=1,(function(u){Object.defineProperty(u,"__esModule",{value:!0}),u.TemporalFilterExpression=void 0;const M=Nt(),z=es(),V=Cr();u.TemporalFilterExpression={parse(c){if(c.match(/^\s*$/))return{parsed:null,log:[]};const s=(0,V.run_parser)(c,z.parse);return s.parsed&&(0,M.isTemporalFilter)(s.parsed)?{parsed:s.parsed,log:[]}:{parsed:null,log:s.log}},unparse(c){if(c===null)return"";switch(c.operator){case"null":return g(c,"null");case"in":return g(c,f(c.in));case"()":return"("+u.TemporalFilterExpression.unparse(c.expr)+")";case"in_last":return g(c,l(c));case"last":case"next":return g(c,`${c.operator} ${l(c)}`);case"before":return`${c.not?"starting":"before"} ${f(c.before)}`;case"after":return`${c.not?"through":"after"} ${f(c.after)}`;case"to":return g(c,`${f(c.fromMoment)} to ${f(c.toMoment)}`);case"for":return g(c,`${f(c.begin)} for ${l(c)}`);case"or":return c.members.map(s=>u.TemporalFilterExpression.unparse(s)).join(" or ");case"and":return c.members.map(s=>u.TemporalFilterExpression.unparse(s)).join(" and ")}}};function g(c,s){return"not"in c&&c.not?"not "+s:s}function l(c){return c.n==="1"?`1 ${c.units}`:`${c.n} ${c.units}s`}function f(c){switch(c.moment){case"literal":return c.literal;case"now":case"today":case"yesterday":case"tomorrow":return c.moment;case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":return c.which==="next"?"next "+c.moment:c.moment;case"this":case"next":case"last":return`${c.moment} ${c.units}`;case"ago":return`${l(c)} ago`;case"from_now":return`${l(c)} from now`}}})(Fr)),Fr}var fn;function rs(){return fn||(fn=1,(function(u){var M=Pt&&Pt.__createBinding||(Object.create?(function(c,s,d,e){e===void 0&&(e=d);var w=Object.getOwnPropertyDescriptor(s,d);(!w||("get"in w?!s.__esModule:w.writable||w.configurable))&&(w={enumerable:!0,get:function(){return s[d]}}),Object.defineProperty(c,e,w)}):(function(c,s,d,e){e===void 0&&(e=d),c[e]=s[d]})),z=Pt&&Pt.__exportStar||function(c,s){for(var d in c)d!=="default"&&!Object.prototype.hasOwnProperty.call(s,d)&&M(s,c,d)};Object.defineProperty(u,"__esModule",{value:!0}),u.TemporalFilterExpression=u.StringFilterExpression=u.NumberFilterExpression=u.BooleanFilterExpression=void 0,z(Nt(),u);var V=Ki();Object.defineProperty(u,"BooleanFilterExpression",{enumerable:!0,get:function(){return V.BooleanFilterExpression}});var g=Ji();Object.defineProperty(u,"NumberFilterExpression",{enumerable:!0,get:function(){return g.NumberFilterExpression}});var l=Zi();Object.defineProperty(u,"StringFilterExpression",{enumerable:!0,get:function(){return l.StringFilterExpression}});var f=ts();Object.defineProperty(u,"TemporalFilterExpression",{enumerable:!0,get:function(){return f.TemporalFilterExpression}})})(Pt)),Pt}var xt={},Yt={},un;function An(){return un||(un=1,Object.defineProperty(Yt,"__esModule",{value:!0}),Yt.MALLOY_INTERFACE_TYPES=void 0,Yt.MALLOY_INTERFACE_TYPES={Aggregate:{type:"struct",name:"Aggregate",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},Annotation:{type:"struct",name:"Annotation",fields:{value:{type:"string",optional:!1,array:!1}}},AnonymousQueryInfo:{type:"struct",name:"AnonymousQueryInfo",fields:{schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},ArrayCell:{type:"struct",name:"ArrayCell",fields:{array_value:{type:"Cell",array:!0,optional:!1}}},ArrayType:{type:"struct",name:"ArrayType",fields:{element_type:{type:"AtomicType",optional:!1,array:!1}}},AtomicType:{type:"union",name:"AtomicType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",timestamptz_type:"TimestamptzType"}},BooleanCell:{type:"struct",name:"BooleanCell",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanLiteral:{type:"struct",name:"BooleanLiteral",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanType:{type:"struct",name:"BooleanType",fields:{}},CalculateInfo:{type:"struct",name:"CalculateInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},CalculateOperation:{type:"struct",name:"CalculateOperation",fields:{name:{type:"string",optional:!1,array:!1},field:{type:"Field",optional:!1,array:!1}}},Cell:{type:"union",name:"Cell",options:{string_cell:"StringCell",boolean_cell:"BooleanCell",date_cell:"DateCell",timestamp_cell:"TimestampCell",number_cell:"NumberCell",json_cell:"JSONCell",record_cell:"RecordCell",array_cell:"ArrayCell",null_cell:"NullCell",sql_native_cell:"SQLNativeCell"}},CompileModelRequest:{type:"struct",name:"CompileModelRequest",fields:{model_url:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileModelResponse:{type:"struct",name:"CompileModelResponse",fields:{model:{type:"ModelInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompileQueryRequest:{type:"struct",name:"CompileQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!0,array:!1},query_malloy:{type:"string",optional:!0,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileQueryResponse:{type:"struct",name:"CompileQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompileSourceRequest:{type:"struct",name:"CompileSourceRequest",fields:{model_url:{type:"string",optional:!1,array:!1},name:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileSourceResponse:{type:"struct",name:"CompileSourceResponse",fields:{source:{type:"SourceInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompilerNeeds:{type:"struct",name:"CompilerNeeds",fields:{table_schemas:{type:"SQLTable",array:!0,optional:!0},sql_schemas:{type:"SQLQuery",array:!0,optional:!0},files:{type:"File",array:!0,optional:!0},connections:{type:"Connection",array:!0,optional:!0},translations:{type:"Translation",array:!0,optional:!0}}},Connection:{type:"struct",name:"Connection",fields:{name:{type:"string",optional:!1,array:!1},dialect:{type:"string",optional:!0,array:!1}}},Data:{type:"union",name:"Data",options:{record_cell:"RecordCell",array_cell:"ArrayCell"}},DateCell:{type:"struct",name:"DateCell",fields:{date_value:{type:"string",optional:!1,array:!1}}},DateLiteral:{type:"struct",name:"DateLiteral",fields:{date_value:{type:"string",optional:!1,array:!1},granularity:{type:"DateTimeframe",optional:!0,array:!1},timezone:{type:"string",optional:!0,array:!1}}},DateTimeframe:{type:"enum",name:"DateTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5}},DateType:{type:"struct",name:"DateType",fields:{timeframe:{type:"DateTimeframe",optional:!0,array:!1}}},DimensionInfo:{type:"struct",name:"DimensionInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},DocumentPosition:{type:"struct",name:"DocumentPosition",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},DocumentRange:{type:"struct",name:"DocumentRange",fields:{start:{type:"DocumentPosition",optional:!1,array:!1},end:{type:"DocumentPosition",optional:!1,array:!1}}},DrillOperation:{type:"struct",name:"DrillOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},Expression:{type:"union",name:"Expression",options:{field_reference:"Reference",time_truncation:"TimeTruncationFieldReference",filtered_field:"FilteredField",literal_value:"LiteralValueExpression",moving_average:"MovingAverage"}},Field:{type:"struct",name:"Field",fields:{expression:{type:"Expression",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},FieldInfo:{type:"union",name:"FieldInfo",options:{dimension:"DimensionInfo",measure:"MeasureInfo",join:"JoinInfo",view:"ViewInfo",calculate:"CalculateInfo"}},File:{type:"struct",name:"File",fields:{url:{type:"string",optional:!1,array:!1},contents:{type:"string",optional:!0,array:!1},invalidation_key:{type:"string",optional:!0,array:!1}}},Filter:{type:"union",name:"Filter",options:{filter_string:"FilterStringApplication",literal_equality:"LiteralEqualityComparison"}},FilterExpressionLiteral:{type:"struct",name:"FilterExpressionLiteral",fields:{filter_expression_value:{type:"string",optional:!1,array:!1}}},FilterExpressionType:{type:"struct",name:"FilterExpressionType",fields:{filter_type:{type:"FilterableType",optional:!1,array:!1}}},FilterOperation:{type:"struct",name:"FilterOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},FilterStringApplication:{type:"struct",name:"FilterStringApplication",fields:{expression:{type:"Expression",optional:!1,array:!1},filter:{type:"string",optional:!1,array:!1}}},FilterableType:{type:"union",name:"FilterableType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",date_type:"DateType",timestamp_type:"TimestampType",timestamptz_type:"TimestamptzType"}},FilteredField:{type:"struct",name:"FilteredField",fields:{field_reference:{type:"Reference",optional:!1,array:!1},where:{type:"FilterOperation",array:!0,optional:!1}}},GroupBy:{type:"struct",name:"GroupBy",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},JSONCell:{type:"struct",name:"JSONCell",fields:{json_value:{type:"string",optional:!1,array:!1}}},JSONType:{type:"struct",name:"JSONType",fields:{}},JoinInfo:{type:"struct",name:"JoinInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},relationship:{type:"Relationship",optional:!1,array:!1}}},Limit:{type:"struct",name:"Limit",fields:{limit:{type:"number",optional:!1,array:!1}}},LiteralEqualityComparison:{type:"struct",name:"LiteralEqualityComparison",fields:{expression:{type:"Expression",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},LiteralValue:{type:"union",name:"LiteralValue",options:{string_literal:"StringLiteral",number_literal:"NumberLiteral",date_literal:"DateLiteral",timestamp_literal:"TimestampLiteral",boolean_literal:"BooleanLiteral",null_literal:"NullLiteral",filter_expression_literal:"FilterExpressionLiteral"}},LiteralValueExpression:{type:"struct",name:"LiteralValueExpression",fields:{literal_value:{type:"LiteralValue",optional:!1,array:!1}}},Location:{type:"struct",name:"Location",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"Range",optional:!1,array:!1}}},LogMessage:{type:"struct",name:"LogMessage",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"DocumentRange",optional:!1,array:!1},severity:{type:"LogSeverity",optional:!1,array:!1},message:{type:"string",optional:!1,array:!1}}},LogSeverity:{type:"enum",name:"LogSeverity",values:{debug:1,info:2,warn:3,error:4}},MeasureInfo:{type:"struct",name:"MeasureInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ModelEntryValue:{type:"union",name:"ModelEntryValue",options:{source:"SourceInfo",query:"QueryInfo"}},ModelInfo:{type:"struct",name:"ModelInfo",fields:{entries:{type:"ModelEntryValue",array:!0,optional:!1},annotations:{type:"Annotation",array:!0,optional:!0},anonymous_queries:{type:"AnonymousQueryInfo",array:!0,optional:!1}}},MovingAverage:{type:"struct",name:"MovingAverage",fields:{field_reference:{type:"Reference",optional:!1,array:!1},rows_preceding:{type:"number",optional:!0,array:!1},rows_following:{type:"number",optional:!0,array:!1},partition_fields:{type:"Reference",array:!0,optional:!0}}},Nest:{type:"struct",name:"Nest",fields:{name:{type:"string",optional:!0,array:!1},view:{type:"View",optional:!1,array:!1}}},NullCell:{type:"struct",name:"NullCell",fields:{}},NullLiteral:{type:"struct",name:"NullLiteral",fields:{}},NumberCell:{type:"struct",name:"NumberCell",fields:{number_value:{type:"number",optional:!1,array:!1},subtype:{type:"NumberSubtype",optional:!0,array:!1},string_value:{type:"string",optional:!0,array:!1}}},NumberLiteral:{type:"struct",name:"NumberLiteral",fields:{number_value:{type:"number",optional:!1,array:!1},string_value:{type:"string",optional:!0,array:!1}}},NumberSubtype:{type:"enum",name:"NumberSubtype",values:{integer:1,decimal:2,bigint:3}},NumberType:{type:"struct",name:"NumberType",fields:{subtype:{type:"NumberSubtype",optional:!0,array:!1}}},OrderBy:{type:"struct",name:"OrderBy",fields:{field_reference:{type:"Reference",optional:!1,array:!1},direction:{type:"OrderByDirection",optional:!0,array:!1}}},OrderByDirection:{type:"enum",name:"OrderByDirection",values:{asc:1,desc:2}},ParameterInfo:{type:"struct",name:"ParameterInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"ParameterType",optional:!1,array:!1},default_value:{type:"LiteralValue",optional:!0,array:!1}}},ParameterType:{type:"union",name:"ParameterType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",filter_expression_type:"FilterExpressionType",timestamptz_type:"TimestamptzType"}},ParameterValue:{type:"struct",name:"ParameterValue",fields:{name:{type:"string",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},Position:{type:"struct",name:"Position",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},Query:{type:"struct",name:"Query",fields:{definition:{type:"QueryDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},QueryArrow:{type:"struct",name:"QueryArrow",fields:{source:{type:"QueryArrowSource",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},QueryArrowSource:{type:"union",name:"QueryArrowSource",options:{refinement:"QueryRefinement",source_reference:"Reference"}},QueryDefinition:{type:"union",name:"QueryDefinition",options:{arrow:"QueryArrow",query_reference:"Reference",refinement:"QueryRefinement"}},QueryInfo:{type:"struct",name:"QueryInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},QueryRefinement:{type:"struct",name:"QueryRefinement",fields:{base:{type:"QueryDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},Range:{type:"struct",name:"Range",fields:{start:{type:"Position",optional:!1,array:!1},end:{type:"Position",optional:!1,array:!1}}},RecordCell:{type:"struct",name:"RecordCell",fields:{record_value:{type:"Cell",array:!0,optional:!1}}},RecordType:{type:"struct",name:"RecordType",fields:{fields:{type:"DimensionInfo",array:!0,optional:!1}}},Reference:{type:"struct",name:"Reference",fields:{name:{type:"string",optional:!1,array:!1},path:{type:"string",array:!0,optional:!0},parameters:{type:"ParameterValue",array:!0,optional:!0}}},Relationship:{type:"enum",name:"Relationship",values:{one:1,many:2,cross:3}},Result:{type:"struct",name:"Result",fields:{data:{type:"Data",optional:!0,array:!1},schema:{type:"Schema",optional:!1,array:!1},sql:{type:"string",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},model_annotations:{type:"Annotation",array:!0,optional:!0},query_timezone:{type:"string",optional:!0,array:!1},source_annotations:{type:"Annotation",array:!0,optional:!0}}},RunIndexQueryRequest:{type:"struct",name:"RunIndexQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},source_name:{type:"string",optional:!1,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunIndexQueryResponse:{type:"struct",name:"RunIndexQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},RunQueryRequest:{type:"struct",name:"RunQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!0,array:!1},query_malloy:{type:"string",optional:!0,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryResponse:{type:"struct",name:"RunQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},SQLNativeCell:{type:"struct",name:"SQLNativeCell",fields:{sql_native_value:{type:"string",optional:!1,array:!1}}},SQLNativeType:{type:"struct",name:"SQLNativeType",fields:{sql_type:{type:"string",optional:!0,array:!1}}},SQLQuery:{type:"struct",name:"SQLQuery",fields:{sql:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},SQLTable:{type:"struct",name:"SQLTable",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},Schema:{type:"struct",name:"Schema",fields:{fields:{type:"FieldInfo",array:!0,optional:!1}}},SourceInfo:{type:"struct",name:"SourceInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},parameters:{type:"ParameterInfo",array:!0,optional:!0}}},StringCell:{type:"struct",name:"StringCell",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringLiteral:{type:"struct",name:"StringLiteral",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringType:{type:"struct",name:"StringType",fields:{}},TimeTruncationFieldReference:{type:"struct",name:"TimeTruncationFieldReference",fields:{field_reference:{type:"Reference",optional:!1,array:!1},truncation:{type:"TimestampTimeframe",optional:!1,array:!1}}},TimestampCell:{type:"struct",name:"TimestampCell",fields:{timestamp_value:{type:"string",optional:!1,array:!1}}},TimestampLiteral:{type:"struct",name:"TimestampLiteral",fields:{timestamp_value:{type:"string",optional:!1,array:!1},granularity:{type:"TimestampTimeframe",optional:!0,array:!1},timezone:{type:"string",optional:!0,array:!1}}},TimestampTimeframe:{type:"enum",name:"TimestampTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5,hour:6,minute:7,second:8}},TimestampType:{type:"struct",name:"TimestampType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimestamptzType:{type:"struct",name:"TimestamptzType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimingInfo:{type:"struct",name:"TimingInfo",fields:{name:{type:"string",optional:!1,array:!1},duration_ms:{type:"number",optional:!1,array:!1},detailed_timing:{type:"TimingInfo",array:!0,optional:!0}}},Translation:{type:"struct",name:"Translation",fields:{url:{type:"string",optional:!1,array:!1},compiled_model_json:{type:"string",optional:!0,array:!1}}},View:{type:"struct",name:"View",fields:{definition:{type:"ViewDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ViewArrow:{type:"struct",name:"ViewArrow",fields:{source:{type:"ViewDefinition",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},ViewDefinition:{type:"union",name:"ViewDefinition",options:{arrow:"ViewArrow",view_reference:"Reference",refinement:"ViewRefinement",segment:"ViewSegment"}},ViewInfo:{type:"struct",name:"ViewInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"View",optional:!0,array:!1}}},ViewOperation:{type:"union",name:"ViewOperation",options:{group_by:"GroupBy",aggregate:"Aggregate",order_by:"OrderBy",limit:"Limit",where:"FilterOperation",nest:"Nest",having:"FilterOperation",drill:"DrillOperation",calculate:"CalculateOperation"}},ViewRefinement:{type:"struct",name:"ViewRefinement",fields:{base:{type:"ViewDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},ViewSegment:{type:"struct",name:"ViewSegment",fields:{operations:{type:"ViewOperation",array:!0,optional:!1}}}}),Yt}var Kt={},or={},Ht={},cn;function ns(){return cn||(cn=1,Object.defineProperty(Ht,"__esModule",{value:!0}),Ht.RESERVED_WORDS=void 0,Ht.RESERVED_WORDS=["accept","aggregate","declare","dimension","except","explore","group_by","having","index","join_cross","join_one","join_many","limit","measure","nest","order_by","primary_key","project","query","rename","sample","source","sql","turduck","top","where","all","as","asc","avg","boolean","by","case","cast","condition","count","date","day","days","desc","distinct","else","end","exclude","false","for","from","from_sql","has","hour","hours","import","is","json","last","max","min","minute","minutes","month","months","not","now","null","number","on","or","pick","quarter","quarters","second","seconds","string","sum","table","then","this","timestamp","to","true","turtle","week","weeks","when","with","year","years","ungrouped"]),Ht}var pn;function is(){if(pn)return or;pn=1,Object.defineProperty(or,"__esModule",{value:!0}),or.maybeQuoteIdentifier=z;const u=ns();function M(V){const g=!V.match(/^[A-Za-z_][A-Za-z_0-9]*$/),l=u.RESERVED_WORDS.includes(V.toLowerCase());return g||l}function z(V){return M(V)?`\`${V}\``:V}return or}var dn;function ss(){if(dn)return Kt;dn=1,Object.defineProperty(Kt,"__esModule",{value:!0}),Kt.queryToMalloy=M,Kt.filterToMalloy=z;const u=is();function M($,{tabWidth:p}={tabWidth:2}){const v=oe($);return c(v,{tabWidth:p})}function z($,{tabWidth:p}={tabWidth:2}){const v=tt($);return c(v,{tabWidth:p})}const V=Symbol("indent"),g=Symbol("newline"),l=Symbol("outdent"),f=Symbol("optional_newline_indent");function c($,{tabWidth:p}={tabWidth:2}){let v="",m=0,b=!0;for(const A of $)if(A===g)v+=`
|
|
40
|
+
`,b=!0;else if(A===l)m--;else if(A===V)m++;else{if(A===f)continue;b&&(v+=" ".repeat(m*p),b=!1),v+=A}return v}function s($,p,v,m){var b;if(p.includes(g))return[$,g,V,...p,g,l,v];const L=((b=m?.spaces)!==null&&b!==void 0?b:!0)?" ":"";return[$,L,...p,L,v]}function d($){return{contents:$,quoteCharacter:'"'}}function e($,p){const v=[];for(let m=0;m<$.length;m++){const b=$[m];v.push(b),m<$.length-1&&v.push(p)}return v}function w($){var p,v;switch($.kind){case"filter_expression_literal":return[ge($.filter_expression_value)];case"boolean_literal":return[$.boolean_value.toString()];case"string_literal":{const{contents:m,quoteCharacter:b}=d($.string_value);return[b,m,b]}case"number_literal":return[$.number_value.toString()];case"null_literal":return["null"];case"date_literal":return[x(E($.date_value),(p=$.granularity)!==null&&p!==void 0?p:"day",$.timezone)];case"timestamp_literal":return[x(E($.timestamp_value),(v=$.granularity)!==null&&v!==void 0?v:"second",$.timezone)]}}function E($){let p;if(p=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/.exec($)){const[v,m,b,A,L,U,K]=p;return[m,b,A,L,U,K]}else if(p=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d)/.exec($)){const[v,m,b,A,L,U]=p;return[m,b,A,L,U,"00"]}else if(p=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d)(?:00)?/.exec($)){const[v,m,b,A,L]=p;return[m,b,A,L,"00","00"]}else if(p=/(\d\d\d\d)-(\d\d)-(\d\d)/.exec($)){const[v,m,b,A]=p;return[m,b,A,"00","00","00"]}else if(p=/(\d\d\d\d)-(\d\d)/.exec($)){const[v,m,b]=p;return[m,b,"01","00","00","00"]}else if(p=/(\d\d\d\d)/.exec($)){const[v,m]=p;return[m,"01","01","00","00","00"]}return["1970","01","01","00","00","00"]}function x([$,p,v,m,b,A],L,U){switch(L){case"year":return`@${$}`;case"quarter":{const K=Math.floor(+p/3)+1;return`@${$}-Q${K}`}case"month":return`@${$}-${p}`;case"week":return`@${$}-${p}-${v}-WK`;case"day":return`@${$}-${p}-${v}`;case"hour":return`@${$}-${p}-${v} ${m}`;case"minute":return`@${$}-${p}-${v} ${m}:${b}`;case"second":return U!==void 0?`@${$}-${p}-${v} ${m}:${b}:${A}[${U}]`:`@${$}-${p}-${v} ${m}:${b}:${A}`;default:throw new Error("Unknown timeframe.")}}function G($){var p;const v=[];for(const m of(p=$.path)!==null&&p!==void 0?p:[])v.push((0,u.maybeQuoteIdentifier)(m)),v.push(".");if(v.push((0,u.maybeQuoteIdentifier)($.name)),$.parameters){const m=[];for(let b=0;b<$.parameters.length;b++){const A=$.parameters[b];m.push((0,u.maybeQuoteIdentifier)(A.name)),m.push(" is "),m.push(...w(A.value)),b<$.parameters.length-1&&m.push(",",g)}v.push(...s("(",m,")",{spaces:!1}))}return v}function oe($){const p=[];return p.push(...it($.annotations)),p.push("run: "),p.push(...R($.definition)),p}function C($){const p=[];switch($.kind){case"source_reference":{p.push(...G($));break}case"refinement":p.push(...R($));break}return p}function R($){const p=[];switch($.kind){case"arrow":{p.push(...C($.source)),p.push(" -> "),p.push(...P($.view));break}case"query_reference":{p.push(...G($));break}case"refinement":{const v=R($.base);$.base.kind==="arrow"?p.push(...s("(",v,")",{spaces:!1})):p.push(...v),p.push(" + "),p.push(...P($.refinement));break}}return p}function P($){const p=[];switch($.kind){case"arrow":{p.push(...P($.source)),p.push(" -> "),p.push(...P($.view));break}case"view_reference":{p.push(...G($));break}case"refinement":{p.push(...P($.base)),p.push(" + "),p.push(...P($.refinement));break}case"segment":{p.push(...N($));break}}return p}function N($){if($.operations.length===0)return["{ }"];const p=$.operations.length>1,v=[];for(let m=0;m<$.operations.length;m++){const b=$.operations[m],A=[b];for(;m<$.operations.length-1;){const L=$.operations[m+1];if(L.kind===b.kind)A.push(L),m++;else break}v.push(...ye(A)),p&&m<$.operations.length-1&&v.push(g)}return s("{",v,"}")}function ye($){switch($[0].kind){case"aggregate":return D($,"aggregate");case"group_by":return D($,"group_by");case"order_by":return B($);case"nest":return j($);case"limit":return re($);case"where":return he($);case"having":return _e($);case"drill":return Ae($);case"calculate":return D($,"calculate")}}function Se($,p,v=""){const m=[];m.push(`${$}:`);const b=p.length>1||p.some(A=>A.includes(g));b?m.push(g,V):m.push(" ");for(let A=0;A<p.length;A++){const L=p[A];m.push(...L),p.length>1&&A<p.length-1&&m.push(v),b&&A<p.length-1&&m.push(g)}return b&&m.push(l),m}function Ee($){const p=[];return p.push(...ve($.expression)),p}function xe($){return $}function ve($){var p;switch($.kind){case"field_reference":return G($);case"time_truncation":return[...G($.field_reference),".",$.truncation];case"filtered_field":return[...G($.field_reference),...s(" {",he($.where),"}")];case"literal_value":return w($.literal_value);case"moving_average":{const v=["avg_moving",...s("(",[...G($.field_reference),$.rows_preceding!==void 0?`, ${$.rows_preceding}`:", 0",$.rows_following!==void 0?`, ${$.rows_following}`:""],")",{spaces:!1})];return!((p=$.partition_fields)===null||p===void 0)&&p.length&&v.push(...s(" {",["partition_by",": ",...e($.partition_fields.flatMap(m=>G(m)),", ")],"}")),v}}}function $e($,p=!1){const v=[];return p||v.push(...it($.field.annotations)),$.name&&(v.push((0,u.maybeQuoteIdentifier)($.name)),v.push(" is ")),v.push(...Ee($.field)),v}function D($,p){const v=[],m=$.length===1;return m&&v.push(...it($[0].field.annotations)),v.push(...Se(p,$.map(b=>$e(b,m)))),v}function B($){return Se("order_by",$.map(Y),",")}function Y($){const p=[];return p.push(...G($.field_reference)),$.direction&&(p.push(" "),p.push($.direction)),p}function j($){const p=[],v=$.length===1;return v&&p.push(...it($[0].view.annotations)),p.push(...Se("nest",$.map(m=>W(m,v)))),p}function W($,p=!1){const v=[];return p||v.push(...it($.view.annotations)),$.name&&(v.push((0,u.maybeQuoteIdentifier)($.name)),v.push(" is ")),v.push(...Q($.view)),v}function Q($){return P($.definition)}function ne($){return[`limit: ${$.limit}`]}function re($){const p=[];for(let v=0;v<$.length;v++)v!==0&&p.push(g),p.push(...ne($[v]));return p}function he($){return Se("where",$.map(at),",")}function Ae($){return Se("drill",$.map(at),",")}function _e($){return Se("having",$.map(at),",")}const pe=["`","'",'"'];function ge($){let p,v;for(const m of pe){const b=Ve($,m);if(b===$)return`f${m}${$}${m}`;(v===void 0||b.length<v.length)&&(p=m,v=b)}return`f${p}${v}${p}`}function Ve($,p){let v="";for(let m=0;m<$.length;m++)$.slice(m).startsWith(p)?(v+="\\"+p,m+=p.length):(v+=$[m],$[m]==="\\"&&(v+=$[++m]));return v}function tt($){switch($.kind){case"filter_string":return[...ve($.expression)," ~ ",ge($.filter)];case"literal_equality":return[...ve($.expression)," = ",...w($.value)]}}function at($){return tt($.filter)}function it($){return $?$.flatMap(X):[]}function X($){return[$.value.trim(),g]}return Kt}var Vt={},hn;function as(){if(hn)return Vt;hn=1,Object.defineProperty(Vt,"__esModule",{value:!0}),Vt.nestUnions=M,Vt.unnestUnions=z,Vt.convertFromThrift=V,Vt.convertToThrift=l;const u=An();function M(f){if(f==null)return f;if(typeof f=="string"||typeof f=="number"||typeof f=="boolean")return f;if(Array.isArray(f))return f.map(M);{const c={};let s;for(const d in f)d==="kind"?s=f[d]:c[d]=M(f[d]);return s===void 0?c:{[s]:c}}}function z(f,c){if(f==null)return f;if(typeof f=="string"||typeof f=="number"||typeof f=="boolean")return f;if(Array.isArray(f))return f.map(s=>z(s,c));{const s=g(c);if(s.type==="union"){for(const d in s.options)if(f[d]!==void 0){const e=z(f[d],s.options[d]);if(typeof e=="object")return{kind:d,...e}}}else if(s.type==="struct"){const d={};for(const e in f){const w=s.fields[e];if(w===void 0)throw new Error(`Unknown field ${e} in ${c}`);d[e]=z(f[e],w.type)}return d}else throw new Error(`Cannot unnest unions in an enum type ${c}`)}}function V(f,c){if(f==null)return f;if(typeof f=="string"||typeof f=="boolean")return f;if(typeof f=="number"){if(c==="number")return f;const s=g(c);if(s.type!=="enum")throw new Error(`Found a number where a ${c} was expected`);const d=Object.entries(s.values).find(([,e])=>e===f);if(d===void 0)throw new Error(`${f} is not a valid enum value for ${c}`);return d[0]}else{if(Array.isArray(f))return f.map(s=>V(s,c));{const s=g(c);if(s.type==="union"){for(const d in s.options)if(f[d]!==void 0&&f[d]!==null){const e=V(f[d],s.options[d]);if(typeof e=="object")return{kind:d,...e}}}else if(s.type==="struct"){const d={};for(const e in f){const w=s.fields[e];if(w===void 0)throw new Error(`Unknown field ${e} in ${c}`);d[e]=V(f[e],w.type)}return d}else throw new Error(`Cannot unnest unions in an enum type ${c}`)}}}function g(f){const c=u.MALLOY_INTERFACE_TYPES[f];if(c===void 0)throw new Error(`Unknown Malloy interface type ${f}`);return c}function l(f,c){if(f==null)return f;if(typeof f=="number"||typeof f=="boolean")return f;if(typeof f=="string"){if(c==="string")return f;const s=g(c);if(s.type==="enum"){const d=s.values[f];if(d===void 0)throw new Error(`${f} is not a valid enum value for ${c}`);return d}}else{if(Array.isArray(f))return f.map(s=>l(s,c));{const s=g(c);if(s.type==="union"){const d=f.kind,e=s.options[d];if(e===void 0)throw new Error(`${d} is not a valid union of ${c}`);const w=g(e);if(w.type!=="struct")throw new Error("Union fields must be structs");const E={};for(const x in f){if(x==="kind")continue;const G=w.fields[x];E[x]=l(f[x],G.type)}return{[d]:E}}else if(s.type==="struct"){const d={};for(const e in f){const w=s.fields[e];if(w===void 0)throw new Error(`Unknown field ${e} in ${c}`);d[e]=l(f[e],w.type)}return d}}}}return Vt}var gn;function os(){return gn||(gn=1,(function(u){var M=xt&&xt.__createBinding||(Object.create?(function(l,f,c,s){s===void 0&&(s=c);var d=Object.getOwnPropertyDescriptor(f,c);(!d||("get"in d?!f.__esModule:d.writable||d.configurable))&&(d={enumerable:!0,get:function(){return f[c]}}),Object.defineProperty(l,s,d)}):(function(l,f,c,s){s===void 0&&(s=c),l[s]=f[c]})),z=xt&&xt.__exportStar||function(l,f){for(var c in l)c!=="default"&&!Object.prototype.hasOwnProperty.call(f,c)&&M(f,l,c)};Object.defineProperty(u,"__esModule",{value:!0}),u.thingy4sddfdfsd=u.thingy4sdfsd=u.thingy4dfdsfs=u.thingy4asdfas=u.thingy4asdfasdf=u.thingy3dfdf=u.thingy3=u.thingy2asdf=u.thingyssdfg=u.thingy123r=u.thingy1=u.res=u.test=u.convertToThrift=u.convertFromThrift=u.unnestUnions=u.nestUnions=u.filterToMalloy=u.queryToMalloy=void 0,z(An(),u);var V=ss();Object.defineProperty(u,"queryToMalloy",{enumerable:!0,get:function(){return V.queryToMalloy}}),Object.defineProperty(u,"filterToMalloy",{enumerable:!0,get:function(){return V.filterToMalloy}});var g=as();Object.defineProperty(u,"nestUnions",{enumerable:!0,get:function(){return g.nestUnions}}),Object.defineProperty(u,"unnestUnions",{enumerable:!0,get:function(){return g.unnestUnions}}),Object.defineProperty(u,"convertFromThrift",{enumerable:!0,get:function(){return g.convertFromThrift}}),Object.defineProperty(u,"convertToThrift",{enumerable:!0,get:function(){return g.convertToThrift}}),u.test={entries:[{kind:"source",name:"flights",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"boolean_type"},annotations:[{value:"# foo=1"}]},{kind:"dimension",name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}},{kind:"dimension",name:"arr_rec",type:{kind:"array_type",element_type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}}},{kind:"dimension",name:"rec",type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}},{kind:"join",name:"carriers",relationship:"one",schema:{fields:[{kind:"dimension",name:"code",type:{kind:"string_type"}}]}},{kind:"view",name:"by_carrier",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]}}]},parameters:[{name:"param",type:{kind:"number_type"},default_value:{kind:"number_literal",number_value:7}}]}],anonymous_queries:[]},u.res={connection_name:"foo",data:{kind:"array_cell",array_value:[{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"UA"},{kind:"number_cell",number_value:12341234}]},{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"AA"},{kind:"number_cell",number_value:2343}]}]},schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]},sql:"SELECT * ..."},u.thingy1={definition:{kind:"query_reference",name:"flights_by_carrier"}},u.thingy123r={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},u.thingyssdfg={definition:{kind:"refinement",base:{kind:"query_reference",name:"flights"},refinement:{kind:"view_reference",name:"by_carrier"}}},u.thingy2asdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"where",filter:{kind:"filter_string",expression:{kind:"field_reference",name:"carrier"},filter:"WN"}}]}}}},u.thingy3={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}}},u.thingy3dfdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"view_reference",name:"top10"}}}},u.thingy4asdfasdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}},u.thingy4asdfas={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},u.thingy4dfdsfs={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"limit",limit:10}]}}}},u.thingy4sdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"limit",limit:10}]}}},u.thingy4sddfdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[]}}}})(xt)),xt}var It={},wt={},mn;function ls(){return mn||(mn=1,(function(u){var M=wt&&wt.__createBinding||(Object.create?(function(k,t,a,y){y===void 0&&(y=a);var h=Object.getOwnPropertyDescriptor(t,a);(!h||("get"in h?!t.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(k,y,h)}):(function(k,t,a,y){y===void 0&&(y=a),k[y]=t[a]})),z=wt&&wt.__setModuleDefault||(Object.create?(function(k,t){Object.defineProperty(k,"default",{enumerable:!0,value:t})}):function(k,t){k.default=t}),V=wt&&wt.__importStar||(function(){var k=function(t){return k=Object.getOwnPropertyNames||function(a){var y=[];for(var h in a)Object.prototype.hasOwnProperty.call(a,h)&&(y[y.length]=h);return y},k(t)};return function(t){if(t&&t.__esModule)return t;var a={};if(t!=null)for(var y=k(t),h=0;h<y.length;h++)y[h]!=="default"&&M(a,t,y[h]);return z(a,t),a}})();Object.defineProperty(u,"__esModule",{value:!0}),u.ASTAnnotationList=u.ASTLimitViewOperation=u.ASTView=u.ASTFilterWithLiteralEquality=u.ASTFilterWithFilterString=u.ASTFilter=u.ASTCalculateViewOperation=u.ASTHavingViewOperation=u.ASTDrillViewOperation=u.ASTWhereViewOperation=u.ASTNestViewOperation=u.ASTFilteredFieldExpression=u.ASTFilterOperationList=u.ASTFilterOperation=u.ASTMovingAverageExpression=u.ASTFieldReferenceList=u.ASTLiteralValueExpression=u.ASTTimeTruncationExpression=u.ASTReferenceExpression=u.ASTExpression=u.ASTField=u.ASTAggregateViewOperation=u.ASTGroupByViewOperation=u.ASTOrderByViewOperation=u.ASTViewOperation=u.ASTViewOperationList=u.ASTSegmentViewDefinition=u.ASTRefinementViewDefinition=u.ASTArrowViewDefinition=u.ASTReferenceViewDefinition=u.ASTReferenceQueryArrowSource=u.ASTReferenceQueryDefinition=u.ASTRefinementQueryDefinition=u.ASTArrowQueryDefinition=u.ASTQueryDefinition=u.ASTQueryArrowSource=u.ASTUnimplemented=u.ASTFilterExpressionLiteralValue=u.ASTTimestampLiteralValue=u.ASTDateLiteralValue=u.ASTBooleanLiteralValue=u.ASTNumberLiteralValue=u.ASTNullLiteralValue=u.ASTStringLiteralValue=u.ASTLiteralValue=u.ASTParameterValue=u.ASTParameterValueList=u.ASTFieldReference=u.ASTReference=u.ASTQuery=void 0,u.ASTAnnotation=void 0;const g=V(os()),l=Yi(),f=V(rs());class c{constructor(){this.edited=!1}edit(){return this.edited=!0,this._parent&&this._parent.edit(),this}get as(){const t=this;return{Query(){if(t instanceof w)return t;throw new Error("Not an ASTQuery")},Reference(){if(t instanceof E)return t;throw new Error("Not an ASTReference")},ReferenceQueryArrowSource(){if(t instanceof B)return t;throw new Error("Not an ASTReferenceQueryArrowSource")},ParameterValueList(){if(t instanceof G)return t;throw new Error("Not an ASTParameterValueList")},FilterOperation(){if(t instanceof p)return t;throw new Error("Not an ASTFilterOperation")},FilterOperationList(){if(t instanceof v)return t;throw new Error("Not an ASTFilterOperationList")},ParameterValue(){if(t instanceof oe)return t;throw new Error("Not an ASTParameterValue")},StringLiteralValue(){if(t instanceof C)return t;throw new Error("Not an ASTStringLiteralValue")},NumberLiteralValue(){if(t instanceof P)return t;throw new Error("Not an ASTNumberLiteralValue")},ViewOperationList(){if(t instanceof Ae)return t;throw new Error("Not an ASTViewOperationList")},GroupByViewOperation(){if(t instanceof pe)return t;throw new Error("Not an ASTGroupByViewOperation")},AggregateViewOperation(){if(t instanceof ge)return t;throw new Error("Not an ASTAggregateViewOperation")},OrderByViewOperation(){if(t instanceof _e)return t;throw new Error("Not an ASTOrderByViewOperation")},Field(){if(t instanceof Ve)return t;throw new Error("Not an ASTField")},ReferenceExpression(){if(t instanceof tt)return t;throw new Error("Not an ASTReferenceExpression")},ReferenceViewDefinition(){if(t instanceof Q)return t;throw new Error("Not an ASTReferenceViewDefinition")},ArrowQueryDefinition(){if(t instanceof ve)return t;throw new Error("Not an ASTArrowQueryDefinition")},ArrowViewDefinition(){if(t instanceof ne)return t;throw new Error("Not an ASTArrowViewDefinition")},RefinementViewDefinition(){if(t instanceof re)return t;throw new Error("Not an ASTRefinementViewDefinition")},TimeTruncationExpression(){if(t instanceof at)return t;throw new Error("Not an ASTTimeTruncationExpression")},FilteredFieldExpression(){if(t instanceof m)return t;throw new Error("Not an ASTFilteredFieldExpression")},NestViewOperation(){if(t instanceof A)return t;throw new Error("Not an ASTNestViewOperation")},View(){if(t instanceof le)return t;throw new Error("Not an ASTView")},SegmentViewDefinition(){if(t instanceof he)return t;throw new Error("Not an ASTSegmentViewDefinition")},LimitViewOperation(){if(t instanceof Fe)return t;throw new Error("Not an ASTLimitViewOperation")},AnnotationList(){if(t instanceof Ne)return t;throw new Error("Not an ASTAnnotationList")},Annotation(){if(t instanceof ze)return t;throw new Error("Not an ASTAnnotation")}}}get find(){const t=this;return{Query(a){return t.findAny(a).as.Query()},Reference(a){return t.findAny(a).as.Reference()},ReferenceQueryArrowSource(a){return t.findAny(a).as.ReferenceQueryArrowSource()},ParameterValueList(a){return t.findAny(a).as.ParameterValueList()},FilterOperation(a){return t.findAny(a).as.FilterOperation()},FilterOperationList(a){return t.findAny(a).as.FilterOperationList()},ParameterValue(a){return t.findAny(a).as.ParameterValue()},StringLiteralValue(a){return t.findAny(a).as.StringLiteralValue()},NumberLiteralValue(a){return t.findAny(a).as.NumberLiteralValue()},ViewOperationList(a){return t.findAny(a).as.ViewOperationList()},GroupByViewOperation(a){return t.findAny(a).as.GroupByViewOperation()},AggregateViewOperation(a){return t.findAny(a).as.AggregateViewOperation()},OrderByViewOperation(a){return t.findAny(a).as.OrderByViewOperation()},Field(a){return t.findAny(a).as.Field()},ReferenceExpression(a){return t.findAny(a).as.ReferenceExpression()},ReferenceViewDefinition(a){return t.findAny(a).as.ReferenceViewDefinition()},ArrowQueryDefinition(a){return t.findAny(a).as.ArrowQueryDefinition()},ArrowViewDefinition(a){return t.findAny(a).as.ArrowViewDefinition()},RefinementViewDefinition(a){return t.findAny(a).as.RefinementViewDefinition()},TimeTruncationExpression(a){return t.findAny(a).as.TimeTruncationExpression()},FilteredFieldExpression(a){return t.findAny(a).as.FilteredFieldExpression()},NestViewOperation(a){return t.findAny(a).as.NestViewOperation()},View(a){return t.findAny(a).as.View()},SegmentViewDefinition(a){return t.findAny(a).as.SegmentViewDefinition()},LimitViewOperation(a){return t.findAny(a).as.LimitViewOperation()},AnnotationList(a){return t.findAny(a).as.AnnotationList()},Annotation(a){return t.findAny(a).as.Annotation()}}}get parent(){if(this._parent===void 0)throw new Error("This node does not have a parent");return this._parent}set parent(t){this._parent=t}static schemaTryGet(t,a,y){return c._schemaTryGet(t,a,y,!1)}static schemaTryGetDrillField(t,a,y){return c._schemaTryGet(t,a,y,!0)}static _schemaTryGet(t,a,y,h){let J=t.fields;for(const Le of y??[]){const Z=J.find(Me=>Me.name===Le);if(Z===void 0)throw new Error(`${Le} not found`);if(Z.kind==="join"||h&&Z.kind==="view"){J=Z.schema.fields;continue}if(Z.kind==="dimension"||Z.kind==="measure"){if(Z.type.kind==="record_type"){J=Z.type.fields.map(Me=>({kind:Z.kind,...Me}));continue}else if(Z.type.kind==="array_type"&&Z.type.element_type.kind==="record_type"){J=Z.type.element_type.fields.map(Me=>({kind:Z.kind,...Me}));continue}}throw new Error(`${Le} is not a join, record, or repeated record`)}return J.find(Le=>Le.name===a)}static schemaGet(t,a,y){const h=c.schemaTryGet(t,a,y);if(h===void 0)throw new Error(`${a} not found`);return h}static schemaGetDrillField(t,a,y){const h=c.schemaTryGetDrillField(t,a,y);if(h===void 0)throw new Error(`${a} not found`);return h}static schemaMerge(t,a){return{fields:[...t.fields,...a.fields]}}static tagFor(t,a="# "){var y,h;const J=(h=(y=t.annotations)===null||y===void 0?void 0:y.map(Le=>Le.value))===null||h===void 0?void 0:h.filter(Le=>Le.startsWith(a)),me=new l.TagParser;for(const Le of J??[])me.parseAnnotation(Le);return me.finish()}static fieldWasCalculation(t){if(t.kind!=="dimension")throw new Error(`${t.name} could not be an output field, because it is a ${t.kind}, and only dimensions can appear in output schemas`);return c.tagFor(t,"#(malloy) ").has("calculation")}}function s(k){return Array.isArray(k)||typeof k=="string"||typeof k=="number"||typeof k=="boolean"}class d extends c{constructor(t,a){super(),this.node=t,this.children=a,this.originalChildren=[...a],a.forEach(y=>y.parent=this)}*iter(){for(let t=0;t<this.length;t++)yield this.index(t)}get length(){return this.children.length}get last(){return this.children[this.children.length-1]}index(t){return this.children[t]}insert(t,a){this.edit(),this.children.splice(a,0,t),t.parent=this}add(t){this.edit(),this.children.push(t),t.parent=this}remove(t){const a=this.children.findIndex(y=>y===t);if(a===-1)return this;this.edit(),this.children.splice(a,1)}build(){if(!this.edited)return this.node;const t=this.children.map(a=>a.build());return this.edited=!1,this.originalChildren=[...this.children],this.node=t,t}findAny(t){if(t.length===0)return this;const[a,...y]=t;if(typeof a!="number")throw new Error(`${this.constructor.name} is a ASTListNode and thus cannot contain a ${a}`);return this.children[a].findAny(y)}findIndex(t){return this.children.findIndex(t)}indexOf(t){return this.children.indexOf(t)}}class e extends c{constructor(t,a){super(),this.node=t,this.children=a;for(const y in a){const h=a[y];h&&!s(h)&&(h.parent=this)}}build(){if(!this.edited)return this.node;let t=this.node;for(const a in this.children){const y=this.children[a];y===void 0?t={...t,[a]:void 0}:s(y)?this.edited&&(t={...t,[a]:y}):t={...t,[a]:y.build()}}return this.node=t,this.edited=!1,t}findAny(t){if(t.length===0)return this;const[a,...y]=t;if(typeof a!="string")throw new Error(`${this.constructor.name} is a ASTListNode and thus cannot contain a ${a}`);const h=this.children[a];if(s(h))throw new Error(`${this.constructor.name}.${a} refers to a basic type, not an ASTNode`);return h._find(y)}}class w extends e{constructor(t){var a,y;let h=t.source;if(h===void 0){if(t.model===void 0)throw new Error("Need a model or source");if(t.query){const Z=t.query.definition;if(Z.kind==="arrow"&&Z.source.kind==="source_reference"){const Me=Z.source.name;if(h=t.model.entries.find(Ke=>Ke.name===Me),h===void 0)throw new Error(`Model does not contain source or query named ${Me}`)}}if(h===void 0&&(h=t.model.entries[0]),h===void 0)throw new Error("Model does not contain any sources or queries")}const J=te(h),me=(a=t.query)!==null&&a!==void 0?a:{definition:{kind:"arrow",source:{kind:"source_reference",name:J.name},view:{kind:"segment",operations:[]}}},Le=(y=t.model)!==null&&y!==void 0?y:{entries:[J],anonymous_queries:[]};super(me,{definition:u.ASTQueryDefinition.from(me.definition),annotations:me.annotations&&new Ne(me.annotations)}),this.model=Le,t.source&&this.setSource(t.source.name)}get definition(){return this.children.definition}set definition(t){this.edit(),this.children.definition=t,t.parent=this}get annotations(){return this.children.annotations}reorderFields(t){this.definition.reorderFields(t)}getOrAddAnnotations(){if(this.annotations)return this.annotations;this.edit();const t=new Ne([]);return this.children.annotations=t,t.parent=this,t}getInheritedTag(t="# "){return He(t,this.getInheritedAnnotations())}getIntrinsicTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getIntrinsicTag(t))!==null&&y!==void 0?y:new l.Tag}getTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getTag(t))!==null&&y!==void 0?y:this.getInheritedTag(t)}setTagProperty(t,a=null,y="# "){this.getOrAddAnnotations().setTagProperty(t,a,y)}removeTagProperty(t,a="# "){this.getTag().has(...t)&&this.getOrAddAnnotations().removeTagProperty(t,a)}setViewToEmptySegment(){if(!(this.definition instanceof ve))throw new Error("Must set source before setting view");return this.definition=new ve({kind:"arrow",source:this.definition.source.build(),view:{kind:"segment",operations:[]}}),this.definition.view.as.SegmentViewDefinition()}isRunnable(){return this.definition.isRunnable()}isEmpty(){return this.definition instanceof ve&&this.definition.view instanceof he&&this.definition.view.operations.length===0}getOrAddDefaultSegment(){return this.definition.getOrAddDefaultSegment()}setSource(t){if(this.definition instanceof ve&&this.definition.source instanceof B&&this.definition.source.name===t)return;if(this.model.entries.find(y=>y.name===t)===void 0)throw new Error(`Source ${t} is not defined in model`);this.definition=new ve({kind:"arrow",source:{kind:"source_reference",name:t},view:this.definition instanceof ve?this.definition.view.build():{kind:"segment",operations:[]}})}setQueryHead(t){const a=this.model.entries.find(y=>y.name===t);if(a===void 0||a.kind!=="query")throw new Error(`No query named ${t} in the model`);this.definition=new D({kind:"query_reference",name:t})}getQueryInfo(t){const a=this.model.entries.find(y=>y.name===t);if(a===void 0)throw new Error(`Query ${t} is not defined in model`);if(a.kind!=="query")throw new Error(`Model entry ${t} is not a query`);return a}toMalloy(){return g.queryToMalloy(this.build())}build(){return super.build()}setView(t){if(!(this.definition instanceof ve))throw new Error("Must set source before setting view");return this.definition=new ve({kind:"arrow",source:this.definition.source.build(),view:{kind:"view_reference",name:t}}),this.definition.view.as.ReferenceViewDefinition()}_getInheritedAnnotations(t){var a;return t instanceof D?(a=this.getQueryInfo(t.name).annotations)!==null&&a!==void 0?a:[]:t instanceof $e?this._getInheritedAnnotations(t.base):t instanceof ve?t.view.getInheritedAnnotations():[]}getInheritedAnnotations(){return this._getInheritedAnnotations(this.definition)}}u.ASTQuery=w;class E extends e{constructor(t){super(t,{name:t.name,path:t.path,parameters:t.parameters&&new G(t.parameters)}),this.reference=t}get name(){return this.children.name}set name(t){this.edit(),this.children.name=t}get parameters(){return this.children.parameters}set parameters(t){this.edit(),this.children.parameters=t}get path(){return this.children.path}static getOrAddParameters(t){if(t.parameters)return t.parameters;t.edit();const a=new G([]);return t.parameters=a,a}static setParameter(t,a,y){const h=E.tryGetParameter(t,a);if(h!==void 0){h.value=u.ASTLiteralValue.from(u.ASTLiteralValue.makeLiteral(y));return}return t.getOrAddParameters().addParameter(a,y)}static tryGetParameter(t,a){if(t.parameters!==void 0){for(const y of t.parameters.iter())if(y.name===a)return y}}getOrAddParameters(){return E.getOrAddParameters(this)}setParameter(t,a){return E.setParameter(this,t,a)}tryGetParameter(t){return E.tryGetParameter(this,t)}}u.ASTReference=E;class x extends E{get segment(){const t=this.parent;return t instanceof m||t instanceof at?t.field.segment:t instanceof H||t instanceof ae?t.segment:t.list.segment}getReferenceSchema(){return this.parent instanceof _e?this.segment.getOutputSchema():this.segment.getInputSchema()}getFieldInfo(){const t=this.getReferenceSchema();return c.schemaGet(t,this.name,this.path)}}u.ASTFieldReference=x;class G extends d{constructor(t){super(t,t.map(a=>new oe(a)))}get parameters(){return this.children}addParameter(t,a){this.add(new oe({name:t,value:u.ASTLiteralValue.makeLiteral(a)}))}}u.ASTParameterValueList=G;class oe extends e{constructor(t){super(t,{name:t.name,value:u.ASTLiteralValue.from(t.value)}),this.parameter=t}get name(){return this.children.name}get value(){return this.children.value}set value(t){this.edit(),this.children.value=t}}u.ASTParameterValue=oe,u.ASTLiteralValue={from(k){switch(k.kind){case"string_literal":return new C(k);case"number_literal":return new P(k);case"boolean_literal":return new N(k);case"date_literal":return new ye(k);case"timestamp_literal":return new Se(k);case"null_literal":return new R(k);case"filter_expression_literal":return new Ee(k)}},makeLiteral(k){if(k!==null&&typeof k=="object"&&"kind"in k)return k;if(typeof k=="string")return{kind:"string_literal",string_value:k};if(typeof k=="boolean")return{kind:"boolean_literal",boolean_value:k};if(typeof k=="number")return{kind:"number_literal",number_value:k};if(k===null)return{kind:"null_literal"};if("date"in k){const t=k.granularity,a=De(k.date);return Re(t)?{kind:"date_literal",date_value:a,granularity:t}:{kind:"timestamp_literal",timestamp_value:a,granularity:t}}throw new Error("Unknown literal type")}};class C extends e{constructor(t){super(t,{kind:t.kind,string_value:t.string_value}),this.node=t,this.kind="string_literal"}get fieldType(){return{kind:"string_type"}}}u.ASTStringLiteralValue=C;class R extends e{constructor(t){super(t,{kind:t.kind}),this.node=t,this.kind="null_literal"}get fieldType(){}}u.ASTNullLiteralValue=R;class P extends e{constructor(t){super(t,{kind:t.kind,number_value:t.number_value}),this.node=t,this.kind="number_literal"}get fieldType(){return{kind:"number_type",subtype:Number.isInteger(this.children.number_value)?"integer":"decimal"}}}u.ASTNumberLiteralValue=P;class N extends e{constructor(t){super(t,{kind:t.kind,boolean_value:t.boolean_value}),this.node=t,this.kind="boolean_literal"}get fieldType(){return{kind:"boolean_type"}}}u.ASTBooleanLiteralValue=N;class ye extends e{constructor(t){super(t,{kind:t.kind,date_value:t.date_value,granularity:t.granularity}),this.node=t,this.kind="date_literal"}get fieldType(){return{kind:"date_type",timeframe:this.children.granularity}}}u.ASTDateLiteralValue=ye;class Se extends e{constructor(t){super(t,{kind:t.kind,timestamp_value:t.timestamp_value,granularity:t.granularity}),this.node=t,this.kind="timestamp_literal"}get fieldType(){return{kind:"timestamp_type",timeframe:this.children.granularity}}}u.ASTTimestampLiteralValue=Se;class Ee extends e{constructor(t){super(t,{kind:t.kind,filter_expression_value:t.filter_expression_value}),this.node=t,this.kind="filter_expression_literal"}get fieldType(){}}u.ASTFilterExpressionLiteralValue=Ee;class xe extends c{constructor(t){super(),this.node=t}get treeEdited(){return!1}build(){return this.node}findAny(){throw new Error("Tried to find a node from an unimplemented node type")}}u.ASTUnimplemented=xe,u.ASTQueryArrowSource={from(k){switch(k.kind){case"refinement":return new $e(k);case"source_reference":return new B(k)}}},u.ASTQueryDefinition={from(k){switch(k.kind){case"arrow":return new ve(k);case"query_reference":return new D(k);case"refinement":return new $e(k)}}};class ve extends e{constructor(t){super(t,{kind:"arrow",source:u.ASTQueryArrowSource.from(t.source),view:Y.from(t.view)}),this.node=t}get view(){return this.children.view}set view(t){this.edit(),this.children.view=t,t.parent=this}get source(){return this.children.source}set source(t){this.edit(),this.children.source=t}getOrAddDefaultSegment(){return this.view.getOrAddDefaultSegment()}getSourceInfo(){return this.source.getSourceInfo()}getOutputSchema(){return this.view.getRefinementSchema()}isRunnable(){return this.view.isRunnable()&&this.source.isRunnable()}get query(){return this.parent.as.Query()}propagateUp(t){this.propagateDown(t)}propagateDown(t){t(this.view),this.view.propagateDown(t)}reorderFields(t){this.view instanceof he?this.view.reorderFields(t):this.query.getOrAddAnnotations().setTagProperty(["field_order"],t)}}u.ASTArrowQueryDefinition=ve;class $e extends e{constructor(t){super(t,{kind:"refinement",base:u.ASTQueryDefinition.from(t.base),refinement:Y.from(t.refinement)}),this.node=t}get base(){return this.children.base}get refinement(){return this.children.refinement}set refinement(t){this.edit(),this.children.refinement=t,t.parent=this}isRunnable(){return!0}get query(){return this.parent.as.Query()}getOrAddDefaultSegment(){return this.refinement.getOrAddDefaultSegment()}getOutputSchema(){const t=this.base.getOutputSchema(),a=this.refinement.getRefinementSchema();return w.schemaMerge(t,a)}propagateUp(t){this.propagateDown(t)}propagateDown(t){t(this.refinement),this.refinement.propagateDown(t)}reorderFields(t){this.query.getOrAddAnnotations().setTagProperty(["field_order"],t)}getSourceInfo(){return this.base.getSourceInfo()}}u.ASTRefinementQueryDefinition=$e;class D extends e{constructor(t){super(t,{kind:"query_reference",name:t.name,path:t.path,parameters:t.parameters&&new G(t.parameters)}),this.node=t}isRunnable(){return!0}get name(){return this.children.name}get query(){return this.parent.as.Query()}get parameters(){return this.children.parameters}set parameters(t){this.edit(),this.children.parameters=t}get path(){return this.children.path}getOrAddDefaultSegment(){const t=new $e({kind:"refinement",base:this.build(),refinement:{kind:"segment",operations:[]}});return this.query.definition=t,t.refinement.as.SegmentViewDefinition()}propagateUp(t){}propagateDown(t){}reorderFields(t){this.query.getOrAddAnnotations().setTagProperty(["field_order"],t)}getOrAddParameters(){return E.getOrAddParameters(this)}setParameter(t,a){return E.setParameter(this,t,a)}tryGetParameter(t){return E.tryGetParameter(this,t)}getOutputSchema(){return this.getSourceInfo().schema}getSourceInfo(){const a=this.query.model.entries.find(y=>y.name===this.name);if(a===void 0)throw new Error(`Query not found with name ${this.name}`);return a}}u.ASTReferenceQueryDefinition=D;class B extends e{constructor(t){super(t,{kind:"source_reference",name:t.name,path:t.path,parameters:t.parameters&&new G(t.parameters)}),this.node=t}isRunnable(){return this.areRequiredParametersSet()}get name(){return this.children.name}get arrow(){return this.parent.as.ArrowQueryDefinition()}get parameters(){return this.children.parameters}set parameters(t){this.edit(),this.children.parameters=t}get path(){return this.children.path}getSourceInfo(){const t=this.arrow.query.model.entries.find(a=>a.name===this.name);if(t===void 0)throw new Error(`No query or source named ${this.name}`);return t}getOrAddDefaultSegment(){if(this.getSourceInfo().kind!=="query")throw new Error(`Cannot refine source ${this.name}`);const a=new $e({kind:"refinement",base:{...this.build(),kind:"query_reference"},refinement:{kind:"segment",operations:[]}});return this.arrow.source=a,a.refinement.as.SegmentViewDefinition()}propagateUp(t){}propagateDown(t){}getOrAddParameters(){return E.getOrAddParameters(this)}setParameter(t,a){return E.setParameter(this,t,a)}tryGetParameter(t){return E.tryGetParameter(this,t)}get query(){return this.parent.parent.as.Query()}getSourceParameters(){var t;const a=this.getSourceInfo();return a.kind==="query"?[]:(t=a.parameters)!==null&&t!==void 0?t:[]}areRequiredParametersSet(){const t=this.getSourceParameters();for(const a of t){if(a.default_value!==void 0)continue;if(this.tryGetParameter(a.name)===void 0)return!1}return!0}}u.ASTReferenceQueryArrowSource=B;const Y={from(k){switch(k.kind){case"arrow":return new ne(k);case"view_reference":return new Q(k);case"segment":return new he(k);case"refinement":return new re(k)}}};function j(k,t){const a=k.parent;a instanceof ve?a.view=t:a instanceof $e?a.refinement=t:a instanceof le?a.definition=t:a instanceof ne?a.source===k?a.source=t:a.view=t:a.base===k?a.base=t:a.refinement=t}function W(k,t,a=[]){const y=k.getInputSchema(),h=w.schemaGet(y,t,a);if(h===void 0)return{isValidViewRefinement:!1,error:`${t} is not defined`};if(h.kind!=="view")return{isValidViewRefinement:!1,error:`${t} is not a view`};const J=k.getOutputSchema();for(const me of h.schema.fields)if(w.schemaTryGet(J,me.name,[]))return{isValidViewRefinement:!1,error:`Cannot refine with ${t} because stage already has an output field named ${me.name}`};return{isValidViewRefinement:!0}}class Q extends e{constructor(t){super(t,{kind:"view_reference",name:t.name,path:t.path,parameters:t.parameters&&new G(t.parameters)}),this.node=t}isRunnable(){return!0}get name(){return this.children.name}get path(){return this.children.path}get parameters(){return this.children.parameters}set parameters(t){this.edit(),this.children.parameters=t}getOrAddDefaultSegment(){return this.addEmptyRefinement()}addEmptyRefinement(){const t=re.segmentRefinementOf(this.build());return j(this,t),t.refinement.as.SegmentViewDefinition()}addViewRefinement(t,a){const{error:y}=this.isValidViewRefinement(t,a);if(y)throw new Error(y);const h=re.viewRefinementOf(this.build(),t,a);return j(this,h),h.refinement.as.ReferenceViewDefinition()}convertToNest(t){const a=Y.from({kind:"segment",operations:[{kind:"nest",name:t,view:{definition:this.build()}}]});j(this,a)}isValidViewRefinement(t,a){return W(this,t,a)}getInputSchema(){return kt(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getImplicitName(){return this.name}getViewInfo(){const t=this.getInputSchema(),a=c.schemaGet(t,this.name,this.path);if(a.kind!=="view")throw new Error("Not a view");return a}getRefinementSchema(){return this.getViewInfo().schema}propagateUp(t){this.parent.propagateUp(t)}propagateDown(t){}getInheritedAnnotations(){var t;return(t=this.getViewInfo().annotations)!==null&&t!==void 0?t:[]}getOrAddParameters(){return E.getOrAddParameters(this)}setParameter(t,a){return E.setParameter(this,t,a)}tryGetParameter(t){return E.tryGetParameter(this,t)}}u.ASTReferenceViewDefinition=Q;class ne extends e{constructor(t){super(t,{kind:"arrow",source:Y.from(t.source),view:Y.from(t.view)}),this.node=t}isRunnable(){return this.source.isRunnable()&&this.view.isRunnable()}get source(){return this.children.source}set source(t){this.edit(),this.children.source=t}get view(){return this.children.view}set view(t){this.edit(),this.children.view=t,t.parent=this}getOrAddDefaultSegment(){return this.view.getOrAddDefaultSegment()}addEmptyRefinement(){return this.view.addEmptyRefinement()}addViewRefinement(t,a){return this.view.addViewRefinement(t,a)}convertToNest(t){const a=Y.from({kind:"segment",operations:[{kind:"nest",name:t,view:{definition:this.build()}}]});j(this,a)}getInputSchema(){return this.source.getOutputSchema()}getOutputSchema(){return this.view.getRefinementSchema()}getImplicitName(){return this.view.getImplicitName()}getRefinementSchema(){throw new Error("An arrow is not a valid refinement")}isValidViewRefinement(t,a){return W(this,t,a)}propagateUp(t){this.propagateDown(t)}propagateDown(t){t(this.view),this.view.propagateDown(t)}getInheritedAnnotations(){return[]}}u.ASTArrowViewDefinition=ne;class re extends e{constructor(t){super(t,{kind:"refinement",base:Y.from(t.base),refinement:Y.from(t.refinement)}),this.node=t}isRunnable(){return this.getOutputSchema().fields.length>0}get refinement(){return this.children.refinement}set refinement(t){this.edit(),this.children.refinement=t,t.parent=this}get base(){return this.children.base}set base(t){this.edit(),this.children.base=t}convertToNest(t){const a=Y.from({kind:"segment",operations:[{kind:"nest",name:t,view:{definition:this.build()}}]});j(this,a)}getOrAddDefaultSegment(){return this.refinement.getOrAddDefaultSegment()}addEmptyRefinement(){return this.refinement.addEmptyRefinement()}addViewRefinement(t,a){return this.refinement.addViewRefinement(t,a)}getInputSchema(){return kt(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getRefinementSchema(){return c.schemaMerge(this.base.getRefinementSchema(),this.refinement.getRefinementSchema())}getImplicitName(){return this.base.getImplicitName()}isValidViewRefinement(t,a){return W(this,t,a)}propagateUp(t){this.parent.propagateUp(t)}propagateDown(t){t(this.base),t(this.refinement),this.base.propagateDown(t),this.refinement.propagateDown(t)}getInheritedAnnotations(){return this.base.getInheritedAnnotations()}static viewRefinementOf(t,a,y){return new re({kind:"refinement",base:t,refinement:{kind:"view_reference",name:a,path:y}})}static segmentRefinementOf(t){return new re({kind:"refinement",base:t,refinement:{kind:"segment",operations:[]}})}}u.ASTRefinementViewDefinition=re;class he extends e{constructor(t){super(t,{kind:"segment",operations:new Ae(t.operations)}),this.node=t,this.DEFAULT_INSERTION_ORDER=["group_by","aggregate","drill","where","having","nest","order_by","calculate","limit"]}isRunnable(){let t=!1;for(const a of this.operations.iter()){if(a instanceof ge||a instanceof pe)return!0;if(a instanceof A){if(!a.view.definition.isRunnable())return!1;t=!0}}return t}get operations(){return this.children.operations}convertToNest(t){const a=Y.from({kind:"segment",operations:[{kind:"nest",name:t,view:{definition:this.build()}}]});j(this,a)}renameOrderBys(t,a){for(const y of this.operations.iter())y instanceof _e&&y.name===t&&y.setField(a)}propagateUp(t){this.parent.propagateUp(t)}propagateDown(t){}removeOrderBys(t){for(const a of this.operations.iter())a instanceof _e&&a.name===t&&a.delete()}reorderFields(t){const a=[],y=[],h={};let J=!1;for(const Z of this.operations.iter()){if((Z instanceof ge||Z instanceof pe||Z instanceof A)&&t.includes(Z.name)){h[Z.name]=Z,J=!0;continue}J?y.push(Z):a.push(Z)}const me=[];for(const Z of t){const Me=h[Z];if(Me===void 0)throw new Error(`No field named ${Z}`);me.push(Me)}const Le=[...a,...me,...y];this.operations.items=Le}renameField(t,a){if(t.name===a)return;const y=this.getOutputSchema();if(c.schemaTryGet(y,a,[]))throw new Error(`Output already has a field named ${a}`);const h=t.name;t.name=a,this.propagateUp(J=>{J instanceof he&&J.renameOrderBys(h,a)})}addOrderBy(t,a){const y=this.getOutputSchema();try{c.schemaGet(y,t,[])}catch{throw new Error(`No such field ${t} in stage output`)}for(const J of this.operations.iter())if(J instanceof _e&&J.name===t)return J.direction=a,J;const h=new _e({kind:"order_by",field_reference:{name:t},direction:a});return this.addOperation(h),h}addEmptyNest(t){const a=new A({kind:"nest",name:t,view:{definition:{kind:"segment",operations:[]}}});return this.addOperation(a),a}firstIndexOfOperationType(t){return this.operations.findIndex(a=>a.kind===t)}findInsertionPoint(t){const a=this.firstIndexOfOperationType(t);if(a>-1){let J=a;for(;this.operations.index(J)&&this.operations.index(J).kind===t;)J++;return J}const y=this.DEFAULT_INSERTION_ORDER.indexOf(t);if(y===-1)throw new Error(`Operation ${t} is not supported for \`findInsertionPoint\``);const h=this.DEFAULT_INSERTION_ORDER.slice(y+1);for(const J of h){const me=this.firstIndexOfOperationType(J);if(me>-1)return me}return this.operations.length}getFieldNamed(t){const a=this.tryGetFieldNamed(t);if(a===void 0)throw new Error("No such field");return a}hasFieldNamed(t){return this.tryGetFieldNamed(t)!==void 0}hasField(t,a){return this.tryGetField(t,a)!==void 0}getField(t,a){const y=this.tryGetField(t,a);if(y===void 0)throw new Error("No such field");return y}tryGetField(t,a){for(const y of this.operations.iter())if(y instanceof pe||y instanceof ge){const h=y.field.getReference();if(h&&h.name===t&&Ye(h.path,a))return y}else if(y instanceof A){if(y.view instanceof Q)return y}else if(y instanceof F){const h=y.expression.field.getReference();if(h&&h.name===t&&Ye(h.path,a))return y}}tryGetFieldNamed(t){for(const a of this.operations.iter())if((a instanceof pe||a instanceof ge||a instanceof A||a instanceof F)&&a.name===t)return a}getGroupBy(t){for(const a of this.operations.iter())if(a instanceof pe&&a.name===t)return a}removeGroupBy(t){var a;return(a=this.getGroupBy(t))===null||a===void 0||a.delete(),this}addGroupBy(t,a=[],y){const h=this.makeField(t,a,y,"dimension");return this.addOperation(h),h}addDrill(t){const a=new U({kind:"drill",...t});return this.addOperation(a),a}addWhere(t,a,y){const h=Array.isArray(a)?a:[],J=y===void 0?a:y,me=typeof J=="string"?J:Je(J),Le=this.getInputSchema(),Z=w.schemaGet(Le,t,h);lt(Z,J);const Me=new L({kind:"where",filter:{kind:"filter_string",expression:{kind:"field_reference",name:t,path:h},filter:me}});return this.addOperation(Me),Me}addHaving(t,a,y){const h=Array.isArray(a)?a:[],J=y===void 0?a:y,me=typeof J=="string"?J:Je(J),Le=this.getInputSchema(),Z=w.schemaGet(Le,t,h);lt(Z,J);const Me=new K({kind:"having",filter:{kind:"filter_string",expression:{kind:"field_reference",name:t,path:h},filter:me}});return this.addOperation(Me),Me}addCalculateMovingAverage(t,a,y,h,J){const me=new F({kind:"calculate",name:t,field:{expression:{kind:"moving_average",field_reference:{name:a,path:y},rows_preceding:h,rows_following:J}}});return this.addOperation(me),me}addTimeGroupBy(t,a,y,h){const J=this.getInputSchema(),me=c.schemaGet(J,t,a);if(me===void 0)throw new Error(`No such field ${t}`);if(me.kind!=="dimension")throw new Error(`Cannot group by non-dimension ${t}`);if(me.type.kind!==h)throw new Error(`${t} is not a ${h}`);const Le=new pe({kind:"group_by",field:{expression:{kind:"time_truncation",field_reference:{name:t,path:a},truncation:y}}});return this.addOperation(Le),Le}addDateGroupBy(t,a,y){const h=y===void 0?a:y,J=y===void 0?[]:a;return this.addTimeGroupBy(t,J,h,"date_type")}addTimestampGroupBy(t,a,y){const h=y===void 0?a:y,J=y===void 0?[]:a;return this.addTimeGroupBy(t,J,h,"timestamp_type")}addTimestamptzGroupBy(t,a,y){const h=y===void 0?a:y,J=y===void 0?[]:a;return this.addTimeGroupBy(t,J,h,"timestamptz_type")}addAggregate(t,a=[],y){const h=this.makeField(t,a,y,"measure");return this.addOperation(h),h}addNest(t,a){const y=this.makeField(t,[],a,"view");return this.addOperation(y),y}makeField(t,a,y,h){const J=this.getInputSchema(),me=c.schemaGet(J,t,a);if(me===void 0)throw new Error(`No such field ${t}`);if(me.kind!==h){const Le=Ue(h),Z=h;throw new Error(`Cannot ${Le} non-${Z} ${t}`)}return h==="dimension"?pe.fromReference(t,a,y):h==="measure"?ge.fromReference(t,a,y):A.fromReference(t,a,y)}addOperation(t){if((t instanceof pe||t instanceof ge||t instanceof A||t instanceof F)&&this.hasFieldNamed(t.name))throw new Error(`Query already has a field named ${t.name}`);const a=this.findInsertionPoint(t.kind);return this.operations.insert(t,a),t}getRefinementSchema(){const t=[];for(const a of this.operations.iter())(a instanceof pe||a instanceof ge||a instanceof A||a instanceof F)&&t.push(a.getFieldInfo());return{fields:t}}setLimit(t){Fe.validateLimit(t);const a=[...this.operations.iter()].find(u.ASTViewOperation.isLimit);a?a.limit=t:this.operations.add(new Fe({kind:"limit",limit:t}))}getOrAddDefaultSegment(){return this}addEmptyRefinement(){const t=re.segmentRefinementOf(this.build());return j(this,t),t.refinement.as.SegmentViewDefinition()}addViewRefinement(t,a){const{error:y}=this.isValidViewRefinement(t,a);if(y)throw new Error(y);const h=re.viewRefinementOf(this.build(),t,a);return j(this,h),h.refinement.as.ReferenceViewDefinition()}getInputSchema(){return kt(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getImplicitName(){}isValidViewRefinement(t,a){return W(this,t,a)}getInheritedAnnotations(){return[]}}u.ASTSegmentViewDefinition=he;class Ae extends d{constructor(t){super(t,t.map(a=>u.ASTViewOperation.from(a)))}get items(){return this.children}set items(t){this.edit(),this.children=t}get segment(){return this.parent.as.SegmentViewDefinition()}}u.ASTViewOperationList=Ae,u.ASTViewOperation={from(k){switch(k.kind){case"group_by":return new pe(k);case"aggregate":return new ge(k);case"order_by":return new _e(k);case"nest":return new A(k);case"limit":return new Fe(k);case"where":return new L(k);case"drill":return new U(k);case"having":return new K(k);case"calculate":return new F(k)}},isLimit(k){return k instanceof Fe}};class _e extends e{constructor(t){super(t,{kind:"order_by",field_reference:new x(t.field_reference),direction:t.direction}),this.node=t,this.kind="order_by"}get fieldReference(){return this.children.field_reference}get name(){return this.fieldReference.name}get direction(){return this.children.direction}set direction(t){this.direction!==t&&(this.edit(),this.children.direction=t)}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}setField(t){const a=this.list.segment.getOutputSchema();c.schemaGet(a,t,[]),this.edit(),this.children.field_reference=new x({name:t})}setDirection(t){this.direction=t}}u.ASTOrderByViewOperation=_e;class pe extends e{constructor(t){super(t,{kind:"group_by",name:t.name,field:new Ve(t.field)}),this.node=t,this.kind="group_by"}get field(){return this.children.field}get name(){var t;const a=(t=this.children.name)!==null&&t!==void 0?t:this.field.name;if(a===void 0)throw new Error("Group by does not have a name");return a}set name(t){this.name!==t&&(this.edit(),this.field.name===t?this.children.name=void 0:this.children.name=t)}get list(){return this.parent.as.ViewOperationList()}rename(t){this.list.segment.renameField(this,t)}delete(){this.list.remove(this),this.list.segment.propagateUp(t=>{t instanceof he&&t.removeOrderBys(this.name)})}getFieldInfo(){return{kind:"dimension",name:this.name,type:this.field.type}}get annotations(){return this.field.annotations}set annotations(t){this.edit(),this.field.annotations=t}getOrAddAnnotations(){return this.field.getOrAddAnnotations()}getInheritedTag(t="# "){return He(t,this.field.getInheritedAnnotations())}getIntrinsicTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getIntrinsicTag(t))!==null&&y!==void 0?y:new l.Tag}getTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getTag(t))!==null&&y!==void 0?y:this.getInheritedTag(t)}setTagProperty(t,a=null,y="# "){this.getOrAddAnnotations().setTagProperty(t,a,y)}removeTagProperty(t,a="# "){this.getTag().has(...t)&&this.getOrAddAnnotations().removeTagProperty(t,a)}static fromReference(t,a,y){return new pe({kind:"group_by",name:y,field:{expression:{kind:"field_reference",name:t,path:a}}})}}u.ASTGroupByViewOperation=pe;class ge extends e{constructor(t){super(t,{kind:"aggregate",name:t.name,field:new Ve(t.field)}),this.node=t,this.kind="aggregate"}get field(){return this.children.field}get name(){var t;const a=(t=this.children.name)!==null&&t!==void 0?t:this.field.name;if(a===void 0)throw new Error("Aggregate does not have a name");return a}set name(t){this.name!==t&&(this.edit(),this.field.name===t?this.children.name=void 0:this.children.name=t)}get annotations(){return this.field.annotations}rename(t){this.list.segment.renameField(this,t)}convertToCalculateMovingAverage(t,a,y=0,h=[]){if(!(this.field.expression instanceof tt))throw new Error("Cannot convert aggregate to smoothed metric unless it is a field reference");this.list.remove(this);const J=new F({kind:"calculate",name:t,field:{expression:{kind:"moving_average",field_reference:{name:this.field.expression.name,path:this.field.expression.path},rows_preceding:a,rows_following:y,partition_fields:h.map(me=>({name:me}))}}});return this.list.add(J),J}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this),this.list.segment.propagateUp(t=>{t instanceof he&&t.removeOrderBys(this.name)})}getFieldInfo(){return{annotations:[{value:l.Tag.withPrefix("#(malloy) ").set(["calculation"]).toString()}],kind:"dimension",name:this.name,type:this.field.type}}getOrAddAnnotations(){return this.field.getOrAddAnnotations()}getInheritedTag(t="# "){return He(t,this.field.getInheritedAnnotations())}getIntrinsicTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getIntrinsicTag(t))!==null&&y!==void 0?y:new l.Tag}getTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getTag(t))!==null&&y!==void 0?y:this.getInheritedTag(t)}setTagProperty(t,a=null,y="# "){this.getOrAddAnnotations().setTagProperty(t,a,y)}removeTagProperty(t,a="# "){this.getTag().has(...t)&&this.getOrAddAnnotations().removeTagProperty(t,a)}addWhere(t,a,y){const h=Array.isArray(a)?a:[],J=y===void 0?a:y,me=typeof J=="string"?J:Je(J),Le=this.list.segment.getInputSchema(),Z=w.schemaGet(Le,t,h);lt(Z,J);const Me={filter:{kind:"filter_string",expression:{kind:"field_reference",name:t,path:h},filter:me}};if(this.field.expression instanceof m)return this.field.expression.where.add(new p(Me)),this.field.expression;if(this.field.expression instanceof tt){const Ke=this.field.expression.build();return this.field.expression=new m({kind:"filtered_field",field_reference:{name:Ke.name,path:Ke.path,parameters:Ke.parameters},where:[Me]}),this.field.expression}else throw new Error("This kind of expression does not support addWhere")}static fromReference(t,a,y){return new ge({kind:"aggregate",name:y,field:{expression:{kind:"field_reference",name:t,path:a}}})}}u.ASTAggregateViewOperation=ge;class Ve extends e{constructor(t){super(t,{expression:u.ASTExpression.from(t.expression),annotations:t.annotations&&new Ne(t.annotations)}),this.node=t}get expression(){return this.children.expression}set expression(t){this.edit(),this.children.expression=t,t.parent=this}get name(){return this.expression.name}get type(){const t=this.expression.fieldType;if(t===void 0)throw new Error("Field expression does not have a type");return t}get annotations(){return this.children.annotations}set annotations(t){this.edit(),this.children.annotations=t}getReference(){if(!(this.expression instanceof it))return this.expression.getReference()}getOrAddAnnotations(){if(this.annotations)return this.annotations;this.edit();const t=new Ne([]);return this.children.annotations=t,t.parent=this,t}getInheritedTag(t="# "){return He(t,this.getInheritedAnnotations())}getIntrinsicTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getIntrinsicTag(t))!==null&&y!==void 0?y:new l.Tag}getTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getTag(t))!==null&&y!==void 0?y:this.getInheritedTag(t)}setTagProperty(t,a=null,y="# "){this.getOrAddAnnotations().setTagProperty(t,a,y)}removeTagProperty(t,a="# "){this.getTag().has(...t)&&this.getOrAddAnnotations().removeTagProperty(t,a)}get segment(){return this.parent.list.segment}getInheritedAnnotations(){return this.expression.getInheritedAnnotations()}}u.ASTField=Ve,u.ASTExpression={from(k){switch(k.kind){case"field_reference":return new tt(k);case"filtered_field":return new m(k);case"time_truncation":return new at(k);case"literal_value":return new it(k);case"moving_average":return new $(k)}}};class tt extends e{constructor(t){super(t,{kind:t.kind,name:t.name,path:t.path,parameters:t.parameters&&new G(t.parameters)}),this.node=t,this.kind="field_reference"}get name(){return this.children.name}get parameters(){return this.children.parameters}set parameters(t){this.edit(),this.children.parameters=t}get segment(){const t=this.parent;if(t instanceof Ve)return t.segment;if(t instanceof H||t instanceof ae)return t.segment;throw new Error("Invalid expression parent")}get path(){return this.children.path}getReference(){return this.build()}getFieldInfo(){const t=this.segment.getInputSchema(),y=this.parent instanceof ae&&this.parent.parent instanceof U?c.schemaGetDrillField(t,this.name,this.path):c.schemaGet(t,this.name,this.path);if(y.kind!=="dimension"&&y.kind!=="measure")throw new Error("Invalid field for ASTReferenceExpression");return y}get fieldType(){return this.getFieldInfo().type}getInheritedAnnotations(){var t;return(t=this.getFieldInfo().annotations)!==null&&t!==void 0?t:[]}getOrAddParameters(){return E.getOrAddParameters(this)}setParameter(t,a){return E.setParameter(this,t,a)}tryGetParameter(t){return E.tryGetParameter(this,t)}}u.ASTReferenceExpression=tt;class at extends e{constructor(t){super(t,{kind:t.kind,field_reference:new x(t.field_reference),truncation:t.truncation}),this.node=t,this.kind="time_truncation"}getReference(){return this.fieldReference.build()}get fieldReference(){return this.children.field_reference}get truncation(){return this.children.truncation}set truncation(t){this.edit(),this.children.truncation=t}get name(){return this.fieldReference.name}get field(){return this.parent.as.Field()}getFieldInfo(){const t=this.field.segment.getInputSchema(),a=c.schemaGet(t,this.name,this.fieldReference.path);if(a.kind!=="dimension"&&a.kind!=="measure")throw new Error("Invalid field for ASTReferenceExpression");return a}get fieldType(){const t=this.getFieldInfo();if(t.type.kind==="date_type")return{...t.type,timeframe:b(this.truncation)};if(t.type.kind==="timestamp_type"||t.type.kind==="timestamptz_type")return{...t.type,timeframe:this.truncation};throw new Error("This type of field cannot have a time truncation")}getInheritedAnnotations(){var t;return(t=this.getFieldInfo().annotations)!==null&&t!==void 0?t:[]}}u.ASTTimeTruncationExpression=at;class it extends e{constructor(t){super(t,{kind:t.kind,literal_value:u.ASTLiteralValue.from(t.literal_value)}),this.node=t,this.kind="time_truncation"}get name(){}get literalValue(){return this.children.literal_value}get fieldType(){return this.literalValue.fieldType}getInheritedAnnotations(){return[]}getFieldInfo(){}}u.ASTLiteralValueExpression=it;class X extends d{constructor(t){super(t,t.map(a=>new x(a)))}}u.ASTFieldReferenceList=X;class $ extends e{constructor(t){super(t,{kind:t.kind,field_reference:new x(t.field_reference),rows_preceding:t.rows_preceding,rows_following:t.rows_following,partition_fields:new X(t.partition_fields||[])}),this.node=t,this.kind="moving_average"}getReference(){return this.fieldReference.build()}get fieldReference(){return this.children.field_reference}get rowsPreceding(){return this.children.rows_preceding}set rowsPreceding(t){this.edit(),this.children.rows_preceding=t}get rowsFollowing(){return this.children.rows_following}set rowsFollowing(t){this.edit(),this.children.rows_following=t}get name(){return this.fieldReference.name}get field(){return this.parent.as.Field()}get partitionFields(){return this.children.partition_fields}setPartitionFields(t){this.children.partition_fields=new X(t)}getFieldInfo(){const t=this.field.segment.getInputSchema(),a=c.schemaGet(t,this.name,this.fieldReference.path);if(a.kind!=="dimension"&&a.kind!=="measure")throw new Error("Invalid field for ASTReferenceExpression");return a}get fieldType(){return this.getFieldInfo().type}getInheritedAnnotations(){var t;return(t=this.getFieldInfo().annotations)!==null&&t!==void 0?t:[]}}u.ASTMovingAverageExpression=$;class p extends e{constructor(t){super(t,{filter:u.ASTFilter.from(t.filter)})}get filter(){return this.children.filter}get list(){return this.parent.as.FilterOperationList()}delete(){this.list.remove(this)}}u.ASTFilterOperation=p;class v extends d{constructor(t){super(t,t.map(a=>new p(a)))}get expression(){return this.parent.as.FilteredFieldExpression()}}u.ASTFilterOperationList=v;class m extends e{constructor(t){super(t,{kind:t.kind,field_reference:new x(t.field_reference),where:new v(t.where)}),this.node=t,this.kind="filtered_field"}getReference(){return this.fieldReference.build()}get fieldReference(){return this.children.field_reference}get name(){return this.fieldReference.name}get where(){return this.children.where}get field(){return this.parent.as.Field()}getFieldInfo(){const t=this.field.segment.getInputSchema(),a=c.schemaGet(t,this.name,this.fieldReference.path);if(a.kind!=="measure")throw new Error("Invalid field for ASTFilteredFieldExpression");return a}get fieldType(){return this.getFieldInfo().type}getInheritedAnnotations(){var t;return(t=this.getFieldInfo().annotations)!==null&&t!==void 0?t:[]}}u.ASTFilteredFieldExpression=m;function b(k){switch(k){case"day":case"week":case"month":case"year":case"quarter":return k;default:throw new Error("Invalid date timeframe")}}class A extends e{constructor(t){super(t,{kind:"nest",name:t.name,view:new le(t.view)}),this.node=t,this.kind="nest"}get view(){return this.children.view}get annotations(){return this.view.annotations}get name(){var t;const a=(t=this.children.name)!==null&&t!==void 0?t:this.view.name;if(a===void 0)throw new Error("Nest does not have a name");return a}set name(t){this.name!==t&&(this.edit(),this.view.name===t?this.children.name=void 0:this.children.name=t)}get list(){return this.parent.as.ViewOperationList()}getOrAddAnnotations(){return this.view.getOrAddAnnotations()}getInheritedTag(t="# "){return He(t,this.view.getInheritedAnnotations())}getIntrinsicTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getIntrinsicTag(t))!==null&&y!==void 0?y:new l.Tag}getTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getTag(t))!==null&&y!==void 0?y:this.getInheritedTag(t)}setTagProperty(t,a=null,y="# "){this.getOrAddAnnotations().setTagProperty(t,a,y)}removeTagProperty(t,a="# "){this.getTag().has(...t)&&this.getOrAddAnnotations().removeTagProperty(t,a)}delete(){this.list.remove(this)}rename(t){this.list.segment.renameField(this,t)}getFieldInfo(){return{kind:"view",name:this.name,definition:this.view.build(),schema:this.view.getOutputSchema()}}static fromReference(t,a,y){return new A({kind:"nest",name:y,view:{definition:{kind:"view_reference",name:t,path:a}}})}}u.ASTNestViewOperation=A;class L extends e{constructor(t){super(t,{kind:"where",filter:u.ASTFilter.from(t.filter)}),this.node=t,this.kind="where"}get filter(){return this.children.filter}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}u.ASTWhereViewOperation=L;class U extends e{constructor(t){super(t,{kind:"drill",filter:u.ASTFilter.from(t.filter)}),this.node=t,this.kind="drill"}get filter(){return this.children.filter}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}u.ASTDrillViewOperation=U;class K extends e{constructor(t){super(t,{kind:"having",filter:u.ASTFilter.from(t.filter)}),this.node=t,this.kind="having"}get filter(){return this.children.filter}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}u.ASTHavingViewOperation=K;class F extends e{constructor(t){super(t,{kind:"calculate",field:new Ve(t.field),name:t.name}),this.node=t,this.kind="calculate"}get expression(){return this.children.field.expression}set expression(t){this.edit(),this.children.field.expression=t,t.parent=this}get name(){return this.node.name}set name(t){this.name!==t&&(this.edit(),this.node.name=t)}getFieldInfo(){return{annotations:[{value:l.Tag.withPrefix("#(malloy) ").set(["calculation"]).toString()}],kind:"calculate",name:this.name,type:this.expression.fieldType}}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}u.ASTCalculateViewOperation=F,u.ASTFilter={from(k){switch(k.kind){case"filter_string":return new H(k);case"literal_equality":return new ae(k)}},getSegment(k){const t=k.parent;return t instanceof p?t.list.expression.field.segment:t.list.segment}};class H extends e{constructor(t){super(t,{kind:"filter_string",expression:u.ASTExpression.from(t.expression),filter:t.filter}),this.node=t,this.kind="filter_string"}get expression(){return this.children.expression}get filterString(){return this.children.filter}set filterString(t){this.edit(),this.children.filter=t}setFilterString(t){const a=this.getFilterType();O(this.filterString,a),this.filterString=t}get segment(){return u.ASTFilter.getSegment(this)}getFieldInfo(){const t=this.expression.getFieldInfo();if(t===void 0||t.kind!=="dimension"&&t.kind!=="measure")throw new Error("Invalid field type for filter with filter string");return t}getFilterType(){const t=this.getFieldInfo();return ut(t)}setFilter(t){const a=this.getFilterType();if(a!==t.kind)throw new Error(`Invalid filter: expected type ${a}, got ${t.kind}`);this.filterString=Je(t)}getFilter(){const t=this.getFilterType();return O(this.filterString,t)}}u.ASTFilterWithFilterString=H;class ae extends e{constructor(t){super(t,{kind:"literal_equality",expression:u.ASTExpression.from(t.expression),value:u.ASTLiteralValue.from(t.value)}),this.node=t,this.kind="literal_equality"}get expression(){return this.children.expression}get value(){return this.children.value}get segment(){return u.ASTFilter.getSegment(this)}}u.ASTFilterWithLiteralEquality=ae;class le extends e{constructor(t){super(t,{definition:Y.from(t.definition),annotations:t.annotations&&new Ne(t.annotations)}),this.node=t}get definition(){return this.children.definition}set definition(t){this.edit(),this.children.definition=t,t.parent=this}get name(){return this.definition.getImplicitName()}getOrAddDefaultSegment(){return this.definition.getOrAddDefaultSegment()}get nest(){return this.parent.as.NestViewOperation()}getInputSchema(){return this.nest.list.segment.getInputSchema()}getOutputSchema(){return this.definition.getRefinementSchema()}propagateUp(t){this.propagateDown(t)}propagateDown(t){t(this.definition),this.definition.propagateDown(t)}reorderFields(t){this.definition instanceof he?this.definition.reorderFields(t):this.getOrAddAnnotations().setTagProperty(["field_order"],t)}get annotations(){return this.children.annotations}getOrAddAnnotations(){if(this.annotations)return this.annotations;this.edit();const t=new Ne([]);return this.children.annotations=t,t.parent=this,t}getInheritedAnnotations(){return this.definition.getInheritedAnnotations()}getInheritedTag(t="# "){return He(t,this.getInheritedAnnotations())}getIntrinsicTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getIntrinsicTag(t))!==null&&y!==void 0?y:new l.Tag}getTag(t="# "){var a,y;return(y=(a=this.annotations)===null||a===void 0?void 0:a.getTag(t))!==null&&y!==void 0?y:this.getInheritedTag(t)}setTagProperty(t,a=null,y="# "){this.getOrAddAnnotations().setTagProperty(t,a,y)}removeTagProperty(t,a="# "){this.getTag().has(...t)&&this.getOrAddAnnotations().removeTagProperty(t,a)}}u.ASTView=le;class Fe extends e{get limit(){return this.children.limit}set limit(t){Fe.validateLimit(t),this.edit(),this.children.limit=t}constructor(t){super(t,{kind:t.kind,limit:t.limit}),this.node=t,this.kind="limit"}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}static validateLimit(t){if(!Number.isInteger(t))throw new Error("Limit must be an integer")}}u.ASTLimitViewOperation=Fe;function Ue(k){switch(k){case"dimension":return"group by";case"measure":return"aggregate";case"view":return"nest";case"join":return"join";case"calculate":return"calculate"}}function rt(k){return k}class Ne extends d{constructor(t){super(t,t.map(a=>new ze(a)))}get items(){return this.children}getInheritedAnnotations(){return this.parent.getInheritedAnnotations()}getIntrinsicTag(t="# "){return He(t,this.items)}getTag(t="# "){return He(t,this.items,this.getInheritedAnnotations())}get annotations(){return this.children.map(t=>t.node)}setTagProperty(t,a=null,y="# "){let h;for(let J=this.items.length-1;J>=0;J--){const me=this.index(J);if(me.hasPrefix(y)&&(h=me,me.hasIntrinsicTagProperty(t))){me.setTagProperty(t,a);return}}h?h.setTagProperty(t,a):this.add(new ze({value:new l.Tag({prefix:y}).set(t,a).toString()}))}removeTagProperty(t,a="# "){let y;for(let h=this.items.length-1;h>=0;h--){const J=this.index(h);if(J.hasPrefix(a)&&(y=J,J.hasIntrinsicTagProperty(t))){J.removeTagProperty(t);return}}y?y.removeTagProperty(t):this.add(new ze({value:new l.Tag({prefix:a}).unset(...t).toString()}))}}u.ASTAnnotationList=Ne;class ze extends e{get value(){return this.children.value}set value(t){this.edit(),this.children.value=t}constructor(t){super(t,{value:t.value}),this.node=t}get list(){return this.parent.as.AnnotationList()}get index(){return this.list.indexOf(this)}delete(){this.list.remove(this)}getIntrinsicTag(){const t=new l.TagParser;return t.parseAnnotation(this.value),t.finish()}getTag(){const t=new l.TagParser;for(const a of this.list.getInheritedAnnotations())t.parseAnnotation(a.value);for(let a=0;a<=this.index;a++)t.parseAnnotation(this.list.index(a).value);return t.finish()}hasPrefix(t){return this.value.startsWith(t)}hasIntrinsicTagProperty(t){return this.getIntrinsicTag().has(...t)}setTagProperty(t,a){this.value=this.getIntrinsicTag().set(t,a).toString()}removeTagProperty(t){this.value=this.getTag().unset(...t).toString()}}u.ASTAnnotation=ze;function He(k,t=[],a=[]){const y=new l.TagParser;for(const J of a)y.parseAnnotation(J.value);const h=t.map(J=>J.value).filter(J=>typeof k=="string"?J.startsWith(k):J.match(k));for(const J of h)y.parseAnnotation(J);return y.finish()}function Je(k){switch(k.kind){case"string":return f.StringFilterExpression.unparse(k.parsed);case"number":return f.NumberFilterExpression.unparse(k.parsed);case"boolean":return f.BooleanFilterExpression.unparse(k.parsed);case"timestamp":case"timestamptz":case"date":return f.TemporalFilterExpression.unparse(k.parsed)}}function O(k,t){function a(y){const h=y.filter(J=>J.severity==="error");if(h.length!==0)throw new Error(`Invalid Malloy filter string: ${h[0].message}`)}switch(t){case"string":{const y=f.StringFilterExpression.parse(k);return a(y.log),{kind:t,parsed:y.parsed}}case"number":{const y=f.NumberFilterExpression.parse(k);return a(y.log),{kind:t,parsed:y.parsed}}case"boolean":{const y=f.BooleanFilterExpression.parse(k);return a(y.log),{kind:t,parsed:y.parsed}}case"timestamp":case"timestamptz":case"date":{const y=f.TemporalFilterExpression.parse(k);return a(y.log),{kind:t,parsed:y.parsed}}case"other":throw new Error("Not implemented")}}function te(k){return"kind"in k?k:{...k,kind:"source"}}function Re(k){switch(k){case"year":case"quarter":case"month":case"week":case"day":return!0;default:return!1}}function de(k,t){return k.toString().padStart(t,"0")}function De(k){const t=de(k.getUTCFullYear(),4),a=de(k.getUTCMonth()+1,2),y=de(k.getUTCDate(),2),h=de(k.getUTCHours(),2),J=de(k.getUTCMinutes(),2),me=de(k.getUTCSeconds(),2);return`${t}-${a}-${y} ${h}:${J}:${me}`}function Ye(k,t){const a=k??[],y=t??[];return a.length===y.length&&a.every((h,J)=>h===y[J])}function ut(k){switch(k.type.kind){case"string_type":return"string";case"boolean_type":return"boolean";case"number_type":return"number";case"date_type":return"date";case"timestamp_type":return"timestamp";case"timestamptz_type":return"timestamp";default:return"other"}}function lt(k,t){if(k.kind!=="dimension"&&k.kind!=="measure")throw new Error(`Cannot filter by field of type ${k.kind}`);const a=ut(k);if(typeof t=="string")O(t,a);else if(t.kind!==a)throw new Error(`Invalid filter for field ${k.name}; expected type ${a}, but got ${t.kind}`)}function kt(k){if(k instanceof ve)return k.getSourceInfo().schema;if(k instanceof $e)throw new Error("unimplemented");return k.getInputSchema()}})(wt)),wt}var yn;function fs(){return yn||(yn=1,(function(u){var M=It&&It.__createBinding||(Object.create?(function(V,g,l,f){f===void 0&&(f=l);var c=Object.getOwnPropertyDescriptor(g,l);(!c||("get"in c?!g.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return g[l]}}),Object.defineProperty(V,f,c)}):(function(V,g,l,f){f===void 0&&(f=l),V[f]=g[l]})),z=It&&It.__exportStar||function(V,g){for(var l in V)l!=="default"&&!Object.prototype.hasOwnProperty.call(g,l)&&M(g,V,l)};Object.defineProperty(u,"__esModule",{value:!0}),z(ls(),u)})(It)),It}var bn=fs();const us=Ni(bn),ps=Mi({__proto__:null,default:us},[bn]);export{rs as a,os as b,bn as d,ps as i,Yi as r};
|