@malloy-publisher/server 0.0.248 → 0.0.250

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.
Files changed (29) hide show
  1. package/README.docker.md +5 -0
  2. package/README.md +5 -0
  3. package/dist/app/api-doc.html +5 -0
  4. package/dist/app/api-doc.yaml +444 -31
  5. package/dist/app/assets/{EnvironmentPage-DrTRtRHz.js → EnvironmentPage-CiuWaYTk.js} +1 -1
  6. package/dist/app/assets/HomePage-ZXsmEAjw.js +1 -0
  7. package/dist/app/assets/{LightMode-4Y7DEWAD.js → LightMode-10iLdX5H.js} +1 -1
  8. package/dist/app/assets/{MainPage-DKNR-8Vr.js → MainPage-u-IAaBdE.js} +2 -2
  9. package/dist/app/assets/{MaterializationsPage-h3ONDcgJ.js → MaterializationsPage-AcoL_Rnx.js} +1 -1
  10. package/dist/app/assets/ModelPage-BjB-p4Qn.js +1 -0
  11. package/dist/app/assets/{PackagePage-D8mM4T37.js → PackagePage-le809jUO.js} +1 -1
  12. package/dist/app/assets/{RouteError-DzJ0TPOj.js → RouteError-DTlqmNQd.js} +1 -1
  13. package/dist/app/assets/{ThemeEditorPage-BYvxc5op.js → ThemeEditorPage-DrmSzweH.js} +1 -1
  14. package/dist/app/assets/{WorkbookPage-CYOpAw7I.js → WorkbookPage-CIRFZXlP.js} +1 -1
  15. package/dist/app/assets/{core-BuvlzSIX.es-cZHBIpH6.js → core-Cr-9Wkp3.es-YhIv13au.js} +10 -10
  16. package/dist/app/assets/{index-BgMR5Uuv.js → index-CM5d1afN.js} +113 -113
  17. package/dist/app/assets/{index-BgAa2J25.js → index-CSFSsus4.js} +1 -1
  18. package/dist/app/assets/index-DP4bilgp.js +615 -0
  19. package/dist/app/assets/index-DdUOWgW6.js +2 -0
  20. package/dist/app/index.html +6 -1
  21. package/dist/package_load_worker.mjs +342 -2
  22. package/dist/runtime/publisher.js +3 -0
  23. package/dist/server.mjs +4361 -257
  24. package/dist/sshcrypto-vd2k5hq9.node +0 -0
  25. package/package.json +4 -2
  26. package/dist/app/assets/HomePage-X_Wozguy.js +0 -1
  27. package/dist/app/assets/ModelPage-B8Qsrbxn.js +0 -1
  28. package/dist/app/assets/index-BwoU1Ko8.js +0 -529
  29. package/dist/app/assets/index-CuaX7xuf.js +0 -18
