@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,685 +0,0 @@
1
- import type { PersistSource } from "@malloydata/malloy";
2
- import { describe, expect, it } from "bun:test";
3
- import * as sinon from "sinon";
4
- import type { BuildGraph as MalloyBuildGraph } from "@malloydata/malloy";
5
- import {
6
- compilePackageBuildPlan,
7
- computeSourceEntityId,
8
- computePackageBuildPlan,
9
- deriveAnnotationFields,
10
- deriveBuildPlan,
11
- flattenDependsOn,
12
- iterGraphSources,
13
- projectToPublicColumns,
14
- resolveFreshness,
15
- resolveQueryMetadata,
16
- resolvePackageConnections,
17
- } from "./build_plan";
18
- import { MaterializationEligibilityError } from "../errors";
19
- import { fakeSource } from "./materialization_test_fixtures";
20
- import { Model } from "./model";
21
-
22
- describe("flattenDependsOn", () => {
23
- it("maps nested dependsOn entries to a flat sourceID list", () => {
24
- expect(
25
- flattenDependsOn({
26
- dependsOn: [{ sourceID: "a" }, { sourceID: "b" }],
27
- }),
28
- ).toEqual(["a", "b"]);
29
- });
30
- });
31
-
32
- describe("iterGraphSources", () => {
33
- it("yields resolvable sources in dependency order, skipping missing ones", () => {
34
- const a = fakeSource({ name: "a", sourceEntityId: "ba" });
35
- const b = fakeSource({ name: "b", sourceEntityId: "bb" });
36
- const graph = {
37
- connectionName: "duckdb",
38
- nodes: [
39
- [{ sourceID: "a@m", dependsOn: [] }],
40
- [
41
- { sourceID: "missing@m", dependsOn: [] },
42
- { sourceID: "b@m", dependsOn: [] },
43
- ],
44
- ],
45
- } as unknown as MalloyBuildGraph;
46
-
47
- const names = [...iterGraphSources(graph, { "a@m": a, "b@m": b })].map(
48
- (s) => s.name,
49
- );
50
- expect(names).toEqual(["a", "b"]);
51
- });
52
-
53
- it("walks each root's nested dependsOn tree, deps before dependents", () => {
54
- // root -> mid -> leaf, with only `root` at the graph's node level — this
55
- // mirrors malloy getBuildPlan(): terminal persist sources are the nodes,
56
- // and every transitive persist dependency is nested in dependsOn. All
57
- // three must be yielded (so all get built), leaf-first so a downstream
58
- // build reads its upstream's freshly materialized table.
59
- const root = fakeSource({ name: "root", sourceEntityId: "br" });
60
- const mid = fakeSource({ name: "mid", sourceEntityId: "bm" });
61
- const leaf = fakeSource({ name: "leaf", sourceEntityId: "bl" });
62
- const graph = {
63
- connectionName: "duckdb",
64
- nodes: [
65
- [
66
- {
67
- sourceID: "root@m",
68
- dependsOn: [
69
- {
70
- sourceID: "mid@m",
71
- dependsOn: [{ sourceID: "leaf@m", dependsOn: [] }],
72
- },
73
- ],
74
- },
75
- ],
76
- ],
77
- } as unknown as MalloyBuildGraph;
78
-
79
- const names = [
80
- ...iterGraphSources(graph, {
81
- "root@m": root,
82
- "mid@m": mid,
83
- "leaf@m": leaf,
84
- }),
85
- ].map((s) => s.name);
86
- expect(names).toEqual(["leaf", "mid", "root"]);
87
- });
88
-
89
- it("deduplicates a shared (diamond) dependency across roots", () => {
90
- // r1 and r2 both depend on `shared`; it must be yielded exactly once and
91
- // before both dependents.
92
- const r1 = fakeSource({ name: "r1", sourceEntityId: "b1" });
93
- const r2 = fakeSource({ name: "r2", sourceEntityId: "b2" });
94
- const shared = fakeSource({ name: "shared", sourceEntityId: "bs" });
95
- const graph = {
96
- connectionName: "duckdb",
97
- nodes: [
98
- [
99
- {
100
- sourceID: "r1@m",
101
- dependsOn: [{ sourceID: "shared@m", dependsOn: [] }],
102
- },
103
- {
104
- sourceID: "r2@m",
105
- dependsOn: [{ sourceID: "shared@m", dependsOn: [] }],
106
- },
107
- ],
108
- ],
109
- } as unknown as MalloyBuildGraph;
110
-
111
- const names = [
112
- ...iterGraphSources(graph, {
113
- "r1@m": r1,
114
- "r2@m": r2,
115
- "shared@m": shared,
116
- }),
117
- ].map((s) => s.name);
118
- expect(names).toEqual(["shared", "r1", "r2"]);
119
- });
120
- });
121
-
122
- describe("deriveAnnotationFields", () => {
123
- it("returns all key=value fields of the #@ persist annotation", () => {
124
- const source = {
125
- annotations: {
126
- parseAsTag: () => ({
127
- tag: {
128
- *entries() {
129
- yield ["name", { text: () => "engaged_events" }];
130
- yield ["realization", { text: () => "COPY" }];
131
- },
132
- },
133
- }),
134
- },
135
- } as unknown as PersistSource;
136
-
137
- expect(deriveAnnotationFields(source)).toEqual({
138
- name: "engaged_events",
139
- realization: "COPY",
140
- });
141
- });
142
-
143
- it("degrades to {} when the annotation is absent or unparseable", () => {
144
- const source = {
145
- annotations: {
146
- parseAsTag: () => {
147
- throw new Error("no @ annotation");
148
- },
149
- },
150
- } as unknown as PersistSource;
151
-
152
- expect(deriveAnnotationFields(source)).toEqual({});
153
- });
154
- });
155
-
156
- describe("projectToPublicColumns", () => {
157
- // A source whose PUBLIC surface (intrinsic atomic fields) is `cols` — i.e. any
158
- // `except:`-ed / access-restricted column is already absent here, as Malloy
159
- // reflects it. deriveColumns reads exactly this.
160
- const sourceWithPublicCols = (cols: string[]): PersistSource =>
161
- ({
162
- dialectName: "postgres",
163
- _explore: {
164
- intrinsicFields: cols.map((name) => ({
165
- name,
166
- isAtomicField: () => true,
167
- type: "string",
168
- })),
169
- },
170
- }) as unknown as PersistSource;
171
-
172
- it("wraps the build SQL to project only the source's public columns", () => {
173
- const src = sourceWithPublicCols(["order_date", "amount"]); // `region` hidden → absent
174
- const out = projectToPublicColumns(
175
- src,
176
- "SELECT order_date, region, amount FROM t",
177
- );
178
- // Outer projection lists ONLY the public columns; the hidden one is dropped.
179
- expect(out).toMatch(/^SELECT\b/);
180
- expect(out).toContain("order_date");
181
- expect(out).toContain("amount");
182
- expect(out).toContain(
183
- "FROM (SELECT order_date, region, amount FROM t) AS __public",
184
- );
185
- // `region` must not appear in the OUTER projection (before the subquery).
186
- const outerProjection = out.slice(0, out.indexOf("FROM ("));
187
- expect(outerProjection).not.toContain("region");
188
- });
189
-
190
- // Fails closed, like the rest of the eligibility surface: a public surface we
191
- // can't determine refuses the build rather than widening to everything getSQL
192
- // projects (which is where the hidden columns are).
193
- it("refuses the build when the field list can't be read", () => {
194
- const noExplore = {} as unknown as PersistSource;
195
- expect(() => projectToPublicColumns(noExplore, "SELECT 1")).toThrow(
196
- /public column surface could not be determined/,
197
- );
198
- });
199
-
200
- it("refuses the build when the source exposes no public atomic columns", () => {
201
- // Everything getSQL projects is hidden — the worst case to materialize.
202
- expect(() =>
203
- projectToPublicColumns(sourceWithPublicCols([]), "SELECT 1"),
204
- ).toThrow(/no public atomic columns/);
205
- });
206
-
207
- it("refuses with an eligibility error (422), naming the source", () => {
208
- const src = { ...sourceWithPublicCols([]), name: "daily" };
209
- try {
210
- projectToPublicColumns(src as unknown as PersistSource, "SELECT 1");
211
- throw new Error("expected a refusal");
212
- } catch (err) {
213
- expect(err).toBeInstanceOf(MaterializationEligibilityError);
214
- expect((err as Error).message).toContain("'daily'");
215
- }
216
- });
217
- });
218
-
219
- describe("computeSourceEntityId", () => {
220
- it("delegates to PersistSource.makeBuildId with the connection digest and SQL", () => {
221
- const makeBuildId = sinon.stub().returns("computed-id");
222
- const source = {
223
- connectionName: "duckdb",
224
- makeBuildId,
225
- getSQL: () => "SELECT 7",
226
- } as unknown as PersistSource;
227
-
228
- const id = computeSourceEntityId(source, { duckdb: "dig-1" });
229
-
230
- expect(id).toBe("computed-id");
231
- expect(makeBuildId.calledOnceWithExactly("dig-1", "SELECT 7")).toBe(true);
232
- });
233
- });
234
-
235
- describe("resolvePackageConnections", () => {
236
- it("resolves each unique name once and omits failures", async () => {
237
- const getMalloyConnection = sinon.stub();
238
- getMalloyConnection.withArgs("ok").resolves({ id: "ok-conn" });
239
- getMalloyConnection.withArgs("bad").rejects(new Error("nope"));
240
-
241
- const map = await resolvePackageConnections({ getMalloyConnection }, [
242
- "ok",
243
- "ok",
244
- "bad",
245
- ]);
246
-
247
- expect(map.has("ok")).toBe(true);
248
- expect(map.has("bad")).toBe(false);
249
- // "ok" requested twice but resolved once (dedupe).
250
- expect(getMalloyConnection.withArgs("ok").callCount).toBe(1);
251
- });
252
- });
253
-
254
- describe("deriveBuildPlan", () => {
255
- it("projects graphs and sources into the wire build plan", () => {
256
- const orders = fakeSource({
257
- name: "orders",
258
- sourceEntityId: "bid-orders",
259
- sql: "SELECT 1",
260
- });
261
- const plan = deriveBuildPlan(
262
- [
263
- {
264
- connectionName: "duckdb",
265
- nodes: [[{ sourceID: "orders@m", dependsOn: [] }]],
266
- },
267
- ] as unknown as Parameters<typeof deriveBuildPlan>[0],
268
- { "orders@m": orders },
269
- { duckdb: "dig" },
270
- );
271
-
272
- expect(plan.graphs[0].connectionName).toBe("duckdb");
273
- expect(plan.sources["orders@m"]).toMatchObject({
274
- name: "orders",
275
- connectionName: "duckdb",
276
- sourceEntityId: "bid-orders",
277
- sql: "SELECT 1",
278
- columns: [],
279
- });
280
- });
281
-
282
- it("reports declared refresh verbatim (null when unset) and does not emit sharing/schedule", () => {
283
- // `refresh` is a metadata pass-through; `sharing`/`schedule` were retired
284
- // from the contract and must not be emitted as typed fields (they stay in
285
- // the raw annotationFields for the publish-time validator to detect).
286
- const declared = fakeSource({
287
- name: "declared",
288
- sourceEntityId: "bid-d",
289
- annotationFields: {
290
- name: "d_table",
291
- sharing: "private",
292
- refresh: "incremental",
293
- },
294
- });
295
- const unset = fakeSource({ name: "unset", sourceEntityId: "bid-u" });
296
- const plan = deriveBuildPlan(
297
- [
298
- {
299
- connectionName: "duckdb",
300
- nodes: [
301
- [
302
- { sourceID: "declared@m", dependsOn: [] },
303
- { sourceID: "unset@m", dependsOn: [] },
304
- ],
305
- ],
306
- },
307
- ] as unknown as Parameters<typeof deriveBuildPlan>[0],
308
- { "declared@m": declared, "unset@m": unset },
309
- { duckdb: "dig" },
310
- );
311
-
312
- expect(plan.sources["declared@m"].refresh).toBe("incremental");
313
- // Retired typed fields are absent from the wire projection.
314
- expect(
315
- (plan.sources["declared@m"] as Record<string, unknown>).sharing,
316
- ).toBeUndefined();
317
- expect(
318
- (plan.sources["declared@m"] as Record<string, unknown>).schedule,
319
- ).toBeUndefined();
320
- // The raw annotation map still carries every field (so the validator can
321
- // reject a source-level sharing/schedule at publish).
322
- expect(plan.sources["declared@m"].annotationFields).toEqual({
323
- name: "d_table",
324
- sharing: "private",
325
- refresh: "incremental",
326
- });
327
- // Unset refresh is null on the wire.
328
- expect(plan.sources["unset@m"].refresh).toBeNull();
329
- });
330
-
331
- it("honors the sourceNames filter", () => {
332
- const a = fakeSource({ name: "a", sourceEntityId: "bid-a" });
333
- const b = fakeSource({ name: "b", sourceEntityId: "bid-b" });
334
- const plan = deriveBuildPlan(
335
- [
336
- {
337
- connectionName: "duckdb",
338
- nodes: [[{ sourceID: "a@m", dependsOn: [] }]],
339
- },
340
- ] as unknown as Parameters<typeof deriveBuildPlan>[0],
341
- { "a@m": a, "b@m": b },
342
- { duckdb: "dig" },
343
- ["a"],
344
- );
345
-
346
- expect(Object.keys(plan.sources)).toEqual(["a@m"]);
347
- });
348
-
349
- it("carries the per-source package-relative modelPath", () => {
350
- const a = fakeSource({ name: "a", sourceEntityId: "bid-a" });
351
- const b = fakeSource({ name: "b", sourceEntityId: "bid-b" });
352
- const plan = deriveBuildPlan(
353
- [
354
- {
355
- connectionName: "duckdb",
356
- nodes: [[{ sourceID: "a@m", dependsOn: [] }]],
357
- },
358
- ] as unknown as Parameters<typeof deriveBuildPlan>[0],
359
- { "a@m": a, "b@m": b },
360
- { duckdb: "dig" },
361
- undefined,
362
- { "a@m": "rollup.malloy" },
363
- );
364
-
365
- // Mapped source gets its model path; an unmapped source stays undefined.
366
- expect(plan.sources["a@m"].modelPath).toBe("rollup.malloy");
367
- expect(plan.sources["b@m"].modelPath).toBeUndefined();
368
- });
369
- });
370
-
371
- describe("resolveFreshness", () => {
372
- it("reports source-level freshness verbatim", () => {
373
- const source = fakeSource({
374
- name: "s",
375
- sourceEntityId: "bid",
376
- freshnessSchedule: {
377
- freshness: { window: "1h", fallback: "stale_ok" },
378
- },
379
- });
380
- expect(resolveFreshness(source, null)).toEqual({
381
- window: "1h",
382
- fallback: "stale_ok",
383
- });
384
- });
385
-
386
- it("returns null when unset at every level", () => {
387
- const source = fakeSource({ name: "s", sourceEntityId: "bid" });
388
- expect(resolveFreshness(source, null)).toBeNull();
389
- });
390
-
391
- it("falls back to model-file then package per field (most-specific-wins)", () => {
392
- // freshness.window from source, freshness.fallback from model-file.
393
- const source = fakeSource({
394
- name: "s",
395
- sourceEntityId: "bid",
396
- freshnessSchedule: { freshness: { window: "1h" } },
397
- modelFreshnessSchedule: { freshness: { fallback: "fail" } },
398
- });
399
- const pkg = {
400
- schedule: null,
401
- freshness: { window: "24h", fallback: "live" as const },
402
- };
403
- expect(resolveFreshness(source, pkg)).toEqual({
404
- window: "1h",
405
- fallback: "fail",
406
- });
407
- });
408
-
409
- it("inherits the package freshness when the source and model are unset", () => {
410
- const source = fakeSource({ name: "s", sourceEntityId: "bid" });
411
- const pkg = { schedule: null, freshness: { window: "24h" } };
412
- expect(resolveFreshness(source, pkg)).toEqual({ window: "24h" });
413
- });
414
-
415
- it("drops an invalid fallback rather than defaulting it", () => {
416
- const source = fakeSource({
417
- name: "s",
418
- sourceEntityId: "bid",
419
- freshnessSchedule: { freshness: { window: "1h", fallback: "bogus" } },
420
- });
421
- expect(resolveFreshness(source, null)).toEqual({ window: "1h" });
422
- });
423
-
424
- it("reads the model-file `materialization` envelope", () => {
425
- const source = fakeSource({
426
- name: "s",
427
- sourceEntityId: "bid",
428
- modelMaterialization: { freshness: { freshness: { window: "12h" } } },
429
- });
430
- expect(resolveFreshness(source, null)).toEqual({ window: "12h" });
431
- });
432
-
433
- it("prefers the envelope over the deprecated bare model-file form", () => {
434
- const source = fakeSource({
435
- name: "s",
436
- sourceEntityId: "bid",
437
- modelFreshnessSchedule: { freshness: { window: "48h" } },
438
- modelMaterialization: { freshness: { freshness: { window: "12h" } } },
439
- });
440
- expect(resolveFreshness(source, null)).toEqual({ window: "12h" });
441
- });
442
-
443
- it("still reads a bare model-file knob the envelope does not declare", () => {
444
- // A package published before the envelope existed keeps resolving, and the
445
- // envelope does not hide the knobs it says nothing about.
446
- const source = fakeSource({
447
- name: "s",
448
- sourceEntityId: "bid",
449
- modelFreshnessSchedule: { freshness: { fallback: "fail" } },
450
- modelMaterialization: { freshness: { freshness: { window: "12h" } } },
451
- });
452
- expect(resolveFreshness(source, null)).toEqual({
453
- window: "12h",
454
- fallback: "fail",
455
- });
456
- });
457
- });
458
-
459
- describe("resolveQueryMetadata", () => {
460
- it("returns null when no layer declares anything", () => {
461
- const source = fakeSource({ name: "s", sourceEntityId: "bid" });
462
- expect(resolveQueryMetadata(source, null)).toBeNull();
463
- expect(
464
- resolveQueryMetadata(source, {
465
- schedule: null,
466
- freshness: null,
467
- queryMetadata: null,
468
- }),
469
- ).toBeNull();
470
- });
471
-
472
- it("reads the source's `#@ persist queryMetadata.*` properties", () => {
473
- const source = fakeSource({
474
- name: "s",
475
- sourceEntityId: "bid",
476
- queryMetadata: { team: "finance", workload: "orders" },
477
- });
478
- expect(resolveQueryMetadata(source, null)).toEqual({
479
- team: "finance",
480
- workload: "orders",
481
- });
482
- });
483
-
484
- it("resolves most-specific-wins PER PROPERTY across all four layers", () => {
485
- // Package declares team+tier, the model-file envelope overrides tier and
486
- // adds one of its own, the source overrides only workload: every property
487
- // nothing more specific overrides has to survive.
488
- const source = fakeSource({
489
- name: "s",
490
- sourceEntityId: "bid",
491
- queryMetadata: { workload: "orders" },
492
- modelMaterialization: {
493
- queryMetadata: { tier: "gold", surface: "marts" },
494
- },
495
- });
496
- expect(
497
- resolveQueryMetadata(source, {
498
- schedule: null,
499
- freshness: null,
500
- queryMetadata: { team: "finance", tier: "bronze" },
501
- }),
502
- ).toEqual({
503
- team: "finance",
504
- tier: "gold",
505
- surface: "marts",
506
- workload: "orders",
507
- });
508
- });
509
-
510
- it("prefers the model-file envelope over the bare form, per property", () => {
511
- const source = fakeSource({
512
- name: "s",
513
- sourceEntityId: "bid",
514
- modelQueryMetadata: { tier: "bronze", legacy: "kept" },
515
- modelMaterialization: { queryMetadata: { tier: "gold" } },
516
- });
517
- expect(resolveQueryMetadata(source, null)).toEqual({
518
- tier: "gold",
519
- legacy: "kept",
520
- });
521
- });
522
-
523
- it("keeps a contract-violating property for the validator to report", () => {
524
- const source = fakeSource({
525
- name: "s",
526
- sourceEntityId: "bid",
527
- queryMetadata: { "team.name": "finance" },
528
- });
529
- expect(resolveQueryMetadata(source, null)).toEqual({
530
- "team.name": "finance",
531
- });
532
- });
533
-
534
- it("does not confuse the scalar `#@ persist` fields beside it", () => {
535
- const source = fakeSource({
536
- name: "s",
537
- sourceEntityId: "bid",
538
- annotationFields: { name: "s_table", refresh: "full" },
539
- queryMetadata: { team: "finance" },
540
- });
541
- expect(resolveQueryMetadata(source, null)).toEqual({ team: "finance" });
542
- expect(deriveAnnotationFields(source)).toEqual({
543
- name: "s_table",
544
- refresh: "full",
545
- });
546
- });
547
- });
548
-
549
- describe("deriveBuildPlan freshness", () => {
550
- it("projects the resolved per-source freshness onto the plan (no schedule/sharing)", () => {
551
- const source = fakeSource({
552
- name: "s",
553
- sourceEntityId: "bid",
554
- annotationFields: { name: "s_table" },
555
- freshnessSchedule: { freshness: { window: "1h" } },
556
- });
557
- const plan = deriveBuildPlan(
558
- [
559
- {
560
- connectionName: "duckdb",
561
- nodes: [[{ sourceID: "s@m", dependsOn: [] }]],
562
- },
563
- ] as unknown as Parameters<typeof deriveBuildPlan>[0],
564
- { "s@m": source },
565
- { duckdb: "dig" },
566
- undefined,
567
- undefined,
568
- {
569
- schedule: null,
570
- freshness: { window: "24h", fallback: "live" as const },
571
- },
572
- );
573
-
574
- // Source window wins over the package default; package fallback fills the
575
- // unset source fallback.
576
- expect(plan.sources["s@m"].freshness).toEqual({
577
- window: "1h",
578
- fallback: "live",
579
- });
580
- // Retired fields are not emitted.
581
- expect(
582
- (plan.sources["s@m"] as Record<string, unknown>).schedule,
583
- ).toBeUndefined();
584
- expect(
585
- (plan.sources["s@m"] as Record<string, unknown>).sharing,
586
- ).toBeUndefined();
587
- });
588
- });
589
-
590
- describe("compilePackageBuildPlan", () => {
591
- it("skips .malloynb notebooks without compiling them", async () => {
592
- // A notebook would throw on its `>>>` cell delimiter if compiled as a
593
- // flat model, aborting the whole package plan; it must be skipped.
594
- const getModelRuntime = sinon.stub(Model, "getModelRuntime");
595
- try {
596
- const pkg = {
597
- getModelPaths: () => ["notes.malloynb"],
598
- getPackagePath: () => "/test",
599
- getMalloyConfig: () => ({}),
600
- getMalloyConnection: async () => ({}),
601
- } as unknown as Parameters<typeof compilePackageBuildPlan>[0];
602
-
603
- const compiled = await compilePackageBuildPlan(pkg);
604
-
605
- expect(compiled.graphs).toEqual([]);
606
- expect(getModelRuntime.called).toBe(false);
607
- } finally {
608
- getModelRuntime.restore();
609
- }
610
- });
611
-
612
- it("skips a model lacking ##! experimental.persistence instead of aborting the package", async () => {
613
- // getBuildPlan() THROWS on a model without the flag (it does not return
614
- // empty), so a header-less non-persist model — e.g. an imported base that
615
- // only defines raw sources — must be skipped, or it would abort the whole
616
- // package plan and drop the persist source in the sibling model.
617
- const fakeModel = (hasFlag: boolean, graphs: MalloyBuildGraph[]) => ({
618
- modelAnnotations: {
619
- parseAsTag: () => ({ tag: { has: () => hasFlag } }),
620
- },
621
- getBuildPlan: () => {
622
- if (!hasFlag) {
623
- throw new Error(
624
- "Model must have ##! experimental.persistence to use getBuildPlan()",
625
- );
626
- }
627
- return { graphs, sources: {}, tagParseLog: [] };
628
- },
629
- });
630
- const models: Record<string, ReturnType<typeof fakeModel>> = {
631
- "base.malloy": fakeModel(false, []), // header-less: must be skipped
632
- "agg.malloy": fakeModel(true, [
633
- {
634
- connectionName: "duckdb",
635
- nodes: [[{ sourceID: "daily@agg", dependsOn: [] }]],
636
- },
637
- ] as unknown as MalloyBuildGraph[]),
638
- };
639
- const getModelRuntime = sinon
640
- .stub(Model, "getModelRuntime")
641
- .callsFake((async (_path: unknown, modelPath: unknown) => ({
642
- runtime: {
643
- loadModel: () => ({
644
- getModel: async () => models[modelPath as string],
645
- }),
646
- },
647
- modelURL: new URL(`file:///${modelPath}`),
648
- importBaseURL: new URL("file:///"),
649
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
650
- })) as any);
651
- try {
652
- const pkg = {
653
- getModelPaths: () => ["base.malloy", "agg.malloy"],
654
- getPackagePath: () => "/test",
655
- getMalloyConfig: () => ({}),
656
- getMalloyConnection: async () => ({ getDigest: async () => "dig" }),
657
- } as unknown as Parameters<typeof compilePackageBuildPlan>[0];
658
-
659
- // Would throw here before the guard (base.malloy's getBuildPlan).
660
- const compiled = await compilePackageBuildPlan(pkg);
661
-
662
- // The header-less model is skipped; the persist source in agg survives.
663
- expect(compiled.graphs).toHaveLength(1);
664
- expect(compiled.graphs[0].nodes[0][0].sourceID).toBe("daily@agg");
665
- } finally {
666
- getModelRuntime.restore();
667
- }
668
- });
669
- });
670
-
671
- describe("computePackageBuildPlan", () => {
672
- it("returns a null plan and no dropped sources when the package declares no persist sources", async () => {
673
- const pkg = {
674
- getModelPaths: () => [],
675
- getPackagePath: () => "/test",
676
- getMalloyConfig: () => ({}),
677
- getMalloyConnection: async () => ({}),
678
- } as unknown as Parameters<typeof computePackageBuildPlan>[0];
679
-
680
- const { plan, droppedPersistSources } =
681
- await computePackageBuildPlan(pkg);
682
- expect(plan).toBeNull();
683
- expect(droppedPersistSources).toEqual([]);
684
- });
685
- });