@malloydata/render 0.0.250-dev250327172557 → 0.0.250-dev250327174617

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.
@@ -122044,7 +122044,7 @@ const FW = FXe(rk), bo = jt, Ke = FW.default.compile({
122044
122044
  oparen: "(",
122045
122045
  cparen: ")",
122046
122046
  comma: ",",
122047
- literal: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*))/,
122047
+ literal: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*)?)/,
122048
122048
  lit_week: /\d\d\d\d-\d\d-\d\d-[Ww][Kk]/,
122049
122049
  lit_quarter: /\d\d\d\d-[qQ][1234]/,
122050
122050
  lit_min: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d/,
@@ -122360,8 +122360,10 @@ class IXe {
122360
122360
  return { begin: o, end: this.literalNode(a.toFormat(zi)).sql };
122361
122361
  }
122362
122362
  case void 0:
122363
- case "second":
122364
- return { begin: this.literalNode(r), end: r };
122363
+ case "second": {
122364
+ const i = this.literalNode(r);
122365
+ return { begin: i, end: i.sql };
122366
+ }
122365
122367
  }
122366
122368
  }
122367
122369
  literalNode(e) {
@@ -151725,6 +151727,11 @@ TE.MALLOY_INTERFACE_TYPES = {
151725
151727
  type: "CompilerNeeds",
151726
151728
  optional: !0,
151727
151729
  array: !1
151730
+ },
151731
+ translations: {
151732
+ type: "Translation",
151733
+ array: !0,
151734
+ optional: !0
151728
151735
  }
151729
151736
  }
151730
151737
  },
@@ -151767,6 +151774,11 @@ TE.MALLOY_INTERFACE_TYPES = {
151767
151774
  type: "CompilerNeeds",
151768
151775
  optional: !0,
151769
151776
  array: !1
151777
+ },
151778
+ translations: {
151779
+ type: "Translation",
151780
+ array: !0,
151781
+ optional: !0
151770
151782
  }
151771
151783
  }
151772
151784
  },
@@ -1042,7 +1042,7 @@ Use (?: … ) instead`);if(!ue.lineBreaks&&j.test(`
1042
1042
  `))throw new Error("Rule should declare lineBreaks: "+j);xe.push(l(L))}}var z=q&&q.fallback,F=i&&!z?"ym":"gm",k=i||z?"":"|";X===!0&&(F+="u");var U=new RegExp(c(xe)+k,F);return{regexp:U,groups:fe,fast:K,error:q||E}}function _(D){var B=A(g(D));return new S({start:B},"start")}function v(D,B,q){var K=D&&(D.push||D.next);if(K&&!q[K])throw new Error("Missing state '"+K+"' (in token '"+D.defaultType+"' of state '"+B+"')");if(D&&D.pop&&+D.pop!=1)throw new Error("pop must be 1 (in token '"+D.defaultType+"' of state '"+B+"')")}function C(D,B){var q=D.$all?g(D.$all):[];delete D.$all;var K=Object.getOwnPropertyNames(D);B||(B=K[0]);for(var Q=Object.create(null),X=0;X<K.length;X++){var fe=K[X];Q[fe]=g(D[fe]).concat(q)}for(var X=0;X<K.length;X++)for(var fe=K[X],xe=Q[fe],te=Object.create(null),ue=0;ue<xe.length;ue++){var de=xe[ue];if(de.include){var Se=[ue,1];if(de.include!==fe&&!te[de.include]){te[de.include]=!0;var I=Q[de.include];if(!I)throw new Error("Cannot include nonexistent state '"+de.include+"' (in state '"+fe+"')");for(var N=0;N<I.length;N++){var L=I[N];xe.indexOf(L)===-1&&Se.push(L)}}xe.splice.apply(xe,Se),ue--}}for(var j=Object.create(null),X=0;X<K.length;X++){var fe=K[X];j[fe]=A(Q[fe],!0)}for(var X=0;X<K.length;X++){for(var V=K[X],z=j[V],F=z.groups,ue=0;ue<F.length;ue++)v(F[ue],V,j);for(var k=Object.getOwnPropertyNames(z.fast),ue=0;ue<k.length;ue++)v(z.fast[k[ue]],V,j)}return new S(j,B)}function b(D){for(var B=typeof Map<"u",q=B?new Map:Object.create(null),K=Object.getOwnPropertyNames(D),Q=0;Q<K.length;Q++){var X=K[Q],fe=D[X],xe=Array.isArray(fe)?fe:[fe];xe.forEach(function(te){if(typeof te!="string")throw new Error("keyword must be string (in keyword '"+X+"')");B?q.set(te,X):q[te]=X})}return function(te){return B?q.get(te):q[te]}}var S=function(D,B){this.startState=B,this.states=D,this.buffer="",this.stack=[],this.reset()};S.prototype.reset=function(D,B){return this.buffer=D||"",this.index=0,this.line=B?B.line:1,this.col=B?B.col:1,this.queuedToken=B?B.queuedToken:null,this.queuedText=B?B.queuedText:"",this.queuedThrow=B?B.queuedThrow:null,this.setState(B?B.state:this.startState),this.stack=B&&B.stack?B.stack.slice():[],this},S.prototype.save=function(){return{line:this.line,col:this.col,state:this.state,stack:this.stack.slice(),queuedToken:this.queuedToken,queuedText:this.queuedText,queuedThrow:this.queuedThrow}},S.prototype.setState=function(D){if(!(!D||this.state===D)){this.state=D;var B=this.states[D];this.groups=B.groups,this.error=B.error,this.re=B.regexp,this.fast=B.fast}},S.prototype.popState=function(){this.setState(this.stack.pop())},S.prototype.pushState=function(D){this.stack.push(this.state),this.setState(D)};var R=i?function(D,B){return D.exec(B)}:function(D,B){var q=D.exec(B);return q[0].length===0?null:q};S.prototype._getGroup=function(D){for(var B=this.groups.length,q=0;q<B;q++)if(D[q+1]!==void 0)return this.groups[q];throw new Error("Cannot find token type for matched text")};function O(){return this.value}if(S.prototype.next=function(){var D=this.index;if(this.queuedGroup){var B=this._token(this.queuedGroup,this.queuedText,D);return this.queuedGroup=null,this.queuedText="",B}var q=this.buffer;if(D!==q.length){var fe=this.fast[q.charCodeAt(D)];if(fe)return this._token(fe,q.charAt(D),D);var K=this.re;K.lastIndex=D;var Q=R(K,q),X=this.error;if(Q==null)return this._token(X,q.slice(D,q.length),D);var fe=this._getGroup(Q),xe=Q[0];return X.fallback&&Q.index!==D?(this.queuedGroup=fe,this.queuedText=xe,this._token(X,q.slice(D,Q.index),D)):this._token(fe,xe,D)}},S.prototype._token=function(D,B,q){var K=0;if(D.lineBreaks){var Q=/\n/g,X=1;if(B===`
1043
1043
  `)K=1;else for(;Q.exec(B);)K++,X=Q.lastIndex}var fe={type:typeof D.type=="function"&&D.type(B)||D.defaultType,value:typeof D.value=="function"?D.value(B):B,text:B,toString:O,offset:q,lineBreaks:K,line:this.line,col:this.col},xe=B.length;if(this.index+=xe,this.line+=K,K!==0?this.col=xe-X+1:this.col+=xe,D.shouldThrow){var te=new Error(this.formatError(fe,"invalid syntax"));throw te}return D.pop?this.popState():D.push?this.pushState(D.push):D.next&&this.setState(D.next),fe},typeof Symbol<"u"&&Symbol.iterator){var $=function(D){this.lexer=D};$.prototype.next=function(){var D=this.lexer.next();return{value:D,done:!D}},$.prototype[Symbol.iterator]=function(){return this},S.prototype[Symbol.iterator]=function(){return new $(this)}}return S.prototype.formatError=function(D,B){if(D==null)var q=this.buffer.slice(this.index),D={text:q,offset:this.index,lineBreaks:q.indexOf(`
1044
1044
  `)===-1?0:1,line:this.line,col:this.col};var K=2,Q=Math.max(D.line-K,1),X=D.line+K,fe=String(X).length,xe=h(this.buffer,this.line-D.line+K+1).slice(0,5),te=[];te.push(B+" at line "+D.line+" col "+D.col+":"),te.push("");for(var ue=0;ue<xe.length;ue++){var de=xe[ue],Se=Q+ue;te.push(x(String(Se),fe)+" "+de),Se===D.line&&te.push(x("",fe+D.col+1)+"^")}return te.join(`
