@malloydata/render 0.0.237-dev250226000711 → 0.0.238-dev250226004650

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.
@@ -54136,7 +54136,7 @@ sh.exploreQueryWalkerBuilder = wDe;
54136
54136
  var Oe = {}, YS = {};
54137
54137
  Object.defineProperty(YS, "__esModule", { value: !0 });
54138
54138
  YS.MALLOY_VERSION = void 0;
54139
- YS.MALLOY_VERSION = "0.0.237";
54139
+ YS.MALLOY_VERSION = "0.0.238";
54140
54140
  Object.defineProperty(Oe, "__esModule", { value: !0 });
54141
54141
  Oe.InMemoryModelCache = Oe.CacheManager = Oe.CSVWriter = Oe.JSONWriter = Oe.DataWriter = Oe.DataRecord = Oe.DataArray = Oe.Result = Oe.ExploreMaterializer = Oe.PreparedResultMaterializer = Oe.QueryMaterializer = Oe.ModelMaterializer = Oe.SingleConnectionRuntime = Oe.ConnectionRuntime = Oe.Runtime = Oe.ExploreField = Oe.JoinRelationship = Oe.QueryField = Oe.Query = Oe.StringField = Oe.UnsupportedField = Oe.JSONField = Oe.BooleanField = Oe.NumberField = Oe.TimestampField = Oe.DateField = Oe.TimestampTimeframe = Oe.DateTimeframe = Oe.AtomicField = Oe.AtomicFieldType = Oe.Explore = Oe.SourceRelationship = Oe.FixedConnectionMap = Oe.InMemoryURLReader = Oe.EmptyURLReader = Oe.PreparedResult = Oe.DocumentCompletion = Oe.DocumentSymbol = Oe.DocumentPosition = Oe.DocumentRange = Oe.DocumentTablePath = Oe.Parse = Oe.PreparedQuery = Oe.Model = Oe.MalloyError = Oe.Malloy = void 0;
54142
54142
  const bj = CN, tr = Xi, Tj = Gw, FR = Ph, LDe = YS, IDe = mm, bn = ds, Rj = "internal://internal.malloy";
