@malloydata/render 0.0.189-dev240924171744 → 0.0.189-dev240925161023
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/component/{chart.d.ts → chart/chart.d.ts} +1 -1
- package/dist/component/chart/default-chart-tooltip.d.ts +4 -0
- package/dist/component/tooltip/tooltip.d.ts +6 -0
- package/dist/component/types.d.ts +8 -0
- package/dist/component/vega/vega-chart.d.ts +3 -0
- package/dist/module/index.mjs +6 -2
- package/dist/module/index.umd.js +1 -1
- package/dist/register/register.mjs +16757 -16608
- package/dist/register/register.umd.js +252 -252
- package/dist/register/style.css +1 -1
- package/dist/webcomponent/malloy-render.mjs +16757 -16608
- package/dist/webcomponent/malloy-render.umd.js +252 -252
- package/dist/webcomponent/style.css +1 -1
- package/package.json +2 -2
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
/// <reference path="../../src/vega.d.ts" />
|
|
1
2
|
import { DataColumn, Explore, Field, QueryData, Tag } from '@malloydata/malloy';
|
|
3
|
+
import { Item } from 'vega';
|
|
2
4
|
export type VegaSpec = any;
|
|
3
5
|
export type VegaChartProps = {
|
|
4
6
|
spec: VegaSpec;
|
|
@@ -8,6 +10,7 @@ export type VegaChartProps = {
|
|
|
8
10
|
totalWidth: number;
|
|
9
11
|
totalHeight: number;
|
|
10
12
|
chartType: string;
|
|
13
|
+
getTooltipData?: (item: Item) => ChartTooltipEntry[] | null;
|
|
11
14
|
};
|
|
12
15
|
export type FieldHeaderRangeMap = Record<string, {
|
|
13
16
|
abs: [number, number];
|
|
@@ -45,3 +48,8 @@ export type MalloyClickEventPayload = {
|
|
|
45
48
|
type: 'dashboard-item' | 'table-cell';
|
|
46
49
|
};
|
|
47
50
|
export type VegaConfigHandler = (chartType: string) => Record<string, unknown> | undefined;
|
|
51
|
+
export type ChartTooltipEntry = {
|
|
52
|
+
field: Field;
|
|
53
|
+
fieldName: string;
|
|
54
|
+
value: unknown;
|
|
55
|
+
};
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
/// <reference path="../../../src/vega.d.ts" />
|
|
1
2
|
import { VegaJSON } from '../vega-types';
|
|
3
|
+
import { EventListenerHandler } from 'vega';
|
|
2
4
|
type VegaChartProps = {
|
|
3
5
|
spec: VegaJSON;
|
|
4
6
|
type: 'vega' | 'vega-lite';
|
|
5
7
|
width?: number;
|
|
6
8
|
height?: number;
|
|
9
|
+
onMouseOver?: EventListenerHandler;
|
|
7
10
|
};
|
|
8
11
|
export declare function VegaChart(props: VegaChartProps): import("solid-js").JSX.Element;
|
|
9
12
|
export {};
|
package/dist/module/index.mjs
CHANGED
|
@@ -5820,8 +5820,12 @@ class Fr extends Mz {
|
|
|
5820
5820
|
getQueryFieldReference(e, n) {
|
|
5821
5821
|
const r = this.getQueryFieldByName(e);
|
|
5822
5822
|
if (n) {
|
|
5823
|
-
|
|
5824
|
-
|
|
5823
|
+
if (r.parent === void 0)
|
|
5824
|
+
throw new Error("Expected field to have a parent");
|
|
5825
|
+
return r.parent.makeQueryField({
|
|
5826
|
+
...r.fieldDef,
|
|
5827
|
+
annotation: n
|
|
5828
|
+
});
|
|
5825
5829
|
}
|
|
5826
5830
|
return r;
|
|
5827
5831
|
}
|
package/dist/module/index.umd.js
CHANGED
|
@@ -374,7 +374,7 @@ FROM ${n}
|
|
|
374
374
|
FROM ${h}
|
|
375
375
|
`),this.resultStage}}class gce extends Es{generateSQL(e){const n=this.parent.fieldDef.structSource;if(n.type!=="sql"||n.method!=="subquery")throw new Error("Invalid struct for QueryQueryRaw, currently only supports SQL");const r=n.sqlBlock.selectStr;return e.addStage(r)}prepare(){}getResultStructDef(){return this.parent.fieldDef}getResultMetadata(e){}}class mce extends Es{constructor(e,n,r,i){super(e,n,r,i),this.stages=[],this.fieldDef=e,this.fieldsToStages()}fieldsToStages(){const e=this.firstSegment;if(this.parent.dialect.dontUnionIndex){this.stages=[e.indexFields];return}const n={};for(const r of e.indexFields){if(r.path.length>1){const i=n$(r.path.slice(0,r.path.length-1)),s=n[i];if(s===void 0){const o=this.parent.nameMap.get(r.path[0]);if(o instanceof br&&(o.fieldDef.structRelationship.type==="many"||o.fieldDef.structRelationship.type==="nested")&&o.fieldDef.fields.length>1){const u=[r];n[i]=u,this.stages.push(u);continue}}else{s.push(r);continue}}this.stages[0]===void 0&&(this.stages[0]=[]),this.stages[0].push(r)}}expandFields(e){}generateSQL(e){const n=this.firstSegment,r=[];for(const i of this.stages){const s=new pce({...this.fieldDef,pipeline:[{...n,indexFields:i}]},this.parent,e,this.isJoinedSubquery);s.prepare(e);const o=s.generateSQL(e);r.push(o)}return r.length===1?this.resultStage=r[0]:this.resultStage=e.addStage(r.map(i=>`SELECT * FROM ${i}
|
|
376
376
|
`).join(` UNION ALL
|
|
377
|
-
`)),this.resultStage}getResultStructDef(){const e={type:"struct",name:this.resultStage||"result",dialect:this.parent.fieldDef.dialect,fields:[{type:"string",name:"fieldName"},{type:"string",name:"fieldPath"},{type:"string",name:"fieldValue"},{type:"string",name:"fieldType"},{type:"number",name:"weight",numberType:"integer"}],structRelationship:{type:"basetable",connectionName:this.parent.connectionName},structSource:{type:"query_result"}};return this.parent.fieldDef.modelAnnotation&&(e.modelAnnotation=this.parent.fieldDef.modelAnnotation),e}}class br extends r${constructor(e,n,r){if(super(e),this.sourceArguments=n,this.nameMap=new Map,this._arguments=void 0,this.setParent(r),"model"in r)if(this.model=r.model,this.pathAliasMap=new Map,e.structRelationship.type==="basetable")this.connectionName=e.structRelationship.connectionName;else throw new Error("All root StructDefs should be a baseTable");else this.model=this.getModel(),this.pathAliasMap=this.root().pathAliasMap,this.connectionName=this.root().connectionName;this.fieldDef=e,this.dialect=(0,ece.getDialect)(this.fieldDef.dialect),this.addFieldsFromFieldList(this.fieldDef.fields)}resolveParentParameterReferences(e){return{...e,value:e.value===null?null:(0,an.exprMap)(e.value,n=>{if(n.node==="parameter"){if(this.parent===void 0)throw new Error("No parent from which to retrieve parameter value");const r=this.parent.arguments()[n.path[0]],i=this.parent.resolveParentParameterReferences(r);if(i.value===null)throw new Error("Invalid parameter value");return i.value}return n})}}arguments(){var e;if(this._arguments!==void 0)return this._arguments;this._arguments={};const n=(e=this.fieldDef.parameters)!==null&&e!==void 0?e:{};for(const i in n)this._arguments[i]=n[i];const r={...this.fieldDef.arguments,...this.sourceArguments};for(const i in r){const s=r[i];this._arguments[i]=this.resolveParentParameterReferences(s)}return this._arguments}addFieldsFromFieldList(e){for(const n of e){const r=(0,Ze.getIdentifier)(n);switch(n.type){case"struct":{this.addFieldToNameMap(r,new br(n,void 0,{struct:this}));break}case"turtle":{this.addFieldToNameMap(r,Es.makeQuery(n,this,void 0,!1));break}default:this.addFieldToNameMap(r,this.makeQueryField(n))}}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new lce({type:"string",name:"__distinct_key"},this))}getAliasIdentifier(){const e=this.getFullOutputName(),n=this.pathAliasMap.get(e);if(n===void 0){const r=Array.from(this.pathAliasMap.values()),i=nce((0,Ze.getIdentifier)(this.fieldDef));let s=`${i}_0`,o=1;for(;r.includes(s)&&o<1e3;)o++,s=`${i}_${o}`;if(o<1e3)return this.pathAliasMap.set(e,s),s;throw new Error("Internal Error: cannot create unique alias name")}else return n}getSQLIdentifier(){return this.unnestWithNumbers()&&this.parent!==void 0?this.parent.getSQLIdentifier()+"."+(0,Ze.getIdentifier)(this.fieldDef)+`[${this.getIdentifier()}.__row_id]`:this.getIdentifier()}getIdentifier(){return this.fieldDef.structRelationship.type==="basetable"?"base":this.fieldDef.structRelationship.type==="inline"&&this.parent?this.parent.getSQLIdentifier()+"."+super.getIdentifier():this.getAliasIdentifier()}getFullOutputName(){return this.parent?this.parent.getFullOutputName()+(0,Ze.getIdentifier)(this.fieldDef)+".":""}needsSymetricCalculation(e){const n=this.getJoinableParent().getIdentifier(),r=e.root().joins.get(n);if(r)return!r.leafiest;throw new Error(`Join ${n} not found in result set`)}unnestWithNumbers(){return this.dialect.unnestWithNumbers&&this.fieldDef.structRelationship.type==="nested"}getJoinableParent(){if(this.fieldDef.structRelationship.type==="inline"){if(this.parent)return this.parent.getJoinableParent();throw new Error("Internal Error: inline struct cannot be root")}return this}addFieldToNameMap(e,n){if(this.nameMap.has(e))throw new Error(`Redefinition of ${e}`);this.nameMap.set(e,n)}getPrimaryKeyField(e){let n;if(n=this.primaryKey())return n;throw new Error(`Missing primary key for ${e}`)}resolveQueryFields(){if(this.fieldDef.structSource.type==="query"){const e=this.model.loadQuery(this.fieldDef.structSource.query,void 0).structs.pop();if(!e)throw new Error("Internal Error, query didn't produce a struct");const n={...this.fieldDef};for(const r of e.fields){let i;this.nameMap.has(i=(0,Ze.getIdentifier)(r))||(n.fields.push(r),this.nameMap.set(i,this.makeQueryField(r)))}this.fieldDef=n,!this.fieldDef.primaryKey&&e.primaryKey&&(this.fieldDef.primaryKey=e.primaryKey)}for(const[,e]of this.nameMap)e instanceof br&&e.resolveQueryFields()}getModel(){if(this.model)return this.model;if(this.parent===void 0)throw new Error("Expected this query struct to have a parent, as no model was present.");return this.parent.getModel()}setParent(e){"struct"in e&&(this.parent=e.struct),"model"in e?this.model=e.model:this.model=this.getModel()}makeQueryField(e){switch(e.type){case"string":return new ice(e,this);case"date":return new iT(e,this);case"timestamp":return new sT(e,this);case"number":return new sce(e,this);case"boolean":return new rT(e,this);case"json":return new oce(e,this);case"sql native":return new uce(e,this);case"turtle":return new u$(e,this);default:throw new Error(`unknown field definition ${JSON.stringify(e)}`)}}structSourceSQL(e){switch(this.fieldDef.structSource.type){case"table":{const n=this.fieldDef.structSource.tablePath;return this.dialect.quoteTablePath(n)}case"sql":if(this.fieldDef.structSource.method==="nested"||this.fieldDef.structSource.method==="lastStage")return this.fieldDef.name;if(this.fieldDef.structSource.method==="subquery")return`(${this.fieldDef.structSource.sqlBlock.selectStr})`;throw new Error("Internal Error: Unknown structSource type 'sql' method");case"nested":return"UNNEST(this.fieldDef.name)";case"inline":return"";case"query":{const n=(0,Ze.getIdentifier)(this.fieldDef);if(n.includes("cache")){const r=new a2(!0,e);return this.model.loadQuery(this.fieldDef.structSource.query,r,!1,!1),r.addPDT(n,this.dialect)}else return this.model.loadQuery(this.fieldDef.structSource.query,e,!1,!0).lastStageName}default:throw new Error(`unknown structSource ${this.fieldDef}`)}}root(){return this.parent===void 0?this:this.parent.root()}primaryKey(){if(this.fieldDef.primaryKey)return this.getDimensionByName([this.fieldDef.primaryKey])}getChildByName(e){return this.nameMap.get(e)}getFieldByName(e){return e.reduce((n,r)=>{const i=n.getChildByName(r);if(i===void 0)throw new Error(e.length===1?`'${r}' not found`:`'${r}' not found in '${e.join(".")}'`);return i},this)}getQueryFieldByName(e){const n=this.getFieldByName(e);if(n instanceof br)throw new Error(`Cannot reference ${e} as a scalar'`);return n}getQueryFieldReference(e,n){const r=this.getQueryFieldByName(e);if(n){const i={...r.fieldDef};i.annotation=n,r.fieldDef=i}return r}getDimensionOrMeasureByName(e){const n=this.getFieldByName(e);if(n instanceof Cr)return n;throw new Error(`${e} is not of type a scalar'`)}getDimensionByName(e){const n=this.getFieldByName(e);if(n instanceof Cr&&cr(n))return n;throw new Error(`${e} is not of type a scalar'`)}getStructByName(e){const n=this.getFieldByName(e);if(n instanceof br)return n;throw new Error(`Error: Path to structure not found '${e.join(".")}'`)}getDistinctKey(){if(this.fieldDef.structRelationship.type!=="inline")return this.getDimensionByName(["__distinct_key"]);if(this.parent)return this.parent.getDistinctKey();throw new Error("Internal Error. inline struct can not be top level")}applyStructFiltersToTurtleDef(e){let n=e.pipeline;const r=e.annotation,i=e.filterList||[];return n=structuredClone(n),n[0].filterList=i.concat(n[0].filterList||[],this.fieldDef.filterList||[]),{type:"turtle",name:e.name,pipeline:n,annotation:r,location:e.location}}}class a${constructor(e){this.dialect=new tce.StandardSQLDialect,this.modelDef=void 0,this.structs=new Map,this.exploreSearchSQLMap=new Map,e&&this.loadModelFromDef(e)}loadModelFromDef(e){this.modelDef=e;for(const n of Object.values(this.modelDef.contents)){let r;if(n.type==="struct")r=new br(n,void 0,{model:this}),this.structs.set((0,Ze.getIdentifier)(n),r),r.resolveQueryFields();else if(n.type!=="query")throw new Error("Internal Error: Unknown structure type")}}getStructByName(e){let n;if(n=this.structs.get(e))return n;throw new Error(`Struct ${e} not found in model.`)}getStructFromRef(e,n){var r;let i;if(typeof e=="string"){const s=this.getStructByName(e);return n!==void 0?new br(s.fieldDef,n,(r=s.parent)!==null&&r!==void 0?r:{model:this}):s}else if(e.type==="struct")i=e;else throw new Error("Broken for now");return new br(i,n,{model:this})}loadQuery(e,n,r=!1,i=!1){const s="";n||(n=new a2(!0,void 0));const o={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},u=Es.makeQuery(o,this.getStructFromRef(e.structRef,e.sourceArguments),n,i),a=u.generateSQLFromPipeline(n);if(r&&u.parent.dialect.hasFinalStage){const l=(0,Ze.getPhysicalFields)(a.outputStruct).map(c=>u.parent.dialect.sqlMaybeQuoteIdentifier(c.name));a.lastStageName=n.addStage(u.parent.dialect.sqlFinalStage(a.lastStageName,l))}return{lastStageName:a.lastStageName,malloy:s,stageWriter:n,structs:[a.outputStruct],connectionName:u.parent.connectionName}}compileQuery(e,n=!0){const i=this.loadQuery(e,void 0,n,!1),s=typeof e.structRef=="string"?e.structRef:e.structRef.type==="struct"?e.structRef.as||e.structRef.name:"(need to figure this out)";return n&&this.dialect.hasFinalStage&&(i.lastStageName=i.stageWriter.addStage(this.dialect.sqlFinalStage(i.lastStageName,[]))),{lastStageName:i.lastStageName,malloy:i.malloy,sql:i.stageWriter.generateSQLStages(),structs:i.structs,sourceExplore:s,sourceFilters:e.filterList,queryName:e.name,connectionName:i.connectionName,annotation:e.annotation}}async searchIndex(e,n,r,i=1e3,s=void 0){if(!e.canPersist())return;const o=this.getStructByName(n);let u=[];for(const[y,E]of o.nameMap)E instanceof br||cr(E)&&E.includeInWildcard()&&u.push({type:"fieldref",path:[y]});u=u.sort((y,E)=>y.path[0].localeCompare(E.path[0]));const a={structRef:n,pipeline:[{type:"index",indexFields:u,sample:o.dialect.defaultSampling}]},l=o.dialect.sqlMaybeQuoteIdentifier("fieldName"),c=o.dialect.sqlMaybeQuoteIdentifier("fieldPath"),f=o.dialect.sqlMaybeQuoteIdentifier("fieldValue"),x=o.dialect.sqlMaybeQuoteIdentifier("fieldType"),h=o.dialect.sqlMaybeQuoteIdentifier("weight");let p=this.exploreSearchSQLMap.get(n);p===void 0&&(p=this.compileQuery(a,!1).sql,this.exploreSearchSQLMap.set(n,p));let m=`SELECT
|
|
377
|
+
`)),this.resultStage}getResultStructDef(){const e={type:"struct",name:this.resultStage||"result",dialect:this.parent.fieldDef.dialect,fields:[{type:"string",name:"fieldName"},{type:"string",name:"fieldPath"},{type:"string",name:"fieldValue"},{type:"string",name:"fieldType"},{type:"number",name:"weight",numberType:"integer"}],structRelationship:{type:"basetable",connectionName:this.parent.connectionName},structSource:{type:"query_result"}};return this.parent.fieldDef.modelAnnotation&&(e.modelAnnotation=this.parent.fieldDef.modelAnnotation),e}}class br extends r${constructor(e,n,r){if(super(e),this.sourceArguments=n,this.nameMap=new Map,this._arguments=void 0,this.setParent(r),"model"in r)if(this.model=r.model,this.pathAliasMap=new Map,e.structRelationship.type==="basetable")this.connectionName=e.structRelationship.connectionName;else throw new Error("All root StructDefs should be a baseTable");else this.model=this.getModel(),this.pathAliasMap=this.root().pathAliasMap,this.connectionName=this.root().connectionName;this.fieldDef=e,this.dialect=(0,ece.getDialect)(this.fieldDef.dialect),this.addFieldsFromFieldList(this.fieldDef.fields)}resolveParentParameterReferences(e){return{...e,value:e.value===null?null:(0,an.exprMap)(e.value,n=>{if(n.node==="parameter"){if(this.parent===void 0)throw new Error("No parent from which to retrieve parameter value");const r=this.parent.arguments()[n.path[0]],i=this.parent.resolveParentParameterReferences(r);if(i.value===null)throw new Error("Invalid parameter value");return i.value}return n})}}arguments(){var e;if(this._arguments!==void 0)return this._arguments;this._arguments={};const n=(e=this.fieldDef.parameters)!==null&&e!==void 0?e:{};for(const i in n)this._arguments[i]=n[i];const r={...this.fieldDef.arguments,...this.sourceArguments};for(const i in r){const s=r[i];this._arguments[i]=this.resolveParentParameterReferences(s)}return this._arguments}addFieldsFromFieldList(e){for(const n of e){const r=(0,Ze.getIdentifier)(n);switch(n.type){case"struct":{this.addFieldToNameMap(r,new br(n,void 0,{struct:this}));break}case"turtle":{this.addFieldToNameMap(r,Es.makeQuery(n,this,void 0,!1));break}default:this.addFieldToNameMap(r,this.makeQueryField(n))}}this.nameMap.has("__distinct_key")||this.addFieldToNameMap("__distinct_key",new lce({type:"string",name:"__distinct_key"},this))}getAliasIdentifier(){const e=this.getFullOutputName(),n=this.pathAliasMap.get(e);if(n===void 0){const r=Array.from(this.pathAliasMap.values()),i=nce((0,Ze.getIdentifier)(this.fieldDef));let s=`${i}_0`,o=1;for(;r.includes(s)&&o<1e3;)o++,s=`${i}_${o}`;if(o<1e3)return this.pathAliasMap.set(e,s),s;throw new Error("Internal Error: cannot create unique alias name")}else return n}getSQLIdentifier(){return this.unnestWithNumbers()&&this.parent!==void 0?this.parent.getSQLIdentifier()+"."+(0,Ze.getIdentifier)(this.fieldDef)+`[${this.getIdentifier()}.__row_id]`:this.getIdentifier()}getIdentifier(){return this.fieldDef.structRelationship.type==="basetable"?"base":this.fieldDef.structRelationship.type==="inline"&&this.parent?this.parent.getSQLIdentifier()+"."+super.getIdentifier():this.getAliasIdentifier()}getFullOutputName(){return this.parent?this.parent.getFullOutputName()+(0,Ze.getIdentifier)(this.fieldDef)+".":""}needsSymetricCalculation(e){const n=this.getJoinableParent().getIdentifier(),r=e.root().joins.get(n);if(r)return!r.leafiest;throw new Error(`Join ${n} not found in result set`)}unnestWithNumbers(){return this.dialect.unnestWithNumbers&&this.fieldDef.structRelationship.type==="nested"}getJoinableParent(){if(this.fieldDef.structRelationship.type==="inline"){if(this.parent)return this.parent.getJoinableParent();throw new Error("Internal Error: inline struct cannot be root")}return this}addFieldToNameMap(e,n){if(this.nameMap.has(e))throw new Error(`Redefinition of ${e}`);this.nameMap.set(e,n)}getPrimaryKeyField(e){let n;if(n=this.primaryKey())return n;throw new Error(`Missing primary key for ${e}`)}resolveQueryFields(){if(this.fieldDef.structSource.type==="query"){const e=this.model.loadQuery(this.fieldDef.structSource.query,void 0).structs.pop();if(!e)throw new Error("Internal Error, query didn't produce a struct");const n={...this.fieldDef};for(const r of e.fields){let i;this.nameMap.has(i=(0,Ze.getIdentifier)(r))||(n.fields.push(r),this.nameMap.set(i,this.makeQueryField(r)))}this.fieldDef=n,!this.fieldDef.primaryKey&&e.primaryKey&&(this.fieldDef.primaryKey=e.primaryKey)}for(const[,e]of this.nameMap)e instanceof br&&e.resolveQueryFields()}getModel(){if(this.model)return this.model;if(this.parent===void 0)throw new Error("Expected this query struct to have a parent, as no model was present.");return this.parent.getModel()}setParent(e){"struct"in e&&(this.parent=e.struct),"model"in e?this.model=e.model:this.model=this.getModel()}makeQueryField(e){switch(e.type){case"string":return new ice(e,this);case"date":return new iT(e,this);case"timestamp":return new sT(e,this);case"number":return new sce(e,this);case"boolean":return new rT(e,this);case"json":return new oce(e,this);case"sql native":return new uce(e,this);case"turtle":return new u$(e,this);default:throw new Error(`unknown field definition ${JSON.stringify(e)}`)}}structSourceSQL(e){switch(this.fieldDef.structSource.type){case"table":{const n=this.fieldDef.structSource.tablePath;return this.dialect.quoteTablePath(n)}case"sql":if(this.fieldDef.structSource.method==="nested"||this.fieldDef.structSource.method==="lastStage")return this.fieldDef.name;if(this.fieldDef.structSource.method==="subquery")return`(${this.fieldDef.structSource.sqlBlock.selectStr})`;throw new Error("Internal Error: Unknown structSource type 'sql' method");case"nested":return"UNNEST(this.fieldDef.name)";case"inline":return"";case"query":{const n=(0,Ze.getIdentifier)(this.fieldDef);if(n.includes("cache")){const r=new a2(!0,e);return this.model.loadQuery(this.fieldDef.structSource.query,r,!1,!1),r.addPDT(n,this.dialect)}else return this.model.loadQuery(this.fieldDef.structSource.query,e,!1,!0).lastStageName}default:throw new Error(`unknown structSource ${this.fieldDef}`)}}root(){return this.parent===void 0?this:this.parent.root()}primaryKey(){if(this.fieldDef.primaryKey)return this.getDimensionByName([this.fieldDef.primaryKey])}getChildByName(e){return this.nameMap.get(e)}getFieldByName(e){return e.reduce((n,r)=>{const i=n.getChildByName(r);if(i===void 0)throw new Error(e.length===1?`'${r}' not found`:`'${r}' not found in '${e.join(".")}'`);return i},this)}getQueryFieldByName(e){const n=this.getFieldByName(e);if(n instanceof br)throw new Error(`Cannot reference ${e} as a scalar'`);return n}getQueryFieldReference(e,n){const r=this.getQueryFieldByName(e);if(n){if(r.parent===void 0)throw new Error("Expected field to have a parent");return r.parent.makeQueryField({...r.fieldDef,annotation:n})}return r}getDimensionOrMeasureByName(e){const n=this.getFieldByName(e);if(n instanceof Cr)return n;throw new Error(`${e} is not of type a scalar'`)}getDimensionByName(e){const n=this.getFieldByName(e);if(n instanceof Cr&&cr(n))return n;throw new Error(`${e} is not of type a scalar'`)}getStructByName(e){const n=this.getFieldByName(e);if(n instanceof br)return n;throw new Error(`Error: Path to structure not found '${e.join(".")}'`)}getDistinctKey(){if(this.fieldDef.structRelationship.type!=="inline")return this.getDimensionByName(["__distinct_key"]);if(this.parent)return this.parent.getDistinctKey();throw new Error("Internal Error. inline struct can not be top level")}applyStructFiltersToTurtleDef(e){let n=e.pipeline;const r=e.annotation,i=e.filterList||[];return n=structuredClone(n),n[0].filterList=i.concat(n[0].filterList||[],this.fieldDef.filterList||[]),{type:"turtle",name:e.name,pipeline:n,annotation:r,location:e.location}}}class a${constructor(e){this.dialect=new tce.StandardSQLDialect,this.modelDef=void 0,this.structs=new Map,this.exploreSearchSQLMap=new Map,e&&this.loadModelFromDef(e)}loadModelFromDef(e){this.modelDef=e;for(const n of Object.values(this.modelDef.contents)){let r;if(n.type==="struct")r=new br(n,void 0,{model:this}),this.structs.set((0,Ze.getIdentifier)(n),r),r.resolveQueryFields();else if(n.type!=="query")throw new Error("Internal Error: Unknown structure type")}}getStructByName(e){let n;if(n=this.structs.get(e))return n;throw new Error(`Struct ${e} not found in model.`)}getStructFromRef(e,n){var r;let i;if(typeof e=="string"){const s=this.getStructByName(e);return n!==void 0?new br(s.fieldDef,n,(r=s.parent)!==null&&r!==void 0?r:{model:this}):s}else if(e.type==="struct")i=e;else throw new Error("Broken for now");return new br(i,n,{model:this})}loadQuery(e,n,r=!1,i=!1){const s="";n||(n=new a2(!0,void 0));const o={type:"turtle",name:"ignoreme",pipeline:e.pipeline,filterList:e.filterList},u=Es.makeQuery(o,this.getStructFromRef(e.structRef,e.sourceArguments),n,i),a=u.generateSQLFromPipeline(n);if(r&&u.parent.dialect.hasFinalStage){const l=(0,Ze.getPhysicalFields)(a.outputStruct).map(c=>u.parent.dialect.sqlMaybeQuoteIdentifier(c.name));a.lastStageName=n.addStage(u.parent.dialect.sqlFinalStage(a.lastStageName,l))}return{lastStageName:a.lastStageName,malloy:s,stageWriter:n,structs:[a.outputStruct],connectionName:u.parent.connectionName}}compileQuery(e,n=!0){const i=this.loadQuery(e,void 0,n,!1),s=typeof e.structRef=="string"?e.structRef:e.structRef.type==="struct"?e.structRef.as||e.structRef.name:"(need to figure this out)";return n&&this.dialect.hasFinalStage&&(i.lastStageName=i.stageWriter.addStage(this.dialect.sqlFinalStage(i.lastStageName,[]))),{lastStageName:i.lastStageName,malloy:i.malloy,sql:i.stageWriter.generateSQLStages(),structs:i.structs,sourceExplore:s,sourceFilters:e.filterList,queryName:e.name,connectionName:i.connectionName,annotation:e.annotation}}async searchIndex(e,n,r,i=1e3,s=void 0){if(!e.canPersist())return;const o=this.getStructByName(n);let u=[];for(const[y,E]of o.nameMap)E instanceof br||cr(E)&&E.includeInWildcard()&&u.push({type:"fieldref",path:[y]});u=u.sort((y,E)=>y.path[0].localeCompare(E.path[0]));const a={structRef:n,pipeline:[{type:"index",indexFields:u,sample:o.dialect.defaultSampling}]},l=o.dialect.sqlMaybeQuoteIdentifier("fieldName"),c=o.dialect.sqlMaybeQuoteIdentifier("fieldPath"),f=o.dialect.sqlMaybeQuoteIdentifier("fieldValue"),x=o.dialect.sqlMaybeQuoteIdentifier("fieldType"),h=o.dialect.sqlMaybeQuoteIdentifier("weight");let p=this.exploreSearchSQLMap.get(n);p===void 0&&(p=this.compileQuery(a,!1).sql,this.exploreSearchSQLMap.set(n,p));let m=`SELECT
|
|
378
378
|
${l},
|
|
379
379
|
${c},
|
|
380
380
|
${f},
|