1045
- `)},S.prototype.clone=function(){return new S(this.states,this.state)},S.prototype.has=function(D){return!0},{compile:_,states:C,error:Object.freeze({error:!0}),fallback:Object.freeze({fallback:!0}),keywords:b}})})(hae);var X$=hae.exports,qt={};Object.defineProperty(qt,"__esModule",{value:!0}),qt.mkUnits=qt.timeLiteral=qt.joinTemporal=qt.temporalNot=qt.numNot=qt.mkValues=qt.mkRange=qt.joinNumbers=qt.conjoin=qt.matchOp=qt.escape=qt.unescape=qt.maybeNot=void 0;const Sa=bn;function IJe(t){const[e,r]=t;return e&&r&&(0,Sa.isStringFilter)(r)?{...r,not:!0}:r}qt.maybeNot=IJe;function vy(t){return t.replace(/\\(.)/g,"$1")}qt.unescape=vy;function $Je(t){const e=t.toLowerCase();return e==="null"||e==="empty"?"\\"+t:t.replace(/([,; |()\\%_-])/g,"\\$1")}qt.escape=$Je;function M4(t){let e=!1,r=!1,i=0,s=!1;const o=t.length;for(let u=0;u<o;u+=1){const a=t[u];if(a===" "||a===" "){i+=1;continue}i=0,a==="%"?(s=!0,u===0&&(e=!0),r=!0):(r=!1,a==="\\"?u+=1:a==="_"&&(s=!0))}return{hasLike:s,percentEnd:r&&o>1,percentStart:e&&o>1,endSpace:i}}function BJe(t){let e=t.trimStart();const{hasLike:r,percentEnd:i,percentStart:s,endSpace:o}=M4(e);if(o>0&&(e=e.slice(0,-o)),r){if(s&&i){const u=e.slice(1,-1);if(!M4(u).hasLike&&u.length>0)return{operator:"contains",values:[vy(u)]}}else if(i){const u=e.slice(0,-1);if(!M4(u).hasLike)return{operator:"starts",values:[vy(u)]}}else if(s){const u=e.slice(1);if(!M4(u).hasLike)return{operator:"ends",values:[vy(u)]}}return{operator:"~",escaped_values:[e]}}return e.toLowerCase()==="null"||e==="NULL"?{operator:"null"}:e==="empty"||e==="EMPTY"?{operator:"empty"}:{operator:"=",values:[vy(e)]}}qt.matchOp=BJe;function Z$(t,e){var r,i;return t.operator===e.operator&&((r=t.not)!==null&&r!==void 0?r:!1)===((i=e.not)!==null&&i!==void 0?i:!1)}function kJe(t,e,r){if((0,Sa.isStringFilter)(t)&&(0,Sa.isStringFilter)(r)){if(e===","){if(t.operator==="~"&&Z$(t,r))return{...t,escaped_values:[...t.escaped_values,...r.escaped_values]};if((0,Sa.isStringCondition)(t)&&Z$(t,r))return{...t,values:[...t.values,...r.values]}}const i=e===","?",":e==="|"?"or":e===";"?"and":void 0;if(i)return t.operator===i?{...t,members:[...t.members,r]}:{operator:i,members:[t,r]}}return null}qt.conjoin=kJe;function MJe(t,e,r){if((0,Sa.isNumberFilter)(t)&&(0,Sa.isNumberFilter)(r)){if(e==="or"&&t.operator==="="&&Z$(t,r)){const i={operator:"=",values:[...t.values,...r.values]};return t.not&&(i.not=!0),i}if(e==="and"||e==="or")return t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}}return null}qt.joinNumbers=MJe;function PJe(t,e,r,i){return{operator:"range",startValue:e,startOperator:t==="("?">":">=",endValue:r,endOperator:i===")"?"<":"<="}}qt.mkRange=PJe;function UJe(t,e){return{values:[t,...e]}}qt.mkValues=UJe;function jJe(t,e){return(0,Sa.isNumberFilter)(t)&&e?t.operator==="="?{operator:"!=",values:t.values}:t.operator==="!="?{operator:"=",values:t.values}:{...t,not:!0}:t}qt.numNot=jJe;function qJe(t,e){return(0,Sa.isTemporalFilter)(t)&&e?{...t,not:!0}:t}qt.temporalNot=qJe;function HJe(t,e,r){return(0,Sa.isTemporalFilter)(t)&&(0,Sa.isTemporalFilter)(r)&&(e==="and"||e==="or")?t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}:null}qt.joinTemporal=HJe;function QJe(t,e){const r={moment:"literal",literal:t};return e&&(r.units=e),r}qt.timeLiteral=QJe;function zJe(t){switch(t.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"}}qt.mkUnits=zJe;var GJe=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(J$,"__esModule",{value:!0});function WJe(t){return t[0]}const pae=GJe(X$),Qp=qt,Ln=pae.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:pae.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to"})},oparen:"(",cparen:")",obrack:"[",cbrack:"]",comma:",",op:/<=|>=|<|>/,ne:"!=",eq:"=",float:/-?(?:\d+)?\.\d+(?:[Ee][+-]?\d+)?/,numberE:/-?\d+[Ee][+-]?\d+/,integer:/-?\d+/}),VJe=Ln.next;Ln.next=(t=>()=>{for(;;){const e=t.call(Ln);if(e===void 0||e.type!=="WS")return e}})(VJe);const YJe={Lexer:Ln,ParserRules:[{name:"numberFilter",symbols:["numberFilter","conjunction","numberUnary"],postprocess:([t,e,r])=>(0,Qp.joinNumbers)(t,e[0].text,r)},{name:"numberFilter",symbols:["numberUnary"],postprocess:t=>t[0]},{name:"numberUnary$ebnf$1",symbols:[Ln.has("NOT")?{type:"NOT"}:NOT],postprocess:WJe},{name:"numberUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"numberUnary",symbols:["numberUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,Qp.numNot)(e,t)},{name:"clause",symbols:[Ln.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause$ebnf$1",symbols:[]},{name:"clause$ebnf$1",symbols:["clause$ebnf$1","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:["N","clause$ebnf$1"],postprocess:([t,e])=>({operator:"=",...(0,Qp.mkValues)(t,e)})},{name:"clause$ebnf$2",symbols:[]},{name:"clause$ebnf$2",symbols:["clause$ebnf$2","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[Ln.has("eq")?{type:"eq"}:eq,"N","clause$ebnf$2"],postprocess:([t,e,r])=>({operator:"=",...(0,Qp.mkValues)(e,r)})},{name:"clause$ebnf$3",symbols:[]},{name:"clause$ebnf$3",symbols:["clause$ebnf$3","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[Ln.has("ne")?{type:"ne"}:ne,"N","clause$ebnf$3"],postprocess:([t,e,r])=>({operator:"!=",...(0,Qp.mkValues)(e,r)})},{name:"clause",symbols:[Ln.has("op")?{type:"op"}:op,"N"],postprocess:([t,e])=>({operator:t.text,values:[e]})},{name:"clause",symbols:[Ln.has("oparen")?{type:"oparen"}:oparen,"numberFilter",Ln.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:["openInterval","N",Ln.has("TO")?{type:"TO"}:TO,"N","closeInterval"],postprocess:([t,e,r,i,s])=>(0,Qp.mkRange)(t[0].text,e,i,s[0].text)},{name:"numberList",symbols:[Ln.has("comma")?{type:"comma"}:comma,"N"],postprocess:([t,e])=>e},{name:"closeInterval",symbols:[Ln.has("cbrack")?{type:"cbrack"}:cbrack]},{name:"closeInterval",symbols:[Ln.has("cparen")?{type:"cparen"}:cparen]},{name:"openInterval",symbols:[Ln.has("obrack")?{type:"obrack"}:obrack]},{name:"openInterval",symbols:[Ln.has("oparen")?{type:"oparen"}:oparen]},{name:"N$subexpression$1",symbols:[Ln.has("float")?{type:"float"}:float]},{name:"N$subexpression$1",symbols:[Ln.has("numberE")?{type:"numberE"}:numberE]},{name:"N$subexpression$1",symbols:[Ln.has("integer")?{type:"integer"}:integer]},{name:"N",symbols:["N$subexpression$1"],postprocess:([t])=>t[0].text},{name:"conjunction",symbols:[Ln.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[Ln.has("AND")?{type:"AND"}:AND]}],ParserStart:"numberFilter"};J$.default=YJe;var zp={};Object.defineProperty(zp,"__esModule",{value:!0}),zp.run_parser=void 0;const KJe=bn;function JJe(t,e){try{e.feed(t);const i=e.finish()[0];return i&&(0,KJe.isFilterExpression)(i)?{parsed:i,log:[]}:{parsed:null,log:[]}}catch(r){let i=r.message,s=1,o=t.length;if(r.token){const u=r.token;s=u.col,o=u.text.length;const l=r.message.match(new RegExp("(?<=A ).*(?= based on:)","g")).map(c=>c.replace(/\s+token/i,""));i=`Unexpected ${u.type} token "${u.value}"`,l&&l.length&&(i+=` Tokens expected: ${[...new Set(l)]}`)}return{parsed:null,log:[{message:i,startIndex:s-1,endIndex:s-1+o-1,severity:"error"}]}}}zp.run_parser=JJe,function(t){var e=T&&T.__createBinding||(Object.create?function(c,f,x,h){h===void 0&&(h=x);var p=Object.getOwnPropertyDescriptor(f,x);(!p||("get"in p?!f.__esModule:p.writable||p.configurable))&&(p={enumerable:!0,get:function(){return f[x]}}),Object.defineProperty(c,h,p)}:function(c,f,x,h){h===void 0&&(h=x),c[h]=f[x]}),r=T&&T.__setModuleDefault||(Object.create?function(c,f){Object.defineProperty(c,"default",{enumerable:!0,value:f})}:function(c,f){c.default=f}),i=T&&T.__importStar||function(c){if(c&&c.__esModule)return c;var f={};if(c!=null)for(var x in c)x!=="default"&&Object.prototype.hasOwnProperty.call(c,x)&&e(f,c,x);return r(f,c),f},s=T&&T.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(t,"__esModule",{value:!0}),t.NumberFilterExpression=void 0;const o=bn,u=i(K$),a=s(J$),l=zp;t.NumberFilterExpression={parse(c){if(c.match(/^\s*$/))return{parsed:null,log:[]};const f=new u.Parser(u.Grammar.fromCompiled(a.default)),x=(0,l.run_parser)(c,f);return x.parsed&&(0,o.isNumberFilter)(x.parsed)?{parsed:x.parsed,log:[]}:{parsed:null,log:x.log}},unparse(c){if(c===null)return"";switch(c.operator){case"=":return c.values.join(", ");case"!=":return"!= "+c.values.join(", ");case">":case"<":case"<=":case">=":return c.not?c.values.map(f=>c.operator==="="?`not ${f}`:`not ${c.operator} ${f}`).join(", "):c.values.map(f=>`${c.operator} ${f}`).join(", ");case"range":{const f=c.startOperator===">"?"(":"[",x=c.endOperator==="<"?")":"]",h=`${f}${c.startValue} to ${c.endValue}${x}`;return c.not?`not ${h}`:h}case"null":return c.not?"not null":"null";case"and":case"or":return c.members.map(f=>t.NumberFilterExpression.unparse(f)).join(` ${c.operator} `);case"()":{const f="("+t.NumberFilterExpression.unparse(c.expr)+")";return c.not?"not "+f:f}}return`no unparse for ${JSON.stringify(c)}`}}}(xae);var mae={},eB={},XJe=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(eB,"__esModule",{value:!0});function ZJe(t){return t[0]}const eXe=XJe(X$),tB=qt,fu=eXe.default.compile({WS:/[ \t]+/,comma:",",semi:";",or:"|",open:"(",close:")",minus:"-",matchStr:/(?:\\[^\n]|[^\n,;()|])+/}),tXe=fu.next;fu.next=(t=>()=>{for(;;){const e=t.call(fu);if(e==null||e.type!=="WS")return e}})(tXe);const nXe={Lexer:fu,ParserRules:[{name:"stringFilter",symbols:["stringFilter","conjunction","sfUnary"],postprocess:([t,e,r])=>(0,tB.conjoin)(t,e[0].text,r)},{name:"stringFilter",symbols:["sfUnary"],postprocess:t=>t[0]},{name:"sfUnary$ebnf$1",symbols:[fu.has("minus")?{type:"minus"}:minus],postprocess:ZJe},{name:"sfUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"sfUnary",symbols:["sfUnary$ebnf$1","clause"],postprocess:t=>(0,tB.maybeNot)(t)},{name:"parens",symbols:[fu.has("open")?{type:"open"}:open,"stringFilter",fu.has("close")?{type:"close"}:close],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:[fu.has("matchStr")?{type:"matchStr"}:matchStr],postprocess:([t])=>(0,tB.matchOp)(t.text)},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"conjunction",symbols:[fu.has("comma")?{type:"comma"}:comma]},{name:"conjunction",symbols:[fu.has("semi")?{type:"semi"}:semi]},{name:"conjunction",symbols:[fu.has("or")?{type:"or"}:or]}],ParserStart:"stringFilter"};eB.default=nXe,function(t){var e=T&&T.__createBinding||(Object.create?function(f,x,h,p){p===void 0&&(p=h);var m=Object.getOwnPropertyDescriptor(x,h);(!m||("get"in m?!x.__esModule:m.writable||m.configurable))&&(m={enumerable:!0,get:function(){return x[h]}}),Object.defineProperty(f,p,m)}:function(f,x,h,p){p===void 0&&(p=h),f[p]=x[h]}),r=T&&T.__setModuleDefault||(Object.create?function(f,x){Object.defineProperty(f,"default",{enumerable:!0,value:x})}:function(f,x){f.default=x}),i=T&&T.__importStar||function(f){if(f&&f.__esModule)return f;var x={};if(f!=null)for(var h in f)h!=="default"&&Object.prototype.hasOwnProperty.call(f,h)&&e(x,f,h);return r(x,f),x},s=T&&T.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(t,"__esModule",{value:!0}),t.StringFilterExpression=void 0;const o=bn,u=i(K$),a=s(eB),l=qt,c=zp;t.StringFilterExpression={parse(f){if(f.match(/^\s*$/))return{parsed:null,log:[]};const x=new u.Parser(u.Grammar.fromCompiled(a.default)),h=(0,c.run_parser)(f,x);return h.parsed&&(0,o.isStringFilter)(h.parsed)?{parsed:h.parsed,log:[]}:{parsed:null,log:h.log}},unparse(f){if(f===null)return"";switch(f.operator){case"=":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)).join(", "):f.values.map(x=>(0,l.escape)(x)).join(", ");case"~":return f.not?f.escaped_values.map(x=>"-"+x).join(", "):f.escaped_values.join(", ");case"starts":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>(0,l.escape)(x)+"%").join(", ");case"ends":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)).join(", "):f.values.map(x=>"%"+(0,l.escape)(x)).join(", ");case"contains":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>"%"+(0,l.escape)(x)+"%").join(", ");case"or":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(" | ");case"and":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join("; ");case",":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(", ");case"()":{const x="("+t.StringFilterExpression.unparse(f.expr)+")";return f.not?"-"+x:x}case"null":return f.not?"-null":"null";case"empty":return f.not?"-empty":"empty"}}}}(mae);var gae={},nB={},rXe=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(nB,"__esModule",{value:!0});function iXe(t){return t[0]}const yae=rXe(X$),xu=qt,Ke=yae.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:yae.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to",NOW:"now",LAST:"last",THIS:"this",NEXT:"next",AGO:"ago",FROM:"from",BEFORE:"before",AFTER:"after",FOR:"for",TODAY:"today",YESTERDAY:"yesterday",TOMORROW:"tomorrow",SECOND:"second",MINUTE:"minute",HOUR:"hour",DAY:"day",WEEK:"week",MONTH:"month",QUARTER:"quarter",YEAR:"year",SECONDS:"seconds",MINUTES:"minutes",HOURS:"hours",DAYS:"days",WEEKS:"weeks",MONTHS:"months",QUARTERS:"quarters",YEARS:"years",MONDAY:"monday",TUESDAY:"tuesday",WEDNESDAY:"wednesday",THURSDAY:"thursday",FRIDAY:"friday",SATURDAY:"saturday",SUNDAY:"sunday"})},oparen:"(",cparen:")",comma:",",literal:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*))/,lit_week:/\d\d\d\d-\d\d-\d\d-[Ww][Kk]/,lit_quarter:/\d\d\d\d-[qQ][1234]/,lit_min:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d/,lit_hour:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d/,lit_day:/\d\d\d\d-\d\d-\d\d/,lit_month:/\d\d\d\d-\d\d/,lit_year:/\d\d\d\d/,n:/\d+/}),sXe=Ke.next;Ke.next=(t=>()=>{for(;;){const e=t.call(Ke);if(e===void 0||e.type!=="WS")return e}})(sXe);const oXe={Lexer:Ke,ParserRules:[{name:"temporalFilter",symbols:["temporalFilter","conjunction","temporalUnary"],postprocess:([t,e,r])=>(0,xu.joinTemporal)(t,e[0].text,r)},{name:"temporalFilter",symbols:["temporalUnary"],postprocess:t=>t[0]},{name:"temporalUnary$ebnf$1",symbols:[Ke.has("NOT")?{type:"NOT"}:NOT],postprocess:iXe},{name:"temporalUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"temporalUnary",symbols:["temporalUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,xu.temporalNot)(e,t)},{name:"duration",symbols:["number","unit"],postprocess:([t,e])=>({units:e,n:t})},{name:"number",symbols:[Ke.has("n")?{type:"n"}:n],postprocess:([t])=>t.text},{name:"number",symbols:[Ke.has("lityear")?{type:"lityear"}:lityear],postprocess:([t])=>t.text},{name:"unit$subexpression$1",symbols:[Ke.has("SECOND")?{type:"SECOND"}:SECOND]},{name:"unit$subexpression$1",symbols:[Ke.has("MINUTE")?{type:"MINUTE"}:MINUTE]},{name:"unit$subexpression$1",symbols:[Ke.has("HOUR")?{type:"HOUR"}:HOUR]},{name:"unit$subexpression$1",symbols:[Ke.has("DAY")?{type:"DAY"}:DAY]},{name:"unit$subexpression$1",symbols:[Ke.has("WEEK")?{type:"WEEK"}:WEEK]},{name:"unit$subexpression$1",symbols:[Ke.has("MONTH")?{type:"MONTH"}:MONTH]},{name:"unit$subexpression$1",symbols:[Ke.has("QUARTER")?{type:"QUARTER"}:QUARTER]},{name:"unit$subexpression$1",symbols:[Ke.has("YEAR")?{type:"YEAR"}:YEAR]},{name:"unit$subexpression$1",symbols:[Ke.has("SECONDS")?{type:"SECONDS"}:SECONDS]},{name:"unit$subexpression$1",symbols:[Ke.has("MINUTES")?{type:"MINUTES"}:MINUTES]},{name:"unit$subexpression$1",symbols:[Ke.has("HOURS")?{type:"HOURS"}:HOURS]},{name:"unit$subexpression$1",symbols:[Ke.has("DAYS")?{type:"DAYS"}:DAYS]},{name:"unit$subexpression$1",symbols:[Ke.has("WEEKS")?{type:"WEEKS"}:WEEKS]},{name:"unit$subexpression$1",symbols:[Ke.has("MONTHS")?{type:"MONTHS"}:MONTHS]},{name:"unit$subexpression$1",symbols:[Ke.has("QUARTERS")?{type:"QUARTERS"}:QUARTERS]},{name:"unit$subexpression$1",symbols:[Ke.has("YEARS")?{type:"YEARS"}:YEARS]},{name:"unit",symbols:["unit$subexpression$1"],postprocess:([t])=>(0,xu.mkUnits)(t[0].text)},{name:"clause",symbols:[Ke.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"clause",symbols:["duration"],postprocess:([t])=>({operator:"in_last",...t})},{name:"clause",symbols:[Ke.has("BEFORE")?{type:"BEFORE"}:BEFORE,"moment"],postprocess:([t,e])=>({operator:"before",before:e})},{name:"clause",symbols:[Ke.has("AFTER")?{type:"AFTER"}:AFTER,"moment"],postprocess:([t,e])=>({operator:"after",after:e})},{name:"clause",symbols:["moment",Ke.has("TO")?{type:"TO"}:TO,"moment"],postprocess:([t,e,r])=>({operator:"to",fromMoment:t,toMoment:r})},{name:"clause",symbols:["moment",Ke.has("FOR")?{type:"FOR"}:FOR,"duration"],postprocess:([t,e,r])=>({...r,operator:"for",begin:t})},{name:"clause$subexpression$1",symbols:[Ke.has("LAST")?{type:"LAST"}:LAST]},{name:"clause$subexpression$1",symbols:[Ke.has("NEXT")?{type:"NEXT"}:NEXT]},{name:"clause",symbols:["clause$subexpression$1","duration"],postprocess:([t,e])=>({operator:t[0].text,...e})},{name:"clause",symbols:["moment"],postprocess:([t])=>({operator:"in",in:t})},{name:"lastNextThis",symbols:[Ke.has("THIS")?{type:"THIS"}:THIS],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Ke.has("NEXT")?{type:"NEXT"}:NEXT],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Ke.has("LAST")?{type:"LAST"}:LAST],postprocess:([t])=>t.text.toLowerCase()},{name:"moment",symbols:[Ke.has("NOW")?{type:"NOW"}:NOW],postprocess:()=>({moment:"now"})},{name:"moment",symbols:["lastNextThis","unit"],postprocess:([t,e])=>({moment:t,units:e})},{name:"moment",symbols:[Ke.has("TODAY")?{type:"TODAY"}:TODAY],postprocess:()=>({moment:"today"})},{name:"moment",symbols:[Ke.has("YESTERDAY")?{type:"YESTERDAY"}:YESTERDAY],postprocess:()=>({moment:"yesterday"})},{name:"moment",symbols:[Ke.has("TOMORROW")?{type:"TOMORROW"}:TOMORROW],postprocess:()=>({moment:"tomorrow"})},{name:"moment",symbols:["duration",Ke.has("AGO")?{type:"AGO"}:AGO],postprocess:([t,e])=>({moment:"ago",...t})},{name:"moment",symbols:["duration",Ke.has("FROM")?{type:"FROM"}:FROM,Ke.has("NOW")?{type:"NOW"}:NOW],postprocess:([t,e])=>({moment:"from_now",...t})},{name:"moment",symbols:[Ke.has("NEXT")?{type:"NEXT"}:NEXT,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"next"})},{name:"moment",symbols:[Ke.has("LAST")?{type:"LAST"}:LAST,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"last"})},{name:"moment",symbols:["weekday"],postprocess:([t])=>({moment:t.toLowerCase(),which:"last"})},{name:"moment",symbols:["timeLiteral"],postprocess:t=>t[0]},{name:"timeLiteral",symbols:[Ke.has("literal")?{type:"literal"}:literal],postprocess:([t])=>(0,xu.timeLiteral)(t.text)},{name:"timeLiteral",symbols:[Ke.has("lit_day")?{type:"lit_day"}:lit_day],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"day")},{name:"timeLiteral",symbols:[Ke.has("lit_min")?{type:"lit_min"}:lit_min],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"minute")},{name:"timeLiteral",symbols:[Ke.has("lit_hour")?{type:"lit_hour"}:lit_hour],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"hour")},{name:"timeLiteral",symbols:[Ke.has("lit_month")?{type:"lit_month"}:lit_month],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"month")},{name:"timeLiteral",symbols:[Ke.has("lit_quarter")?{type:"lit_quarter"}:lit_quarter],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"quarter")},{name:"timeLiteral",symbols:[Ke.has("lit_week")?{type:"lit_week"}:lit_week],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"week")},{name:"timeLiteral",symbols:[Ke.has("lit_year")?{type:"lit_year"}:lit_year],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"year")},{name:"weekday$subexpression$1",symbols:[Ke.has("MONDAY")?{type:"MONDAY"}:MONDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("TUESDAY")?{type:"TUESDAY"}:TUESDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("WEDNESDAY")?{type:"WEDNESDAY"}:WEDNESDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("THURSDAY")?{type:"THURSDAY"}:THURSDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("FRIDAY")?{type:"FRIDAY"}:FRIDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("SATURDAY")?{type:"SATURDAY"}:SATURDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("SUNDAY")?{type:"SUNDAY"}:SUNDAY]},{name:"weekday",symbols:["weekday$subexpression$1"],postprocess:([t])=>t[0].text},{name:"parens",symbols:[Ke.has("oparen")?{type:"oparen"}:oparen,"temporalFilter",Ke.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"conjunction",symbols:[Ke.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[Ke.has("AND")?{type:"AND"}:AND]}],ParserStart:"temporalFilter"};nB.default=oXe,function(t){var e=T&&T.__createBinding||(Object.create?function(h,p,m,y){y===void 0&&(y=m);var g=Object.getOwnPropertyDescriptor(p,m);(!g||("get"in g?!p.__esModule:g.writable||g.configurable))&&(g={enumerable:!0,get:function(){return p[m]}}),Object.defineProperty(h,y,g)}:function(h,p,m,y){y===void 0&&(y=m),h[y]=p[m]}),r=T&&T.__setModuleDefault||(Object.create?function(h,p){Object.defineProperty(h,"default",{enumerable:!0,value:p})}:function(h,p){h.default=p}),i=T&&T.__importStar||function(h){if(h&&h.__esModule)return h;var p={};if(h!=null)for(var m in h)m!=="default"&&Object.prototype.hasOwnProperty.call(h,m)&&e(p,h,m);return r(p,h),p},s=T&&T.__importDefault||function(h){return h&&h.__esModule?h:{default:h}};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=void 0;const o=bn,u=s(nB),a=i(K$),l=zp;t.TemporalFilterExpression={parse(h){if(h.match(/^\s*$/))return{parsed:null,log:[]};const p=new a.Parser(a.Grammar.fromCompiled(u.default)),m=(0,l.run_parser)(h,p);return m.parsed&&(0,o.isTemporalFilter)(m.parsed)?{parsed:m.parsed,log:[]}:{parsed:null,log:m.log}},unparse(h){if(h===null)return"";switch(h.operator){case"null":return c(h,"null");case"in":return c(h,x(h.in));case"()":return"("+t.TemporalFilterExpression.unparse(h.expr)+")";case"in_last":return c(h,f(h));case"last":case"next":return c(h,`${h.operator} ${f(h)}`);case"before":return c(h,`before ${x(h.before)}`);case"after":return c(h,`after ${x(h.after)}`);case"to":return c(h,`${x(h.fromMoment)} to ${x(h.toMoment)}`);case"for":return c(h,`${x(h.begin)} for ${f(h)}`);case"or":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" or ");case"and":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" and ")}}};function c(h,p){return"not"in h&&h.not?"not "+p:p}function f(h){return h.n==="1"?`1 ${h.units}`:`${h.n} ${h.units}s`}function x(h){switch(h.moment){case"literal":return h.literal;case"now":case"today":case"yesterday":case"tomorrow":return h.moment;case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":return h.which==="next"?"next "+h.moment:h.moment;case"this":case"next":case"last":return`${h.moment} ${h.units}`;case"ago":return`${f(h)} ago`;case"from_now":return`${f(h)} from now`}}}(gae),function(t){var e=T&&T.__createBinding||(Object.create?function(a,l,c,f){f===void 0&&(f=c);var x=Object.getOwnPropertyDescriptor(l,c);(!x||("get"in x?!l.__esModule:x.writable||x.configurable))&&(x={enumerable:!0,get:function(){return l[c]}}),Object.defineProperty(a,f,x)}:function(a,l,c,f){f===void 0&&(f=c),a[f]=l[c]}),r=T&&T.__exportStar||function(a,l){for(var c in a)c!=="default"&&!Object.prototype.hasOwnProperty.call(l,c)&&e(l,a,c)};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=t.StringFilterExpression=t.NumberFilterExpression=t.BooleanFilterExpression=void 0,r(bn,t);var i=k4;Object.defineProperty(t,"BooleanFilterExpression",{enumerable:!0,get:function(){return i.BooleanFilterExpression}});var s=xae;Object.defineProperty(t,"NumberFilterExpression",{enumerable:!0,get:function(){return s.NumberFilterExpression}});var o=mae;Object.defineProperty(t,"StringFilterExpression",{enumerable:!0,get:function(){return o.StringFilterExpression}});var u=gae;Object.defineProperty(t,"TemporalFilterExpression",{enumerable:!0,get:function(){return u.TemporalFilterExpression}})}(B4);var P4={};const Cy=yP(H1e);Object.defineProperty(P4,"__esModule",{value:!0}),P4.TemporalFilterCompiler=void 0;const rB=Xe,Zx=Cy,Eae="yyyy",Aae=`${Eae}-LL`,iB=`${Aae}-dd`,_ae=`${iB} HH`,vae=`${_ae}:mm`,xs=`${vae}:ss`;class uXe{constructor(e,r,i="timestamp"){this.expr=e,this.timetype=i,this.d=r}time(e){return this.timetype==="timestamp"?e:this.d.sqlCast({},{node:"cast",e:{node:"genericSQLExpr",src:["",e],kids:{args:[]},sql:e},srcType:{type:"timestamp"},dstType:{type:"date"},safe:!1})}compile(e){const r=this.expr;switch(e.operator){case"after":return`${r} ${e.not?"<":">="} ${this.time(this.moment(e.after).end)}`;case"before":return`${r} ${e.not?">=":"<"} ${this.time(this.moment(e.before).begin.sql)}`;case"in":{const i=this.moment(e.in);return i.begin.sql===i.end?e.not?`${r} != ${this.time(i.end)} OR ${r} IS NULL`:`${r} = ${this.time(i.end)}`:this.isIn(e.not,i.begin.sql,i.end)}case"for":{const i=this.moment(e.begin),s=this.delta(i.begin,"+",e.n,e.units);return this.isIn(e.not,i.begin.sql,s.sql)}case"in_last":{const i=Number(e.n)-1,s=this.nowDot(e.units),o=i>0?this.delta(s,"-",i.toString(),e.units):s,u=this.delta(s,"+","1",e.units);return this.isIn(e.not,o.sql,u.sql)}case"to":{const i=this.moment(e.fromMoment),s=this.moment(e.toMoment);return this.isIn(e.not,i.begin.sql,s.begin.sql)}case"last":{const i=this.nowDot(e.units),s=this.delta(i,"-",e.n,e.units);return this.isIn(e.not,s.sql,i.sql)}case"next":{const i=this.nowDot(e.units),s=this.delta(i,"+","1",e.units),o=this.delta(i,"+",(Number(e.n)+1).toString(),e.units);return this.isIn(e.not,s.sql,o.sql)}case"null":return e.not?`${r} IS NOT NULL`:`${r} IS NULL`;case"()":{const i="("+this.compile(e.expr)+")";return e.not?`NOT ${i}`:i}case"and":case"or":return e.members.map(i=>this.compile(i)).join(` ${e.operator.toUpperCase()} `)}}expandLiteral(e){let r=e.literal;switch(e.units){case"year":{const i=Zx.DateTime.fromFormat(r,Eae),s=this.literalNode(i.toFormat(xs)),o=i.plus({year:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"month":{const i=Zx.DateTime.fromFormat(r,Aae),s=this.literalNode(i.toFormat(xs)),o=i.plus({month:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"day":{const i=Zx.DateTime.fromFormat(r,iB),s=this.literalNode(i.toFormat(xs)),o=i.plus({day:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"hour":{const i=Zx.DateTime.fromFormat(r,_ae),s=this.literalNode(i.toFormat(xs)),o=i.plus({hour:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"minute":{const i=Zx.DateTime.fromFormat(r,vae),s=this.literalNode(i.toFormat(xs)),o=i.plus({minute:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"week":{const o=Zx.DateTime.fromFormat(r.slice(0,10),iB).plus({day:1}).startOf("week").minus({day:1}),u=this.literalNode(o.toFormat(xs)),a=o.plus({days:7});return{begin:u,end:this.literalNode(a.toFormat(xs)).sql}}case"quarter":{const i=r.slice(0,4),s=r.slice(6);s==="1"?r=`${i}-01-01 00:00:00`:s==="2"?r=`${i}-03-01 00:00:00`:s==="3"?r=`${i}-06-01 00:00:00`:r=`${i}-09-01 00:00:00`;const o=this.literalNode(r),a=Zx.DateTime.fromFormat(r,xs).plus({months:3});return{begin:o,end:this.literalNode(a.toFormat(xs)).sql}}case void 0:case"second":return{begin:this.literalNode(r),end:r}}}literalNode(e){const r={node:"timeLiteral",typeDef:{type:"timestamp"},literal:e};return{...r,sql:this.d.sqlLiteralTime({},r)}}nowExpr(){return{node:"now",typeDef:{type:"timestamp"},sql:this.d.sqlNowExpr()}}n(e){return{node:"numberLiteral",literal:e,sql:e}}delta(e,r,i,s){const o={node:"delta",op:r,units:s,kids:{base:(0,rB.mkTemporal)(e,"timestamp"),delta:this.n(i)}};return{...o,sql:this.d.sqlAlterTimeExpr(o)}}dayofWeek(e){const r={node:"extract",e:(0,rB.mkTemporal)(e,"timestamp"),units:"day_of_week"};return{...r,sql:this.d.sqlTimeExtractExpr({},r)}}nowDot(e){const r={node:"trunc",e:this.nowExpr(),units:e};return{...r,sql:this.d.sqlTruncExpr({},r)}}thisUnit(e){const r=this.nowDot(e),i=this.delta(r,"+","1",e);return{begin:r,end:i.sql}}lastUnit(e){const r=this.nowDot(e);return{begin:this.delta(r,"-","1",e),end:r.sql}}nextUnit(e){const r=this.nowDot(e),i=this.delta(r,"+","1",e),s=this.delta(r,"+","2",e);return{begin:i,end:s.sql}}mod7(e){return this.d.hasModOperator?`(${e})%7`:`MOD(${e},7)`}moment(e){switch(e.moment){case"now":{const r=this.nowExpr();return{begin:r,end:r.sql}}case"literal":return this.expandLiteral(e);case"ago":case"from_now":{const r=this.nowDot(e.units),i=(0,rB.mkTemporal)(r,"timestamp"),s=this.delta(i,e.moment==="ago"?"-":"+",e.n,e.units);if(e.moment==="ago"&&e.n==="1")return{begin:s,end:r.sql};const o=Number(e.n)+(e.moment==="ago"?-1:1),u={...s,kids:{base:i,delta:this.n(o.toString())}};return{begin:s,end:this.d.sqlAlterTimeExpr(u)}}case"today":return this.thisUnit("day");case"yesterday":return this.lastUnit("day");case"tomorrow":return this.nextUnit("day");case"this":return this.thisUnit(e.units);case"last":return this.lastUnit(e.units);case"next":return this.nextUnit(e.units);case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":{const r=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"].indexOf(e.moment),i=this.dayofWeek(this.nowExpr()).sql;if(e.which==="next"){const a=`${this.mod7(`${r}-(${i}-1)+6`)}+1`,l=this.delta(this.thisUnit("day").begin,"+",a,"day"),c=this.delta(this.thisUnit("day").begin,"+",`${a}+1`,"day");return{begin:l,end:c.sql}}const s=`${this.mod7(`(${i}-1)-${r}+6`)}+1`,o=this.delta(this.thisUnit("day").begin,"-",s,"day"),u=this.delta(this.thisUnit("day").begin,"-",`(${s})-1`,"day");return{begin:o,end:u.sql}}}}isIn(e,r,i){let s=">=",o="<",u="AND";return e&&(u="OR",s="<",o=">="),r=this.time(r),i=this.time(i),`${this.expr} ${s} ${r} ${u} ${this.expr} ${o} ${i}`}}P4.TemporalFilterCompiler=uXe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.FilterCompilers=void 0;const e=B4,r=P4;function i(u){return u.replace(/([%_\\])/g,"\\$1")}function s(u){return u===">"?"<=":u==="<"?">=":u===">="?"<":">"}function o(u,a){const l=` OR ${a} IS NULL`;return u.length===1?`${u[0]}${l}`:`(${u.join(" AND ")})${l}`}t.FilterCompilers={compile(u,a,l,c){if(a===null)return"true";if(u==="string"&&(0,e.isStringFilter)(a))return t.FilterCompilers.stringCompile(a,l,c);if(u==="number"&&(0,e.isNumberFilter)(a))return t.FilterCompilers.numberCompile(a,l,c);if(u==="boolean"&&(0,e.isBooleanFilter)(a))return t.FilterCompilers.booleanCompile(a,l,c);if((u==="date"||u==="timestamp")&&(0,e.isTemporalFilter)(a))return t.FilterCompilers.temporalCompile(a,l,c,u);throw new Error("INTERNAL ERROR: No filter compiler for "+u)},numberCompile(u,a,l){switch(u.operator){case"!=":case"=":{const c=u.operator==="="&&u.not||u.operator==="!="&&!u.not,f=u.values.join(", ");return u.values.length===1?c?`${a} != ${f} OR ${a} IS NULL`:`${a} = ${f}`:c?`${a} NOT IN (${f}) OR ${a} IS NULL`:`${a} IN (${f})`}case">":case"<":case">=":case"<=":return u.values.map(c=>`${a} ${u.operator} ${c}`).join(u.not?" AND ":" OR ");case"range":{let c=u.startOperator,f=u.endOperator,x=" AND ";return u.not&&(c=s(c),f=s(f),x=" OR "),`${a} ${c} ${u.startValue} ${x} ${a} ${f} ${u.endValue}`}case"null":return u.not?`${a} IS NOT NULL`:`${a} IS NULL`;case"()":{const c="("+t.FilterCompilers.numberCompile(u.expr,a,l)+")";return u.not?`NOT ${c}`:c}case"and":case"or":return u.members.map(c=>t.FilterCompilers.numberCompile(c,a,l)).join(` ${u.operator.toUpperCase()} `)}},booleanCompile(u,a,l){switch(u.operator){case"false":return`${a} = false`;case"false_or_null":return`${a} IS NULL OR ${a} = false`;case"null":return u.not?`${a} IS NOT NULL`:`${a} IS NULL`;case"true":return a}},stringCompile(u,a,l){switch(u.operator){case"null":return u.not?`${a} IS NOT NULL`:`${a} IS NULL`;case"empty":return u.not?`COALESCE(${a},'') != ''`:`COALESCE(${a},'') = ''`;case"=":{if(u.values.length===1){const f=u.not?"!=":"=",x=`${a} ${f} ${l.sqlLiteralString(u.values[0])}`;return u.not?`(${x} OR ${a} IS NULL)`:x}const c="("+u.values.map(f=>l.sqlLiteralString(f)).join(", ")+")";return u.not?`(${a} NOT IN ${c} OR ${a} IS NULL)`:`${a} IN ${c}`}case"()":{const c="("+t.FilterCompilers.stringCompile(u.expr,a,l)+")";return u.not?`not ${c}`:c}case"contains":{const c=u.values.map(f=>"%"+i(f)+"%");return u.not?o(c.map(f=>l.sqlLike("NOT LIKE",a,f)),a):c.map(f=>l.sqlLike("LIKE",a,f)).join(" OR ")}case"starts":{const c=u.values.map(f=>i(f)+"%");return u.not?o(c.map(f=>l.sqlLike("NOT LIKE",a,f)),a):c.map(f=>l.sqlLike("LIKE",a,f)).join(" OR ")}case"ends":{const c=u.values.map(f=>"%"+i(f));return u.not?o(c.map(f=>l.sqlLike("NOT LIKE",a,f)),a):c.map(f=>l.sqlLike("LIKE",a,f)).join(" OR ")}case"~":return u.not?o(u.escaped_values.map(c=>l.sqlLike("NOT LIKE",a,c)),a):u.escaped_values.map(c=>l.sqlLike("LIKE",a,c)).join(" OR ");case"and":return u.members.map(f=>t.FilterCompilers.stringCompile(f,a,l)).join(" AND ");case"or":return u.members.map(f=>t.FilterCompilers.stringCompile(f,a,l)).join(" AND ");case",":{const c=[],f=[];let x=!1,h=!1,p=!1,m=!1;for(const E of u.members)switch(E.operator){case"or":case"and":case",":c.push(E);break;case"null":E.not?h=!0:x=!0;break;case"empty":E.not?(m=!0,h=!0):(p=!0,x=!0);break;default:(E.not?f:c).push(E)}if(p&&m||x&&h)return"false";let y="";if(c.length>0||x||p){m=!1,h=!1;const E=c.map(A=>t.FilterCompilers.stringCompile(A,a,l));p&&E.push(`${a} = ''`),x&&E.push(`${a} IS NULL`),y=E.join(" OR ")}let g="";if(f.length>0||m||h){const E=f.map(A=>t.FilterCompilers.stringCompile(A,a,l));m&&E.push(`${a} != ''`),h&&E.push(`${a} IS NOT NULL`),g=E.join(" AND ")}return y?g!==""?`(${y}) AND (${g})`:y:g!==""?g:"true"}}},temporalCompile(u,a,l,c){return new r.TemporalFilterCompiler(a,l,c).compile(u)}}}(fae),Object.defineProperty($s,"__esModule",{value:!0}),$s.QueryModel=$s.getResultStructDefForQuery=$s.getResultStructDefForView=$s.Segment=void 0;const aXe=Up,lXe=Mp,cXe=Ey,ke=Xe,Tn=$t,U4=Hp,fXe=ai,xXe=fae,dXe=B4;function Cae(t){return t.map(e=>encodeURIComponent(e)).join("/")}function sB(t){return`'${t}'`}function hXe(t){return t.replace(/[^a-zA-Z0-9_]/g,"_o_")}function Gp(t){const e=[];for(const r of t.fields.filter(ke.fieldIsIntrinsic))e.push({type:r.type,sqlExpression:(0,ke.getIdentifier)(r),rawName:(0,ke.getIdentifier)(r),sqlOutputName:(0,ke.getIdentifier)(r)});return e}class pXe extends Set{add_use(e){if(e!==void 0)return this.add(e)}hasAsymetricFunctions(){return this.has("sum")||this.has("avg")||this.has("count")||this.has("generic_asymmetric_aggregate")}}class Sy{constructor(e=!0,r){this.parent=r,this.withs=[],this.udfs=[],this.pdts=[],this.dependenciesToMaterialize={},this.stagePrefix="__stage",this.useCTE=e}getName(e){return`${this.stagePrefix}${e}`}root(){return this.parent===void 0?this:this.parent.root()}addStage(e){return this.useCTE?(this.withs.push(e),this.getName(this.withs.length-1)):(this.withs[0]=e,(0,Tn.indent)(`
1045
+ `)},S.prototype.clone=function(){return new S(this.states,this.state)},S.prototype.has=function(D){return!0},{compile:_,states:C,error:Object.freeze({error:!0}),fallback:Object.freeze({fallback:!0}),keywords:b}})})(hae);var X$=hae.exports,qt={};Object.defineProperty(qt,"__esModule",{value:!0}),qt.mkUnits=qt.timeLiteral=qt.joinTemporal=qt.temporalNot=qt.numNot=qt.mkValues=qt.mkRange=qt.joinNumbers=qt.conjoin=qt.matchOp=qt.escape=qt.unescape=qt.maybeNot=void 0;const Sa=bn;function IJe(t){const[e,r]=t;return e&&r&&(0,Sa.isStringFilter)(r)?{...r,not:!0}:r}qt.maybeNot=IJe;function vy(t){return t.replace(/\\(.)/g,"$1")}qt.unescape=vy;function $Je(t){const e=t.toLowerCase();return e==="null"||e==="empty"?"\\"+t:t.replace(/([,; |()\\%_-])/g,"\\$1")}qt.escape=$Je;function M4(t){let e=!1,r=!1,i=0,s=!1;const o=t.length;for(let u=0;u<o;u+=1){const a=t[u];if(a===" "||a===" "){i+=1;continue}i=0,a==="%"?(s=!0,u===0&&(e=!0),r=!0):(r=!1,a==="\\"?u+=1:a==="_"&&(s=!0))}return{hasLike:s,percentEnd:r&&o>1,percentStart:e&&o>1,endSpace:i}}function BJe(t){let e=t.trimStart();const{hasLike:r,percentEnd:i,percentStart:s,endSpace:o}=M4(e);if(o>0&&(e=e.slice(0,-o)),r){if(s&&i){const u=e.slice(1,-1);if(!M4(u).hasLike&&u.length>0)return{operator:"contains",values:[vy(u)]}}else if(i){const u=e.slice(0,-1);if(!M4(u).hasLike)return{operator:"starts",values:[vy(u)]}}else if(s){const u=e.slice(1);if(!M4(u).hasLike)return{operator:"ends",values:[vy(u)]}}return{operator:"~",escaped_values:[e]}}return e.toLowerCase()==="null"||e==="NULL"?{operator:"null"}:e==="empty"||e==="EMPTY"?{operator:"empty"}:{operator:"=",values:[vy(e)]}}qt.matchOp=BJe;function Z$(t,e){var r,i;return t.operator===e.operator&&((r=t.not)!==null&&r!==void 0?r:!1)===((i=e.not)!==null&&i!==void 0?i:!1)}function kJe(t,e,r){if((0,Sa.isStringFilter)(t)&&(0,Sa.isStringFilter)(r)){if(e===","){if(t.operator==="~"&&Z$(t,r))return{...t,escaped_values:[...t.escaped_values,...r.escaped_values]};if((0,Sa.isStringCondition)(t)&&Z$(t,r))return{...t,values:[...t.values,...r.values]}}const i=e===","?",":e==="|"?"or":e===";"?"and":void 0;if(i)return t.operator===i?{...t,members:[...t.members,r]}:{operator:i,members:[t,r]}}return null}qt.conjoin=kJe;function MJe(t,e,r){if((0,Sa.isNumberFilter)(t)&&(0,Sa.isNumberFilter)(r)){if(e==="or"&&t.operator==="="&&Z$(t,r)){const i={operator:"=",values:[...t.values,...r.values]};return t.not&&(i.not=!0),i}if(e==="and"||e==="or")return t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}}return null}qt.joinNumbers=MJe;function PJe(t,e,r,i){return{operator:"range",startValue:e,startOperator:t==="("?">":">=",endValue:r,endOperator:i===")"?"<":"<="}}qt.mkRange=PJe;function UJe(t,e){return{values:[t,...e]}}qt.mkValues=UJe;function jJe(t,e){return(0,Sa.isNumberFilter)(t)&&e?t.operator==="="?{operator:"!=",values:t.values}:t.operator==="!="?{operator:"=",values:t.values}:{...t,not:!0}:t}qt.numNot=jJe;function qJe(t,e){return(0,Sa.isTemporalFilter)(t)&&e?{...t,not:!0}:t}qt.temporalNot=qJe;function HJe(t,e,r){return(0,Sa.isTemporalFilter)(t)&&(0,Sa.isTemporalFilter)(r)&&(e==="and"||e==="or")?t.operator===e?{...t,members:[...t.members,r]}:{operator:e,members:[t,r]}:null}qt.joinTemporal=HJe;function QJe(t,e){const r={moment:"literal",literal:t};return e&&(r.units=e),r}qt.timeLiteral=QJe;function zJe(t){switch(t.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"}}qt.mkUnits=zJe;var GJe=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(J$,"__esModule",{value:!0});function WJe(t){return t[0]}const pae=GJe(X$),Qp=qt,Ln=pae.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:pae.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to"})},oparen:"(",cparen:")",obrack:"[",cbrack:"]",comma:",",op:/<=|>=|<|>/,ne:"!=",eq:"=",float:/-?(?:\d+)?\.\d+(?:[Ee][+-]?\d+)?/,numberE:/-?\d+[Ee][+-]?\d+/,integer:/-?\d+/}),VJe=Ln.next;Ln.next=(t=>()=>{for(;;){const e=t.call(Ln);if(e===void 0||e.type!=="WS")return e}})(VJe);const YJe={Lexer:Ln,ParserRules:[{name:"numberFilter",symbols:["numberFilter","conjunction","numberUnary"],postprocess:([t,e,r])=>(0,Qp.joinNumbers)(t,e[0].text,r)},{name:"numberFilter",symbols:["numberUnary"],postprocess:t=>t[0]},{name:"numberUnary$ebnf$1",symbols:[Ln.has("NOT")?{type:"NOT"}:NOT],postprocess:WJe},{name:"numberUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"numberUnary",symbols:["numberUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,Qp.numNot)(e,t)},{name:"clause",symbols:[Ln.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause$ebnf$1",symbols:[]},{name:"clause$ebnf$1",symbols:["clause$ebnf$1","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:["N","clause$ebnf$1"],postprocess:([t,e])=>({operator:"=",...(0,Qp.mkValues)(t,e)})},{name:"clause$ebnf$2",symbols:[]},{name:"clause$ebnf$2",symbols:["clause$ebnf$2","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[Ln.has("eq")?{type:"eq"}:eq,"N","clause$ebnf$2"],postprocess:([t,e,r])=>({operator:"=",...(0,Qp.mkValues)(e,r)})},{name:"clause$ebnf$3",symbols:[]},{name:"clause$ebnf$3",symbols:["clause$ebnf$3","numberList"],postprocess:t=>t[0].concat([t[1]])},{name:"clause",symbols:[Ln.has("ne")?{type:"ne"}:ne,"N","clause$ebnf$3"],postprocess:([t,e,r])=>({operator:"!=",...(0,Qp.mkValues)(e,r)})},{name:"clause",symbols:[Ln.has("op")?{type:"op"}:op,"N"],postprocess:([t,e])=>({operator:t.text,values:[e]})},{name:"clause",symbols:[Ln.has("oparen")?{type:"oparen"}:oparen,"numberFilter",Ln.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:["openInterval","N",Ln.has("TO")?{type:"TO"}:TO,"N","closeInterval"],postprocess:([t,e,r,i,s])=>(0,Qp.mkRange)(t[0].text,e,i,s[0].text)},{name:"numberList",symbols:[Ln.has("comma")?{type:"comma"}:comma,"N"],postprocess:([t,e])=>e},{name:"closeInterval",symbols:[Ln.has("cbrack")?{type:"cbrack"}:cbrack]},{name:"closeInterval",symbols:[Ln.has("cparen")?{type:"cparen"}:cparen]},{name:"openInterval",symbols:[Ln.has("obrack")?{type:"obrack"}:obrack]},{name:"openInterval",symbols:[Ln.has("oparen")?{type:"oparen"}:oparen]},{name:"N$subexpression$1",symbols:[Ln.has("float")?{type:"float"}:float]},{name:"N$subexpression$1",symbols:[Ln.has("numberE")?{type:"numberE"}:numberE]},{name:"N$subexpression$1",symbols:[Ln.has("integer")?{type:"integer"}:integer]},{name:"N",symbols:["N$subexpression$1"],postprocess:([t])=>t[0].text},{name:"conjunction",symbols:[Ln.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[Ln.has("AND")?{type:"AND"}:AND]}],ParserStart:"numberFilter"};J$.default=YJe;var zp={};Object.defineProperty(zp,"__esModule",{value:!0}),zp.run_parser=void 0;const KJe=bn;function JJe(t,e){try{e.feed(t);const i=e.finish()[0];return i&&(0,KJe.isFilterExpression)(i)?{parsed:i,log:[]}:{parsed:null,log:[]}}catch(r){let i=r.message,s=1,o=t.length;if(r.token){const u=r.token;s=u.col,o=u.text.length;const l=r.message.match(new RegExp("(?<=A ).*(?= based on:)","g")).map(c=>c.replace(/\s+token/i,""));i=`Unexpected ${u.type} token "${u.value}"`,l&&l.length&&(i+=` Tokens expected: ${[...new Set(l)]}`)}return{parsed:null,log:[{message:i,startIndex:s-1,endIndex:s-1+o-1,severity:"error"}]}}}zp.run_parser=JJe,function(t){var e=T&&T.__createBinding||(Object.create?function(c,f,x,h){h===void 0&&(h=x);var p=Object.getOwnPropertyDescriptor(f,x);(!p||("get"in p?!f.__esModule:p.writable||p.configurable))&&(p={enumerable:!0,get:function(){return f[x]}}),Object.defineProperty(c,h,p)}:function(c,f,x,h){h===void 0&&(h=x),c[h]=f[x]}),r=T&&T.__setModuleDefault||(Object.create?function(c,f){Object.defineProperty(c,"default",{enumerable:!0,value:f})}:function(c,f){c.default=f}),i=T&&T.__importStar||function(c){if(c&&c.__esModule)return c;var f={};if(c!=null)for(var x in c)x!=="default"&&Object.prototype.hasOwnProperty.call(c,x)&&e(f,c,x);return r(f,c),f},s=T&&T.__importDefault||function(c){return c&&c.__esModule?c:{default:c}};Object.defineProperty(t,"__esModule",{value:!0}),t.NumberFilterExpression=void 0;const o=bn,u=i(K$),a=s(J$),l=zp;t.NumberFilterExpression={parse(c){if(c.match(/^\s*$/))return{parsed:null,log:[]};const f=new u.Parser(u.Grammar.fromCompiled(a.default)),x=(0,l.run_parser)(c,f);return x.parsed&&(0,o.isNumberFilter)(x.parsed)?{parsed:x.parsed,log:[]}:{parsed:null,log:x.log}},unparse(c){if(c===null)return"";switch(c.operator){case"=":return c.values.join(", ");case"!=":return"!= "+c.values.join(", ");case">":case"<":case"<=":case">=":return c.not?c.values.map(f=>c.operator==="="?`not ${f}`:`not ${c.operator} ${f}`).join(", "):c.values.map(f=>`${c.operator} ${f}`).join(", ");case"range":{const f=c.startOperator===">"?"(":"[",x=c.endOperator==="<"?")":"]",h=`${f}${c.startValue} to ${c.endValue}${x}`;return c.not?`not ${h}`:h}case"null":return c.not?"not null":"null";case"and":case"or":return c.members.map(f=>t.NumberFilterExpression.unparse(f)).join(` ${c.operator} `);case"()":{const f="("+t.NumberFilterExpression.unparse(c.expr)+")";return c.not?"not "+f:f}}return`no unparse for ${JSON.stringify(c)}`}}}(xae);var mae={},eB={},XJe=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(eB,"__esModule",{value:!0});function ZJe(t){return t[0]}const eXe=XJe(X$),tB=qt,fu=eXe.default.compile({WS:/[ \t]+/,comma:",",semi:";",or:"|",open:"(",close:")",minus:"-",matchStr:/(?:\\[^\n]|[^\n,;()|])+/}),tXe=fu.next;fu.next=(t=>()=>{for(;;){const e=t.call(fu);if(e==null||e.type!=="WS")return e}})(tXe);const nXe={Lexer:fu,ParserRules:[{name:"stringFilter",symbols:["stringFilter","conjunction","sfUnary"],postprocess:([t,e,r])=>(0,tB.conjoin)(t,e[0].text,r)},{name:"stringFilter",symbols:["sfUnary"],postprocess:t=>t[0]},{name:"sfUnary$ebnf$1",symbols:[fu.has("minus")?{type:"minus"}:minus],postprocess:ZJe},{name:"sfUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"sfUnary",symbols:["sfUnary$ebnf$1","clause"],postprocess:t=>(0,tB.maybeNot)(t)},{name:"parens",symbols:[fu.has("open")?{type:"open"}:open,"stringFilter",fu.has("close")?{type:"close"}:close],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"clause",symbols:[fu.has("matchStr")?{type:"matchStr"}:matchStr],postprocess:([t])=>(0,tB.matchOp)(t.text)},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"conjunction",symbols:[fu.has("comma")?{type:"comma"}:comma]},{name:"conjunction",symbols:[fu.has("semi")?{type:"semi"}:semi]},{name:"conjunction",symbols:[fu.has("or")?{type:"or"}:or]}],ParserStart:"stringFilter"};eB.default=nXe,function(t){var e=T&&T.__createBinding||(Object.create?function(f,x,h,p){p===void 0&&(p=h);var m=Object.getOwnPropertyDescriptor(x,h);(!m||("get"in m?!x.__esModule:m.writable||m.configurable))&&(m={enumerable:!0,get:function(){return x[h]}}),Object.defineProperty(f,p,m)}:function(f,x,h,p){p===void 0&&(p=h),f[p]=x[h]}),r=T&&T.__setModuleDefault||(Object.create?function(f,x){Object.defineProperty(f,"default",{enumerable:!0,value:x})}:function(f,x){f.default=x}),i=T&&T.__importStar||function(f){if(f&&f.__esModule)return f;var x={};if(f!=null)for(var h in f)h!=="default"&&Object.prototype.hasOwnProperty.call(f,h)&&e(x,f,h);return r(x,f),x},s=T&&T.__importDefault||function(f){return f&&f.__esModule?f:{default:f}};Object.defineProperty(t,"__esModule",{value:!0}),t.StringFilterExpression=void 0;const o=bn,u=i(K$),a=s(eB),l=qt,c=zp;t.StringFilterExpression={parse(f){if(f.match(/^\s*$/))return{parsed:null,log:[]};const x=new u.Parser(u.Grammar.fromCompiled(a.default)),h=(0,c.run_parser)(f,x);return h.parsed&&(0,o.isStringFilter)(h.parsed)?{parsed:h.parsed,log:[]}:{parsed:null,log:h.log}},unparse(f){if(f===null)return"";switch(f.operator){case"=":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)).join(", "):f.values.map(x=>(0,l.escape)(x)).join(", ");case"~":return f.not?f.escaped_values.map(x=>"-"+x).join(", "):f.escaped_values.join(", ");case"starts":return f.not?f.values.map(x=>"-"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>(0,l.escape)(x)+"%").join(", ");case"ends":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)).join(", "):f.values.map(x=>"%"+(0,l.escape)(x)).join(", ");case"contains":return f.not?f.values.map(x=>"-%"+(0,l.escape)(x)+"%").join(", "):f.values.map(x=>"%"+(0,l.escape)(x)+"%").join(", ");case"or":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(" | ");case"and":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join("; ");case",":return f.members.map(x=>t.StringFilterExpression.unparse(x)).join(", ");case"()":{const x="("+t.StringFilterExpression.unparse(f.expr)+")";return f.not?"-"+x:x}case"null":return f.not?"-null":"null";case"empty":return f.not?"-empty":"empty"}}}}(mae);var gae={},nB={},rXe=T&&T.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(nB,"__esModule",{value:!0});function iXe(t){return t[0]}const yae=rXe(X$),xu=qt,Ke=yae.default.compile({WS:/[ \t]+/,id:{match:/[a-zA-Z]+/,type:yae.default.keywords({AND:"and",OR:"or",NOT:"not",NULL_KW:"null",TO:"to",NOW:"now",LAST:"last",THIS:"this",NEXT:"next",AGO:"ago",FROM:"from",BEFORE:"before",AFTER:"after",FOR:"for",TODAY:"today",YESTERDAY:"yesterday",TOMORROW:"tomorrow",SECOND:"second",MINUTE:"minute",HOUR:"hour",DAY:"day",WEEK:"week",MONTH:"month",QUARTER:"quarter",YEAR:"year",SECONDS:"seconds",MINUTES:"minutes",HOURS:"hours",DAYS:"days",WEEKS:"weeks",MONTHS:"months",QUARTERS:"quarters",YEARS:"years",MONDAY:"monday",TUESDAY:"tuesday",WEDNESDAY:"wednesday",THURSDAY:"thursday",FRIDAY:"friday",SATURDAY:"saturday",SUNDAY:"sunday"})},oparen:"(",cparen:")",comma:",",literal:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*)?)/,lit_week:/\d\d\d\d-\d\d-\d\d-[Ww][Kk]/,lit_quarter:/\d\d\d\d-[qQ][1234]/,lit_min:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d/,lit_hour:/\d\d\d\d-\d\d-\d\d[ Tt]\d\d/,lit_day:/\d\d\d\d-\d\d-\d\d/,lit_month:/\d\d\d\d-\d\d/,lit_year:/\d\d\d\d/,n:/\d+/}),sXe=Ke.next;Ke.next=(t=>()=>{for(;;){const e=t.call(Ke);if(e===void 0||e.type!=="WS")return e}})(sXe);const oXe={Lexer:Ke,ParserRules:[{name:"temporalFilter",symbols:["temporalFilter","conjunction","temporalUnary"],postprocess:([t,e,r])=>(0,xu.joinTemporal)(t,e[0].text,r)},{name:"temporalFilter",symbols:["temporalUnary"],postprocess:t=>t[0]},{name:"temporalUnary$ebnf$1",symbols:[Ke.has("NOT")?{type:"NOT"}:NOT],postprocess:iXe},{name:"temporalUnary$ebnf$1",symbols:[],postprocess:()=>null},{name:"temporalUnary",symbols:["temporalUnary$ebnf$1","clause"],postprocess:([t,e])=>(0,xu.temporalNot)(e,t)},{name:"duration",symbols:["number","unit"],postprocess:([t,e])=>({units:e,n:t})},{name:"number",symbols:[Ke.has("n")?{type:"n"}:n],postprocess:([t])=>t.text},{name:"number",symbols:[Ke.has("lityear")?{type:"lityear"}:lityear],postprocess:([t])=>t.text},{name:"unit$subexpression$1",symbols:[Ke.has("SECOND")?{type:"SECOND"}:SECOND]},{name:"unit$subexpression$1",symbols:[Ke.has("MINUTE")?{type:"MINUTE"}:MINUTE]},{name:"unit$subexpression$1",symbols:[Ke.has("HOUR")?{type:"HOUR"}:HOUR]},{name:"unit$subexpression$1",symbols:[Ke.has("DAY")?{type:"DAY"}:DAY]},{name:"unit$subexpression$1",symbols:[Ke.has("WEEK")?{type:"WEEK"}:WEEK]},{name:"unit$subexpression$1",symbols:[Ke.has("MONTH")?{type:"MONTH"}:MONTH]},{name:"unit$subexpression$1",symbols:[Ke.has("QUARTER")?{type:"QUARTER"}:QUARTER]},{name:"unit$subexpression$1",symbols:[Ke.has("YEAR")?{type:"YEAR"}:YEAR]},{name:"unit$subexpression$1",symbols:[Ke.has("SECONDS")?{type:"SECONDS"}:SECONDS]},{name:"unit$subexpression$1",symbols:[Ke.has("MINUTES")?{type:"MINUTES"}:MINUTES]},{name:"unit$subexpression$1",symbols:[Ke.has("HOURS")?{type:"HOURS"}:HOURS]},{name:"unit$subexpression$1",symbols:[Ke.has("DAYS")?{type:"DAYS"}:DAYS]},{name:"unit$subexpression$1",symbols:[Ke.has("WEEKS")?{type:"WEEKS"}:WEEKS]},{name:"unit$subexpression$1",symbols:[Ke.has("MONTHS")?{type:"MONTHS"}:MONTHS]},{name:"unit$subexpression$1",symbols:[Ke.has("QUARTERS")?{type:"QUARTERS"}:QUARTERS]},{name:"unit$subexpression$1",symbols:[Ke.has("YEARS")?{type:"YEARS"}:YEARS]},{name:"unit",symbols:["unit$subexpression$1"],postprocess:([t])=>(0,xu.mkUnits)(t[0].text)},{name:"clause",symbols:[Ke.has("NULL_KW")?{type:"NULL_KW"}:NULL_KW],postprocess:()=>({operator:"null"})},{name:"clause",symbols:["parens"],postprocess:t=>t[0]},{name:"clause",symbols:["duration"],postprocess:([t])=>({operator:"in_last",...t})},{name:"clause",symbols:[Ke.has("BEFORE")?{type:"BEFORE"}:BEFORE,"moment"],postprocess:([t,e])=>({operator:"before",before:e})},{name:"clause",symbols:[Ke.has("AFTER")?{type:"AFTER"}:AFTER,"moment"],postprocess:([t,e])=>({operator:"after",after:e})},{name:"clause",symbols:["moment",Ke.has("TO")?{type:"TO"}:TO,"moment"],postprocess:([t,e,r])=>({operator:"to",fromMoment:t,toMoment:r})},{name:"clause",symbols:["moment",Ke.has("FOR")?{type:"FOR"}:FOR,"duration"],postprocess:([t,e,r])=>({...r,operator:"for",begin:t})},{name:"clause$subexpression$1",symbols:[Ke.has("LAST")?{type:"LAST"}:LAST]},{name:"clause$subexpression$1",symbols:[Ke.has("NEXT")?{type:"NEXT"}:NEXT]},{name:"clause",symbols:["clause$subexpression$1","duration"],postprocess:([t,e])=>({operator:t[0].text,...e})},{name:"clause",symbols:["moment"],postprocess:([t])=>({operator:"in",in:t})},{name:"lastNextThis",symbols:[Ke.has("THIS")?{type:"THIS"}:THIS],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Ke.has("NEXT")?{type:"NEXT"}:NEXT],postprocess:([t])=>t.text.toLowerCase()},{name:"lastNextThis",symbols:[Ke.has("LAST")?{type:"LAST"}:LAST],postprocess:([t])=>t.text.toLowerCase()},{name:"moment",symbols:[Ke.has("NOW")?{type:"NOW"}:NOW],postprocess:()=>({moment:"now"})},{name:"moment",symbols:["lastNextThis","unit"],postprocess:([t,e])=>({moment:t,units:e})},{name:"moment",symbols:[Ke.has("TODAY")?{type:"TODAY"}:TODAY],postprocess:()=>({moment:"today"})},{name:"moment",symbols:[Ke.has("YESTERDAY")?{type:"YESTERDAY"}:YESTERDAY],postprocess:()=>({moment:"yesterday"})},{name:"moment",symbols:[Ke.has("TOMORROW")?{type:"TOMORROW"}:TOMORROW],postprocess:()=>({moment:"tomorrow"})},{name:"moment",symbols:["duration",Ke.has("AGO")?{type:"AGO"}:AGO],postprocess:([t,e])=>({moment:"ago",...t})},{name:"moment",symbols:["duration",Ke.has("FROM")?{type:"FROM"}:FROM,Ke.has("NOW")?{type:"NOW"}:NOW],postprocess:([t,e])=>({moment:"from_now",...t})},{name:"moment",symbols:[Ke.has("NEXT")?{type:"NEXT"}:NEXT,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"next"})},{name:"moment",symbols:[Ke.has("LAST")?{type:"LAST"}:LAST,"weekday"],postprocess:([t,e])=>({moment:e.toLowerCase(),which:"last"})},{name:"moment",symbols:["weekday"],postprocess:([t])=>({moment:t.toLowerCase(),which:"last"})},{name:"moment",symbols:["timeLiteral"],postprocess:t=>t[0]},{name:"timeLiteral",symbols:[Ke.has("literal")?{type:"literal"}:literal],postprocess:([t])=>(0,xu.timeLiteral)(t.text)},{name:"timeLiteral",symbols:[Ke.has("lit_day")?{type:"lit_day"}:lit_day],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"day")},{name:"timeLiteral",symbols:[Ke.has("lit_min")?{type:"lit_min"}:lit_min],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"minute")},{name:"timeLiteral",symbols:[Ke.has("lit_hour")?{type:"lit_hour"}:lit_hour],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"hour")},{name:"timeLiteral",symbols:[Ke.has("lit_month")?{type:"lit_month"}:lit_month],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"month")},{name:"timeLiteral",symbols:[Ke.has("lit_quarter")?{type:"lit_quarter"}:lit_quarter],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"quarter")},{name:"timeLiteral",symbols:[Ke.has("lit_week")?{type:"lit_week"}:lit_week],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"week")},{name:"timeLiteral",symbols:[Ke.has("lit_year")?{type:"lit_year"}:lit_year],postprocess:([t])=>(0,xu.timeLiteral)(t.text,"year")},{name:"weekday$subexpression$1",symbols:[Ke.has("MONDAY")?{type:"MONDAY"}:MONDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("TUESDAY")?{type:"TUESDAY"}:TUESDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("WEDNESDAY")?{type:"WEDNESDAY"}:WEDNESDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("THURSDAY")?{type:"THURSDAY"}:THURSDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("FRIDAY")?{type:"FRIDAY"}:FRIDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("SATURDAY")?{type:"SATURDAY"}:SATURDAY]},{name:"weekday$subexpression$1",symbols:[Ke.has("SUNDAY")?{type:"SUNDAY"}:SUNDAY]},{name:"weekday",symbols:["weekday$subexpression$1"],postprocess:([t])=>t[0].text},{name:"parens",symbols:[Ke.has("oparen")?{type:"oparen"}:oparen,"temporalFilter",Ke.has("cparen")?{type:"cparen"}:cparen],postprocess:([t,e,r])=>({operator:"()",expr:e})},{name:"conjunction",symbols:[Ke.has("OR")?{type:"OR"}:OR]},{name:"conjunction",symbols:[Ke.has("AND")?{type:"AND"}:AND]}],ParserStart:"temporalFilter"};nB.default=oXe,function(t){var e=T&&T.__createBinding||(Object.create?function(h,p,m,y){y===void 0&&(y=m);var g=Object.getOwnPropertyDescriptor(p,m);(!g||("get"in g?!p.__esModule:g.writable||g.configurable))&&(g={enumerable:!0,get:function(){return p[m]}}),Object.defineProperty(h,y,g)}:function(h,p,m,y){y===void 0&&(y=m),h[y]=p[m]}),r=T&&T.__setModuleDefault||(Object.create?function(h,p){Object.defineProperty(h,"default",{enumerable:!0,value:p})}:function(h,p){h.default=p}),i=T&&T.__importStar||function(h){if(h&&h.__esModule)return h;var p={};if(h!=null)for(var m in h)m!=="default"&&Object.prototype.hasOwnProperty.call(h,m)&&e(p,h,m);return r(p,h),p},s=T&&T.__importDefault||function(h){return h&&h.__esModule?h:{default:h}};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=void 0;const o=bn,u=s(nB),a=i(K$),l=zp;t.TemporalFilterExpression={parse(h){if(h.match(/^\s*$/))return{parsed:null,log:[]};const p=new a.Parser(a.Grammar.fromCompiled(u.default)),m=(0,l.run_parser)(h,p);return m.parsed&&(0,o.isTemporalFilter)(m.parsed)?{parsed:m.parsed,log:[]}:{parsed:null,log:m.log}},unparse(h){if(h===null)return"";switch(h.operator){case"null":return c(h,"null");case"in":return c(h,x(h.in));case"()":return"("+t.TemporalFilterExpression.unparse(h.expr)+")";case"in_last":return c(h,f(h));case"last":case"next":return c(h,`${h.operator} ${f(h)}`);case"before":return c(h,`before ${x(h.before)}`);case"after":return c(h,`after ${x(h.after)}`);case"to":return c(h,`${x(h.fromMoment)} to ${x(h.toMoment)}`);case"for":return c(h,`${x(h.begin)} for ${f(h)}`);case"or":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" or ");case"and":return h.members.map(p=>t.TemporalFilterExpression.unparse(p)).join(" and ")}}};function c(h,p){return"not"in h&&h.not?"not "+p:p}function f(h){return h.n==="1"?`1 ${h.units}`:`${h.n} ${h.units}s`}function x(h){switch(h.moment){case"literal":return h.literal;case"now":case"today":case"yesterday":case"tomorrow":return h.moment;case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":return h.which==="next"?"next "+h.moment:h.moment;case"this":case"next":case"last":return`${h.moment} ${h.units}`;case"ago":return`${f(h)} ago`;case"from_now":return`${f(h)} from now`}}}(gae),function(t){var e=T&&T.__createBinding||(Object.create?function(a,l,c,f){f===void 0&&(f=c);var x=Object.getOwnPropertyDescriptor(l,c);(!x||("get"in x?!l.__esModule:x.writable||x.configurable))&&(x={enumerable:!0,get:function(){return l[c]}}),Object.defineProperty(a,f,x)}:function(a,l,c,f){f===void 0&&(f=c),a[f]=l[c]}),r=T&&T.__exportStar||function(a,l){for(var c in a)c!=="default"&&!Object.prototype.hasOwnProperty.call(l,c)&&e(l,a,c)};Object.defineProperty(t,"__esModule",{value:!0}),t.TemporalFilterExpression=t.StringFilterExpression=t.NumberFilterExpression=t.BooleanFilterExpression=void 0,r(bn,t);var i=k4;Object.defineProperty(t,"BooleanFilterExpression",{enumerable:!0,get:function(){return i.BooleanFilterExpression}});var s=xae;Object.defineProperty(t,"NumberFilterExpression",{enumerable:!0,get:function(){return s.NumberFilterExpression}});var o=mae;Object.defineProperty(t,"StringFilterExpression",{enumerable:!0,get:function(){return o.StringFilterExpression}});var u=gae;Object.defineProperty(t,"TemporalFilterExpression",{enumerable:!0,get:function(){return u.TemporalFilterExpression}})}(B4);var P4={};const Cy=yP(H1e);Object.defineProperty(P4,"__esModule",{value:!0}),P4.TemporalFilterCompiler=void 0;const rB=Xe,Zx=Cy,Eae="yyyy",Aae=`${Eae}-LL`,iB=`${Aae}-dd`,_ae=`${iB} HH`,vae=`${_ae}:mm`,xs=`${vae}:ss`;class uXe{constructor(e,r,i="timestamp"){this.expr=e,this.timetype=i,this.d=r}time(e){return this.timetype==="timestamp"?e:this.d.sqlCast({},{node:"cast",e:{node:"genericSQLExpr",src:["",e],kids:{args:[]},sql:e},srcType:{type:"timestamp"},dstType:{type:"date"},safe:!1})}compile(e){const r=this.expr;switch(e.operator){case"after":return`${r} ${e.not?"<":">="} ${this.time(this.moment(e.after).end)}`;case"before":return`${r} ${e.not?">=":"<"} ${this.time(this.moment(e.before).begin.sql)}`;case"in":{const i=this.moment(e.in);return i.begin.sql===i.end?e.not?`${r} != ${this.time(i.end)} OR ${r} IS NULL`:`${r} = ${this.time(i.end)}`:this.isIn(e.not,i.begin.sql,i.end)}case"for":{const i=this.moment(e.begin),s=this.delta(i.begin,"+",e.n,e.units);return this.isIn(e.not,i.begin.sql,s.sql)}case"in_last":{const i=Number(e.n)-1,s=this.nowDot(e.units),o=i>0?this.delta(s,"-",i.toString(),e.units):s,u=this.delta(s,"+","1",e.units);return this.isIn(e.not,o.sql,u.sql)}case"to":{const i=this.moment(e.fromMoment),s=this.moment(e.toMoment);return this.isIn(e.not,i.begin.sql,s.begin.sql)}case"last":{const i=this.nowDot(e.units),s=this.delta(i,"-",e.n,e.units);return this.isIn(e.not,s.sql,i.sql)}case"next":{const i=this.nowDot(e.units),s=this.delta(i,"+","1",e.units),o=this.delta(i,"+",(Number(e.n)+1).toString(),e.units);return this.isIn(e.not,s.sql,o.sql)}case"null":return e.not?`${r} IS NOT NULL`:`${r} IS NULL`;case"()":{const i="("+this.compile(e.expr)+")";return e.not?`NOT ${i}`:i}case"and":case"or":return e.members.map(i=>this.compile(i)).join(` ${e.operator.toUpperCase()} `)}}expandLiteral(e){let r=e.literal;switch(e.units){case"year":{const i=Zx.DateTime.fromFormat(r,Eae),s=this.literalNode(i.toFormat(xs)),o=i.plus({year:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"month":{const i=Zx.DateTime.fromFormat(r,Aae),s=this.literalNode(i.toFormat(xs)),o=i.plus({month:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"day":{const i=Zx.DateTime.fromFormat(r,iB),s=this.literalNode(i.toFormat(xs)),o=i.plus({day:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"hour":{const i=Zx.DateTime.fromFormat(r,_ae),s=this.literalNode(i.toFormat(xs)),o=i.plus({hour:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"minute":{const i=Zx.DateTime.fromFormat(r,vae),s=this.literalNode(i.toFormat(xs)),o=i.plus({minute:1});return{begin:s,end:this.literalNode(o.toFormat(xs)).sql}}case"week":{const o=Zx.DateTime.fromFormat(r.slice(0,10),iB).plus({day:1}).startOf("week").minus({day:1}),u=this.literalNode(o.toFormat(xs)),a=o.plus({days:7});return{begin:u,end:this.literalNode(a.toFormat(xs)).sql}}case"quarter":{const i=r.slice(0,4),s=r.slice(6);s==="1"?r=`${i}-01-01 00:00:00`:s==="2"?r=`${i}-03-01 00:00:00`:s==="3"?r=`${i}-06-01 00:00:00`:r=`${i}-09-01 00:00:00`;const o=this.literalNode(r),a=Zx.DateTime.fromFormat(r,xs).plus({months:3});return{begin:o,end:this.literalNode(a.toFormat(xs)).sql}}case void 0:case"second":{const i=this.literalNode(r);return{begin:i,end:i.sql}}}}literalNode(e){const r={node:"timeLiteral",typeDef:{type:"timestamp"},literal:e};return{...r,sql:this.d.sqlLiteralTime({},r)}}nowExpr(){return{node:"now",typeDef:{type:"timestamp"},sql:this.d.sqlNowExpr()}}n(e){return{node:"numberLiteral",literal:e,sql:e}}delta(e,r,i,s){const o={node:"delta",op:r,units:s,kids:{base:(0,rB.mkTemporal)(e,"timestamp"),delta:this.n(i)}};return{...o,sql:this.d.sqlAlterTimeExpr(o)}}dayofWeek(e){const r={node:"extract",e:(0,rB.mkTemporal)(e,"timestamp"),units:"day_of_week"};return{...r,sql:this.d.sqlTimeExtractExpr({},r)}}nowDot(e){const r={node:"trunc",e:this.nowExpr(),units:e};return{...r,sql:this.d.sqlTruncExpr({},r)}}thisUnit(e){const r=this.nowDot(e),i=this.delta(r,"+","1",e);return{begin:r,end:i.sql}}lastUnit(e){const r=this.nowDot(e);return{begin:this.delta(r,"-","1",e),end:r.sql}}nextUnit(e){const r=this.nowDot(e),i=this.delta(r,"+","1",e),s=this.delta(r,"+","2",e);return{begin:i,end:s.sql}}mod7(e){return this.d.hasModOperator?`(${e})%7`:`MOD(${e},7)`}moment(e){switch(e.moment){case"now":{const r=this.nowExpr();return{begin:r,end:r.sql}}case"literal":return this.expandLiteral(e);case"ago":case"from_now":{const r=this.nowDot(e.units),i=(0,rB.mkTemporal)(r,"timestamp"),s=this.delta(i,e.moment==="ago"?"-":"+",e.n,e.units);if(e.moment==="ago"&&e.n==="1")return{begin:s,end:r.sql};const o=Number(e.n)+(e.moment==="ago"?-1:1),u={...s,kids:{base:i,delta:this.n(o.toString())}};return{begin:s,end:this.d.sqlAlterTimeExpr(u)}}case"today":return this.thisUnit("day");case"yesterday":return this.lastUnit("day");case"tomorrow":return this.nextUnit("day");case"this":return this.thisUnit(e.units);case"last":return this.lastUnit(e.units);case"next":return this.nextUnit(e.units);case"monday":case"tuesday":case"wednesday":case"thursday":case"friday":case"saturday":case"sunday":{const r=["sunday","monday","tuesday","wednesday","thursday","friday","saturday"].indexOf(e.moment),i=this.dayofWeek(this.nowExpr()).sql;if(e.which==="next"){const a=`${this.mod7(`${r}-(${i}-1)+6`)}+1`,l=this.delta(this.thisUnit("day").begin,"+",a,"day"),c=this.delta(this.thisUnit("day").begin,"+",`${a}+1`,"day");return{begin:l,end:c.sql}}const s=`${this.mod7(`(${i}-1)-${r}+6`)}+1`,o=this.delta(this.thisUnit("day").begin,"-",s,"day"),u=this.delta(this.thisUnit("day").begin,"-",`(${s})-1`,"day");return{begin:o,end:u.sql}}}}isIn(e,r,i){let s=">=",o="<",u="AND";return e&&(u="OR",s="<",o=">="),r=this.time(r),i=this.time(i),`${this.expr} ${s} ${r} ${u} ${this.expr} ${o} ${i}`}}P4.TemporalFilterCompiler=uXe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.FilterCompilers=void 0;const e=B4,r=P4;function i(u){return u.replace(/([%_\\])/g,"\\$1")}function s(u){return u===">"?"<=":u==="<"?">=":u===">="?"<":">"}function o(u,a){const l=` OR ${a} IS NULL`;return u.length===1?`${u[0]}${l}`:`(${u.join(" AND ")})${l}`}t.FilterCompilers={compile(u,a,l,c){if(a===null)return"true";if(u==="string"&&(0,e.isStringFilter)(a))return t.FilterCompilers.stringCompile(a,l,c);if(u==="number"&&(0,e.isNumberFilter)(a))return t.FilterCompilers.numberCompile(a,l,c);if(u==="boolean"&&(0,e.isBooleanFilter)(a))return t.FilterCompilers.booleanCompile(a,l,c);if((u==="date"||u==="timestamp")&&(0,e.isTemporalFilter)(a))return t.FilterCompilers.temporalCompile(a,l,c,u);throw new Error("INTERNAL ERROR: No filter compiler for "+u)},numberCompile(u,a,l){switch(u.operator){case"!=":case"=":{const c=u.operator==="="&&u.not||u.operator==="!="&&!u.not,f=u.values.join(", ");return u.values.length===1?c?`${a} != ${f} OR ${a} IS NULL`:`${a} = ${f}`:c?`${a} NOT IN (${f}) OR ${a} IS NULL`:`${a} IN (${f})`}case">":case"<":case">=":case"<=":return u.values.map(c=>`${a} ${u.operator} ${c}`).join(u.not?" AND ":" OR ");case"range":{let c=u.startOperator,f=u.endOperator,x=" AND ";return u.not&&(c=s(c),f=s(f),x=" OR "),`${a} ${c} ${u.startValue} ${x} ${a} ${f} ${u.endValue}`}case"null":return u.not?`${a} IS NOT NULL`:`${a} IS NULL`;case"()":{const c="("+t.FilterCompilers.numberCompile(u.expr,a,l)+")";return u.not?`NOT ${c}`:c}case"and":case"or":return u.members.map(c=>t.FilterCompilers.numberCompile(c,a,l)).join(` ${u.operator.toUpperCase()} `)}},booleanCompile(u,a,l){switch(u.operator){case"false":return`${a} = false`;case"false_or_null":return`${a} IS NULL OR ${a} = false`;case"null":return u.not?`${a} IS NOT NULL`:`${a} IS NULL`;case"true":return a}},stringCompile(u,a,l){switch(u.operator){case"null":return u.not?`${a} IS NOT NULL`:`${a} IS NULL`;case"empty":return u.not?`COALESCE(${a},'') != ''`:`COALESCE(${a},'') = ''`;case"=":{if(u.values.length===1){const f=u.not?"!=":"=",x=`${a} ${f} ${l.sqlLiteralString(u.values[0])}`;return u.not?`(${x} OR ${a} IS NULL)`:x}const c="("+u.values.map(f=>l.sqlLiteralString(f)).join(", ")+")";return u.not?`(${a} NOT IN ${c} OR ${a} IS NULL)`:`${a} IN ${c}`}case"()":{const c="("+t.FilterCompilers.stringCompile(u.expr,a,l)+")";return u.not?`not ${c}`:c}case"contains":{const c=u.values.map(f=>"%"+i(f)+"%");return u.not?o(c.map(f=>l.sqlLike("NOT LIKE",a,f)),a):c.map(f=>l.sqlLike("LIKE",a,f)).join(" OR ")}case"starts":{const c=u.values.map(f=>i(f)+"%");return u.not?o(c.map(f=>l.sqlLike("NOT LIKE",a,f)),a):c.map(f=>l.sqlLike("LIKE",a,f)).join(" OR ")}case"ends":{const c=u.values.map(f=>"%"+i(f));return u.not?o(c.map(f=>l.sqlLike("NOT LIKE",a,f)),a):c.map(f=>l.sqlLike("LIKE",a,f)).join(" OR ")}case"~":return u.not?o(u.escaped_values.map(c=>l.sqlLike("NOT LIKE",a,c)),a):u.escaped_values.map(c=>l.sqlLike("LIKE",a,c)).join(" OR ");case"and":return u.members.map(f=>t.FilterCompilers.stringCompile(f,a,l)).join(" AND ");case"or":return u.members.map(f=>t.FilterCompilers.stringCompile(f,a,l)).join(" AND ");case",":{const c=[],f=[];let x=!1,h=!1,p=!1,m=!1;for(const E of u.members)switch(E.operator){case"or":case"and":case",":c.push(E);break;case"null":E.not?h=!0:x=!0;break;case"empty":E.not?(m=!0,h=!0):(p=!0,x=!0);break;default:(E.not?f:c).push(E)}if(p&&m||x&&h)return"false";let y="";if(c.length>0||x||p){m=!1,h=!1;const E=c.map(A=>t.FilterCompilers.stringCompile(A,a,l));p&&E.push(`${a} = ''`),x&&E.push(`${a} IS NULL`),y=E.join(" OR ")}let g="";if(f.length>0||m||h){const E=f.map(A=>t.FilterCompilers.stringCompile(A,a,l));m&&E.push(`${a} != ''`),h&&E.push(`${a} IS NOT NULL`),g=E.join(" AND ")}return y?g!==""?`(${y}) AND (${g})`:y:g!==""?g:"true"}}},temporalCompile(u,a,l,c){return new r.TemporalFilterCompiler(a,l,c).compile(u)}}}(fae),Object.defineProperty($s,"__esModule",{value:!0}),$s.QueryModel=$s.getResultStructDefForQuery=$s.getResultStructDefForView=$s.Segment=void 0;const aXe=Up,lXe=Mp,cXe=Ey,ke=Xe,Tn=$t,U4=Hp,fXe=ai,xXe=fae,dXe=B4;function Cae(t){return t.map(e=>encodeURIComponent(e)).join("/")}function sB(t){return`'${t}'`}function hXe(t){return t.replace(/[^a-zA-Z0-9_]/g,"_o_")}function Gp(t){const e=[];for(const r of t.fields.filter(ke.fieldIsIntrinsic))e.push({type:r.type,sqlExpression:(0,ke.getIdentifier)(r),rawName:(0,ke.getIdentifier)(r),sqlOutputName:(0,ke.getIdentifier)(r)});return e}class pXe extends Set{add_use(e){if(e!==void 0)return this.add(e)}hasAsymetricFunctions(){return this.has("sum")||this.has("avg")||this.has("count")||this.has("generic_asymmetric_aggregate")}}class Sy{constructor(e=!0,r){this.parent=r,this.withs=[],this.udfs=[],this.pdts=[],this.dependenciesToMaterialize={},this.stagePrefix="__stage",this.useCTE=e}getName(e){return`${this.stagePrefix}${e}`}root(){return this.parent===void 0?this:this.parent.root()}addStage(e){return this.useCTE?(this.withs.push(e),this.getName(this.withs.length-1)):(this.withs[0]=e,(0,Tn.indent)(`
1046
1046
  (${e})
