@malloy-publisher/server 0.0.235 → 0.0.237

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (319) hide show
  1. package/dist/app/api-doc.yaml +83 -27
  2. package/dist/app/assets/{EnvironmentPage-BsAnavYN.js → EnvironmentPage-DaP6CpgK.js} +1 -1
  3. package/dist/app/assets/{HomePage-CADE138j.js → HomePage-C9yNw3iu.js} +1 -1
  4. package/dist/app/assets/{LightMode-Cfh7KzN8.js → LightMode-Be4-G-dX.js} +1 -1
  5. package/dist/app/assets/{MainPage-CO3pRlnV.js → MainPage-J_rU2SgI.js} +2 -2
  6. package/dist/app/assets/{MaterializationsPage-p9YjkRXZ.js → MaterializationsPage-DHgPI4MO.js} +1 -1
  7. package/dist/app/assets/ModelPage-BzXfjTu5.js +1 -0
  8. package/dist/app/assets/{PackagePage-e4kN75YR.js → PackagePage-ByoSTLJ4.js} +1 -1
  9. package/dist/app/assets/RouteError-CrSeKN2r.js +1 -0
  10. package/dist/app/assets/{ThemeEditorPage-CciagFTq.js → ThemeEditorPage-Btxnmhtk.js} +1 -1
  11. package/dist/app/assets/{WorkbookPage-DNWmkCXa.js → WorkbookPage-D6JLPnWO.js} +1 -1
  12. package/dist/app/assets/{core-Rj_4rRnA.es-BZyvITuO.js → core-BSRgt1mG.es-Bc_D2Lq4.js} +1 -1
  13. package/dist/app/assets/{index-CH2AcDzc.js → index-BRijWj6K.js} +15 -15
  14. package/dist/app/assets/{index-DQa463gC.js → index-BX4D94xw.js} +1 -1
  15. package/dist/app/assets/{index-VBbcc8s6.js → index-Cvy0xtb7.js} +1 -1
  16. package/dist/app/assets/{index-DQpV7MyA.js → index-DMAhIJNC.js} +1 -1
  17. package/dist/app/index.html +1 -1
  18. package/dist/package_load_worker.mjs +59 -20
  19. package/dist/server.mjs +1342 -616
  20. package/package.json +8 -2
  21. package/.eslintrc.json +0 -44
  22. package/.prettierignore +0 -1
  23. package/.prettierrc +0 -4
  24. package/build.ts +0 -97
  25. package/dist/app/assets/ModelPage-C1OSTv-x.js +0 -1
  26. package/dist/app/assets/RouteError-CzbfOkng.js +0 -1
  27. package/eslint.config.mjs +0 -76
  28. package/k6-tests/README.md +0 -144
  29. package/k6-tests/bun.lock +0 -797
  30. package/k6-tests/load-test/load-test-crud-connections.ts +0 -263
  31. package/k6-tests/load-test/load-test-crud-packages.ts +0 -461
  32. package/k6-tests/load-test/load-test-crud-projects.ts +0 -160
  33. package/k6-tests/load-test/load-test-crud.ts +0 -142
  34. package/k6-tests/load-test/load-test.ts +0 -784
  35. package/k6-tests/package.json +0 -27
  36. package/k6-tests/scripts/run-with-otel.sh +0 -50
  37. package/k6-tests/smoke-test/smoke-test.ts +0 -158
  38. package/k6-tests/tsconfig.json +0 -29
  39. package/k6-tests/utils/client_factory.ts +0 -128
  40. package/k6-tests/utils/common.ts +0 -489
  41. package/k6-tests/utils/logger.ts +0 -62
  42. package/k6-tests/utils/types.d.ts +0 -35
  43. package/malloy_mcp.dxt +0 -0
  44. package/publisher.config.example.bigquery.json +0 -33
  45. package/publisher.config.example.duckdb.json +0 -23
  46. package/publisher.config.json +0 -23
  47. package/scripts/bake-duckdb-extensions.js +0 -110
  48. package/src/config.spec.ts +0 -1535
  49. package/src/config.theme.spec.ts +0 -178
  50. package/src/config.ts +0 -1142
  51. package/src/constants.ts +0 -105
  52. package/src/controller/compile.controller.ts +0 -40
  53. package/src/controller/connection.controller.spec.ts +0 -849
  54. package/src/controller/connection.controller.ts +0 -901
  55. package/src/controller/database.controller.ts +0 -24
  56. package/src/controller/materialization.controller.spec.ts +0 -293
  57. package/src/controller/materialization.controller.ts +0 -319
  58. package/src/controller/model.controller.ts +0 -164
  59. package/src/controller/package.controller.spec.ts +0 -273
  60. package/src/controller/package.controller.ts +0 -306
  61. package/src/controller/query.controller.ts +0 -152
  62. package/src/controller/theme.controller.ts +0 -83
  63. package/src/controller/watch-mode.controller.ts +0 -243
  64. package/src/data_styles.ts +0 -71
  65. package/src/default-publisher.config.json +0 -23
  66. package/src/ducklake_version.spec.ts +0 -163
  67. package/src/ducklake_version.ts +0 -153
  68. package/src/errors.spec.ts +0 -119
  69. package/src/errors.ts +0 -237
  70. package/src/filter_deprecation.spec.ts +0 -64
  71. package/src/filter_deprecation.ts +0 -42
  72. package/src/health.spec.ts +0 -123
  73. package/src/health.ts +0 -233
  74. package/src/heap_check.spec.ts +0 -144
  75. package/src/heap_check.ts +0 -144
  76. package/src/instrumentation.ts +0 -214
  77. package/src/json_utils.spec.ts +0 -51
  78. package/src/json_utils.ts +0 -33
  79. package/src/logger.spec.ts +0 -210
  80. package/src/logger.ts +0 -251
  81. package/src/malloy_pin_prereqs.spec.ts +0 -25
  82. package/src/materialization_metrics.spec.ts +0 -169
  83. package/src/materialization_metrics.ts +0 -346
  84. package/src/mcp/error_messages.spec.ts +0 -35
  85. package/src/mcp/error_messages.ts +0 -183
  86. package/src/mcp/handler_utils.spec.ts +0 -108
  87. package/src/mcp/handler_utils.ts +0 -251
  88. package/src/mcp/mcp_constants.ts +0 -6
  89. package/src/mcp/query_envelope.spec.ts +0 -229
  90. package/src/mcp/query_envelope.ts +0 -240
  91. package/src/mcp/server.protocol.spec.ts +0 -250
  92. package/src/mcp/server.ts +0 -87
  93. package/src/mcp/skills/build_skills_bundle.spec.ts +0 -51
  94. package/src/mcp/skills/build_skills_bundle.ts +0 -176
  95. package/src/mcp/skills/skills_bundle.json +0 -1
  96. package/src/mcp/skills/skills_bundle.spec.ts +0 -171
  97. package/src/mcp/tool_response.spec.ts +0 -108
  98. package/src/mcp/tool_response.ts +0 -138
  99. package/src/mcp/tools/compile_tool.spec.ts +0 -315
  100. package/src/mcp/tools/compile_tool.ts +0 -208
  101. package/src/mcp/tools/docs_search/build_docs_index.ts +0 -132
  102. package/src/mcp/tools/docs_search/malloy_docs_index.json +0 -1
  103. package/src/mcp/tools/docs_search_tool.spec.ts +0 -32
  104. package/src/mcp/tools/docs_search_tool.ts +0 -128
  105. package/src/mcp/tools/embedding_index.spec.ts +0 -1236
  106. package/src/mcp/tools/embedding_index.ts +0 -808
  107. package/src/mcp/tools/execute_query_tool.spec.ts +0 -294
  108. package/src/mcp/tools/execute_query_tool.ts +0 -316
  109. package/src/mcp/tools/get_context_eval.ts +0 -275
  110. package/src/mcp/tools/get_context_tool.spec.ts +0 -592
  111. package/src/mcp/tools/get_context_tool.ts +0 -585
  112. package/src/mcp/tools/reload_package_tool.spec.ts +0 -232
  113. package/src/mcp/tools/reload_package_tool.ts +0 -132
  114. package/src/mcp_config.spec.ts +0 -919
  115. package/src/mcp_config.ts +0 -425
  116. package/src/oom_guards.integration.spec.ts +0 -269
  117. package/src/package_load/package_load_pool.spec.ts +0 -252
  118. package/src/package_load/package_load_pool.ts +0 -931
  119. package/src/package_load/package_load_worker.ts +0 -1034
  120. package/src/package_load/protocol.ts +0 -364
  121. package/src/package_load/rpc_wait_accountant.spec.ts +0 -109
  122. package/src/package_load/rpc_wait_accountant.ts +0 -76
  123. package/src/package_load_metrics.spec.ts +0 -114
  124. package/src/package_load_metrics.ts +0 -127
  125. package/src/path_safety.spec.ts +0 -158
  126. package/src/path_safety.ts +0 -146
  127. package/src/pg_helpers.spec.ts +0 -223
  128. package/src/pg_helpers.ts +0 -52
  129. package/src/query_cap_metrics.spec.ts +0 -89
  130. package/src/query_cap_metrics.ts +0 -116
  131. package/src/query_concurrency.spec.ts +0 -247
  132. package/src/query_concurrency.ts +0 -237
  133. package/src/query_metadata_metrics.ts +0 -49
  134. package/src/query_param_utils.ts +0 -29
  135. package/src/query_timeout.spec.ts +0 -224
  136. package/src/query_timeout.ts +0 -179
  137. package/src/runtime/publisher.js +0 -328
  138. package/src/server-old.ts +0 -988
  139. package/src/server.ts +0 -2059
  140. package/src/service/annotations.spec.ts +0 -118
  141. package/src/service/annotations.ts +0 -91
  142. package/src/service/authorize.spec.ts +0 -154
  143. package/src/service/authorize.ts +0 -498
  144. package/src/service/authorize_integration.spec.ts +0 -2041
  145. package/src/service/build_plan.spec.ts +0 -685
  146. package/src/service/build_plan.ts +0 -797
  147. package/src/service/compile_authorize.spec.ts +0 -85
  148. package/src/service/compile_fragment_techniques.spec.ts +0 -156
  149. package/src/service/connection.spec.ts +0 -2360
  150. package/src/service/connection.ts +0 -2187
  151. package/src/service/connection_config.spec.ts +0 -734
  152. package/src/service/connection_config.ts +0 -899
  153. package/src/service/connection_federation.spec.ts +0 -184
  154. package/src/service/connection_fingerprint.spec.ts +0 -102
  155. package/src/service/connection_service.spec.ts +0 -711
  156. package/src/service/connection_service.ts +0 -291
  157. package/src/service/cron_evaluator.spec.ts +0 -79
  158. package/src/service/cron_evaluator.ts +0 -105
  159. package/src/service/db_utils.spec.ts +0 -1085
  160. package/src/service/db_utils.ts +0 -1502
  161. package/src/service/duckdb_instance_isolation.spec.ts +0 -137
  162. package/src/service/ducklake_lazy_attach.spec.ts +0 -110
  163. package/src/service/embedding_provider.spec.ts +0 -329
  164. package/src/service/embedding_provider.ts +0 -236
  165. package/src/service/environment.ts +0 -2191
  166. package/src/service/environment_admission.spec.ts +0 -344
  167. package/src/service/environment_compile.spec.ts +0 -197
  168. package/src/service/environment_store.spec.ts +0 -2274
  169. package/src/service/environment_store.ts +0 -2434
  170. package/src/service/environment_store_anchoring.spec.ts +0 -107
  171. package/src/service/environment_store_clone.spec.ts +0 -350
  172. package/src/service/explore_visibility.spec.ts +0 -434
  173. package/src/service/exports_probe.spec.ts +0 -107
  174. package/src/service/extension_fetch_policy.spec.ts +0 -256
  175. package/src/service/filter.spec.ts +0 -458
  176. package/src/service/filter.ts +0 -341
  177. package/src/service/filter_bypass.spec.ts +0 -418
  178. package/src/service/filter_integration.spec.ts +0 -1004
  179. package/src/service/freshness.spec.ts +0 -183
  180. package/src/service/freshness.ts +0 -112
  181. package/src/service/gcs_s3_utils.ts +0 -427
  182. package/src/service/given.ts +0 -105
  183. package/src/service/givens_integration.spec.ts +0 -219
  184. package/src/service/manifest_loader.spec.ts +0 -189
  185. package/src/service/manifest_loader.ts +0 -156
  186. package/src/service/materialization_build_session.spec.ts +0 -435
  187. package/src/service/materialization_build_session.ts +0 -681
  188. package/src/service/materialization_config_validation.spec.ts +0 -99
  189. package/src/service/materialization_config_validation.ts +0 -120
  190. package/src/service/materialization_eligibility.spec.ts +0 -158
  191. package/src/service/materialization_eligibility.ts +0 -305
  192. package/src/service/materialization_schedule_surface.spec.ts +0 -256
  193. package/src/service/materialization_scheduler.spec.ts +0 -289
  194. package/src/service/materialization_scheduler.ts +0 -304
  195. package/src/service/materialization_serve_transform.spec.ts +0 -1003
  196. package/src/service/materialization_serve_transform.ts +0 -779
  197. package/src/service/materialization_service.spec.ts +0 -2373
  198. package/src/service/materialization_service.ts +0 -2342
  199. package/src/service/materialization_test_fixtures.ts +0 -249
  200. package/src/service/model.spec.ts +0 -1157
  201. package/src/service/model.ts +0 -3370
  202. package/src/service/model_limits.spec.ts +0 -209
  203. package/src/service/model_limits.ts +0 -131
  204. package/src/service/model_storage_serve.spec.ts +0 -193
  205. package/src/service/model_storage_serve_joins.spec.ts +0 -193
  206. package/src/service/package.spec.ts +0 -612
  207. package/src/service/package.ts +0 -1799
  208. package/src/service/package_manifest.spec.ts +0 -230
  209. package/src/service/package_manifest.ts +0 -241
  210. package/src/service/package_memory_governor.spec.ts +0 -173
  211. package/src/service/package_memory_governor.ts +0 -233
  212. package/src/service/package_quote_bound_tables.spec.ts +0 -171
  213. package/src/service/package_race.spec.ts +0 -208
  214. package/src/service/package_reload_safety.spec.ts +0 -193
  215. package/src/service/package_rollback.spec.ts +0 -190
  216. package/src/service/package_worker_path.spec.ts +0 -645
  217. package/src/service/path_injection.spec.ts +0 -39
  218. package/src/service/persist_annotation_validation.spec.ts +0 -89
  219. package/src/service/persist_annotation_validation.ts +0 -59
  220. package/src/service/persistence_policy.spec.ts +0 -374
  221. package/src/service/proxy.spec.ts +0 -414
  222. package/src/service/proxy.ts +0 -248
  223. package/src/service/query_boundary.spec.ts +0 -470
  224. package/src/service/query_metadata.spec.ts +0 -408
  225. package/src/service/query_metadata.ts +0 -492
  226. package/src/service/query_metadata_identity.spec.ts +0 -149
  227. package/src/service/query_text.spec.ts +0 -79
  228. package/src/service/query_text.ts +0 -43
  229. package/src/service/quoting.spec.ts +0 -135
  230. package/src/service/quoting.ts +0 -78
  231. package/src/service/resolve_environment.ts +0 -15
  232. package/src/service/restricted_mode.spec.ts +0 -299
  233. package/src/service/source_extraction.ts +0 -225
  234. package/src/service/theme_store.ts +0 -199
  235. package/src/storage/DatabaseInterface.ts +0 -198
  236. package/src/storage/StorageManager.ts +0 -113
  237. package/src/storage/duckdb/ConnectionRepository.ts +0 -143
  238. package/src/storage/duckdb/DuckDBConnection.ts +0 -123
  239. package/src/storage/duckdb/DuckDBRepository.ts +0 -208
  240. package/src/storage/duckdb/EnvironmentRepository.ts +0 -148
  241. package/src/storage/duckdb/MaterializationRepository.spec.ts +0 -191
  242. package/src/storage/duckdb/MaterializationRepository.ts +0 -336
  243. package/src/storage/duckdb/PackageRepository.ts +0 -135
  244. package/src/storage/duckdb/schema.ts +0 -229
  245. package/src/stream_helpers.spec.ts +0 -280
  246. package/src/stream_helpers.ts +0 -162
  247. package/src/telemetry.ts +0 -20
  248. package/src/test_helpers/metrics_harness.ts +0 -166
  249. package/src/theme_key_parity.spec.ts +0 -57
  250. package/src/utils.ts +0 -29
  251. package/tests/fixtures/authorize-compile/model.malloy +0 -9
  252. package/tests/fixtures/authorize-compile/publisher.json +0 -4
  253. package/tests/fixtures/html-pages-nopublic/model.malloy +0 -1
  254. package/tests/fixtures/html-pages-nopublic/publisher.json +0 -5
  255. package/tests/fixtures/html-pages-test/data.csv +0 -3
  256. package/tests/fixtures/html-pages-test/public/assets/app.css +0 -3
  257. package/tests/fixtures/html-pages-test/public/barehtml.html +0 -4
  258. package/tests/fixtures/html-pages-test/public/bodymeta.html +0 -8
  259. package/tests/fixtures/html-pages-test/public/data.json +0 -1
  260. package/tests/fixtures/html-pages-test/public/fitcomment.html +0 -11
  261. package/tests/fixtures/html-pages-test/public/index.html +0 -9
  262. package/tests/fixtures/html-pages-test/public/nohead.html +0 -8
  263. package/tests/fixtures/html-pages-test/public/notfit.html +0 -13
  264. package/tests/fixtures/html-pages-test/public/slides.html +0 -12
  265. package/tests/fixtures/html-pages-test/public/sub/page2.html +0 -9
  266. package/tests/fixtures/html-pages-test/public/unterminated.html +0 -10
  267. package/tests/fixtures/html-pages-test/publisher.json +0 -5
  268. package/tests/fixtures/html-pages-test/report.malloy +0 -1
  269. package/tests/fixtures/persist-multi-level/data/orders.csv +0 -5
  270. package/tests/fixtures/persist-multi-level/multi_level.malloy +0 -18
  271. package/tests/fixtures/persist-multi-level/publisher.json +0 -5
  272. package/tests/fixtures/persist-schedule-test/data/orders.csv +0 -5
  273. package/tests/fixtures/persist-schedule-test/persist_schedule_test.malloy +0 -11
  274. package/tests/fixtures/persist-schedule-test/publisher.json +0 -7
  275. package/tests/fixtures/persist-schedule-warn-test/data/orders.csv +0 -5
  276. package/tests/fixtures/persist-schedule-warn-test/persist_warn_test.malloy +0 -11
  277. package/tests/fixtures/persist-schedule-warn-test/publisher.json +0 -6
  278. package/tests/fixtures/persist-test/data/orders.csv +0 -5
  279. package/tests/fixtures/persist-test/persist_test.malloy +0 -11
  280. package/tests/fixtures/persist-test/publisher.json +0 -5
  281. package/tests/fixtures/publisher.config.json +0 -15
  282. package/tests/fixtures/query-givens/data/orders.csv +0 -7
  283. package/tests/fixtures/query-givens/model.malloy +0 -34
  284. package/tests/fixtures/query-givens/publisher.json +0 -5
  285. package/tests/fixtures/xlsx/database.xlsx +0 -0
  286. package/tests/harness/mcp_test_setup.ts +0 -332
  287. package/tests/harness/rest_e2e.ts +0 -68
  288. package/tests/integration/authorize/compile_authorize_http.integration.spec.ts +0 -92
  289. package/tests/integration/concurrent_package/concurrent_package.integration.spec.ts +0 -280
  290. package/tests/integration/duckdb_storage/duckdb_storage.integration.spec.ts +0 -138
  291. package/tests/integration/first_boot/readiness_line.integration.spec.ts +0 -177
  292. package/tests/integration/html_pages/html_pages.integration.spec.ts +0 -440
  293. package/tests/integration/legacy_routes/legacy_routes.integration.spec.ts +0 -259
  294. package/tests/integration/materialization/environment_list.integration.spec.ts +0 -133
  295. package/tests/integration/materialization/freshness_gate.integration.spec.ts +0 -292
  296. package/tests/integration/materialization/manifest_binding.integration.spec.ts +0 -430
  297. package/tests/integration/materialization/materialization_lifecycle.integration.spec.ts +0 -441
  298. package/tests/integration/materialization/orchestrated_rebind.integration.spec.ts +0 -150
  299. package/tests/integration/materialization/reference_manifest.integration.spec.ts +0 -251
  300. package/tests/integration/materialization/schedule_edit.integration.spec.ts +0 -126
  301. package/tests/integration/materialization/scheduler.integration.spec.ts +0 -200
  302. package/tests/integration/materialization/scheduler_recovery.integration.spec.ts +0 -172
  303. package/tests/integration/materialization/scheduler_transitions.integration.spec.ts +0 -256
  304. package/tests/integration/materialization/scheduler_wiring.integration.spec.ts +0 -143
  305. package/tests/integration/mcp/mcp_execute_query_tool.integration.spec.ts +0 -438
  306. package/tests/integration/mcp/mcp_get_context_semantic.integration.spec.ts +0 -235
  307. package/tests/integration/mcp/mcp_transport.integration.spec.ts +0 -98
  308. package/tests/integration/query_givens/query_givens.integration.spec.ts +0 -146
  309. package/tests/integration/query_givens/query_givens_authorize.integration.spec.ts +0 -121
  310. package/tests/integration/sdk_givens/sdk_givens.integration.spec.ts +0 -110
  311. package/tests/integration/watch-mode/watch_mode.integration.spec.ts +0 -421
  312. package/tests/unit/controller/theme.controller.spec.ts +0 -141
  313. package/tests/unit/duckdb/attached_databases.test.ts +0 -1243
  314. package/tests/unit/duckdb/duckdb_connection.test.ts +0 -181
  315. package/tests/unit/duckdb/legacy_schema_migration.test.ts +0 -197
  316. package/tests/unit/duckdb/repositories.test.ts +0 -208
  317. package/tests/unit/ducklake/ducklake.test.ts +0 -952
  318. package/tests/unit/service/theme_store.spec.ts +0 -139
  319. package/tsconfig.json +0 -32
