@malloy-publisher/server 0.3.0 → 0.4.0
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/app/api-doc.yaml +140 -44
- package/dist/app/assets/{EnvironmentPage-D6kQraU3.js → EnvironmentPage-BnxD6uzV.js} +1 -1
- package/dist/app/assets/{HomePage-BZbuE5jv.js → HomePage-D_srvBnZ.js} +1 -1
- package/dist/app/assets/{LightMode-BxZdPcNr.js → LightMode-DCsTKw61.js} +1 -1
- package/dist/app/assets/MainPage-CzHkstrF.js +2 -0
- package/dist/app/assets/ModelPage-CoQ07DHX.js +2 -0
- package/dist/app/assets/PackagePage-CUeUHOnm.js +1 -0
- package/dist/app/assets/RenderedResult-BnPzJ9Jf.es-Dme58kt1.js +116 -0
- package/dist/app/assets/RouteError-gRAhsKGi.js +1 -0
- package/dist/app/assets/ThemeEditorPage-C2gOJTU1.js +1 -0
- package/dist/app/assets/ToggleButtonGroup-CoIPitu6.js +1 -0
- package/dist/app/assets/index-BhkeAzTe.js +453 -0
- package/dist/app/assets/index-BswZnpqD.js +1322 -0
- package/dist/app/assets/index-CRAwrhYM.js +2 -0
- package/dist/app/assets/index-DKvKsj6c.js +442 -0
- package/dist/app/assets/{index-By-g8wiC.js → index-DTfS9vNi.js} +1 -1
- package/dist/app/assets/index-hVLQwLRj.js +1 -0
- package/dist/app/assets/index.es-D0L4_L8o.js +106 -0
- package/dist/app/index.html +1 -1
- package/dist/package_load_worker.mjs +20 -1
- package/dist/server.mjs +1033 -683
- package/package.json +3 -3
- package/dist/app/assets/MainPage-DrczCw4J.js +0 -2
- package/dist/app/assets/MaterializationsPage-BFLHLEuk.js +0 -1
- package/dist/app/assets/ModelPage-CFnfQ6BL.js +0 -1
- package/dist/app/assets/PackagePage-DHsVf_mP.js +0 -1
- package/dist/app/assets/RouteError-CHq8ubhy.js +0 -1
- package/dist/app/assets/ThemeEditorPage-B2y8Y64Y.js +0 -1
- package/dist/app/assets/index-BVv6KQ93.js +0 -557
- package/dist/app/assets/index-Bqrhk3ff.js +0 -2
- package/dist/app/assets/index-CawCwLK3.js +0 -1774
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{aL as a}from"./index-DKvKsj6c.js";import{r as f}from"./index-w_0OQJgZ.js";function c(t,n){for(var o=0;o<n.length;o++){const e=n[o];if(typeof e!="string"&&!Array.isArray(e)){for(const r in e)if(r!=="default"&&!(r in t)){const i=Object.getOwnPropertyDescriptor(e,r);i&&Object.defineProperty(t,r,i.get?i:{enumerable:!0,get:()=>e[r]})}}}return Object.freeze(Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}))}var s=f();const p=a(s),l=c({__proto__:null,default:p},[s]);export{s as d,l as i};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{aK as Le,aL as Ne}from"./index-DKvKsj6c.js";import{r as Ge}from"./index-CRAwrhYM.js";import{r as $e}from"./index-w_0OQJgZ.js";function qe(r,q){for(var N=0;N<q.length;N++){const w=q[N];if(typeof w!="string"&&!Array.isArray(w)){for(const g in w)if(g!=="default"&&!(g in r)){const l=Object.getOwnPropertyDescriptor(w,g);l&&Object.defineProperty(r,g,l.get?l:{enumerable:!0,get:()=>w[g]})}}}return Object.freeze(Object.defineProperty(r,Symbol.toStringTag,{value:"Module"}))}var $={},V={},Ve;function xe(){return Ve||(Ve=1,(function(r){var q=V&&V.__createBinding||(Object.create?(function(i,e,t,n){n===void 0&&(n=t);var s=Object.getOwnPropertyDescriptor(e,t);(!s||("get"in s?!e.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return e[t]}}),Object.defineProperty(i,n,s)}):(function(i,e,t,n){n===void 0&&(n=t),i[n]=e[t]})),N=V&&V.__setModuleDefault||(Object.create?(function(i,e){Object.defineProperty(i,"default",{enumerable:!0,value:e})}):function(i,e){i.default=e}),w=V&&V.__importStar||(function(){var i=function(e){return i=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},i(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=i(e),s=0;s<n.length;s++)n[s]!=="default"&&q(t,e,n[s]);return N(t,e),t}})();Object.defineProperty(r,"__esModule",{value:!0}),r.ASTAnnotationList=r.ASTLimitViewOperation=r.ASTView=r.ASTFilterWithLiteralEquality=r.ASTFilterWithFilterString=r.ASTFilter=r.ASTCalculateViewOperation=r.ASTHavingViewOperation=r.ASTDrillViewOperation=r.ASTWhereViewOperation=r.ASTNestViewOperation=r.ASTFilteredFieldExpression=r.ASTFilterOperationList=r.ASTFilterOperation=r.ASTMovingAverageExpression=r.ASTFieldReferenceList=r.ASTLiteralValueExpression=r.ASTTimeTruncationExpression=r.ASTReferenceExpression=r.ASTExpression=r.ASTField=r.ASTAggregateViewOperation=r.ASTGroupByViewOperation=r.ASTOrderByViewOperation=r.ASTViewOperation=r.ASTViewOperationList=r.ASTSegmentViewDefinition=r.ASTRefinementViewDefinition=r.ASTArrowViewDefinition=r.ASTReferenceViewDefinition=r.ASTReferenceQueryArrowSource=r.ASTReferenceQueryDefinition=r.ASTRefinementQueryDefinition=r.ASTArrowQueryDefinition=r.ASTQueryDefinition=r.ASTQueryArrowSource=r.ASTUnimplemented=r.ASTFilterExpressionLiteralValue=r.ASTTimestampLiteralValue=r.ASTDateLiteralValue=r.ASTBooleanLiteralValue=r.ASTNumberLiteralValue=r.ASTNullLiteralValue=r.ASTStringLiteralValue=r.ASTLiteralValue=r.ASTParameterValue=r.ASTParameterValueList=r.ASTFieldReference=r.ASTReference=r.ASTQuery=void 0,r.ASTAnnotation=void 0;const g=w(Ge()),l=$e(),p=w(Le());class h{constructor(){this.edited=!1}edit(){return this.edited=!0,this._parent&&this._parent.edit(),this}get as(){const e=this;return{Query(){if(e instanceof k)return e;throw new Error("Not an ASTQuery")},Reference(){if(e instanceof c)return e;throw new Error("Not an ASTReference")},ReferenceQueryArrowSource(){if(e instanceof Y)return e;throw new Error("Not an ASTReferenceQueryArrowSource")},ParameterValueList(){if(e instanceof b)return e;throw new Error("Not an ASTParameterValueList")},FilterOperation(){if(e instanceof j)return e;throw new Error("Not an ASTFilterOperation")},FilterOperationList(){if(e instanceof he)return e;throw new Error("Not an ASTFilterOperationList")},ParameterValue(){if(e instanceof H)return e;throw new Error("Not an ASTParameterValue")},StringLiteralValue(){if(e instanceof ae)return e;throw new Error("Not an ASTStringLiteralValue")},NumberLiteralValue(){if(e instanceof oe)return e;throw new Error("Not an ASTNumberLiteralValue")},ViewOperationList(){if(e instanceof de)return e;throw new Error("Not an ASTViewOperationList")},GroupByViewOperation(){if(e instanceof A)return e;throw new Error("Not an ASTGroupByViewOperation")},AggregateViewOperation(){if(e instanceof S)return e;throw new Error("Not an ASTAggregateViewOperation")},OrderByViewOperation(){if(e instanceof F)return e;throw new Error("Not an ASTOrderByViewOperation")},Field(){if(e instanceof x)return e;throw new Error("Not an ASTField")},ReferenceExpression(){if(e instanceof U)return e;throw new Error("Not an ASTReferenceExpression")},ReferenceViewDefinition(){if(e instanceof X)return e;throw new Error("Not an ASTReferenceViewDefinition")},ArrowQueryDefinition(){if(e instanceof y)return e;throw new Error("Not an ASTArrowQueryDefinition")},ArrowViewDefinition(){if(e instanceof Z)return e;throw new Error("Not an ASTArrowViewDefinition")},RefinementViewDefinition(){if(e instanceof _)return e;throw new Error("Not an ASTRefinementViewDefinition")},TimeTruncationExpression(){if(e instanceof ee)return e;throw new Error("Not an ASTTimeTruncationExpression")},FilteredFieldExpression(){if(e instanceof Q)return e;throw new Error("Not an ASTFilteredFieldExpression")},NestViewOperation(){if(e instanceof T)return e;throw new Error("Not an ASTNestViewOperation")},View(){if(e instanceof ie)return e;throw new Error("Not an ASTView")},SegmentViewDefinition(){if(e instanceof O)return e;throw new Error("Not an ASTSegmentViewDefinition")},LimitViewOperation(){if(e instanceof P)return e;throw new Error("Not an ASTLimitViewOperation")},AnnotationList(){if(e instanceof D)return e;throw new Error("Not an ASTAnnotationList")},Annotation(){if(e instanceof W)return e;throw new Error("Not an ASTAnnotation")}}}get find(){const e=this;return{Query(t){return e.findAny(t).as.Query()},Reference(t){return e.findAny(t).as.Reference()},ReferenceQueryArrowSource(t){return e.findAny(t).as.ReferenceQueryArrowSource()},ParameterValueList(t){return e.findAny(t).as.ParameterValueList()},FilterOperation(t){return e.findAny(t).as.FilterOperation()},FilterOperationList(t){return e.findAny(t).as.FilterOperationList()},ParameterValue(t){return e.findAny(t).as.ParameterValue()},StringLiteralValue(t){return e.findAny(t).as.StringLiteralValue()},NumberLiteralValue(t){return e.findAny(t).as.NumberLiteralValue()},ViewOperationList(t){return e.findAny(t).as.ViewOperationList()},GroupByViewOperation(t){return e.findAny(t).as.GroupByViewOperation()},AggregateViewOperation(t){return e.findAny(t).as.AggregateViewOperation()},OrderByViewOperation(t){return e.findAny(t).as.OrderByViewOperation()},Field(t){return e.findAny(t).as.Field()},ReferenceExpression(t){return e.findAny(t).as.ReferenceExpression()},ReferenceViewDefinition(t){return e.findAny(t).as.ReferenceViewDefinition()},ArrowQueryDefinition(t){return e.findAny(t).as.ArrowQueryDefinition()},ArrowViewDefinition(t){return e.findAny(t).as.ArrowViewDefinition()},RefinementViewDefinition(t){return e.findAny(t).as.RefinementViewDefinition()},TimeTruncationExpression(t){return e.findAny(t).as.TimeTruncationExpression()},FilteredFieldExpression(t){return e.findAny(t).as.FilteredFieldExpression()},NestViewOperation(t){return e.findAny(t).as.NestViewOperation()},View(t){return e.findAny(t).as.View()},SegmentViewDefinition(t){return e.findAny(t).as.SegmentViewDefinition()},LimitViewOperation(t){return e.findAny(t).as.LimitViewOperation()},AnnotationList(t){return e.findAny(t).as.AnnotationList()},Annotation(t){return e.findAny(t).as.Annotation()}}}get parent(){if(this._parent===void 0)throw new Error("This node does not have a parent");return this._parent}set parent(e){this._parent=e}static schemaTryGet(e,t,n){return h._schemaTryGet(e,t,n,!1)}static schemaTryGetDrillField(e,t,n){return h._schemaTryGet(e,t,n,!0)}static _schemaTryGet(e,t,n,s){let a=e.fields;for(const f of n??[]){const u=a.find(m=>m.name===f);if(u===void 0)throw new Error(`${f} not found`);if(u.kind==="join"||s&&u.kind==="view"){a=u.schema.fields;continue}if(u.kind==="dimension"||u.kind==="measure"){if(u.type.kind==="record_type"){a=u.type.fields.map(m=>({kind:u.kind,...m}));continue}else if(u.type.kind==="array_type"&&u.type.element_type.kind==="record_type"){a=u.type.element_type.fields.map(m=>({kind:u.kind,...m}));continue}}throw new Error(`${f} is not a join, record, or repeated record`)}return a.find(f=>f.name===t)}static schemaGet(e,t,n){const s=h.schemaTryGet(e,t,n);if(s===void 0)throw new Error(`${t} not found`);return s}static schemaGetDrillField(e,t,n){const s=h.schemaTryGetDrillField(e,t,n);if(s===void 0)throw new Error(`${t} not found`);return s}static schemaMerge(e,t){return{fields:[...e.fields,...t.fields]}}static tagFor(e,t="# "){var n,s;const a=(s=(n=e.annotations)===null||n===void 0?void 0:n.map(f=>f.value))===null||s===void 0?void 0:s.filter(f=>f.startsWith(t)),o=new l.TagParser;for(const f of a??[])o.parseAnnotation(f);return o.finish()}static fieldWasCalculation(e){if(e.kind!=="dimension")throw new Error(`${e.name} could not be an output field, because it is a ${e.kind}, and only dimensions can appear in output schemas`);return h.tagFor(e,"#(malloy) ").has("calculation")}}function se(i){return Array.isArray(i)||typeof i=="string"||typeof i=="number"||typeof i=="boolean"}class M extends h{constructor(e,t){super(),this.node=e,this.children=t,this.originalChildren=[...t],t.forEach(n=>n.parent=this)}*iter(){for(let e=0;e<this.length;e++)yield this.index(e)}get length(){return this.children.length}get last(){return this.children[this.children.length-1]}index(e){return this.children[e]}insert(e,t){this.edit(),this.children.splice(t,0,e),e.parent=this}add(e){this.edit(),this.children.push(e),e.parent=this}remove(e){const t=this.children.findIndex(n=>n===e);if(t===-1)return this;this.edit(),this.children.splice(t,1)}build(){if(!this.edited)return this.node;const e=this.children.map(t=>t.build());return this.edited=!1,this.originalChildren=[...this.children],this.node=e,e}findAny(e){if(e.length===0)return this;const[t,...n]=e;if(typeof t!="number")throw new Error(`${this.constructor.name} is a ASTListNode and thus cannot contain a ${t}`);return this.children[t].findAny(n)}findIndex(e){return this.children.findIndex(e)}indexOf(e){return this.children.indexOf(e)}}class d extends h{constructor(e,t){super(),this.node=e,this.children=t;for(const n in t){const s=t[n];s&&!se(s)&&(s.parent=this)}}build(){if(!this.edited)return this.node;let e=this.node;for(const t in this.children){const n=this.children[t];n===void 0?e={...e,[t]:void 0}:se(n)?this.edited&&(e={...e,[t]:n}):e={...e,[t]:n.build()}}return this.node=e,this.edited=!1,e}findAny(e){if(e.length===0)return this;const[t,...n]=e;if(typeof t!="string")throw new Error(`${this.constructor.name} is a ASTListNode and thus cannot contain a ${t}`);const s=this.children[t];if(se(s))throw new Error(`${this.constructor.name}.${t} refers to a basic type, not an ASTNode`);return s._find(n)}}class k extends d{constructor(e){var t,n;let s=e.source;if(s===void 0){if(e.model===void 0)throw new Error("Need a model or source");if(e.query){const u=e.query.definition;if(u.kind==="arrow"&&u.source.kind==="source_reference"){const m=u.source.name;if(s=e.model.entries.find(z=>z.name===m),s===void 0)throw new Error(`Model does not contain source or query named ${m}`)}}if(s===void 0&&(s=e.model.entries[0]),s===void 0)throw new Error("Model does not contain any sources or queries")}const a=Re(s),o=(t=e.query)!==null&&t!==void 0?t:{definition:{kind:"arrow",source:{kind:"source_reference",name:a.name},view:{kind:"segment",operations:[]}}},f=(n=e.model)!==null&&n!==void 0?n:{entries:[a],anonymous_queries:[]};super(o,{definition:r.ASTQueryDefinition.from(o.definition),annotations:o.annotations&&new D(o.annotations)}),this.model=f,e.source&&this.setSource(e.source.name)}get definition(){return this.children.definition}set definition(e){this.edit(),this.children.definition=e,e.parent=this}get annotations(){return this.children.annotations}reorderFields(e){this.definition.reorderFields(e)}getOrAddAnnotations(){if(this.annotations)return this.annotations;this.edit();const e=new D([]);return this.children.annotations=e,e.parent=this,e}getInheritedTag(e="# "){return L(e,this.getInheritedAnnotations())}getIntrinsicTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getIntrinsicTag(e))!==null&&n!==void 0?n:new l.Tag}getTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getTag(e))!==null&&n!==void 0?n:this.getInheritedTag(e)}setTagProperty(e,t=null,n="# "){this.getOrAddAnnotations().setTagProperty(e,t,n)}removeTagProperty(e,t="# "){this.getTag().has(...e)&&this.getOrAddAnnotations().removeTagProperty(e,t)}setViewToEmptySegment(){if(!(this.definition instanceof y))throw new Error("Must set source before setting view");return this.definition=new y({kind:"arrow",source:this.definition.source.build(),view:{kind:"segment",operations:[]}}),this.definition.view.as.SegmentViewDefinition()}isRunnable(){return this.definition.isRunnable()}isEmpty(){return this.definition instanceof y&&this.definition.view instanceof O&&this.definition.view.operations.length===0}getOrAddDefaultSegment(){return this.definition.getOrAddDefaultSegment()}setSource(e){if(this.definition instanceof y&&this.definition.source instanceof Y&&this.definition.source.name===e)return;if(this.model.entries.find(n=>n.name===e)===void 0)throw new Error(`Source ${e} is not defined in model`);this.definition=new y({kind:"arrow",source:{kind:"source_reference",name:e},view:this.definition instanceof y?this.definition.view.build():{kind:"segment",operations:[]}})}setQueryHead(e){const t=this.model.entries.find(n=>n.name===e);if(t===void 0||t.kind!=="query")throw new Error(`No query named ${e} in the model`);this.definition=new K({kind:"query_reference",name:e})}getQueryInfo(e){const t=this.model.entries.find(n=>n.name===e);if(t===void 0)throw new Error(`Query ${e} is not defined in model`);if(t.kind!=="query")throw new Error(`Model entry ${e} is not a query`);return t}toMalloy(){return g.queryToMalloy(this.build())}build(){return super.build()}setView(e){if(!(this.definition instanceof y))throw new Error("Must set source before setting view");return this.definition=new y({kind:"arrow",source:this.definition.source.build(),view:{kind:"view_reference",name:e}}),this.definition.view.as.ReferenceViewDefinition()}_getInheritedAnnotations(e){var t;return e instanceof K?(t=this.getQueryInfo(e.name).annotations)!==null&&t!==void 0?t:[]:e instanceof E?this._getInheritedAnnotations(e.base):e instanceof y?e.view.getInheritedAnnotations():[]}getInheritedAnnotations(){return this._getInheritedAnnotations(this.definition)}}r.ASTQuery=k;class c extends d{constructor(e){super(e,{name:e.name,path:e.path,parameters:e.parameters&&new b(e.parameters)}),this.reference=e}get name(){return this.children.name}set name(e){this.edit(),this.children.name=e}get parameters(){return this.children.parameters}set parameters(e){this.edit(),this.children.parameters=e}get path(){return this.children.path}static getOrAddParameters(e){if(e.parameters)return e.parameters;e.edit();const t=new b([]);return e.parameters=t,t}static setParameter(e,t,n){const s=c.tryGetParameter(e,t);if(s!==void 0){s.value=r.ASTLiteralValue.from(r.ASTLiteralValue.makeLiteral(n));return}return e.getOrAddParameters().addParameter(t,n)}static tryGetParameter(e,t){if(e.parameters!==void 0){for(const n of e.parameters.iter())if(n.name===t)return n}}getOrAddParameters(){return c.getOrAddParameters(this)}setParameter(e,t){return c.setParameter(this,e,t)}tryGetParameter(e){return c.tryGetParameter(this,e)}}r.ASTReference=c;class G extends c{get segment(){const e=this.parent;return e instanceof Q||e instanceof ee?e.field.segment:e instanceof ne||e instanceof C?e.segment:e.list.segment}getReferenceSchema(){return this.parent instanceof F?this.segment.getOutputSchema():this.segment.getInputSchema()}getFieldInfo(){const e=this.getReferenceSchema();return h.schemaGet(e,this.name,this.path)}}r.ASTFieldReference=G;class b extends M{constructor(e){super(e,e.map(t=>new H(t)))}get parameters(){return this.children}addParameter(e,t){this.add(new H({name:e,value:r.ASTLiteralValue.makeLiteral(t)}))}}r.ASTParameterValueList=b;class H extends d{constructor(e){super(e,{name:e.name,value:r.ASTLiteralValue.from(e.value)}),this.parameter=e}get name(){return this.children.name}get value(){return this.children.value}set value(e){this.edit(),this.children.value=e}}r.ASTParameterValue=H,r.ASTLiteralValue={from(i){switch(i.kind){case"string_literal":return new ae(i);case"number_literal":return new oe(i);case"boolean_literal":return new ye(i);case"date_literal":return new Ae(i);case"timestamp_literal":return new Te(i);case"null_literal":return new we(i);case"filter_expression_literal":return new Se(i)}},makeLiteral(i){if(i!==null&&typeof i=="object"&&"kind"in i)return i;if(typeof i=="string")return{kind:"string_literal",string_value:i};if(typeof i=="boolean")return{kind:"boolean_literal",boolean_value:i};if(typeof i=="number")return{kind:"number_literal",number_value:i};if(i===null)return{kind:"null_literal"};if("date"in i){const e=i.granularity,t=De(i.date);return Pe(e)?{kind:"date_literal",date_value:t,granularity:e}:{kind:"timestamp_literal",timestamp_value:t,granularity:e}}throw new Error("Unknown literal type")}};class ae extends d{constructor(e){super(e,{kind:e.kind,string_value:e.string_value}),this.node=e,this.kind="string_literal"}get fieldType(){return{kind:"string_type"}}}r.ASTStringLiteralValue=ae;class we extends d{constructor(e){super(e,{kind:e.kind}),this.node=e,this.kind="null_literal"}get fieldType(){}}r.ASTNullLiteralValue=we;class oe extends d{constructor(e){super(e,{kind:e.kind,number_value:e.number_value}),this.node=e,this.kind="number_literal"}get fieldType(){return{kind:"number_type",subtype:Number.isInteger(this.children.number_value)?"integer":"decimal"}}}r.ASTNumberLiteralValue=oe;class ye extends d{constructor(e){super(e,{kind:e.kind,boolean_value:e.boolean_value}),this.node=e,this.kind="boolean_literal"}get fieldType(){return{kind:"boolean_type"}}}r.ASTBooleanLiteralValue=ye;class Ae extends d{constructor(e){super(e,{kind:e.kind,date_value:e.date_value,granularity:e.granularity}),this.node=e,this.kind="date_literal"}get fieldType(){return{kind:"date_type",timeframe:this.children.granularity}}}r.ASTDateLiteralValue=Ae;class Te extends d{constructor(e){super(e,{kind:e.kind,timestamp_value:e.timestamp_value,granularity:e.granularity}),this.node=e,this.kind="timestamp_literal"}get fieldType(){return{kind:"timestamp_type",timeframe:this.children.granularity}}}r.ASTTimestampLiteralValue=Te;class Se extends d{constructor(e){super(e,{kind:e.kind,filter_expression_value:e.filter_expression_value}),this.node=e,this.kind="filter_expression_literal"}get fieldType(){}}r.ASTFilterExpressionLiteralValue=Se;class Ee extends h{constructor(e){super(),this.node=e}get treeEdited(){return!1}build(){return this.node}findAny(){throw new Error("Tried to find a node from an unimplemented node type")}}r.ASTUnimplemented=Ee,r.ASTQueryArrowSource={from(i){switch(i.kind){case"refinement":return new E(i);case"source_reference":return new Y(i)}}},r.ASTQueryDefinition={from(i){switch(i.kind){case"arrow":return new y(i);case"query_reference":return new K(i);case"refinement":return new E(i)}}};class y extends d{constructor(e){super(e,{kind:"arrow",source:r.ASTQueryArrowSource.from(e.source),view:v.from(e.view)}),this.node=e}get view(){return this.children.view}set view(e){this.edit(),this.children.view=e,e.parent=this}get source(){return this.children.source}set source(e){this.edit(),this.children.source=e}getOrAddDefaultSegment(){return this.view.getOrAddDefaultSegment()}getSourceInfo(){return this.source.getSourceInfo()}getOutputSchema(){return this.view.getRefinementSchema()}isRunnable(){return this.view.isRunnable()&&this.source.isRunnable()}get query(){return this.parent.as.Query()}propagateUp(e){this.propagateDown(e)}propagateDown(e){e(this.view),this.view.propagateDown(e)}reorderFields(e){this.view instanceof O?this.view.reorderFields(e):this.query.getOrAddAnnotations().setTagProperty(["field_order"],e)}}r.ASTArrowQueryDefinition=y;class E extends d{constructor(e){super(e,{kind:"refinement",base:r.ASTQueryDefinition.from(e.base),refinement:v.from(e.refinement)}),this.node=e}get base(){return this.children.base}get refinement(){return this.children.refinement}set refinement(e){this.edit(),this.children.refinement=e,e.parent=this}isRunnable(){return!0}get query(){return this.parent.as.Query()}getOrAddDefaultSegment(){return this.refinement.getOrAddDefaultSegment()}getOutputSchema(){const e=this.base.getOutputSchema(),t=this.refinement.getRefinementSchema();return k.schemaMerge(e,t)}propagateUp(e){this.propagateDown(e)}propagateDown(e){e(this.refinement),this.refinement.propagateDown(e)}reorderFields(e){this.query.getOrAddAnnotations().setTagProperty(["field_order"],e)}getSourceInfo(){return this.base.getSourceInfo()}}r.ASTRefinementQueryDefinition=E;class K extends d{constructor(e){super(e,{kind:"query_reference",name:e.name,path:e.path,parameters:e.parameters&&new b(e.parameters)}),this.node=e}isRunnable(){return!0}get name(){return this.children.name}get query(){return this.parent.as.Query()}get parameters(){return this.children.parameters}set parameters(e){this.edit(),this.children.parameters=e}get path(){return this.children.path}getOrAddDefaultSegment(){const e=new E({kind:"refinement",base:this.build(),refinement:{kind:"segment",operations:[]}});return this.query.definition=e,e.refinement.as.SegmentViewDefinition()}propagateUp(e){}propagateDown(e){}reorderFields(e){this.query.getOrAddAnnotations().setTagProperty(["field_order"],e)}getOrAddParameters(){return c.getOrAddParameters(this)}setParameter(e,t){return c.setParameter(this,e,t)}tryGetParameter(e){return c.tryGetParameter(this,e)}getOutputSchema(){return this.getSourceInfo().schema}getSourceInfo(){const t=this.query.model.entries.find(n=>n.name===this.name);if(t===void 0)throw new Error(`Query not found with name ${this.name}`);return t}}r.ASTReferenceQueryDefinition=K;class Y extends d{constructor(e){super(e,{kind:"source_reference",name:e.name,path:e.path,parameters:e.parameters&&new b(e.parameters)}),this.node=e}isRunnable(){return this.areRequiredParametersSet()}get name(){return this.children.name}get arrow(){return this.parent.as.ArrowQueryDefinition()}get parameters(){return this.children.parameters}set parameters(e){this.edit(),this.children.parameters=e}get path(){return this.children.path}getSourceInfo(){const e=this.arrow.query.model.entries.find(t=>t.name===this.name);if(e===void 0)throw new Error(`No query or source named ${this.name}`);return e}getOrAddDefaultSegment(){if(this.getSourceInfo().kind!=="query")throw new Error(`Cannot refine source ${this.name}`);const t=new E({kind:"refinement",base:{...this.build(),kind:"query_reference"},refinement:{kind:"segment",operations:[]}});return this.arrow.source=t,t.refinement.as.SegmentViewDefinition()}propagateUp(e){}propagateDown(e){}getOrAddParameters(){return c.getOrAddParameters(this)}setParameter(e,t){return c.setParameter(this,e,t)}tryGetParameter(e){return c.tryGetParameter(this,e)}get query(){return this.parent.parent.as.Query()}getSourceParameters(){var e;const t=this.getSourceInfo();return t.kind==="query"?[]:(e=t.parameters)!==null&&e!==void 0?e:[]}areRequiredParametersSet(){const e=this.getSourceParameters();for(const t of e){if(t.default_value!==void 0)continue;if(this.tryGetParameter(t.name)===void 0)return!1}return!0}}r.ASTReferenceQueryArrowSource=Y;const v={from(i){switch(i.kind){case"arrow":return new Z(i);case"view_reference":return new X(i);case"segment":return new O(i);case"refinement":return new _(i)}}};function I(i,e){const t=i.parent;t instanceof y?t.view=e:t instanceof E?t.refinement=e:t instanceof ie?t.definition=e:t instanceof Z?t.source===i?t.source=e:t.view=e:t.base===i?t.base=e:t.refinement=e}function J(i,e,t=[]){const n=i.getInputSchema(),s=k.schemaGet(n,e,t);if(s===void 0)return{isValidViewRefinement:!1,error:`${e} is not defined`};if(s.kind!=="view")return{isValidViewRefinement:!1,error:`${e} is not a view`};const a=i.getOutputSchema();for(const o of s.schema.fields)if(k.schemaTryGet(a,o.name,[]))return{isValidViewRefinement:!1,error:`Cannot refine with ${e} because stage already has an output field named ${o.name}`};return{isValidViewRefinement:!0}}class X extends d{constructor(e){super(e,{kind:"view_reference",name:e.name,path:e.path,parameters:e.parameters&&new b(e.parameters)}),this.node=e}isRunnable(){return!0}get name(){return this.children.name}get path(){return this.children.path}get parameters(){return this.children.parameters}set parameters(e){this.edit(),this.children.parameters=e}getOrAddDefaultSegment(){return this.addEmptyRefinement()}addEmptyRefinement(){const e=_.segmentRefinementOf(this.build());return I(this,e),e.refinement.as.SegmentViewDefinition()}addViewRefinement(e,t){const{error:n}=this.isValidViewRefinement(e,t);if(n)throw new Error(n);const s=_.viewRefinementOf(this.build(),e,t);return I(this,s),s.refinement.as.ReferenceViewDefinition()}convertToNest(e){const t=v.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});I(this,t)}isValidViewRefinement(e,t){return J(this,e,t)}getInputSchema(){return pe(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getImplicitName(){return this.name}getViewInfo(){const e=this.getInputSchema(),t=h.schemaGet(e,this.name,this.path);if(t.kind!=="view")throw new Error("Not a view");return t}getRefinementSchema(){return this.getViewInfo().schema}propagateUp(e){this.parent.propagateUp(e)}propagateDown(e){}getInheritedAnnotations(){var e;return(e=this.getViewInfo().annotations)!==null&&e!==void 0?e:[]}getOrAddParameters(){return c.getOrAddParameters(this)}setParameter(e,t){return c.setParameter(this,e,t)}tryGetParameter(e){return c.tryGetParameter(this,e)}}r.ASTReferenceViewDefinition=X;class Z extends d{constructor(e){super(e,{kind:"arrow",source:v.from(e.source),view:v.from(e.view)}),this.node=e}isRunnable(){return this.source.isRunnable()&&this.view.isRunnable()}get source(){return this.children.source}set source(e){this.edit(),this.children.source=e}get view(){return this.children.view}set view(e){this.edit(),this.children.view=e,e.parent=this}getOrAddDefaultSegment(){return this.view.getOrAddDefaultSegment()}addEmptyRefinement(){return this.view.addEmptyRefinement()}addViewRefinement(e,t){return this.view.addViewRefinement(e,t)}convertToNest(e){const t=v.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});I(this,t)}getInputSchema(){return this.source.getOutputSchema()}getOutputSchema(){return this.view.getRefinementSchema()}getImplicitName(){return this.view.getImplicitName()}getRefinementSchema(){throw new Error("An arrow is not a valid refinement")}isValidViewRefinement(e,t){return J(this,e,t)}propagateUp(e){this.propagateDown(e)}propagateDown(e){e(this.view),this.view.propagateDown(e)}getInheritedAnnotations(){return[]}}r.ASTArrowViewDefinition=Z;class _ extends d{constructor(e){super(e,{kind:"refinement",base:v.from(e.base),refinement:v.from(e.refinement)}),this.node=e}isRunnable(){return this.getOutputSchema().fields.length>0}get refinement(){return this.children.refinement}set refinement(e){this.edit(),this.children.refinement=e,e.parent=this}get base(){return this.children.base}set base(e){this.edit(),this.children.base=e}convertToNest(e){const t=v.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});I(this,t)}getOrAddDefaultSegment(){return this.refinement.getOrAddDefaultSegment()}addEmptyRefinement(){return this.refinement.addEmptyRefinement()}addViewRefinement(e,t){return this.refinement.addViewRefinement(e,t)}getInputSchema(){return pe(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getRefinementSchema(){return h.schemaMerge(this.base.getRefinementSchema(),this.refinement.getRefinementSchema())}getImplicitName(){return this.base.getImplicitName()}isValidViewRefinement(e,t){return J(this,e,t)}propagateUp(e){this.parent.propagateUp(e)}propagateDown(e){e(this.base),e(this.refinement),this.base.propagateDown(e),this.refinement.propagateDown(e)}getInheritedAnnotations(){return this.base.getInheritedAnnotations()}static viewRefinementOf(e,t,n){return new _({kind:"refinement",base:e,refinement:{kind:"view_reference",name:t,path:n}})}static segmentRefinementOf(e){return new _({kind:"refinement",base:e,refinement:{kind:"segment",operations:[]}})}}r.ASTRefinementViewDefinition=_;class O extends d{constructor(e){super(e,{kind:"segment",operations:new de(e.operations)}),this.node=e,this.DEFAULT_INSERTION_ORDER=["group_by","aggregate","drill","where","having","nest","order_by","calculate","limit"]}isRunnable(){let e=!1;for(const t of this.operations.iter()){if(t instanceof S||t instanceof A)return!0;if(t instanceof T){if(!t.view.definition.isRunnable())return!1;e=!0}}return e}get operations(){return this.children.operations}convertToNest(e){const t=v.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});I(this,t)}renameOrderBys(e,t){for(const n of this.operations.iter())n instanceof F&&n.name===e&&n.setField(t)}propagateUp(e){this.parent.propagateUp(e)}propagateDown(e){}removeOrderBys(e){for(const t of this.operations.iter())t instanceof F&&t.name===e&&t.delete()}reorderFields(e){const t=[],n=[],s={};let a=!1;for(const u of this.operations.iter()){if((u instanceof S||u instanceof A||u instanceof T)&&e.includes(u.name)){s[u.name]=u,a=!0;continue}a?n.push(u):t.push(u)}const o=[];for(const u of e){const m=s[u];if(m===void 0)throw new Error(`No field named ${u}`);o.push(m)}const f=[...t,...o,...n];this.operations.items=f}renameField(e,t){if(e.name===t)return;const n=this.getOutputSchema();if(h.schemaTryGet(n,t,[]))throw new Error(`Output already has a field named ${t}`);const s=e.name;e.name=t,this.propagateUp(a=>{a instanceof O&&a.renameOrderBys(s,t)})}addOrderBy(e,t){const n=this.getOutputSchema();try{h.schemaGet(n,e,[])}catch{throw new Error(`No such field ${e} in stage output`)}for(const a of this.operations.iter())if(a instanceof F&&a.name===e)return a.direction=t,a;const s=new F({kind:"order_by",field_reference:{name:e},direction:t});return this.addOperation(s),s}addEmptyNest(e){const t=new T({kind:"nest",name:e,view:{definition:{kind:"segment",operations:[]}}});return this.addOperation(t),t}firstIndexOfOperationType(e){return this.operations.findIndex(t=>t.kind===e)}findInsertionPoint(e){const t=this.firstIndexOfOperationType(e);if(t>-1){let a=t;for(;this.operations.index(a)&&this.operations.index(a).kind===e;)a++;return a}const n=this.DEFAULT_INSERTION_ORDER.indexOf(e);if(n===-1)throw new Error(`Operation ${e} is not supported for \`findInsertionPoint\``);const s=this.DEFAULT_INSERTION_ORDER.slice(n+1);for(const a of s){const o=this.firstIndexOfOperationType(a);if(o>-1)return o}return this.operations.length}getFieldNamed(e){const t=this.tryGetFieldNamed(e);if(t===void 0)throw new Error("No such field");return t}hasFieldNamed(e){return this.tryGetFieldNamed(e)!==void 0}hasField(e,t){return this.tryGetField(e,t)!==void 0}getField(e,t){const n=this.tryGetField(e,t);if(n===void 0)throw new Error("No such field");return n}tryGetField(e,t){for(const n of this.operations.iter())if(n instanceof A||n instanceof S){const s=n.field.getReference();if(s&&s.name===e&&_e(s.path,t))return n}else if(n instanceof T){if(n.view instanceof X)return n}else if(n instanceof R){const s=n.expression.field.getReference();if(s&&s.name===e&&_e(s.path,t))return n}}tryGetFieldNamed(e){for(const t of this.operations.iter())if((t instanceof A||t instanceof S||t instanceof T||t instanceof R)&&t.name===e)return t}getGroupBy(e){for(const t of this.operations.iter())if(t instanceof A&&t.name===e)return t}removeGroupBy(e){var t;return(t=this.getGroupBy(e))===null||t===void 0||t.delete(),this}addGroupBy(e,t=[],n){const s=this.makeField(e,t,n,"dimension");return this.addOperation(s),s}addDrill(e){const t=new te({kind:"drill",...e});return this.addOperation(t),t}addWhere(e,t,n){const s=Array.isArray(t)?t:[],a=n===void 0?t:n,o=typeof a=="string"?a:re(a),f=this.getInputSchema(),u=k.schemaGet(f,e,s);ge(u,a);const m=new fe({kind:"where",filter:{kind:"filter_string",expression:{kind:"field_reference",name:e,path:s},filter:o}});return this.addOperation(m),m}addHaving(e,t,n){const s=Array.isArray(t)?t:[],a=n===void 0?t:n,o=typeof a=="string"?a:re(a),f=this.getInputSchema(),u=k.schemaGet(f,e,s);ge(u,a);const m=new ce({kind:"having",filter:{kind:"filter_string",expression:{kind:"field_reference",name:e,path:s},filter:o}});return this.addOperation(m),m}addCalculateMovingAverage(e,t,n,s,a){const o=new R({kind:"calculate",name:e,field:{expression:{kind:"moving_average",field_reference:{name:t,path:n},rows_preceding:s,rows_following:a}}});return this.addOperation(o),o}addTimeGroupBy(e,t,n,s){const a=this.getInputSchema(),o=h.schemaGet(a,e,t);if(o===void 0)throw new Error(`No such field ${e}`);if(o.kind!=="dimension")throw new Error(`Cannot group by non-dimension ${e}`);if(o.type.kind!==s)throw new Error(`${e} is not a ${s}`);const f=new A({kind:"group_by",field:{expression:{kind:"time_truncation",field_reference:{name:e,path:t},truncation:n}}});return this.addOperation(f),f}addDateGroupBy(e,t,n){const s=n===void 0?t:n,a=n===void 0?[]:t;return this.addTimeGroupBy(e,a,s,"date_type")}addTimestampGroupBy(e,t,n){const s=n===void 0?t:n,a=n===void 0?[]:t;return this.addTimeGroupBy(e,a,s,"timestamp_type")}addTimestamptzGroupBy(e,t,n){const s=n===void 0?t:n,a=n===void 0?[]:t;return this.addTimeGroupBy(e,a,s,"timestamptz_type")}addAggregate(e,t=[],n){const s=this.makeField(e,t,n,"measure");return this.addOperation(s),s}addNest(e,t){const n=this.makeField(e,[],t,"view");return this.addOperation(n),n}makeField(e,t,n,s){const a=this.getInputSchema(),o=h.schemaGet(a,e,t);if(o===void 0)throw new Error(`No such field ${e}`);if(o.kind!==s){const f=Fe(s),u=s;throw new Error(`Cannot ${f} non-${u} ${e}`)}return s==="dimension"?A.fromReference(e,t,n):s==="measure"?S.fromReference(e,t,n):T.fromReference(e,t,n)}addOperation(e){if((e instanceof A||e instanceof S||e instanceof T||e instanceof R)&&this.hasFieldNamed(e.name))throw new Error(`Query already has a field named ${e.name}`);const t=this.findInsertionPoint(e.kind);return this.operations.insert(e,t),e}getRefinementSchema(){const e=[];for(const t of this.operations.iter())(t instanceof A||t instanceof S||t instanceof T||t instanceof R)&&e.push(t.getFieldInfo());return{fields:e}}setLimit(e){P.validateLimit(e);const t=[...this.operations.iter()].find(r.ASTViewOperation.isLimit);t?t.limit=e:this.operations.add(new P({kind:"limit",limit:e}))}getOrAddDefaultSegment(){return this}addEmptyRefinement(){const e=_.segmentRefinementOf(this.build());return I(this,e),e.refinement.as.SegmentViewDefinition()}addViewRefinement(e,t){const{error:n}=this.isValidViewRefinement(e,t);if(n)throw new Error(n);const s=_.viewRefinementOf(this.build(),e,t);return I(this,s),s.refinement.as.ReferenceViewDefinition()}getInputSchema(){return pe(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getImplicitName(){}isValidViewRefinement(e,t){return J(this,e,t)}getInheritedAnnotations(){return[]}}r.ASTSegmentViewDefinition=O;class de extends M{constructor(e){super(e,e.map(t=>r.ASTViewOperation.from(t)))}get items(){return this.children}set items(e){this.edit(),this.children=e}get segment(){return this.parent.as.SegmentViewDefinition()}}r.ASTViewOperationList=de,r.ASTViewOperation={from(i){switch(i.kind){case"group_by":return new A(i);case"aggregate":return new S(i);case"order_by":return new F(i);case"nest":return new T(i);case"limit":return new P(i);case"where":return new fe(i);case"drill":return new te(i);case"having":return new ce(i);case"calculate":return new R(i)}},isLimit(i){return i instanceof P}};class F extends d{constructor(e){super(e,{kind:"order_by",field_reference:new G(e.field_reference),direction:e.direction}),this.node=e,this.kind="order_by"}get fieldReference(){return this.children.field_reference}get name(){return this.fieldReference.name}get direction(){return this.children.direction}set direction(e){this.direction!==e&&(this.edit(),this.children.direction=e)}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}setField(e){const t=this.list.segment.getOutputSchema();h.schemaGet(t,e,[]),this.edit(),this.children.field_reference=new G({name:e})}setDirection(e){this.direction=e}}r.ASTOrderByViewOperation=F;class A extends d{constructor(e){super(e,{kind:"group_by",name:e.name,field:new x(e.field)}),this.node=e,this.kind="group_by"}get field(){return this.children.field}get name(){var e;const t=(e=this.children.name)!==null&&e!==void 0?e:this.field.name;if(t===void 0)throw new Error("Group by does not have a name");return t}set name(e){this.name!==e&&(this.edit(),this.field.name===e?this.children.name=void 0:this.children.name=e)}get list(){return this.parent.as.ViewOperationList()}rename(e){this.list.segment.renameField(this,e)}delete(){this.list.remove(this),this.list.segment.propagateUp(e=>{e instanceof O&&e.removeOrderBys(this.name)})}getFieldInfo(){return{kind:"dimension",name:this.name,type:this.field.type}}get annotations(){return this.field.annotations}set annotations(e){this.edit(),this.field.annotations=e}getOrAddAnnotations(){return this.field.getOrAddAnnotations()}getInheritedTag(e="# "){return L(e,this.field.getInheritedAnnotations())}getIntrinsicTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getIntrinsicTag(e))!==null&&n!==void 0?n:new l.Tag}getTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getTag(e))!==null&&n!==void 0?n:this.getInheritedTag(e)}setTagProperty(e,t=null,n="# "){this.getOrAddAnnotations().setTagProperty(e,t,n)}removeTagProperty(e,t="# "){this.getTag().has(...e)&&this.getOrAddAnnotations().removeTagProperty(e,t)}static fromReference(e,t,n){return new A({kind:"group_by",name:n,field:{expression:{kind:"field_reference",name:e,path:t}}})}}r.ASTGroupByViewOperation=A;class S extends d{constructor(e){super(e,{kind:"aggregate",name:e.name,field:new x(e.field)}),this.node=e,this.kind="aggregate"}get field(){return this.children.field}get name(){var e;const t=(e=this.children.name)!==null&&e!==void 0?e:this.field.name;if(t===void 0)throw new Error("Aggregate does not have a name");return t}set name(e){this.name!==e&&(this.edit(),this.field.name===e?this.children.name=void 0:this.children.name=e)}get annotations(){return this.field.annotations}rename(e){this.list.segment.renameField(this,e)}convertToCalculateMovingAverage(e,t,n=0,s=[]){if(!(this.field.expression instanceof U))throw new Error("Cannot convert aggregate to smoothed metric unless it is a field reference");this.list.remove(this);const a=new R({kind:"calculate",name:e,field:{expression:{kind:"moving_average",field_reference:{name:this.field.expression.name,path:this.field.expression.path},rows_preceding:t,rows_following:n,partition_fields:s.map(o=>({name:o}))}}});return this.list.add(a),a}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this),this.list.segment.propagateUp(e=>{e instanceof O&&e.removeOrderBys(this.name)})}getFieldInfo(){return{annotations:[{value:l.Tag.withPrefix("#(malloy) ").set(["calculation"]).toString()}],kind:"dimension",name:this.name,type:this.field.type}}getOrAddAnnotations(){return this.field.getOrAddAnnotations()}getInheritedTag(e="# "){return L(e,this.field.getInheritedAnnotations())}getIntrinsicTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getIntrinsicTag(e))!==null&&n!==void 0?n:new l.Tag}getTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getTag(e))!==null&&n!==void 0?n:this.getInheritedTag(e)}setTagProperty(e,t=null,n="# "){this.getOrAddAnnotations().setTagProperty(e,t,n)}removeTagProperty(e,t="# "){this.getTag().has(...e)&&this.getOrAddAnnotations().removeTagProperty(e,t)}addWhere(e,t,n){const s=Array.isArray(t)?t:[],a=n===void 0?t:n,o=typeof a=="string"?a:re(a),f=this.list.segment.getInputSchema(),u=k.schemaGet(f,e,s);ge(u,a);const m={filter:{kind:"filter_string",expression:{kind:"field_reference",name:e,path:s},filter:o}};if(this.field.expression instanceof Q)return this.field.expression.where.add(new j(m)),this.field.expression;if(this.field.expression instanceof U){const z=this.field.expression.build();return this.field.expression=new Q({kind:"filtered_field",field_reference:{name:z.name,path:z.path,parameters:z.parameters},where:[m]}),this.field.expression}else throw new Error("This kind of expression does not support addWhere")}static fromReference(e,t,n){return new S({kind:"aggregate",name:n,field:{expression:{kind:"field_reference",name:e,path:t}}})}}r.ASTAggregateViewOperation=S;class x extends d{constructor(e){super(e,{expression:r.ASTExpression.from(e.expression),annotations:e.annotations&&new D(e.annotations)}),this.node=e}get expression(){return this.children.expression}set expression(e){this.edit(),this.children.expression=e,e.parent=this}get name(){return this.expression.name}get type(){const e=this.expression.fieldType;if(e===void 0)throw new Error("Field expression does not have a type");return e}get annotations(){return this.children.annotations}set annotations(e){this.edit(),this.children.annotations=e}getReference(){if(!(this.expression instanceof ue))return this.expression.getReference()}getOrAddAnnotations(){if(this.annotations)return this.annotations;this.edit();const e=new D([]);return this.children.annotations=e,e.parent=this,e}getInheritedTag(e="# "){return L(e,this.getInheritedAnnotations())}getIntrinsicTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getIntrinsicTag(e))!==null&&n!==void 0?n:new l.Tag}getTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getTag(e))!==null&&n!==void 0?n:this.getInheritedTag(e)}setTagProperty(e,t=null,n="# "){this.getOrAddAnnotations().setTagProperty(e,t,n)}removeTagProperty(e,t="# "){this.getTag().has(...e)&&this.getOrAddAnnotations().removeTagProperty(e,t)}get segment(){return this.parent.list.segment}getInheritedAnnotations(){return this.expression.getInheritedAnnotations()}}r.ASTField=x,r.ASTExpression={from(i){switch(i.kind){case"field_reference":return new U(i);case"filtered_field":return new Q(i);case"time_truncation":return new ee(i);case"literal_value":return new ue(i);case"moving_average":return new ve(i)}}};class U extends d{constructor(e){super(e,{kind:e.kind,name:e.name,path:e.path,parameters:e.parameters&&new b(e.parameters)}),this.node=e,this.kind="field_reference"}get name(){return this.children.name}get parameters(){return this.children.parameters}set parameters(e){this.edit(),this.children.parameters=e}get segment(){const e=this.parent;if(e instanceof x)return e.segment;if(e instanceof ne||e instanceof C)return e.segment;throw new Error("Invalid expression parent")}get path(){return this.children.path}getReference(){return this.build()}getFieldInfo(){const e=this.segment.getInputSchema(),n=this.parent instanceof C&&this.parent.parent instanceof te?h.schemaGetDrillField(e,this.name,this.path):h.schemaGet(e,this.name,this.path);if(n.kind!=="dimension"&&n.kind!=="measure")throw new Error("Invalid field for ASTReferenceExpression");return n}get fieldType(){return this.getFieldInfo().type}getInheritedAnnotations(){var e;return(e=this.getFieldInfo().annotations)!==null&&e!==void 0?e:[]}getOrAddParameters(){return c.getOrAddParameters(this)}setParameter(e,t){return c.setParameter(this,e,t)}tryGetParameter(e){return c.tryGetParameter(this,e)}}r.ASTReferenceExpression=U;class ee extends d{constructor(e){super(e,{kind:e.kind,field_reference:new G(e.field_reference),truncation:e.truncation}),this.node=e,this.kind="time_truncation"}getReference(){return this.fieldReference.build()}get fieldReference(){return this.children.field_reference}get truncation(){return this.children.truncation}set truncation(e){this.edit(),this.children.truncation=e}get name(){return this.fieldReference.name}get field(){return this.parent.as.Field()}getFieldInfo(){const e=this.field.segment.getInputSchema(),t=h.schemaGet(e,this.name,this.fieldReference.path);if(t.kind!=="dimension"&&t.kind!=="measure")throw new Error("Invalid field for ASTReferenceExpression");return t}get fieldType(){const e=this.getFieldInfo();if(e.type.kind==="date_type")return{...e.type,timeframe:Ie(this.truncation)};if(e.type.kind==="timestamp_type"||e.type.kind==="timestamptz_type")return{...e.type,timeframe:this.truncation};throw new Error("This type of field cannot have a time truncation")}getInheritedAnnotations(){var e;return(e=this.getFieldInfo().annotations)!==null&&e!==void 0?e:[]}}r.ASTTimeTruncationExpression=ee;class ue extends d{constructor(e){super(e,{kind:e.kind,literal_value:r.ASTLiteralValue.from(e.literal_value)}),this.node=e,this.kind="time_truncation"}get name(){}get literalValue(){return this.children.literal_value}get fieldType(){return this.literalValue.fieldType}getInheritedAnnotations(){return[]}getFieldInfo(){}}r.ASTLiteralValueExpression=ue;class le extends M{constructor(e){super(e,e.map(t=>new G(t)))}}r.ASTFieldReferenceList=le;class ve extends d{constructor(e){super(e,{kind:e.kind,field_reference:new G(e.field_reference),rows_preceding:e.rows_preceding,rows_following:e.rows_following,partition_fields:new le(e.partition_fields||[])}),this.node=e,this.kind="moving_average"}getReference(){return this.fieldReference.build()}get fieldReference(){return this.children.field_reference}get rowsPreceding(){return this.children.rows_preceding}set rowsPreceding(e){this.edit(),this.children.rows_preceding=e}get rowsFollowing(){return this.children.rows_following}set rowsFollowing(e){this.edit(),this.children.rows_following=e}get name(){return this.fieldReference.name}get field(){return this.parent.as.Field()}get partitionFields(){return this.children.partition_fields}setPartitionFields(e){this.children.partition_fields=new le(e)}getFieldInfo(){const e=this.field.segment.getInputSchema(),t=h.schemaGet(e,this.name,this.fieldReference.path);if(t.kind!=="dimension"&&t.kind!=="measure")throw new Error("Invalid field for ASTReferenceExpression");return t}get fieldType(){return this.getFieldInfo().type}getInheritedAnnotations(){var e;return(e=this.getFieldInfo().annotations)!==null&&e!==void 0?e:[]}}r.ASTMovingAverageExpression=ve;class j extends d{constructor(e){super(e,{filter:r.ASTFilter.from(e.filter)})}get filter(){return this.children.filter}get list(){return this.parent.as.FilterOperationList()}delete(){this.list.remove(this)}}r.ASTFilterOperation=j;class he extends M{constructor(e){super(e,e.map(t=>new j(t)))}get expression(){return this.parent.as.FilteredFieldExpression()}}r.ASTFilterOperationList=he;class Q extends d{constructor(e){super(e,{kind:e.kind,field_reference:new G(e.field_reference),where:new he(e.where)}),this.node=e,this.kind="filtered_field"}getReference(){return this.fieldReference.build()}get fieldReference(){return this.children.field_reference}get name(){return this.fieldReference.name}get where(){return this.children.where}get field(){return this.parent.as.Field()}getFieldInfo(){const e=this.field.segment.getInputSchema(),t=h.schemaGet(e,this.name,this.fieldReference.path);if(t.kind!=="measure")throw new Error("Invalid field for ASTFilteredFieldExpression");return t}get fieldType(){return this.getFieldInfo().type}getInheritedAnnotations(){var e;return(e=this.getFieldInfo().annotations)!==null&&e!==void 0?e:[]}}r.ASTFilteredFieldExpression=Q;function Ie(i){switch(i){case"day":case"week":case"month":case"year":case"quarter":return i;default:throw new Error("Invalid date timeframe")}}class T extends d{constructor(e){super(e,{kind:"nest",name:e.name,view:new ie(e.view)}),this.node=e,this.kind="nest"}get view(){return this.children.view}get annotations(){return this.view.annotations}get name(){var e;const t=(e=this.children.name)!==null&&e!==void 0?e:this.view.name;if(t===void 0)throw new Error("Nest does not have a name");return t}set name(e){this.name!==e&&(this.edit(),this.view.name===e?this.children.name=void 0:this.children.name=e)}get list(){return this.parent.as.ViewOperationList()}getOrAddAnnotations(){return this.view.getOrAddAnnotations()}getInheritedTag(e="# "){return L(e,this.view.getInheritedAnnotations())}getIntrinsicTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getIntrinsicTag(e))!==null&&n!==void 0?n:new l.Tag}getTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getTag(e))!==null&&n!==void 0?n:this.getInheritedTag(e)}setTagProperty(e,t=null,n="# "){this.getOrAddAnnotations().setTagProperty(e,t,n)}removeTagProperty(e,t="# "){this.getTag().has(...e)&&this.getOrAddAnnotations().removeTagProperty(e,t)}delete(){this.list.remove(this)}rename(e){this.list.segment.renameField(this,e)}getFieldInfo(){return{kind:"view",name:this.name,definition:this.view.build(),schema:this.view.getOutputSchema()}}static fromReference(e,t,n){return new T({kind:"nest",name:n,view:{definition:{kind:"view_reference",name:e,path:t}}})}}r.ASTNestViewOperation=T;class fe extends d{constructor(e){super(e,{kind:"where",filter:r.ASTFilter.from(e.filter)}),this.node=e,this.kind="where"}get filter(){return this.children.filter}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}r.ASTWhereViewOperation=fe;class te extends d{constructor(e){super(e,{kind:"drill",filter:r.ASTFilter.from(e.filter)}),this.node=e,this.kind="drill"}get filter(){return this.children.filter}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}r.ASTDrillViewOperation=te;class ce extends d{constructor(e){super(e,{kind:"having",filter:r.ASTFilter.from(e.filter)}),this.node=e,this.kind="having"}get filter(){return this.children.filter}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}r.ASTHavingViewOperation=ce;class R extends d{constructor(e){super(e,{kind:"calculate",field:new x(e.field),name:e.name}),this.node=e,this.kind="calculate"}get expression(){return this.children.field.expression}set expression(e){this.edit(),this.children.field.expression=e,e.parent=this}get name(){return this.node.name}set name(e){this.name!==e&&(this.edit(),this.node.name=e)}getFieldInfo(){return{annotations:[{value:l.Tag.withPrefix("#(malloy) ").set(["calculation"]).toString()}],kind:"calculate",name:this.name,type:this.expression.fieldType}}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}}r.ASTCalculateViewOperation=R,r.ASTFilter={from(i){switch(i.kind){case"filter_string":return new ne(i);case"literal_equality":return new C(i)}},getSegment(i){const e=i.parent;return e instanceof j?e.list.expression.field.segment:e.list.segment}};class ne extends d{constructor(e){super(e,{kind:"filter_string",expression:r.ASTExpression.from(e.expression),filter:e.filter}),this.node=e,this.kind="filter_string"}get expression(){return this.children.expression}get filterString(){return this.children.filter}set filterString(e){this.edit(),this.children.filter=e}setFilterString(e){const t=this.getFilterType();me(this.filterString,t),this.filterString=e}get segment(){return r.ASTFilter.getSegment(this)}getFieldInfo(){const e=this.expression.getFieldInfo();if(e===void 0||e.kind!=="dimension"&&e.kind!=="measure")throw new Error("Invalid field type for filter with filter string");return e}getFilterType(){const e=this.getFieldInfo();return Oe(e)}setFilter(e){const t=this.getFilterType();if(t!==e.kind)throw new Error(`Invalid filter: expected type ${t}, got ${e.kind}`);this.filterString=re(e)}getFilter(){const e=this.getFilterType();return me(this.filterString,e)}}r.ASTFilterWithFilterString=ne;class C extends d{constructor(e){super(e,{kind:"literal_equality",expression:r.ASTExpression.from(e.expression),value:r.ASTLiteralValue.from(e.value)}),this.node=e,this.kind="literal_equality"}get expression(){return this.children.expression}get value(){return this.children.value}get segment(){return r.ASTFilter.getSegment(this)}}r.ASTFilterWithLiteralEquality=C;class ie extends d{constructor(e){super(e,{definition:v.from(e.definition),annotations:e.annotations&&new D(e.annotations)}),this.node=e}get definition(){return this.children.definition}set definition(e){this.edit(),this.children.definition=e,e.parent=this}get name(){return this.definition.getImplicitName()}getOrAddDefaultSegment(){return this.definition.getOrAddDefaultSegment()}get nest(){return this.parent.as.NestViewOperation()}getInputSchema(){return this.nest.list.segment.getInputSchema()}getOutputSchema(){return this.definition.getRefinementSchema()}propagateUp(e){this.propagateDown(e)}propagateDown(e){e(this.definition),this.definition.propagateDown(e)}reorderFields(e){this.definition instanceof O?this.definition.reorderFields(e):this.getOrAddAnnotations().setTagProperty(["field_order"],e)}get annotations(){return this.children.annotations}getOrAddAnnotations(){if(this.annotations)return this.annotations;this.edit();const e=new D([]);return this.children.annotations=e,e.parent=this,e}getInheritedAnnotations(){return this.definition.getInheritedAnnotations()}getInheritedTag(e="# "){return L(e,this.getInheritedAnnotations())}getIntrinsicTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getIntrinsicTag(e))!==null&&n!==void 0?n:new l.Tag}getTag(e="# "){var t,n;return(n=(t=this.annotations)===null||t===void 0?void 0:t.getTag(e))!==null&&n!==void 0?n:this.getInheritedTag(e)}setTagProperty(e,t=null,n="# "){this.getOrAddAnnotations().setTagProperty(e,t,n)}removeTagProperty(e,t="# "){this.getTag().has(...e)&&this.getOrAddAnnotations().removeTagProperty(e,t)}}r.ASTView=ie;class P extends d{get limit(){return this.children.limit}set limit(e){P.validateLimit(e),this.edit(),this.children.limit=e}constructor(e){super(e,{kind:e.kind,limit:e.limit}),this.node=e,this.kind="limit"}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this)}static validateLimit(e){if(!Number.isInteger(e))throw new Error("Limit must be an integer")}}r.ASTLimitViewOperation=P;function Fe(i){switch(i){case"dimension":return"group by";case"measure":return"aggregate";case"view":return"nest";case"join":return"join";case"calculate":return"calculate"}}function Me(i){return i}class D extends M{constructor(e){super(e,e.map(t=>new W(t)))}get items(){return this.children}getInheritedAnnotations(){return this.parent.getInheritedAnnotations()}getIntrinsicTag(e="# "){return L(e,this.items)}getTag(e="# "){return L(e,this.items,this.getInheritedAnnotations())}get annotations(){return this.children.map(e=>e.node)}setTagProperty(e,t=null,n="# "){let s;for(let a=this.items.length-1;a>=0;a--){const o=this.index(a);if(o.hasPrefix(n)&&(s=o,o.hasIntrinsicTagProperty(e))){o.setTagProperty(e,t);return}}s?s.setTagProperty(e,t):this.add(new W({value:new l.Tag({prefix:n}).set(e,t).toString()}))}removeTagProperty(e,t="# "){let n;for(let s=this.items.length-1;s>=0;s--){const a=this.index(s);if(a.hasPrefix(t)&&(n=a,a.hasIntrinsicTagProperty(e))){a.removeTagProperty(e);return}}n?n.removeTagProperty(e):this.add(new W({value:new l.Tag({prefix:t}).unset(...e).toString()}))}}r.ASTAnnotationList=D;class W extends d{get value(){return this.children.value}set value(e){this.edit(),this.children.value=e}constructor(e){super(e,{value:e.value}),this.node=e}get list(){return this.parent.as.AnnotationList()}get index(){return this.list.indexOf(this)}delete(){this.list.remove(this)}getIntrinsicTag(){const e=new l.TagParser;return e.parseAnnotation(this.value),e.finish()}getTag(){const e=new l.TagParser;for(const t of this.list.getInheritedAnnotations())e.parseAnnotation(t.value);for(let t=0;t<=this.index;t++)e.parseAnnotation(this.list.index(t).value);return e.finish()}hasPrefix(e){return this.value.startsWith(e)}hasIntrinsicTagProperty(e){return this.getIntrinsicTag().has(...e)}setTagProperty(e,t){this.value=this.getIntrinsicTag().set(e,t).toString()}removeTagProperty(e){this.value=this.getTag().unset(...e).toString()}}r.ASTAnnotation=W;function L(i,e=[],t=[]){const n=new l.TagParser;for(const a of t)n.parseAnnotation(a.value);const s=e.map(a=>a.value).filter(a=>typeof i=="string"?a.startsWith(i):a.match(i));for(const a of s)n.parseAnnotation(a);return n.finish()}function re(i){switch(i.kind){case"string":return p.StringFilterExpression.unparse(i.parsed);case"number":return p.NumberFilterExpression.unparse(i.parsed);case"boolean":return p.BooleanFilterExpression.unparse(i.parsed);case"timestamp":case"timestamptz":case"date":return p.TemporalFilterExpression.unparse(i.parsed)}}function me(i,e){function t(n){const s=n.filter(a=>a.severity==="error");if(s.length!==0)throw new Error(`Invalid Malloy filter string: ${s[0].message}`)}switch(e){case"string":{const n=p.StringFilterExpression.parse(i);return t(n.log),{kind:e,parsed:n.parsed}}case"number":{const n=p.NumberFilterExpression.parse(i);return t(n.log),{kind:e,parsed:n.parsed}}case"boolean":{const n=p.BooleanFilterExpression.parse(i);return t(n.log),{kind:e,parsed:n.parsed}}case"timestamp":case"timestamptz":case"date":{const n=p.TemporalFilterExpression.parse(i);return t(n.log),{kind:e,parsed:n.parsed}}case"other":throw new Error("Not implemented")}}function Re(i){return"kind"in i?i:{...i,kind:"source"}}function Pe(i){switch(i){case"year":case"quarter":case"month":case"week":case"day":return!0;default:return!1}}function B(i,e){return i.toString().padStart(e,"0")}function De(i){const e=B(i.getUTCFullYear(),4),t=B(i.getUTCMonth()+1,2),n=B(i.getUTCDate(),2),s=B(i.getUTCHours(),2),a=B(i.getUTCMinutes(),2),o=B(i.getUTCSeconds(),2);return`${e}-${t}-${n} ${s}:${a}:${o}`}function _e(i,e){const t=i??[],n=e??[];return t.length===n.length&&t.every((s,a)=>s===n[a])}function Oe(i){switch(i.type.kind){case"string_type":return"string";case"boolean_type":return"boolean";case"number_type":return"number";case"date_type":return"date";case"timestamp_type":return"timestamp";case"timestamptz_type":return"timestamp";default:return"other"}}function ge(i,e){if(i.kind!=="dimension"&&i.kind!=="measure")throw new Error(`Cannot filter by field of type ${i.kind}`);const t=Oe(i);if(typeof e=="string")me(e,t);else if(e.kind!==t)throw new Error(`Invalid filter for field ${i.name}; expected type ${t}, but got ${e.kind}`)}function pe(i){if(i instanceof y)return i.getSourceInfo().schema;if(i instanceof E)throw new Error("unimplemented");return i.getInputSchema()}})(V)),V}var ke;function Qe(){return ke||(ke=1,(function(r){var q=$&&$.__createBinding||(Object.create?(function(w,g,l,p){p===void 0&&(p=l);var h=Object.getOwnPropertyDescriptor(g,l);(!h||("get"in h?!g.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return g[l]}}),Object.defineProperty(w,p,h)}):(function(w,g,l,p){p===void 0&&(p=l),w[p]=g[l]})),N=$&&$.__exportStar||function(w,g){for(var l in w)l!=="default"&&!Object.prototype.hasOwnProperty.call(g,l)&&q(g,w,l)};Object.defineProperty(r,"__esModule",{value:!0}),N(xe(),r)})($)),$}var be=Qe();const Be=Ne(be),We=qe({__proto__:null,default:Be},[be]);export{be as d,We as i};
|