1047
1047
  `))}addUDF(e,r,i){var s;let{sql:o,lastStageName:u}=e.combineStages(!0);if(u===void 0)throw new Error("Internal Error: no stage to combine");o+=r.sqlCreateFunctionCombineLastStage(u,Gp(i),(s=i.resultMetadata)===null||s===void 0?void 0:s.orderBy);const a=`${r.udfPrefix}${this.root().udfs.length}`;return o=r.sqlCreateFunction(a,o),this.root().udfs.push(o),a}addMaterializedQuery(e,r,i){var s;const o=r.name;if(!o)throw new Error(`Source ${e} on a unnamed query that is tagged as materialize, only named queries can be materialized.`);const u=(s=r.location)===null||s===void 0?void 0:s.url;if(!u)throw new Error(`Trying to materialize query ${o}, but its path is not set.`);const a=(0,U4.buildQueryMaterializationSpec)(u,o,i);return this.root().dependenciesToMaterialize[a.id]=a,a.id}addPDT(e,r){const i=this.combineStages(!1).sql+this.withs[this.withs.length-1],o=`scratch.${e+(0,Tn.generateHash)(i)}`;return this.root().pdts.push(r.sqlCreateTableAsSelect(o,i)),o}combineStages(e){if(!this.useCTE)return{sql:this.withs[0],lastStageName:this.withs[0]};let r=this.getName(0),i="WITH ",s="";for(let o=0;o<this.withs.length-(e?0:1);o++){const u=this.withs[o];if(r=this.getName(o),u===void 0)throw new Error(`Expected sql WITH to be present for stage ${r}.`);s+=`${i}${r} AS (
1048
1048
  ${(0,Tn.indent)(u)})
