@malloy-publisher/server 0.17.0 → 0.17.1

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 (30) hide show
  1. package/dist/app/api-doc.yaml +169 -613
  2. package/dist/app/assets/{EnvironmentPage-D2-0ts2G.js → EnvironmentPage-DF2PahCR.js} +1 -1
  3. package/dist/app/assets/{HomePage-S_Bkczsx.js → HomePage-DIYlgPCz.js} +1 -1
  4. package/dist/app/assets/{MainPage-DEy4SyjJ.js → MainPage-C7PGAA5k.js} +1 -1
  5. package/dist/app/assets/ModelPage-BMoBnrW7.js +2 -0
  6. package/dist/app/assets/PackagePage-DD2vLSFe.js +1 -0
  7. package/dist/app/assets/{PackageSplatRoute-ChFCJOWE.js → PackageSplatRoute-BYIMwnLL.js} +2 -2
  8. package/dist/app/assets/{RenderedResult-BcEDcw0V.es-BD6PNbt6.js → RenderedResult-CYJ2Y9Fm.es-C8nokn71.js} +7 -7
  9. package/dist/app/assets/{RouteError-CDSSYdLB.js → RouteError-B8dE60Vs.js} +1 -1
  10. package/dist/app/assets/{ThemeEditorPage-DO2JWYOR.js → ThemeEditorPage-D0wf74fh.js} +1 -1
  11. package/dist/app/assets/{ToggleButtonGroup-BylAiUaK.js → ToggleButtonGroup-CX0_J2zR.js} +1 -1
  12. package/dist/app/assets/{documentRoutes-CaOt2rpR.js → documentRoutes-DgSMAc0m.js} +1 -1
  13. package/dist/app/assets/{editPageMounted-79YCIKgP.js → editPageMounted-BUGVg-_g.js} +2 -2
  14. package/dist/app/assets/{index-BOCBPBsi.js → index-BQL8UUcK.js} +1 -1
  15. package/dist/app/assets/{index-CPSEdm5f.js → index-BiOT4K_d.js} +1 -1
  16. package/dist/app/assets/{index-keJ8KKBp.js → index-DAQjZOAL.js} +1 -1
  17. package/dist/app/assets/index-DRkw60sj.js +512 -0
  18. package/dist/app/assets/{index.es-DTreXoC5.js → index.es-DgNl8IqU.js} +20 -20
  19. package/dist/app/assets/usePackageLinkNavigate-bHr_AFYo.js +1 -0
  20. package/dist/app/assets/{usePackageRoute-G6fA1__J.js → usePackageRoute-BhB6txS6.js} +1 -1
  21. package/dist/app/index.html +1 -1
  22. package/dist/app/mcp-app/report.js +2683 -757
  23. package/dist/instrumentation.mjs +4 -4
  24. package/dist/package_load_worker.mjs +199 -39
  25. package/dist/server.mjs +2119 -1164
  26. package/package.json +1 -1
  27. package/dist/app/assets/ModelPage-BVHjDM-u.js +0 -2
  28. package/dist/app/assets/PackagePage-Cbrg7o1X.js +0 -1
  29. package/dist/app/assets/index-BKjEX4_C.js +0 -512
  30. package/dist/app/assets/usePackageLinkNavigate-BfSAqkJS.js +0 -1
@@ -645,7 +645,7 @@ var init_query = __esm(() => {
645
645
  type: integer({ min: 0 }),
646
646
  default: DEFAULT_MAX_QUERY_ROWS,
647
647
  description: "Row cap on ad-hoc connection SQL; 0 leaves only the byte cap.",
648
- notes: "Maximum rows returned per query on every query surface (`/connections/.../sqlQuery`, model query, notebook cell, MCP `executeQuery`). Forwarded to the connector / Malloy `runnable.run` as the effective row limit; queries that exceed the cap fail with HTTP 413. Set to `0` to disable. A caller-supplied `rowLimit` smaller than the cap is preserved.",
648
+ notes: "Maximum rows returned per query on every query surface (`/connections/.../sqlQuery`, model query, MCP `executeQuery`). Forwarded to the connector / Malloy `runnable.run` as the effective row limit; queries that exceed the cap fail with HTTP 413. Set to `0` to disable. A caller-supplied `rowLimit` smaller than the cap is preserved.",
649
649
  aliases: { env: ["PUBLISHER_MAX_QUERY_ROWS"] }
650
650
  }),
