@malloydata/render 0.0.206-dev241101154502 → 0.0.207-dev241101160127
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module/index.mjs
CHANGED
|
@@ -51806,7 +51806,7 @@ Cd.exploreQueryWalkerBuilder = dTe;
|
|
|
51806
51806
|
var Oe = {}, V5 = {};
|
|
51807
51807
|
Object.defineProperty(V5, "__esModule", { value: !0 });
|
|
51808
51808
|
V5.MALLOY_VERSION = void 0;
|
|
51809
|
-
V5.MALLOY_VERSION = "0.0.
|
|
51809
|
+
V5.MALLOY_VERSION = "0.0.207";
|
|
51810
51810
|
Object.defineProperty(Oe, "__esModule", { value: !0 });
|
|
51811
51811
|
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;
|
|
51812
51812
|
const hTe = X8, fr = fs, LM = CK, yn = Su, d6 = rh, pTe = V5;
|
package/dist/module/index.umd.js
CHANGED
|
@@ -1326,7 +1326,7 @@ QUERY: ${(0,vq.inspect)(n,{breakLength:72,depth:1/0})}`)}return Sq.ErrorFactory.
|
|
|
1326
1326
|
| ${l}`,u>0&&(i=i+`
|
|
1327
1327
|
| ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
|
|
1328
1328
|
`+i,n=s),e!==""?e=`${e}
|
|
1329
|
-
${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().translated)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,Ube.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}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,Kbe.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<=o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}tu.MalloyTranslation=vD;class SQ extends vD{constructor(e,n){super(e),this.root=n}}tu.MalloyChildTranslator=SQ;class lTe extends vD{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new _D.Zone,this.importZone=new _D.Zone,this.sqlQueryZone=new _D.Zone,this.root=this,this.logger=new AD.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)}logError(e,n,r){return this.logger.log((0,AD.makeLogMessage)(e,n,{severity:"error",...r})),e}}tu.MalloyTranslator=lTe;class CQ{constructor(e,n){this.translator=e,this.messages=n}logError(e,n,r){return this.messages.log((0,AD.makeLogMessage)(e,n,{severity:"error",...r})),e}syntaxError(e,n,r,i,s,o){const u={line:r-1,character:i},a=n?this.translator.rangeFromToken(n):{start:u,end:u};this.logError("syntax-error",{message:s},{at:{url:this.translator.sourceURL,range:a}})}}tu.MalloyParserErrorHandler=CQ;var kd={};Object.defineProperty(kd,"__esModule",{value:!0}),kd.exploreQueryWalkerBuilder=kd.ExploreQueryWalker=void 0;const cTe=gl;class bQ{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}}kd.ExploreQueryWalker=bQ;function fTe(t,e){const n=new bQ(t),r=n;return cTe.ParseTreeWalker.DEFAULT.walk(r,e),n}kd.exploreQueryWalkerBuilder=fTe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslator=void 0;var e=tu;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}});var n=kd;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(G6);var Oe={},Dv={};Object.defineProperty(Dv,"__esModule",{value:!0}),Dv.MALLOY_VERSION=void 0,Dv.MALLOY_VERSION="0.0.
|
|
1329
|
+
${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().translated)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,Ube.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}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,Kbe.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<=o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}tu.MalloyTranslation=vD;class SQ extends vD{constructor(e,n){super(e),this.root=n}}tu.MalloyChildTranslator=SQ;class lTe extends vD{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new _D.Zone,this.importZone=new _D.Zone,this.sqlQueryZone=new _D.Zone,this.root=this,this.logger=new AD.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)}logError(e,n,r){return this.logger.log((0,AD.makeLogMessage)(e,n,{severity:"error",...r})),e}}tu.MalloyTranslator=lTe;class CQ{constructor(e,n){this.translator=e,this.messages=n}logError(e,n,r){return this.messages.log((0,AD.makeLogMessage)(e,n,{severity:"error",...r})),e}syntaxError(e,n,r,i,s,o){const u={line:r-1,character:i},a=n?this.translator.rangeFromToken(n):{start:u,end:u};this.logError("syntax-error",{message:s},{at:{url:this.translator.sourceURL,range:a}})}}tu.MalloyParserErrorHandler=CQ;var kd={};Object.defineProperty(kd,"__esModule",{value:!0}),kd.exploreQueryWalkerBuilder=kd.ExploreQueryWalker=void 0;const cTe=gl;class bQ{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}}kd.ExploreQueryWalker=bQ;function fTe(t,e){const n=new bQ(t),r=n;return cTe.ParseTreeWalker.DEFAULT.walk(r,e),n}kd.exploreQueryWalkerBuilder=fTe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslator=void 0;var e=tu;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}});var n=kd;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(G6);var Oe={},Dv={};Object.defineProperty(Dv,"__esModule",{value:!0}),Dv.MALLOY_VERSION=void 0,Dv.MALLOY_VERSION="0.0.207",Object.defineProperty(Oe,"__esModule",{value:!0}),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 xTe=G6,hr=Ui,TQ=Fz,An=jo,SD=xx,dTe=Dv;class wn{static get version(){return dTe.MALLOY_VERSION}static _parse(e,n,r,i){n===void 0&&(n=new URL("internal://internal.malloy"));let s=n;i!=null&&i.importBaseURL&&(s=i==null?void 0:i.importBaseURL);const o=new xTe.MalloyTranslator(n.toString(),s.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(o.allDialectsEnabled=!0),new OQ(o)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return wn._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 n.readURL(e).then(o=>wn._parse(o,e,i,s))}static async compile({urlReader:e,connections:n,parse:r,model:i,refreshSchemaCache:s,noThrowOnError:o,eventStream:u,replaceMaterializedReferences:a,materializedTablePrefix:l}){var c,f,x,d;let p;s&&(p=typeof s=="number"?s:Date.now());const m=r._translator;for(;;){const g=m.translate(i==null?void 0:i._modelDef);if(g.final){if(g.translated)return new sg(g.translated.modelDef,g.translated.queryList,g.problems||[],[...(c=i==null?void 0:i.fromSources)!==null&&c!==void 0?c:[],...(f=g.fromSources)!==null&&f!==void 0?f:[]],y=>m.referenceAt(y),y=>m.importAt(y));if(o){const y={name:"modelDidNotCompile",exports:[],contents:{}},E=(i==null?void 0:i._modelDef)||y;return new sg(E,[],g.problems||[],[...(x=i==null?void 0:i.fromSources)!==null&&x!==void 0?x:[],...(d=g.fromSources)!==null&&d!==void 0?d:[]],A=>m.referenceAt(A),A=>m.importAt(A))}else{const y=g.problems||[],E=m.prettyErrors();throw new RQ(`Error(s) compiling model:
|
|
1330
1330
|
${E}`,y)}}else{if(g.urls)for(const E of g.urls)try{if(E.startsWith("internal://"))throw new Error("In order to use relative imports, you must compile a file via a URL.");const A=await e.readURL(new URL(E)),_={[E]:A};m.update({urls:_})}catch(A){m.update({errors:{urls:{[E]:A.message}}})}const{modelAnnotation:y}=m.modelAnnotation(i==null?void 0:i._modelDef);if(g.tables){const E=new Map;for(const A in g.tables){const{connectionName:_,tablePath:v}=g.tables[A],C=E.get(_);C===void 0?E.set(_,{[A]:v}):C[A]=v}for(const[A,_]of E)try{const v=await n.lookupConnection(A),{schemas:C,errors:S}=await wn.safelyFetchTableSchema(v,_,{refreshTimestamp:p,modelAnnotation:y});m.update({tables:C,errors:{tables:S}})}catch(v){const C={},S={};for(const b in _)S[b]=v.toString();m.update({tables:C,errors:{tables:S}})}}if(g.compileSQL){const E=g.compileSQL,A=E.connection;try{const _=await n.lookupConnection(A),v=wn.compileSQLBlock(_.dialectName,g.partialModel,E,{replaceMaterializedReferences:a,materializedTablePrefix:l,eventStream:u}),C=await _.fetchSchemaForSQLStruct(v,{refreshTimestamp:p,modelAnnotation:y});C.error&&m.update({errors:{compileSQL:{[v.name]:C.error}}}),C.structDef&&m.update({compileSQL:{[v.name]:C.structDef}})}catch(_){const v={};v[E.name]=_.toString(),m.update({errors:{compileSQL:v}})}}}}}static async safelyFetchTableSchema(e,n,r){const i=await e.fetchSchemaForTables(n,r);for(const s of Object.keys(n))if(i.schemas[s]===void 0&&i.errors[s]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${s} from ${e.dialectName}`);return i}static compileSQLBlock(e,n,r,i){let s,o="",u=!1;for(const c of r.select)if((0,hr.isSegmentSQL)(c))o+=c.sql,u=c.sql.match(/\(\s*$/)!==null;else{if(!s){if(!n)throw new Error("Internal error: Partial model missing when compiling SQL block");s=new hr.QueryModel(n,i==null?void 0:i.eventStream)}const f=s.compileQuery(c,i,!1).sql;o+=u?f:`(${f})`,u=!1}const{name:a,connection:l}=r;return{type:"sql_select",name:a,connection:l,dialect:e,selectStr:o,fields:[]}}static async run({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(!i){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);i=await e.lookupConnection(o)}if(r){const o=await i.runSQL(r.selectStr);return new lg({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:{}})}else if(n){const o=await i.runSQL(n.sql,s);return new lg({...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 es(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 Xc(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=wn;class RQ extends Error{constructor(e,n=[]){super(e),this.problems=n}}Oe.MalloyError=RQ;let sg=class{constructor(e,n,r,i,s=()=>{},o=()=>{}){this.modelDef=e,this.queryList=n,this.problems=r,this.fromSources=i,this._referenceAt=s,this._importAt=o}tagParse(e){return An.Tag.annotationToTag(this.modelDef.annotation,e)}getTaglines(e){return An.Tag.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 Pd(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.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new Pd(this.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.queryList.length===0)throw new Error("Model has no queries.");return new Pd(this.queryList[this.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,hr.isSourceDef)(n))return new es(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(hr.isSourceDef).map(e=>new es(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=sg;class Pd{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=An.Tag.annotationToTag(this._modelDef.annotation).tag;return e=An.Tag.addModelScope(e,n),An.Tag.annotationToTag(this._query.annotation,e)}getTaglines(e){return An.Tag.annotationToTaglines(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new hr.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new og({...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,hr.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}Oe.PreparedQuery=Pd;class OQ{constructor(e){this.translator=e}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new Nv(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new DQ(r))}get _translator(){return this.translator}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new NQ(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}Oe.Parse=OQ;class DQ{constructor(e){this._range=Md.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=DQ;class Md{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 Md(new CD(e.start.line,e.start.character),new CD(e.end.line,e.end.character))}}Oe.DocumentRange=Md;class CD{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=CD;class Nv{constructor(e){this._range=Md.fromJSON(e.range),this._lensRange=e.lensRange?Md.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new Nv(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=Nv;class NQ{constructor(e){this.type=e.type,this.text=e.text}}Oe.DocumentCompletion=NQ;class og{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 og(e,n)}tagParse(e){const n=An.Tag.annotationToTag(this.modelDef.annotation).tag;return e=An.Tag.addModelScope(e,n),An.Tag.annotationToTag(this.inner.annotation,e)}getTaglines(e){return An.Tag.annotationToTaglines(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return An.Tag.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 es(n,this.sourceExplore)}catch{return new es(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n===void 0)throw new Error("Malformed query result.");if((0,hr.isSourceDef)(n))return new es(n);throw new Error(`'${e} is not an explore`)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}Oe.PreparedResult=og;class wQ{async readURL(e){throw new Error("No files.")}}Oe.EmptyURLReader=wQ;class hTe{constructor(e){this.files=e}async readURL(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve(n);throw new Error(`File not found '${e}'`)}}Oe.InMemoryURLReader=hTe;class ug{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 ug(new Map(e.map(n=>[n.name,n])))}}Oe.FixedConnectionMap=ug;var FQ;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(FQ||(Oe.SourceRelationship=FQ={}));class bD{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 es}isQuery(){return this instanceof FD}}class es extends bD{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,hr.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return An.Tag.annotationToTag(this._structDef.annotation,e)}getTaglines(e){return An.Tag.annotationToTaglines(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=An.Tag.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 Pd(r,this.modelDef,[],e)}get modelDef(){return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef}}}getSingleExploreModel(){return new sg(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,hr.isJoined)(r))return[i,new LD(r,this,s)];if(r.type==="turtle")return[i,new FD(r,this,s)];if(r.type==="string")return[i,new wD(r,this,s)];if(r.type==="number")return[i,new wv(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new wv({...r,type:"number"},this,s)]:[i,new TD(r,this,s)];if(r.type==="timestamp")return[i,new RD(r,this,s)];if(r.type==="boolean")return[i,new OD(r,this,s)];if(r.type==="json")return[i,new DD(r,this,s)];if(r.type==="sql native")return[i,new ND(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 LD}get filters(){var e;return(0,hr.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,hr.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?es.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?es.fromJSON(e.sourceExplore):void 0;return new es(e._structDef,n,r)}get location(){return this.structDef.location}}Oe.Explore=es;var cu;(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"})(cu||(Oe.AtomicFieldType=cu={}));class Zl extends bD{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 cu.String;case"boolean":return cu.Boolean;case"date":return cu.Date;case"timestamp":return cu.Timestamp;case"number":return cu.Number;case"json":return cu.Json;case"sql native":return cu.NativeUnsupported;case"error":return cu.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=An.Tag.addModelScope(e,this.parent.modelTag),An.Tag.annotationToTag(this.fieldTypeDef.annotation,e)}getTaglines(e){return An.Tag.annotationToTaglines(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,hr.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,hr.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 wD}isNumber(){return this instanceof wv}isDate(){return this instanceof TD}isBoolean(){return this instanceof OD}isJSON(){return this instanceof DD}isTimestamp(){return this instanceof RD}isUnsupported(){return this instanceof ND}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=Zl;var Jc;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Jc||(Oe.DateTimeframe=Jc={}));var fu;(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"})(fu||(Oe.TimestampTimeframe=fu={}));class TD extends Zl{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 Jc.Day;case"week":return Jc.Week;case"month":return Jc.Month;case"quarter":return Jc.Quarter;case"year":return Jc.Year}}}Oe.DateField=TD;class RD extends Zl{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 fu.Day;case"week":return fu.Week;case"month":return fu.Month;case"quarter":return fu.Quarter;case"year":return fu.Year;case"second":return fu.Second;case"hour":return fu.Hour;case"minute":return fu.Minute}}}Oe.TimestampField=RD;class wv extends Zl{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}Oe.NumberField=wv;class OD extends Zl{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}Oe.BooleanField=OD;class DD extends Zl{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}Oe.JSONField=DD;class ND extends Zl{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Oe.UnsupportedField=ND;class wD extends Zl{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}Oe.StringField=wD;class LQ extends bD{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=LQ;class FD extends LQ{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=An.Tag.addModelScope(e,this.parent.modelTag),An.Tag.annotationToTag(this.turtleDef.annotation,e)}getTaglines(e){return An.Tag.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=FD;var jd;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(jd||(Oe.JoinRelationship=jd={}));class LD extends es{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,hr.isJoined)(this.structDef))switch(this.structDef.join){case"one":return jd.OneToOne;case"many":case"cross":return jd.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===jd.OneToOne}get isArray(){return this.joinRelationship!==jd.OneToOne}tagParse(e){return e=An.Tag.addModelScope(e,this._parentExplore.modelTag),An.Tag.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=LD;class ID{constructor(...e){this.isTestRuntime=!1;let n,r,i;for(const s of e)s!==void 0&&(GQ(s)?n=s:ETe(s)?r=s:WQ(s)?i=s:r={lookupConnection:()=>Promise.resolve(s)});if(n===void 0&&(n=new wQ),r===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");this._urlReader=n,this._connections=r,this._eventStream=i}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};return this.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new ag(this,async()=>{const s=e instanceof URL?await wn.parse({url:e,urlReader:this.urlReader,eventStream:this.eventStream,options:n}):wn.parse({source:e,eventStream:this.eventStream,options:n});return wn.compile({urlReader:this.urlReader,connections:this.connections,parse:s,refreshSchemaCache:r,noThrowOnError:i,eventStream:this.eventStream,replaceMaterializedReferences:n==null?void 0:n.replaceMaterializedReferences,materializedTablePrefix:n==null?void 0:n.materializedTablePrefix})},n)}_loadModelFromModelDef(e,n){return new ag(this,async()=>new sg(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=ID;class pTe extends ID{constructor(e,n){if(n===void 0){const r=e;super(ug.fromArray(r)),this.rawConnections=r}else{const r=n;super(e,ug.fromArray(r)),this.rawConnections=r}}}Oe.ConnectionRuntime=pTe;class gTe extends ID{constructor(...e){let n,r,i;for(const s of e)GQ(s)&&(n=s),ATe(s)&&(r=s),WQ(s)&&(i=s);if(r===void 0)throw new Error("Expected connection to be passed into SingleConnectionRuntime");super(n,r,i),this.connection=r}get supportsNesting(){return(0,SD.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,SD.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,SD.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Oe.SingleConnectionRuntime=gTe;class Fv{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 IQ(this.runtime,e,n)}makeExploreMaterializer(e,n){return new BQ(this.runtime,e,n)}makePreparedResultMaterializer(e){return new $Q(this.runtime,e)}}class ag extends Fv{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?await wn.parse({url:e,urlReader:s,options:n}):wn.parse({source:e,options:n}),a=await this.getModel();return(await wn.compile({urlReader:s,connections:o,parse:u,model:a,refreshSchemaCache:r,noThrowOnError:i,...this.compileQueryOptions})).preparedQuery})}extendModel(e,n){return this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new ag(this.runtime,async()=>{const r=this.runtime.urlReader,i=this.runtime.connections,s=e instanceof URL?await wn.parse({url:e,urlReader:r,options:n}):wn.parse({source:e,options:n}),o=await this.getModel();return await wn.compile({urlReader:r,connections:i,parse:s,model:o,refreshSchemaCache:n==null?void 0:n.refreshSchemaCache,noThrowOnError:n==null?void 0:n.noThrowOnError,...this.compileQueryOptions})},n)}async search(e,n,r=1e3,i=void 0,s){const o=await this.materialize(),u=new hr.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,hr.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,hr.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=`
|
|
1331
1331
|
run: ${e}
|
|
1332
1332
|
-> ${o}
|
|
@@ -52963,7 +52963,7 @@ ih.exploreQueryWalkerBuilder = iRe;
|
|
|
52963
52963
|
var De = {}, R5 = {};
|
|
52964
52964
|
Object.defineProperty(R5, "__esModule", { value: !0 });
|
|
52965
52965
|
R5.MALLOY_VERSION = void 0;
|
|
52966
|
-
R5.MALLOY_VERSION = "0.0.
|
|
52966
|
+
R5.MALLOY_VERSION = "0.0.207";
|
|
52967
52967
|
Object.defineProperty(De, "__esModule", { value: !0 });
|
|
52968
52968
|
De.CSVWriter = De.JSONWriter = De.DataWriter = De.DataRecord = De.DataArray = De.Result = De.ExploreMaterializer = De.PreparedResultMaterializer = De.QueryMaterializer = De.ModelMaterializer = De.SingleConnectionRuntime = De.ConnectionRuntime = De.Runtime = De.ExploreField = De.JoinRelationship = De.QueryField = De.Query = De.StringField = De.UnsupportedField = De.JSONField = De.BooleanField = De.NumberField = De.TimestampField = De.DateField = De.TimestampTimeframe = De.DateTimeframe = De.AtomicField = De.AtomicFieldType = De.Explore = De.SourceRelationship = De.FixedConnectionMap = De.InMemoryURLReader = De.EmptyURLReader = De.PreparedResult = De.DocumentCompletion = De.DocumentSymbol = De.DocumentPosition = De.DocumentRange = De.DocumentTablePath = De.Parse = De.PreparedQuery = De.Model = De.MalloyError = De.Malloy = void 0;
|
|
52969
52969
|
const sRe = b8, pr = ys, fj = Gi, vn = Mu, X6 = jh, oRe = R5;
|
|
@@ -1326,7 +1326,7 @@ QUERY: ${(0,dz.inspect)(n,{breakLength:72,depth:1/0})}`)}return hz.ErrorFactory.
|
|
|
1326
1326
|
| ${l}`,u>0&&(i=i+`
|
|
1327
1327
|
| ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
|
|
1328
1328
|
`+i,n=s),e!==""?e=`${e}
|
|
1329
|
-
${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().translated)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,F6e.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}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,U6e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<=o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}pu.MalloyTranslation=h7;class dG extends h7{constructor(e,n){super(e),this.root=n}}pu.MalloyChildTranslator=dG;class eRe extends h7{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new d7.Zone,this.importZone=new d7.Zone,this.sqlQueryZone=new d7.Zone,this.root=this,this.logger=new x7.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)}logError(e,n,r){return this.logger.log((0,x7.makeLogMessage)(e,n,{severity:"error",...r})),e}}pu.MalloyTranslator=eRe;class hG{constructor(e,n){this.translator=e,this.messages=n}logError(e,n,r){return this.messages.log((0,x7.makeLogMessage)(e,n,{severity:"error",...r})),e}syntaxError(e,n,r,i,s,o){const u={line:r-1,character:i},a=n?this.translator.rangeFromToken(n):{start:u,end:u};this.logError("syntax-error",{message:s},{at:{url:this.translator.sourceURL,range:a}})}}pu.MalloyParserErrorHandler=hG;var xh={};Object.defineProperty(xh,"__esModule",{value:!0}),xh.exploreQueryWalkerBuilder=xh.ExploreQueryWalker=void 0;const tRe=$l;class pG{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}}xh.ExploreQueryWalker=pG;function nRe(t,e){const n=new pG(t),r=n;return tRe.ParseTreeWalker.DEFAULT.walk(r,e),n}xh.exploreQueryWalkerBuilder=nRe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslator=void 0;var e=pu;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}});var n=xh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(PR);var De={},CS={};Object.defineProperty(CS,"__esModule",{value:!0}),CS.MALLOY_VERSION=void 0,CS.MALLOY_VERSION="0.0.
|
|
1329
|
+
${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().translated)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,F6e.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}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,U6e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<=o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}pu.MalloyTranslation=h7;class dG extends h7{constructor(e,n){super(e),this.root=n}}pu.MalloyChildTranslator=dG;class eRe extends h7{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new d7.Zone,this.importZone=new d7.Zone,this.sqlQueryZone=new d7.Zone,this.root=this,this.logger=new x7.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)}logError(e,n,r){return this.logger.log((0,x7.makeLogMessage)(e,n,{severity:"error",...r})),e}}pu.MalloyTranslator=eRe;class hG{constructor(e,n){this.translator=e,this.messages=n}logError(e,n,r){return this.messages.log((0,x7.makeLogMessage)(e,n,{severity:"error",...r})),e}syntaxError(e,n,r,i,s,o){const u={line:r-1,character:i},a=n?this.translator.rangeFromToken(n):{start:u,end:u};this.logError("syntax-error",{message:s},{at:{url:this.translator.sourceURL,range:a}})}}pu.MalloyParserErrorHandler=hG;var xh={};Object.defineProperty(xh,"__esModule",{value:!0}),xh.exploreQueryWalkerBuilder=xh.ExploreQueryWalker=void 0;const tRe=$l;class pG{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}}xh.ExploreQueryWalker=pG;function nRe(t,e){const n=new pG(t),r=n;return tRe.ParseTreeWalker.DEFAULT.walk(r,e),n}xh.exploreQueryWalkerBuilder=nRe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslator=void 0;var e=pu;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}});var n=xh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(PR);var De={},CS={};Object.defineProperty(CS,"__esModule",{value:!0}),CS.MALLOY_VERSION=void 0,CS.MALLOY_VERSION="0.0.207",Object.defineProperty(De,"__esModule",{value:!0}),De.CSVWriter=De.JSONWriter=De.DataWriter=De.DataRecord=De.DataArray=De.Result=De.ExploreMaterializer=De.PreparedResultMaterializer=De.QueryMaterializer=De.ModelMaterializer=De.SingleConnectionRuntime=De.ConnectionRuntime=De.Runtime=De.ExploreField=De.JoinRelationship=De.QueryField=De.Query=De.StringField=De.UnsupportedField=De.JSONField=De.BooleanField=De.NumberField=De.TimestampField=De.DateField=De.TimestampTimeframe=De.DateTimeframe=De.AtomicField=De.AtomicFieldType=De.Explore=De.SourceRelationship=De.FixedConnectionMap=De.InMemoryURLReader=De.EmptyURLReader=De.PreparedResult=De.DocumentCompletion=De.DocumentSymbol=De.DocumentPosition=De.DocumentRange=De.DocumentTablePath=De.Parse=De.PreparedQuery=De.Model=De.MalloyError=De.Malloy=void 0;const rRe=PR,yr=Vi,gG=wi,Sn=eu,p7=Ux,iRe=CS;class In{static get version(){return iRe.MALLOY_VERSION}static _parse(e,n,r,i){n===void 0&&(n=new URL("internal://internal.malloy"));let s=n;i!=null&&i.importBaseURL&&(s=i==null?void 0:i.importBaseURL);const o=new rRe.MalloyTranslator(n.toString(),s.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(o.allDialectsEnabled=!0),new yG(o)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return In._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 n.readURL(e).then(o=>In._parse(o,e,i,s))}static async compile({urlReader:e,connections:n,parse:r,model:i,refreshSchemaCache:s,noThrowOnError:o,eventStream:u,replaceMaterializedReferences:a,materializedTablePrefix:l}){var c,f,x,d;let p;s&&(p=typeof s=="number"?s:Date.now());const g=r._translator;for(;;){const m=g.translate(i==null?void 0:i._modelDef);if(m.final){if(m.translated)return new Hg(m.translated.modelDef,m.translated.queryList,m.problems||[],[...(c=i==null?void 0:i.fromSources)!==null&&c!==void 0?c:[],...(f=m.fromSources)!==null&&f!==void 0?f:[]],y=>g.referenceAt(y),y=>g.importAt(y));if(o){const y={name:"modelDidNotCompile",exports:[],contents:{}},E=(i==null?void 0:i._modelDef)||y;return new Hg(E,[],m.problems||[],[...(x=i==null?void 0:i.fromSources)!==null&&x!==void 0?x:[],...(d=m.fromSources)!==null&&d!==void 0?d:[]],A=>g.referenceAt(A),A=>g.importAt(A))}else{const y=m.problems||[],E=g.prettyErrors();throw new mG(`Error(s) compiling model:
|
|
1330
1330
|
${E}`,y)}}else{if(m.urls)for(const E of m.urls)try{if(E.startsWith("internal://"))throw new Error("In order to use relative imports, you must compile a file via a URL.");const A=await e.readURL(new URL(E)),v={[E]:A};g.update({urls:v})}catch(A){g.update({errors:{urls:{[E]:A.message}}})}const{modelAnnotation:y}=g.modelAnnotation(i==null?void 0:i._modelDef);if(m.tables){const E=new Map;for(const A in m.tables){const{connectionName:v,tablePath:_}=m.tables[A],S=E.get(v);S===void 0?E.set(v,{[A]:_}):S[A]=_}for(const[A,v]of E)try{const _=await n.lookupConnection(A),{schemas:S,errors:b}=await In.safelyFetchTableSchema(_,v,{refreshTimestamp:p,modelAnnotation:y});g.update({tables:S,errors:{tables:b}})}catch(_){const S={},b={};for(const C in v)b[C]=_.toString();g.update({tables:S,errors:{tables:b}})}}if(m.compileSQL){const E=m.compileSQL,A=E.connection;try{const v=await n.lookupConnection(A),_=In.compileSQLBlock(v.dialectName,m.partialModel,E,{replaceMaterializedReferences:a,materializedTablePrefix:l,eventStream:u}),S=await v.fetchSchemaForSQLStruct(_,{refreshTimestamp:p,modelAnnotation:y});S.error&&g.update({errors:{compileSQL:{[_.name]:S.error}}}),S.structDef&&g.update({compileSQL:{[_.name]:S.structDef}})}catch(v){const _={};_[E.name]=v.toString(),g.update({errors:{compileSQL:_}})}}}}}static async safelyFetchTableSchema(e,n,r){const i=await e.fetchSchemaForTables(n,r);for(const s of Object.keys(n))if(i.schemas[s]===void 0&&i.errors[s]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${s} from ${e.dialectName}`);return i}static compileSQLBlock(e,n,r,i){let s,o="",u=!1;for(const c of r.select)if((0,yr.isSegmentSQL)(c))o+=c.sql,u=c.sql.match(/\(\s*$/)!==null;else{if(!s){if(!n)throw new Error("Internal error: Partial model missing when compiling SQL block");s=new yr.QueryModel(n,i==null?void 0:i.eventStream)}const f=s.compileQuery(c,i,!1).sql;o+=u?f:`(${f})`,u=!1}const{name:a,connection:l}=r;return{type:"sql_select",name:a,connection:l,dialect:e,selectStr:o,fields:[]}}static async run({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(!i){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);i=await e.lookupConnection(o)}if(r){const o=await i.runSQL(r.selectStr);return new Vg({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:{}})}else if(n){const o=await i.runSQL(n.sql,s);return new Vg({...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 us(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 Ef(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.")}}De.Malloy=In;class mG extends Error{constructor(e,n=[]){super(e),this.problems=n}}De.MalloyError=mG;let Hg=class{constructor(e,n,r,i,s=()=>{},o=()=>{}){this.modelDef=e,this.queryList=n,this.problems=r,this.fromSources=i,this._referenceAt=s,this._importAt=o}tagParse(e){return Sn.Tag.annotationToTag(this.modelDef.annotation,e)}getTaglines(e){return Sn.Tag.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 dh(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.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new dh(this.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.queryList.length===0)throw new Error("Model has no queries.");return new dh(this.queryList[this.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,yr.isSourceDef)(n))return new us(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(yr.isSourceDef).map(e=>new us(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}};De.Model=Hg;class dh{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=Sn.Tag.annotationToTag(this._modelDef.annotation).tag;return e=Sn.Tag.addModelScope(e,n),Sn.Tag.annotationToTag(this._query.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new yr.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new Qg({...r,queryName:this.name||r.queryName},this._modelDef)}get dialect(){const e=this._query.structRef,n=typeof e=="string"?this._modelDef.contents[e]:e;if(!(0,yr.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}De.PreparedQuery=dh;class yG{constructor(e){this.translator=e}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new TS(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new EG(r))}get _translator(){return this.translator}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new AG(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}De.Parse=yG;class EG{constructor(e){this._range=hh.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}}De.DocumentTablePath=EG;class hh{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 hh(new g7(e.start.line,e.start.character),new g7(e.end.line,e.end.character))}}De.DocumentRange=hh;class g7{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}}}De.DocumentPosition=g7;class TS{constructor(e){this._range=hh.fromJSON(e.range),this._lensRange=e.lensRange?hh.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new TS(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}}De.DocumentSymbol=TS;class AG{constructor(e){this.type=e.type,this.text=e.text}}De.DocumentCompletion=AG;class Qg{constructor(e,n){this.modelDef=n,this.inner=e}static fromJson({query:e,modelDef:n}){if(!e||!n)throw new Error("Missing required properties in JSON data");return new Qg(e,n)}tagParse(e){const n=Sn.Tag.annotationToTag(this.modelDef.annotation).tag;return e=Sn.Tag.addModelScope(e,n),Sn.Tag.annotationToTag(this.inner.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return Sn.Tag.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 us(n,this.sourceExplore)}catch{return new us(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n===void 0)throw new Error("Malformed query result.");if((0,yr.isSourceDef)(n))return new us(n);throw new Error(`'${e} is not an explore`)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}De.PreparedResult=Qg;class vG{async readURL(e){throw new Error("No files.")}}De.EmptyURLReader=vG;class sRe{constructor(e){this.files=e}async readURL(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve(n);throw new Error(`File not found '${e}'`)}}De.InMemoryURLReader=sRe;class Gg{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 Gg(new Map(e.map(n=>[n.name,n])))}}De.FixedConnectionMap=Gg;var _G;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(_G||(De.SourceRelationship=_G={}));class m7{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 us}isQuery(){return this instanceof b7}}class us extends m7{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,yr.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return Sn.Tag.annotationToTag(this._structDef.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=Sn.Tag.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 dh(r,this.modelDef,[],e)}get modelDef(){return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef}}}getSingleExploreModel(){return new Hg(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,yr.isJoined)(r))return[i,new C7(r,this,s)];if(r.type==="turtle")return[i,new b7(r,this,s)];if(r.type==="string")return[i,new S7(r,this,s)];if(r.type==="number")return[i,new RS(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new RS({...r,type:"number"},this,s)]:[i,new y7(r,this,s)];if(r.type==="timestamp")return[i,new E7(r,this,s)];if(r.type==="boolean")return[i,new A7(r,this,s)];if(r.type==="json")return[i,new v7(r,this,s)];if(r.type==="sql native")return[i,new _7(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 C7}get filters(){var e;return(0,yr.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,yr.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?us.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?us.fromJSON(e.sourceExplore):void 0;return new us(e._structDef,n,r)}get location(){return this.structDef.location}}De.Explore=us;var bu;(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"})(bu||(De.AtomicFieldType=bu={}));class y0 extends m7{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 bu.String;case"boolean":return bu.Boolean;case"date":return bu.Date;case"timestamp":return bu.Timestamp;case"number":return bu.Number;case"json":return bu.Json;case"sql native":return bu.NativeUnsupported;case"error":return bu.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=Sn.Tag.addModelScope(e,this.parent.modelTag),Sn.Tag.annotationToTag(this.fieldTypeDef.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,yr.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,yr.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 S7}isNumber(){return this instanceof RS}isDate(){return this instanceof y7}isBoolean(){return this instanceof A7}isJSON(){return this instanceof v7}isTimestamp(){return this instanceof E7}isUnsupported(){return this instanceof _7}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}}De.AtomicField=y0;var yf;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(yf||(De.DateTimeframe=yf={}));var Cu;(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"})(Cu||(De.TimestampTimeframe=Cu={}));class y7 extends y0{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 yf.Day;case"week":return yf.Week;case"month":return yf.Month;case"quarter":return yf.Quarter;case"year":return yf.Year}}}De.DateField=y7;class E7 extends y0{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 Cu.Day;case"week":return Cu.Week;case"month":return Cu.Month;case"quarter":return Cu.Quarter;case"year":return Cu.Year;case"second":return Cu.Second;case"hour":return Cu.Hour;case"minute":return Cu.Minute}}}De.TimestampField=E7;class RS extends y0{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}De.NumberField=RS;class A7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}De.BooleanField=A7;class v7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}De.JSONField=v7;class _7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}De.UnsupportedField=_7;class S7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}De.StringField=S7;class SG extends m7{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}}De.Query=SG;class b7 extends SG{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=Sn.Tag.addModelScope(e,this.parent.modelTag),Sn.Tag.annotationToTag(this.turtleDef.annotation,e)}getTaglines(e){return Sn.Tag.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}}De.QueryField=b7;var ph;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(ph||(De.JoinRelationship=ph={}));class C7 extends us{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,yr.isJoined)(this.structDef))switch(this.structDef.join){case"one":return ph.OneToOne;case"many":case"cross":return ph.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===ph.OneToOne}get isArray(){return this.joinRelationship!==ph.OneToOne}tagParse(e){return e=Sn.Tag.addModelScope(e,this._parentExplore.modelTag),Sn.Tag.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]:[]}}De.ExploreField=C7;class T7{constructor(...e){this.isTestRuntime=!1;let n,r,i;for(const s of e)s!==void 0&&(BG(s)?n=s:cRe(s)?r=s:kG(s)?i=s:r={lookupConnection:()=>Promise.resolve(s)});if(n===void 0&&(n=new vG),r===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");this._urlReader=n,this._connections=r,this._eventStream=i}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};return this.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new Wg(this,async()=>{const s=e instanceof URL?await In.parse({url:e,urlReader:this.urlReader,eventStream:this.eventStream,options:n}):In.parse({source:e,eventStream:this.eventStream,options:n});return In.compile({urlReader:this.urlReader,connections:this.connections,parse:s,refreshSchemaCache:r,noThrowOnError:i,eventStream:this.eventStream,replaceMaterializedReferences:n==null?void 0:n.replaceMaterializedReferences,materializedTablePrefix:n==null?void 0:n.materializedTablePrefix})},n)}_loadModelFromModelDef(e,n){return new Wg(this,async()=>new Hg(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()}}De.Runtime=T7;class oRe extends T7{constructor(e,n){if(n===void 0){const r=e;super(Gg.fromArray(r)),this.rawConnections=r}else{const r=n;super(e,Gg.fromArray(r)),this.rawConnections=r}}}De.ConnectionRuntime=oRe;class uRe extends T7{constructor(...e){let n,r,i;for(const s of e)BG(s)&&(n=s),fRe(s)&&(r=s),kG(s)&&(i=s);if(r===void 0)throw new Error("Expected connection to be passed into SingleConnectionRuntime");super(n,r,i),this.connection=r}get supportsNesting(){return(0,p7.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,p7.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,p7.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}De.SingleConnectionRuntime=uRe;class OS{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 bG(this.runtime,e,n)}makeExploreMaterializer(e,n){return new TG(this.runtime,e,n)}makePreparedResultMaterializer(e){return new CG(this.runtime,e)}}class Wg extends OS{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?await In.parse({url:e,urlReader:s,options:n}):In.parse({source:e,options:n}),a=await this.getModel();return(await In.compile({urlReader:s,connections:o,parse:u,model:a,refreshSchemaCache:r,noThrowOnError:i,...this.compileQueryOptions})).preparedQuery})}extendModel(e,n){return this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new Wg(this.runtime,async()=>{const r=this.runtime.urlReader,i=this.runtime.connections,s=e instanceof URL?await In.parse({url:e,urlReader:r,options:n}):In.parse({source:e,options:n}),o=await this.getModel();return await In.compile({urlReader:r,connections:i,parse:s,model:o,refreshSchemaCache:n==null?void 0:n.refreshSchemaCache,noThrowOnError:n==null?void 0:n.noThrowOnError,...this.compileQueryOptions})},n)}async search(e,n,r=1e3,i=void 0,s){const o=await this.materialize(),u=new yr.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,yr.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,yr.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=`
|
|
1331
1331
|
run: ${e}
|
|
1332
1332
|
-> ${o}
|
|
@@ -52963,7 +52963,7 @@ ih.exploreQueryWalkerBuilder = iRe;
|
|
|
52963
52963
|
var De = {}, R5 = {};
|
|
52964
52964
|
Object.defineProperty(R5, "__esModule", { value: !0 });
|
|
52965
52965
|
R5.MALLOY_VERSION = void 0;
|
|
52966
|
-
R5.MALLOY_VERSION = "0.0.
|
|
52966
|
+
R5.MALLOY_VERSION = "0.0.207";
|
|
52967
52967
|
Object.defineProperty(De, "__esModule", { value: !0 });
|
|
52968
52968
|
De.CSVWriter = De.JSONWriter = De.DataWriter = De.DataRecord = De.DataArray = De.Result = De.ExploreMaterializer = De.PreparedResultMaterializer = De.QueryMaterializer = De.ModelMaterializer = De.SingleConnectionRuntime = De.ConnectionRuntime = De.Runtime = De.ExploreField = De.JoinRelationship = De.QueryField = De.Query = De.StringField = De.UnsupportedField = De.JSONField = De.BooleanField = De.NumberField = De.TimestampField = De.DateField = De.TimestampTimeframe = De.DateTimeframe = De.AtomicField = De.AtomicFieldType = De.Explore = De.SourceRelationship = De.FixedConnectionMap = De.InMemoryURLReader = De.EmptyURLReader = De.PreparedResult = De.DocumentCompletion = De.DocumentSymbol = De.DocumentPosition = De.DocumentRange = De.DocumentTablePath = De.Parse = De.PreparedQuery = De.Model = De.MalloyError = De.Malloy = void 0;
|
|
52969
52969
|
const sRe = b8, pr = ys, fj = Gi, vn = Mu, X6 = jh, oRe = R5;
|
|
@@ -1326,7 +1326,7 @@ QUERY: ${(0,xz.inspect)(n,{breakLength:72,depth:1/0})}`)}return dz.ErrorFactory.
|
|
|
1326
1326
|
| ${l}`,u>0&&(i=i+`
|
|
1327
1327
|
| ${" ".repeat(u)}^`)}else i=`line ${o+1}: char ${u}: ${r.message}`}n!==s&&(i=`FILE: ${s}
|
|
1328
1328
|
`+i,n=s),e!==""?e=`${e}
|
|
1329
|
-
${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().translated)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,F6e.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}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,U6e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<=o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}pu.MalloyTranslation=d7;class xG extends d7{constructor(e,n){super(e),this.root=n}}pu.MalloyChildTranslator=xG;class eRe extends d7{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new x7.Zone,this.importZone=new x7.Zone,this.sqlQueryZone=new x7.Zone,this.root=this,this.logger=new f7.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)}logError(e,n,r){return this.logger.log((0,f7.makeLogMessage)(e,n,{severity:"error",...r})),e}}pu.MalloyTranslator=eRe;class dG{constructor(e,n){this.translator=e,this.messages=n}logError(e,n,r){return this.messages.log((0,f7.makeLogMessage)(e,n,{severity:"error",...r})),e}syntaxError(e,n,r,i,s,o){const u={line:r-1,character:i},a=n?this.translator.rangeFromToken(n):{start:u,end:u};this.logError("syntax-error",{message:s},{at:{url:this.translator.sourceURL,range:a}})}}pu.MalloyParserErrorHandler=dG;var xh={};Object.defineProperty(xh,"__esModule",{value:!0}),xh.exploreQueryWalkerBuilder=xh.ExploreQueryWalker=void 0;const tRe=$l;class hG{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}}xh.ExploreQueryWalker=hG;function nRe(t,e){const n=new hG(t),r=n;return tRe.ParseTreeWalker.DEFAULT.walk(r,e),n}xh.exploreQueryWalkerBuilder=nRe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslator=void 0;var e=pu;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}});var n=xh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(kR);var De={},bS={};Object.defineProperty(bS,"__esModule",{value:!0}),bS.MALLOY_VERSION=void 0,bS.MALLOY_VERSION="0.0.
|
|
1329
|
+
${i}`:e=i}return e}childRequest(e){var n;const r=decodeURI(new URL(e,this.sourceURL).toString()),i=(n=this.childTranslators.get(r))===null||n===void 0?void 0:n.translate();if(i!=null&&i.compileSQL)return{compileSQL:i.compileSQL,partialModel:i.partialModel}}getChildExports(e){const n={},r=decodeURI(new URL(e,this.sourceURL).toString()),i=this.childTranslators.get(r);if(i&&i.translate().translated)for(const o of i.modelDef.exports){const u=i.modelDef.contents[o];((0,F6e.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}importAt(e){for(let n=0;n<this.imports.length;n++){const r=this.imports[n];if((0,U6e.locationContainsPosition)(r.location,e))return r}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return this.rangeFromTokens(e.start,e.stop||e.start)}rangeFromTokens(e,n){const r={line:e.line-1,character:e.charPositionInLine};if(this.parseStep.sourceInfo&&n.stopIndex!==-1){const i=this.parseStep.sourceInfo.lines.length-1;for(let s=e.line-1;s<=i;s++){const o=this.parseStep.sourceInfo.at[s];if(n.stopIndex>=o.begin&&n.stopIndex<=o.end)return{start:r,end:{line:s,character:n.stopIndex-o.begin+1}}}return{start:r,end:{line:i,character:this.parseStep.sourceInfo.lines[i].length}}}return{start:r,end:r}}rangeFromToken(e){return this.rangeFromTokens(e,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const n=this.compilerFlags.tag("experimental");return n!==void 0&&(n.bare()||n.has("dialect",e))}}pu.MalloyTranslation=d7;class xG extends d7{constructor(e,n){super(e),this.root=n}}pu.MalloyChildTranslator=xG;class eRe extends d7{constructor(e,n=null,r=null,i=null){super(e,n),this.eventStream=i,this.schemaZone=new x7.Zone,this.importZone=new x7.Zone,this.sqlQueryZone=new x7.Zone,this.root=this,this.logger=new f7.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)}logError(e,n,r){return this.logger.log((0,f7.makeLogMessage)(e,n,{severity:"error",...r})),e}}pu.MalloyTranslator=eRe;class dG{constructor(e,n){this.translator=e,this.messages=n}logError(e,n,r){return this.messages.log((0,f7.makeLogMessage)(e,n,{severity:"error",...r})),e}syntaxError(e,n,r,i,s,o){const u={line:r-1,character:i},a=n?this.translator.rangeFromToken(n):{start:u,end:u};this.logError("syntax-error",{message:s},{at:{url:this.translator.sourceURL,range:a}})}}pu.MalloyParserErrorHandler=dG;var xh={};Object.defineProperty(xh,"__esModule",{value:!0}),xh.exploreQueryWalkerBuilder=xh.ExploreQueryWalker=void 0;const tRe=$l;class hG{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}}xh.ExploreQueryWalker=hG;function nRe(t,e){const n=new hG(t),r=n;return tRe.ParseTreeWalker.DEFAULT.walk(r,e),n}xh.exploreQueryWalkerBuilder=nRe,function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.exploreQueryWalkerBuilder=t.MalloyTranslator=void 0;var e=pu;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}});var n=xh;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return n.exploreQueryWalkerBuilder}})}(kR);var De={},bS={};Object.defineProperty(bS,"__esModule",{value:!0}),bS.MALLOY_VERSION=void 0,bS.MALLOY_VERSION="0.0.207",Object.defineProperty(De,"__esModule",{value:!0}),De.CSVWriter=De.JSONWriter=De.DataWriter=De.DataRecord=De.DataArray=De.Result=De.ExploreMaterializer=De.PreparedResultMaterializer=De.QueryMaterializer=De.ModelMaterializer=De.SingleConnectionRuntime=De.ConnectionRuntime=De.Runtime=De.ExploreField=De.JoinRelationship=De.QueryField=De.Query=De.StringField=De.UnsupportedField=De.JSONField=De.BooleanField=De.NumberField=De.TimestampField=De.DateField=De.TimestampTimeframe=De.DateTimeframe=De.AtomicField=De.AtomicFieldType=De.Explore=De.SourceRelationship=De.FixedConnectionMap=De.InMemoryURLReader=De.EmptyURLReader=De.PreparedResult=De.DocumentCompletion=De.DocumentSymbol=De.DocumentPosition=De.DocumentRange=De.DocumentTablePath=De.Parse=De.PreparedQuery=De.Model=De.MalloyError=De.Malloy=void 0;const rRe=kR,yr=Vi,pG=wi,Sn=eu,h7=Ux,iRe=bS;class In{static get version(){return iRe.MALLOY_VERSION}static _parse(e,n,r,i){n===void 0&&(n=new URL("internal://internal.malloy"));let s=n;i!=null&&i.importBaseURL&&(s=i==null?void 0:i.importBaseURL);const o=new rRe.MalloyTranslator(n.toString(),s.toString(),{urls:{[n.toString()]:e}},r);return i!=null&&i.testEnvironment&&(o.allDialectsEnabled=!0),new mG(o)}static parse({url:e,urlReader:n,source:r,eventStream:i,options:s}){if(r!==void 0)return In._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 n.readURL(e).then(o=>In._parse(o,e,i,s))}static async compile({urlReader:e,connections:n,parse:r,model:i,refreshSchemaCache:s,noThrowOnError:o,eventStream:u,replaceMaterializedReferences:a,materializedTablePrefix:l}){var c,f,x,d;let p;s&&(p=typeof s=="number"?s:Date.now());const g=r._translator;for(;;){const m=g.translate(i==null?void 0:i._modelDef);if(m.final){if(m.translated)return new qg(m.translated.modelDef,m.translated.queryList,m.problems||[],[...(c=i==null?void 0:i.fromSources)!==null&&c!==void 0?c:[],...(f=m.fromSources)!==null&&f!==void 0?f:[]],y=>g.referenceAt(y),y=>g.importAt(y));if(o){const y={name:"modelDidNotCompile",exports:[],contents:{}},E=(i==null?void 0:i._modelDef)||y;return new qg(E,[],m.problems||[],[...(x=i==null?void 0:i.fromSources)!==null&&x!==void 0?x:[],...(d=m.fromSources)!==null&&d!==void 0?d:[]],A=>g.referenceAt(A),A=>g.importAt(A))}else{const y=m.problems||[],E=g.prettyErrors();throw new gG(`Error(s) compiling model:
|
|
1330
1330
|
${E}`,y)}}else{if(m.urls)for(const E of m.urls)try{if(E.startsWith("internal://"))throw new Error("In order to use relative imports, you must compile a file via a URL.");const A=await e.readURL(new URL(E)),v={[E]:A};g.update({urls:v})}catch(A){g.update({errors:{urls:{[E]:A.message}}})}const{modelAnnotation:y}=g.modelAnnotation(i==null?void 0:i._modelDef);if(m.tables){const E=new Map;for(const A in m.tables){const{connectionName:v,tablePath:_}=m.tables[A],S=E.get(v);S===void 0?E.set(v,{[A]:_}):S[A]=_}for(const[A,v]of E)try{const _=await n.lookupConnection(A),{schemas:S,errors:b}=await In.safelyFetchTableSchema(_,v,{refreshTimestamp:p,modelAnnotation:y});g.update({tables:S,errors:{tables:b}})}catch(_){const S={},b={};for(const C in v)b[C]=_.toString();g.update({tables:S,errors:{tables:b}})}}if(m.compileSQL){const E=m.compileSQL,A=E.connection;try{const v=await n.lookupConnection(A),_=In.compileSQLBlock(v.dialectName,m.partialModel,E,{replaceMaterializedReferences:a,materializedTablePrefix:l,eventStream:u}),S=await v.fetchSchemaForSQLStruct(_,{refreshTimestamp:p,modelAnnotation:y});S.error&&g.update({errors:{compileSQL:{[_.name]:S.error}}}),S.structDef&&g.update({compileSQL:{[_.name]:S.structDef}})}catch(v){const _={};_[E.name]=v.toString(),g.update({errors:{compileSQL:_}})}}}}}static async safelyFetchTableSchema(e,n,r){const i=await e.fetchSchemaForTables(n,r);for(const s of Object.keys(n))if(i.schemas[s]===void 0&&i.errors[s]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${s} from ${e.dialectName}`);return i}static compileSQLBlock(e,n,r,i){let s,o="",u=!1;for(const c of r.select)if((0,yr.isSegmentSQL)(c))o+=c.sql,u=c.sql.match(/\(\s*$/)!==null;else{if(!s){if(!n)throw new Error("Internal error: Partial model missing when compiling SQL block");s=new yr.QueryModel(n,i==null?void 0:i.eventStream)}const f=s.compileQuery(c,i,!1).sql;o+=u?f:`(${f})`,u=!1}const{name:a,connection:l}=r;return{type:"sql_select",name:a,connection:l,dialect:e,selectStr:o,fields:[]}}static async run({connections:e,preparedResult:n,sqlStruct:r,connection:i,options:s}){if(!i){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const o=(r==null?void 0:r.connection)||(n==null?void 0:n.connectionName);i=await e.lookupConnection(o)}if(r){const o=await i.runSQL(r.selectStr);return new Gg({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:{}})}else if(n){const o=await i.runSQL(n.sql,s);return new Gg({...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 us(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 Ef(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.")}}De.Malloy=In;class gG extends Error{constructor(e,n=[]){super(e),this.problems=n}}De.MalloyError=gG;let qg=class{constructor(e,n,r,i,s=()=>{},o=()=>{}){this.modelDef=e,this.queryList=n,this.problems=r,this.fromSources=i,this._referenceAt=s,this._importAt=o}tagParse(e){return Sn.Tag.annotationToTag(this.modelDef.annotation,e)}getTaglines(e){return Sn.Tag.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 dh(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.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new dh(this.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.queryList.length===0)throw new Error("Model has no queries.");return new dh(this.queryList[this.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const n=this.modelDef.contents[e];if((0,yr.isSourceDef)(n))return new us(n);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(yr.isSourceDef).map(e=>new us(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}};De.Model=qg;class dh{constructor(e,n,r,i){this.problems=r,this.name=i,this._query=e,this._modelDef=n}tagParse(e){const n=Sn.Tag.annotationToTag(this._modelDef.annotation).tag;return e=Sn.Tag.addModelScope(e,n),Sn.Tag.annotationToTag(this._query.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const r=new yr.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new zg({...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,yr.isSourceDef)(n))throw new Error("Invalid source for query");return n.dialect}getFlattenedQuery(e){return this}}De.PreparedQuery=dh;class mG{constructor(e){this.translator=e}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new CS(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(r=>new yG(r))}get _translator(){return this.translator}completions(e){return(this.translator.completions(e).completions||[]).map(n=>new EG(n))}helpContext(e){return this.translator.helpContext(e).helpContext}}De.Parse=mG;class yG{constructor(e){this._range=hh.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}}De.DocumentTablePath=yG;class hh{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 hh(new p7(e.start.line,e.start.character),new p7(e.end.line,e.end.character))}}De.DocumentRange=hh;class p7{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}}}De.DocumentPosition=p7;class CS{constructor(e){this._range=hh.fromJSON(e.range),this._lensRange=e.lensRange?hh.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(n=>new CS(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}}De.DocumentSymbol=CS;class EG{constructor(e){this.type=e.type,this.text=e.text}}De.DocumentCompletion=EG;class zg{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 zg(e,n)}tagParse(e){const n=Sn.Tag.annotationToTag(this.modelDef.annotation).tag;return e=Sn.Tag.addModelScope(e,n),Sn.Tag.annotationToTag(this.inner.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return Sn.Tag.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 us(n,this.sourceExplore)}catch{return new us(n)}}get sourceExplore(){const e=this.inner.sourceExplore,n=this.modelDef.contents[e];if(n===void 0)throw new Error("Malformed query result.");if((0,yr.isSourceDef)(n))return new us(n);throw new Error(`'${e} is not an explore`)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceFilters(){return this.inner.sourceFilters||[]}}De.PreparedResult=zg;class AG{async readURL(e){throw new Error("No files.")}}De.EmptyURLReader=AG;class sRe{constructor(e){this.files=e}async readURL(e){const n=this.files.get(e.toString());if(n!==void 0)return Promise.resolve(n);throw new Error(`File not found '${e}'`)}}De.InMemoryURLReader=sRe;class Hg{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 Hg(new Map(e.map(n=>[n.name,n])))}}De.FixedConnectionMap=Hg;var vG;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})(vG||(De.SourceRelationship=vG={}));class g7{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 us}isQuery(){return this instanceof S7}}class us extends g7{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,yr.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return Sn.Tag.annotationToTag(this._structDef.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=Sn.Tag.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 dh(r,this.modelDef,[],e)}get modelDef(){return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef}}}getSingleExploreModel(){return new qg(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,yr.isJoined)(r))return[i,new b7(r,this,s)];if(r.type==="turtle")return[i,new S7(r,this,s)];if(r.type==="string")return[i,new _7(r,this,s)];if(r.type==="number")return[i,new TS(r,this,s)];if(r.type==="date")return r.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(r.timeframe)?[i,new TS({...r,type:"number"},this,s)]:[i,new m7(r,this,s)];if(r.type==="timestamp")return[i,new y7(r,this,s)];if(r.type==="boolean")return[i,new E7(r,this,s)];if(r.type==="json")return[i,new A7(r,this,s)];if(r.type==="sql native")return[i,new v7(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 b7}get filters(){var e;return(0,yr.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,yr.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?us.fromJSON(e._parentExplore):void 0,r=e.sourceExplore!==void 0?us.fromJSON(e.sourceExplore):void 0;return new us(e._structDef,n,r)}get location(){return this.structDef.location}}De.Explore=us;var bu;(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"})(bu||(De.AtomicFieldType=bu={}));class y0 extends g7{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 bu.String;case"boolean":return bu.Boolean;case"date":return bu.Date;case"timestamp":return bu.Timestamp;case"number":return bu.Number;case"json":return bu.Json;case"sql native":return bu.NativeUnsupported;case"error":return bu.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=Sn.Tag.addModelScope(e,this.parent.modelTag),Sn.Tag.annotationToTag(this.fieldTypeDef.annotation,e)}getTaglines(e){return Sn.Tag.annotationToTaglines(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,yr.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,yr.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 _7}isNumber(){return this instanceof TS}isDate(){return this instanceof m7}isBoolean(){return this instanceof E7}isJSON(){return this instanceof A7}isTimestamp(){return this instanceof y7}isUnsupported(){return this instanceof v7}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}}De.AtomicField=y0;var yf;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(yf||(De.DateTimeframe=yf={}));var Cu;(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"})(Cu||(De.TimestampTimeframe=Cu={}));class m7 extends y0{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 yf.Day;case"week":return yf.Week;case"month":return yf.Month;case"quarter":return yf.Quarter;case"year":return yf.Year}}}De.DateField=m7;class y7 extends y0{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 Cu.Day;case"week":return Cu.Week;case"month":return Cu.Month;case"quarter":return Cu.Quarter;case"year":return Cu.Year;case"second":return Cu.Second;case"hour":return Cu.Hour;case"minute":return Cu.Minute}}}De.TimestampField=y7;class TS extends y0{constructor(e,n,r){super(e,n,r),this.fieldNumberDef=e}}De.NumberField=TS;class E7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldBooleanDef=e}}De.BooleanField=E7;class A7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldJSONDef=e}}De.JSONField=A7;class v7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}De.UnsupportedField=v7;class _7 extends y0{constructor(e,n,r){super(e,n,r),this.fieldStringDef=e}}De.StringField=_7;class _G extends g7{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}}De.Query=_G;class S7 extends _G{constructor(e,n,r){super(e,n,r),this.parent=n}tagParse(e){return e=Sn.Tag.addModelScope(e,this.parent.modelTag),Sn.Tag.annotationToTag(this.turtleDef.annotation,e)}getTaglines(e){return Sn.Tag.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}}De.QueryField=S7;var ph;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(ph||(De.JoinRelationship=ph={}));class b7 extends us{constructor(e,n,r){super(e,n,r),this._parentExplore=n}get joinRelationship(){if((0,yr.isJoined)(this.structDef))switch(this.structDef.join){case"one":return ph.OneToOne;case"many":case"cross":return ph.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===ph.OneToOne}get isArray(){return this.joinRelationship!==ph.OneToOne}tagParse(e){return e=Sn.Tag.addModelScope(e,this._parentExplore.modelTag),Sn.Tag.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]:[]}}De.ExploreField=b7;class C7{constructor(...e){this.isTestRuntime=!1;let n,r,i;for(const s of e)s!==void 0&&($G(s)?n=s:cRe(s)?r=s:BG(s)?i=s:r={lookupConnection:()=>Promise.resolve(s)});if(n===void 0&&(n=new AG),r===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");this._urlReader=n,this._connections=r,this._eventStream=i}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,n){const{refreshSchemaCache:r,noThrowOnError:i}=n||{};return this.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new Qg(this,async()=>{const s=e instanceof URL?await In.parse({url:e,urlReader:this.urlReader,eventStream:this.eventStream,options:n}):In.parse({source:e,eventStream:this.eventStream,options:n});return In.compile({urlReader:this.urlReader,connections:this.connections,parse:s,refreshSchemaCache:r,noThrowOnError:i,eventStream:this.eventStream,replaceMaterializedReferences:n==null?void 0:n.replaceMaterializedReferences,materializedTablePrefix:n==null?void 0:n.materializedTablePrefix})},n)}_loadModelFromModelDef(e,n){return new Qg(this,async()=>new qg(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()}}De.Runtime=C7;class oRe extends C7{constructor(e,n){if(n===void 0){const r=e;super(Hg.fromArray(r)),this.rawConnections=r}else{const r=n;super(e,Hg.fromArray(r)),this.rawConnections=r}}}De.ConnectionRuntime=oRe;class uRe extends C7{constructor(...e){let n,r,i;for(const s of e)$G(s)&&(n=s),fRe(s)&&(r=s),BG(s)&&(i=s);if(r===void 0)throw new Error("Expected connection to be passed into SingleConnectionRuntime");super(n,r,i),this.connection=r}get supportsNesting(){return(0,h7.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,h7.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,h7.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}De.SingleConnectionRuntime=uRe;class RS{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 SG(this.runtime,e,n)}makeExploreMaterializer(e,n){return new CG(this.runtime,e,n)}makePreparedResultMaterializer(e){return new bG(this.runtime,e)}}class Qg extends RS{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?await In.parse({url:e,urlReader:s,options:n}):In.parse({source:e,options:n}),a=await this.getModel();return(await In.compile({urlReader:s,connections:o,parse:u,model:a,refreshSchemaCache:r,noThrowOnError:i,...this.compileQueryOptions})).preparedQuery})}extendModel(e,n){return this.runtime.isTestRuntime&&(n===void 0?n={testEnvironment:!0}:n={...n,testEnvironment:!0}),new Qg(this.runtime,async()=>{const r=this.runtime.urlReader,i=this.runtime.connections,s=e instanceof URL?await In.parse({url:e,urlReader:r,options:n}):In.parse({source:e,options:n}),o=await this.getModel();return await In.compile({urlReader:r,connections:i,parse:s,model:o,refreshSchemaCache:n==null?void 0:n.refreshSchemaCache,noThrowOnError:n==null?void 0:n.noThrowOnError,...this.compileQueryOptions})},n)}async search(e,n,r=1e3,i=void 0,s){const o=await this.materialize(),u=new yr.QueryModel(o._modelDef,s),a=o.getExploreByName(e).structDef;if(!(0,yr.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,yr.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=`
|
|
1331
1331
|
run: ${e}
|
|
1332
1332
|
-> ${o}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.207-dev241101160127",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/module/index.umd.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"build-types": "tsc --build --declaration --emitDeclarationOnly"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@malloydata/malloy": "^0.0.
|
|
35
|
+
"@malloydata/malloy": "^0.0.207-dev241101160127",
|
|
36
36
|
"@tanstack/solid-virtual": "^3.10.4",
|
|
37
37
|
"component-register": "^0.8.6",
|
|
38
38
|
"lodash": "^4.17.20",
|