@@ -1487,7 +1487,7 @@ ${S}`,b)}else{if(C.urls)for(const S of C.urls)try{if(NR(S))throw new Error("In o
1487
1487
  `)}}this.stream.write(`
1488
1488
  ]
1489
1489
  `),this.stream.close()}}Fe.JSONWriter=dxt;class hxt extends nP{constructor(){super(...arguments),this.columnSeparator=",",this.rowSeparator=`
1490
- `,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(e){const r=e.includes(this.quoteCharacter),i=e.includes(this.columnSeparator),s=e.includes(this.rowSeparator),o=i||r||s;return r&&(e=e.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),o&&(e=this.quoteCharacter+e+this.quoteCharacter),e}stringify(e){return e===null?this.emptyCell:e instanceof Date?e.toISOString():typeof e=="boolean"||typeof e=="number"?JSON.stringify(e):`${e}`}getColWeight(e){let r=e;Array.isArray(e)&&(r=e[0]);let i=0;for(const s in r){i=i+1;const o=r[s];if(Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u}}return i}getHeaderRow(e){const r=[];let i=0;for(const s in e){r.push(this.escape(s));const o=e[s];if(i++,Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u;for(let a=0;a<u;a++)r.push(this.emptyCell)}}return{rows:[r.join(this.columnSeparator)],length:1,width:i}}mergeMatrices(e){const r=Math.max(...e.map(o=>o.length)),i=e.reduce((o,u)=>o+u.width,0),s=[];for(let o=0;o<r;o++){const u=[];for(const a of e)if(o<a.length)u.push(a.rows[o]);else{const l=Array(a.width).fill(this.emptyCell);u.push(...l)}s.push(u.join(this.columnSeparator))}return{rows:s,length:r,width:i}}getChildMatrix(e){if(Array.isArray(e)){if(e.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const r=[],i=this.getHeaderRow(e[0]);r.push(...i.rows);const s=i.width;let o=1;for(const u of e){const a=this.getRowMatrix(u);o=o+a.length,r.push(...a.rows)}return{rows:r,length:o,width:s}}getRowMatrix(e){const r=[];for(const i in e){const s=e[i];if(Array.isArray(s)){const o=this.getChildMatrix(s);r.push(o)}else{const o={rows:[this.stringify(s)],length:1,width:1};r.push(o)}}return this.mergeMatrices(r)}async process(e){let r=!1;for await(const i of e){if(!r&&this.includeHeader){const o=this.getHeaderRow(i.toObject());this.stream.write(o.rows[0]),this.stream.write(this.rowSeparator),r=!0}const s=this.getRowMatrix(i.toObject());for(const o of s.rows)this.stream.write(o),this.stream.write(this.rowSeparator)}this.stream.close()}}Fe.CSVWriter=hxt;class pxt{constructor(e){this.modelCache=e,this.modelDependencies=new Map,this.modelInvalidationKeys=new Map}async getCachedModelDef(e,r){const i=this.modelDependencies.get(r);if(i===void 0)return;const s=[r,...FR(i)],o={};for(const a of s){const l=this.modelInvalidationKeys.get(a);if(l==null)return;o[a]=l}for(const a of s)if(await rP(e,new URL(a))!==o[a])return;const u=await this.modelCache.getModel(new URL(r));if(u!==void 0){for(const a of s)if(u.invalidationKeys[a]!==o[a])return;return{modelDef:u.modelDef,invalidationKeys:o}}}async setCachedModelDef(e,r){this.modelDependencies.set(e,r.modelDef.dependencies);const i={};for(const o of[e,...FR(r.modelDef.dependencies)]){if(r.invalidationKeys[o]===null)return!1;if(r.invalidationKeys[o]===void 0)throw new Error(`Missing invalidation key for dependency ${o}`);this.modelInvalidationKeys.set(o,r.invalidationKeys[o]),i[o]=r.invalidationKeys[o]}return!!await this.modelCache.setModel(new URL(e),{modelDef:r.modelDef,invalidationKeys:i})}}Fe.CacheManager=pxt;function FR(t){return[...Object.keys(t),...Object.values(t).map(FR).flat()]}class mxt{constructor(){this.models=new Map}async getModel(e){return Promise.resolve(this.models.get(e.toString()))}async setModel(e,r){return this.models.set(e.toString(),r),Promise.resolve(!0)}}Fe.InMemoryModelCache=mxt;function Cxe(t){return(0,oxt.v5)(t,"76c17e9d-f3ce-5f2d-bfde-98ad3d2a37f6")}async function wR(t,e){const r=await t.readURL(e),{contents:i,invalidationKey:s}=typeof r=="string"?{contents:r,invalidationKey:void 0}:r;return{contents:i,invalidationKey:NR(e.toString())?null:s??Cxe(i)}}async function rP(t,e){return NR(e.toString())?null:t.getInvalidationKey!==void 0?await t.getInvalidationKey(e):(await wR(t,e)).invalidationKey}function NR(t){return t.startsWith("internal://")}var LR={};Object.defineProperty(LR,"__esModule",{value:!0}),LR.toAsyncGenerator=void 0;async function*gxt(t){let e=!1;function r(s){let o;const u=new Promise(a=>{o=a});return s(a=>{o({done:!0,isError:!0,error:a})},a=>{o({done:!1,value:a,isError:!1,next:new Promise(l=>{o=l})})},()=>{o({done:!0,isError:!1})}),u}let i=r(t);for(;!e;){const s=await i;if(s.done){if(e=!0,s.isError)throw s.error;break}else i=s.next,yield s.value}}LR.toAsyncGenerator=gxt;var Sxe={},Yc={},iP={},AE={};Object.defineProperty(AE,"__esModule",{value:!0}),AE.MALLOY_INTERFACE_TYPES=void 0,AE.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"}},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:{}},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},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}}},CompileQueryRequest:{type:"struct",name:"CompileQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileQueryResponse:{type:"struct",name:"CompileQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",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},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}}},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}}},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}}},Expression:{type:"union",name:"Expression",options:{field_reference:"Reference",time_truncation:"TimeTruncationFieldReference",filtered_field:"FilteredField"}},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"}},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"}},FilterStringApplication:{type:"struct",name:"FilterStringApplication",fields:{field_reference:{type:"Reference",optional:!1,array:!1},filter:{type:"string",optional:!1,array:!1}}},FilteredField:{type:"struct",name:"FilteredField",fields:{field_reference:{type:"Reference",optional:!1,array:!1},where:{type:"Where",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}}},LiteralValue:{type:"union",name:"LiteralValue",options:{string_literal:"StringLiteral",number_literal:"NumberLiteral",date_literal:"DateLiteral",timestamp_literal:"TimestampLiteral",boolean_literal:"BooleanLiteral",null_literal:"NullLiteral"}},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}}},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}}},NumberLiteral:{type:"struct",name:"NumberLiteral",fields:{number_value:{type:"number",optional:!1,array:!1}}},NumberSubtype:{type:"enum",name:"NumberSubtype",values:{integer:1,decimal:2}},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:"AtomicType",optional:!1,array:!1},default_value:{type:"LiteralValue",optional:!0,array:!1}}},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}}},RunIndexQueryRequest:{type:"struct",name:"RunIndexQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},source_name:{type:"string",optional:!1,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}}},RunQueryRequest:{type:"struct",name:"RunQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryResponse:{type:"struct",name:"RunQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",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}}},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}}},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:"Where",nest:"Nest"}},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}}},Where:{type:"struct",name:"Where",fields:{filter:{type:"Filter",optional:!1,array:!1}}}};var IR={},$R={},BR={};Object.defineProperty(BR,"__esModule",{value:!0}),BR.RESERVED_WORDS=void 0,BR.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"],Object.defineProperty($R,"__esModule",{value:!0}),$R.maybeQuoteIdentifier=void 0;const yxt=BR;function Ext(t){const e=!t.match(/^[A-Za-z_][A-Za-z_0-9]*$/),r=yxt.RESERVED_WORDS.includes(t.toLowerCase());return e||r}function Axt(t){const e=t.split(".");for(let r=0;r<e.length;r++)Ext(e[r])&&(e[r]=`\`${e[r]}\``);return e.join(".")}$R.maybeQuoteIdentifier=Axt,Object.defineProperty(IR,"__esModule",{value:!0}),IR.queryToMalloy=void 0;const _E=$R;function _xt(t,{tabWidth:e}={tabWidth:2}){const r=Txt(t);return Cxt(r,{tabWidth:e})}IR.queryToMalloy=_xt;const sP=Symbol("indent"),yu=Symbol("newline"),oP=Symbol("outdent"),vxt=Symbol("optional_newline_indent");function Cxt(t,{tabWidth:e}={tabWidth:2}){let r="",i=0,s=!0;for(const o of t)if(o===yu)r+=`
1490
+ `,this.quoteCharacter='"',this.includeHeader=!0,this.emptyCell=""}escape(e){const r=e.includes(this.quoteCharacter),i=e.includes(this.columnSeparator),s=e.includes(this.rowSeparator),o=i||r||s;return r&&(e=e.replace(new RegExp(this.quoteCharacter,"g"),this.quoteCharacter+this.quoteCharacter)),o&&(e=this.quoteCharacter+e+this.quoteCharacter),e}stringify(e){return e===null?this.emptyCell:e instanceof Date?e.toISOString():typeof e=="boolean"||typeof e=="number"?JSON.stringify(e):`${e}`}getColWeight(e){let r=e;Array.isArray(e)&&(r=e[0]);let i=0;for(const s in r){i=i+1;const o=r[s];if(Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u}}return i}getHeaderRow(e){const r=[];let i=0;for(const s in e){r.push(this.escape(s));const o=e[s];if(i++,Array.isArray(o)){const u=this.getColWeight(o)-1;i=i+u;for(let a=0;a<u;a++)r.push(this.emptyCell)}}return{rows:[r.join(this.columnSeparator)],length:1,width:i}}mergeMatrices(e){const r=Math.max(...e.map(o=>o.length)),i=e.reduce((o,u)=>o+u.width,0),s=[];for(let o=0;o<r;o++){const u=[];for(const a of e)if(o<a.length)u.push(a.rows[o]);else{const l=Array(a.width).fill(this.emptyCell);u.push(...l)}s.push(u.join(this.columnSeparator))}return{rows:s,length:r,width:i}}getChildMatrix(e){if(Array.isArray(e)){if(e.length===0)return{rows:[""],length:1,width:1}}else return{rows:["Invalid data found, value is not an array"],length:1,width:1};const r=[],i=this.getHeaderRow(e[0]);r.push(...i.rows);const s=i.width;let o=1;for(const u of e){const a=this.getRowMatrix(u);o=o+a.length,r.push(...a.rows)}return{rows:r,length:o,width:s}}getRowMatrix(e){const r=[];for(const i in e){const s=e[i];if(Array.isArray(s)){const o=this.getChildMatrix(s);r.push(o)}else{const o={rows:[this.stringify(s)],length:1,width:1};r.push(o)}}return this.mergeMatrices(r)}async process(e){let r=!1;for await(const i of e){if(!r&&this.includeHeader){const o=this.getHeaderRow(i.toObject());this.stream.write(o.rows[0]),this.stream.write(this.rowSeparator),r=!0}const s=this.getRowMatrix(i.toObject());for(const o of s.rows)this.stream.write(o),this.stream.write(this.rowSeparator)}this.stream.close()}}Fe.CSVWriter=hxt;class pxt{constructor(e){this.modelCache=e,this.modelDependencies=new Map,this.modelInvalidationKeys=new Map}async getCachedModelDef(e,r){const i=this.modelDependencies.get(r);if(i===void 0)return;const s=[r,...FR(i)],o={};for(const a of s){const l=this.modelInvalidationKeys.get(a);if(l==null)return;o[a]=l}for(const a of s)if(await rP(e,new URL(a))!==o[a])return;const u=await this.modelCache.getModel(new URL(r));if(u!==void 0){for(const a of s)if(u.invalidationKeys[a]!==o[a])return;return{modelDef:u.modelDef,invalidationKeys:o}}}async setCachedModelDef(e,r){this.modelDependencies.set(e,r.modelDef.dependencies);const i={};for(const o of[e,...FR(r.modelDef.dependencies)]){if(r.invalidationKeys[o]===null)return!1;if(r.invalidationKeys[o]===void 0)throw new Error(`Missing invalidation key for dependency ${o}`);this.modelInvalidationKeys.set(o,r.invalidationKeys[o]),i[o]=r.invalidationKeys[o]}return!!await this.modelCache.setModel(new URL(e),{modelDef:r.modelDef,invalidationKeys:i})}}Fe.CacheManager=pxt;function FR(t){return[...Object.keys(t),...Object.values(t).map(FR).flat()]}class mxt{constructor(){this.models=new Map}async getModel(e){return Promise.resolve(this.models.get(e.toString()))}async setModel(e,r){return this.models.set(e.toString(),r),Promise.resolve(!0)}}Fe.InMemoryModelCache=mxt;function Cxe(t){return(0,oxt.v5)(t,"76c17e9d-f3ce-5f2d-bfde-98ad3d2a37f6")}async function wR(t,e){const r=await t.readURL(e),{contents:i,invalidationKey:s}=typeof r=="string"?{contents:r,invalidationKey:void 0}:r;return{contents:i,invalidationKey:NR(e.toString())?null:s??Cxe(i)}}async function rP(t,e){return NR(e.toString())?null:t.getInvalidationKey!==void 0?await t.getInvalidationKey(e):(await wR(t,e)).invalidationKey}function NR(t){return t.startsWith("internal://")}var LR={};Object.defineProperty(LR,"__esModule",{value:!0}),LR.toAsyncGenerator=void 0;async function*gxt(t){let e=!1;function r(s){let o;const u=new Promise(a=>{o=a});return s(a=>{o({done:!0,isError:!0,error:a})},a=>{o({done:!1,value:a,isError:!1,next:new Promise(l=>{o=l})})},()=>{o({done:!0,isError:!1})}),u}let i=r(t);for(;!e;){const s=await i;if(s.done){if(e=!0,s.isError)throw s.error;break}else i=s.next,yield s.value}}LR.toAsyncGenerator=gxt;var Sxe={},Yc={},iP={},AE={};Object.defineProperty(AE,"__esModule",{value:!0}),AE.MALLOY_INTERFACE_TYPES=void 0,AE.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"}},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:{}},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},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}}},CompileQueryRequest:{type:"struct",name:"CompileQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileQueryResponse:{type:"struct",name:"CompileQueryResponse",fields:{result:{type:"Result",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}}},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},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}}},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}}},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}}},Expression:{type:"union",name:"Expression",options:{field_reference:"Reference",time_truncation:"TimeTruncationFieldReference",filtered_field:"FilteredField"}},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"}},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"}},FilterStringApplication:{type:"struct",name:"FilterStringApplication",fields:{field_reference:{type:"Reference",optional:!1,array:!1},filter:{type:"string",optional:!1,array:!1}}},FilteredField:{type:"struct",name:"FilteredField",fields:{field_reference:{type:"Reference",optional:!1,array:!1},where:{type:"Where",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}}},LiteralValue:{type:"union",name:"LiteralValue",options:{string_literal:"StringLiteral",number_literal:"NumberLiteral",date_literal:"DateLiteral",timestamp_literal:"TimestampLiteral",boolean_literal:"BooleanLiteral",null_literal:"NullLiteral"}},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}}},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}}},NumberLiteral:{type:"struct",name:"NumberLiteral",fields:{number_value:{type:"number",optional:!1,array:!1}}},NumberSubtype:{type:"enum",name:"NumberSubtype",values:{integer:1,decimal:2}},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:"AtomicType",optional:!1,array:!1},default_value:{type:"LiteralValue",optional:!0,array:!1}}},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}}},RunIndexQueryRequest:{type:"struct",name:"RunIndexQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},source_name:{type:"string",optional:!1,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}}},RunQueryRequest:{type:"struct",name:"RunQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!1,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryResponse:{type:"struct",name:"RunQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",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}}},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}}},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:"Where",nest:"Nest"}},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}}},Where:{type:"struct",name:"Where",fields:{filter:{type:"Filter",optional:!1,array:!1}}}};var IR={},$R={},BR={};Object.defineProperty(BR,"__esModule",{value:!0}),BR.RESERVED_WORDS=void 0,BR.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"],Object.defineProperty($R,"__esModule",{value:!0}),$R.maybeQuoteIdentifier=void 0;const yxt=BR;function Ext(t){const e=!t.match(/^[A-Za-z_][A-Za-z_0-9]*$/),r=yxt.RESERVED_WORDS.includes(t.toLowerCase());return e||r}function Axt(t){const e=t.split(".");for(let r=0;r<e.length;r++)Ext(e[r])&&(e[r]=`\`${e[r]}\``);return e.join(".")}$R.maybeQuoteIdentifier=Axt,Object.defineProperty(IR,"__esModule",{value:!0}),IR.queryToMalloy=void 0;const _E=$R;function _xt(t,{tabWidth:e}={tabWidth:2}){const r=Txt(t);return Cxt(r,{tabWidth:e})}IR.queryToMalloy=_xt;const sP=Symbol("indent"),yu=Symbol("newline"),oP=Symbol("outdent"),vxt=Symbol("optional_newline_indent");function Cxt(t,{tabWidth:e}={tabWidth:2}){let r="",i=0,s=!0;for(const o of t)if(o===yu)r+=`
1491
1491
  `,s=!0;else if(o===oP)i--;else if(o===sP)i++;else{if(o===vxt)continue;s&&(r+=" ".repeat(i*e),s=!1),r+=o}return r}function kR(t,e,r,i){var s;if(e.includes(yu))return[t,yu,sP,...e,yu,oP,r];const u=((s=i==null?void 0:i.spaces)!==null&&s!==void 0?s:!0)?" ":"";return[t,u,...e,u,r]}function Sxt(t){return{contents:t,quoteCharacter:'"'}}function bxt(t){var e,r;switch(t.kind){case"boolean_literal":return[t.boolean_value.toString()];case"string_literal":{const{contents:i,quoteCharacter:s}=Sxt(t.string_value);return[s,i,s]}case"number_literal":return[t.number_value.toString()];case"null_literal":return["null"];case"date_literal":return[Txe(bxe(t.date_value),(e=t.granularity)!==null&&e!==void 0?e:"day")];case"timestamp_literal":return[Txe(bxe(t.timestamp_value),(r=t.granularity)!==null&&r!==void 0?r:"second")]}}function bxe(t){return new Date(t)}function yn(t,e){return t.toString().padStart(e,"0")}function Txe(t,e){switch(e){case"year":return`@${yn(t.getUTCFullYear(),4)}`;case"quarter":{const r=yn(t.getUTCFullYear(),4),i=Math.floor(t.getUTCMonth()/3)+1;return`@${r}-Q${i}`}case"month":{const r=yn(t.getUTCFullYear(),2),i=yn(t.getUTCMonth()+1,2);return`@${r}-${i}`}case"week":{const r=yn(t.getUTCFullYear(),2),i=yn(t.getUTCMonth()+1,2),s=yn(t.getUTCDate(),2);return`@WK${r}-${i}-${s}`}case"day":{const r=yn(t.getUTCFullYear(),2),i=yn(t.getUTCMonth()+1,2),s=yn(t.getUTCDate(),2);return`@${r}-${i}-${s}`}case"hour":{const r=yn(t.getUTCFullYear(),2),i=yn(t.getUTCMonth()+1,2),s=yn(t.getUTCDate(),2),o=yn(t.getUTCHours(),2);return`@${r}-${i}-${s} ${o}`}case"minute":{const r=yn(t.getUTCFullYear(),2),i=yn(t.getUTCMonth()+1,2),s=yn(t.getUTCDate(),2),o=yn(t.getUTCHours(),2),u=yn(t.getUTCMinutes(),2);return`@${r}-${i}-${s} ${o}:${u}`}case"second":{const r=yn(t.getUTCFullYear(),2),i=yn(t.getUTCMonth()+1,2),s=yn(t.getUTCDate(),2),o=yn(t.getUTCHours(),2),u=yn(t.getUTCMinutes(),2),a=yn(t.getUTCSeconds(),2);return`@${r}-${i}-${s} ${o}:${u}:${a}`}default:throw new Error("Unknown timeframe.")}}function Kc(t){var e;const r=[];for(const i of(e=t.path)!==null&&e!==void 0?e:[])r.push((0,_E.maybeQuoteIdentifier)(i)),r.push(".");if(r.push((0,_E.maybeQuoteIdentifier)(t.name)),t.parameters){const i=[];for(let s=0;s<t.parameters.length;s++){const o=t.parameters[s];i.push((0,_E.maybeQuoteIdentifier)(o.name)),i.push(" is "),i.push(...bxt(o.value)),s<t.parameters.length-1&&i.push(",",yu)}r.push(...kR("(",i,")",{spaces:!1}))}return r}function Txt(t){const e=[];return e.push(...N2(t.annotations)),e.push("run: "),e.push(...uP(t.definition)),e}function Rxt(t){const e=[];switch(t.kind){case"source_reference":{e.push(...Kc(t));break}case"refinement":e.push(...uP(t));break}return e}function uP(t){const e=[];switch(t.kind){case"arrow":{e.push(...Rxt(t.source)),e.push(" -> "),e.push(...hd(t.view));break}case"query_reference":{e.push(...Kc(t));break}case"refinement":{const r=uP(t.base);t.base.kind==="arrow"?e.push(...kR("(",r,")",{spaces:!1})):e.push(...r),e.push(" + "),e.push(...hd(t.refinement));break}}return e}function hd(t){const e=[];switch(t.kind){case"arrow":{e.push(...hd(t.source)),e.push(" -> "),e.push(...hd(t.view));break}case"view_reference":{e.push(...Kc(t));break}case"refinement":{e.push(...hd(t.base)),e.push(" + "),e.push(...hd(t.refinement));break}case"segment":{e.push(...Dxt(t));break}}return e}function Dxt(t){if(t.operations.length===0)return["{ }"];const e=t.operations.length>1,r=[];for(let i=0;i<t.operations.length;i++){const s=t.operations[i],o=[s];for(;i<t.operations.length-1;){const u=t.operations[i+1];if(u.kind===s.kind)o.push(u),i++;else break}r.push(...Oxt(o)),e&&i<t.operations.length-1&&r.push(yu)}return kR("{",r,"}")}function Oxt(t){switch(t[0].kind){case"aggregate":return Lxt(t);case"group_by":return Nxt(t);case"order_by":return Ixt(t);case"nest":return Bxt(t);case"limit":return Uxt(t);case"where":return Dxe(t)}}function vE(t,e,r=""){const i=[];i.push(`${t}:`);const s=e.length>1||e.some(o=>o.includes(yu));s?i.push(yu,sP):i.push(" ");for(let o=0;o<e.length;o++){const u=e[o];i.push(...u),e.length>1&&o<e.length-1&&i.push(r),s&&o<e.length-1&&i.push(yu)}return s&&i.push(oP),i}function Fxt(t){const e=[];return e.push(...wxt(t.expression)),e}function pht(t){return t}function wxt(t){switch(t.kind){case"field_reference":return Kc(t);case"time_truncation":return[...Kc(t.field_reference),".",t.truncation];case"filtered_field":return[...Kc(t.field_reference),...kR(" {",Dxe(t.where),"}")]}}function Rxe(t,e=!1){const r=[];return e||r.push(...N2(t.field.annotations)),t.name&&(r.push((0,_E.maybeQuoteIdentifier)(t.name)),r.push(" is ")),r.push(...Fxt(t.field)),r}function Nxt(t){const e=[],r=t.length===1;return r&&e.push(...N2(t[0].field.annotations)),e.push(...vE("group_by",t.map(i=>Rxe(i,r)))),e}function Lxt(t){const e=[],r=t.length===1;return r&&e.push(...N2(t[0].field.annotations)),e.push(...vE("aggregate",t.map(i=>Rxe(i,r)))),e}function Ixt(t){return vE("order_by",t.map($xt),",")}function $xt(t){const e=[];return e.push(...Kc(t.field_reference)),t.direction&&(e.push(" "),e.push(t.direction)),e}function Bxt(t){const e=[],r=t.length===1;return r&&e.push(...N2(t[0].view.annotations)),e.push(...vE("nest",t.map(i=>kxt(i,r)))),e}function kxt(t,e=!1){const r=[];return e||r.push(...N2(t.view.annotations)),t.name&&(r.push((0,_E.maybeQuoteIdentifier)(t.name)),r.push(" is ")),r.push(...Mxt(t.view)),r}function Mxt(t){return hd(t.definition)}function Pxt(t){return[`limit: ${t.limit}`]}function Uxt(t){const e=[];for(let r=0;r<t.length;r++)r!==0&&e.push(yu),e.push(...Pxt(t[r]));return e}function Dxe(t){return vE("where",t.map(Qxt),",")}const jxt=["`","'",'"'];function qxt(t){let e,r;for(const i of jxt){const s=Hxt(t,i);if(s===t)return`f${i}${t}${i}`;(r===void 0||s.length<r.length)&&(e=i,r=s)}return`f${e}${r}${e}`}function Hxt(t,e){let r="";for(let i=0;i<t.length;i++)t.slice(i).startsWith(e)?(r+="\\"+e,i+=e.length):(r+=t[i],t[i]==="\\"&&(r+=t[++i]));return r}function Qxt(t){switch(t.filter.kind){case"filter_string":return[...Kc(t.filter.field_reference)," ~ ",qxt(t.filter.filter)]}}function N2(t){return t?t.flatMap(zxt):[]}function zxt(t){return[t.value.trim(),yu]}var Ma={};Object.defineProperty(Ma,"__esModule",{value:!0}),Ma.convertToThrift=Ma.convertFromThrift=Ma.unnestUnions=Ma.nestUnions=void 0;const Gxt=AE;function aP(t){if(t==null)return t;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return t;if(Array.isArray(t))return t.map(aP);{const e={};let r;for(const i in t)i==="kind"?r=t[i]:e[i]=aP(t[i]);return r===void 0?e:{[r]:e}}}Ma.nestUnions=aP;function MR(t,e){if(t==null)return t;if(typeof t=="string"||typeof t=="number"||typeof t=="boolean")return t;if(Array.isArray(t))return t.map(r=>MR(r,e));{const r=L2(e);if(r.type==="union"){for(const i in r.options)if(t[i]!==void 0){const s=MR(t[i],r.options[i]);if(typeof s=="object")return{kind:i,...s}}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=MR(t[s],o.type)}return i}else throw new Error(`Cannot unnest unions in an enum type ${e}`)}}Ma.unnestUnions=MR;function PR(t,e){if(t==null)return t;if(typeof t=="string"||typeof t=="boolean")return t;if(typeof t=="number"){if(e==="number")return t;const r=L2(e);if(r.type!=="enum")throw new Error(`Found a number where a ${e} was expected`);const i=Object.entries(r.values).find(([,s])=>s===t);if(i===void 0)throw new Error(`${t} is not a valid enum value for ${e}`);return i[0]}else{if(Array.isArray(t))return t.map(r=>PR(r,e));{const r=L2(e);if(r.type==="union"){for(const i in r.options)if(t[i]!==void 0){const s=PR(t[i],r.options[i]);if(typeof s=="object")return{kind:i,...s}}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=PR(t[s],o.type)}return i}else throw new Error(`Cannot unnest unions in an enum type ${e}`)}}}Ma.convertFromThrift=PR;function L2(t){const e=Gxt.MALLOY_INTERFACE_TYPES[t];if(e===void 0)throw new Error(`Unknown Malloy interface type ${t}`);return e}function UR(t,e){if(t==null)return t;if(typeof t=="number"||typeof t=="boolean")return t;if(typeof t=="string"){if(e==="string")return t;const r=L2(e);if(r.type==="enum"){const i=r.values[t];if(i===void 0)throw new Error(`${t} is not a valid enum value for ${e}`);return i}}else{if(Array.isArray(t))return t.map(r=>UR(r,e));{const r=L2(e);if(r.type==="union"){const i=t.kind,s=r.options[i];if(s===void 0)throw new Error(`${i} is not a valid union of ${e}`);const o=L2(s);if(o.type!=="struct")throw new Error("Union fields must be structs");const u={};for(const a in t){if(a==="kind")continue;const l=o.fields[a];u[a]=UR(t[a],l.type)}return{[i]:u}}else if(r.type==="struct"){const i={};for(const s in t){const o=r.fields[s];if(o===void 0)throw new Error(`Unknown field ${s} in ${e}`);i[s]=UR(t[s],o.type)}return i}}}}Ma.convertToThrift=UR,function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.thingy4sddfdfsd=t.thingy4sdfsd=t.thingy4dfdsfs=t.thingy4asdfas=t.thingy4asdfasdf=t.thingy3dfdf=t.thingy3=t.thingy2asdf=t.thingyssdfg=t.thingy123r=t.thingy1=t.res=t.test=t.convertToThrift=t.convertFromThrift=t.unnestUnions=t.nestUnions=t.queryToMalloy=void 0,r(AE,t);var i=IR;Object.defineProperty(t,"queryToMalloy",{enumerable:!0,get:function(){return i.queryToMalloy}});var s=Ma;Object.defineProperty(t,"nestUnions",{enumerable:!0,get:function(){return s.nestUnions}}),Object.defineProperty(t,"unnestUnions",{enumerable:!0,get:function(){return s.unnestUnions}}),Object.defineProperty(t,"convertFromThrift",{enumerable:!0,get:function(){return s.convertFromThrift}}),Object.defineProperty(t,"convertToThrift",{enumerable:!0,get:function(){return s.convertToThrift}}),t.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:[]},t.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 * ..."},t.thingy1={definition:{kind:"query_reference",name:"flights_by_carrier"}},t.thingy123r={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},t.thingyssdfg={definition:{kind:"refinement",base:{kind:"query_reference",name:"flights"},refinement:{kind:"view_reference",name:"by_carrier"}}},t.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",field_reference:{name:"carrier"},filter:"WN"}}]}}}},t.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"}}}]}}}},t.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"}}}},t.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"}}}]}}},t.thingy4asdfas={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},t.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}]}}}},t.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}]}}},t.thingy4sddfdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[]}}}}(iP);var tn={},Wxt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Vxt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Yxt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Wxt(e,t,r);return Vxt(e,t),e};Object.defineProperty(tn,"__esModule",{value:!0}),tn.statedCompileQuery=tn.newCompileQueryState=tn.hasErrors=tn.compileSource=tn.compileModel=tn._statedCompileModel=tn.statedCompileSource=tn.statedCompileModel=tn.newCompileSourceState=tn.newCompileModelState=tn.updateCompileModelState=tn.compileQuery=void 0;const Kxt=Yxt(iP),Jxt=H4,Oxe=Ui,Xxt=Ia,Fxe=Yl,Zxt=ai,wxe=Zo,I2=hE;function Nxe(t,e){return`${t}:${e}`}function edt(t,e){return{type:"sql_select",selectStr:t.sql,connection:t.connection_name,dialect:e,fields:t.schema?Ixe(t.schema):[],name:(0,Fxe.sqlKey)(t.connection_name,t.sql)}}function tdt(t,e){return{type:"table",tablePath:t.name,connection:t.connection_name,dialect:e,fields:t.schema?Ixe(t.schema):[],name:Nxe(t.connection_name,t.name)}}function ndt(t){if(t!==void 0)return t==="decimal"?"float":"integer"}function Lxe(t){switch(t.kind){case"string_type":return{type:"string"};case"number_type":return{type:"number",numberType:ndt(t.subtype)};case"boolean_type":return{type:"boolean"};case"timestamp_type":return{type:"timestamp",timeframe:t.timeframe};case"date_type":return{type:"date",timeframe:t.timeframe};case"sql_native_type":return{type:"sql native",rawType:t.sql_type};case"json_type":return{type:"json"};case"array_type":{if(t.element_type.kind==="record_type")return{type:"array",elementTypeDef:{type:"record_element"},fields:t.element_type.fields.map(lP)};{const e=Lxe(t.element_type);if(e.type==="record")throw new Error("Arrays of records should be a repeated record type");return{type:"array",elementTypeDef:e}}}case"record_type":return{type:"record",fields:t.fields.map(lP)}}}function lP(t){const e=Lxe(t.type);return(0,Oxe.mkFieldDef)(e,t.name)}function rdt(t){if(t.kind!=="dimension")throw new Error("Table schemas must only have dimension fields");return lP(t)}function Ixe(t){const e=[];for(const r of t.fields)e.push(rdt(r));return e}function $xe(t){var e,r,i,s,o,u;const a={urls:{},tables:{},compileSQL:{},translations:{}};if(t){for(const l of(e=t.files)!==null&&e!==void 0?e:[])l.contents!==void 0&&(a.urls[l.url]=l.contents);for(const l of(r=t.table_schemas)!==null&&r!==void 0?r:[]){const c=(i=t.connections)===null||i===void 0?void 0:i.find(f=>f.name===l.connection_name);c&&l.schema&&c.dialect&&(a.tables[Nxe(l.connection_name,l.name)]=tdt(l,c.dialect))}for(const l of(s=t.sql_schemas)!==null&&s!==void 0?s:[]){const c=(o=t.connections)===null||o===void 0?void 0:o.find(f=>f.name===l.connection_name);c&&c.dialect&&(a.compileSQL[(0,Fxe.sqlKey)(l.connection_name,l.sql)]=edt(l,c.dialect))}for(const l of(u=t.translations)!==null&&u!==void 0?u:[])if(l.compiled_model_json){const c=JSON.parse(l.compiled_model_json);a.translations[l.url]=c}}return a}function Bxe(t,e,r){var i,s,o;const u={},a=new Set;if(t!==void 0&&(u.sql_schemas=[{sql:t.selectStr,connection_name:t.connection}],a.add(t.connection)),e!==void 0)for(const l of e)(i=u.files)!==null&&i!==void 0||(u.files=[]),u.files.push({url:l});if(r!==void 0)for(const l in r){const c=r[l],f=(s=c.connectionName)!==null&&s!==void 0?s:"__default__";(o=u.table_schemas)!==null&&o!==void 0||(u.table_schemas=[]),u.table_schemas.push({name:c.tablePath,connection_name:f}),a.add(f)}return a.size>0&&(u.connections=Array.from(a).map(l=>({name:l}))),u}function idt(t,e){return e??(e=jxe(t)),qxe(e)}tn.compileQuery=idt;function sdt(t,e){function r(s,o){var u,a;s.translator.update(o),s.extending&&r(s.extending,o),s.hasSource||(s.hasSource=(a=(u=e==null?void 0:e.files)===null||u===void 0?void 0:u.some(l=>l.url===s.translator.sourceURL))!==null&&a!==void 0?a:!1)}const i=$xe(e);r(t,i)}tn.updateCompileModelState=sdt;function jR(t,e,r){var i,s;const o=new Jxt.MalloyTranslator(t,null,$xe(e)),u=(s=(i=e==null?void 0:e.files)===null||i===void 0?void 0:i.some(a=>a.url===t))!==null&&s!==void 0?s:!1;return r?{extending:jR(r,e),translator:o,done:!1,hasSource:u}:{translator:o,done:!1,hasSource:u}}function kxe(t){return jR(t.model_url,t.compiler_needs,t.extend_model_url)}tn.newCompileModelState=kxe;function Mxe(t){return jR(t.model_url,t.compiler_needs,t.extend_model_url)}tn.newCompileSourceState=Mxe;function Pxe(t){return odt(CE(t),t.translator.sourceURL)}tn.statedCompileModel=Pxe;function Uxe(t,e){return ldt(CE(t),e,t.translator.sourceURL)}tn.statedCompileSource=Uxe;function CE(t){let e;if(t.extending){if(!t.extending.done){const i=CE(t.extending);if(!t.extending.done)return i}e=t.extending.translator.modelDef}if(!t.hasSource)return{compilerNeeds:Bxe(void 0,[t.translator.sourceURL],void 0)};const r=t.translator.translate(e);if(r.final){if(t.done=!0,r.modelDef)return{model:(0,Xxt.modelDefToModelInfo)(r.modelDef),modelDef:r.modelDef};if(r.problems===void 0||r.problems.length===0)throw new Error("No problems found, but no model either");return{logs:r.problems}}else return{compilerNeeds:Bxe(r.compileSQL,r.urls,r.tables),logs:r.problems}}tn._statedCompileModel=CE;function odt(t,e){const r=t.logs?(0,I2.mapLogs)(t.logs,e):void 0;if(t.compilerNeeds)return{compiler_needs:t.compilerNeeds,logs:r};{let i;return t.modelDef&&(i=[{url:e,compiled_model_json:JSON.stringify(t.modelDef)}]),{model:t.model,logs:r,translations:i}}}function udt(t,e){return e??(e=kxe(t)),Pxe(e)}tn.compileModel=udt;function adt(t){const e=Mxe(t);return Uxe(e,t.name)}tn.compileSource=adt;function ldt(t,e,r){const i=t.logs?(0,I2.mapLogs)(t.logs,r):void 0;if(t.model){const s=t.model.entries.find(o=>o.name===e);return s===void 0?{logs:[...i??[],{url:r,severity:"error",message:`Model does not contain a source named ${e}`,range:I2.DEFAULT_LOG_RANGE}]}:{source:s,logs:i}}else return{compiler_needs:t.compilerNeeds,logs:i}}function cdt(t){var e;return(e=t==null?void 0:t.some(r=>r.severity==="error"))!==null&&e!==void 0?e:!1}tn.hasErrors=cdt;function jxe(t){var e,r;const i=Kxt.queryToMalloy(t.query),s={...(e=t.compiler_needs)!==null&&e!==void 0?e:{}},o="internal://query.malloy";return s.files=[{url:o,contents:i},...(r=s.files)!==null&&r!==void 0?r:[]],jR(o,s,t.model_url)}tn.newCompileQueryState=jxe;function qxe(t){var e;const r=CE(t),i=t.translator.sourceURL,s=r.logs?(0,I2.mapLogs)(r.logs,i):void 0;if(r.model){const o=r.modelDef.queryList;if(o.length===0)return{logs:[...s??[],{url:i,severity:"error",message:"Internal error: No queries found",range:I2.DEFAULT_LOG_RANGE}]};const u=o.length-1,a=r.modelDef.queryList[u],l=r.model.anonymous_queries[u].schema,c=(e=r.model.anonymous_queries[u].annotations)!==null&&e!==void 0?e:[];try{const x=new Oxe.QueryModel(r.modelDef).compileQuery(a),h=(0,Zxt.annotationToTaglines)(r.modelDef.annotation).map(p=>({value:p}));return c.push({value:wxe.Tag.withPrefix("#(malloy) ").set(["source_name"],x.sourceExplore).toString()}),x.queryName&&c.push({value:wxe.Tag.withPrefix("#(malloy) ").set(["query_name"],x.queryName).toString()}),{result:{sql:x.sql,schema:l,connection_name:x.connectionName,annotations:c.length>0?c:void 0,model_annotations:h.length>0?h:void 0,query_timezone:x.queryTimezone}}}catch(f){return{logs:[...s??[],{url:i,severity:"error",message:`Internal compiler error: ${f.message}`,range:I2.DEFAULT_LOG_RANGE}]}}}else return{compiler_needs:r.compilerNeeds,logs:s}}tn.statedCompileQuery=qxe;var fdt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),xdt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Hxe=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&fdt(e,t,r);return xdt(e,t),e};Object.defineProperty(Yc,"__esModule",{value:!0}),Yc.compileQuery=Yc.compileSource=Yc.compileModel=void 0;const ddt=Hxe(iP),Pa=Hxe(tn),hdt=Up;function pdt(t,e){return t.type==="compile_model"?e.type!=="compile_model"?!1:t.modelURL===e.modelURL&&t.extendModelURL===e.extendModelURL:t.type==="compile_source"?e.type!=="compile_source"?!1:t.modelURL===e.modelURL&&t.extendModelURL===e.extendModelURL&&t.name===e.name:e.type!=="compile_query"?!1:t.modelURL===e.modelURL&&t.queryString===e.queryString}class mdt{constructor(){this.sessions=new Map}purgeExpired(e){const r=new Date;for(const i of this.sessions.values())i.sessionId!==(e==null?void 0:e.except)&&i.expires&&i.expires<r&&this.sessions.delete(i.sessionId)}findSession(e,r){const i=this.sessions.get(e);if(i&&pdt(i.sessionInfo,r))return i}getExpires(e){return e instanceof Date?e:new Date(Date.now()+e.seconds*1e3)}newSessionId(){let e;do e=(0,hdt.v4)();while(this.sessions.has(e));return e}newCompileModelSession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=Pa.newCompileModelState(e);return{type:"compile_model",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}newCompileSourceSession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=Pa.newCompileSourceState(e);return{type:"compile_source",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}newCompileQuerySession(e,r,i){const s=i!=null&&i.ttl?this.getExpires(i.ttl):void 0,o=Pa.newCompileQueryState(e);return{type:"compile_query",sessionInfo:r,state:o,expires:s,sessionId:this.newSessionId()}}findCompileModelSession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_model")return i}killSession(e){this.sessions.delete(e)}hasErrors(e){return Pa.hasErrors(e)}compileModel(e,r){const i={type:"compile_model",modelURL:e.model_url,extendModelURL:e.extend_model_url};let s=(r==null?void 0:r.session_id)&&this.findCompileModelSession(r.session_id,i);this.purgeExpired({except:r==null?void 0:r.session_id}),s?(r!=null&&r.ttl&&(s.expires=this.getExpires(r.ttl)),Pa.updateCompileModelState(s.state,e.compiler_needs)):(s=this.newCompileModelSession(e,i,r),this.sessions.set(s.sessionId,s));const o=Pa.statedCompileModel(s.state);return(o.model||this.hasErrors(o.logs))&&this.killSession(s.sessionId),{...o,session_id:s.sessionId}}findCompileSourceSession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_source")return i}compileSource(e,r){const i={type:"compile_source",modelURL:e.model_url,name:e.name,extendModelURL:e.extend_model_url};let s=(r==null?void 0:r.session_id)&&this.findCompileSourceSession(r.session_id,i);this.purgeExpired({except:r==null?void 0:r.session_id}),s?(r!=null&&r.ttl&&(s.expires=this.getExpires(r.ttl)),Pa.updateCompileModelState(s.state,e.compiler_needs)):(s=this.newCompileSourceSession(e,i,r),this.sessions.set(s.sessionId,s));const o=Pa.statedCompileSource(s.state,e.name);return(o.source||this.hasErrors(o.logs))&&this.killSession(s.sessionId),{...o,session_id:s.sessionId}}findCompileQuerySession(e,r){const i=this.findSession(e,r);if((i==null?void 0:i.type)==="compile_query")return i}compileQuery(e,r){const i=ddt.queryToMalloy(e.query),s={type:"compile_query",modelURL:e.model_url,queryString:i,query:e.query};let o=(r==null?void 0:r.session_id)&&this.findCompileQuerySession(r.session_id,s);this.purgeExpired({except:r==null?void 0:r.session_id}),o?(r!=null&&r.ttl&&(o.expires=this.getExpires(r.ttl)),Pa.updateCompileModelState(o.state,e.compiler_needs)):(o=this.newCompileQuerySession(e,s,r),this.sessions.set(o.sessionId,o));const u=Pa.statedCompileQuery(o.state);return(u.result||this.hasErrors(u.logs))&&this.killSession(o.sessionId),{...u,session_id:o.sessionId}}}const cP=new mdt;function gdt(t,e){return cP.compileModel(t,e)}Yc.compileModel=gdt;function ydt(t,e){return cP.compileSource(t,e)}Yc.compileSource=ydt;function Edt(t,e){return cP.compileQuery(t,e)}Yc.compileQuery=Edt;var Jc={},Adt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),_dt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),vdt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Adt(e,t,r);return _dt(e,t),e};Object.defineProperty(Jc,"__esModule",{value:!0}),Jc.compileQuery=Jc.compileSource=Jc.compileModel=void 0;const fP=vdt(tn);function Cdt(t){return fP.compileModel(t)}Jc.compileModel=Cdt;function Sdt(t){return fP.compileSource(t)}Jc.compileSource=Sdt;function bdt(t){return fP.compileQuery(t)}Jc.compileQuery=bdt;var Ua={},Tdt=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),Rdt=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),Ddt=T&&T.__importStar||function(t){if(t&&t.__esModule)return t;var e={};if(t!=null)for(var r in t)r!=="default"&&Object.prototype.hasOwnProperty.call(t,r)&&Tdt(e,t,r);return Rdt(e,t),e};Object.defineProperty(Ua,"__esModule",{value:!0}),Ua.runQuery=Ua.compileQuery=Ua.compileSource=Ua.compileModel=void 0;const vo=Ddt(tn),Qxe=hE;async function xP(t,e){var r,i,s,o,u,a,l,c,f;if(t===void 0)throw new Error("Expected compiler to have needs because it didn't return a result");const x={};if(t.connections)for(const h of t.connections){const p=await e.connections.lookupConnection(h.name);(r=x.connections)!==null&&r!==void 0||(x.connections=[]),x.connections.push({...h,dialect:p.dialectName})}if(t.files)for(const h of t.files){const p=await e.urls.readURL(new URL(h.url));(i=x.files)!==null&&i!==void 0||(x.files=[]),typeof p=="string"?x.files.push({...h,contents:p}):x.files.push({...h,contents:p.contents,invalidation_key:(s=p.invalidationKey)===null||s===void 0?void 0:s.toString()})}if(t.table_schemas){const h={};for(const p of t.table_schemas)(o=h[c=p.connection_name])!==null&&o!==void 0||(h[c]=[]),h[p.connection_name].push(p);for(const p in h){const m=await e.connections.lookupConnection(p),y=h[p].map(E=>E.name),g=await Promise.all(y.map(async E=>({name:E,schema:await m.fetchSchemaForTable(E)})));(u=x.table_schemas)!==null&&u!==void 0||(x.table_schemas=[]);for(const E of g)x.table_schemas.push({connection_name:p,name:E.name,schema:E.schema})}}if(t.sql_schemas){const h={};for(const p of t.sql_schemas)(a=h[f=p.connection_name])!==null&&a!==void 0||(h[f]=[]),h[p.connection_name].push(p);for(const p in h){const m=await e.connections.lookupConnection(p),y=h[p].map(E=>E.sql),g=await Promise.all(y.map(async E=>({sql:E,schema:await m.fetchSchemaForSQLQuery(E)})));(l=x.sql_schemas)!==null&&l!==void 0||(x.sql_schemas=[]);for(const E of g)x.sql_schemas.push({connection_name:p,sql:E.sql,schema:E.schema})}}return x}async function Odt(t,e){const r=vo.newCompileModelState(t);for(;;){const i=vo.statedCompileModel(r);if(i.model||vo.hasErrors(i.logs))return i;const s=await xP(i.compiler_needs,e);vo.updateCompileModelState(r,s)}}Ua.compileModel=Odt;async function Fdt(t,e){const r=vo.newCompileSourceState(t);for(;;){const i=vo.statedCompileSource(r,t.name);if(i.source||vo.hasErrors(i.logs))return i;const s=await xP(i.compiler_needs,e);vo.updateCompileModelState(r,s)}}Ua.compileSource=Fdt;async function zxe(t,e){const r=vo.newCompileQueryState(t);for(;;){const i=vo.statedCompileQuery(r);if(i.result||vo.hasErrors(i.logs))return i;const s=await xP(i.compiler_needs,e);vo.updateCompileModelState(r,s)}}Ua.compileQuery=zxe;async function wdt(t,e){var r,i;const s=await zxe(t,e);if(s.result===void 0)return s;const o=t.model_url;if(s.result.sql===void 0)return{logs:[...(r=s.logs)!==null&&r!==void 0?r:[],{url:o,severity:"error",message:"Internal error: Compiler did not generate SQL",range:Qxe.DEFAULT_LOG_RANGE}]};try{const a=await(await e.connections.lookupConnection(s.result.connection_name)).runSQL(s.result.sql,s.result.schema);return{...s,result:{...s.result,data:a}}}catch(u){return{...s,logs:[...(i=s.logs)!==null&&i!==void 0?i:[],{url:o,severity:"error",message:`Error running SQL: ${u.message}`,range:Qxe.DEFAULT_LOG_RANGE}]}}}Ua.runQuery=wdt;var Gxe={};Object.defineProperty(Gxe,"__esModule",{value:!0}),function(t){var e=T&&T.__createBinding||(Object.create?function(o,u,a,l){l===void 0&&(l=a);var c=Object.getOwnPropertyDescriptor(u,a);(!c||("get"in c?!u.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return u[a]}}),Object.defineProperty(o,l,c)}:function(o,u,a,l){l===void 0&&(l=a),o[l]=u[a]}),r=T&&T.__setModuleDefault||(Object.create?function(o,u){Object.defineProperty(o,"default",{enumerable:!0,value:u})}:function(o,u){o.default=u}),i=T&&T.__importStar||function(o){if(o&&o.__esModule)return o;var u={};if(o!=null)for(var a in o)a!=="default"&&Object.prototype.hasOwnProperty.call(o,a)&&e(u,o,a);return r(u,o),u},s=T&&T.__exportStar||function(o,u){for(var a in o)a!=="default"&&!Object.prototype.hasOwnProperty.call(u,a)&&e(u,o,a)};Object.defineProperty(t,"__esModule",{value:!0}),t.util=t.asynchronous=t.stateless=t.sessioned=void 0,t.sessioned=i(Yc),t.stateless=i(Jc),t.asynchronous=i(Ua),s(Gxe,t),t.util=i(hE)}(Sxe),function(t){var e=T&&T.__createBinding||(Object.create?function(h,p,m,y){y===void 0&&(y=m);var g=Object.getOwnPropertyDescriptor(p,m);(!g||("get"in g?!p.__esModule:g.writable||g.configurable))&&(g={enumerable:!0,get:function(){return p[m]}}),Object.defineProperty(h,y,g)}:function(h,p,m,y){y===void 0&&(y=m),h[y]=p[m]}),r=T&&T.__setModuleDefault||(Object.create?function(h,p){Object.defineProperty(h,"default",{enumerable:!0,value:p})}:function(h,p){h.default=p}),i=T&&T.__importStar||function(h){if(h&&h.__esModule)return h;var p={};if(h!=null)for(var m in h)m!=="default"&&Object.prototype.hasOwnProperty.call(h,m)&&e(p,h,m);return r(p,h),p};Object.defineProperty(t,"__esModule",{value:!0}),t.EmptyURLReader=t.SingleConnectionRuntime=t.ConnectionRuntime=t.AtomicFieldType=t.Runtime=t.Malloy=t.Model=t.MalloyTranslator=t.malloyToQuery=t.composeSQLExpr=t.indent=t.expressionIsUngroupedAggregate=t.expressionIsScalar=t.expressionIsCalculation=t.expressionIsAnalytic=t.expressionIsAggregate=t.mkFieldDef=t.mkArrayDef=t.isScalarArray=t.isRepeatedRecord=t.isSamplingRows=t.isSamplingPercent=t.isSamplingEnable=t.isJoinedSource=t.isJoined=t.isLeafAtomic=t.Segment=t.isSourceDef=t.TinyParser=t.Dialect=t.spread=t.literal=t.variadicParam=t.param=t.makeParam=t.sql=t.maxScalar=t.minAggregate=t.anyExprType=t.minScalar=t.overload=t.qtz=t.arg=t.registerDialect=t.MySQLDialect=t.SnowflakeDialect=t.PostgresDialect=t.TrinoDialect=t.StandardSQLDialect=t.DuckDBDialect=void 0,t.annotationToTaglines=t.annotationToTag=t.sqlKey=t.API=t.modelDefToModelInfo=t.toAsyncGenerator=t.CacheManager=t.InMemoryModelCache=t.Explore=t.DataWriter=t.Parse=t.JSONWriter=t.CSVWriter=t.QueryMaterializer=t.Result=t.PreparedResult=t.TimestampTimeframe=t.DateTimeframe=t.SourceRelationship=t.JoinRelationship=t.MalloyError=t.FixedConnectionMap=t.InMemoryURLReader=void 0;var s=Mp;Object.defineProperty(t,"DuckDBDialect",{enumerable:!0,get:function(){return s.DuckDBDialect}}),Object.defineProperty(t,"StandardSQLDialect",{enumerable:!0,get:function(){return s.StandardSQLDialect}}),Object.defineProperty(t,"TrinoDialect",{enumerable:!0,get:function(){return s.TrinoDialect}}),Object.defineProperty(t,"PostgresDialect",{enumerable:!0,get:function(){return s.PostgresDialect}}),Object.defineProperty(t,"SnowflakeDialect",{enumerable:!0,get:function(){return s.SnowflakeDialect}}),Object.defineProperty(t,"MySQLDialect",{enumerable:!0,get:function(){return s.MySQLDialect}}),Object.defineProperty(t,"registerDialect",{enumerable:!0,get:function(){return s.registerDialect}}),Object.defineProperty(t,"arg",{enumerable:!0,get:function(){return s.arg}}),Object.defineProperty(t,"qtz",{enumerable:!0,get:function(){return s.qtz}}),Object.defineProperty(t,"overload",{enumerable:!0,get:function(){return s.overload}}),Object.defineProperty(t,"minScalar",{enumerable:!0,get:function(){return s.minScalar}}),Object.defineProperty(t,"anyExprType",{enumerable:!0,get:function(){return s.anyExprType}}),Object.defineProperty(t,"minAggregate",{enumerable:!0,get:function(){return s.minAggregate}}),Object.defineProperty(t,"maxScalar",{enumerable:!0,get:function(){return s.maxScalar}}),Object.defineProperty(t,"sql",{enumerable:!0,get:function(){return s.sql}}),Object.defineProperty(t,"makeParam",{enumerable:!0,get:function(){return s.makeParam}}),Object.defineProperty(t,"param",{enumerable:!0,get:function(){return s.param}}),Object.defineProperty(t,"variadicParam",{enumerable:!0,get:function(){return s.variadicParam}}),Object.defineProperty(t,"literal",{enumerable:!0,get:function(){return s.literal}}),Object.defineProperty(t,"spread",{enumerable:!0,get:function(){return s.spread}}),Object.defineProperty(t,"Dialect",{enumerable:!0,get:function(){return s.Dialect}}),Object.defineProperty(t,"TinyParser",{enumerable:!0,get:function(){return s.TinyParser}});var o=Ui;Object.defineProperty(t,"isSourceDef",{enumerable:!0,get:function(){return o.isSourceDef}}),Object.defineProperty(t,"Segment",{enumerable:!0,get:function(){return o.Segment}}),Object.defineProperty(t,"isLeafAtomic",{enumerable:!0,get:function(){return o.isLeafAtomic}}),Object.defineProperty(t,"isJoined",{enumerable:!0,get:function(){return o.isJoined}}),Object.defineProperty(t,"isJoinedSource",{enumerable:!0,get:function(){return o.isJoinedSource}}),Object.defineProperty(t,"isSamplingEnable",{enumerable:!0,get:function(){return o.isSamplingEnable}}),Object.defineProperty(t,"isSamplingPercent",{enumerable:!0,get:function(){return o.isSamplingPercent}}),Object.defineProperty(t,"isSamplingRows",{enumerable:!0,get:function(){return o.isSamplingRows}}),Object.defineProperty(t,"isRepeatedRecord",{enumerable:!0,get:function(){return o.isRepeatedRecord}}),Object.defineProperty(t,"isScalarArray",{enumerable:!0,get:function(){return o.isScalarArray}}),Object.defineProperty(t,"mkArrayDef",{enumerable:!0,get:function(){return o.mkArrayDef}}),Object.defineProperty(t,"mkFieldDef",{enumerable:!0,get:function(){return o.mkFieldDef}}),Object.defineProperty(t,"expressionIsAggregate",{enumerable:!0,get:function(){return o.expressionIsAggregate}}),Object.defineProperty(t,"expressionIsAnalytic",{enumerable:!0,get:function(){return o.expressionIsAnalytic}}),Object.defineProperty(t,"expressionIsCalculation",{enumerable:!0,get:function(){return o.expressionIsCalculation}}),Object.defineProperty(t,"expressionIsScalar",{enumerable:!0,get:function(){return o.expressionIsScalar}}),Object.defineProperty(t,"expressionIsUngroupedAggregate",{enumerable:!0,get:function(){return o.expressionIsUngroupedAggregate}}),Object.defineProperty(t,"indent",{enumerable:!0,get:function(){return o.indent}}),Object.defineProperty(t,"composeSQLExpr",{enumerable:!0,get:function(){return o.composeSQLExpr}});var u=H4;Object.defineProperty(t,"malloyToQuery",{enumerable:!0,get:function(){return u.malloyToQuery}}),Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return u.MalloyTranslator}});var a=Fe;Object.defineProperty(t,"Model",{enumerable:!0,get:function(){return a.Model}}),Object.defineProperty(t,"Malloy",{enumerable:!0,get:function(){return a.Malloy}}),Object.defineProperty(t,"Runtime",{enumerable:!0,get:function(){return a.Runtime}}),Object.defineProperty(t,"AtomicFieldType",{enumerable:!0,get:function(){return a.AtomicFieldType}}),Object.defineProperty(t,"ConnectionRuntime",{enumerable:!0,get:function(){return a.ConnectionRuntime}}),Object.defineProperty(t,"SingleConnectionRuntime",{enumerable:!0,get:function(){return a.SingleConnectionRuntime}}),Object.defineProperty(t,"EmptyURLReader",{enumerable:!0,get:function(){return a.EmptyURLReader}}),Object.defineProperty(t,"InMemoryURLReader",{enumerable:!0,get:function(){return a.InMemoryURLReader}}),Object.defineProperty(t,"FixedConnectionMap",{enumerable:!0,get:function(){return a.FixedConnectionMap}}),Object.defineProperty(t,"MalloyError",{enumerable:!0,get:function(){return a.MalloyError}}),Object.defineProperty(t,"JoinRelationship",{enumerable:!0,get:function(){return a.JoinRelationship}}),Object.defineProperty(t,"SourceRelationship",{enumerable:!0,get:function(){return a.SourceRelationship}}),Object.defineProperty(t,"DateTimeframe",{enumerable:!0,get:function(){return a.DateTimeframe}}),Object.defineProperty(t,"TimestampTimeframe",{enumerable:!0,get:function(){return a.TimestampTimeframe}}),Object.defineProperty(t,"PreparedResult",{enumerable:!0,get:function(){return a.PreparedResult}}),Object.defineProperty(t,"Result",{enumerable:!0,get:function(){return a.Result}}),Object.defineProperty(t,"QueryMaterializer",{enumerable:!0,get:function(){return a.QueryMaterializer}}),Object.defineProperty(t,"CSVWriter",{enumerable:!0,get:function(){return a.CSVWriter}}),Object.defineProperty(t,"JSONWriter",{enumerable:!0,get:function(){return a.JSONWriter}}),Object.defineProperty(t,"Parse",{enumerable:!0,get:function(){return a.Parse}}),Object.defineProperty(t,"DataWriter",{enumerable:!0,get:function(){return a.DataWriter}}),Object.defineProperty(t,"Explore",{enumerable:!0,get:function(){return a.Explore}}),Object.defineProperty(t,"InMemoryModelCache",{enumerable:!0,get:function(){return a.InMemoryModelCache}}),Object.defineProperty(t,"CacheManager",{enumerable:!0,get:function(){return a.CacheManager}});var l=LR;Object.defineProperty(t,"toAsyncGenerator",{enumerable:!0,get:function(){return l.toAsyncGenerator}});var c=Ia;Object.defineProperty(t,"modelDefToModelInfo",{enumerable:!0,get:function(){return c.modelDefToModelInfo}}),t.API=i(Sxe);var f=Yl;Object.defineProperty(t,"sqlKey",{enumerable:!0,get:function(){return f.sqlKey}});var x=ai;Object.defineProperty(t,"annotationToTag",{enumerable:!0,get:function(){return x.annotationToTag}}),Object.defineProperty(t,"annotationToTaglines",{enumerable:!0,get:function(){return x.annotationToTaglines}})}(_$);class Ndt{constructor(e){this.document=e}async render(e,r){var l;let i;if(e instanceof _$.Result||"modelDef"in e?i=_$.API.util.wrapResult(e):i=e,!n4(i.model_annotations,"## ").has("renderer_legacy"))if(!!((l=this.document.defaultView)!=null&&l.customElements.get("malloy-render"))){const f=this.document.createElement("malloy-render");f.malloyResult=i;const x=r.nextRendererOptions??{};for(const[h,p]of Object.entries(x))f[h]=p;return f}else console.warn("Tried to use the new Malloy renderer, but the malloy-render component was not found. Falling back to the legacy renderer.");const u=due(i),a=Vxe(u.field,this.document,r,{size:"large"},u.field.queryTimezone,u.field.tag);try{return await a.render(u)}catch(c){return c instanceof Error?Vs(this.document,c):Vs(this.document,"Internal error - Exception not an Error object.")}}}class Ldt{constructor(e){this.document=e}async render(e){const r=new gP(this.document);try{return await r.render(e)}catch(i){return i instanceof Error?Vs(this.document,i):Vs(this.document,"Internal error - Exception not an Error object.")}}}const Wxe={shape_map:"shape_map",point_map:"point_map",bar_chart:"bar_chart",image:"image",json:"json",segment_map:"segment_map",dashboard:"dashboard",line_chart:"line_chart",scatter_chart:"scatter_chart",url:"url",list:"list",list_detail:"list_detail",sparkline:"sparkline",sparkline_area:"sparkline",sparkline_column:"sparkline",sparkline_bar:"sparkline"};function Idt(t,e){const r=e[t.name],{name:i}=t;for(const s in Wxe)if(i.endsWith(`_${s}`)){const o=i.slice(0,i.length-s.length-1);return $dt(s,o,Wxe,r)}return r}function $dt(t,e,r,i){var s;return i?(i.renderer??(i.renderer=r[t]),i.data??(i.data={}),(s=i.data).label??(s.label=e)):i={renderer:r[t],data:{label:e}},i}function qR(t){if(t.isRecordOrRepeatedRecord())return t;throw new Error(`${t.name} does not contain fields and cannot be rendered this way`)}function Vxe(t,e,r,i,s,o){const u=Idt(t,r.dataStyles);r.dataStyles[t.name]=u;const a=new UL().create(u,o,e,i,r,t,s);if(a)return a;if((u==null?void 0:u.renderer)==="dashboard"||o.has("dashboard"))return HR(E$,e,qR(t),r,o);if((u==null?void 0:u.renderer)==="list"||o.has("list"))return HR(Aue,e,qR(t),r,o);if((u==null?void 0:u.renderer)==="list_detail"||o.has("list_detail"))return HR(pYe,e,qR(t),r,o);if((u==null?void 0:u.renderer)==="table"||o.has("table")||t.isRecordOrRepeatedRecord())return HR(X2,e,qR(t),r,o);throw new Error(`Could not find a proper renderer for field ${t.name}`)}function HR(t,e,r,i,s){const o=FE.make(t,e,r,i,s),u={};return r.fields.forEach(a=>{u[a.name]=Vxe(a,e,i,o.defaultStylesForChildren,a.root().queryTimezone,a.tag)}),o.childRenderers=u,o}async function Bdt(t){const e=await Yxe(t);try{await navigator.clipboard.writeText(e)}catch(r){console.error("Failed to copy text: ",r)}}async function Yxe(t){let e="";const r=t.tableConfig??{},i=Object.assign({disableVirtualization:!0},r);t.tableConfig=i;const s=t.dashboardConfig??{},o=Object.assign({disableVirtualization:!0},s);if(t.dashboardConfig=o,await kdt(1e3),t.shadowRoot){let u="";for(const a of[...t.shadowRoot.adoptedStyleSheets]){for(let c=0;c<a.cssRules.length;c++){const f=a.cssRules.item(c);f&&(u+=`
