@malloy-publisher/server 0.0.221 → 0.0.223

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.
@@ -1,4 +1,4 @@
1
- import{aI as ci}from"./index-Cr-asgoV.js";import{r as di}from"./index-w_0OQJgZ.js";function pi(u,re){for(var j=0;j<re.length;j++){const N=re[j];if(typeof N!="string"&&!Array.isArray(N)){for(const E in N)if(E!=="default"&&!(E in u)){const S=Object.getOwnPropertyDescriptor(N,E);S&&Object.defineProperty(u,E,S.get?S:{enumerable:!0,get:()=>N[E]})}}}return Object.freeze(Object.defineProperty(u,Symbol.toStringTag,{value:"Module"}))}var bt={},ut={},Or;function Vt(){if(Or)return ut;Or=1,Object.defineProperty(ut,"__esModule",{value:!0}),ut.isChainOp=u,ut.isStringCondition=re,ut.isStringFilter=j,ut.isBooleanFilter=N,ut.isNumberFilter=E,ut.isTemporalFilter=S,ut.isFilterExpression=w,ut.isFilterable=y;function u(o){return["and","or",","].includes(o)}function re(o){return["starts","ends","contains","="].includes(o.operator)}function j(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["starts","ends","contains","=","~","null","empty","and","or",",","()"].includes(o.operator)}function N(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["null","true","false","=false","=true"].includes(o.operator)}function E(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["range","<=",">=","!=","=",">","<","and","or","()","null"].includes(o.operator)}function S(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["literal","before","after","to","for","in","and","or","in_last","this","last","next","()","null"].includes(o.operator)}function w(o){return typeof o=="object"&&o!==null&&"operator"in o}function y(o){return["string","number","boolean","timestamp","timestamptz","date"].includes(o)}return ut}var Pt={},Er;function hi(){return Er||(Er=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.BooleanFilterExpression=void 0,Pt.BooleanFilterExpression={parse(u){var re;if(u.match(/^\s*$/))return{parsed:null,log:[]};const j={parsed:null,log:[]};let N=u.toLowerCase().trim().replace(/\s\s+/," "),E=!1;if(N.startsWith("not ")&&(E=!0,N=N.slice(4)),N==="true")j.parsed={operator:"true"};else if(N==="=true")j.parsed={operator:"=true"};else if(N==="false")j.parsed={operator:"false"};else if(N==="=false")j.parsed={operator:"=false"};else if(N==="null")j.parsed={operator:"null"};else{const S=u.match(/[^\s]/),w=S&&(re=S.index)!==null&&re!==void 0?re:0;j.log=[{message:`Illegal boolean filter '${N}'. Must be one of true,=true,false,=false,null`,severity:"error",startIndex:w,endIndex:w+u.length-1}]}return E&&j.parsed&&(j.parsed.not=!0),j},unparse(u){return u===null?"":(u.not?"not ":"")+u.operator}}),Pt}var pr={},Ue={},kr;function Ht(){if(kr)return Ue;kr=1,Object.defineProperty(Ue,"__esModule",{value:!0}),Ue.maybeNot=re,Ue.unescape=j,Ue.escape=N,Ue.matchOp=S,Ue.conjoin=y,Ue.joinNumbers=o,Ue.mkRange=d,Ue.mkValues=t,Ue.numNot=D,Ue.temporalNot=x,Ue.joinTemporal=Z,Ue.timeLiteral=ee,Ue.mkUnits=ce;const u=Vt();function re(O){const[A,b]=O;return A&&b&&(0,u.isStringFilter)(b)?{...b,not:!0}:b}function j(O){return O.replace(/\\(.)/g,"$1")}function N(O){const A=O.toLowerCase();return A==="null"||A==="empty"?"\\"+O:O.replace(/([,; |()\\%_-])/g,"\\$1")}function E(O){let A=!1,b=!1,B=0,de=!1;const Fe=O.length;for(let ve=0;ve<Fe;ve+=1){const Ye=O[ve];if(Ye===" "||Ye===" "){B+=1;continue}B=0,Ye==="%"?(de=!0,ve===0&&(A=!0),b=!0):(b=!1,Ye==="\\"?ve+=1:Ye==="_"&&(de=!0))}return{hasLike:de,percentEnd:b&&Fe>1,percentStart:A&&Fe>1,endSpace:B}}function S(O){let A=O.trimStart();const{hasLike:b,percentEnd:B,percentStart:de,endSpace:Fe}=E(A);if(Fe>0&&(A=A.slice(0,-Fe)),b){if(de&&B){const ve=A.slice(1,-1);if(!E(ve).hasLike&&ve.length>0)return{operator:"contains",values:[j(ve)]}}else if(B){const ve=A.slice(0,-1);if(!E(ve).hasLike)return{operator:"starts",values:[j(ve)]}}else if(de){const ve=A.slice(1);if(!E(ve).hasLike)return{operator:"ends",values:[j(ve)]}}return{operator:"~",escaped_values:[A]}}return A.toLowerCase()==="null"?{operator:"null"}:A.toLowerCase()==="empty"?{operator:"empty"}:{operator:"=",values:[j(A)]}}function w(O,A){var b,B;return O.operator===A.operator&&((b=O.not)!==null&&b!==void 0?b:!1)===((B=A.not)!==null&&B!==void 0?B:!1)}function y(O,A,b){if(A=A.toLowerCase(),(0,u.isStringFilter)(O)&&(0,u.isStringFilter)(b)){if(A===","){if(O.operator==="~"&&w(O,b))return{...O,escaped_values:[...O.escaped_values,...b.escaped_values]};if((0,u.isStringCondition)(O)&&w(O,b))return{...O,values:[...O.values,...b.values]}}const B=A===","?",":A==="|"?"or":A===";"?"and":void 0;if(B)return O.operator===B?{...O,members:[...O.members,b]}:{operator:B,members:[O,b]}}return null}function o(O,A,b){if(A=A.toLowerCase(),(0,u.isNumberFilter)(O)&&(0,u.isNumberFilter)(b)){if(A==="or"&&O.operator==="="&&w(O,b)){const B={operator:"=",values:[...O.values,...b.values]};return O.not&&(B.not=!0),B}if(A==="and"||A==="or")return O.operator===A?{...O,members:[...O.members,b]}:{operator:A,members:[O,b]}}return null}function d(O,A,b,B){return{operator:"range",startValue:A,startOperator:O==="("?">":">=",endValue:b,endOperator:B===")"?"<":"<="}}function t(O,A){return{values:[O,...A]}}function D(O,A){return(0,u.isNumberFilter)(O)&&A?O.operator==="="?{operator:"!=",values:O.values}:O.operator==="!="?{operator:"=",values:O.values}:{...O,not:!0}:O}function x(O,A){if((0,u.isTemporalFilter)(O)&&A){if("not"in O){const b={...O};return O.not?delete b.not:b.not=!0,b}return{...O,not:!0}}return O}function Z(O,A,b){return A=A.toLowerCase(),(0,u.isTemporalFilter)(O)&&(0,u.isTemporalFilter)(b)&&(A==="and"||A==="or")?O.operator===A?{...O,members:[...O.members,b]}:{operator:A,members:[O,b]}:null}function ee(O,A){const b={moment:"literal",literal:O};return A&&(b.units=A),b}function ce(O){switch(O.toLowerCase()){case"second":case"seconds":return"second";case"minute":case"minutes":return"minute";case"hour":case"hours":return"hour";case"day":case"days":return"day";case"week":case"weeks":return"week";case"month":case"months":return"month";case"quarter":case"quarters":return"quarter";case"year":case"years":return"year"}}return Ue}var hr,Rr;function mi(){if(Rr)return hr;Rr=1;const{numNot:u,mkRange:re,joinNumbers:j,mkValues:N}=Ht();function E(o,d){function t(){this.constructor=o}t.prototype=d.prototype,o.prototype=new t}function S(o,d,t,D){var x=Error.call(this,o);return Object.setPrototypeOf&&Object.setPrototypeOf(x,S.prototype),x.expected=d,x.found=t,x.location=D,x.name="SyntaxError",x}E(S,Error);function w(o,d,t){return t=t||" ",o.length>d?o:(d-=o.length,t+=t.repeat(d),o+t.slice(0,d))}S.prototype.format=function(o){var d="Error: "+this.message;if(this.location){var t=null,D;for(D=0;D<o.length;D++)if(o[D].source===this.location.source){t=o[D].text.split(/\r\n|\n|\r/g);break}var x=this.location.start,Z=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(x):x,ee=this.location.source+":"+Z.line+":"+Z.column;if(t){var ce=this.location.end,O=w("",Z.line.toString().length," "),A=t[x.line-1],b=x.line===ce.line?ce.column:A.length+1,B=b-x.column||1;d+=`
1
+ import{aI as ci}from"./index-D2sm5RBA.js";import{r as di}from"./index-w_0OQJgZ.js";function pi(u,re){for(var j=0;j<re.length;j++){const N=re[j];if(typeof N!="string"&&!Array.isArray(N)){for(const E in N)if(E!=="default"&&!(E in u)){const S=Object.getOwnPropertyDescriptor(N,E);S&&Object.defineProperty(u,E,S.get?S:{enumerable:!0,get:()=>N[E]})}}}return Object.freeze(Object.defineProperty(u,Symbol.toStringTag,{value:"Module"}))}var bt={},ut={},Or;function Vt(){if(Or)return ut;Or=1,Object.defineProperty(ut,"__esModule",{value:!0}),ut.isChainOp=u,ut.isStringCondition=re,ut.isStringFilter=j,ut.isBooleanFilter=N,ut.isNumberFilter=E,ut.isTemporalFilter=S,ut.isFilterExpression=w,ut.isFilterable=y;function u(o){return["and","or",","].includes(o)}function re(o){return["starts","ends","contains","="].includes(o.operator)}function j(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["starts","ends","contains","=","~","null","empty","and","or",",","()"].includes(o.operator)}function N(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["null","true","false","=false","=true"].includes(o.operator)}function E(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["range","<=",">=","!=","=",">","<","and","or","()","null"].includes(o.operator)}function S(o){return typeof o=="object"&&o!==null&&"operator"in o&&typeof o.operator=="string"&&["literal","before","after","to","for","in","and","or","in_last","this","last","next","()","null"].includes(o.operator)}function w(o){return typeof o=="object"&&o!==null&&"operator"in o}function y(o){return["string","number","boolean","timestamp","timestamptz","date"].includes(o)}return ut}var Pt={},Er;function hi(){return Er||(Er=1,Object.defineProperty(Pt,"__esModule",{value:!0}),Pt.BooleanFilterExpression=void 0,Pt.BooleanFilterExpression={parse(u){var re;if(u.match(/^\s*$/))return{parsed:null,log:[]};const j={parsed:null,log:[]};let N=u.toLowerCase().trim().replace(/\s\s+/," "),E=!1;if(N.startsWith("not ")&&(E=!0,N=N.slice(4)),N==="true")j.parsed={operator:"true"};else if(N==="=true")j.parsed={operator:"=true"};else if(N==="false")j.parsed={operator:"false"};else if(N==="=false")j.parsed={operator:"=false"};else if(N==="null")j.parsed={operator:"null"};else{const S=u.match(/[^\s]/),w=S&&(re=S.index)!==null&&re!==void 0?re:0;j.log=[{message:`Illegal boolean filter '${N}'. Must be one of true,=true,false,=false,null`,severity:"error",startIndex:w,endIndex:w+u.length-1}]}return E&&j.parsed&&(j.parsed.not=!0),j},unparse(u){return u===null?"":(u.not?"not ":"")+u.operator}}),Pt}var pr={},Ue={},kr;function Ht(){if(kr)return Ue;kr=1,Object.defineProperty(Ue,"__esModule",{value:!0}),Ue.maybeNot=re,Ue.unescape=j,Ue.escape=N,Ue.matchOp=S,Ue.conjoin=y,Ue.joinNumbers=o,Ue.mkRange=d,Ue.mkValues=t,Ue.numNot=D,Ue.temporalNot=x,Ue.joinTemporal=Z,Ue.timeLiteral=ee,Ue.mkUnits=ce;const u=Vt();function re(O){const[A,b]=O;return A&&b&&(0,u.isStringFilter)(b)?{...b,not:!0}:b}function j(O){return O.replace(/\\(.)/g,"$1")}function N(O){const A=O.toLowerCase();return A==="null"||A==="empty"?"\\"+O:O.replace(/([,; |()\\%_-])/g,"\\$1")}function E(O){let A=!1,b=!1,B=0,de=!1;const Fe=O.length;for(let ve=0;ve<Fe;ve+=1){const Ye=O[ve];if(Ye===" "||Ye===" "){B+=1;continue}B=0,Ye==="%"?(de=!0,ve===0&&(A=!0),b=!0):(b=!1,Ye==="\\"?ve+=1:Ye==="_"&&(de=!0))}return{hasLike:de,percentEnd:b&&Fe>1,percentStart:A&&Fe>1,endSpace:B}}function S(O){let A=O.trimStart();const{hasLike:b,percentEnd:B,percentStart:de,endSpace:Fe}=E(A);if(Fe>0&&(A=A.slice(0,-Fe)),b){if(de&&B){const ve=A.slice(1,-1);if(!E(ve).hasLike&&ve.length>0)return{operator:"contains",values:[j(ve)]}}else if(B){const ve=A.slice(0,-1);if(!E(ve).hasLike)return{operator:"starts",values:[j(ve)]}}else if(de){const ve=A.slice(1);if(!E(ve).hasLike)return{operator:"ends",values:[j(ve)]}}return{operator:"~",escaped_values:[A]}}return A.toLowerCase()==="null"?{operator:"null"}:A.toLowerCase()==="empty"?{operator:"empty"}:{operator:"=",values:[j(A)]}}function w(O,A){var b,B;return O.operator===A.operator&&((b=O.not)!==null&&b!==void 0?b:!1)===((B=A.not)!==null&&B!==void 0?B:!1)}function y(O,A,b){if(A=A.toLowerCase(),(0,u.isStringFilter)(O)&&(0,u.isStringFilter)(b)){if(A===","){if(O.operator==="~"&&w(O,b))return{...O,escaped_values:[...O.escaped_values,...b.escaped_values]};if((0,u.isStringCondition)(O)&&w(O,b))return{...O,values:[...O.values,...b.values]}}const B=A===","?",":A==="|"?"or":A===";"?"and":void 0;if(B)return O.operator===B?{...O,members:[...O.members,b]}:{operator:B,members:[O,b]}}return null}function o(O,A,b){if(A=A.toLowerCase(),(0,u.isNumberFilter)(O)&&(0,u.isNumberFilter)(b)){if(A==="or"&&O.operator==="="&&w(O,b)){const B={operator:"=",values:[...O.values,...b.values]};return O.not&&(B.not=!0),B}if(A==="and"||A==="or")return O.operator===A?{...O,members:[...O.members,b]}:{operator:A,members:[O,b]}}return null}function d(O,A,b,B){return{operator:"range",startValue:A,startOperator:O==="("?">":">=",endValue:b,endOperator:B===")"?"<":"<="}}function t(O,A){return{values:[O,...A]}}function D(O,A){return(0,u.isNumberFilter)(O)&&A?O.operator==="="?{operator:"!=",values:O.values}:O.operator==="!="?{operator:"=",values:O.values}:{...O,not:!0}:O}function x(O,A){if((0,u.isTemporalFilter)(O)&&A){if("not"in O){const b={...O};return O.not?delete b.not:b.not=!0,b}return{...O,not:!0}}return O}function Z(O,A,b){return A=A.toLowerCase(),(0,u.isTemporalFilter)(O)&&(0,u.isTemporalFilter)(b)&&(A==="and"||A==="or")?O.operator===A?{...O,members:[...O.members,b]}:{operator:A,members:[O,b]}:null}function ee(O,A){const b={moment:"literal",literal:O};return A&&(b.units=A),b}function ce(O){switch(O.toLowerCase()){case"second":case"seconds":return"second";case"minute":case"minutes":return"minute";case"hour":case"hours":return"hour";case"day":case"days":return"day";case"week":case"weeks":return"week";case"month":case"months":return"month";case"quarter":case"quarters":return"quarter";case"year":case"years":return"year"}}return Ue}var hr,Rr;function mi(){if(Rr)return hr;Rr=1;const{numNot:u,mkRange:re,joinNumbers:j,mkValues:N}=Ht();function E(o,d){function t(){this.constructor=o}t.prototype=d.prototype,o.prototype=new t}function S(o,d,t,D){var x=Error.call(this,o);return Object.setPrototypeOf&&Object.setPrototypeOf(x,S.prototype),x.expected=d,x.found=t,x.location=D,x.name="SyntaxError",x}E(S,Error);function w(o,d,t){return t=t||" ",o.length>d?o:(d-=o.length,t+=t.repeat(d),o+t.slice(0,d))}S.prototype.format=function(o){var d="Error: "+this.message;if(this.location){var t=null,D;for(D=0;D<o.length;D++)if(o[D].source===this.location.source){t=o[D].text.split(/\r\n|\n|\r/g);break}var x=this.location.start,Z=this.location.source&&typeof this.location.source.offset=="function"?this.location.source.offset(x):x,ee=this.location.source+":"+Z.line+":"+Z.column;if(t){var ce=this.location.end,O=w("",Z.line.toString().length," "),A=t[x.line-1],b=x.line===ce.line?ce.column:A.length+1,B=b-x.column||1;d+=`
2
2
  --> `+ee+`
3
3
  `+O+` |
4
4
  `+Z.line+" | "+A+`
@@ -1,4 +1,4 @@
1
- import{aF as KF,r as L,j as O,ae as Ht,R as JF,aG as XF,aH as is}from"./index-Cr-asgoV.js";import{r as Zd,a as dA,d as ft}from"./index-DcCw_qxr.js";import{r as za}from"./index-w_0OQJgZ.js";import{d as CU}from"./index-BF8PkFm8.js";import{MalloyRenderer as ZF,isCoreVizPluginInstance as AU}from"./index-8E2uLeV9.js";var vo={},K3={},xr={},J3={},mR;function Ge(){return mR||(mR=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.TD=e.ValueType=void 0,e.safeRecordGet=r,e.mkSafeRecord=i,e.exprHasKids=o,e.exprHasE=s,e.exprIsLeaf=a,e.isAsymmetricExpr=l,e.mkTemporal=d,e.isRawCast=c,e.isFilterExprType=h,e.isTimeLiteral=f,e.isParameterType=p,e.paramHasValue=x,e.activeName=m,e.expressionIsScalar=g,e.expressionIsAggregate=E,e.expressionIsUngroupedAggregate=v,e.expressionInvolvesAggregate=S,e.expressionIsCalculation=C,e.expressionIsAnalytic=T,e.isExpressionTypeLEQ=_,e.maxExpressionType=R,e.maxOfExpressionTypes=D,e.hasExpression=w,e.isTemporalType=N,e.isBasicAtomicType=I,e.isAtomicFieldType=k,e.canOrderBy=$,e.fieldIsIntrinsic=J,e.mkFieldDef=re,e.mkArrayDef=ie,e.mkArrayTypeDef=oe,e.isRepeatedRecordFunctionParam=U,e.isRepeatedRecord=ee,e.isRecordOrRepeatedRecord=K,e.isBasicArray=te,e.isMatrixOperation=q,e.isJoinable=H,e.isJoined=Q,e.isJoinedSource=M,e.isDateUnit=j,e.isTimestampUnit=P,e.isExtractUnit=V,e.refIsStructDef=ae,e.segmentHasErrors=ce,e.structHasErrors=le,e.isReduceSegment=se,e.isPartialSegment=fe,e.isProjectSegment=pe,e.isQuerySegment=ye,e.isSamplingRows=Ce,e.isSamplingPercent=me,e.isSamplingEnable=_e,e.isRawSegment=we,e.isIndexSegment=Ke,e.bareFieldUsage=rt,e.fieldUsageFrom=ge,e.givenUsageFrom=Ee,e.mkRefSummary=Pe,e.mapFieldUsage=ke,e.setFieldUsage=Me,e.isSegmentSQL=Xe,e.isSegmentSource=at,e.isSourceRegistryReference=Qe,e.sourceBase=Et,e.isSourceDef=mt,e.isPersistableSourceDef=Te,e.isBaseTable=ze,e.isLiteral=st,e.mergeEvalSpaces=de,e.isBasicAtomic=he,e.isUserTypeDef=ve,e.isCompoundArrayData=be,e.isTurtle=Be,e.isAtomic=Ie,e.isValueString=We,e.isValueNumber=nt,e.isValueBoolean=gt,e.isValueTimestamp=yt,e.isValueDate=ut,e.mergeUniqueKeyRequirement=et;const t=Object.prototype.hasOwnProperty;function r(ne,Ae){return t.call(ne,Ae)?ne[Ae]:void 0}function i(){return Object.create(null)}function o(ne){return"kids"in ne}function s(ne){return"e"in ne}function a(ne){return!(o(ne)||s(ne))}function l(ne){return ne.node==="aggregate"&&["sum","avg","count","distinct"].includes(ne.function)}function u(ne){return ne.node!=="arrayLiteral"&&ne.node!=="recordLiteral"}function d(ne,Ae){if(!("typeDef"in ne)){const Ne=typeof Ae=="string"?{type:Ae}:Ae;if(u(ne))return{...ne,typeDef:{...Ne}}}return ne}function c(ne){return"dstSQLType"in ne}function h(ne){return["string","number","boolean","date","timestamp","timestamptz"].includes(ne)}function f(ne){return ne.node==="dateLiteral"||ne.node==="timestampLiteral"||ne.node==="timestamptzLiteral"}function p(ne){return["string","number","boolean","date","timestamp","timestamptz","filter expression","error"].includes(ne)}function x(ne){return ne.value!==null}function m(ne){var Ae;return(Ae=ne.as)!==null&&Ae!==void 0?Ae:ne.name}function g(ne){return ne===void 0||ne==="scalar"}function E(ne){return ne==="aggregate"||ne==="ungrouped_aggregate"}function v(ne){return ne==="ungrouped_aggregate"}function S(ne){return ne==="aggregate"||ne==="ungrouped_aggregate"||ne==="aggregate_analytic"}function C(ne){return ne==="aggregate"||ne==="scalar_analytic"||ne==="aggregate_analytic"||ne==="ungrouped_aggregate"}function T(ne){return ne==="aggregate_analytic"||ne==="scalar_analytic"}function b(ne){return{scalar:0,aggregate:1,ungrouped_aggregate:2,scalar_analytic:2,aggregate_analytic:3}[ne]}function _(ne,Ae){return ne===Ae||b(ne)<b(Ae)}function R(ne,Ae){let Ne="scalar";return(ne==="aggregate"||Ae==="aggregate")&&(Ne="aggregate"),(ne==="ungrouped_aggregate"||Ae==="ungrouped_aggregate")&&(Ne="ungrouped_aggregate"),(ne==="scalar_analytic"||Ae==="scalar_analytic")&&(Ne="scalar_analytic"),(ne==="aggregate_analytic"||Ae==="aggregate_analytic")&&(Ne="aggregate_analytic"),(ne==="scalar_analytic"&&Ae==="aggregate"||ne==="aggregate"&&Ae==="scalar_analytic")&&(Ne="aggregate_analytic"),Ne}function D(ne){return ne.reduce(R,"scalar")}function w(ne){return"e"in ne&&ne.e!==void 0}function N(ne){return ne==="date"||ne==="timestamp"||ne==="timestamptz"}function I(ne){return["string","number","date","timestamp","timestamptz","boolean","json","sql native","error"].includes(ne)}function k(ne){return I(ne)||ne==="record"||ne==="array"}function $(ne){return["string","number","date","boolean","date","timestamp","timestamptz"].includes(ne)}function J(ne){return k(ne.type)&&!w(ne)}function re(ne,Ae){if(te(ne))return ie(ne.elementTypeDef,Ae);if(ee(ne)){const{type:je,fields:it,elementTypeDef:dt}=ne;return{type:je,fields:it,elementTypeDef:dt,join:"many",name:Ae}}if(ne.type==="record"){const{type:je,fields:it}=ne;return{type:je,fields:it,join:"one",name:Ae}}const Ne={name:Ae,type:ne.type};switch(ne.type){case"sql native":return{...Ne,rawType:ne.rawType};case"number":{const je=ne.numberType;return je?{...Ne,numberType:je}:Ne}case"date":{const je=ne.timeframe;return je?{name:Ae,type:"date",timeframe:je}:Ne}case"timestamp":{const je={name:Ae,type:"timestamp"};return ne.timeframe&&(je.timeframe=ne.timeframe),je}case"timestamptz":{const je={name:Ae,type:"timestamptz"};return ne.timeframe&&(je.timeframe=ne.timeframe),je}}return Ne}function ie(ne,Ae){if(ne.type==="record")return{type:"array",join:"many",name:Ae,elementTypeDef:{type:"record_element"},fields:ne.fields};const Ne=re(ne,"value");return{type:"array",join:"many",name:Ae,elementTypeDef:ne,fields:[Ne,{...Ne,name:"each",e:{node:"field",path:["value"]}}]}}function oe(ne){return ne.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:ne.fields}:{type:"array",elementTypeDef:ne}}function U(ne){return ne.type==="array"&&ne.elementTypeDef.type==="record_element"}function ee(ne){return ne.type==="array"&&ne.elementTypeDef.type==="record_element"}function K(ne){return ne.type==="record"||ne.type==="array"&&"elementTypeDef"in ne&&ne.elementTypeDef.type==="record_element"}function te(ne){return ne.type==="array"&&ne.elementTypeDef.type!=="record_element"}function q(ne){return["left","right","full","inner"].includes(ne)}function H(ne){return["composite","table","sql_select","query_source","virtual","array","record"].includes(ne.type)}function Q(ne){return"join"in ne}function M(ne){return mt(ne)&&Q(ne)}function j(ne){return["day","week","month","quarter","year"].includes(ne)}function P(ne){return j(ne)||["hour","minute","second"].includes(ne)}function V(ne){return P(ne)||ne==="day_of_week"||ne==="day_of_year"}var Z;(function(ne){ne.Date="date",ne.Timestamp="timestamp",ne.Number="number",ne.String="string"})(Z||(e.ValueType=Z={}));function ae(ne){return typeof ne!="string"}function ce(ne){return!!((ne.type==="reduce"||ne.type==="project"||ne.type==="partial")&&(ne.extendSource&&ne.extendSource.some(Ae=>Ae.type==="error")||ne.queryFields.some(Ae=>Ae.type==="error")))}function le(ne){return ne.fields.some(Ae=>Ae.type==="error")}function se(ne){return ne.type==="reduce"}function fe(ne){return ne.type==="partial"}function pe(ne){return ne.type==="project"}function ye(ne){return pe(ne)||se(ne)}function Ce(ne){return ne.rows!==void 0}function me(ne){return ne.percent!==void 0}function _e(ne){return ne.enable!==void 0}function we(ne){return ne.type==="raw"}function Ke(ne){return ne.type==="index"}function rt(ne){return ne.uniqueKeyRequirement===void 0&&ne.analyticFunctionUse===void 0}function ge(ne){var Ae;return(Ae=ne?.fieldUsage)!==null&&Ae!==void 0?Ae:[]}function Ee(ne){var Ae;return(Ae=ne?.givenUsage)!==null&&Ae!==void 0?Ae:[]}function Pe({fieldUsage:ne,givenUsage:Ae}){if(!(ne===void 0&&Ae===void 0))return{fieldUsage:ne??[],...Ae&&{givenUsage:Ae}}}function ke(ne,Ae){return ne&&{...ne,fieldUsage:ne.fieldUsage.map(Ae)}}function Me(ne,Ae){ne.refSummary?ne.refSummary.fieldUsage=Ae:ne.refSummary={fieldUsage:Ae}}function Xe(ne){return"sql"in ne}function at(ne){return"type"in ne&&(ne.type==="sql_select"||ne.type==="query_source")}function Qe(ne){return ne.type==="source_registry_reference"}function Et(ne){return{...ne}}function mt(ne){return ne.type==="table"||ne.type==="sql_select"||ne.type==="query_source"||ne.type==="query_result"||ne.type==="finalize"||ne.type==="nest_source"||ne.type==="virtual"||ne.type==="composite"}function Te(ne){return ne.type==="sql_select"||ne.type==="query_source"}function ze(ne){return M(ne)?!1:!!mt(ne)}function st(ne){return ne==="literal"}function de(...ne){return ne.length<=1&&ne.every(Ae=>Ae==="literal")?"literal":ne.every(Ae=>Ae==="constant"||Ae==="literal")?"constant":ne.every(Ae=>Ae==="output"||Ae==="constant"||Ae==="literal")?"output":"input"}function he(ne){return ne.type==="string"||N(ne.type)||ne.type==="number"||ne.type==="boolean"||ne.type==="json"||ne.type==="sql native"||ne.type==="error"}function ve(ne){return ne.type==="userType"}function be(ne){return Array.isArray(ne)&&(ne.length===0||typeof ne[0]=="object"&&ne[0]!==null&&!Array.isArray(ne[0]))}function Be(ne){return ne.type==="turtle"}function Ie(ne){return k(ne.type)}function We(ne,Ae){return Ae.type==="string"}function nt(ne,Ae){return Ae.type==="number"}function gt(ne,Ae){return Ae.type==="boolean"}function yt(ne,Ae){return Ae.type==="timestamp"}function ut(ne,Ae){return Ae.type==="date"}e.TD={isAtomic(ne){return ne!==void 0&&k(ne.type)},isBasicAtomic(ne){return ne!==void 0&&he({type:ne.type})},isString:ne=>ne?.type==="string",isNumber:ne=>ne?.type==="number",isBoolean:ne=>ne?.type==="boolean",isJSON:ne=>ne?.type==="json",isSQL:ne=>ne?.type==="sql native",isDate:ne=>ne?.type==="date",isTimestamp:ne=>ne?.type==="timestamp",isTimestamptz:ne=>ne?.type==="timestamptz",isAnyTimestamp(ne){return ne?.type==="timestamp"||ne?.type==="timestamptz"},isTemporal(ne){var Ae;const Ne=(Ae=ne?.type)!==null&&Ae!==void 0?Ae:"";return N(Ne)},isError:ne=>ne?.type==="error",atomicDef(ne){if(!e.TD.isAtomic(ne))return{type:"error"};switch(ne.type){case"array":return ee(ne)?{type:"array",elementTypeDef:ne.elementTypeDef,fields:ne.fields}:{type:"array",elementTypeDef:ne.elementTypeDef};case"record":return{type:"record",fields:ne.fields};case"number":return ne.numberType?{type:"number",numberType:ne.numberType}:{type:"number"};case"sql native":return ne.rawType?{type:"sql native",rawType:ne.rawType}:{type:"sql native"};case"timestamp":case"timestamptz":return ne.timeframe?{type:ne.type,timeframe:ne.timeframe}:{type:ne.type};default:return{type:ne.type}}},eq(ne,Ae){if(ne===void 0||Ae===void 0)return!1;function Ne(je,it){const dt={},lt=je.fields||[],xt=it.fields||[];if(lt.length!==xt.length)return!1;for(const It of lt)if(It.name)dt[It.name]=It;else return!1;for(const It of xt)if(!e.TD.eq(dt[It.name],It))return!1;return!0}return ne.type==="array"&&Ae.type==="array"?ne.elementTypeDef.type!==Ae.elementTypeDef.type?!1:ne.elementTypeDef.type!=="record_element"&&Ae.elementTypeDef.type!=="record_element"?e.TD.eq(ne.elementTypeDef,Ae.elementTypeDef):e.TD.isAtomic(ne)&&e.TD.isAtomic(Ae)&&Ne(ne,Ae):ne.type==="record"&&Ae.type==="record"?e.TD.isAtomic(ne)&&e.TD.isAtomic(Ae)&&Ne(ne,Ae):ne.type==="sql native"&&Ae.type==="sql native"?ne.rawType!==void 0&&ne.rawType===Ae.rawType:ne.type===Ae.type}};function et(ne,Ae){return ne?Ae?{isCount:ne.isCount||Ae.isCount}:ne:Ae}})(J3)),J3}var gR;function ds(){if(gR)return xr;gR=1,Object.defineProperty(xr,"__esModule",{value:!0}),xr.arg=t,xr.spread=r,xr.sql=i,xr.constant=o,xr.output=s,xr.literal=a,xr.variadicParam=l,xr.param=u,xr.makeParam=d,xr.maxScalar=c,xr.maxAggregate=h,xr.anyExprType=f,xr.maxUngroupedAggregate=p,xr.maxAnalytic=x,xr.minScalar=m,xr.minAggregate=g,xr.minAnalytic=E,xr.overload=v,xr.expandBlueprintMap=te,xr.expandOverrideMapFromBase=Q,xr.def=j;const e=Ge();function t(P){return{node:"function_parameter",name:P}}function r(P,V=void 0,Z=void 0){return{node:"spread",e:P,prefix:V,suffix:Z}}function i(P,...V){const Z={node:"genericSQLExpr",kids:{args:[]},src:[]},ae=[...V];let ce="";for(const le of P){ce+=le;const se=ae.shift();se!==void 0&&(typeof se=="string"?ce+=se:(Z.src.push(ce),Z.kids.args.push(se),ce=""))}return ce.length>0&&Z.src.push(ce),Z}function o(P){return{...P,evalSpace:"constant"}}function s(P){return{...P,evalSpace:"output"}}function a(P){return{...P,evalSpace:"literal"}}function l(P,...V){return{name:P,isVariadic:!0,allowedTypes:V}}function u(P,...V){return{name:P,isVariadic:!1,allowedTypes:V}}function d(P,...V){return{param:u(P,...V),arg:t(P)}}function c(P){return{...P,expressionType:"scalar",evalSpace:"input"}}function h(P){return{...P,expressionType:"aggregate",evalSpace:"input"}}function f(P){return{...P,expressionType:void 0,evalSpace:"input"}}function p(P){return{...P,expressionType:"ungrouped_aggregate",evalSpace:"input"}}function x(P){return{...P,expressionType:"aggregate_analytic",evalSpace:"input"}}function m(P){return{...P,expressionType:"scalar",evalSpace:"input"}}function g(P){return{...P,expressionType:"aggregate",evalSpace:"input"}}function E(P){return{...P,expressionType:"scalar_analytic",evalSpace:"input"}}function v(P,V,Z,ae){return{returnType:P,params:V,e:Z,needsWindowOrderBy:ae?.needsWindowOrderBy,between:ae?.between,isSymmetric:ae?.isSymmetric,supportsOrderBy:ae?.supportsOrderBy,defaultOrderByArgIndex:ae?.defaultOrderByArgIndex,supportsLimit:ae?.supportsLimit}}function S(P,V=!0,Z=!0){if(!V&&P==="any")throw new Error("Return type cannot include any");if(typeof P=="string")return{type:P};if("array"in P){const ae=V?S(P.array,!0):S(P.array,!1);return ae.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:ae.fields}:{type:"array",elementTypeDef:ae}}else if("record"in P){const ae=[];for(const[ce,le]of Object.entries(P.record)){const se=V?S(le,!0):S(le,!1);e.TD.isAtomic(se)&&ae.push((0,e.mkFieldDef)(se,ce))}return{type:"record",fields:ae}}else if("generic"in P){if(!Z)throw new Error("Cannot use generic");return{type:"generic",generic:P.generic}}else if("sql_native"in P)return{type:"sql native",rawType:P.sql_native};throw new Error("Cannot figure out type")}function C(P){if(P==="any")throw new Error("Cannot return any type");if(typeof P=="string")return m({type:P});if("array"in P)return f(S(P,!1));if("record"in P)return f(S(P,!1));if("generic"in P)return m(S(P,!1));if("literal"in P)return a(m(S(P.literal,!1)));if("constant"in P)return o(m(S(P.constant,!1)));if("dimension"in P)return m(S(P.dimension,!1));if("measure"in P)return g(S(P.measure,!1));if("sql_native"in P)return f({type:"sql native",rawType:P.sql_native});if("calculation"in P)return E(S(P.calculation,!1));throw new Error("Invalid function blueprint")}function T(P){return typeof P=="string"||"array"in P||"record"in P||"generic"in P||"literal"in P||"constant"in P||"dimension"in P||"measure"in P||"calculation"in P||"sql_native"in P}function b(P){return T(P)?[P]:Array.isArray(P)?P:T(P.variadic)?[P.variadic]:P.variadic}function _(P){if(typeof P=="string")return f({type:P});if("generic"in P)return f(S(P));if("literal"in P)return a(c(S(P.literal)));if("constant"in P)return o(c(S(P.constant)));if("dimension"in P)return c(S(P.dimension));if("measure"in P)return h(S(P.measure));if("array"in P)return f(S(P,!1));if("record"in P)return f(S(P,!1));if("sql_native"in P)return f({type:"sql native",rawType:P.sql_native});if("calculation"in P)return x(S(P.calculation));throw new Error("Invalid function blueprint")}function R(P){return P.map(V=>_(V))}function D(P){return typeof P!="string"&&"variadic"in P}function w(P,V){return{name:P,allowedTypes:R(b(V)),isVariadic:D(V)}}function N(P){return Object.entries(P).map(Z=>w(Z[0],Z[1]))}function I(P){const V=[],Z=[];let ae=P;for(;ae.length>0;){const le=ae.indexOf("${");if(le===-1){V.push(ae);break}const se=ae.slice(0,le);ae=ae.slice(le);const fe=ae.indexOf("}");if(fe===-1){V.push(se+ae);break}const pe=ae.slice(2,fe);ae=ae.slice(fe+1);const ye=pe.startsWith("..."),Ce=pe.endsWith(":"),me=ye?pe.slice(3):Ce?pe.slice(0,-1):pe,_e={node:"function_parameter",name:me};V.push(se),ye?Z.push({node:"spread",e:_e,prefix:"",suffix:""}):Ce&&me==="order_by"?Z.push({node:"aggregate_order_by"}):Ce&&me==="limit"?Z.push({node:"aggregate_limit"}):Z.push(_e)}return{node:"genericSQLExpr",kids:{args:Z},src:V}}function k(P,V){return D(V)?{node:"spread",e:{node:"function_parameter",name:P},prefix:"",suffix:""}:{node:"function_parameter",name:P}}function $(P,V){const Z=Object.entries(V.takes),ae=Z.length>0?Z.length-1:0;return{node:"genericSQLExpr",kids:{args:Z.map(ce=>k(ce[0],ce[1]))},src:[`${P}(`,...Array(ae).fill(","),")"]}}function J(P){return"sql"in P.impl?I(P.impl.sql):"expr"in P.impl?P.impl.expr:$(P.impl.function,P)}function re(P){return{e:J(P),between:P.impl.between,needsWindowOrderBy:P.impl.needsWindowOrderBy,defaultOrderByArgIndex:P.impl.defaultOrderByArgIndex}}function ie(P){if(P!==void 0)return Object.entries(P).map(([V,Z])=>({name:V,acceptibleTypes:Z.map(ae=>S(ae,!0,!1))}))}function oe(P){return{returnType:C(P.returns),params:N(P.takes),isSymmetric:P.isSymmetric,supportsOrderBy:P.supportsOrderBy,supportsLimit:P.supportsLimit,genericTypes:ie(P.generic),...re(P)}}function U(P){return"takes"in P&&"returns"in P&&"impl"in P}function ee(P){return"function"in P||"sql"in P||"expr"in P}function K(P){return U(P)?[oe(P)]:Object.values(P).flatMap(V=>oe(V))}function te(P){const V={};for(const Z in P)V[Z]=K(P[Z]);return V}function q(P,V){return[oe({...P,impl:V})]}function H(P,V,Z){if(ee(Z)){if(!U(V))throw new Error(`Malformed function override: ${P}. Attempt to override multiple overloads with a single overload (missing: ${Object.keys(V)})`);return q(V,Z)}else{if(U(V))throw new Error(`Malformed function override: ${P}. Attempt to override a single overload with multiple overloads (extraneous: ${Object.keys(Z)})`);return Object.entries(Z).flatMap(([ae,ce])=>{const le=V[ae];if(le===void 0)throw new Error(`Malformed function override: ${P}. No overload named ${ae}`);return q(le,ce)})}}function Q(P,V){const Z={};for(const ae in V){if(!(ae in P))throw new Error(`Malformed function override: ${ae}. No such function in Malloy standard`);Z[ae]=H(ae,P[ae],V[ae])}return Z}function*M(P){if(typeof P!="string"){if("generic"in P)yield P;else if("record"in P)for(const V of Object.values(P.record))yield*M(V);else for(const V of["array","literal","measure","dimension","measure","constant","cacluation"])if(V in P){yield*M(P[V]);return}}}function j(P,V,Z,ae={}){let ce=!1;const le={};for(const fe of Object.values(V))for(const pe of M(fe))le[pe.generic]=["any"],ce=!0;ce&&ae.generic===void 0&&(ae.generic=le);const se={takes:V,returns:Z,impl:{function:P.toUpperCase()},...ae};return{[P]:se}}return xr}var X3={},Df={},yR;function xA(){if(yR)return Df;yR=1,Object.defineProperty(Df,"__esModule",{value:!0}),Df.decodeDottedTablePath=e,Df.validateDottedTablePath=t;function e(o,s){const{quoteChar:a,escapeStyle:l,bareIdentRegex:u,dialectName:d}=s;if(o.length===0)return{ok:!1,error:`${d} table path is empty`};const c=[];let h=0;for(;;){let f,p;if(o[h]===a){const x=r(o,h,a,l);if(x===null)return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — unterminated quoted segment`};f=x.decoded,p=!0,h=x.end}else{const x=o.slice(h).match(u);if(!x||x.index!==0||x[0].length===0)return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — invalid segment at position ${h}`};f=x[0],p=!1,h+=x[0].length}if(f.includes(";")||f.includes("--"))return{ok:!1,error:`Invalid ${d} table path: segment ${JSON.stringify(f)} contains forbidden character; even when quoted, table-path segments may not contain \`;\` or \`--\`.`};if(c.push({value:f,quoted:p}),h===o.length)return{ok:!0,segments:c};if(o[h]!==".")return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — expected '.' at position ${h}`};if(h++,h===o.length)return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — trailing dot`}}}function t(o,s){const a=e(o,s);return a.ok?{ok:!0,canonical:o}:a}function r(o,s,a,l){let u=s+1,d="";for(;u<o.length;){if(l==="backslash"&&o[u]==="\\"){if(u+1>=o.length)return null;d+=i(o[u+1]),u+=2;continue}if(o[u]===a){if(l==="doubled"&&o[u+1]===a){d+=a,u+=2;continue}return{decoded:d,end:u+1}}d+=o[u],u++}return null}function i(o){switch(o){case"n":return`
1
+ import{aF as KF,r as L,j as O,ae as Ht,R as JF,aG as XF,aH as is}from"./index-D2sm5RBA.js";import{r as Zd,a as dA,d as ft}from"./index-Dz8hgkmy.js";import{r as za}from"./index-w_0OQJgZ.js";import{d as CU}from"./index-CtQm7kvp.js";import{MalloyRenderer as ZF,isCoreVizPluginInstance as AU}from"./index-8E2uLeV9.js";var vo={},K3={},xr={},J3={},mR;function Ge(){return mR||(mR=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.TD=e.ValueType=void 0,e.safeRecordGet=r,e.mkSafeRecord=i,e.exprHasKids=o,e.exprHasE=s,e.exprIsLeaf=a,e.isAsymmetricExpr=l,e.mkTemporal=d,e.isRawCast=c,e.isFilterExprType=h,e.isTimeLiteral=f,e.isParameterType=p,e.paramHasValue=x,e.activeName=m,e.expressionIsScalar=g,e.expressionIsAggregate=E,e.expressionIsUngroupedAggregate=v,e.expressionInvolvesAggregate=S,e.expressionIsCalculation=C,e.expressionIsAnalytic=T,e.isExpressionTypeLEQ=_,e.maxExpressionType=R,e.maxOfExpressionTypes=D,e.hasExpression=w,e.isTemporalType=N,e.isBasicAtomicType=I,e.isAtomicFieldType=k,e.canOrderBy=$,e.fieldIsIntrinsic=J,e.mkFieldDef=re,e.mkArrayDef=ie,e.mkArrayTypeDef=oe,e.isRepeatedRecordFunctionParam=U,e.isRepeatedRecord=ee,e.isRecordOrRepeatedRecord=K,e.isBasicArray=te,e.isMatrixOperation=q,e.isJoinable=H,e.isJoined=Q,e.isJoinedSource=M,e.isDateUnit=j,e.isTimestampUnit=P,e.isExtractUnit=V,e.refIsStructDef=ae,e.segmentHasErrors=ce,e.structHasErrors=le,e.isReduceSegment=se,e.isPartialSegment=fe,e.isProjectSegment=pe,e.isQuerySegment=ye,e.isSamplingRows=Ce,e.isSamplingPercent=me,e.isSamplingEnable=_e,e.isRawSegment=we,e.isIndexSegment=Ke,e.bareFieldUsage=rt,e.fieldUsageFrom=ge,e.givenUsageFrom=Ee,e.mkRefSummary=Pe,e.mapFieldUsage=ke,e.setFieldUsage=Me,e.isSegmentSQL=Xe,e.isSegmentSource=at,e.isSourceRegistryReference=Qe,e.sourceBase=Et,e.isSourceDef=mt,e.isPersistableSourceDef=Te,e.isBaseTable=ze,e.isLiteral=st,e.mergeEvalSpaces=de,e.isBasicAtomic=he,e.isUserTypeDef=ve,e.isCompoundArrayData=be,e.isTurtle=Be,e.isAtomic=Ie,e.isValueString=We,e.isValueNumber=nt,e.isValueBoolean=gt,e.isValueTimestamp=yt,e.isValueDate=ut,e.mergeUniqueKeyRequirement=et;const t=Object.prototype.hasOwnProperty;function r(ne,Ae){return t.call(ne,Ae)?ne[Ae]:void 0}function i(){return Object.create(null)}function o(ne){return"kids"in ne}function s(ne){return"e"in ne}function a(ne){return!(o(ne)||s(ne))}function l(ne){return ne.node==="aggregate"&&["sum","avg","count","distinct"].includes(ne.function)}function u(ne){return ne.node!=="arrayLiteral"&&ne.node!=="recordLiteral"}function d(ne,Ae){if(!("typeDef"in ne)){const Ne=typeof Ae=="string"?{type:Ae}:Ae;if(u(ne))return{...ne,typeDef:{...Ne}}}return ne}function c(ne){return"dstSQLType"in ne}function h(ne){return["string","number","boolean","date","timestamp","timestamptz"].includes(ne)}function f(ne){return ne.node==="dateLiteral"||ne.node==="timestampLiteral"||ne.node==="timestamptzLiteral"}function p(ne){return["string","number","boolean","date","timestamp","timestamptz","filter expression","error"].includes(ne)}function x(ne){return ne.value!==null}function m(ne){var Ae;return(Ae=ne.as)!==null&&Ae!==void 0?Ae:ne.name}function g(ne){return ne===void 0||ne==="scalar"}function E(ne){return ne==="aggregate"||ne==="ungrouped_aggregate"}function v(ne){return ne==="ungrouped_aggregate"}function S(ne){return ne==="aggregate"||ne==="ungrouped_aggregate"||ne==="aggregate_analytic"}function C(ne){return ne==="aggregate"||ne==="scalar_analytic"||ne==="aggregate_analytic"||ne==="ungrouped_aggregate"}function T(ne){return ne==="aggregate_analytic"||ne==="scalar_analytic"}function b(ne){return{scalar:0,aggregate:1,ungrouped_aggregate:2,scalar_analytic:2,aggregate_analytic:3}[ne]}function _(ne,Ae){return ne===Ae||b(ne)<b(Ae)}function R(ne,Ae){let Ne="scalar";return(ne==="aggregate"||Ae==="aggregate")&&(Ne="aggregate"),(ne==="ungrouped_aggregate"||Ae==="ungrouped_aggregate")&&(Ne="ungrouped_aggregate"),(ne==="scalar_analytic"||Ae==="scalar_analytic")&&(Ne="scalar_analytic"),(ne==="aggregate_analytic"||Ae==="aggregate_analytic")&&(Ne="aggregate_analytic"),(ne==="scalar_analytic"&&Ae==="aggregate"||ne==="aggregate"&&Ae==="scalar_analytic")&&(Ne="aggregate_analytic"),Ne}function D(ne){return ne.reduce(R,"scalar")}function w(ne){return"e"in ne&&ne.e!==void 0}function N(ne){return ne==="date"||ne==="timestamp"||ne==="timestamptz"}function I(ne){return["string","number","date","timestamp","timestamptz","boolean","json","sql native","error"].includes(ne)}function k(ne){return I(ne)||ne==="record"||ne==="array"}function $(ne){return["string","number","date","boolean","date","timestamp","timestamptz"].includes(ne)}function J(ne){return k(ne.type)&&!w(ne)}function re(ne,Ae){if(te(ne))return ie(ne.elementTypeDef,Ae);if(ee(ne)){const{type:je,fields:it,elementTypeDef:dt}=ne;return{type:je,fields:it,elementTypeDef:dt,join:"many",name:Ae}}if(ne.type==="record"){const{type:je,fields:it}=ne;return{type:je,fields:it,join:"one",name:Ae}}const Ne={name:Ae,type:ne.type};switch(ne.type){case"sql native":return{...Ne,rawType:ne.rawType};case"number":{const je=ne.numberType;return je?{...Ne,numberType:je}:Ne}case"date":{const je=ne.timeframe;return je?{name:Ae,type:"date",timeframe:je}:Ne}case"timestamp":{const je={name:Ae,type:"timestamp"};return ne.timeframe&&(je.timeframe=ne.timeframe),je}case"timestamptz":{const je={name:Ae,type:"timestamptz"};return ne.timeframe&&(je.timeframe=ne.timeframe),je}}return Ne}function ie(ne,Ae){if(ne.type==="record")return{type:"array",join:"many",name:Ae,elementTypeDef:{type:"record_element"},fields:ne.fields};const Ne=re(ne,"value");return{type:"array",join:"many",name:Ae,elementTypeDef:ne,fields:[Ne,{...Ne,name:"each",e:{node:"field",path:["value"]}}]}}function oe(ne){return ne.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:ne.fields}:{type:"array",elementTypeDef:ne}}function U(ne){return ne.type==="array"&&ne.elementTypeDef.type==="record_element"}function ee(ne){return ne.type==="array"&&ne.elementTypeDef.type==="record_element"}function K(ne){return ne.type==="record"||ne.type==="array"&&"elementTypeDef"in ne&&ne.elementTypeDef.type==="record_element"}function te(ne){return ne.type==="array"&&ne.elementTypeDef.type!=="record_element"}function q(ne){return["left","right","full","inner"].includes(ne)}function H(ne){return["composite","table","sql_select","query_source","virtual","array","record"].includes(ne.type)}function Q(ne){return"join"in ne}function M(ne){return mt(ne)&&Q(ne)}function j(ne){return["day","week","month","quarter","year"].includes(ne)}function P(ne){return j(ne)||["hour","minute","second"].includes(ne)}function V(ne){return P(ne)||ne==="day_of_week"||ne==="day_of_year"}var Z;(function(ne){ne.Date="date",ne.Timestamp="timestamp",ne.Number="number",ne.String="string"})(Z||(e.ValueType=Z={}));function ae(ne){return typeof ne!="string"}function ce(ne){return!!((ne.type==="reduce"||ne.type==="project"||ne.type==="partial")&&(ne.extendSource&&ne.extendSource.some(Ae=>Ae.type==="error")||ne.queryFields.some(Ae=>Ae.type==="error")))}function le(ne){return ne.fields.some(Ae=>Ae.type==="error")}function se(ne){return ne.type==="reduce"}function fe(ne){return ne.type==="partial"}function pe(ne){return ne.type==="project"}function ye(ne){return pe(ne)||se(ne)}function Ce(ne){return ne.rows!==void 0}function me(ne){return ne.percent!==void 0}function _e(ne){return ne.enable!==void 0}function we(ne){return ne.type==="raw"}function Ke(ne){return ne.type==="index"}function rt(ne){return ne.uniqueKeyRequirement===void 0&&ne.analyticFunctionUse===void 0}function ge(ne){var Ae;return(Ae=ne?.fieldUsage)!==null&&Ae!==void 0?Ae:[]}function Ee(ne){var Ae;return(Ae=ne?.givenUsage)!==null&&Ae!==void 0?Ae:[]}function Pe({fieldUsage:ne,givenUsage:Ae}){if(!(ne===void 0&&Ae===void 0))return{fieldUsage:ne??[],...Ae&&{givenUsage:Ae}}}function ke(ne,Ae){return ne&&{...ne,fieldUsage:ne.fieldUsage.map(Ae)}}function Me(ne,Ae){ne.refSummary?ne.refSummary.fieldUsage=Ae:ne.refSummary={fieldUsage:Ae}}function Xe(ne){return"sql"in ne}function at(ne){return"type"in ne&&(ne.type==="sql_select"||ne.type==="query_source")}function Qe(ne){return ne.type==="source_registry_reference"}function Et(ne){return{...ne}}function mt(ne){return ne.type==="table"||ne.type==="sql_select"||ne.type==="query_source"||ne.type==="query_result"||ne.type==="finalize"||ne.type==="nest_source"||ne.type==="virtual"||ne.type==="composite"}function Te(ne){return ne.type==="sql_select"||ne.type==="query_source"}function ze(ne){return M(ne)?!1:!!mt(ne)}function st(ne){return ne==="literal"}function de(...ne){return ne.length<=1&&ne.every(Ae=>Ae==="literal")?"literal":ne.every(Ae=>Ae==="constant"||Ae==="literal")?"constant":ne.every(Ae=>Ae==="output"||Ae==="constant"||Ae==="literal")?"output":"input"}function he(ne){return ne.type==="string"||N(ne.type)||ne.type==="number"||ne.type==="boolean"||ne.type==="json"||ne.type==="sql native"||ne.type==="error"}function ve(ne){return ne.type==="userType"}function be(ne){return Array.isArray(ne)&&(ne.length===0||typeof ne[0]=="object"&&ne[0]!==null&&!Array.isArray(ne[0]))}function Be(ne){return ne.type==="turtle"}function Ie(ne){return k(ne.type)}function We(ne,Ae){return Ae.type==="string"}function nt(ne,Ae){return Ae.type==="number"}function gt(ne,Ae){return Ae.type==="boolean"}function yt(ne,Ae){return Ae.type==="timestamp"}function ut(ne,Ae){return Ae.type==="date"}e.TD={isAtomic(ne){return ne!==void 0&&k(ne.type)},isBasicAtomic(ne){return ne!==void 0&&he({type:ne.type})},isString:ne=>ne?.type==="string",isNumber:ne=>ne?.type==="number",isBoolean:ne=>ne?.type==="boolean",isJSON:ne=>ne?.type==="json",isSQL:ne=>ne?.type==="sql native",isDate:ne=>ne?.type==="date",isTimestamp:ne=>ne?.type==="timestamp",isTimestamptz:ne=>ne?.type==="timestamptz",isAnyTimestamp(ne){return ne?.type==="timestamp"||ne?.type==="timestamptz"},isTemporal(ne){var Ae;const Ne=(Ae=ne?.type)!==null&&Ae!==void 0?Ae:"";return N(Ne)},isError:ne=>ne?.type==="error",atomicDef(ne){if(!e.TD.isAtomic(ne))return{type:"error"};switch(ne.type){case"array":return ee(ne)?{type:"array",elementTypeDef:ne.elementTypeDef,fields:ne.fields}:{type:"array",elementTypeDef:ne.elementTypeDef};case"record":return{type:"record",fields:ne.fields};case"number":return ne.numberType?{type:"number",numberType:ne.numberType}:{type:"number"};case"sql native":return ne.rawType?{type:"sql native",rawType:ne.rawType}:{type:"sql native"};case"timestamp":case"timestamptz":return ne.timeframe?{type:ne.type,timeframe:ne.timeframe}:{type:ne.type};default:return{type:ne.type}}},eq(ne,Ae){if(ne===void 0||Ae===void 0)return!1;function Ne(je,it){const dt={},lt=je.fields||[],xt=it.fields||[];if(lt.length!==xt.length)return!1;for(const It of lt)if(It.name)dt[It.name]=It;else return!1;for(const It of xt)if(!e.TD.eq(dt[It.name],It))return!1;return!0}return ne.type==="array"&&Ae.type==="array"?ne.elementTypeDef.type!==Ae.elementTypeDef.type?!1:ne.elementTypeDef.type!=="record_element"&&Ae.elementTypeDef.type!=="record_element"?e.TD.eq(ne.elementTypeDef,Ae.elementTypeDef):e.TD.isAtomic(ne)&&e.TD.isAtomic(Ae)&&Ne(ne,Ae):ne.type==="record"&&Ae.type==="record"?e.TD.isAtomic(ne)&&e.TD.isAtomic(Ae)&&Ne(ne,Ae):ne.type==="sql native"&&Ae.type==="sql native"?ne.rawType!==void 0&&ne.rawType===Ae.rawType:ne.type===Ae.type}};function et(ne,Ae){return ne?Ae?{isCount:ne.isCount||Ae.isCount}:ne:Ae}})(J3)),J3}var gR;function ds(){if(gR)return xr;gR=1,Object.defineProperty(xr,"__esModule",{value:!0}),xr.arg=t,xr.spread=r,xr.sql=i,xr.constant=o,xr.output=s,xr.literal=a,xr.variadicParam=l,xr.param=u,xr.makeParam=d,xr.maxScalar=c,xr.maxAggregate=h,xr.anyExprType=f,xr.maxUngroupedAggregate=p,xr.maxAnalytic=x,xr.minScalar=m,xr.minAggregate=g,xr.minAnalytic=E,xr.overload=v,xr.expandBlueprintMap=te,xr.expandOverrideMapFromBase=Q,xr.def=j;const e=Ge();function t(P){return{node:"function_parameter",name:P}}function r(P,V=void 0,Z=void 0){return{node:"spread",e:P,prefix:V,suffix:Z}}function i(P,...V){const Z={node:"genericSQLExpr",kids:{args:[]},src:[]},ae=[...V];let ce="";for(const le of P){ce+=le;const se=ae.shift();se!==void 0&&(typeof se=="string"?ce+=se:(Z.src.push(ce),Z.kids.args.push(se),ce=""))}return ce.length>0&&Z.src.push(ce),Z}function o(P){return{...P,evalSpace:"constant"}}function s(P){return{...P,evalSpace:"output"}}function a(P){return{...P,evalSpace:"literal"}}function l(P,...V){return{name:P,isVariadic:!0,allowedTypes:V}}function u(P,...V){return{name:P,isVariadic:!1,allowedTypes:V}}function d(P,...V){return{param:u(P,...V),arg:t(P)}}function c(P){return{...P,expressionType:"scalar",evalSpace:"input"}}function h(P){return{...P,expressionType:"aggregate",evalSpace:"input"}}function f(P){return{...P,expressionType:void 0,evalSpace:"input"}}function p(P){return{...P,expressionType:"ungrouped_aggregate",evalSpace:"input"}}function x(P){return{...P,expressionType:"aggregate_analytic",evalSpace:"input"}}function m(P){return{...P,expressionType:"scalar",evalSpace:"input"}}function g(P){return{...P,expressionType:"aggregate",evalSpace:"input"}}function E(P){return{...P,expressionType:"scalar_analytic",evalSpace:"input"}}function v(P,V,Z,ae){return{returnType:P,params:V,e:Z,needsWindowOrderBy:ae?.needsWindowOrderBy,between:ae?.between,isSymmetric:ae?.isSymmetric,supportsOrderBy:ae?.supportsOrderBy,defaultOrderByArgIndex:ae?.defaultOrderByArgIndex,supportsLimit:ae?.supportsLimit}}function S(P,V=!0,Z=!0){if(!V&&P==="any")throw new Error("Return type cannot include any");if(typeof P=="string")return{type:P};if("array"in P){const ae=V?S(P.array,!0):S(P.array,!1);return ae.type==="record"?{type:"array",elementTypeDef:{type:"record_element"},fields:ae.fields}:{type:"array",elementTypeDef:ae}}else if("record"in P){const ae=[];for(const[ce,le]of Object.entries(P.record)){const se=V?S(le,!0):S(le,!1);e.TD.isAtomic(se)&&ae.push((0,e.mkFieldDef)(se,ce))}return{type:"record",fields:ae}}else if("generic"in P){if(!Z)throw new Error("Cannot use generic");return{type:"generic",generic:P.generic}}else if("sql_native"in P)return{type:"sql native",rawType:P.sql_native};throw new Error("Cannot figure out type")}function C(P){if(P==="any")throw new Error("Cannot return any type");if(typeof P=="string")return m({type:P});if("array"in P)return f(S(P,!1));if("record"in P)return f(S(P,!1));if("generic"in P)return m(S(P,!1));if("literal"in P)return a(m(S(P.literal,!1)));if("constant"in P)return o(m(S(P.constant,!1)));if("dimension"in P)return m(S(P.dimension,!1));if("measure"in P)return g(S(P.measure,!1));if("sql_native"in P)return f({type:"sql native",rawType:P.sql_native});if("calculation"in P)return E(S(P.calculation,!1));throw new Error("Invalid function blueprint")}function T(P){return typeof P=="string"||"array"in P||"record"in P||"generic"in P||"literal"in P||"constant"in P||"dimension"in P||"measure"in P||"calculation"in P||"sql_native"in P}function b(P){return T(P)?[P]:Array.isArray(P)?P:T(P.variadic)?[P.variadic]:P.variadic}function _(P){if(typeof P=="string")return f({type:P});if("generic"in P)return f(S(P));if("literal"in P)return a(c(S(P.literal)));if("constant"in P)return o(c(S(P.constant)));if("dimension"in P)return c(S(P.dimension));if("measure"in P)return h(S(P.measure));if("array"in P)return f(S(P,!1));if("record"in P)return f(S(P,!1));if("sql_native"in P)return f({type:"sql native",rawType:P.sql_native});if("calculation"in P)return x(S(P.calculation));throw new Error("Invalid function blueprint")}function R(P){return P.map(V=>_(V))}function D(P){return typeof P!="string"&&"variadic"in P}function w(P,V){return{name:P,allowedTypes:R(b(V)),isVariadic:D(V)}}function N(P){return Object.entries(P).map(Z=>w(Z[0],Z[1]))}function I(P){const V=[],Z=[];let ae=P;for(;ae.length>0;){const le=ae.indexOf("${");if(le===-1){V.push(ae);break}const se=ae.slice(0,le);ae=ae.slice(le);const fe=ae.indexOf("}");if(fe===-1){V.push(se+ae);break}const pe=ae.slice(2,fe);ae=ae.slice(fe+1);const ye=pe.startsWith("..."),Ce=pe.endsWith(":"),me=ye?pe.slice(3):Ce?pe.slice(0,-1):pe,_e={node:"function_parameter",name:me};V.push(se),ye?Z.push({node:"spread",e:_e,prefix:"",suffix:""}):Ce&&me==="order_by"?Z.push({node:"aggregate_order_by"}):Ce&&me==="limit"?Z.push({node:"aggregate_limit"}):Z.push(_e)}return{node:"genericSQLExpr",kids:{args:Z},src:V}}function k(P,V){return D(V)?{node:"spread",e:{node:"function_parameter",name:P},prefix:"",suffix:""}:{node:"function_parameter",name:P}}function $(P,V){const Z=Object.entries(V.takes),ae=Z.length>0?Z.length-1:0;return{node:"genericSQLExpr",kids:{args:Z.map(ce=>k(ce[0],ce[1]))},src:[`${P}(`,...Array(ae).fill(","),")"]}}function J(P){return"sql"in P.impl?I(P.impl.sql):"expr"in P.impl?P.impl.expr:$(P.impl.function,P)}function re(P){return{e:J(P),between:P.impl.between,needsWindowOrderBy:P.impl.needsWindowOrderBy,defaultOrderByArgIndex:P.impl.defaultOrderByArgIndex}}function ie(P){if(P!==void 0)return Object.entries(P).map(([V,Z])=>({name:V,acceptibleTypes:Z.map(ae=>S(ae,!0,!1))}))}function oe(P){return{returnType:C(P.returns),params:N(P.takes),isSymmetric:P.isSymmetric,supportsOrderBy:P.supportsOrderBy,supportsLimit:P.supportsLimit,genericTypes:ie(P.generic),...re(P)}}function U(P){return"takes"in P&&"returns"in P&&"impl"in P}function ee(P){return"function"in P||"sql"in P||"expr"in P}function K(P){return U(P)?[oe(P)]:Object.values(P).flatMap(V=>oe(V))}function te(P){const V={};for(const Z in P)V[Z]=K(P[Z]);return V}function q(P,V){return[oe({...P,impl:V})]}function H(P,V,Z){if(ee(Z)){if(!U(V))throw new Error(`Malformed function override: ${P}. Attempt to override multiple overloads with a single overload (missing: ${Object.keys(V)})`);return q(V,Z)}else{if(U(V))throw new Error(`Malformed function override: ${P}. Attempt to override a single overload with multiple overloads (extraneous: ${Object.keys(Z)})`);return Object.entries(Z).flatMap(([ae,ce])=>{const le=V[ae];if(le===void 0)throw new Error(`Malformed function override: ${P}. No overload named ${ae}`);return q(le,ce)})}}function Q(P,V){const Z={};for(const ae in V){if(!(ae in P))throw new Error(`Malformed function override: ${ae}. No such function in Malloy standard`);Z[ae]=H(ae,P[ae],V[ae])}return Z}function*M(P){if(typeof P!="string"){if("generic"in P)yield P;else if("record"in P)for(const V of Object.values(P.record))yield*M(V);else for(const V of["array","literal","measure","dimension","measure","constant","cacluation"])if(V in P){yield*M(P[V]);return}}}function j(P,V,Z,ae={}){let ce=!1;const le={};for(const fe of Object.values(V))for(const pe of M(fe))le[pe.generic]=["any"],ce=!0;ce&&ae.generic===void 0&&(ae.generic=le);const se={takes:V,returns:Z,impl:{function:P.toUpperCase()},...ae};return{[P]:se}}return xr}var X3={},Df={},yR;function xA(){if(yR)return Df;yR=1,Object.defineProperty(Df,"__esModule",{value:!0}),Df.decodeDottedTablePath=e,Df.validateDottedTablePath=t;function e(o,s){const{quoteChar:a,escapeStyle:l,bareIdentRegex:u,dialectName:d}=s;if(o.length===0)return{ok:!1,error:`${d} table path is empty`};const c=[];let h=0;for(;;){let f,p;if(o[h]===a){const x=r(o,h,a,l);if(x===null)return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — unterminated quoted segment`};f=x.decoded,p=!0,h=x.end}else{const x=o.slice(h).match(u);if(!x||x.index!==0||x[0].length===0)return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — invalid segment at position ${h}`};f=x[0],p=!1,h+=x[0].length}if(f.includes(";")||f.includes("--"))return{ok:!1,error:`Invalid ${d} table path: segment ${JSON.stringify(f)} contains forbidden character; even when quoted, table-path segments may not contain \`;\` or \`--\`.`};if(c.push({value:f,quoted:p}),h===o.length)return{ok:!0,segments:c};if(o[h]!==".")return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — expected '.' at position ${h}`};if(h++,h===o.length)return{ok:!1,error:`Invalid ${d} table path: ${JSON.stringify(o)} — trailing dot`}}}function t(o,s){const a=e(o,s);return a.ok?{ok:!0,canonical:o}:a}function r(o,s,a,l){let u=s+1,d="";for(;u<o.length;){if(l==="backslash"&&o[u]==="\\"){if(u+1>=o.length)return null;d+=i(o[u+1]),u+=2;continue}if(o[u]===a){if(l==="doubled"&&o[u+1]===a){d+=a,u+=2;continue}return{decoded:d,end:u+1}}d+=o[u],u++}return null}function i(o){switch(o){case"n":return`
2
2
  `;case"t":return" ";case"r":return"\r";default:return o}}return Df}var ER;function Ys(){return ER||(ER=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.Dialect=e.dayIndex=e.EscapeStyle=e.MAX_DECIMAL38=e.MIN_DECIMAL38=e.MAX_INT128=e.MIN_INT128=e.MAX_INT64=e.MIN_INT64=e.MAX_INT32=e.MIN_INT32=void 0,e.inDays=o,e.qtz=s,e.turtleGroupSetCondition=a;const t=Ge(),r=xA();e.MIN_INT32=-2147483648,e.MAX_INT32=2147483647,e.MIN_INT64=BigInt("-9223372036854775808"),e.MAX_INT64=BigInt("9223372036854775807"),e.MIN_INT128=BigInt("-170141183460469231731687303715884105728"),e.MAX_INT128=BigInt("170141183460469231731687303715884105727"),e.MIN_DECIMAL38=BigInt("-99999999999999999999999999999999999999"),e.MAX_DECIMAL38=BigInt("99999999999999999999999999999999999999"),e.EscapeStyle={Doubled:"doubled",Backslash:"backslash",Unset:"unset"};const i=["microsecond","millisecond","second","minute","hour","day","week","month","quarter","year"];e.dayIndex=i.indexOf("day");function o(u){return i.indexOf(u)>=e.dayIndex}function s(u){const d=u.queryTimezone;if(!(d===void 0||d===u.systemTimezone))return d}function a(u,d){return u===void 0?d:d?`group_set=${u} AND ${d}`:`group_set=${u}`}class l{constructor(){this.cantPartitionWindowFunctionsOnExpressions=!1,this.supportsPipelinesInViews=!0,this.supportsNestedProjectionLimit=!1,this.supportsArraysInData=!0,this.hasTimestamptz=!1,this.readsNestedData=!0,this.orderByClause="ordinal",this.nullMatchesFunctionSignature=!0,this.supportsSelectReplace=!0,this.supportsBigIntPrecision=!0,this.supportsComplexFilteredSources=!0,this.supportsTempTables=!0,this.maxIdentifierLength=128,this.hasModOperator=!0,this.supportsLeftJoinUnnest=!0,this.requiresExplicitUnnestOrdering=!1,this.hasLateralColumnAliasInSelect=!1,this.supportsCountApprox=!1,this.supportsHyperLogLog=!1,this.supportsFullJoin=!0,this.nestedArrays=!0,this.compoundObjectInSchema=!0,this.booleanType="supported",this.likeEscape=!0,this.integerTypeMappings=[{min:BigInt(e.MIN_INT32),max:BigInt(e.MAX_INT32),numberType:"integer"},{min:e.MIN_INT64,max:e.MAX_INT64,numberType:"bigint"}],this.tablePathBareIdentRegex=/^[A-Za-z_][A-Za-z0-9_]*/,this.identifierQuoteChar="",this.stringLiteralStyle=e.EscapeStyle.Unset,this.identifierEscapeStyle=e.EscapeStyle.Unset}sqlLateralJoinBag(d){throw this.cantPartitionWindowFunctionsOnExpressions?new Error(`Dialect '${this.name}' sets cantPartitionWindowFunctionsOnExpressions but does not implement sqlLateralJoinBag`):new Error("Internal error: sqlLateralJoinBag called but cantPartitionWindowFunctionsOnExpressions is false")}literalNumberType(d){if(!/^-?\d+$/.test(d))return{type:"number",numberType:"float"};const h=BigInt(d);for(const f of this.integerTypeMappings)if(h>=f.min&&h<=f.max)return{type:"number",numberType:f.numberType};return{type:"number",numberType:"bigint"}}static makeTimeLiteralNode(d,c,h,f,p){var x;const m=(x=d?.hasTimestamptz)!==null&&x!==void 0?x:!1;return p==="date"?{node:"dateLiteral",literal:c,typeDef:{type:"date",timeframe:f!==void 0&&(0,t.isDateUnit)(f)?f:void 0}}:h&&m?{node:"timestamptzLiteral",literal:c,typeDef:{type:"timestamptz",timeframe:f},timezone:h}:h?{node:"timestampLiteral",literal:c,typeDef:{type:"timestamp",timeframe:f},timezone:h}:{node:"timestampLiteral",literal:c,typeDef:{type:"timestamp",timeframe:f}}}sqlValidateTableName(d){if(this.identifierEscapeStyle!==e.EscapeStyle.Doubled&&this.identifierEscapeStyle!==e.EscapeStyle.Backslash)throw new Error(`${this.name}: sqlValidateTableName requires identifierEscapeStyle to be set to Doubled or Backslash (or override sqlValidateTableName).`);return(0,r.validateDottedTablePath)(d,{quoteChar:this.identifierQuoteChar,escapeStyle:this.identifierEscapeStyle,bareIdentRegex:this.tablePathBareIdentRegex,dialectName:this.name})}sqlTurtleOrderByClause(d){const c=d.map(h=>` ${h.field} ${h.dir.toUpperCase()}`);return" "+this.sqlOrderBy(c,"turtle")}sqlFinalStage(d,c){throw new Error("Dialect has no final Stage but called Anyway")}sqlDateToString(d){return this.castToString(`DATE(${d})`)}escapeBackslashStyle(d,c){let h="";for(const f of d)switch(f){case"\\":h+="\\\\";break;case`
3
3
  `:h+="\\n";break;case"\r":h+="\\r";break;case" ":h+="\\t";break;case c:h+="\\"+c;break;default:h+=f}return h}sqlQuoteIdentifier(d){const c=this.identifierQuoteChar;if(!c)throw new Error(`${this.name}: identifierQuoteChar is not set. Set it on the dialect (e.g. '"' or "\`"), or override sqlQuoteIdentifier.`);if(this.identifierEscapeStyle===e.EscapeStyle.Doubled)return c+d.split(c).join(c+c)+c;if(this.identifierEscapeStyle===e.EscapeStyle.Backslash)return c+this.escapeBackslashStyle(d,c)+c;throw new Error(`${this.name}: identifierEscapeStyle is not set. Set it to EscapeStyle.Doubled or EscapeStyle.Backslash on the dialect, or override sqlQuoteIdentifier.`)}sqlLiteralNumber(d){return d}ignoreInProject(d){return!1}needsCivilTimeComputation(d,c,h,f){const p=["day","week","month","quarter","year"],x=c!==void 0&&p.includes(c),m=h!==void 0&&p.includes(h),g=s(f);return{needed:t.TD.isAnyTimestamp(d)&&(x||m)&&g!==void 0,tz:g}}sqlTruncAndOffset(d,c,h,f){if(t.TD.isAnyTimestamp(d.typeDef)){const{needed:x,tz:m}=this.needsCivilTimeComputation(d.typeDef,h,f?.unit,c);if(x&&m){const g=this.sqlConvertToCivilTime(d.sql,m,d.typeDef);let E=g.sql;const v=g.typeDef;return h&&(E=this.sqlTruncate(E,h,v,!0,m)),f&&(E=this.sqlOffsetTime(E,f.op,f.magnitude,f.unit,v,!0,m)),this.sqlConvertFromCivilTime(E,m,d.typeDef)}}let p=d.sql;return h&&(p=this.sqlTruncate(p,h,d.typeDef,!1,s(c))),f&&(p=this.sqlOffsetTime(p,f.op,f.magnitude,f.unit,d.typeDef,!1,s(c))),p}sqlLiteralString(d){if(this.stringLiteralStyle==="doubled")return"'"+d.split("'").join("''")+"'";if(this.stringLiteralStyle==="backslash")return"'"+this.escapeBackslashStyle(d,"'")+"'";throw new Error(`${this.name}: stringLiteralStyle is not set. Set it to EscapeStyle.Doubled or EscapeStyle.Backslash on the dialect, or override sqlLiteralString.`)}sqlLiteralRegexp(d){return this.sqlLiteralString(d)}exprToSQL(d,c){switch(c.node){case"now":return this.sqlNowExpr();case"timeDiff":return this.sqlMeasureTimeExpr(c);case"delta":{const h=c.kids.base;return h.node==="trunc"?this.sqlTruncAndOffset(h.e,d,h.units,{op:c.op,magnitude:c.kids.delta.sql,unit:c.units}):this.sqlTruncAndOffset(h,d,void 0,{op:c.op,magnitude:c.kids.delta.sql,unit:c.units})}case"trunc":return this.sqlTruncAndOffset(c.e,d,c.units);case"extract":return this.sqlTimeExtractExpr(d,c);case"cast":return this.sqlCast(d,c);case"regexpMatch":return this.sqlRegexpMatch(c);case"/":return this.divisionIsInteger?`${c.kids.left.sql}*1.0/${c.kids.right.sql}`:void 0;case"%":return this.hasModOperator?void 0:`MOD(${c.kids.left.sql},${c.kids.right.sql})`;case"dateLiteral":return this.sqlDateLiteral(d,c.literal);case"timestampLiteral":return this.sqlTimestampLiteral(d,c.literal,c.timezone);case"timestamptzLiteral":return this.sqlTimestamptzLiteral(d,c.literal,c.timezone);case"stringLiteral":return this.sqlLiteralString(c.literal);case"numberLiteral":return this.sqlLiteralNumber(c.literal);case"regexpLiteral":return this.sqlLiteralRegexp(c.literal);case"recordLiteral":return this.sqlLiteralRecord(c);case"arrayLiteral":return this.sqlLiteralArray(c)}}sqlSumDistinct(d,c,h){return"sqlSumDistinct called but not implemented"}sqlAggDistinct(d,c,h){return"sqlAggDistinct called but not implemented"}sqlSampleTable(d,c){if(c!==void 0)throw new Error(`Sampling is not supported on dialect ${this.name}.`);return d}sqlOrderBy(d,c){return`ORDER BY ${d.join(",")}`}sqlTzStr(d){return`"${d.queryTimezone}"`}sqlMakeUnnestKey(d,c){return this.concat(d,"'x'",c)}sqlStringAggDistinct(d,c,h){const f="__STRING_AGG_KS__",p="__STRING_AGG_KE__";return`REGEXP_REPLACE(
4
4
  STRING_AGG(DISTINCT ${`concat('${f}', ${d}, '${p}', ${c})`}${h.length>0?","+h:""}),
@@ -1283,7 +1283,7 @@ z\fzzט\vzzz{{{\x07{ן
1283
1283
  | ${j}`,Q>0&&(te=te+`
1284
1284
  | ${" ".repeat(Q)}^`)}else te=`line ${H+1}: char ${Q}: ${K.message}`}ee!==q&&(te=`FILE: ${q}
1285
1285
  `+te,ee=q),U!==""?U=`${U}
1286
- ${te}`:U=te}return U}childRequest(U){var ee;const K=decodeURI(new URL(U,this.sourceURL).toString()),te=(ee=this.childTranslators.get(K))===null||ee===void 0?void 0:ee.translate();if(te?.compileSQL)return{compileSQL:te.compileSQL}}importModelDef(U){const ee=decodeURI(new URL(U,this.sourceURL).toString()),K=this.childTranslators.get(ee);if(K)return K.translate().modelDef}translate(U){if(this.finalAnswer)return this.finalAnswer;const ee=this.translateStep.step(this,U);return ee.final&&(this.finalAnswer=ee),ee}translatorForDependency(U){return this.childTranslators.get(U)}importAt(U){for(let ee=0;ee<this.imports.length;ee++){const K=this.imports[ee];if((0,g.locationContainsPosition)(K.location,U))return K}}metadata(){return this.metadataStep.step(this)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(U){return this.completionsStep.step(this,U)}helpContext(U){return this.helpContextStep.step(this,U)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(U){return(0,g.rangeFromContext)(this.parseStep.sourceInfo,U)}firstReferenceToDialect(U){return this.dialectAlreadyChecked[U]?!1:(this.dialectAlreadyChecked[U]=!0,!0)}experimentalDialectEnabled(U){if(this.allDialectsEnabled)return!0;const ee=this.getCompilerFlags().tag("experimental");return ee!==void 0&&(ee.bare()||ee.has("dialect",U))}}pn.MalloyTranslation=$;class J extends ${constructor(U,ee){super(U),this.root=ee}}pn.MalloyChildTranslator=J;class re extends ${constructor(U,ee=null,K=null,te=null,q=!1){super(U,ee),this.eventStream=te,this.restrictedMode=q,this.schemaZone=new c.Zone,this.importZone=new c.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new c.Zone,this.connectionDialectZone=new c.Zone,this.root=this,this.logger=new l.BaseMessageLogger(te),K&&this.update(K)}update(U){var ee,K,te,q;this.schemaZone.updateFrom(U.tables,(ee=U.errors)===null||ee===void 0?void 0:ee.tables),this.importZone.updateFrom(U.urls,(K=U.errors)===null||K===void 0?void 0:K.urls),this.sqlQueryZone.updateFrom(U.compileSQL,(te=U.errors)===null||te===void 0?void 0:te.compileSQL),this.connectionDialectZone.updateFrom(U.connectionDialects,(q=U.errors)===null||q===void 0?void 0:q.connectionDialects);for(const H in U.translations)this.pretranslatedModels.set(H,U.translations[H])}lockZonesIfRestricted(){this.restrictedMode&&(this.schemaZone.lock(),this.importZone.lock(),this.sqlQueryZone.lock(),this.connectionDialectZone.lock())}translate(U){return this.lockZonesIfRestricted(),super.translate(U)}logError(U,ee,K){return this.logger.log((0,l.makeLogMessage)(U,ee,{severity:"error",...K})),U}}pn.MalloyTranslator=re;function ie(oe){return[...Object.keys(oe),...Object.keys(oe).map(U=>ie(oe[U])).flat()]}return pn}var pd={},a8;function hz(){if(a8)return pd;a8=1,Object.defineProperty(pd,"__esModule",{value:!0}),pd.ExploreQueryWalker=void 0,pd.exploreQueryWalkerBuilder=r;const e=sx();class t{constructor(o){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=o}exploreQueryAtOffset(o){return this.exploreClauseRefs.find(s=>s.range[0]===void 0||s.range[1]===void 0?!1:s.range[0]<=o&&s.range[1]>=o)}filterAtOffset(o){const s=this.exploreQueryAtOffset(o);if(s)return s.filterRefs.find(a=>a.range[0]===void 0||a.range[1]===void 0?!1:a.range[0]<=o&&a.range[1]>=o)}hasFilterListAtOffset(o){const s=this.exploreQueryAtOffset(o);return s?!!s.filterLists.find(a=>a.range[0]===void 0||a.range[1]===void 0?!1:a.range[0]<=o&&a.range[1]>=o):!1}enterMalloyDocument(){this.inDocument=!0}}pd.ExploreQueryWalker=t;function r(i,o){const s=new t(i),a=s;return e.ParseTreeWalker.DEFAULT.walk(a,o),s}return pd}var ri={},iS={},md={},u8;function YE(){if(u8)return md;u8=1,Object.defineProperty(md,"__esModule",{value:!0}),md.validateCanonicalTablePath=t,md.validateCanonicalTablePathAnyDialect=r,md.requireCanonicalTablePathAnyDialect=i;const e=bE();function t(o,s){let a;try{a=(0,e.getDialect)(o)}catch{return`tablePath '${s}' cannot be validated: unknown dialect '${o}'`}const l=a.sqlValidateTableName(s);if(!l.ok)return`tablePath '${s}' is not canonical SQL for the ${o} dialect; the translator must validate before passing it here. (${l.error})`;if(l.canonical!==s)return`tablePath '${s}' is not canonical SQL for the ${o} dialect; the translator must validate before passing it here.`}function r(o){let s;for(const a of(0,e.getDialects)()){const l=a.sqlValidateTableName(o);if(l.ok){if(l.canonical===o)return;s===void 0&&(s=l.canonical)}}return s!==void 0?`value '${o}' is not canonical SQL; did you mean '${s}'?`:`value '${o}' is not a valid canonical table path in any registered dialect`}function i(o,s){const a=r(o);if(a!==void 0)throw new Error(`${s}: ${a}`)}return md}var yn={},l8;function KE(){if(l8)return yn;l8=1;var e=yn&&yn.__createBinding||(Object.create?(function(w,N,I,k){k===void 0&&(k=I);var $=Object.getOwnPropertyDescriptor(N,I);(!$||("get"in $?!N.__esModule:$.writable||$.configurable))&&($={enumerable:!0,get:function(){return N[I]}}),Object.defineProperty(w,k,$)}):(function(w,N,I,k){k===void 0&&(k=I),w[k]=N[I]})),t=yn&&yn.__setModuleDefault||(Object.create?(function(w,N){Object.defineProperty(w,"default",{enumerable:!0,value:N})}):function(w,N){w.default=N}),r=yn&&yn.__importStar||(function(){var w=function(N){return w=Object.getOwnPropertyNames||function(I){var k=[];for(var $ in I)Object.prototype.hasOwnProperty.call(I,$)&&(k[k.length]=$);return k},w(N)};return function(N){if(N&&N.__esModule)return N;var I={};if(N!=null)for(var k=w(N),$=0;$<k.length;$++)k[$]!=="default"&&e(I,N,k[$]);return t(I,N),I}})();Object.defineProperty(yn,"__esModule",{value:!0}),yn.sourceDefToSourceInfo=l,yn.modelDefToModelInfo=u,yn.toStableAnnotations=c,yn.convertFieldInfos=h,yn.writeLiteralToTag=m,yn.getResultStructMetadataAnnotation=v;const i=r(dA()),o=jr(),s=x0(),a=za();function l(w){const N=w.parameters&&Object.entries(w.parameters).length>0?Object.entries(w.parameters).map(([k,$])=>(0,o.isAtomic)($)?{name:k,type:S($),default_value:d($.value)}:{name:k,type:{kind:"filter_expression_type",filter_type:{kind:`${$.filterType}_type`}},default_value:d($.value)}):void 0;return{name:(0,o.activeName)(w),schema:{fields:h(w,w.fields)},parameters:N,annotations:c(w.annotations)}}function u(w){const N={entries:[],anonymous_queries:[]};for(const[I,k]of Object.entries(w.contents))if(w.exports.includes(I)){if((0,o.isSourceDef)(k)){const $=l(k);N.entries.push({kind:"source",...$})}else if(k.type==="query"){const $=(0,o.getResultStructDefForQuery)(w,k),J=c(k.annotations),re=$.resultMetadata?v($,$.resultMetadata):void 0,ie=[...J??[],...re?[re]:[]],oe={kind:"source",name:I,schema:{fields:h($,$.fields)},annotations:ie.length>0?ie:void 0};N.entries.push(oe)}}for(const I of w.queryList){const k=(0,o.getResultStructDefForQuery)(w,I),$=c(I.annotations),J=k.resultMetadata?v(k,k.resultMetadata):void 0,re=[...$??[],...J?[J]:[]],ie={schema:{fields:h(k,k.fields)},annotations:re.length>0?re:void 0};N.anonymous_queries.push(ie)}return N}function d(w){if(w!==null)switch(w.node){case"numberLiteral":return{kind:"number_literal",number_value:parseFloat(w.literal)};case"stringLiteral":return{kind:"string_literal",string_value:w.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:w.filterSrc};case"dateLiteral":return{kind:"date_literal",date_value:w.literal};case"timestampLiteral":case"timestamptzLiteral":return{kind:"timestamp_literal",timestamp_value:w.literal,timezone:w.timezone};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"null":return{kind:"null_literal"};default:throw new Error("Invalid parameter default value")}}function c(w){return new s.Annotations(w).texts().map(N=>({value:N}))}function h(w,N){const I=[];for(const k of N){if(!(k.accessModifier===void 0))continue;const J=c(k.annotations),re=J.length>0?J:void 0;if((0,o.isTurtle)(k)){const ie=(0,o.getResultStructDefForView)(w,k),oe=ie.resultMetadata?v(ie,ie.resultMetadata):void 0,U=[...re??[],...oe?[oe]:[]],ee={kind:"view",name:(0,o.activeName)(k),annotations:U.length>0?U:void 0,schema:{fields:h(ie,ie.fields)}};I.push(ee)}else if((0,o.isAtomic)(k)){const ie=(0,o.expressionIsAggregate)(k.expressionType),oe=(0,o.expressionIsScalar)(k.expressionType);if(!ie&&!oe||k.type==="error")continue;const U=k.resultMetadata?f(k,k.resultMetadata):void 0;let ee;if((0,o.isRecordOrRepeatedRecord)(k)&&k.queryTimezone){const q=a.Tag.withPrefix("#(malloy) ");q.set(["query_timezone"],k.queryTimezone),ee={value:q.toString()}}const K=[...re??[],...U?[U]:[],...ee?[ee]:[]],te={kind:ie?"measure":"dimension",name:(0,o.activeName)(k),type:S(k),annotations:K.length>0?K:void 0};I.push(te)}else if((0,o.isJoinedSource)(k)){const ie={kind:"join",name:(0,o.activeName)(k),annotations:re,schema:{fields:h(k,k.fields)},relationship:k.join};I.push(ie)}}return I}function f(w,N){const I=a.Tag.withPrefix("#(malloy) ");let k=!1;if(N.referenceId!==void 0&&(I.set(["reference_id"],N.referenceId),k=!0),N.fieldKind==="measure"&&(I.set(["calculation"]),k=!0),N.drillable&&(I.set(["drillable"]),k=!0),N.filterList&&(p(I,N.filterList),k=!0),N.drillExpression&&(x(I,["drill_expression"],N.drillExpression),k=!0),N.fieldKind==="dimension"){const J=N?.sourceExpression||(N?.sourceField.includes(".")?N?.sourceField:E(w.name));I.set(["drill_expression","code"],J),k=!0}return k?{value:I.toString()}:void 0}function p(w,N){for(let I=0;I<N.length;I++){const k=N[I];k.expressionType!=="scalar"||k.isSourceFilter||(w.set(["drill_filters",I,"code"],k.code),k.filterView&&w.set(["drill_filters",I,"filter_view"],k.filterView),k.filterView===void 0&&k.stableFilter!==void 0&&(x(w,["drill_filters",I,"expression"],k.stableFilter.expression),k.stableFilter.kind==="filter_string"?(w.set(["drill_filters",I,"kind"],"filter_expression"),w.set(["drill_filters",I,"filter_expression"],k.stableFilter.filter)):(w.set(["drill_filters",I,"kind"],"literal_equality"),m(w,["drill_filters",I,"value"],k.stableFilter.value))))}}function x(w,N,I){D(w,N,I,"Expression")}function m(w,N,I){D(w,N,I,"LiteralValue")}function g(w){return w.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}function E(w){return w.match(/^[A-Za-z_][0-9A-Za-z_]*$/)?w:`\`${g(w)}\``}function v(w,N){var I;const k=a.Tag.withPrefix("#(malloy) ");let $=!1;if(N.limit!==void 0&&(k.set(["limit"],N.limit),$=!0),N.filterList&&(p(k,N.filterList),$=!0),N.drillable&&(k.set(["drillable"]),$=!0),N.orderBy){for(let J=0;J<N.orderBy.length;J++){const re=N.orderBy[J],ie=typeof re.field=="number"?(0,o.activeName)(w.fields[re.field-1]):re.field,oe=(I=re.dir)!==null&&I!==void 0?I:null;k.set(["ordered_by",J,ie],oe)}$=!0}return w.queryTimezone&&(k.set(["query_timezone"],w.queryTimezone),$=!0),$?{value:k.toString()}:void 0}function S(w){if((0,o.isBasicAtomic)(w))switch(w.type){case"string":return{kind:"string_type"};case"number":return{kind:"number_type",subtype:w.numberType==="float"?"decimal":w.numberType==="integer"?"integer":w.numberType==="bigint"?"bigint":void 0};case"boolean":return{kind:"boolean_type"};case"date":{const N=w.timeframe;return N&&!T(N)?{kind:"timestamp_type",timeframe:w.timeframe}:{kind:"date_type",timeframe:b(w.timeframe)}}case"timestamp":return{kind:"timestamp_type",timeframe:w.timeframe};case"timestamptz":return{kind:"timestamptz_type",timeframe:w.timeframe};case"json":return{kind:"json_type"};case"sql native":return{kind:"sql_native_type",sql_type:w.rawType};case"error":throw new Error("Error type is not supported in stable interface")}else{if((0,o.isRepeatedRecord)(w))return{kind:"array_type",element_type:C(w)};if(w.type==="record")return C(w);if(w.type==="array")return{kind:"array_type",element_type:S(w.elementTypeDef)}}throw new Error("Unexpected field type")}function C(w){return{kind:"record_type",fields:w.fields.map(N=>{const I=[];if("resultMetadata"in N&&N.resultMetadata){const k=f(N,N.resultMetadata);k&&I.push(k)}if(N.annotations&&I.push(...c(N.annotations)),(0,o.isAtomic)(N))return{name:N.name,annotations:I.length>0?I:void 0,type:S(N)};throw new Error("Expected record type to not have a table as its child")})}}function T(w){switch(w){case"day":case"week":case"month":case"year":case"quarter":return!0;default:return!1}}function b(w){switch(w){case void 0:return;case"day":case"week":case"month":case"year":case"quarter":return w;default:throw new Error(`Invalid date timeframe ${w}`)}}function _(w){return w}function R(w){return w}function D(w,N,I,k){if(k==="string"){w.set(N,I);return}else if(k==="number"){w.set(N,I);return}else if(k==="boolean"){w.set(N,I.toString());return}const $=i.MALLOY_INTERFACE_TYPES[k];if($===void 0)throw new Error(`Unknown Malloy interface type ${k}`);if($.type==="enum")if(typeof I=="string")w.set(N,I);else throw new Error(`Expected string for enum ${k}`);else if($.type==="struct")for(const J in $.fields){const re=$.fields[J],ie=I[J];if(ie===void 0){if(!re.optional)throw new Error(`Mising value for non-optional field ${J} in type ${k}`)}else if(re.array)if(Array.isArray(ie))for(let oe=0;oe<ie.length;oe++)D(w,[...N,J,oe],ie[oe],re.type);else throw new Error(`Expected array for field ${J} of type ${k} but got ${typeof I}`);else D(w,[...N,J],ie,re.type)}else{const J=I.kind;w.set([...N,"kind"],J);const re=$.options[J];if(re===void 0)throw new Error(`Unknown Malloy interface union kind ${J} for type ${k}`);D(w,N,I,re)}}return yn}var c8;function X2(){return c8||(c8=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_LOG_RANGE=void 0,e.wrapLegacyInfoConnection=o,e.wrapLegacyConnection=s,e.mapData=a,e.wrapResult=l,e.nodeToLiteralValue=u,e.mapLogs=d;const t=YE(),r=KE(),i=w2();function o(c){return{get dialectName(){return c.dialectName},async fetchSchemaForSQLQuery(h){const f=await c.fetchSchemaForSQLStruct({connection:c.name,selectStr:h},{}),p=f.structDef;if(p===void 0)throw new Error(f.error);return{fields:(0,r.convertFieldInfos)(p,p.fields)}},async fetchSchemaForTable(h){const f=(0,t.validateCanonicalTablePath)(c.dialectName,h);if(f!==void 0)throw new Error(f);const p=`${c.name}:${h}`,x=await c.fetchSchemaForTables({[p]:h},{}),m=x.schemas[p];if(m===void 0)throw new Error(x.errors[p]);return{fields:(0,r.convertFieldInfos)(m,m.fields)}}}}function s(c){return{...o(c),runSQL:async(h,f)=>{const p=await c.runSQL(h);return a(p.rows,f)}}}function a(c,h){function f(m,g){if(m===null)return{kind:"null_cell"};if(g.type.kind==="date_type"||g.type.kind==="timestamp_type"||g.type.kind==="timestamptz_type"){const E=(0,i.rowDataToDate)(m).toISOString();return g.type.kind==="date_type"?{kind:"date_cell",date_value:E}:{kind:"timestamp_cell",timestamp_value:E}}else if(g.type.kind==="boolean_type"){if(typeof m=="number"||typeof m=="bigint")return{kind:"boolean_cell",boolean_value:m!==0};if(typeof m=="string")return{kind:"boolean_cell",boolean_value:m!=="0"&&m!==""};if(typeof m!="boolean")throw new Error(`Invalid boolean ${m}`);return{kind:"boolean_cell",boolean_value:m}}else if(g.type.kind==="number_type"){const E=g.type.subtype,v=E==="bigint"?(0,i.rowDataToSerializedBigint)(m):void 0;return{kind:"number_cell",number_value:(0,i.rowDataToNumber)(m),subtype:E,string_value:v}}else if(g.type.kind==="string_type"){if(typeof m!="string")throw new Error(`Invalid string ${m}`);return{kind:"string_cell",string_value:m}}else if(g.type.kind==="array_type"){if(!Array.isArray(m))throw new Error(`Invalid array ${m}`);return{kind:"array_cell",array_value:m.map(E=>f(E,{name:"array_element",type:g.type.element_type}))}}else{if(g.type.kind==="json_type")return{kind:"json_cell",json_value:JSON.stringify(m)};if(g.type.kind==="sql_native_type")return{kind:"sql_native_cell",sql_native_value:JSON.stringify(m)};{const E=g.type;if(E.kind!=="record_type")throw new Error(`Invalid record in result ${JSON.stringify(g)}, ${JSON.stringify(m)}`);return p(m,{schema:{fields:E.fields.map(v=>({kind:"dimension",...v}))}})}}}function p(m,g){const E=[];for(const v of g.schema.fields){const S=m[v.name];if(v.kind!=="dimension")throw new Error("Invalid result -- expected all fields to be dimensions");const C=f(S,v);E.push(C)}return{kind:"record_cell",record_value:E}}const x={schema:h};return{kind:"array_cell",array_value:c.map(m=>p(m,x))}}function l(c){const h=c._queryResult.structs,f=h[h.length-1],p={fields:(0,r.convertFieldInfos)(f,f.fields)};return c.toStableResult(a(c.data.rawData,p))}function u(c){switch(c?.node){case"numberLiteral":return{kind:"number_literal",number_value:Number.parseFloat(c.literal)};case"null":return{kind:"null_literal"};case"stringLiteral":return{kind:"string_literal",string_value:c.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:c.filterSrc};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"dateLiteral":return{kind:"date_literal",date_value:c.literal,granularity:c.typeDef.timeframe};case"timestampLiteral":case"timestamptzLiteral":return{kind:"timestamp_literal",timestamp_value:c.literal,timezone:c.timezone,granularity:c.typeDef.timeframe};default:return}}e.DEFAULT_LOG_RANGE={start:{line:0,character:0},end:{line:0,character:0}};function d(c,h){return c.map(f=>{var p,x,m,g;return{severity:f.severity,message:f.message,range:(x=(p=f.at)===null||p===void 0?void 0:p.range)!==null&&x!==void 0?x:e.DEFAULT_LOG_RANGE,url:(g=(m=f.at)===null||m===void 0?void 0:m.url)!==null&&g!==void 0?g:h}})}})(iS)),iS}var d8;function pz(){if(d8)return ri;d8=1;var e=ri&&ri.__createBinding||(Object.create?(function(g,E,v,S){S===void 0&&(S=v);var C=Object.getOwnPropertyDescriptor(E,v);(!C||("get"in C?!E.__esModule:C.writable||C.configurable))&&(C={enumerable:!0,get:function(){return E[v]}}),Object.defineProperty(g,S,C)}):(function(g,E,v,S){S===void 0&&(S=v),g[S]=E[v]})),t=ri&&ri.__setModuleDefault||(Object.create?(function(g,E){Object.defineProperty(g,"default",{enumerable:!0,value:E})}):function(g,E){g.default=E}),r=ri&&ri.__importStar||(function(){var g=function(E){return g=Object.getOwnPropertyNames||function(v){var S=[];for(var C in v)Object.prototype.hasOwnProperty.call(v,C)&&(S[S.length]=C);return S},g(E)};return function(E){if(E&&E.__esModule)return E;var v={};if(E!=null)for(var S=g(E),C=0;C<S.length;C++)S[C]!=="default"&&e(v,E,S[C]);return t(v,E),v}})();Object.defineProperty(ri,"__esModule",{value:!0}),ri.MalloyToQuery=void 0,ri.malloyToQuery=m;const i=K2(),o=hT(),s=r(V2()),a=D2(),l=Y2(),u=Ge(),d=XP(),c=xs(),h=X2(),f=H1(),p="Malloy query documents";class x extends o.AbstractParseTreeVisitor{constructor(E,v){super(),this.parseInfo=E,this.msgLog=v}internalError(E,v){return this.contextError(E,"internal-translator-error",{message:v}),new Error(`Internal Translator Error: ${v}`)}getLocation(E){return{url:this.parseInfo.sourceURL,range:(0,c.rangeFromContext)(this.parseInfo.sourceInfo,E)}}contextError(E,v,S,C){this.msgLog.log((0,a.makeLogMessage)(v,S,{at:this.getLocation(E),...C}))}getNumber(E){return Number.parseInt(E.text)}defaultResult(){return null}getAnnotations(E){const v=E.annotation().map(S=>({value:(0,l.getAnnotationText)(S)}));return v.length>0?v:void 0}getIsAnnotations(E){var v,S;if(E===void 0)return;const T=((v=this.getAnnotations(E._beforeIs))!==null&&v!==void 0?v:[]).concat((S=this.getAnnotations(E._afterIs))!==null&&S!==void 0?S:[]);return T.length>0?T:void 0}notAllowed(E,v){this.illegal(E,`${v} are not allowed in ${p}`)}illegal(E,v){this.contextError(E,"invalid-malloy-query-document",v)}visitMalloyDocument(E){const v=E.malloyStatement();let S;for(const C of v)C.defineSourceStatement()?this.notAllowed(C,"Source definitions"):C.defineQuery()?this.notAllowed(C,"Query definitions"):C.importStatement()?this.notAllowed(C,"Import statements"):C.docAnnotations()?this.notAllowed(C,"Model annotations"):C.ignoredObjectAnnotations()?this.notAllowed(C,"Detatched object annotations"):C.experimentalStatementForTesting()?this.notAllowed(C,"Experimental testing statements"):S===void 0?S=C.runStatement():this.illegal(C,`${p} may only have one run statement`);return S===void 0?(this.illegal(E,`${p} must have a run statement`),null):this.visitRunStatement(S)}visitRunStatement(E){const v=E.topLevelAnonQueryDef(),S=this.getQueryDefinition(v.sqExpr()),C=this.getAnnotations(E.tags()),T=this.getAnnotations(E.topLevelAnonQueryDef().tags()),b=this.combineAnnotations(C,T);return S!==null?{annotations:b,definition:S}:null}getSourceArguments(E){const v=[];for(const S of E.sourceArgument()){const C=S.argumentId();if(C===void 0)return this.contextError(S,"unnamed-source-argument","Source argument must be named"),null;const T=(0,l.getId)(C),b=this.getLiteralIncludingNegativeNumber(S.fieldExpr());if(b===null)return null;v.push({name:T,value:b})}return v}getQueryReference(E){const v=E.sourceArguments(),S=(0,l.getId)(E);if(v){const C=this.getSourceArguments(v);return C===null?null:{name:S,parameters:C}}else return{name:S}}getQueryDefinition(E){if(E instanceof s.SQIDContext){const v=this.getQueryReference(E);if(v!==null)return{kind:"query_reference",...v}}else{if(E instanceof s.SQParensContext)return this.getQueryDefinition(E.sqExpr());if(E instanceof s.SQComposeContext)this.notAllowed(E,"Source compositions");else if(E instanceof s.SQRefinedQueryContext){const v=E.sqExpr(),S=this.getQueryDefinition(v),C=this.getRefinementSegment(E.segExpr());return C===null||S===null?null:(C.kind==="arrow"&&this.notAllowed(E,"Queries against refined queries"),{kind:"refinement",base:S,refinement:C})}else if(E instanceof s.SQExtendedSourceContext)this.notAllowed(E,"Source extensions");else if(E instanceof s.SQIncludeContext)this.notAllowed(E,"Source inclusions");else if(E instanceof s.SQTableContext)this.notAllowed(E,"Table statements");else if(E instanceof s.SQSQLContext)this.notAllowed(E,"SQL statements");else if(E instanceof s.SQArrowContext){const v=E.sqExpr(),S=this.getQueryDefinition(v),C=this.getRefinementSegment(E.segExpr());return C===null||S===null?null:S.kind==="query_reference"?{kind:"arrow",source:{...S,kind:"source_reference"},view:C}:S.kind==="arrow"?{kind:"arrow",source:S.source,view:{kind:"arrow",source:S.view,view:C}}:{kind:"arrow",source:S,view:C}}}return null}getRefinementSegment(E){if(E instanceof s.SegOpsContext){const v=E.queryProperties().queryStatement().flatMap(S=>this.getSegmentOperation(S));return v.some(S=>S===null)?null:{kind:"segment",operations:v}}else if(E instanceof s.SegFieldContext){const{name:v,path:S}=this.getFieldPath(E.fieldPath());return{kind:"view_reference",name:v,path:S}}else{if(E instanceof s.SegParenContext)return this.getViewExpression(E.vExpr());if(E instanceof s.SegRefineContext){const v=this.getRefinementSegment(E._lhs),S=this.getRefinementSegment(E._rhs);return v===null||S===null?null:{kind:"refinement",base:v,refinement:S}}}return null}getGroupByStatement(E){const v=this.getAnnotations(E.tags()),C=E.queryFieldList().queryFieldEntry().map(T=>this.getQueryField(T));return C.some(T=>T===null)||C===null?null:C.map(T=>{var b;const _=[...v??[],...(b=T.field.annotations)!==null&&b!==void 0?b:[]];return{kind:"group_by",name:T.name,field:{...T.field,annotations:_.length>0?_:void 0}}})}getAggregateStatement(E){const v=this.getAnnotations(E.tags()),C=E.queryFieldList().queryFieldEntry().map(T=>this.getQueryField(T));return C.some(T=>T===null)||C===null?null:C.map(T=>{var b;const _=[...v??[],...(b=T.field.annotations)!==null&&b!==void 0?b:[]];return{kind:"aggregate",name:T.name,field:{...T.field,annotations:_.length>0?_:void 0}}})}getOrderByStatement(E){var v,S;const C=E.ordering().orderBySpec(),T=[];for(const b of C){if(b.INTEGER_LITERAL()){this.notAllowed(b,"Indexed order by statements");continue}const _=(S=(v=b.possibleBadPath())===null||v===void 0?void 0:v.badWord())!==null&&S!==void 0?S:[],R=_.length===1?_[0].fieldName():void 0;if(!R)return null;const D=(0,l.getId)(R),w=b.ASC()?"asc":b.DESC()?"desc":void 0;T.push({kind:"order_by",direction:w,field_reference:{name:D}})}return T}getNestStatement(E){const v=this.getAnnotations(E.tags()),S=E.nestedQueryList().nestEntry(),C=[];for(const T of S){if(!(T instanceof s.NestDefContext))return this.internalError(T,"Expected nestDef"),null;const b=this.getAnnotations(T.tags()),_=this.getIsAnnotations(T.isDefine()),R=T.queryName(),D=R?(0,l.getId)(R):void 0,w=this.getViewExpression(T.vExpr());if(w===null)return null;C.push({kind:"nest",name:D,view:{definition:w,annotations:this.combineAnnotations(v,b,_)}})}return C}getViewExpression(E){if(E instanceof s.VSegContext)return this.getRefinementSegment(E.segExpr());if(E instanceof s.VArrowContext){const v=this.getRefinementSegment(E),S=this.getViewExpression(E._rhs);return v===null||S===null?null:{kind:"arrow",source:v,view:S}}else return this.internalError(E,"Unexpected VExpr node"),null}getLimitStatement(E){return{kind:"limit",limit:this.getNumber(E.INTEGER_LITERAL())}}getSegmentOperation(E){if(E.groupByStatement()){const v=E.groupByStatement();return this.getGroupByStatement(v)}else if(E.aggregateStatement()){const v=E.aggregateStatement();return this.getAggregateStatement(v)}else if(E.limitStatement()){const v=E.limitStatement(),S=this.getLimitStatement(v);return S===null?null:[S]}else if(E.declareStatement())this.notAllowed(E,"Declare statements");else if(E.queryJoinStatement())this.notAllowed(E,"Query join statements");else if(E.queryExtend())this.notAllowed(E,"Query extend statements");else if(E.projectStatement())this.notAllowed(E,"Select statements");else if(E.indexStatement())this.notAllowed(E,"Index statements");else if(E.calculateStatement())this.notAllowed(E,"Calculate statements");else if(E.topStatement())this.notAllowed(E,"Top statements");else if(E.orderByStatement()){const v=E.orderByStatement();return this.getOrderByStatement(v)}else if(E.whereStatement()){const v=E.whereStatement(),S=this.getWhere(v);return S===null?null:S.map(C=>({kind:"where",...C}))}else if(E.drillStatement()){const v=E.drillStatement(),S=this.getDrill(v);return S===null?null:S.map(C=>({kind:"drill",...C}))}else if(E.havingStatement()){const v=E.havingStatement(),S=this.getHaving(v);return S===null?null:S.map(C=>({kind:"having",...C}))}else if(E.nestStatement()){const v=E.nestStatement();return this.getNestStatement(v)}else E.sampleStatement()?this.notAllowed(E,"Sample statements"):E.timezoneStatement()?this.notAllowed(E,"Timezone statements"):(E.queryAnnotation()||E.ignoredModelAnnotations())&&this.notAllowed(E,"Detached annotation statements");return null}getFieldPath(E){const v=E.fieldName().map(T=>(0,l.getId)(T)),S=v[v.length-1],C=v.slice(0,-1);return{name:S,path:C.length>0?C:void 0}}getTimeframe(E){const v=E.text;return(0,u.isTimestampUnit)(v)?v:(this.illegal(E,`Invalid timeframe ${v}`),null)}getQueryField(E){if(E.taggedRef()){const v=E.taggedRef(),S=this.getAnnotations(v.tags()),{name:C,path:T}=this.getFieldPath(v.fieldPath());if(v.refExpr()){const b=v.refExpr();if(b.timeframe()){const _=this.getTimeframe(b.timeframe());return _===null?null:{name:void 0,field:{annotations:S,expression:{kind:"time_truncation",field_reference:{name:C,path:T},truncation:_}}}}else b.aggregate()&&this.notAllowed(b,"Aggregate expressions")}else return{name:void 0,field:{annotations:S,expression:{kind:"field_reference",name:C,path:T}}}}else if(E.fieldDef()){const v=E.fieldDef(),S=this.getAnnotations(v.tags()),C=this.getIsAnnotations(v.isDefine()),T=(0,l.getId)(v.fieldNameDef()),b=this.getFieldExpression(v.fieldExpr());return b===null?null:{name:T,field:{expression:b,annotations:this.combineAnnotations(S,C)}}}return null}getFieldExpression(E){if(E instanceof s.ExprFieldPathContext){const{name:v,path:S}=this.getFieldPath(E.fieldPath());return{kind:"field_reference",name:v,path:S}}else if(E instanceof s.ExprTimeTruncContext){const v=this.getTimeframe(E.timeframe()),S=E.fieldExpr(),C=this.getFieldExpression(S);return C===null||v===null?null:C.kind!=="field_reference"?(this.illegal(S,"Left hand side of time truncation must be a field reference"),null):{kind:"time_truncation",truncation:v,field_reference:{name:C.name,path:C.path,parameters:C.parameters}}}else if(E instanceof s.ExprFieldPropsContext){const v=E.fieldExpr(),S=this.getFieldExpression(v);if(S===null)return null;if(S.kind!=="field_reference")return this.illegal(v,"Left hand side of filtered field must be a field reference"),null;const C=E.fieldProperties().fieldPropertyStatement(),T=[];for(const b of C){const _=b.whereStatement();if(_){const R=this.getWhere(_);if(R===null)return null;T.push(...R)}}return{kind:"filtered_field",field_reference:{name:S.name,path:S.path,parameters:S.parameters},where:T}}else{const v=this.getLiteralIncludingNegativeNumber(E);return v===null?null:{kind:"literal_value",literal_value:v}}}stripQuote(E,v){return E.slice(E.indexOf(v)+v.length,E.lastIndexOf(v))}getFilterString(E){const v=E.tripFilterString(),S=E.tickFilterString();if(v){const C=v.BQ3_FILTER(),T=v.DQ3_FILTER(),b=v.SQ3_FILTER();if(C)return this.stripQuote(C.text,"```");if(T)return this.stripQuote(T.text,'"""');if(b)return this.stripQuote(b.text,"'''")}else if(S){const C=S.BQ_FILTER(),T=S.DQ_FILTER(),b=S.SQ_FILTER();if(C)return this.stripQuote(C.text,"`");if(T)return this.stripQuote(T.text,'"');if(b)return this.stripQuote(b.text,"'")}return null}getFilterExpr(E){if(E instanceof s.ExprCompareContext){if(E.compareOp().MATCH()){const v=E.fieldExpr()[0],S=E.fieldExpr()[1];if(v instanceof s.ExprFieldPathContext&&S instanceof s.ExprLiteralContext){const{path:C,name:T}=this.getFieldPath(v.fieldPath()),b=S.literal();if(b instanceof s.FilterString_stubContext){const _=this.getFilterString(b.filterString());return _===null?null:{filter:{kind:"filter_string",expression:{kind:"field_reference",name:T,path:C},filter:_}}}}}else if(E.compareOp().EQ()){const v=E.fieldExpr()[0],S=E.fieldExpr()[1];if(v instanceof s.ExprFieldPathContext){const{path:C,name:T}=this.getFieldPath(v.fieldPath()),b=this.getLiteralIncludingNegativeNumber(S);return b===null?(this.notAllowed(E,"Filters other than comparisons with filter strings or equality with literals"),null):{filter:{kind:"literal_equality",expression:{kind:"field_reference",name:T,path:C},value:b}}}}}return this.notAllowed(E,"Filters other than comparisons with filter strings or equality with literals"),null}getTimeLiteral(E,v){const S=v(E.text);if(!S)return this.contextError(E,"failed-to-parse-time-literal","Time data parse error"),null;const C=S.getValue(),T=C.timeframe,b=C.value;return(0,u.isTimeLiteral)(b)?b.node==="dateLiteral"?T==="hour"||T==="minute"||T==="second"?null:{kind:"date_literal",date_value:b.literal,granularity:T}:{kind:"timestamp_literal",timestamp_value:b.literal,granularity:T,timezone:b.timezone}:null}getLiteralIncludingNegativeNumber(E){if(E instanceof s.ExprLiteralContext)return this.getLiteral(E.literal());if(E instanceof s.ExprMinusContext){const v=E.fieldExpr();if(v instanceof s.ExprLiteralContext){const S=this.getLiteral(v.literal());return S===null||S.kind!=="number_literal"?null:{kind:"number_literal",number_value:-S.number_value}}}return null}getLiteral(E){if(E instanceof s.ExprTimeContext){const v=E.dateLiteral();return v instanceof s.LiteralTimestampContext?this.getTimeLiteral(v,f.LiteralTimestamp.parse):v instanceof s.LiteralHourContext?this.getTimeLiteral(v,f.LiteralHour.parse):v instanceof s.LiteralDayContext?this.getTimeLiteral(v,f.LiteralDay.parse):v instanceof s.LiteralWeekContext?this.getTimeLiteral(v,f.LiteralWeek.parse):v instanceof s.LiteralMonthContext?this.getTimeLiteral(v,f.LiteralMonth.parse):v instanceof s.LiteralQuarterContext?this.getTimeLiteral(v,f.LiteralQuarter.parse):v instanceof s.LiteralYearContext?this.getTimeLiteral(v,f.LiteralYear.parse):null}else{if(E instanceof s.ExprArrayLiteralContext)return this.notAllowed(E,"array literals"),null;if(E instanceof s.ExprLiteralRecordContext)return this.notAllowed(E,"record literals"),null;if(E instanceof s.ExprStringContext){const[v,S]=(0,l.getPlainString)(E);for(const C of S)C instanceof i.ParserRuleContext&&this.contextError(C,"illegal-query-interpolation-outside-sql-block","%{ query } illegal in this string");return{kind:"string_literal",string_value:v??""}}else{if(E instanceof s.ExprBoolContext)return{kind:"boolean_literal",boolean_value:E.TRUE()!==null};if(E instanceof s.ExprNumberContext)return{kind:"number_literal",number_value:Number(E.text)};if(E instanceof s.ExprNULLContext)return{kind:"null_literal"};if(E instanceof s.FilterString_stubContext){const v=E.getChild(0);if(v instanceof s.FilterStringContext){const S=this.getFilterString(v);if(S)return{kind:"filter_expression_literal",filter_expression_value:S}}}}}return null}getDrill(E){const S=E.drillClauseList().fieldExpr().map(C=>this.getFilterExpr(C));return S.some(C=>C===null)?null:S}getWhere(E){const S=E.filterClauseList().fieldExpr().map(C=>this.getFilterExpr(C));return S.some(C=>C===null)?null:S}getHaving(E){const S=E.filterClauseList().fieldExpr().map(C=>this.getFilterExpr(C));return S.some(C=>C===null)?null:S}combineAnnotations(...E){const v=E.flatMap(S=>S??[]);return v.length>0?v:void 0}}ri.MalloyToQuery=x;function m(g){const E=(0,c.getSourceInfo)(g),v=new a.BaseMessageLogger(null),S="internal://query.malloy",C=(0,d.runMalloyParser)(g,S,E,v),b=new x(C,v).visit(C.root),_=(0,h.mapLogs)(v.getLog(),S);if(b===null)return{logs:_};if(!("definition"in b))throw new Error("Expected a query");return{query:b,logs:_}}return ri}var x8;function pT(){return x8||(x8=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.malloyToQuery=e.exploreQueryWalkerBuilder=e.MalloyTranslation=e.MalloyTranslator=void 0;var t=fz();Object.defineProperty(e,"MalloyTranslator",{enumerable:!0,get:function(){return t.MalloyTranslator}}),Object.defineProperty(e,"MalloyTranslation",{enumerable:!0,get:function(){return t.MalloyTranslation}});var r=hz();Object.defineProperty(e,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return r.exploreQueryWalkerBuilder}});var i=pz();Object.defineProperty(e,"malloyToQuery",{enumerable:!0,get:function(){return i.malloyToQuery}})})(uv)),uv}var sS={},Tm={},f8;function mz(){return f8||(f8=1,Object.defineProperty(Tm,"__esModule",{value:!0}),Tm.EMPTY_BUILD_MANIFEST=void 0,Tm.EMPTY_BUILD_MANIFEST=Object.freeze({entries:Object.freeze({}),strict:!1})),Tm}var jn={},h8;function JE(){if(h8)return jn;h8=1,Object.defineProperty(jn,"__esModule",{value:!0}),jn.FixedConnectionMap=jn.InMemoryURLReader=jn.EmptyURLReader=void 0,jn.hashForInvalidationKey=t,jn.isInternalURL=r,jn.readURL=i,jn.getInvalidationKey=o;const e=_0();function t(u){return(0,e.v5)(u,"76c17e9d-f3ce-5f2d-bfde-98ad3d2a37f6")}function r(u){return u.startsWith("internal://")}async function i(u,d){const c=await u.readURL(d),{contents:h,invalidationKey:f}=typeof c=="string"?{contents:c,invalidationKey:void 0}:c;return{contents:h,invalidationKey:r(d.toString())?null:f??t(h)}}async function o(u,d){return r(d.toString())?null:u.getInvalidationKey!==void 0?await u.getInvalidationKey(d):(await i(u,d)).invalidationKey}class s{async readURL(d){throw new Error("No files.")}async getInvalidationKey(d){throw new Error("No files.")}}jn.EmptyURLReader=s;class a{constructor(d){this.files=d}async readURL(d){const c=this.files.get(d.toString());if(c!==void 0)return Promise.resolve({contents:c,invalidationKey:this.invalidationKey(d,c)});throw new Error(`File not found '${d}'`)}async getInvalidationKey(d){const c=this.files.get(d.toString());if(c!==void 0)return Promise.resolve(this.invalidationKey(d,c));throw new Error(`File not found '${d}'`)}invalidationKey(d,c){return r(d.toString())?null:t(c)}}jn.InMemoryURLReader=a;class l{constructor(d,c){this.connections=d,this.defaultConnectionName=c}async getConnection(d){if(d===void 0)if(this.defaultConnectionName!==void 0)d=this.defaultConnectionName;else throw new Error("No default connection.");const c=this.connections.get(d);if(c!==void 0)return Promise.resolve(c);throw new Error(`No connection found with name ${d}.`)}listConnections(){return Array.from(this.connections.values())}async lookupConnection(d){return this.getConnection(d)}static fromArray(d){return new l(new Map(d.map(c=>[c.name,c])))}}return jn.FixedConnectionMap=l,jn}var Xc={},p8;function gz(){if(p8)return Xc;p8=1,Object.defineProperty(Xc,"__esModule",{value:!0}),Xc.InMemoryModelCache=Xc.CacheManager=void 0;const e=JE();class t{constructor(s){this.modelCache=s,this.modelDependencies=new Map,this.modelInvalidationKeys=new Map}async getCachedModelDef(s,a){const l=this.modelDependencies.get(a);if(l===void 0)return;const u=[a,...r(l)],d={};for(const h of u){const f=this.modelInvalidationKeys.get(h);if(f==null)return;d[h]=f}for(const h of u)if(await(0,e.getInvalidationKey)(s,new URL(h))!==d[h])return;const c=await this.modelCache.getModel(new URL(a));if(c!==void 0){for(const h of u)if(c.invalidationKeys[h]!==d[h])return;return{modelDef:c.modelDef,invalidationKeys:d}}}async setCachedModelDef(s,a){this.modelDependencies.set(s,a.modelDef.dependencies);const l={};for(const d of[s,...r(a.modelDef.dependencies)]){if(a.invalidationKeys[d]===null)return!1;if(a.invalidationKeys[d]===void 0)throw new Error(`Missing invalidation key for dependency ${d}`);this.modelInvalidationKeys.set(d,a.invalidationKeys[d]),l[d]=a.invalidationKeys[d]}return!!await this.modelCache.setModel(new URL(s),{modelDef:a.modelDef,invalidationKeys:l})}}Xc.CacheManager=t;function r(o){return[...Object.keys(o),...Object.values(o).map(r).flat()]}class i{constructor(){this.models=new Map}async getModel(s){return Promise.resolve(this.models.get(s.toString()))}async setModel(s,a){return this.models.set(s.toString(),a),Promise.resolve(!0)}}return Xc.InMemoryModelCache=i,Xc}var En={},m8;function ZP(){if(m8)return En;m8=1,Object.defineProperty(En,"__esModule",{value:!0}),En.DocumentCompletion=En.DocumentSymbol=En.DocumentPosition=En.DocumentRange=En.DocumentTablePath=En.Parse=void 0;class e{constructor(l,u){this.translator=l,this.invalidationKey=u}get symbols(){return(this.translator.metadata().symbols||[]).map(l=>new o(l))}get tablePathInfo(){var l;return((l=this.translator.tablePathInfo().pathInfo)!==null&&l!==void 0?l:[]).map(d=>new t(d))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(l){return(this.translator.completions(l).completions||[]).map(u=>new s(u))}helpContext(l){return this.translator.helpContext(l).helpContext}}En.Parse=e;class t{constructor(l){this._range=r.fromJSON(l.range),this._connectionId=l.connectionId,this._tablePath=l.tablePath}get range(){return this._range}get connectionId(){return this._connectionId}get tablePath(){return this._tablePath}}En.DocumentTablePath=t;class r{constructor(l,u){this._start=l,this._end=u}get start(){return this._start}get end(){return this._end}toJSON(){return{start:this.start.toJSON(),end:this.end.toJSON()}}static fromJSON(l){return new r(new i(l.start.line,l.start.character),new i(l.end.line,l.end.character))}}En.DocumentRange=r;class i{constructor(l,u){this._line=l,this._character=u}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}En.DocumentPosition=i;class o{constructor(l){this._range=r.fromJSON(l.range),this._lensRange=l.lensRange?r.fromJSON(l.lensRange):void 0,this._type=l.type,this._name=l.name,this._children=l.children.map(u=>new o(u))}get range(){return this._range}get lensRange(){var l;return(l=this._lensRange)!==null&&l!==void 0?l:this._range}get type(){return this._type}get name(){return this._name}get children(){return this._children}}En.DocumentSymbol=o;class s{constructor(l){this.type=l.type,this.text=l.text}}return En.DocumentCompletion=s,En}var vt={},g8;function XE(){if(g8)return vt;g8=1,Object.defineProperty(vt,"__esModule",{value:!0}),vt.PreparedResult=vt.PreparedQuery=vt.Given=vt.PersistSource=vt.Model=vt.Reference=vt.ExploreField=vt.QueryField=vt.Query=vt.StringField=vt.UnsupportedField=vt.JSONField=vt.BooleanField=vt.NumberField=vt.TimestampField=vt.DateField=vt.AtomicField=vt.Explore=vt.JoinRelationship=vt.TimestampTimeframe=vt.DateTimeframe=vt.AtomicFieldType=vt.SourceRelationship=void 0,vt.pseudoModelFor=x;const e=jr(),t=Zt(),r=Va(),i=AA(),o=Ks(),s=x9(),a=za(),l=x0(),u=KE(),d=X2(),c=xs(),h=JP();function f(Q){return Q.type==="table"||Q.type==="sql_select"||Q.type==="query_source"}const p="internal://generated-model";function x(Q,M=p,j={}){if(!(0,e.isSourceDef)(Q))throw new Error(`Cannot create pseudo model for struct type ${Q.type}`);const P=(0,t.mkModelDef)("generated_model",M);return P.modelAnnotations=j,P.contents[Q.name]=Q,P}class m{constructor(M,j,P){this._name=M,this._parent=j,this._source=P}get source(){return this._source}get name(){return this._name}get sourceClasses(){const M=[];return this.source&&M.push(this.source.name),M.push(this.name),M}get fieldPath(){const M=[this.name];let j=this._parent;for(;j;)M.unshift(j.name),j=j._parent;return M}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof T}isQuery(){return this instanceof J}}var g;(function(Q){Q.Nested="nested",Q.BaseTable="base_table",Q.Cross="cross",Q.One="one",Q.Many="many",Q.Inline="inline"})(g||(vt.SourceRelationship=g={}));var E;(function(Q){Q.String="string",Q.Number="number",Q.Boolean="boolean",Q.Date="date",Q.Timestamp="timestamp",Q.Timestamptz="timestamptz",Q.Json="json",Q.NativeUnsupported="sql native",Q.Error="error"})(E||(vt.AtomicFieldType=E={}));var v;(function(Q){Q.Day="day",Q.Week="week",Q.Month="month",Q.Quarter="quarter",Q.Year="year"})(v||(vt.DateTimeframe=v={}));var S;(function(Q){Q.Day="day",Q.Week="week",Q.Month="month",Q.Quarter="quarter",Q.Year="year",Q.Second="second",Q.Hour="hour",Q.Minute="minute"})(S||(vt.TimestampTimeframe=S={}));var C;(function(Q){Q.OneToOne="one_to_one",Q.OneToMany="one_to_many",Q.ManyToOne="many_to_one"})(C||(vt.JoinRelationship=C={}));class T extends m{constructor(M,j,P,V){super((0,e.activeName)(j),P,V),this._ownerModelDef=M,this._structDef=j,this._parentExplore=P,this.sourceExplore=V}get _modelDef(){return this._ownerModelDef}get source(){return this.sourceExplore}get referenceSourceID(){return(0,e.isSourceDef)(this._structDef)?this._structDef.referenceID:void 0}referencedSource(){if(!(0,e.isSourceDef)(this._structDef))return;const M=(0,o.sourceNamespaceReference)(this._ownerModelDef,this._structDef);return M?new T(this._ownerModelDef,M.source):void 0}isIntrinsic(){return(0,e.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(M){return(0,l.annotationToTag)(this._structDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this._structDef.annotations,M)}get annotations(){return new l.Annotations(this._structDef.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this._ownerModelDef))}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=this.modelAnnotations.parseAsTag().tag),this.parsedModelTag}get name(){return(0,e.activeName)(this.structDef)}getQueryByName(M){const j=this.sourceStructDef;if(!j)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const P=j.fields.find(Z=>(0,e.activeName)(Z)===M);if(P===void 0)throw new Error(`No such view named \`${M}\``);if(P.type!=="turtle")throw new Error(`\`${M}\` is not a view`);const V={type:"query",structRef:j,pipeline:P.pipeline};return new q(V,this.getSingleExploreModel(),[],M)}getSingleExploreModel(){return new U(this._ownerModelDef,[],[])}get fieldMap(){var M;if(this._fieldMap===void 0){const j=((M=this.source)===null||M===void 0?void 0:M.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(P=>{const V=(0,e.activeName)(P),Z=j.get(P.name);if((0,e.isJoined)(P))return[V,new re(P,this,Z)];if(P.type==="turtle")return[V,new J(P,this,Z)];if(P.type==="string")return[V,new k(P,this,Z)];if(P.type==="number")return[V,new D(P,this,Z)];if(P.type==="date")return P.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(P.timeframe)?[V,new D({...P,type:"number"},this,Z)]:[V,new _(P,this,Z)];if(P.type==="timestamp")return[V,new R(P,this,Z)];if(P.type==="timestamptz")return[V,new R(P,this,Z)];if(P.type==="boolean")return[V,new w(P,this,Z)];if(P.type==="json")return[V,new N(P,this,Z)];if(P.type==="sql native")return[V,new I(P,this,Z)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var M,j,P;if(!this._allFieldsWithOrder){const V=[...((P=(j=(M=this.sourceStructDef)===null||M===void 0?void 0:M.resultMetadata)===null||j===void 0?void 0:j.orderBy)===null||P===void 0?void 0:P.map(ae=>{if(typeof ae.field=="string")return{field:this.fieldMap.get(ae.field),dir:ae.dir};throw new Error("Does not support mapping order by from number.")}))||[]],Z=new Set(V.map(ae=>ae.field.name));this._allFieldsWithOrder=[...V,...this.allFields.filter(ae=>!Z.has(ae.name)).map(ae=>({field:ae,dir:"asc"}))]}return this._allFieldsWithOrder}get intrinsicFields(){return[...this.fieldMap.values()].filter(M=>M.isIntrinsic())}get dimensions(){return[...this.allFieldsWithOrder].filter(M=>M.field.isAtomicField()&&M.field.sourceWasDimension())}getFieldByName(M){const j=this.fieldMap.get(M);if(j===void 0)throw new Error(`No such field ${M}.`);return j}getFieldByNameIfExists(M){return this.fieldMap.get(M)}get primaryKey(){var M;return(M=this.sourceStructDef)===null||M===void 0?void 0:M.primaryKey}get parentExplore(){return this._parentExplore}hasParentExplore(){return this instanceof re}get filters(){var M;return(0,e.isSourceDef)(this.structDef)?((M=this.structDef.resultMetadata)===null||M===void 0?void 0:M.filterList)||[]:[]}get limit(){var M,j;return(j=(M=this.sourceStructDef)===null||M===void 0?void 0:M.resultMetadata)===null||j===void 0?void 0:j.limit}get structDef(){return this._structDef}get queryTimezone(){var M;return(M=this.sourceStructDef)===null||M===void 0?void 0:M.queryTimezone}get sourceStructDef(){if((0,e.isSourceDef)(this.structDef))return this.structDef}toJSON(){var M,j;return{_structDef:this._structDef,modelID:this._ownerModelDef.modelID,modelAnnotations:this._ownerModelDef.modelAnnotations,sourceExplore:(M=this.sourceExplore)===null||M===void 0?void 0:M.toJSON(),_parentExplore:(j=this._parentExplore)===null||j===void 0?void 0:j.toJSON()}}static fromJSON(M){const j=M._parentExplore!==void 0?T.fromJSON(M._parentExplore):void 0,P=M.sourceExplore!==void 0?T.fromJSON(M.sourceExplore):void 0;return new T(x(M._structDef,M.modelID,M.modelAnnotations),M._structDef,j,P)}get location(){return this.structDef.location}collectSourceComponents(M){const j=[];if(M.type==="composite"){for(const P of M.sources)j.push(...this.collectSourceComponents(P));return j}if(f(M)){if(M.type==="table")j.push({type:"table",tableName:M.tablePath,componentID:`${M.connection}:${M.tablePath}`,sourceID:`${M.connection}:${M.tablePath}`});else if(M.type==="sql_select")j.push({type:"sql",selectStatement:M.selectStr,componentID:`${M.connection}:${M.selectStr}`,sourceID:`${M.connection}:${M.selectStr}`});else if(M.type==="query_source"){let P;try{P=new q(M.query,this.getSingleExploreModel(),[]).getPreparedResult().sql}catch(Z){P=`-- Could not compile SQL for query ${M.query.name||"unnamed query"}: ${Z instanceof Error?Z.message:String(Z)}`}const V=`${M.connection}:${P}`;j.push({type:"sql",selectStatement:P,componentID:V,sourceID:V})}}else return[];for(const P of M.fields)(0,e.isJoined)(P)&&j.push(...this.collectSourceComponents(P));return j}getSourceComponents(){const M={};if((0,e.isSourceDef)(this.structDef)){const j=this.collectSourceComponents(this.structDef);for(const P of j)P.componentID?M[P.componentID]=P:P.sourceID&&(M[P.sourceID]=P)}return Object.values(M)}}vt.Explore=T;class b extends m{constructor(M,j,P){super((0,e.activeName)(M),j,P),this.fieldTypeDef=M,this.parent=j}get type(){switch(this.fieldTypeDef.type){case"string":return E.String;case"boolean":return E.Boolean;case"date":return E.Date;case"timestamp":return E.Timestamp;case"timestamptz":return E.Timestamptz;case"number":return E.Number;case"json":return E.Json;case"sql native":return E.NativeUnsupported;case"error":return E.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const M=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${M}`)}}}tagParse(M){return(0,l.annotationToTag)(this.fieldTypeDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.fieldTypeDef.annotations,M)}get annotations(){return new l.Annotations(this.fieldTypeDef.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this.parent._modelDef))}isIntrinsic(){return(0,e.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,e.expressionIsCalculation)(this.fieldTypeDef.expressionType)}get sourceField(){throw new Error}get sourceClasses(){const M=this.fieldTypeDef.name||this.fieldTypeDef.as;return M?[M]:[]}get referenceId(){var M;return(M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.referenceId}sourceWasMeasure(){var M;return((M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.fieldKind)==="measure"}sourceWasMeasureLike(){var M,j;return((M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.fieldKind)==="measure"||((j=this.fieldTypeDef.resultMetadata)===null||j===void 0?void 0:j.fieldKind)==="struct"}sourceWasDimension(){var M;return((M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.fieldKind)==="dimension"}hasParentExplore(){return!0}isString(){return this instanceof k}isNumber(){return this instanceof D}isDate(){return this instanceof _}isBoolean(){return this instanceof w}isJSON(){return this instanceof N}isTimestamp(){return this instanceof R}isUnsupported(){return this instanceof I}get parentExplore(){return this.parent}get expression(){const j=this.fieldTypeDef.resultMetadata;return j?.sourceExpression||(j?.sourceField.includes(".")?j?.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}vt.AtomicField=b;class _ extends b{constructor(M,j,P){super(M,j,P),this.fieldDateDef=M}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return v.Day;case"week":return v.Week;case"month":return v.Month;case"quarter":return v.Quarter;case"year":return v.Year}}}vt.DateField=_;class R extends b{constructor(M,j,P){super(M,j,P),this.fieldTimestampDef=M}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return S.Day;case"week":return S.Week;case"month":return S.Month;case"quarter":return S.Quarter;case"year":return S.Year;case"second":return S.Second;case"hour":return S.Hour;case"minute":return S.Minute}}}vt.TimestampField=R;class D extends b{constructor(M,j,P){super(M,j,P),this.fieldNumberDef=M}}vt.NumberField=D;class w extends b{constructor(M,j,P){super(M,j,P),this.fieldBooleanDef=M}}vt.BooleanField=w;class N extends b{constructor(M,j,P){super(M,j,P),this.fieldJSONDef=M}}vt.JSONField=N;class I extends b{constructor(M,j,P){super(M,j,P),this.fieldUnsupportedDef=M}get rawType(){return this.fieldUnsupportedDef.rawType}}vt.UnsupportedField=I;class k extends b{constructor(M,j,P){super(M,j,P),this.fieldStringDef=M}}vt.StringField=k;class $ extends m{constructor(M,j,P){super((0,e.activeName)(M),j,P),this.turtleDef=M}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}tagParse(M){return(0,l.annotationToTag)(this.turtleDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.turtleDef.annotations,M)}get annotations(){return new l.Annotations(this.turtleDef.annotations)}get modelAnnotations(){var M;const j=(M=this._parent)===null||M===void 0?void 0:M._modelDef;return new l.Annotations(j&&(0,e.getModelAnnotations)(j))}}vt.Query=$;class J extends ${constructor(M,j,P){super(M,j,P),this.parent=j}isQueryField(){return!0}isExploreField(){return!1}isAtomicField(){return!1}get sourceClasses(){const M=this.turtleDef.name||this.turtleDef.as;return M?[M]:[]}hasParentExplore(){return!0}get parentExplore(){return this.parent}get expression(){return this.name}}vt.QueryField=J;class re extends T{constructor(M,j,P){super(j._modelDef,M,j,P),this._parentExplore=j}get joinRelationship(){if((0,e.isJoined)(this.structDef))switch(this.structDef.join){case"one":return C.OneToOne;case"many":case"cross":return C.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===C.OneToOne}get isArray(){return this.joinRelationship!==C.OneToOne}tagParse(M){return(0,l.annotationToTag)(this._structDef.annotations,M)}get annotations(){return new l.Annotations(this._structDef.annotations)}isQueryField(){return!1}isExploreField(){return!0}isAtomicField(){return!1}get parentExplore(){return this._parentExplore}get sourceClasses(){const M=this.structDef.name||this.structDef.as;return M?[M]:[]}get queryTimezone(){return(0,e.isRecordOrRepeatedRecord)(this._structDef)?this._structDef.queryTimezone:super.queryTimezone}}vt.ExploreField=re;const ie={fieldReference:"field",joinReference:"join",exploreReference:"explore",queryReference:"query",sqlBlockReference:"sqlBlock",givenReference:"given"};class oe{constructor(M){this._ref=M}get text(){return this._ref.text}get kind(){return ie[this._ref.type]}get location(){return this._ref.location}get definitionLocation(){return this._ref.definition.location}get definitionType(){return this._ref.definition.type}get defaultText(){if(this._ref.type==="givenReference")return this._ref.definition.defaultText}get annotations(){return new l.Annotations(this._ref.definition.annotations)}}vt.Reference=oe;class U{constructor(M,j,P,V,Z){var ae,ce;this.modelDef=M,this.problems=j,this.fromSources=P,this.runtimeContext=Z,this.references=new h.ReferenceList((ae=P[0])!==null&&ae!==void 0?ae:"",(ce=M.references)!==null&&ce!==void 0?ce:[]),this._queryModel=V,this.contentsMap=new Map(Object.entries(M.contents))}getContent(M){return this.contentsMap.get(M)}get queryModel(){return this._queryModel||(this._queryModel=new e.QueryModel(this.modelDef)),this._queryModel}getExistingQueryModel(){return this._queryModel}get givens(){var M,j;const P=new Map,V=this.modelDef.givens;if(!V)return P;for(const[Z,ae]of this.contentsMap){if(ae.type!=="given"||!((j=(M=this.runtimeContext)===null||M===void 0?void 0:M.finalizedGivens)===null||j===void 0)&&j.has(Z))continue;const ce=V[ae.id];ce&&!ce.inline&&P.set(Z,new K(Z,ae.id,ce,this.modelDef))}return P}get _ownModelAnnotations(){var M;return(M=this.modelDef.modelAnnotations[this.modelDef.modelID])===null||M===void 0?void 0:M.ownNotes}tagParse(M){return(0,l.annotationToTag)(this._ownModelAnnotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this._ownModelAnnotations,M)}get annotations(){return new l.Annotations(this._ownModelAnnotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this.modelDef))}referenceAt(M){const j=this.references.find(M);return j?new oe(j):void 0}getReference(M){return this.references.find(M)}getImport(M){var j;return(j=this.modelDef.imports)===null||j===void 0?void 0:j.find(P=>(0,c.locationContainsPosition)(P.location,M))}getPreparedQueryByName(M){const j=this.getContent(M);if(j?.type==="query")return new q(j,this,this.problems,M);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(M){if(M<0)throw new Error(`Invalid index ${M}.`);if(M>=this.modelDef.queryList.length)throw new Error(`Query index ${M} is out of bounds.`);return new q(this.modelDef.queryList[M],this,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new q(this.modelDef.queryList[this.modelDef.queryList.length-1],this,this.problems)}getExploreByName(M){const j=this.getContent(M);if(j&&(0,e.isSourceDef)(j))return new T(this.modelDef,j);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(e.isSourceDef).map(M=>new T(this.modelDef,M))}queries(){const M=[];for(const j of Object.values(this.modelDef.contents))j.type==="query"&&M.push(j.name);return{named:M,unnamed:this.modelDef.queryList.length}}get namedQueries(){const M=j=>j.type==="query";return Object.values(this.modelDef.contents).filter(M)}get exportedExplores(){return this.explores.filter(M=>this.modelDef.exports.includes(M.name))}get _modelDef(){return this.modelDef}getBuildPlan(){if(!this.modelAnnotations.parseAsTag("!").tag.has("experimental","persistence"))throw new Error("Model must have ##! experimental.persistence to use getBuildPlan()");const j=[],P=[];for(const se of Object.values(this.modelDef.contents))(se.type==="query"||(0,e.isSourceDef)(se))&&j.push(...(0,i.findPersistentDependencies)(se,this.modelDef,P));for(const se of this.modelDef.queryList)j.push(...(0,i.findPersistentDependencies)(se,this.modelDef,P));if(j.length===0)return{graphs:[],sources:{},tagParseLog:P};const V=(0,i.minimalBuildGraph)(j),Z={},ae=se=>{for(const fe of se){if(!(fe.sourceID in Z)){const pe=(0,o.resolveSourceID)(this.modelDef,fe.sourceID);pe&&(Z[fe.sourceID]=new ee(new T(this.modelDef,pe),this))}ae(fe.dependsOn)}};ae(V);const ce=new Map;for(const se of V){const fe=Z[se.sourceID];if(!fe)continue;const pe=fe.connectionName;ce.has(pe)||ce.set(pe,[]),ce.get(pe).push(se)}const le=[];for(const[se,fe]of ce)le.push({connectionName:se,nodes:[fe]});return{graphs:le,sources:Z,tagParseLog:P}}}vt.Model=U;class ee{constructor(M,j){this.explore=M,this.model=j;const P=M.structDef;if(!(0,e.isSourceDef)(P))throw new Error("Cannot create PersistSource from non-source type");if(!(0,e.isPersistableSourceDef)(P))throw new Error(`Cannot persist source '${M.name}' of type '${P.type}'. Only query_source and sql_select sources can be persisted.`);this.persistableDef=P}get name(){return this.explore.name}get sourceID(){const M=this.persistableDef.sourceID;if(!M)throw new Error(`PersistSource '${this.name}' has no sourceID. This should not happen - sourceID is set at translation time.`);return M}get _explore(){return this.explore}get annotation(){return this.persistableDef.annotations}tagParse(M){return this.explore.tagParse(M)}getTaglines(M){return this.explore.getTaglines(M)}get annotations(){return this.explore.annotations}get modelAnnotations(){return this.explore.modelAnnotations}get connectionName(){return this.persistableDef.connection}get dialectName(){return this.persistableDef.dialect}get dialect(){return(0,r.getDialect)(this.dialectName)}makeBuildId(M,j){return(0,o.mkBuildID)(M,j)}getSQL(M){const j=this.persistableDef,P=this.model.queryModel;return j.type==="sql_select"?(0,e.getCompiledSQL)(j,M??{},(V,Z)=>P.compileQuery(V,Z).sql):P.compileQuery(j.query,M).sql}get _sourceDef(){return this.persistableDef}get _model(){return this.model}}vt.PersistSource=ee;class K{constructor(M,j,P,V){this.name=M,this.id=j,this._internal=P,this._modelDef=V}get type(){return this._internal.type}get default(){return this._internal.default}get location(){return this._internal.location}tagParse(M){return(0,l.annotationToTag)(this._internal.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this._internal.annotations,M)}get annotations(){return new l.Annotations(this._internal.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this._modelDef))}}vt.Given=K;class te{constructor(M){this.pipelineDef=M}get annotations(){return new l.Annotations(this.pipelineDef.annotations)}get location(){return this.pipelineDef.location}tagParse(M){return(0,l.annotationToTag)(this.pipelineDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.pipelineDef.annotations,M)}}class q extends te{constructor(M,j,P,V){super(M),this._model=j,this.problems=P,this.name=V}get _query(){return this.pipelineDef}get _modelDef(){return this._model._modelDef}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this._modelDef))}get preparedResult(){return this.getPreparedResult()}getPreparedResult(M){const j=this._model.queryModel,P=M?.givens?(0,s.resolveSuppliedGivens)(M.givens,this._modelDef):new Map;(0,s.evaluateInlineGivens)(P,this._modelDef);const V={...M,resolvedGivens:P.size>0?P:void 0},Z=j.compileQuery(this._query,V);return new H({...Z,queryName:this.name||Z.queryName},this._modelDef)}get dialect(){const M=this._query.structRef,j=typeof M=="string"?this._model.getContent(M):M;if(j===void 0||!(0,e.isSourceDef)(j))throw new Error("Invalid source for query");return j.dialect}getFlattenedQuery(M){return this}get model(){return this._model}get givens(){const M=new Map,j=this._query.givenUsage;if(!j||j.length===0)return M;const P=new Set(j.map(V=>V.id));for(const[V,Z]of this._model.givens)P.has(Z.id)&&M.set(V,Z);return M}}vt.PreparedQuery=q;class H{constructor(M,j){this.modelDef=j,this.inner=M}static fromJson({query:M,modelDef:j}){if(!M||!j)throw new Error("Missing required properties in JSON data");return new H(M,j)}tagParse(M){return(0,l.annotationToTag)(this.inner.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.inner.annotations,M)}get annotations(){return new l.Annotations(this.inner.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this.modelDef))}get annotation(){return this.inner.annotations}get modelAnnotation(){return(0,e.getModelAnnotations)(this.modelDef)}get modelTag(){return new l.Annotations((0,e.getModelAnnotations)(this.modelDef)).parseAsTag().tag}get connectionName(){return this.inner.connectionName}get _rawQuery(){return this.inner}get _modelDef(){return this.modelDef}get sql(){return this.inner.sql}get resultExplore(){if(this.inner.structs.length===0)throw new Error("Malformed query result.");const M=this.inner.structs[this.inner.structs.length-1],j={...M,annotations:this.inner.annotations,name:this.inner.queryName||M.name};try{return new T(this.modelDef,j,this.sourceExplore)}catch{return new T(this.modelDef,j)}}get sourceExplore(){const M=this.inner.sourceExplore,j=(0,e.safeRecordGet)(this.modelDef.contents,M);if(j&&(0,e.isSourceDef)(j))return new T(this.modelDef,j)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceArguments(){return this.inner.sourceArguments}get _sourceFilters(){return this.inner.sourceFilters||[]}get hasSchema(){return this.inner.structs.length>0}toStableResult(M){const j=this.inner.structs,P=j[j.length-1],V={fields:(0,u.convertFieldInfos)(P,P.fields)},Z=(0,u.toStableAnnotations)(this.inner.annotations),ae=P.resultMetadata?(0,u.getResultStructMetadataAnnotation)(P,P.resultMetadata):void 0;ae&&Z.push(ae);const ce=a.Tag.withPrefix("#(malloy) "),le=this.sourceExplore;if(le&&ce.set(["source","name"],le.name),this._sourceArguments){const fe=Object.entries(this._sourceArguments);for(let pe=0;pe<fe.length;pe++){const[ye,Ce]=fe[pe],me=(0,d.nodeToLiteralValue)(Ce.value);me!==void 0&&(0,u.writeLiteralToTag)(ce,["source","parameters",pe,"value"],me),ce.set(["source","parameters",pe,"name"],ye)}}Z.push({value:ce.toString()}),Z.push({value:a.Tag.withPrefix("#(malloy) ").set(["query_name"],this.inner.queryName||P.name).toString()});const se=(0,u.toStableAnnotations)((0,e.getModelAnnotations)(this.modelDef));return{schema:V,data:M,connection_name:this.inner.connectionName,annotations:Z.length>0?Z:void 0,model_annotations:se.length>0?se:void 0,query_timezone:P.queryTimezone,sql:this.inner.sql}}}return vt.PreparedResult=H,vt}var Da={},y8;function ek(){if(y8)return Da;y8=1,Object.defineProperty(Da,"__esModule",{value:!0}),Da.DataRecord=Da.DataArray=Da.Result=void 0;const e=jr(),t=w2(),r=XE();class i extends r.PreparedResult{constructor(N,I){super(N,I),this.inner=N}get _queryResult(){return this.inner}get data(){return new R(this.inner.result,this.resultExplore,void 0,void 0)}get totalRows(){return this.inner.totalRows}get runStats(){return this.inner.runStats}get profilingUrl(){return this.inner.profilingUrl}toJSON(){return this.hasSchema?{queryResult:{...this.inner,result:this.data.toJSON()},modelDef:this._modelDef}:{queryResult:this.inner,modelDef:this._modelDef}}static fromJSON({queryResult:N,modelDef:I}){return new i(N,I)}}Da.Result=i;class o{constructor(N,I,k){this.parent=I,this.parentRecord=k,this._field=N}get field(){return this._field}isString(){return this instanceof a}get string(){if(this.isString())return this;throw new Error("Not a string.")}isBoolean(){return this instanceof u}get boolean(){if(this.isBoolean())return this;throw new Error("Not a boolean.")}isNumber(){return this instanceof c}get number(){if(this.isNumber())return this;throw new Error("Not a number.")}isTimestamp(){return this instanceof h}get timestamp(){if(this.isTimestamp())return this;throw new Error("Not a timestamp.")}isDate(){return this instanceof f}get date(){if(this.isDate())return this;throw new Error("Not a date.")}isNull(){return this instanceof x}isBytes(){return this instanceof p}get bytes(){if(this.isBytes())return this;throw new Error("Not bytes.")}isRecord(){return this instanceof D}get record(){if(this.isRecord())return this;throw new Error("Not a record.")}isUnsupported(){return this instanceof l}get unsupported(){if(this.isUnsupported())return this;throw new Error("Not unsupported.")}isArray(){return this instanceof R}get array(){if(this.isArray())return this;throw new Error("Not an array.")}isArrayOrRecord(){if(this instanceof R||this instanceof D)return this;throw new Error("No Array or Record")}isScalar(){return!0}}class s extends o{constructor(N,I,k,$){super(I,k,$),this._value=N,this._field=I}get value(){return this._value}get field(){return this._field}isScalar(){return this instanceof s}}class a extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return this.value}compareTo(N){return this.value.toLocaleLowerCase().localeCompare(N.value.toLocaleLowerCase())}}class l extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return"<unsupported>"}compareTo(N){return 0}}class u extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return`${this.value}`}compareTo(N){return this.value===N.value?0:this.value?1:-1}}class d extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return this.value}compareTo(N){const I=this.value.toString(),k=N.toString();return I===k?0:I>k?1:-1}}class c extends s{constructor(N,I,k,$){super((0,t.rowDataToNumber)(N),I,k,$),this._field=I}get field(){return this._field}get key(){return`${this.value}`}compareTo(N){const I=this.value-N.value;return I>0?1:I===0?0:-1}}class h extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get value(){return(0,t.rowDataToDate)(this._value)}get field(){return this._field}get key(){return`${this.value.toLocaleString()}`}compareTo(N){return this.value>N.value?1:this.value<N.value?-1:0}}class f extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get value(){return(0,t.rowDataToDate)(this._value)}get field(){return this._field}get key(){return`${this.value.toLocaleString()}`}compareTo(N){return this.value>N.value?1:this.value<N.value?-1:0}}class p extends s{get key(){return this.value.toString()}compareTo(N){const I=this.value.toString(),k=N.toString();return I===k?0:I>k?1:-1}}class x extends o{get value(){return null}get key(){return"<null>"}}function m(w){const N=(0,t.rowDataToSerializedBigint)(w);if(N.includes(".")||N.includes("e")||N.includes("E"))return(0,t.rowDataToNumber)(w);try{return BigInt(N)}catch{return(0,t.rowDataToNumber)(w)}}function g(w){const N=(0,t.rowDataToSerializedBigint)(w);return N.includes(".")||N.includes("e")||N.includes("E")?(0,t.rowDataToNumber)(w):N}const E={number:t.rowDataToNumber,bigint:m,date:t.rowDataToDate},v={number:t.rowDataToNumber,bigint:g,date:w=>(0,t.rowDataToDate)(w).toISOString()};function S(w,N,I){return w.map(k=>C(k,N,I))}function C(w,N,I){const k={};for(const $ of N.fields){const J=(0,e.activeName)($),re=w[J];k[J]=T(re,$,I)}return k}function T(w,N,I){if(w==null)return null;if(N.type==="number")return N.numberType==="bigint"?I.bigint(w):I.number(w);if(N.type==="date"||N.type==="timestamp"||N.type==="timestamptz")return I.date(w);if(N.type==="string"||N.type==="boolean"||N.type==="json"||N.type==="sql native")return N.type==="boolean"&&typeof w=="number"?w!==0:w;if(N.type==="array"){if(!Array.isArray(w))return w;if((0,e.isRepeatedRecord)(N))return w.map(k=>C(k,N,I));if((0,e.isBasicArray)(N)){const k=N.elementTypeDef;return w.map($=>b($,k,I))}}return N.type==="record"&&typeof w=="object"&&w!==null&&!Array.isArray(w)?C(w,N,I):w}function b(w,N,I){if(w==null)return null;if(N.type==="number")return N.numberType==="bigint"?I.bigint(w):I.number(w);if(N.type==="date"||N.type==="timestamp"||N.type==="timestamptz")return I.date(w);if(N.type==="boolean"&&typeof w=="number")return w!==0;if(N.type==="array"&&Array.isArray(w)){if((0,e.isBasicArray)(N)){const k=N.elementTypeDef;return w.map($=>b($,k,I))}else if((0,e.isRepeatedRecord)(N))return w.map(k=>C(k,N,I))}return w}function _(w,N){for(const I of N)typeof I=="number"?w=w.array.row(I):w=w.record.cell(I);return w}class R extends o{constructor(N,I,k,$){super(I,k,$),this.rowCache=new Map,this.queryData=N,this._field=I}get field(){return this._field}get rawData(){return this.queryData}toObject(){return S(this.queryData,this._field.structDef,E)}toJSON(){return S(this.queryData,this._field.structDef,v)}path(...N){return _(this,N)}row(N){let I=this.rowCache.get(N);return I||(I=new D(this.queryData[N],N,this.field,this,this.parentRecord),this.rowCache.set(N,I)),I}get rowCount(){return this.queryData.length}get value(){return this.toObject()}[Symbol.iterator](){let N=0;const I=this.queryData,k=$=>this.row($);return{next(){return N<I.length?{value:k(N++),done:!1}:{value:void 0,done:!0}}}}async*inMemoryStream(){for(let N=0;N<this.queryData.length;N++)yield this.row(N)}}Da.DataArray=R;class D extends o{constructor(N,I,k,$,J){super(k,$,J),this.cellCache=new Map,this.queryDataRow=N,this._field=k,this.index=I}toObject(){return C(this.queryDataRow,this._field.structDef,E)}toJSON(){return C(this.queryDataRow,this._field.structDef,v)}path(...N){return _(this,N)}cell(N){const I=typeof N=="string"?N:N.name,k=this._field.getFieldByName(I);let $=this.cellCache.get(I);if(!$){const J=this.queryDataRow[I];J===null?$=new x(k,this,this):k.isAtomicField()?k.isBoolean()?$=new u(J,k,this,this):k.isDate()?$=new f(J,k,this,this):k.isJSON()?$=new d(J,k,this,this):k.isTimestamp()?$=new h(J,k,this,this):k.isNumber()?$=new c(J,k,this,this):k.isString()?$=new a(J,k,this,this):k.isUnsupported()&&($=new l(J,k,this,this)):k.isExploreField()&&((0,e.isCompoundArrayData)(J)?$=new R(J,k,this,this):$=new D(J,void 0,k,this,this)),$&&this.cellCache.set(I,$)}if($)return $;throw new Error(`Internal Error: could not construct data column for field '${I}'.`)}get value(){throw new Error("Not implemented;")}get field(){return this._field}[Symbol.iterator](){let N=!1;const I=()=>this;return{next(){return N?{value:void 0,done:!0}:(N=!0,{value:I(),done:!1})}}}}return Da.DataRecord=D,Da}var Na={},E8;function yz(){if(E8)return Na;E8=1,Object.defineProperty(Na,"__esModule",{value:!0}),Na.CSVWriter=Na.JSONWriter=Na.DataWriter=void 0;const e=jr();class t{constructor(s){this.stream=s}}Na.DataWriter=t;class r extends t{async process(s){this.stream.write(`[
1286
+ ${te}`:U=te}return U}childRequest(U){var ee;const K=decodeURI(new URL(U,this.sourceURL).toString()),te=(ee=this.childTranslators.get(K))===null||ee===void 0?void 0:ee.translate();if(te?.compileSQL)return{compileSQL:te.compileSQL}}importModelDef(U){const ee=decodeURI(new URL(U,this.sourceURL).toString()),K=this.childTranslators.get(ee);if(K)return K.translate().modelDef}translate(U){if(this.finalAnswer)return this.finalAnswer;const ee=this.translateStep.step(this,U);return ee.final&&(this.finalAnswer=ee),ee}translatorForDependency(U){return this.childTranslators.get(U)}importAt(U){for(let ee=0;ee<this.imports.length;ee++){const K=this.imports[ee];if((0,g.locationContainsPosition)(K.location,U))return K}}metadata(){return this.metadataStep.step(this)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(U){return this.completionsStep.step(this,U)}helpContext(U){return this.helpContextStep.step(this,U)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(U){return(0,g.rangeFromContext)(this.parseStep.sourceInfo,U)}firstReferenceToDialect(U){return this.dialectAlreadyChecked[U]?!1:(this.dialectAlreadyChecked[U]=!0,!0)}experimentalDialectEnabled(U){if(this.allDialectsEnabled)return!0;const ee=this.getCompilerFlags().tag("experimental");return ee!==void 0&&(ee.bare()||ee.has("dialect",U))}}pn.MalloyTranslation=$;class J extends ${constructor(U,ee){super(U),this.root=ee}}pn.MalloyChildTranslator=J;class re extends ${constructor(U,ee=null,K=null,te=null,q=!1){super(U,ee),this.eventStream=te,this.restrictedMode=q,this.schemaZone=new c.Zone,this.importZone=new c.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new c.Zone,this.connectionDialectZone=new c.Zone,this.root=this,this.logger=new l.BaseMessageLogger(te),K&&this.update(K)}update(U){var ee,K,te,q;this.schemaZone.updateFrom(U.tables,(ee=U.errors)===null||ee===void 0?void 0:ee.tables),this.importZone.updateFrom(U.urls,(K=U.errors)===null||K===void 0?void 0:K.urls),this.sqlQueryZone.updateFrom(U.compileSQL,(te=U.errors)===null||te===void 0?void 0:te.compileSQL),this.connectionDialectZone.updateFrom(U.connectionDialects,(q=U.errors)===null||q===void 0?void 0:q.connectionDialects);for(const H in U.translations)this.pretranslatedModels.set(H,U.translations[H])}lockZonesIfRestricted(){this.restrictedMode&&(this.schemaZone.lock(),this.importZone.lock(),this.sqlQueryZone.lock(),this.connectionDialectZone.lock())}translate(U){return this.lockZonesIfRestricted(),super.translate(U)}logError(U,ee,K){return this.logger.log((0,l.makeLogMessage)(U,ee,{severity:"error",...K})),U}}pn.MalloyTranslator=re;function ie(oe){return[...Object.keys(oe),...Object.keys(oe).map(U=>ie(oe[U])).flat()]}return pn}var pd={},a8;function hz(){if(a8)return pd;a8=1,Object.defineProperty(pd,"__esModule",{value:!0}),pd.ExploreQueryWalker=void 0,pd.exploreQueryWalkerBuilder=r;const e=sx();class t{constructor(o){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=o}exploreQueryAtOffset(o){return this.exploreClauseRefs.find(s=>s.range[0]===void 0||s.range[1]===void 0?!1:s.range[0]<=o&&s.range[1]>=o)}filterAtOffset(o){const s=this.exploreQueryAtOffset(o);if(s)return s.filterRefs.find(a=>a.range[0]===void 0||a.range[1]===void 0?!1:a.range[0]<=o&&a.range[1]>=o)}hasFilterListAtOffset(o){const s=this.exploreQueryAtOffset(o);return s?!!s.filterLists.find(a=>a.range[0]===void 0||a.range[1]===void 0?!1:a.range[0]<=o&&a.range[1]>=o):!1}enterMalloyDocument(){this.inDocument=!0}}pd.ExploreQueryWalker=t;function r(i,o){const s=new t(i),a=s;return e.ParseTreeWalker.DEFAULT.walk(a,o),s}return pd}var ri={},iS={},md={},u8;function YE(){if(u8)return md;u8=1,Object.defineProperty(md,"__esModule",{value:!0}),md.validateCanonicalTablePath=t,md.validateCanonicalTablePathAnyDialect=r,md.requireCanonicalTablePathAnyDialect=i;const e=bE();function t(o,s){let a;try{a=(0,e.getDialect)(o)}catch{return`tablePath '${s}' cannot be validated: unknown dialect '${o}'`}const l=a.sqlValidateTableName(s);if(!l.ok)return`tablePath '${s}' is not canonical SQL for the ${o} dialect; the translator must validate before passing it here. (${l.error})`;if(l.canonical!==s)return`tablePath '${s}' is not canonical SQL for the ${o} dialect; the translator must validate before passing it here.`}function r(o){let s;for(const a of(0,e.getDialects)()){const l=a.sqlValidateTableName(o);if(l.ok){if(l.canonical===o)return;s===void 0&&(s=l.canonical)}}return s!==void 0?`value '${o}' is not canonical SQL; did you mean '${s}'?`:`value '${o}' is not a valid canonical table path in any registered dialect`}function i(o,s){const a=r(o);if(a!==void 0)throw new Error(`${s}: ${a}`)}return md}var yn={},l8;function KE(){if(l8)return yn;l8=1;var e=yn&&yn.__createBinding||(Object.create?(function(w,N,I,k){k===void 0&&(k=I);var $=Object.getOwnPropertyDescriptor(N,I);(!$||("get"in $?!N.__esModule:$.writable||$.configurable))&&($={enumerable:!0,get:function(){return N[I]}}),Object.defineProperty(w,k,$)}):(function(w,N,I,k){k===void 0&&(k=I),w[k]=N[I]})),t=yn&&yn.__setModuleDefault||(Object.create?(function(w,N){Object.defineProperty(w,"default",{enumerable:!0,value:N})}):function(w,N){w.default=N}),r=yn&&yn.__importStar||(function(){var w=function(N){return w=Object.getOwnPropertyNames||function(I){var k=[];for(var $ in I)Object.prototype.hasOwnProperty.call(I,$)&&(k[k.length]=$);return k},w(N)};return function(N){if(N&&N.__esModule)return N;var I={};if(N!=null)for(var k=w(N),$=0;$<k.length;$++)k[$]!=="default"&&e(I,N,k[$]);return t(I,N),I}})();Object.defineProperty(yn,"__esModule",{value:!0}),yn.sourceDefToSourceInfo=l,yn.modelDefToModelInfo=u,yn.toStableAnnotations=c,yn.convertFieldInfos=h,yn.writeLiteralToTag=m,yn.getResultStructMetadataAnnotation=v;const i=r(dA()),o=jr(),s=x0(),a=za();function l(w){const N=w.parameters&&Object.entries(w.parameters).length>0?Object.entries(w.parameters).map(([k,$])=>(0,o.isAtomic)($)?{name:k,type:S($),default_value:d($.value)}:{name:k,type:{kind:"filter_expression_type",filter_type:{kind:`${$.filterType}_type`}},default_value:d($.value)}):void 0;return{name:(0,o.activeName)(w),schema:{fields:h(w,w.fields)},parameters:N,annotations:c(w.annotations)}}function u(w){const N={entries:[],anonymous_queries:[]};for(const[I,k]of Object.entries(w.contents))if(w.exports.includes(I)){if((0,o.isSourceDef)(k)){const $=l(k);N.entries.push({kind:"source",...$})}else if(k.type==="query"){const $=(0,o.getResultStructDefForQuery)(w,k),J=c(k.annotations),re=$.resultMetadata?v($,$.resultMetadata):void 0,ie=[...J??[],...re?[re]:[]],oe={kind:"source",name:I,schema:{fields:h($,$.fields)},annotations:ie.length>0?ie:void 0};N.entries.push(oe)}}for(const I of w.queryList){const k=(0,o.getResultStructDefForQuery)(w,I),$=c(I.annotations),J=k.resultMetadata?v(k,k.resultMetadata):void 0,re=[...$??[],...J?[J]:[]],ie={schema:{fields:h(k,k.fields)},annotations:re.length>0?re:void 0};N.anonymous_queries.push(ie)}return N}function d(w){if(w!==null)switch(w.node){case"numberLiteral":return{kind:"number_literal",number_value:parseFloat(w.literal)};case"stringLiteral":return{kind:"string_literal",string_value:w.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:w.filterSrc};case"dateLiteral":return{kind:"date_literal",date_value:w.literal};case"timestampLiteral":case"timestamptzLiteral":return{kind:"timestamp_literal",timestamp_value:w.literal,timezone:w.timezone};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"null":return{kind:"null_literal"};default:throw new Error("Invalid parameter default value")}}function c(w){return new s.Annotations(w).texts().map(N=>({value:N}))}function h(w,N){const I=[];for(const k of N){if(!(k.accessModifier===void 0))continue;const J=c(k.annotations),re=J.length>0?J:void 0;if((0,o.isTurtle)(k)){const ie=(0,o.getResultStructDefForView)(w,k),oe=ie.resultMetadata?v(ie,ie.resultMetadata):void 0,U=[...re??[],...oe?[oe]:[]],ee={kind:"view",name:(0,o.activeName)(k),annotations:U.length>0?U:void 0,schema:{fields:h(ie,ie.fields)}};I.push(ee)}else if((0,o.isAtomic)(k)){const ie=(0,o.expressionIsAggregate)(k.expressionType),oe=(0,o.expressionIsScalar)(k.expressionType);if(!ie&&!oe||k.type==="error")continue;const U=k.resultMetadata?f(k,k.resultMetadata):void 0;let ee;if((0,o.isRecordOrRepeatedRecord)(k)&&k.queryTimezone){const q=a.Tag.withPrefix("#(malloy) ");q.set(["query_timezone"],k.queryTimezone),ee={value:q.toString()}}const K=[...re??[],...U?[U]:[],...ee?[ee]:[]],te={kind:ie?"measure":"dimension",name:(0,o.activeName)(k),type:S(k),annotations:K.length>0?K:void 0};I.push(te)}else if((0,o.isJoinedSource)(k)){const ie={kind:"join",name:(0,o.activeName)(k),annotations:re,schema:{fields:h(k,k.fields)},relationship:k.join};I.push(ie)}}return I}function f(w,N){const I=a.Tag.withPrefix("#(malloy) ");let k=!1;if(N.referenceId!==void 0&&(I.set(["reference_id"],N.referenceId),k=!0),N.fieldKind==="measure"&&(I.set(["calculation"]),k=!0),N.drillable&&(I.set(["drillable"]),k=!0),N.filterList&&(p(I,N.filterList),k=!0),N.drillExpression&&(x(I,["drill_expression"],N.drillExpression),k=!0),N.fieldKind==="dimension"){const J=N?.sourceExpression||(N?.sourceField.includes(".")?N?.sourceField:E(w.name));I.set(["drill_expression","code"],J),k=!0}return k?{value:I.toString()}:void 0}function p(w,N){for(let I=0;I<N.length;I++){const k=N[I];k.expressionType!=="scalar"||k.isSourceFilter||(w.set(["drill_filters",I,"code"],k.code),k.filterView&&w.set(["drill_filters",I,"filter_view"],k.filterView),k.filterView===void 0&&k.stableFilter!==void 0&&(x(w,["drill_filters",I,"expression"],k.stableFilter.expression),k.stableFilter.kind==="filter_string"?(w.set(["drill_filters",I,"kind"],"filter_expression"),w.set(["drill_filters",I,"filter_expression"],k.stableFilter.filter)):(w.set(["drill_filters",I,"kind"],"literal_equality"),m(w,["drill_filters",I,"value"],k.stableFilter.value))))}}function x(w,N,I){D(w,N,I,"Expression")}function m(w,N,I){D(w,N,I,"LiteralValue")}function g(w){return w.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}function E(w){return w.match(/^[A-Za-z_][0-9A-Za-z_]*$/)?w:`\`${g(w)}\``}function v(w,N){var I;const k=a.Tag.withPrefix("#(malloy) ");let $=!1;if(N.limit!==void 0&&(k.set(["limit"],N.limit),$=!0),N.filterList&&(p(k,N.filterList),$=!0),N.drillable&&(k.set(["drillable"]),$=!0),N.orderBy){for(let J=0;J<N.orderBy.length;J++){const re=N.orderBy[J],ie=typeof re.field=="number"?(0,o.activeName)(w.fields[re.field-1]):re.field,oe=(I=re.dir)!==null&&I!==void 0?I:null;k.set(["ordered_by",J,ie],oe)}$=!0}return w.queryTimezone&&(k.set(["query_timezone"],w.queryTimezone),$=!0),$?{value:k.toString()}:void 0}function S(w){if((0,o.isBasicAtomic)(w))switch(w.type){case"string":return{kind:"string_type"};case"number":return{kind:"number_type",subtype:w.numberType==="float"?"decimal":w.numberType==="integer"?"integer":w.numberType==="bigint"?"bigint":void 0};case"boolean":return{kind:"boolean_type"};case"date":{const N=w.timeframe;return N&&!T(N)?{kind:"timestamp_type",timeframe:w.timeframe}:{kind:"date_type",timeframe:b(w.timeframe)}}case"timestamp":return{kind:"timestamp_type",timeframe:w.timeframe};case"timestamptz":return{kind:"timestamptz_type",timeframe:w.timeframe};case"json":return{kind:"json_type"};case"sql native":return{kind:"sql_native_type",sql_type:w.rawType};case"error":throw new Error("Error type is not supported in stable interface")}else{if((0,o.isRepeatedRecord)(w))return{kind:"array_type",element_type:C(w)};if(w.type==="record")return C(w);if(w.type==="array")return{kind:"array_type",element_type:S(w.elementTypeDef)}}throw new Error("Unexpected field type")}function C(w){return{kind:"record_type",fields:w.fields.map(N=>{const I=[];if("resultMetadata"in N&&N.resultMetadata){const k=f(N,N.resultMetadata);k&&I.push(k)}if(N.annotations&&I.push(...c(N.annotations)),(0,o.isAtomic)(N))return{name:N.name,annotations:I.length>0?I:void 0,type:S(N)};throw new Error("Expected record type to not have a table as its child")})}}function T(w){switch(w){case"day":case"week":case"month":case"year":case"quarter":return!0;default:return!1}}function b(w){switch(w){case void 0:return;case"day":case"week":case"month":case"year":case"quarter":return w;default:throw new Error(`Invalid date timeframe ${w}`)}}function _(w){return w}function R(w){return w}function D(w,N,I,k){if(k==="string"){w.set(N,I);return}else if(k==="number"){w.set(N,I);return}else if(k==="boolean"){w.set(N,I.toString());return}const $=i.MALLOY_INTERFACE_TYPES[k];if($===void 0)throw new Error(`Unknown Malloy interface type ${k}`);if($.type==="enum")if(typeof I=="string")w.set(N,I);else throw new Error(`Expected string for enum ${k}`);else if($.type==="struct")for(const J in $.fields){const re=$.fields[J],ie=I[J];if(ie===void 0){if(!re.optional)throw new Error(`Mising value for non-optional field ${J} in type ${k}`)}else if(re.array)if(Array.isArray(ie))for(let oe=0;oe<ie.length;oe++)D(w,[...N,J,oe],ie[oe],re.type);else throw new Error(`Expected array for field ${J} of type ${k} but got ${typeof I}`);else D(w,[...N,J],ie,re.type)}else{const J=I.kind;w.set([...N,"kind"],J);const re=$.options[J];if(re===void 0)throw new Error(`Unknown Malloy interface union kind ${J} for type ${k}`);D(w,N,I,re)}}return yn}var c8;function X2(){return c8||(c8=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.DEFAULT_LOG_RANGE=void 0,e.wrapLegacyInfoConnection=o,e.wrapLegacyConnection=s,e.mapData=a,e.wrapResult=l,e.nodeToLiteralValue=u,e.mapLogs=d;const t=YE(),r=KE(),i=w2();function o(c){return{get dialectName(){return c.dialectName},async fetchSchemaForSQLQuery(h){const f=await c.fetchSchemaForSQLStruct({connection:c.name,selectStr:h},{}),p=f.structDef;if(p===void 0)throw new Error(f.error);return{fields:(0,r.convertFieldInfos)(p,p.fields)}},async fetchSchemaForTable(h){const f=(0,t.validateCanonicalTablePath)(c.dialectName,h);if(f!==void 0)throw new Error(f);const p=`${c.name}:${h}`,x=await c.fetchSchemaForTables({[p]:h},{}),m=x.schemas[p];if(m===void 0)throw new Error(x.errors[p]);return{fields:(0,r.convertFieldInfos)(m,m.fields)}}}}function s(c){return{...o(c),runSQL:async(h,f)=>{const p=await c.runSQL(h);return a(p.rows,f)}}}function a(c,h){function f(m,g){if(m===null)return{kind:"null_cell"};if(g.type.kind==="date_type"||g.type.kind==="timestamp_type"||g.type.kind==="timestamptz_type"){const E=(0,i.rowDataToDate)(m).toISOString();return g.type.kind==="date_type"?{kind:"date_cell",date_value:E}:{kind:"timestamp_cell",timestamp_value:E}}else if(g.type.kind==="boolean_type"){if(typeof m=="number"||typeof m=="bigint")return{kind:"boolean_cell",boolean_value:m!==0};if(typeof m=="string")return{kind:"boolean_cell",boolean_value:m!=="0"&&m!==""};if(typeof m!="boolean")throw new Error(`Invalid boolean ${m}`);return{kind:"boolean_cell",boolean_value:m}}else if(g.type.kind==="number_type"){const E=g.type.subtype,v=E==="bigint"?(0,i.rowDataToSerializedBigint)(m):void 0;return{kind:"number_cell",number_value:(0,i.rowDataToNumber)(m),subtype:E,string_value:v}}else if(g.type.kind==="string_type"){if(typeof m!="string")throw new Error(`Invalid string ${m}`);return{kind:"string_cell",string_value:m}}else if(g.type.kind==="array_type"){if(!Array.isArray(m))throw new Error(`Invalid array ${m}`);return{kind:"array_cell",array_value:m.map(E=>f(E,{name:"array_element",type:g.type.element_type}))}}else{if(g.type.kind==="json_type")return{kind:"json_cell",json_value:JSON.stringify(m)};if(g.type.kind==="sql_native_type")return{kind:"sql_native_cell",sql_native_value:JSON.stringify(m)};{const E=g.type;if(E.kind!=="record_type")throw new Error(`Invalid record in result ${JSON.stringify(g)}, ${JSON.stringify(m)}`);return p(m,{schema:{fields:E.fields.map(v=>({kind:"dimension",...v}))}})}}}function p(m,g){const E=[];for(const v of g.schema.fields){const S=m[v.name];if(v.kind!=="dimension")throw new Error("Invalid result -- expected all fields to be dimensions");const C=f(S,v);E.push(C)}return{kind:"record_cell",record_value:E}}const x={schema:h};return{kind:"array_cell",array_value:c.map(m=>p(m,x))}}function l(c){const h=c._queryResult.structs,f=h[h.length-1],p={fields:(0,r.convertFieldInfos)(f,f.fields)};return c.toStableResult(a(c.data.rawData,p))}function u(c){switch(c?.node){case"numberLiteral":return{kind:"number_literal",number_value:Number.parseFloat(c.literal)};case"null":return{kind:"null_literal"};case"stringLiteral":return{kind:"string_literal",string_value:c.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:c.filterSrc};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"dateLiteral":return{kind:"date_literal",date_value:c.literal,granularity:c.typeDef.timeframe};case"timestampLiteral":case"timestamptzLiteral":return{kind:"timestamp_literal",timestamp_value:c.literal,timezone:c.timezone,granularity:c.typeDef.timeframe};default:return}}e.DEFAULT_LOG_RANGE={start:{line:0,character:0},end:{line:0,character:0}};function d(c,h){return c.map(f=>{var p,x,m,g;return{severity:f.severity,message:f.message,range:(x=(p=f.at)===null||p===void 0?void 0:p.range)!==null&&x!==void 0?x:e.DEFAULT_LOG_RANGE,url:(g=(m=f.at)===null||m===void 0?void 0:m.url)!==null&&g!==void 0?g:h}})}})(iS)),iS}var d8;function pz(){if(d8)return ri;d8=1;var e=ri&&ri.__createBinding||(Object.create?(function(g,E,v,S){S===void 0&&(S=v);var C=Object.getOwnPropertyDescriptor(E,v);(!C||("get"in C?!E.__esModule:C.writable||C.configurable))&&(C={enumerable:!0,get:function(){return E[v]}}),Object.defineProperty(g,S,C)}):(function(g,E,v,S){S===void 0&&(S=v),g[S]=E[v]})),t=ri&&ri.__setModuleDefault||(Object.create?(function(g,E){Object.defineProperty(g,"default",{enumerable:!0,value:E})}):function(g,E){g.default=E}),r=ri&&ri.__importStar||(function(){var g=function(E){return g=Object.getOwnPropertyNames||function(v){var S=[];for(var C in v)Object.prototype.hasOwnProperty.call(v,C)&&(S[S.length]=C);return S},g(E)};return function(E){if(E&&E.__esModule)return E;var v={};if(E!=null)for(var S=g(E),C=0;C<S.length;C++)S[C]!=="default"&&e(v,E,S[C]);return t(v,E),v}})();Object.defineProperty(ri,"__esModule",{value:!0}),ri.MalloyToQuery=void 0,ri.malloyToQuery=m;const i=K2(),o=hT(),s=r(V2()),a=D2(),l=Y2(),u=Ge(),d=XP(),c=xs(),h=X2(),f=H1(),p="Malloy query documents";class x extends o.AbstractParseTreeVisitor{constructor(E,v){super(),this.parseInfo=E,this.msgLog=v}internalError(E,v){return this.contextError(E,"internal-translator-error",{message:v}),new Error(`Internal Translator Error: ${v}`)}getLocation(E){return{url:this.parseInfo.sourceURL,range:(0,c.rangeFromContext)(this.parseInfo.sourceInfo,E)}}contextError(E,v,S,C){this.msgLog.log((0,a.makeLogMessage)(v,S,{at:this.getLocation(E),...C}))}getNumber(E){return Number.parseInt(E.text)}defaultResult(){return null}getAnnotations(E){const v=E.annotation().map(S=>({value:(0,l.getAnnotationText)(S)}));return v.length>0?v:void 0}getIsAnnotations(E){var v,S;if(E===void 0)return;const T=((v=this.getAnnotations(E._beforeIs))!==null&&v!==void 0?v:[]).concat((S=this.getAnnotations(E._afterIs))!==null&&S!==void 0?S:[]);return T.length>0?T:void 0}notAllowed(E,v){this.illegal(E,`${v} are not allowed in ${p}`)}illegal(E,v){this.contextError(E,"invalid-malloy-query-document",v)}visitMalloyDocument(E){const v=E.malloyStatement();let S;for(const C of v)C.defineSourceStatement()?this.notAllowed(C,"Source definitions"):C.defineQuery()?this.notAllowed(C,"Query definitions"):C.importStatement()?this.notAllowed(C,"Import statements"):C.docAnnotations()?this.notAllowed(C,"Model annotations"):C.ignoredObjectAnnotations()?this.notAllowed(C,"Detatched object annotations"):C.experimentalStatementForTesting()?this.notAllowed(C,"Experimental testing statements"):S===void 0?S=C.runStatement():this.illegal(C,`${p} may only have one run statement`);return S===void 0?(this.illegal(E,`${p} must have a run statement`),null):this.visitRunStatement(S)}visitRunStatement(E){const v=E.topLevelAnonQueryDef(),S=this.getQueryDefinition(v.sqExpr()),C=this.getAnnotations(E.tags()),T=this.getAnnotations(E.topLevelAnonQueryDef().tags()),b=this.combineAnnotations(C,T);return S!==null?{annotations:b,definition:S}:null}getSourceArguments(E){const v=[];for(const S of E.sourceArgument()){const C=S.argumentId();if(C===void 0)return this.contextError(S,"unnamed-source-argument","Source argument must be named"),null;const T=(0,l.getId)(C),b=this.getLiteralIncludingNegativeNumber(S.fieldExpr());if(b===null)return null;v.push({name:T,value:b})}return v}getQueryReference(E){const v=E.sourceArguments(),S=(0,l.getId)(E);if(v){const C=this.getSourceArguments(v);return C===null?null:{name:S,parameters:C}}else return{name:S}}getQueryDefinition(E){if(E instanceof s.SQIDContext){const v=this.getQueryReference(E);if(v!==null)return{kind:"query_reference",...v}}else{if(E instanceof s.SQParensContext)return this.getQueryDefinition(E.sqExpr());if(E instanceof s.SQComposeContext)this.notAllowed(E,"Source compositions");else if(E instanceof s.SQRefinedQueryContext){const v=E.sqExpr(),S=this.getQueryDefinition(v),C=this.getRefinementSegment(E.segExpr());return C===null||S===null?null:(C.kind==="arrow"&&this.notAllowed(E,"Queries against refined queries"),{kind:"refinement",base:S,refinement:C})}else if(E instanceof s.SQExtendedSourceContext)this.notAllowed(E,"Source extensions");else if(E instanceof s.SQIncludeContext)this.notAllowed(E,"Source inclusions");else if(E instanceof s.SQTableContext)this.notAllowed(E,"Table statements");else if(E instanceof s.SQSQLContext)this.notAllowed(E,"SQL statements");else if(E instanceof s.SQArrowContext){const v=E.sqExpr(),S=this.getQueryDefinition(v),C=this.getRefinementSegment(E.segExpr());return C===null||S===null?null:S.kind==="query_reference"?{kind:"arrow",source:{...S,kind:"source_reference"},view:C}:S.kind==="arrow"?{kind:"arrow",source:S.source,view:{kind:"arrow",source:S.view,view:C}}:{kind:"arrow",source:S,view:C}}}return null}getRefinementSegment(E){if(E instanceof s.SegOpsContext){const v=E.queryProperties().queryStatement().flatMap(S=>this.getSegmentOperation(S));return v.some(S=>S===null)?null:{kind:"segment",operations:v}}else if(E instanceof s.SegFieldContext){const{name:v,path:S}=this.getFieldPath(E.fieldPath());return{kind:"view_reference",name:v,path:S}}else{if(E instanceof s.SegParenContext)return this.getViewExpression(E.vExpr());if(E instanceof s.SegRefineContext){const v=this.getRefinementSegment(E._lhs),S=this.getRefinementSegment(E._rhs);return v===null||S===null?null:{kind:"refinement",base:v,refinement:S}}}return null}getGroupByStatement(E){const v=this.getAnnotations(E.tags()),C=E.queryFieldList().queryFieldEntry().map(T=>this.getQueryField(T));return C.some(T=>T===null)||C===null?null:C.map(T=>{var b;const _=[...v??[],...(b=T.field.annotations)!==null&&b!==void 0?b:[]];return{kind:"group_by",name:T.name,field:{...T.field,annotations:_.length>0?_:void 0}}})}getAggregateStatement(E){const v=this.getAnnotations(E.tags()),C=E.queryFieldList().queryFieldEntry().map(T=>this.getQueryField(T));return C.some(T=>T===null)||C===null?null:C.map(T=>{var b;const _=[...v??[],...(b=T.field.annotations)!==null&&b!==void 0?b:[]];return{kind:"aggregate",name:T.name,field:{...T.field,annotations:_.length>0?_:void 0}}})}getOrderByStatement(E){var v,S;const C=E.ordering().orderBySpec(),T=[];for(const b of C){if(b.INTEGER_LITERAL()){this.notAllowed(b,"Indexed order by statements");continue}const _=(S=(v=b.possibleBadPath())===null||v===void 0?void 0:v.badWord())!==null&&S!==void 0?S:[],R=_.length===1?_[0].fieldName():void 0;if(!R)return null;const D=(0,l.getId)(R),w=b.ASC()?"asc":b.DESC()?"desc":void 0;T.push({kind:"order_by",direction:w,field_reference:{name:D}})}return T}getNestStatement(E){const v=this.getAnnotations(E.tags()),S=E.nestedQueryList().nestEntry(),C=[];for(const T of S){if(!(T instanceof s.NestDefContext))return this.internalError(T,"Expected nestDef"),null;const b=this.getAnnotations(T.tags()),_=this.getIsAnnotations(T.isDefine()),R=T.queryName(),D=R?(0,l.getId)(R):void 0,w=this.getViewExpression(T.vExpr());if(w===null)return null;C.push({kind:"nest",name:D,view:{definition:w,annotations:this.combineAnnotations(v,b,_)}})}return C}getViewExpression(E){if(E instanceof s.VSegContext)return this.getRefinementSegment(E.segExpr());if(E instanceof s.VArrowContext){const v=this.getRefinementSegment(E),S=this.getViewExpression(E._rhs);return v===null||S===null?null:{kind:"arrow",source:v,view:S}}else return this.internalError(E,"Unexpected VExpr node"),null}getLimitStatement(E){return{kind:"limit",limit:this.getNumber(E.INTEGER_LITERAL())}}getSegmentOperation(E){if(E.groupByStatement()){const v=E.groupByStatement();return this.getGroupByStatement(v)}else if(E.aggregateStatement()){const v=E.aggregateStatement();return this.getAggregateStatement(v)}else if(E.limitStatement()){const v=E.limitStatement(),S=this.getLimitStatement(v);return S===null?null:[S]}else if(E.declareStatement())this.notAllowed(E,"Declare statements");else if(E.queryJoinStatement())this.notAllowed(E,"Query join statements");else if(E.queryExtend())this.notAllowed(E,"Query extend statements");else if(E.projectStatement())this.notAllowed(E,"Select statements");else if(E.indexStatement())this.notAllowed(E,"Index statements");else if(E.calculateStatement())this.notAllowed(E,"Calculate statements");else if(E.topStatement())this.notAllowed(E,"Top statements");else if(E.orderByStatement()){const v=E.orderByStatement();return this.getOrderByStatement(v)}else if(E.whereStatement()){const v=E.whereStatement(),S=this.getWhere(v);return S===null?null:S.map(C=>({kind:"where",...C}))}else if(E.drillStatement()){const v=E.drillStatement(),S=this.getDrill(v);return S===null?null:S.map(C=>({kind:"drill",...C}))}else if(E.havingStatement()){const v=E.havingStatement(),S=this.getHaving(v);return S===null?null:S.map(C=>({kind:"having",...C}))}else if(E.nestStatement()){const v=E.nestStatement();return this.getNestStatement(v)}else E.sampleStatement()?this.notAllowed(E,"Sample statements"):E.timezoneStatement()?this.notAllowed(E,"Timezone statements"):(E.queryAnnotation()||E.ignoredModelAnnotations())&&this.notAllowed(E,"Detached annotation statements");return null}getFieldPath(E){const v=E.fieldName().map(T=>(0,l.getId)(T)),S=v[v.length-1],C=v.slice(0,-1);return{name:S,path:C.length>0?C:void 0}}getTimeframe(E){const v=E.text;return(0,u.isTimestampUnit)(v)?v:(this.illegal(E,`Invalid timeframe ${v}`),null)}getQueryField(E){if(E.taggedRef()){const v=E.taggedRef(),S=this.getAnnotations(v.tags()),{name:C,path:T}=this.getFieldPath(v.fieldPath());if(v.refExpr()){const b=v.refExpr();if(b.timeframe()){const _=this.getTimeframe(b.timeframe());return _===null?null:{name:void 0,field:{annotations:S,expression:{kind:"time_truncation",field_reference:{name:C,path:T},truncation:_}}}}else b.aggregate()&&this.notAllowed(b,"Aggregate expressions")}else return{name:void 0,field:{annotations:S,expression:{kind:"field_reference",name:C,path:T}}}}else if(E.fieldDef()){const v=E.fieldDef(),S=this.getAnnotations(v.tags()),C=this.getIsAnnotations(v.isDefine()),T=(0,l.getId)(v.fieldNameDef()),b=this.getFieldExpression(v.fieldExpr());return b===null?null:{name:T,field:{expression:b,annotations:this.combineAnnotations(S,C)}}}return null}getFieldExpression(E){if(E instanceof s.ExprFieldPathContext){const{name:v,path:S}=this.getFieldPath(E.fieldPath());return{kind:"field_reference",name:v,path:S}}else if(E instanceof s.ExprTimeTruncContext){const v=this.getTimeframe(E.timeframe()),S=E.fieldExpr(),C=this.getFieldExpression(S);return C===null||v===null?null:C.kind!=="field_reference"?(this.illegal(S,"Left hand side of time truncation must be a field reference"),null):{kind:"time_truncation",truncation:v,field_reference:{name:C.name,path:C.path,parameters:C.parameters}}}else if(E instanceof s.ExprFieldPropsContext){const v=E.fieldExpr(),S=this.getFieldExpression(v);if(S===null)return null;if(S.kind!=="field_reference")return this.illegal(v,"Left hand side of filtered field must be a field reference"),null;const C=E.fieldProperties().fieldPropertyStatement(),T=[];for(const b of C){const _=b.whereStatement();if(_){const R=this.getWhere(_);if(R===null)return null;T.push(...R)}}return{kind:"filtered_field",field_reference:{name:S.name,path:S.path,parameters:S.parameters},where:T}}else{const v=this.getLiteralIncludingNegativeNumber(E);return v===null?null:{kind:"literal_value",literal_value:v}}}stripQuote(E,v){return E.slice(E.indexOf(v)+v.length,E.lastIndexOf(v))}getFilterString(E){const v=E.tripFilterString(),S=E.tickFilterString();if(v){const C=v.BQ3_FILTER(),T=v.DQ3_FILTER(),b=v.SQ3_FILTER();if(C)return this.stripQuote(C.text,"```");if(T)return this.stripQuote(T.text,'"""');if(b)return this.stripQuote(b.text,"'''")}else if(S){const C=S.BQ_FILTER(),T=S.DQ_FILTER(),b=S.SQ_FILTER();if(C)return this.stripQuote(C.text,"`");if(T)return this.stripQuote(T.text,'"');if(b)return this.stripQuote(b.text,"'")}return null}getFilterExpr(E){if(E instanceof s.ExprCompareContext){if(E.compareOp().MATCH()){const v=E.fieldExpr()[0],S=E.fieldExpr()[1];if(v instanceof s.ExprFieldPathContext&&S instanceof s.ExprLiteralContext){const{path:C,name:T}=this.getFieldPath(v.fieldPath()),b=S.literal();if(b instanceof s.FilterString_stubContext){const _=this.getFilterString(b.filterString());return _===null?null:{filter:{kind:"filter_string",expression:{kind:"field_reference",name:T,path:C},filter:_}}}}}else if(E.compareOp().EQ()){const v=E.fieldExpr()[0],S=E.fieldExpr()[1];if(v instanceof s.ExprFieldPathContext){const{path:C,name:T}=this.getFieldPath(v.fieldPath()),b=this.getLiteralIncludingNegativeNumber(S);return b===null?(this.notAllowed(E,"Filters other than comparisons with filter strings or equality with literals"),null):{filter:{kind:"literal_equality",expression:{kind:"field_reference",name:T,path:C},value:b}}}}}return this.notAllowed(E,"Filters other than comparisons with filter strings or equality with literals"),null}getTimeLiteral(E,v){const S=v(E.text);if(!S)return this.contextError(E,"failed-to-parse-time-literal","Time data parse error"),null;const C=S.getValue(),T=C.timeframe,b=C.value;return(0,u.isTimeLiteral)(b)?b.node==="dateLiteral"?T==="hour"||T==="minute"||T==="second"?null:{kind:"date_literal",date_value:b.literal,granularity:T}:{kind:"timestamp_literal",timestamp_value:b.literal,granularity:T,timezone:b.timezone}:null}getLiteralIncludingNegativeNumber(E){if(E instanceof s.ExprLiteralContext)return this.getLiteral(E.literal());if(E instanceof s.ExprMinusContext){const v=E.fieldExpr();if(v instanceof s.ExprLiteralContext){const S=this.getLiteral(v.literal());return S===null||S.kind!=="number_literal"?null:{kind:"number_literal",number_value:-S.number_value}}}return null}getLiteral(E){if(E instanceof s.ExprTimeContext){const v=E.dateLiteral();return v instanceof s.LiteralTimestampContext?this.getTimeLiteral(v,f.LiteralTimestamp.parse):v instanceof s.LiteralHourContext?this.getTimeLiteral(v,f.LiteralHour.parse):v instanceof s.LiteralDayContext?this.getTimeLiteral(v,f.LiteralDay.parse):v instanceof s.LiteralWeekContext?this.getTimeLiteral(v,f.LiteralWeek.parse):v instanceof s.LiteralMonthContext?this.getTimeLiteral(v,f.LiteralMonth.parse):v instanceof s.LiteralQuarterContext?this.getTimeLiteral(v,f.LiteralQuarter.parse):v instanceof s.LiteralYearContext?this.getTimeLiteral(v,f.LiteralYear.parse):null}else{if(E instanceof s.ExprArrayLiteralContext)return this.notAllowed(E,"array literals"),null;if(E instanceof s.ExprLiteralRecordContext)return this.notAllowed(E,"record literals"),null;if(E instanceof s.ExprStringContext){const[v,S]=(0,l.getPlainString)(E);for(const C of S)C instanceof i.ParserRuleContext&&this.contextError(C,"illegal-query-interpolation-outside-sql-block","%{ query } illegal in this string");return{kind:"string_literal",string_value:v??""}}else{if(E instanceof s.ExprBoolContext)return{kind:"boolean_literal",boolean_value:E.TRUE()!==null};if(E instanceof s.ExprNumberContext)return{kind:"number_literal",number_value:Number(E.text)};if(E instanceof s.ExprNULLContext)return{kind:"null_literal"};if(E instanceof s.FilterString_stubContext){const v=E.getChild(0);if(v instanceof s.FilterStringContext){const S=this.getFilterString(v);if(S)return{kind:"filter_expression_literal",filter_expression_value:S}}}}}return null}getDrill(E){const S=E.drillClauseList().fieldExpr().map(C=>this.getFilterExpr(C));return S.some(C=>C===null)?null:S}getWhere(E){const S=E.filterClauseList().fieldExpr().map(C=>this.getFilterExpr(C));return S.some(C=>C===null)?null:S}getHaving(E){const S=E.filterClauseList().fieldExpr().map(C=>this.getFilterExpr(C));return S.some(C=>C===null)?null:S}combineAnnotations(...E){const v=E.flatMap(S=>S??[]);return v.length>0?v:void 0}}ri.MalloyToQuery=x;function m(g){const E=(0,c.getSourceInfo)(g),v=new a.BaseMessageLogger(null),S="internal://query.malloy",C=(0,d.runMalloyParser)(g,S,E,v),b=new x(C,v).visit(C.root),_=(0,h.mapLogs)(v.getLog(),S);if(b===null)return{logs:_};if(!("definition"in b))throw new Error("Expected a query");return{query:b,logs:_}}return ri}var x8;function pT(){return x8||(x8=1,(function(e){Object.defineProperty(e,"__esModule",{value:!0}),e.malloyToQuery=e.exploreQueryWalkerBuilder=e.MalloyTranslation=e.MalloyTranslator=void 0;var t=fz();Object.defineProperty(e,"MalloyTranslator",{enumerable:!0,get:function(){return t.MalloyTranslator}}),Object.defineProperty(e,"MalloyTranslation",{enumerable:!0,get:function(){return t.MalloyTranslation}});var r=hz();Object.defineProperty(e,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return r.exploreQueryWalkerBuilder}});var i=pz();Object.defineProperty(e,"malloyToQuery",{enumerable:!0,get:function(){return i.malloyToQuery}})})(uv)),uv}var sS={},Tm={},f8;function mz(){return f8||(f8=1,Object.defineProperty(Tm,"__esModule",{value:!0}),Tm.EMPTY_BUILD_MANIFEST=void 0,Tm.EMPTY_BUILD_MANIFEST=Object.freeze({entries:Object.freeze({}),strict:!1})),Tm}var jn={},h8;function JE(){if(h8)return jn;h8=1,Object.defineProperty(jn,"__esModule",{value:!0}),jn.FixedConnectionMap=jn.InMemoryURLReader=jn.EmptyURLReader=void 0,jn.hashForInvalidationKey=t,jn.isInternalURL=r,jn.readURL=i,jn.getInvalidationKey=o;const e=_0();function t(u){return(0,e.v5)(u,"76c17e9d-f3ce-5f2d-bfde-98ad3d2a37f6")}function r(u){return u.startsWith("internal://")}async function i(u,d){const c=await u.readURL(d),{contents:h,invalidationKey:f}=typeof c=="string"?{contents:c,invalidationKey:void 0}:c;return{contents:h,invalidationKey:r(d.toString())?null:f??t(h)}}async function o(u,d){return r(d.toString())?null:u.getInvalidationKey!==void 0?await u.getInvalidationKey(d):(await i(u,d)).invalidationKey}class s{async readURL(d){throw new Error("No files.")}async getInvalidationKey(d){throw new Error("No files.")}}jn.EmptyURLReader=s;class a{constructor(d){this.files=d}async readURL(d){const c=this.files.get(d.toString());if(c!==void 0)return Promise.resolve({contents:c,invalidationKey:this.invalidationKey(d,c)});throw new Error(`File not found '${d}'`)}async getInvalidationKey(d){const c=this.files.get(d.toString());if(c!==void 0)return Promise.resolve(this.invalidationKey(d,c));throw new Error(`File not found '${d}'`)}invalidationKey(d,c){return r(d.toString())?null:t(c)}}jn.InMemoryURLReader=a;class l{constructor(d,c){this.connections=d,this.defaultConnectionName=c}async getConnection(d){if(d===void 0)if(this.defaultConnectionName!==void 0)d=this.defaultConnectionName;else throw new Error("No default connection.");const c=this.connections.get(d);if(c!==void 0)return Promise.resolve(c);throw new Error(`No connection found with name ${d}.`)}listConnections(){return Array.from(this.connections.values())}async lookupConnection(d){return this.getConnection(d)}static fromArray(d){return new l(new Map(d.map(c=>[c.name,c])))}}return jn.FixedConnectionMap=l,jn}var Xc={},p8;function gz(){if(p8)return Xc;p8=1,Object.defineProperty(Xc,"__esModule",{value:!0}),Xc.InMemoryModelCache=Xc.CacheManager=void 0;const e=JE();class t{constructor(s){this.modelCache=s,this.modelDependencies=new Map,this.modelInvalidationKeys=new Map}async getCachedModelDef(s,a){const l=this.modelDependencies.get(a);if(l===void 0)return;const u=[a,...r(l)],d={};for(const h of u){const f=this.modelInvalidationKeys.get(h);if(f==null)return;d[h]=f}for(const h of u)if(await(0,e.getInvalidationKey)(s,new URL(h))!==d[h])return;const c=await this.modelCache.getModel(new URL(a));if(c!==void 0){for(const h of u)if(c.invalidationKeys[h]!==d[h])return;return{modelDef:c.modelDef,invalidationKeys:d}}}async setCachedModelDef(s,a){this.modelDependencies.set(s,a.modelDef.dependencies);const l={};for(const d of[s,...r(a.modelDef.dependencies)]){if(a.invalidationKeys[d]===null)return!1;if(a.invalidationKeys[d]===void 0)throw new Error(`Missing invalidation key for dependency ${d}`);this.modelInvalidationKeys.set(d,a.invalidationKeys[d]),l[d]=a.invalidationKeys[d]}return!!await this.modelCache.setModel(new URL(s),{modelDef:a.modelDef,invalidationKeys:l})}}Xc.CacheManager=t;function r(o){return[...Object.keys(o),...Object.values(o).map(r).flat()]}class i{constructor(){this.models=new Map}async getModel(s){return Promise.resolve(this.models.get(s.toString()))}async setModel(s,a){return this.models.set(s.toString(),a),Promise.resolve(!0)}}return Xc.InMemoryModelCache=i,Xc}var En={},m8;function ZP(){if(m8)return En;m8=1,Object.defineProperty(En,"__esModule",{value:!0}),En.DocumentCompletion=En.DocumentSymbol=En.DocumentPosition=En.DocumentRange=En.DocumentTablePath=En.Parse=void 0;class e{constructor(l,u){this.translator=l,this.invalidationKey=u}get symbols(){return(this.translator.metadata().symbols||[]).map(l=>new o(l))}get tablePathInfo(){var l;return((l=this.translator.tablePathInfo().pathInfo)!==null&&l!==void 0?l:[]).map(d=>new t(d))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(l){return(this.translator.completions(l).completions||[]).map(u=>new s(u))}helpContext(l){return this.translator.helpContext(l).helpContext}}En.Parse=e;class t{constructor(l){this._range=r.fromJSON(l.range),this._connectionId=l.connectionId,this._tablePath=l.tablePath}get range(){return this._range}get connectionId(){return this._connectionId}get tablePath(){return this._tablePath}}En.DocumentTablePath=t;class r{constructor(l,u){this._start=l,this._end=u}get start(){return this._start}get end(){return this._end}toJSON(){return{start:this.start.toJSON(),end:this.end.toJSON()}}static fromJSON(l){return new r(new i(l.start.line,l.start.character),new i(l.end.line,l.end.character))}}En.DocumentRange=r;class i{constructor(l,u){this._line=l,this._character=u}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}En.DocumentPosition=i;class o{constructor(l){this._range=r.fromJSON(l.range),this._lensRange=l.lensRange?r.fromJSON(l.lensRange):void 0,this._type=l.type,this._name=l.name,this._children=l.children.map(u=>new o(u))}get range(){return this._range}get lensRange(){var l;return(l=this._lensRange)!==null&&l!==void 0?l:this._range}get type(){return this._type}get name(){return this._name}get children(){return this._children}}En.DocumentSymbol=o;class s{constructor(l){this.type=l.type,this.text=l.text}}return En.DocumentCompletion=s,En}var vt={},g8;function XE(){if(g8)return vt;g8=1,Object.defineProperty(vt,"__esModule",{value:!0}),vt.PreparedResult=vt.PreparedQuery=vt.Given=vt.PersistSource=vt.Model=vt.Reference=vt.ExploreField=vt.QueryField=vt.Query=vt.StringField=vt.UnsupportedField=vt.JSONField=vt.BooleanField=vt.NumberField=vt.TimestampField=vt.DateField=vt.AtomicField=vt.Explore=vt.JoinRelationship=vt.TimestampTimeframe=vt.DateTimeframe=vt.AtomicFieldType=vt.SourceRelationship=void 0,vt.pseudoModelFor=x;const e=jr(),t=Zt(),r=Va(),i=AA(),o=Ks(),s=x9(),a=za(),l=x0(),u=KE(),d=X2(),c=xs(),h=JP();function f(Q){return Q.type==="table"||Q.type==="sql_select"||Q.type==="query_source"}const p="internal://generated-model";function x(Q,M=p,j={}){if(!(0,e.isSourceDef)(Q))throw new Error(`Cannot create pseudo model for struct type ${Q.type}`);const P=(0,t.mkModelDef)("generated_model",M);return P.modelAnnotations=j,P.contents[Q.name]=Q,P}class m{constructor(M,j,P){this._name=M,this._parent=j,this._source=P}get source(){return this._source}get name(){return this._name}get sourceClasses(){const M=[];return this.source&&M.push(this.source.name),M.push(this.name),M}get fieldPath(){const M=[this.name];let j=this._parent;for(;j;)M.unshift(j.name),j=j._parent;return M}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof T}isQuery(){return this instanceof J}}var g;(function(Q){Q.Nested="nested",Q.BaseTable="base_table",Q.Cross="cross",Q.One="one",Q.Many="many",Q.Inline="inline"})(g||(vt.SourceRelationship=g={}));var E;(function(Q){Q.String="string",Q.Number="number",Q.Boolean="boolean",Q.Date="date",Q.Timestamp="timestamp",Q.Timestamptz="timestamptz",Q.Json="json",Q.NativeUnsupported="sql native",Q.Error="error"})(E||(vt.AtomicFieldType=E={}));var v;(function(Q){Q.Day="day",Q.Week="week",Q.Month="month",Q.Quarter="quarter",Q.Year="year"})(v||(vt.DateTimeframe=v={}));var S;(function(Q){Q.Day="day",Q.Week="week",Q.Month="month",Q.Quarter="quarter",Q.Year="year",Q.Second="second",Q.Hour="hour",Q.Minute="minute"})(S||(vt.TimestampTimeframe=S={}));var C;(function(Q){Q.OneToOne="one_to_one",Q.OneToMany="one_to_many",Q.ManyToOne="many_to_one"})(C||(vt.JoinRelationship=C={}));class T extends m{constructor(M,j,P,V){super((0,e.activeName)(j),P,V),this._ownerModelDef=M,this._structDef=j,this._parentExplore=P,this.sourceExplore=V}get _modelDef(){return this._ownerModelDef}get source(){return this.sourceExplore}get referenceSourceID(){return(0,e.isSourceDef)(this._structDef)?this._structDef.referenceID:void 0}referencedSource(){if(!(0,e.isSourceDef)(this._structDef))return;const M=(0,o.sourceNamespaceReference)(this._ownerModelDef,this._structDef);return M?new T(this._ownerModelDef,M.source):void 0}isIntrinsic(){return(0,e.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(M){return(0,l.annotationToTag)(this._structDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this._structDef.annotations,M)}get annotations(){return new l.Annotations(this._structDef.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this._ownerModelDef))}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=this.modelAnnotations.parseAsTag().tag),this.parsedModelTag}get name(){return(0,e.activeName)(this.structDef)}getQueryByName(M){const j=this.sourceStructDef;if(!j)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const P=j.fields.find(Z=>(0,e.activeName)(Z)===M);if(P===void 0)throw new Error(`No such view named \`${M}\``);if(P.type!=="turtle")throw new Error(`\`${M}\` is not a view`);const V={type:"query",structRef:j,pipeline:P.pipeline};return new q(V,this.getSingleExploreModel(),[],M)}getSingleExploreModel(){return new U(this._ownerModelDef,[],[])}get fieldMap(){var M;if(this._fieldMap===void 0){const j=((M=this.source)===null||M===void 0?void 0:M.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(P=>{const V=(0,e.activeName)(P),Z=j.get(P.name);if((0,e.isJoined)(P))return[V,new re(P,this,Z)];if(P.type==="turtle")return[V,new J(P,this,Z)];if(P.type==="string")return[V,new k(P,this,Z)];if(P.type==="number")return[V,new D(P,this,Z)];if(P.type==="date")return P.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(P.timeframe)?[V,new D({...P,type:"number"},this,Z)]:[V,new _(P,this,Z)];if(P.type==="timestamp")return[V,new R(P,this,Z)];if(P.type==="timestamptz")return[V,new R(P,this,Z)];if(P.type==="boolean")return[V,new w(P,this,Z)];if(P.type==="json")return[V,new N(P,this,Z)];if(P.type==="sql native")return[V,new I(P,this,Z)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var M,j,P;if(!this._allFieldsWithOrder){const V=[...((P=(j=(M=this.sourceStructDef)===null||M===void 0?void 0:M.resultMetadata)===null||j===void 0?void 0:j.orderBy)===null||P===void 0?void 0:P.map(ae=>{if(typeof ae.field=="string")return{field:this.fieldMap.get(ae.field),dir:ae.dir};throw new Error("Does not support mapping order by from number.")}))||[]],Z=new Set(V.map(ae=>ae.field.name));this._allFieldsWithOrder=[...V,...this.allFields.filter(ae=>!Z.has(ae.name)).map(ae=>({field:ae,dir:"asc"}))]}return this._allFieldsWithOrder}get intrinsicFields(){return[...this.fieldMap.values()].filter(M=>M.isIntrinsic())}get dimensions(){return[...this.allFieldsWithOrder].filter(M=>M.field.isAtomicField()&&M.field.sourceWasDimension())}getFieldByName(M){const j=this.fieldMap.get(M);if(j===void 0)throw new Error(`No such field ${M}.`);return j}getFieldByNameIfExists(M){return this.fieldMap.get(M)}get primaryKey(){var M;return(M=this.sourceStructDef)===null||M===void 0?void 0:M.primaryKey}get parentExplore(){return this._parentExplore}hasParentExplore(){return this instanceof re}get filters(){var M;return(0,e.isSourceDef)(this.structDef)?((M=this.structDef.resultMetadata)===null||M===void 0?void 0:M.filterList)||[]:[]}get limit(){var M,j;return(j=(M=this.sourceStructDef)===null||M===void 0?void 0:M.resultMetadata)===null||j===void 0?void 0:j.limit}get structDef(){return this._structDef}get queryTimezone(){var M;return(M=this.sourceStructDef)===null||M===void 0?void 0:M.queryTimezone}get sourceStructDef(){if((0,e.isSourceDef)(this.structDef))return this.structDef}toJSON(){var M,j;return{_structDef:this._structDef,modelID:this._ownerModelDef.modelID,modelAnnotations:this._ownerModelDef.modelAnnotations,sourceExplore:(M=this.sourceExplore)===null||M===void 0?void 0:M.toJSON(),_parentExplore:(j=this._parentExplore)===null||j===void 0?void 0:j.toJSON()}}static fromJSON(M){const j=M._parentExplore!==void 0?T.fromJSON(M._parentExplore):void 0,P=M.sourceExplore!==void 0?T.fromJSON(M.sourceExplore):void 0;return new T(x(M._structDef,M.modelID,M.modelAnnotations),M._structDef,j,P)}get location(){return this.structDef.location}collectSourceComponents(M){const j=[];if(M.type==="composite"){for(const P of M.sources)j.push(...this.collectSourceComponents(P));return j}if(f(M)){if(M.type==="table")j.push({type:"table",tableName:M.tablePath,componentID:`${M.connection}:${M.tablePath}`,sourceID:`${M.connection}:${M.tablePath}`});else if(M.type==="sql_select")j.push({type:"sql",selectStatement:M.selectStr,componentID:`${M.connection}:${M.selectStr}`,sourceID:`${M.connection}:${M.selectStr}`});else if(M.type==="query_source"){let P;try{P=new q(M.query,this.getSingleExploreModel(),[]).getPreparedResult().sql}catch(Z){P=`-- Could not compile SQL for query ${M.query.name||"unnamed query"}: ${Z instanceof Error?Z.message:String(Z)}`}const V=`${M.connection}:${P}`;j.push({type:"sql",selectStatement:P,componentID:V,sourceID:V})}}else return[];for(const P of M.fields)(0,e.isJoined)(P)&&j.push(...this.collectSourceComponents(P));return j}getSourceComponents(){const M={};if((0,e.isSourceDef)(this.structDef)){const j=this.collectSourceComponents(this.structDef);for(const P of j)P.componentID?M[P.componentID]=P:P.sourceID&&(M[P.sourceID]=P)}return Object.values(M)}}vt.Explore=T;class b extends m{constructor(M,j,P){super((0,e.activeName)(M),j,P),this.fieldTypeDef=M,this.parent=j}get type(){switch(this.fieldTypeDef.type){case"string":return E.String;case"boolean":return E.Boolean;case"date":return E.Date;case"timestamp":return E.Timestamp;case"timestamptz":return E.Timestamptz;case"number":return E.Number;case"json":return E.Json;case"sql native":return E.NativeUnsupported;case"error":return E.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const M=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${M}`)}}}tagParse(M){return(0,l.annotationToTag)(this.fieldTypeDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.fieldTypeDef.annotations,M)}get annotations(){return new l.Annotations(this.fieldTypeDef.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this.parent._modelDef))}isIntrinsic(){return(0,e.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,e.expressionIsCalculation)(this.fieldTypeDef.expressionType)}get sourceField(){throw new Error}get sourceClasses(){const M=this.fieldTypeDef.name||this.fieldTypeDef.as;return M?[M]:[]}get referenceId(){var M;return(M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.referenceId}sourceWasMeasure(){var M;return((M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.fieldKind)==="measure"}sourceWasMeasureLike(){var M,j;return((M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.fieldKind)==="measure"||((j=this.fieldTypeDef.resultMetadata)===null||j===void 0?void 0:j.fieldKind)==="struct"}sourceWasDimension(){var M;return((M=this.fieldTypeDef.resultMetadata)===null||M===void 0?void 0:M.fieldKind)==="dimension"}hasParentExplore(){return!0}isString(){return this instanceof k}isNumber(){return this instanceof D}isDate(){return this instanceof _}isBoolean(){return this instanceof w}isJSON(){return this instanceof N}isTimestamp(){return this instanceof R}isUnsupported(){return this instanceof I}get parentExplore(){return this.parent}get expression(){const j=this.fieldTypeDef.resultMetadata;return j?.sourceExpression||(j?.sourceField.includes(".")?j?.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}vt.AtomicField=b;class _ extends b{constructor(M,j,P){super(M,j,P),this.fieldDateDef=M}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return v.Day;case"week":return v.Week;case"month":return v.Month;case"quarter":return v.Quarter;case"year":return v.Year}}}vt.DateField=_;class R extends b{constructor(M,j,P){super(M,j,P),this.fieldTimestampDef=M}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return S.Day;case"week":return S.Week;case"month":return S.Month;case"quarter":return S.Quarter;case"year":return S.Year;case"second":return S.Second;case"hour":return S.Hour;case"minute":return S.Minute}}}vt.TimestampField=R;class D extends b{constructor(M,j,P){super(M,j,P),this.fieldNumberDef=M}}vt.NumberField=D;class w extends b{constructor(M,j,P){super(M,j,P),this.fieldBooleanDef=M}}vt.BooleanField=w;class N extends b{constructor(M,j,P){super(M,j,P),this.fieldJSONDef=M}}vt.JSONField=N;class I extends b{constructor(M,j,P){super(M,j,P),this.fieldUnsupportedDef=M}get rawType(){return this.fieldUnsupportedDef.rawType}}vt.UnsupportedField=I;class k extends b{constructor(M,j,P){super(M,j,P),this.fieldStringDef=M}}vt.StringField=k;class $ extends m{constructor(M,j,P){super((0,e.activeName)(M),j,P),this.turtleDef=M}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}tagParse(M){return(0,l.annotationToTag)(this.turtleDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.turtleDef.annotations,M)}get annotations(){return new l.Annotations(this.turtleDef.annotations)}get modelAnnotations(){var M;const j=(M=this._parent)===null||M===void 0?void 0:M._modelDef;return new l.Annotations(j&&(0,e.getModelAnnotations)(j))}}vt.Query=$;class J extends ${constructor(M,j,P){super(M,j,P),this.parent=j}isQueryField(){return!0}isExploreField(){return!1}isAtomicField(){return!1}get sourceClasses(){const M=this.turtleDef.name||this.turtleDef.as;return M?[M]:[]}hasParentExplore(){return!0}get parentExplore(){return this.parent}get expression(){return this.name}}vt.QueryField=J;class re extends T{constructor(M,j,P){super(j._modelDef,M,j,P),this._parentExplore=j}get joinRelationship(){if((0,e.isJoined)(this.structDef))switch(this.structDef.join){case"one":return C.OneToOne;case"many":case"cross":return C.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===C.OneToOne}get isArray(){return this.joinRelationship!==C.OneToOne}tagParse(M){return(0,l.annotationToTag)(this._structDef.annotations,M)}get annotations(){return new l.Annotations(this._structDef.annotations)}isQueryField(){return!1}isExploreField(){return!0}isAtomicField(){return!1}get parentExplore(){return this._parentExplore}get sourceClasses(){const M=this.structDef.name||this.structDef.as;return M?[M]:[]}get queryTimezone(){return(0,e.isRecordOrRepeatedRecord)(this._structDef)?this._structDef.queryTimezone:super.queryTimezone}}vt.ExploreField=re;const ie={fieldReference:"field",joinReference:"join",exploreReference:"explore",queryReference:"query",sqlBlockReference:"sqlBlock",givenReference:"given"};class oe{constructor(M){this._ref=M}get text(){return this._ref.text}get kind(){return ie[this._ref.type]}get location(){return this._ref.location}get definitionLocation(){return this._ref.definition.location}get definitionType(){return this._ref.definition.type}get defaultText(){if(this._ref.type==="givenReference")return this._ref.definition.defaultText}get annotations(){return new l.Annotations(this._ref.definition.annotations)}}vt.Reference=oe;class U{constructor(M,j,P,V,Z){var ae,ce;this.modelDef=M,this.problems=j,this.fromSources=P,this.runtimeContext=Z,this.references=new h.ReferenceList((ae=P[0])!==null&&ae!==void 0?ae:"",(ce=M.references)!==null&&ce!==void 0?ce:[]),this._queryModel=V,this.contentsMap=new Map(Object.entries(M.contents))}getContent(M){return this.contentsMap.get(M)}get queryModel(){return this._queryModel||(this._queryModel=new e.QueryModel(this.modelDef)),this._queryModel}getExistingQueryModel(){return this._queryModel}get givens(){var M,j;const P=new Map,V=this.modelDef.givens;if(!V)return P;for(const[Z,ae]of this.contentsMap){if(ae.type!=="given"||!((j=(M=this.runtimeContext)===null||M===void 0?void 0:M.finalizedGivens)===null||j===void 0)&&j.has(Z))continue;const ce=V[ae.id];ce&&!ce.inline&&P.set(Z,new K(Z,ae.id,ce,this.modelDef))}return P}get _ownModelAnnotations(){var M;return(M=this.modelDef.modelAnnotations[this.modelDef.modelID])===null||M===void 0?void 0:M.ownNotes}tagParse(M){return(0,l.annotationToTag)(this._ownModelAnnotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this._ownModelAnnotations,M)}get annotations(){return new l.Annotations(this._ownModelAnnotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this.modelDef))}referenceAt(M){const j=this.references.find(M);return j?new oe(j):void 0}getReference(M){return this.references.find(M)}getImport(M){var j;return(j=this.modelDef.imports)===null||j===void 0?void 0:j.find(P=>(0,c.locationContainsPosition)(P.location,M))}getPreparedQueryByName(M){const j=this.getContent(M);if(j?.type==="query")return new q(j,this,this.problems,M);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(M){if(M<0)throw new Error(`Invalid index ${M}.`);if(M>=this.modelDef.queryList.length)throw new Error(`Query index ${M} is out of bounds.`);return new q(this.modelDef.queryList[M],this,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new q(this.modelDef.queryList[this.modelDef.queryList.length-1],this,this.problems)}getExploreByName(M){const j=this.getContent(M);if(j&&(0,e.isSourceDef)(j))return new T(this.modelDef,j);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(e.isSourceDef).map(M=>new T(this.modelDef,M))}queries(){const M=[];for(const j of Object.values(this.modelDef.contents))j.type==="query"&&M.push(j.name);return{named:M,unnamed:this.modelDef.queryList.length}}get namedQueries(){const M=j=>j.type==="query";return Object.values(this.modelDef.contents).filter(M)}get exportedExplores(){return this.explores.filter(M=>this.modelDef.exports.includes(M.name))}get _modelDef(){return this.modelDef}getBuildPlan(){if(!this.modelAnnotations.parseAsTag("!").tag.has("experimental","persistence"))throw new Error("Model must have ##! experimental.persistence to use getBuildPlan()");const j=[],P=[];for(const se of Object.values(this.modelDef.contents))(se.type==="query"||(0,e.isSourceDef)(se))&&j.push(...(0,i.findPersistentDependencies)(se,this.modelDef,P));for(const se of this.modelDef.queryList)j.push(...(0,i.findPersistentDependencies)(se,this.modelDef,P));if(j.length===0)return{graphs:[],sources:{},tagParseLog:P};const V=(0,i.minimalBuildGraph)(j),Z={},ae=se=>{for(const fe of se){if(!(fe.sourceID in Z)){const pe=(0,o.resolveSourceID)(this.modelDef,fe.sourceID);pe&&(Z[fe.sourceID]=new ee(new T(this.modelDef,pe),this))}ae(fe.dependsOn)}};ae(V);const ce=new Map;for(const se of V){const fe=Z[se.sourceID];if(!fe)continue;const pe=fe.connectionName;ce.has(pe)||ce.set(pe,[]),ce.get(pe).push(se)}const le=[];for(const[se,fe]of ce)le.push({connectionName:se,nodes:[fe]});return{graphs:le,sources:Z,tagParseLog:P}}}vt.Model=U;class ee{constructor(M,j){this.explore=M,this.model=j;const P=M.structDef;if(!(0,e.isSourceDef)(P))throw new Error("Cannot create PersistSource from non-source type");if(!(0,e.isPersistableSourceDef)(P))throw new Error(`Cannot persist source '${M.name}' of type '${P.type}'. Only query_source and sql_select sources can be persisted.`);this.persistableDef=P}get name(){return this.explore.name}get sourceID(){const M=this.persistableDef.sourceID;if(!M)throw new Error(`PersistSource '${this.name}' has no sourceID. This should not happen - sourceID is set at translation time.`);return M}get _explore(){return this.explore}get annotation(){return this.persistableDef.annotations}tagParse(M){return this.explore.tagParse(M)}getTaglines(M){return this.explore.getTaglines(M)}get annotations(){return this.explore.annotations}get modelAnnotations(){return this.explore.modelAnnotations}get connectionName(){return this.persistableDef.connection}get dialectName(){return this.persistableDef.dialect}get dialect(){return(0,r.getDialect)(this.dialectName)}makeBuildId(M,j){return(0,o.mkBuildID)(M,j)}getSQL(M){const j=this.persistableDef,P=this.model.queryModel;return j.type==="sql_select"?(0,e.getCompiledSQL)(j,M??{},(V,Z)=>P.compileQuery(V,Z,!1).sql):P.compileQuery(j.query,M,!1).sql}get _sourceDef(){return this.persistableDef}get _model(){return this.model}}vt.PersistSource=ee;class K{constructor(M,j,P,V){this.name=M,this.id=j,this._internal=P,this._modelDef=V}get type(){return this._internal.type}get default(){return this._internal.default}get location(){return this._internal.location}tagParse(M){return(0,l.annotationToTag)(this._internal.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this._internal.annotations,M)}get annotations(){return new l.Annotations(this._internal.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this._modelDef))}}vt.Given=K;class te{constructor(M){this.pipelineDef=M}get annotations(){return new l.Annotations(this.pipelineDef.annotations)}get location(){return this.pipelineDef.location}tagParse(M){return(0,l.annotationToTag)(this.pipelineDef.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.pipelineDef.annotations,M)}}class q extends te{constructor(M,j,P,V){super(M),this._model=j,this.problems=P,this.name=V}get _query(){return this.pipelineDef}get _modelDef(){return this._model._modelDef}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this._modelDef))}get preparedResult(){return this.getPreparedResult()}getPreparedResult(M){const j=this._model.queryModel,P=M?.givens?(0,s.resolveSuppliedGivens)(M.givens,this._modelDef):new Map;(0,s.evaluateInlineGivens)(P,this._modelDef);const V={...M,resolvedGivens:P.size>0?P:void 0},Z=j.compileQuery(this._query,V);return new H({...Z,queryName:this.name||Z.queryName},this._modelDef)}get dialect(){const M=this._query.structRef,j=typeof M=="string"?this._model.getContent(M):M;if(j===void 0||!(0,e.isSourceDef)(j))throw new Error("Invalid source for query");return j.dialect}getFlattenedQuery(M){return this}get model(){return this._model}get givens(){const M=new Map,j=this._query.givenUsage;if(!j||j.length===0)return M;const P=new Set(j.map(V=>V.id));for(const[V,Z]of this._model.givens)P.has(Z.id)&&M.set(V,Z);return M}}vt.PreparedQuery=q;class H{constructor(M,j){this.modelDef=j,this.inner=M}static fromJson({query:M,modelDef:j}){if(!M||!j)throw new Error("Missing required properties in JSON data");return new H(M,j)}tagParse(M){return(0,l.annotationToTag)(this.inner.annotations,M)}getTaglines(M){return(0,l.annotationToTaglines)(this.inner.annotations,M)}get annotations(){return new l.Annotations(this.inner.annotations)}get modelAnnotations(){return new l.Annotations((0,e.getModelAnnotations)(this.modelDef))}get annotation(){return this.inner.annotations}get modelAnnotation(){return(0,e.getModelAnnotations)(this.modelDef)}get modelTag(){return new l.Annotations((0,e.getModelAnnotations)(this.modelDef)).parseAsTag().tag}get connectionName(){return this.inner.connectionName}get _rawQuery(){return this.inner}get _modelDef(){return this.modelDef}get sql(){return this.inner.sql}get resultExplore(){if(this.inner.structs.length===0)throw new Error("Malformed query result.");const M=this.inner.structs[this.inner.structs.length-1],j={...M,annotations:this.inner.annotations,name:this.inner.queryName||M.name};try{return new T(this.modelDef,j,this.sourceExplore)}catch{return new T(this.modelDef,j)}}get sourceExplore(){const M=this.inner.sourceExplore,j=(0,e.safeRecordGet)(this.modelDef.contents,M);if(j&&(0,e.isSourceDef)(j))return new T(this.modelDef,j)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceArguments(){return this.inner.sourceArguments}get _sourceFilters(){return this.inner.sourceFilters||[]}get hasSchema(){return this.inner.structs.length>0}toStableResult(M){const j=this.inner.structs,P=j[j.length-1],V={fields:(0,u.convertFieldInfos)(P,P.fields)},Z=(0,u.toStableAnnotations)(this.inner.annotations),ae=P.resultMetadata?(0,u.getResultStructMetadataAnnotation)(P,P.resultMetadata):void 0;ae&&Z.push(ae);const ce=a.Tag.withPrefix("#(malloy) "),le=this.sourceExplore;if(le&&ce.set(["source","name"],le.name),this._sourceArguments){const fe=Object.entries(this._sourceArguments);for(let pe=0;pe<fe.length;pe++){const[ye,Ce]=fe[pe],me=(0,d.nodeToLiteralValue)(Ce.value);me!==void 0&&(0,u.writeLiteralToTag)(ce,["source","parameters",pe,"value"],me),ce.set(["source","parameters",pe,"name"],ye)}}Z.push({value:ce.toString()}),Z.push({value:a.Tag.withPrefix("#(malloy) ").set(["query_name"],this.inner.queryName||P.name).toString()});const se=(0,u.toStableAnnotations)((0,e.getModelAnnotations)(this.modelDef));return{schema:V,data:M,connection_name:this.inner.connectionName,annotations:Z.length>0?Z:void 0,model_annotations:se.length>0?se:void 0,query_timezone:P.queryTimezone,sql:this.inner.sql}}}return vt.PreparedResult=H,vt}var Da={},y8;function ek(){if(y8)return Da;y8=1,Object.defineProperty(Da,"__esModule",{value:!0}),Da.DataRecord=Da.DataArray=Da.Result=void 0;const e=jr(),t=w2(),r=XE();class i extends r.PreparedResult{constructor(N,I){super(N,I),this.inner=N}get _queryResult(){return this.inner}get data(){return new R(this.inner.result,this.resultExplore,void 0,void 0)}get totalRows(){return this.inner.totalRows}get runStats(){return this.inner.runStats}get profilingUrl(){return this.inner.profilingUrl}toJSON(){return this.hasSchema?{queryResult:{...this.inner,result:this.data.toJSON()},modelDef:this._modelDef}:{queryResult:this.inner,modelDef:this._modelDef}}static fromJSON({queryResult:N,modelDef:I}){return new i(N,I)}}Da.Result=i;class o{constructor(N,I,k){this.parent=I,this.parentRecord=k,this._field=N}get field(){return this._field}isString(){return this instanceof a}get string(){if(this.isString())return this;throw new Error("Not a string.")}isBoolean(){return this instanceof u}get boolean(){if(this.isBoolean())return this;throw new Error("Not a boolean.")}isNumber(){return this instanceof c}get number(){if(this.isNumber())return this;throw new Error("Not a number.")}isTimestamp(){return this instanceof h}get timestamp(){if(this.isTimestamp())return this;throw new Error("Not a timestamp.")}isDate(){return this instanceof f}get date(){if(this.isDate())return this;throw new Error("Not a date.")}isNull(){return this instanceof x}isBytes(){return this instanceof p}get bytes(){if(this.isBytes())return this;throw new Error("Not bytes.")}isRecord(){return this instanceof D}get record(){if(this.isRecord())return this;throw new Error("Not a record.")}isUnsupported(){return this instanceof l}get unsupported(){if(this.isUnsupported())return this;throw new Error("Not unsupported.")}isArray(){return this instanceof R}get array(){if(this.isArray())return this;throw new Error("Not an array.")}isArrayOrRecord(){if(this instanceof R||this instanceof D)return this;throw new Error("No Array or Record")}isScalar(){return!0}}class s extends o{constructor(N,I,k,$){super(I,k,$),this._value=N,this._field=I}get value(){return this._value}get field(){return this._field}isScalar(){return this instanceof s}}class a extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return this.value}compareTo(N){return this.value.toLocaleLowerCase().localeCompare(N.value.toLocaleLowerCase())}}class l extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return"<unsupported>"}compareTo(N){return 0}}class u extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return`${this.value}`}compareTo(N){return this.value===N.value?0:this.value?1:-1}}class d extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get field(){return this._field}get key(){return this.value}compareTo(N){const I=this.value.toString(),k=N.toString();return I===k?0:I>k?1:-1}}class c extends s{constructor(N,I,k,$){super((0,t.rowDataToNumber)(N),I,k,$),this._field=I}get field(){return this._field}get key(){return`${this.value}`}compareTo(N){const I=this.value-N.value;return I>0?1:I===0?0:-1}}class h extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get value(){return(0,t.rowDataToDate)(this._value)}get field(){return this._field}get key(){return`${this.value.toLocaleString()}`}compareTo(N){return this.value>N.value?1:this.value<N.value?-1:0}}class f extends s{constructor(N,I,k,$){super(N,I,k,$),this._field=I}get value(){return(0,t.rowDataToDate)(this._value)}get field(){return this._field}get key(){return`${this.value.toLocaleString()}`}compareTo(N){return this.value>N.value?1:this.value<N.value?-1:0}}class p extends s{get key(){return this.value.toString()}compareTo(N){const I=this.value.toString(),k=N.toString();return I===k?0:I>k?1:-1}}class x extends o{get value(){return null}get key(){return"<null>"}}function m(w){const N=(0,t.rowDataToSerializedBigint)(w);if(N.includes(".")||N.includes("e")||N.includes("E"))return(0,t.rowDataToNumber)(w);try{return BigInt(N)}catch{return(0,t.rowDataToNumber)(w)}}function g(w){const N=(0,t.rowDataToSerializedBigint)(w);return N.includes(".")||N.includes("e")||N.includes("E")?(0,t.rowDataToNumber)(w):N}const E={number:t.rowDataToNumber,bigint:m,date:t.rowDataToDate},v={number:t.rowDataToNumber,bigint:g,date:w=>(0,t.rowDataToDate)(w).toISOString()};function S(w,N,I){return w.map(k=>C(k,N,I))}function C(w,N,I){const k={};for(const $ of N.fields){const J=(0,e.activeName)($),re=w[J];k[J]=T(re,$,I)}return k}function T(w,N,I){if(w==null)return null;if(N.type==="number")return N.numberType==="bigint"?I.bigint(w):I.number(w);if(N.type==="date"||N.type==="timestamp"||N.type==="timestamptz")return I.date(w);if(N.type==="string"||N.type==="boolean"||N.type==="json"||N.type==="sql native")return N.type==="boolean"&&typeof w=="number"?w!==0:w;if(N.type==="array"){if(!Array.isArray(w))return w;if((0,e.isRepeatedRecord)(N))return w.map(k=>C(k,N,I));if((0,e.isBasicArray)(N)){const k=N.elementTypeDef;return w.map($=>b($,k,I))}}return N.type==="record"&&typeof w=="object"&&w!==null&&!Array.isArray(w)?C(w,N,I):w}function b(w,N,I){if(w==null)return null;if(N.type==="number")return N.numberType==="bigint"?I.bigint(w):I.number(w);if(N.type==="date"||N.type==="timestamp"||N.type==="timestamptz")return I.date(w);if(N.type==="boolean"&&typeof w=="number")return w!==0;if(N.type==="array"&&Array.isArray(w)){if((0,e.isBasicArray)(N)){const k=N.elementTypeDef;return w.map($=>b($,k,I))}else if((0,e.isRepeatedRecord)(N))return w.map(k=>C(k,N,I))}return w}function _(w,N){for(const I of N)typeof I=="number"?w=w.array.row(I):w=w.record.cell(I);return w}class R extends o{constructor(N,I,k,$){super(I,k,$),this.rowCache=new Map,this.queryData=N,this._field=I}get field(){return this._field}get rawData(){return this.queryData}toObject(){return S(this.queryData,this._field.structDef,E)}toJSON(){return S(this.queryData,this._field.structDef,v)}path(...N){return _(this,N)}row(N){let I=this.rowCache.get(N);return I||(I=new D(this.queryData[N],N,this.field,this,this.parentRecord),this.rowCache.set(N,I)),I}get rowCount(){return this.queryData.length}get value(){return this.toObject()}[Symbol.iterator](){let N=0;const I=this.queryData,k=$=>this.row($);return{next(){return N<I.length?{value:k(N++),done:!1}:{value:void 0,done:!0}}}}async*inMemoryStream(){for(let N=0;N<this.queryData.length;N++)yield this.row(N)}}Da.DataArray=R;class D extends o{constructor(N,I,k,$,J){super(k,$,J),this.cellCache=new Map,this.queryDataRow=N,this._field=k,this.index=I}toObject(){return C(this.queryDataRow,this._field.structDef,E)}toJSON(){return C(this.queryDataRow,this._field.structDef,v)}path(...N){return _(this,N)}cell(N){const I=typeof N=="string"?N:N.name,k=this._field.getFieldByName(I);let $=this.cellCache.get(I);if(!$){const J=this.queryDataRow[I];J===null?$=new x(k,this,this):k.isAtomicField()?k.isBoolean()?$=new u(J,k,this,this):k.isDate()?$=new f(J,k,this,this):k.isJSON()?$=new d(J,k,this,this):k.isTimestamp()?$=new h(J,k,this,this):k.isNumber()?$=new c(J,k,this,this):k.isString()?$=new a(J,k,this,this):k.isUnsupported()&&($=new l(J,k,this,this)):k.isExploreField()&&((0,e.isCompoundArrayData)(J)?$=new R(J,k,this,this):$=new D(J,void 0,k,this,this)),$&&this.cellCache.set(I,$)}if($)return $;throw new Error(`Internal Error: could not construct data column for field '${I}'.`)}get value(){throw new Error("Not implemented;")}get field(){return this._field}[Symbol.iterator](){let N=!1;const I=()=>this;return{next(){return N?{value:void 0,done:!0}:(N=!0,{value:I(),done:!1})}}}}return Da.DataRecord=D,Da}var Na={},E8;function yz(){if(E8)return Na;E8=1,Object.defineProperty(Na,"__esModule",{value:!0}),Na.CSVWriter=Na.JSONWriter=Na.DataWriter=void 0;const e=jr();class t{constructor(s){this.stream=s}}Na.DataWriter=t;class r extends t{async process(s){this.stream.write(`[
1287
1287
  `);for await(const a of s){a.index!==void 0&&a.index>0&&this.stream.write(`,
1288
1288
  `);const u=JSON.stringify(a.toJSON(),null,2).split(`
1289
1289
  `);for(let d=0;d<u.length;d++){const c=u[d];this.stream.write(` ${c}`),d<u.length-1&&this.stream.write(`
@@ -11,7 +11,7 @@
11
11
  href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
12
12
  />
13
13
  <title>Malloy Publisher</title>
14
- <script type="module" crossorigin src="/assets/index-Cr-asgoV.js"></script>
14
+ <script type="module" crossorigin src="/assets/index-D2sm5RBA.js"></script>
15
15
  <link rel="stylesheet" crossorigin href="/assets/index-5eLCcNmP.css">
16
16
  </head>
17
17
  <body>
package/dist/server.mjs CHANGED
@@ -158407,11 +158407,6 @@ var require_utils74 = __commonJS((exports, module) => {
158407
158407
  };
158408
158408
  });
158409
158409
 
158410
- // ../../node_modules/ssh2/lib/protocol/crypto/build/Release/sshcrypto.node
158411
- var require_sshcrypto = __commonJS((exports, module) => {
158412
- module.exports = __require("./sshcrypto-8m50vnmb.node");
158413
- });
158414
-
158415
158410
  // ../../node_modules/ssh2/lib/protocol/crypto/poly1305.js
158416
158411
  var require_poly1305 = __commonJS((exports, module) => {
158417
158412
  var __dirname = "/home/runner/work/publisher/publisher/node_modules/ssh2/lib/protocol/crypto", __filename = "/home/runner/work/publisher/publisher/node_modules/ssh2/lib/protocol/crypto/poly1305.js";
@@ -158898,7 +158893,7 @@ var require_crypto = __commonJS((exports, module) => {
158898
158893
  var ChaChaPolyDecipher;
158899
158894
  var GenericDecipher;
158900
158895
  try {
158901
- binding = require_sshcrypto();
158896
+ binding = (()=>{throw new Error("Cannot require module "+"./crypto/build/Release/sshcrypto.node");})();
158902
158897
  ({
158903
158898
  AESGCMCipher,
158904
158899
  ChaChaPolyCipher,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/server",
3
3
  "description": "Malloy Publisher Server",
4
- "version": "0.0.221",
4
+ "version": "0.0.223",
5
5
  "main": "dist/server.mjs",
6
6
  "bin": {
7
7
  "malloy-publisher": "dist/server.mjs"