651
651
  setting({
@@ -653,7 +653,7 @@ var init_query = __esm(() => {
653
653
  type: integer({ min: 0 }),
654
654
  default: DEFAULT_MAX_RESPONSE_BYTES,
655
655
  description: "Byte cap on ad-hoc connection SQL responses; 0 leaves only the row cap.",
656
- notes: "Maximum JSON-serialized response size, for ad-hoc SQL, model queries and notebook cells. Streaming-capable connections (Postgres, DuckDB) enforce mid-stream and abort the driver immediately; non-streaming connections enforce post-buffer. Exceeding the cap fails with HTTP 413. Set to `0` to disable. See the note below the table.",
656
+ notes: "Maximum JSON-serialized response size, for ad-hoc SQL and model queries. Streaming-capable connections (Postgres, DuckDB) enforce mid-stream and abort the driver immediately; non-streaming connections enforce post-buffer. Exceeding the cap fails with HTTP 413. Set to `0` to disable. See the note below the table.",
657
657
  defaultText: "`50000000` (50 MB)",
658
658
  aliases: { env: ["PUBLISHER_MAX_RESPONSE_BYTES"] }
659
659
  }),
@@ -1110,7 +1110,7 @@ var init_server = __esm(() => {
1110
1110
  type: oneOf(["explorer", "viewer"]),
1111
1111
  default: "explorer",
1112
1112
  description: "The page the Console shows for a model, reported on /status as modelPage: explorer, or viewer, which builds no query and takes the Explorer out of the legacy notebook too.",
1113
- notes: "`explorer` or `viewer`: the page the Console shows for a model, reported on `/status` as `modelPage`. `explorer` is the [Explorer](explorer.md), which writes the queries it builds back to Malloy with string values unescaped (`escapeString` in `@malloydata/malloy-interfaces` is a TODO), so a drilled value holding a double quote rewrites its query; the server's restricted mode and `#(authorize)` still bound what that query can read. `viewer` shows the model viewer, which builds no query, and also takes the Explorer's \"Data sources\" dialog out of the legacy notebook; there a given's option list also quotes every name. The Console keeps both pages, and shows the viewer if `/status` cannot be read. Any other value fails startup.",
1113
+ notes: "`explorer` or `viewer`: the page the Console shows for a model, reported on `/status` as `modelPage`. `explorer` is the [Explorer](explorer.md), which builds queries; the server's restricted mode and `#(authorize)` bound what those queries can read. `viewer` shows the model viewer, which builds no query, and also takes the Explorer's \"Data sources\" dialog out of the legacy notebook; there a given's option list also quotes every name. The Console keeps both pages, and shows the viewer if `/status` cannot be read. Any other value fails startup.",
1114
1114
  noFlag: true,
1115
1115
  aliases: { env: ["PUBLISHER_MODEL_PAGE"] }
1116
1116
  }),
@@ -167061,7 +167061,7 @@ var init_telemetry = __esm(() => {
167061
167061
  });
167062
167062
 
167063
167063
  // package.json
167064
- var version = "0.17.0";
167064
+ var version = "0.17.1";
167065
167065
  var init_package = () => {};
167066
167066
 
167067
167067
  // src/version.ts
@@ -76,6 +76,71 @@ var init_constants = __esm(() => {
76
76
 
77
77
  // src/service/deprecated/malloynb.ts
78
78
  import { MalloySQLParser } from "@malloydata/malloy-sql";
79
+ function listMalloynbCellFindings(notebooks, limits) {
80
+ const warnings = [];
81
+ let listed = 0;
82
+ let unlisted = 0;
83
+ const past = [];
84
+ const pastByReason = new Map;
85
+ for (const { model, refusals } of notebooks) {
86
+ const shown = Math.max(0, Math.min(limits.perNotebook, limits.perPackage - listed));
87
+ const kept = refusals.slice(0, shown);
88
+ const rest = refusals.slice(shown);
89
+ warnings.push(...kept.map((r) => r.finding));
90
+ listed += kept.length;
91
+ if (rest.length === 0)
92
+ continue;
93
+ unlisted += rest.length;
94
+ if (kept.length === 0) {
95
+ past.push({ model, cells: rest.length });
96
+ for (const { finding } of rest) {
97
+ const reason = finding.reason ?? "unknown";
98
+ pastByReason.set(reason, (pastByReason.get(reason) ?? 0) + 1);
99
+ }
100
+ continue;
101
+ }
102
+ const byReason = new Map;
103
+ for (const { cell, finding } of rest) {
104
+ const reason = finding.reason ?? "unknown";
105
+ const cells = byReason.get(reason);
106
+ if (cells)
107
+ cells.push(cell);
108
+ else
109
+ byReason.set(reason, [cell]);
110
+ }
111
+ const groups = Array.from(byReason, ([reason, cells]) => `${cells.length === 1 ? "cell" : "cells"} ${numberList(cells)} (${reason})`).join("; ");
112
+ warnings.push({
113
+ model,
114
+ code: MALLOYNB_CELLS_UNLISTED,
115
+ severity: "warn",
116
+ message: `${rest.length} more ${rest.length === 1 ? "cell" : "cells"} of ` + `${model} won't run for any reader in the Console, not listed ` + `one by one: ${groups}. ${FIX_AND_RELOAD}`
117
+ });
118
+ }
119
+ if (past.length > 0) {
120
+ const cells = past.reduce((sum, notebook) => sum + notebook.cells, 0);
121
+ const named = past.slice(0, limits.notebooksNamed).map((notebook) => `${notebook.cells} in ${notebook.model}`);
122
+ const others = past.slice(limits.notebooksNamed);
123
+ if (others.length > 0) {
124
+ const otherCells = others.reduce((sum, n) => sum + n.cells, 0);
125
+ named.push(`${otherCells} in ${others.length} other ` + `${others.length === 1 ? "notebook" : "notebooks"}`);
126
+ }
127
+ const reasons = Array.from(pastByReason, ([reason, count]) => `${count} ${reason}`);
128
+ warnings.push({
129
+ code: MALLOYNB_CELLS_UNLISTED,
130
+ severity: "warn",
131
+ message: `${cells} more ${cells === 1 ? "cell" : "cells"}, in ` + `${past.length} more ` + `${past.length === 1 ? "notebook" : "notebooks"}, won't run for ` + `any reader in the Console, not listed because the package lists ` + `at most ${limits.perPackage} one by one: ${wordList(named)}. ` + `By reason: ${wordList(reasons)}. ${FIX_AND_RELOAD}`
132
+ });
133
+ }
134
+ return { warnings, unlisted };
135
+ }
136
+ function numberList(numbers) {
137
+ return wordList(numbers.map(String));
138
+ }
139
+ function wordList(words) {
140
+ if (words.length === 1)
141
+ return words[0];
142
+ return `${words.slice(0, -1).join(", ")} and ${words[words.length - 1]}`;
143
+ }
79
144
  function isMalloynbPath(modelPath) {
80
145
  return modelPath.endsWith(NOTEBOOK_FILE_SUFFIX);
81
146
  }
@@ -83,8 +148,15 @@ function parseMalloynb(fileContents, modelPath) {
83
148
  return MalloySQLParser.parse(fileContents.replace(/\r\n/g, `
84
149
  `), modelPath);
85
150
  }
151
+ var MALLOYNB_CELL_REFUSED = "malloynb-cell-refused", MALLOYNB_CELLS_UNLISTED = "malloynb-cells-unlisted", MALLOYNB_CELL_CHECK_FAILED = "malloynb-cell-check-failed", MALLOYNB_CELLS_LISTED, FIX_AND_RELOAD;
86
152
  var init_malloynb = __esm(() => {
87
153
  init_constants();
154
+ MALLOYNB_CELLS_LISTED = {
155
+ perNotebook: 10,
156
+ perPackage: 50,
157
+ notebooksNamed: 10
158
+ };
159
+ FIX_AND_RELOAD = "The legacy .malloynb section of docs/reports.md gives the fix for each " + "reason, and a reload after fixing lists what remains.";
88
160
  });
89
161
 
90
162
  // ../../node_modules/@opentelemetry/api/build/src/platform/node/globalThis.js
@@ -2167,7 +2239,7 @@ var init_query = __esm(() => {
2167
2239
  type: integer({ min: 0 }),
2168
2240
  default: DEFAULT_MAX_QUERY_ROWS,
2169
2241
  description: "Row cap on ad-hoc connection SQL; 0 leaves only the byte cap.",
2170
- notes: "Maximum rows returned per query on every query surface (`/connections/.../sqlQuery`, model query, notebook cell, MCP `executeQuery`). Forwarded to the connector / Malloy `runnable.run` as the effective row limit; queries that exceed the cap fail with HTTP 413. Set to `0` to disable. A caller-supplied `rowLimit` smaller than the cap is preserved.",
2242
+ notes: "Maximum rows returned per query on every query surface (`/connections/.../sqlQuery`, model query, MCP `executeQuery`). Forwarded to the connector / Malloy `runnable.run` as the effective row limit; queries that exceed the cap fail with HTTP 413. Set to `0` to disable. A caller-supplied `rowLimit` smaller than the cap is preserved.",
2171
2243
  aliases: { env: ["PUBLISHER_MAX_QUERY_ROWS"] }
2172
2244
  }),
2173
2245
  setting({
@@ -2175,7 +2247,7 @@ var init_query = __esm(() => {
2175
2247
  type: integer({ min: 0 }),
2176
2248
  default: DEFAULT_MAX_RESPONSE_BYTES,
2177
2249
  description: "Byte cap on ad-hoc connection SQL responses; 0 leaves only the row cap.",
2178
- notes: "Maximum JSON-serialized response size, for ad-hoc SQL, model queries and notebook cells. Streaming-capable connections (Postgres, DuckDB) enforce mid-stream and abort the driver immediately; non-streaming connections enforce post-buffer. Exceeding the cap fails with HTTP 413. Set to `0` to disable. See the note below the table.",
2250
+ notes: "Maximum JSON-serialized response size, for ad-hoc SQL and model queries. Streaming-capable connections (Postgres, DuckDB) enforce mid-stream and abort the driver immediately; non-streaming connections enforce post-buffer. Exceeding the cap fails with HTTP 413. Set to `0` to disable. See the note below the table.",
2179
2251
  defaultText: "`50000000` (50 MB)",
2180
2252
  aliases: { env: ["PUBLISHER_MAX_RESPONSE_BYTES"] }
2181
2253
  }),
@@ -2632,7 +2704,7 @@ var init_server = __esm(() => {
2632
2704
  type: oneOf(["explorer", "viewer"]),
2633
2705
  default: "explorer",
2634
2706
  description: "The page the Console shows for a model, reported on /status as modelPage: explorer, or viewer, which builds no query and takes the Explorer out of the legacy notebook too.",
2635
- notes: "`explorer` or `viewer`: the page the Console shows for a model, reported on `/status` as `modelPage`. `explorer` is the [Explorer](explorer.md), which writes the queries it builds back to Malloy with string values unescaped (`escapeString` in `@malloydata/malloy-interfaces` is a TODO), so a drilled value holding a double quote rewrites its query; the server's restricted mode and `#(authorize)` still bound what that query can read. `viewer` shows the model viewer, which builds no query, and also takes the Explorer's \"Data sources\" dialog out of the legacy notebook; there a given's option list also quotes every name. The Console keeps both pages, and shows the viewer if `/status` cannot be read. Any other value fails startup.",
2707
+ notes: "`explorer` or `viewer`: the page the Console shows for a model, reported on `/status` as `modelPage`. `explorer` is the [Explorer](explorer.md), which builds queries; the server's restricted mode and `#(authorize)` bound what those queries can read. `viewer` shows the model viewer, which builds no query, and also takes the Explorer's \"Data sources\" dialog out of the legacy notebook; there a given's option list also quotes every name. The Console keeps both pages, and shows the viewer if `/status` cannot be read. Any other value fails startup.",
2636
2708
  noFlag: true,
2637
2709
  aliases: { env: ["PUBLISHER_MODEL_PAGE"] }
2638
2710
  }),
@@ -13386,18 +13458,16 @@ ${body}`;
13386
13458
  if (modelDef && runCount !== modelDef.queryList.length) {
13387
13459
  return refuse({
13388
13460
  line: 1,
13389
- message: `Line 1: the notebook reader found ${runCount} run: statements where Malloy compiled ${modelDef.queryList.length}, so its query cells cannot be matched to their results. Fix: none in the file; report it, since the reader and the compiler disagree.`
13461
+ message: `Line 1: the notebook reader and the Malloy compiler disagree on the number of run: statements. The reader found ${runCount} and the compiler ${modelDef.queryList.length}. Fix: none in the file; report it.`
13390
13462
  });
13391
13463
  }
13392
13464
  const cells = [];
13393
13465
  const annotations = [];
13394
13466
  let lineRun;
13395
- let runsSeen = 0;
13396
13467
  items.forEach((item, index) => {
13397
13468
  const belowTag = index > artifactAt;
13398
13469
  if (item.kind === "statement") {
13399
13470
  lineRun = undefined;
13400
- const queryIndex = item.run ? runsSeen++ : undefined;
13401
13471
  const pushed = item.run && belowTag ? {
13402
13472
  kind: "query",
13403
13473
  type: "code",
@@ -13411,8 +13481,7 @@ ${body}`;
13411
13481
  caption: item.caption
13412
13482
  },
13413
13483
  startLine: item.startLine,
13414
- endLine: item.endLine,
13415
- queryIndex
13484
+ endLine: item.endLine
13416
13485
  } : {
13417
13486
  kind: "definition",
13418
13487
  type: "code",
@@ -15513,6 +15582,9 @@ function probeFilterList(view) {
15513
15582
  const ref = view.structRef;
15514
15583
  return ref?.filterList;
15515
15584
  }
15585
+ function requiresUniqueKey(requirement) {
15586
+ return requirement !== undefined && requirement !== false;
15587
+ }
15516
15588
  function joinGrainAggregatePaths(view) {
15517
15589
  const out = [];
15518
15590
  let unreadable = false;
@@ -15527,9 +15599,9 @@ function joinGrainAggregatePaths(view) {
15527
15599
  const usage = node.expandedFieldUsage;
15528
15600
  if (Array.isArray(usage)) {
15529
15601
  for (const u of usage) {
15530
- if (!u || u.uniqueKeyRequirement === undefined)
15602
+ if (!u || !requiresUniqueKey(u.uniqueKeyRequirement))
15531
15603
  continue;
15532
- if (!Array.isArray(u.path) || u.path.some((p) => typeof p !== "string")) {
15604
+ if (u.uniqueKeyRequirement !== true || !Array.isArray(u.path) || u.path.some((p) => typeof p !== "string")) {
15533
15605
  unreadable = true;
15534
15606
  continue;
15535
15607
  }
@@ -15819,9 +15891,9 @@ function aggregateOutsideJoin(view, sourceDef, join) {
15819
15891
  if (!Array.isArray(usage))
15820
15892
  return;
15821
15893
  for (const u of usage) {
15822
- if (!u || u.uniqueKeyRequirement === undefined)
15894
+ if (!u || !requiresUniqueKey(u.uniqueKeyRequirement))
15823
15895
  continue;
15824
- if (!Array.isArray(u.path)) {
15896
+ if (u.uniqueKeyRequirement !== true || !Array.isArray(u.path)) {
15825
15897
  unreadable = true;
15826
15898
  continue;
15827
15899
  }
@@ -25601,17 +25673,6 @@ var init_model_load_checks = __esm(() => {
25601
25673
 
25602
25674
  // src/service/model_notebook_cell.ts
25603
25675
  import { MalloySQLStatementType } from "@malloydata/malloy-sql";
25604
- function declaredGivensPerCell(cells) {
25605
- return cells.map((cell) => {
25606
- if (!cell.modelDef)
25607
- return;
25608
- const registry = cell.modelDef.givens ?? {};
25609
- return {
25610
- ids: new Set(Object.keys(registry)),
25611
- names: new Set(Object.values(registry).map((g) => g.name))
25612
- };
25613
- });
25614
- }
25615
25676
  async function tileQueryInfo(materializer, text) {
25616
25677
  try {
25617
25678
  const def = (await materializer.extendModel(text).getModel())._modelDef;
@@ -25669,7 +25730,6 @@ async function compileNotebookCells(runtime, importBaseURL, statements) {
25669
25730
  cells.push({
25670
25731
  type: "code",
25671
25732
  text: statement.text,
25672
- materializer,
25673
25733
  modelDef,
25674
25734
  newSources,
25675
25735
  query,
@@ -28743,7 +28803,7 @@ var init_dialect = __esm(() => {
28743
28803
  castsToIntegerType: true,
28744
28804
  onlyBigIntegerType: "INT64",
28745
28805
  leafBudget: 120,
28746
- stringCollation: "binary",
28806
+ stringCollation: "dataset",
28747
28807
  ungroupableTypes: {
28748
28808
  malloy: ["json", "array", "record"],
28749
28809
  native: ["geography"]
@@ -29966,6 +30026,39 @@ function skipAnnotation(text, i, blank) {
29966
30026
  }
29967
30027
  return at;
29968
30028
  }
30029
+ function annotationsBefore(text, from, to) {
30030
+ let found = [];
30031
+ const keep = () => {
30032
+ return;
30033
+ };
30034
+ let i = from;
30035
+ while (i < to) {
30036
+ const code = text.charCodeAt(i);
30037
+ if (isSpaceCode(code, text, i)) {
30038
+ i += unitsAt(text, i);
30039
+ continue;
30040
+ }
30041
+ let end = -1;
30042
+ if (code === 35) {
30043
+ end = skipAnnotation(text, i, keep);
30044
+ if (end >= 0) {
30045
+ found.push({ from: i, to: end, model: text.startsWith("##", i) });
30046
+ }
30047
+ } else if (text.startsWith("--", i) || text.startsWith("//", i)) {
30048
+ end = toEndOfLine(text, i);
30049
+ } else if (text.startsWith("/*", i)) {
30050
+ const close = text.indexOf("*/", i + 2);
30051
+ end = close === -1 ? text.length : close + 2;
30052
+ }
30053
+ if (end < 0) {
30054
+ found = [];
30055
+ i += unitsAt(text, i);
30056
+ continue;
30057
+ }
30058
+ i = end;
30059
+ }
30060
+ return found;
30061
+ }
29969
30062
  function closesBlock(text, at, column, closer) {
29970
30063
  for (let c = 0;c < column; c++) {
29971
30064
  const code = text.charCodeAt(at + c);
@@ -33123,6 +33216,14 @@ function sourceReads(source) {
33123
33216
  return;
33124
33217
  }
33125
33218
  }
33219
+ function queryTableReads(entry, pipeline) {
33220
+ return sourceReads({
33221
+ _sourceDef: {
33222
+ type: "query_source",
33223
+ query: { structRef: entry, pipeline }
33224
+ }
33225
+ });
33226
+ }
33126
33227
  var MAX_DEPTH = 200, Unknown;
33127
33228
  var init_source_reads = __esm(() => {
33128
33229
  Unknown = class Unknown extends Error {
@@ -35845,6 +35946,15 @@ function storedColumnsOfOutput(fields, options) {
35845
35946
  }
35846
35947
  return out;
35847
35948
  }
35949
+ function spelledNativeType(nativeType, dialect) {
35950
+ if (isArrayType(nativeType))
35951
+ return;
35952
+ const [spelled] = storedColumnsOfOutput([{ name: "c", ...getDialect2(dialect).sqlTypeToMalloyType(nativeType) }], { nested: false, bigint: true, timestamptz: true });
35953
+ return spelled?.type;
35954
+ }
35955
+ function isArrayType(type) {
35956
+ return /\[\s*\d*\s*\]\s*$/.test(type) || /^\s*ARRAY\b/i.test(type);
35957
+ }
35848
35958
  function storedTypeOfField(field, nested, depth, bigint = false, timestamptz = false) {
35849
35959
  if (depth > 16 || field === null || typeof field !== "object") {
35850
35960
  return;
@@ -36367,6 +36477,50 @@ function extractRunTargetSourceNames(query) {
36367
36477
  }
36368
36478
  return [];
36369
36479
  }
36480
+ function lastRunStatementText(text) {
36481
+ const tokens = tokenize2(stripMalloyCommentsAndLiterals(text));
36482
+ const colonStatement = (k, words) => words.some((word) => isWord(tokens, k, word)) && textIs(tokens, k + 1, ":");
36483
+ let depth = 0;
36484
+ let open = -1;
36485
+ let last = -1;
36486
+ let found;
36487
+ for (let k = 0;k < tokens.count; k++) {
36488
+ const opens = depth === 0 && (textIs(tokens, k, ";") || isWord(tokens, k, "import") || isWord(tokens, k, "export") || colonStatement(k, COLON_STATEMENTS));
36489
+ if (opens) {
36490
+ if (open >= 0)
36491
+ found = [open, last];
36492
+ open = colonStatement(k, ["run"]) ? k : -1;
36493
+ last = k + 1;
36494
+ if (open >= 0)
36495
+ k++;
36496
+ continue;
36497
+ }
36498
+ last = k;
36499
+ if (tokens.kind[k] !== PUNCT)
36500
+ continue;
36501
+ const code = tokens.source.charCodeAt(tokens.start[k]);
36502
+ if (code === 40 || code === 91 || code === 123)
36503
+ depth++;
36504
+ else if (code === 41 || code === 93 || code === 125)
36505
+ depth = Math.max(0, depth - 1);
36506
+ }
36507
+ if (open >= 0)
36508
+ found = [open, last];
36509
+ if (!found)
36510
+ return;
36511
+ const [run, end] = found;
36512
+ let from = tokens.start[run];
36513
+ const before = annotationsBefore(text, run > 0 ? rawEnd(tokens, run - 1) : 0, from);
36514
+ for (const tag of before.reverse()) {
36515
+ if (tag.model)
36516
+ break;
36517
+ from = tag.from;
36518
+ }
36519
+ return text.slice(from, rawEnd(tokens, end));
36520
+ }
36521
+ function rawEnd(tokens, k) {
36522
+ return tokens.end[k] + (tokens.kind[k] === QUOTED ? 1 : 0);
36523
+ }
36370
36524
  function namesOutside(tokens, headFrom, headTo) {
36371
36525
  const names = new Set;
36372
36526
  for (let k = 0;k < tokens.count; k++) {
@@ -36781,10 +36935,11 @@ function locateProblemsInCallerText(problems, callerText, prefixLines) {
36781
36935
  };
36782
36936
  });
36783
36937
  }
36784
- var UNREADABLE_BASE = "`", PUNCT = 0, NAME = 1, QUOTED = 2;
36938
+ var UNREADABLE_BASE = "`", COLON_STATEMENTS, PUNCT = 0, NAME = 1, QUOTED = 2;
36785
36939
  var init_query_text = __esm(() => {
36786
36940
  init_malloy_lexer_core();
36787
36941
  init_malloy_lexer_core();
36942
+ COLON_STATEMENTS = ["run", "source", "query", "given", "sql", "type"];
36788
36943
  });
36789
36944
 
36790
36945
  // src/service/materialization/plan/materialize_read_time.ts
@@ -41979,12 +42134,12 @@ function statementsOf(text, tokens) {
41979
42134
  }
41980
42135
  return out;
41981
42136
  }
41982
- function definitionCutAt(text, offset) {
42137
+ function definitionCutAt(text, offset, topLevel = false) {
41983
42138
  const tokens = lexAll(text);
41984
42139
  if (!tokens)
41985
42140
  return;
41986
42141
  const statements = statementsOf(text, tokens);
41987
- const holding = statements.filter((s) => DEFINITION_KEYWORDS.has(s.keyword.text) && s.keyword.start <= offset && offset < s.end && (s.keyword.depth === 0 || s.keyword.text !== "source" && s.keyword.text !== "query"));
42142
+ const holding = statements.filter((s) => DEFINITION_KEYWORDS.has(s.keyword.text) && s.keyword.start <= offset && offset < s.end && (s.keyword.depth === 0 ? !topLevel || s.keyword.text === "source" || s.keyword.text === "query" : !topLevel && s.keyword.text !== "source" && s.keyword.text !== "query"));
41988
42143
  if (holding.length === 0)
41989
42144
  return;
41990
42145
  const stmt = holding.reduce((a, b) => b.keyword.depth > a.keyword.depth || b.keyword.depth === a.keyword.depth && b.keyword.start > a.keyword.start ? b : a);
@@ -42031,19 +42186,24 @@ function definitionCutAt(text, offset) {
42031
42186
  name,
42032
42187
  ...declaration && declaration !== name ? { declaration } : {}
42033
42188
  };
42034
- if (defs.length === 1) {
42035
- const head = statementHead(tokens, tokens.indexOf(stmt.keyword));
42036
- const before = tokens.filter((t) => t.end <= head.start);
42037
- return {
42038
- start: annotationsStart(text, before[before.length - 1]?.end ?? 0, head.start),
42039
- end: stmtLast.end,
42040
- left
42041
- };
42042
- }
42189
+ const head = statementHead(tokens, tokens.indexOf(stmt.keyword));
42190
+ const before = tokens.filter((t) => t.end <= head.start);
42191
+ const whole = {
42192
+ start: annotationsStart(text, before[before.length - 1]?.end ?? 0, head.start),
42193
+ end: stmtLast.end
42194
+ };
42195
+ if (defs.length === 1)
42196
+ return { ...whole, left };
42197
+ const statement = { ...whole, definitions: defs.length };
42043
42198
  if (index === 0) {
42044
- return { start: stmt.colon.end, end: def.fullEnd, left };
42199
+ return { start: stmt.colon.end, end: def.fullEnd, left, statement };
42045
42200
  }
42046
- return { start: defs[index - 1].lastEnd, end: def.lastEnd, left };
42201
+ return {
42202
+ start: defs[index - 1].lastEnd,
42203
+ end: def.lastEnd,
42204
+ left,
42205
+ statement
42206
+ };
42047
42207
  }
42048
42208
  function annotationsStart(text, floor, keyword) {
42049
42209
  const lineStart = text.lastIndexOf(`