@malloydata/render 0.0.290 → 0.0.291
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
|
@@ -150387,7 +150387,7 @@ function q2t(t) {
|
|
|
150387
150387
|
var Le = {}, UO = {};
|
|
150388
150388
|
Object.defineProperty(UO, "__esModule", { value: !0 });
|
|
150389
150389
|
UO.MALLOY_VERSION = void 0;
|
|
150390
|
-
UO.MALLOY_VERSION = "0.0.
|
|
150390
|
+
UO.MALLOY_VERSION = "0.0.291";
|
|
150391
150391
|
Object.defineProperty(Le, "__esModule", { value: !0 });
|
|
150392
150392
|
Le.InMemoryModelCache = Le.CacheManager = Le.CSVWriter = Le.JSONWriter = Le.DataWriter = Le.DataRecord = Le.DataArray = Le.Result = Le.ExploreMaterializer = Le.PreparedResultMaterializer = Le.QueryMaterializer = Le.ModelMaterializer = Le.SingleConnectionRuntime = Le.ConnectionRuntime = Le.Runtime = Le.ExploreField = Le.JoinRelationship = Le.QueryField = Le.Query = Le.StringField = Le.UnsupportedField = Le.JSONField = Le.BooleanField = Le.NumberField = Le.TimestampField = Le.DateField = Le.TimestampTimeframe = Le.DateTimeframe = Le.AtomicField = Le.AtomicFieldType = Le.Explore = Le.SourceRelationship = Le.FixedConnectionMap = Le.InMemoryURLReader = Le.EmptyURLReader = Le.PreparedResult = Le.DocumentCompletion = Le.DocumentSymbol = Le.DocumentPosition = Le.DocumentRange = Le.DocumentTablePath = Le.Parse = Le.PreparedQuery = Le.Model = Le.MalloyError = Le.Malloy = void 0;
|
|
150393
150393
|
const yJ = iD, gr = yi, EJ = rv, W7 = r1, z2t = UO, H2t = i1, kn = to, Q2t = Wx, G2t = Zi, W2t = Mv;
|
|
@@ -163327,9 +163327,9 @@ const oyt = `.malloy-render {
|
|
|
163327
163327
|
}
|
|
163328
163328
|
`, uyt = {
|
|
163329
163329
|
name: "line_chart_series",
|
|
163330
|
-
matches: (t, e) => t.has("line_chart") && e === Ns.RepeatedRecord,
|
|
163330
|
+
matches: (t, e) => (t.has("line_chart") || t.text("viz") === "line") && e === Ns.RepeatedRecord,
|
|
163331
163331
|
plugin: (t) => {
|
|
163332
|
-
const e = "line_chart_series", r = (i, s) => i.has("line_chart") && s === Ns.RepeatedRecord;
|
|
163332
|
+
const e = "line_chart_series", r = (i, s) => (i.has("line_chart") || i.text("viz") === "line") && s === Ns.RepeatedRecord;
|
|
163333
163333
|
try {
|
|
163334
163334
|
if (!t.isNest())
|
|
163335
163335
|
throw new Error("Line chart: must be a nest field");
|
package/dist/module/index.umd.js
CHANGED
|
@@ -1390,7 +1390,7 @@ z{{{{{{{{ӆ
|
|
|
1390
1390
|
| ${c}`,a>0&&(s=s+`
|
|
1391
1391
|
| ${" ".repeat(a)}^`)}else s=`line ${u+1}: char ${a}: ${i.message}`}r!==o&&(s=`FILE: ${o}
|
|
1392
1392
|
`+s,r=o),e!==""?e=`${e}
|
|
1393
|
-
${s}`:e=s}return e}childRequest(e){var r;const i=decodeURI(new URL(e,this.sourceURL).toString()),s=(r=this.childTranslators.get(i))===null||r===void 0?void 0:r.translate();if(s!=null&&s.compileSQL)return{compileSQL:s.compileSQL}}getChildExports(e){const r={},i=decodeURI(new URL(e,this.sourceURL).toString()),s=this.childTranslators.get(i);if(s&&s.translate().modelDef)for(const u of s.modelDef.exports){const a=s.modelDef.contents[u];((0,Npt.isSourceDef)(a)||a.type==="query")&&(r[u]=a)}return r}translate(e){if(this.finalAnswer)return this.finalAnswer;const r=this.translateStep.step(this,e);return r.final&&(this.finalAnswer=r),r}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let r=0;r<this.imports.length;r++){const i=this.imports[r];if((0,Sj.locationContainsPosition)(i.location,e))return i}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return(0,Sj.rangeFromContext)(this.parseStep.sourceInfo,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const r=this.compilerFlags.tag("experimental");return r!==void 0&&(r.bare()||r.has("dialect",e))}}nf.MalloyTranslation=Cj;class hhe extends Cj{constructor(e,r){super(e),this.root=r}}nf.MalloyChildTranslator=hhe;class Zpt extends Cj{constructor(e,r=null,i=null,s=null){super(e,r),this.eventStream=s,this.schemaZone=new Aj.Zone,this.importZone=new Aj.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new Aj.Zone,this.root=this,this.logger=new xhe.BaseMessageLogger(s),i&&this.update(i)}update(e){var r,i,s;this.schemaZone.updateFrom(e.tables,(r=e.errors)===null||r===void 0?void 0:r.tables),this.importZone.updateFrom(e.urls,(i=e.errors)===null||i===void 0?void 0:i.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(s=e.errors)===null||s===void 0?void 0:s.compileSQL);for(const o in e.translations)this.pretranslatedModels.set(o,e.translations[o])}logError(e,r,i){return this.logger.log((0,xhe.makeLogMessage)(e,r,{severity:"error",...i})),e}}nf.MalloyTranslator=Zpt;function phe(t){return[...Object.keys(t),...Object.keys(t).map(e=>phe(t[e])).flat()]}var Cv={};Object.defineProperty(Cv,"__esModule",{value:!0}),Cv.ExploreQueryWalker=void 0,Cv.exploreQueryWalkerBuilder=t2t;const e2t=kc;class mhe{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}filterAtOffset(e){const r=this.exploreQueryAtOffset(e);if(r)return r.filterRefs.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e)}hasFilterListAtOffset(e){const r=this.exploreQueryAtOffset(e);return r?!!r.filterLists.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}Cv.ExploreQueryWalker=mhe;function t2t(t,e){const r=new mhe(t),i=r;return e2t.ParseTreeWalker.DEFAULT.walk(i,e),r}var bv={},Tv={},T0={};Object.defineProperty(T0,"__esModule",{value:!0}),T0.sourceDefToSourceInfo=yhe,T0.modelDefToModelInfo=n2t,T0.convertFieldInfos=x1,T0.writeLiteralToTag=Ahe,T0.getResultStructMetadataAnnotation=MD;const jo=pi,bj=wu,Tj=Ws,ghe=Ps;function yhe(t){var e;const r=t.parameters&&Object.entries(t.parameters).length>0?Object.entries(t.parameters).map(([s,o])=>(0,jo.isAtomic)(o)?{name:s,type:PD(o),default_value:Ehe(o.value)}:{name:s,type:{kind:"filter_expression_type",filter_type:{kind:`${o.filterType}_type`}},default_value:Ehe(o.value)}):void 0;return{name:(e=t.as)!==null&&e!==void 0?e:t.name,schema:{fields:x1(t,t.fields)},parameters:r,annotations:Rj(t)}}function n2t(t){const e={entries:[],anonymous_queries:[]};for(const[r,i]of Object.entries(t.contents))if(t.exports.includes(r)){if((0,jo.isSourceDef)(i)){const s=yhe(i);e.entries.push({kind:"source",...s})}else if(i.type==="query"){const s=(0,bj.getResultStructDefForQuery)(t,i),o=Rj(i),u=s.resultMetadata?MD(s,s.resultMetadata):void 0,a=[...o??[],...u?[u]:[]],l={kind:"source",name:r,schema:{fields:x1(s,s.fields)},annotations:a.length>0?a:void 0};e.entries.push(l)}}for(const r of t.queryList){const i=(0,bj.getResultStructDefForQuery)(t,r),s=Rj(r),o=i.resultMetadata?MD(i,i.resultMetadata):void 0,u=[...s??[],...o?[o]:[]],a={schema:{fields:x1(i,i.fields)},annotations:u.length>0?u:void 0};e.anonymous_queries.push(a)}return e}function Ehe(t){if(t!==null)switch(t.node){case"numberLiteral":return{kind:"number_literal",number_value:parseFloat(t.literal)};case"stringLiteral":return{kind:"string_literal",string_value:t.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:t.filterSrc};case"timeLiteral":return{kind:"timestamp_literal",timestamp_value:t.literal};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"null":return{kind:"null_literal"};default:throw new Error("Invalid parameter default value")}}function Rj(t){return(0,Tj.annotationToTaglines)(t.annotation).map(r=>({value:r}))}function x1(t,e){var r,i,s;const o=[];for(const u of e){if(!(u.accessModifier===void 0))continue;const c=(0,Tj.annotationToTaglines)(u.annotation).map(d=>({value:d})),f=c.length>0?c:void 0;if((0,jo.isTurtle)(u)){const d=(0,bj.getResultStructDefForView)(t,u),x=d.resultMetadata?MD(d,d.resultMetadata):void 0,p=[...f??[],...x?[x]:[]],m={kind:"view",name:(r=u.as)!==null&&r!==void 0?r:u.name,annotations:p.length>0?p:void 0,schema:{fields:x1(d,d.fields)}};o.push(m)}else if((0,jo.isAtomic)(u)){const d=(0,jo.expressionIsAggregate)(u.expressionType),x=(0,jo.expressionIsScalar)(u.expressionType);if(!d&&!x||u.type==="error")continue;const p=u.resultMetadata?vhe(u,u.resultMetadata):void 0,m=[...f??[],...p?[p]:[]],g={kind:d?"measure":"dimension",name:(i=u.as)!==null&&i!==void 0?i:u.name,type:PD(u),annotations:m.length>0?m:void 0};o.push(g)}else if((0,jo.isJoinedSource)(u)){const d={kind:"join",name:(s=u.as)!==null&&s!==void 0?s:u.name,annotations:f,schema:{fields:x1(u,u.fields)},relationship:u.join};o.push(d)}}return o}function vhe(t,e){const r=ghe.Tag.withPrefix("#(malloy) ");let i=!1;if(e.referenceId!==void 0&&(r.set(["reference_id"],e.referenceId),i=!0),e.fieldKind==="measure"&&(r.set(["calculation"]),i=!0),e.drillable&&(r.set(["drillable"]),i=!0),((0,jo.isAtomic)(t)||(0,jo.isTurtle)(t))&&t.drillView!==void 0&&(r.set(["drill_view"],t.drillView),i=!0),e.filterList&&(_he(r,e.filterList),i=!0),e.fieldKind==="dimension"){const o=(e==null?void 0:e.sourceExpression)||(e!=null&&e.sourceField.includes(".")?e==null?void 0:e.sourceField:i2t(t.name));r.set(["drill_expression"],o),i=!0}return i?{value:r.toString()}:void 0}function _he(t,e){var r;for(let i=0;i<e.length;i++){const s=e[i];s.expressionType!=="scalar"||s.isSourceFilter||(t.set(["drill_filters",i,"code"],s.code),s.drillView&&t.set(["drill_filters",i,"drill_view"],s.drillView),s.drillView===void 0&&s.stableFilter!==void 0&&(t.set(["drill_filters",i,"field_reference"],[...(r=s.stableFilter.field_reference.path)!==null&&r!==void 0?r:[],s.stableFilter.field_reference.name]),s.stableFilter.kind==="filter_string"?(t.set(["drill_filters",i,"kind"],"filter_expression"),t.set(["drill_filters",i,"filter_expression"],s.stableFilter.filter)):(t.set(["drill_filters",i,"kind"],"literal_equality"),Ahe(t,["drill_filters",i,"value"],s.stableFilter.value))))}}function Ahe(t,e,r){switch(t.set([...e,"kind"],r.kind),r.kind){case"string_literal":t.set([...e,"string_value"],r.string_value);break;case"number_literal":t.set([...e,"number_value"],r.number_value);break;case"boolean_literal":t.set([...e,"boolean_value"],r.boolean_value.toString());break;case"date_literal":t.set([...e,"date_value"],r.date_value),t.set([...e,"timezone"],r.timezone),t.set([...e,"granularity"],r.granularity);break;case"timestamp_literal":t.set([...e,"timestamp_value"],r.timestamp_value),t.set([...e,"timezone"],r.timezone),t.set([...e,"granularity"],r.granularity);break;case"filter_expression_literal":t.set([...e,"filter_expression_value"],r.filter_expression_value);break}}function r2t(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}function i2t(t){return t.match(/^[A-Za-z_][0-9A-Za-z_]*$/)?t:`\`${r2t(t)}\``}function MD(t,e){var r,i;const s=ghe.Tag.withPrefix("#(malloy) ");let o=!1;if(e.limit!==void 0&&(s.set(["limit"],e.limit),o=!0),e.filterList&&(_he(s,e.filterList),o=!0),e.drillable&&(s.set(["drillable"]),o=!0),e.orderBy){for(let u=0;u<e.orderBy.length;u++){const a=e.orderBy[u],l=typeof a.field=="number"?(r=t.fields[a.field-1].as)!==null&&r!==void 0?r:t.fields[a.field-1].name:a.field,c=(i=a.dir)!==null&&i!==void 0?i:null;s.set(["ordered_by",u,l],c)}o=!0}return o?{value:s.toString()}:void 0}function PD(t){if((0,jo.isBasicAtomic)(t))switch(t.type){case"string":return{kind:"string_type"};case"number":return{kind:"number_type",subtype:t.numberType==="float"?"decimal":t.numberType==="integer"?"integer":void 0};case"boolean":return{kind:"boolean_type"};case"date":{const e=t.timeframe;return e&&!s2t(e)?{kind:"timestamp_type",timeframe:t.timeframe}:{kind:"date_type",timeframe:o2t(t.timeframe)}}case"timestamp":return{kind:"timestamp_type",timeframe:t.timeframe};case"json":return{kind:"json_type"};case"sql native":return{kind:"sql_native_type",sql_type:t.rawType};case"error":throw new Error("Error type is not supported in stable interface")}else{if((0,jo.isRepeatedRecord)(t))return{kind:"array_type",element_type:She(t)};if(t.type==="record")return She(t);if(t.type==="array")return{kind:"array_type",element_type:PD(t.elementTypeDef)}}throw new Error("Unexpected field type")}function She(t){return{kind:"record_type",fields:t.fields.map(e=>{const r=[];if("resultMetadata"in e&&e.resultMetadata){const i=vhe(e,e.resultMetadata);i&&r.push(i)}if(e.annotation){const i=(0,Tj.annotationToTaglines)(e.annotation);r.push(...i.map(s=>({value:s})))}if((0,jo.isAtomic)(e))return{name:e.name,annotations:r.length>0?r:void 0,type:PD(e)};throw new Error("Expected record type to not have a table as its child")})}}function s2t(t){switch(t){case"day":case"week":case"month":case"year":case"quarter":return!0;default:return!1}}function o2t(t){switch(t){case void 0:return;case"day":case"week":case"month":case"year":case"quarter":return t;default:throw new Error(`Invalid date timeframe ${t}`)}}function Eyt(t){return t}function vyt(t){return t}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_LOG_RANGE=void 0,t.wrapLegacyInfoConnection=u,t.wrapLegacyConnection=a,t.mapData=c,t.wrapResult=f,t.nodeToLiteralValue=d,t.mapLogs=x;const e=Ps,r=Ws,i=pi,s=T0,o=_E;function u(p){return{get dialectName(){return p.dialectName},async fetchSchemaForSQLQuery(m){const g=await p.fetchSchemaForSQLStruct({connection:p.name,selectStr:m},{}),y=g.structDef;if(y===void 0)throw new Error(g.error);return{fields:(0,s.convertFieldInfos)(y,y.fields)}},async fetchSchemaForTable(m){const g=`${p.name}:${m}`,y=await p.fetchSchemaForTables({[g]:m},{}),E=y.schemas[g];if(E===void 0)throw new Error(y.errors[g]);return{fields:(0,s.convertFieldInfos)(E,E.fields)}}}}function a(p){return{...u(p),runSQL:async(m,g)=>{const y=await p.runSQL(m);return c(y.rows,g)}}}function l(p){if(p instanceof Date)return p;if(p.constructor.name==="Date")return new Date(p);if(typeof p=="number")return new Date(p);if(typeof p!="string")return new Date(p.value);{let g=o.DateTime.fromISO(p,{zone:"UTC"});return g.isValid||(g=o.DateTime.fromSQL(p,{zone:"UTC"})),g.toJSDate()}}function c(p,m){function g(v,_){if(v===null)return{kind:"null_cell"};if(_.type.kind==="date_type"||_.type.kind==="timestamp_type"){const A=l(v).toISOString();return _.type.kind==="date_type"?{kind:"date_cell",date_value:A}:{kind:"timestamp_cell",timestamp_value:A}}else if(_.type.kind==="boolean_type"){if(typeof v=="number")return{kind:"boolean_cell",boolean_value:v!==0};if(typeof v!="boolean")throw new Error(`Invalid boolean ${v}`);return{kind:"boolean_cell",boolean_value:v}}else if(_.type.kind==="number_type"){if(typeof v!="number")throw new Error(`Invalid number ${v}`);return{kind:"number_cell",number_value:v}}else if(_.type.kind==="string_type"){if(typeof v!="string")throw new Error(`Invalid string ${v}`);return{kind:"string_cell",string_value:v}}else if(_.type.kind==="array_type"){if(!Array.isArray(v))throw new Error(`Invalid array ${v}`);return{kind:"array_cell",array_value:v.map(A=>g(A,{name:"array_element",type:_.type.element_type}))}}else{if(_.type.kind==="json_type")return{kind:"json_cell",json_value:JSON.stringify(v)};if(_.type.kind==="sql_native_type")return{kind:"sql_native_cell",sql_native_value:JSON.stringify(v)};{const A=_.type;if(A.kind!=="record_type")throw new Error(`Invalid record in result ${JSON.stringify(_)}, ${JSON.stringify(v)}`);return y(v,{kind:"join",relationship:"many",name:"array_element",schema:{fields:A.fields.map(S=>({kind:"dimension",...S}))}})}}}function y(v,_){const A=[];for(const S of _.schema.fields){const b=v[S.name];if(S.kind!=="dimension")throw new Error("Invalid result -- expected all fields to be dimensions");const C=g(b,S);A.push(C)}return{kind:"record_cell",record_value:A}}const E={kind:"join",schema:m,name:"root",relationship:"one"};return{kind:"array_cell",array_value:p.map(v=>y(v,E))}}function f(p){const m=p._queryResult.structs,g=m[m.length-1],y={fields:(0,s.convertFieldInfos)(g,g.fields)},E=(0,r.annotationToTaglines)(p.annotation).map(A=>({value:A})),v=g.resultMetadata?(0,s.getResultStructMetadataAnnotation)(g,g.resultMetadata):void 0;v&&E.push(v),E.push(...g.resultMetadata?[]:[]);const _=e.Tag.withPrefix("#(malloy) ");if(p.sourceExplore&&_.set(["source","name"],p.sourceExplore.name),p._sourceArguments){const A=Object.entries(p._sourceArguments);for(let S=0;S<A.length;S++){const[b,C]=A[S],R=d(C.value);R!==void 0&&(0,s.writeLiteralToTag)(_,["source","parameters",S,"value"],R),_.set(["source","parameters",S,"name"],b)}}return E.push({value:_.toString()}),E.push({value:e.Tag.withPrefix("#(malloy) ").set(["query_name"],p.resultExplore.name).toString()}),{schema:y,data:c(p.data.toObject(),y),connection_name:p.connectionName,annotations:E.length>0?E:void 0,query_timezone:p.data.field.queryTimezone,sql:p.sql}}function d(p){switch(p==null?void 0:p.node){case"numberLiteral":return{kind:"number_literal",number_value:Number.parseFloat(p.literal)};case"null":return{kind:"null_literal"};case"stringLiteral":return{kind:"string_literal",string_value:p.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:p.filterSrc};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"timeLiteral":return p.typeDef.type==="date"?p.typeDef.timeframe===void 0||(0,i.isDateUnit)(p.typeDef.timeframe)?{kind:"date_literal",date_value:p.literal,timezone:p.timezone,granularity:p.typeDef.timeframe}:void 0:{kind:"timestamp_literal",timestamp_value:p.literal,timezone:p.timezone,granularity:p.typeDef.timeframe};default:return}}t.DEFAULT_LOG_RANGE={start:{line:0,character:0},end:{line:0,character:0}};function x(p,m){return p.map(g=>{var y,E,v,_;return{severity:g.severity,message:g.message,range:(E=(y=g.at)===null||y===void 0?void 0:y.range)!==null&&E!==void 0?E:t.DEFAULT_LOG_RANGE,url:(_=(v=g.at)===null||v===void 0?void 0:v.url)!==null&&_!==void 0?_:m}})}})(Tv);var u2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),a2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),l2t=T&&T.__importStar||function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var i=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[i.length]=s);return i},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i=t(e),s=0;s<i.length;s++)i[s]!=="default"&&u2t(r,e,i[s]);return a2t(r,e),r}}();Object.defineProperty(bv,"__esModule",{value:!0}),bv.MalloyToQuery=void 0,bv.malloyToQuery=p2t;const c2t=g2,f2t=Mp,_t=l2t($),Che=L2,Hx=Cs,d2t=Ke,x2t=zR,bhe=Ji,h2t=Tv,Qx=SE,Dj="Malloy query documents";class The extends f2t.AbstractParseTreeVisitor{constructor(e,r){super(),this.parseInfo=e,this.msgLog=r}internalError(e,r){return this.contextError(e,"internal-translator-error",{message:r}),new Error(`Internal Translator Error: ${r}`)}getLocation(e){return{url:this.parseInfo.sourceURL,range:(0,bhe.rangeFromContext)(this.parseInfo.sourceInfo,e)}}contextError(e,r,i,s){this.msgLog.log((0,Che.makeLogMessage)(r,i,{at:this.getLocation(e),...s}))}getNumber(e){return Number.parseInt(e.text)}defaultResult(){return null}getAnnotations(e){const r=e.ANNOTATION().map(i=>({value:i.text}));return r.length>0?r:void 0}getIsAnnotations(e){var r,i;if(e===void 0)return;const o=((r=this.getAnnotations(e._beforeIs))!==null&&r!==void 0?r:[]).concat((i=this.getAnnotations(e._afterIs))!==null&&i!==void 0?i:[]);return o.length>0?o:void 0}notAllowed(e,r){this.illegal(e,`${r} are not allowed in ${Dj}`)}illegal(e,r){this.contextError(e,"invalid-malloy-query-document",r)}visitMalloyDocument(e){const r=e.malloyStatement();let i;for(const s of r)s.defineSourceStatement()?this.notAllowed(s,"Source definitions"):s.defineQuery()?this.notAllowed(s,"Query definitions"):s.importStatement()?this.notAllowed(s,"Import statements"):s.docAnnotations()?this.notAllowed(s,"Model annotations"):s.ignoredObjectAnnotations()?this.notAllowed(s,"Detatched object annotations"):s.experimentalStatementForTesting()?this.notAllowed(s,"Experimental testing statements"):i===void 0?i=s.runStatement():this.illegal(s,`${Dj} may only have one run statement`);return i===void 0?(this.illegal(e,`${Dj} must have a run statement`),null):this.visitRunStatement(i)}visitRunStatement(e){const r=e.topLevelAnonQueryDef(),i=this.getQueryDefinition(r.sqExpr()),s=this.getAnnotations(e.topLevelAnonQueryDef().tags());return i!==null?{annotations:s,definition:i}:null}getSourceArguments(e){const r=[];for(const i of e.sourceArgument()){const s=i.argumentId();if(s===void 0)return this.contextError(i,"unnamed-source-argument","Source argument must be named"),null;const o=(0,Hx.getId)(s),u=this.getLiteralIncludingNegativeNumber(i.fieldExpr());if(u===null)return null;r.push({name:o,value:u})}return r}getQueryReference(e){const r=e.sourceArguments(),i=(0,Hx.getId)(e);if(r){const s=this.getSourceArguments(r);return s===null?null:{name:i,parameters:s}}else return{name:i}}getQueryDefinition(e){if(e instanceof _t.SQIDContext){const r=this.getQueryReference(e);if(r!==null)return{kind:"query_reference",...r}}else{if(e instanceof _t.SQParensContext)return this.getQueryDefinition(e.sqExpr());if(e instanceof _t.SQComposeContext)this.notAllowed(e,"Source compositions");else if(e instanceof _t.SQRefinedQueryContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:(s.kind==="arrow"&&this.notAllowed(e,"Queries against refined queries"),{kind:"refinement",base:i,refinement:s})}else if(e instanceof _t.SQExtendedSourceContext)this.notAllowed(e,"Source extensions");else if(e instanceof _t.SQIncludeContext)this.notAllowed(e,"Source inclusions");else if(e instanceof _t.SQTableContext)this.notAllowed(e,"Table statements");else if(e instanceof _t.SQSQLContext)this.notAllowed(e,"SQL statements");else if(e instanceof _t.SQArrowContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:i.kind==="query_reference"?{kind:"arrow",source:{...i,kind:"source_reference"},view:s}:i.kind==="arrow"?{kind:"arrow",source:i.source,view:{kind:"arrow",source:i.view,view:s}}:{kind:"arrow",source:i,view:s}}}return null}getRefinementSegment(e){if(e instanceof _t.SegOpsContext){const r=e.queryProperties().queryStatement().flatMap(i=>this.getSegmentOperation(i));return r.some(i=>i===null)?null:{kind:"segment",operations:r}}else if(e instanceof _t.SegFieldContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"view_reference",name:r,path:i}}else{if(e instanceof _t.SegParenContext)return this.getViewExpression(e.vExpr());if(e instanceof _t.SegRefineContext){const r=this.getRefinementSegment(e._lhs),i=this.getRefinementSegment(e._rhs);return r===null||i===null?null:{kind:"refinement",base:r,refinement:i}}}return null}getGroupByStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"group_by",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getAggregateStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"aggregate",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getOrderByStatement(e){const r=e.ordering().orderBySpec(),i=[];for(const s of r)if(s.INTEGER_LITERAL())this.notAllowed(s,"Indexed order by statements");else if(s.fieldName()){const o=(0,Hx.getId)(s.fieldName()),u=s.ASC()?"asc":s.DESC()?"desc":void 0;i.push({kind:"order_by",direction:u,field_reference:{name:o}})}else return null;return i}getNestStatement(e){const r=this.getAnnotations(e.tags()),i=e.nestedQueryList().nestEntry(),s=[];for(const o of i){if(!(o instanceof _t.NestDefContext))return this.internalError(o,"Expected nestDef"),null;const u=this.getAnnotations(o.tags()),a=this.getIsAnnotations(o.isDefine()),l=o.queryName(),c=l?(0,Hx.getId)(l):void 0,f=this.getViewExpression(o.vExpr());if(f===null)return null;s.push({kind:"nest",name:c,view:{definition:f,annotations:this.combineAnnotations(r,u,a)}})}return s}getViewExpression(e){if(e instanceof _t.VSegContext)return this.getRefinementSegment(e.segExpr());if(e instanceof _t.VArrowContext){const r=this.getRefinementSegment(e),i=this.getViewExpression(e._rhs);return r===null||i===null?null:{kind:"arrow",source:r,view:i}}else return this.internalError(e,"Unexpected VExpr node"),null}getLimitStatement(e){return{kind:"limit",limit:this.getNumber(e.INTEGER_LITERAL())}}getSegmentOperation(e){if(e.groupByStatement()){const r=e.groupByStatement();return this.getGroupByStatement(r)}else if(e.aggregateStatement()){const r=e.aggregateStatement();return this.getAggregateStatement(r)}else if(e.limitStatement()){const r=e.limitStatement(),i=this.getLimitStatement(r);return i===null?null:[i]}else if(e.declareStatement())this.notAllowed(e,"Declare statements");else if(e.queryJoinStatement())this.notAllowed(e,"Query join statements");else if(e.queryExtend())this.notAllowed(e,"Query extend statements");else if(e.projectStatement())this.notAllowed(e,"Select statements");else if(e.indexStatement())this.notAllowed(e,"Index statements");else if(e.calculateStatement())this.notAllowed(e,"Calculate statements");else if(e.topStatement())this.notAllowed(e,"Top statements");else if(e.orderByStatement()){const r=e.orderByStatement();return this.getOrderByStatement(r)}else if(e.whereStatement()){const r=e.whereStatement(),i=this.getWhere(r);return i===null?null:i.map(s=>({kind:"where",...s}))}else if(e.drillStatement()){const r=e.drillStatement(),i=this.getDrill(r);return i===null?null:i.map(s=>({kind:"drill",...s}))}else if(e.havingStatement()){const r=e.havingStatement(),i=this.getHaving(r);return i===null?null:i.map(s=>({kind:"having",...s}))}else if(e.nestStatement()){const r=e.nestStatement();return this.getNestStatement(r)}else e.sampleStatement()?this.notAllowed(e,"Sample statements"):e.timezoneStatement()?this.notAllowed(e,"Timezone statements"):(e.queryAnnotation()||e.ignoredModelAnnotations())&&this.notAllowed(e,"Detached annotation statements");return null}getFieldPath(e){const r=e.fieldName().map(o=>(0,Hx.getId)(o)),i=r[r.length-1],s=r.slice(0,-1);return{name:i,path:s.length>0?s:void 0}}getTimeframe(e){const r=e.text;return(0,d2t.isTimestampUnit)(r)?r:(this.illegal(e,`Invalid timeframe ${r}`),null)}getQueryField(e){if(e.taggedRef()){const r=e.taggedRef(),i=this.getAnnotations(r.tags()),{name:s,path:o}=this.getFieldPath(r.fieldPath());if(r.refExpr()){const u=r.refExpr();if(u.timeframe()){const a=this.getTimeframe(u.timeframe());return a===null?null:{name:void 0,field:{annotations:i,expression:{kind:"time_truncation",field_reference:{name:s,path:o},truncation:a}}}}else u.aggregate()&&this.notAllowed(u,"Aggregate expressions")}else return{name:void 0,field:{annotations:i,expression:{kind:"field_reference",name:s,path:o}}}}else if(e.fieldDef()){const r=e.fieldDef(),i=this.getAnnotations(r.tags()),s=this.getIsAnnotations(r.isDefine()),o=(0,Hx.getId)(r.fieldNameDef()),u=this.getFieldExpression(r.fieldExpr());return u===null?null:{name:o,field:{expression:u,annotations:this.combineAnnotations(i,s)}}}return null}getFieldExpression(e){if(e instanceof _t.ExprFieldPathContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"field_reference",name:r,path:i}}else if(e instanceof _t.ExprTimeTruncContext){const r=this.getTimeframe(e.timeframe()),i=e.fieldExpr(),s=this.getFieldExpression(i);return s===null||r===null?null:s.kind!=="field_reference"?(this.illegal(i,"Left hand side of time truncation must be a field reference"),null):{kind:"time_truncation",truncation:r,field_reference:{name:s.name,path:s.path,parameters:s.parameters}}}else if(e instanceof _t.ExprFieldPropsContext){const r=e.fieldExpr(),i=this.getFieldExpression(r);if(i===null)return null;if(i.kind!=="field_reference")return this.illegal(r,"Left hand side of filtered field must be a field reference"),null;const s=e.fieldProperties().fieldPropertyStatement(),o=[];for(const u of s){const a=u.whereStatement();if(a){const l=this.getWhere(a);if(l===null)return null;o.push(...l)}}return{kind:"filtered_field",field_reference:{name:i.name,path:i.path,parameters:i.parameters},where:o}}else{const r=this.getLiteralIncludingNegativeNumber(e);return r===null?null:{kind:"literal_value",literal_value:r}}}stripQuote(e,r){return e.slice(e.indexOf(r)+r.length,e.lastIndexOf(r))}getFilterString(e){const r=e.tripFilterString(),i=e.tickFilterString();if(r){const s=r.BQ3_FILTER(),o=r.DQ3_FILTER(),u=r.SQ3_FILTER();if(s)return this.stripQuote(s.text,"```");if(o)return this.stripQuote(o.text,'"""');if(u)return this.stripQuote(u.text,"'''")}else if(i){const s=i.BQ_FILTER(),o=i.DQ_FILTER(),u=i.SQ_FILTER();if(s)return this.stripQuote(s.text,"`");if(o)return this.stripQuote(o.text,'"');if(u)return this.stripQuote(u.text,"'")}return null}getFilterExpr(e){if(e instanceof _t.ExprCompareContext){if(e.compareOp().MATCH()){const r=e.fieldExpr()[0],i=e.fieldExpr()[1];if(r instanceof _t.ExprFieldPathContext&&i instanceof _t.ExprLiteralContext){const{path:s,name:o}=this.getFieldPath(r.fieldPath()),u=i.literal();if(u instanceof _t.FilterString_stubContext){const a=this.getFilterString(u.filterString());return a===null?null:{filter:{kind:"filter_string",field_reference:{name:o,path:s},filter:a}}}}}else if(e.compareOp().EQ()){const r=e.fieldExpr()[0],i=e.fieldExpr()[1];if(r instanceof _t.ExprFieldPathContext){const{path:s,name:o}=this.getFieldPath(r.fieldPath()),u=this.getLiteralIncludingNegativeNumber(i);return u===null?(this.notAllowed(e,"Filters other than comparisons with filter strings or equality with literals"),null):{filter:{kind:"literal_equality",field_reference:{name:o,path:s},value:u}}}}}return this.notAllowed(e,"Filters other than comparisons with filter strings or equality with literals"),null}getTimeLiteral(e,r){const i=r(e.text);if(!i)return this.contextError(e,"failed-to-parse-time-literal","Time data parse error"),null;const s=i.getValue(),o=s.timeframe;if(s.value.node!=="timeLiteral")return null;const u=s.value.literal,a=s.value.timezone;return s.type==="timestamp"?{kind:"timestamp_literal",timestamp_value:u,granularity:o,timezone:a}:o==="hour"||o==="minute"||o==="second"?null:{kind:"date_literal",date_value:u,granularity:o,timezone:a}}getLiteralIncludingNegativeNumber(e){if(e instanceof _t.ExprLiteralContext)return this.getLiteral(e.literal());if(e instanceof _t.ExprMinusContext){const r=e.fieldExpr();if(r instanceof _t.ExprLiteralContext){const i=this.getLiteral(r.literal());return i===null||i.kind!=="number_literal"?null:{kind:"number_literal",number_value:-i.number_value}}}return null}getLiteral(e){if(e instanceof _t.ExprTimeContext){const r=e.dateLiteral();return r instanceof _t.LiteralTimestampContext?this.getTimeLiteral(r,Qx.LiteralTimestamp.parse):r instanceof _t.LiteralHourContext?this.getTimeLiteral(r,Qx.LiteralHour.parse):r instanceof _t.LiteralDayContext?this.getTimeLiteral(r,Qx.LiteralDay.parse):r instanceof _t.LiteralWeekContext?this.getTimeLiteral(r,Qx.LiteralWeek.parse):r instanceof _t.LiteralMonthContext?this.getTimeLiteral(r,Qx.LiteralMonth.parse):r instanceof _t.LiteralQuarterContext?this.getTimeLiteral(r,Qx.LiteralQuarter.parse):r instanceof _t.LiteralYearContext?this.getTimeLiteral(r,Qx.LiteralYear.parse):null}else{if(e instanceof _t.ExprArrayLiteralContext)return this.notAllowed(e,"array literals"),null;if(e instanceof _t.ExprLiteralRecordContext)return this.notAllowed(e,"record literals"),null;if(e instanceof _t.ExprStringContext){const[r,i]=(0,Hx.getPlainString)(e);for(const s of i)s instanceof c2t.ParserRuleContext&&this.contextError(s,"illegal-query-interpolation-outside-sql-block","%{ query } illegal in this string");return{kind:"string_literal",string_value:r??""}}else{if(e instanceof _t.ExprBoolContext)return{kind:"boolean_literal",boolean_value:e.TRUE()!==null};if(e instanceof _t.ExprNumberContext)return{kind:"number_literal",number_value:Number(e.text)};if(e instanceof _t.ExprNULLContext)return{kind:"null_literal"}}}return null}getDrill(e){const i=e.drillClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}getWhere(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}getHaving(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}combineAnnotations(...e){const r=e.flatMap(i=>i??[]);return r.length>0?r:void 0}}bv.MalloyToQuery=The;function p2t(t){const e=(0,bhe.getSourceInfo)(t),r=new Che.BaseMessageLogger(null),i="internal://query.malloy",s=(0,x2t.runMalloyParser)(t,i,e,r),u=new The(s,r).visit(s.root),a=(0,h2t.mapLogs)(r.getLog(),i);if(u===null)return{logs:a};if(!("definition"in u))throw new Error("Expected a query");return{query:u,logs:a}}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.malloyToQuery=t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=nf;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var r=Cv;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return r.exploreQueryWalkerBuilder}});var i=bv;Object.defineProperty(t,"malloyToQuery",{enumerable:!0,get:function(){return i.malloyToQuery}})})(dT);var Le={},jD={};Object.defineProperty(jD,"__esModule",{value:!0}),jD.MALLOY_VERSION=void 0,jD.MALLOY_VERSION="0.0.290",Object.defineProperty(Le,"__esModule",{value:!0}),Le.InMemoryModelCache=Le.CacheManager=Le.CSVWriter=Le.JSONWriter=Le.DataWriter=Le.DataRecord=Le.DataArray=Le.Result=Le.ExploreMaterializer=Le.PreparedResultMaterializer=Le.QueryMaterializer=Le.ModelMaterializer=Le.SingleConnectionRuntime=Le.ConnectionRuntime=Le.Runtime=Le.ExploreField=Le.JoinRelationship=Le.QueryField=Le.Query=Le.StringField=Le.UnsupportedField=Le.JSONField=Le.BooleanField=Le.NumberField=Le.TimestampField=Le.DateField=Le.TimestampTimeframe=Le.DateTimeframe=Le.AtomicField=Le.AtomicFieldType=Le.Explore=Le.SourceRelationship=Le.FixedConnectionMap=Le.InMemoryURLReader=Le.EmptyURLReader=Le.PreparedResult=Le.DocumentCompletion=Le.DocumentSymbol=Le.DocumentPosition=Le.DocumentRange=Le.DocumentTablePath=Le.Parse=Le.PreparedQuery=Le.Model=Le.MalloyError=Le.Malloy=void 0;const Rhe=dT,Nr=pi,Dhe=_E,Oj=A2,m2t=jD,g2t=C2,Mn=Ws,y2t=Bx,E2t=Ji,v2t=mv;function _2t(t){return t.type==="table"||t.type==="sql_select"||t.type==="query_source"}const Ohe="internal://internal.malloy";let R0=class ZO{static get version(){return m2t.MALLOY_VERSION}static _parse(e,r,i,s,o){r===void 0&&(r=new URL(Ohe));let u=r;s!=null&&s.importBaseURL&&(u=s==null?void 0:s.importBaseURL);const a=new Rhe.MalloyTranslator(r.toString(),u.toString(),{urls:{[r.toString()]:e}},i);return s!=null&&s.testEnvironment&&(a.allDialectsEnabled=!0),new Fhe(a,o)}static parse({url:e,urlReader:r,source:i,eventStream:s,options:o}){if(i!==void 0)return ZO._parse(i,e,s,o);if(r===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 VD(r,e).then(({contents:u,invalidationKey:a})=>ZO._parse(u,e,s,o,a))}static async compile({url:e,source:r,parse:i,urlReader:s,connections:o,model:u,refreshSchemaCache:a,noThrowOnError:l,eventStream:c,importBaseURL:f,cacheManager:d}){var x,p,m,g,y;let E;if(a&&(E=typeof a=="number"?a:Date.now()),e===void 0&&r===void 0&&i===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(i!==void 0?e=new URL(i._translator.sourceURL):e=new URL(Ohe));const v={};if(r===void 0&&d!==void 0){const S=await d.getCachedModelDef(s,e.toString());if(S)return new h1(S.modelDef,[],[e.toString(),...WD(S.modelDef.dependencies)])}f??(f=e);let _;const A=e.toString();if(i!==void 0){_=i._translator;const S=(x=i._invalidationKey)!==null&&x!==void 0?x:await qj(s,e);v[A]=S}else{if(r===void 0){const{contents:S,invalidationKey:b}=await VD(s,e);v[A]=b,r=S}else{const S=await qj(s,e);v[A]=S}_=new Rhe.MalloyTranslator(A,f.toString(),{urls:{[A]:r}},c)}for(;;){const S=_.translate(u==null?void 0:u._modelDef);if(S.final)if(S.modelDef){await(d==null?void 0:d.setCachedModelDef(e.toString(),{modelDef:S.modelDef,invalidationKeys:v}));for(const b of _.newlyTranslatedDependencies())await(d==null?void 0:d.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new h1(S.modelDef,S.problems||[],[...(p=u==null?void 0:u.fromSources)!==null&&p!==void 0?p:[],...(m=S.fromSources)!==null&&m!==void 0?m:[]])}else if(l){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},C=(u==null?void 0:u._modelDef)||b;return new h1(C,S.problems||[],[...(g=u==null?void 0:u.fromSources)!==null&&g!==void 0?g:[],...(y=S.fromSources)!==null&&y!==void 0?y:[]])}else{const b=S.problems||[],C=_.prettyErrors();throw new whe(`Error(s) compiling model:
|
|
1393
|
+
${s}`:e=s}return e}childRequest(e){var r;const i=decodeURI(new URL(e,this.sourceURL).toString()),s=(r=this.childTranslators.get(i))===null||r===void 0?void 0:r.translate();if(s!=null&&s.compileSQL)return{compileSQL:s.compileSQL}}getChildExports(e){const r={},i=decodeURI(new URL(e,this.sourceURL).toString()),s=this.childTranslators.get(i);if(s&&s.translate().modelDef)for(const u of s.modelDef.exports){const a=s.modelDef.contents[u];((0,Npt.isSourceDef)(a)||a.type==="query")&&(r[u]=a)}return r}translate(e){if(this.finalAnswer)return this.finalAnswer;const r=this.translateStep.step(this,e);return r.final&&(this.finalAnswer=r),r}translatorForDependency(e){return this.childTranslators.get(e)}importAt(e){for(let r=0;r<this.imports.length;r++){const i=this.imports[r];if((0,Sj.locationContainsPosition)(i.location,e))return i}}metadata(){return this.metadataStep.step(this)}modelAnnotation(e){return this.modelAnnotationStep.step(this,e)}tablePathInfo(){return this.tablePathInfoStep.step(this)}completions(e){return this.completionsStep.step(this,e)}helpContext(e){return this.helpContextStep.step(this,e)}defaultLocation(){return{url:this.sourceURL,range:{start:{line:0,character:0},end:{line:0,character:0}}}}rangeFromContext(e){return(0,Sj.rangeFromContext)(this.parseStep.sourceInfo,e)}firstReferenceToDialect(e){return this.dialectAlreadyChecked[e]?!1:(this.dialectAlreadyChecked[e]=!0,!0)}experimentalDialectEnabled(e){if(this.allDialectsEnabled)return!0;const r=this.compilerFlags.tag("experimental");return r!==void 0&&(r.bare()||r.has("dialect",e))}}nf.MalloyTranslation=Cj;class hhe extends Cj{constructor(e,r){super(e),this.root=r}}nf.MalloyChildTranslator=hhe;class Zpt extends Cj{constructor(e,r=null,i=null,s=null){super(e,r),this.eventStream=s,this.schemaZone=new Aj.Zone,this.importZone=new Aj.Zone,this.pretranslatedModels=new Map,this.sqlQueryZone=new Aj.Zone,this.root=this,this.logger=new xhe.BaseMessageLogger(s),i&&this.update(i)}update(e){var r,i,s;this.schemaZone.updateFrom(e.tables,(r=e.errors)===null||r===void 0?void 0:r.tables),this.importZone.updateFrom(e.urls,(i=e.errors)===null||i===void 0?void 0:i.urls),this.sqlQueryZone.updateFrom(e.compileSQL,(s=e.errors)===null||s===void 0?void 0:s.compileSQL);for(const o in e.translations)this.pretranslatedModels.set(o,e.translations[o])}logError(e,r,i){return this.logger.log((0,xhe.makeLogMessage)(e,r,{severity:"error",...i})),e}}nf.MalloyTranslator=Zpt;function phe(t){return[...Object.keys(t),...Object.keys(t).map(e=>phe(t[e])).flat()]}var Cv={};Object.defineProperty(Cv,"__esModule",{value:!0}),Cv.ExploreQueryWalker=void 0,Cv.exploreQueryWalkerBuilder=t2t;const e2t=kc;class mhe{constructor(e){this.inDocument=!1,this.exploreClauseRefs=[],this.tokens=e}exploreQueryAtOffset(e){return this.exploreClauseRefs.find(r=>r.range[0]===void 0||r.range[1]===void 0?!1:r.range[0]<=e&&r.range[1]>=e)}filterAtOffset(e){const r=this.exploreQueryAtOffset(e);if(r)return r.filterRefs.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e)}hasFilterListAtOffset(e){const r=this.exploreQueryAtOffset(e);return r?!!r.filterLists.find(i=>i.range[0]===void 0||i.range[1]===void 0?!1:i.range[0]<=e&&i.range[1]>=e):!1}enterMalloyDocument(){this.inDocument=!0}}Cv.ExploreQueryWalker=mhe;function t2t(t,e){const r=new mhe(t),i=r;return e2t.ParseTreeWalker.DEFAULT.walk(i,e),r}var bv={},Tv={},T0={};Object.defineProperty(T0,"__esModule",{value:!0}),T0.sourceDefToSourceInfo=yhe,T0.modelDefToModelInfo=n2t,T0.convertFieldInfos=x1,T0.writeLiteralToTag=Ahe,T0.getResultStructMetadataAnnotation=MD;const jo=pi,bj=wu,Tj=Ws,ghe=Ps;function yhe(t){var e;const r=t.parameters&&Object.entries(t.parameters).length>0?Object.entries(t.parameters).map(([s,o])=>(0,jo.isAtomic)(o)?{name:s,type:PD(o),default_value:Ehe(o.value)}:{name:s,type:{kind:"filter_expression_type",filter_type:{kind:`${o.filterType}_type`}},default_value:Ehe(o.value)}):void 0;return{name:(e=t.as)!==null&&e!==void 0?e:t.name,schema:{fields:x1(t,t.fields)},parameters:r,annotations:Rj(t)}}function n2t(t){const e={entries:[],anonymous_queries:[]};for(const[r,i]of Object.entries(t.contents))if(t.exports.includes(r)){if((0,jo.isSourceDef)(i)){const s=yhe(i);e.entries.push({kind:"source",...s})}else if(i.type==="query"){const s=(0,bj.getResultStructDefForQuery)(t,i),o=Rj(i),u=s.resultMetadata?MD(s,s.resultMetadata):void 0,a=[...o??[],...u?[u]:[]],l={kind:"source",name:r,schema:{fields:x1(s,s.fields)},annotations:a.length>0?a:void 0};e.entries.push(l)}}for(const r of t.queryList){const i=(0,bj.getResultStructDefForQuery)(t,r),s=Rj(r),o=i.resultMetadata?MD(i,i.resultMetadata):void 0,u=[...s??[],...o?[o]:[]],a={schema:{fields:x1(i,i.fields)},annotations:u.length>0?u:void 0};e.anonymous_queries.push(a)}return e}function Ehe(t){if(t!==null)switch(t.node){case"numberLiteral":return{kind:"number_literal",number_value:parseFloat(t.literal)};case"stringLiteral":return{kind:"string_literal",string_value:t.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:t.filterSrc};case"timeLiteral":return{kind:"timestamp_literal",timestamp_value:t.literal};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"null":return{kind:"null_literal"};default:throw new Error("Invalid parameter default value")}}function Rj(t){return(0,Tj.annotationToTaglines)(t.annotation).map(r=>({value:r}))}function x1(t,e){var r,i,s;const o=[];for(const u of e){if(!(u.accessModifier===void 0))continue;const c=(0,Tj.annotationToTaglines)(u.annotation).map(d=>({value:d})),f=c.length>0?c:void 0;if((0,jo.isTurtle)(u)){const d=(0,bj.getResultStructDefForView)(t,u),x=d.resultMetadata?MD(d,d.resultMetadata):void 0,p=[...f??[],...x?[x]:[]],m={kind:"view",name:(r=u.as)!==null&&r!==void 0?r:u.name,annotations:p.length>0?p:void 0,schema:{fields:x1(d,d.fields)}};o.push(m)}else if((0,jo.isAtomic)(u)){const d=(0,jo.expressionIsAggregate)(u.expressionType),x=(0,jo.expressionIsScalar)(u.expressionType);if(!d&&!x||u.type==="error")continue;const p=u.resultMetadata?vhe(u,u.resultMetadata):void 0,m=[...f??[],...p?[p]:[]],g={kind:d?"measure":"dimension",name:(i=u.as)!==null&&i!==void 0?i:u.name,type:PD(u),annotations:m.length>0?m:void 0};o.push(g)}else if((0,jo.isJoinedSource)(u)){const d={kind:"join",name:(s=u.as)!==null&&s!==void 0?s:u.name,annotations:f,schema:{fields:x1(u,u.fields)},relationship:u.join};o.push(d)}}return o}function vhe(t,e){const r=ghe.Tag.withPrefix("#(malloy) ");let i=!1;if(e.referenceId!==void 0&&(r.set(["reference_id"],e.referenceId),i=!0),e.fieldKind==="measure"&&(r.set(["calculation"]),i=!0),e.drillable&&(r.set(["drillable"]),i=!0),((0,jo.isAtomic)(t)||(0,jo.isTurtle)(t))&&t.drillView!==void 0&&(r.set(["drill_view"],t.drillView),i=!0),e.filterList&&(_he(r,e.filterList),i=!0),e.fieldKind==="dimension"){const o=(e==null?void 0:e.sourceExpression)||(e!=null&&e.sourceField.includes(".")?e==null?void 0:e.sourceField:i2t(t.name));r.set(["drill_expression"],o),i=!0}return i?{value:r.toString()}:void 0}function _he(t,e){var r;for(let i=0;i<e.length;i++){const s=e[i];s.expressionType!=="scalar"||s.isSourceFilter||(t.set(["drill_filters",i,"code"],s.code),s.drillView&&t.set(["drill_filters",i,"drill_view"],s.drillView),s.drillView===void 0&&s.stableFilter!==void 0&&(t.set(["drill_filters",i,"field_reference"],[...(r=s.stableFilter.field_reference.path)!==null&&r!==void 0?r:[],s.stableFilter.field_reference.name]),s.stableFilter.kind==="filter_string"?(t.set(["drill_filters",i,"kind"],"filter_expression"),t.set(["drill_filters",i,"filter_expression"],s.stableFilter.filter)):(t.set(["drill_filters",i,"kind"],"literal_equality"),Ahe(t,["drill_filters",i,"value"],s.stableFilter.value))))}}function Ahe(t,e,r){switch(t.set([...e,"kind"],r.kind),r.kind){case"string_literal":t.set([...e,"string_value"],r.string_value);break;case"number_literal":t.set([...e,"number_value"],r.number_value);break;case"boolean_literal":t.set([...e,"boolean_value"],r.boolean_value.toString());break;case"date_literal":t.set([...e,"date_value"],r.date_value),t.set([...e,"timezone"],r.timezone),t.set([...e,"granularity"],r.granularity);break;case"timestamp_literal":t.set([...e,"timestamp_value"],r.timestamp_value),t.set([...e,"timezone"],r.timezone),t.set([...e,"granularity"],r.granularity);break;case"filter_expression_literal":t.set([...e,"filter_expression_value"],r.filter_expression_value);break}}function r2t(t){return t.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}function i2t(t){return t.match(/^[A-Za-z_][0-9A-Za-z_]*$/)?t:`\`${r2t(t)}\``}function MD(t,e){var r,i;const s=ghe.Tag.withPrefix("#(malloy) ");let o=!1;if(e.limit!==void 0&&(s.set(["limit"],e.limit),o=!0),e.filterList&&(_he(s,e.filterList),o=!0),e.drillable&&(s.set(["drillable"]),o=!0),e.orderBy){for(let u=0;u<e.orderBy.length;u++){const a=e.orderBy[u],l=typeof a.field=="number"?(r=t.fields[a.field-1].as)!==null&&r!==void 0?r:t.fields[a.field-1].name:a.field,c=(i=a.dir)!==null&&i!==void 0?i:null;s.set(["ordered_by",u,l],c)}o=!0}return o?{value:s.toString()}:void 0}function PD(t){if((0,jo.isBasicAtomic)(t))switch(t.type){case"string":return{kind:"string_type"};case"number":return{kind:"number_type",subtype:t.numberType==="float"?"decimal":t.numberType==="integer"?"integer":void 0};case"boolean":return{kind:"boolean_type"};case"date":{const e=t.timeframe;return e&&!s2t(e)?{kind:"timestamp_type",timeframe:t.timeframe}:{kind:"date_type",timeframe:o2t(t.timeframe)}}case"timestamp":return{kind:"timestamp_type",timeframe:t.timeframe};case"json":return{kind:"json_type"};case"sql native":return{kind:"sql_native_type",sql_type:t.rawType};case"error":throw new Error("Error type is not supported in stable interface")}else{if((0,jo.isRepeatedRecord)(t))return{kind:"array_type",element_type:She(t)};if(t.type==="record")return She(t);if(t.type==="array")return{kind:"array_type",element_type:PD(t.elementTypeDef)}}throw new Error("Unexpected field type")}function She(t){return{kind:"record_type",fields:t.fields.map(e=>{const r=[];if("resultMetadata"in e&&e.resultMetadata){const i=vhe(e,e.resultMetadata);i&&r.push(i)}if(e.annotation){const i=(0,Tj.annotationToTaglines)(e.annotation);r.push(...i.map(s=>({value:s})))}if((0,jo.isAtomic)(e))return{name:e.name,annotations:r.length>0?r:void 0,type:PD(e)};throw new Error("Expected record type to not have a table as its child")})}}function s2t(t){switch(t){case"day":case"week":case"month":case"year":case"quarter":return!0;default:return!1}}function o2t(t){switch(t){case void 0:return;case"day":case"week":case"month":case"year":case"quarter":return t;default:throw new Error(`Invalid date timeframe ${t}`)}}function Eyt(t){return t}function vyt(t){return t}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.DEFAULT_LOG_RANGE=void 0,t.wrapLegacyInfoConnection=u,t.wrapLegacyConnection=a,t.mapData=c,t.wrapResult=f,t.nodeToLiteralValue=d,t.mapLogs=x;const e=Ps,r=Ws,i=pi,s=T0,o=_E;function u(p){return{get dialectName(){return p.dialectName},async fetchSchemaForSQLQuery(m){const g=await p.fetchSchemaForSQLStruct({connection:p.name,selectStr:m},{}),y=g.structDef;if(y===void 0)throw new Error(g.error);return{fields:(0,s.convertFieldInfos)(y,y.fields)}},async fetchSchemaForTable(m){const g=`${p.name}:${m}`,y=await p.fetchSchemaForTables({[g]:m},{}),E=y.schemas[g];if(E===void 0)throw new Error(y.errors[g]);return{fields:(0,s.convertFieldInfos)(E,E.fields)}}}}function a(p){return{...u(p),runSQL:async(m,g)=>{const y=await p.runSQL(m);return c(y.rows,g)}}}function l(p){if(p instanceof Date)return p;if(p.constructor.name==="Date")return new Date(p);if(typeof p=="number")return new Date(p);if(typeof p!="string")return new Date(p.value);{let g=o.DateTime.fromISO(p,{zone:"UTC"});return g.isValid||(g=o.DateTime.fromSQL(p,{zone:"UTC"})),g.toJSDate()}}function c(p,m){function g(v,_){if(v===null)return{kind:"null_cell"};if(_.type.kind==="date_type"||_.type.kind==="timestamp_type"){const A=l(v).toISOString();return _.type.kind==="date_type"?{kind:"date_cell",date_value:A}:{kind:"timestamp_cell",timestamp_value:A}}else if(_.type.kind==="boolean_type"){if(typeof v=="number")return{kind:"boolean_cell",boolean_value:v!==0};if(typeof v!="boolean")throw new Error(`Invalid boolean ${v}`);return{kind:"boolean_cell",boolean_value:v}}else if(_.type.kind==="number_type"){if(typeof v!="number")throw new Error(`Invalid number ${v}`);return{kind:"number_cell",number_value:v}}else if(_.type.kind==="string_type"){if(typeof v!="string")throw new Error(`Invalid string ${v}`);return{kind:"string_cell",string_value:v}}else if(_.type.kind==="array_type"){if(!Array.isArray(v))throw new Error(`Invalid array ${v}`);return{kind:"array_cell",array_value:v.map(A=>g(A,{name:"array_element",type:_.type.element_type}))}}else{if(_.type.kind==="json_type")return{kind:"json_cell",json_value:JSON.stringify(v)};if(_.type.kind==="sql_native_type")return{kind:"sql_native_cell",sql_native_value:JSON.stringify(v)};{const A=_.type;if(A.kind!=="record_type")throw new Error(`Invalid record in result ${JSON.stringify(_)}, ${JSON.stringify(v)}`);return y(v,{kind:"join",relationship:"many",name:"array_element",schema:{fields:A.fields.map(S=>({kind:"dimension",...S}))}})}}}function y(v,_){const A=[];for(const S of _.schema.fields){const b=v[S.name];if(S.kind!=="dimension")throw new Error("Invalid result -- expected all fields to be dimensions");const C=g(b,S);A.push(C)}return{kind:"record_cell",record_value:A}}const E={kind:"join",schema:m,name:"root",relationship:"one"};return{kind:"array_cell",array_value:p.map(v=>y(v,E))}}function f(p){const m=p._queryResult.structs,g=m[m.length-1],y={fields:(0,s.convertFieldInfos)(g,g.fields)},E=(0,r.annotationToTaglines)(p.annotation).map(A=>({value:A})),v=g.resultMetadata?(0,s.getResultStructMetadataAnnotation)(g,g.resultMetadata):void 0;v&&E.push(v),E.push(...g.resultMetadata?[]:[]);const _=e.Tag.withPrefix("#(malloy) ");if(p.sourceExplore&&_.set(["source","name"],p.sourceExplore.name),p._sourceArguments){const A=Object.entries(p._sourceArguments);for(let S=0;S<A.length;S++){const[b,C]=A[S],R=d(C.value);R!==void 0&&(0,s.writeLiteralToTag)(_,["source","parameters",S,"value"],R),_.set(["source","parameters",S,"name"],b)}}return E.push({value:_.toString()}),E.push({value:e.Tag.withPrefix("#(malloy) ").set(["query_name"],p.resultExplore.name).toString()}),{schema:y,data:c(p.data.toObject(),y),connection_name:p.connectionName,annotations:E.length>0?E:void 0,query_timezone:p.data.field.queryTimezone,sql:p.sql}}function d(p){switch(p==null?void 0:p.node){case"numberLiteral":return{kind:"number_literal",number_value:Number.parseFloat(p.literal)};case"null":return{kind:"null_literal"};case"stringLiteral":return{kind:"string_literal",string_value:p.literal};case"filterLiteral":return{kind:"filter_expression_literal",filter_expression_value:p.filterSrc};case"true":return{kind:"boolean_literal",boolean_value:!0};case"false":return{kind:"boolean_literal",boolean_value:!1};case"timeLiteral":return p.typeDef.type==="date"?p.typeDef.timeframe===void 0||(0,i.isDateUnit)(p.typeDef.timeframe)?{kind:"date_literal",date_value:p.literal,timezone:p.timezone,granularity:p.typeDef.timeframe}:void 0:{kind:"timestamp_literal",timestamp_value:p.literal,timezone:p.timezone,granularity:p.typeDef.timeframe};default:return}}t.DEFAULT_LOG_RANGE={start:{line:0,character:0},end:{line:0,character:0}};function x(p,m){return p.map(g=>{var y,E,v,_;return{severity:g.severity,message:g.message,range:(E=(y=g.at)===null||y===void 0?void 0:y.range)!==null&&E!==void 0?E:t.DEFAULT_LOG_RANGE,url:(_=(v=g.at)===null||v===void 0?void 0:v.url)!==null&&_!==void 0?_:m}})}})(Tv);var u2t=T&&T.__createBinding||(Object.create?function(t,e,r,i){i===void 0&&(i=r);var s=Object.getOwnPropertyDescriptor(e,r);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[r]}}),Object.defineProperty(t,i,s)}:function(t,e,r,i){i===void 0&&(i=r),t[i]=e[r]}),a2t=T&&T.__setModuleDefault||(Object.create?function(t,e){Object.defineProperty(t,"default",{enumerable:!0,value:e})}:function(t,e){t.default=e}),l2t=T&&T.__importStar||function(){var t=function(e){return t=Object.getOwnPropertyNames||function(r){var i=[];for(var s in r)Object.prototype.hasOwnProperty.call(r,s)&&(i[i.length]=s);return i},t(e)};return function(e){if(e&&e.__esModule)return e;var r={};if(e!=null)for(var i=t(e),s=0;s<i.length;s++)i[s]!=="default"&&u2t(r,e,i[s]);return a2t(r,e),r}}();Object.defineProperty(bv,"__esModule",{value:!0}),bv.MalloyToQuery=void 0,bv.malloyToQuery=p2t;const c2t=g2,f2t=Mp,_t=l2t($),Che=L2,Hx=Cs,d2t=Ke,x2t=zR,bhe=Ji,h2t=Tv,Qx=SE,Dj="Malloy query documents";class The extends f2t.AbstractParseTreeVisitor{constructor(e,r){super(),this.parseInfo=e,this.msgLog=r}internalError(e,r){return this.contextError(e,"internal-translator-error",{message:r}),new Error(`Internal Translator Error: ${r}`)}getLocation(e){return{url:this.parseInfo.sourceURL,range:(0,bhe.rangeFromContext)(this.parseInfo.sourceInfo,e)}}contextError(e,r,i,s){this.msgLog.log((0,Che.makeLogMessage)(r,i,{at:this.getLocation(e),...s}))}getNumber(e){return Number.parseInt(e.text)}defaultResult(){return null}getAnnotations(e){const r=e.ANNOTATION().map(i=>({value:i.text}));return r.length>0?r:void 0}getIsAnnotations(e){var r,i;if(e===void 0)return;const o=((r=this.getAnnotations(e._beforeIs))!==null&&r!==void 0?r:[]).concat((i=this.getAnnotations(e._afterIs))!==null&&i!==void 0?i:[]);return o.length>0?o:void 0}notAllowed(e,r){this.illegal(e,`${r} are not allowed in ${Dj}`)}illegal(e,r){this.contextError(e,"invalid-malloy-query-document",r)}visitMalloyDocument(e){const r=e.malloyStatement();let i;for(const s of r)s.defineSourceStatement()?this.notAllowed(s,"Source definitions"):s.defineQuery()?this.notAllowed(s,"Query definitions"):s.importStatement()?this.notAllowed(s,"Import statements"):s.docAnnotations()?this.notAllowed(s,"Model annotations"):s.ignoredObjectAnnotations()?this.notAllowed(s,"Detatched object annotations"):s.experimentalStatementForTesting()?this.notAllowed(s,"Experimental testing statements"):i===void 0?i=s.runStatement():this.illegal(s,`${Dj} may only have one run statement`);return i===void 0?(this.illegal(e,`${Dj} must have a run statement`),null):this.visitRunStatement(i)}visitRunStatement(e){const r=e.topLevelAnonQueryDef(),i=this.getQueryDefinition(r.sqExpr()),s=this.getAnnotations(e.topLevelAnonQueryDef().tags());return i!==null?{annotations:s,definition:i}:null}getSourceArguments(e){const r=[];for(const i of e.sourceArgument()){const s=i.argumentId();if(s===void 0)return this.contextError(i,"unnamed-source-argument","Source argument must be named"),null;const o=(0,Hx.getId)(s),u=this.getLiteralIncludingNegativeNumber(i.fieldExpr());if(u===null)return null;r.push({name:o,value:u})}return r}getQueryReference(e){const r=e.sourceArguments(),i=(0,Hx.getId)(e);if(r){const s=this.getSourceArguments(r);return s===null?null:{name:i,parameters:s}}else return{name:i}}getQueryDefinition(e){if(e instanceof _t.SQIDContext){const r=this.getQueryReference(e);if(r!==null)return{kind:"query_reference",...r}}else{if(e instanceof _t.SQParensContext)return this.getQueryDefinition(e.sqExpr());if(e instanceof _t.SQComposeContext)this.notAllowed(e,"Source compositions");else if(e instanceof _t.SQRefinedQueryContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:(s.kind==="arrow"&&this.notAllowed(e,"Queries against refined queries"),{kind:"refinement",base:i,refinement:s})}else if(e instanceof _t.SQExtendedSourceContext)this.notAllowed(e,"Source extensions");else if(e instanceof _t.SQIncludeContext)this.notAllowed(e,"Source inclusions");else if(e instanceof _t.SQTableContext)this.notAllowed(e,"Table statements");else if(e instanceof _t.SQSQLContext)this.notAllowed(e,"SQL statements");else if(e instanceof _t.SQArrowContext){const r=e.sqExpr(),i=this.getQueryDefinition(r),s=this.getRefinementSegment(e.segExpr());return s===null||i===null?null:i.kind==="query_reference"?{kind:"arrow",source:{...i,kind:"source_reference"},view:s}:i.kind==="arrow"?{kind:"arrow",source:i.source,view:{kind:"arrow",source:i.view,view:s}}:{kind:"arrow",source:i,view:s}}}return null}getRefinementSegment(e){if(e instanceof _t.SegOpsContext){const r=e.queryProperties().queryStatement().flatMap(i=>this.getSegmentOperation(i));return r.some(i=>i===null)?null:{kind:"segment",operations:r}}else if(e instanceof _t.SegFieldContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"view_reference",name:r,path:i}}else{if(e instanceof _t.SegParenContext)return this.getViewExpression(e.vExpr());if(e instanceof _t.SegRefineContext){const r=this.getRefinementSegment(e._lhs),i=this.getRefinementSegment(e._rhs);return r===null||i===null?null:{kind:"refinement",base:r,refinement:i}}}return null}getGroupByStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"group_by",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getAggregateStatement(e){const r=this.getAnnotations(e.tags()),s=e.queryFieldList().queryFieldEntry().map(o=>this.getQueryField(o));return s.some(o=>o===null)||s===null?null:s.map(o=>{var u;const a=[...r??[],...(u=o.field.annotations)!==null&&u!==void 0?u:[]];return{kind:"aggregate",name:o.name,field:{...o.field,annotations:a.length>0?a:void 0}}})}getOrderByStatement(e){const r=e.ordering().orderBySpec(),i=[];for(const s of r)if(s.INTEGER_LITERAL())this.notAllowed(s,"Indexed order by statements");else if(s.fieldName()){const o=(0,Hx.getId)(s.fieldName()),u=s.ASC()?"asc":s.DESC()?"desc":void 0;i.push({kind:"order_by",direction:u,field_reference:{name:o}})}else return null;return i}getNestStatement(e){const r=this.getAnnotations(e.tags()),i=e.nestedQueryList().nestEntry(),s=[];for(const o of i){if(!(o instanceof _t.NestDefContext))return this.internalError(o,"Expected nestDef"),null;const u=this.getAnnotations(o.tags()),a=this.getIsAnnotations(o.isDefine()),l=o.queryName(),c=l?(0,Hx.getId)(l):void 0,f=this.getViewExpression(o.vExpr());if(f===null)return null;s.push({kind:"nest",name:c,view:{definition:f,annotations:this.combineAnnotations(r,u,a)}})}return s}getViewExpression(e){if(e instanceof _t.VSegContext)return this.getRefinementSegment(e.segExpr());if(e instanceof _t.VArrowContext){const r=this.getRefinementSegment(e),i=this.getViewExpression(e._rhs);return r===null||i===null?null:{kind:"arrow",source:r,view:i}}else return this.internalError(e,"Unexpected VExpr node"),null}getLimitStatement(e){return{kind:"limit",limit:this.getNumber(e.INTEGER_LITERAL())}}getSegmentOperation(e){if(e.groupByStatement()){const r=e.groupByStatement();return this.getGroupByStatement(r)}else if(e.aggregateStatement()){const r=e.aggregateStatement();return this.getAggregateStatement(r)}else if(e.limitStatement()){const r=e.limitStatement(),i=this.getLimitStatement(r);return i===null?null:[i]}else if(e.declareStatement())this.notAllowed(e,"Declare statements");else if(e.queryJoinStatement())this.notAllowed(e,"Query join statements");else if(e.queryExtend())this.notAllowed(e,"Query extend statements");else if(e.projectStatement())this.notAllowed(e,"Select statements");else if(e.indexStatement())this.notAllowed(e,"Index statements");else if(e.calculateStatement())this.notAllowed(e,"Calculate statements");else if(e.topStatement())this.notAllowed(e,"Top statements");else if(e.orderByStatement()){const r=e.orderByStatement();return this.getOrderByStatement(r)}else if(e.whereStatement()){const r=e.whereStatement(),i=this.getWhere(r);return i===null?null:i.map(s=>({kind:"where",...s}))}else if(e.drillStatement()){const r=e.drillStatement(),i=this.getDrill(r);return i===null?null:i.map(s=>({kind:"drill",...s}))}else if(e.havingStatement()){const r=e.havingStatement(),i=this.getHaving(r);return i===null?null:i.map(s=>({kind:"having",...s}))}else if(e.nestStatement()){const r=e.nestStatement();return this.getNestStatement(r)}else e.sampleStatement()?this.notAllowed(e,"Sample statements"):e.timezoneStatement()?this.notAllowed(e,"Timezone statements"):(e.queryAnnotation()||e.ignoredModelAnnotations())&&this.notAllowed(e,"Detached annotation statements");return null}getFieldPath(e){const r=e.fieldName().map(o=>(0,Hx.getId)(o)),i=r[r.length-1],s=r.slice(0,-1);return{name:i,path:s.length>0?s:void 0}}getTimeframe(e){const r=e.text;return(0,d2t.isTimestampUnit)(r)?r:(this.illegal(e,`Invalid timeframe ${r}`),null)}getQueryField(e){if(e.taggedRef()){const r=e.taggedRef(),i=this.getAnnotations(r.tags()),{name:s,path:o}=this.getFieldPath(r.fieldPath());if(r.refExpr()){const u=r.refExpr();if(u.timeframe()){const a=this.getTimeframe(u.timeframe());return a===null?null:{name:void 0,field:{annotations:i,expression:{kind:"time_truncation",field_reference:{name:s,path:o},truncation:a}}}}else u.aggregate()&&this.notAllowed(u,"Aggregate expressions")}else return{name:void 0,field:{annotations:i,expression:{kind:"field_reference",name:s,path:o}}}}else if(e.fieldDef()){const r=e.fieldDef(),i=this.getAnnotations(r.tags()),s=this.getIsAnnotations(r.isDefine()),o=(0,Hx.getId)(r.fieldNameDef()),u=this.getFieldExpression(r.fieldExpr());return u===null?null:{name:o,field:{expression:u,annotations:this.combineAnnotations(i,s)}}}return null}getFieldExpression(e){if(e instanceof _t.ExprFieldPathContext){const{name:r,path:i}=this.getFieldPath(e.fieldPath());return{kind:"field_reference",name:r,path:i}}else if(e instanceof _t.ExprTimeTruncContext){const r=this.getTimeframe(e.timeframe()),i=e.fieldExpr(),s=this.getFieldExpression(i);return s===null||r===null?null:s.kind!=="field_reference"?(this.illegal(i,"Left hand side of time truncation must be a field reference"),null):{kind:"time_truncation",truncation:r,field_reference:{name:s.name,path:s.path,parameters:s.parameters}}}else if(e instanceof _t.ExprFieldPropsContext){const r=e.fieldExpr(),i=this.getFieldExpression(r);if(i===null)return null;if(i.kind!=="field_reference")return this.illegal(r,"Left hand side of filtered field must be a field reference"),null;const s=e.fieldProperties().fieldPropertyStatement(),o=[];for(const u of s){const a=u.whereStatement();if(a){const l=this.getWhere(a);if(l===null)return null;o.push(...l)}}return{kind:"filtered_field",field_reference:{name:i.name,path:i.path,parameters:i.parameters},where:o}}else{const r=this.getLiteralIncludingNegativeNumber(e);return r===null?null:{kind:"literal_value",literal_value:r}}}stripQuote(e,r){return e.slice(e.indexOf(r)+r.length,e.lastIndexOf(r))}getFilterString(e){const r=e.tripFilterString(),i=e.tickFilterString();if(r){const s=r.BQ3_FILTER(),o=r.DQ3_FILTER(),u=r.SQ3_FILTER();if(s)return this.stripQuote(s.text,"```");if(o)return this.stripQuote(o.text,'"""');if(u)return this.stripQuote(u.text,"'''")}else if(i){const s=i.BQ_FILTER(),o=i.DQ_FILTER(),u=i.SQ_FILTER();if(s)return this.stripQuote(s.text,"`");if(o)return this.stripQuote(o.text,'"');if(u)return this.stripQuote(u.text,"'")}return null}getFilterExpr(e){if(e instanceof _t.ExprCompareContext){if(e.compareOp().MATCH()){const r=e.fieldExpr()[0],i=e.fieldExpr()[1];if(r instanceof _t.ExprFieldPathContext&&i instanceof _t.ExprLiteralContext){const{path:s,name:o}=this.getFieldPath(r.fieldPath()),u=i.literal();if(u instanceof _t.FilterString_stubContext){const a=this.getFilterString(u.filterString());return a===null?null:{filter:{kind:"filter_string",field_reference:{name:o,path:s},filter:a}}}}}else if(e.compareOp().EQ()){const r=e.fieldExpr()[0],i=e.fieldExpr()[1];if(r instanceof _t.ExprFieldPathContext){const{path:s,name:o}=this.getFieldPath(r.fieldPath()),u=this.getLiteralIncludingNegativeNumber(i);return u===null?(this.notAllowed(e,"Filters other than comparisons with filter strings or equality with literals"),null):{filter:{kind:"literal_equality",field_reference:{name:o,path:s},value:u}}}}}return this.notAllowed(e,"Filters other than comparisons with filter strings or equality with literals"),null}getTimeLiteral(e,r){const i=r(e.text);if(!i)return this.contextError(e,"failed-to-parse-time-literal","Time data parse error"),null;const s=i.getValue(),o=s.timeframe;if(s.value.node!=="timeLiteral")return null;const u=s.value.literal,a=s.value.timezone;return s.type==="timestamp"?{kind:"timestamp_literal",timestamp_value:u,granularity:o,timezone:a}:o==="hour"||o==="minute"||o==="second"?null:{kind:"date_literal",date_value:u,granularity:o,timezone:a}}getLiteralIncludingNegativeNumber(e){if(e instanceof _t.ExprLiteralContext)return this.getLiteral(e.literal());if(e instanceof _t.ExprMinusContext){const r=e.fieldExpr();if(r instanceof _t.ExprLiteralContext){const i=this.getLiteral(r.literal());return i===null||i.kind!=="number_literal"?null:{kind:"number_literal",number_value:-i.number_value}}}return null}getLiteral(e){if(e instanceof _t.ExprTimeContext){const r=e.dateLiteral();return r instanceof _t.LiteralTimestampContext?this.getTimeLiteral(r,Qx.LiteralTimestamp.parse):r instanceof _t.LiteralHourContext?this.getTimeLiteral(r,Qx.LiteralHour.parse):r instanceof _t.LiteralDayContext?this.getTimeLiteral(r,Qx.LiteralDay.parse):r instanceof _t.LiteralWeekContext?this.getTimeLiteral(r,Qx.LiteralWeek.parse):r instanceof _t.LiteralMonthContext?this.getTimeLiteral(r,Qx.LiteralMonth.parse):r instanceof _t.LiteralQuarterContext?this.getTimeLiteral(r,Qx.LiteralQuarter.parse):r instanceof _t.LiteralYearContext?this.getTimeLiteral(r,Qx.LiteralYear.parse):null}else{if(e instanceof _t.ExprArrayLiteralContext)return this.notAllowed(e,"array literals"),null;if(e instanceof _t.ExprLiteralRecordContext)return this.notAllowed(e,"record literals"),null;if(e instanceof _t.ExprStringContext){const[r,i]=(0,Hx.getPlainString)(e);for(const s of i)s instanceof c2t.ParserRuleContext&&this.contextError(s,"illegal-query-interpolation-outside-sql-block","%{ query } illegal in this string");return{kind:"string_literal",string_value:r??""}}else{if(e instanceof _t.ExprBoolContext)return{kind:"boolean_literal",boolean_value:e.TRUE()!==null};if(e instanceof _t.ExprNumberContext)return{kind:"number_literal",number_value:Number(e.text)};if(e instanceof _t.ExprNULLContext)return{kind:"null_literal"}}}return null}getDrill(e){const i=e.drillClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}getWhere(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}getHaving(e){const i=e.filterClauseList().fieldExpr().map(s=>this.getFilterExpr(s));return i.some(s=>s===null)?null:i}combineAnnotations(...e){const r=e.flatMap(i=>i??[]);return r.length>0?r:void 0}}bv.MalloyToQuery=The;function p2t(t){const e=(0,bhe.getSourceInfo)(t),r=new Che.BaseMessageLogger(null),i="internal://query.malloy",s=(0,x2t.runMalloyParser)(t,i,e,r),u=new The(s,r).visit(s.root),a=(0,h2t.mapLogs)(r.getLog(),i);if(u===null)return{logs:a};if(!("definition"in u))throw new Error("Expected a query");return{query:u,logs:a}}(function(t){Object.defineProperty(t,"__esModule",{value:!0}),t.malloyToQuery=t.exploreQueryWalkerBuilder=t.MalloyTranslation=t.MalloyTranslator=void 0;var e=nf;Object.defineProperty(t,"MalloyTranslator",{enumerable:!0,get:function(){return e.MalloyTranslator}}),Object.defineProperty(t,"MalloyTranslation",{enumerable:!0,get:function(){return e.MalloyTranslation}});var r=Cv;Object.defineProperty(t,"exploreQueryWalkerBuilder",{enumerable:!0,get:function(){return r.exploreQueryWalkerBuilder}});var i=bv;Object.defineProperty(t,"malloyToQuery",{enumerable:!0,get:function(){return i.malloyToQuery}})})(dT);var Le={},jD={};Object.defineProperty(jD,"__esModule",{value:!0}),jD.MALLOY_VERSION=void 0,jD.MALLOY_VERSION="0.0.291",Object.defineProperty(Le,"__esModule",{value:!0}),Le.InMemoryModelCache=Le.CacheManager=Le.CSVWriter=Le.JSONWriter=Le.DataWriter=Le.DataRecord=Le.DataArray=Le.Result=Le.ExploreMaterializer=Le.PreparedResultMaterializer=Le.QueryMaterializer=Le.ModelMaterializer=Le.SingleConnectionRuntime=Le.ConnectionRuntime=Le.Runtime=Le.ExploreField=Le.JoinRelationship=Le.QueryField=Le.Query=Le.StringField=Le.UnsupportedField=Le.JSONField=Le.BooleanField=Le.NumberField=Le.TimestampField=Le.DateField=Le.TimestampTimeframe=Le.DateTimeframe=Le.AtomicField=Le.AtomicFieldType=Le.Explore=Le.SourceRelationship=Le.FixedConnectionMap=Le.InMemoryURLReader=Le.EmptyURLReader=Le.PreparedResult=Le.DocumentCompletion=Le.DocumentSymbol=Le.DocumentPosition=Le.DocumentRange=Le.DocumentTablePath=Le.Parse=Le.PreparedQuery=Le.Model=Le.MalloyError=Le.Malloy=void 0;const Rhe=dT,Nr=pi,Dhe=_E,Oj=A2,m2t=jD,g2t=C2,Mn=Ws,y2t=Bx,E2t=Ji,v2t=mv;function _2t(t){return t.type==="table"||t.type==="sql_select"||t.type==="query_source"}const Ohe="internal://internal.malloy";let R0=class ZO{static get version(){return m2t.MALLOY_VERSION}static _parse(e,r,i,s,o){r===void 0&&(r=new URL(Ohe));let u=r;s!=null&&s.importBaseURL&&(u=s==null?void 0:s.importBaseURL);const a=new Rhe.MalloyTranslator(r.toString(),u.toString(),{urls:{[r.toString()]:e}},i);return s!=null&&s.testEnvironment&&(a.allDialectsEnabled=!0),new Fhe(a,o)}static parse({url:e,urlReader:r,source:i,eventStream:s,options:o}){if(i!==void 0)return ZO._parse(i,e,s,o);if(r===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 VD(r,e).then(({contents:u,invalidationKey:a})=>ZO._parse(u,e,s,o,a))}static async compile({url:e,source:r,parse:i,urlReader:s,connections:o,model:u,refreshSchemaCache:a,noThrowOnError:l,eventStream:c,importBaseURL:f,cacheManager:d}){var x,p,m,g,y;let E;if(a&&(E=typeof a=="number"?a:Date.now()),e===void 0&&r===void 0&&i===void 0)throw new Error("Internal Error: url, source, or parse required.");e===void 0&&(i!==void 0?e=new URL(i._translator.sourceURL):e=new URL(Ohe));const v={};if(r===void 0&&d!==void 0){const S=await d.getCachedModelDef(s,e.toString());if(S)return new h1(S.modelDef,[],[e.toString(),...WD(S.modelDef.dependencies)])}f??(f=e);let _;const A=e.toString();if(i!==void 0){_=i._translator;const S=(x=i._invalidationKey)!==null&&x!==void 0?x:await qj(s,e);v[A]=S}else{if(r===void 0){const{contents:S,invalidationKey:b}=await VD(s,e);v[A]=b,r=S}else{const S=await qj(s,e);v[A]=S}_=new Rhe.MalloyTranslator(A,f.toString(),{urls:{[A]:r}},c)}for(;;){const S=_.translate(u==null?void 0:u._modelDef);if(S.final)if(S.modelDef){await(d==null?void 0:d.setCachedModelDef(e.toString(),{modelDef:S.modelDef,invalidationKeys:v}));for(const b of _.newlyTranslatedDependencies())await(d==null?void 0:d.setCachedModelDef(b.url,{modelDef:b.modelDef,invalidationKeys:v}));return new h1(S.modelDef,S.problems||[],[...(p=u==null?void 0:u.fromSources)!==null&&p!==void 0?p:[],...(m=S.fromSources)!==null&&m!==void 0?m:[]])}else if(l){const b={name:"modelDidNotCompile",exports:[],contents:{},dependencies:{},queryList:[]},C=(u==null?void 0:u._modelDef)||b;return new h1(C,S.problems||[],[...(g=u==null?void 0:u.fromSources)!==null&&g!==void 0?g:[],...(y=S.fromSources)!==null&&y!==void 0?y:[]])}else{const b=S.problems||[],C=_.prettyErrors();throw new whe(`Error(s) compiling model:
|
|
1394
1394
|
${C}`,b)}else{if(S.urls)for(const C of S.urls)try{if(YD(C))throw new Error("In order to use relative imports, you must compile a file via a URL.");if(d!==void 0){const D=await d.getCachedModelDef(s,C);if(D){for(const B in D.invalidationKeys)v[B]=D.invalidationKeys[B];_.update({translations:{[C]:D.modelDef}});continue}}const{contents:R,invalidationKey:O}=await VD(s,new URL(C)),k={[C]:R};v[C]=O,_.update({urls:k})}catch(R){_.update({errors:{urls:{[C]:R.message}}})}const{modelAnnotation:b}=_.modelAnnotation(u==null?void 0:u._modelDef);if(S.tables){const C=new Map;for(const R in S.tables){const{connectionName:O,tablePath:k}=S.tables[R],D=C.get(O);D===void 0?C.set(O,{[R]:k}):D[R]=k}for(const[R,O]of C)try{const k=await o.lookupConnection(R),{schemas:D,errors:B}=await ZO.safelyFetchTableSchema(k,O,{refreshTimestamp:E,modelAnnotation:b});_.update({tables:D,errors:{tables:B}})}catch(k){const D={},B={};for(const P in O)B[P]=k.toString();_.update({tables:D,errors:{tables:B}})}}if(S.compileSQL){const C=S.compileSQL,R=C.connection,O=(0,y2t.sqlKey)(C.connection,C.selectStr);try{const D=await(await o.lookupConnection(R)).fetchSchemaForSQLStruct(C,{refreshTimestamp:E,modelAnnotation:b});D.error&&_.update({errors:{compileSQL:{[O]:D.error}}}),D.structDef&&_.update({compileSQL:{[O]:D.structDef}})}catch(k){const D={};D[O]=k.toString(),_.update({errors:{compileSQL:D}})}}}}}static async safelyFetchTableSchema(e,r,i){const s=await e.fetchSchemaForTables(r,i);for(const o of Object.keys(r))if(s.schemas[o]===void 0&&s.errors[o]===void 0)throw new Error(`Schema fetch error for ${e.name}, no response for ${o} from ${e.dialectName}`);return s}static async run({connections:e,preparedResult:r,sqlStruct:i,connection:s,options:o}){if(!s){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const u=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName);s=await e.lookupConnection(u)}if(i){const u=await s.runSQL(i.selectStr);return new Ov({structs:[i],sql:i.selectStr,result:u.rows,totalRows:u.totalRows,runStats:u.runStats,lastStageName:i.name,malloy:"",connectionName:i.connection,sourceExplore:"",sourceFilters:[],profilingUrl:u.profilingUrl},{name:"empty_model",exports:[],contents:{},queryList:[],dependencies:{}})}else if(r){const u=await s.runSQL(r.sql,o);return new Ov({...r._rawQuery,result:u.rows,totalRows:u.totalRows,runStats:u.runStats,profilingUrl:u.profilingUrl},r._modelDef)}else throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}static async*runStream({connections:e,preparedResult:r,sqlStruct:i,connection:s,options:o}){if(i===void 0&&r===void 0)throw new Error("Internal error: sqlBlock or preparedResult must be provided.");const u=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName);if(s===void 0){if(e===void 0)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");s=await e.lookupConnection(u)}if(!s.canStream())throw new Error(`Connection '${u}' cannot stream results.`);let a,l;if(i)l=new Xs(i),a=i.selectStr;else if(r!==void 0)l=r.resultExplore,a=r.sql;else throw new Error("Internal error: sqlStruct or preparedResult must be provided.");let c=0;for await(const f of s.runSQLStream(a,o))yield new Vx(f,c,l,void 0,void 0),c+=1}static async estimateQueryCost({connections:e,preparedResult:r,sqlStruct:i}){if(!e)throw new Error("Internal Error: Connection or LookupConnection<Connection> must be provided.");const s=(i==null?void 0:i.connection)||(r==null?void 0:r.connectionName),o=await e.lookupConnection(s);if(i)return await o.estimateQueryCost(i.selectStr);if(r)return await o.estimateQueryCost(r.sql);throw new Error("Internal error: sqlStruct or preparedResult must be provided.")}};Le.Malloy=R0;class whe extends Error{constructor(e,r=[]){super(e),this.problems=r}}Le.MalloyError=whe;class h1{constructor(e,r,i){var s,o;this.modelDef=e,this.problems=r,this.fromSources=i,this.references=new v2t.ReferenceList((s=i[0])!==null&&s!==void 0?s:"",(o=e.references)!==null&&o!==void 0?o:[])}tagParse(e){return(0,Mn.annotationToTag)(this.modelDef.annotation,e)}getTaglines(e){return(0,Mn.annotationToTaglines)(this.modelDef.annotation,e)}getReference(e){return this.references.find(e)}getImport(e){var r;return(r=this.modelDef.imports)===null||r===void 0?void 0:r.find(i=>(0,E2t.locationContainsPosition)(i.location,e))}getPreparedQueryByName(e){const r=this.modelDef.contents[e];if((r==null?void 0:r.type)==="query")return new Gx(r,this.modelDef,this.problems,e);throw new Error("Given query name does not refer to a named query.")}getPreparedQueryByIndex(e){if(e<0)throw new Error(`Invalid index ${e}.`);if(e>=this.modelDef.queryList.length)throw new Error(`Query index ${e} is out of bounds.`);return new Gx(this.modelDef.queryList[e],this.modelDef,this.problems)}get preparedQuery(){return this.getPreparedQuery()}getPreparedQuery(){if(this.modelDef.queryList.length===0)throw new Error("Model has no queries.");return new Gx(this.modelDef.queryList[this.modelDef.queryList.length-1],this.modelDef,this.problems)}getExploreByName(e){const r=this.modelDef.contents[e];if(r&&(0,Nr.isSourceDef)(r))return new Xs(r);throw new Error("'name' is not an explore")}get explores(){return Object.values(this.modelDef.contents).filter(Nr.isSourceDef).map(e=>new Xs(e))}get namedQueries(){const e=r=>r.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}}Le.Model=h1;class Gx{constructor(e,r,i,s){this.problems=i,this.name=s,this._query=e,this._modelDef=r}tagParse(e){const r=(0,Mn.annotationToTag)(this._modelDef.annotation).tag;return e=(0,Mn.addModelScope)(e,r),(0,Mn.annotationToTag)(this._query.annotation,e)}getTaglines(e){return(0,Mn.annotationToTaglines)(this._query.annotation,e)}get preparedResult(){return this.getPreparedResult()}getPreparedResult(e){const i=new Nr.QueryModel(this._modelDef,e==null?void 0:e.eventStream).compileQuery(this._query,e);return new Rv({...i,queryName:this.name||i.queryName},this._modelDef)}get dialect(){const e=this._query.structRef,r=typeof e=="string"?this._modelDef.contents[e]:e;if(!(0,Nr.isSourceDef)(r))throw new Error("Invalid source for query");return r.dialect}getFlattenedQuery(e){return this}}Le.PreparedQuery=Gx;class Fhe{constructor(e,r){this.translator=e,this.invalidationKey=r}get symbols(){return(this.translator.metadata().symbols||[]).map(e=>new UD(e))}get tablePathInfo(){var e;return((e=this.translator.tablePathInfo().pathInfo)!==null&&e!==void 0?e:[]).map(i=>new Nhe(i))}get _translator(){return this.translator}get _invalidationKey(){return this.invalidationKey}completions(e){return(this.translator.completions(e).completions||[]).map(r=>new Lhe(r))}helpContext(e){return this.translator.helpContext(e).helpContext}}Le.Parse=Fhe;class Nhe{constructor(e){this._range=p1.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}}Le.DocumentTablePath=Nhe;class p1{constructor(e,r){this._start=e,this._end=r}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 p1(new wj(e.start.line,e.start.character),new wj(e.end.line,e.end.character))}}Le.DocumentRange=p1;class wj{constructor(e,r){this._line=e,this._character=r}get line(){return this._line}get character(){return this._character}toJSON(){return{line:this.line,character:this.character}}}Le.DocumentPosition=wj;class UD{constructor(e){this._range=p1.fromJSON(e.range),this._lensRange=e.lensRange?p1.fromJSON(e.lensRange):void 0,this._type=e.type,this._name=e.name,this._children=e.children.map(r=>new UD(r))}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}}Le.DocumentSymbol=UD;class Lhe{constructor(e){this.type=e.type,this.text=e.text}}Le.DocumentCompletion=Lhe;class Rv{constructor(e,r){this.modelDef=r,this.inner=e}static fromJson({query:e,modelDef:r}){if(!e||!r)throw new Error("Missing required properties in JSON data");return new Rv(e,r)}tagParse(e){const r=(0,Mn.annotationToTag)(this.modelDef.annotation).tag;return e=(0,Mn.addModelScope)(e,r),(0,Mn.annotationToTag)(this.inner.annotation,e)}getTaglines(e){return(0,Mn.annotationToTaglines)(this.inner.annotation,e)}get annotation(){return this.inner.annotation}get modelAnnotation(){return this.modelDef.annotation}get modelTag(){return(0,Mn.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],r={...e,annotation:this.inner.annotation,name:this.inner.queryName||e.name};try{return new Xs(r,this.sourceExplore)}catch{return new Xs(r)}}get sourceExplore(){const e=this.inner.sourceExplore,r=this.modelDef.contents[e];if(r&&(0,Nr.isSourceDef)(r))return new Xs(r)}get _sourceExploreName(){return this.inner.sourceExplore}get _sourceArguments(){return this.inner.sourceArguments}get _sourceFilters(){return this.inner.sourceFilters||[]}}Le.PreparedResult=Rv;class Ihe{async readURL(e){throw new Error("No files.")}async getInvalidationKey(e){throw new Error("No files.")}}Le.EmptyURLReader=Ihe;class A2t{constructor(e){this.files=e}async readURL(e){const r=this.files.get(e.toString());if(r!==void 0)return Promise.resolve({contents:r,invalidationKey:this.invalidationKey(e,r)});throw new Error(`File not found '${e}'`)}async getInvalidationKey(e){const r=this.files.get(e.toString());if(r!==void 0)return Promise.resolve(this.invalidationKey(e,r));throw new Error(`File not found '${e}'`)}invalidationKey(e,r){return YD(e.toString())?null:Yhe(r)}}Le.InMemoryURLReader=A2t;class qD{constructor(e,r){this.connections=e,this.defaultConnectionName=r}async getConnection(e){if(e===void 0)if(this.defaultConnectionName!==void 0)e=this.defaultConnectionName;else throw new Error("No default connection.");const r=this.connections.get(e);if(r!==void 0)return Promise.resolve(r);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 qD(new Map(e.map(r=>[r.name,r])))}}Le.FixedConnectionMap=qD;var $he;(function(t){t.Nested="nested",t.BaseTable="base_table",t.Cross="cross",t.One="one",t.Many="many",t.Inline="inline"})($he||(Le.SourceRelationship=$he={}));class Fj{constructor(e,r,i){this._name=e,this._parent=r,this._source=i}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 r=this._parent;for(;r;)e.unshift(r.name),r=r._parent;return e}hasParentExplore(){return this._parent!==void 0}isExplore(){return this instanceof Xs}isQuery(){return this instanceof Mj}}class Xs extends Fj{constructor(e,r,i){super(e.as||e.name,r,i),this._structDef=e,this._parentExplore=r,this.sourceExplore=i}get source(){return this.sourceExplore}isIntrinsic(){return(0,Nr.isAtomicFieldType)(this._structDef.type)?!("e"in this._structDef):!1}isExploreField(){return!1}tagParse(e){return(0,Mn.annotationToTag)(this._structDef.annotation,e)}getTaglines(e){return(0,Mn.annotationToTaglines)(this._structDef.annotation,e)}get modelTag(){return this.parsedModelTag||(this.parsedModelTag=(0,Mn.annotationToTag)(this._structDef.modelAnnotation).tag),this.parsedModelTag}get name(){return this.structDef.as||this.structDef.name}getQueryByName(e){const r=this.sourceStructDef;if(!r)throw new Error(`Cannot get query by name from a struct of type ${this.structDef.type}`);const i={type:"query",structRef:r,pipeline:[{type:"reduce",queryFields:[{type:"fieldref",path:[e]}]}]};return new Gx(i,this.modelDef,[],e)}get modelDef(){if(!(0,Nr.isSourceDef)(this.structDef))throw new Error(`Cannot create pseudo model for struct type ${this.structDef.type}`);return{name:"generated_model",exports:[],contents:{[this.structDef.name]:this.structDef},queryList:[],dependencies:{}}}getSingleExploreModel(){return new h1(this.modelDef,[],[])}get fieldMap(){var e;if(this._fieldMap===void 0){const r=((e=this.source)===null||e===void 0?void 0:e.fieldMap)||new Map;this._fieldMap=new Map(this.structDef.fields.map(i=>{const s=i.as||i.name,o=r.get(i.name);if((0,Nr.isJoined)(i))return[s,new Pj(i,this,o)];if(i.type==="turtle")return[s,new Mj(i,this,o)];if(i.type==="string")return[s,new kj(i,this,o)];if(i.type==="number")return[s,new zD(i,this,o)];if(i.type==="date")return i.timeframe&&["day_of_month","day_of_week","day_of_year"].includes(i.timeframe)?[s,new zD({...i,type:"number"},this,o)]:[s,new Nj(i,this,o)];if(i.type==="timestamp")return[s,new Lj(i,this,o)];if(i.type==="boolean")return[s,new Ij(i,this,o)];if(i.type==="json")return[s,new $j(i,this,o)];if(i.type==="sql native")return[s,new Bj(i,this,o)]}))}return this._fieldMap}get allFields(){return[...this.fieldMap.values()]}get allFieldsWithOrder(){var e,r,i;if(!this._allFieldsWithOrder){const s=[...((i=(r=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||r===void 0?void 0:r.orderBy)===null||i===void 0?void 0:i.map(u=>{if(typeof u.field=="string")return{field:this.fieldMap.get(u.field),dir:u.dir};throw new Error("Does not support mapping order by from number.")}))||[]],o=new Set(s.map(u=>u.field.name));this._allFieldsWithOrder=[...s,...this.allFields.filter(u=>!o.has(u.name)).map(u=>({field:u,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 r=this.fieldMap.get(e);if(r===void 0)throw new Error(`No such field ${e}.`);return r}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 Pj}get filters(){var e;return(0,Nr.isSourceDef)(this.structDef)?((e=this.structDef.resultMetadata)===null||e===void 0?void 0:e.filterList)||[]:[]}get limit(){var e,r;return(r=(e=this.sourceStructDef)===null||e===void 0?void 0:e.resultMetadata)===null||r===void 0?void 0:r.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,Nr.isSourceDef)(this.structDef))return this.structDef}toJSON(){var e,r;return{_structDef:this._structDef,sourceExplore:(e=this.sourceExplore)===null||e===void 0?void 0:e.toJSON(),_parentExplore:(r=this._parentExplore)===null||r===void 0?void 0:r.toJSON()}}static fromJSON(e){const r=e._parentExplore!==void 0?Xs.fromJSON(e._parentExplore):void 0,i=e.sourceExplore!==void 0?Xs.fromJSON(e.sourceExplore):void 0;return new Xs(e._structDef,r,i)}get location(){return this.structDef.location}collectSourceComponents(e){const r=[];if(e.type==="composite"){for(const i of e.sources)r.push(...this.collectSourceComponents(i));return r}if(_2t(e)){if(e.type==="table")r.push({type:"table",tableName:e.tablePath,sourceID:`${e.connection}:${e.tablePath}`});else if(e.type==="sql_select")r.push({type:"sql",selectStatement:e.selectStr,sourceID:`${e.connection}:${e.selectStr}`});else if(e.type==="query_source"){let i;try{i=new Gx(e.query,this.modelDef,[]).getPreparedResult().sql}catch(o){i=`-- Could not compile SQL for query ${e.query.name||"unnamed query"}: ${o instanceof Error?o.message:String(o)}`}const s=`${e.connection}:${i}`;r.push({type:"sql",selectStatement:i,sourceID:s})}}else return[];for(const i of e.fields)(0,Nr.isJoined)(i)&&r.push(...this.collectSourceComponents(i));return r}getSourceComponents(){const e={};if((0,Nr.isSourceDef)(this.structDef)){const r=this.collectSourceComponents(this.structDef);for(const i of r)e[i.sourceID]=i}return Object.values(e)}}Le.Explore=Xs;var nl;(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"})(nl||(Le.AtomicFieldType=nl={}));class Sf extends Fj{constructor(e,r,i){super(e.as||e.name,r,i),this.fieldTypeDef=e,this.parent=r}get type(){switch(this.fieldTypeDef.type){case"string":return nl.String;case"boolean":return nl.Boolean;case"date":return nl.Date;case"timestamp":return nl.Timestamp;case"number":return nl.Number;case"json":return nl.Json;case"sql native":return nl.NativeUnsupported;case"error":return nl.Error;case"record":case"array":throw new Error(`MTOY TODO IMPLEMENT Atomic ${this.fieldTypeDef.type}`);default:{const e=this.fieldTypeDef;throw new Error(`Can't make an atomic field from ${e}`)}}}tagParse(e){return e=(0,Mn.addModelScope)(e,this.parent.modelTag),(0,Mn.annotationToTag)(this.fieldTypeDef.annotation,e)}getTaglines(e){return(0,Mn.annotationToTaglines)(this.fieldTypeDef.annotation,e)}isIntrinsic(){return(0,Nr.fieldIsIntrinsic)(this.fieldTypeDef)}isQueryField(){return!1}isExploreField(){return!1}isAtomicField(){return!0}isCalculation(){return(0,Nr.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,r;return((e=this.fieldTypeDef.resultMetadata)===null||e===void 0?void 0:e.fieldKind)==="measure"||((r=this.fieldTypeDef.resultMetadata)===null||r===void 0?void 0:r.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 kj}isNumber(){return this instanceof zD}isDate(){return this instanceof Nj}isBoolean(){return this instanceof Ij}isJSON(){return this instanceof $j}isTimestamp(){return this instanceof Lj}isUnsupported(){return this instanceof Bj}get parentExplore(){return this.parent}get expression(){const e=".",r=this.fieldTypeDef.resultMetadata;return(r==null?void 0:r.sourceExpression)||(r!=null&&r.sourceField.includes(e)?r==null?void 0:r.sourceField:this.name)}get location(){return this.fieldTypeDef.location}}Le.AtomicField=Sf;var Wx;(function(t){t.Day="day",t.Week="week",t.Month="month",t.Quarter="quarter",t.Year="year"})(Wx||(Le.DateTimeframe=Wx={}));var rl;(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"})(rl||(Le.TimestampTimeframe=rl={}));let Nj=class extends Sf{constructor(e,r,i){super(e,r,i),this.fieldDateDef=e}get timeframe(){if(this.fieldDateDef.timeframe!==void 0)switch(this.fieldDateDef.timeframe){case"day":return Wx.Day;case"week":return Wx.Week;case"month":return Wx.Month;case"quarter":return Wx.Quarter;case"year":return Wx.Year}}};Le.DateField=Nj;let Lj=class extends Sf{constructor(e,r,i){super(e,r,i),this.fieldTimestampDef=e}get timeframe(){if(this.fieldTimestampDef.timeframe!==void 0)switch(this.fieldTimestampDef.timeframe){case"day":return rl.Day;case"week":return rl.Week;case"month":return rl.Month;case"quarter":return rl.Quarter;case"year":return rl.Year;case"second":return rl.Second;case"hour":return rl.Hour;case"minute":return rl.Minute}}};Le.TimestampField=Lj;let zD=class extends Sf{constructor(e,r,i){super(e,r,i),this.fieldNumberDef=e}};Le.NumberField=zD;let Ij=class extends Sf{constructor(e,r,i){super(e,r,i),this.fieldBooleanDef=e}};Le.BooleanField=Ij;let $j=class extends Sf{constructor(e,r,i){super(e,r,i),this.fieldJSONDef=e}};Le.JSONField=$j;class Bj extends Sf{constructor(e,r,i){super(e,r,i),this.fieldUnsupportedDef=e}get rawType(){return this.fieldUnsupportedDef.rawType}}Le.UnsupportedField=Bj;let kj=class extends Sf{constructor(e,r,i){super(e,r,i),this.fieldStringDef=e}};Le.StringField=kj;class Bhe extends Fj{constructor(e,r,i){super(e.as||e.name,r,i),this.turtleDef=e}get source(){return this.sourceQuery}isIntrinsic(){return!1}get location(){return this.turtleDef.location}}Le.Query=Bhe;class Mj extends Bhe{constructor(e,r,i){super(e,r,i),this.parent=r}tagParse(e){return e=(0,Mn.addModelScope)(e,this.parent.modelTag),(0,Mn.annotationToTag)(this.turtleDef.annotation,e)}getTaglines(e){return(0,Mn.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}}Le.QueryField=Mj;var m1;(function(t){t.OneToOne="one_to_one",t.OneToMany="one_to_many",t.ManyToOne="many_to_one"})(m1||(Le.JoinRelationship=m1={}));class Pj extends Xs{constructor(e,r,i){super(e,r,i),this._parentExplore=r}get joinRelationship(){if((0,Nr.isJoined)(this.structDef))switch(this.structDef.join){case"one":return m1.OneToOne;case"many":case"cross":return m1.ManyToOne}throw new Error("A source field must have a join relationship.")}get isRecord(){return this.joinRelationship===m1.OneToOne}get isArray(){return this.joinRelationship!==m1.OneToOne}tagParse(e){return e=(0,Mn.addModelScope)(e,this._parentExplore.modelTag),(0,Mn.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]:[]}}Le.ExploreField=Pj;class jj{constructor({urlReader:e,connections:r,connection:i,eventStream:s,cacheManager:o}){if(this.isTestRuntime=!1,r===void 0){if(i===void 0)throw new Error("A LookupConnection<Connection> or Connection is required.");r={lookupConnection:()=>Promise.resolve(i)}}e===void 0&&(e=new Ihe),this._urlReader=e,this._connections=r,this._eventStream=s,this._cacheManager=o}get cacheManager(){return this._cacheManager}get urlReader(){return this._urlReader}get connections(){return this._connections}get eventStream(){return this._eventStream}loadModel(e,r){const{refreshSchemaCache:i,noThrowOnError:s}=r||{};this.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0});const o=e instanceof URL?{url:e}:{source:e};return new Dv(this,async()=>R0.compile({...o,urlReader:this.urlReader,connections:this.connections,refreshSchemaCache:i,noThrowOnError:s,eventStream:this.eventStream,replaceMaterializedReferences:r==null?void 0:r.replaceMaterializedReferences,materializedTablePrefix:r==null?void 0:r.materializedTablePrefix,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,cacheManager:this.cacheManager}),r)}_loadModelFromModelDef(e,r){return new Dv(this,async()=>new h1(e,[],[]),r)}loadQuery(e,r){return this.loadModel(e,r).loadFinalQuery()}loadQueryByIndex(e,r,i){return this.loadModel(e,i).loadQueryByIndex(r,i)}loadQueryByName(e,r,i){return this.loadModel(e,i).loadQueryByName(r,i)}getModel(e,r){return this.loadModel(e,r).getModel()}getQuery(e,r){return this.loadQuery(e,r).getPreparedQuery()}getQueryByIndex(e,r,i){return this.loadQueryByIndex(e,r,i).getPreparedQuery()}getQueryByName(e,r,i){return this.loadQueryByName(e,r,i).getPreparedQuery()}}Le.Runtime=jj;class S2t extends jj{constructor({urlReader:e,connections:r}){super({connections:qD.fromArray(r),urlReader:e}),this.rawConnections=r}}Le.ConnectionRuntime=S2t;class C2t extends jj{constructor({urlReader:e,connection:r,eventStream:i,cacheManager:s}){super({urlReader:e,eventStream:i,cacheManager:s,connection:r}),this.connection=r}get supportsNesting(){return(0,Oj.getDialect)(this.connection.dialectName).supportsNesting}quote(e){return(0,Oj.getDialect)(this.connection.dialectName).sqlMaybeQuoteIdentifier(e)}get dialect(){return(0,Oj.getDialect)(this.connection.dialectName)}getQuoter(){return e=>this.quote(e.toString())}}Le.SingleConnectionRuntime=C2t;class HD{constructor(e,r){this.runtime=e,this._materialize=r}materialize(){return this.materialized===void 0?this.rematerialize():this.materialized}rematerialize(){return this.materialized=this._materialize(),this.materialized}makeQueryMaterializer(e,r){return new khe(this.runtime,e,r)}makeExploreMaterializer(e,r){return new Phe(this.runtime,e,r)}makePreparedResultMaterializer(e){return new Mhe(this.runtime,e)}}class Dv extends HD{constructor(e,r,i){super(e,r),this.runtime=e,this.compileQueryOptions=i}loadFinalQuery(e){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQuery(),{...this.compileQueryOptions,...e})}loadQueryByIndex(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByIndex(e),{...this.compileQueryOptions,...r})}loadQueryByName(e,r){return this.makeQueryMaterializer(async()=>(await this.materialize()).getPreparedQueryByName(e),{...this.compileQueryOptions,...r})}loadQuery(e,r){const{refreshSchemaCache:i,noThrowOnError:s}=r||{};return this.makeQueryMaterializer(async()=>{const o=this.runtime.urlReader,u=this.runtime.connections;this.runtime.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0});const a=e instanceof URL?{url:e}:{source:e},l=await this.getModel();return(await R0.compile({...a,urlReader:o,connections:u,model:l,refreshSchemaCache:i,noThrowOnError:s,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,...this.compileQueryOptions})).preparedQuery})}extendModel(e,r){return this.runtime.isTestRuntime&&(r===void 0?r={testEnvironment:!0}:r={...r,testEnvironment:!0}),new Dv(this.runtime,async()=>{const i=this.runtime.urlReader,s=this.runtime.connections,o=e instanceof URL?{url:e}:{source:e},u=await this.getModel();return await R0.compile({...o,urlReader:i,connections:s,model:u,refreshSchemaCache:r==null?void 0:r.refreshSchemaCache,noThrowOnError:r==null?void 0:r.noThrowOnError,importBaseURL:r==null?void 0:r.importBaseURL,testEnvironment:r==null?void 0:r.testEnvironment,...this.compileQueryOptions})},r)}async search(e,r,i=1e3,s=void 0,o){const u=await this.materialize(),a=new Nr.QueryModel(u._modelDef,o),l=u.getExploreByName(e).structDef;if(!(0,Nr.isSourceDef)(l))throw new Error("Source to be searched was unexpectedly, not a source");const c=l.connection,f=await this.runtime.connections.lookupConnection(c);return await a.searchIndex(f,e,r,i,s)}async searchValueMap(e,r=10,i){const o=(await this.materialize()).getExploreByName(e);if(!(0,Nr.isSourceDef)(o.structDef))throw new Error("Source to be searched was unexpectedly, not a source");let u="{index: *}";o.getFieldByNameIfExists("search_index")&&(u="search_index");const a=`
|
|
1395
1395
|
run: ${e}
|
|
1396
1396
|
-> ${u}
|
|
@@ -2051,7 +2051,7 @@ ${r.map(s=>` ${s}`).join(`,
|
|
|
2051
2051
|
transition: all 0s;
|
|
2052
2052
|
animation: modal-slide-in 2s forwards;
|
|
2053
2053
|
}
|
|
2054
|
-
`,L3t={name:"line_chart_series",matches:(t,e)=>t.has("line_chart")&&e===Zs.RepeatedRecord,plugin:t=>{const e="line_chart_series",r=(i,s)=>i.has("line_chart")&&s===Zs.RepeatedRecord;try{if(!t.isNest())throw new Error("Line chart: must be a nest field");const i=N2e(t),s=new Map,o=t.fieldAt(i.yChannel.fields[0]),u=i.seriesChannel.fields[0],a=u?t.fieldAt(u):null;if(!o)throw new Error("Line chart: missing a y field. Did you add an aggregation?");return{name:e,matches:r,processData:(f,d)=>{let x;if(d instanceof Hv)x=d.rows;else if(d instanceof sO)x=[d];else return;for(const p of x)if(a){const m=p.column(a.name).value??cr,g=p.column(o.name).value,y=s.get(m)??{sum:0,count:0,avg:0};y.sum+=g,y.count+=1,y.avg=y.sum/y.count,s.set(m,y)}},getTopNSeries:f=>{const d="sum";return s?Array.from(s.entries()).sort((p,m)=>m[1][d]-p[1][d]).slice(0,f).map(p=>p[0]):[]}}}catch{return{name:e,matches:r,processData:()=>{},getTopNSeries:()=>[]}}}};var I3t=Ct("<div class=malloy-copied-modal>Copied query to clipboard!"),$3t=Ct("<div class=malloy-render>");const $2e=pU(),eh=()=>{const t=mU($2e);if(!t)throw new Error("ConfigContext missing a value; did you provide a ConfigProvider?");return t};function B3t(t){N0.addStylesheet(N3t);const e=()=>Object.assign({disableVirtualization:!1,rowLimit:1/0,shouldFillWidth:!1,enableDrill:!1},t.tableConfig),r=()=>Object.assign({disableVirtualization:!1},t.dashboardConfig);return Ge(Mmt,{fallback:i=>{var s;return(s=t==null?void 0:t.onError)==null||s.call(t,i.error),Ge(SU,{get message(){return i.error.message}})},get children(){return Ge(Ir,{get when(){return t.result},get children(){return Ge($2e.Provider,{get value(){return{onClick:t.onClick,onDrill:t.onDrill,vegaConfigOverride:t.vegaConfigOverride,tableConfig:e,dashboardConfig:r,modalElement:t.modalElement}},get children(){return Ge(k3t,{get result(){return t.result},get element(){return t.element},get scrollEl(){return t.scrollEl},get vegaConfigOverride(){return t.vegaConfigOverride}})}})}})}})}const B2e=4;function k3t(t){const[e,r]=fr({width:0,height:0}),i=dr(()=>Npe(t.result,[L3t])),s=dr(()=>w3t(i().field,{getVegaConfigOverride:t.vegaConfigOverride,parentSize:{width:e().width-B2e,height:e().height-B2e}})),o=()=>{const l=i().field.modelTag,c=i().field.tag,f=l.tag("theme"),d=c.tag("theme");return{modelTag:l,resultTag:c,modelTheme:f,localTheme:d}},u=()=>M3t(o().modelTheme,o().localTheme),a=()=>{const l=i();return s(),Rf({dataColumn:l,tag:l.field.tag,customProps:{table:{scrollEl:t.scrollEl},dashboard:{scrollEl:t.scrollEl}}})};return(()=>{var l=$3t();return to(t2e,l,()=>[e,r]),nt(l,Ge(Ir,{get when(){return dr(()=>e().width>0)()&&e().height>0},get children(){return[Ge(l2e.Provider,{value:s,get children(){return a().renderValue}}),Ge(Ir,{get when(){return s().store.store.showCopiedModal},get children(){return I3t()}})]}})),Yn(c=>Tf(l,u(),c)),l})()}function qo(t,...e){let r;for(const i of e)if(r=i==null?void 0:i.text(t),typeof r<"u")break;return r??`var(--malloy-theme--${t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()})`}function M3t(t,e){const r=qo("tableRowHeight",e,t),i=qo("tableBodyColor",e,t),s=qo("tableFontSize",e,t),o=qo("tableHeaderColor",e,t),u=qo("tableHeaderWeight",e,t),a=qo("tableBodyWeight",e,t),l=qo("tableBorder",e,t),c=qo("tableBackground",e,t),f=qo("tableGutterSize",e,t),d=qo("tablePinnedBackground",e,t),x=qo("tablePinnedBorder",e,t),p=qo("fontFamily",e,t);return`
|
|
2054
|
+
`,L3t={name:"line_chart_series",matches:(t,e)=>(t.has("line_chart")||t.text("viz")==="line")&&e===Zs.RepeatedRecord,plugin:t=>{const e="line_chart_series",r=(i,s)=>(i.has("line_chart")||i.text("viz")==="line")&&s===Zs.RepeatedRecord;try{if(!t.isNest())throw new Error("Line chart: must be a nest field");const i=N2e(t),s=new Map,o=t.fieldAt(i.yChannel.fields[0]),u=i.seriesChannel.fields[0],a=u?t.fieldAt(u):null;if(!o)throw new Error("Line chart: missing a y field. Did you add an aggregation?");return{name:e,matches:r,processData:(f,d)=>{let x;if(d instanceof Hv)x=d.rows;else if(d instanceof sO)x=[d];else return;for(const p of x)if(a){const m=p.column(a.name).value??cr,g=p.column(o.name).value,y=s.get(m)??{sum:0,count:0,avg:0};y.sum+=g,y.count+=1,y.avg=y.sum/y.count,s.set(m,y)}},getTopNSeries:f=>{const d="sum";return s?Array.from(s.entries()).sort((p,m)=>m[1][d]-p[1][d]).slice(0,f).map(p=>p[0]):[]}}}catch{return{name:e,matches:r,processData:()=>{},getTopNSeries:()=>[]}}}};var I3t=Ct("<div class=malloy-copied-modal>Copied query to clipboard!"),$3t=Ct("<div class=malloy-render>");const $2e=pU(),eh=()=>{const t=mU($2e);if(!t)throw new Error("ConfigContext missing a value; did you provide a ConfigProvider?");return t};function B3t(t){N0.addStylesheet(N3t);const e=()=>Object.assign({disableVirtualization:!1,rowLimit:1/0,shouldFillWidth:!1,enableDrill:!1},t.tableConfig),r=()=>Object.assign({disableVirtualization:!1},t.dashboardConfig);return Ge(Mmt,{fallback:i=>{var s;return(s=t==null?void 0:t.onError)==null||s.call(t,i.error),Ge(SU,{get message(){return i.error.message}})},get children(){return Ge(Ir,{get when(){return t.result},get children(){return Ge($2e.Provider,{get value(){return{onClick:t.onClick,onDrill:t.onDrill,vegaConfigOverride:t.vegaConfigOverride,tableConfig:e,dashboardConfig:r,modalElement:t.modalElement}},get children(){return Ge(k3t,{get result(){return t.result},get element(){return t.element},get scrollEl(){return t.scrollEl},get vegaConfigOverride(){return t.vegaConfigOverride}})}})}})}})}const B2e=4;function k3t(t){const[e,r]=fr({width:0,height:0}),i=dr(()=>Npe(t.result,[L3t])),s=dr(()=>w3t(i().field,{getVegaConfigOverride:t.vegaConfigOverride,parentSize:{width:e().width-B2e,height:e().height-B2e}})),o=()=>{const l=i().field.modelTag,c=i().field.tag,f=l.tag("theme"),d=c.tag("theme");return{modelTag:l,resultTag:c,modelTheme:f,localTheme:d}},u=()=>M3t(o().modelTheme,o().localTheme),a=()=>{const l=i();return s(),Rf({dataColumn:l,tag:l.field.tag,customProps:{table:{scrollEl:t.scrollEl},dashboard:{scrollEl:t.scrollEl}}})};return(()=>{var l=$3t();return to(t2e,l,()=>[e,r]),nt(l,Ge(Ir,{get when(){return dr(()=>e().width>0)()&&e().height>0},get children(){return[Ge(l2e.Provider,{value:s,get children(){return a().renderValue}}),Ge(Ir,{get when(){return s().store.store.showCopiedModal},get children(){return I3t()}})]}})),Yn(c=>Tf(l,u(),c)),l})()}function qo(t,...e){let r;for(const i of e)if(r=i==null?void 0:i.text(t),typeof r<"u")break;return r??`var(--malloy-theme--${t.replace(/([a-z])([A-Z])/g,"$1-$2").toLowerCase()})`}function M3t(t,e){const r=qo("tableRowHeight",e,t),i=qo("tableBodyColor",e,t),s=qo("tableFontSize",e,t),o=qo("tableHeaderColor",e,t),u=qo("tableHeaderWeight",e,t),a=qo("tableBodyWeight",e,t),l=qo("tableBorder",e,t),c=qo("tableBackground",e,t),f=qo("tableGutterSize",e,t),d=qo("tablePinnedBackground",e,t),x=qo("tablePinnedBorder",e,t),p=qo("fontFamily",e,t);return`
|
|
2055
2055
|
--malloy-render--table-row-height: ${r};
|
|
2056
2056
|
--malloy-render--table-body-color: ${i};
|
|
2057
2057
|
--malloy-render--table-font-size: ${s};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@malloydata/render",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.291",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "dist/module/index.umd.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -31,9 +31,9 @@
|
|
|
31
31
|
"generate-flow": "ts-node ../../scripts/gen-flow.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@malloydata/malloy": "0.0.
|
|
35
|
-
"@malloydata/malloy-interfaces": "0.0.
|
|
36
|
-
"@malloydata/malloy-tag": "0.0.
|
|
34
|
+
"@malloydata/malloy": "0.0.291",
|
|
35
|
+
"@malloydata/malloy-interfaces": "0.0.291",
|
|
36
|
+
"@malloydata/malloy-tag": "0.0.291",
|
|
37
37
|
"@tanstack/solid-virtual": "^3.10.4",
|
|
38
38
|
"lodash": "^4.17.20",
|
|
39
39
|
"luxon": "^2.4.0",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"vega-lite": "^5.2.0"
|
|
45
45
|
},
|
|
46
46
|
"devDependencies": {
|
|
47
|
-
"@malloydata/db-duckdb": "0.0.
|
|
47
|
+
"@malloydata/db-duckdb": "0.0.291",
|
|
48
48
|
"@storybook/addon-essentials": "^8.5.8",
|
|
49
49
|
"@storybook/addon-interactions": "^8.5.8",
|
|
50
50
|
"@storybook/addon-links": "^8.5.8",
|