@@ -1,1004 +0,0 @@
1
- import { DuckDBConnection } from "@malloydata/db-duckdb";
2
- import { Connection } from "@malloydata/malloy";
3
- import {
4
- afterAll,
5
- afterEach,
6
- beforeAll,
7
- beforeEach,
8
- describe,
9
- expect,
10
- it,
11
- } from "bun:test";
12
- import fs from "fs/promises";
13
- import os from "os";
14
- import path from "path";
15
- import { BadRequestError } from "../errors";
16
- import { Model } from "./model";
17
-
18
- const TEST_DIR = path.join(os.tmpdir(), "filter-integration-tests");
19
- const TEST_DB_DIR = path.join(TEST_DIR, "db");
20
- const TEST_DB_PATH = path.join(TEST_DB_DIR, "test.duckdb");
21
- const TEST_PKG_DIR = path.join(TEST_DIR, "pkg");
22
-
23
- let duckdbConnection: DuckDBConnection;
24
-
25
- const SEED_SQL = `
26
- CREATE TABLE IF NOT EXISTS orders (
27
- order_id INTEGER,
28
- region VARCHAR,
29
- status VARCHAR,
30
- customer_id VARCHAR,
31
- amount DOUBLE
32
- );
33
- INSERT INTO orders VALUES
34
- (1, 'US', 'active', 'cust_a', 100.0),
35
- (2, 'US', 'active', 'cust_a', 200.0),
36
- (3, 'EU', 'active', 'cust_b', 150.0),
37
- (4, 'EU', 'cancelled', 'cust_b', 75.0),
38
- (5, 'APAC', 'active', 'cust_c', 300.0),
39
- (6, 'APAC', 'cancelled', 'cust_c', 50.0);
40
- `;
41
-
42
- const MODEL_WITH_REQUIRED = `
43
- #(filter) dimension=region type=in
44
- #(filter) dimension=status type=equal
45
- #(filter) name=tenant dimension=customer_id type=equal implicit required
46
- source: orders is duckdb.table('orders') extend {
47
- primary_key: order_id
48
-
49
- measure:
50
- order_count is count()
51
- total_amount is sum(amount)
52
-
53
- view: summary is {
54
- aggregate: order_count, total_amount
55
- }
56
-
57
- view: by_region is {
58
- group_by: region
59
- aggregate: order_count, total_amount
60
- order_by: region
61
- }
62
- }
63
- `;
64
-
65
- const MODEL_OPTIONAL_ONLY = `
66
- #(filter) dimension=region type=in
67
- #(filter) dimension=status type=equal
68
- source: orders is duckdb.table('orders') extend {
69
- primary_key: order_id
70
-
71
- measure:
72
- order_count is count()
73
- total_amount is sum(amount)
74
-
75
- view: summary is {
76
- aggregate: order_count, total_amount
77
- }
78
-
79
- view: by_region is {
80
- group_by: region
81
- aggregate: order_count, total_amount
82
- order_by: region
83
- }
84
- }
85
- `;
86
-
87
- const NOTEBOOK_MALLOYNB = `>>>markdown
88
- # Test Notebook
89
-
90
- >>>malloy
91
- import "orders_optional.malloy"
92
-
93
- >>>malloy
94
- run: orders -> summary
95
- `;
96
-
97
- // Base source with 3 filters: region (in), status (equal), customer_id (equal, required)
98
- const MODEL_BASE_FOR_EXTEND = `
99
- #(filter) name=region dimension=region type=in
100
- #(filter) name=status dimension=status type=equal
101
- #(filter) name=tenant dimension=customer_id type=equal required
102
- source: base_orders is duckdb.table('orders') extend {
103
- primary_key: order_id
104
-
105
- measure:
106
- order_count is count()
107
- total_amount is sum(amount)
108
-
109
- view: summary is {
110
- aggregate: order_count, total_amount
111
- }
112
- }
113
- `;
114
-
115
- // Extending source: overrides region (in → equal), overrides tenant
116
- // (removes required), keeps status from base unchanged
117
- const MODEL_CHILD_EXTEND = `
118
- import "base_orders.malloy"
119
-
120
- #(filter) name=region dimension=region type=equal
121
- #(filter) name=tenant dimension=customer_id type=equal
122
- source: child_orders is base_orders extend {}
123
- `;
124
-
125
- // Notebook against the extended source
126
- const NOTEBOOK_EXTEND = `>>>markdown
127
- # Extend Test
128
-
129
- >>>malloy
130
- import "child_orders.malloy"
131
-
132
- >>>malloy
133
- run: child_orders -> summary
134
- `;
135
-
136
- // Model with a given: declaration — view filters rows by the given value
137
- const MODEL_WITH_GIVENS = `##! experimental.givens
138
-
139
- given: target_region :: string is 'US'
140
-
141
- source: orders is duckdb.table('orders') extend {
142
- primary_key: order_id
143
-
144
- measure:
145
- order_count is count()
146
- total_amount is sum(amount)
147
-
148
- view: by_given_region is {
149
- where: region = $target_region
150
- aggregate: order_count, total_amount
151
- }
152
- }
153
- `;
154
-
155
- // Model with both a #(filter) annotation and a given: declaration to verify composition
156
- const MODEL_WITH_GIVENS_AND_FILTER = `##! experimental.givens
157
-
158
- given: target_region :: string is 'US'
159
-
160
- #(filter) dimension=status type=equal
161
- source: orders is duckdb.table('orders') extend {
162
- primary_key: order_id
163
-
164
- measure:
165
- order_count is count()
166
- total_amount is sum(amount)
167
-
168
- view: by_given_region is {
169
- where: region = $target_region
170
- aggregate: order_count, total_amount
171
- }
172
- }
173
- `;
174
-
175
- const NOTEBOOK_GIVENS = `>>>markdown
176
- # Givens Test
177
-
178
- >>>malloy
179
- import "orders_givens.malloy"
180
-
181
- >>>malloy
182
- run: orders -> by_given_region
183
- `;
184
-
185
- beforeAll(async () => {
186
- await fs.mkdir(TEST_DB_DIR, { recursive: true });
187
- await fs.mkdir(TEST_PKG_DIR, { recursive: true });
188
- duckdbConnection = new DuckDBConnection("duckdb", TEST_DB_PATH, TEST_DB_DIR);
189
- for (const stmt of SEED_SQL.trim().split(";").filter(Boolean)) {
190
- await duckdbConnection.runSQL(stmt.trim() + ";");
191
- }
192
- });
193
-
194
- afterAll(async () => {
195
- try {
196
- await duckdbConnection.close();
197
- await new Promise((resolve) => setTimeout(resolve, 100));
198
- await fs.rm(TEST_DIR, { recursive: true, force: true });
199
- } catch {
200
- // Ignore cleanup errors
201
- }
202
- });
203
-
204
- function getConnections(): Map<string, Connection> {
205
- const map = new Map<string, Connection>();
206
- map.set("duckdb", duckdbConnection);
207
- return map;
208
- }
209
-
210
- async function writeFile(filename: string, content: string): Promise<void> {
211
- await fs.writeFile(path.join(TEST_PKG_DIR, filename), content, "utf-8");
212
- }
213
-
214
- type Row = Record<string, unknown>;
215
-
216
- /**
217
- * Malloy's compactResult (queryResults.data.value) is the raw array of row objects.
218
- */
219
- function asRows(compactResult: unknown): Row[] {
220
- return compactResult as Row[];
221
- }
222
-
223
- /**
224
- * Parse a notebook cell result (JSON-stringified Malloy result).
225
- * The shape is: { schema, data: { kind, array_value: [{ record_value: { field_name: {kind, ...value} } }, ...] }, ... }
226
- * We extract column values from the record structure.
227
- */
228
- function parseNotebookResult(resultJson: string): Row[] {
229
- const parsed = JSON.parse(resultJson);
230
- const arrayValue = parsed?.data?.array_value;
231
- if (!Array.isArray(arrayValue)) {
232
- throw new Error(
233
- `Cannot extract rows from notebook result: ${JSON.stringify(Object.keys(parsed?.data ?? {}))}`,
234
- );
235
- }
236
-
237
- const schema = parsed.schema?.fields ?? [];
238
- const fieldNames = schema.map((f: { name: string }) => f.name);
239
-
240
- return arrayValue.map(
241
- (record: { record_value?: Array<Record<string, unknown>> }) => {
242
- const row: Row = {};
243
- const cells = record.record_value ?? [];
244
- for (let i = 0; i < fieldNames.length; i++) {
245
- const cell = cells[i];
246
- if (!cell) continue;
247
- row[fieldNames[i]] =
248
- cell.number_value ??
249
- cell.string_value ??
250
- cell.boolean_value ??
251
- cell.timestamp_value ??
252
- null;
253
- }
254
- return row;
255
- },
256
- );
257
- }
258
-
259
- describe("filter integration", () => {
260
- beforeEach(async () => {
261
- await writeFile("orders.malloy", MODEL_WITH_REQUIRED);
262
- await writeFile("orders_optional.malloy", MODEL_OPTIONAL_ONLY);
263
- await writeFile("test_notebook.malloynb", NOTEBOOK_MALLOYNB);
264
- });
265
-
266
- afterEach(async () => {
267
- const files = await fs.readdir(TEST_PKG_DIR);
268
- for (const f of files) {
269
- if (f.endsWith(".malloy") || f.endsWith(".malloynb")) {
270
- await fs.unlink(path.join(TEST_PKG_DIR, f));
271
- }
272
- }
273
- });
274
-
275
- // -----------------------------------------------------------------------
276
- // Model loading & filter metadata
277
- // -----------------------------------------------------------------------
278
- describe("model loading", () => {
279
- it("parses filter annotations and exposes them via getSources()", async () => {
280
- const model = await Model.create(
281
- "test-pkg",
282
- TEST_PKG_DIR,
283
- "orders.malloy",
284
- getConnections(),
285
- );
286
-
287
- const sources = model.getSources();
288
- expect(sources).toBeDefined();
289
- expect(sources!.length).toBeGreaterThanOrEqual(1);
290
-
291
- const ordersSource = sources!.find((s) => s.name === "orders");
292
- expect(ordersSource).toBeDefined();
293
- expect(ordersSource!.filters).toBeDefined();
294
- expect(ordersSource!.filters!.length).toBe(3);
295
-
296
- const regionFilter = ordersSource!.filters!.find(
297
- (f) => f.dimension === "region",
298
- );
299
- expect(regionFilter).toBeDefined();
300
- expect(regionFilter!.type).toBe("in");
301
- expect(regionFilter!.required).toBe(false);
302
- expect(regionFilter!.implicit).toBe(false);
303
-
304
- const statusFilter = ordersSource!.filters!.find(
305
- (f) => f.dimension === "status",
306
- );
307
- expect(statusFilter).toBeDefined();
308
- expect(statusFilter!.type).toBe("equal");
309
- expect(statusFilter!.required).toBe(false);
310
-
311
- const tenantFilter = ordersSource!.filters!.find(
312
- (f) => f.dimension === "customer_id",
313
- );
314
- expect(tenantFilter).toBeDefined();
315
- expect(tenantFilter!.name).toBe("tenant");
316
- expect(tenantFilter!.type).toBe("equal");
317
- expect(tenantFilter!.implicit).toBe(true);
318
- expect(tenantFilter!.required).toBe(true);
319
- });
320
-
321
- it("loads a model with optional-only filters", async () => {
322
- const model = await Model.create(
323
- "test-pkg",
324
- TEST_PKG_DIR,
325
- "orders_optional.malloy",
326
- getConnections(),
327
- );
328
-
329
- const sources = model.getSources();
330
- const ordersSource = sources!.find((s) => s.name === "orders");
331
- expect(ordersSource!.filters!.length).toBe(2);
332
- expect(ordersSource!.filters!.every((f) => f.required === false)).toBe(
333
- true,
334
- );
335
- });
336
- });
337
-
338
- // -----------------------------------------------------------------------
339
- // Query execution with optional filters
340
- // -----------------------------------------------------------------------
341
- describe("query execution with optional filters", () => {
342
- it("runs unfiltered query (no filterParams provided)", async () => {
343
- const model = await Model.create(
344
- "test-pkg",
345
- TEST_PKG_DIR,
346
- "orders_optional.malloy",
347
- getConnections(),
348
- );
349
-
350
- const { compactResult } = await model.getQueryResults(
351
- "orders",
352
- "summary",
353
- );
354
-
355
- const r = asRows(compactResult);
356
- expect(r.length).toBe(1);
357
- expect(Number(r[0].order_count)).toBe(6);
358
- expect(Number(r[0].total_amount)).toBe(875);
359
- });
360
-
361
- it("applies region=in filter with single value", async () => {
362
- const model = await Model.create(
363
- "test-pkg",
364
- TEST_PKG_DIR,
365
- "orders_optional.malloy",
366
- getConnections(),
367
- );
368
-
369
- const { compactResult } = await model.getQueryResults(
370
- "orders",
371
- "summary",
372
- undefined,
373
- { region: ["US"] },
374
- );
375
-
376
- const r = asRows(compactResult);
377
- expect(r.length).toBe(1);
378
- expect(Number(r[0].order_count)).toBe(2);
379
- expect(Number(r[0].total_amount)).toBe(300);
380
- });
381
-
382
- it("applies region=in filter with multiple values", async () => {
383
- const model = await Model.create(
384
- "test-pkg",
385
- TEST_PKG_DIR,
386
- "orders_optional.malloy",
387
- getConnections(),
388
- );
389
-
390
- const { compactResult } = await model.getQueryResults(
391
- "orders",
392
- "summary",
393
- undefined,
394
- { region: ["US", "EU"] },
395
- );
396
-
397
- const r = asRows(compactResult);
398
- expect(r.length).toBe(1);
399
- expect(Number(r[0].order_count)).toBe(4);
400
- expect(Number(r[0].total_amount)).toBe(525);
401
- });
402
-
403
- it("applies status=equal filter", async () => {
404
- const model = await Model.create(
405
- "test-pkg",
406
- TEST_PKG_DIR,
407
- "orders_optional.malloy",
408
- getConnections(),
409
- );
410
-
411
- const { compactResult } = await model.getQueryResults(
412
- "orders",
413
- "summary",
414
- undefined,
415
- { status: "active" },
416
- );
417
-
418
- const r = asRows(compactResult);
419
- expect(r.length).toBe(1);
420
- expect(Number(r[0].order_count)).toBe(4);
421
- expect(Number(r[0].total_amount)).toBe(750);
422
- });
423
-
424
- it("applies combined region + status filters", async () => {
425
- const model = await Model.create(
426
- "test-pkg",
427
- TEST_PKG_DIR,
428
- "orders_optional.malloy",
429
- getConnections(),
430
- );
431
-
432
- const { compactResult } = await model.getQueryResults(
433
- "orders",
434
- "summary",
435
- undefined,
436
- { region: ["EU"], status: "cancelled" },
437
- );
438
-
439
- const r = asRows(compactResult);
440
- expect(r.length).toBe(1);
441
- expect(Number(r[0].order_count)).toBe(1);
442
- expect(Number(r[0].total_amount)).toBe(75);
443
- });
444
-
445
- it("works with by_region view and filters", async () => {
446
- const model = await Model.create(
447
- "test-pkg",
448
- TEST_PKG_DIR,
449
- "orders_optional.malloy",
450
- getConnections(),
451
- );
452
-
453
- const { compactResult } = await model.getQueryResults(
454
- "orders",
455
- "by_region",
456
- undefined,
457
- { status: "cancelled" },
458
- );
459
-
460
- const r = asRows(compactResult);
461
- expect(r.length).toBe(2);
462
- const regions = r.map((row) => row.region);
463
- expect(regions).toContain("EU");
464
- expect(regions).toContain("APAC");
465
- });
466
-
467
- it("works with ad-hoc query string and filters", async () => {
468
- const model = await Model.create(
469
- "test-pkg",
470
- TEST_PKG_DIR,
471
- "orders_optional.malloy",
472
- getConnections(),
473
- );
474
-
475
- const { compactResult } = await model.getQueryResults(
476
- undefined,
477
- undefined,
478
- "run: orders -> { aggregate: order_count is count() }",
479
- { region: ["APAC"] },
480
- );
481
-
482
- const r = asRows(compactResult);
483
- expect(r.length).toBe(1);
484
- expect(Number(r[0].order_count)).toBe(2);
485
- });
486
- });
487
-
488
- // -----------------------------------------------------------------------
489
- // Mixed givens + #(filter) composition on the query-results path
490
- //
491
- // PR 5/6 of the givens migration deprecates `#(filter)` but keeps both
492
- // injection paths working independently and in combination. These tests
493
- // assert that `model.getQueryResults` (the path behind POST /…/query)
494
- // composes a `given:` substitution with a `filterParams` WHERE-injection
495
- // — same model, same call, both effects apply.
496
- // -----------------------------------------------------------------------
497
- describe("givens + filterParams composition", () => {
498
- it("composes a given override with filterParams on getQueryResults", async () => {
499
- await writeFile(
500
- "orders_givens_filter.malloy",
501
- MODEL_WITH_GIVENS_AND_FILTER,
502
- );
503
- const model = await Model.create(
504
- "test-pkg",
505
- TEST_PKG_DIR,
506
- "orders_givens_filter.malloy",
507
- getConnections(),
508
- );
509
-
510
- // given restricts to APAC; filterParam restricts to active.
511
- // APAC + active: only (5,'APAC','active',300) → order_count=1, total_amount=300.
512
- const { compactResult } = await model.getQueryResults(
513
- "orders",
514
- "by_given_region",
515
- undefined,
516
- { status: "active" },
517
- undefined,
518
- { target_region: "APAC" },
519
- );
520
-
521
- const r = asRows(compactResult);
522
- expect(r.length).toBe(1);
523
- expect(Number(r[0].order_count)).toBe(1);
524
- expect(Number(r[0].total_amount)).toBe(300);
525
- });
526
-
527
- it("falls back to the given default when no override is supplied", async () => {
528
- await writeFile(
529
- "orders_givens_filter.malloy",
530
- MODEL_WITH_GIVENS_AND_FILTER,
531
- );
532
- const model = await Model.create(
533
- "test-pkg",
534
- TEST_PKG_DIR,
535
- "orders_givens_filter.malloy",
536
- getConnections(),
537
- );
538
-
539
- // Default given target_region='US'; filterParam restricts to active.
540
- // US + active: (1,'US','active',100) and (2,'US','active',200) → order_count=2, total_amount=300.
541
- const { compactResult } = await model.getQueryResults(
542
- "orders",
543
- "by_given_region",
544
- undefined,
545
- { status: "active" },
546
- undefined,
547
- undefined,
548
- );
549
-
550
- const r = asRows(compactResult);
551
- expect(r.length).toBe(1);
552
- expect(Number(r[0].order_count)).toBe(2);
553
- expect(Number(r[0].total_amount)).toBe(300);
554
- });
555
- });
556
-
557
- // -----------------------------------------------------------------------
558
- // Required filter enforcement
559
- // -----------------------------------------------------------------------
560
- describe("required filter enforcement", () => {
561
- it("throws when required filter is missing", async () => {
562
- const model = await Model.create(
563
- "test-pkg",
564
- TEST_PKG_DIR,
565
- "orders.malloy",
566
- getConnections(),
567
- );
568
-
569
- await expect(
570
- model.getQueryResults("orders", "summary", undefined, {
571
- region: ["US"],
572
- }),
573
- ).rejects.toThrow(BadRequestError);
574
- });
575
-
576
- it("throws descriptive error for missing required filter", async () => {
577
- const model = await Model.create(
578
- "test-pkg",
579
- TEST_PKG_DIR,
580
- "orders.malloy",
581
- getConnections(),
582
- );
583
-
584
- try {
585
- await model.getQueryResults("orders", "summary", undefined, {});
586
- throw new Error("Should have thrown");
587
- } catch (error) {
588
- expect(error).toBeInstanceOf(BadRequestError);
589
- expect((error as Error).message).toContain("tenant");
590
- }
591
- });
592
-
593
- it("succeeds when required filter is provided", async () => {
594
- const model = await Model.create(
595
- "test-pkg",
596
- TEST_PKG_DIR,
597
- "orders.malloy",
598
- getConnections(),
599
- );
600
-
601
- const { compactResult } = await model.getQueryResults(
602
- "orders",
603
- "summary",
604
- undefined,
605
- { tenant: "cust_a", region: ["US"] },
606
- );
607
-
608
- const r = asRows(compactResult);
609
- expect(r.length).toBe(1);
610
- expect(Number(r[0].order_count)).toBe(2);
611
- expect(Number(r[0].total_amount)).toBe(300);
612
- });
613
-
614
- it("applies required + optional filters together", async () => {
615
- const model = await Model.create(
616
- "test-pkg",
617
- TEST_PKG_DIR,
618
- "orders.malloy",
619
- getConnections(),
620
- );
621
-
622
- const { compactResult } = await model.getQueryResults(
623
- "orders",
624
- "summary",
625
- undefined,
626
- { tenant: "cust_b", status: "cancelled" },
627
- );
628
-
629
- const r = asRows(compactResult);
630
- expect(r.length).toBe(1);
631
- expect(Number(r[0].order_count)).toBe(1);
632
- expect(Number(r[0].total_amount)).toBe(75);
633
- });
634
- });
635
-
636
- // -----------------------------------------------------------------------
637
- // bypassFilters
638
- // -----------------------------------------------------------------------
639
- describe("bypassFilters", () => {
640
- it("skips required filter validation when bypassFilters=true", async () => {
641
- const model = await Model.create(
642
- "test-pkg",
643
- TEST_PKG_DIR,
644
- "orders.malloy",
645
- getConnections(),
646
- );
647
-
648
- const { compactResult } = await model.getQueryResults(
649
- "orders",
650
- "summary",
651
- undefined,
652
- {},
653
- true,
654
- );
655
-
656
- const r = asRows(compactResult);
657
- expect(r.length).toBe(1);
658
- expect(Number(r[0].order_count)).toBe(6);
659
- expect(Number(r[0].total_amount)).toBe(875);
660
- });
661
-
662
- it("ignores provided filters when bypassFilters=true", async () => {
663
- const model = await Model.create(
664
- "test-pkg",
665
- TEST_PKG_DIR,
666
- "orders_optional.malloy",
667
- getConnections(),
668
- );
669
-
670
- const { compactResult } = await model.getQueryResults(
671
- "orders",
672
- "summary",
673
- undefined,
674
- { region: ["US"] },
675
- true,
676
- );
677
-
678
- const r = asRows(compactResult);
679
- expect(Number(r[0].order_count)).toBe(6);
680
- });
681
- });
682
-
683
- // -----------------------------------------------------------------------
684
- // Notebook cell execution with filters
685
- // -----------------------------------------------------------------------
686
- describe("notebook cell execution", () => {
687
- it("executes notebook code cell without filters", async () => {
688
- const model = await Model.create(
689
- "test-pkg",
690
- TEST_PKG_DIR,
691
- "test_notebook.malloynb",
692
- getConnections(),
693
- );
694
-
695
- // Cell 0 = markdown ("# Test Notebook")
696
- // Cell 1 = code (model definition — no query, just source)
697
- // Cell 2 = code (run: orders -> summary)
698
- const codeCell = await model.executeNotebookCell(2);
699
- expect(codeCell.type).toBe("code");
700
- expect(codeCell.result).toBeDefined();
701
-
702
- const notebookRows = parseNotebookResult(codeCell.result!);
703
- expect(notebookRows.length).toBe(1);
704
- expect(Number(notebookRows[0].order_count)).toBe(6);
705
- expect(Number(notebookRows[0].total_amount)).toBe(875);
706
- });
707
-
708
- it("applies filterParams to notebook cell execution", async () => {
709
- const model = await Model.create(
710
- "test-pkg",
711
- TEST_PKG_DIR,
712
- "test_notebook.malloynb",
713
- getConnections(),
714
- );
715
-
716
- const codeCell = await model.executeNotebookCell(2, {
717
- region: ["US"],
718
- });
719
- expect(codeCell.result).toBeDefined();
720
-
721
- const notebookRows = parseNotebookResult(codeCell.result!);
722
- expect(notebookRows.length).toBe(1);
723
- expect(Number(notebookRows[0].order_count)).toBe(2);
724
- expect(Number(notebookRows[0].total_amount)).toBe(300);
725
- });
726
-
727
- it("applies status filter to notebook cell execution", async () => {
728
- const model = await Model.create(
729
- "test-pkg",
730
- TEST_PKG_DIR,
731
- "test_notebook.malloynb",
732
- getConnections(),
733
- );
734
-
735
- const codeCell = await model.executeNotebookCell(2, {
736
- status: "cancelled",
737
- });
738
- expect(codeCell.result).toBeDefined();
739
-
740
- const notebookRows = parseNotebookResult(codeCell.result!);
741
- expect(notebookRows.length).toBe(1);
742
- expect(Number(notebookRows[0].order_count)).toBe(2);
743
- expect(Number(notebookRows[0].total_amount)).toBe(125);
744
- });
745
-
746
- it("bypassFilters skips filter injection on notebook cells", async () => {
747
- const model = await Model.create(
748
- "test-pkg",
749
- TEST_PKG_DIR,
750
- "test_notebook.malloynb",
751
- getConnections(),
752
- );
753
-
754
- const codeCell = await model.executeNotebookCell(
755
- 2,
756
- { region: ["US"] },
757
- true,
758
- );
759
- expect(codeCell.result).toBeDefined();
760
-
761
- const notebookRows = parseNotebookResult(codeCell.result!);
762
- expect(notebookRows.length).toBe(1);
763
- expect(Number(notebookRows[0].order_count)).toBe(6);
764
- });
765
-
766
- it("returns markdown cells unchanged", async () => {
767
- const model = await Model.create(
768
- "test-pkg",
769
- TEST_PKG_DIR,
770
- "test_notebook.malloynb",
771
- getConnections(),
772
- );
773
-
774
- const markdownCell = await model.executeNotebookCell(0);
775
- expect(markdownCell.type).toBe("markdown");
776
- expect(markdownCell.text).toContain("Test Notebook");
777
- });
778
-
779
- it("applies givens to notebook cell execution", async () => {
780
- await writeFile("orders_givens.malloy", MODEL_WITH_GIVENS);
781
- await writeFile("givens_notebook.malloynb", NOTEBOOK_GIVENS);
782
- const model = await Model.create(
783
- "test-pkg",
784
- TEST_PKG_DIR,
785
- "givens_notebook.malloynb",
786
- getConnections(),
787
- );
788
-
789
- // Cell 2: run: orders -> by_given_region with target_region overridden to 'EU'
790
- // EU rows: (3,'EU','active',150) and (4,'EU','cancelled',75) → order_count=2, total_amount=225
791
- const codeCell = await model.executeNotebookCell(
792
- 2,
793
- undefined,
794
- undefined,
795
- { target_region: "EU" },
796
- );
797
- expect(codeCell.result).toBeDefined();
798
-
799
- const notebookRows = parseNotebookResult(codeCell.result!);
800
- expect(notebookRows.length).toBe(1);
801
- expect(Number(notebookRows[0].order_count)).toBe(2);
802
- expect(Number(notebookRows[0].total_amount)).toBe(225);
803
- });
804
-
805
- it("composes givens and filterParams in notebook cell execution", async () => {
806
- await writeFile(
807
- "orders_givens_filter.malloy",
808
- MODEL_WITH_GIVENS_AND_FILTER,
809
- );
810
- await writeFile(
811
- "givens_filter_notebook.malloynb",
812
- NOTEBOOK_GIVENS.replace(
813
- "orders_givens.malloy",
814
- "orders_givens_filter.malloy",
815
- ),
816
- );
817
- const model = await Model.create(
818
- "test-pkg",
819
- TEST_PKG_DIR,
820
- "givens_filter_notebook.malloynb",
821
- getConnections(),
822
- );
823
-
824
- // given restricts to APAC; filterParam restricts to active
825
- // APAC + active: only (5,'APAC','active',300) → order_count=1, total_amount=300
826
- const codeCell = await model.executeNotebookCell(
827
- 2,
828
- { status: "active" },
829
- undefined,
830
- { target_region: "APAC" },
831
- );
832
- expect(codeCell.result).toBeDefined();
833
-
834
- const notebookRows = parseNotebookResult(codeCell.result!);
835
- expect(notebookRows.length).toBe(1);
836
- expect(Number(notebookRows[0].order_count)).toBe(1);
837
- expect(Number(notebookRows[0].total_amount)).toBe(300);
838
- });
839
- });
840
-
841
- // -----------------------------------------------------------------------
842
- // Extended source filter inheritance
843
- // -----------------------------------------------------------------------
844
- describe("extended source filter inheritance", () => {
845
- beforeEach(async () => {
846
- await writeFile("base_orders.malloy", MODEL_BASE_FOR_EXTEND);
847
- await writeFile("child_orders.malloy", MODEL_CHILD_EXTEND);
848
- await writeFile("extend_notebook.malloynb", NOTEBOOK_EXTEND);
849
- });
850
-
851
- it("inherits base-only filters on extended source", async () => {
852
- const model = await Model.create(
853
- "test-pkg",
854
- TEST_PKG_DIR,
855
- "child_orders.malloy",
856
- getConnections(),
857
- );
858
-
859
- const sources = model.getSources();
860
- const child = sources!.find((s) => s.name === "child_orders");
861
- expect(child).toBeDefined();
862
- expect(child!.filters).toBeDefined();
863
-
864
- // status is defined only on the base — it should carry through
865
- const statusFilter = child!.filters!.find((f) => f.name === "status");
866
- expect(statusFilter).toBeDefined();
867
- expect(statusFilter!.type).toBe("equal");
868
- });
869
-
870
- it("child overrides base filter type", async () => {
871
- const model = await Model.create(
872
- "test-pkg",
873
- TEST_PKG_DIR,
874
- "child_orders.malloy",
875
- getConnections(),
876
- );
877
-
878
- const sources = model.getSources();
879
- const child = sources!.find((s) => s.name === "child_orders");
880
- expect(child).toBeDefined();
881
-
882
- // region: base=in, child overrides to equal
883
- const regionFilter = child!.filters!.find((f) => f.name === "region");
884
- expect(regionFilter).toBeDefined();
885
- expect(regionFilter!.type).toBe("equal");
886
- });
887
-
888
- it("child can remove required flag by overriding", async () => {
889
- const model = await Model.create(
890
- "test-pkg",
891
- TEST_PKG_DIR,
892
- "child_orders.malloy",
893
- getConnections(),
894
- );
895
-
896
- const sources = model.getSources();
897
- const child = sources!.find((s) => s.name === "child_orders");
898
- expect(child).toBeDefined();
899
-
900
- // tenant: base=required, child overrides without required
901
- const tenantFilter = child!.filters!.find((f) => f.name === "tenant");
902
- expect(tenantFilter).toBeDefined();
903
- expect(tenantFilter!.required).toBeFalsy();
904
- });
905
-
906
- it("has exactly the expected merged filter set", async () => {
907
- const model = await Model.create(
908
- "test-pkg",
909
- TEST_PKG_DIR,
910
- "child_orders.malloy",
911
- getConnections(),
912
- );
913
-
914
- const sources = model.getSources();
915
- const child = sources!.find((s) => s.name === "child_orders");
916
- expect(child).toBeDefined();
917
-
918
- // 3 unique filter names: region, status (from base), tenant
919
- const filterNames = child!.filters!.map((f) => f.name).sort();
920
- expect(filterNames).toEqual(["region", "status", "tenant"]);
921
- });
922
-
923
- it("applies inherited filter to query on extended source", async () => {
924
- const model = await Model.create(
925
- "test-pkg",
926
- TEST_PKG_DIR,
927
- "child_orders.malloy",
928
- getConnections(),
929
- );
930
-
931
- // status=active is inherited from the base; should work on child
932
- const { compactResult } = await model.getQueryResults(
933
- "child_orders",
934
- "summary",
935
- undefined,
936
- { status: "active" },
937
- );
938
- const rows = asRows(compactResult);
939
- expect(rows.length).toBe(1);
940
- // 4 active rows: US(2), EU(1), APAC(1)
941
- expect(Number(rows[0].order_count)).toBe(4);
942
- });
943
-
944
- it("applies overridden filter to query on extended source", async () => {
945
- const model = await Model.create(
946
- "test-pkg",
947
- TEST_PKG_DIR,
948
- "child_orders.malloy",
949
- getConnections(),
950
- );
951
-
952
- // region is overridden to type=equal on the child
953
- const { compactResult } = await model.getQueryResults(
954
- "child_orders",
955
- "summary",
956
- undefined,
957
- { region: "US" },
958
- );
959
- const rows = asRows(compactResult);
960
- expect(rows.length).toBe(1);
961
- // 2 US rows
962
- expect(Number(rows[0].order_count)).toBe(2);
963
- });
964
-
965
- it("no longer requires base's required filter after child override", async () => {
966
- const model = await Model.create(
967
- "test-pkg",
968
- TEST_PKG_DIR,
969
- "child_orders.malloy",
970
- getConnections(),
971
- );
972
-
973
- // On the base, tenant is required. On the child, it's not.
974
- // Running without tenant should NOT throw.
975
- const { compactResult } = await model.getQueryResults(
976
- "child_orders",
977
- "summary",
978
- );
979
- const rows = asRows(compactResult);
980
- expect(rows.length).toBe(1);
981
- expect(Number(rows[0].order_count)).toBe(6);
982
- });
983
-
984
- it("applies inherited filters to notebook cells", async () => {
985
- const model = await Model.create(
986
- "test-pkg",
987
- TEST_PKG_DIR,
988
- "extend_notebook.malloynb",
989
- getConnections(),
990
- );
991
-
992
- // Apply status=cancelled (inherited from base) via notebook cell
993
- const codeCell = await model.executeNotebookCell(2, {
994
- status: "cancelled",
995
- });
996
- expect(codeCell.result).toBeDefined();
997
-
998
- const rows = parseNotebookResult(codeCell.result!);
999
- expect(rows.length).toBe(1);
1000
- // 2 cancelled rows: EU(1), APAC(1)
1001
- expect(Number(rows[0].order_count)).toBe(2);
1002
- });
1003
- });
1004
- });