@malloy-publisher/server 0.0.382-dev → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.docker.md +145 -20
- package/README.md +65 -12
- package/dist/app/api-doc.html +5 -0
- package/dist/app/api-doc.yaml +3903 -583
- package/dist/app/assets/EnvironmentPage-DiUgLuCH.js +1 -0
- package/dist/app/assets/HomePage-MhhjhnFj.js +1 -0
- package/dist/app/assets/LightMode-BEyvNUzT.js +1 -0
- package/dist/app/assets/MainPage-D4Cfee9o.js +2 -0
- package/dist/app/assets/MaterializationsPage-nGgGqwSN.js +1 -0
- package/dist/app/assets/ModelPage-DLAcEw-F.js +1 -0
- package/dist/app/assets/PackagePage-Df0ikH7w.js +1 -0
- package/dist/app/assets/RouteError-BFQwtroH.js +1 -0
- package/dist/app/assets/ThemeEditorPage-OoskoQYN.js +1 -0
- package/dist/app/assets/WorkbookPage-CpFgvUDC.js +1 -0
- package/dist/app/assets/{core-CjeTkq8O.es-BqRc6yhC.js → core-lb28vQkR.es-BoVSOc75.js} +1 -1
- package/dist/app/assets/github-dark-DenFmJkN.es-DHJKELXO.js +1 -0
- package/dist/app/assets/index-5eLCcNmP.css +1 -0
- package/dist/app/assets/index-6ypuFH6g.js +1774 -0
- package/dist/app/assets/index-B8pnU_V_.js +615 -0
- package/dist/app/assets/index-BImcHmVP.js +1 -0
- package/dist/app/assets/index-DSoCUF-f.js +2725 -0
- package/dist/app/assets/index-DfqzSItA.js +2 -0
- package/dist/app/assets/index-w_0OQJgZ.js +23 -0
- package/dist/app/index.html +8 -4
- package/dist/cpufeatures-1yrn0vtw.node +0 -0
- package/dist/default-publisher.config.json +23 -0
- package/dist/{instrumentation.js → instrumentation.mjs} +10631 -10573
- package/dist/package_load_worker.mjs +15219 -0
- package/dist/runtime/publisher.js +331 -0
- package/dist/{server.js → server.mjs} +115548 -49590
- package/dist/sshcrypto-vd2k5hq9.node +0 -0
- package/package.json +41 -28
- package/publisher.config.example.bigquery.json +33 -0
- package/publisher.config.example.duckdb.json +23 -0
- package/.eslintrc.json +0 -44
- package/.prettierignore +0 -1
- package/.prettierrc +0 -4
- package/build.ts +0 -38
- package/dist/app/assets/HomePage-Dn3E4CuB.js +0 -1
- package/dist/app/assets/MainPage-BzB3yoqi.js +0 -2
- package/dist/app/assets/ModelPage-C9O_sAXT.js +0 -1
- package/dist/app/assets/PackagePage-DcxKEjBX.js +0 -1
- package/dist/app/assets/ProjectPage-BDj307rF.js +0 -1
- package/dist/app/assets/RouteError-DAShbVCG.js +0 -1
- package/dist/app/assets/WorkbookPage-Cs_XYEaB.js +0 -1
- package/dist/app/assets/index-15BOvhp0.js +0 -456
- package/dist/app/assets/index-Bb2jqquW.js +0 -676
- package/dist/app/assets/index-CMlGQMcl.css +0 -1
- package/dist/app/assets/index-D68X76-7.js +0 -1276
- package/dist/app/assets/index.umd-DGBekgSu.js +0 -1145
- package/dxt/malloy_bridge.py +0 -354
- package/dxt/manifest.json +0 -22
- package/eslint.config.mjs +0 -76
- package/k6-tests/README.md +0 -144
- package/k6-tests/bun.lock +0 -797
- package/k6-tests/load-test/load-test-crud-connections.ts +0 -263
- package/k6-tests/load-test/load-test-crud-packages.ts +0 -461
- package/k6-tests/load-test/load-test-crud-projects.ts +0 -160
- package/k6-tests/load-test/load-test-crud.ts +0 -142
- package/k6-tests/load-test/load-test.ts +0 -784
- package/k6-tests/package.json +0 -27
- package/k6-tests/scripts/run-with-otel.sh +0 -50
- package/k6-tests/smoke-test/smoke-test.ts +0 -158
- package/k6-tests/tsconfig.json +0 -29
- package/k6-tests/utils/client_factory.ts +0 -128
- package/k6-tests/utils/common.ts +0 -489
- package/k6-tests/utils/logger.ts +0 -62
- package/k6-tests/utils/types.d.ts +0 -35
- package/malloy_mcp.dxt +0 -0
- package/publisher.config.json +0 -33
- package/src/config.spec.ts +0 -850
- package/src/config.ts +0 -305
- package/src/constants.ts +0 -10
- package/src/controller/compile.controller.ts +0 -35
- package/src/controller/connection.controller.ts +0 -515
- package/src/controller/database.controller.ts +0 -21
- package/src/controller/manifest.controller.ts +0 -29
- package/src/controller/materialization.controller.ts +0 -125
- package/src/controller/model.controller.ts +0 -107
- package/src/controller/package.controller.ts +0 -182
- package/src/controller/query.controller.ts +0 -60
- package/src/controller/watch-mode.controller.ts +0 -98
- package/src/data_styles.ts +0 -71
- package/src/dto/connection.dto.spec.ts +0 -131
- package/src/dto/connection.dto.ts +0 -174
- package/src/dto/index.ts +0 -2
- package/src/dto/package.dto.spec.ts +0 -42
- package/src/dto/package.dto.ts +0 -12
- package/src/dto/validate.spec.ts +0 -76
- package/src/dto/validate.ts +0 -31
- package/src/errors.ts +0 -116
- package/src/health.ts +0 -189
- package/src/instrumentation.ts +0 -148
- package/src/logger.ts +0 -154
- package/src/mcp/error_messages.ts +0 -199
- package/src/mcp/handler_utils.ts +0 -239
- package/src/mcp/mcp_constants.ts +0 -22
- package/src/mcp/prompts/handlers.ts +0 -84
- package/src/mcp/prompts/index.ts +0 -11
- package/src/mcp/prompts/prompt_definitions.ts +0 -160
- package/src/mcp/prompts/prompt_service.ts +0 -67
- package/src/mcp/prompts/utils.ts +0 -62
- package/src/mcp/resource_metadata.ts +0 -47
- package/src/mcp/resources/model_resource.ts +0 -153
- package/src/mcp/resources/notebook_resource.ts +0 -137
- package/src/mcp/resources/package_resource.ts +0 -370
- package/src/mcp/resources/project_resource.ts +0 -184
- package/src/mcp/resources/query_resource.ts +0 -117
- package/src/mcp/resources/source_resource.ts +0 -141
- package/src/mcp/resources/view_resource.ts +0 -136
- package/src/mcp/server.ts +0 -62
- package/src/mcp/tools/discovery_tools.ts +0 -258
- package/src/mcp/tools/execute_query_tool.ts +0 -265
- package/src/server.ts +0 -1195
- package/src/service/connection.spec.ts +0 -1331
- package/src/service/connection.ts +0 -1511
- package/src/service/connection_service.spec.ts +0 -641
- package/src/service/connection_service.ts +0 -181
- package/src/service/db_utils.spec.ts +0 -714
- package/src/service/db_utils.ts +0 -1227
- package/src/service/filter.spec.ts +0 -447
- package/src/service/filter.ts +0 -337
- package/src/service/filter_integration.spec.ts +0 -825
- package/src/service/gcs_s3_utils.ts +0 -427
- package/src/service/manifest_service.spec.ts +0 -201
- package/src/service/manifest_service.ts +0 -106
- package/src/service/materialization_service.spec.ts +0 -648
- package/src/service/materialization_service.ts +0 -929
- package/src/service/materialized_table_gc.spec.ts +0 -383
- package/src/service/materialized_table_gc.ts +0 -279
- package/src/service/model.spec.ts +0 -257
- package/src/service/model.ts +0 -1069
- package/src/service/package.spec.ts +0 -236
- package/src/service/package.ts +0 -463
- package/src/service/project.ts +0 -681
- package/src/service/project_compile.spec.ts +0 -197
- package/src/service/project_store.spec.ts +0 -859
- package/src/service/project_store.ts +0 -1531
- package/src/service/quoting.ts +0 -41
- package/src/service/resolve_project.ts +0 -13
- package/src/storage/BaseRepository.ts +0 -31
- package/src/storage/DatabaseInterface.ts +0 -180
- package/src/storage/StorageManager.mock.ts +0 -59
- package/src/storage/StorageManager.ts +0 -210
- package/src/storage/duckdb/ConnectionRepository.ts +0 -141
- package/src/storage/duckdb/DuckDBConnection.ts +0 -177
- package/src/storage/duckdb/DuckDBManifestStore.ts +0 -70
- package/src/storage/duckdb/DuckDBRepository.ts +0 -224
- package/src/storage/duckdb/ManifestRepository.ts +0 -119
- package/src/storage/duckdb/MaterializationRepository.ts +0 -249
- package/src/storage/duckdb/PackageRepository.ts +0 -135
- package/src/storage/duckdb/ProjectRepository.ts +0 -148
- package/src/storage/duckdb/manifest_store.spec.ts +0 -133
- package/src/storage/duckdb/schema.ts +0 -147
- package/src/storage/ducklake/DuckLakeManifestStore.ts +0 -146
- package/src/utils.ts +0 -13
- package/tests/fixtures/persist-test/data/orders.csv +0 -5
- package/tests/fixtures/persist-test/persist_test.malloy +0 -11
- package/tests/fixtures/persist-test/publisher.json +0 -5
- package/tests/fixtures/publisher.config.json +0 -15
- package/tests/harness/e2e.ts +0 -96
- package/tests/harness/mcp_test_setup.ts +0 -344
- package/tests/harness/mocks.ts +0 -37
- package/tests/harness/rest_e2e.ts +0 -68
- package/tests/harness/uris.ts +0 -31
- package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +0 -470
- package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +0 -434
- package/tests/integration/mcp/mcp_resource.integration.spec.ts +0 -663
- package/tests/integration/mcp/mcp_transport.integration.spec.ts +0 -122
- package/tests/integration/mcp/setup.spec.ts +0 -5
- package/tests/unit/duckdb/attached_databases.test.ts +0 -1132
- package/tests/unit/ducklake/ducklake.test.ts +0 -950
- package/tests/unit/mcp/prompt_definitions.test.ts +0 -102
- package/tests/unit/mcp/prompt_happy.test.ts +0 -51
- package/tsconfig.json +0 -32
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{aN as Je,aS as Ye}from"./index-B8pnU_V_.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};
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
var te={},ae={},me;function $e(){if(me)return ae;me=1,Object.defineProperty(ae,"__esModule",{value:!0}),ae.Tag=void 0,ae.interfaceFromTag=E,ae.interfaceFromDict=M;class a{get parent(){return this._parent}get root(){let i=this;for(;i._parent!==void 0;)i=i._parent;return i}static id(i){let e=a.ids.get(i);return e===void 0&&(e=a.nextTagId,a.ids.set(i,e),a.nextTagId+=1),e}peek(i=0){const e=" ".repeat(i);let t=`#${a.id(this)}`;if(this.properties===void 0&&this.eq&&typeof this.eq=="string")return t+`=${this.eq}`;if(t+=" {",this.eq!==void 0&&(Array.isArray(this.eq)?t+=`
|
|
2
|
+
${e} =: [
|
|
3
|
+
${e} ${this.eq.map(n=>n.peek(i+4)).join(`
|
|
4
|
+
${e} `)}
|
|
5
|
+
${e} ]`:t+=`
|
|
6
|
+
${e} =: ${this.eq}`),this.properties)for(const n in this.properties)t+=`
|
|
7
|
+
${e} ${n}: ${this.properties[n].peek(i+2)}`;return t+=`
|
|
8
|
+
${e}}`,t}constructor(i={},e){if(this._read=!1,e!==void 0&&(this._parent=e),i.eq!==void 0&&(Array.isArray(i.eq)?this.eq=i.eq.map(t=>t instanceof a?t:new a(t,this)):this.eq=i.eq),i.properties){this.properties={};for(const[t,n]of Object.entries(i.properties))this.properties[t]=n instanceof a?n:new a(n,this)}i.deleted&&(this.deleted=i.deleted),i.prefix&&(this.prefix=i.prefix)}static withPrefix(i){return new a({prefix:i})}tag(...i){return this.find(i)}text(...i){var e;const t=(e=this.find(i))===null||e===void 0?void 0:e.getEq();if(!(t===void 0||Array.isArray(t)))return t instanceof Date?t.toISOString():String(t)}scalarType(...i){var e;const t=i.length>0?(e=this.find(i))===null||e===void 0?void 0:e.getEq():this.getEq();if(!(t===void 0||Array.isArray(t)))return t instanceof Date?"date":typeof t}numeric(...i){var e;const t=(e=this.find(i))===null||e===void 0?void 0:e.getEq();if(typeof t=="number")return t;if(typeof t=="string"){const n=Number.parseFloat(t);if(!Number.isNaN(n))return n}}boolean(...i){var e;const t=(e=this.find(i))===null||e===void 0?void 0:e.getEq();if(typeof t=="boolean")return t}isTrue(...i){var e;return((e=this.find(i))===null||e===void 0?void 0:e.getEq())===!0}isFalse(...i){var e;return((e=this.find(i))===null||e===void 0?void 0:e.getEq())===!1}date(...i){var e;const t=(e=this.find(i))===null||e===void 0?void 0:e.getEq();if(t instanceof Date)return t}bare(...i){const e=this.find(i);if(e!==void 0)return!e.hasProperties()}getEq(){return this.eq}getProperty(i){var e;return(e=this.properties)===null||e===void 0?void 0:e[i]}getArrayElement(i){if(Array.isArray(this.eq)&&i<this.eq.length)return this.eq[i]}get dict(){var i;return(i=this.properties)!==null&&i!==void 0?i:{}}*entries(){if(this.properties)for(const i in this.properties)yield[i,this.properties[i]]}*keys(){if(this.properties)for(const i in this.properties)yield i}hasProperties(){return this.properties!==void 0&&Object.keys(this.properties).length>0}array(...i){const e=this.find(i);if(e===void 0)return;const t=e.getEq();if(Array.isArray(t))return t.map((n,u)=>e.getArrayElement(u))}textArray(...i){const e=this.find(i);if(e===void 0)return;const t=e.getEq();if(Array.isArray(t))return t.reduce((n,u,d)=>{const s=e.getArrayElement(d),o=s?.getEq();return o===void 0||Array.isArray(o)?n:o instanceof Date?n.concat(o.toISOString()):n.concat(String(o))},[])}numericArray(...i){const e=this.find(i);if(e===void 0)return;const t=e.getEq();if(Array.isArray(t))return t.reduce((n,u,d)=>{const s=e.getArrayElement(d),o=s?.getEq();if(typeof o=="number")return n.concat(o);if(typeof o=="string"){const g=Number.parseFloat(o);if(!Number.isNaN(g))return n.concat(g)}return n},[])}getProperties(){return this.properties===void 0&&(this.properties={}),this.properties}clone(i){this._read=!0;const e=new a({},i);if(e.prefix=this.prefix,e.deleted=this.deleted,e.location=this.location,e._clonedFrom=this,this.eq!==void 0&&(Array.isArray(this.eq)?e.eq=this.eq.map(t=>t.clone(e)):e.eq=this.eq instanceof Date?new Date(this.eq):this.eq),this.properties){e.properties={};for(const[t,n]of Object.entries(this.properties))e.properties[t]=n.clone(e)}return e}toJSON(){const i={};if(this.eq!==void 0&&(Array.isArray(this.eq)?i.eq=this.eq.map(e=>e.toJSON()):i.eq=this.eq),this.properties!==void 0){i.properties={};for(const[e,t]of Object.entries(this.properties))i.properties[e]=t.toJSON()}return this.deleted&&(i.deleted=!0),this.prefix&&(i.prefix=this.prefix),this.location&&(i.location=this.location),i}validateReferences(){const i=[];return this.collectReferenceErrors(i,[]),i}collectReferenceErrors(i,e){if(this.properties)for(const[t,n]of Object.entries(this.properties))n.deleted||n.collectReferenceErrors(i,[...e,t]);Array.isArray(this.eq)&&this.eq.forEach((t,n)=>{t.collectReferenceErrors(i,[...e,`[${n}]`])})}static escapeString(i){return i.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n")}static escapeProp(i){return i.replace(/\\/g,"\\\\").replace(/`/g,"\\`")}static quoteAndEscape(i,e=!1){return i.match(/^[0-9A-Za-z_]+$/)?i:e?`\`${a.escapeProp(i)}\``:`"${a.escapeString(i)}"`}static serializeScalar(i){return typeof i=="boolean"?i?"@true":"@false":i instanceof Date?`@${i.toISOString()}`:typeof i=="number"?String(i):a.quoteAndEscape(i)}toString(){var i;let e=(i=this.prefix)!==null&&i!==void 0?i:"# ";function t(d){var s;const o=Object.keys((s=d.properties)!==null&&s!==void 0?s:{});for(let g=0;g<o.length;g++)u(o[g],d.properties[o[g]]),g<o.length-1&&(e+=" ")}function n(d,s=!1){if(d.eq!==void 0)if(s||(e+=" = "),Array.isArray(d.eq)){e+="[";for(let o=0;o<d.eq.length;o++)n(d.eq[o],!0),o!==d.eq.length-1&&(e+=", ");e+="]"}else e+=a.serializeScalar(d.eq);if(d.properties){const o=Object.keys(d.properties);!s&&o.length===1&&!o.some(g=>{var y;return((y=d.properties)!==null&&y!==void 0?y:{})[g].deleted})&&d.eq===void 0?(e+=".",t(d)):((!s||d.eq!==void 0)&&(e+=" "),e+="{ ",t(d),e+=" }")}}function u(d,s){if(s.deleted){e+=`-${a.quoteAndEscape(d,!0)}`;return}e+=a.quoteAndEscape(d,!0),n(s)}return t(this),e+=`
|
|
9
|
+
`,e}find(i){let e=this;for(const t of i){let n;if(typeof t=="number"?n=e.getArrayElement(t):n=e.getProperty(t),n===void 0)return;n.markRead(),e=n}return e.deleted?void 0:e}markRead(){this._read=!0,this._clonedFrom&&(this._clonedFrom._read=!0)}get wasRead(){return this._read}*walk(i=[]){if(this.properties)for(const[e,t]of Object.entries(this.properties)){if(t.deleted)continue;const n=[...i,e];yield{path:n,tag:t},yield*t.walk(n)}if(Array.isArray(this.eq))for(let e=0;e<this.eq.length;e++){const t=[...i,e.toString()];yield{path:t,tag:this.eq[e]},yield*this.eq[e].walk(t)}}resetReadTracking(){this._read=!1;for(const{tag:i}of this.walk())i._read=!1}getUnreadProperties(i=[]){const e=[];if(this.properties)for(const[t,n]of Object.entries(this.properties)){if(n.deleted)continue;const u=[...i,t];n._read?e.push(...n.getUnreadProperties(u)):e.push(u)}return e}has(...i){return this.find(i)!==void 0}set(i,e=null){let t=this,n,u;for(const d of i)if(n=t,u=d,typeof d=="number"){if(t.eq===void 0||!Array.isArray(t.eq))t.eq=Array.from({length:d+1}).map(()=>new a({},t));else if(t.eq.length<=d){const s=t.eq,o=Array.from({length:d+1}).map((g,y)=>y<s.length?s[y]:new a({},t));t.eq=o}t=t.eq[d]}else{const s=t.properties;s===void 0?(t.properties={[d]:new a({},t)},t=t.properties[d]):d in s?(t=s[d],t.deleted&&(t.deleted=!1)):(s[d]=new a({},t),t=s[d])}if(e===null)t.eq=void 0;else if(e instanceof a){const d=e.clone(n);n&&u!==void 0&&(typeof u=="number"&&Array.isArray(n.eq)?n.eq[u]=d:typeof u=="string"&&n.properties&&(n.properties[u]=d))}else typeof e=="string"||typeof e=="number"||typeof e=="boolean"||e instanceof Date?t.eq=e:Array.isArray(e)&&(t.eq=e.map(d=>new a({eq:d},t)));return this}delete(...i){return this.remove(i,!1)}unset(...i){return this.remove(i,!0)}remove(i,e=!1){var t;let n=this;for(const d of i.slice(0,i.length-1))if(typeof d=="number"){if(n.eq===void 0||!Array.isArray(n.eq)){if(!e)return this;n.eq=Array.from({length:d}).map(()=>new a({},n))}else if(n.eq.length<=d){if(!e)return this;const s=n.eq,o=Array.from({length:d}).map((g,y)=>y<s.length?s[y]:new a({},n));n.eq=o}n=n.eq[d]}else{const s=n.properties;if(s===void 0){if(!e)return this;n.properties={[d]:new a({},n)},n=n.properties[d]}else if(d in s)n=s[d];else{if(!e)return this;s[d]=new a({},n),n=s[d]}}const u=i[i.length-1];return typeof u=="string"?n.properties&&u in n.properties?delete n.properties[u]:e&&((t=n.properties)!==null&&t!==void 0||(n.properties={}),n.properties[u]=new a({deleted:!0},n)):Array.isArray(n.eq)&&n.eq.splice(u,1),this}}ae.Tag=a,a.ids=new Map,a.nextTagId=1e3;function E(C){const i={};return C.eq!==void 0&&(Array.isArray(C.eq)?i.eq=C.eq.map(e=>E(e)):i.eq=C.eq),C.properties!==void 0&&(i.properties=M(C.properties)),C.deleted&&(i.deleted=!0),i}function M(C){const i={};for(const[e,t]of Object.entries(C))i[e]=E(t);return i}return ae}var ue={},ve={},se={},ke;function le(){if(ke)return se;ke=1,Object.defineProperty(se,"__esModule",{value:!0}),se.formatRef=a,se.isRef=E,se.isDataNode=M,se.isEnvRef=C,se.isMotlyError=i;function a(e){let t="$";for(let u=0;u<e.linkUps;u++)t+="^";let n=!0;for(const u of e.linkTo)typeof u=="string"?((!n||e.linkUps>0)&&(t+="."),t+=u,n=!1):t+=`[${u}]`;return t}function E(e){return typeof e=="object"&&e!==null&&"linkTo"in e&&"linkUps"in e&&!Array.isArray(e)&&!(e instanceof Date)}function M(e){return typeof e=="object"&&e!==null&&!E(e)}function C(e){return typeof e=="object"&&e!==null&&"env"in e&&!Array.isArray(e)&&!(e instanceof Date)}function i(e){return typeof e=="object"&&e!==null&&"code"in e&&"message"in e&&"begin"in e&&"end"in e}return se}var oe={},be;function Pe(){if(be)return oe;be=1,Object.defineProperty(oe,"__esModule",{value:!0}),oe.MotValue=oe.Mot=void 0,oe.buildMot=d;const a=le();class E{text(...o){return this.get(...o)._text()}numeric(...o){return this.get(...o)._numeric()}boolean(...o){return this.get(...o)._boolean()}date(...o){return this.get(...o)._date()}valueType(...o){return this.get(...o)._valueType()}values(...o){return this.get(...o)._values()}texts(...o){const g=this.get(...o)._values();if(!g)return;const y=[];for(const P of g){const I=P._text();if(I===void 0)return;y.push(I)}return y}numerics(...o){const g=this.get(...o)._values();if(!g)return;const y=[];for(const P of g){const I=P._numeric();if(I===void 0)return;y.push(I)}return y}booleans(...o){const g=this.get(...o)._values();if(!g)return;const y=[];for(const P of g){const I=P._boolean();if(I===void 0)return;y.push(I)}return y}dates(...o){const g=this.get(...o)._values();if(!g)return;const y=[];for(const P of g){const I=P._date();if(I===void 0)return;y.push(I)}return y}has(...o){return this.get(...o).exists}}oe.Mot=E;class M extends E{constructor(o,g,y=!0){super(),this.isRef=!1,this._val=o,this._props=g,this.exists=y}_text(){return this._val?.type==="string"?this._val.value:void 0}_numeric(){return this._val?.type==="number"?this._val.value:void 0}_boolean(){return this._val?.type==="boolean"?this._val.value:void 0}_date(){return this._val?.type==="date"?this._val.value:void 0}_values(){return this._val?.type==="array"?this._val.value:void 0}_valueType(){return this._val?.type}get keys(){return this._props.keys()}get entries(){return this._props.entries()}get(...o){let g=this;for(const y of o){if(typeof y=="number"){const P=g.values();if(!P||!Number.isInteger(y)||y<0||y>=P.length)return t;g=P[y]}else g===this?g=this._props.get(y)??t:g=g.get(y);if(!g.exists)return t}return g}}oe.MotValue=M;class C extends E{constructor(o,g){super(),this.exists=!0,this.isRef=!0,this._target=g}_text(){return this._target.text()}_numeric(){return this._target.numeric()}_boolean(){return this._target.boolean()}_date(){return this._target.date()}_values(){return this._target.values()}_valueType(){return this._target.valueType()}get keys(){return this._target.keys}get entries(){return this._target.entries}get(...o){return this._target.get(...o)}}const i={[Symbol.iterator]:()=>({next:()=>({done:!0,value:void 0})})};class e extends E{constructor(){super(...arguments),this.exists=!1,this.isRef=!1}_text(){}_numeric(){}_boolean(){}_date(){}_values(){}_valueType(){}get keys(){return i}get entries(){return i}get(...o){return this}}const t=new e,n={createMot(s,o){return new M(s,o)},createRefMot(s,o){return new C(s,o)},undefinedMot:t};function u(s,o,g,y){let P,I;if(s.linkUps===0)P=o,I=[];else{const O=g.length-s.linkUps;if(O<0||O>=g.length)return;P=g[O],I=g.slice(0,O)}let N=P,W=I,Q=P;for(let O=0;O<s.linkTo.length;O++){if((0,a.isRef)(N)){if(y.has(N))return;y.add(N);const H=u(N,o,W,y);if(y.delete(N),!H)return;N=H.target,W=H.ancestors,Q=N,O--;continue}const B=N,z=s.linkTo[O];if(typeof z=="string"){if(!B.properties||!(z in B.properties))return;O>0&&(W=[...W,Q]),Q=B,N=B.properties[z]}else{if(!B.eq||!Array.isArray(B.eq)||z>=B.eq.length)return;O>0&&(W=[...W,Q]),Q=B,N=B.eq[z]}}if((0,a.isRef)(N)){if(y.has(N))return;y.add(N);const O=u(N,o,W,y);return y.delete(N),O}return{target:N,ancestors:W}}function d(s,o){const g=o?.env,y=o?.factory??n,P=y.undefinedMot,I=new Map;function N(O,B,z){if(O.deleted)return P;if(I.has(O))return I.get(O);const H=new Map,Y=Q(O.eq,B,z,O),J=y.createMot(Y,H);if(I.set(O,J),O.properties)for(const[K,c]of Object.entries(O.properties)){const m=W(c,B,z,O);m.exists&&H.set(K,m)}return J}function W(O,B,z,H){if((0,a.isRef)(O)){const J=new Set;J.add(O);const K=u(O,B,z,J);if(!K||K.target.deleted)return P;const c=N(K.target,B,K.ancestors);return y.createRefMot(O,c)}const Y=O;return Y.deleted?P:N(Y,B,[...z,H])}function Q(O,B,z,H){if(O!==void 0){if((0,a.isEnvRef)(O)){const Y=g?g[O.env]:void 0;return Y===void 0?void 0:{type:"string",value:Y}}if(Array.isArray(O)){const Y=[...z,H],J=[];for(const K of O)J.push(W(K,B,Y,H));return{type:"array",value:J}}if(typeof O=="string")return{type:"string",value:O};if(typeof O=="number")return{type:"number",value:O};if(typeof O=="boolean")return{type:"boolean",value:O};if(O instanceof Date)return{type:"date",value:O}}}return N(s,s,[s])}return oe}var ne={},de={},qe;function Me(){if(qe)return de;qe=1,Object.defineProperty(de,"__esModule",{value:!0}),de.parse=C;class a{constructor(e){this.input=e,this.pos=0}peekChar(){return this.pos<this.input.length?this.input[this.pos]:void 0}advance(e){this.pos+=e}startsWith(e){return this.input.startsWith(e,this.pos)}eatChar(e){return this.peekChar()===e?(this.advance(1),!0):!1}expectChar(e){if(!this.eatChar(e)){const t=this.peekChar();throw this.errorPoint(`Expected '${e}', found ${t===void 0?"end of input":`'${t}'`}`)}}position(){const e=this.input.substring(0,this.pos),t=(e.match(/\n/g)||[]).length,n=e.lastIndexOf(`
|
|
10
|
+
`),u=this.pos-(n===-1?0:n+1);return{line:t,column:u,offset:this.pos}}errorPoint(e){const t=this.position();return{code:"tag-parse-syntax-error",message:e,begin:t,end:t}}errorSpan(e,t){return{code:"tag-parse-syntax-error",message:e,begin:t,end:this.position()}}skipWs(){for(;;){for(;this.pos<this.input.length;){const e=this.input[this.pos];if(e===" "||e===" "||e==="\r"||e===`
|
|
11
|
+
`)this.pos++;else break}if(this.peekChar()==="#")for(;this.pos<this.input.length;){const e=this.input[this.pos];if(e==="\r"||e===`
|
|
12
|
+
`)break;this.pos++}else break}}skipWsAndCommas(){for(this.skipWs();this.peekChar()===",";)this.advance(1),this.skipWs()}parseStatements(){const e=[];for(this.skipWsAndCommas();this.pos<this.input.length;)e.push(this.parseStatement()),this.skipWsAndCommas();return e}parseStatement(){const e=this.position();if(this.startsWith("-..."))return this.advance(4),{kind:"clearAll",span:{begin:e,end:this.position()}};if(this.peekChar()==="-")return this.advance(1),{kind:"define",path:this.parsePropName(),deleted:!0,span:{begin:e,end:this.position()}};const t=this.parsePropName();this.skipWs();const n=this.peekChar();if(n===":"&&this.startsWith(":=")){this.advance(2),this.skipWs();const u=this.parseEqValue();if(this.skipWs(),this.peekChar()==="{"){const d=this.parsePropertiesBlock();return{kind:"assignBoth",path:t,value:u,properties:d,span:{begin:e,end:this.position()}}}return{kind:"assignBoth",path:t,value:u,properties:null,span:{begin:e,end:this.position()}}}if(n==="="){if(this.advance(1),this.skipWs(),this.peekChar()==="{")throw this.errorPoint("'=' requires a value; use ': { ... }' to replace properties");const u=this.parseEqValue();if(this.skipWs(),this.peekChar()==="{"){const d=this.parsePropertiesBlock();return{kind:"setEq",path:t,value:u,properties:d,span:{begin:e,end:this.position()}}}return{kind:"setEq",path:t,value:u,properties:null,span:{begin:e,end:this.position()}}}if(n===":"){this.advance(1),this.skipWs();const u=this.parsePropertiesBlock();return{kind:"replaceProperties",path:t,properties:u,span:{begin:e,end:this.position()}}}if(n==="{"){const u=this.parsePropertiesBlock();return{kind:"updateProperties",path:t,properties:u,span:{begin:e,end:this.position()}}}return{kind:"define",path:t,deleted:!1,span:{begin:e,end:this.position()}}}parsePropName(){const t=[this.parseIdentifier()];for(;this.peekChar()===".";)this.advance(1),t.push(this.parseIdentifier());return t}parseIdentifier(){return this.peekChar()==="`"?this.parseBacktickString():this.parseBareString()}parseEqValue(e=!0){const t=this.peekChar();if(e&&t==="[")return{kind:"array",elements:this.parseArray()};if(this.startsWith("<<<"))return{kind:"scalar",value:{kind:"string",value:this.parseHeredoc()}};if(t==="@")return{kind:"scalar",value:this.parseAtValue()};if(t==="$")return{kind:"scalar",value:this.parseReference()};if(t==='"')return this.startsWith('"""')?{kind:"scalar",value:{kind:"string",value:this.parseTripleString()}}:{kind:"scalar",value:{kind:"string",value:this.parseDoubleQuotedString()}};if(t==="'")return this.startsWith("'''")?{kind:"scalar",value:{kind:"string",value:this.parseTripleSingleQuotedString()}}:{kind:"scalar",value:{kind:"string",value:this.parseSingleQuotedString()}};if(t!==void 0&&(t==="-"||t>="0"&&t<="9"||t==="."))return this.parseNumberOrString();if(t!==void 0&&E(t))return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}};throw this.errorPoint("Expected a value")}parseAtValue(){const e=this.position();if(this.expectChar("@"),this.startsWith("true")&&!this.isBareCharAt(4))return this.advance(4),{kind:"boolean",value:!0};if(this.startsWith("false")&&!this.isBareCharAt(5))return this.advance(5),{kind:"boolean",value:!1};if(this.startsWith("none")&&!this.isBareCharAt(4))return this.advance(4),{kind:"none"};if(this.startsWith("env."))return this.advance(4),{kind:"env",name:this.parseIdentifier()};const t=this.peekChar();if(t!==void 0&&t>="0"&&t<="9")return this.parseDate(e);const n=this.pos;for(;this.pos<this.input.length&&E(this.input[this.pos]);)this.pos++;const u=this.pos>n?this.input.substring(n,this.pos):"";throw this.errorSpan(`Illegal constant @${u}; expected @true, @false, @none, @env.NAME, or @date`,e)}isBareCharAt(e){const t=this.pos+e;return t<this.input.length&&E(this.input[t])}parseDate(e){const t=this.pos;if(this.consumeDigits(4,e),this.expectChar("-"),this.consumeDigits(2,e),this.expectChar("-"),this.consumeDigits(2,e),this.peekChar()==="T"){if(this.advance(1),this.consumeDigits(2,e),this.expectChar(":"),this.consumeDigits(2,e),this.peekChar()===":"&&(this.advance(1),this.consumeDigits(2,e),this.peekChar()===".")){this.advance(1);const d=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.pos++;if(this.pos===d)throw this.errorSpan("Expected fractional digits in date",e)}const u=this.peekChar();u==="Z"?this.advance(1):(u==="+"||u==="-")&&(this.advance(1),this.consumeDigits(2,e),this.peekChar()===":"&&this.advance(1),this.consumeDigits(2,e))}return{kind:"date",value:this.input.substring(t,this.pos)}}consumeDigits(e,t){for(let n=0;n<e;n++){const u=this.peekChar();if(u===void 0||u<"0"||u>"9")throw this.errorSpan("Expected digit",t);this.advance(1)}}parseOptionalExponent(e){const t=this.peekChar();if(t!=="e"&&t!=="E")return;this.advance(1);const n=this.peekChar();(n==="+"||n==="-")&&this.advance(1);const u=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===u)throw this.errorSpan("Expected exponent digits",e)}parseNumberOrString(){const e=this.pos,t=this.position(),n=this.peekChar()==="-";n&&this.advance(1);let u=!1,d=!1;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)u=!0,this.advance(1);if(this.peekChar()==="."){d=!0,this.advance(1);const y=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===y)return this.pos=e,this.parseIntegerOrBare(e,n)}if(!u&&!d){if(this.pos=e,n)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}this.parseOptionalExponent(t);const s=this.peekChar();if(s!==void 0&&E(s)&&!(s>="0"&&s<="9")){if(this.pos=e,n)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}const o=this.input.substring(e,this.pos),g=parseFloat(o);if(isNaN(g))throw this.errorSpan(`Invalid number: ${o}`,t);return{kind:"scalar",value:{kind:"number",value:g}}}parseIntegerOrBare(e,t){this.pos=e;const n=this.position();t&&this.advance(1);const u=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.advance(1);if(this.pos===u){if(this.pos=e,t)throw this.errorPoint("Expected a value");return{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}if(!t){const o=this.peekChar();if(o!==void 0&&E(o)&&!(o>="0"&&o<="9"))return this.pos=e,{kind:"scalar",value:{kind:"string",value:this.parseBareString()}}}this.parseOptionalExponent(n);const d=this.input.substring(e,this.pos),s=parseFloat(d);if(isNaN(s))throw this.errorSpan(`Invalid number: ${d}`,n);return{kind:"scalar",value:{kind:"number",value:s}}}parseBareString(){const e=this.pos;for(;this.pos<this.input.length&&E(this.input[this.pos]);)this.pos++;if(this.pos===e)throw this.errorPoint("Expected an identifier");return this.input.substring(e,this.pos)}parseDoubleQuotedString(){const e=this.position();this.expectChar('"');let t="";for(;;){const n=this.peekChar();if(n===void 0||n==="\r"||n===`
|
|
13
|
+
`)throw this.errorSpan("Unterminated string",e);if(n==='"')return this.advance(1),t;n==="\\"?(this.advance(1),t+=this.parseEscapeChar()):(this.advance(1),t+=n)}}parseSingleQuotedString(){const e=this.position();this.expectChar("'");let t="";for(;;){const n=this.peekChar();if(n===void 0||n==="\r"||n===`
|
|
14
|
+
`)throw this.errorSpan("Unterminated string",e);if(n==="'")return this.advance(1),t;if(n==="\\"){this.advance(1),t+="\\";const u=this.peekChar();if(u===void 0||u==="\r"||u===`
|
|
15
|
+
`)throw this.errorSpan("Unterminated string",e);this.advance(1),t+=u}else this.advance(1),t+=n}}parseTripleSingleQuotedString(){const e=this.position();if(!this.startsWith("'''"))throw this.errorPoint("Expected triple-single-quoted string");this.advance(3);let t="";for(;;){if(this.startsWith("'''"))return this.advance(3),t;const n=this.peekChar();if(n===void 0)throw this.errorSpan("Unterminated triple-single-quoted string",e);if(n==="\\"){this.advance(1),t+="\\";const u=this.peekChar();if(u===void 0)throw this.errorSpan("Unterminated triple-single-quoted string",e);this.advance(1),t+=u}else this.advance(1),t+=n}}parseBacktickString(){const e=this.position();this.expectChar("`");let t="";for(;;){const n=this.peekChar();if(n===void 0||n==="\r"||n===`
|
|
16
|
+
`)throw this.errorSpan("Unterminated backtick string",e);if(n==="`")return this.advance(1),t;n==="\\"?(this.advance(1),t+=this.parseEscapeChar()):(this.advance(1),t+=n)}}parseTripleString(){const e=this.position();if(!this.startsWith('"""'))throw this.errorPoint("Expected triple-quoted string");this.advance(3);let t="";for(;;){if(this.startsWith('"""'))return this.advance(3),t;const n=this.peekChar();if(n===void 0)throw this.errorSpan("Unterminated triple-quoted string",e);n==="\\"?(this.advance(1),t+=this.parseEscapeChar()):(this.advance(1),t+=n)}}parseEscapeChar(){const e=this.peekChar();if(e===void 0)throw this.errorPoint("Unterminated escape sequence");switch(e){case"b":return this.advance(1),"\b";case"f":return this.advance(1),"\f";case"n":return this.advance(1),`
|
|
17
|
+
`;case"r":return this.advance(1),"\r";case"t":return this.advance(1)," ";case"u":{const t=this.position();this.advance(1);const n=this.pos;for(let s=0;s<4;s++){const o=this.peekChar();if(o===void 0||!M(o))throw this.errorSpan("Expected 4 hex digits in \\uXXXX",t);this.advance(1)}const u=this.input.substring(n,this.pos),d=parseInt(u,16);return String.fromCharCode(d)}default:return this.advance(1),e}}parseHeredoc(){const e=this.position();for(this.advance(3);this.pos<this.input.length;){const s=this.input[this.pos];if(s===" "||s===" ")this.pos++;else break}if(this.pos<this.input.length&&this.input[this.pos]==="\r"&&this.advance(1),this.pos>=this.input.length||this.input[this.pos]!==`
|
|
18
|
+
`)throw this.errorSpan("Expected newline after <<<",e);this.advance(1);const t=[];let n=!1;for(;this.pos<this.input.length;){const s=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]!==`
|
|
19
|
+
`;)this.pos++;let o=this.input.substring(s,this.pos);if(o.endsWith("\r")&&(o=o.substring(0,o.length-1)),this.pos<this.input.length&&this.input[this.pos]===`
|
|
20
|
+
`&&this.advance(1),o.trim()===">>>"){n=!0;break}t.push(o)}if(!n)throw this.errorSpan("Unterminated heredoc (expected >>>)",e);if(t.length===0)return"";let u=0;for(const s of t){const o=s.trimStart();if(o.length>0){u=s.length-o.length;break}}return t.map(s=>s.trimStart().length===0?"":u<=s.length?s.substring(u):s).join(`
|
|
21
|
+
`)+`
|
|
22
|
+
`}parseArray(){const e=this.position();if(this.expectChar("["),this.skipWs(),this.eatChar("]"))return[];const t=[];for(t.push(this.parseArrayElement());;){if(this.skipWs(),this.eatChar("]"))return t;if(this.eatChar(",")){if(this.skipWs(),this.peekChar()==="]")return this.advance(1),t;t.push(this.parseArrayElement())}else throw this.pos>=this.input.length?this.errorSpan("Unclosed '['",e):this.errorPoint("Expected ',' or ']' in array")}}parseArrayElement(){this.skipWs();const e=this.position(),t=this.peekChar();if(t==="{")return{value:null,properties:this.parsePropertiesBlock(),span:{begin:e,end:this.position()}};if(t==="["){const u=this.parseArray();if(this.skipWs(),this.peekChar()==="{"){const d=this.parsePropertiesBlock();return{value:{kind:"array",elements:u},properties:d,span:{begin:e,end:this.position()}}}return{value:{kind:"array",elements:u},properties:null,span:{begin:e,end:this.position()}}}const n=this.parseEqValue(!1);if(this.skipWs(),this.peekChar()==="{"){const u=this.parsePropertiesBlock();return{value:n,properties:u,span:{begin:e,end:this.position()}}}return{value:n,properties:null,span:{begin:e,end:this.position()}}}parsePropertiesBlock(){const e=this.position();this.expectChar("{");const t=[];for(;;){if(this.skipWsAndCommas(),this.eatChar("}"))return t;if(this.pos>=this.input.length)throw this.errorSpan("Unclosed '{'",e);t.push(this.parseStatement())}}parseReference(){this.expectChar("$");let e=0;for(;this.peekChar()==="^";)this.advance(1),e++;if(e>0){if(this.peekChar()!==".")return{kind:"reference",ups:e,path:[]};this.advance(1)}const t=[],n=this.parseIdentifier();if(t.push({kind:"name",name:n}),this.peekChar()==="["){this.advance(1),this.skipWs();const u=this.parseRefIndex();t.push({kind:"index",index:u}),this.skipWs(),this.expectChar("]")}for(;this.peekChar()===".";){this.advance(1);const u=this.parseIdentifier();if(t.push({kind:"name",name:u}),this.peekChar()==="["){this.advance(1),this.skipWs();const d=this.parseRefIndex();t.push({kind:"index",index:d}),this.skipWs(),this.expectChar("]")}}return{kind:"reference",ups:e,path:t}}parseRefIndex(){const e=this.position(),t=this.pos;for(;this.pos<this.input.length&&this.input[this.pos]>="0"&&this.input[this.pos]<="9";)this.pos++;if(this.pos===t)throw this.errorPoint("Expected array index");const n=parseInt(this.input.substring(t,this.pos),10);if(isNaN(n))throw this.errorSpan("Invalid array index",e);return n}}function E(i){const e=i.charCodeAt(0);return e>=48&&e<=57||e>=65&&e<=90||e>=97&&e<=122||e===95||e>=192&&e<=591||e>=7680&&e<=7935}function M(i){const e=i.charCodeAt(0);return e>=48&&e<=57||e>=65&&e<=70||e>=97&&e<=102}function C(i){return new a(i).parseStatements()}return de}var fe={},re={},we;function Oe(){if(we)return re;we=1,Object.defineProperty(re,"__esModule",{value:!0}),re.clonePropertyValue=re.cloneValue=void 0,re.cloneNode=E,re.cloneMotlyNode=M;const a=le();function E(C){const i={};if(C.deleted&&(i.deleted=!0),C.eq!==void 0&&(C.eq instanceof Date?i.eq=new Date(C.eq.getTime()):Array.isArray(C.eq)?i.eq=C.eq.map(M):(0,a.isEnvRef)(C.eq)?i.eq={env:C.eq.env}:i.eq=C.eq),C.properties){const e={};for(const t of Object.keys(C.properties))e[t]=M(C.properties[t]);i.properties=e}return C.location&&(i.location={parseId:C.location.parseId,begin:{...C.location.begin},end:{...C.location.end}}),i}function M(C){return(0,a.isRef)(C)?{linkTo:[...C.linkTo],linkUps:C.linkUps}:E(C)}return re.cloneValue=E,re.clonePropertyValue=M,re}var Ae;function Te(){if(Ae)return fe;Ae=1,Object.defineProperty(fe,"__esModule",{value:!0}),fe.flatten=M,fe.chunk=e,fe.topoSort=o,fe.executeChunked=g;const a=le(),E=Oe();function M(r,l){const p=[];return C(r,[],l.parseId,p),p}function C(r,l,p,h){for(const f of r)i(f,l,p,h)}function i(r,l,p,h){switch(r.kind){case"setEq":{const f=[...l,...r.path];if(r.value.kind==="scalar"&&r.value.value.kind==="reference"){const b=r.value.value;h.push({path:f,op:{kind:"link",ups:b.ups,refPath:b.path},span:r.span,parseId:p})}else h.push({path:f,op:{kind:"setValue",value:r.value},span:r.span,parseId:p}),r.properties!==null&&C(r.properties,f,p,h);break}case"assignBoth":{const f=[...l,...r.path];if(r.value.kind==="scalar"&&r.value.value.kind==="reference"){const b=r.value.value;h.push({path:f,op:{kind:"clone",ups:b.ups,refPath:b.path},span:r.span,parseId:p}),r.properties!==null&&(h.push({path:f,op:{kind:"clearProperties"},span:r.span,parseId:p}),C(r.properties,f,p,h))}else h.push({path:f,op:{kind:"assignValue",value:r.value},span:r.span,parseId:p}),r.properties!==null&&C(r.properties,f,p,h);break}case"replaceProperties":{const f=[...l,...r.path];h.push({path:f,op:{kind:"clearProperties"},span:r.span,parseId:p}),C(r.properties,f,p,h);break}case"updateProperties":{const f=[...l,...r.path];h.push({path:f,op:{kind:"define"},span:r.span,parseId:p}),C(r.properties,f,p,h);break}case"define":{const f=[...l,...r.path];h.push({path:f,op:{kind:r.deleted?"delete":"define"},span:r.span,parseId:p});break}case"clearAll":{h.push({path:[...l],op:{kind:"clearAll"},span:r.span,parseId:p});break}}}function e(r){const l=r.length;if(l===0)return{splits:[0],deps:[]};const p=new Map;for(let D=0;D<l;D++)p.set(t(r[D].path),D);const h=new Set([0,l]),f=new Set,b=[];for(let D=0;D<l;D++){const F=r[D],G=t(F.path);if(F.op.kind==="link"||F.op.kind==="clone"){const Z=d(F.path,F.op.ups,F.op.refPath);if(!n(f,Z)){b.push({refIdx:D,targetKey:Z}),h.add(D),h.add(D+1);const ie=u(p,Z);ie>D&&h.add(ie)}}f.add(G)}const w=Array.from(h).sort((D,F)=>D-F),$=w.length-1,_=Array.from({length:$},()=>new Set);for(const{refIdx:D,targetKey:F}of b){const G=s(w,D),Z=u(p,F);if(Z!==-1){const ee=s(w,Z);ee!==G&&_[G].add(ee)}const ie=t(r[D].path);for(let ee=D+1;ee<l;ee++){const ce=t(r[ee].path);if(ce===ie||ce.startsWith(ie+"\0")){const he=s(w,ee);he!==G&&_[he].add(G)}}}const x=_.map(D=>Array.from(D));return{splits:w,deps:x}}function t(r){return r.join("\0")}function n(r,l){for(const p of r)if(p===l||p.startsWith(l+"\0"))return!0;return!1}function u(r,l){let p=-1;for(const[h,f]of r)(h===l||h.startsWith(l+"\0")||l.startsWith(h+"\0"))&&(p=Math.max(p,f));return p}function d(r,l,p){const h=[];if(l>0){const f=Math.max(0,r.length-1-l);for(let b=0;b<f;b++)h.push(r[b])}for(const f of p)f.kind==="name"?h.push(f.name):h.push(`[${f.index}]`);return h.join("\0")}function s(r,l){let p=0,h=r.length-2;for(;p<h;){const f=p+h+1>>1;r[f]<=l?p=f:h=f-1}return p}function o(r){const l=r.length,p=new Array(l).fill(0),h=Array.from({length:l},()=>[]);for(let _=0;_<l;_++)for(const x of r[_])h[x].push(_),p[_]++;const f=[];for(let _=0;_<l;_++)p[_]===0&&f.push(_);const b=[];let w=0;for(;w<f.length;){const _=f[w++];b.push(_);for(const x of h[_])--p[x]===0&&f.push(x)}const $=[];if(b.length<l){const _=new Set(b);for(let x=0;x<l;x++)_.has(x)||$.push(x)}return{order:b,cycles:$}}function g(r,l,p,h,f){const b=[],w=[];for(const $ of p){const _=l[$],x=l[$+1];for(let D=_;D<x;D++)P(r[D],h,f,b,w)}return y(b,w),b}function y(r,l){if(l.length<2)return;const p=new Map;for(const w of l)p.set(w.sourcePath,w);const h=new Set,f=new Set;for(const w of l){if(f.has(w.sourcePath))continue;const $=[],_=new Set;let x=w;for(;x&&!_.has(x.sourcePath)&&!f.has(x.sourcePath);)$.push(x),_.add(x.sourcePath),x=p.get(x.targetPath);if(x&&_.has(x.sourcePath)){const D=x.sourcePath,F=[];let G=!1;for(const X of $)X.sourcePath===D&&(G=!0),G&&F.push(X);const Z=X=>X.replace(/\0/g,"."),ie=F.map(X=>Z(X.sourcePath)),ee=F.map(X=>`$${Z(X.targetPath)}`);let ce=ie[0];for(let X=0;X<ee.length;X++)ce+=` clones ${ee[X]}`,X<ee.length-1&&(ce+=`, ${ie[X+1]}`);for(const X of F)h.add(X.errorIndex);const he=F[0].errorIndex,ye={line:0,column:0,offset:0};r[he]={code:"circular-reference",message:`Circular clone dependency: ${ce}`,begin:ye,end:ye}}for(const D of $)f.add(D.sourcePath)}const b=Array.from(h).sort((w,$)=>$-w);for(const w of b)r[w].code!=="circular-reference"&&r.splice(w,1)}function P(r,l,p,h,f){const b={parseId:r.parseId,options:p};switch(r.op.kind){case"setValue":I(r.path,r.op.value,l,b,r.span,h);break;case"assignValue":N(r.path,r.op.value,l,b,r.span,h);break;case"clearProperties":W(r.path,l,b,r.span,h);break;case"clearAll":Q(r.path,l,b,r.span,h);break;case"define":O(r.path,l,b,r.span,h);break;case"delete":B(r.path,l,b,r.span,h);break;case"link":z(r.path,r.op.ups,r.op.refPath,l,b,r.span,h);break;case"clone":H(r.path,r.op.ups,r.op.refPath,l,b,r.span,h,f);break}}function I(r,l,p,h,f,b){if(r.length===0){c(p,l,h,b);return}const w=K(p,r,h,f,b);if(!w)return;const[$,_]=w,x=T(_);x[$]===void 0&&(x[$]={});const D=V(x,$);J(D,h,f),c(D,l,h,b)}function N(r,l,p,h,f,b){if(r.length===0){delete p.properties,p.location=Y(h,f),c(p,l,h,b);return}const w=K(p,r,h,f,b);if(!w)return;const[$,_]=w,x={};x.location=Y(h,f),c(x,l,h,b),T(_)[$]=x}function W(r,l,p,h,f){if(r.length===0){delete l.properties;return}const b=K(l,r,p,h,f);if(!b)return;const[w,$]=b,_=T($),x=_[w];if(x!==void 0&&!(0,a.isRef)(x))delete x.properties;else{const D={};D.location=Y(p,h),_[w]=D}}function Q(r,l,p,h,f){if(r.length===0){delete l.eq,l.properties={};return}const b=K(l,r,p,h,f);if(!b)return;const[w,$]=b,_=T($),x=_[w];x!==void 0&&!(0,a.isRef)(x)?(delete x.eq,x.properties={}):_[w]={}}function O(r,l,p,h,f){const b=K(l,r,p,h,f);if(!b)return;const[w,$]=b,_=T($);if(_[w]===void 0){const x={};x.location=Y(p,h),_[w]=x}}function B(r,l,p,h,f){const b=K(l,r,p,h,f);if(!b)return;const[w,$]=b,_={deleted:!0};_.location=Y(p,h),T($)[w]=_}function z(r,l,p,h,f,b,w){f.options.disableReferences&&w.push({code:"ref-not-allowed",message:"References are not allowed in this session. Use := for cloning.",begin:b.begin,end:b.end});const $=K(h,r,f,b,w);if(!$)return;const[_,x]=$;T(x)[_]=v(l,p)}function H(r,l,p,h,f,b,w,$){const _=K(h,r,f,b,w);if(!_)return;const[x,D]=_;let F;try{F=R(h,r,l,p)}catch(G){if((0,a.isMotlyError)(G)){const Z=w.length;w.push(G),$.push({sourcePath:t(r),targetPath:d(r,l,p),errorIndex:Z})}return}j(F,0,w),F.location=Y(f,b),T(D)[x]=F}function Y(r,l){return{parseId:r.parseId,begin:l.begin,end:l.end}}function J(r,l,p){r.location||(r.location=Y(l,p))}function K(r,l,p,h,f){let b=r;for(let w=0;w<l.length-1;w++){const $=l[w],_=T(b);if(_[$]!==void 0&&(0,a.isRef)(_[$]))return f.push({code:"write-through-link",message:`Cannot write through link reference "${$}"`,begin:h.begin,end:h.end}),null;if(_[$]===void 0){const x={};x.location=Y(p,h),_[$]=x}b=V(_,$),J(b,p,h)}return[l[l.length-1],b]}function c(r,l,p,h){if(l.kind==="array")r.eq=m(l.elements,h,p);else{const f=l.value;switch(f.kind){case"string":r.eq=f.value;break;case"number":r.eq=f.value;break;case"boolean":r.eq=f.value;break;case"date":r.eq=new Date(f.value);break;case"reference":throw new Error("References should be handled before calling setEqSlot");case"env":r.eq={env:f.name};break;case"none":delete r.eq;break}}}function m(r,l,p){return r.map(h=>q(h,l,p))}function q(r,l,p){if(r.value!==null&&r.value.kind==="scalar"&&r.value.value.kind==="reference"){if(p.options.disableReferences&&l.push({code:"ref-not-allowed",message:"References are not allowed in this session. Use := for cloning.",begin:r.span.begin,end:r.span.end}),r.properties!==null){const f={line:0,column:0,offset:0};l.push({code:"ref-with-properties",message:"Cannot add properties to a reference. Did you mean := (clone)?",begin:f,end:f})}return v(r.value.value.ups,r.value.value.path)}const h={};if(h.location=Y(p,r.span),r.value!==null&&c(h,r.value,p,l),r.properties!==null){const f=M(r.properties,p),{splits:b,deps:w}=e(f),{order:$}=o(w);l.push(...g(f,b,$,h,p.options))}return h}function v(r,l){return{linkTo:l.map(p=>p.kind==="name"?p.name:p.index),linkUps:r}}function k(r,l){let p="$";for(let f=0;f<r;f++)p+="^";let h=!0;for(const f of l)f.kind==="name"?((!h||r>0)&&(p+="."),p+=f.name,h=!1):p+=`[${f.index}]`;return p}function R(r,l,p,h){const f=k(p,h);let b;if(p===0)b=r;else{const $=l.length-1-p;if($<0)throw A(`Clone reference ${f} goes ${p} level(s) up but only ${l.length-1} ancestor(s) available`);b=r;for(let _=0;_<$;_++){if(!b.properties)throw A(`Clone reference ${f} could not be resolved: path segment "${l[_]}" not found`);const x=b.properties[l[_]];if(x===void 0)throw A(`Clone reference ${f} could not be resolved: path segment "${l[_]}" not found`);if((0,a.isRef)(x)){const D=S(r,x);if(!D)throw A(`Clone reference ${f} could not be resolved: path segment "${l[_]}" is an unresolvable link reference`);b=D;continue}b=x}}let w=b;for(const $ of h)if($.kind==="name"){if(!w.properties)throw A(`Clone reference ${f} could not be resolved: property "${$.name}" not found`);const _=w.properties[$.name];if(_===void 0)throw A(`Clone reference ${f} could not be resolved: property "${$.name}" not found`);if((0,a.isRef)(_)){const x=S(r,_);if(!x)throw A(`Clone reference ${f} could not be resolved: property "${$.name}" is an unresolvable link reference`);w=x;continue}w=_}else{if(!w.eq||!Array.isArray(w.eq))throw A(`Clone reference ${f} could not be resolved: index [${$.index}] used on non-array`);if($.index>=w.eq.length)throw A(`Clone reference ${f} could not be resolved: index [${$.index}] out of bounds (array length ${w.eq.length})`);const _=w.eq[$.index];if((0,a.isRef)(_)){const x=S(r,_);if(!x)throw A(`Clone reference ${f} could not be resolved: index [${$.index}] is an unresolvable link reference`);w=x;continue}w=_}return(0,E.cloneNode)(w)}function A(r){const l={line:0,column:0,offset:0};return{code:"unresolved-clone-reference",message:r,begin:l,end:l}}function S(r,l,p){p||(p=new Set);const h=(0,a.formatRef)(l);if(p.has(h)||(p.add(h),l.linkUps>0))return null;let f=r;for(const b of l.linkTo){if(f===void 0)return null;if((0,a.isRef)(f)){const $=S(r,f,p);if(!$)return null;f=$}if(!(0,a.isDataNode)(f))return null;const w=f;if(typeof b=="string"){if(!w.properties||!(b in w.properties))return null;f=w.properties[b]}else{if(!w.eq||!Array.isArray(w.eq)||b>=w.eq.length)return null;f=w.eq[b]}}return f!==void 0&&(0,a.isRef)(f)?S(r,f,p):f??null}function j(r,l,p){if(r.eq!==void 0&&Array.isArray(r.eq))for(let h=0;h<r.eq.length;h++)U(r.eq,h,l+1,p);if(r.properties)for(const h of Object.keys(r.properties))L(r.properties,h,l+1,p)}function U(r,l,p,h){const f=r[l];if((0,a.isRef)(f)){if(f.linkUps>0&&f.linkUps>p){const b={line:0,column:0,offset:0};h.push({code:"clone-reference-out-of-scope",message:`Cloned reference "${(0,a.formatRef)(f)}" escapes the clone boundary (${f.linkUps} level(s) up from depth ${p})`,begin:b,end:b}),r[l]={}}}else j(f,p,h)}function L(r,l,p,h){const f=r[l];if((0,a.isRef)(f)){if(f.linkUps>0&&f.linkUps>p){const b={line:0,column:0,offset:0};h.push({code:"clone-reference-out-of-scope",message:`Cloned reference "${(0,a.formatRef)(f)}" escapes the clone boundary (${f.linkUps} level(s) up from depth ${p})`,begin:b,end:b}),r[l]={}}}else j(f,p,h)}function T(r){return r.properties||(r.properties={}),r.properties}function V(r,l){const p=r[l];if((0,a.isRef)(p)){const h={};return r[l]=h,h}return p}return fe}var pe={},Re;function je(){if(Re)return pe;Re=1,Object.defineProperty(pe,"__esModule",{value:!0}),pe.validateReferences=M,pe.validateSchema=d;const a=le();function E(c,m,q,v,k){const R={code:m,message:q,path:v};k?.location&&(R.location=k.location),c.push(R)}function M(c){const m=[];return C(c,[],[c],c,m),m}function C(c,m,q,v,k){if(c.eq!==void 0&&Array.isArray(c.eq)&&i(c.eq,m,q,c,v,k),c.properties)for(const R of Object.keys(c.properties)){const A=c.properties[R];if(m.push(R),(0,a.isRef)(A)){const S=e(A,q,v);if(S!==null){const j={message:S,path:[...m],code:"unresolved-reference"};c.location&&(j.location=c.location),k.push(j)}}else q.push(c),C(A,m,q,v,k),q.pop();m.pop()}}function i(c,m,q,v,k,R){for(let A=0;A<c.length;A++){const S=c[A],j=`[${A}]`;if(m.push(j),(0,a.isRef)(S)){const U=e(S,q,k);U!==null&&R.push({message:U,path:[...m],code:"unresolved-reference"})}else q.push(v),C(S,m,q,k,R),q.pop();m.pop()}}function e(c,m,q){const v=(0,a.formatRef)(c);let k;if(c.linkUps===0)k=q;else{const R=m.length-c.linkUps;if(R<0||R>=m.length)return`Reference "${v}" goes ${c.linkUps} level(s) up but only ${m.length} ancestor(s) available`;k=m[R]}return t(k,c.linkTo,v)}function t(c,m,q){let v=c;for(const k of m){if(v==="terminal")return`Reference "${q}" could not be resolved: cannot follow path through a link`;if(typeof k=="string"){if(!v.properties)return`Reference "${q}" could not be resolved: property "${k}" not found (node has no properties)`;const R=v.properties[k];if(R===void 0)return`Reference "${q}" could not be resolved: property "${k}" not found`;(0,a.isRef)(R)?v="terminal":v=R}else{if(v.eq===void 0||!Array.isArray(v.eq))return`Reference "${q}" could not be resolved: index [${k}] used on non-array`;if(k>=v.eq.length)return`Reference "${q}" could not be resolved: index [${k}] out of bounds (array length ${v.eq.length})`;const R=v.eq[k];(0,a.isRef)(R)?v="terminal":v=R}}return null}const n=64,u={string:{properties:{VALUE:{eq:"string"}}},number:{properties:{VALUE:{eq:"number"}}},integer:{properties:{VALUE:{eq:"integer"}}},boolean:{properties:{VALUE:{eq:"boolean"}}},date:{properties:{VALUE:{eq:"date"}}},flag:{properties:{ADDITIONAL:{eq:"reject"}}},tag:{properties:{ADDITIONAL:{eq:"accept"}}},any:{properties:{ADDITIONAL:{eq:"accept"}}}};function d(c,m){const q=[],v=s(m,q);return g(c,m,v,[],q,0),q}function s(c,m){const q={...u},v=o(c,"TYPES");if(v?.properties){for(const[k,R]of Object.entries(v.properties))if(!(0,a.isRef)(R)){if(k in u){m.push({message:`Type "${k}" cannot shadow pre-loaded type`,path:["TYPES",k],code:"invalid-schema"});continue}q[k]=R}}return q}function o(c,m){if(!c.properties)return;const q=c.properties[m];if(!(q===void 0||(0,a.isRef)(q)))return q}function g(c,m,q,v,k,R){if(R>n){E(k,"invalid-schema","Maximum validation depth exceeded (possible recursive type cycle)",[...v],c);return}const A=o(m,"ONEOF");if(A&&Array.isArray(A.eq)){Y(c,A.eq,q,v,k,R);return}const S=o(m,"VALUE");S&&y(c,S,q,v,k),O(c,m,q,v,k,R)}function y(c,m,q,v,k,R){const A=typeof m.eq=="string"?m.eq:void 0;if(!A)return;const S=c.eq;switch(A){case"string":if(typeof S!="string"){E(k,"wrong-type",`Expected string, got ${P(S)}`,[...v],c);return}I(S,m,v,k,c);break;case"number":if(typeof S!="number"){E(k,"wrong-type",`Expected number, got ${P(S)}`,[...v],c);return}N(S,m,v,k,c);break;case"integer":if(typeof S!="number"||!Number.isInteger(S)){E(k,"wrong-type",`Expected integer, got ${P(S)}`,[...v],c);return}N(S,m,v,k,c);break;case"boolean":if(typeof S!="boolean"){E(k,"wrong-type",`Expected boolean, got ${P(S)}`,[...v],c);return}W(S,m,v,k,c);break;case"date":if(!(S instanceof Date)){E(k,"wrong-type",`Expected date, got ${P(S)}`,[...v],c);return}W(S,m,v,k,c);break;default:{const j=q[A];if(!j){E(k,"invalid-schema",`Unknown VALUE type "${A}"`,[...v],c);return}const U=o(j,"VALUE");if(!U){E(k,"invalid-schema",`Type "${A}" cannot be used as a VALUE type (no VALUE constraint)`,[...v],c);return}y(c,U,q,v,k)}}}function P(c){return c===void 0?"no value":c instanceof Date?`date ${c.toISOString()}`:Array.isArray(c)?"array":typeof c=="string"?`string ${JSON.stringify(c)}`:typeof c=="number"||typeof c=="boolean"?`${typeof c} ${c}`:typeof c}function I(c,m,q,v,k){W(c,m,q,v,k);const R=o(m,"MATCHES");if(R&&typeof R.eq=="string")try{new RegExp(R.eq).test(c)||E(v,"pattern-mismatch",`Value "${c}" does not match pattern "${R.eq}"`,[...q],k)}catch(j){E(v,"invalid-schema",`Invalid regex pattern "${R.eq}": ${j}`,[...q],k)}const A=o(m,"MIN_LENGTH");A&&typeof A.eq=="number"&&c.length<A.eq&&E(v,"length-violation",`String length ${c.length} is less than minimum ${A.eq}`,[...q],k);const S=o(m,"MAX_LENGTH");S&&typeof S.eq=="number"&&c.length>S.eq&&E(v,"length-violation",`String length ${c.length} exceeds maximum ${S.eq}`,[...q],k)}function N(c,m,q,v,k){W(c,m,q,v,k);const R=o(m,"MIN");R&&typeof R.eq=="number"&&c<R.eq&&E(v,"out-of-range",`Value ${c} is less than minimum ${R.eq}`,[...q],k);const A=o(m,"MAX");A&&typeof A.eq=="number"&&c>A.eq&&E(v,"out-of-range",`Value ${c} exceeds maximum ${A.eq}`,[...q],k)}function W(c,m,q,v,k){const R=o(m,"ENUM");if(!R||!Array.isArray(R.eq))return;if(!R.eq.some(S=>{if((0,a.isRef)(S))return!1;const j=S.eq;return j instanceof Date&&c instanceof Date?j.getTime()===c.getTime():j===c})){const S=R.eq.filter(j=>!(0,a.isRef)(j)).map(j=>String(j.eq));E(v,"invalid-enum-value",`${P(c)} is not one of: [${S.join(", ")}]`,[...q],k)}}function Q(c){if(!c.properties)return{kind:"reject"};const m=c.properties.ADDITIONAL;return m===void 0?{kind:"reject"}:(0,a.isRef)(m)?{kind:"reject"}:typeof m.eq=="string"?m.eq==="reject"?{kind:"reject"}:m.eq==="accept"?{kind:"accept"}:{kind:"type",typeName:m.eq}:m.properties&&Object.keys(m.properties).some(v=>v==="VALUE"||v==="REQUIRED"||v==="OPTIONAL"||v==="ADDITIONAL"||v==="ONEOF")?{kind:"inline",constraint:m}:{kind:"accept"}}function O(c,m,q,v,k,R){const A=o(m,"REQUIRED")?.properties,S=o(m,"OPTIONAL")?.properties,j=Q(m),U=c.properties;if(A)for(const[L,T]of Object.entries(A)){if((0,a.isRef)(T))continue;const V=[...v,L],r=U?.[L];r===void 0?E(k,"missing-required",`Missing required property "${L}"`,V,c):B(r,T,q,V,k,R)}if(S&&U)for(const[L,T]of Object.entries(S)){if((0,a.isRef)(T))continue;const V=U[L];V!==void 0&&B(V,T,q,[...v,L],k,R)}if(U){const L=new Set;if(A)for(const T of Object.keys(A))L.add(T);if(S)for(const T of Object.keys(S))L.add(T);for(const T of Object.keys(U)){if(L.has(T))continue;const V=[...v,T];switch(j.kind){case"reject":{const r=U[T];E(k,"unknown-property",`Unknown property "${T}"`,V,(0,a.isRef)(r)?void 0:r);break}case"accept":break;case"type":B(U[T],{eq:j.typeName},q,V,k,R);break;case"inline":{const r=U[T];(0,a.isRef)(r)?E(k,"wrong-type",`Expected a value but found a link ${(0,a.formatRef)(r)}`,V):g(r,j.constraint,q,V,k,R+1);break}}}}J(A,S,U,v,k),K(A,S,U,v,k)}function B(c,m,q,v,k,R){if((0,a.isRef)(c)){E(k,"wrong-type",`Expected a value but found a link ${(0,a.formatRef)(c)}`,[...v]);return}const A=typeof m.eq=="string"?m.eq:void 0;if(A){z(c,A,q,v,k,R);return}g(c,m,q,v,k,R+1)}function z(c,m,q,v,k,R){if(m.endsWith("[]")){H(c,m.slice(0,-2),q,v,k,R);return}const A=q[m];if(!A){E(k,"invalid-schema",`Unknown type "${m}" in schema`,[...v],c);return}if(Array.isArray(A.eq)){Y(c,A.eq,q,v,k,R);return}g(c,A,q,v,k,R+1)}function H(c,m,q,v,k,R){if(!Array.isArray(c.eq)){E(k,"wrong-type",`Expected ${m}[], got ${P(c.eq)}`,[...v],c);return}for(let A=0;A<c.eq.length;A++){const S=[...v,`[${A}]`],j=c.eq[A];(0,a.isRef)(j)?E(k,"wrong-type",`Expected ${m}, got link ${(0,a.formatRef)(j)}`,S):z(j,m,q,S,k,R)}}function Y(c,m,q,v,k,R){const A=[];let S,j;for(const L of m){if((0,a.isRef)(L))continue;const T=typeof L.eq=="string"?L.eq:void 0;if(!T)continue;A.push(T);const V=[];if(z(c,T,q,v,V,R),V.length===0)return;(!S||V.length<S.length)&&(S=V,j=T)}let U=`Value does not match any type in oneOf: [${A.join(", ")}]`;if(S&&S.length>0&&A.length>1){const L=S.map(T=>T.message).join("; ");U+=`. Closest match "${j}": ${L}`}E(k,"wrong-type",U,[...v],c)}function J(c,m,q,v,k){if(!q)return;const R={};function A(S){if(S)for(const[j,U]of Object.entries(S)){if((0,a.isRef)(U))continue;const L=o(U,"EXCLUSIVE");if(!L)continue;let T;if(typeof L.eq=="string")T=[L.eq];else if(Array.isArray(L.eq))T=L.eq.filter(V=>!(0,a.isRef)(V)).map(V=>String(V.eq));else continue;for(const V of T)R[V]||(R[V]=[]),R[V].push(j)}}A(c),A(m);for(const[S,j]of Object.entries(R)){const U=j.filter(L=>q[L]!==void 0);U.length>1&&E(k,"exclusive-violation",`Properties [${U.join(", ")}] are mutually exclusive (group "${S}")`,[...v])}}function K(c,m,q,v,k){if(!q)return;function R(A){if(A)for(const[S,j]of Object.entries(A)){if((0,a.isRef)(j)||q[S]===void 0)continue;const U=o(j,"REQUIRES");if(!(!U||!Array.isArray(U.eq)))for(const L of U.eq){if((0,a.isRef)(L))continue;const T=typeof L.eq=="string"?L.eq:void 0;T&&q[T]===void 0&&E(k,"requires-violation",`Property "${S}" requires "${T}" to be present`,[...v,S])}}}R(c),R(m)}return pe}var Ee;function De(){if(Ee)return ne;Ee=1,Object.defineProperty(ne,"__esModule",{value:!0}),ne.MOTLYSchema=ne.MOTLYResult=ne.MOTLYSession=void 0;const a=le(),E=Me(),M=Te(),C=je(),i=Oe(),e=Pe();class t{constructor(s){this.accumulated=[],this.nextParseId=0,this.finished=!1,this.disposed=!1,this.options=s??{}}parse(s){if(this.ensureAlive(),this.finished)throw new Error("MOTLYSession is spent after finish() — create a new session");const o=this.nextParseId++;try{const g=(0,E.parse)(s);return this.accumulated.push({stmts:g,parseId:o}),{parseId:o,errors:[]}}catch(g){if((0,a.isMotlyError)(g))return{parseId:o,errors:[g]};throw g}}finish(){if(this.ensureAlive(),this.finished)throw new Error("finish() has already been called on this session");this.finished=!0;const s=[],o={},g=[];for(const{stmts:W,parseId:Q}of this.accumulated){const O={parseId:Q,options:{disableReferences:this.options.disableReferences}};g.push(...(0,M.flatten)(W,O))}const{splits:y,deps:P}=(0,M.chunk)(g),{order:I}=(0,M.topoSort)(P),N=(0,M.executeChunked)(g,y,I,o,this.options);if(s.push(...N),!this.options.disableReferences){const W=(0,C.validateReferences)(o);for(const Q of W)s.push({code:Q.code,message:Q.message,begin:{line:0,column:0,offset:0},end:{line:0,column:0,offset:0}})}return new n(o,s)}dispose(){this.disposed=!0}ensureAlive(){if(this.disposed)throw new Error("MOTLYSession has been disposed")}}ne.MOTLYSession=t;class n{constructor(s,o){this.value=s,this.errors=o}getValue(){return(0,i.cloneNode)(this.value)}getMot(s){return(0,e.buildMot)(this.value,s)}}ne.MOTLYResult=n;class u{constructor(s){this.tree=s}static parse(s){const o={disableReferences:!0},g={parseId:0,options:o};try{const y=(0,E.parse)(s),P={},I=(0,M.flatten)(y,g),{splits:N,deps:W}=(0,M.chunk)(I),{order:Q}=(0,M.topoSort)(W),O=(0,M.executeChunked)(I,N,Q,P,o);return{schema:new u(P),errors:O}}catch(y){if((0,a.isMotlyError)(y))return{schema:new u({}),errors:[y]};throw y}}validate(s){return(0,C.validateSchema)(s,this.tree)}}return ne.MOTLYSchema=u,ne}var Se;function Ie(){return Se||(Se=1,(function(a){Object.defineProperty(a,"__esModule",{value:!0}),a.MOTLYSchema=a.MOTLYResult=a.MOTLYSession=a.MotValue=a.Mot=a.formatRef=a.isMotlyError=a.isEnvRef=a.isDataNode=a.isRef=void 0;var E=le();Object.defineProperty(a,"isRef",{enumerable:!0,get:function(){return E.isRef}}),Object.defineProperty(a,"isDataNode",{enumerable:!0,get:function(){return E.isDataNode}}),Object.defineProperty(a,"isEnvRef",{enumerable:!0,get:function(){return E.isEnvRef}}),Object.defineProperty(a,"isMotlyError",{enumerable:!0,get:function(){return E.isMotlyError}}),Object.defineProperty(a,"formatRef",{enumerable:!0,get:function(){return E.formatRef}});var M=Pe();Object.defineProperty(a,"Mot",{enumerable:!0,get:function(){return M.Mot}}),Object.defineProperty(a,"MotValue",{enumerable:!0,get:function(){return M.MotValue}});var C=De();Object.defineProperty(a,"MOTLYSession",{enumerable:!0,get:function(){return C.MOTLYSession}}),Object.defineProperty(a,"MOTLYResult",{enumerable:!0,get:function(){return C.MOTLYResult}}),Object.defineProperty(a,"MOTLYSchema",{enumerable:!0,get:function(){return C.MOTLYSchema}})})(ve)),ve}var _e;function Ne(){if(_e)return ue;_e=1;var a={};Object.defineProperty(ue,"__esModule",{value:!0}),ue.TagParser=void 0,ue.parseTag=u,ue.parseAnnotation=d;const E=Ie(),M=$e();function C(s){const o=s.search(/[ \t\r\n]/);return o>0?s.slice(o):""}function i(s){return{code:s.code,message:s.message,line:s.begin.line,offset:s.begin.column}}function e(s,o){const g=o.get(s.parseId);if(g)return{url:g.url,range:{start:{line:g.startLine+s.begin.line,character:s.begin.line===0?g.startColumn+s.begin.column:s.begin.column},end:{line:g.startLine+s.end.line,character:s.end.line===0?g.startColumn+s.end.column:s.end.column}}}}function t(s,o,g){if((0,E.isRef)(s))return new M.Tag({deleted:!0},o);const y=new M.Tag({},o);if(s.location&&g&&(y.location=e(s.location,g)),s.eq!==void 0)if(Array.isArray(s.eq))y.eq=s.eq.map(P=>t(P,y,g));else if((0,E.isEnvRef)(s.eq)){const P=a[s.eq.env];P!==void 0&&(y.eq=P)}else s.eq instanceof Date?y.eq=new Date(s.eq):y.eq=s.eq;if(s.properties!==void 0){y.properties={};for(const[P,I]of Object.entries(s.properties))y.properties[P]=t(I,y,g)}return s.deleted&&(y.deleted=!0),y}class n{constructor(){this.origins=new Map,this.session=new E.MOTLYSession}parse(o,g){return this.parseSource(o,0,g)}parseAnnotation(o,g){const y=C(o),P=o.length-y.length;return this.parseSource(y,P,g)}parseSource(o,g,y){const{parseId:P,errors:I}=this.session.parse(o);y&&this.origins.set(P,{url:y.url,startLine:y.startLine,startColumn:y.startColumn+g});const N=I.map(i);return{tag:new M.Tag,log:N}}finish(){const g=this.session.finish().getValue();return this.session.dispose(),t(g,void 0,this.origins)}}ue.TagParser=n;function u(s){const o=new n;if(typeof s=="string"){const{log:y}=o.parse(s);return{tag:o.finish(),log:y}}const g=[];for(let y=0;y<s.length;y++){const P=o.parse(s[y]);for(const I of P.log)g.push({...I,line:y+I.line})}return{tag:o.finish(),log:g}}function d(s){const o=new n;if(typeof s=="string"){const{log:y}=o.parseAnnotation(s);return{tag:o.finish(),log:y}}const g=[];for(let y=0;y<s.length;y++){const P=o.parseAnnotation(s[y]);for(const I of P.log)g.push({...I,line:y+I.line})}return{tag:o.finish(),log:g}}return ue}var ge={},Ce;function Ue(){if(Ce)return ge;Ce=1,Object.defineProperty(ge,"__esModule",{value:!0}),ge.parseString=E;var a;(function(M){M[M.Normal=0]="Normal",M[M.ReverseVirgule=1]="ReverseVirgule",M[M.Unicode=2]="Unicode"})(a||(a={}));function E(M,C=""){let i=M.slice(C.length),e=a.Normal;C.length&&(i=i.slice(0,-C.length));let t="",n="";for(const u of i)switch(e){case a.Normal:{u==="\\"?e=a.ReverseVirgule:t+=u;break}case a.ReverseVirgule:{let d=u;if(u==="u"){e=a.Unicode,n="";continue}u==="b"?d="\b":u==="f"?d="\f":u==="n"?d=`
|
|
23
|
+
`:u==="r"?d="\r":u==="t"&&(d=" "),t+=d,e=a.Normal;break}case a.Unicode:"ABCDEFabcdef0123456789".includes(u)?(n+=u,n.length===4&&(t+=String.fromCharCode(parseInt(n,16)),e=a.Normal)):e=a.Normal}return t}return ge}var xe;function Le(){return xe||(xe=1,(function(a){var E=te&&te.__createBinding||(Object.create?(function(t,n,u,d){d===void 0&&(d=u);var s=Object.getOwnPropertyDescriptor(n,u);(!s||("get"in s?!n.__esModule:s.writable||s.configurable))&&(s={enumerable:!0,get:function(){return n[u]}}),Object.defineProperty(t,d,s)}):(function(t,n,u,d){d===void 0&&(d=u),t[d]=n[u]})),M=te&&te.__setModuleDefault||(Object.create?(function(t,n){Object.defineProperty(t,"default",{enumerable:!0,value:n})}):function(t,n){t.default=n}),C=te&&te.__exportStar||function(t,n){for(var u in t)u!=="default"&&!Object.prototype.hasOwnProperty.call(n,u)&&E(n,t,u)},i=te&&te.__importStar||(function(){var t=function(n){return t=Object.getOwnPropertyNames||function(u){var d=[];for(var s in u)Object.prototype.hasOwnProperty.call(u,s)&&(d[d.length]=s);return d},t(n)};return function(n){if(n&&n.__esModule)return n;var u={};if(n!=null)for(var d=t(n),s=0;s<d.length;s++)d[s]!=="default"&&E(u,n,d[s]);return M(u,n),u}})();Object.defineProperty(a,"__esModule",{value:!0}),a.ParseUtil=a.TagParser=a.parseAnnotation=a.parseTag=void 0,C($e(),a);var e=Ne();Object.defineProperty(a,"parseTag",{enumerable:!0,get:function(){return e.parseTag}}),Object.defineProperty(a,"parseAnnotation",{enumerable:!0,get:function(){return e.parseAnnotation}}),Object.defineProperty(a,"TagParser",{enumerable:!0,get:function(){return e.TagParser}}),a.ParseUtil=i(Ue())})(te)),te}export{Le as r};
|
package/dist/app/index.html
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
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" />
|
|
5
10
|
<link rel="icon" type="image/svg+xml" href="/logo.svg" />
|
|
6
11
|
<meta name="viewport" content="initial-scale=1, width=device-width" />
|
|
7
|
-
<!-- Fonts to support Material Design -->
|
|
8
12
|
<link rel="preconnect" href="https://fonts.googleapis.com" />
|
|
9
13
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
|
|
10
14
|
<link
|
|
11
15
|
rel="stylesheet"
|
|
12
|
-
href="https://fonts.googleapis.com/css2?family=
|
|
16
|
+
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap"
|
|
13
17
|
/>
|
|
14
18
|
<title>Malloy Publisher</title>
|
|
15
|
-
<script type="module" crossorigin src="/assets/index-
|
|
16
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
19
|
+
<script type="module" crossorigin src="/assets/index-B8pnU_V_.js"></script>
|
|
20
|
+
<link rel="stylesheet" crossorigin href="/assets/index-5eLCcNmP.css">
|
|
17
21
|
</head>
|
|
18
22
|
<body>
|
|
19
23
|
<div id="root"></div>
|
|
Binary file
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"frozenConfig": false,
|
|
3
|
+
"environments": [
|
|
4
|
+
{
|
|
5
|
+
"name": "examples",
|
|
6
|
+
"packages": [
|
|
7
|
+
{
|
|
8
|
+
"name": "storefront",
|
|
9
|
+
"location": "https://github.com/malloydata/publisher/tree/main/examples/storefront"
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
"name": "governed-analytics",
|
|
13
|
+
"location": "https://github.com/malloydata/publisher/tree/main/examples/governed-analytics"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"name": "html-data-app",
|
|
17
|
+
"location": "https://github.com/malloydata/publisher/tree/main/examples/html-data-app"
|
|
18
|
+
}
|
|
19
|
+
],
|
|
20
|
+
"connections": []
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|