@@ -1271,7 +1271,7 @@ QUERY: ${(0,JQ.inspect)(n,{breakLength:72,depth:1/0})}`)}return XQ.ErrorFactory.
1271
1271
  | ${l}`,u>0&&(i=i+`
1272
1272
  | ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
1273
1273
  `+i,n=s),e!==""?e=`${e}
1274
- ${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().modelDef)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,rDe.isSourceDef)(u)||u.type==="query")&&(n[o]=u)}return n}translate(e){if(this.finalAnswer)return this.finalAnswer;const n=this.translateStep.step(this,e);return n.final&&(this.finalAnswer=n),n}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,xDe.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}n0.MalloyTranslation=JO;class BW extends JO{constructor(e,n){super(e),this.root=n}}n0.MalloyChildTranslator=BW;class ODe extends JO{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new KO.Zone,this.importZone=new KO.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new KO.Zone,this.root=this,this.logger=new IW.BaseMessageLogger(i),r&&this.update(r)}update(e){var n,r,i;this.schemaZone.updateFrom(e.tables,(n=e.errors)===null||n===void 0?void 0:n.tables),this.importZone.updateFrom(e.urls,(r=e.errors)===null||r===void 0?void 0:r.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(i=e.errors)===null||i===void 0?void 0:i.compileSQL);for(const s in e.translations)this.pretranslatedModels.set(s,e.translations[s])}logError(e,n,r){return this.logger.log((0,IW.makeLogMessage)(e,n,{severity:"error",...r})),e}}n0.MalloyTranslator=ODe;function $W(t){return[...Object.keys(t),...Object.keys(t).map(e=>$W(t[e])).flat()]}var mh={};Object.defineProperty(mh,"__esModule",{value:!0}),mh.exploreQueryWalkerBuilder=mh.ExploreQueryWalker=void 0;const FDe=ql;class kW{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(n=>n.range[0]===void 0||n.range[1]===void 0?!1:n.range[0]<=e&&n.range[1]>=e)}filterAtOffset(e){const n=this.exploreQueryAtOffset(e);if(n)return n.filterRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}hasFilterListAtOffset(e){const n=this.exploreQueryAtOffset(e);return n?!!n.filterLists.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}mh.ExploreQueryWalker=kW;function NDe(t,e){const n=new kW(t),r=n;return FDe.ParseTreeWalker.DEFAULT.walk(r,e),n}mh.exploreQueryWalkerBuilder=NDe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=n0;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=mh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(iD);var Oe={},C_={};Object.defineProperty(C_,"__esModule",{value:!0}),C_.MALLOY_VERSION=void 0,C_.MALLOY_VERSION="0.0.237",Object.defineProperty(Oe,"__esModule",{value:!0}),Oe.InMemoryModelCache=Oe.CacheManager=Oe.CSVWriter=Oe.JSONWriter=Oe.DataWriter=Oe.DataRecord=Oe.DataArray=Oe.Result=Oe.ExploreMaterializer=Oe.PreparedResultMaterializer=Oe.QueryMaterializer=Oe.ModelMaterializer=Oe.SingleConnectionRuntime=Oe.ConnectionRuntime=Oe.Runtime=Oe.ExploreField=Oe.JoinRelationship=Oe.QueryField=Oe.Query=Oe.StringField=Oe.UnsupportedField=Oe.JSONField=Oe.BooleanField=Oe.NumberField=Oe.TimestampField=Oe.DateField=Oe.TimestampTimeframe=Oe.DateTimeframe=Oe.AtomicField=Oe.AtomicFieldType=Oe.Explore=Oe.SourceRelationship=Oe.FixedConnectionMap=Oe.InMemoryURLReader=Oe.EmptyURLReader=Oe.PreparedResult=Oe.DocumentCompletion=Oe.DocumentSymbol=Oe.DocumentPosition=Oe.DocumentRange=Oe.DocumentTablePath=Oe.Parse=Oe.PreparedQuery=Oe.Model=Oe.MalloyError=Oe.Malloy=void 0;const PW=iD,rr=Li,MW=K7,XO=Hx,wDe=C_,LDe=K2,Tn=ss,UW="internal://internal.malloy";class Ui{static get version(){return wDe.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(UW));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new PW.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new qW(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return Ui._parse(r,e,i,s);if(n===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return F_(n,e).then(({contents:o,invalidationKey:u})=>Ui._parse(o,e,i,s,u))}static async compile({url:e,source:n,parse:r,urlReader:i,connections:s,model:o,refreshSchemaCache:u,noThrowOnError:a,eventStream:l,replaceMaterializedReferences:c,materializedTablePrefix:f,importBaseURL:d,cacheManager:h}){var p,m,g,y,E;let A;if(u&&(A=typeof u=="number"?u:Date.now()),e===void 0&&n===void 0&&r===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(r!==void 0?e=new URL(r._translator.sourceURL):e=new URL(UW));const v={};if(n===void 0&&h!==void 0){const _=await h.getCachedModelDef(i,e.toString());if(_)return new yh(_.modelDef,[],[e.toString(),...O_(_.modelDef.dependencies)])}d??(d=e);let C;const S=e.toString();if(r!==void 0){C=r._translator;const _=(p=r._invalidationKey)!==null&&p!==void 0?p:await f8(i,e);v[S]=_}else{if(n===void 0){const{contents:_,invalidationKey:b}=await F_(i,e);v[S]=b,n=_}else{const _=await f8(i,e);v[S]=_}C=new PW.MalloyTranslator(S,d.toString(),{urls:{[S]:n}},l)}for(;;){const _=C.translate(o==null?void 0:o._modelDef);if(_.final)if(_.modelDef){await(h==null?void 0:h.setCachedModelDef(e.toString(),{modelDef:_.modelDef,invalidationKeys:v}));for(const b of C.newlyTranslatedDependencies())await(h==null?void 0:h.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new yh(_.modelDef,_.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=_.fromSources)!==null&&g!==void 0?g:[]],b=>C.referenceAt(b),b=>C.importAt(b))}else if(a){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},R=(o==null?void 0:o._modelDef)||b;return new yh(R,_.problems||[],[...(y=o==null?void 0:o.fromSources)!==null&&y!==void 0?y:[],...(E=_.fromSources)!==null&&E!==void 0?E:[]],w=>C.referenceAt(w),w=>C.importAt(w))}else{const b=_.problems||[],R=C.prettyErrors();throw new jW(`Error(s) compiling model:
1274
+ ${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().modelDef)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,rDe.isSourceDef)(u)||u.type==="query")&&(n[o]=u)}return n}translate(e){if(this.finalAnswer)return this.finalAnswer;const n=this.translateStep.step(this,e);return n.final&&(this.finalAnswer=n),n}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,xDe.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}n0.MalloyTranslation=JO;class BW extends JO{constructor(e,n){super(e),this.root=n}}n0.MalloyChildTranslator=BW;class ODe extends JO{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new KO.Zone,this.importZone=new KO.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new KO.Zone,this.root=this,this.logger=new IW.BaseMessageLogger(i),r&&this.update(r)}update(e){var n,r,i;this.schemaZone.updateFrom(e.tables,(n=e.errors)===null||n===void 0?void 0:n.tables),this.importZone.updateFrom(e.urls,(r=e.errors)===null||r===void 0?void 0:r.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(i=e.errors)===null||i===void 0?void 0:i.compileSQL);for(const s in e.translations)this.pretranslatedModels.set(s,e.translations[s])}logError(e,n,r){return this.logger.log((0,IW.makeLogMessage)(e,n,{severity:"error",...r})),e}}n0.MalloyTranslator=ODe;function $W(t){return[...Object.keys(t),...Object.keys(t).map(e=>$W(t[e])).flat()]}var mh={};Object.defineProperty(mh,"__esModule",{value:!0}),mh.exploreQueryWalkerBuilder=mh.ExploreQueryWalker=void 0;const FDe=ql;class kW{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(n=>n.range[0]===void 0||n.range[1]===void 0?!1:n.range[0]<=e&&n.range[1]>=e)}filterAtOffset(e){const n=this.exploreQueryAtOffset(e);if(n)return n.filterRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}hasFilterListAtOffset(e){const n=this.exploreQueryAtOffset(e);return n?!!n.filterLists.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}mh.ExploreQueryWalker=kW;function NDe(t,e){const n=new kW(t),r=n;return FDe.ParseTreeWalker.DEFAULT.walk(r,e),n}mh.exploreQueryWalkerBuilder=NDe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=n0;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=mh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(iD);var Oe={},C_={};Object.defineProperty(C_,"__esModule",{value:!0}),C_.MALLOY_VERSION=void 0,C_.MALLOY_VERSION="0.0.238",Object.defineProperty(Oe,"__esModule",{value:!0}),Oe.InMemoryModelCache=Oe.CacheManager=Oe.CSVWriter=Oe.JSONWriter=Oe.DataWriter=Oe.DataRecord=Oe.DataArray=Oe.Result=Oe.ExploreMaterializer=Oe.PreparedResultMaterializer=Oe.QueryMaterializer=Oe.ModelMaterializer=Oe.SingleConnectionRuntime=Oe.ConnectionRuntime=Oe.Runtime=Oe.ExploreField=Oe.JoinRelationship=Oe.QueryField=Oe.Query=Oe.StringField=Oe.UnsupportedField=Oe.JSONField=Oe.BooleanField=Oe.NumberField=Oe.TimestampField=Oe.DateField=Oe.TimestampTimeframe=Oe.DateTimeframe=Oe.AtomicField=Oe.AtomicFieldType=Oe.Explore=Oe.SourceRelationship=Oe.FixedConnectionMap=Oe.InMemoryURLReader=Oe.EmptyURLReader=Oe.PreparedResult=Oe.DocumentCompletion=Oe.DocumentSymbol=Oe.DocumentPosition=Oe.DocumentRange=Oe.DocumentTablePath=Oe.Parse=Oe.PreparedQuery=Oe.Model=Oe.MalloyError=Oe.Malloy=void 0;const PW=iD,rr=Li,MW=K7,XO=Hx,wDe=C_,LDe=K2,Tn=ss,UW="internal://internal.malloy";class Ui{static get version(){return wDe.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(UW));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new PW.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new qW(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return Ui._parse(r,e,i,s);if(n===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return F_(n,e).then(({contents:o,invalidationKey:u})=>Ui._parse(o,e,i,s,u))}static async compile({url:e,source:n,parse:r,urlReader:i,connections:s,model:o,refreshSchemaCache:u,noThrowOnError:a,eventStream:l,replaceMaterializedReferences:c,materializedTablePrefix:f,importBaseURL:d,cacheManager:h}){var p,m,g,y,E;let A;if(u&&(A=typeof u=="number"?u:Date.now()),e===void 0&&n===void 0&&r===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(r!==void 0?e=new URL(r._translator.sourceURL):e=new URL(UW));const v={};if(n===void 0&&h!==void 0){const _=await h.getCachedModelDef(i,e.toString());if(_)return new yh(_.modelDef,[],[e.toString(),...O_(_.modelDef.dependencies)])}d??(d=e);let C;const S=e.toString();if(r!==void 0){C=r._translator;const _=(p=r._invalidationKey)!==null&&p!==void 0?p:await f8(i,e);v[S]=_}else{if(n===void 0){const{contents:_,invalidationKey:b}=await F_(i,e);v[S]=b,n=_}else{const _=await f8(i,e);v[S]=_}C=new PW.MalloyTranslator(S,d.toString(),{urls:{[S]:n}},l)}for(;;){const _=C.translate(o==null?void 0:o._modelDef);if(_.final)if(_.modelDef){await(h==null?void 0:h.setCachedModelDef(e.toString(),{modelDef:_.modelDef,invalidationKeys:v}));for(const b of C.newlyTranslatedDependencies())await(h==null?void 0:h.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new yh(_.modelDef,_.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=_.fromSources)!==null&&g!==void 0?g:[]],b=>C.referenceAt(b),b=>C.importAt(b))}else if(a){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},R=(o==null?void 0:o._modelDef)||b;return new yh(R,_.problems||[],[...(y=o==null?void 0:o.fromSources)!==null&&y!==void 0?y:[],...(E=_.fromSources)!==null&&E!==void 0?E:[]],w=>C.referenceAt(w),w=>C.importAt(w))}else{const b=_.problems||[],R=C.prettyErrors();throw new jW(`Error(s) compiling model:
1275
1275
  ${R}`,b)}else{if(_.urls)for(const R of _.urls)try{if(N_(R))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(h!==void 0){const q=await h.getCachedModelDef(i,R);if(q){for(const J in q.invalidationKeys)v[J]=q.invalidationKeys[J];C.update({translations:{[R]:q.modelDef}});continue}}const{contents:w,invalidationKey:I}=await F_(i,new URL(R)),P={[R]:w};v[R]=I,C.update({urls:P})}catch(w){C.update({errors:{urls:{[R]:w.message}}})}const{modelAnnotation:b}=C.modelAnnotation(o==null?void 0:o._modelDef);if(_.tables){const R=new Map;for(const w in _.tables){const{connectionName:I,tablePath:P}=_.tables[w],q=R.get(I);q===void 0?R.set(I,{[w]:P}):q[w]=P}for(const[w,I]of R)try{const P=await s.lookupConnection(w),{schemas:q,errors:J}=await Ui.safelyFetchTableSchema(P,I,{refreshTimestamp:A,modelAnnotation:b});C.update({tables:q,errors:{tables:J}})}catch(P){const q={},J={};for(const G in I)J[G]=P.toString();C.update({tables:q,errors:{tables:J}})}}if(_.compileSQL){const R=_.compileSQL,w=R.connection;try{const I=await s.lookupConnection(w),P=Ui.compileSQLBlock(I.dialectName,_.partialModel,R,{replaceMaterializedReferences:c,materializedTablePrefix:f,eventStream:l}),q=await I.fetchSchemaForSQLStruct(P,{refreshTimestamp:A,modelAnnotation:b});q.error&&C.update({errors:{compileSQL:{[P.name]:q.error}}}),q.structDef&&C.update({compileSQL:{[P.name]:q.structDef}})}catch(I){const P={};P[R.name]=I.toString(),C.update({errors:{compileSQL:P}})}}}}}static async safelyFetchTableSchema(e,n,r){const i=await e.fetchSchemaForTables(n,r);for(const s of Object.keys(n))if(i.schemas[s]===void 0&&i.errors[s]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${s} from ${e.dialectName}`);return i}static compileSQLBlock(e,n,r,i){let s,o="",u=!1;for(const c of r.select)if((0,rr.isSegmentSQL)(c))o+=c.sql,u=c.sql.match(/\(\s*$/)!==null;else{if(!s){if(!n)throw new Error("Internal error: Partial model missing when compiling SQL block");s=new rr.QueryModel(n,i==null?void 0:i.eventStream)}const f=s.compileQuery(c,{...i,defaultRowLimit:void 0},!1).sql;o+=u?f:`(${f})`,u=!1}const{name:a,connection:l}=r;return{type:"sql_select",name:a,connection:l,dialect:e,selectStr:o,fields:[]}}static async run({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(!i){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);i=await e.lookupConnection(o)}if(r){const o=await i.runSQL(r.selectStr);return new Wg({structs:[r],sql:r.selectStr,result:o.rows,totalRows:o.totalRows,runStats:o.runStats,lastStageName:r.name,malloy:"",connectionName:r.connection,sourceExplore:"",sourceFilters:[],profilingUrl:o.profilingUrl},{name:"empty_model",exports:[],contents:{},queryList:[],dependencies:{}})}else if(n){const o=await i.runSQL(n.sql,s);return new Wg({...n._rawQuery,result:o.rows,totalRows:o.totalRows,runStats:o.runStats,profilingUrl:o.profilingUrl},n._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(r===void 0&&n===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);if(i===void 0){if(e===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");i=await e.lookupConnection(o)}if(!i.canStream())throw new Error(`Connection '${o}' cannot stream results.`);let u,a;if(r)a=new ys(r),u=r.selectStr;else if(n!==void 0)a=n.resultExplore,u=n.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let l=0;for await(const c of i.runSQLStream(u,s))yield new Df(c,l,a,void 0,void 0),l+=1}static async estimateQueryCost({connections:e,preparedResult:n,sqlStruct:r}){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const i=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName),s=await e.lookupConnection(i);if(r)return await s.estimateQueryCost(r.selectStr);if(n)return await s.estimateQueryCost(n.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}Oe.Malloy=Ui;class jW extends Error{constructor(e,n=[]){super(e),this.problems=n}}Oe.MalloyError=jW;let yh=class{constructor(e,n,r,i=()=>{},s=()=>{}){this.modelDef=e,this.problems=n,this.fromSources=r,this._referenceAt=i,this._importAt=s}tagParse(e){return(0,Tn.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,Tn.annotationToTaglines)(this.modelDef.annotation,e)}getReference(e){return this._referenceAt(e)}getImport(e){return this._importAt(e)}getPreparedQueryByName(e){const n=this.modelDef.contents[e];if((n==null?void 0:n.type)==="query")return new Eh(n,this.modelDef,this.problems,e);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(e){if(e<0)throw new Error(`Invalid index ${e}.`);if(e>=this.modelDef.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new Eh(this.modelDef.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new Eh(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,rr.isSourceDef)(n))return new ys(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(rr.isSourceDef).map(e=>new ys(e))}get namedQueries(){const e=n=>n.type==="query";return Object.values(this.modelDef.contents).filter(e)}get exportedExplores(){return this.explores.filter(e=>this.modelDef.exports.includes(e.name))}get _modelDef(){return this.modelDef}};Oe.Model=yh;class Eh{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=(0,Tn.annotationToTag)(this._modelDef.annotation).tag;return e=(0,Tn.addModelScope)(e,n),(0,Tn.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,Tn.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new rr.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new Qg({...r,queryName:this.name||r.queryName},this._modelDef)}get dialect(){const e=this._query.structRef,n=typeof e=="string"?this._modelDef.contents[e]:e;if(!(0,rr.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}Oe.PreparedQuery=Eh;class qW{constructor(e,n){this.translator=e,this.invalidationKey=n}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new __(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new HW(r))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new zW(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}Oe.Parse=qW;class HW{constructor(e){this._range=Ah.fromJSON(e.range),this._connectionId=e.connectionId,this._tablePath=e.tablePath}get range(){return this._range}get connectionId(){return this._connectionId}get tablePath(){return this._tablePath}}Oe.DocumentTablePath=HW;class Ah{constructor(e,n){this._start=e,this._end=n}get start(){return this._start}get end(){return this._end}toJSON(){return{start:this.start.toJSON(),end:this.end.toJSON()}}static fromJSON(e){return new Ah(new ZO(e.start.line,e.start.character),new ZO(e.end.line,e.end.character))}}Oe.DocumentRange=Ah;class ZO{constructor(e,n){this._line=e,this._character=n}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}Oe.DocumentPosition=ZO;class __{constructor(e){this._range=Ah.fromJSON(e.range),this._lensRange=e.lensRange?Ah.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new __(n))}get range(){return this._range}get lensRange(){var e;return(e=this._lensRange)!==null&&e!==void 0?e:this._range}get type(){return this._type}get name(){return this._name}get children(){return this._children}}Oe.DocumentSymbol=__;class zW{constructor(e){this.type=e.type,this.text=e.text}}Oe.DocumentCompletion=zW;class Qg{constructor(e,n){this.modelDef=n,this.inner=e}static fromJson({query:e,modelDef:n}){if(!e||!n)throw new Error("Missing required properties in JSON data");return new Qg(e,n)}tagParse(e){const n=(0,Tn.annotationToTag)(this.modelDef.annotation).tag;return e=(0,Tn.addModelScope)(e,n),(0,Tn.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,Tn.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,Tn.annotationToTag)(this.modelDef.annotation).tag}get connectionName(){return this.inner.connectionName}get _rawQuery(){return this.inner}get _modelDef(){return this.modelDef}get sql(){return this.inner.sql}get dependenciesToMaterialize(){return this.inner.dependenciesToMaterialize}get materialization(){return this.inner.materialization}get resultExplore(){if(this.inner.structs.length===0)throw new Error("Malformed query result.");const e=this.inner.structs[this.inner.structs.length-1],n={...e,annotation:this.inner.annotation,name:this.inner.queryName||e.name};try{return new ys(n,this.sourceExplore)}catch{return new ys(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n===void 0)throw new Error("Malformed query result.");if((0,rr.isSourceDef)(n))return new ys(n);throw new Error(`'${e} is not an explore`)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}Oe.PreparedResult=Qg;class QW{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}Oe.EmptyURLReader=QW;class IDe{constructor(e){this.files=e}async readURL(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve({contents:n,invalidationKey:this.invalidationKey(e,n)});throw new Error(`File not found '${e}'`)}async getInvalidationKey(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve(this.invalidationKey(e,n));throw new Error(`File not found '${e}'`)}invalidationKey(e,n){return N_(e.toString())?null:oV(n)}}Oe.InMemoryURLReader=IDe;class S_{constructor(e,n){this.connections=e,this.defaultConnectionName=n}async getConnection(e){if(e===void 0)if(this.defaultConnectionName!==void 0)e=this.defaultConnectionName;else throw new Error("No default connection.");const n=this.connections.get(e);if(n!==void 0)return Promise.resolve(n);throw new Error(`No connection found with name ${e}.`)}listConnections(){return Array.from(this.connections.values())}async lookupConnection(e){return this.getConnection(e)}static fromArray(e){return new S_(new Map(e.map(n=>[n.name,n])))}}Oe.FixedConnectionMap=S_;var GW;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(GW||(Oe.SourceRelationship=GW={}));class e8{constructor(e,n,r){this._name=e,this._parent=n,this._source=r}get source(){return this.source}get name(){return this._name}get sourceClasses(){const e=[];return this.source&&e.push(this.source.name),e.push(this.name),e}get fieldPath(){const e=[this.name];let n=this._parent;for(;n;)e.unshift(n.name),n=n._parent;return e}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof ys}isQuery(){return this instanceof u8}}class ys extends e8{constructor(e,n,r){super(e.as||e.name,n,r),this._structDef=e,this._parentExplore=n,this.sourceExplore=r}get source(){return this.sourceExplore}isIntrinsic(){return(0,rr.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,Tn.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,Tn.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,Tn.annotationToTag)(this._structDef.modelAnnotation).tag),this.parsedModelTag}get name(){return this.structDef.as||this.structDef.name}getQueryByName(e){const n=this.sourceStructDef;if(!n)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const r={type:"query",structRef:n,pipeline:[{type:"reduce",queryFields:[{type:"fieldref",path:[e]}]}]};return new Eh(r,this.modelDef,[],e)}get modelDef(){if(!(0,rr.isSourceDef)(this.structDef))throw new Error(`Cannot create pseudo model for struct type ${this.structDef.type}`);return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef},queryList:[],dependencies:{}}}getSingleExploreModel(){return new yh(this.modelDef,[],[])}get fieldMap(){var e;if(this._fieldMap===void 0){const n=((e=this.source)===null||e===void 0?void 0:e.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(r=>{const i=r.as||r.name,s=n.get(r.name);if((0,rr.isJoined)(r))return[i,new a8(r,this,s)];if(r.type==="turtle")return[i,new u8(r,this,s)];if(r.type==="string")return[i,new o8(r,this,s)];if(r.type==="number")return[i,new b_(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new b_({...r,type:"number"},this,s)]:[i,new t8(r,this,s)];if(r.type==="timestamp")return[i,new n8(r,this,s)];if(r.type==="boolean")return[i,new r8(r,this,s)];if(r.type==="json")return[i,new i8(r,this,s)];if(r.type==="sql native")return[i,new s8(r,this,s)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var e,n,r;if(!this._allFieldsWithOrder){const i=[...((r=(n=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||n===void 0?void 0:n.orderBy)===null||r===void 0?void 0:r.map(o=>{if(typeof o.field=="string")return{field:this.fieldMap.get(o.field),dir:o.dir};throw new Error("Does not support mapping order by from number.")}))||[]],s=new Set(i.map(o=>o.field.name));this._allFieldsWithOrder=[...i,...this.allFields.filter(o=>!s.has(o.name)).map(o=>({field:o,dir:"asc"}))]}return this._allFieldsWithOrder}get intrinsicFields(){return[...this.fieldMap.values()].filter(e=>e.isIntrinsic())}get dimensions(){return[...this.allFieldsWithOrder].filter(e=>e.field.isAtomicField()&&e.field.sourceWasDimension())}getFieldByName(e){const n=this.fieldMap.get(e);if(n===void 0)throw new Error(`No such field ${e}.`);return n}getFieldByNameIfExists(e){return this.fieldMap.get(e)}get primaryKey(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.primaryKey}get parentExplore(){return this._parentExplore}hasParentExplore(){return this instanceof a8}get filters(){var e;return(0,rr.isSourceDef)(this.structDef)?((e=this.structDef.resultMetadata)===null||e===void 0?void 0:e.filterList)||[]:[]}get limit(){var e,n;return(n=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||n===void 0?void 0:n.limit}get structDef(){return this._structDef}get queryTimezone(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.queryTimezone}get sourceStructDef(){if((0,rr.isSourceDef)(this.structDef))return this.structDef}toJSON(){var e,n;return{_structDef:this._structDef,sourceExplore:(e=this.sourceExplore)===null||e===void 0?void 0:e.toJSON(),_parentExplore:(n=this._parentExplore)===null||n===void 0?void 0:n.toJSON()}}static fromJSON(e){const n=e._parentExplore!==void 0?ys.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?ys.fromJSON(e.sourceExplore):void 0;return new ys(e._structDef,n,r)}get location(){return this.structDef.location}}Oe.Explore=ys;var Fu;(function(t){t.String="string",t.Number="number",t.Boolean="boolean",t.Date="date",t.Timestamp="timestamp",t.Json="json",t.NativeUnsupported="sql native",t.Error="error"})(Fu||(Oe.AtomicFieldType=Fu={}));class b0 extends e8{constructor(e,n,r){super(e.as||e.name,n,r),this.fieldTypeDef=e,this.parent=n}get type(){switch(this.fieldTypeDef.type){case"string":return Fu.String;case"boolean":return Fu.Boolean;case"date":return Fu.Date;case"timestamp":return Fu.Timestamp;case"number":return Fu.Number;case"json":return Fu.Json;case"sql native":return Fu.NativeUnsupported;case"error":return Fu.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const e=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${e}`)}}}tagParse(e){return e=(0,Tn.addModelScope)(e,this.parent.modelTag),(0,Tn.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,Tn.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,rr.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,rr.expressionIsCalculation)(this.fieldTypeDef.expressionType)}get sourceField(){throw new Error}get sourceClasses(){const e=this.fieldTypeDef.name||this.fieldTypeDef.as;return e?[e]:[]}get referenceId(){var e;return(e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.referenceId}sourceWasMeasure(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"}sourceWasMeasureLike(){var e,n;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"||((n=this.fieldTypeDef.resultMetadata)===null||n===void 0?void 0:n.fieldKind)==="struct"}sourceWasDimension(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="dimension"}hasParentExplore(){return!0}isString(){return this instanceof o8}isNumber(){return this instanceof b_}isDate(){return this instanceof t8}isBoolean(){return this instanceof r8}isJSON(){return this instanceof i8}isTimestamp(){return this instanceof n8}isUnsupported(){return this instanceof s8}get parentExplore(){return this.parent}get expression(){const e=".",n=this.fieldTypeDef.resultMetadata;return(n==null?void 0:n.sourceExpression)||(n!=null&&n.sourceField.includes(e)?n==null?void 0:n.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}Oe.AtomicField=b0;var Rf;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Rf||(Oe.DateTimeframe=Rf={}));var Nu;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year",t.Second="second",t.Hour="hour",t.Minute="minute"})(Nu||(Oe.TimestampTimeframe=Nu={}));class t8 extends b0{constructor(e,n,r){super(e,n,r),this.fieldDateDef=e}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return Rf.Day;case"week":return Rf.Week;case"month":return Rf.Month;case"quarter":return Rf.Quarter;case"year":return Rf.Year}}}Oe.DateField=t8;class n8 extends b0{constructor(e,n,r){super(e,n,r),this.fieldTimestampDef=e}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return Nu.Day;case"week":return Nu.Week;case"month":return Nu.Month;case"quarter":return Nu.Quarter;case"year":return Nu.Year;case"second":return Nu.Second;case"hour":return Nu.Hour;case"minute":return Nu.Minute}}}Oe.TimestampField=n8;class b_ extends b0{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}Oe.NumberField=b_;class r8 extends b0{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}Oe.BooleanField=r8;class i8 extends b0{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}Oe.JSONField=i8;class s8 extends b0{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Oe.UnsupportedField=s8;class o8 extends b0{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}Oe.StringField=o8;class WW extends e8{constructor(e,n,r){super(e.as||e.name,n,r),this.turtleDef=e}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}}Oe.Query=WW;class u8 extends WW{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=(0,Tn.addModelScope)(e,this.parent.modelTag),(0,Tn.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,Tn.annotationToTaglines)(this.turtleDef.annotation,e)}isQueryField(){return!0}isExploreField(){return!1}isAtomicField(){return!1}get sourceClasses(){const e=this.turtleDef.name||this.turtleDef.as;return e?[e]:[]}hasParentExplore(){return!0}get parentExplore(){return this.parent}get expression(){return this.name}}Oe.QueryField=u8;var vh;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(vh||(Oe.JoinRelationship=vh={}));class a8 extends ys{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,rr.isJoined)(this.structDef))switch(this.structDef.join){case"one":return vh.OneToOne;case"many":case"cross":return vh.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===vh.OneToOne}get isArray(){return this.joinRelationship!==vh.OneToOne}tagParse(e){return e=(0,Tn.addModelScope)(e,this._parentExplore.modelTag),(0,Tn.annotationToTag)(this._structDef.annotation,e)}isQueryField(){return!1}isExploreField(){return!0}isAtomicField(){return!1}get parentExplore(){return this._parentExplore}get sourceClasses(){const e=this.structDef.name||this.structDef.as;return e?[e]:[]}}Oe.ExploreField=a8;class l8{constructor({urlReader:e,connections:n,connection:r,eventStream:i,cacheManager:s}){if(this.isTestRuntime=!1,n===void 0){if(r===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");n={lookupConnection:()=>Promise.resolve(r)}}e===void 0&&(e=new QW),this._urlReader=e,this._connections=n,this._eventStream=i,this._cacheManager=s}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};this.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0});const s=e instanceof URL?{url:e}:{source:e};return new Gg(this,async()=>Ui.compile({...s,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:r,noThrowOnError:i,eventStream:this.eventStream,replaceMaterializedReferences:n==null?void 0:n.replaceMaterializedReferences,materializedTablePrefix:n==null?void 0:n.materializedTablePrefix,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,cacheManager:this.cacheManager}),n)}_loadModelFromModelDef(e,n){return new Gg(this,async()=>new yh(e,[],[]),n)}loadQuery(e,n){return this.loadModel(e,n).loadFinalQuery()}loadQueryByIndex(e,n,r){return this.loadModel(e,r).loadQueryByIndex(n,r)}loadQueryByName(e,n,r){return this.loadModel(e,r).loadQueryByName(n,r)}getModel(e,n){return this.loadModel(e,n).getModel()}getQuery(e,n){return this.loadQuery(e,n).getPreparedQuery()}getQueryByIndex(e,n,r){return this.loadQueryByIndex(e,n,r).getPreparedQuery()}getQueryByName(e,n,r){return this.loadQueryByName(e,n,r).getPreparedQuery()}}Oe.Runtime=l8;class BDe extends l8{constructor({urlReader:e,connections:n}){super({connections:S_.fromArray(n),urlReader:e}),this.rawConnections=n}}Oe.ConnectionRuntime=BDe;class $De extends l8{constructor({urlReader:e,connection:n,eventStream:r,cacheManager:i}){super({urlReader:e,eventStream:r,cacheManager:i,connection:n}),this.connection=n}get supportsNesting(){return(0,XO.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,XO.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,XO.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Oe.SingleConnectionRuntime=$De;class T_{constructor(e,n){this.runtime=e,this._materialize=n}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(e,n){return new VW(this.runtime,e,n)}makeExploreMaterializer(e,n){return new KW(this.runtime,e,n)}makePreparedResultMaterializer(e){return new YW(this.runtime,e)}}class Gg extends T_{constructor(e,n,r){super(e,n),this.runtime=e,this.compileQueryOptions=r}loadFinalQuery(e){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...e})}loadQueryByIndex(e,n){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(e),{...this.compileQueryOptions,...n})}loadQueryByName(e,n){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(e),{...this.compileQueryOptions,...n})}loadQuery(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};return this.makeQueryMaterializer(async()=>{const s=this.runtime.urlReader,o=this.runtime.connections;this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0});const u=e instanceof URL?{url:e}:{source:e},a=await this.getModel();return(await Ui.compile({...u,urlReader:s,connections:o,model:a,refreshSchemaCache:r,noThrowOnError:i,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,...this.compileQueryOptions})).preparedQuery})}extendModel(e,n){return this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new Gg(this.runtime,async()=>{const r=this.runtime.urlReader,i=this.runtime.connections,s=e instanceof URL?{url:e}:{source:e},o=await this.getModel();return await Ui.compile({...s,urlReader:r,connections:i,model:o,refreshSchemaCache:n==null?void 0:n.refreshSchemaCache,noThrowOnError:n==null?void 0:n.noThrowOnError,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,...this.compileQueryOptions})},n)}async search(e,n,r=1e3,i=void 0,s){const o=await this.materialize(),u=new rr.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,rr.isSourceDef)(a))throw new Error("Source to be searched was unexpectedly, not a source");const l=a.connection,c=await this.runtime.connections.lookupConnection(l);return await u.searchIndex(c,e,n,r,i)}async searchValueMap(e,n=10,r){const s=(await this.materialize()).getExploreByName(e);if(!(0,rr.isSourceDef)(s.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let o="{index: *}";s.getFieldByNameIfExists("search_index")&&(o="search_index");const u=`
1276
1276
  run: ${e}
1277
1277
  -> ${o}
@@ -55275,7 +55275,7 @@ Uh.exploreQueryWalkerBuilder = F7e;
55275
55275
  var we = {}, Fb = {};
55276
55276
  Object.defineProperty(Fb, "__esModule", { value: !0 });
55277
55277
  Fb.MALLOY_VERSION = void 0;
55278
- Fb.MALLOY_VERSION = "0.0.237";
55278
+ Fb.MALLOY_VERSION = "0.0.238";
55279
55279
  Object.defineProperty(we, "__esModule", { value: !0 });
55280
55280
  we.InMemoryModelCache = we.CacheManager = we.CSVWriter = we.JSONWriter = we.DataWriter = we.DataRecord = we.DataArray = we.Result = we.ExploreMaterializer = we.PreparedResultMaterializer = we.QueryMaterializer = we.ModelMaterializer = we.SingleConnectionRuntime = we.ConnectionRuntime = we.Runtime = we.ExploreField = we.JoinRelationship = we.QueryField = we.Query = we.StringField = we.UnsupportedField = we.JSONField = we.BooleanField = we.NumberField = we.TimestampField = we.DateField = we.TimestampTimeframe = we.DateTimeframe = we.AtomicField = we.AtomicFieldType = we.Explore = we.SourceRelationship = we.FixedConnectionMap = we.InMemoryURLReader = we.EmptyURLReader = we.PreparedResult = we.DocumentCompletion = we.DocumentSymbol = we.DocumentPosition = we.DocumentRange = we.DocumentTablePath = we.Parse = we.PreparedQuery = we.Model = we.MalloyError = we.Malloy = void 0;
55281
55281
  const aq = Jw, or = as, lq = $i, pD = v2, w7e = Fb, N7e = o3, Dn = Cs, cq = "internal://internal.malloy";
@@ -1271,7 +1271,7 @@ QUERY: ${(0,VG.inspect)(n,{breakLength:72,depth:1/0})}`)}return YG.ErrorFactory.
1271
1271
  | ${l}`,u>0&&(i=i+`
1272
1272
  | ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
1273
1273
  `+i,n=s),e!==""?e=`${e}
1274
- ${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().modelDef)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,e7e.isSourceDef)(u)||u.type==="query")&&(n[o]=u)}return n}translate(e){if(this.finalAnswer)return this.finalAnswer;const n=this.translateStep.step(this,e);return n.final&&(this.finalAnswer=n),n}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,l7e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}S0.MalloyTranslation=zF;class NV extends zF{constructor(e,n){super(e),this.root=n}}S0.MalloyChildTranslator=NV;class T7e extends zF{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new HF.Zone,this.importZone=new HF.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new HF.Zone,this.root=this,this.logger=new wV.BaseMessageLogger(i),r&&this.update(r)}update(e){var n,r,i;this.schemaZone.updateFrom(e.tables,(n=e.errors)===null||n===void 0?void 0:n.tables),this.importZone.updateFrom(e.urls,(r=e.errors)===null||r===void 0?void 0:r.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(i=e.errors)===null||i===void 0?void 0:i.compileSQL);for(const s in e.translations)this.pretranslatedModels.set(s,e.translations[s])}logError(e,n,r){return this.logger.log((0,wV.makeLogMessage)(e,n,{severity:"error",...r})),e}}S0.MalloyTranslator=T7e;function LV(t){return[...Object.keys(t),...Object.keys(t).map(e=>LV(t[e])).flat()]}var Vh={};Object.defineProperty(Vh,"__esModule",{value:!0}),Vh.exploreQueryWalkerBuilder=Vh.ExploreQueryWalker=void 0;const R7e=c0;class IV{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(n=>n.range[0]===void 0||n.range[1]===void 0?!1:n.range[0]<=e&&n.range[1]>=e)}filterAtOffset(e){const n=this.exploreQueryAtOffset(e);if(n)return n.filterRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}hasFilterListAtOffset(e){const n=this.exploreQueryAtOffset(e);return n?!!n.filterLists.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}Vh.ExploreQueryWalker=IV;function D7e(t,e){const n=new IV(t),r=n;return R7e.ParseTreeWalker.DEFAULT.walk(r,e),n}Vh.exploreQueryWalkerBuilder=D7e,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=S0;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=Vh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(XD);var we={},ES={};Object.defineProperty(ES,"__esModule",{value:!0}),ES.MALLOY_VERSION=void 0,ES.MALLOY_VERSION="0.0.237",Object.defineProperty(we,"__esModule",{value:!0}),we.InMemoryModelCache=we.CacheManager=we.CSVWriter=we.JSONWriter=we.DataWriter=we.DataRecord=we.DataArray=we.Result=we.ExploreMaterializer=we.PreparedResultMaterializer=we.QueryMaterializer=we.ModelMaterializer=we.SingleConnectionRuntime=we.ConnectionRuntime=we.Runtime=we.ExploreField=we.JoinRelationship=we.QueryField=we.Query=we.StringField=we.UnsupportedField=we.JSONField=we.BooleanField=we.NumberField=we.TimestampField=we.DateField=we.TimestampTimeframe=we.DateTimeframe=we.AtomicField=we.AtomicFieldType=we.Explore=we.SourceRelationship=we.FixedConnectionMap=we.InMemoryURLReader=we.EmptyURLReader=we.PreparedResult=we.DocumentCompletion=we.DocumentSymbol=we.DocumentPosition=we.DocumentRange=we.DocumentTablePath=we.Parse=we.PreparedQuery=we.Model=we.MalloyError=we.Malloy=void 0;const BV=XD,ar=Ui,$V=di,QF=Ad,O7e=ES,F7e=kp,On=ps,kV="internal://internal.malloy";class Wi{static get version(){return O7e.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(kV));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new BV.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new PV(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return Wi._parse(r,e,i,s);if(n===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return RS(n,e).then(({contents:o,invalidationKey:u})=>Wi._parse(o,e,i,s,u))}static async compile({url:e,source:n,parse:r,urlReader:i,connections:s,model:o,refreshSchemaCache:u,noThrowOnError:a,eventStream:l,replaceMaterializedReferences:c,materializedTablePrefix:f,importBaseURL:d,cacheManager:h}){var p,m,g,y,E;let A;if(u&&(A=typeof u=="number"?u:Date.now()),e===void 0&&n===void 0&&r===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(r!==void 0?e=new URL(r._translator.sourceURL):e=new URL(kV));const v={};if(n===void 0&&h!==void 0){const S=await h.getCachedModelDef(i,e.toString());if(S)return new Yh(S.modelDef,[],[e.toString(),...TS(S.modelDef.dependencies)])}d??(d=e);let _;const C=e.toString();if(r!==void 0){_=r._translator;const S=(p=r._invalidationKey)!==null&&p!==void 0?p:await i8(i,e);v[C]=S}else{if(n===void 0){const{contents:S,invalidationKey:b}=await RS(i,e);v[C]=b,n=S}else{const S=await i8(i,e);v[C]=S}_=new BV.MalloyTranslator(C,d.toString(),{urls:{[C]:n}},l)}for(;;){const S=_.translate(o==null?void 0:o._modelDef);if(S.final)if(S.modelDef){await(h==null?void 0:h.setCachedModelDef(e.toString(),{modelDef:S.modelDef,invalidationKeys:v}));for(const b of _.newlyTranslatedDependencies())await(h==null?void 0:h.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new Yh(S.modelDef,S.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=S.fromSources)!==null&&g!==void 0?g:[]],b=>_.referenceAt(b),b=>_.importAt(b))}else if(a){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},R=(o==null?void 0:o._modelDef)||b;return new Yh(R,S.problems||[],[...(y=o==null?void 0:o.fromSources)!==null&&y!==void 0?y:[],...(E=S.fromSources)!==null&&E!==void 0?E:[]],I=>_.referenceAt(I),I=>_.importAt(I))}else{const b=S.problems||[],R=_.prettyErrors();throw new MV(`Error(s) compiling model:
1274
+ ${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().modelDef)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,e7e.isSourceDef)(u)||u.type==="query")&&(n[o]=u)}return n}translate(e){if(this.finalAnswer)return this.finalAnswer;const n=this.translateStep.step(this,e);return n.final&&(this.finalAnswer=n),n}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,l7e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}S0.MalloyTranslation=zF;class NV extends zF{constructor(e,n){super(e),this.root=n}}S0.MalloyChildTranslator=NV;class T7e extends zF{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new HF.Zone,this.importZone=new HF.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new HF.Zone,this.root=this,this.logger=new wV.BaseMessageLogger(i),r&&this.update(r)}update(e){var n,r,i;this.schemaZone.updateFrom(e.tables,(n=e.errors)===null||n===void 0?void 0:n.tables),this.importZone.updateFrom(e.urls,(r=e.errors)===null||r===void 0?void 0:r.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(i=e.errors)===null||i===void 0?void 0:i.compileSQL);for(const s in e.translations)this.pretranslatedModels.set(s,e.translations[s])}logError(e,n,r){return this.logger.log((0,wV.makeLogMessage)(e,n,{severity:"error",...r})),e}}S0.MalloyTranslator=T7e;function LV(t){return[...Object.keys(t),...Object.keys(t).map(e=>LV(t[e])).flat()]}var Vh={};Object.defineProperty(Vh,"__esModule",{value:!0}),Vh.exploreQueryWalkerBuilder=Vh.ExploreQueryWalker=void 0;const R7e=c0;class IV{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(n=>n.range[0]===void 0||n.range[1]===void 0?!1:n.range[0]<=e&&n.range[1]>=e)}filterAtOffset(e){const n=this.exploreQueryAtOffset(e);if(n)return n.filterRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}hasFilterListAtOffset(e){const n=this.exploreQueryAtOffset(e);return n?!!n.filterLists.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}Vh.ExploreQueryWalker=IV;function D7e(t,e){const n=new IV(t),r=n;return R7e.ParseTreeWalker.DEFAULT.walk(r,e),n}Vh.exploreQueryWalkerBuilder=D7e,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=S0;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=Vh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(XD);var we={},ES={};Object.defineProperty(ES,"__esModule",{value:!0}),ES.MALLOY_VERSION=void 0,ES.MALLOY_VERSION="0.0.238",Object.defineProperty(we,"__esModule",{value:!0}),we.InMemoryModelCache=we.CacheManager=we.CSVWriter=we.JSONWriter=we.DataWriter=we.DataRecord=we.DataArray=we.Result=we.ExploreMaterializer=we.PreparedResultMaterializer=we.QueryMaterializer=we.ModelMaterializer=we.SingleConnectionRuntime=we.ConnectionRuntime=we.Runtime=we.ExploreField=we.JoinRelationship=we.QueryField=we.Query=we.StringField=we.UnsupportedField=we.JSONField=we.BooleanField=we.NumberField=we.TimestampField=we.DateField=we.TimestampTimeframe=we.DateTimeframe=we.AtomicField=we.AtomicFieldType=we.Explore=we.SourceRelationship=we.FixedConnectionMap=we.InMemoryURLReader=we.EmptyURLReader=we.PreparedResult=we.DocumentCompletion=we.DocumentSymbol=we.DocumentPosition=we.DocumentRange=we.DocumentTablePath=we.Parse=we.PreparedQuery=we.Model=we.MalloyError=we.Malloy=void 0;const BV=XD,ar=Ui,$V=di,QF=Ad,O7e=ES,F7e=kp,On=ps,kV="internal://internal.malloy";class Wi{static get version(){return O7e.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(kV));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new BV.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new PV(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return Wi._parse(r,e,i,s);if(n===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return RS(n,e).then(({contents:o,invalidationKey:u})=>Wi._parse(o,e,i,s,u))}static async compile({url:e,source:n,parse:r,urlReader:i,connections:s,model:o,refreshSchemaCache:u,noThrowOnError:a,eventStream:l,replaceMaterializedReferences:c,materializedTablePrefix:f,importBaseURL:d,cacheManager:h}){var p,m,g,y,E;let A;if(u&&(A=typeof u=="number"?u:Date.now()),e===void 0&&n===void 0&&r===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(r!==void 0?e=new URL(r._translator.sourceURL):e=new URL(kV));const v={};if(n===void 0&&h!==void 0){const S=await h.getCachedModelDef(i,e.toString());if(S)return new Yh(S.modelDef,[],[e.toString(),...TS(S.modelDef.dependencies)])}d??(d=e);let _;const C=e.toString();if(r!==void 0){_=r._translator;const S=(p=r._invalidationKey)!==null&&p!==void 0?p:await i8(i,e);v[C]=S}else{if(n===void 0){const{contents:S,invalidationKey:b}=await RS(i,e);v[C]=b,n=S}else{const S=await i8(i,e);v[C]=S}_=new BV.MalloyTranslator(C,d.toString(),{urls:{[C]:n}},l)}for(;;){const S=_.translate(o==null?void 0:o._modelDef);if(S.final)if(S.modelDef){await(h==null?void 0:h.setCachedModelDef(e.toString(),{modelDef:S.modelDef,invalidationKeys:v}));for(const b of _.newlyTranslatedDependencies())await(h==null?void 0:h.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new Yh(S.modelDef,S.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=S.fromSources)!==null&&g!==void 0?g:[]],b=>_.referenceAt(b),b=>_.importAt(b))}else if(a){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},R=(o==null?void 0:o._modelDef)||b;return new Yh(R,S.problems||[],[...(y=o==null?void 0:o.fromSources)!==null&&y!==void 0?y:[],...(E=S.fromSources)!==null&&E!==void 0?E:[]],I=>_.referenceAt(I),I=>_.importAt(I))}else{const b=S.problems||[],R=_.prettyErrors();throw new MV(`Error(s) compiling model:
1275
1275
  ${R}`,b)}else{if(S.urls)for(const R of S.urls)try{if(DS(R))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(h!==void 0){const j=await h.getCachedModelDef(i,R);if(j){for(const J in j.invalidationKeys)v[J]=j.invalidationKeys[J];_.update({translations:{[R]:j.modelDef}});continue}}const{contents:I,invalidationKey:L}=await RS(i,new URL(R)),M={[R]:I};v[R]=L,_.update({urls:M})}catch(I){_.update({errors:{urls:{[R]:I.message}}})}const{modelAnnotation:b}=_.modelAnnotation(o==null?void 0:o._modelDef);if(S.tables){const R=new Map;for(const I in S.tables){const{connectionName:L,tablePath:M}=S.tables[I],j=R.get(L);j===void 0?R.set(L,{[I]:M}):j[I]=M}for(const[I,L]of R)try{const M=await s.lookupConnection(I),{schemas:j,errors:J}=await Wi.safelyFetchTableSchema(M,L,{refreshTimestamp:A,modelAnnotation:b});_.update({tables:j,errors:{tables:J}})}catch(M){const j={},J={};for(const Q in L)J[Q]=M.toString();_.update({tables:j,errors:{tables:J}})}}if(S.compileSQL){const R=S.compileSQL,I=R.connection;try{const L=await s.lookupConnection(I),M=Wi.compileSQLBlock(L.dialectName,S.partialModel,R,{replaceMaterializedReferences:c,materializedTablePrefix:f,eventStream:l}),j=await L.fetchSchemaForSQLStruct(M,{refreshTimestamp:A,modelAnnotation:b});j.error&&_.update({errors:{compileSQL:{[M.name]:j.error}}}),j.structDef&&_.update({compileSQL:{[M.name]:j.structDef}})}catch(L){const M={};M[R.name]=L.toString(),_.update({errors:{compileSQL:M}})}}}}}static async safelyFetchTableSchema(e,n,r){const i=await e.fetchSchemaForTables(n,r);for(const s of Object.keys(n))if(i.schemas[s]===void 0&&i.errors[s]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${s} from ${e.dialectName}`);return i}static compileSQLBlock(e,n,r,i){let s,o="",u=!1;for(const c of r.select)if((0,ar.isSegmentSQL)(c))o+=c.sql,u=c.sql.match(/\(\s*$/)!==null;else{if(!s){if(!n)throw new Error("Internal error: Partial model missing when compiling SQL block");s=new ar.QueryModel(n,i==null?void 0:i.eventStream)}const f=s.compileQuery(c,{...i,defaultRowLimit:void 0},!1).sql;o+=u?f:`(${f})`,u=!1}const{name:a,connection:l}=r;return{type:"sql_select",name:a,connection:l,dialect:e,selectStr:o,fields:[]}}static async run({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(!i){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);i=await e.lookupConnection(o)}if(r){const o=await i.runSQL(r.selectStr);return new Im({structs:[r],sql:r.selectStr,result:o.rows,totalRows:o.totalRows,runStats:o.runStats,lastStageName:r.name,malloy:"",connectionName:r.connection,sourceExplore:"",sourceFilters:[],profilingUrl:o.profilingUrl},{name:"empty_model",exports:[],contents:{},queryList:[],dependencies:{}})}else if(n){const o=await i.runSQL(n.sql,s);return new Im({...n._rawQuery,result:o.rows,totalRows:o.totalRows,runStats:o.runStats,profilingUrl:o.profilingUrl},n._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(r===void 0&&n===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);if(i===void 0){if(e===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");i=await e.lookupConnection(o)}if(!i.canStream())throw new Error(`Connection '${o}' cannot stream results.`);let u,a;if(r)a=new Ds(r),u=r.selectStr;else if(n!==void 0)a=n.resultExplore,u=n.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let l=0;for await(const c of i.runSQLStream(u,s))yield new Xf(c,l,a,void 0,void 0),l+=1}static async estimateQueryCost({connections:e,preparedResult:n,sqlStruct:r}){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const i=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName),s=await e.lookupConnection(i);if(r)return await s.estimateQueryCost(r.selectStr);if(n)return await s.estimateQueryCost(n.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}we.Malloy=Wi;class MV extends Error{constructor(e,n=[]){super(e),this.problems=n}}we.MalloyError=MV;let Yh=class{constructor(e,n,r,i=()=>{},s=()=>{}){this.modelDef=e,this.problems=n,this.fromSources=r,this._referenceAt=i,this._importAt=s}tagParse(e){return(0,On.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.modelDef.annotation,e)}getReference(e){return this._referenceAt(e)}getImport(e){return this._importAt(e)}getPreparedQueryByName(e){const n=this.modelDef.contents[e];if((n==null?void 0:n.type)==="query")return new Kh(n,this.modelDef,this.problems,e);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(e){if(e<0)throw new Error(`Invalid index ${e}.`);if(e>=this.modelDef.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new Kh(this.modelDef.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new Kh(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,ar.isSourceDef)(n))return new Ds(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(ar.isSourceDef).map(e=>new Ds(e))}get namedQueries(){const e=n=>n.type==="query";return Object.values(this.modelDef.contents).filter(e)}get exportedExplores(){return this.explores.filter(e=>this.modelDef.exports.includes(e.name))}get _modelDef(){return this.modelDef}};we.Model=Yh;class Kh{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=(0,On.annotationToTag)(this._modelDef.annotation).tag;return e=(0,On.addModelScope)(e,n),(0,On.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new ar.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new Nm({...r,queryName:this.name||r.queryName},this._modelDef)}get dialect(){const e=this._query.structRef,n=typeof e=="string"?this._modelDef.contents[e]:e;if(!(0,ar.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}we.PreparedQuery=Kh;class PV{constructor(e,n){this.translator=e,this.invalidationKey=n}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new AS(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new UV(r))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new jV(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}we.Parse=PV;class UV{constructor(e){this._range=Jh.fromJSON(e.range),this._connectionId=e.connectionId,this._tablePath=e.tablePath}get range(){return this._range}get connectionId(){return this._connectionId}get tablePath(){return this._tablePath}}we.DocumentTablePath=UV;class Jh{constructor(e,n){this._start=e,this._end=n}get start(){return this._start}get end(){return this._end}toJSON(){return{start:this.start.toJSON(),end:this.end.toJSON()}}static fromJSON(e){return new Jh(new GF(e.start.line,e.start.character),new GF(e.end.line,e.end.character))}}we.DocumentRange=Jh;class GF{constructor(e,n){this._line=e,this._character=n}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}we.DocumentPosition=GF;class AS{constructor(e){this._range=Jh.fromJSON(e.range),this._lensRange=e.lensRange?Jh.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new AS(n))}get range(){return this._range}get lensRange(){var e;return(e=this._lensRange)!==null&&e!==void 0?e:this._range}get type(){return this._type}get name(){return this._name}get children(){return this._children}}we.DocumentSymbol=AS;class jV{constructor(e){this.type=e.type,this.text=e.text}}we.DocumentCompletion=jV;class Nm{constructor(e,n){this.modelDef=n,this.inner=e}static fromJson({query:e,modelDef:n}){if(!e||!n)throw new Error("Missing required properties in JSON data");return new Nm(e,n)}tagParse(e){const n=(0,On.annotationToTag)(this.modelDef.annotation).tag;return e=(0,On.addModelScope)(e,n),(0,On.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,On.annotationToTag)(this.modelDef.annotation).tag}get connectionName(){return this.inner.connectionName}get _rawQuery(){return this.inner}get _modelDef(){return this.modelDef}get sql(){return this.inner.sql}get dependenciesToMaterialize(){return this.inner.dependenciesToMaterialize}get materialization(){return this.inner.materialization}get resultExplore(){if(this.inner.structs.length===0)throw new Error("Malformed query result.");const e=this.inner.structs[this.inner.structs.length-1],n={...e,annotation:this.inner.annotation,name:this.inner.queryName||e.name};try{return new Ds(n,this.sourceExplore)}catch{return new Ds(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n===void 0)throw new Error("Malformed query result.");if((0,ar.isSourceDef)(n))return new Ds(n);throw new Error(`'${e} is not an explore`)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}we.PreparedResult=Nm;class qV{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}we.EmptyURLReader=qV;class w7e{constructor(e){this.files=e}async readURL(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve({contents:n,invalidationKey:this.invalidationKey(e,n)});throw new Error(`File not found '${e}'`)}async getInvalidationKey(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve(this.invalidationKey(e,n));throw new Error(`File not found '${e}'`)}invalidationKey(e,n){return DS(e.toString())?null:rY(n)}}we.InMemoryURLReader=w7e;class vS{constructor(e,n){this.connections=e,this.defaultConnectionName=n}async getConnection(e){if(e===void 0)if(this.defaultConnectionName!==void 0)e=this.defaultConnectionName;else throw new Error("No default connection.");const n=this.connections.get(e);if(n!==void 0)return Promise.resolve(n);throw new Error(`No connection found with name ${e}.`)}listConnections(){return Array.from(this.connections.values())}async lookupConnection(e){return this.getConnection(e)}static fromArray(e){return new vS(new Map(e.map(n=>[n.name,n])))}}we.FixedConnectionMap=vS;var HV;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(HV||(we.SourceRelationship=HV={}));class WF{constructor(e,n,r){this._name=e,this._parent=n,this._source=r}get source(){return this.source}get name(){return this._name}get sourceClasses(){const e=[];return this.source&&e.push(this.source.name),e.push(this.name),e}get fieldPath(){const e=[this.name];let n=this._parent;for(;n;)e.unshift(n.name),n=n._parent;return e}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof Ds}isQuery(){return this instanceof e8}}class Ds extends WF{constructor(e,n,r){super(e.as||e.name,n,r),this._structDef=e,this._parentExplore=n,this.sourceExplore=r}get source(){return this.sourceExplore}isIntrinsic(){return(0,ar.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,On.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,On.annotationToTag)(this._structDef.modelAnnotation).tag),this.parsedModelTag}get name(){return this.structDef.as||this.structDef.name}getQueryByName(e){const n=this.sourceStructDef;if(!n)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const r={type:"query",structRef:n,pipeline:[{type:"reduce",queryFields:[{type:"fieldref",path:[e]}]}]};return new Kh(r,this.modelDef,[],e)}get modelDef(){if(!(0,ar.isSourceDef)(this.structDef))throw new Error(`Cannot create pseudo model for struct type ${this.structDef.type}`);return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef},queryList:[],dependencies:{}}}getSingleExploreModel(){return new Yh(this.modelDef,[],[])}get fieldMap(){var e;if(this._fieldMap===void 0){const n=((e=this.source)===null||e===void 0?void 0:e.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(r=>{const i=r.as||r.name,s=n.get(r.name);if((0,ar.isJoined)(r))return[i,new t8(r,this,s)];if(r.type==="turtle")return[i,new e8(r,this,s)];if(r.type==="string")return[i,new ZF(r,this,s)];if(r.type==="number")return[i,new _S(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new _S({...r,type:"number"},this,s)]:[i,new VF(r,this,s)];if(r.type==="timestamp")return[i,new YF(r,this,s)];if(r.type==="boolean")return[i,new KF(r,this,s)];if(r.type==="json")return[i,new JF(r,this,s)];if(r.type==="sql native")return[i,new XF(r,this,s)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var e,n,r;if(!this._allFieldsWithOrder){const i=[...((r=(n=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||n===void 0?void 0:n.orderBy)===null||r===void 0?void 0:r.map(o=>{if(typeof o.field=="string")return{field:this.fieldMap.get(o.field),dir:o.dir};throw new Error("Does not support mapping order by from number.")}))||[]],s=new Set(i.map(o=>o.field.name));this._allFieldsWithOrder=[...i,...this.allFields.filter(o=>!s.has(o.name)).map(o=>({field:o,dir:"asc"}))]}return this._allFieldsWithOrder}get intrinsicFields(){return[...this.fieldMap.values()].filter(e=>e.isIntrinsic())}get dimensions(){return[...this.allFieldsWithOrder].filter(e=>e.field.isAtomicField()&&e.field.sourceWasDimension())}getFieldByName(e){const n=this.fieldMap.get(e);if(n===void 0)throw new Error(`No such field ${e}.`);return n}getFieldByNameIfExists(e){return this.fieldMap.get(e)}get primaryKey(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.primaryKey}get parentExplore(){return this._parentExplore}hasParentExplore(){return this instanceof t8}get filters(){var e;return(0,ar.isSourceDef)(this.structDef)?((e=this.structDef.resultMetadata)===null||e===void 0?void 0:e.filterList)||[]:[]}get limit(){var e,n;return(n=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||n===void 0?void 0:n.limit}get structDef(){return this._structDef}get queryTimezone(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.queryTimezone}get sourceStructDef(){if((0,ar.isSourceDef)(this.structDef))return this.structDef}toJSON(){var e,n;return{_structDef:this._structDef,sourceExplore:(e=this.sourceExplore)===null||e===void 0?void 0:e.toJSON(),_parentExplore:(n=this._parentExplore)===null||n===void 0?void 0:n.toJSON()}}static fromJSON(e){const n=e._parentExplore!==void 0?Ds.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?Ds.fromJSON(e.sourceExplore):void 0;return new Ds(e._structDef,n,r)}get location(){return this.structDef.location}}we.Explore=Ds;var Gu;(function(t){t.String="string",t.Number="number",t.Boolean="boolean",t.Date="date",t.Timestamp="timestamp",t.Json="json",t.NativeUnsupported="sql native",t.Error="error"})(Gu||(we.AtomicFieldType=Gu={}));class W0 extends WF{constructor(e,n,r){super(e.as||e.name,n,r),this.fieldTypeDef=e,this.parent=n}get type(){switch(this.fieldTypeDef.type){case"string":return Gu.String;case"boolean":return Gu.Boolean;case"date":return Gu.Date;case"timestamp":return Gu.Timestamp;case"number":return Gu.Number;case"json":return Gu.Json;case"sql native":return Gu.NativeUnsupported;case"error":return Gu.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const e=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${e}`)}}}tagParse(e){return e=(0,On.addModelScope)(e,this.parent.modelTag),(0,On.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,ar.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,ar.expressionIsCalculation)(this.fieldTypeDef.expressionType)}get sourceField(){throw new Error}get sourceClasses(){const e=this.fieldTypeDef.name||this.fieldTypeDef.as;return e?[e]:[]}get referenceId(){var e;return(e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.referenceId}sourceWasMeasure(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"}sourceWasMeasureLike(){var e,n;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"||((n=this.fieldTypeDef.resultMetadata)===null||n===void 0?void 0:n.fieldKind)==="struct"}sourceWasDimension(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="dimension"}hasParentExplore(){return!0}isString(){return this instanceof ZF}isNumber(){return this instanceof _S}isDate(){return this instanceof VF}isBoolean(){return this instanceof KF}isJSON(){return this instanceof JF}isTimestamp(){return this instanceof YF}isUnsupported(){return this instanceof XF}get parentExplore(){return this.parent}get expression(){const e=".",n=this.fieldTypeDef.resultMetadata;return(n==null?void 0:n.sourceExpression)||(n!=null&&n.sourceField.includes(e)?n==null?void 0:n.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}we.AtomicField=W0;var Jf;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Jf||(we.DateTimeframe=Jf={}));var Wu;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year",t.Second="second",t.Hour="hour",t.Minute="minute"})(Wu||(we.TimestampTimeframe=Wu={}));class VF extends W0{constructor(e,n,r){super(e,n,r),this.fieldDateDef=e}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return Jf.Day;case"week":return Jf.Week;case"month":return Jf.Month;case"quarter":return Jf.Quarter;case"year":return Jf.Year}}}we.DateField=VF;class YF extends W0{constructor(e,n,r){super(e,n,r),this.fieldTimestampDef=e}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return Wu.Day;case"week":return Wu.Week;case"month":return Wu.Month;case"quarter":return Wu.Quarter;case"year":return Wu.Year;case"second":return Wu.Second;case"hour":return Wu.Hour;case"minute":return Wu.Minute}}}we.TimestampField=YF;class _S extends W0{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}we.NumberField=_S;class KF extends W0{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}we.BooleanField=KF;class JF extends W0{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}we.JSONField=JF;class XF extends W0{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}we.UnsupportedField=XF;class ZF extends W0{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}we.StringField=ZF;class zV extends WF{constructor(e,n,r){super(e.as||e.name,n,r),this.turtleDef=e}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}}we.Query=zV;class e8 extends zV{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=(0,On.addModelScope)(e,this.parent.modelTag),(0,On.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.turtleDef.annotation,e)}isQueryField(){return!0}isExploreField(){return!1}isAtomicField(){return!1}get sourceClasses(){const e=this.turtleDef.name||this.turtleDef.as;return e?[e]:[]}hasParentExplore(){return!0}get parentExplore(){return this.parent}get expression(){return this.name}}we.QueryField=e8;var Xh;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(Xh||(we.JoinRelationship=Xh={}));class t8 extends Ds{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,ar.isJoined)(this.structDef))switch(this.structDef.join){case"one":return Xh.OneToOne;case"many":case"cross":return Xh.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===Xh.OneToOne}get isArray(){return this.joinRelationship!==Xh.OneToOne}tagParse(e){return e=(0,On.addModelScope)(e,this._parentExplore.modelTag),(0,On.annotationToTag)(this._structDef.annotation,e)}isQueryField(){return!1}isExploreField(){return!0}isAtomicField(){return!1}get parentExplore(){return this._parentExplore}get sourceClasses(){const e=this.structDef.name||this.structDef.as;return e?[e]:[]}}we.ExploreField=t8;class n8{constructor({urlReader:e,connections:n,connection:r,eventStream:i,cacheManager:s}){if(this.isTestRuntime=!1,n===void 0){if(r===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");n={lookupConnection:()=>Promise.resolve(r)}}e===void 0&&(e=new qV),this._urlReader=e,this._connections=n,this._eventStream=i,this._cacheManager=s}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};this.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0});const s=e instanceof URL?{url:e}:{source:e};return new Lm(this,async()=>Wi.compile({...s,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:r,noThrowOnError:i,eventStream:this.eventStream,replaceMaterializedReferences:n==null?void 0:n.replaceMaterializedReferences,materializedTablePrefix:n==null?void 0:n.materializedTablePrefix,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,cacheManager:this.cacheManager}),n)}_loadModelFromModelDef(e,n){return new Lm(this,async()=>new Yh(e,[],[]),n)}loadQuery(e,n){return this.loadModel(e,n).loadFinalQuery()}loadQueryByIndex(e,n,r){return this.loadModel(e,r).loadQueryByIndex(n,r)}loadQueryByName(e,n,r){return this.loadModel(e,r).loadQueryByName(n,r)}getModel(e,n){return this.loadModel(e,n).getModel()}getQuery(e,n){return this.loadQuery(e,n).getPreparedQuery()}getQueryByIndex(e,n,r){return this.loadQueryByIndex(e,n,r).getPreparedQuery()}getQueryByName(e,n,r){return this.loadQueryByName(e,n,r).getPreparedQuery()}}we.Runtime=n8;class N7e extends n8{constructor({urlReader:e,connections:n}){super({connections:vS.fromArray(n),urlReader:e}),this.rawConnections=n}}we.ConnectionRuntime=N7e;class L7e extends n8{constructor({urlReader:e,connection:n,eventStream:r,cacheManager:i}){super({urlReader:e,eventStream:r,cacheManager:i,connection:n}),this.connection=n}get supportsNesting(){return(0,QF.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,QF.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,QF.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}we.SingleConnectionRuntime=L7e;class CS{constructor(e,n){this.runtime=e,this._materialize=n}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(e,n){return new QV(this.runtime,e,n)}makeExploreMaterializer(e,n){return new WV(this.runtime,e,n)}makePreparedResultMaterializer(e){return new GV(this.runtime,e)}}class Lm extends CS{constructor(e,n,r){super(e,n),this.runtime=e,this.compileQueryOptions=r}loadFinalQuery(e){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...e})}loadQueryByIndex(e,n){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(e),{...this.compileQueryOptions,...n})}loadQueryByName(e,n){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(e),{...this.compileQueryOptions,...n})}loadQuery(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};return this.makeQueryMaterializer(async()=>{const s=this.runtime.urlReader,o=this.runtime.connections;this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0});const u=e instanceof URL?{url:e}:{source:e},a=await this.getModel();return(await Wi.compile({...u,urlReader:s,connections:o,model:a,refreshSchemaCache:r,noThrowOnError:i,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,...this.compileQueryOptions})).preparedQuery})}extendModel(e,n){return this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new Lm(this.runtime,async()=>{const r=this.runtime.urlReader,i=this.runtime.connections,s=e instanceof URL?{url:e}:{source:e},o=await this.getModel();return await Wi.compile({...s,urlReader:r,connections:i,model:o,refreshSchemaCache:n==null?void 0:n.refreshSchemaCache,noThrowOnError:n==null?void 0:n.noThrowOnError,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,...this.compileQueryOptions})},n)}async search(e,n,r=1e3,i=void 0,s){const o=await this.materialize(),u=new ar.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,ar.isSourceDef)(a))throw new Error("Source to be searched was unexpectedly, not a source");const l=a.connection,c=await this.runtime.connections.lookupConnection(l);return await u.searchIndex(c,e,n,r,i)}async searchValueMap(e,n=10,r){const s=(await this.materialize()).getExploreByName(e);if(!(0,ar.isSourceDef)(s.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let o="{index: *}";s.getFieldByNameIfExists("search_index")&&(o="search_index");const u=`
1276
1276
  run: ${e}
1277
1277
  -> ${o}
@@ -55275,7 +55275,7 @@ Uh.exploreQueryWalkerBuilder = F7e;
55275
55275
  var we = {}, Fb = {};
55276
55276
  Object.defineProperty(Fb, "__esModule", { value: !0 });
55277
55277
  Fb.MALLOY_VERSION = void 0;
55278
- Fb.MALLOY_VERSION = "0.0.237";
55278
+ Fb.MALLOY_VERSION = "0.0.238";
55279
55279
  Object.defineProperty(we, "__esModule", { value: !0 });
55280
55280
  we.InMemoryModelCache = we.CacheManager = we.CSVWriter = we.JSONWriter = we.DataWriter = we.DataRecord = we.DataArray = we.Result = we.ExploreMaterializer = we.PreparedResultMaterializer = we.QueryMaterializer = we.ModelMaterializer = we.SingleConnectionRuntime = we.ConnectionRuntime = we.Runtime = we.ExploreField = we.JoinRelationship = we.QueryField = we.Query = we.StringField = we.UnsupportedField = we.JSONField = we.BooleanField = we.NumberField = we.TimestampField = we.DateField = we.TimestampTimeframe = we.DateTimeframe = we.AtomicField = we.AtomicFieldType = we.Explore = we.SourceRelationship = we.FixedConnectionMap = we.InMemoryURLReader = we.EmptyURLReader = we.PreparedResult = we.DocumentCompletion = we.DocumentSymbol = we.DocumentPosition = we.DocumentRange = we.DocumentTablePath = we.Parse = we.PreparedQuery = we.Model = we.MalloyError = we.Malloy = void 0;
55281
55281
  const aq = Jw, or = as, lq = $i, pD = v2, w7e = Fb, N7e = o3, Dn = Cs, cq = "internal://internal.malloy";
@@ -1271,7 +1271,7 @@ QUERY: ${(0,WG.inspect)(n,{breakLength:72,depth:1/0})}`)}return VG.ErrorFactory.
1271
1271
  | ${l}`,u>0&&(i=i+`
1272
1272
  | ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
1273
1273
  `+i,n=s),e!==""?e=`${e}
1274
- ${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().modelDef)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,e7e.isSourceDef)(u)||u.type==="query")&&(n[o]=u)}return n}translate(e){if(this.finalAnswer)return this.finalAnswer;const n=this.translateStep.step(this,e);return n.final&&(this.finalAnswer=n),n}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,l7e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}S0.MalloyTranslation=HF;class wV extends HF{constructor(e,n){super(e),this.root=n}}S0.MalloyChildTranslator=wV;class T7e extends HF{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new qF.Zone,this.importZone=new qF.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new qF.Zone,this.root=this,this.logger=new FV.BaseMessageLogger(i),r&&this.update(r)}update(e){var n,r,i;this.schemaZone.updateFrom(e.tables,(n=e.errors)===null||n===void 0?void 0:n.tables),this.importZone.updateFrom(e.urls,(r=e.errors)===null||r===void 0?void 0:r.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(i=e.errors)===null||i===void 0?void 0:i.compileSQL);for(const s in e.translations)this.pretranslatedModels.set(s,e.translations[s])}logError(e,n,r){return this.logger.log((0,FV.makeLogMessage)(e,n,{severity:"error",...r})),e}}S0.MalloyTranslator=T7e;function NV(t){return[...Object.keys(t),...Object.keys(t).map(e=>NV(t[e])).flat()]}var Vh={};Object.defineProperty(Vh,"__esModule",{value:!0}),Vh.exploreQueryWalkerBuilder=Vh.ExploreQueryWalker=void 0;const R7e=c0;class LV{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(n=>n.range[0]===void 0||n.range[1]===void 0?!1:n.range[0]<=e&&n.range[1]>=e)}filterAtOffset(e){const n=this.exploreQueryAtOffset(e);if(n)return n.filterRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}hasFilterListAtOffset(e){const n=this.exploreQueryAtOffset(e);return n?!!n.filterLists.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}Vh.ExploreQueryWalker=LV;function D7e(t,e){const n=new LV(t),r=n;return R7e.ParseTreeWalker.DEFAULT.walk(r,e),n}Vh.exploreQueryWalkerBuilder=D7e,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=S0;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=Vh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(JD);var we={},yS={};Object.defineProperty(yS,"__esModule",{value:!0}),yS.MALLOY_VERSION=void 0,yS.MALLOY_VERSION="0.0.237",Object.defineProperty(we,"__esModule",{value:!0}),we.InMemoryModelCache=we.CacheManager=we.CSVWriter=we.JSONWriter=we.DataWriter=we.DataRecord=we.DataArray=we.Result=we.ExploreMaterializer=we.PreparedResultMaterializer=we.QueryMaterializer=we.ModelMaterializer=we.SingleConnectionRuntime=we.ConnectionRuntime=we.Runtime=we.ExploreField=we.JoinRelationship=we.QueryField=we.Query=we.StringField=we.UnsupportedField=we.JSONField=we.BooleanField=we.NumberField=we.TimestampField=we.DateField=we.TimestampTimeframe=we.DateTimeframe=we.AtomicField=we.AtomicFieldType=we.Explore=we.SourceRelationship=we.FixedConnectionMap=we.InMemoryURLReader=we.EmptyURLReader=we.PreparedResult=we.DocumentCompletion=we.DocumentSymbol=we.DocumentPosition=we.DocumentRange=we.DocumentTablePath=we.Parse=we.PreparedQuery=we.Model=we.MalloyError=we.Malloy=void 0;const IV=JD,ar=Ui,BV=di,zF=Ad,O7e=yS,F7e=Bp,On=ps,$V="internal://internal.malloy";class Wi{static get version(){return O7e.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL($V));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new IV.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new MV(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return Wi._parse(r,e,i,s);if(n===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return TS(n,e).then(({contents:o,invalidationKey:u})=>Wi._parse(o,e,i,s,u))}static async compile({url:e,source:n,parse:r,urlReader:i,connections:s,model:o,refreshSchemaCache:u,noThrowOnError:a,eventStream:l,replaceMaterializedReferences:c,materializedTablePrefix:f,importBaseURL:d,cacheManager:h}){var p,m,g,y,E;let A;if(u&&(A=typeof u=="number"?u:Date.now()),e===void 0&&n===void 0&&r===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(r!==void 0?e=new URL(r._translator.sourceURL):e=new URL($V));const v={};if(n===void 0&&h!==void 0){const S=await h.getCachedModelDef(i,e.toString());if(S)return new Yh(S.modelDef,[],[e.toString(),...bS(S.modelDef.dependencies)])}d??(d=e);let _;const C=e.toString();if(r!==void 0){_=r._translator;const S=(p=r._invalidationKey)!==null&&p!==void 0?p:await r8(i,e);v[C]=S}else{if(n===void 0){const{contents:S,invalidationKey:b}=await TS(i,e);v[C]=b,n=S}else{const S=await r8(i,e);v[C]=S}_=new IV.MalloyTranslator(C,d.toString(),{urls:{[C]:n}},l)}for(;;){const S=_.translate(o==null?void 0:o._modelDef);if(S.final)if(S.modelDef){await(h==null?void 0:h.setCachedModelDef(e.toString(),{modelDef:S.modelDef,invalidationKeys:v}));for(const b of _.newlyTranslatedDependencies())await(h==null?void 0:h.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new Yh(S.modelDef,S.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=S.fromSources)!==null&&g!==void 0?g:[]],b=>_.referenceAt(b),b=>_.importAt(b))}else if(a){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},R=(o==null?void 0:o._modelDef)||b;return new Yh(R,S.problems||[],[...(y=o==null?void 0:o.fromSources)!==null&&y!==void 0?y:[],...(E=S.fromSources)!==null&&E!==void 0?E:[]],I=>_.referenceAt(I),I=>_.importAt(I))}else{const b=S.problems||[],R=_.prettyErrors();throw new kV(`Error(s) compiling model:
1274
+ ${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().modelDef)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,e7e.isSourceDef)(u)||u.type==="query")&&(n[o]=u)}return n}translate(e){if(this.finalAnswer)return this.finalAnswer;const n=this.translateStep.step(this,e);return n.final&&(this.finalAnswer=n),n}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,l7e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}S0.MalloyTranslation=HF;class wV extends HF{constructor(e,n){super(e),this.root=n}}S0.MalloyChildTranslator=wV;class T7e extends HF{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new qF.Zone,this.importZone=new qF.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new qF.Zone,this.root=this,this.logger=new FV.BaseMessageLogger(i),r&&this.update(r)}update(e){var n,r,i;this.schemaZone.updateFrom(e.tables,(n=e.errors)===null||n===void 0?void 0:n.tables),this.importZone.updateFrom(e.urls,(r=e.errors)===null||r===void 0?void 0:r.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(i=e.errors)===null||i===void 0?void 0:i.compileSQL);for(const s in e.translations)this.pretranslatedModels.set(s,e.translations[s])}logError(e,n,r){return this.logger.log((0,FV.makeLogMessage)(e,n,{severity:"error",...r})),e}}S0.MalloyTranslator=T7e;function NV(t){return[...Object.keys(t),...Object.keys(t).map(e=>NV(t[e])).flat()]}var Vh={};Object.defineProperty(Vh,"__esModule",{value:!0}),Vh.exploreQueryWalkerBuilder=Vh.ExploreQueryWalker=void 0;const R7e=c0;class LV{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(n=>n.range[0]===void 0||n.range[1]===void 0?!1:n.range[0]<=e&&n.range[1]>=e)}filterAtOffset(e){const n=this.exploreQueryAtOffset(e);if(n)return n.filterRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}hasFilterListAtOffset(e){const n=this.exploreQueryAtOffset(e);return n?!!n.filterLists.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}Vh.ExploreQueryWalker=LV;function D7e(t,e){const n=new LV(t),r=n;return R7e.ParseTreeWalker.DEFAULT.walk(r,e),n}Vh.exploreQueryWalkerBuilder=D7e,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=S0;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=Vh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(JD);var we={},yS={};Object.defineProperty(yS,"__esModule",{value:!0}),yS.MALLOY_VERSION=void 0,yS.MALLOY_VERSION="0.0.238",Object.defineProperty(we,"__esModule",{value:!0}),we.InMemoryModelCache=we.CacheManager=we.CSVWriter=we.JSONWriter=we.DataWriter=we.DataRecord=we.DataArray=we.Result=we.ExploreMaterializer=we.PreparedResultMaterializer=we.QueryMaterializer=we.ModelMaterializer=we.SingleConnectionRuntime=we.ConnectionRuntime=we.Runtime=we.ExploreField=we.JoinRelationship=we.QueryField=we.Query=we.StringField=we.UnsupportedField=we.JSONField=we.BooleanField=we.NumberField=we.TimestampField=we.DateField=we.TimestampTimeframe=we.DateTimeframe=we.AtomicField=we.AtomicFieldType=we.Explore=we.SourceRelationship=we.FixedConnectionMap=we.InMemoryURLReader=we.EmptyURLReader=we.PreparedResult=we.DocumentCompletion=we.DocumentSymbol=we.DocumentPosition=we.DocumentRange=we.DocumentTablePath=we.Parse=we.PreparedQuery=we.Model=we.MalloyError=we.Malloy=void 0;const IV=JD,ar=Ui,BV=di,zF=Ad,O7e=yS,F7e=Bp,On=ps,$V="internal://internal.malloy";class Wi{static get version(){return O7e.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL($V));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new IV.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new MV(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return Wi._parse(r,e,i,s);if(n===void 0)throw new Error("Internal Error: urlReader is required.");if(e===void 0)throw new Error("Internal Error: url is required if source not present.");return TS(n,e).then(({contents:o,invalidationKey:u})=>Wi._parse(o,e,i,s,u))}static async compile({url:e,source:n,parse:r,urlReader:i,connections:s,model:o,refreshSchemaCache:u,noThrowOnError:a,eventStream:l,replaceMaterializedReferences:c,materializedTablePrefix:f,importBaseURL:d,cacheManager:h}){var p,m,g,y,E;let A;if(u&&(A=typeof u=="number"?u:Date.now()),e===void 0&&n===void 0&&r===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(r!==void 0?e=new URL(r._translator.sourceURL):e=new URL($V));const v={};if(n===void 0&&h!==void 0){const S=await h.getCachedModelDef(i,e.toString());if(S)return new Yh(S.modelDef,[],[e.toString(),...bS(S.modelDef.dependencies)])}d??(d=e);let _;const C=e.toString();if(r!==void 0){_=r._translator;const S=(p=r._invalidationKey)!==null&&p!==void 0?p:await r8(i,e);v[C]=S}else{if(n===void 0){const{contents:S,invalidationKey:b}=await TS(i,e);v[C]=b,n=S}else{const S=await r8(i,e);v[C]=S}_=new IV.MalloyTranslator(C,d.toString(),{urls:{[C]:n}},l)}for(;;){const S=_.translate(o==null?void 0:o._modelDef);if(S.final)if(S.modelDef){await(h==null?void 0:h.setCachedModelDef(e.toString(),{modelDef:S.modelDef,invalidationKeys:v}));for(const b of _.newlyTranslatedDependencies())await(h==null?void 0:h.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new Yh(S.modelDef,S.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=S.fromSources)!==null&&g!==void 0?g:[]],b=>_.referenceAt(b),b=>_.importAt(b))}else if(a){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},R=(o==null?void 0:o._modelDef)||b;return new Yh(R,S.problems||[],[...(y=o==null?void 0:o.fromSources)!==null&&y!==void 0?y:[],...(E=S.fromSources)!==null&&E!==void 0?E:[]],I=>_.referenceAt(I),I=>_.importAt(I))}else{const b=S.problems||[],R=_.prettyErrors();throw new kV(`Error(s) compiling model:
1275
1275
  ${R}`,b)}else{if(S.urls)for(const R of S.urls)try{if(RS(R))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(h!==void 0){const j=await h.getCachedModelDef(i,R);if(j){for(const J in j.invalidationKeys)v[J]=j.invalidationKeys[J];_.update({translations:{[R]:j.modelDef}});continue}}const{contents:I,invalidationKey:L}=await TS(i,new URL(R)),M={[R]:I};v[R]=L,_.update({urls:M})}catch(I){_.update({errors:{urls:{[R]:I.message}}})}const{modelAnnotation:b}=_.modelAnnotation(o==null?void 0:o._modelDef);if(S.tables){const R=new Map;for(const I in S.tables){const{connectionName:L,tablePath:M}=S.tables[I],j=R.get(L);j===void 0?R.set(L,{[I]:M}):j[I]=M}for(const[I,L]of R)try{const M=await s.lookupConnection(I),{schemas:j,errors:J}=await Wi.safelyFetchTableSchema(M,L,{refreshTimestamp:A,modelAnnotation:b});_.update({tables:j,errors:{tables:J}})}catch(M){const j={},J={};for(const Q in L)J[Q]=M.toString();_.update({tables:j,errors:{tables:J}})}}if(S.compileSQL){const R=S.compileSQL,I=R.connection;try{const L=await s.lookupConnection(I),M=Wi.compileSQLBlock(L.dialectName,S.partialModel,R,{replaceMaterializedReferences:c,materializedTablePrefix:f,eventStream:l}),j=await L.fetchSchemaForSQLStruct(M,{refreshTimestamp:A,modelAnnotation:b});j.error&&_.update({errors:{compileSQL:{[M.name]:j.error}}}),j.structDef&&_.update({compileSQL:{[M.name]:j.structDef}})}catch(L){const M={};M[R.name]=L.toString(),_.update({errors:{compileSQL:M}})}}}}}static async safelyFetchTableSchema(e,n,r){const i=await e.fetchSchemaForTables(n,r);for(const s of Object.keys(n))if(i.schemas[s]===void 0&&i.errors[s]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${s} from ${e.dialectName}`);return i}static compileSQLBlock(e,n,r,i){let s,o="",u=!1;for(const c of r.select)if((0,ar.isSegmentSQL)(c))o+=c.sql,u=c.sql.match(/\(\s*$/)!==null;else{if(!s){if(!n)throw new Error("Internal error: Partial model missing when compiling SQL block");s=new ar.QueryModel(n,i==null?void 0:i.eventStream)}const f=s.compileQuery(c,{...i,defaultRowLimit:void 0},!1).sql;o+=u?f:`(${f})`,u=!1}const{name:a,connection:l}=r;return{type:"sql_select",name:a,connection:l,dialect:e,selectStr:o,fields:[]}}static async run({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(!i){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);i=await e.lookupConnection(o)}if(r){const o=await i.runSQL(r.selectStr);return new Nm({structs:[r],sql:r.selectStr,result:o.rows,totalRows:o.totalRows,runStats:o.runStats,lastStageName:r.name,malloy:"",connectionName:r.connection,sourceExplore:"",sourceFilters:[],profilingUrl:o.profilingUrl},{name:"empty_model",exports:[],contents:{},queryList:[],dependencies:{}})}else if(n){const o=await i.runSQL(n.sql,s);return new Nm({...n._rawQuery,result:o.rows,totalRows:o.totalRows,runStats:o.runStats,profilingUrl:o.profilingUrl},n._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(r===void 0&&n===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);if(i===void 0){if(e===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");i=await e.lookupConnection(o)}if(!i.canStream())throw new Error(`Connection '${o}' cannot stream results.`);let u,a;if(r)a=new Ds(r),u=r.selectStr;else if(n!==void 0)a=n.resultExplore,u=n.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let l=0;for await(const c of i.runSQLStream(u,s))yield new Xf(c,l,a,void 0,void 0),l+=1}static async estimateQueryCost({connections:e,preparedResult:n,sqlStruct:r}){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const i=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName),s=await e.lookupConnection(i);if(r)return await s.estimateQueryCost(r.selectStr);if(n)return await s.estimateQueryCost(n.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}}we.Malloy=Wi;class kV extends Error{constructor(e,n=[]){super(e),this.problems=n}}we.MalloyError=kV;let Yh=class{constructor(e,n,r,i=()=>{},s=()=>{}){this.modelDef=e,this.problems=n,this.fromSources=r,this._referenceAt=i,this._importAt=s}tagParse(e){return(0,On.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.modelDef.annotation,e)}getReference(e){return this._referenceAt(e)}getImport(e){return this._importAt(e)}getPreparedQueryByName(e){const n=this.modelDef.contents[e];if((n==null?void 0:n.type)==="query")return new Kh(n,this.modelDef,this.problems,e);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(e){if(e<0)throw new Error(`Invalid index ${e}.`);if(e>=this.modelDef.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new Kh(this.modelDef.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new Kh(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,ar.isSourceDef)(n))return new Ds(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(ar.isSourceDef).map(e=>new Ds(e))}get namedQueries(){const e=n=>n.type==="query";return Object.values(this.modelDef.contents).filter(e)}get exportedExplores(){return this.explores.filter(e=>this.modelDef.exports.includes(e.name))}get _modelDef(){return this.modelDef}};we.Model=Yh;class Kh{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=(0,On.annotationToTag)(this._modelDef.annotation).tag;return e=(0,On.addModelScope)(e,n),(0,On.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new ar.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new Fm({...r,queryName:this.name||r.queryName},this._modelDef)}get dialect(){const e=this._query.structRef,n=typeof e=="string"?this._modelDef.contents[e]:e;if(!(0,ar.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}we.PreparedQuery=Kh;class MV{constructor(e,n){this.translator=e,this.invalidationKey=n}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new ES(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new PV(r))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new UV(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}we.Parse=MV;class PV{constructor(e){this._range=Jh.fromJSON(e.range),this._connectionId=e.connectionId,this._tablePath=e.tablePath}get range(){return this._range}get connectionId(){return this._connectionId}get tablePath(){return this._tablePath}}we.DocumentTablePath=PV;class Jh{constructor(e,n){this._start=e,this._end=n}get start(){return this._start}get end(){return this._end}toJSON(){return{start:this.start.toJSON(),end:this.end.toJSON()}}static fromJSON(e){return new Jh(new QF(e.start.line,e.start.character),new QF(e.end.line,e.end.character))}}we.DocumentRange=Jh;class QF{constructor(e,n){this._line=e,this._character=n}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}we.DocumentPosition=QF;class ES{constructor(e){this._range=Jh.fromJSON(e.range),this._lensRange=e.lensRange?Jh.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new ES(n))}get range(){return this._range}get lensRange(){var e;return(e=this._lensRange)!==null&&e!==void 0?e:this._range}get type(){return this._type}get name(){return this._name}get children(){return this._children}}we.DocumentSymbol=ES;class UV{constructor(e){this.type=e.type,this.text=e.text}}we.DocumentCompletion=UV;class Fm{constructor(e,n){this.modelDef=n,this.inner=e}static fromJson({query:e,modelDef:n}){if(!e||!n)throw new Error("Missing required properties in JSON data");return new Fm(e,n)}tagParse(e){const n=(0,On.annotationToTag)(this.modelDef.annotation).tag;return e=(0,On.addModelScope)(e,n),(0,On.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,On.annotationToTag)(this.modelDef.annotation).tag}get connectionName(){return this.inner.connectionName}get _rawQuery(){return this.inner}get _modelDef(){return this.modelDef}get sql(){return this.inner.sql}get dependenciesToMaterialize(){return this.inner.dependenciesToMaterialize}get materialization(){return this.inner.materialization}get resultExplore(){if(this.inner.structs.length===0)throw new Error("Malformed query result.");const e=this.inner.structs[this.inner.structs.length-1],n={...e,annotation:this.inner.annotation,name:this.inner.queryName||e.name};try{return new Ds(n,this.sourceExplore)}catch{return new Ds(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n===void 0)throw new Error("Malformed query result.");if((0,ar.isSourceDef)(n))return new Ds(n);throw new Error(`'${e} is not an explore`)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}we.PreparedResult=Fm;class jV{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}we.EmptyURLReader=jV;class w7e{constructor(e){this.files=e}async readURL(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve({contents:n,invalidationKey:this.invalidationKey(e,n)});throw new Error(`File not found '${e}'`)}async getInvalidationKey(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve(this.invalidationKey(e,n));throw new Error(`File not found '${e}'`)}invalidationKey(e,n){return RS(e.toString())?null:nY(n)}}we.InMemoryURLReader=w7e;class AS{constructor(e,n){this.connections=e,this.defaultConnectionName=n}async getConnection(e){if(e===void 0)if(this.defaultConnectionName!==void 0)e=this.defaultConnectionName;else throw new Error("No default connection.");const n=this.connections.get(e);if(n!==void 0)return Promise.resolve(n);throw new Error(`No connection found with name ${e}.`)}listConnections(){return Array.from(this.connections.values())}async lookupConnection(e){return this.getConnection(e)}static fromArray(e){return new AS(new Map(e.map(n=>[n.name,n])))}}we.FixedConnectionMap=AS;var qV;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(qV||(we.SourceRelationship=qV={}));class GF{constructor(e,n,r){this._name=e,this._parent=n,this._source=r}get source(){return this.source}get name(){return this._name}get sourceClasses(){const e=[];return this.source&&e.push(this.source.name),e.push(this.name),e}get fieldPath(){const e=[this.name];let n=this._parent;for(;n;)e.unshift(n.name),n=n._parent;return e}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof Ds}isQuery(){return this instanceof ZF}}class Ds extends GF{constructor(e,n,r){super(e.as||e.name,n,r),this._structDef=e,this._parentExplore=n,this.sourceExplore=r}get source(){return this.sourceExplore}isIntrinsic(){return(0,ar.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,On.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,On.annotationToTag)(this._structDef.modelAnnotation).tag),this.parsedModelTag}get name(){return this.structDef.as||this.structDef.name}getQueryByName(e){const n=this.sourceStructDef;if(!n)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const r={type:"query",structRef:n,pipeline:[{type:"reduce",queryFields:[{type:"fieldref",path:[e]}]}]};return new Kh(r,this.modelDef,[],e)}get modelDef(){if(!(0,ar.isSourceDef)(this.structDef))throw new Error(`Cannot create pseudo model for struct type ${this.structDef.type}`);return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef},queryList:[],dependencies:{}}}getSingleExploreModel(){return new Yh(this.modelDef,[],[])}get fieldMap(){var e;if(this._fieldMap===void 0){const n=((e=this.source)===null||e===void 0?void 0:e.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(r=>{const i=r.as||r.name,s=n.get(r.name);if((0,ar.isJoined)(r))return[i,new e8(r,this,s)];if(r.type==="turtle")return[i,new ZF(r,this,s)];if(r.type==="string")return[i,new XF(r,this,s)];if(r.type==="number")return[i,new vS(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new vS({...r,type:"number"},this,s)]:[i,new WF(r,this,s)];if(r.type==="timestamp")return[i,new VF(r,this,s)];if(r.type==="boolean")return[i,new YF(r,this,s)];if(r.type==="json")return[i,new KF(r,this,s)];if(r.type==="sql native")return[i,new JF(r,this,s)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var e,n,r;if(!this._allFieldsWithOrder){const i=[...((r=(n=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||n===void 0?void 0:n.orderBy)===null||r===void 0?void 0:r.map(o=>{if(typeof o.field=="string")return{field:this.fieldMap.get(o.field),dir:o.dir};throw new Error("Does not support mapping order by from number.")}))||[]],s=new Set(i.map(o=>o.field.name));this._allFieldsWithOrder=[...i,...this.allFields.filter(o=>!s.has(o.name)).map(o=>({field:o,dir:"asc"}))]}return this._allFieldsWithOrder}get intrinsicFields(){return[...this.fieldMap.values()].filter(e=>e.isIntrinsic())}get dimensions(){return[...this.allFieldsWithOrder].filter(e=>e.field.isAtomicField()&&e.field.sourceWasDimension())}getFieldByName(e){const n=this.fieldMap.get(e);if(n===void 0)throw new Error(`No such field ${e}.`);return n}getFieldByNameIfExists(e){return this.fieldMap.get(e)}get primaryKey(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.primaryKey}get parentExplore(){return this._parentExplore}hasParentExplore(){return this instanceof e8}get filters(){var e;return(0,ar.isSourceDef)(this.structDef)?((e=this.structDef.resultMetadata)===null||e===void 0?void 0:e.filterList)||[]:[]}get limit(){var e,n;return(n=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||n===void 0?void 0:n.limit}get structDef(){return this._structDef}get queryTimezone(){var e;return(e=this.sourceStructDef)===null||e===void 0?void 0:e.queryTimezone}get sourceStructDef(){if((0,ar.isSourceDef)(this.structDef))return this.structDef}toJSON(){var e,n;return{_structDef:this._structDef,sourceExplore:(e=this.sourceExplore)===null||e===void 0?void 0:e.toJSON(),_parentExplore:(n=this._parentExplore)===null||n===void 0?void 0:n.toJSON()}}static fromJSON(e){const n=e._parentExplore!==void 0?Ds.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?Ds.fromJSON(e.sourceExplore):void 0;return new Ds(e._structDef,n,r)}get location(){return this.structDef.location}}we.Explore=Ds;var Gu;(function(t){t.String="string",t.Number="number",t.Boolean="boolean",t.Date="date",t.Timestamp="timestamp",t.Json="json",t.NativeUnsupported="sql native",t.Error="error"})(Gu||(we.AtomicFieldType=Gu={}));class W0 extends GF{constructor(e,n,r){super(e.as||e.name,n,r),this.fieldTypeDef=e,this.parent=n}get type(){switch(this.fieldTypeDef.type){case"string":return Gu.String;case"boolean":return Gu.Boolean;case"date":return Gu.Date;case"timestamp":return Gu.Timestamp;case"number":return Gu.Number;case"json":return Gu.Json;case"sql native":return Gu.NativeUnsupported;case"error":return Gu.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const e=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${e}`)}}}tagParse(e){return e=(0,On.addModelScope)(e,this.parent.modelTag),(0,On.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,ar.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,ar.expressionIsCalculation)(this.fieldTypeDef.expressionType)}get sourceField(){throw new Error}get sourceClasses(){const e=this.fieldTypeDef.name||this.fieldTypeDef.as;return e?[e]:[]}get referenceId(){var e;return(e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.referenceId}sourceWasMeasure(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"}sourceWasMeasureLike(){var e,n;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"||((n=this.fieldTypeDef.resultMetadata)===null||n===void 0?void 0:n.fieldKind)==="struct"}sourceWasDimension(){var e;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="dimension"}hasParentExplore(){return!0}isString(){return this instanceof XF}isNumber(){return this instanceof vS}isDate(){return this instanceof WF}isBoolean(){return this instanceof YF}isJSON(){return this instanceof KF}isTimestamp(){return this instanceof VF}isUnsupported(){return this instanceof JF}get parentExplore(){return this.parent}get expression(){const e=".",n=this.fieldTypeDef.resultMetadata;return(n==null?void 0:n.sourceExpression)||(n!=null&&n.sourceField.includes(e)?n==null?void 0:n.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}we.AtomicField=W0;var Jf;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Jf||(we.DateTimeframe=Jf={}));var Wu;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year",t.Second="second",t.Hour="hour",t.Minute="minute"})(Wu||(we.TimestampTimeframe=Wu={}));class WF extends W0{constructor(e,n,r){super(e,n,r),this.fieldDateDef=e}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return Jf.Day;case"week":return Jf.Week;case"month":return Jf.Month;case"quarter":return Jf.Quarter;case"year":return Jf.Year}}}we.DateField=WF;class VF extends W0{constructor(e,n,r){super(e,n,r),this.fieldTimestampDef=e}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return Wu.Day;case"week":return Wu.Week;case"month":return Wu.Month;case"quarter":return Wu.Quarter;case"year":return Wu.Year;case"second":return Wu.Second;case"hour":return Wu.Hour;case"minute":return Wu.Minute}}}we.TimestampField=VF;class vS extends W0{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}we.NumberField=vS;class YF extends W0{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}we.BooleanField=YF;class KF extends W0{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}we.JSONField=KF;class JF extends W0{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}we.UnsupportedField=JF;class XF extends W0{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}we.StringField=XF;class HV extends GF{constructor(e,n,r){super(e.as||e.name,n,r),this.turtleDef=e}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}}we.Query=HV;class ZF extends HV{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=(0,On.addModelScope)(e,this.parent.modelTag),(0,On.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,On.annotationToTaglines)(this.turtleDef.annotation,e)}isQueryField(){return!0}isExploreField(){return!1}isAtomicField(){return!1}get sourceClasses(){const e=this.turtleDef.name||this.turtleDef.as;return e?[e]:[]}hasParentExplore(){return!0}get parentExplore(){return this.parent}get expression(){return this.name}}we.QueryField=ZF;var Xh;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(Xh||(we.JoinRelationship=Xh={}));class e8 extends Ds{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,ar.isJoined)(this.structDef))switch(this.structDef.join){case"one":return Xh.OneToOne;case"many":case"cross":return Xh.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===Xh.OneToOne}get isArray(){return this.joinRelationship!==Xh.OneToOne}tagParse(e){return e=(0,On.addModelScope)(e,this._parentExplore.modelTag),(0,On.annotationToTag)(this._structDef.annotation,e)}isQueryField(){return!1}isExploreField(){return!0}isAtomicField(){return!1}get parentExplore(){return this._parentExplore}get sourceClasses(){const e=this.structDef.name||this.structDef.as;return e?[e]:[]}}we.ExploreField=e8;class t8{constructor({urlReader:e,connections:n,connection:r,eventStream:i,cacheManager:s}){if(this.isTestRuntime=!1,n===void 0){if(r===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");n={lookupConnection:()=>Promise.resolve(r)}}e===void 0&&(e=new jV),this._urlReader=e,this._connections=n,this._eventStream=i,this._cacheManager=s}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};this.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0});const s=e instanceof URL?{url:e}:{source:e};return new wm(this,async()=>Wi.compile({...s,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:r,noThrowOnError:i,eventStream:this.eventStream,replaceMaterializedReferences:n==null?void 0:n.replaceMaterializedReferences,materializedTablePrefix:n==null?void 0:n.materializedTablePrefix,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,cacheManager:this.cacheManager}),n)}_loadModelFromModelDef(e,n){return new wm(this,async()=>new Yh(e,[],[]),n)}loadQuery(e,n){return this.loadModel(e,n).loadFinalQuery()}loadQueryByIndex(e,n,r){return this.loadModel(e,r).loadQueryByIndex(n,r)}loadQueryByName(e,n,r){return this.loadModel(e,r).loadQueryByName(n,r)}getModel(e,n){return this.loadModel(e,n).getModel()}getQuery(e,n){return this.loadQuery(e,n).getPreparedQuery()}getQueryByIndex(e,n,r){return this.loadQueryByIndex(e,n,r).getPreparedQuery()}getQueryByName(e,n,r){return this.loadQueryByName(e,n,r).getPreparedQuery()}}we.Runtime=t8;class N7e extends t8{constructor({urlReader:e,connections:n}){super({connections:AS.fromArray(n),urlReader:e}),this.rawConnections=n}}we.ConnectionRuntime=N7e;class L7e extends t8{constructor({urlReader:e,connection:n,eventStream:r,cacheManager:i}){super({urlReader:e,eventStream:r,cacheManager:i,connection:n}),this.connection=n}get supportsNesting(){return(0,zF.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,zF.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,zF.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}we.SingleConnectionRuntime=L7e;class _S{constructor(e,n){this.runtime=e,this._materialize=n}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(e,n){return new zV(this.runtime,e,n)}makeExploreMaterializer(e,n){return new GV(this.runtime,e,n)}makePreparedResultMaterializer(e){return new QV(this.runtime,e)}}class wm extends _S{constructor(e,n,r){super(e,n),this.runtime=e,this.compileQueryOptions=r}loadFinalQuery(e){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...e})}loadQueryByIndex(e,n){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(e),{...this.compileQueryOptions,...n})}loadQueryByName(e,n){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(e),{...this.compileQueryOptions,...n})}loadQuery(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};return this.makeQueryMaterializer(async()=>{const s=this.runtime.urlReader,o=this.runtime.connections;this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0});const u=e instanceof URL?{url:e}:{source:e},a=await this.getModel();return(await Wi.compile({...u,urlReader:s,connections:o,model:a,refreshSchemaCache:r,noThrowOnError:i,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,...this.compileQueryOptions})).preparedQuery})}extendModel(e,n){return this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new wm(this.runtime,async()=>{const r=this.runtime.urlReader,i=this.runtime.connections,s=e instanceof URL?{url:e}:{source:e},o=await this.getModel();return await Wi.compile({...s,urlReader:r,connections:i,model:o,refreshSchemaCache:n==null?void 0:n.refreshSchemaCache,noThrowOnError:n==null?void 0:n.noThrowOnError,importBaseURL:n==null?void 0:n.importBaseURL,testEnvironment:n==null?void 0:n.testEnvironment,...this.compileQueryOptions})},n)}async search(e,n,r=1e3,i=void 0,s){const o=await this.materialize(),u=new ar.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,ar.isSourceDef)(a))throw new Error("Source to be searched was unexpectedly, not a source");const l=a.connection,c=await this.runtime.connections.lookupConnection(l);return await u.searchIndex(c,e,n,r,i)}async searchValueMap(e,n=10,r){const s=(await this.materialize()).getExploreByName(e);if(!(0,ar.isSourceDef)(s.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let o="{index: *}";s.getFieldByNameIfExists("search_index")&&(o="search_index");const u=`
1276
1276
  run: ${e}
1277
1277
  -> ${o}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.237-dev250226000711",
3
+ "version": "0.0.238-dev250226004650",
4
4
  "license": "MIT",
5
5
  "main": "dist/module/index.umd.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,8 +31,8 @@
31
31
  "build-types": "tsc --build --declaration --emitDeclarationOnly"
32
32
  },
33
33
  "dependencies": {
34
- "@malloydata/malloy": "^0.0.237-dev250226000711",
35
- "@malloydata/malloy-tag": "^0.0.237-dev250226000711",
34
+ "@malloydata/malloy": "^0.0.238-dev250226004650",
35
+ "@malloydata/malloy-tag": "^0.0.238-dev250226004650",
36
36
  "@tanstack/solid-virtual": "^3.10.4",
37
37
  "component-register": "^0.8.6",
38
38
  "lodash": "^4.17.20",