@@ -0,0 +1,2 @@
1
+ import{aN as Je,aS as Ye}from"./index-DP4bilgp.js";import{r as He}from"./index-w_0OQJgZ.js";function Ke(i,I){for(var R=0;R<I.length;R++){const v=I[R];if(typeof v!="string"&&!Array.isArray(v)){for(const _ in v)if(_!=="default"&&!(_ in i)){const y=Object.getOwnPropertyDescriptor(v,_);y&&Object.defineProperty(i,_,y.get?y:{enumerable:!0,get:()=>v[_]})}}}return Object.freeze(Object.defineProperty(i,Symbol.toStringTag,{value:"Module"}))}var te={},ge={},Le;function Be(){return Le||(Le=1,Object.defineProperty(ge,"__esModule",{value:!0}),ge.MALLOY_INTERFACE_TYPES=void 0,ge.MALLOY_INTERFACE_TYPES={Aggregate:{type:"struct",name:"Aggregate",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},Annotation:{type:"struct",name:"Annotation",fields:{value:{type:"string",optional:!1,array:!1}}},AnonymousQueryInfo:{type:"struct",name:"AnonymousQueryInfo",fields:{schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},ArrayCell:{type:"struct",name:"ArrayCell",fields:{array_value:{type:"Cell",array:!0,optional:!1}}},ArrayType:{type:"struct",name:"ArrayType",fields:{element_type:{type:"AtomicType",optional:!1,array:!1}}},AtomicType:{type:"union",name:"AtomicType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",timestamptz_type:"TimestamptzType"}},BooleanCell:{type:"struct",name:"BooleanCell",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanLiteral:{type:"struct",name:"BooleanLiteral",fields:{boolean_value:{type:"boolean",optional:!1,array:!1}}},BooleanType:{type:"struct",name:"BooleanType",fields:{}},CalculateInfo:{type:"struct",name:"CalculateInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},CalculateOperation:{type:"struct",name:"CalculateOperation",fields:{name:{type:"string",optional:!1,array:!1},field:{type:"Field",optional:!1,array:!1}}},Cell:{type:"union",name:"Cell",options:{string_cell:"StringCell",boolean_cell:"BooleanCell",date_cell:"DateCell",timestamp_cell:"TimestampCell",number_cell:"NumberCell",json_cell:"JSONCell",record_cell:"RecordCell",array_cell:"ArrayCell",null_cell:"NullCell",sql_native_cell:"SQLNativeCell"}},CompileModelRequest:{type:"struct",name:"CompileModelRequest",fields:{model_url:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileModelResponse:{type:"struct",name:"CompileModelResponse",fields:{model:{type:"ModelInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompileQueryRequest:{type:"struct",name:"CompileQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!0,array:!1},query_malloy:{type:"string",optional:!0,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileQueryResponse:{type:"struct",name:"CompileQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},translations:{type:"Translation",array:!0,optional:!0},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompileSourceRequest:{type:"struct",name:"CompileSourceRequest",fields:{model_url:{type:"string",optional:!1,array:!1},name:{type:"string",optional:!1,array:!1},extend_model_url:{type:"string",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},CompileSourceResponse:{type:"struct",name:"CompileSourceResponse",fields:{source:{type:"SourceInfo",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},CompilerNeeds:{type:"struct",name:"CompilerNeeds",fields:{table_schemas:{type:"SQLTable",array:!0,optional:!0},sql_schemas:{type:"SQLQuery",array:!0,optional:!0},files:{type:"File",array:!0,optional:!0},connections:{type:"Connection",array:!0,optional:!0},translations:{type:"Translation",array:!0,optional:!0}}},Connection:{type:"struct",name:"Connection",fields:{name:{type:"string",optional:!1,array:!1},dialect:{type:"string",optional:!0,array:!1}}},Data:{type:"union",name:"Data",options:{record_cell:"RecordCell",array_cell:"ArrayCell"}},DateCell:{type:"struct",name:"DateCell",fields:{date_value:{type:"string",optional:!1,array:!1}}},DateLiteral:{type:"struct",name:"DateLiteral",fields:{date_value:{type:"string",optional:!1,array:!1},granularity:{type:"DateTimeframe",optional:!0,array:!1},timezone:{type:"string",optional:!0,array:!1}}},DateTimeframe:{type:"enum",name:"DateTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5}},DateType:{type:"struct",name:"DateType",fields:{timeframe:{type:"DateTimeframe",optional:!0,array:!1}}},DimensionInfo:{type:"struct",name:"DimensionInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},DocumentPosition:{type:"struct",name:"DocumentPosition",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},DocumentRange:{type:"struct",name:"DocumentRange",fields:{start:{type:"DocumentPosition",optional:!1,array:!1},end:{type:"DocumentPosition",optional:!1,array:!1}}},DrillOperation:{type:"struct",name:"DrillOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},Expression:{type:"union",name:"Expression",options:{field_reference:"Reference",time_truncation:"TimeTruncationFieldReference",filtered_field:"FilteredField",literal_value:"LiteralValueExpression",moving_average:"MovingAverage"}},Field:{type:"struct",name:"Field",fields:{expression:{type:"Expression",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},FieldInfo:{type:"union",name:"FieldInfo",options:{dimension:"DimensionInfo",measure:"MeasureInfo",join:"JoinInfo",view:"ViewInfo",calculate:"CalculateInfo"}},File:{type:"struct",name:"File",fields:{url:{type:"string",optional:!1,array:!1},contents:{type:"string",optional:!0,array:!1},invalidation_key:{type:"string",optional:!0,array:!1}}},Filter:{type:"union",name:"Filter",options:{filter_string:"FilterStringApplication",literal_equality:"LiteralEqualityComparison"}},FilterExpressionLiteral:{type:"struct",name:"FilterExpressionLiteral",fields:{filter_expression_value:{type:"string",optional:!1,array:!1}}},FilterExpressionType:{type:"struct",name:"FilterExpressionType",fields:{filter_type:{type:"FilterableType",optional:!1,array:!1}}},FilterOperation:{type:"struct",name:"FilterOperation",fields:{filter:{type:"Filter",optional:!1,array:!1}}},FilterStringApplication:{type:"struct",name:"FilterStringApplication",fields:{expression:{type:"Expression",optional:!1,array:!1},filter:{type:"string",optional:!1,array:!1}}},FilterableType:{type:"union",name:"FilterableType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",date_type:"DateType",timestamp_type:"TimestampType",timestamptz_type:"TimestamptzType"}},FilteredField:{type:"struct",name:"FilteredField",fields:{field_reference:{type:"Reference",optional:!1,array:!1},where:{type:"FilterOperation",array:!0,optional:!1}}},GroupBy:{type:"struct",name:"GroupBy",fields:{name:{type:"string",optional:!0,array:!1},field:{type:"Field",optional:!1,array:!1}}},JSONCell:{type:"struct",name:"JSONCell",fields:{json_value:{type:"string",optional:!1,array:!1}}},JSONType:{type:"struct",name:"JSONType",fields:{}},JoinInfo:{type:"struct",name:"JoinInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},relationship:{type:"Relationship",optional:!1,array:!1}}},Limit:{type:"struct",name:"Limit",fields:{limit:{type:"number",optional:!1,array:!1}}},LiteralEqualityComparison:{type:"struct",name:"LiteralEqualityComparison",fields:{expression:{type:"Expression",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},LiteralValue:{type:"union",name:"LiteralValue",options:{string_literal:"StringLiteral",number_literal:"NumberLiteral",date_literal:"DateLiteral",timestamp_literal:"TimestampLiteral",boolean_literal:"BooleanLiteral",null_literal:"NullLiteral",filter_expression_literal:"FilterExpressionLiteral"}},LiteralValueExpression:{type:"struct",name:"LiteralValueExpression",fields:{literal_value:{type:"LiteralValue",optional:!1,array:!1}}},Location:{type:"struct",name:"Location",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"Range",optional:!1,array:!1}}},LogMessage:{type:"struct",name:"LogMessage",fields:{url:{type:"string",optional:!1,array:!1},range:{type:"DocumentRange",optional:!1,array:!1},severity:{type:"LogSeverity",optional:!1,array:!1},message:{type:"string",optional:!1,array:!1}}},LogSeverity:{type:"enum",name:"LogSeverity",values:{debug:1,info:2,warn:3,error:4}},MeasureInfo:{type:"struct",name:"MeasureInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"AtomicType",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ModelEntryValue:{type:"union",name:"ModelEntryValue",options:{source:"SourceInfo",query:"QueryInfo"}},ModelInfo:{type:"struct",name:"ModelInfo",fields:{entries:{type:"ModelEntryValue",array:!0,optional:!1},annotations:{type:"Annotation",array:!0,optional:!0},anonymous_queries:{type:"AnonymousQueryInfo",array:!0,optional:!1}}},MovingAverage:{type:"struct",name:"MovingAverage",fields:{field_reference:{type:"Reference",optional:!1,array:!1},rows_preceding:{type:"number",optional:!0,array:!1},rows_following:{type:"number",optional:!0,array:!1},partition_fields:{type:"Reference",array:!0,optional:!0}}},Nest:{type:"struct",name:"Nest",fields:{name:{type:"string",optional:!0,array:!1},view:{type:"View",optional:!1,array:!1}}},NullCell:{type:"struct",name:"NullCell",fields:{}},NullLiteral:{type:"struct",name:"NullLiteral",fields:{}},NumberCell:{type:"struct",name:"NumberCell",fields:{number_value:{type:"number",optional:!1,array:!1},subtype:{type:"NumberSubtype",optional:!0,array:!1},string_value:{type:"string",optional:!0,array:!1}}},NumberLiteral:{type:"struct",name:"NumberLiteral",fields:{number_value:{type:"number",optional:!1,array:!1},string_value:{type:"string",optional:!0,array:!1}}},NumberSubtype:{type:"enum",name:"NumberSubtype",values:{integer:1,decimal:2,bigint:3}},NumberType:{type:"struct",name:"NumberType",fields:{subtype:{type:"NumberSubtype",optional:!0,array:!1}}},OrderBy:{type:"struct",name:"OrderBy",fields:{field_reference:{type:"Reference",optional:!1,array:!1},direction:{type:"OrderByDirection",optional:!0,array:!1}}},OrderByDirection:{type:"enum",name:"OrderByDirection",values:{asc:1,desc:2}},ParameterInfo:{type:"struct",name:"ParameterInfo",fields:{name:{type:"string",optional:!1,array:!1},type:{type:"ParameterType",optional:!1,array:!1},default_value:{type:"LiteralValue",optional:!0,array:!1}}},ParameterType:{type:"union",name:"ParameterType",options:{string_type:"StringType",boolean_type:"BooleanType",number_type:"NumberType",json_type:"JSONType",sql_native_type:"SQLNativeType",date_type:"DateType",timestamp_type:"TimestampType",array_type:"ArrayType",record_type:"RecordType",filter_expression_type:"FilterExpressionType",timestamptz_type:"TimestamptzType"}},ParameterValue:{type:"struct",name:"ParameterValue",fields:{name:{type:"string",optional:!1,array:!1},value:{type:"LiteralValue",optional:!1,array:!1}}},Position:{type:"struct",name:"Position",fields:{line:{type:"number",optional:!1,array:!1},character:{type:"number",optional:!1,array:!1}}},Query:{type:"struct",name:"Query",fields:{definition:{type:"QueryDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},QueryArrow:{type:"struct",name:"QueryArrow",fields:{source:{type:"QueryArrowSource",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},QueryArrowSource:{type:"union",name:"QueryArrowSource",options:{refinement:"QueryRefinement",source_reference:"Reference"}},QueryDefinition:{type:"union",name:"QueryDefinition",options:{arrow:"QueryArrow",query_reference:"Reference",refinement:"QueryRefinement"}},QueryInfo:{type:"struct",name:"QueryInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"Query",optional:!0,array:!1},code:{type:"string",optional:!0,array:!1},location:{type:"Location",optional:!0,array:!1}}},QueryRefinement:{type:"struct",name:"QueryRefinement",fields:{base:{type:"QueryDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},Range:{type:"struct",name:"Range",fields:{start:{type:"Position",optional:!1,array:!1},end:{type:"Position",optional:!1,array:!1}}},RecordCell:{type:"struct",name:"RecordCell",fields:{record_value:{type:"Cell",array:!0,optional:!1}}},RecordType:{type:"struct",name:"RecordType",fields:{fields:{type:"DimensionInfo",array:!0,optional:!1}}},Reference:{type:"struct",name:"Reference",fields:{name:{type:"string",optional:!1,array:!1},path:{type:"string",array:!0,optional:!0},parameters:{type:"ParameterValue",array:!0,optional:!0}}},Relationship:{type:"enum",name:"Relationship",values:{one:1,many:2,cross:3}},Result:{type:"struct",name:"Result",fields:{data:{type:"Data",optional:!0,array:!1},schema:{type:"Schema",optional:!1,array:!1},sql:{type:"string",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},model_annotations:{type:"Annotation",array:!0,optional:!0},query_timezone:{type:"string",optional:!0,array:!1},source_annotations:{type:"Annotation",array:!0,optional:!0}}},RunIndexQueryRequest:{type:"struct",name:"RunIndexQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},source_name:{type:"string",optional:!1,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunIndexQueryResponse:{type:"struct",name:"RunIndexQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},RunQueryRequest:{type:"struct",name:"RunQueryRequest",fields:{model_url:{type:"string",optional:!1,array:!1},query:{type:"Query",optional:!0,array:!1},query_malloy:{type:"string",optional:!0,array:!1},default_row_limit:{type:"number",optional:!0,array:!1},exclude_references:{type:"boolean",optional:!0,array:!1},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1}}},RunQueryResponse:{type:"struct",name:"RunQueryResponse",fields:{result:{type:"Result",optional:!0,array:!1},default_row_limit_added:{type:"number",optional:!0,array:!1},logs:{type:"LogMessage",array:!0,optional:!0},compiler_needs:{type:"CompilerNeeds",optional:!0,array:!1},timing_info:{type:"TimingInfo",optional:!0,array:!1}}},SQLNativeCell:{type:"struct",name:"SQLNativeCell",fields:{sql_native_value:{type:"string",optional:!1,array:!1}}},SQLNativeType:{type:"struct",name:"SQLNativeType",fields:{sql_type:{type:"string",optional:!0,array:!1}}},SQLQuery:{type:"struct",name:"SQLQuery",fields:{sql:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},SQLTable:{type:"struct",name:"SQLTable",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!0,array:!1},connection_name:{type:"string",optional:!1,array:!1}}},Schema:{type:"struct",name:"Schema",fields:{fields:{type:"FieldInfo",array:!0,optional:!1}}},SourceInfo:{type:"struct",name:"SourceInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},parameters:{type:"ParameterInfo",array:!0,optional:!0}}},StringCell:{type:"struct",name:"StringCell",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringLiteral:{type:"struct",name:"StringLiteral",fields:{string_value:{type:"string",optional:!1,array:!1}}},StringType:{type:"struct",name:"StringType",fields:{}},TimeTruncationFieldReference:{type:"struct",name:"TimeTruncationFieldReference",fields:{field_reference:{type:"Reference",optional:!1,array:!1},truncation:{type:"TimestampTimeframe",optional:!1,array:!1}}},TimestampCell:{type:"struct",name:"TimestampCell",fields:{timestamp_value:{type:"string",optional:!1,array:!1}}},TimestampLiteral:{type:"struct",name:"TimestampLiteral",fields:{timestamp_value:{type:"string",optional:!1,array:!1},granularity:{type:"TimestampTimeframe",optional:!0,array:!1},timezone:{type:"string",optional:!0,array:!1}}},TimestampTimeframe:{type:"enum",name:"TimestampTimeframe",values:{year:1,quarter:2,month:3,week:4,day:5,hour:6,minute:7,second:8}},TimestampType:{type:"struct",name:"TimestampType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimestamptzType:{type:"struct",name:"TimestamptzType",fields:{timeframe:{type:"TimestampTimeframe",optional:!0,array:!1}}},TimingInfo:{type:"struct",name:"TimingInfo",fields:{name:{type:"string",optional:!1,array:!1},duration_ms:{type:"number",optional:!1,array:!1},detailed_timing:{type:"TimingInfo",array:!0,optional:!0}}},Translation:{type:"struct",name:"Translation",fields:{url:{type:"string",optional:!1,array:!1},compiled_model_json:{type:"string",optional:!0,array:!1}}},View:{type:"struct",name:"View",fields:{definition:{type:"ViewDefinition",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0}}},ViewArrow:{type:"struct",name:"ViewArrow",fields:{source:{type:"ViewDefinition",optional:!1,array:!1},view:{type:"ViewDefinition",optional:!1,array:!1}}},ViewDefinition:{type:"union",name:"ViewDefinition",options:{arrow:"ViewArrow",view_reference:"Reference",refinement:"ViewRefinement",segment:"ViewSegment"}},ViewInfo:{type:"struct",name:"ViewInfo",fields:{name:{type:"string",optional:!1,array:!1},schema:{type:"Schema",optional:!1,array:!1},annotations:{type:"Annotation",array:!0,optional:!0},definition:{type:"View",optional:!0,array:!1}}},ViewOperation:{type:"union",name:"ViewOperation",options:{group_by:"GroupBy",aggregate:"Aggregate",order_by:"OrderBy",limit:"Limit",where:"FilterOperation",nest:"Nest",having:"FilterOperation",drill:"DrillOperation",calculate:"CalculateOperation"}},ViewRefinement:{type:"struct",name:"ViewRefinement",fields:{base:{type:"ViewDefinition",optional:!1,array:!1},refinement:{type:"ViewDefinition",optional:!1,array:!1}}},ViewSegment:{type:"struct",name:"ViewSegment",fields:{operations:{type:"ViewOperation",array:!0,optional:!1}}}}),ge}var we={},Oe={},_e={},Pe;function Ze(){return Pe||(Pe=1,Object.defineProperty(_e,"__esModule",{value:!0}),_e.RESERVED_WORDS=void 0,_e.RESERVED_WORDS=["all","and","as","asc","avg","boolean","by","case","cast","compose","count","date","day","days","desc","distinct","else","end","exclude","export","extend","false","filter","for","from","full","has","hour","hours","import","in","include","inner","internal","is","json","left","like","max","min","minute","minutes","month","months","not","now","null","number","on","or","pick","private","public","quarter","quarters","right","second","seconds","source","sql","string","sum","table","then","this","timestamp","timestamptz","to","true","virtual","week","weeks","when","with","year","years"]),_e}var Ne;function Xe(){if(Ne)return Oe;Ne=1,Object.defineProperty(Oe,"__esModule",{value:!0}),Oe.maybeQuoteIdentifier=R;const i=Ze();function I(v){const _=!v.match(/^[A-Za-z_][A-Za-z_0-9]*$/),y=i.RESERVED_WORDS.includes(v.toLowerCase());return _||y}function R(v){return I(v)?`\`${v}\``:v}return Oe}var $e;function je(){if($e)return we;$e=1,Object.defineProperty(we,"__esModule",{value:!0}),we.queryToMalloy=I,we.filterToMalloy=R;const i=Xe();function I(a,{tabWidth:o}={tabWidth:2}){const u=ie(a);return c(u,{tabWidth:o})}function R(a,{tabWidth:o}={tabWidth:2}){const u=Y(a);return c(u,{tabWidth:o})}const v=Symbol("indent"),_=Symbol("newline"),y=Symbol("outdent"),l=Symbol("optional_newline_indent");function c(a,{tabWidth:o}={tabWidth:2}){let u="",d=0,g=!0;for(const w of a)if(w===_)u+=`
2
+ `,g=!0;else if(w===y)d--;else if(w===v)d++;else{if(w===l)continue;g&&(u+=" ".repeat(d*o),g=!1),u+=w}return u}function m(a,o,u,d){var g;if(o.includes(_))return[a,_,v,...o,_,y,u];const F=((g=d?.spaces)!==null&&g!==void 0?g:!0)?" ":"";return[a,F,...o,F,u]}function h(a){return{contents:a,quoteCharacter:'"'}}function p(a,o){const u=[];for(let d=0;d<a.length;d++){const g=a[d];u.push(g),d<a.length-1&&u.push(o)}return u}function b(a){var o,u;switch(a.kind){case"filter_expression_literal":return[P(a.filter_expression_value)];case"boolean_literal":return[a.boolean_value.toString()];case"string_literal":{const{contents:d,quoteCharacter:g}=h(a.string_value);return[g,d,g]}case"number_literal":return[a.number_value.toString()];case"null_literal":return["null"];case"date_literal":return[L(S(a.date_value),(o=a.granularity)!==null&&o!==void 0?o:"day",a.timezone)];case"timestamp_literal":return[L(S(a.timestamp_value),(u=a.granularity)!==null&&u!==void 0?u:"second",a.timezone)]}}function S(a){let o;if(o=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)/.exec(a)){const[u,d,g,w,F,C,ee]=o;return[d,g,w,F,C,ee]}else if(o=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d)/.exec(a)){const[u,d,g,w,F,C]=o;return[d,g,w,F,C,"00"]}else if(o=/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d)(?:00)?/.exec(a)){const[u,d,g,w,F]=o;return[d,g,w,F,"00","00"]}else if(o=/(\d\d\d\d)-(\d\d)-(\d\d)/.exec(a)){const[u,d,g,w]=o;return[d,g,w,"00","00","00"]}else if(o=/(\d\d\d\d)-(\d\d)/.exec(a)){const[u,d,g]=o;return[d,g,"01","00","00","00"]}else if(o=/(\d\d\d\d)/.exec(a)){const[u,d]=o;return[d,"01","01","00","00","00"]}return["1970","01","01","00","00","00"]}function L([a,o,u,d,g,w],F,C){switch(F){case"year":return`@${a}`;case"quarter":{const ee=Math.floor(+o/3)+1;return`@${a}-Q${ee}`}case"month":return`@${a}-${o}`;case"week":return`@${a}-${o}-${u}-WK`;case"day":return`@${a}-${o}-${u}`;case"hour":return`@${a}-${o}-${u} ${d}`;case"minute":return`@${a}-${o}-${u} ${d}:${g}`;case"second":return C!==void 0?`@${a}-${o}-${u} ${d}:${g}:${w}[${C}]`:`@${a}-${o}-${u} ${d}:${g}:${w}`;default:throw new Error("Unknown timeframe.")}}function O(a){var o;const u=[];for(const d of(o=a.path)!==null&&o!==void 0?o:[])u.push((0,i.maybeQuoteIdentifier)(d)),u.push(".");if(u.push((0,i.maybeQuoteIdentifier)(a.name)),a.parameters){const d=[];for(let g=0;g<a.parameters.length;g++){const w=a.parameters[g];d.push((0,i.maybeQuoteIdentifier)(w.name)),d.push(" is "),d.push(...b(w.value)),g<a.parameters.length-1&&d.push(",",_)}u.push(...m("(",d,")",{spaces:!1}))}return u}function ie(a){const o=[];return o.push(...U(a.annotations)),o.push("run: "),o.push(...ae(a.definition)),o}function de(a){const o=[];switch(a.kind){case"source_reference":{o.push(...O(a));break}case"refinement":o.push(...ae(a));break}return o}function ae(a){const o=[];switch(a.kind){case"arrow":{o.push(...de(a.source)),o.push(" -> "),o.push(...q(a.view));break}case"query_reference":{o.push(...O(a));break}case"refinement":{const u=ae(a.base);a.base.kind==="arrow"?o.push(...m("(",u,")",{spaces:!1})):o.push(...u),o.push(" + "),o.push(...q(a.refinement));break}}return o}function q(a){const o=[];switch(a.kind){case"arrow":{o.push(...q(a.source)),o.push(" -> "),o.push(...q(a.view));break}case"view_reference":{o.push(...O(a));break}case"refinement":{o.push(...q(a.base)),o.push(" + "),o.push(...q(a.refinement));break}case"segment":{o.push(...Te(a));break}}return o}function Te(a){if(a.operations.length===0)return["{ }"];const o=a.operations.length>1,u=[];for(let d=0;d<a.operations.length;d++){const g=a.operations[d],w=[g];for(;d<a.operations.length-1;){const F=a.operations[d+1];if(F.kind===g.kind)w.push(F),d++;else break}u.push(...Ae(w)),o&&d<a.operations.length-1&&u.push(_)}return m("{",u,"}")}function Ae(a){switch(a[0].kind){case"aggregate":return z(a,"aggregate");case"group_by":return z(a,"group_by");case"order_by":return se(a);case"nest":return B(a);case"limit":return Q(a);case"where":return $(a);case"having":return G(a);case"drill":return ce(a);case"calculate":return z(a,"calculate")}}function x(a,o,u=""){const d=[];d.push(`${a}:`);const g=o.length>1||o.some(w=>w.includes(_));g?d.push(_,v):d.push(" ");for(let w=0;w<o.length;w++){const F=o[w];d.push(...F),o.length>1&&w<o.length-1&&d.push(u),g&&w<o.length-1&&d.push(_)}return g&&d.push(y),d}function ve(a){const o=[];return o.push(...E(a.expression)),o}function Ee(a){return a}function E(a){var o;switch(a.kind){case"field_reference":return O(a);case"time_truncation":return[...O(a.field_reference),".",a.truncation];case"filtered_field":return[...O(a.field_reference),...m(" {",$(a.where),"}")];case"literal_value":return b(a.literal_value);case"moving_average":{const u=["avg_moving",...m("(",[...O(a.field_reference),a.rows_preceding!==void 0?`, ${a.rows_preceding}`:", 0",a.rows_following!==void 0?`, ${a.rows_following}`:""],")",{spaces:!1})];return!((o=a.partition_fields)===null||o===void 0)&&o.length&&u.push(...m(" {",["partition_by",": ",...p(a.partition_fields.flatMap(d=>O(d)),", ")],"}")),u}}}function M(a,o=!1){const u=[];return o||u.push(...U(a.field.annotations)),a.name&&(u.push((0,i.maybeQuoteIdentifier)(a.name)),u.push(" is ")),u.push(...ve(a.field)),u}function z(a,o){const u=[],d=a.length===1;return d&&u.push(...U(a[0].field.annotations)),u.push(...x(o,a.map(g=>M(g,d)))),u}function se(a){return x("order_by",a.map(N),",")}function N(a){const o=[];return o.push(...O(a.field_reference)),a.direction&&(o.push(" "),o.push(a.direction)),o}function B(a){const o=[],u=a.length===1;return u&&o.push(...U(a[0].view.annotations)),o.push(...x("nest",a.map(d=>oe(d,u)))),o}function oe(a,o=!1){const u=[];return o||u.push(...U(a.view.annotations)),a.name&&(u.push((0,i.maybeQuoteIdentifier)(a.name)),u.push(" is ")),u.push(...le(a.view)),u}function le(a){return q(a.definition)}function ue(a){return[`limit: ${a.limit}`]}function Q(a){const o=[];for(let u=0;u<a.length;u++)u!==0&&o.push(_),o.push(...ue(a[u]));return o}function $(a){return x("where",a.map(H),",")}function ce(a){return x("drill",a.map(H),",")}function G(a){return x("having",a.map(H),",")}const D=["`","'",'"'];function P(a){let o,u;for(const d of D){const g=J(a,d);if(g===a)return`f${d}${a}${d}`;(u===void 0||g.length<u.length)&&(o=d,u=g)}return`f${o}${u}${o}`}function J(a,o){let u="";for(let d=0;d<a.length;d++)a.slice(d).startsWith(o)?(u+="\\"+o,d+=o.length):(u+=a[d],a[d]==="\\"&&(u+=a[++d]));return u}function Y(a){switch(a.kind){case"filter_string":return[...E(a.expression)," ~ ",P(a.filter)];case"literal_equality":return[...E(a.expression)," = ",...b(a.value)]}}function H(a){return Y(a.filter)}function U(a){return a?a.flatMap(pe):[]}function pe(a){return[a.value.trim(),_]}return we}var ne={},Qe;function et(){if(Qe)return ne;Qe=1,Object.defineProperty(ne,"__esModule",{value:!0}),ne.nestUnions=I,ne.unnestUnions=R,ne.convertFromThrift=v,ne.convertToThrift=y;const i=Be();function I(l){if(l==null)return l;if(typeof l=="string"||typeof l=="number"||typeof l=="boolean")return l;if(Array.isArray(l))return l.map(I);{const c={};let m;for(const h in l)h==="kind"?m=l[h]:c[h]=I(l[h]);return m===void 0?c:{[m]:c}}}function R(l,c){if(l==null)return l;if(typeof l=="string"||typeof l=="number"||typeof l=="boolean")return l;if(Array.isArray(l))return l.map(m=>R(m,c));{const m=_(c);if(m.type==="union"){for(const h in m.options)if(l[h]!==void 0){const p=R(l[h],m.options[h]);if(typeof p=="object")return{kind:h,...p}}}else if(m.type==="struct"){const h={};for(const p in l){const b=m.fields[p];if(b===void 0)throw new Error(`Unknown field ${p} in ${c}`);h[p]=R(l[p],b.type)}return h}else throw new Error(`Cannot unnest unions in an enum type ${c}`)}}function v(l,c){if(l==null)return l;if(typeof l=="string"||typeof l=="boolean")return l;if(typeof l=="number"){if(c==="number")return l;const m=_(c);if(m.type!=="enum")throw new Error(`Found a number where a ${c} was expected`);const h=Object.entries(m.values).find(([,p])=>p===l);if(h===void 0)throw new Error(`${l} is not a valid enum value for ${c}`);return h[0]}else{if(Array.isArray(l))return l.map(m=>v(m,c));{const m=_(c);if(m.type==="union"){for(const h in m.options)if(l[h]!==void 0&&l[h]!==null){const p=v(l[h],m.options[h]);if(typeof p=="object")return{kind:h,...p}}}else if(m.type==="struct"){const h={};for(const p in l){const b=m.fields[p];if(b===void 0)throw new Error(`Unknown field ${p} in ${c}`);h[p]=v(l[p],b.type)}return h}else throw new Error(`Cannot unnest unions in an enum type ${c}`)}}}function _(l){const c=i.MALLOY_INTERFACE_TYPES[l];if(c===void 0)throw new Error(`Unknown Malloy interface type ${l}`);return c}function y(l,c){if(l==null)return l;if(typeof l=="number"||typeof l=="boolean")return l;if(typeof l=="string"){if(c==="string")return l;const m=_(c);if(m.type==="enum"){const h=m.values[l];if(h===void 0)throw new Error(`${l} is not a valid enum value for ${c}`);return h}}else{if(Array.isArray(l))return l.map(m=>y(m,c));{const m=_(c);if(m.type==="union"){const h=l.kind,p=m.options[h];if(p===void 0)throw new Error(`${h} is not a valid union of ${c}`);const b=_(p);if(b.type!=="struct")throw new Error("Union fields must be structs");const S={};for(const L in l){if(L==="kind")continue;const O=b.fields[L];S[L]=y(l[L],O.type)}return{[h]:S}}else if(m.type==="struct"){const h={};for(const p in l){const b=m.fields[p];if(b===void 0)throw new Error(`Unknown field ${p} in ${c}`);h[p]=y(l[p],b.type)}return h}}}}return ne}var qe;function tt(){return qe||(qe=1,(function(i){var I=te&&te.__createBinding||(Object.create?(function(y,l,c,m){m===void 0&&(m=c);var h=Object.getOwnPropertyDescriptor(l,c);(!h||("get"in h?!l.__esModule:h.writable||h.configurable))&&(h={enumerable:!0,get:function(){return l[c]}}),Object.defineProperty(y,m,h)}):(function(y,l,c,m){m===void 0&&(m=c),y[m]=l[c]})),R=te&&te.__exportStar||function(y,l){for(var c in y)c!=="default"&&!Object.prototype.hasOwnProperty.call(l,c)&&I(l,y,c)};Object.defineProperty(i,"__esModule",{value:!0}),i.thingy4sddfdfsd=i.thingy4sdfsd=i.thingy4dfdsfs=i.thingy4asdfas=i.thingy4asdfasdf=i.thingy3dfdf=i.thingy3=i.thingy2asdf=i.thingyssdfg=i.thingy123r=i.thingy1=i.res=i.test=i.convertToThrift=i.convertFromThrift=i.unnestUnions=i.nestUnions=i.filterToMalloy=i.queryToMalloy=void 0,R(Be(),i);var v=je();Object.defineProperty(i,"queryToMalloy",{enumerable:!0,get:function(){return v.queryToMalloy}}),Object.defineProperty(i,"filterToMalloy",{enumerable:!0,get:function(){return v.filterToMalloy}});var _=et();Object.defineProperty(i,"nestUnions",{enumerable:!0,get:function(){return _.nestUnions}}),Object.defineProperty(i,"unnestUnions",{enumerable:!0,get:function(){return _.unnestUnions}}),Object.defineProperty(i,"convertFromThrift",{enumerable:!0,get:function(){return _.convertFromThrift}}),Object.defineProperty(i,"convertToThrift",{enumerable:!0,get:function(){return _.convertToThrift}}),i.test={entries:[{kind:"source",name:"flights",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"boolean_type"},annotations:[{value:"# foo=1"}]},{kind:"dimension",name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}},{kind:"dimension",name:"arr_rec",type:{kind:"array_type",element_type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}}},{kind:"dimension",name:"rec",type:{kind:"record_type",fields:[{name:"arr",type:{kind:"array_type",element_type:{kind:"boolean_type"}}}]}},{kind:"join",name:"carriers",relationship:"one",schema:{fields:[{kind:"dimension",name:"code",type:{kind:"string_type"}}]}},{kind:"view",name:"by_carrier",schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]}}]},parameters:[{name:"param",type:{kind:"number_type"},default_value:{kind:"number_literal",number_value:7}}]}],anonymous_queries:[]},i.res={connection_name:"foo",data:{kind:"array_cell",array_value:[{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"UA"},{kind:"number_cell",number_value:12341234}]},{kind:"record_cell",record_value:[{kind:"string_cell",string_value:"AA"},{kind:"number_cell",number_value:2343}]}]},schema:{fields:[{kind:"dimension",name:"carrier",type:{kind:"string_type"}},{kind:"dimension",name:"flight_count",type:{kind:"number_type"}}]},sql:"SELECT * ..."},i.thingy1={definition:{kind:"query_reference",name:"flights_by_carrier"}},i.thingy123r={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},i.thingyssdfg={definition:{kind:"refinement",base:{kind:"query_reference",name:"flights"},refinement:{kind:"view_reference",name:"by_carrier"}}},i.thingy2asdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"where",filter:{kind:"filter_string",expression:{kind:"field_reference",name:"carrier"},filter:"WN"}}]}}}},i.thingy3={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}}},i.thingy3dfdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"view_reference",name:"top10"}}}},i.thingy4asdfasdf={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"group_by",field:{expression:{kind:"field_reference",name:"foo"}}}]}}},i.thingy4asdfas={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"view_reference",name:"by_carrier"}}},i.thingy4dfdsfs={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"refinement",base:{kind:"view_reference",name:"by_carrier"},refinement:{kind:"segment",operations:[{kind:"limit",limit:10}]}}}},i.thingy4sdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[{kind:"group_by",field:{expression:{kind:"field_reference",name:"carrier"}}},{kind:"limit",limit:10}]}}},i.thingy4sddfdfsd={definition:{kind:"arrow",source:{kind:"source_reference",name:"flights"},view:{kind:"segment",operations:[]}}}})(te)),te}var re={},W={},Ce;function nt(){return Ce||(Ce=1,(function(i){var I=W&&W.__createBinding||(Object.create?(function(r,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(r,n,s)}):(function(r,e,t,n){n===void 0&&(n=t),r[n]=e[t]})),R=W&&W.__setModuleDefault||(Object.create?(function(r,e){Object.defineProperty(r,"default",{enumerable:!0,value:e})}):function(r,e){r.default=e}),v=W&&W.__importStar||(function(){var r=function(e){return r=Object.getOwnPropertyNames||function(t){var n=[];for(var s in t)Object.prototype.hasOwnProperty.call(t,s)&&(n[n.length]=s);return n},r(e)};return function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var n=r(e),s=0;s<n.length;s++)n[s]!=="default"&&I(t,e,n[s]);return R(t,e),t}})();Object.defineProperty(i,"__esModule",{value:!0}),i.ASTAnnotationList=i.ASTLimitViewOperation=i.ASTView=i.ASTFilterWithLiteralEquality=i.ASTFilterWithFilterString=i.ASTFilter=i.ASTCalculateViewOperation=i.ASTHavingViewOperation=i.ASTDrillViewOperation=i.ASTWhereViewOperation=i.ASTNestViewOperation=i.ASTFilteredFieldExpression=i.ASTFilterOperationList=i.ASTFilterOperation=i.ASTMovingAverageExpression=i.ASTFieldReferenceList=i.ASTLiteralValueExpression=i.ASTTimeTruncationExpression=i.ASTReferenceExpression=i.ASTExpression=i.ASTField=i.ASTAggregateViewOperation=i.ASTGroupByViewOperation=i.ASTOrderByViewOperation=i.ASTViewOperation=i.ASTViewOperationList=i.ASTSegmentViewDefinition=i.ASTRefinementViewDefinition=i.ASTArrowViewDefinition=i.ASTReferenceViewDefinition=i.ASTReferenceQueryArrowSource=i.ASTReferenceQueryDefinition=i.ASTRefinementQueryDefinition=i.ASTArrowQueryDefinition=i.ASTQueryDefinition=i.ASTQueryArrowSource=i.ASTUnimplemented=i.ASTFilterExpressionLiteralValue=i.ASTTimestampLiteralValue=i.ASTDateLiteralValue=i.ASTBooleanLiteralValue=i.ASTNumberLiteralValue=i.ASTNullLiteralValue=i.ASTStringLiteralValue=i.ASTLiteralValue=i.ASTParameterValue=i.ASTParameterValueList=i.ASTFieldReference=i.ASTReference=i.ASTQuery=void 0,i.ASTAnnotation=void 0;const _=v(tt()),y=He(),l=v(Je());class c{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 b)return e;throw new Error("Not an ASTQuery")},Reference(){if(e instanceof S)return e;throw new Error("Not an ASTReference")},ReferenceQueryArrowSource(){if(e instanceof se)return e;throw new Error("Not an ASTReferenceQueryArrowSource")},ParameterValueList(){if(e instanceof O)return e;throw new Error("Not an ASTParameterValueList")},FilterOperation(){if(e instanceof o)return e;throw new Error("Not an ASTFilterOperation")},FilterOperationList(){if(e instanceof u)return e;throw new Error("Not an ASTFilterOperationList")},ParameterValue(){if(e instanceof ie)return e;throw new Error("Not an ASTParameterValue")},StringLiteralValue(){if(e instanceof de)return e;throw new Error("Not an ASTStringLiteralValue")},NumberLiteralValue(){if(e instanceof q)return e;throw new Error("Not an ASTNumberLiteralValue")},ViewOperationList(){if(e instanceof ce)return e;throw new Error("Not an ASTViewOperationList")},GroupByViewOperation(){if(e instanceof D)return e;throw new Error("Not an ASTGroupByViewOperation")},AggregateViewOperation(){if(e instanceof P)return e;throw new Error("Not an ASTAggregateViewOperation")},OrderByViewOperation(){if(e instanceof G)return e;throw new Error("Not an ASTOrderByViewOperation")},Field(){if(e instanceof J)return e;throw new Error("Not an ASTField")},ReferenceExpression(){if(e instanceof Y)return e;throw new Error("Not an ASTReferenceExpression")},ReferenceViewDefinition(){if(e instanceof le)return e;throw new Error("Not an ASTReferenceViewDefinition")},ArrowQueryDefinition(){if(e instanceof E)return e;throw new Error("Not an ASTArrowQueryDefinition")},ArrowViewDefinition(){if(e instanceof ue)return e;throw new Error("Not an ASTArrowViewDefinition")},RefinementViewDefinition(){if(e instanceof Q)return e;throw new Error("Not an ASTRefinementViewDefinition")},TimeTruncationExpression(){if(e instanceof H)return e;throw new Error("Not an ASTTimeTruncationExpression")},FilteredFieldExpression(){if(e instanceof d)return e;throw new Error("Not an ASTFilteredFieldExpression")},NestViewOperation(){if(e instanceof w)return e;throw new Error("Not an ASTNestViewOperation")},View(){if(e instanceof ke)return e;throw new Error("Not an ASTView")},SegmentViewDefinition(){if(e instanceof $)return e;throw new Error("Not an ASTSegmentViewDefinition")},LimitViewOperation(){if(e instanceof Z)return e;throw new Error("Not an ASTLimitViewOperation")},AnnotationList(){if(e instanceof X)return e;throw new Error("Not an ASTAnnotationList")},Annotation(){if(e instanceof he)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 c._schemaTryGet(e,t,n,!1)}static schemaTryGetDrillField(e,t,n){return c._schemaTryGet(e,t,n,!0)}static _schemaTryGet(e,t,n,s){let f=e.fields;for(const k of n??[]){const A=f.find(V=>V.name===k);if(A===void 0)throw new Error(`${k} not found`);if(A.kind==="join"||s&&A.kind==="view"){f=A.schema.fields;continue}if(A.kind==="dimension"||A.kind==="measure"){if(A.type.kind==="record_type"){f=A.type.fields.map(V=>({kind:A.kind,...V}));continue}else if(A.type.kind==="array_type"&&A.type.element_type.kind==="record_type"){f=A.type.element_type.fields.map(V=>({kind:A.kind,...V}));continue}}throw new Error(`${k} is not a join, record, or repeated record`)}return f.find(k=>k.name===t)}static schemaGet(e,t,n){const s=c.schemaTryGet(e,t,n);if(s===void 0)throw new Error(`${t} not found`);return s}static schemaGetDrillField(e,t,n){const s=c.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 f=(s=(n=e.annotations)===null||n===void 0?void 0:n.map(k=>k.value))===null||s===void 0?void 0:s.filter(k=>k.startsWith(t)),T=new y.TagParser;for(const k of f??[])T.parseAnnotation(k);return T.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 c.tagFor(e,"#(malloy) ").has("calculation")}}function m(r){return Array.isArray(r)||typeof r=="string"||typeof r=="number"||typeof r=="boolean"}class h extends c{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 p extends c{constructor(e,t){super(),this.node=e,this.children=t;for(const n in t){const s=t[n];s&&!m(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}:m(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(m(s))throw new Error(`${this.constructor.name}.${t} refers to a basic type, not an ASTNode`);return s._find(n)}}class b extends p{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 A=e.query.definition;if(A.kind==="arrow"&&A.source.kind==="source_reference"){const V=A.source.name;if(s=e.model.entries.find(ye=>ye.name===V),s===void 0)throw new Error(`Model does not contain source or query named ${V}`)}}if(s===void 0&&(s=e.model.entries[0]),s===void 0)throw new Error("Model does not contain any sources or queries")}const f=Ue(s),T=(t=e.query)!==null&&t!==void 0?t:{definition:{kind:"arrow",source:{kind:"source_reference",name:f.name},view:{kind:"segment",operations:[]}}},k=(n=e.model)!==null&&n!==void 0?n:{entries:[f],anonymous_queries:[]};super(T,{definition:i.ASTQueryDefinition.from(T.definition),annotations:T.annotations&&new X(T.annotations)}),this.model=k,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 X([]);return this.children.annotations=e,e.parent=this,e}getInheritedTag(e="# "){return j(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 y.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 E))throw new Error("Must set source before setting view");return this.definition=new E({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 E&&this.definition.view instanceof $&&this.definition.view.operations.length===0}getOrAddDefaultSegment(){return this.definition.getOrAddDefaultSegment()}setSource(e){if(this.definition instanceof E&&this.definition.source instanceof se&&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 E({kind:"arrow",source:{kind:"source_reference",name:e},view:this.definition instanceof E?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 z({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 _.queryToMalloy(this.build())}build(){return super.build()}setView(e){if(!(this.definition instanceof E))throw new Error("Must set source before setting view");return this.definition=new E({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 z?(t=this.getQueryInfo(e.name).annotations)!==null&&t!==void 0?t:[]:e instanceof M?this._getInheritedAnnotations(e.base):e instanceof E?e.view.getInheritedAnnotations():[]}getInheritedAnnotations(){return this._getInheritedAnnotations(this.definition)}}i.ASTQuery=b;class S extends p{constructor(e){super(e,{name:e.name,path:e.path,parameters:e.parameters&&new O(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 O([]);return e.parameters=t,t}static setParameter(e,t,n){const s=S.tryGetParameter(e,t);if(s!==void 0){s.value=i.ASTLiteralValue.from(i.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 S.getOrAddParameters(this)}setParameter(e,t){return S.setParameter(this,e,t)}tryGetParameter(e){return S.tryGetParameter(this,e)}}i.ASTReference=S;class L extends S{get segment(){const e=this.parent;return e instanceof d||e instanceof H?e.field.segment:e instanceof Se||e instanceof me?e.segment:e.list.segment}getReferenceSchema(){return this.parent instanceof G?this.segment.getOutputSchema():this.segment.getInputSchema()}getFieldInfo(){const e=this.getReferenceSchema();return c.schemaGet(e,this.name,this.path)}}i.ASTFieldReference=L;class O extends h{constructor(e){super(e,e.map(t=>new ie(t)))}get parameters(){return this.children}addParameter(e,t){this.add(new ie({name:e,value:i.ASTLiteralValue.makeLiteral(t)}))}}i.ASTParameterValueList=O;class ie extends p{constructor(e){super(e,{name:e.name,value:i.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}}i.ASTParameterValue=ie,i.ASTLiteralValue={from(r){switch(r.kind){case"string_literal":return new de(r);case"number_literal":return new q(r);case"boolean_literal":return new Te(r);case"date_literal":return new Ae(r);case"timestamp_literal":return new x(r);case"null_literal":return new ae(r);case"filter_expression_literal":return new ve(r)}},makeLiteral(r){if(r!==null&&typeof r=="object"&&"kind"in r)return r;if(typeof r=="string")return{kind:"string_literal",string_value:r};if(typeof r=="boolean")return{kind:"boolean_literal",boolean_value:r};if(typeof r=="number")return{kind:"number_literal",number_value:r};if(r===null)return{kind:"null_literal"};if("date"in r){const e=r.granularity,t=ze(r.date);return We(e)?{kind:"date_literal",date_value:t,granularity:e}:{kind:"timestamp_literal",timestamp_value:t,granularity:e}}throw new Error("Unknown literal type")}};class de extends p{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"}}}i.ASTStringLiteralValue=de;class ae extends p{constructor(e){super(e,{kind:e.kind}),this.node=e,this.kind="null_literal"}get fieldType(){}}i.ASTNullLiteralValue=ae;class q extends p{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"}}}i.ASTNumberLiteralValue=q;class Te extends p{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"}}}i.ASTBooleanLiteralValue=Te;class Ae extends p{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}}}i.ASTDateLiteralValue=Ae;class x extends p{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}}}i.ASTTimestampLiteralValue=x;class ve extends p{constructor(e){super(e,{kind:e.kind,filter_expression_value:e.filter_expression_value}),this.node=e,this.kind="filter_expression_literal"}get fieldType(){}}i.ASTFilterExpressionLiteralValue=ve;class Ee extends c{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")}}i.ASTUnimplemented=Ee,i.ASTQueryArrowSource={from(r){switch(r.kind){case"refinement":return new M(r);case"source_reference":return new se(r)}}},i.ASTQueryDefinition={from(r){switch(r.kind){case"arrow":return new E(r);case"query_reference":return new z(r);case"refinement":return new M(r)}}};class E extends p{constructor(e){super(e,{kind:"arrow",source:i.ASTQueryArrowSource.from(e.source),view:N.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 $?this.view.reorderFields(e):this.query.getOrAddAnnotations().setTagProperty(["field_order"],e)}}i.ASTArrowQueryDefinition=E;class M extends p{constructor(e){super(e,{kind:"refinement",base:i.ASTQueryDefinition.from(e.base),refinement:N.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 b.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()}}i.ASTRefinementQueryDefinition=M;class z extends p{constructor(e){super(e,{kind:"query_reference",name:e.name,path:e.path,parameters:e.parameters&&new O(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 M({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 S.getOrAddParameters(this)}setParameter(e,t){return S.setParameter(this,e,t)}tryGetParameter(e){return S.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}}i.ASTReferenceQueryDefinition=z;class se extends p{constructor(e){super(e,{kind:"source_reference",name:e.name,path:e.path,parameters:e.parameters&&new O(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 M({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 S.getOrAddParameters(this)}setParameter(e,t){return S.setParameter(this,e,t)}tryGetParameter(e){return S.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}}i.ASTReferenceQueryArrowSource=se;const N={from(r){switch(r.kind){case"arrow":return new ue(r);case"view_reference":return new le(r);case"segment":return new $(r);case"refinement":return new Q(r)}}};function B(r,e){const t=r.parent;t instanceof E?t.view=e:t instanceof M?t.refinement=e:t instanceof ke?t.definition=e:t instanceof ue?t.source===r?t.source=e:t.view=e:t.base===r?t.base=e:t.refinement=e}function oe(r,e,t=[]){const n=r.getInputSchema(),s=b.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 f=r.getOutputSchema();for(const T of s.schema.fields)if(b.schemaTryGet(f,T.name,[]))return{isValidViewRefinement:!1,error:`Cannot refine with ${e} because stage already has an output field named ${T.name}`};return{isValidViewRefinement:!0}}class le extends p{constructor(e){super(e,{kind:"view_reference",name:e.name,path:e.path,parameters:e.parameters&&new O(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=Q.segmentRefinementOf(this.build());return B(this,e),e.refinement.as.SegmentViewDefinition()}addViewRefinement(e,t){const{error:n}=this.isValidViewRefinement(e,t);if(n)throw new Error(n);const s=Q.viewRefinementOf(this.build(),e,t);return B(this,s),s.refinement.as.ReferenceViewDefinition()}convertToNest(e){const t=N.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});B(this,t)}isValidViewRefinement(e,t){return oe(this,e,t)}getInputSchema(){return Re(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getImplicitName(){return this.name}getViewInfo(){const e=this.getInputSchema(),t=c.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 S.getOrAddParameters(this)}setParameter(e,t){return S.setParameter(this,e,t)}tryGetParameter(e){return S.tryGetParameter(this,e)}}i.ASTReferenceViewDefinition=le;class ue extends p{constructor(e){super(e,{kind:"arrow",source:N.from(e.source),view:N.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=N.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});B(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 oe(this,e,t)}propagateUp(e){this.propagateDown(e)}propagateDown(e){e(this.view),this.view.propagateDown(e)}getInheritedAnnotations(){return[]}}i.ASTArrowViewDefinition=ue;class Q extends p{constructor(e){super(e,{kind:"refinement",base:N.from(e.base),refinement:N.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=N.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});B(this,t)}getOrAddDefaultSegment(){return this.refinement.getOrAddDefaultSegment()}addEmptyRefinement(){return this.refinement.addEmptyRefinement()}addViewRefinement(e,t){return this.refinement.addViewRefinement(e,t)}getInputSchema(){return Re(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getRefinementSchema(){return c.schemaMerge(this.base.getRefinementSchema(),this.refinement.getRefinementSchema())}getImplicitName(){return this.base.getImplicitName()}isValidViewRefinement(e,t){return oe(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 Q({kind:"refinement",base:e,refinement:{kind:"view_reference",name:t,path:n}})}static segmentRefinementOf(e){return new Q({kind:"refinement",base:e,refinement:{kind:"segment",operations:[]}})}}i.ASTRefinementViewDefinition=Q;class $ extends p{constructor(e){super(e,{kind:"segment",operations:new ce(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 P||t instanceof D)return!0;if(t instanceof w){if(!t.view.definition.isRunnable())return!1;e=!0}}return e}get operations(){return this.children.operations}convertToNest(e){const t=N.from({kind:"segment",operations:[{kind:"nest",name:e,view:{definition:this.build()}}]});B(this,t)}renameOrderBys(e,t){for(const n of this.operations.iter())n instanceof G&&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 G&&t.name===e&&t.delete()}reorderFields(e){const t=[],n=[],s={};let f=!1;for(const A of this.operations.iter()){if((A instanceof P||A instanceof D||A instanceof w)&&e.includes(A.name)){s[A.name]=A,f=!0;continue}f?n.push(A):t.push(A)}const T=[];for(const A of e){const V=s[A];if(V===void 0)throw new Error(`No field named ${A}`);T.push(V)}const k=[...t,...T,...n];this.operations.items=k}renameField(e,t){if(e.name===t)return;const n=this.getOutputSchema();if(c.schemaTryGet(n,t,[]))throw new Error(`Output already has a field named ${t}`);const s=e.name;e.name=t,this.propagateUp(f=>{f instanceof $&&f.renameOrderBys(s,t)})}addOrderBy(e,t){const n=this.getOutputSchema();try{c.schemaGet(n,e,[])}catch{throw new Error(`No such field ${e} in stage output`)}for(const f of this.operations.iter())if(f instanceof G&&f.name===e)return f.direction=t,f;const s=new G({kind:"order_by",field_reference:{name:e},direction:t});return this.addOperation(s),s}addEmptyNest(e){const t=new w({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 f=t;for(;this.operations.index(f)&&this.operations.index(f).kind===e;)f++;return f}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 f of s){const T=this.firstIndexOfOperationType(f);if(T>-1)return T}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 D||n instanceof P){const s=n.field.getReference();if(s&&s.name===e&&Ie(s.path,t))return n}else if(n instanceof w){if(n.view instanceof le)return n}else if(n instanceof K){const s=n.expression.field.getReference();if(s&&s.name===e&&Ie(s.path,t))return n}}tryGetFieldNamed(e){for(const t of this.operations.iter())if((t instanceof D||t instanceof P||t instanceof w||t instanceof K)&&t.name===e)return t}getGroupBy(e){for(const t of this.operations.iter())if(t instanceof D&&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 C({kind:"drill",...e});return this.addOperation(t),t}addWhere(e,t,n){const s=Array.isArray(t)?t:[],f=n===void 0?t:n,T=typeof f=="string"?f:be(f),k=this.getInputSchema(),A=b.schemaGet(k,e,s);Fe(A,f);const V=new F({kind:"where",filter:{kind:"filter_string",expression:{kind:"field_reference",name:e,path:s},filter:T}});return this.addOperation(V),V}addHaving(e,t,n){const s=Array.isArray(t)?t:[],f=n===void 0?t:n,T=typeof f=="string"?f:be(f),k=this.getInputSchema(),A=b.schemaGet(k,e,s);Fe(A,f);const V=new ee({kind:"having",filter:{kind:"filter_string",expression:{kind:"field_reference",name:e,path:s},filter:T}});return this.addOperation(V),V}addCalculateMovingAverage(e,t,n,s,f){const T=new K({kind:"calculate",name:e,field:{expression:{kind:"moving_average",field_reference:{name:t,path:n},rows_preceding:s,rows_following:f}}});return this.addOperation(T),T}addTimeGroupBy(e,t,n,s){const f=this.getInputSchema(),T=c.schemaGet(f,e,t);if(T===void 0)throw new Error(`No such field ${e}`);if(T.kind!=="dimension")throw new Error(`Cannot group by non-dimension ${e}`);if(T.type.kind!==s)throw new Error(`${e} is not a ${s}`);const k=new D({kind:"group_by",field:{expression:{kind:"time_truncation",field_reference:{name:e,path:t},truncation:n}}});return this.addOperation(k),k}addDateGroupBy(e,t,n){const s=n===void 0?t:n,f=n===void 0?[]:t;return this.addTimeGroupBy(e,f,s,"date_type")}addTimestampGroupBy(e,t,n){const s=n===void 0?t:n,f=n===void 0?[]:t;return this.addTimeGroupBy(e,f,s,"timestamp_type")}addTimestamptzGroupBy(e,t,n){const s=n===void 0?t:n,f=n===void 0?[]:t;return this.addTimeGroupBy(e,f,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 f=this.getInputSchema(),T=c.schemaGet(f,e,t);if(T===void 0)throw new Error(`No such field ${e}`);if(T.kind!==s){const k=xe(s),A=s;throw new Error(`Cannot ${k} non-${A} ${e}`)}return s==="dimension"?D.fromReference(e,t,n):s==="measure"?P.fromReference(e,t,n):w.fromReference(e,t,n)}addOperation(e){if((e instanceof D||e instanceof P||e instanceof w||e instanceof K)&&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 D||t instanceof P||t instanceof w||t instanceof K)&&e.push(t.getFieldInfo());return{fields:e}}setLimit(e){Z.validateLimit(e);const t=[...this.operations.iter()].find(i.ASTViewOperation.isLimit);t?t.limit=e:this.operations.add(new Z({kind:"limit",limit:e}))}getOrAddDefaultSegment(){return this}addEmptyRefinement(){const e=Q.segmentRefinementOf(this.build());return B(this,e),e.refinement.as.SegmentViewDefinition()}addViewRefinement(e,t){const{error:n}=this.isValidViewRefinement(e,t);if(n)throw new Error(n);const s=Q.viewRefinementOf(this.build(),e,t);return B(this,s),s.refinement.as.ReferenceViewDefinition()}getInputSchema(){return Re(this.parent)}getOutputSchema(){return this.parent.getOutputSchema()}getImplicitName(){}isValidViewRefinement(e,t){return oe(this,e,t)}getInheritedAnnotations(){return[]}}i.ASTSegmentViewDefinition=$;class ce extends h{constructor(e){super(e,e.map(t=>i.ASTViewOperation.from(t)))}get items(){return this.children}set items(e){this.edit(),this.children=e}get segment(){return this.parent.as.SegmentViewDefinition()}}i.ASTViewOperationList=ce,i.ASTViewOperation={from(r){switch(r.kind){case"group_by":return new D(r);case"aggregate":return new P(r);case"order_by":return new G(r);case"nest":return new w(r);case"limit":return new Z(r);case"where":return new F(r);case"drill":return new C(r);case"having":return new ee(r);case"calculate":return new K(r)}},isLimit(r){return r instanceof Z}};class G extends p{constructor(e){super(e,{kind:"order_by",field_reference:new L(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();c.schemaGet(t,e,[]),this.edit(),this.children.field_reference=new L({name:e})}setDirection(e){this.direction=e}}i.ASTOrderByViewOperation=G;class D extends p{constructor(e){super(e,{kind:"group_by",name:e.name,field:new J(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 $&&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 j(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 y.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 D({kind:"group_by",name:n,field:{expression:{kind:"field_reference",name:e,path:t}}})}}i.ASTGroupByViewOperation=D;class P extends p{constructor(e){super(e,{kind:"aggregate",name:e.name,field:new J(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 Y))throw new Error("Cannot convert aggregate to smoothed metric unless it is a field reference");this.list.remove(this);const f=new K({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(T=>({name:T}))}}});return this.list.add(f),f}get list(){return this.parent.as.ViewOperationList()}delete(){this.list.remove(this),this.list.segment.propagateUp(e=>{e instanceof $&&e.removeOrderBys(this.name)})}getFieldInfo(){return{annotations:[{value:y.Tag.withPrefix("#(malloy) ").set(["calculation"]).toString()}],kind:"dimension",name:this.name,type:this.field.type}}getOrAddAnnotations(){return this.field.getOrAddAnnotations()}getInheritedTag(e="# "){return j(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 y.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:[],f=n===void 0?t:n,T=typeof f=="string"?f:be(f),k=this.list.segment.getInputSchema(),A=b.schemaGet(k,e,s);Fe(A,f);const V={filter:{kind:"filter_string",expression:{kind:"field_reference",name:e,path:s},filter:T}};if(this.field.expression instanceof d)return this.field.expression.where.add(new o(V)),this.field.expression;if(this.field.expression instanceof Y){const ye=this.field.expression.build();return this.field.expression=new d({kind:"filtered_field",field_reference:{name:ye.name,path:ye.path,parameters:ye.parameters},where:[V]}),this.field.expression}else throw new Error("This kind of expression does not support addWhere")}static fromReference(e,t,n){return new P({kind:"aggregate",name:n,field:{expression:{kind:"field_reference",name:e,path:t}}})}}i.ASTAggregateViewOperation=P;class J extends p{constructor(e){super(e,{expression:i.ASTExpression.from(e.expression),annotations:e.annotations&&new X(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 U))return this.expression.getReference()}getOrAddAnnotations(){if(this.annotations)return this.annotations;this.edit();const e=new X([]);return this.children.annotations=e,e.parent=this,e}getInheritedTag(e="# "){return j(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 y.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()}}i.ASTField=J,i.ASTExpression={from(r){switch(r.kind){case"field_reference":return new Y(r);case"filtered_field":return new d(r);case"time_truncation":return new H(r);case"literal_value":return new U(r);case"moving_average":return new a(r)}}};class Y extends p{constructor(e){super(e,{kind:e.kind,name:e.name,path:e.path,parameters:e.parameters&&new O(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 J)return e.segment;if(e instanceof Se||e instanceof me)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 me&&this.parent.parent instanceof C?c.schemaGetDrillField(e,this.name,this.path):c.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 S.getOrAddParameters(this)}setParameter(e,t){return S.setParameter(this,e,t)}tryGetParameter(e){return S.tryGetParameter(this,e)}}i.ASTReferenceExpression=Y;class H extends p{constructor(e){super(e,{kind:e.kind,field_reference:new L(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=c.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:g(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:[]}}i.ASTTimeTruncationExpression=H;class U extends p{constructor(e){super(e,{kind:e.kind,literal_value:i.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(){}}i.ASTLiteralValueExpression=U;class pe extends h{constructor(e){super(e,e.map(t=>new L(t)))}}i.ASTFieldReferenceList=pe;class a extends p{constructor(e){super(e,{kind:e.kind,field_reference:new L(e.field_reference),rows_preceding:e.rows_preceding,rows_following:e.rows_following,partition_fields:new pe(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 pe(e)}getFieldInfo(){const e=this.field.segment.getInputSchema(),t=c.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:[]}}i.ASTMovingAverageExpression=a;class o extends p{constructor(e){super(e,{filter:i.ASTFilter.from(e.filter)})}get filter(){return this.children.filter}get list(){return this.parent.as.FilterOperationList()}delete(){this.list.remove(this)}}i.ASTFilterOperation=o;class u extends h{constructor(e){super(e,e.map(t=>new o(t)))}get expression(){return this.parent.as.FilteredFieldExpression()}}i.ASTFilterOperationList=u;class d extends p{constructor(e){super(e,{kind:e.kind,field_reference:new L(e.field_reference),where:new u(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=c.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:[]}}i.ASTFilteredFieldExpression=d;function g(r){switch(r){case"day":case"week":case"month":case"year":case"quarter":return r;default:throw new Error("Invalid date timeframe")}}class w extends p{constructor(e){super(e,{kind:"nest",name:e.name,view:new ke(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 j(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 y.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 w({kind:"nest",name:n,view:{definition:{kind:"view_reference",name:e,path:t}}})}}i.ASTNestViewOperation=w;class F extends p{constructor(e){super(e,{kind:"where",filter:i.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)}}i.ASTWhereViewOperation=F;class C extends p{constructor(e){super(e,{kind:"drill",filter:i.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)}}i.ASTDrillViewOperation=C;class ee extends p{constructor(e){super(e,{kind:"having",filter:i.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)}}i.ASTHavingViewOperation=ee;class K extends p{constructor(e){super(e,{kind:"calculate",field:new J(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:y.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)}}i.ASTCalculateViewOperation=K,i.ASTFilter={from(r){switch(r.kind){case"filter_string":return new Se(r);case"literal_equality":return new me(r)}},getSegment(r){const e=r.parent;return e instanceof o?e.list.expression.field.segment:e.list.segment}};class Se extends p{constructor(e){super(e,{kind:"filter_string",expression:i.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();Ve(this.filterString,t),this.filterString=e}get segment(){return i.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 De(e)}setFilter(e){const t=this.getFilterType();if(t!==e.kind)throw new Error(`Invalid filter: expected type ${t}, got ${e.kind}`);this.filterString=be(e)}getFilter(){const e=this.getFilterType();return Ve(this.filterString,e)}}i.ASTFilterWithFilterString=Se;class me extends p{constructor(e){super(e,{kind:"literal_equality",expression:i.ASTExpression.from(e.expression),value:i.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 i.ASTFilter.getSegment(this)}}i.ASTFilterWithLiteralEquality=me;class ke extends p{constructor(e){super(e,{definition:N.from(e.definition),annotations:e.annotations&&new X(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 $?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 X([]);return this.children.annotations=e,e.parent=this,e}getInheritedAnnotations(){return this.definition.getInheritedAnnotations()}getInheritedTag(e="# "){return j(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 y.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)}}i.ASTView=ke;class Z extends p{get limit(){return this.children.limit}set limit(e){Z.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")}}i.ASTLimitViewOperation=Z;function xe(r){switch(r){case"dimension":return"group by";case"measure":return"aggregate";case"view":return"nest";case"join":return"join";case"calculate":return"calculate"}}function at(r){return r}class X extends h{constructor(e){super(e,e.map(t=>new he(t)))}get items(){return this.children}getInheritedAnnotations(){return this.parent.getInheritedAnnotations()}getIntrinsicTag(e="# "){return j(e,this.items)}getTag(e="# "){return j(e,this.items,this.getInheritedAnnotations())}get annotations(){return this.children.map(e=>e.node)}setTagProperty(e,t=null,n="# "){let s;for(let f=this.items.length-1;f>=0;f--){const T=this.index(f);if(T.hasPrefix(n)&&(s=T,T.hasIntrinsicTagProperty(e))){T.setTagProperty(e,t);return}}s?s.setTagProperty(e,t):this.add(new he({value:new y.Tag({prefix:n}).set(e,t).toString()}))}removeTagProperty(e,t="# "){let n;for(let s=this.items.length-1;s>=0;s--){const f=this.index(s);if(f.hasPrefix(t)&&(n=f,f.hasIntrinsicTagProperty(e))){f.removeTagProperty(e);return}}n?n.removeTagProperty(e):this.add(new he({value:new y.Tag({prefix:t}).unset(...e).toString()}))}}i.ASTAnnotationList=X;class he extends p{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 y.TagParser;return e.parseAnnotation(this.value),e.finish()}getTag(){const e=new y.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()}}i.ASTAnnotation=he;function j(r,e=[],t=[]){const n=new y.TagParser;for(const f of t)n.parseAnnotation(f.value);const s=e.map(f=>f.value).filter(f=>typeof r=="string"?f.startsWith(r):f.match(r));for(const f of s)n.parseAnnotation(f);return n.finish()}function be(r){switch(r.kind){case"string":return l.StringFilterExpression.unparse(r.parsed);case"number":return l.NumberFilterExpression.unparse(r.parsed);case"boolean":return l.BooleanFilterExpression.unparse(r.parsed);case"timestamp":case"timestamptz":case"date":return l.TemporalFilterExpression.unparse(r.parsed)}}function Ve(r,e){function t(n){const s=n.filter(f=>f.severity==="error");if(s.length!==0)throw new Error(`Invalid Malloy filter string: ${s[0].message}`)}switch(e){case"string":{const n=l.StringFilterExpression.parse(r);return t(n.log),{kind:e,parsed:n.parsed}}case"number":{const n=l.NumberFilterExpression.parse(r);return t(n.log),{kind:e,parsed:n.parsed}}case"boolean":{const n=l.BooleanFilterExpression.parse(r);return t(n.log),{kind:e,parsed:n.parsed}}case"timestamp":case"timestamptz":case"date":{const n=l.TemporalFilterExpression.parse(r);return t(n.log),{kind:e,parsed:n.parsed}}case"other":throw new Error("Not implemented")}}function Ue(r){return"kind"in r?r:{...r,kind:"source"}}function We(r){switch(r){case"year":case"quarter":case"month":case"week":case"day":return!0;default:return!1}}function fe(r,e){return r.toString().padStart(e,"0")}function ze(r){const e=fe(r.getUTCFullYear(),4),t=fe(r.getUTCMonth()+1,2),n=fe(r.getUTCDate(),2),s=fe(r.getUTCHours(),2),f=fe(r.getUTCMinutes(),2),T=fe(r.getUTCSeconds(),2);return`${e}-${t}-${n} ${s}:${f}:${T}`}function Ie(r,e){const t=r??[],n=e??[];return t.length===n.length&&t.every((s,f)=>s===n[f])}function De(r){switch(r.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 Fe(r,e){if(r.kind!=="dimension"&&r.kind!=="measure")throw new Error(`Cannot filter by field of type ${r.kind}`);const t=De(r);if(typeof e=="string")Ve(e,t);else if(e.kind!==t)throw new Error(`Invalid filter for field ${r.name}; expected type ${t}, but got ${e.kind}`)}function Re(r){if(r instanceof E)return r.getSourceInfo().schema;if(r instanceof M)throw new Error("unimplemented");return r.getInputSchema()}})(W)),W}var Me;function rt(){return Me||(Me=1,(function(i){var I=re&&re.__createBinding||(Object.create?(function(v,_,y,l){l===void 0&&(l=y);var c=Object.getOwnPropertyDescriptor(_,y);(!c||("get"in c?!_.__esModule:c.writable||c.configurable))&&(c={enumerable:!0,get:function(){return _[y]}}),Object.defineProperty(v,l,c)}):(function(v,_,y,l){l===void 0&&(l=y),v[l]=_[y]})),R=re&&re.__exportStar||function(v,_){for(var y in v)y!=="default"&&!Object.prototype.hasOwnProperty.call(_,y)&&I(_,v,y)};Object.defineProperty(i,"__esModule",{value:!0}),R(nt(),i)})(re)),re}var Ge=rt();const it=Ye(Ge),lt=Ke({__proto__:null,default:it},[Ge]);export{Ge as d,lt as i,tt as r};
@@ -1,4 +1,9 @@
1
1
  <!doctype html>
2
+ <!--
3
+ Copyright (c) Credible Data Inc.
4
+ SPDX-License-Identifier: MIT
5
+ -->
6
+
2
7
  <html lang="en">
3
8
  <head>
4
9
  <meta charset="utf-8" />
@@ -11,7 +16,7 @@
11
16
  href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
12
17
  />
13
18
  <title>Malloy Publisher</title>
14
- <script type="module" crossorigin src="/assets/index-BwoU1Ko8.js"></script>
19
+ <script type="module" crossorigin src="/assets/index-DP4bilgp.js"></script>
15
20
  <link rel="stylesheet" crossorigin href="/assets/index-5eLCcNmP.css">
16
21
  </head>
17
22
  <body>
@@ -2369,6 +2369,8 @@ function internalErrorToHttpError(error) {
2369
2369
  return httpError(404, error.message);
2370
2370
  } else if (error instanceof ModelNotFoundError) {
2371
2371
  return httpError(404, error.message);
2372
+ } else if (error instanceof DashboardNotFoundError) {
2373
+ return httpError(404, error.message);
2372
2374
  } else if (error instanceof NotQueryableError) {
2373
2375
  return httpError(404, error.message);
2374
2376
  } else if (error instanceof MalloyError) {
@@ -2414,7 +2416,7 @@ function httpError(code, message) {
2414
2416
  }
2415
2417
  };
2416
2418
  }
2417
- var NotImplementedError, BadRequestError, InvalidArgumentError, EnvironmentNotFoundError, PackageNotFoundError, ModelNotFoundError, ConnectionNotFoundError, ConnectionError, DestinationNotFoundError, ConnectionAuthError, UnsupportedCatalogFormatError, ModelCompilationError, MaterializationEligibilityError, FrozenConfigError, AccessDeniedError, NotQueryableError, MaterializationNotFoundError, MaterializationConflictError, InvalidStateTransitionError, ServiceUnavailableError, PayloadTooLargeError, ResponseUnserializableError, QueryTimeoutError;
2419
+ var NotImplementedError, BadRequestError, InvalidArgumentError, EnvironmentNotFoundError, PackageNotFoundError, ModelNotFoundError, DashboardNotFoundError, ConnectionNotFoundError, ConnectionError, DestinationNotFoundError, ConnectionAuthError, UnsupportedCatalogFormatError, ModelCompilationError, MaterializationEligibilityError, FrozenConfigError, AccessDeniedError, NotQueryableError, MaterializationNotFoundError, MaterializationConflictError, InvalidStateTransitionError, ServiceUnavailableError, PayloadTooLargeError, ResponseUnserializableError, QueryTimeoutError;
2418
2420
  var init_errors = __esm(() => {
2419
2421
  init_constants();
2420
2422
  NotImplementedError = class NotImplementedError extends Error {
@@ -2444,6 +2446,11 @@ var init_errors = __esm(() => {
2444
2446
  super(message);
2445
2447
  }
2446
2448
  };
2449
+ DashboardNotFoundError = class DashboardNotFoundError extends Error {
2450
+ constructor(message) {
2451
+ super(message);
2452
+ }
2453
+ };
2447
2454
  ConnectionNotFoundError = class ConnectionNotFoundError extends Error {
2448
2455
  constructor(message) {
2449
2456
  super(message);
@@ -14186,19 +14193,352 @@ var init_source_extraction = __esm(() => {
14186
14193
  init_gate_registry_walk();
14187
14194
  });
14188
14195
 
14196
+ // src/service/motly.ts
14197
+ import { parseAnnotation } from "@malloydata/malloy-tag";
14198
+ function onMotlyRoute(text) {
14199
+ const afterSigil = text.replace(/^##?\|?/, "");
14200
+ return afterSigil === "" || /^[ \t\r\n]/.test(afterSigil);
14201
+ }
14202
+ function hasEnvReference(annotation) {
14203
+ return annotation.includes("@env.");
14204
+ }
14205
+ function pollutionTargets() {
14206
+ const targets = [Object.prototype];
14207
+ for (const key of Object.getOwnPropertyNames(Object.prototype)) {
14208
+ const descriptor = Object.getOwnPropertyDescriptor(Object.prototype, key);
14209
+ if (!descriptor)
14210
+ continue;
14211
+ let value;
14212
+ if ("value" in descriptor) {
14213
+ value = descriptor.value;
14214
+ } else {
14215
+ if (BUILT_IN_PROTO_GETTER === undefined || descriptor.get !== BUILT_IN_PROTO_GETTER) {
14216
+ return;
14217
+ }
14218
+ continue;
14219
+ }
14220
+ if ((typeof value === "object" || typeof value === "function") && value !== null && !targets.includes(value)) {
14221
+ targets.push(value);
14222
+ }
14223
+ }
14224
+ return targets;
14225
+ }
14226
+ function parseGuarded(texts) {
14227
+ const targets = pollutionTargets();
14228
+ if (targets === undefined) {
14229
+ return { tag: undefined, messages: [UNSAFE_TO_PARSE] };
14230
+ }
14231
+ let unreadable = false;
14232
+ const ownNames = (target) => {
14233
+ try {
14234
+ return Object.getOwnPropertyNames(target);
14235
+ } catch {
14236
+ unreadable = true;
14237
+ return [];
14238
+ }
14239
+ };
14240
+ const before = targets.map(ownNames);
14241
+ if (unreadable)
14242
+ return { tag: undefined, messages: [UNSAFE_TO_PARSE] };
14243
+ const undoPollution = () => {
14244
+ let polluted = false;
14245
+ targets.forEach((target, index) => {
14246
+ for (const key of ownNames(target)) {
14247
+ if (before[index].includes(key))
14248
+ continue;
14249
+ polluted = true;
14250
+ try {
14251
+ delete target[key];
14252
+ } catch {}
14253
+ }
14254
+ });
14255
+ return polluted || unreadable;
14256
+ };
14257
+ if (texts.some((text) => text.length > MAX_ANNOTATION_CHARS)) {
14258
+ return { tag: undefined, messages: [ANNOTATION_TOO_LONG] };
14259
+ }
14260
+ try {
14261
+ const result = parseAnnotation([...texts]);
14262
+ if (undoPollution())
14263
+ return { tag: undefined, messages: [UNSAFE_TO_PARSE] };
14264
+ return {
14265
+ tag: result.tag,
14266
+ messages: result.log.map((error) => error.message)
14267
+ };
14268
+ } catch {
14269
+ undoPollution();
14270
+ return { tag: undefined, messages: [UNSAFE_TO_PARSE] };
14271
+ }
14272
+ }
14273
+ function docCommentText(texts) {
14274
+ const lines = texts.filter((text) => /^##?\|?"([ \t\r\n]|$)/.test(text)).map((text) => text.replace(/^##?\|?"[ \t\r\n]?/, "").trimEnd());
14275
+ return lines.some((text) => text.trim().length > 0) ? lines.join(`
14276
+ `) : undefined;
14277
+ }
14278
+ function splitDocComment(texts) {
14279
+ const text = docCommentText(texts);
14280
+ if (text === undefined)
14281
+ return {};
14282
+ const lines = text.split(`
14283
+ `);
14284
+ const titleLine = lines.findIndex((line) => line.trim().length > 0);
14285
+ if (titleLine === -1)
14286
+ return {};
14287
+ const body = lines.slice(titleLine + 1).join(`
14288
+ `).replace(/^[ \t\r\n]+/, "").trimEnd();
14289
+ return {
14290
+ title: lines[titleLine].trim(),
14291
+ body: body.length > 0 ? body : undefined
14292
+ };
14293
+ }
14294
+ function docCommentTitleAndDescription(texts, explicitTitle) {
14295
+ if (explicitTitle !== undefined) {
14296
+ return { title: explicitTitle, description: docCommentText(texts) };
14297
+ }
14298
+ const { title, body } = splitDocComment(texts);
14299
+ return { title, description: body };
14300
+ }
14301
+ function quoteFilterLiterals(annotation) {
14302
+ const VALUE_START = /[=[,]/;
14303
+ const BARE_FILTER_LITERAL = /^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;
14304
+ let out = "";
14305
+ let i = 0;
14306
+ while (i < annotation.length) {
14307
+ const char = annotation[i];
14308
+ const delimited = endOfDelimited(annotation, i);
14309
+ if (delimited > i) {
14310
+ out += annotation.slice(i, delimited);
14311
+ i = delimited;
14312
+ continue;
14313
+ }
14314
+ if (VALUE_START.test(char)) {
14315
+ const match = BARE_FILTER_LITERAL.exec(annotation.slice(i + 1));
14316
+ if (match) {
14317
+ const body = match[3].replace(/\\/g, "\\\\").replace(/"/g, "\\\"");
14318
+ out += `${char}${match[1]}"f'${body}'"`;
14319
+ i += 1 + match[0].length;
14320
+ continue;
14321
+ }
14322
+ }
14323
+ out += char;
14324
+ i += 1;
14325
+ }
14326
+ return out;
14327
+ }
14328
+ function endOfDelimited(text, start) {
14329
+ const char = text[start];
14330
+ if (char === "`") {
14331
+ let i = start + 1;
14332
+ while (i < text.length) {
14333
+ if (text[i] === "\\") {
14334
+ i += 2;
14335
+ continue;
14336
+ }
14337
+ if (text[i] === "`")
14338
+ return i + 1;
14339
+ if (text[i] === `
14340
+ `)
14341
+ return text.length;
14342
+ i += 1;
14343
+ }
14344
+ return text.length;
14345
+ }
14346
+ if (text.startsWith("<<<", start)) {
14347
+ let lineStart = start + 3;
14348
+ for (;; ) {
14349
+ const newline = text.indexOf(`
14350
+ `, lineStart);
14351
+ const lineEnd = newline === -1 ? text.length : newline;
14352
+ if (text.slice(lineStart, lineEnd).trim() === ">>>")
14353
+ return lineEnd;
14354
+ if (newline === -1)
14355
+ return text.length;
14356
+ lineStart = newline + 1;
14357
+ }
14358
+ }
14359
+ if (char === '"' || char === "'") {
14360
+ const triple = char.repeat(3);
14361
+ if (text.startsWith(triple, start)) {
14362
+ let i2 = start + triple.length;
14363
+ while (i2 < text.length) {
14364
+ if (text[i2] === "\\") {
14365
+ i2 += 2;
14366
+ continue;
14367
+ }
14368
+ if (text.startsWith(triple, i2))
14369
+ return i2 + triple.length;
14370
+ i2 += 1;
14371
+ }
14372
+ return text.length;
14373
+ }
14374
+ let i = start + 1;
14375
+ while (i < text.length) {
14376
+ if (text[i] === "\\") {
14377
+ i += 2;
14378
+ continue;
14379
+ }
14380
+ if (text[i] === char)
14381
+ return i + 1;
14382
+ if (text[i] === `
14383
+ `)
14384
+ return i;
14385
+ i += 1;
14386
+ }
14387
+ return text.length;
14388
+ }
14389
+ return start;
14390
+ }
14391
+ function unwrapFilterLiteral(value) {
14392
+ const match = /^f(['"])([\s\S]*)\1$/.exec(value);
14393
+ return match ? match[2] : value;
14394
+ }
14395
+ function parseMotly(texts) {
14396
+ const onRoute = texts.filter(onMotlyRoute);
14397
+ const motly = onRoute.filter((text) => !hasEnvReference(text));
14398
+ const envDropped = onRoute.length - motly.length;
14399
+ const envErrors = envDropped > 0 ? [ENV_REFERENCE_DROPPED] : [];
14400
+ if (motly.length === 0)
14401
+ return { tag: undefined, errors: envErrors };
14402
+ const direct = parseGuarded(motly);
14403
+ if (direct.messages.length === 0)
14404
+ return { tag: direct.tag, errors: envErrors };
14405
+ const rescued = motly.map((text) => {
14406
+ if (parseGuarded([text]).messages.length === 0)
14407
+ return text;
14408
+ const rewritten = quoteFilterLiterals(text);
14409
+ return parseGuarded([rewritten]).messages.length === 0 ? rewritten : text;
14410
+ });
14411
+ const after = parseGuarded(rescued);
14412
+ return { tag: after.tag, errors: [...envErrors, ...after.messages] };
14413
+ }
14414
+ function tagText(tag, ...path) {
14415
+ try {
14416
+ return tag?.text(...path);
14417
+ } catch {
14418
+ return;
14419
+ }
14420
+ }
14421
+ function tagNumeric(tag, ...path) {
14422
+ try {
14423
+ const raw = tagText(tag, ...path);
14424
+ if (raw === undefined)
14425
+ return;
14426
+ const DECIMAL = /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][-+]?\d+)?$/;
14427
+ const text = raw.trim();
14428
+ if (!DECIMAL.test(text))
14429
+ return;
14430
+ const value = Number(text);
14431
+ return Number.isFinite(value) ? value : undefined;
14432
+ } catch {
14433
+ return;
14434
+ }
14435
+ }
14436
+ function motlyTag(texts) {
14437
+ return parseMotly(texts).tag;
14438
+ }
14439
+ function motlyParseErrors(texts) {
14440
+ return parseMotly(texts).errors;
14441
+ }
14442
+ function readAutorun(tag) {
14443
+ return tagText(tag, "autorun") !== "false";
14444
+ }
14445
+ function scalarTypeOf(tag) {
14446
+ try {
14447
+ return tag?.scalarType();
14448
+ } catch {
14449
+ return;
14450
+ }
14451
+ }
14452
+ function authoredDay(isoText) {
14453
+ const value = new Date(isoText);
14454
+ if (Number.isNaN(value.getTime()))
14455
+ return isoText.slice(0, 10);
14456
+ const atUtcMidnight = value.getUTCHours() === 0 && value.getUTCMinutes() === 0 && value.getUTCSeconds() === 0 && value.getUTCMilliseconds() === 0;
14457
+ const year = atUtcMidnight ? value.getUTCFullYear() : value.getFullYear();
14458
+ const month = atUtcMidnight ? value.getUTCMonth() : value.getMonth();
14459
+ const day = atUtcMidnight ? value.getUTCDate() : value.getDate();
14460
+ return `${year}-${String(month + 1).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
14461
+ }
14462
+ function readStartingGivens(tag, declaredType) {
14463
+ const entries = tag?.tag("givens");
14464
+ if (!entries)
14465
+ return;
14466
+ const collected = {};
14467
+ for (const [name, value] of entries.entries()) {
14468
+ const tag2 = value;
14469
+ const text = tagText(tag2);
14470
+ if (text === undefined)
14471
+ continue;
14472
+ const declared = declaredType(name);
14473
+ collected[name] = scalarTypeOf(tag2) === "date" && declared !== "timestamp" && declared !== "timestamptz" ? authoredDay(text) : declared?.startsWith("filter<") ? unwrapFilterLiteral(text) : text;
14474
+ }
14475
+ return Object.keys(collected).length > 0 ? collected : undefined;
14476
+ }
14477
+ var BUILT_IN_PROTO_GETTER, MAX_ANNOTATION_CHARS = 8192, ANNOTATION_TOO_LONG, ENV_REFERENCE_DROPPED = "annotation dropped for carrying an @env. reference", UNSAFE_TO_PARSE = "annotation could not be parsed safely";
14478
+ var init_motly = __esm(() => {
14479
+ BUILT_IN_PROTO_GETTER = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__")?.get;
14480
+ ANNOTATION_TOO_LONG = `annotation exceeds ${MAX_ANNOTATION_CHARS} characters and was not parsed`;
14481
+ });
14482
+
14189
14483
  // src/service/given.ts
14484
+ function presentText(tag, ...path) {
14485
+ const raw = tagText(tag, ...path);
14486
+ return raw !== undefined && raw.trim() !== "" ? raw : undefined;
14487
+ }
14488
+ function readGivenControlSpec(annotationTexts2) {
14489
+ const spec = {};
14490
+ const tag = motlyTag(annotationTexts2);
14491
+ if (!tag)
14492
+ return spec;
14493
+ const label = presentText(tag, "label");
14494
+ if (label !== undefined)
14495
+ spec.label = label;
14496
+ const description = presentText(tag, "description");
14497
+ if (description !== undefined)
14498
+ spec.description = description;
14499
+ const control = tagText(tag, "control");
14500
+ if (control === "select" || control === "multiselect") {
14501
+ spec.control = control;
14502
+ }
14503
+ const rangeMin = tagNumeric(tag, "range_min");
14504
+ if (rangeMin !== undefined)
14505
+ spec.rangeMin = rangeMin;
14506
+ const rangeMax = tagNumeric(tag, "range_max");
14507
+ if (rangeMax !== undefined)
14508
+ spec.rangeMax = rangeMax;
14509
+ const suggest = tag.tag("suggest");
14510
+ if (suggest) {
14511
+ const parsed = {};
14512
+ const query = presentText(suggest, "query");
14513
+ if (query !== undefined)
14514
+ parsed.query = query;
14515
+ const source = presentText(suggest, "source");
14516
+ if (source !== undefined)
14517
+ parsed.source = source;
14518
+ const dimension = presentText(suggest, "dimension");
14519
+ if (dimension !== undefined)
14520
+ parsed.dimension = dimension;
14521
+ const runnable = parsed.query !== undefined || parsed.source !== undefined && parsed.dimension !== undefined;
14522
+ if (runnable)
14523
+ spec.suggest = parsed;
14524
+ }
14525
+ return spec;
14526
+ }
14190
14527
  function malloyGivenToApi(given) {
14191
14528
  const type = given.type;
14192
14529
  const renderedType = type.type === "filter expression" ? `filter<${type.filterType}>` : type.type;
14530
+ const allNotes = given.annotations.forRoute(undefined);
14193
14531
  return {
14194
14532
  name: given.name,
14195
14533
  type: renderedType,
14196
- annotations: given.annotations.forRoute(undefined).filter((note) => !isReservedRoute(note.route)).map((note) => note.text),
14534
+ annotations: allNotes.filter((note) => !isReservedRoute(note.route)).map((note) => note.text),
14535
+ ...readGivenControlSpec(allNotes.map((note) => note.text)),
14197
14536
  default: given._internal?.defaultText
14198
14537
  };
14199
14538
  }
14200
14539
  var init_given = __esm(() => {
14201
14540
  init_annotations();
14541
+ init_motly();
14202
14542
  });
14203
14543
 
14204
14544
  // src/utils.ts