@malloydata/render 0.0.240-dev250311214430 → 0.0.241-dev250311221410

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.
@@ -146232,7 +146232,7 @@ Zh.exploreQueryWalkerBuilder = hct;
146232
146232
  var Oe = {}, D6 = {};
146233
146233
  Object.defineProperty(D6, "__esModule", { value: !0 });
146234
146234
  D6.MALLOY_VERSION = void 0;
146235
- D6.MALLOY_VERSION = "0.0.240";
146235
+ D6.MALLOY_VERSION = "0.0.241";
146236
146236
  Object.defineProperty(Oe, "__esModule", { value: !0 });
146237
146237
  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;
146238
146238
  const nV = Bb, zr = Ii, rV = jb, PO = G2, pct = D6, mct = W2, Tn = Zr, gct = vl, iV = "internal://internal.malloy";
@@ -1437,7 +1437,7 @@ wxxyyzz{{||}}}Ү
1437
1437
  | ${l}`,u>0&&(i=i+`
1438
1438
  | ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
1439
1439
  `+i,n=s),e!==""?e=`${e}
1440
- ${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}}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,y0t.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,Vk.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(0,Vk.rangeFromContext)(this.parseStep.sourceInfo,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))}}pc.MalloyTranslation=Yk;class Hce extends Yk{constructor(e,n){super(e),this.root=n}}pc.MalloyChildTranslator=Hce;class P0t extends Yk{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new Wk.Zone,this.importZone=new Wk.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new Wk.Zone,this.root=this,this.logger=new qce.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,qce.makeLogMessage)(e,n,{severity:"error",...r})),e}}pc.MalloyTranslator=P0t;function zce(t){return[...Object.keys(t),...Object.keys(t).map(e=>zce(t[e])).flat()]}var op={};Object.defineProperty(op,"__esModule",{value:!0}),op.exploreQueryWalkerBuilder=op.ExploreQueryWalker=void 0;const U0t=Y0;class Qce{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}}op.ExploreQueryWalker=Qce;function j0t(t,e){const n=new Qce(t),r=n;return U0t.ParseTreeWalker.DEFAULT.walk(r,e),n}op.exploreQueryWalkerBuilder=j0t,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=pc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=op;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(p4);var Oe={},GT={};Object.defineProperty(GT,"__esModule",{value:!0}),GT.MALLOY_VERSION=void 0,GT.MALLOY_VERSION="0.0.240",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 Gce=p4,ni=Ni,Wce=C4,Kk=v2,q0t=GT,H0t=S2,Dn=Zr,z0t=$l,Vce="internal://internal.malloy";let Hl=class j6{static get version(){return q0t.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(Vce));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new Gce.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new Kce(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return j6._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 e6(n,e).then(({contents:o,invalidationKey:u})=>j6._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,importBaseURL:c,cacheManager:f}){var d,h,p,m,g;let E;if(u&&(E=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(Vce));const y={};if(n===void 0&&f!==void 0){const v=await f.getCachedModelDef(i,e.toString());if(v)return new up(v.modelDef,[],[e.toString(),...ZT(v.modelDef.dependencies)])}c??(c=e);let A;const _=e.toString();if(r!==void 0){A=r._translator;const v=(d=r._invalidationKey)!==null&&d!==void 0?d:await lM(i,e);y[_]=v}else{if(n===void 0){const{contents:v,invalidationKey:C}=await e6(i,e);y[_]=C,n=v}else{const v=await lM(i,e);y[_]=v}A=new Gce.MalloyTranslator(_,c.toString(),{urls:{[_]:n}},l)}for(;;){const v=A.translate(o==null?void 0:o._modelDef);if(v.final)if(v.modelDef){await(f==null?void 0:f.setCachedModelDef(e.toString(),{modelDef:v.modelDef,invalidationKeys:y}));for(const C of A.newlyTranslatedDependencies())await(f==null?void 0:f.setCachedModelDef(C.url,{modelDef:C.modelDef,invalidationKeys:y}));return new up(v.modelDef,v.problems||[],[...(h=o==null?void 0:o.fromSources)!==null&&h!==void 0?h:[],...(p=v.fromSources)!==null&&p!==void 0?p:[]],C=>A.referenceAt(C),C=>A.importAt(C))}else if(a){const C={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},S=(o==null?void 0:o._modelDef)||C;return new up(S,v.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=v.fromSources)!==null&&g!==void 0?g:[]],T=>A.referenceAt(T),T=>A.importAt(T))}else{const C=v.problems||[],S=A.prettyErrors();throw new Yce(`Error(s) compiling model:
1440
+ ${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}}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,y0t.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,Vk.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(0,Vk.rangeFromContext)(this.parseStep.sourceInfo,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))}}pc.MalloyTranslation=Yk;class Hce extends Yk{constructor(e,n){super(e),this.root=n}}pc.MalloyChildTranslator=Hce;class P0t extends Yk{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new Wk.Zone,this.importZone=new Wk.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new Wk.Zone,this.root=this,this.logger=new qce.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,qce.makeLogMessage)(e,n,{severity:"error",...r})),e}}pc.MalloyTranslator=P0t;function zce(t){return[...Object.keys(t),...Object.keys(t).map(e=>zce(t[e])).flat()]}var op={};Object.defineProperty(op,"__esModule",{value:!0}),op.exploreQueryWalkerBuilder=op.ExploreQueryWalker=void 0;const U0t=Y0;class Qce{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}}op.ExploreQueryWalker=Qce;function j0t(t,e){const n=new Qce(t),r=n;return U0t.ParseTreeWalker.DEFAULT.walk(r,e),n}op.exploreQueryWalkerBuilder=j0t,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=pc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=op;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(p4);var Oe={},GT={};Object.defineProperty(GT,"__esModule",{value:!0}),GT.MALLOY_VERSION=void 0,GT.MALLOY_VERSION="0.0.241",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 Gce=p4,ni=Ni,Wce=C4,Kk=v2,q0t=GT,H0t=S2,Dn=Zr,z0t=$l,Vce="internal://internal.malloy";let Hl=class j6{static get version(){return q0t.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(Vce));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new Gce.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new Kce(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return j6._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 e6(n,e).then(({contents:o,invalidationKey:u})=>j6._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,importBaseURL:c,cacheManager:f}){var d,h,p,m,g;let E;if(u&&(E=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(Vce));const y={};if(n===void 0&&f!==void 0){const v=await f.getCachedModelDef(i,e.toString());if(v)return new up(v.modelDef,[],[e.toString(),...ZT(v.modelDef.dependencies)])}c??(c=e);let A;const _=e.toString();if(r!==void 0){A=r._translator;const v=(d=r._invalidationKey)!==null&&d!==void 0?d:await lM(i,e);y[_]=v}else{if(n===void 0){const{contents:v,invalidationKey:C}=await e6(i,e);y[_]=C,n=v}else{const v=await lM(i,e);y[_]=v}A=new Gce.MalloyTranslator(_,c.toString(),{urls:{[_]:n}},l)}for(;;){const v=A.translate(o==null?void 0:o._modelDef);if(v.final)if(v.modelDef){await(f==null?void 0:f.setCachedModelDef(e.toString(),{modelDef:v.modelDef,invalidationKeys:y}));for(const C of A.newlyTranslatedDependencies())await(f==null?void 0:f.setCachedModelDef(C.url,{modelDef:C.modelDef,invalidationKeys:y}));return new up(v.modelDef,v.problems||[],[...(h=o==null?void 0:o.fromSources)!==null&&h!==void 0?h:[],...(p=v.fromSources)!==null&&p!==void 0?p:[]],C=>A.referenceAt(C),C=>A.importAt(C))}else if(a){const C={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},S=(o==null?void 0:o._modelDef)||C;return new up(S,v.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=v.fromSources)!==null&&g!==void 0?g:[]],T=>A.referenceAt(T),T=>A.importAt(T))}else{const C=v.problems||[],S=A.prettyErrors();throw new Yce(`Error(s) compiling model:
1441
1441
  ${S}`,C)}else{if(v.urls)for(const S of v.urls)try{if(t6(S))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(f!==void 0){const I=await f.getCachedModelDef(i,S);if(I){for(const P in I.invalidationKeys)y[P]=I.invalidationKeys[P];A.update({translations:{[S]:I.modelDef}});continue}}const{contents:T,invalidationKey:R}=await e6(i,new URL(S)),L={[S]:T};y[S]=R,A.update({urls:L})}catch(T){A.update({errors:{urls:{[S]:T.message}}})}const{modelAnnotation:C}=A.modelAnnotation(o==null?void 0:o._modelDef);if(v.tables){const S=new Map;for(const T in v.tables){const{connectionName:R,tablePath:L}=v.tables[T],I=S.get(R);I===void 0?S.set(R,{[T]:L}):I[T]=L}for(const[T,R]of S)try{const L=await s.lookupConnection(T),{schemas:I,errors:P}=await j6.safelyFetchTableSchema(L,R,{refreshTimestamp:E,modelAnnotation:C});A.update({tables:I,errors:{tables:P}})}catch(L){const I={},P={};for(const G in R)P[G]=L.toString();A.update({tables:I,errors:{tables:P}})}}if(v.compileSQL){const S=v.compileSQL,T=S.connection,R=(0,z0t.sqlKey)(S.connection,S.selectStr);try{const I=await(await s.lookupConnection(T)).fetchSchemaForSQLStruct(S,{refreshTimestamp:E,modelAnnotation:C});I.error&&A.update({errors:{compileSQL:{[R]:I.error}}}),I.structDef&&A.update({compileSQL:{[R]:I.structDef}})}catch(L){const I={};I[R]=L.toString(),A.update({errors:{compileSQL:I}})}}}}}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 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 Ky({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 Ky({...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 Ns(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 Zx(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=Hl;class Yce extends Error{constructor(e,n=[]){super(e),this.problems=n}}Oe.MalloyError=Yce;class up{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,Dn.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,Dn.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 ap(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 ap(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 ap(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,ni.isSourceDef)(n))return new Ns(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(ni.isSourceDef).map(e=>new Ns(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=up;class ap{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=(0,Dn.annotationToTag)(this._modelDef.annotation).tag;return e=(0,Dn.addModelScope)(e,n),(0,Dn.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,Dn.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new ni.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new Vy({...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,ni.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}Oe.PreparedQuery=ap;class Kce{constructor(e,n){this.translator=e,this.invalidationKey=n}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new WT(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new Jce(r))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new Xce(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}Oe.Parse=Kce;class Jce{constructor(e){this._range=lp.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=Jce;class lp{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 lp(new Jk(e.start.line,e.start.character),new Jk(e.end.line,e.end.character))}}Oe.DocumentRange=lp;class Jk{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=Jk;class WT{constructor(e){this._range=lp.fromJSON(e.range),this._lensRange=e.lensRange?lp.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new WT(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=WT;class Xce{constructor(e){this.type=e.type,this.text=e.text}}Oe.DocumentCompletion=Xce;class Vy{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 Vy(e,n)}tagParse(e){const n=(0,Dn.annotationToTag)(this.modelDef.annotation).tag;return e=(0,Dn.addModelScope)(e,n),(0,Dn.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,Dn.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,Dn.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 Ns(n,this.sourceExplore)}catch{return new Ns(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n&&(0,ni.isSourceDef)(n))return new Ns(n)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}Oe.PreparedResult=Vy;class Zce{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}Oe.EmptyURLReader=Zce;class Q0t{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 t6(e.toString())?null:hfe(n)}}Oe.InMemoryURLReader=Q0t;class VT{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 VT(new Map(e.map(n=>[n.name,n])))}}Oe.FixedConnectionMap=VT;var efe;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(efe||(Oe.SourceRelationship=efe={}));class Xk{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 Ns}isQuery(){return this instanceof sM}}class Ns extends Xk{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,ni.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,Dn.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,Dn.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,Dn.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 ap(r,this.modelDef,[],e)}get modelDef(){if(!(0,ni.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 up(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,ni.isJoined)(r))return[i,new oM(r,this,s)];if(r.type==="turtle")return[i,new sM(r,this,s)];if(r.type==="string")return[i,new iM(r,this,s)];if(r.type==="number")return[i,new YT(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new YT({...r,type:"number"},this,s)]:[i,new Zk(r,this,s)];if(r.type==="timestamp")return[i,new eM(r,this,s)];if(r.type==="boolean")return[i,new tM(r,this,s)];if(r.type==="json")return[i,new nM(r,this,s)];if(r.type==="sql native")return[i,new rM(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 oM}get filters(){var e;return(0,ni.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,ni.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?Ns.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?Ns.fromJSON(e.sourceExplore):void 0;return new Ns(e._structDef,n,r)}get location(){return this.structDef.location}}Oe.Explore=Ns;var _a;(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"})(_a||(Oe.AtomicFieldType=_a={}));class Bc extends Xk{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 _a.String;case"boolean":return _a.Boolean;case"date":return _a.Date;case"timestamp":return _a.Timestamp;case"number":return _a.Number;case"json":return _a.Json;case"sql native":return _a.NativeUnsupported;case"error":return _a.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,Dn.addModelScope)(e,this.parent.modelTag),(0,Dn.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,Dn.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,ni.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,ni.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 iM}isNumber(){return this instanceof YT}isDate(){return this instanceof Zk}isBoolean(){return this instanceof tM}isJSON(){return this instanceof nM}isTimestamp(){return this instanceof eM}isUnsupported(){return this instanceof rM}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=Bc;var Xx;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Xx||(Oe.DateTimeframe=Xx={}));var va;(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"})(va||(Oe.TimestampTimeframe=va={}));class Zk extends Bc{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 Xx.Day;case"week":return Xx.Week;case"month":return Xx.Month;case"quarter":return Xx.Quarter;case"year":return Xx.Year}}}Oe.DateField=Zk;class eM extends Bc{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 va.Day;case"week":return va.Week;case"month":return va.Month;case"quarter":return va.Quarter;case"year":return va.Year;case"second":return va.Second;case"hour":return va.Hour;case"minute":return va.Minute}}}Oe.TimestampField=eM;class YT extends Bc{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}Oe.NumberField=YT;class tM extends Bc{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}Oe.BooleanField=tM;class nM extends Bc{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}Oe.JSONField=nM;class rM extends Bc{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Oe.UnsupportedField=rM;class iM extends Bc{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}Oe.StringField=iM;class tfe extends Xk{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=tfe;class sM extends tfe{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=(0,Dn.addModelScope)(e,this.parent.modelTag),(0,Dn.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,Dn.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=sM;var cp;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(cp||(Oe.JoinRelationship=cp={}));class oM extends Ns{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,ni.isJoined)(this.structDef))switch(this.structDef.join){case"one":return cp.OneToOne;case"many":case"cross":return cp.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===cp.OneToOne}get isArray(){return this.joinRelationship!==cp.OneToOne}tagParse(e){return e=(0,Dn.addModelScope)(e,this._parentExplore.modelTag),(0,Dn.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=oM;class uM{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 Zce),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 Yy(this,async()=>Hl.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 Yy(this,async()=>new up(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=uM;class G0t extends uM{constructor({urlReader:e,connections:n}){super({connections:VT.fromArray(n),urlReader:e}),this.rawConnections=n}}Oe.ConnectionRuntime=G0t;class W0t extends uM{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,Kk.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,Kk.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,Kk.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Oe.SingleConnectionRuntime=W0t;class KT{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 nfe(this.runtime,e,n)}makeExploreMaterializer(e,n){return new ife(this.runtime,e,n)}makePreparedResultMaterializer(e){return new rfe(this.runtime,e)}}class Yy extends KT{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 Hl.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 Yy(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 Hl.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 ni.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,ni.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,ni.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=`
1442
1442
  run: ${e}
1443
1443
  -> ${o}
@@ -150044,7 +150044,7 @@ F2.exploreQueryWalkerBuilder = adt;
150044
150044
  var Fe = {}, tR = {};
150045
150045
  Object.defineProperty(tR, "__esModule", { value: !0 });
150046
150046
  tR.MALLOY_VERSION = void 0;
150047
- tR.MALLOY_VERSION = "0.0.240";
150047
+ tR.MALLOY_VERSION = "0.0.241";
150048
150048
  Object.defineProperty(Fe, "__esModule", { value: !0 });
150049
150049
  Fe.InMemoryModelCache = Fe.CacheManager = Fe.CSVWriter = Fe.JSONWriter = Fe.DataWriter = Fe.DataRecord = Fe.DataArray = Fe.Result = Fe.ExploreMaterializer = Fe.PreparedResultMaterializer = Fe.QueryMaterializer = Fe.ModelMaterializer = Fe.SingleConnectionRuntime = Fe.ConnectionRuntime = Fe.Runtime = Fe.ExploreField = Fe.JoinRelationship = Fe.QueryField = Fe.Query = Fe.StringField = Fe.UnsupportedField = Fe.JSONField = Fe.BooleanField = Fe.NumberField = Fe.TimestampField = Fe.DateField = Fe.TimestampTimeframe = Fe.DateTimeframe = Fe.AtomicField = Fe.AtomicFieldType = Fe.Explore = Fe.SourceRelationship = Fe.FixedConnectionMap = Fe.InMemoryURLReader = Fe.EmptyURLReader = Fe.PreparedResult = Fe.DocumentCompletion = Fe.DocumentSymbol = Fe.DocumentPosition = Fe.DocumentRange = Fe.DocumentTablePath = Fe.Parse = Fe.PreparedQuery = Fe.Model = Fe.MalloyError = Fe.Malloy = void 0;
150050
150050
  const LV = lT, Kr = qi, IV = ci, m7 = bp, ldt = tR, cdt = Tp, wn = oi, fdt = zl, BV = "internal://internal.malloy";
@@ -1832,7 +1832,7 @@ wxxyyzz{{||}}}Ү
1832
1832
  | ${l}`,u>0&&(i=i+`
1833
1833
  | ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
1834
1834
  `+i,n=s),e!==""?e=`${e}
1835
- ${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}}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,cxt.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,hM.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(0,hM.rangeFromContext)(this.parseStep.sourceInfo,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))}}Bc.MalloyTranslation=pM;class Hfe extends pM{constructor(e,n){super(e),this.root=n}}Bc.MalloyChildTranslator=Hfe;class Fxt extends pM{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new dM.Zone,this.importZone=new dM.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new dM.Zone,this.root=this,this.logger=new zfe.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,zfe.makeLogMessage)(e,n,{severity:"error",...r})),e}}Bc.MalloyTranslator=Fxt;function Qfe(t){return[...Object.keys(t),...Object.keys(t).map(e=>Qfe(t[e])).flat()]}var kp={};Object.defineProperty(kp,"__esModule",{value:!0}),kp.exploreQueryWalkerBuilder=kp.ExploreQueryWalker=void 0;const Nxt=h0;class Gfe{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}}kp.ExploreQueryWalker=Gfe;function Lxt(t,e){const n=new Gfe(t),r=n;return Nxt.ParseTreeWalker.DEFAULT.walk(r,e),n}kp.exploreQueryWalkerBuilder=Lxt,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=Bc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=kp;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(x4);var Fe={},q6={};Object.defineProperty(q6,"__esModule",{value:!0}),q6.MALLOY_VERSION=void 0,q6.MALLOY_VERSION="0.0.240",Object.defineProperty(Fe,"__esModule",{value:!0}),Fe.InMemoryModelCache=Fe.CacheManager=Fe.CSVWriter=Fe.JSONWriter=Fe.DataWriter=Fe.DataRecord=Fe.DataArray=Fe.Result=Fe.ExploreMaterializer=Fe.PreparedResultMaterializer=Fe.QueryMaterializer=Fe.ModelMaterializer=Fe.SingleConnectionRuntime=Fe.ConnectionRuntime=Fe.Runtime=Fe.ExploreField=Fe.JoinRelationship=Fe.QueryField=Fe.Query=Fe.StringField=Fe.UnsupportedField=Fe.JSONField=Fe.BooleanField=Fe.NumberField=Fe.TimestampField=Fe.DateField=Fe.TimestampTimeframe=Fe.DateTimeframe=Fe.AtomicField=Fe.AtomicFieldType=Fe.Explore=Fe.SourceRelationship=Fe.FixedConnectionMap=Fe.InMemoryURLReader=Fe.EmptyURLReader=Fe.PreparedResult=Fe.DocumentCompletion=Fe.DocumentSymbol=Fe.DocumentPosition=Fe.DocumentRange=Fe.DocumentTablePath=Fe.Parse=Fe.PreparedQuery=Fe.Model=Fe.MalloyError=Fe.Malloy=void 0;const Wfe=x4,fi=ji,Vfe=ni,gM=Z2,Ixt=q6,Bxt=tp,Nn=ai,$xt=i0,Yfe="internal://internal.malloy";let f0=class pR{static get version(){return Ixt.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(Yfe));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new Wfe.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new Jfe(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return pR._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 K6(n,e).then(({contents:o,invalidationKey:u})=>pR._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,importBaseURL:c,cacheManager:f}){var d,h,p,m,g;let y;if(u&&(y=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(Yfe));const E={};if(n===void 0&&f!==void 0){const _=await f.getCachedModelDef(i,e.toString());if(_)return new Mp(_.modelDef,[],[e.toString(),...Y6(_.modelDef.dependencies)])}c??(c=e);let A;const v=e.toString();if(r!==void 0){A=r._translator;const _=(d=r._invalidationKey)!==null&&d!==void 0?d:await OM(i,e);E[v]=_}else{if(n===void 0){const{contents:_,invalidationKey:C}=await K6(i,e);E[v]=C,n=_}else{const _=await OM(i,e);E[v]=_}A=new Wfe.MalloyTranslator(v,c.toString(),{urls:{[v]:n}},l)}for(;;){const _=A.translate(o==null?void 0:o._modelDef);if(_.final)if(_.modelDef){await(f==null?void 0:f.setCachedModelDef(e.toString(),{modelDef:_.modelDef,invalidationKeys:E}));for(const C of A.newlyTranslatedDependencies())await(f==null?void 0:f.setCachedModelDef(C.url,{modelDef:C.modelDef,invalidationKeys:E}));return new Mp(_.modelDef,_.problems||[],[...(h=o==null?void 0:o.fromSources)!==null&&h!==void 0?h:[],...(p=_.fromSources)!==null&&p!==void 0?p:[]],C=>A.referenceAt(C),C=>A.importAt(C))}else if(a){const C={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},S=(o==null?void 0:o._modelDef)||C;return new Mp(S,_.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=_.fromSources)!==null&&g!==void 0?g:[]],T=>A.referenceAt(T),T=>A.importAt(T))}else{const C=_.problems||[],S=A.prettyErrors();throw new Kfe(`Error(s) compiling model:
1835
+ ${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}}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,cxt.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,hM.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(0,hM.rangeFromContext)(this.parseStep.sourceInfo,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))}}Bc.MalloyTranslation=pM;class Hfe extends pM{constructor(e,n){super(e),this.root=n}}Bc.MalloyChildTranslator=Hfe;class Fxt extends pM{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new dM.Zone,this.importZone=new dM.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new dM.Zone,this.root=this,this.logger=new zfe.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,zfe.makeLogMessage)(e,n,{severity:"error",...r})),e}}Bc.MalloyTranslator=Fxt;function Qfe(t){return[...Object.keys(t),...Object.keys(t).map(e=>Qfe(t[e])).flat()]}var kp={};Object.defineProperty(kp,"__esModule",{value:!0}),kp.exploreQueryWalkerBuilder=kp.ExploreQueryWalker=void 0;const Nxt=h0;class Gfe{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}}kp.ExploreQueryWalker=Gfe;function Lxt(t,e){const n=new Gfe(t),r=n;return Nxt.ParseTreeWalker.DEFAULT.walk(r,e),n}kp.exploreQueryWalkerBuilder=Lxt,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=Bc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=kp;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(x4);var Fe={},q6={};Object.defineProperty(q6,"__esModule",{value:!0}),q6.MALLOY_VERSION=void 0,q6.MALLOY_VERSION="0.0.241",Object.defineProperty(Fe,"__esModule",{value:!0}),Fe.InMemoryModelCache=Fe.CacheManager=Fe.CSVWriter=Fe.JSONWriter=Fe.DataWriter=Fe.DataRecord=Fe.DataArray=Fe.Result=Fe.ExploreMaterializer=Fe.PreparedResultMaterializer=Fe.QueryMaterializer=Fe.ModelMaterializer=Fe.SingleConnectionRuntime=Fe.ConnectionRuntime=Fe.Runtime=Fe.ExploreField=Fe.JoinRelationship=Fe.QueryField=Fe.Query=Fe.StringField=Fe.UnsupportedField=Fe.JSONField=Fe.BooleanField=Fe.NumberField=Fe.TimestampField=Fe.DateField=Fe.TimestampTimeframe=Fe.DateTimeframe=Fe.AtomicField=Fe.AtomicFieldType=Fe.Explore=Fe.SourceRelationship=Fe.FixedConnectionMap=Fe.InMemoryURLReader=Fe.EmptyURLReader=Fe.PreparedResult=Fe.DocumentCompletion=Fe.DocumentSymbol=Fe.DocumentPosition=Fe.DocumentRange=Fe.DocumentTablePath=Fe.Parse=Fe.PreparedQuery=Fe.Model=Fe.MalloyError=Fe.Malloy=void 0;const Wfe=x4,fi=ji,Vfe=ni,gM=Z2,Ixt=q6,Bxt=tp,Nn=ai,$xt=i0,Yfe="internal://internal.malloy";let f0=class pR{static get version(){return Ixt.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(Yfe));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new Wfe.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new Jfe(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return pR._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 K6(n,e).then(({contents:o,invalidationKey:u})=>pR._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,importBaseURL:c,cacheManager:f}){var d,h,p,m,g;let y;if(u&&(y=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(Yfe));const E={};if(n===void 0&&f!==void 0){const _=await f.getCachedModelDef(i,e.toString());if(_)return new Mp(_.modelDef,[],[e.toString(),...Y6(_.modelDef.dependencies)])}c??(c=e);let A;const v=e.toString();if(r!==void 0){A=r._translator;const _=(d=r._invalidationKey)!==null&&d!==void 0?d:await OM(i,e);E[v]=_}else{if(n===void 0){const{contents:_,invalidationKey:C}=await K6(i,e);E[v]=C,n=_}else{const _=await OM(i,e);E[v]=_}A=new Wfe.MalloyTranslator(v,c.toString(),{urls:{[v]:n}},l)}for(;;){const _=A.translate(o==null?void 0:o._modelDef);if(_.final)if(_.modelDef){await(f==null?void 0:f.setCachedModelDef(e.toString(),{modelDef:_.modelDef,invalidationKeys:E}));for(const C of A.newlyTranslatedDependencies())await(f==null?void 0:f.setCachedModelDef(C.url,{modelDef:C.modelDef,invalidationKeys:E}));return new Mp(_.modelDef,_.problems||[],[...(h=o==null?void 0:o.fromSources)!==null&&h!==void 0?h:[],...(p=_.fromSources)!==null&&p!==void 0?p:[]],C=>A.referenceAt(C),C=>A.importAt(C))}else if(a){const C={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},S=(o==null?void 0:o._modelDef)||C;return new Mp(S,_.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=_.fromSources)!==null&&g!==void 0?g:[]],T=>A.referenceAt(T),T=>A.importAt(T))}else{const C=_.problems||[],S=A.prettyErrors();throw new Kfe(`Error(s) compiling model:
1836
1836
  ${S}`,C)}else{if(_.urls)for(const S of _.urls)try{if(J6(S))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(f!==void 0){const L=await f.getCachedModelDef(i,S);if(L){for(const M in L.invalidationKeys)E[M]=L.invalidationKeys[M];A.update({translations:{[S]:L.modelDef}});continue}}const{contents:T,invalidationKey:w}=await K6(i,new URL(S)),I={[S]:T};E[S]=w,A.update({urls:I})}catch(T){A.update({errors:{urls:{[S]:T.message}}})}const{modelAnnotation:C}=A.modelAnnotation(o==null?void 0:o._modelDef);if(_.tables){const S=new Map;for(const T in _.tables){const{connectionName:w,tablePath:I}=_.tables[T],L=S.get(w);L===void 0?S.set(w,{[T]:I}):L[T]=I}for(const[T,w]of S)try{const I=await s.lookupConnection(T),{schemas:L,errors:M}=await pR.safelyFetchTableSchema(I,w,{refreshTimestamp:y,modelAnnotation:C});A.update({tables:L,errors:{tables:M}})}catch(I){const L={},M={};for(const z in w)M[z]=I.toString();A.update({tables:L,errors:{tables:M}})}}if(_.compileSQL){const S=_.compileSQL,T=S.connection,w=(0,$xt.sqlKey)(S.connection,S.selectStr);try{const L=await(await s.lookupConnection(T)).fetchSchemaForSQLStruct(S,{refreshTimestamp:y,modelAnnotation:C});L.error&&A.update({errors:{compileSQL:{[w]:L.error}}}),L.structDef&&A.update({compileSQL:{[w]:L.structDef}})}catch(I){const L={};L[w]=I.toString(),A.update({errors:{compileSQL:L}})}}}}}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 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 FE({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 FE({...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 js(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 Sd(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.")}};Fe.Malloy=f0;class Kfe extends Error{constructor(e,n=[]){super(e),this.problems=n}}Fe.MalloyError=Kfe;class Mp{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,Nn.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,Nn.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 Pp(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 Pp(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 Pp(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,fi.isSourceDef)(n))return new js(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(fi.isSourceDef).map(e=>new js(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}}Fe.Model=Mp;class Pp{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=(0,Nn.annotationToTag)(this._modelDef.annotation).tag;return e=(0,Nn.addModelScope)(e,n),(0,Nn.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new fi.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new OE({...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,fi.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}Fe.PreparedQuery=Pp;class Jfe{constructor(e,n){this.translator=e,this.invalidationKey=n}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new z6(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new Xfe(r))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new Zfe(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}Fe.Parse=Jfe;class Xfe{constructor(e){this._range=jp.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}}Fe.DocumentTablePath=Xfe;class jp{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 jp(new mM(e.start.line,e.start.character),new mM(e.end.line,e.end.character))}}Fe.DocumentRange=jp;class mM{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}}}Fe.DocumentPosition=mM;class z6{constructor(e){this._range=jp.fromJSON(e.range),this._lensRange=e.lensRange?jp.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new z6(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}}Fe.DocumentSymbol=z6;class Zfe{constructor(e){this.type=e.type,this.text=e.text}}Fe.DocumentCompletion=Zfe;class OE{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 OE(e,n)}tagParse(e){const n=(0,Nn.annotationToTag)(this.modelDef.annotation).tag;return e=(0,Nn.addModelScope)(e,n),(0,Nn.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,Nn.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 js(n,this.sourceExplore)}catch{return new js(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n&&(0,fi.isSourceDef)(n))return new js(n)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}Fe.PreparedResult=OE;class exe{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}Fe.EmptyURLReader=exe;class kxt{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 J6(e.toString())?null:pxe(n)}}Fe.InMemoryURLReader=kxt;class H6{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 H6(new Map(e.map(n=>[n.name,n])))}}Fe.FixedConnectionMap=H6;var txe;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(txe||(Fe.SourceRelationship=txe={}));class yM{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 js}isQuery(){return this instanceof bM}}class js extends yM{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,fi.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,Nn.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,Nn.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 Pp(r,this.modelDef,[],e)}get modelDef(){if(!(0,fi.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 Mp(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,fi.isJoined)(r))return[i,new TM(r,this,s)];if(r.type==="turtle")return[i,new bM(r,this,s)];if(r.type==="string")return[i,new SM(r,this,s)];if(r.type==="number")return[i,new Q6(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new Q6({...r,type:"number"},this,s)]:[i,new EM(r,this,s)];if(r.type==="timestamp")return[i,new AM(r,this,s)];if(r.type==="boolean")return[i,new vM(r,this,s)];if(r.type==="json")return[i,new _M(r,this,s)];if(r.type==="sql native")return[i,new CM(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 TM}get filters(){var e;return(0,fi.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,fi.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?js.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?js.fromJSON(e.sourceExplore):void 0;return new js(e._structDef,n,r)}get location(){return this.structDef.location}}Fe.Explore=js;var $a;(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"})($a||(Fe.AtomicFieldType=$a={}));class tf extends yM{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 $a.String;case"boolean":return $a.Boolean;case"date":return $a.Date;case"timestamp":return $a.Timestamp;case"number":return $a.Number;case"json":return $a.Json;case"sql native":return $a.NativeUnsupported;case"error":return $a.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,Nn.addModelScope)(e,this.parent.modelTag),(0,Nn.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,fi.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,fi.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 SM}isNumber(){return this instanceof Q6}isDate(){return this instanceof EM}isBoolean(){return this instanceof vM}isJSON(){return this instanceof _M}isTimestamp(){return this instanceof AM}isUnsupported(){return this instanceof CM}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}}Fe.AtomicField=tf;var Cd;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Cd||(Fe.DateTimeframe=Cd={}));var ka;(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"})(ka||(Fe.TimestampTimeframe=ka={}));class EM extends tf{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 Cd.Day;case"week":return Cd.Week;case"month":return Cd.Month;case"quarter":return Cd.Quarter;case"year":return Cd.Year}}}Fe.DateField=EM;class AM extends tf{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 ka.Day;case"week":return ka.Week;case"month":return ka.Month;case"quarter":return ka.Quarter;case"year":return ka.Year;case"second":return ka.Second;case"hour":return ka.Hour;case"minute":return ka.Minute}}}Fe.TimestampField=AM;class Q6 extends tf{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}Fe.NumberField=Q6;class vM extends tf{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}Fe.BooleanField=vM;class _M extends tf{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}Fe.JSONField=_M;class CM extends tf{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Fe.UnsupportedField=CM;class SM extends tf{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}Fe.StringField=SM;class nxe extends yM{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}}Fe.Query=nxe;class bM extends nxe{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=(0,Nn.addModelScope)(e,this.parent.modelTag),(0,Nn.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,Nn.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}}Fe.QueryField=bM;var Up;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(Up||(Fe.JoinRelationship=Up={}));class TM extends js{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,fi.isJoined)(this.structDef))switch(this.structDef.join){case"one":return Up.OneToOne;case"many":case"cross":return Up.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===Up.OneToOne}get isArray(){return this.joinRelationship!==Up.OneToOne}tagParse(e){return e=(0,Nn.addModelScope)(e,this._parentExplore.modelTag),(0,Nn.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]:[]}}Fe.ExploreField=TM;class RM{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 exe),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 wE(this,async()=>f0.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 wE(this,async()=>new Mp(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()}}Fe.Runtime=RM;class Mxt extends RM{constructor({urlReader:e,connections:n}){super({connections:H6.fromArray(n),urlReader:e}),this.rawConnections=n}}Fe.ConnectionRuntime=Mxt;class Pxt extends RM{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,gM.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,gM.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,gM.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Fe.SingleConnectionRuntime=Pxt;class G6{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 rxe(this.runtime,e,n)}makeExploreMaterializer(e,n){return new sxe(this.runtime,e,n)}makePreparedResultMaterializer(e){return new ixe(this.runtime,e)}}class wE extends G6{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 f0.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 wE(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 f0.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 fi.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,fi.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,fi.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=`
1837
1837
  run: ${e}
1838
1838
  -> ${o}
@@ -150044,7 +150044,7 @@ F2.exploreQueryWalkerBuilder = adt;
150044
150044
  var Fe = {}, tR = {};
150045
150045
  Object.defineProperty(tR, "__esModule", { value: !0 });
150046
150046
  tR.MALLOY_VERSION = void 0;
150047
- tR.MALLOY_VERSION = "0.0.240";
150047
+ tR.MALLOY_VERSION = "0.0.241";
150048
150048
  Object.defineProperty(Fe, "__esModule", { value: !0 });
150049
150049
  Fe.InMemoryModelCache = Fe.CacheManager = Fe.CSVWriter = Fe.JSONWriter = Fe.DataWriter = Fe.DataRecord = Fe.DataArray = Fe.Result = Fe.ExploreMaterializer = Fe.PreparedResultMaterializer = Fe.QueryMaterializer = Fe.ModelMaterializer = Fe.SingleConnectionRuntime = Fe.ConnectionRuntime = Fe.Runtime = Fe.ExploreField = Fe.JoinRelationship = Fe.QueryField = Fe.Query = Fe.StringField = Fe.UnsupportedField = Fe.JSONField = Fe.BooleanField = Fe.NumberField = Fe.TimestampField = Fe.DateField = Fe.TimestampTimeframe = Fe.DateTimeframe = Fe.AtomicField = Fe.AtomicFieldType = Fe.Explore = Fe.SourceRelationship = Fe.FixedConnectionMap = Fe.InMemoryURLReader = Fe.EmptyURLReader = Fe.PreparedResult = Fe.DocumentCompletion = Fe.DocumentSymbol = Fe.DocumentPosition = Fe.DocumentRange = Fe.DocumentTablePath = Fe.Parse = Fe.PreparedQuery = Fe.Model = Fe.MalloyError = Fe.Malloy = void 0;
150050
150050
  const LV = lT, Kr = qi, IV = ci, m7 = bp, ldt = tR, cdt = Tp, wn = oi, fdt = zl, BV = "internal://internal.malloy";
@@ -1832,7 +1832,7 @@ wxxyyzz{{||}}}Ү
1832
1832
  | ${l}`,u>0&&(i=i+`
1833
1833
  | ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
1834
1834
  `+i,n=s),e!==""?e=`${e}
1835
- ${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}}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,cxt.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,dM.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(0,dM.rangeFromContext)(this.parseStep.sourceInfo,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))}}Bc.MalloyTranslation=hM;class zfe extends hM{constructor(e,n){super(e),this.root=n}}Bc.MalloyChildTranslator=zfe;class Fxt extends hM{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new xM.Zone,this.importZone=new xM.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new xM.Zone,this.root=this,this.logger=new qfe.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,qfe.makeLogMessage)(e,n,{severity:"error",...r})),e}}Bc.MalloyTranslator=Fxt;function Hfe(t){return[...Object.keys(t),...Object.keys(t).map(e=>Hfe(t[e])).flat()]}var kp={};Object.defineProperty(kp,"__esModule",{value:!0}),kp.exploreQueryWalkerBuilder=kp.ExploreQueryWalker=void 0;const Nxt=h0;class Qfe{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}}kp.ExploreQueryWalker=Qfe;function Lxt(t,e){const n=new Qfe(t),r=n;return Nxt.ParseTreeWalker.DEFAULT.walk(r,e),n}kp.exploreQueryWalkerBuilder=Lxt,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=Bc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=kp;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(f4);var Fe={},U6={};Object.defineProperty(U6,"__esModule",{value:!0}),U6.MALLOY_VERSION=void 0,U6.MALLOY_VERSION="0.0.240",Object.defineProperty(Fe,"__esModule",{value:!0}),Fe.InMemoryModelCache=Fe.CacheManager=Fe.CSVWriter=Fe.JSONWriter=Fe.DataWriter=Fe.DataRecord=Fe.DataArray=Fe.Result=Fe.ExploreMaterializer=Fe.PreparedResultMaterializer=Fe.QueryMaterializer=Fe.ModelMaterializer=Fe.SingleConnectionRuntime=Fe.ConnectionRuntime=Fe.Runtime=Fe.ExploreField=Fe.JoinRelationship=Fe.QueryField=Fe.Query=Fe.StringField=Fe.UnsupportedField=Fe.JSONField=Fe.BooleanField=Fe.NumberField=Fe.TimestampField=Fe.DateField=Fe.TimestampTimeframe=Fe.DateTimeframe=Fe.AtomicField=Fe.AtomicFieldType=Fe.Explore=Fe.SourceRelationship=Fe.FixedConnectionMap=Fe.InMemoryURLReader=Fe.EmptyURLReader=Fe.PreparedResult=Fe.DocumentCompletion=Fe.DocumentSymbol=Fe.DocumentPosition=Fe.DocumentRange=Fe.DocumentTablePath=Fe.Parse=Fe.PreparedQuery=Fe.Model=Fe.MalloyError=Fe.Malloy=void 0;const Gfe=f4,fi=ji,Wfe=ni,pM=Z2,Ixt=U6,Bxt=tp,Nn=ai,$xt=i0,Vfe="internal://internal.malloy";let f0=class hR{static get version(){return Ixt.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(Vfe));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new Gfe.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new Kfe(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return hR._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 Y6(n,e).then(({contents:o,invalidationKey:u})=>hR._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,importBaseURL:c,cacheManager:f}){var d,h,p,m,g;let y;if(u&&(y=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(Vfe));const E={};if(n===void 0&&f!==void 0){const _=await f.getCachedModelDef(i,e.toString());if(_)return new Mp(_.modelDef,[],[e.toString(),...V6(_.modelDef.dependencies)])}c??(c=e);let A;const v=e.toString();if(r!==void 0){A=r._translator;const _=(d=r._invalidationKey)!==null&&d!==void 0?d:await DM(i,e);E[v]=_}else{if(n===void 0){const{contents:_,invalidationKey:C}=await Y6(i,e);E[v]=C,n=_}else{const _=await DM(i,e);E[v]=_}A=new Gfe.MalloyTranslator(v,c.toString(),{urls:{[v]:n}},l)}for(;;){const _=A.translate(o==null?void 0:o._modelDef);if(_.final)if(_.modelDef){await(f==null?void 0:f.setCachedModelDef(e.toString(),{modelDef:_.modelDef,invalidationKeys:E}));for(const C of A.newlyTranslatedDependencies())await(f==null?void 0:f.setCachedModelDef(C.url,{modelDef:C.modelDef,invalidationKeys:E}));return new Mp(_.modelDef,_.problems||[],[...(h=o==null?void 0:o.fromSources)!==null&&h!==void 0?h:[],...(p=_.fromSources)!==null&&p!==void 0?p:[]],C=>A.referenceAt(C),C=>A.importAt(C))}else if(a){const C={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},S=(o==null?void 0:o._modelDef)||C;return new Mp(S,_.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=_.fromSources)!==null&&g!==void 0?g:[]],T=>A.referenceAt(T),T=>A.importAt(T))}else{const C=_.problems||[],S=A.prettyErrors();throw new Yfe(`Error(s) compiling model:
1835
+ ${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}}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,cxt.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,dM.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(0,dM.rangeFromContext)(this.parseStep.sourceInfo,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))}}Bc.MalloyTranslation=hM;class zfe extends hM{constructor(e,n){super(e),this.root=n}}Bc.MalloyChildTranslator=zfe;class Fxt extends hM{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new xM.Zone,this.importZone=new xM.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new xM.Zone,this.root=this,this.logger=new qfe.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,qfe.makeLogMessage)(e,n,{severity:"error",...r})),e}}Bc.MalloyTranslator=Fxt;function Hfe(t){return[...Object.keys(t),...Object.keys(t).map(e=>Hfe(t[e])).flat()]}var kp={};Object.defineProperty(kp,"__esModule",{value:!0}),kp.exploreQueryWalkerBuilder=kp.ExploreQueryWalker=void 0;const Nxt=h0;class Qfe{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}}kp.ExploreQueryWalker=Qfe;function Lxt(t,e){const n=new Qfe(t),r=n;return Nxt.ParseTreeWalker.DEFAULT.walk(r,e),n}kp.exploreQueryWalkerBuilder=Lxt,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=Bc;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var n=kp;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(f4);var Fe={},U6={};Object.defineProperty(U6,"__esModule",{value:!0}),U6.MALLOY_VERSION=void 0,U6.MALLOY_VERSION="0.0.241",Object.defineProperty(Fe,"__esModule",{value:!0}),Fe.InMemoryModelCache=Fe.CacheManager=Fe.CSVWriter=Fe.JSONWriter=Fe.DataWriter=Fe.DataRecord=Fe.DataArray=Fe.Result=Fe.ExploreMaterializer=Fe.PreparedResultMaterializer=Fe.QueryMaterializer=Fe.ModelMaterializer=Fe.SingleConnectionRuntime=Fe.ConnectionRuntime=Fe.Runtime=Fe.ExploreField=Fe.JoinRelationship=Fe.QueryField=Fe.Query=Fe.StringField=Fe.UnsupportedField=Fe.JSONField=Fe.BooleanField=Fe.NumberField=Fe.TimestampField=Fe.DateField=Fe.TimestampTimeframe=Fe.DateTimeframe=Fe.AtomicField=Fe.AtomicFieldType=Fe.Explore=Fe.SourceRelationship=Fe.FixedConnectionMap=Fe.InMemoryURLReader=Fe.EmptyURLReader=Fe.PreparedResult=Fe.DocumentCompletion=Fe.DocumentSymbol=Fe.DocumentPosition=Fe.DocumentRange=Fe.DocumentTablePath=Fe.Parse=Fe.PreparedQuery=Fe.Model=Fe.MalloyError=Fe.Malloy=void 0;const Gfe=f4,fi=ji,Wfe=ni,pM=Z2,Ixt=U6,Bxt=tp,Nn=ai,$xt=i0,Vfe="internal://internal.malloy";let f0=class hR{static get version(){return Ixt.MALLOY_VERSION}static _parse(e,n,r,i,s){n===void 0&&(n=new URL(Vfe));let o=n;i!=null&&i.importBaseURL&&(o=i==null?void 0:i.importBaseURL);const u=new Gfe.MalloyTranslator(n.toString(),o.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(u.allDialectsEnabled=!0),new Kfe(u,s)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return hR._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 Y6(n,e).then(({contents:o,invalidationKey:u})=>hR._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,importBaseURL:c,cacheManager:f}){var d,h,p,m,g;let y;if(u&&(y=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(Vfe));const E={};if(n===void 0&&f!==void 0){const _=await f.getCachedModelDef(i,e.toString());if(_)return new Mp(_.modelDef,[],[e.toString(),...V6(_.modelDef.dependencies)])}c??(c=e);let A;const v=e.toString();if(r!==void 0){A=r._translator;const _=(d=r._invalidationKey)!==null&&d!==void 0?d:await DM(i,e);E[v]=_}else{if(n===void 0){const{contents:_,invalidationKey:C}=await Y6(i,e);E[v]=C,n=_}else{const _=await DM(i,e);E[v]=_}A=new Gfe.MalloyTranslator(v,c.toString(),{urls:{[v]:n}},l)}for(;;){const _=A.translate(o==null?void 0:o._modelDef);if(_.final)if(_.modelDef){await(f==null?void 0:f.setCachedModelDef(e.toString(),{modelDef:_.modelDef,invalidationKeys:E}));for(const C of A.newlyTranslatedDependencies())await(f==null?void 0:f.setCachedModelDef(C.url,{modelDef:C.modelDef,invalidationKeys:E}));return new Mp(_.modelDef,_.problems||[],[...(h=o==null?void 0:o.fromSources)!==null&&h!==void 0?h:[],...(p=_.fromSources)!==null&&p!==void 0?p:[]],C=>A.referenceAt(C),C=>A.importAt(C))}else if(a){const C={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},S=(o==null?void 0:o._modelDef)||C;return new Mp(S,_.problems||[],[...(m=o==null?void 0:o.fromSources)!==null&&m!==void 0?m:[],...(g=_.fromSources)!==null&&g!==void 0?g:[]],T=>A.referenceAt(T),T=>A.importAt(T))}else{const C=_.problems||[],S=A.prettyErrors();throw new Yfe(`Error(s) compiling model:
1836
1836
  ${S}`,C)}else{if(_.urls)for(const S of _.urls)try{if(K6(S))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(f!==void 0){const L=await f.getCachedModelDef(i,S);if(L){for(const M in L.invalidationKeys)E[M]=L.invalidationKeys[M];A.update({translations:{[S]:L.modelDef}});continue}}const{contents:T,invalidationKey:w}=await Y6(i,new URL(S)),I={[S]:T};E[S]=w,A.update({urls:I})}catch(T){A.update({errors:{urls:{[S]:T.message}}})}const{modelAnnotation:C}=A.modelAnnotation(o==null?void 0:o._modelDef);if(_.tables){const S=new Map;for(const T in _.tables){const{connectionName:w,tablePath:I}=_.tables[T],L=S.get(w);L===void 0?S.set(w,{[T]:I}):L[T]=I}for(const[T,w]of S)try{const I=await s.lookupConnection(T),{schemas:L,errors:M}=await hR.safelyFetchTableSchema(I,w,{refreshTimestamp:y,modelAnnotation:C});A.update({tables:L,errors:{tables:M}})}catch(I){const L={},M={};for(const z in w)M[z]=I.toString();A.update({tables:L,errors:{tables:M}})}}if(_.compileSQL){const S=_.compileSQL,T=S.connection,w=(0,$xt.sqlKey)(S.connection,S.selectStr);try{const L=await(await s.lookupConnection(T)).fetchSchemaForSQLStruct(S,{refreshTimestamp:y,modelAnnotation:C});L.error&&A.update({errors:{compileSQL:{[w]:L.error}}}),L.structDef&&A.update({compileSQL:{[w]:L.structDef}})}catch(I){const L={};L[w]=I.toString(),A.update({errors:{compileSQL:L}})}}}}}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 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 OE({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 OE({...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 js(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 Sd(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.")}};Fe.Malloy=f0;class Yfe extends Error{constructor(e,n=[]){super(e),this.problems=n}}Fe.MalloyError=Yfe;class Mp{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,Nn.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,Nn.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 Pp(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 Pp(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 Pp(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,fi.isSourceDef)(n))return new js(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(fi.isSourceDef).map(e=>new js(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}}Fe.Model=Mp;class Pp{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=(0,Nn.annotationToTag)(this._modelDef.annotation).tag;return e=(0,Nn.addModelScope)(e,n),(0,Nn.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new fi.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new RE({...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,fi.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}Fe.PreparedQuery=Pp;class Kfe{constructor(e,n){this.translator=e,this.invalidationKey=n}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new q6(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new Jfe(r))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new Xfe(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}Fe.Parse=Kfe;class Jfe{constructor(e){this._range=jp.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}}Fe.DocumentTablePath=Jfe;class jp{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 jp(new gM(e.start.line,e.start.character),new gM(e.end.line,e.end.character))}}Fe.DocumentRange=jp;class gM{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}}}Fe.DocumentPosition=gM;class q6{constructor(e){this._range=jp.fromJSON(e.range),this._lensRange=e.lensRange?jp.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new q6(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}}Fe.DocumentSymbol=q6;class Xfe{constructor(e){this.type=e.type,this.text=e.text}}Fe.DocumentCompletion=Xfe;class RE{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 RE(e,n)}tagParse(e){const n=(0,Nn.annotationToTag)(this.modelDef.annotation).tag;return e=(0,Nn.addModelScope)(e,n),(0,Nn.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,Nn.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 js(n,this.sourceExplore)}catch{return new js(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n&&(0,fi.isSourceDef)(n))return new js(n)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}Fe.PreparedResult=RE;class Zfe{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}Fe.EmptyURLReader=Zfe;class kxt{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 K6(e.toString())?null:hxe(n)}}Fe.InMemoryURLReader=kxt;class z6{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 z6(new Map(e.map(n=>[n.name,n])))}}Fe.FixedConnectionMap=z6;var exe;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(exe||(Fe.SourceRelationship=exe={}));class mM{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 js}isQuery(){return this instanceof SM}}class js extends mM{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,fi.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,Nn.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,Nn.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 Pp(r,this.modelDef,[],e)}get modelDef(){if(!(0,fi.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 Mp(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,fi.isJoined)(r))return[i,new bM(r,this,s)];if(r.type==="turtle")return[i,new SM(r,this,s)];if(r.type==="string")return[i,new CM(r,this,s)];if(r.type==="number")return[i,new H6(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new H6({...r,type:"number"},this,s)]:[i,new yM(r,this,s)];if(r.type==="timestamp")return[i,new EM(r,this,s)];if(r.type==="boolean")return[i,new AM(r,this,s)];if(r.type==="json")return[i,new vM(r,this,s)];if(r.type==="sql native")return[i,new _M(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 bM}get filters(){var e;return(0,fi.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,fi.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?js.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?js.fromJSON(e.sourceExplore):void 0;return new js(e._structDef,n,r)}get location(){return this.structDef.location}}Fe.Explore=js;var $a;(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"})($a||(Fe.AtomicFieldType=$a={}));class tf extends mM{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 $a.String;case"boolean":return $a.Boolean;case"date":return $a.Date;case"timestamp":return $a.Timestamp;case"number":return $a.Number;case"json":return $a.Json;case"sql native":return $a.NativeUnsupported;case"error":return $a.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,Nn.addModelScope)(e,this.parent.modelTag),(0,Nn.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,Nn.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,fi.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,fi.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 CM}isNumber(){return this instanceof H6}isDate(){return this instanceof yM}isBoolean(){return this instanceof AM}isJSON(){return this instanceof vM}isTimestamp(){return this instanceof EM}isUnsupported(){return this instanceof _M}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}}Fe.AtomicField=tf;var Cd;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Cd||(Fe.DateTimeframe=Cd={}));var ka;(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"})(ka||(Fe.TimestampTimeframe=ka={}));class yM extends tf{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 Cd.Day;case"week":return Cd.Week;case"month":return Cd.Month;case"quarter":return Cd.Quarter;case"year":return Cd.Year}}}Fe.DateField=yM;class EM extends tf{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 ka.Day;case"week":return ka.Week;case"month":return ka.Month;case"quarter":return ka.Quarter;case"year":return ka.Year;case"second":return ka.Second;case"hour":return ka.Hour;case"minute":return ka.Minute}}}Fe.TimestampField=EM;class H6 extends tf{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}Fe.NumberField=H6;class AM extends tf{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}Fe.BooleanField=AM;class vM extends tf{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}Fe.JSONField=vM;class _M extends tf{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Fe.UnsupportedField=_M;class CM extends tf{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}Fe.StringField=CM;class txe extends mM{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}}Fe.Query=txe;class SM extends txe{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=(0,Nn.addModelScope)(e,this.parent.modelTag),(0,Nn.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,Nn.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}}Fe.QueryField=SM;var Up;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(Up||(Fe.JoinRelationship=Up={}));class bM extends js{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,fi.isJoined)(this.structDef))switch(this.structDef.join){case"one":return Up.OneToOne;case"many":case"cross":return Up.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===Up.OneToOne}get isArray(){return this.joinRelationship!==Up.OneToOne}tagParse(e){return e=(0,Nn.addModelScope)(e,this._parentExplore.modelTag),(0,Nn.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]:[]}}Fe.ExploreField=bM;class TM{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 Zfe),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 DE(this,async()=>f0.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 DE(this,async()=>new Mp(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()}}Fe.Runtime=TM;class Mxt extends TM{constructor({urlReader:e,connections:n}){super({connections:z6.fromArray(n),urlReader:e}),this.rawConnections=n}}Fe.ConnectionRuntime=Mxt;class Pxt extends TM{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,pM.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,pM.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,pM.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Fe.SingleConnectionRuntime=Pxt;class Q6{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 nxe(this.runtime,e,n)}makeExploreMaterializer(e,n){return new ixe(this.runtime,e,n)}makePreparedResultMaterializer(e){return new rxe(this.runtime,e)}}class DE extends Q6{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 f0.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 DE(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 f0.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 fi.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,fi.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,fi.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=`
1837
1837
  run: ${e}
1838
1838
  -> ${o}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@malloydata/render",
3
- "version": "0.0.240-dev250311214430",
3
+ "version": "0.0.241-dev250311221410",
4
4
  "license": "MIT",
5
5
  "main": "dist/module/index.umd.js",
6
6
  "types": "dist/index.d.ts",
@@ -31,10 +31,10 @@
31
31
  "build-types": "tsc --build --declaration --emitDeclarationOnly"
32
32
  },
33
33
  "dependencies": {
34
- "@malloydata/db-duckdb": "^0.0.240-dev250311214430",
35
- "@malloydata/malloy": "^0.0.240-dev250311214430",
36
- "@malloydata/malloy-interfaces": "^0.0.240-dev250311214430",
37
- "@malloydata/malloy-tag": "^0.0.240-dev250311214430",
34
+ "@malloydata/db-duckdb": "^0.0.241-dev250311221410",
35
+ "@malloydata/malloy": "^0.0.241-dev250311221410",
36
+ "@malloydata/malloy-interfaces": "^0.0.241-dev250311221410",
37
+ "@malloydata/malloy-tag": "^0.0.241-dev250311221410",
38
38
  "@tanstack/solid-virtual": "^3.10.4",
39
39
  "component-register": "^0.8.6",
40
40
  "lodash": "^4.17.20",