1492
1492
  `+f.cssText)}u=u.replaceAll(":host",".malloy_html_host");const l=t.getAttribute("style");e=`
1493
1493
  <div>
@@ -125857,7 +125857,7 @@ const uV = Ttt(vk), ko = zt, Xe = uV.default.compile({
125857
125857
  oparen: "(",
125858
125858
  cparen: ")",
125859
125859
  comma: ",",
125860
- literal: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*))/,
125860
+ literal: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d(?::\d\d(?:[.,]\d*)?)/,
125861
125861
  lit_week: /\d\d\d\d-\d\d-\d\d-[Ww][Kk]/,
125862
125862
  lit_quarter: /\d\d\d\d-[qQ][1234]/,
125863
125863
  lit_min: /\d\d\d\d-\d\d-\d\d[ Tt]\d\d:\d\d/,
@@ -126172,8 +126172,10 @@ class wtt {
126172
126172
  return { begin: o, end: this.literalNode(a.toFormat(Zi)).sql };
126173
126173
  }
126174
126174
  case void 0:
126175
- case "second":
126176
- return { begin: this.literalNode(r), end: r };
126175
+ case "second": {
126176
+ const i = this.literalNode(r);
126177
+ return { begin: i, end: i.sql };
126178
+ }
126177
126179
  }
126178
126180
  }
126179
126181
  literalNode(e) {
@@ -155537,6 +155539,11 @@ sA.MALLOY_INTERFACE_TYPES = {
155537
155539
  type: "CompilerNeeds",
155538
155540
  optional: !0,
155539
155541
  array: !1
155542
+ },
155543
+ translations: {
155544
+ type: "Translation",
155545
+ array: !0,
155546
+ optional: !0
155540
155547
  }
155541
155548
  }
155542
155549
  },
@@ -155579,6 +155586,11 @@ sA.MALLOY_INTERFACE_TYPES = {
155579
155586
  type: "CompilerNeeds",
155580
155587
  optional: !0,
155581
155588
  array: !1
155589
+ },
155590
+ translations: {
155591
+ type: "Translation",
155592
+ array: !0,
155593
+ optional: !0
155582
155594
  }
155583
155595
  }
155584
155596
  },