@malloy-publisher/server 0.9.10 → 0.9.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/api-doc.yaml +48 -41
- package/dist/app/assets/EnvironmentPage-tIGzymgb.js +1 -0
- package/dist/app/assets/HomePage-7QkNvQ_3.js +1 -0
- package/dist/app/assets/MainPage-BpE_5WuW.js +1 -0
- package/dist/app/assets/ModelPage-ftyDI1tw.js +2 -0
- package/dist/app/assets/PackagePage-QGnFwlHu.js +1 -0
- package/dist/app/assets/RenderedResult-Cmx8sX8d.es-du-Qe1x0.js +153 -0
- package/dist/app/assets/{RouteError-Bc7-ukP7.js → RouteError-zM4SSZaU.js} +1 -1
- package/dist/app/assets/ThemeEditorPage-DhZJXGJm.js +1 -0
- package/dist/app/assets/ToggleButtonGroup-TKxhg0Mg.js +1 -0
- package/dist/app/assets/{documentRoutes-CvCc_EZs.js → documentRoutes-D4TbSIi5.js} +1 -1
- package/dist/app/assets/editPageMounted-0kzl2sgg.js +2 -0
- package/dist/app/assets/{index-DnRXl1Nu.js → index-B-qJVEXn.js} +1 -1
- package/dist/app/assets/{index-DugQbYOk.js → index-Bzi4YH8Y.js} +1 -1
- package/dist/app/assets/{index-Ddy-NxB_.js → index-CS4mmuDD.js} +1 -1
- package/dist/app/assets/index-gQEuz0Cg.js +480 -0
- package/dist/app/assets/index.es-B3P9tIm3.js +143 -0
- package/dist/app/index.html +1 -1
- package/dist/package_load_worker.mjs +23 -9
- package/dist/server.mjs +725 -625
- package/package.json +1 -1
- package/dist/app/assets/EnvironmentPage-DfL-2Fy5.js +0 -1
- package/dist/app/assets/HomePage-Cc5z85GD.js +0 -1
- package/dist/app/assets/MainPage-Cv63Ip_P.js +0 -1
- package/dist/app/assets/ModelPage-DvyYSgri.js +0 -2
- package/dist/app/assets/PackagePage-BDzBa7qB.js +0 -1
- package/dist/app/assets/RenderedResult-Dp1Qdajz.es-woQDtiv_.js +0 -153
- package/dist/app/assets/ThemeEditorPage-DShPXmlS.js +0 -1
- package/dist/app/assets/ToggleButtonGroup-WO-9ZUmS.js +0 -1
- package/dist/app/assets/index-BvSbJtsT.js +0 -483
- package/dist/app/assets/index.es-BhMC9nt1.js +0 -195
package/dist/server.mjs
CHANGED
|
@@ -337127,7 +337127,7 @@ ${body}`;
|
|
|
337127
337127
|
if (artifactAt < 0) {
|
|
337128
337128
|
return refuse({
|
|
337129
337129
|
line: 1,
|
|
337130
|
-
message: "Line 1: this notebook has no ## artifact note, so its header cannot be told from its cells. Fix: add `## artifact { layout=linear }` after the ##! line."
|
|
337130
|
+
message: "Line 1: this notebook has no ## artifact note, so its header cannot be told from its cells. Fix: add `## artifact { layout=linear tiles=[…] }` after the ##! line."
|
|
337131
337131
|
});
|
|
337132
337132
|
}
|
|
337133
337133
|
const runCount = items.filter((item) => item.kind === "statement" && item.run).length;
|
|
@@ -337327,12 +337327,14 @@ function readReportTag(modelNotes) {
|
|
|
337327
337327
|
const kind = tagText(artifact, "kind");
|
|
337328
337328
|
if (kind !== undefined)
|
|
337329
337329
|
return { status: "kind-removed", kind };
|
|
337330
|
-
const
|
|
337331
|
-
if (
|
|
337332
|
-
return { status: "
|
|
337333
|
-
|
|
337334
|
-
|
|
337335
|
-
|
|
337330
|
+
const hasTiles = artifact.has("tiles");
|
|
337331
|
+
if (hasTiles && artifact.array("tiles") === undefined)
|
|
337332
|
+
return { status: "unparsed" };
|
|
337333
|
+
const declared = tagText(artifact, "layout");
|
|
337334
|
+
const layout = parseLayoutValue(declared) ?? (hasTiles || tags?.tag("dashboard") !== undefined ? "grid" : "linear");
|
|
337335
|
+
if (layout === "linear" && !hasTiles)
|
|
337336
|
+
return declared !== undefined && parseLayoutValue(declared) === undefined ? { status: "cells-removed", unknownLayout: declared } : { status: "cells-removed" };
|
|
337337
|
+
return { status: "report", layout };
|
|
337336
337338
|
}
|
|
337337
337339
|
function readReportTagOfText(text) {
|
|
337338
337340
|
return readReportTag(modelNotesOfText(text));
|
|
@@ -346036,7 +346038,7 @@ function mergeStatementTimeoutOption(existing, ms) {
|
|
|
346036
346038
|
}
|
|
346037
346039
|
function conninfoPairs(conninfo) {
|
|
346038
346040
|
const pairs = [];
|
|
346039
|
-
const isSpace = (c) => c !== undefined &&
|
|
346041
|
+
const isSpace = (c) => c !== undefined && /[ \t\n\v\f\r]/.test(c);
|
|
346040
346042
|
let i2 = 0;
|
|
346041
346043
|
while (i2 < conninfo.length) {
|
|
346042
346044
|
while (isSpace(conninfo[i2]))
|
|
@@ -346082,7 +346084,66 @@ function decodeUriComponentOrRaw(value) {
|
|
|
346082
346084
|
return value;
|
|
346083
346085
|
}
|
|
346084
346086
|
}
|
|
346085
|
-
|
|
346087
|
+
var LIBPQ_NO_VERIFY_SSLMODE = "require";
|
|
346088
|
+
var isUriConnectionString = (connectionString) => /^postgres(ql)?:\/\//i.test(connectionString);
|
|
346089
|
+
function mapUriQuery(uri, fn) {
|
|
346090
|
+
const queryStart = uri.indexOf("?");
|
|
346091
|
+
const base = queryStart === -1 ? uri : uri.slice(0, queryStart);
|
|
346092
|
+
const params = fn(queryStart === -1 ? [] : uri.slice(queryStart + 1).split("&"));
|
|
346093
|
+
return params.length ? `${base}?${params.join("&")}` : base;
|
|
346094
|
+
}
|
|
346095
|
+
function libpqSslmodeInRawString(connectionString) {
|
|
346096
|
+
const envNoVerify = process.env.PGSSLMODE?.toLowerCase() === "no-verify" && !process.env.PGSERVICE;
|
|
346097
|
+
const rewritten = `sslmode=${LIBPQ_NO_VERIFY_SSLMODE}`;
|
|
346098
|
+
if (isUriConnectionString(connectionString)) {
|
|
346099
|
+
return mapUriQuery(connectionString, (params) => {
|
|
346100
|
+
const keys = params.map((param) => decodeUriComponentOrRaw(param.split("=")[0]));
|
|
346101
|
+
const hasSslmode = keys.includes("sslmode");
|
|
346102
|
+
const hasCert = keys.some((key) => ["sslrootcert", "sslcert", "sslkey"].includes(key));
|
|
346103
|
+
let seen = false;
|
|
346104
|
+
const mapped = params.flatMap((param, i2) => {
|
|
346105
|
+
const [, ...rest] = param.split("=");
|
|
346106
|
+
const value = decodeUriComponentOrRaw(rest.join("="));
|
|
346107
|
+
if (keys[i2] === "service")
|
|
346108
|
+
seen = true;
|
|
346109
|
+
if (keys[i2] === "uselibpqcompat")
|
|
346110
|
+
return [];
|
|
346111
|
+
if (keys[i2] === "ssl") {
|
|
346112
|
+
if (hasSslmode)
|
|
346113
|
+
return [];
|
|
346114
|
+
if (value === "no-verify") {
|
|
346115
|
+
seen = true;
|
|
346116
|
+
return [rewritten];
|
|
346117
|
+
}
|
|
346118
|
+
if (value === "1")
|
|
346119
|
+
return ["ssl=true"];
|
|
346120
|
+
if (value === "0") {
|
|
346121
|
+
if (hasCert)
|
|
346122
|
+
return [];
|
|
346123
|
+
seen = true;
|
|
346124
|
+
return ["sslmode=disable"];
|
|
346125
|
+
}
|
|
346126
|
+
return [param];
|
|
346127
|
+
}
|
|
346128
|
+
if (keys[i2] !== "sslmode")
|
|
346129
|
+
return [param];
|
|
346130
|
+
seen = true;
|
|
346131
|
+
return [value === "no-verify" ? rewritten : param];
|
|
346132
|
+
});
|
|
346133
|
+
return !seen && envNoVerify ? [...mapped, rewritten] : mapped;
|
|
346134
|
+
});
|
|
346135
|
+
}
|
|
346136
|
+
const pairs = conninfoPairs(connectionString);
|
|
346137
|
+
let result = connectionString;
|
|
346138
|
+
for (const pair of [...pairs].reverse()) {
|
|
346139
|
+
if (pair.key === "sslmode" && pair.value === "no-verify") {
|
|
346140
|
+
result = result.slice(0, pair.start) + rewritten + result.slice(pair.end);
|
|
346141
|
+
}
|
|
346142
|
+
}
|
|
346143
|
+
return !pairs.some((pair) => pair.key === "sslmode" || pair.key === "service") && envNoVerify ? `${result} ${rewritten}` : result;
|
|
346144
|
+
}
|
|
346145
|
+
function libpqConnectionString(name, rawConnectionString, pg) {
|
|
346146
|
+
const connectionString = libpqSslmodeInRawString(rawConnectionString);
|
|
346086
346147
|
const ms = postgresStatementTimeoutMs(name, pg);
|
|
346087
346148
|
if (ms === undefined)
|
|
346088
346149
|
return connectionString;
|
|
@@ -346095,21 +346156,21 @@ function withLibpqStatementTimeout(name, connectionString, pg) {
|
|
|
346095
346156
|
}
|
|
346096
346157
|
return value;
|
|
346097
346158
|
};
|
|
346098
|
-
if (
|
|
346099
|
-
const queryStart = connectionString.indexOf("?");
|
|
346100
|
-
if (queryStart === -1) {
|
|
346101
|
-
return `${connectionString}?options=${encodeURIComponent(merged(undefined))}`;
|
|
346102
|
-
}
|
|
346103
|
-
const params = connectionString.slice(queryStart + 1).split("&");
|
|
346159
|
+
if (isUriConnectionString(connectionString)) {
|
|
346104
346160
|
const isOptions = (param) => decodeUriComponentOrRaw(param.split("=", 1)[0]) === "options";
|
|
346105
|
-
|
|
346106
|
-
|
|
346107
|
-
|
|
346108
|
-
|
|
346161
|
+
return mapUriQuery(connectionString, (params) => {
|
|
346162
|
+
const last = params.map(isOptions).lastIndexOf(true);
|
|
346163
|
+
if (last === -1) {
|
|
346164
|
+
return [
|
|
346165
|
+
...params,
|
|
346166
|
+
`options=${encodeURIComponent(merged(undefined))}`
|
|
346167
|
+
];
|
|
346168
|
+
}
|
|
346109
346169
|
const raw = params[last].slice(params[last].indexOf("=") + 1);
|
|
346110
|
-
|
|
346111
|
-
|
|
346112
|
-
|
|
346170
|
+
const out = [...params];
|
|
346171
|
+
out[last] = `options=${encodeURIComponent(merged(decodeUriComponentOrRaw(raw)))}`;
|
|
346172
|
+
return out;
|
|
346173
|
+
});
|
|
346113
346174
|
}
|
|
346114
346175
|
const existing = conninfoPairs(connectionString).filter((pair) => pair.key === "options").pop();
|
|
346115
346176
|
if (!existing) {
|
|
@@ -346122,12 +346183,13 @@ function buildPgConnectionString(pg, {
|
|
|
346122
346183
|
applyConnectionOptions
|
|
346123
346184
|
}) {
|
|
346124
346185
|
if (pg.connectionString) {
|
|
346125
|
-
if (!applyConnectionOptions)
|
|
346126
|
-
return pg.connectionString;
|
|
346186
|
+
if (!applyConnectionOptions) {
|
|
346187
|
+
return libpqSslmodeInRawString(pg.connectionString);
|
|
346188
|
+
}
|
|
346127
346189
|
if (pg.sslmode != null) {
|
|
346128
346190
|
logger.warn(`Connection '${name}' sets both postgresConnection.sslmode and ` + `connectionString; sslmode is ignored and the connectionString's own sslmode applies.`);
|
|
346129
346191
|
}
|
|
346130
|
-
return
|
|
346192
|
+
return libpqConnectionString(name, pg.connectionString, pg);
|
|
346131
346193
|
}
|
|
346132
346194
|
const parts = [];
|
|
346133
346195
|
if (pg.host)
|
|
@@ -346150,7 +346212,7 @@ function buildPgConnectionString(pg, {
|
|
|
346150
346212
|
const pgSSLMode = process.env.PGSSLMODE;
|
|
346151
346213
|
if (pgSSLMode) {
|
|
346152
346214
|
const mapping = {
|
|
346153
|
-
"no-verify":
|
|
346215
|
+
"no-verify": LIBPQ_NO_VERIFY_SSLMODE,
|
|
346154
346216
|
disable: "disable",
|
|
346155
346217
|
allow: "allow",
|
|
346156
346218
|
prefer: "prefer",
|
|
@@ -346519,7 +346581,7 @@ function libpqSslmodeParts(subject, mode, trust) {
|
|
|
346519
346581
|
case "disable":
|
|
346520
346582
|
return ["sslmode=disable"];
|
|
346521
346583
|
case "no-verify":
|
|
346522
|
-
return [
|
|
346584
|
+
return [`sslmode=${LIBPQ_NO_VERIFY_SSLMODE}`];
|
|
346523
346585
|
case "verify-ca": {
|
|
346524
346586
|
if (!trust.caBundle) {
|
|
346525
346587
|
throw new Error(`${subject} uses sslmode 'verify-ca' but no trusted CA bundle is available (NODE_EXTRA_CA_CERTS is unset).`);
|
|
@@ -349368,6 +349430,19 @@ function recordPackageLoadPhases(timings, status) {
|
|
|
349368
349430
|
schemaFetchDuration?.record(timings.schemaFetchDurationMs, attrs);
|
|
349369
349431
|
schemaFetches?.record(timings.schemaFetchCount, attrs);
|
|
349370
349432
|
}
|
|
349433
|
+
var phaseDuration = null;
|
|
349434
|
+
function recordPackageLoadPhaseDurations(durations) {
|
|
349435
|
+
phaseDuration ??= publisherMeter().createHistogram("publisher_package_load_phase_duration_ms", {
|
|
349436
|
+
description: "Per-load wall-clock time of each stage of a successful package load, main-thread stages included. Label: phase (worker, hydrate, render_validation, discovery, lint, build_plan, total).",
|
|
349437
|
+
unit: "ms",
|
|
349438
|
+
advice: { explicitBucketBoundaries: LOAD_DURATION_BUCKETS_MS }
|
|
349439
|
+
});
|
|
349440
|
+
for (const [phase, ms] of Object.entries(durations)) {
|
|
349441
|
+
if (ms === undefined)
|
|
349442
|
+
continue;
|
|
349443
|
+
phaseDuration.record(ms, { phase });
|
|
349444
|
+
}
|
|
349445
|
+
}
|
|
349371
349446
|
|
|
349372
349447
|
// src/report_metrics.ts
|
|
349373
349448
|
var resetHooks2 = [];
|
|
@@ -354724,7 +354799,7 @@ End with a short **Next steps**: one or two specific deeper analyses the data co
|
|
|
354724
354799
|
{
|
|
354725
354800
|
name: "malloy-analysis-report",
|
|
354726
354801
|
description: 'Combine validated Malloy queries into a report (a linear report, read top to bottom). Use when the user asks to "create a report", "combine these into a report", or wants a persistent multi-query artifact.',
|
|
354727
|
-
body: "# Creating Reports\n\nAn ad-hoc report is a Publisher **report** with `layout=linear`: a `.malloy` file at the package root, `<slug>.malloy` (unless the user asks for another location), that combines markdown narrative with live Malloy queries
|
|
354802
|
+
body: "# Creating Reports\n\nAn ad-hoc report is a Publisher **report** with `layout=linear`: a `.malloy` file at the package root, `<slug>.malloy` (unless the user asks for another location), that combines markdown narrative with live Malloy queries, as text tiles and query tiles read top to bottom. Load `skill:malloy-reports` for the full format and authoring rules; this skill covers when to build one and how to design good report content (tiles, chart annotations, narrative structure). Never write a new `.malloynb`, never write a report as bare `run:` statements (that older form is no longer read), and do not create a `notebooks/` or `dashboards/` directory for it.\n\n## Before building a report\n\n1. **Run each query first** via `execute_query` to verify it works and returns expected results.\n2. **Explain the results** to the user as you go: walk through the analysis step by step.\n3. **Then assemble the report** once the analysis is validated.\n\nDo NOT build the report in the same turn as `execute_query`. Explain first, then build.\n\n## Filters belong to the report, never to the source\n\nAn ad-hoc report usually needs no filters: it records an analysis already run. If the user wants one a reader can change (a manufacturer, a date range), declare the given in the report and bind it on its tiles, as `skill:malloy-reports` describes. Do not add a `given:` to the source for it: a model-level `where:` filters every read of the source, chat and every other report included, and the report builder can show such a filter but not change or remove it. A given the source already reads (a gate, a value every query must supply) shows in the report with no work, and stays in the model.\n\nNever add a `#(filter)` annotation: it is deprecated, and every use has a `given:` form (`malloy-model` covers the migration).\n\n## What goes in the report\n\nDo NOT add an H1 heading in any markdown (use H2 and below for sections); the `title` in the `## artifact` tag serves as the title. To redo the structure rather than tweak one tile, rewrite the report file end-to-end.\n\nText tiles own narrative; query tiles own a single Malloy query whose chart annotation tells the renderer how to display the result. Markdown supports H2 headings, lists, bold, and inline code. Keep text tiles short, one idea per tile, so the rendered output reads as a story instead of a wall of text.\n\nThe file has four parts, in this order:\n\n1. **The tag**, `##| artifact { layout=linear title=\"...\" tiles=[…] }`, listing every tile in reading order. A text tile is `name { kind=text }`; a query tile is the quoted string `\"<extension> -> <view>\"`.\n2. **The `import`** of the model file, relative to the report's own location (`\"order_analysis.malloy\"` from the package root).\n3. **The text tiles**, each a `##|(markdown) name` block: the name on the opener line, the body on the lines below, `|##` closing it.\n4. **One extension of the source**, `source: <source>_tiles is <source> extend { … }`, holding a `view:` per query tile. The view's chart tag and `# label=\"…\"` (the tile's heading) go directly above it.\n\nCompile the file with `/compile` (`\"scope\": \"file\"`, at the path `<slug>.malloy`) before saving; a report compiles as a model, so its errors come back there. After saving and reloading, read the package warnings: a tile that names a missing view is reported there, not by the compile. A complete report:\n\n```malloy\n##| artifact { layout=linear title=\"Sales report\"\n tiles=[\n overview { kind=text },\n \"order_analysis_tiles -> headline\",\n trend { kind=text },\n \"order_analysis_tiles -> revenue_by_month\",\n breakdown { kind=text },\n \"order_analysis_tiles -> top_categories\",\n takeaways { kind=text }\n ]\n}\n|##\nimport \"order_analysis.malloy\"\n\n##|(markdown) overview\n## Overview\nWhat is driving sales, and which categories carry it? The tiles below cover every order in the model.\n|##\n\n##|(markdown) trend\n## Trend\nHow does revenue move over time?\n|##\n\n##|(markdown) breakdown\n## Breakdown\nWhich categories account for the most revenue?\n|##\n\n##|(markdown) takeaways\n## Key takeaways\nWhat to look at next.\n|##\n\nsource: order_analysis_tiles is order_analysis extend {\n # big_value\n # label=\"Headline\"\n view: headline is {\n aggregate:\n # label=\"Revenue\"\n # currency\n total_revenue\n\n # label=\"Orders\"\n # number=auto\n order_count\n }\n\n # line_chart\n # label=\"Revenue by month\"\n view: revenue_by_month is {\n group_by: order_date.month\n aggregate: total_revenue\n order_by: 1\n }\n\n # bar_chart\n # label=\"Top ten categories by revenue\"\n view: top_categories is {\n group_by: category\n aggregate: total_revenue\n order_by: total_revenue desc\n limit: 10\n }\n}\n```\n\nWhen the model already has the view you want, the tile view refines it rather than repeating it: `view: top_categories is by_category + { limit: 10 }`.\n\nA well-structured report typically follows this pattern:\n\n```\n[Text] ## Overview: what question are we answering, what data is in scope (date range, entity count)\n[Query] KPI tile: headline numbers (e.g., # big_value, or # dashboard with nested # big_value views)\n[Text] ## Trend: describe what we should look for over time\n[Query] Time-series tile (e.g., # line_chart on a date dimension)\n[Text] ## Breakdown: where the signal is\n[Query] Categorical tile (e.g., # bar_chart on a categorical dimension)\n[Text] ## Key takeaways: what the user should walk away with\n```\n\nUse this as a default; deviate when the analysis warrants. A grounded report names the time range and entity count up front so every number that follows has context.\n\n## Choosing chart types and annotations\n\nRead `skill:malloy-charts` before picking visualizations: it owns chart-type selection, properties, and the placement rules for chart annotations. `skill:malloy-queries` covers Malloy query patterns and the critical placement rules for chart-annotation tags.\n\nWhen in doubt:\n\n- KPIs / single numbers -> `# big_value`, often nested inside `# dashboard`.\n- Trend over time -> `# line_chart`, usually on the primary date dimension.\n- Category comparisons -> `# bar_chart`, ordered by the metric.\n- Tabular data with many columns -> a plain table tile with `# table.size=fill`.\n- Multiple coordinated charts -> `# dashboard` with `nest:` blocks.\n\nAnnotations go **directly above** the tile's `view:`, never inside its curly braces:\n\n```malloy\n# bar_chart\nview: top_categories is {\n group_by: category\n aggregate: revenue\n order_by: revenue desc\n limit: 10\n}\n```\n\nA `# dashboard` tile composes nested views, useful for KPIs alongside a trend in a single tile. Each `nest:` is a tile; any top-level `aggregate:` measures render as KPI cards. For a fixed grid, use `# dashboard { columns=N }` with `# colspan` on each tile (see `skill:malloy-charts`):\n\n```malloy\n# dashboard { columns=2 }\nview: summary is {\n nest:\n # colspan=2\n # big_value\n kpis is {\n aggregate:\n # label=\"Revenue\"\n # currency\n total_revenue\n\n # label=\"Orders\"\n # number=auto\n order_count\n }\n nest:\n # line_chart\n trend is {\n group_by: order_date.month\n aggregate: total_revenue\n order_by: 1\n }\n}\n```\n\nKey rendering rules to keep in mind when shaping a tile:\n\n- FIRST `group_by` = x-axis, FIRST `aggregate` = y-axis.\n- Override field roles with `# x`, `# y`, `# series` on individual fields.\n- For multiple measure series, place `# y` above the `aggregate:` keyword.\n- One aggregate per chart view: use `# dashboard` with nested views for multiple charts.\n- Use `# table.size=fill` for standalone table queries.\n\n## Editing an existing report\n\nFor small targeted changes (fix one view, insert one tile), edit that view or text block in place and add its entry to `tiles=[…]`, rather than recreating the whole report. For structural rewrites (reordering many tiles, changing the narrative arc), rewrite the report file. An existing `.malloynb` is read, not edited: to change its story, write a `.malloy` report. A tag that sets `kind=notebook` is no longer read, so the file is not a report (`report-kind-removed`): replace it with `layout=linear` and list the tiles. A linear file with no `tiles=[…]`, written as bare `run:` statements, is no longer a report: rewrite it as tiles (`skill:malloy-reports`, `reference/linear.md`).\n\n## IMPORTANT\n\nYou CANNOT see the rendered output of report tiles. Do not claim to see charts, values, or patterns from report tiles you haven't explicitly executed via `execute_query`. If you need to analyze results, run the query via `execute_query` first."
|
|
354728
354803
|
},
|
|
354729
354804
|
{
|
|
354730
354805
|
name: "malloy-charts",
|
|
@@ -354909,7 +354984,7 @@ The user will:
|
|
|
354909
354984
|
- **Remove** fields they don't need.
|
|
354910
354985
|
- **Change** priorities.
|
|
354911
354986
|
|
|
354912
|
-
Once the definitions are confirmed, write them into the \`.malloy\` model (see your modeling workflow). Use \`#(doc)\` annotations to document sources and fields, and \`given:\`
|
|
354987
|
+
Once the definitions are confirmed, write them into the \`.malloy\` model (see your modeling workflow). Use \`#(doc)\` annotations to document sources and fields, and a \`given:\` only where the data's meaning or access depends on a runtime value (a gate, a value every query must supply). A filter a reader picks on a dashboard belongs to the report, not the model. \`#(filter)\` is deprecated. Never add a \`#(filter)\` annotation: every use, including \`required\`, \`implicit\`, and date/number ranges, has a \`given:\` form. See \`skill:malloy-model\` § Parameterizing sources with \`given:\`. Keep the confirmed definitions in the conversation; there is no separate plan-file store.
|
|
354913
354988
|
|
|
354914
354989
|
## Data-driven proposals
|
|
354915
354990
|
|
|
@@ -357447,31 +357522,39 @@ gets unwieldy.
|
|
|
357447
357522
|
|
|
357448
357523
|
## Parameterizing sources with \`given:\` (preferred)
|
|
357449
357524
|
|
|
357450
|
-
Native Malloy **\`given:\` parameters** are
|
|
357525
|
+
Native Malloy **\`given:\` parameters** are runtime values a model reads in its own logic; callers supply them at query time. \`#(filter)\` is deprecated: never add one. Enable givens with \`##! experimental.givens\` at the top of the model.
|
|
357526
|
+
|
|
357527
|
+
**A given belongs in the model only when the data's meaning or access depends on it:**
|
|
357528
|
+
|
|
357529
|
+
- a row-level gate: \`#(authorize)\`, \`#(access_filter)\`, a \`#(secure)\` given, \`$GROUPS\`;
|
|
357530
|
+
- a value every query must supply (the no-default row in the table below);
|
|
357531
|
+
- a parameter a measure, dimension or view is defined with;
|
|
357532
|
+
- scoping the author means to apply to every consumer of the source: chat, MCP and every report.
|
|
357533
|
+
|
|
357534
|
+
**A filter a reader picks on a dashboard or notebook is not modeling.** Manufacturer, a date range, region, a "major recalls only" toggle: don't add it to a source. Leave the source unfiltered, and let the report declare the given and bind it on its tiles (\`skill:malloy-reports\`). A model-level \`where:\` applies to every read of the source, chat and every other report included, and a report cannot take it over, because binding is per declaration, not per name. The report builder shows such a filter but cannot remove or reconfigure it.
|
|
357451
357535
|
|
|
357452
357536
|
\`\`\`malloy
|
|
357453
357537
|
##! experimental.givens
|
|
357454
357538
|
|
|
357455
|
-
|
|
357456
|
-
|
|
357457
|
-
subject_filter :: filter<string> is f''
|
|
357539
|
+
# A value every query must supply: the table is partitioned by day.
|
|
357540
|
+
given: EVENT_DATE :: date
|
|
357458
357541
|
|
|
357459
|
-
source:
|
|
357460
|
-
where:
|
|
357461
|
-
measure:
|
|
357542
|
+
source: events is duckdb.table('data/events.parquet') extend {
|
|
357543
|
+
where: event_date = $EVENT_DATE
|
|
357544
|
+
measure: event_count is count()
|
|
357462
357545
|
}
|
|
357463
357546
|
\`\`\`
|
|
357464
357547
|
|
|
357465
|
-
A given is **declared bare** but **referenced with a \`$\` sigil** in expressions (\`$
|
|
357548
|
+
A given is **declared bare** but **referenced with a \`$\` sigil** in expressions (\`$EVENT_DATE\`), as above.
|
|
357466
357549
|
|
|
357467
|
-
- **
|
|
357550
|
+
- **An optional given in the model gets a neutral, match-all default** (a \`filter<>\` given defaulting to \`f''\`), so an unsupplied value returns unfiltered rows. Because it bakes an always-on \`where:\` into the source, a non-neutral default (a date floor, say) applies to *every* read of the source. Defaults must be Malloy literals.
|
|
357468
357551
|
- **Givens don't auto-inject a \`where:\`.** Unlike \`#(filter)\`, you write the filter expression that references the given yourself (e.g. \`where: dimension ~ $given_name\`).
|
|
357469
357552
|
- **Every \`#(filter)\` use has a \`given:\` form.** Never add a \`#(filter)\` annotation to a model, not even for \`required\`, \`implicit\`, or a date/number range:
|
|
357470
357553
|
|
|
357471
357554
|
| You want | Write this | Not this |
|
|
357472
357555
|
|---|---|---|
|
|
357473
|
-
| An optional value or list filter | \`given: REGION :: filter<string> is f''\`
|
|
357474
|
-
| A date or number range | \`given: MIN_SALE :: filter<number> is f''\` (or \`filter<date>\`)
|
|
357556
|
+
| An optional value or list filter a reader picks | In the **report**, not the model: \`given: REGION :: filter<string> is f''\` there, bound on its tiles with \`+ { where: region ~ $REGION }\` (\`skill:malloy-reports\`). In the model only for one of the cases above. | \`#(filter) dimension=region type=in\` |
|
|
357557
|
+
| A date or number range a reader picks | In the **report** the same way: \`given: MIN_SALE :: filter<number> is f''\` (or \`filter<date>\`), bound with \`+ { where: sale_price ~ $MIN_SALE }\`. The caller sends a filter expression such as \`>= 50\`. | two \`#(filter)\` lines, \`greater_than\` and \`less_than\` |
|
|
357475
357558
|
| A value every query must supply (the primary key is only unique within it, or the table is too big to scan whole) | a given with **no default**, e.g. \`given: EVENT_DATE :: date\` and \`where: event_date = $EVENT_DATE\`. A query that omits it fails with "Given 'EVENT_DATE' has no value and no default". | \`#(filter) ... required\` |
|
|
357476
357559
|
| A row filter the system applies, not the caller | \`#(access_filter) org_id in $ORG_IDS\`, with \`ORG_IDS\` set by a trusted tier (see the trust caveat below) | \`#(filter) ... implicit\` |
|
|
357477
357560
|
|
|
@@ -357501,7 +357584,7 @@ Publisher formats the value from the dimension's type (\`'value'\`, bare \`true\
|
|
|
357501
357584
|
|
|
357502
357585
|
\`#(filter)\` is not a security boundary. A caller skips it with \`bypass_filters=true\` (REST) or \`bypassFilters: true\` (POST body), or by writing their own query text. Use givens with \`#(authorize)\` / \`#(access_filter)\` for access control.
|
|
357503
357586
|
|
|
357504
|
-
**To migrate** a source, replace each annotation using the table above, then delete it. \`type=greater_than\` and \`type=less_than\` are exclusive, so a plain comparison you convert one to is \`>\` or \`<\`, not \`>=\` or \`<=\`. \`docs/givens.md\` § "Coming from \`#(filter)\`" has a worked conversion.
|
|
357587
|
+
**To migrate** a source, replace each annotation using the table above, then delete it. An optional filter (\`type=in\`, \`like\`, \`equal\`, a range) moves to the reports that offer it, declared and bound there, and the source is left unfiltered; a \`required\` one stays in the model as a no-default given. \`type=greater_than\` and \`type=less_than\` are exclusive, so a plain comparison you convert one to is \`>\` or \`<\`, not \`>=\` or \`<=\`. \`docs/givens.md\` § "Coming from \`#(filter)\`" has a worked conversion.
|
|
357505
357588
|
|
|
357506
357589
|
## Access Control: \`#(authorize)\` and \`#(access_filter)\`
|
|
357507
357590
|
|
|
@@ -357932,7 +358015,7 @@ When you've been doing analysis, writing queries, building views, creating repor
|
|
|
357932
358015
|
|
|
357933
358016
|
## Step 1: IDENTIFY, what belongs in a model?
|
|
357934
358017
|
|
|
357935
|
-
Scan your analysis \`.malloy\` files and reports (any \`.malloy\` with an \`## artifact\` tag, wherever it sits, or an existing \`.malloynb\`). A report (a \`tiles=[…]\` layout
|
|
358018
|
+
Scan your analysis \`.malloy\` files and reports (any \`.malloy\` with an \`## artifact\` tag, wherever it sits, or an existing \`.malloynb\`). A report (a \`tiles=[…]\` layout, of either layout) is not a model file to restructure: lift its reusable definitions into a model and leave the report to import them. For each dimension, measure, join, or calculation, ask: **is this a reusable building block?**
|
|
357936
358019
|
|
|
357937
358020
|
A measure or dimension belongs in a model if it meets ANY of these criteria:
|
|
357938
358021
|
|
|
@@ -360351,7 +360434,7 @@ A flat layout at the package root is the simplest default, for models and report
|
|
|
360351
360434
|
|
|
360352
360435
|
Publishable contents:
|
|
360353
360436
|
- \`.malloy\` files - Semantic model definitions (base sources + joined sources)
|
|
360354
|
-
- Reports: \`.malloy\` files with an \`## artifact { layout=linear … }\` or \`## artifact { layout=grid … }\` tag, anywhere in the package (outside \`public/\`), written as tiles
|
|
360437
|
+
- Reports: \`.malloy\` files with an \`## artifact { layout=linear … }\` or \`## artifact { layout=grid … }\` tag, anywhere in the package (outside \`public/\`), written as tiles (see \`skill:malloy-reports\`). A linear tag with no tiles, the retired \`run:\`-cell form, is no report. The tag alone makes a file a report and sets its layout; the folder means nothing. An existing \`.malloynb\` is still served as a linear report; never write a new one.
|
|
360355
360438
|
- Data files (CSV/Parquet/XLSX) - Embedded data published with package
|
|
360356
360439
|
|
|
360357
360440
|
## Version Management
|
|
@@ -360720,7 +360803,7 @@ For anything not covered here, call \`search_malloy_docs\` with the topic (for e
|
|
|
360720
360803
|
{
|
|
360721
360804
|
name: "malloy-reports",
|
|
360722
360805
|
description: "Build or modify a Malloy Publisher report: a .malloy file with an ## artifact tag, written at the package root unless asked otherwise, laid out as a grid (a dashboard, scanned at a glance) or linear (a notebook or data story, read top to bottom), with filter controls rendered from givens and # drill click-through. Use when the user asks for a dashboard, a notebook, a report, a data story, a filterable view, or drill-through between views, and no code is wanted. Legacy .malloynb files are read, not authored.",
|
|
360723
|
-
body: "# Publisher Reports\n\n> A `.malloy` file with an `## artifact { layout=… tiles=[…] }` tag **is** a report. It imports the model, names the views to show, binds the filtering on those views, and says how to lay them out. Publisher discovers it at package load, renders the filter controls from the givens its tiles reference, offers `# drill` click-through, and serves it at `/<env>/<pkg>/<path>`, its package path without `.malloy`. No code, no build step.\n\nWhat other tools call a dashboard and a notebook are both reports here. The **layout** is the only difference:\n\n- **`layout=grid`**: tiles across a grid behind one filter row, scanned at a glance (a dashboard). Read `reference/grid.md` before you lay one out.\n- **`layout=linear`**: tiles and prose top to bottom, read in order (a notebook, a data story). Read `reference/linear.md` before you write one, and before you edit a report written as `run:` cells.\n\nEverything else (filters, text tiles, drill, the builder, the lint, the write path) is the same for both, and switching layout later is a one-property edit.\n\n## Where the file goes\n\n- **Write a new report at the package root**, as `<slug>.malloy`, unless the author asks for another location. No directory is required, and none is a convention: a report can live anywhere in the package except `public/`, and the root `index.malloy` is never a report. Do not create a `dashboards/` or `notebooks/` directory for it.\n- **Always write `layout=grid` or `layout=linear`** in the tag. A tag without one is read by a fallback rule, and a linear report that lists tiles without `layout=linear` is read as a grid. `kind=` is no longer read: a tag that sets it makes no report (`report-kind-removed`), so replace it with `layout=`.\n- **The package path is the report's identity.** `sales/q3.malloy` is the report `sales/q3`: its URL, its `GET …/reports/{path}` address, and its `# drill` target. Two reports may share a basename in different directories.\n- **Imports are relative to the report's own location.** At the root: `import { order_items } from \"storefront.malloy\"`. In a subdirectory: `\"../storefront.malloy\"`.\n- **An untagged `.malloy` file is an ordinary model**, wherever it lives. Shared definitions several reports import go in one.\n\n## When this is the right tool\n\n| The user wants | Use |\n| ---------------------------------------------------- | ------------------------------------------------------------ |\n| A recurring, at-a-glance view behind shared filters | this skill, `layout=grid` |\n| A narrative, with prose between the numbers | this skill, `layout=linear` |\n| A quick write-up of queries you already ran | `skill:malloy-analysis-report`, which writes a linear report |\n| Custom design, branding, or interactions beyond tags | an HTML data app |\n| The model itself: sources, measures, joins | `malloy-model` |\n\nInteractivity is not the axis: both layouts get filter controls, URL-addressable state, Apply batching, and `# drill`. Pick on the shape of the document: scanned at a glance is grid, read top to bottom is linear. When in doubt, linear.\n\n## Build sequence\n\nTool names below are bare (`get_context`); match each against the tools you actually have, since a host may prefix or rename them. A host names its compile and reload tools its own way. Where you have none, use the REST endpoint named beside the step.\n\n1. **READ THE MODEL FIRST.** Get the real source, view, dimension, and given names from the package: `get_context` if you have it, otherwise the REST model endpoint for `index.malloy` (it answers 404 for a file off the surface) or the `.malloy` files. Never guess a name. A guessed field in a query fails the whole package load, not just that one report; a guessed tile or suggest source is quieter, and only shows up in the package warnings. If the package root holds an `index.malloy` (every scaffolded package does), a tile reads only the sources that file exports.\n2. **PICK THE LAYOUT AND THE TILES.** Which views, in what order, and on a grid how wide each sits. A query tile is a `view:` you declare in the report, named as `\"source -> view\"`.\n3. **DECLARE THE GIVENS** the report will filter by, in the report file itself, with their control tags (see \"Filter controls\"). The builder edits the report file and nothing else, so a filter it can add, change or remove is a declaration in that file. A given the model already declares and reads is imported by name, never declared again (see \"Givens that stay in the model\").\n4. **COMPOSE THE FILE** at its path (the package root unless asked otherwise), following the template below, but do not save it yet. Name the sources you need in the import. Each tile binds its controls with a refinement, `view: t is v + { where: category ~ $CATEGORY }`, one clause per given it answers to; a `filter<...>` binds with `~`, a plain `date` or `number` given is a value and binds with `>=`, `<=` or `=`. Only the givens some tile references become controls. Then import every source or query any referenced given names in a `suggest`; **a `suggest` naming a `query=` needs that query's own source imported as well**, because an import is not transitive.\n5. **COMPILE IT** with your compile tool (`POST …/models/<path>/compile` over REST) at the path the file will have, with **`\"scope\": \"file\"`**: a report opens with an `import`, which the default `append` scope refuses, and an existing file compiled at `append` collides with itself. **`\"scope\": \"file\"` does not check tiles, drills or suggest queries.** To see those before you save, compile the same text at `\"scope\": \"package\"` with `modelPath` set to the report's path: it runs the lint step 6 reads and returns its findings with code `dashboard-lint` (or `render-tag`). Editing an untagged model several reports import also wants `\"scope\": \"package\"`, which recompiles every file as saved.\n6. **SAVE IT, RELOAD, AND READ THE MANIFEST AND THE WARNINGS.** Save by writing the file, or with `PUT …/models/<path>` over REST (omit `expectedHash` to create; it creates at any new path and replaces only a file the package already serves as a report). Then your reload tool, or `GET …/packages/<pkg>?reload=true`. A 424 means the package did not load and your edit is not live. **The `warnings` key is absent when there are none.** Then read `GET …/packages/<pkg>/reports/<path>`: its `givens` are exactly the controls that will render, and its `layout` is the layout Publisher read. See \"Read the lint\".\n7. **OPEN IT AND LOOK.** Not optional; see \"What done means\".\n\n## The form\n\n```malloy\n##! experimental.givens\n##\" One line saying what this report is for.\n##| artifact { layout=grid title=\"Storefront overview\"\n tiles=[\n intro { kind=text colspan=12 },\n \"overview -> kpis\",\n \"overview -> revenue_trend\",\n \"overview -> revenue_by_state\"\n ]\n} dashboard { columns=12 }\n|##\nimport { order_items, products } from \"storefront.malloy\"\n\n# label=\"Category\" control=select suggest { source=products dimension=category }\ngiven: CATEGORY :: filter<string> is f''\n# label=\"Ordered since\"\ngiven: SINCE :: date is @2023-01-01\n\n##|(markdown) intro\nRevenue and margin for the selected category.\n|##\n\nsource: overview is order_items extend {\n # colspan=12\n # label=\"Key figures\"\n # big_value\n view: kpis is key_figures + { where: category ~ $CATEGORY, where: created_at >= $SINCE }\n\n # colspan=8\n # break\n # label=\"Revenue by month\"\n view: revenue_trend is sales_by_month + { where: category ~ $CATEGORY, where: created_at >= $SINCE }\n\n # colspan=4\n # label=\"Revenue by state\"\n view: revenue_by_state is sales_by_state + { where: category ~ $CATEGORY, where: created_at >= $SINCE }\n}\n```\n\nThe same file with `layout=linear` and no `dashboard { … }` or `colspan` is a linear report.\n\n- **The tag is model-level**, one line (`## artifact { … }`) or a `##|` … `|##` block with the same text inside, the form to use once the list is long: one tile per line, `}` on its own line, `|##` closing at the opener's column. A one-line `##` tag must stay on one line: wrapping it is a compile error, or worse, compiles clean and quietly stops being a report.\n- **The header** above the tag holds only `##!` flags, `//` comments and the unnamed `\"` notes that are the report's description. A statement or a `#` tag above `## artifact` is an error.\n- **Quote every query entry.** `\"overview -> kpis\"` is a string; unquoted, the tag does not parse (`notebook-artifact-unparsed`). A bare quoted name (`\"top_products\"`) names a model-level `query:` in the file.\n- **A query tile is a thin `view:` on an extension the report declares** (`source: overview is order_items extend { … }`): the modelled view keeps its chart tag, the wrapper carries the tile's `# label`, its width on a grid, and its binding.\n- **A text tile is a `##|(markdown) name` block** listed as `name { kind=text }`. The name is one bare word on the opener line, the body starts on the next line (a heading goes inside the block), and `|##` closes it at the opener's column. A bare `intro` without `{ kind=text }` is the query-tile form for a `query:`, so the block is not shown. On a grid the entry also takes `colspan` and `break`, and nothing else.\n- **File order:** header, imports and givens, the prose blocks in tile order, then the extension that defines the tile views. That is the order the builder writes.\n- **A `run:` in a report that lists `tiles` is never shown** (`notebook-layout-run`). Define a view, list it, delete the `run:`.\n- **A tile expression is a string, so the compiler never checks it.** Rename a view and the file still compiles; the tile fails at package load, where the lint names it.\n- **Chart tags go on the view** (`# line_chart`, `# bar_chart`, `# big_value`, `# label=\"…\"`). `skill:malloy-charts` covers choosing them.\n\n## Filter controls\n\nControls come from the `given:` declarations the tiles reference. The tags on the declaration are the control contract:\n\n```malloy\n##! experimental.givens\n\n# label=\"Category\" control=select suggest { source=products dimension=category }\ngiven: CATEGORY :: filter<string> is f''\n\n# label=\"Brand\" control=multiselect suggest { query=brand_suggest dimension=brand }\ngiven: BRAND :: filter<string> is f''\n\n# label=\"Minimum line total\" range_min=0 range_max=250\ngiven: MIN_SALE :: filter<number> is f''\n\n# label=\"Ordered since\"\ngiven: SINCE :: date is @2023-01-01\n```\n\n`control=select`/`multiselect` with a `suggest` renders a picker filled from the data; `range_min`/`range_max` on a `filter<number>` renders a two-handled range slider; a `filter<date>` or `filter<timestamp>` renders a time-range control with preset windows and a custom day range; a bare `date` or `timestamp` renders a date picker; a `filter<string>` with no tag renders a text box taking filter syntax. Which controls appear is per report, decided by which givens its tiles reference.\n\n- `#(description=\"…\")` renders as helper text under the control and draws a cosmetic \"not a well-formed route\" compile diagnostic for a multi-word value; `# description=\"…\"` publishes to the API but the UI does not render it.\n- `dimension=` can name a field of a directly joined source, quoted: `suggest { source=sales dimension=\"products.department\" }`. On the `query=` form, `dimension` names a column of that query's output; match it to the query's `group_by`.\n- **A suggest's source or query has to resolve in the report file**, so import it there. Getting it wrong does not error: the control still looks like a picker and says \"Could not load the options for this control\"; the package warnings name it.\n- Two options on the artifact tag, either layout: `autorun=false` batches control changes behind an Apply button; `givens { CATEGORY=f'Outerwear' }` sets starting values (a URL parameter wins). A file-level `## autorun=false` does nothing on a `.malloy` report.\n\n### Binding, and givens that stay in the model\n\n**Binding is per declaration, not per name.** A report declaring its own `CATEGORY` over a source whose model-level `where:` reads the model's `CATEGORY` compiles, shows the control, and filters nothing. So bind on the tiles, with `+ { where: … }`. The other design, model-level scoping, still works: put a scoped source in an untagged model that imports the givens it reads, and import that model and those givens into the report. Do not mix the two on one given.\n\nA given stays in the model, declared once there, when a model source, view or measure, an `#(authorize)` or `#(access_filter)` gate, or an HTML data app reads it. The report imports it by name (`import { CATEGORY } from \"givens.malloy\"`) and never re-declares it:\n\n- **Import a name and also declare it: a compile error.** Drop the local declaration.\n- **Declare a name the model already reads, without importing it: no error at all.** The control renders and moves, and the model's own `where:` or gate never sees the value.\n\nA given has to be in the report file's own scope to be bindable: declared there or imported. Never add a `#(filter)` annotation: it is deprecated, a report renders no control for it, and every use has a `given:` form (`malloy-model` covers the migration). `malloy-model` and `docs/givens.md` cover givens themselves.\n\n## Drill\n\n`# drill` goes on a model **dimension**, never on a report:\n\n```malloy\n# drill { to=[\"category\", \"self\"] given=CATEGORY }\ndimension: category is products.category\n\n# drill { to=\"regions/west\" given=REGION }\ndimension: region is regions.region\n```\n\n- **`to=<path>`** navigates to a report, of either layout, by its package path without `.malloy`, read from the package root: `to=category` is `category.malloy` at the root, `to=\"regions/west\"` is `regions/west.malloy`. Quote a path with a `/`. **Always write the path from the package root**: a bare name is a root file, never a report of that name elsewhere.\n- **`to=self`** filters in place; two or more destinations pop a menu.\n- **Always write `given=`.** Without it the given is the dimension name verbatim, so `dimension: category` seeds `category`, not `CATEGORY`. `to=self` survives that (it folds case); `to=<path>` does not, and lands on an unfiltered page with nothing erroring.\n- **The destination needs a control for the given**, declared as `filter<T>`. No lint checks that half, so click it and look.\n- **Only table cells are marked drillable.** A report meant to be drilled wants at least one untagged (table) tile, grouped by the tagged dimension. A column whose rendered header another, non-drillable tile also shows loses its marking: give the two different `# label=`s.\n\n## Read the lint\n\nPackage warnings after a reload are the report's test suite. Fix all of them, and read the text rather than the severity or the count. **\"Dashboard lint stopped early, so this list is incomplete\"** means the rest of the list is partial.\n\n| Finding | Fix |\n| ----------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |\n| `# drill … targets \"x\", which is not a report in this package` | A dead click. Write the target's path |\n| `to=self, but no model in this package declares a given \"X\"` | The clicked value has nowhere to go. Declare the given, or fix `given=` |\n| `given \"X\" suggests options from source \"y\", which this file does not define` | Import `y` into the report |\n| `filters by given \"X\", which this file does not import` | No control is shown for it. Import the given |\n| A tile that does not resolve to a real view | Fix the view name, or declare the view |\n| `notebook-artifact-unparsed` | The tag does not parse, usually an unquoted `source -> view` entry |\n| `notebook-layout-run` | A `run:` beside `tiles`. Make it a view, list it, delete the `run:` |\n| `notebook-tile-layout-ignored` | `colspan` or `break` on a linear report. Remove them, or switch to `layout=grid` |\n| `report-kind-removed` | The tag sets `kind=`, which is no longer read, so the file is no report. Write the `layout=` the finding gives |\n| `report-layout-implicit` | A tag with no tiles and no `layout=`. Add `layout=` |\n| `report-on-surface` | A model `index.malloy` imports (or `explores` lists) is tagged, so its sources left the surface. Untag it, or move the report out |\n| `index-is-not-a-report` | The root `index.malloy` carries a tag. Remove it; put the report in its own file |\n| `report-name-ambiguous` | Two grid reports share a file name, so the deprecated by-name dashboards route answers 409 for it. Rename one of the files |\n| `Tile … reads <source>, which index.malloy doesn't export` | Add the source to the `export { ... }` in `index.malloy`. Never add an `explores` to `publisher.json` |\n| A grid's `columns`, `colspan`, or `dashboard_columns=` findings | `reference/grid.md` |\n| A statement or tag above the artifact tag; prose the reader cannot place | `reference/linear.md`, the cell rules |\n\n**Read the status the reload itself returns, not the listing.** One report that fails to compile fails the whole package load (424), and a package already serving keeps its previous version, so the listing still looks healthy. `GET /api/v0/status` still knows: a package serving an older model than its files appears in `loadErrors` with `stale: true`. If the reload is 200 and your report is not listed, discovery skipped it: usually a missing or misspelled artifact tag, or a file under `public/`.\n\n**A clean reload is not proof the tags are right.** The parse warning is syntax only and carries no position. That is why the last step is opening the page.\n\n## Template\n\n```malloy\n##! experimental.givens\n##\" [One-line description of the report.]\n##| artifact { layout=linear title=\"[Title]\"\n tiles=[\n intro { kind=text },\n \"main_source_tiles -> broad_tile\",\n \"main_source_tiles -> drill_tile\"\n ]\n}\n|##\nimport { main_source } from \"model.malloy\"\n\n##|(markdown) intro\n[Framing question: what are we trying to understand?]\n|##\n\nsource: main_source_tiles is main_source extend {\n view: broad_tile is [broad view]\n view: drill_tile is [drill view]\n}\n```\n\nFor a grid, write `layout=grid`, add `dashboard { columns=12 }` after the tag's closing `}`, and give every tile view a `# colspan` (`reference/grid.md`).\n\n## Editing in the Console\n\nA person can open any report in the Console's builder (**Edit** on the report page; **New report** on the package page writes `<slug>.malloy` at the package root). The builder splices the file rather than regenerating it, so comments and anything it does not model survive; its layout switch rewrites `layout=` and nothing else. A report written as `run:` cells opens converted to tiles, and the first Save asks before it rewrites the file (`reference/linear.md`). A save whose text declares a real `#(authorize)` or `#(access_filter)` gate outside prose is refused with a 400: gates live in a model file the report imports.\n\n## What \"done\" means\n\n- The file is at the package root (or where the author asked), and its tag says `layout=`.\n- Every source, view, and field name came from the model you read in step 1.\n- The reload returned **200**, not 424, with **zero** report warnings, and your report is in `GET …/reports`.\n- You opened the page and every tile shows real numbers: not stuck loading, not an error, not an empty state you did not intend.\n- Each control renders as the widget you intended, and changing one changes the numbers.\n- If you added a `# drill`, its `to=` is a path, and you clicked it and landed where you meant to, with the given seeded.\n- On a grid: every tile carries a colspan, each row sums to `columns`, rows end flush, nothing is clipped, and no legend or card label ends in `…`.\n\n## Reference\n\n- `reference/grid.md`: the grid recipe, its traps, and one query as the whole page.\n- `reference/linear.md`: linear reports, `run:` cells, legacy `.malloynb`, style, and common mistakes.\n- `docs/reports.md`: the full guide this skill condenses.\n- `docs/givens.md`: the givens the controls are generated from.\n\n## Reference files over MCP\n\nThis skill's `reference/` files are served as separate prompts, one per file, fetched only when you ask for them. Where the text above says to read `reference/<name>.md`, get the prompt named `malloy-reports/<name>` instead.\n\nAvailable: grid, linear."
|
|
360806
|
+
body: "# Publisher Reports\n\n> A `.malloy` file with an `## artifact { layout=… tiles=[…] }` tag **is** a report. It imports the model, names the views to show, binds the filtering on those views, and says how to lay them out. Publisher discovers it at package load, renders the filter controls from the givens its tiles reference, offers `# drill` click-through, and serves it at `/<env>/<pkg>/<path>`, its package path without `.malloy`. No code, no build step.\n\nWhat other tools call a dashboard and a notebook are both reports here. The **layout** is the only difference:\n\n- **`layout=grid`**: tiles across a grid behind one filter row, scanned at a glance (a dashboard). Read `reference/grid.md` before you lay one out.\n- **`layout=linear`**: tiles and prose top to bottom, read in order (a notebook, a data story). Read `reference/linear.md` before you write one.\n\nEverything else (filters, text tiles, drill, the builder, the lint, the write path) is the same for both, and switching layout later is a one-property edit.\n\n## Where the file goes\n\n- **Write a new report at the package root**, as `<slug>.malloy`, unless the author asks for another location. No directory is required, and none is a convention: a report can live anywhere in the package except `public/`, and the root `index.malloy` is never a report. Do not create a `dashboards/` or `notebooks/` directory for it.\n- **Always write `layout=grid` or `layout=linear`** in the tag. A tag without one is read by a fallback rule, and a linear report that lists tiles without `layout=linear` is read as a grid. `kind=` is no longer read: a tag that sets it makes no report (`report-kind-removed`), so replace it with `layout=`.\n- **The package path is the report's identity.** `sales/q3.malloy` is the report `sales/q3`: its URL, its `GET …/reports/{path}` address, and its `# drill` target. Two reports may share a basename in different directories.\n- **Imports are relative to the report's own location.** At the root: `import { order_items } from \"storefront.malloy\"`. In a subdirectory: `\"../storefront.malloy\"`.\n- **An untagged `.malloy` file is an ordinary model**, wherever it lives. Shared definitions several reports import go in one.\n\n## When this is the right tool\n\n| The user wants | Use |\n| ---------------------------------------------------- | ------------------------------------------------------------ |\n| A recurring, at-a-glance view behind shared filters | this skill, `layout=grid` |\n| A narrative, with prose between the numbers | this skill, `layout=linear` |\n| A quick write-up of queries you already ran | `skill:malloy-analysis-report`, which writes a linear report |\n| Custom design, branding, or interactions beyond tags | an HTML data app |\n| The model itself: sources, measures, joins | `malloy-model` |\n\nInteractivity is not the axis: both layouts get filter controls, URL-addressable state, Apply batching, and `# drill`. Pick on the shape of the document: scanned at a glance is grid, read top to bottom is linear. When in doubt, linear.\n\n## Build sequence\n\nTool names below are bare (`get_context`); match each against the tools you actually have, since a host may prefix or rename them. A host names its compile and reload tools its own way. Where you have none, use the REST endpoint named beside the step.\n\n1. **READ THE MODEL FIRST.** Get the real source, view, dimension, and given names from the package: `get_context` if you have it, otherwise the REST model endpoint for `index.malloy` (it answers 404 for a file off the surface) or the `.malloy` files. Never guess a name. A guessed field in a query fails the whole package load, not just that one report; a guessed tile or suggest source is quieter, and only shows up in the package warnings. If the package root holds an `index.malloy` (every scaffolded package does), a tile reads only the sources that file exports.\n2. **PICK THE LAYOUT AND THE TILES.** Which views, in what order, and on a grid how wide each sits. A query tile is a `view:` you declare in the report, named as `\"source -> view\"`.\n3. **DECLARE THE GIVENS** the report will filter by, in the report file itself, with their control tags (see \"Filter controls\"). A report holds its own filters: the builder edits the report file and nothing else, so a filter it can add, change or remove is a declaration in that file. A given the model already declares and reads is imported by name, never declared again; if it is only a reader's filter, move it into the report instead (see \"Givens that stay in the model\").\n4. **COMPOSE THE FILE** at its path (the package root unless asked otherwise), following the template below, but do not save it yet. Name the sources you need in the import. Each tile binds its controls with a refinement, `view: t is v + { where: category ~ $CATEGORY }`, one clause per given it answers to; a `filter<...>` binds with `~`, a plain `date` or `number` given is a value and binds with `>=`, `<=` or `=`. Only the givens some tile references become controls. Then import every source or query any referenced given names in a `suggest`; **a `suggest` naming a `query=` needs that query's own source imported as well**, because an import is not transitive.\n5. **COMPILE IT** with your compile tool (`POST …/models/<path>/compile` over REST) at the path the file will have, with **`\"scope\": \"file\"`**: a report opens with an `import`, which the default `append` scope refuses, and an existing file compiled at `append` collides with itself. **`\"scope\": \"file\"` does not check tiles, drills or suggest queries.** To see those before you save, compile the same text at `\"scope\": \"package\"` with `modelPath` set to the report's path: it runs the lint step 6 reads and returns its findings with code `dashboard-lint` (or `render-tag`). Editing an untagged model several reports import also wants `\"scope\": \"package\"`, which recompiles every file as saved.\n6. **SAVE IT, RELOAD, AND READ THE MANIFEST AND THE WARNINGS.** Save by writing the file, or with `PUT …/models/<path>` over REST (omit `expectedHash` to create; it creates at any new path and replaces only a file the package already serves as a report). Then your reload tool, or `GET …/packages/<pkg>?reload=true`. A 424 means the package did not load and your edit is not live. **The `warnings` key is absent when there are none.** Then read `GET …/packages/<pkg>/reports/<path>`: its `givens` are exactly the controls that will render, and its `layout` is the layout Publisher read. See \"Read the lint\".\n7. **OPEN IT AND LOOK.** Not optional; see \"What done means\".\n\n## The form\n\n```malloy\n##! experimental.givens\n##\" One line saying what this report is for.\n##| artifact { layout=grid title=\"Storefront overview\"\n tiles=[\n intro { kind=text colspan=12 },\n \"overview -> kpis\",\n \"overview -> revenue_trend\",\n \"overview -> revenue_by_state\"\n ]\n} dashboard { columns=12 }\n|##\nimport { order_items, products } from \"storefront.malloy\"\n\n# label=\"Category\" control=select suggest { source=products dimension=category }\ngiven: CATEGORY :: filter<string> is f''\n# label=\"Ordered since\"\ngiven: SINCE :: date is @2023-01-01\n\n##|(markdown) intro\nRevenue and margin for the selected category.\n|##\n\nsource: overview is order_items extend {\n # colspan=12\n # label=\"Key figures\"\n # big_value\n view: kpis is key_figures + { where: category ~ $CATEGORY, where: created_at >= $SINCE }\n\n # colspan=8\n # break\n # label=\"Revenue by month\"\n view: revenue_trend is sales_by_month + { where: category ~ $CATEGORY, where: created_at >= $SINCE }\n\n # colspan=4\n # label=\"Revenue by state\"\n view: revenue_by_state is sales_by_state + { where: category ~ $CATEGORY, where: created_at >= $SINCE }\n}\n```\n\nThe same file with `layout=linear` and no `dashboard { … }` or `colspan` is a linear report.\n\n- **The tag is model-level**, one line (`## artifact { … }`) or a `##|` … `|##` block with the same text inside, the form to use once the list is long: one tile per line, `}` on its own line, `|##` closing at the opener's column. A one-line `##` tag must stay on one line: wrapping it is a compile error, or worse, compiles clean and quietly stops being a report.\n- **The header** above the tag holds only `##!` flags, `//` comments and the unnamed `\"` notes that are the report's description. Keep statements and `#` tags below `## artifact`: nothing refuses one above it, but the header is where readers and the builder look.\n- **Quote every query entry.** `\"overview -> kpis\"` is a string; unquoted, the tag does not parse (`notebook-artifact-unparsed`). A bare quoted name (`\"top_products\"`) names a model-level `query:` in the file.\n- **A query tile is a thin `view:` on an extension the report declares** (`source: overview is order_items extend { … }`): the modelled view keeps its chart tag, the wrapper carries the tile's `# label`, its width on a grid, and its binding.\n- **A text tile is a `##|(markdown) name` block** listed as `name { kind=text }`. The name is one bare word on the opener line, the body starts on the next line (a heading goes inside the block), and `|##` closes it at the opener's column. A bare `intro` without `{ kind=text }` is the query-tile form for a `query:`, so the block is not shown. On a grid the entry also takes `colspan` and `break`, and nothing else.\n- **File order:** header, imports and givens, the prose blocks in tile order, then the extension that defines the tile views. That is the order the builder writes.\n- **A `run:` in a report that lists `tiles` is never shown** (`notebook-layout-run`). Define a view, list it, delete the `run:`.\n- **A tile expression is a string, so the compiler never checks it.** Rename a view and the file still compiles; the tile fails at package load, where the lint names it.\n- **Chart tags go on the view** (`# line_chart`, `# bar_chart`, `# big_value`, `# label=\"…\"`). `skill:malloy-charts` covers choosing them.\n\n## Filter controls\n\nControls come from the `given:` declarations the tiles reference. The tags on the declaration are the control contract:\n\n```malloy\n##! experimental.givens\n\n# label=\"Category\" control=select suggest { source=products dimension=category }\ngiven: CATEGORY :: filter<string> is f''\n\n# label=\"Brand\" control=multiselect suggest { query=brand_suggest dimension=brand }\ngiven: BRAND :: filter<string> is f''\n\n# label=\"Minimum line total\" range_min=0 range_max=250\ngiven: MIN_SALE :: filter<number> is f''\n\n# label=\"Ordered since\"\ngiven: SINCE :: date is @2023-01-01\n```\n\n`control=select`/`multiselect` with a `suggest` renders a picker filled from the data; `range_min`/`range_max` on a `filter<number>` renders a two-handled range slider; a `filter<date>` or `filter<timestamp>` renders a time-range control with preset windows and a custom day range; a bare `date` or `timestamp` renders a date picker; a `filter<string>` with no tag renders a text box taking filter syntax. Which controls appear is per report, decided by which givens its tiles reference.\n\n- `#(description=\"…\")` renders as helper text under the control and draws a cosmetic \"not a well-formed route\" compile diagnostic for a multi-word value; `# description=\"…\"` publishes to the API but the UI does not render it.\n- `dimension=` can name a field of a directly joined source, quoted: `suggest { source=sales dimension=\"products.department\" }`. On the `query=` form, `dimension` names a column of that query's output; match it to the query's `group_by`.\n- **A suggest's source or query has to resolve in the report file**, so import it there. Getting it wrong does not error: the control still looks like a picker and says \"Could not load the options for this control\"; the package warnings name it.\n- Two options on the artifact tag, either layout: `autorun=false` batches control changes behind an Apply button; `givens { CATEGORY=f'Outerwear' }` sets starting values (a URL parameter wins). A file-level `## autorun=false` does nothing on a `.malloy` report.\n\n### Binding, and givens that stay in the model\n\n**Binding is per declaration, not per name.** A report declaring its own `CATEGORY` over a source whose model-level `where:` reads the model's `CATEGORY` compiles, shows the control, and filters nothing. So bind on the tiles, with `+ { where: … }`. The other design, model-level scoping, still works: put a scoped source in an untagged model that imports the givens it reads, and import that model and those givens into the report. Do not mix the two on one given.\n\nA given stays in the model, declared once there, when a model source, view or measure, an `#(authorize)` or `#(access_filter)` gate, or an HTML data app reads it. The report imports it by name (`import { CATEGORY } from \"givens.malloy\"`) and never re-declares it:\n\n- **Import a name and also declare it: a compile error.** Drop the local declaration.\n- **Declare a name the model already reads, without importing it: no error at all.** The control renders and moves, and the model's own `where:` or gate never sees the value.\n\n**A model that already scopes a source by an optional filter given** (`where: Manufacturer ~ $manufacturer_filter` in the model) needs a decision:\n\n- **It is a reader's filter and you may change the model: move it.** Delete the given and its `where:` clause from the model, declare it in the report with its control tags, and bind it on each tile that should answer to it. A reader's filter is anything a person picks on the page; a given stays in the model only for the reasons `malloy-model` lists (a gate, a value every query must supply, a parameter a field is defined with, scoping meant for every consumer).\n- **The model can't change, or the given is semantic or governance: import it** as above. Say so plainly: the filter shows in the reader and in the builder, and can be set in both, but the builder cannot remove or reconfigure it. It is the model's.\n\nBefore, in the model:\n\n```malloy\n##! experimental.givens\ngiven:\n manufacturer_filter :: filter<string> is f''\n subject_filter :: filter<string> is f''\n major_recall_filter :: filter<boolean> is f''\n recall_date_filter :: filter<date> is f''\n\nsource: recalls is duckdb.table('data/auto_recalls.csv') extend {\n where:\n Manufacturer ~ $manufacturer_filter,\n Subject ~ $subject_filter,\n `Major Recall` ~ $major_recall_filter,\n `Report Received Date` ~ $recall_date_filter\n dimension: `Major Recall` is ifnull(`Potentially Affected`, 0) > 100000\n}\n```\n\nAfter: the model declares no givens and `recalls` has no `where:`; the report declares the four and binds each tile:\n\n```malloy\n##! experimental.givens\n##| artifact { layout=grid title=\"Recalls\"\n tiles=[\"recalls_tiles -> recalls_by_year\", \"recalls_tiles -> recalls_by_manufacturer\"]\n} dashboard { columns=12 }\n|##\nimport { recalls } from \"auto_recalls.malloy\"\n\n# label=\"Manufacturer\" control=multiselect suggest { source=recalls dimension=Manufacturer }\ngiven: manufacturer_filter :: filter<string> is f''\n# label=\"Subject\"\ngiven: subject_filter :: filter<string> is f''\n# label=\"Major recalls only\"\ngiven: major_recall_filter :: filter<boolean> is f''\n# label=\"Filed\"\ngiven: recall_date_filter :: filter<date> is f''\n\nsource: recalls_tiles is recalls extend {\n # colspan=6\n view: recalls_by_year is by_year + {\n where:\n Manufacturer ~ $manufacturer_filter,\n Subject ~ $subject_filter,\n `Major Recall` ~ $major_recall_filter,\n `Report Received Date` ~ $recall_date_filter\n }\n # colspan=6\n view: recalls_by_manufacturer is by_manufacturer + {\n where:\n Subject ~ $subject_filter,\n `Major Recall` ~ $major_recall_filter,\n `Report Received Date` ~ $recall_date_filter\n }\n}\n```\n\nA tile view takes a name of its own: `view: by_year is by_year + { … }` is \"Cannot redefine 'by_year'\". Each tile binds only the givens it should answer to: `recalls_by_manufacturer` leaves the manufacturer filter off, since it is the breakdown by manufacturer. Every given here is a `filter<…>`, so each binds with `~`; a plain `date` or `number` given binds with `>=`, `<=` or `=` (step 4).\n\nA given has to be in the report file's own scope to be bindable: declared there or imported. Never add a `#(filter)` annotation: it is deprecated, a report renders no control for it, and every use has a `given:` form (`malloy-model` covers the migration). `malloy-model` and `docs/givens.md` cover givens themselves.\n\n## Drill\n\n`# drill` goes on a model **dimension**, never on a report:\n\n```malloy\n# drill { to=[\"category\", \"self\"] given=CATEGORY }\ndimension: category is products.category\n\n# drill { to=\"regions/west\" given=REGION }\ndimension: region is regions.region\n```\n\n- **`to=<path>`** navigates to a report, of either layout, by its package path without `.malloy`, read from the package root: `to=category` is `category.malloy` at the root, `to=\"regions/west\"` is `regions/west.malloy`. Quote a path with a `/`. **Always write the path from the package root**: a bare name is a root file, never a report of that name elsewhere.\n- **`to=self`** filters in place; two or more destinations pop a menu.\n- **Always write `given=`.** Without it the given is the dimension name verbatim, so `dimension: category` seeds `category`, not `CATEGORY`. `to=self` survives that (it folds case); `to=<path>` does not, and lands on an unfiltered page with nothing erroring.\n- **The destination needs a control for the given**, declared as `filter<T>`. No lint checks that half, so click it and look.\n- **Only table cells are marked drillable.** A report meant to be drilled wants at least one untagged (table) tile, grouped by the tagged dimension. A column whose rendered header another, non-drillable tile also shows loses its marking: give the two different `# label=`s.\n\n## Read the lint\n\nPackage warnings after a reload are the report's test suite. Fix all of them, and read the text rather than the severity or the count. **\"Dashboard lint stopped early, so this list is incomplete\"** means the rest of the list is partial.\n\n| Finding | Fix |\n| ------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |\n| `# drill … targets \"x\", which is not a report in this package` | A dead click. Write the target's path |\n| `to=self, but no model in this package declares a given \"X\"` | The clicked value has nowhere to go. Declare the given, or fix `given=` |\n| `given \"X\" suggests options from source \"y\", which this file does not define` | Import `y` into the report |\n| `filters by given \"X\", which this file does not import` | No control is shown for it. Import the given |\n| A tile that does not resolve to a real view | Fix the view name, or declare the view |\n| `notebook-artifact-unparsed` | The tag does not parse, usually an unquoted `source -> view` entry |\n| `notebook-layout-run` | A `run:` beside `tiles`. Make it a view, list it, delete the `run:` |\n| `notebook-tile-layout-ignored` | `colspan` or `break` on a linear report. Remove them, or switch to `layout=grid` |\n| `report-kind-removed` | The tag sets `kind=`, which is no longer read, so the file is no report. Write the `layout=` the finding gives |\n| `report-cells-removed` | A linear tag with no `tiles`, the retired cell format, so the file is no report. List its tiles (`reference/linear.md`) |\n| `report-on-surface` | A model `index.malloy` imports (or `explores` lists) is tagged, so its sources left the surface. Untag it, or move the report out |\n| `index-is-not-a-report` | The root `index.malloy` carries a tag. Remove it; put the report in its own file |\n| `report-name-ambiguous` | Two grid reports share a file name, so the deprecated by-name dashboards route answers 409 for it. Rename one of the files |\n| `Tile … reads <source>, which index.malloy doesn't export` | Add the source to the `export { ... }` in `index.malloy`. Never add an `explores` to `publisher.json` |\n| A grid's `columns`, `colspan`, or `dashboard_columns=` findings | `reference/grid.md` |\n| Prose the reader cannot place (`notebook-markdown-attached-nowhere`, `notebook-markdown-block-unnamed`) | `reference/linear.md` |\n\n**Read the status the reload itself returns, not the listing.** One report that fails to compile fails the whole package load (424), and a package already serving keeps its previous version, so the listing still looks healthy. `GET /api/v0/status` still knows: a package serving an older model than its files appears in `loadErrors` with `stale: true`. If the reload is 200 and your report is not listed, discovery skipped it: usually a missing or misspelled artifact tag, or a file under `public/`.\n\n**A clean reload is not proof the tags are right.** The parse warning is syntax only and carries no position. That is why the last step is opening the page.\n\n## Template\n\n```malloy\n##! experimental.givens\n##\" [One-line description of the report.]\n##| artifact { layout=linear title=\"[Title]\"\n tiles=[\n intro { kind=text },\n \"main_source_tiles -> broad_tile\",\n \"main_source_tiles -> drill_tile\"\n ]\n}\n|##\nimport { main_source } from \"model.malloy\"\n\n##|(markdown) intro\n[Framing question: what are we trying to understand?]\n|##\n\nsource: main_source_tiles is main_source extend {\n view: broad_tile is [broad view]\n view: drill_tile is [drill view]\n}\n```\n\nFor a grid, write `layout=grid`, add `dashboard { columns=12 }` after the tag's closing `}`, and give every tile view a `# colspan` (`reference/grid.md`).\n\n## Editing in the Console\n\nA person can open any report in the Console's builder (**Edit** on the report page; **+ Report** on the package page writes `<slug>.malloy` at the package root). The builder splices the file rather than regenerating it, so comments and anything it does not model survive; its layout switch rewrites `layout=` and nothing else. A file written as `run:` cells, the retired linear form, is no report and does not open (`reference/linear.md`). A save whose text declares a real `#(authorize)` or `#(access_filter)` gate outside prose is refused with a 400: gates live in a model file the report imports.\n\n## What \"done\" means\n\n- The file is at the package root (or where the author asked), and its tag says `layout=`.\n- Every source, view, and field name came from the model you read in step 1.\n- The reload returned **200**, not 424, with **zero** report warnings, and your report is in `GET …/reports`.\n- You opened the page and every tile shows real numbers: not stuck loading, not an error, not an empty state you did not intend.\n- Each control renders as the widget you intended, and changing one changes the numbers.\n- If you added a `# drill`, its `to=` is a path, and you clicked it and landed where you meant to, with the given seeded.\n- On a grid: every tile carries a colspan, each row sums to `columns`, rows end flush, nothing is clipped, and no legend or card label ends in `…`.\n\n## Reference\n\n- `reference/grid.md`: the grid recipe, its traps, and one query as the whole page.\n- `reference/linear.md`: linear reports, rewriting a retired `run:`-cell file, legacy `.malloynb`, style, and common mistakes.\n- `docs/reports.md`: the full guide this skill condenses.\n- `docs/givens.md`: the givens the controls are generated from.\n\n## Reference files over MCP\n\nThis skill's `reference/` files are served as separate prompts, one per file, fetched only when you ask for them. Where the text above says to read `reference/<name>.md`, get the prompt named `malloy-reports/<name>` instead.\n\nAvailable: grid, linear."
|
|
360724
360807
|
},
|
|
360725
360808
|
{
|
|
360726
360809
|
name: "malloy-reports/grid",
|
|
@@ -360772,94 +360855,21 @@ source: category_tiles is order_items extend {
|
|
|
360772
360855
|
|
|
360773
360856
|
- **\`layout=linear\` is required** when the tag lists tiles; without it the file is read as a grid.
|
|
360774
360857
|
- \`dashboard { columns }\` has no effect, and a \`colspan\` or \`break\` on a tile entry is ignored with a warning (\`notebook-tile-layout-ignored\`).
|
|
360775
|
-
- **Tiles run through the model query endpoint**,
|
|
360776
|
-
|
|
360777
|
-
## Reports written as \`run:\` cells (the older form)
|
|
360778
|
-
|
|
360779
|
-
A linear report can also be a file of \`run:\` statements with \`(markdown)\` notes between them. Publisher still reads and serves it, and a person saving it in the Console converts it to tiles. Write new reports as tiles; maintain a cell report in its own form until someone converts it. \`skill:malloy-analysis-report\` writes this form for a quick write-up.
|
|
360780
|
-
|
|
360781
|
-
### The five authoring rules (cell reports)
|
|
360782
|
-
|
|
360783
|
-
Rules 1 and 4 hold for both forms; rules 2, 3 and 5 are about \`run:\` cells and prose notes.
|
|
360784
|
-
|
|
360785
|
-
1. **The header is \`##!\` flags, \`//\` comments and unnamed \`"\` notes (the description), then \`## artifact { layout=linear … }\`.** Nothing else goes above the tag. A statement or a tag above \`## artifact\` is an error, and the report is served with that error instead of opening.
|
|
360786
|
-
2. **Prose is a \`(markdown)\` annotation, and the number of \`#\` says what it belongs to.** Floating markdown is a cell of its own: \`##(markdown) text\` (contiguous lines with no blank line between them merge into one cell) or a \`##|(markdown)\` block, with the body starting on the next line and the \`|##\` closer at the opener's column. Attached markdown, \`#(markdown) text\` or a \`#|(markdown)\` … \`|#\` block, belongs to the statement below it and renders with that cell. Keep the parentheses: \`##| markdown\` reads its prose as ordinary tags, and \`##|markdown\` draws a malformed-route warning. No body line starts with \`|##\`, and a blank line follows the closer. A \`## Heading\` line is model tags, not prose: write a heading inside a \`##|(markdown)\` block.
|
|
360787
|
-
3. **Render tags sit directly above \`run:\`, with nothing between.** A \`#"\` directly above the \`run:\` is its caption; \`# bar_chart\`, \`# label="..."\` and the other render tags go in the same block. Attached \`#(markdown)\` goes above the \`#"\` caption when both are present, and renders as a header above the result.
|
|
360788
|
-
4. **\`given:\` uses \`NAME :: filter<T> is f''\`, bound with \`~\`, declared before first use.** Put \`##! experimental.givens\` at the top of the file.
|
|
360789
|
-
5. **Trailing prose is \`##(markdown)\`, never \`#(markdown)\` or \`#"\`.** Both belong to the statement below them, and at the end of a file there is none. An \`import\` or an \`export\` takes no annotation either, so prose above one is \`##|(markdown)\`.
|
|
360790
|
-
|
|
360791
|
-
### How the file becomes cells
|
|
360792
|
-
|
|
360793
|
-
Cells come from the file's own notes and statements, in file order (imported files add none):
|
|
360794
|
-
|
|
360795
|
-
| In the file | Cell |
|
|
360796
|
-
| ------------------------------------------------------------------------ | ---------------------------------------------------------------------- | --------------------------------------------------------- |
|
|
360797
|
-
| \`##!\` lines, \`## artifact\`, and every \`"\` note above the tag | the header: no cell |
|
|
360798
|
-
| \`##(markdown)\` lines (contiguous) or a \`## | (markdown)\` block, after the tag | one markdown cell |
|
|
360799
|
-
| \`#(markdown)\` or a \`# | (markdown)\`block above a\`run:\`, \`source:\`, \`query:\`, \`given:\`or\`type:\` | no cell of its own: it renders with that statement's cell |
|
|
360800
|
-
| \`run:\` with its contiguous \`#\` tag block, including \`run: <named query>\` | one query cell |
|
|
360801
|
-
| \`import\`, \`source:\`, \`query:\`, \`given:\`, \`export { … }\`, \`type:\` | one definition cell **per statement** |
|
|
360802
|
-
| a non-\`"\` \`##\` note after the tag (\`## title=…\`) | not a cell |
|
|
360803
|
-
|
|
360804
|
-
Definition cells render folded; only query cells run. Earlier spellings are still read: \`##"\`, \`##|"\`, \`##(text)\` and \`##|(text)\` notes below the tag are markdown cells, like \`(markdown)\`. Write \`(markdown)\`. A query cell runs as a _restricted query_ against the already-compiled file, so an \`import\` inside a \`run:\` is rejected (\`file imports are not permitted in a restricted query\`).
|
|
360805
|
-
|
|
360806
|
-
### A complete cell report
|
|
360807
|
-
|
|
360808
|
-
\`\`\`malloy
|
|
360809
|
-
##! experimental.givens
|
|
360810
|
-
##" One category at a time: how it sells across the year and which brands carry it.
|
|
360811
|
-
## artifact { layout=linear title="Category review" }
|
|
360812
|
-
import { order_items, products } from "storefront.malloy"
|
|
360813
|
-
|
|
360814
|
-
##|(markdown)
|
|
360815
|
-
## Category review
|
|
360816
|
-
|
|
360817
|
-
Pick a **Category** in the controls above and every chart below re-runs for it.
|
|
360818
|
-
Leave the control empty to read the whole catalog.
|
|
360819
|
-
|##
|
|
360820
|
-
|
|
360821
|
-
#(description="Narrow to one product category")
|
|
360822
|
-
# label="Category" control=select suggest { source=products dimension=category }
|
|
360823
|
-
given: CATEGORY :: filter<string> is f''
|
|
360824
|
-
|
|
360825
|
-
##(markdown) How is revenue trending for the selected category?
|
|
360826
|
-
|
|
360827
|
-
#(markdown) ### Revenue by month
|
|
360828
|
-
#" Revenue by month for the selected category
|
|
360829
|
-
# line_chart
|
|
360830
|
-
# label="Revenue by month"
|
|
360831
|
-
run: order_items -> sales_by_month + { where: category ~ $CATEGORY }
|
|
360858
|
+
- **Tiles run through the model query endpoint**, against the report's own path, like a grid's.
|
|
360832
360859
|
|
|
360833
|
-
##
|
|
360860
|
+
## Files written as \`run:\` cells (retired)
|
|
360834
360861
|
|
|
360835
|
-
|
|
360836
|
-
# bar_chart
|
|
360837
|
-
# label="Top brands"
|
|
360838
|
-
run: order_items -> top_brands + { where: category ~ $CATEGORY }
|
|
360839
|
-
|
|
360840
|
-
##(markdown) Last, the best-selling products, defined once as a named query and then run.
|
|
360841
|
-
|
|
360842
|
-
query: top_products_in_category is order_items -> top_products + { where: category ~ $CATEGORY }
|
|
360843
|
-
|
|
360844
|
-
#(markdown) ### Best sellers
|
|
360845
|
-
run: top_products_in_category
|
|
360846
|
-
\`\`\`
|
|
360847
|
-
|
|
360848
|
-
The \`##|(markdown)\` block and each \`##(markdown)\` line are floating markdown cells. The two \`#(markdown)\` lines are attached: each renders as a header with the \`run:\` below it. The \`given:\` and the \`query:\` are definition cells, and each \`run:\` is a query cell.
|
|
360862
|
+
An older linear form was a file of \`run:\` statements with \`(markdown)\` notes between them, under a tag with no \`tiles\`. Publisher no longer reads it: such a file is not a report, and the package warnings name it (\`report-cells-removed\`). Never write one. To bring one back, rewrite it as tiles:
|
|
360849
360863
|
|
|
360850
|
-
|
|
360851
|
-
|
|
360852
|
-
|
|
360853
|
-
|
|
360854
|
-
- Every \`run:\` is \`<source> -> <view or query body>\` with a named source. An inline \`extend\` before the arrow, a source that is not a name, or a refinement (\`q + { … }\`) of a multi-stage query is refused, and so is a run that resolves through more than ten named queries.
|
|
360855
|
-
- A chart line the editor does not model (for example \`# bar_chart { size=spark }\`) is kept, and the Viz type picker is disabled for that tile with the reason shown.
|
|
360856
|
-
- The editor opens a report **read-only**, saying why, when it cannot place cells one by one: two statements or notes on one line, text after a block closer, a comment straddling two cells, a lone carriage return (use LF or CRLF), a statement above the \`## artifact\` tag, a statement no cell can hold, or a tag value Malloy cannot read, such as a malformed date literal (\`@2024-13-01\`).
|
|
360864
|
+
1. Each floating \`##(markdown)\` note or \`##|(markdown)\` block becomes a named \`##|(markdown) name\` block, listed as \`name { kind=text }\`.
|
|
360865
|
+
2. Each \`run: <source> -> <query>\` becomes a \`view:\` on a \`<source>_tiles\` extension the report declares, listed as \`"<source>_tiles -> <view>"\`. The render tags above the \`run:\` move to the view; a \`#"\` caption becomes \`# label="…"\`. A \`run:\` of a named \`query:\` is listed by the query's name.
|
|
360866
|
+
3. List the entries in \`tiles=[…]\` in reading order, keep \`layout=linear\`, and delete every \`run:\`.
|
|
360857
360867
|
|
|
360858
360868
|
## Multiple models and cross-model joins
|
|
360859
360869
|
|
|
360860
|
-
A report compiles with **all** its \`import\`s in scope, so it can import several \`.malloy\` models, and a tile's source
|
|
360870
|
+
A report compiles with **all** its \`import\`s in scope, so it can import several \`.malloy\` models, and a tile's source can reference, and **join**, sources from different imported files. Import each model you need at the top; no re-export wrapper is required.
|
|
360861
360871
|
|
|
360862
|
-
**When the package root holds an \`index.malloy\`, tiles
|
|
360872
|
+
**When the package root holds an \`index.malloy\`, tiles read only what it exports.** A tile over a source \`index.malloy\` does not export answers 404, even when the report imports that source's file. A source the report derives from an exported one (\`source: mine is customers extend { ... }\`) still works. A tile's own source over a raw table (\`duckdb.table(...)\`) is refused. To use a source, add it to the \`export { ... }\` in \`index.malloy\`.
|
|
360863
360873
|
|
|
360864
360874
|
## Style
|
|
360865
360875
|
|
|
@@ -360868,14 +360878,20 @@ A report compiles with **all** its \`import\`s in scope, so it can import severa
|
|
|
360868
360878
|
**No data-specific insights in markdown.** Data refreshes will make them stale.
|
|
360869
360879
|
|
|
360870
360880
|
\`\`\`malloy
|
|
360871
|
-
|
|
360881
|
+
##|(markdown) spike_note
|
|
360882
|
+
WRONG: will become stale when data refreshes. Revenue spiked 23% in March.
|
|
360883
|
+
|##
|
|
360872
360884
|
|
|
360873
|
-
|
|
360885
|
+
##|(markdown) trend_q
|
|
360886
|
+
RIGHT: frames the question and lets the query answer it. How is revenue trending?
|
|
360887
|
+
|##
|
|
360874
360888
|
\`\`\`
|
|
360875
360889
|
|
|
360890
|
+
Each is a text tile, listed in \`tiles=[…]\` by name, for example \`trend_q { kind=text }\`.
|
|
360891
|
+
|
|
360876
360892
|
To add \`limit\`, \`where\`, or other options to an existing view, refine it with \`+\`: \`my_view + { limit: 15 }\`.
|
|
360877
360893
|
|
|
360878
|
-
One query per tile
|
|
360894
|
+
One query per tile, and remember a chart renders only the **first** aggregate in its result.
|
|
360879
360895
|
|
|
360880
360896
|
## Existing \`.malloynb\` files
|
|
360881
360897
|
|
|
@@ -360883,28 +360899,21 @@ A \`.malloynb\` (cells delimited by \`>>>markdown\` and \`>>>malloy\`) is a depr
|
|
|
360883
360899
|
|
|
360884
360900
|
## Common mistakes
|
|
360885
360901
|
|
|
360886
|
-
| Mistake | Fix
|
|
360887
|
-
| -------------------------------------------------------------------------- |
|
|
360888
|
-
| A tile list without \`layout=linear\` | Read as a grid. Write \`layout=linear\`.
|
|
360889
|
-
|
|
|
360890
|
-
|
|
|
360891
|
-
| \`##
|
|
360892
|
-
| \`##
|
|
360893
|
-
|
|
|
360894
|
-
| Text on the opener line after
|
|
360895
|
-
|
|
|
360896
|
-
|
|
|
360897
|
-
|
|
|
360898
|
-
| \`
|
|
360899
|
-
|
|
|
360900
|
-
|
|
|
360901
|
-
| \`tiles=[intro { kind=text }, orders_tiles -> headline]\` (entry not quoted) | Every \`source -> view\` entry is a quoted string. Unquoted, the tag does not parse. |
|
|
360902
|
-
| A bare \`intro\` in \`tiles\` for a \`## | (markdown) intro\` block | A bare name is the query-tile form for a \`query:\`. Write \`intro { kind=text }\`. |
|
|
360903
|
-
| \`colspan\` or \`break\` on a linear report's tile entry | Ignored and reported (\`notebook-tile-layout-ignored\`). Remove them, or switch to \`layout=grid\`. |
|
|
360904
|
-
| \`#(filter)\` in any form | Deprecated. Declare a \`given:\` on the model's source instead. |
|
|
360905
|
-
| \`import\` inside a \`run:\` cell | Imports are file-wide; put them at the top. |
|
|
360906
|
-
| Data-specific insights in markdown | Frame questions instead. |
|
|
360907
|
-
| A cross-model join in a quick \`skill:malloy-analysis-report\` cell | That cell renders against a single model. Write it as a report tile over a source the report declares with the join, since the report compiles with all its imports. |`
|
|
360902
|
+
| Mistake | Fix |
|
|
360903
|
+
| -------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
|
|
360904
|
+
| A tile list without \`layout=linear\` | Read as a grid. Write \`layout=linear\`. |
|
|
360905
|
+
| A linear tag with no \`tiles=[…]\` | The retired cell format: no report (\`report-cells-removed\`). List the tiles. |
|
|
360906
|
+
| \`view_name { limit: 10 }\` | Use \`+\`: \`view_name + { limit: 10 }\` |
|
|
360907
|
+
| Floating \`##(markdown)\` prose in a tiled report | Never shown (\`notebook-markdown-block-unnamed\`). Make it a named text tile and list it. |
|
|
360908
|
+
| \`## Heading\` for a section title | That line is model tags, not prose. Write the heading inside a \`##\\|(markdown) name\` text tile. |
|
|
360909
|
+
| \`##\\| markdown\` or \`##\\|markdown\` (no parentheses) | Write \`##\\|(markdown) name\`. |
|
|
360910
|
+
| Text on the opener line after \`##\\|(markdown)\` | Only the tile's name may follow it. Put the text on the next line. |
|
|
360911
|
+
| \`run:\` in a report that lists \`tiles=[…]\` | Never shown. Define a \`view:\`, list \`"source -> view"\` in \`tiles\`, delete the \`run:\`. |
|
|
360912
|
+
| \`tiles=[intro { kind=text }, orders_tiles -> headline]\` (entry not quoted) | Every \`source -> view\` entry is a quoted string. Unquoted, the tag does not parse. |
|
|
360913
|
+
| A bare \`intro\` in \`tiles\` for a \`##\\|(markdown) intro\` block | A bare name is the query-tile form for a \`query:\`. Write \`intro { kind=text }\`. |
|
|
360914
|
+
| \`colspan\` or \`break\` on a linear report's tile entry | Ignored and reported (\`notebook-tile-layout-ignored\`). Remove them, or switch to \`layout=grid\`. |
|
|
360915
|
+
| \`#(filter)\` in any form | Deprecated. Declare a \`given:\` on the model's source instead. |
|
|
360916
|
+
| Data-specific insights in a text tile | Frame questions instead. |`
|
|
360908
360917
|
},
|
|
360909
360918
|
{
|
|
360910
360919
|
name: "malloy-review",
|
|
@@ -361107,7 +361116,7 @@ This review covers 10,173 lines across 47 files. Only ~1,500 lines were deep-rev
|
|
|
361107
361116
|
{
|
|
361108
361117
|
name: "malloy-review/rubric-structure",
|
|
361109
361118
|
description: "Rubric: Structure. Reference detail for the malloy-review skill.",
|
|
361110
|
-
body: "# Rubric: Structure\n\n**Dimension:** `structure`\n**Rules:** 5\n\nApplies to the organization of `.malloy` files within a package. Skip a file for structural review if it's a report (a `.malloy` file anywhere in the package whose model-level notes carry an `## artifact` tag, of either layout, `layout=grid` or `layout=linear` or the deprecated `kind=`, written as `tiles=[…]
|
|
361119
|
+
body: "# Rubric: Structure\n\n**Dimension:** `structure`\n**Rules:** 5\n\nApplies to the organization of `.malloy` files within a package. Skip a file for structural review if it's a report (a `.malloy` file anywhere in the package whose model-level notes carry an `## artifact` tag, of either layout, `layout=grid` or `layout=linear` or the deprecated `kind=`, written as `tiles=[…]`; a legacy query-level `# artifact` on a `query:`; or a `.malloynb`), which has its own conventions (the `malloy-reports` skill), or a one-off sandbox script. Do not flag a report for where it sits: no directory is required for one, and the package root is the default.\n\nFor every rule, the linked instruction-skill section is the canonical source for rationale and examples.\n\n---\n\n## S-01: Base vs joined source separation\n\n- **Severity:** major (non-blocking) · **Category:** structure · LLM-judgment\n- **Detection:** LLM heuristic, a source named after a base table (`customers`, `orders`) that includes cross-table joins, or a file with multiple sources where one clearly joins the others, is a candidate for splitting\n- **Fix:** move the joined source into its own file; leave the base source clean\n- **See:** `skill:malloy-model` § Base vs Joined Sources · `skill:malloy-model` § Joined Source File Template\n\n---\n\n## S-02: Sources should declare `primary_key:` when one exists\n\n- **Severity:** minor (non-blocking) · **Category:** structure · machine-checkable\n- **Why this isn't a correctness rule.** The Malloy compiler auto-synthesizes a UUID-based `__distinct_key` for any `join_one:` target without a declared PK (`packages/malloy/src/model/field_instance.ts:644-670`, `query_query.ts:946-951`), so symmetric aggregation is correct either way, see the C-07 entry in `rubric-correctness.md`'s \"Rules we dropped\" section. The `with` shortcut, which DOES require a declared PK, errors at compile time and surfaces as a diagnostic. The actual silent-correctness hazard (\"declared PK isn't actually unique in the data\") is `rubric-correctness.md` § C-12.\n- **What this rule catches.** A discoverability / hygiene gap: when a source has a natural primary key, declaring it lets downstream code use the `with` shortcut, makes grain explicit in the model, and gives tooling a stable identifier per row. Treat as a recommendation, not a merge gate.\n- **Detection:** for every `source:` declaration, check whether its body contains a `primary_key:` clause. Skip flagging when:\n - The source is a query-based / computed source (`source: x is t -> {...}` or `source: x is (t -> {...}) extend {...}`) where grain is determined by the `group_by` columns, declaring a `primary_key:` on the result is fine but not required.\n - The source represents an event/log table or a denormalized analytical source where no natural PK exists. Both situations are legitimate; the LLM should recognize them and skip the finding.\n- **Fix (when the source does have a natural PK):** declare it, `primary_key: <col>` inside `extend {}`. When there isn't a natural PK, leave it undeclared; if the absence is non-obvious, a one-line `#(doc)` on the source explaining the grain helps future readers.\n- **See:** `skill:malloy-model` § Key Rules · `rubric-correctness.md` § C-12 (the related correctness rule that checks whether a declared PK is actually unique in the data) · `rubric-style.md` § Y-03 (`join_one:` style consistency, which is the other consequence of declared-vs-undeclared PKs)\n\n---\n\n## S-03: Joined tables defined before the source that references them\n\n- **Severity:** blocker (blocking) · **Category:** structure · machine-checkable\n- **Detection:** AST, within a single file, for each source reference inside a `join_*:` or `source is <name>`, verify the target source is declared earlier\n- **Fix:** reorder source declarations so dependencies come first. If two sources reference each other, split into separate files with explicit `import` (cross-file declarations don't have this ordering constraint).\n- **See:** `skill:malloy-gotchas-modeling` § Source Order, Define Joined Tables First\n\n---\n\n## S-04: Base sources curate their column surface\n\n- **Severity:** major (non-blocking) · **Category:** structure · machine-checkable\n- **Detection:** AST, for each `source: ... is conn.table(...)` declaration (a direct-table base source), check whether the source uses **any** of the three column-curation mechanisms below. The finding fires only when the source uses none of them, every column from the underlying table is implicitly public. Query-based sources and sources derived from other sources are exempt.\n- **Fix:** pick whichever option matches the source's needs. Curation options, lightest to heaviest:\n 1. `extend { except: a, b, c }`, drop a small named set of columns. Compatible with `rename:`. No experimental flag.\n 2. `extend { accept: a, b, c }`, keep only a small named set. Compatible with `rename:`. No experimental flag.\n 3. `##! experimental.access_modifiers` + `include { public: …, internal: …, private: … }`, full per-column visibility tiers. **Composes with `rename:` in one order only** (the `extend { rename: }` before the `include {}`, which then names the field by its new name) and disallows measures/dimensions whose names shadow `internal:` columns. Use only when the visibility distinction matters (e.g., shared sources joined into multiple consumers).\n\n Most files only need option 1 or 2, for the small set of columns that shouldn't be public, prefer `except:` over the heavier `include {}` machinery. Reach for `include {}` only when per-column tiers are genuinely worth the constraints.\n- **See:** `skill:malloy-gotchas-modeling` § Field Management: `extend {}` and `include {}`, in that order · `skill:malloy-model` § Base Source Templates · `malloy-model/reference/access-modifiers.md`\n\n---\n\n## S-05: One file per table (base) / one per analytical domain (joined)\n\n- **Severity:** minor (non-blocking) · **Category:** structure · machine-checkable\n- **Detection:** count `source: X is conn.table(...)` base-source declarations per file. More than one → flag.\n- **Fix:** split each base source into its own file named after the source\n- **See:** `skill:malloy-model` § Base Source Templates (file convention is implicit; weak counterpart)\n\n---\n\n## Cross-cutting note\n\nWhen a file violates both S-01 (base+joined mixed) and S-05 (multiple base sources), surface the combined observation as a **Cross-Cutting Theme** in the review output: \"File layout suggests a restructure, see S-series findings for suggested splits.\""
|
|
361111
361120
|
},
|
|
361112
361121
|
{
|
|
361113
361122
|
name: "malloy-review/rubric-style",
|
|
@@ -361484,7 +361493,7 @@ Close with what you used, in a few lines: the agent and package, which skills yo
|
|
|
361484
361493
|
{
|
|
361485
361494
|
name: "malloy-source-unreachable",
|
|
361486
361495
|
description: `Work out why a source is missing from get_context, or why a query against it was refused with a 404 or a 403, and what to do next. Use when a source you expect is absent from discovery, when execute_query answers "No queryable source", when a query that used to work stops working, or when deciding whether a package's curation is hiding something you need.`,
|
|
361487
|
-
body: '# A source you cannot reach\n\n> **Tool names** are written bare here - `get_context`, `execute_query`, `get_status`, `compile_model`. The exact prefixed name depends on the host surface; match each against the tools you actually have.\n\nMost packages publish a curated surface, so a source being absent or refused is usually the package working as its author intended, not a fault. Read the refusal before working around it, because the three things that can refuse you need three different responses and they are told apart by the status code.\n\n## The three answers\n\n| what you got | what it means | what to do |\n| --- | --- | --- |\n| **404** that says "not on this package\'s published surface" | the name is real and the package does not publish it. It is curation, not a typo | follow the fix the message names (usually: name it in the `export { ... }` of `index.malloy` and address the query there), or query what IS published |\n| **404**, plain "No queryable source", "No queryable model" or "Query target is not queryable" | the name does not exist, or it is hidden in a model that carries an `#(authorize)` or `#(access_filter)` gate. In a gated model the two are deliberately indistinguishable, so a refusal cannot be used to probe for hidden names | check the name against `get_context`, then query something on the surface or ask the package\'s author to publish it |\n| **403**, "Access denied" | the source exists and is on the surface, but an `#(authorize)` gate did not admit you | supply the givens the gate reads, or accept that this caller may not read it |\n| **200** with zero rows | you were admitted, and an `#(access_filter)` narrowed the rows to none of them | this is a real answer. Report it as "no matching rows", never as an error |\n\nA 403 names a source, so it tells you the source exists. A plain 404 tells you nothing at all. That asymmetry is deliberate: a source that is both hidden AND gated answers a plain **404**, so you can never use a 403, or the wording of a 404, to discover that a hidden gated name is real.\n\n**One 404 is not about the source at all.** If a query that joins an exported source in its own text answers `Query target is not queryable`, check the joined source\'s givens. A source that reads a given with no default, which `index.malloy` does not import, is refused that way when joined. Queried directly, the same source answers a 400 that names the cause. Run the joining query through `compile_model`: the problem then reads "references given NAME ... which is not surfaced in this model". The fix belongs in the model, not the query, so report it to the model\'s author: `index.malloy` has to import that given, either by importing its declaring file whole or by naming the given in a selective import.\n\n## Addressing the surface, which is the most common 404\n\nA query names a model file. When a package curates its surface, only files on that surface are valid entry points, **even for a source that file declares itself**:\n\n```\nPOST .../packages/sales/models/index.malloy/query {"sourceName": "orders"} -> 200\nPOST .../packages/sales/models/orders.malloy/query {"sourceName": "orders"} -> 404\n```\n\nSame source, same package. `orders.malloy` is off the surface, so it is not an entry point.\n\n**Use the `model_path` that `get_context` gave you, verbatim.** Its `source_info.resource_id` holds `environment`, `package`, `model_path` and `source`, and those are exactly `execute_query`\'s `environmentName`, `packageName`, `modelPath` and `sourceName`. On a curated package the `model_path` is the surface file, not the file that declares the source. Substituting the declaring file because it looks more correct is how this 404 happens.\n\n## Other places a hidden source answers 404\n\nThe query route is not the only one held to the surface. On a curated package, a source or file off it also shows up as a 404 here:\n\n- **Reading a model.** `GET .../models/{path}` answers 404 for a file off the surface, with the same words as the query route. The file still exists and still compiles; read `index.malloy` instead. A model that is on the surface lists only the names it publishes, not everything it imports.\n- **A report tile.** A tile, or a filter `suggest` over a hidden source answers 404. The report itself is still listed. The package load warns once per tile, for example `Tile orders_staging -> by_flag on report overview reads orders_staging, which index.malloy doesn\'t export, so it won\'t load. Fix: add orders_staging to the export { ... } in index.malloy.` It is in the `warnings` on the package\'s own response, `GET .../packages/{pkg}`.\n
|
|
361496
|
+
body: '# A source you cannot reach\n\n> **Tool names** are written bare here - `get_context`, `execute_query`, `get_status`, `compile_model`. The exact prefixed name depends on the host surface; match each against the tools you actually have.\n\nMost packages publish a curated surface, so a source being absent or refused is usually the package working as its author intended, not a fault. Read the refusal before working around it, because the three things that can refuse you need three different responses and they are told apart by the status code.\n\n## The three answers\n\n| what you got | what it means | what to do |\n| --- | --- | --- |\n| **404** that says "not on this package\'s published surface" | the name is real and the package does not publish it. It is curation, not a typo | follow the fix the message names (usually: name it in the `export { ... }` of `index.malloy` and address the query there), or query what IS published |\n| **404**, plain "No queryable source", "No queryable model" or "Query target is not queryable" | the name does not exist, or it is hidden in a model that carries an `#(authorize)` or `#(access_filter)` gate. In a gated model the two are deliberately indistinguishable, so a refusal cannot be used to probe for hidden names | check the name against `get_context`, then query something on the surface or ask the package\'s author to publish it |\n| **403**, "Access denied" | the source exists and is on the surface, but an `#(authorize)` gate did not admit you | supply the givens the gate reads, or accept that this caller may not read it |\n| **200** with zero rows | you were admitted, and an `#(access_filter)` narrowed the rows to none of them | this is a real answer. Report it as "no matching rows", never as an error |\n\nA 403 names a source, so it tells you the source exists. A plain 404 tells you nothing at all. That asymmetry is deliberate: a source that is both hidden AND gated answers a plain **404**, so you can never use a 403, or the wording of a 404, to discover that a hidden gated name is real.\n\n**One 404 is not about the source at all.** If a query that joins an exported source in its own text answers `Query target is not queryable`, check the joined source\'s givens. A source that reads a given with no default, which `index.malloy` does not import, is refused that way when joined. Queried directly, the same source answers a 400 that names the cause. Run the joining query through `compile_model`: the problem then reads "references given NAME ... which is not surfaced in this model". The fix belongs in the model, not the query, so report it to the model\'s author: `index.malloy` has to import that given, either by importing its declaring file whole or by naming the given in a selective import.\n\n## Addressing the surface, which is the most common 404\n\nA query names a model file. When a package curates its surface, only files on that surface are valid entry points, **even for a source that file declares itself**:\n\n```\nPOST .../packages/sales/models/index.malloy/query {"sourceName": "orders"} -> 200\nPOST .../packages/sales/models/orders.malloy/query {"sourceName": "orders"} -> 404\n```\n\nSame source, same package. `orders.malloy` is off the surface, so it is not an entry point.\n\n**Use the `model_path` that `get_context` gave you, verbatim.** Its `source_info.resource_id` holds `environment`, `package`, `model_path` and `source`, and those are exactly `execute_query`\'s `environmentName`, `packageName`, `modelPath` and `sourceName`. On a curated package the `model_path` is the surface file, not the file that declares the source. Substituting the declaring file because it looks more correct is how this 404 happens.\n\n## Other places a hidden source answers 404\n\nThe query route is not the only one held to the surface. On a curated package, a source or file off it also shows up as a 404 here:\n\n- **Reading a model.** `GET .../models/{path}` answers 404 for a file off the surface, with the same words as the query route. The file still exists and still compiles; read `index.malloy` instead. A model that is on the surface lists only the names it publishes, not everything it imports.\n- **A report tile.** A tile, or a filter `suggest` over a hidden source answers 404. The report itself is still listed. The package load warns once per tile, for example `Tile orders_staging -> by_flag on report overview reads orders_staging, which index.malloy doesn\'t export, so it won\'t load. Fix: add orders_staging to the export { ... } in index.malloy.` It is in the `warnings` on the package\'s own response, `GET .../packages/{pkg}`.\n\nThe fix is the same in each case: add the source to the `export { ... }` in `index.malloy`, or use what is already published.\n\n## When the source is not in `get_context` at all\n\nWork down this list. The first three are far more common than the last.\n\n1. **It is off the surface.** The package publishes a curated set and this source is not in it. Nothing you can do from the query side; it is a package edit.\n2. **The package failed to load, or is serving a stale model.** Call `list_packages`: a package that failed to load appears with an `error`, and one serving the model it compiled *before* a failed reload carries `stale: true` and the `error` too. `get_status` has the full load errors.\n3. **You are talking to a different server than you think.** Call `list_packages` and check the environment and package names are the ones you expect. A stale `.mcp.json` outlives the server that wrote it, and another Publisher may hold that port.\n4. **Your search phrasing missed it.** Retry with a bare target (no `search_text`) to enumerate rather than rank. If it appears there, the source exists and was a ranking miss.\n\n## What curation does not do\n\n- **It does not hide fields.** A published source may `join` an unpublished one, and a query grouping by a joined field returns that field\'s values normally. Hiding a source removes it as a landing point; it does not redact columns a published source pulls in.\n- **It does not gate `/compile`.** `compile_model` is exempt, because compile is the authoring loop. A hidden source can still be compile-checked, and that is intended. The exceptions are a hidden source that is also gated, which answers 404 at compile too, and a document (text with a model-level `## artifact` tag): its tiles and cells are held to the surface, so one over a source off it comes back as a `query-not-queryable` problem rather than compiling.\n- **It is not access control.** Curation answers "what is queryable by name", not "who may query it". Identity is `#(authorize)` and `#(access_filter)`. A source is not protected by being hidden.\n\n## Reaching an unpublished source from your own model\n\nIf you are writing Malloy rather than just querying, an unpublished source is still usable, with one condition that trips people.\n\n`export { ... }` decides what an **importing file** can see, which is Malloy\'s rule and not Publisher\'s:\n\n- a file that declares **no** `export` hands an importer everything it declares, so import the file that declares the source and join it normally;\n- a file that **does** declare one hands over exactly that list. Importing a file whose `export` omits the source and then naming it fails to compile with `Reference to undefined object`.\n\nSo an unpublished source is reachable through a file that exports it, or that exports nothing, and not through a file whose `export` leaves it out. Re-export chains are fine at any depth: a source re-exported through several files stays queryable through the surface, because admission follows the declaration rather than the path taken to it.\n\n## Before you report a source as missing\n\nConfirm all three, in this order. Each one has been mistaken for "the data is not there".\n\n1. `get_status` shows the package loaded and not `stale`.\n2. `list_packages` names the environment and package you meant.\n3. An enumerating `get_context` call (a target with no `search_text`) does not list it.\n\nOnly then is it genuinely not published, and the answer to the user is that the package does not expose it, not that the data does not exist.'
|
|
361488
361497
|
}
|
|
361489
361498
|
]
|
|
361490
361499
|
};
|
|
@@ -368234,6 +368243,24 @@ function tryAcquire(sync, alreadyAcquiredError = E_ALREADY_LOCKED) {
|
|
|
368234
368243
|
// src/mcp/tools/embedding_index.ts
|
|
368235
368244
|
init_logger();
|
|
368236
368245
|
|
|
368246
|
+
// src/service/event_loop_yield.ts
|
|
368247
|
+
var DEFAULT_BUDGET_MS = 10;
|
|
368248
|
+
var budgetMs = DEFAULT_BUDGET_MS;
|
|
368249
|
+
function yieldToEventLoop() {
|
|
368250
|
+
return new Promise((resolve3) => setImmediate(resolve3));
|
|
368251
|
+
}
|
|
368252
|
+
function createEventLoopYielder() {
|
|
368253
|
+
let since = performance.now();
|
|
368254
|
+
return {
|
|
368255
|
+
async maybeYield() {
|
|
368256
|
+
if (performance.now() - since < budgetMs)
|
|
368257
|
+
return;
|
|
368258
|
+
await yieldToEventLoop();
|
|
368259
|
+
since = performance.now();
|
|
368260
|
+
}
|
|
368261
|
+
};
|
|
368262
|
+
}
|
|
368263
|
+
|
|
368237
368264
|
// src/mcp/tools/embedding_sync_queue.ts
|
|
368238
368265
|
init_logger();
|
|
368239
368266
|
|
|
@@ -369386,7 +369413,6 @@ function fingerprintOfRows(rows) {
|
|
|
369386
369413
|
return contentHash(rows.join(`
|
|
369387
369414
|
`));
|
|
369388
369415
|
}
|
|
369389
|
-
var yieldToEventLoop = () => new Promise((resolve3) => setImmediate(resolve3));
|
|
369390
369416
|
async function desiredFacetsChunked(entities, plan) {
|
|
369391
369417
|
const desired = [];
|
|
369392
369418
|
for (let i2 = 0;i2 < entities.length; i2 += FINGERPRINT_CHUNK_ENTITIES) {
|
|
@@ -372969,6 +372995,11 @@ function readGivenControlSpec(annotationTexts2) {
|
|
|
372969
372995
|
}
|
|
372970
372996
|
return spec;
|
|
372971
372997
|
}
|
|
372998
|
+
function givenDeclaresNoDefault(given) {
|
|
372999
|
+
const loose = given;
|
|
373000
|
+
const parsed = "default" in loose ? loose.default : loose._internal?.default;
|
|
373001
|
+
return parsed === undefined && loose._internal?.defaultText === undefined;
|
|
373002
|
+
}
|
|
372972
373003
|
function malloyGivenToApi(given) {
|
|
372973
373004
|
const type = given.type;
|
|
372974
373005
|
const renderedType = type.type === "filter expression" ? `filter<${type.filterType}>` : type.type === "array" && type.elementTypeDef?.type ? `${type.elementTypeDef.type}[]` : type.type;
|
|
@@ -372979,7 +373010,8 @@ function malloyGivenToApi(given) {
|
|
|
372979
373010
|
annotations: allNotes.filter((note) => !isReservedRoute(note.route) && note.route !== MARKDOWN_ROUTE).map((note) => note.text),
|
|
372980
373011
|
...readGivenControlSpec(allNotes.map((note) => note.text)),
|
|
372981
373012
|
...allNotes.some((note) => note.route === "secure") && { secure: true },
|
|
372982
|
-
default: given._internal?.defaultText
|
|
373013
|
+
default: given._internal?.defaultText,
|
|
373014
|
+
...givenDeclaresNoDefault(given) && { required: true }
|
|
372983
373015
|
};
|
|
372984
373016
|
}
|
|
372985
373017
|
function collectGivenRefs(value, into) {
|
|
@@ -373188,6 +373220,7 @@ function readReportModelFacts(modelPath, modelDef, surfacedGivenNames, gatesBySo
|
|
|
373188
373220
|
name: given.name,
|
|
373189
373221
|
type: isFilter ? `filter<${type.filterType}>` : type.type,
|
|
373190
373222
|
default: given.defaultText,
|
|
373223
|
+
...given.default === undefined && given.defaultText === undefined ? { required: true } : {},
|
|
373191
373224
|
annotations: (given.annotations?.blockNotes ?? []).concat(given.annotations?.notes ?? []).map((note) => note.text)
|
|
373192
373225
|
});
|
|
373193
373226
|
}
|
|
@@ -373339,6 +373372,7 @@ function givenSpec(declaration, facts) {
|
|
|
373339
373372
|
name: declaration.name,
|
|
373340
373373
|
type: declaration.type,
|
|
373341
373374
|
default: declaration.type.startsWith("filter<") && declaration.default !== undefined ? unwrapFilterLiteral(declaration.default) : declaration.default,
|
|
373375
|
+
...declaration.required ? { required: true } : {},
|
|
373342
373376
|
annotations: declaration.annotations.filter((text) => /^##?\(/.test(text) && !isMarkdownNote(text)),
|
|
373343
373377
|
...declaration.annotations.some((text) => /^#\(secure\)/.test(text)) && {
|
|
373344
373378
|
secure: true
|
|
@@ -380387,276 +380421,10 @@ function extractQueriesFromModelDef(modelDef) {
|
|
|
380387
380421
|
return { queries, misplacedAuthorize };
|
|
380388
380422
|
}
|
|
380389
380423
|
|
|
380390
|
-
// src/service/compile_document.ts
|
|
380391
|
-
var DECLARATION = /\b(?:source|query)\s*:\s*(`(?:[^`\\]|\\.)*`|[\p{L}_][\p{L}\p{N}_]*)\s+is\b/giu;
|
|
380392
|
-
function blankSpans(text, cells) {
|
|
380393
|
-
if (cells.length === 0)
|
|
380394
|
-
return text;
|
|
380395
|
-
const units = text.split("");
|
|
380396
|
-
for (const cell of cells) {
|
|
380397
|
-
const span = cellOffsets.get(cell);
|
|
380398
|
-
if (!span)
|
|
380399
|
-
throw new Error("restricted cell has no recorded span");
|
|
380400
|
-
const [start, end] = span;
|
|
380401
|
-
for (let i2 = start;i2 < end && i2 < units.length; i2++) {
|
|
380402
|
-
if (units[i2] !== `
|
|
380403
|
-
` && units[i2] !== "\r")
|
|
380404
|
-
units[i2] = " ";
|
|
380405
|
-
}
|
|
380406
|
-
}
|
|
380407
|
-
return units.join("");
|
|
380408
|
-
}
|
|
380409
|
-
function declaredNames(text) {
|
|
380410
|
-
const found = new Set(buildDerivationBaseMap(text).keys());
|
|
380411
|
-
for (const match of stripMalloyCommentsAndLiterals(text).matchAll(DECLARATION)) {
|
|
380412
|
-
const name = match[1];
|
|
380413
|
-
found.add(name.startsWith("`") ? name.slice(1, -1) : name);
|
|
380414
|
-
}
|
|
380415
|
-
return found;
|
|
380416
|
-
}
|
|
380417
|
-
function readsSource(prepared) {
|
|
380418
|
-
const ref = prepared._query?.structRef;
|
|
380419
|
-
if (typeof ref === "string")
|
|
380420
|
-
return ref;
|
|
380421
|
-
const named = ref;
|
|
380422
|
-
return named?.as || named?.name;
|
|
380423
|
-
}
|
|
380424
|
-
async function denied(gates, text) {
|
|
380425
|
-
try {
|
|
380426
|
-
await gates.text(text);
|
|
380427
|
-
return false;
|
|
380428
|
-
} catch (error2) {
|
|
380429
|
-
if (error2 instanceof AccessDeniedError)
|
|
380430
|
-
return true;
|
|
380431
|
-
throw error2;
|
|
380432
|
-
}
|
|
380433
|
-
}
|
|
380434
|
-
function tileProblem(expression, reason, cause) {
|
|
380435
|
-
return {
|
|
380436
|
-
code: "tile-does-not-compile",
|
|
380437
|
-
severity: "error",
|
|
380438
|
-
message: `Tile "${expression}" ${cause === "parse" ? "could not be parsed" : "does not compile"}: ${reason.replace(/\.?\s*$/, ".")} ` + `Fix: write the tile as one query over a source and a view, such as \`source -> view\` or \`source -> { group_by: field }\`.`
|
|
380439
|
-
};
|
|
380440
|
-
}
|
|
380441
|
-
function problemLine(problem) {
|
|
380442
|
-
const line = problem.at?.range?.start?.line;
|
|
380443
|
-
return line === undefined ? undefined : line + 1;
|
|
380444
|
-
}
|
|
380445
|
-
async function compileDocument(input) {
|
|
380446
|
-
const { base, source, modelName, gates } = input;
|
|
380447
|
-
const tag = readReportTagOfText(source);
|
|
380448
|
-
if (tag.status !== "report")
|
|
380449
|
-
return;
|
|
380450
|
-
const parse5 = parseNotebookText(source);
|
|
380451
|
-
if (isNotebookReaderError(parse5))
|
|
380452
|
-
return;
|
|
380453
|
-
const read = readNotebookCells(parse5, undefined, source);
|
|
380454
|
-
if (read.error) {
|
|
380455
|
-
return { problems: [cellsUnreadableProblem(read.error, "")] };
|
|
380456
|
-
}
|
|
380457
|
-
const code = read.cells.filter((cell) => cell.type === "code");
|
|
380458
|
-
const restrictedCells = new Set;
|
|
380459
|
-
const tainted = new Set;
|
|
380460
|
-
const mentionsTainted = (text) => tainted.size > 0 && [...scanIdentifiers(text)].some((name) => tainted.has(name));
|
|
380461
|
-
for (const cell of code) {
|
|
380462
|
-
if (mentionsTainted(cell.text) || await denied(gates, cell.text)) {
|
|
380463
|
-
restrictedCells.add(cell);
|
|
380464
|
-
if (cell.kind === "definition") {
|
|
380465
|
-
for (const name of declaredNames(cell.text))
|
|
380466
|
-
tainted.add(name);
|
|
380467
|
-
}
|
|
380468
|
-
}
|
|
380469
|
-
}
|
|
380470
|
-
const tileExpressions = readDocumentTileExpressions(read.annotations);
|
|
380471
|
-
const restrictedTiles = new Set;
|
|
380472
|
-
for (const expression of tileExpressions) {
|
|
380473
|
-
const text = `run: ${expression}`;
|
|
380474
|
-
if (mentionsTainted(text) || await denied(gates, text)) {
|
|
380475
|
-
restrictedTiles.add(normalizeTileExpression(expression));
|
|
380476
|
-
}
|
|
380477
|
-
}
|
|
380478
|
-
const definitions = code.filter((cell) => cell.kind === "definition" && !restrictedCells.has(cell)).map((cell) => cell.text).join(`
|
|
380479
|
-
`);
|
|
380480
|
-
const unparsedTiles = new Set;
|
|
380481
|
-
const tileProblems = [];
|
|
380482
|
-
for (const expression of tileExpressions) {
|
|
380483
|
-
const key = normalizeTileExpression(expression);
|
|
380484
|
-
if (restrictedTiles.has(key))
|
|
380485
|
-
continue;
|
|
380486
|
-
try {
|
|
380487
|
-
await gates.constructs(`${definitions}
|
|
380488
|
-
run: ${expression}`);
|
|
380489
|
-
} catch (error2) {
|
|
380490
|
-
if (!(error2 instanceof UnparseableTextError))
|
|
380491
|
-
throw error2;
|
|
380492
|
-
unparsedTiles.add(key);
|
|
380493
|
-
tileProblems.push(tileProblem(expression, error2.detail, "parse"));
|
|
380494
|
-
}
|
|
380495
|
-
}
|
|
380496
|
-
const boundaryProblems = [];
|
|
380497
|
-
const checkBoundary = async (query, line) => {
|
|
380498
|
-
try {
|
|
380499
|
-
await gates.boundary(query, definitions);
|
|
380500
|
-
} catch (error2) {
|
|
380501
|
-
if (!(error2 instanceof OffSurfaceError))
|
|
380502
|
-
throw error2;
|
|
380503
|
-
boundaryProblems.push({
|
|
380504
|
-
code: "query-not-queryable",
|
|
380505
|
-
severity: "error",
|
|
380506
|
-
message: error2.message,
|
|
380507
|
-
...line !== undefined && {
|
|
380508
|
-
at: {
|
|
380509
|
-
url: "",
|
|
380510
|
-
range: {
|
|
380511
|
-
start: { line: line - 1, character: 0 },
|
|
380512
|
-
end: { line: line - 1, character: 0 }
|
|
380513
|
-
}
|
|
380514
|
-
}
|
|
380515
|
-
}
|
|
380516
|
-
});
|
|
380517
|
-
}
|
|
380518
|
-
};
|
|
380519
|
-
for (const cell of code) {
|
|
380520
|
-
if (cell.kind === "query" && !restrictedCells.has(cell)) {
|
|
380521
|
-
await checkBoundary(cell.text, cell.startLine);
|
|
380522
|
-
}
|
|
380523
|
-
}
|
|
380524
|
-
for (const expression of tileExpressions) {
|
|
380525
|
-
const key = normalizeTileExpression(expression);
|
|
380526
|
-
if (!restrictedTiles.has(key) && !unparsedTiles.has(key)) {
|
|
380527
|
-
await checkBoundary(`run: ${expression}`, undefined);
|
|
380528
|
-
}
|
|
380529
|
-
}
|
|
380530
|
-
if (boundaryProblems.length > 0)
|
|
380531
|
-
return { problems: boundaryProblems };
|
|
380532
|
-
const readable = [
|
|
380533
|
-
...code.filter((cell) => cell.kind === "query" && !restrictedCells.has(cell)).map((cell) => cell.text),
|
|
380534
|
-
...tileExpressions.filter((expression) => {
|
|
380535
|
-
const key = normalizeTileExpression(expression);
|
|
380536
|
-
return !restrictedTiles.has(key) && !unparsedTiles.has(key);
|
|
380537
|
-
}).map((expression) => `run: ${expression}`)
|
|
380538
|
-
];
|
|
380539
|
-
for (const query of readable.length > 0 ? readable : [""]) {
|
|
380540
|
-
gates.nameVisible(query, definitions);
|
|
380541
|
-
}
|
|
380542
|
-
const compiledText = blankSpans(source, [...restrictedCells]);
|
|
380543
|
-
await gates.document(compiledText);
|
|
380544
|
-
const extended = base.extendModel(compiledText);
|
|
380545
|
-
let model;
|
|
380546
|
-
try {
|
|
380547
|
-
model = await extended.getModel();
|
|
380548
|
-
} catch (error2) {
|
|
380549
|
-
if (error2 instanceof MalloyError4)
|
|
380550
|
-
return { problems: [...tileProblems, ...error2.problems] };
|
|
380551
|
-
throw error2;
|
|
380552
|
-
}
|
|
380553
|
-
const modelDef = model._modelDef;
|
|
380554
|
-
const registry2 = modelDef.givens ?? {};
|
|
380555
|
-
const sources = extractSourcesFromModelDef(modelDef, []).sources;
|
|
380556
|
-
const settle2 = async (runnable, onDenied) => {
|
|
380557
|
-
try {
|
|
380558
|
-
await gates.compiled(runnable);
|
|
380559
|
-
} catch (error2) {
|
|
380560
|
-
if (error2 instanceof AccessDeniedError)
|
|
380561
|
-
onDenied();
|
|
380562
|
-
else
|
|
380563
|
-
throw error2;
|
|
380564
|
-
}
|
|
380565
|
-
};
|
|
380566
|
-
const compiledBoundary = async (runnable, prepared, query) => {
|
|
380567
|
-
try {
|
|
380568
|
-
await gates.boundaryCompiled(runnable, readsSource(prepared), query, definitions);
|
|
380569
|
-
} catch (error2) {
|
|
380570
|
-
if (!(error2 instanceof OffSurfaceError))
|
|
380571
|
-
throw error2;
|
|
380572
|
-
boundaryProblems.push({
|
|
380573
|
-
code: "query-not-queryable",
|
|
380574
|
-
severity: "error",
|
|
380575
|
-
message: error2.message
|
|
380576
|
-
});
|
|
380577
|
-
}
|
|
380578
|
-
};
|
|
380579
|
-
for (const cell of code) {
|
|
380580
|
-
if (cell.kind !== "query" || restrictedCells.has(cell))
|
|
380581
|
-
continue;
|
|
380582
|
-
const runnable = extended.loadRestrictedQuery(cell.text);
|
|
380583
|
-
let denied2 = false;
|
|
380584
|
-
await settle2(runnable, () => {
|
|
380585
|
-
denied2 = true;
|
|
380586
|
-
restrictedCells.add(cell);
|
|
380587
|
-
});
|
|
380588
|
-
if (denied2)
|
|
380589
|
-
continue;
|
|
380590
|
-
try {
|
|
380591
|
-
await compiledBoundary(runnable, await runnable.getPreparedQuery(), cell.text);
|
|
380592
|
-
} catch (error2) {
|
|
380593
|
-
if (!(error2 instanceof MalloyError4))
|
|
380594
|
-
throw error2;
|
|
380595
|
-
}
|
|
380596
|
-
}
|
|
380597
|
-
const compiledTiles = await compileTileGivens(tileExpressions, { loadQuery: (text) => extended.loadRestrictedQuery(text) }, registry2, (sourceName) => gateGivenSource(sources, sourceName), new Set([...restrictedTiles, ...unparsedTiles]), async (tile, prepared) => {
|
|
380598
|
-
let denied2 = false;
|
|
380599
|
-
await settle2({ getPreparedQuery: async () => prepared }, () => {
|
|
380600
|
-
denied2 = true;
|
|
380601
|
-
restrictedTiles.add(normalizeTileExpression(tile));
|
|
380602
|
-
});
|
|
380603
|
-
if (!denied2) {
|
|
380604
|
-
await compiledBoundary({ getPreparedQuery: async () => prepared }, prepared, `run: ${tile}`);
|
|
380605
|
-
}
|
|
380606
|
-
}, (tile, error2) => {
|
|
380607
|
-
if (!(error2 instanceof MalloyError4))
|
|
380608
|
-
return;
|
|
380609
|
-
gates.nameVisible(`run: ${tile}`, definitions);
|
|
380610
|
-
tileProblems.push(tileProblem(tile, error2.problems.map((problem) => problem.message).join("; "), "compile"));
|
|
380611
|
-
});
|
|
380612
|
-
if (boundaryProblems.length > 0)
|
|
380613
|
-
return { problems: boundaryProblems };
|
|
380614
|
-
const spans = [...restrictedCells];
|
|
380615
|
-
const problems = [...tileProblems, ...model.problems].filter((problem) => {
|
|
380616
|
-
const line = problemLine(problem);
|
|
380617
|
-
return line === undefined || !spans.some((cell) => line >= cell.startLine && line <= cell.endLine);
|
|
380618
|
-
});
|
|
380619
|
-
const slug = modelName.replace(/^.*\//, "").replace(/\.malloy$/, "");
|
|
380620
|
-
const path13 = `${slug}.malloy`;
|
|
380621
|
-
const facts = readReportModelFacts(path13, modelDef, Object.values(registry2).map((given) => given.name), new Map(sources.flatMap((entry) => entry.name ? [
|
|
380622
|
-
[
|
|
380623
|
-
entry.name,
|
|
380624
|
-
gateGivenSource(sources, entry.name) ?? []
|
|
380625
|
-
]
|
|
380626
|
-
] : [])));
|
|
380627
|
-
const manifest = buildReportManifest({ ...facts, compiledTileGivens: compiledTiles }, { restrictedTiles });
|
|
380628
|
-
const hasTiles = manifest?.tiles !== undefined;
|
|
380629
|
-
const cells = read.cells.filter((cell) => !hasTiles || cell.kind === "definition").map((cell) => {
|
|
380630
|
-
const restricted = restrictedCells.has(cell);
|
|
380631
|
-
if (cell.kind === "markdown") {
|
|
380632
|
-
return { type: "markdown", kind: "markdown", text: cell.text };
|
|
380633
|
-
}
|
|
380634
|
-
return {
|
|
380635
|
-
type: "code",
|
|
380636
|
-
kind: cell.kind,
|
|
380637
|
-
text: cell.text,
|
|
380638
|
-
...cell.markdown !== undefined && { markdown: cell.markdown },
|
|
380639
|
-
...cell.proseLines && { proseLines: cell.proseLines },
|
|
380640
|
-
...cell.codeLine !== undefined && { codeLine: cell.codeLine },
|
|
380641
|
-
...cell.caption !== undefined && { caption: cell.caption },
|
|
380642
|
-
...restricted && { restricted: true }
|
|
380643
|
-
};
|
|
380644
|
-
});
|
|
380645
|
-
if (!manifest) {
|
|
380646
|
-
return { problems, document: { layout: tag.layout, cells } };
|
|
380647
|
-
}
|
|
380648
|
-
const { entryFile: _entry, ...rest } = manifest;
|
|
380649
|
-
return {
|
|
380650
|
-
problems,
|
|
380651
|
-
document: {
|
|
380652
|
-
layout: manifest.layout,
|
|
380653
|
-
manifest: { ...rest, name: slug },
|
|
380654
|
-
cells
|
|
380655
|
-
}
|
|
380656
|
-
};
|
|
380657
|
-
}
|
|
380658
|
-
|
|
380659
380424
|
// src/service/notebook_lint.ts
|
|
380425
|
+
var CELLS_REMOVED = "report-cells-removed";
|
|
380426
|
+
var LAYOUT_UNKNOWN = "report-layout-unknown";
|
|
380427
|
+
var CELLS_REMOVED_MESSAGE = "a linear report written as `run:` cells is no longer read, so this file is not a report. Fix: list its tiles in `tiles=[…]` (a text tile per prose block, a query tile per view), or remove the `## artifact` tag.";
|
|
380660
380428
|
var TILE_ENTRY_FIX = 'Fix: every `source -> view` entry in `tiles` is a quoted string (`"orders_tiles -> headline"`), and a text entry is a bare name followed by `{ kind=text }` (`intro { kind=text }`).';
|
|
380661
380429
|
var quoted = (line, max = 60) => line.trim().slice(0, max);
|
|
380662
380430
|
var asTileName = (token) => {
|
|
@@ -380689,10 +380457,7 @@ function lintNotebookText(modelPath, text) {
|
|
|
380689
380457
|
const tag = readReportTag(tagNotes);
|
|
380690
380458
|
if (tag.status === "none")
|
|
380691
380459
|
return [];
|
|
380692
|
-
const hasTiles = tag.status === "report" && motlyTag(tagNotes)?.tag("artifact")?.has("tiles") === true;
|
|
380693
380460
|
const linear = tag.status === "report" && tag.layout === "linear";
|
|
380694
|
-
const inNotebooks = linear && !hasTiles;
|
|
380695
|
-
const layoutNotebook = linear && hasTiles;
|
|
380696
380461
|
const page = linear ? "notebook" : "dashboard";
|
|
380697
380462
|
const nodeText = (node) => node.start && node.stop ? text.slice(map[node.start.startIndex], map[node.stop.stopIndex + 1]) : "";
|
|
380698
380463
|
const lineOfNode = (node) => node.start?.line ?? 1;
|
|
@@ -380709,12 +380474,10 @@ function lintNotebookText(modelPath, text) {
|
|
|
380709
380474
|
let artifact;
|
|
380710
380475
|
let givensEnabled = false;
|
|
380711
380476
|
let firstGiven;
|
|
380712
|
-
const spans = [];
|
|
380713
380477
|
let closerLine;
|
|
380714
|
-
const aboveArtifact = [];
|
|
380715
380478
|
const modelNotes = [];
|
|
380716
380479
|
const docNotes = [];
|
|
380717
|
-
children.forEach((child
|
|
380480
|
+
children.forEach((child) => {
|
|
380718
380481
|
if (!isRuleNode(child)) {
|
|
380719
380482
|
const token = child?.symbol;
|
|
380720
380483
|
const name = token ? symbolOf(token) : undefined;
|
|
@@ -380727,16 +380490,11 @@ function lintNotebookText(modelPath, text) {
|
|
|
380727
380490
|
return;
|
|
380728
380491
|
}
|
|
380729
380492
|
closerLine = undefined;
|
|
380730
|
-
if (child.start && child.stop)
|
|
380731
|
-
spans.push([child.start.startIndex, child.stop.stopIndex]);
|
|
380732
380493
|
const group = callAccessor(child, "docAnnotations");
|
|
380733
380494
|
if (group) {
|
|
380734
380495
|
const notes = callAccessor(group, "docAnnotation") ?? [];
|
|
380735
380496
|
for (const note of notes) {
|
|
380736
380497
|
const noteText = nodeText(note);
|
|
380737
|
-
const route = routeOfNote(noteText);
|
|
380738
|
-
const first = noteText.split(`
|
|
380739
|
-
`, 1)[0];
|
|
380740
380498
|
const bodyText = modelNoteBody(noteText);
|
|
380741
380499
|
modelNotes.push(bodyText);
|
|
380742
380500
|
if (/^##!\s*experimental\b[\s\S]*\bgivens\b/.test(noteText))
|
|
@@ -380745,23 +380503,8 @@ function lintNotebookText(modelPath, text) {
|
|
|
380745
380503
|
if (!artifact && note.start && isArtifactNoteText(noteText)) {
|
|
380746
380504
|
artifact = {
|
|
380747
380505
|
text: bodyText,
|
|
380748
|
-
line: lineOfNode(note)
|
|
380749
|
-
startIndex: note.start.startIndex
|
|
380506
|
+
line: lineOfNode(note)
|
|
380750
380507
|
};
|
|
380751
|
-
} else if (!artifact && inNotebooks) {
|
|
380752
|
-
if (route === MARKDOWN_ROUTE || route === "text") {
|
|
380753
|
-
aboveArtifact.push({
|
|
380754
|
-
line: lineOfNode(note),
|
|
380755
|
-
code: "notebook-markdown-above-artifact",
|
|
380756
|
-
what: quoted(first)
|
|
380757
|
-
});
|
|
380758
|
-
} else if (!/^##!/.test(noteText) && !/^#{1,2}\|?"/.test(noteText)) {
|
|
380759
|
-
aboveArtifact.push({
|
|
380760
|
-
line: lineOfNode(note),
|
|
380761
|
-
code: "notebook-tag-above-artifact",
|
|
380762
|
-
what: quoted(first)
|
|
380763
|
-
});
|
|
380764
|
-
}
|
|
380765
380508
|
}
|
|
380766
380509
|
}
|
|
380767
380510
|
const last = notes[notes.length - 1];
|
|
@@ -380773,35 +380516,15 @@ function lintNotebookText(modelPath, text) {
|
|
|
380773
380516
|
if (callAccessor(child, "defineGivenStatement")) {
|
|
380774
380517
|
firstGiven ??= keywordLine(child, "GIVEN");
|
|
380775
380518
|
}
|
|
380776
|
-
if (
|
|
380519
|
+
if (linear && callAccessor(child, "runStatement")) {
|
|
380777
380520
|
const line = keywordLine(child, "RUN");
|
|
380778
380521
|
add(line, "notebook-layout-run", "a `run:` is never shown in a notebook written as tiles, whose cells are the entries in `tiles=[…]`. Fix: define the query as a `view:` on a source, list `source -> view` in `tiles`, and delete the `run:`.");
|
|
380779
380522
|
}
|
|
380780
380523
|
if (callAccessor(child, "ignoredObjectAnnotations")) {
|
|
380781
380524
|
const notes = leadingNotes(child);
|
|
380782
380525
|
for (const note of notes.filter((n) => isMarkdownNote(n.text))) {
|
|
380783
|
-
add(note.line, "notebook-markdown-attached-nowhere", `\`${quoted(note.text)}\` annotates no statement, since what follows it (the end of the file, an import or export, or a \`##\` model-level note) takes no annotation. Fix: ${
|
|
380784
|
-
}
|
|
380785
|
-
if (inNotebooks && notes.some((n) => !isMarkdownNote(n.text))) {
|
|
380786
|
-
const next = children[index + 1];
|
|
380787
|
-
const nextRun = children.slice(index + 1).find((sibling) => callAccessor(sibling, "runStatement"));
|
|
380788
|
-
add(lineOfNode(child), "notebook-orphaned-tag", `this # tag is followed by ${describeNext(next)}, not by a run:, so it annotates nothing. Render tags sit directly above their run:. Fix: move the tag, and any #" caption, directly above ${nextRun ? `the run: on line ${keywordLine(nextRun, "RUN")}` : "its run:"}.`);
|
|
380789
|
-
}
|
|
380790
|
-
} else if (inNotebooks && !artifact) {
|
|
380791
|
-
for (const note of leadingNotes(child).filter((n) => isMarkdownNote(n.text))) {
|
|
380792
|
-
aboveArtifact.push({
|
|
380793
|
-
line: note.line,
|
|
380794
|
-
code: "notebook-markdown-above-artifact",
|
|
380795
|
-
what: quoted(note.text)
|
|
380796
|
-
});
|
|
380526
|
+
add(note.line, "notebook-markdown-attached-nowhere", `\`${quoted(note.text)}\` annotates no statement, since what follows it (the end of the file, an import or export, or a \`##\` model-level note) takes no annotation. Fix: ${tileEntryFix("name")}, with the text as its body, or delete it.`, "error");
|
|
380797
380527
|
}
|
|
380798
|
-
const first = firstCodeToken(child);
|
|
380799
|
-
aboveArtifact.push({
|
|
380800
|
-
line: first?.line ?? lineOfNode(child),
|
|
380801
|
-
code: "notebook-statement-above-artifact",
|
|
380802
|
-
what: quoted(first ? text.slice(map[first.startIndex]).split(/\r?\n/, 1)[0] : nodeText(child).split(`
|
|
380803
|
-
`, 1)[0])
|
|
380804
|
-
});
|
|
380805
380528
|
}
|
|
380806
380529
|
});
|
|
380807
380530
|
if (!artifact)
|
|
@@ -380816,44 +380539,13 @@ function lintNotebookText(modelPath, text) {
|
|
|
380816
380539
|
leadingNoteLines.add(note.line);
|
|
380817
380540
|
lintBlocks();
|
|
380818
380541
|
lintHeadings();
|
|
380819
|
-
for (const { line, code, what } of aboveArtifact) {
|
|
380820
|
-
add(line, code, `\`${what}\` sits above the \`## artifact\` tag, and only \`##!\` flags, \`//\` comments and \`"\` notes may. Fix: move it below the artifact tag.`, "error");
|
|
380821
|
-
}
|
|
380822
380542
|
if (firstGiven !== undefined && !givensEnabled) {
|
|
380823
380543
|
add(firstGiven, "notebook-givens-not-enabled", "`given:` needs the givens experiment, which this file does not enable, so it does not compile. Fix: add the line `##! experimental.givens` at the top of the file.");
|
|
380824
380544
|
}
|
|
380825
|
-
|
|
380826
|
-
|
|
380827
|
-
|
|
380828
|
-
lintUnreferencedMarkdownBlocks(artifact);
|
|
380829
|
-
if (artifact && !inNotebooks)
|
|
380830
|
-
lintDescriptionBelow(artifact.line);
|
|
380831
|
-
if (inNotebooks && artifact)
|
|
380832
|
-
lintComments(artifact.startIndex);
|
|
380545
|
+
lintArtifact(artifact);
|
|
380546
|
+
lintUnreferencedMarkdownBlocks(artifact);
|
|
380547
|
+
lintDescriptionBelow(artifact.line);
|
|
380833
380548
|
return findings.sort((a, b3) => a.line - b3.line);
|
|
380834
|
-
function lintComments(from) {
|
|
380835
|
-
const all3 = tokens;
|
|
380836
|
-
const isComment = (t3) => t3.channel !== 0 && /COMMENT/.test(symbolOf(t3) ?? "");
|
|
380837
|
-
const endLine = (t3) => t3.line + (tokenText(t3).replace(/[\r\n]+$/, "").match(/\n/g)?.length ?? 0);
|
|
380838
|
-
const isNoteToken = (t3) => children.some((c3) => c3.start !== undefined && c3.stop !== undefined && t3.startIndex >= c3.start.startIndex && t3.stopIndex <= c3.stop.stopIndex && callAccessor(c3, "docAnnotations") !== undefined);
|
|
380839
|
-
const attached = [];
|
|
380840
|
-
for (let i2 = all3.length - 1;i2 >= 0; i2--) {
|
|
380841
|
-
const next = all3[i2 + 1];
|
|
380842
|
-
attached[i2] = next !== undefined && symbolOf(next) !== "EOF" && next.line === endLine(all3[i2]) + 1 && (isComment(next) ? attached[i2 + 1] : !isNoteToken(next));
|
|
380843
|
-
}
|
|
380844
|
-
all3.forEach((token, i2) => {
|
|
380845
|
-
if (!isComment(token) || token.startIndex < from)
|
|
380846
|
-
return;
|
|
380847
|
-
if (!attached[i2])
|
|
380848
|
-
return;
|
|
380849
|
-
const before = all3[i2 - 1];
|
|
380850
|
-
if (before && endLine(before) === token.line)
|
|
380851
|
-
return;
|
|
380852
|
-
if (spans.some(([lo, hi]) => token.startIndex >= lo && token.stopIndex <= hi))
|
|
380853
|
-
return;
|
|
380854
|
-
add(token.line, "notebook-comment-not-shown", "this comment sits directly above a cell but is not part of it, so the notebook does not show it. Fix: write it as a `##(markdown)` prose note, or move it inside the statement it describes.");
|
|
380855
|
-
});
|
|
380856
|
-
}
|
|
380857
380549
|
function leadingNotes(node) {
|
|
380858
380550
|
const from = node.start?.startIndex ?? 0;
|
|
380859
380551
|
const to2 = node.stop?.stopIndex ?? -1;
|
|
@@ -380876,24 +380568,6 @@ function lintNotebookText(modelPath, text) {
|
|
|
380876
380568
|
}
|
|
380877
380569
|
return notes;
|
|
380878
380570
|
}
|
|
380879
|
-
function describeNext(next) {
|
|
380880
|
-
if (!next)
|
|
380881
|
-
return "the end of the file";
|
|
380882
|
-
if (!isRuleNode(next)) {
|
|
380883
|
-
const token = next.symbol;
|
|
380884
|
-
return !token || symbolOf(token) === "EOF" ? "the end of the file" : `\`${tokenText(token)}\``;
|
|
380885
|
-
}
|
|
380886
|
-
if (callAccessor(next, "docAnnotations"))
|
|
380887
|
-
return "a note";
|
|
380888
|
-
const first = nodeText(next).trim().split(`
|
|
380889
|
-
`)[0].slice(0, 40);
|
|
380890
|
-
return `\`${first}\``;
|
|
380891
|
-
}
|
|
380892
|
-
function firstCodeToken(node) {
|
|
380893
|
-
const from = node.start?.startIndex ?? 0;
|
|
380894
|
-
const to2 = node.stop?.stopIndex ?? -1;
|
|
380895
|
-
return tokens?.find((t3) => t3.channel === 0 && t3.startIndex >= from && t3.stopIndex <= to2 && !/ANNOTATION/.test(symbolOf(t3) ?? ""));
|
|
380896
|
-
}
|
|
380897
380571
|
function keywordLine(node, keyword) {
|
|
380898
380572
|
const from = node.start?.startIndex ?? 0;
|
|
380899
380573
|
const to2 = node.stop?.stopIndex ?? -1;
|
|
@@ -380912,26 +380586,26 @@ function lintNotebookText(modelPath, text) {
|
|
|
380912
380586
|
const line = tokenText(token).replace(/\r?\n$/, "");
|
|
380913
380587
|
if (/^##"\S/.test(line)) {
|
|
380914
380588
|
const rest = quoted(line).slice(3);
|
|
380915
|
-
const fix = belowTag(token.line) ?
|
|
380589
|
+
const fix = belowTag(token.line) ? `Fix: ${tileEntryFix("name")}, with the text as its body.` : `Did you mean \`##" ${rest}\`?`;
|
|
380916
380590
|
add(token.line, "notebook-block-opener-spacing", `\`${quoted(line)}\` has no space after the route, so Malloy drops the note. ${fix}`);
|
|
380917
380591
|
continue;
|
|
380918
380592
|
}
|
|
380919
380593
|
if (/^##\(markdown\)\S/.test(line)) {
|
|
380920
|
-
const fix =
|
|
380594
|
+
const fix = `Fix: ${tileEntryFix("name")}, with the text as its body.`;
|
|
380921
380595
|
add(token.line, "notebook-block-opener-spacing", `\`${quoted(line)}\` has no space after the route, so Malloy drops the note. ${fix}`);
|
|
380922
380596
|
continue;
|
|
380923
380597
|
}
|
|
380924
380598
|
if (/^##\(?markdown\)?(?=[ \t]|$)/i.test(line) && !isMarkdownNote(line)) {
|
|
380925
|
-
add(token.line, "notebook-markdown-opener", `\`${quoted(line)}\` is not on the \`(markdown)\` route, so it is not shown as prose.
|
|
380599
|
+
add(token.line, "notebook-markdown-opener", `\`${quoted(line)}\` is not on the \`(markdown)\` route, so it is not shown as prose. Fix: ${tileEntryFix("name")}, with the text as its body.`);
|
|
380926
380600
|
continue;
|
|
380927
380601
|
}
|
|
380928
|
-
if (
|
|
380602
|
+
if (isMarkdownNote(line) || routeOfNote(line) === "text") {
|
|
380929
380603
|
add(token.line, "notebook-markdown-block-unnamed", `\`${quoted(line)}\` is a floating \`(${routeOfNote(line)})\` line, which a ${page} does not show, since its text tiles are named blocks listed in \`tiles=[…]\`. Fix: ${tileEntryFix("name")}, or delete the line.`);
|
|
380930
380604
|
continue;
|
|
380931
380605
|
}
|
|
380932
380606
|
const content = /^##[ \t]+(\S.*)$/.exec(line)?.[1];
|
|
380933
380607
|
if (content && /^[A-Za-z_]\w*[ \t]+[A-Za-z0-9_]/.test(content) && !/[={]/.test(content)) {
|
|
380934
|
-
const fix = !belowTag(token.line) ? 'Did you mean `##"`?' :
|
|
380608
|
+
const fix = !belowTag(token.line) ? 'Did you mean `##"`?' : `Fix: ${tileEntryFix("name")}, with the text as its body.`;
|
|
380935
380609
|
add(token.line, "notebook-heading-line", `\`${quoted(line)}\` is read as model tags, not shown as prose. ${fix}`);
|
|
380936
380610
|
}
|
|
380937
380611
|
}
|
|
@@ -380950,13 +380624,11 @@ function lintNotebookText(modelPath, text) {
|
|
|
380950
380624
|
return `this \`|##\` closes the block, so the text after it on line ${strayLine} is not prose and does not compile. Fix: a body line cannot start with \`|##\`, so reword it if the block should go on, or delete the stray text if the block is over.`;
|
|
380951
380625
|
}
|
|
380952
380626
|
function nestedMarkdownMessage(note) {
|
|
380953
|
-
return `\`${quoted(note)}\` sits inside a statement, where nothing reads a \`(markdown)\` note, so it is not shown. Fix:
|
|
380627
|
+
return `\`${quoted(note)}\` sits inside a statement, where nothing reads a \`(markdown)\` note, so it is not shown. Fix: a ${page} reads no attached note, so ${tileEntryFix("name")}, with the text as its body, or delete it.`;
|
|
380954
380628
|
}
|
|
380955
380629
|
function placement(sigil, line) {
|
|
380956
380630
|
if (sigil === "#" && !leadingNoteLines.has(line))
|
|
380957
|
-
return
|
|
380958
|
-
if (sigil === "##" && inNotebooks && !belowTag(line))
|
|
380959
|
-
return " It also sits above the `## artifact` tag, where a `(markdown)` note is not read, so put it below the tag.";
|
|
380631
|
+
return " It also sits inside a statement, and a dashboard reads no attached note, so use a text tile or delete it.";
|
|
380960
380632
|
return "";
|
|
380961
380633
|
}
|
|
380962
380634
|
function lintBlocks() {
|
|
@@ -380975,11 +380647,11 @@ function lintNotebookText(modelPath, text) {
|
|
|
380975
380647
|
const markdown = parseMarkdownOpener(opener);
|
|
380976
380648
|
const spelled = `(${markdown?.route})`;
|
|
380977
380649
|
const topLevel = sigil === "##" || leadingNoteLines.has(line);
|
|
380978
|
-
const dashboardTile = sigil === "##"
|
|
380650
|
+
const dashboardTile = sigil === "##";
|
|
380979
380651
|
const glued = /^("|\(markdown\))(\S.*)$/.exec(rest);
|
|
380980
380652
|
if (glued) {
|
|
380981
380653
|
const [, glueRoute, after] = glued;
|
|
380982
|
-
const description2 = glueRoute === '"'
|
|
380654
|
+
const description2 = glueRoute === '"';
|
|
380983
380655
|
const asTile = dashboardTile && (glueRoute !== '"' || belowTag(line));
|
|
380984
380656
|
const fix = !asTile ? `write \`${sigil}|${description2 ? '"' : "(markdown)"}\` and put \`${after}\` on the line below it` : TEXT_BLOCK_NAME.test(after) ? `put a space after the route, as in \`##|(markdown) ${after}\`, and list \`${after} { kind=text }\` in \`tiles\`` : tileBlockFix("name", after);
|
|
380985
380657
|
add(line, "notebook-block-opener-spacing", `\`${quoted(opener)}\` has no space after the route, so Malloy drops the note. Fix: ${fix}.${asTile || glueRoute === '"' ? "" : placement(sigil, line)}`);
|
|
@@ -380991,13 +380663,13 @@ function lintNotebookText(modelPath, text) {
|
|
|
380991
380663
|
add(line, "notebook-markdown-opener-text", `\`${quoted(markdown.rest)}\` is not a valid name for a \`${spelled}\` tile, which takes one bare word of letters, digits and underscores that does not start with a digit. Fix: ${tileEntryFix(asTileName(markdown.rest))}.`, "error");
|
|
380992
380664
|
} else if (opensText) {
|
|
380993
380665
|
add(line, "notebook-markdown-opener-text", `\`${quoted(markdown.rest)}\` follows \`${sigil}|${spelled}\` on its opener line, where only one bare word may go (a name), so the block would show it as its first line. Fix: ${dashboardTile ? tileBlockFix("name", markdown.rest) : "move it into the body, on the line below the opener"}.${placement(sigil, line)}`, "error");
|
|
380994
|
-
} else if (markdown.name &&
|
|
380995
|
-
add(line, "notebook-markdown-block-named", `the name \`${markdown.name}\` on this \`${spelled}\` block means nothing
|
|
380666
|
+
} else if (markdown.name && sigil === "#") {
|
|
380667
|
+
add(line, "notebook-markdown-block-named", `the name \`${markdown.name}\` on this \`${spelled}\` block means nothing on a block attached to a statement, and it is not shown. Fix: remove the name.`);
|
|
380996
380668
|
} else if (!markdown.name && dashboardTile) {
|
|
380997
380669
|
add(line, "notebook-markdown-block-unnamed", `an unnamed \`${spelled}\` block is not shown on a ${page}, whose text tiles are named blocks listed in \`tiles=[…]\`. Fix: ${tileEntryFix("name")}, or delete the block.`);
|
|
380998
380670
|
}
|
|
380999
380671
|
} else if (/^[ \t]*\(?markdown\)?(?=[ \t]|$)/i.test(rest)) {
|
|
381000
|
-
add(line, "notebook-markdown-opener", `\`${opener.trim()}\` opens a block that is not on the \`(markdown)\` route, so its body is not ${sigil === "#" ? "the statement's prose" :
|
|
380672
|
+
add(line, "notebook-markdown-opener", `\`${opener.trim()}\` opens a block that is not on the \`(markdown)\` route, so its body is not ${sigil === "#" ? "the statement's prose" : "a text tile"}. ${dashboardTile ? `Fix: ${tileEntryFix("name")}.` : `Did you mean \`${sigil}|(markdown)\`?${placement(sigil, line)}`}`);
|
|
381001
380673
|
}
|
|
381002
380674
|
let j3 = i2 + 1;
|
|
381003
380675
|
let firstRun;
|
|
@@ -381020,7 +380692,7 @@ function lintNotebookText(modelPath, text) {
|
|
|
381020
380692
|
}
|
|
381021
380693
|
const trailing = tokenText(end).replace(closer, "").trim();
|
|
381022
380694
|
if (tokenText(end).startsWith(closer) && trailing) {
|
|
381023
|
-
const own2 = sigil !== "##" ? "" : !belowTag(end.line) ? 'on its own `##"` line, or ' :
|
|
380695
|
+
const own2 = sigil !== "##" ? "" : !belowTag(end.line) ? 'on its own `##"` line, or ' : `in its own text tile (${tileEntryFix("name")}), or `;
|
|
381024
380696
|
add(end.line, "notebook-text-after-closer", `the text after the closing \`${closer}\` (\`${trailing}\`) is dropped, not shown. Fix: put it ${own2}inside the block.`);
|
|
381025
380697
|
}
|
|
381026
380698
|
}
|
|
@@ -381036,23 +380708,35 @@ function lintNotebookText(modelPath, text) {
|
|
|
381036
380708
|
}
|
|
381037
380709
|
function lintLayout(line, declaredLayout) {
|
|
381038
380710
|
if (declaredLayout !== undefined && declaredLayout !== "grid" && declaredLayout !== "linear") {
|
|
381039
|
-
add(line,
|
|
381040
|
-
}
|
|
381041
|
-
if (tag.status === "report" && tag.decidedBy === "default") {
|
|
381042
|
-
add(line, "report-layout-implicit", "this artifact tag names no `layout` and lists no tiles, so the report is linear only by default. Fix: write `## artifact { layout=linear }` (or `layout=grid` with `tiles=[…]`).");
|
|
380711
|
+
add(line, LAYOUT_UNKNOWN, `\`layout=${declaredLayout}\` is not a layout Publisher knows (grid, linear), so the tag's other properties decide it. Fix: write \`layout=grid\` or \`layout=linear\`.`, "error");
|
|
381043
380712
|
}
|
|
381044
380713
|
}
|
|
381045
380714
|
function tagFinding(tagNote) {
|
|
381046
|
-
const [
|
|
381047
|
-
const kind = tag.status === "kind-removed" ? tag.kind : undefined;
|
|
381048
|
-
const message = kind !== undefined ? `\`kind=${kind}\` is no longer read, so this file is not a report. Fix: remove \`kind=${kind}\` and write \`layout=grid\` or \`layout=linear\`.` : `the \`## artifact\` tag does not parse${parseError !== undefined ? ` (${parseError})` : ""}, so its properties are not read and this file is not a report. ${/\btiles\s*=/.test(tagNote.text) ? TILE_ENTRY_FIX : "Fix: correct the tag so it parses."}`;
|
|
380715
|
+
const [code, message] = tagFindingText(tagNote.text);
|
|
381049
380716
|
return {
|
|
381050
380717
|
line: tagNote.line,
|
|
381051
|
-
code
|
|
380718
|
+
code,
|
|
381052
380719
|
severity: "error",
|
|
381053
380720
|
message: `Line ${tagNote.line}: ${message}`
|
|
381054
380721
|
};
|
|
381055
380722
|
}
|
|
380723
|
+
function tagFindingText(tagText2) {
|
|
380724
|
+
if (tag.status === "kind-removed")
|
|
380725
|
+
return [
|
|
380726
|
+
"report-kind-removed",
|
|
380727
|
+
`\`kind=${tag.kind}\` is no longer read, so this file is not a report. Fix: remove \`kind=${tag.kind}\` and write \`layout=grid\` or \`layout=linear\`.`
|
|
380728
|
+
];
|
|
380729
|
+
if (tag.status === "cells-removed")
|
|
380730
|
+
return tag.unknownLayout !== undefined ? [
|
|
380731
|
+
LAYOUT_UNKNOWN,
|
|
380732
|
+
`\`layout=${tag.unknownLayout}\` is not a layout Publisher knows (grid, linear), and the tag lists no tiles, so this file is not a report. Fix: write \`layout=grid\` or \`layout=linear\`, and list the tiles in \`tiles=[…]\`.`
|
|
380733
|
+
] : [CELLS_REMOVED, CELLS_REMOVED_MESSAGE];
|
|
380734
|
+
const [parseError] = motlyParseErrors([tagText2]);
|
|
380735
|
+
return [
|
|
380736
|
+
"notebook-artifact-unparsed",
|
|
380737
|
+
`the \`## artifact\` tag does not parse${parseError !== undefined ? ` (${parseError})` : ""}, so its properties are not read and this file is not a report. ${/\btiles\s*=/.test(tagText2) ? TILE_ENTRY_FIX : "Fix: correct the tag so it parses."}`
|
|
380738
|
+
];
|
|
380739
|
+
}
|
|
381056
380740
|
function lintUnreferencedMarkdownBlocks(tagNote) {
|
|
381057
380741
|
if (motlyParseErrors([tagNote.text])[0] !== undefined)
|
|
381058
380742
|
return;
|
|
@@ -381076,9 +380760,7 @@ function lintNotebookText(modelPath, text) {
|
|
|
381076
380760
|
return;
|
|
381077
380761
|
const properties = Object.keys(tag2.dict ?? {});
|
|
381078
380762
|
lintLayout(tagNote.line, tagText(tag2, "layout"));
|
|
381079
|
-
if (
|
|
381080
|
-
return;
|
|
381081
|
-
if (layoutNotebook) {
|
|
380763
|
+
if (linear) {
|
|
381082
380764
|
for (const entry of tag2.array("tiles") ?? []) {
|
|
381083
380765
|
const ignored = ["colspan", "break"].filter((p2) => entry.has(p2));
|
|
381084
380766
|
if (ignored.length === 0)
|
|
@@ -381087,7 +380769,7 @@ function lintNotebookText(modelPath, text) {
|
|
|
381087
380769
|
}
|
|
381088
380770
|
}
|
|
381089
380771
|
const columns = motlyTag(modelNotes)?.tag("dashboard");
|
|
381090
|
-
if (
|
|
380772
|
+
if (linear && columns?.has("columns")) {
|
|
381091
380773
|
const width = tagNumeric(columns, "columns");
|
|
381092
380774
|
if (width !== 1) {
|
|
381093
380775
|
add(tagNote.line, "notebook-columns-ignored", "`dashboard { columns }` other than 1 is ignored on a notebook, which is always one column. Fix: remove `dashboard { columns }`.");
|
|
@@ -381126,6 +380808,286 @@ function notebookLintProblems(modelPath, text, url3) {
|
|
|
381126
380808
|
});
|
|
381127
380809
|
}
|
|
381128
380810
|
|
|
380811
|
+
// src/service/compile_document.ts
|
|
380812
|
+
var DECLARATION = /\b(?:source|query)\s*:\s*(`(?:[^`\\]|\\.)*`|[\p{L}_][\p{L}\p{N}_]*)\s+is\b/giu;
|
|
380813
|
+
function blankSpans(text, cells) {
|
|
380814
|
+
if (cells.length === 0)
|
|
380815
|
+
return text;
|
|
380816
|
+
const units = text.split("");
|
|
380817
|
+
for (const cell of cells) {
|
|
380818
|
+
const span = cellOffsets.get(cell);
|
|
380819
|
+
if (!span)
|
|
380820
|
+
throw new Error("restricted cell has no recorded span");
|
|
380821
|
+
const [start, end] = span;
|
|
380822
|
+
for (let i2 = start;i2 < end && i2 < units.length; i2++) {
|
|
380823
|
+
if (units[i2] !== `
|
|
380824
|
+
` && units[i2] !== "\r")
|
|
380825
|
+
units[i2] = " ";
|
|
380826
|
+
}
|
|
380827
|
+
}
|
|
380828
|
+
return units.join("");
|
|
380829
|
+
}
|
|
380830
|
+
function declaredNames(text) {
|
|
380831
|
+
const found = new Set(buildDerivationBaseMap(text).keys());
|
|
380832
|
+
for (const match of stripMalloyCommentsAndLiterals(text).matchAll(DECLARATION)) {
|
|
380833
|
+
const name = match[1];
|
|
380834
|
+
found.add(name.startsWith("`") ? name.slice(1, -1) : name);
|
|
380835
|
+
}
|
|
380836
|
+
return found;
|
|
380837
|
+
}
|
|
380838
|
+
function readsSource(prepared) {
|
|
380839
|
+
const ref = prepared._query?.structRef;
|
|
380840
|
+
if (typeof ref === "string")
|
|
380841
|
+
return ref;
|
|
380842
|
+
const named = ref;
|
|
380843
|
+
return named?.as || named?.name;
|
|
380844
|
+
}
|
|
380845
|
+
async function denied(gates, text) {
|
|
380846
|
+
try {
|
|
380847
|
+
await gates.text(text);
|
|
380848
|
+
return false;
|
|
380849
|
+
} catch (error2) {
|
|
380850
|
+
if (error2 instanceof AccessDeniedError)
|
|
380851
|
+
return true;
|
|
380852
|
+
throw error2;
|
|
380853
|
+
}
|
|
380854
|
+
}
|
|
380855
|
+
function tileProblem(expression, reason, cause) {
|
|
380856
|
+
return {
|
|
380857
|
+
code: "tile-does-not-compile",
|
|
380858
|
+
severity: "error",
|
|
380859
|
+
message: `Tile "${expression}" ${cause === "parse" ? "could not be parsed" : "does not compile"}: ${reason.replace(/\.?\s*$/, ".")} ` + `Fix: write the tile as one query over a source and a view, such as \`source -> view\` or \`source -> { group_by: field }\`.`
|
|
380860
|
+
};
|
|
380861
|
+
}
|
|
380862
|
+
function problemLine(problem) {
|
|
380863
|
+
const line = problem.at?.range?.start?.line;
|
|
380864
|
+
return line === undefined ? undefined : line + 1;
|
|
380865
|
+
}
|
|
380866
|
+
function cellsRemovedProblems(source) {
|
|
380867
|
+
const problems = notebookLintProblems("document.malloy", source, "").filter((problem) => problem.code === CELLS_REMOVED || problem.code === LAYOUT_UNKNOWN);
|
|
380868
|
+
return problems.length > 0 ? problems : [
|
|
380869
|
+
{
|
|
380870
|
+
code: CELLS_REMOVED,
|
|
380871
|
+
severity: "error",
|
|
380872
|
+
message: CELLS_REMOVED_MESSAGE
|
|
380873
|
+
}
|
|
380874
|
+
];
|
|
380875
|
+
}
|
|
380876
|
+
async function compileDocument(input) {
|
|
380877
|
+
const { base, source, modelName, gates } = input;
|
|
380878
|
+
const tag = readReportTagOfText(source);
|
|
380879
|
+
if (tag.status === "cells-removed")
|
|
380880
|
+
return { problems: cellsRemovedProblems(source) };
|
|
380881
|
+
if (tag.status !== "report")
|
|
380882
|
+
return;
|
|
380883
|
+
const parse5 = parseNotebookText(source);
|
|
380884
|
+
if (isNotebookReaderError(parse5))
|
|
380885
|
+
return;
|
|
380886
|
+
const read = readNotebookCells(parse5, undefined, source);
|
|
380887
|
+
if (read.error) {
|
|
380888
|
+
return { problems: [cellsUnreadableProblem(read.error, "")] };
|
|
380889
|
+
}
|
|
380890
|
+
const code = read.cells.filter((cell) => cell.type === "code");
|
|
380891
|
+
const restrictedCells = new Set;
|
|
380892
|
+
const tainted = new Set;
|
|
380893
|
+
const mentionsTainted = (text) => tainted.size > 0 && [...scanIdentifiers(text)].some((name) => tainted.has(name));
|
|
380894
|
+
for (const cell of code) {
|
|
380895
|
+
if (mentionsTainted(cell.text) || await denied(gates, cell.text)) {
|
|
380896
|
+
restrictedCells.add(cell);
|
|
380897
|
+
if (cell.kind === "definition") {
|
|
380898
|
+
for (const name of declaredNames(cell.text))
|
|
380899
|
+
tainted.add(name);
|
|
380900
|
+
}
|
|
380901
|
+
}
|
|
380902
|
+
}
|
|
380903
|
+
const tileExpressions = readDocumentTileExpressions(read.annotations);
|
|
380904
|
+
const restrictedTiles = new Set;
|
|
380905
|
+
for (const expression of tileExpressions) {
|
|
380906
|
+
const text = `run: ${expression}`;
|
|
380907
|
+
if (mentionsTainted(text) || await denied(gates, text)) {
|
|
380908
|
+
restrictedTiles.add(normalizeTileExpression(expression));
|
|
380909
|
+
}
|
|
380910
|
+
}
|
|
380911
|
+
const definitions = code.filter((cell) => cell.kind === "definition" && !restrictedCells.has(cell)).map((cell) => cell.text).join(`
|
|
380912
|
+
`);
|
|
380913
|
+
const unparsedTiles = new Set;
|
|
380914
|
+
const tileProblems = [];
|
|
380915
|
+
for (const expression of tileExpressions) {
|
|
380916
|
+
const key = normalizeTileExpression(expression);
|
|
380917
|
+
if (restrictedTiles.has(key))
|
|
380918
|
+
continue;
|
|
380919
|
+
try {
|
|
380920
|
+
await gates.constructs(`${definitions}
|
|
380921
|
+
run: ${expression}`);
|
|
380922
|
+
} catch (error2) {
|
|
380923
|
+
if (!(error2 instanceof UnparseableTextError))
|
|
380924
|
+
throw error2;
|
|
380925
|
+
unparsedTiles.add(key);
|
|
380926
|
+
tileProblems.push(tileProblem(expression, error2.detail, "parse"));
|
|
380927
|
+
}
|
|
380928
|
+
}
|
|
380929
|
+
const boundaryProblems = [];
|
|
380930
|
+
const checkBoundary = async (query, line) => {
|
|
380931
|
+
try {
|
|
380932
|
+
await gates.boundary(query, definitions);
|
|
380933
|
+
} catch (error2) {
|
|
380934
|
+
if (!(error2 instanceof OffSurfaceError))
|
|
380935
|
+
throw error2;
|
|
380936
|
+
boundaryProblems.push({
|
|
380937
|
+
code: "query-not-queryable",
|
|
380938
|
+
severity: "error",
|
|
380939
|
+
message: error2.message,
|
|
380940
|
+
...line !== undefined && {
|
|
380941
|
+
at: {
|
|
380942
|
+
url: "",
|
|
380943
|
+
range: {
|
|
380944
|
+
start: { line: line - 1, character: 0 },
|
|
380945
|
+
end: { line: line - 1, character: 0 }
|
|
380946
|
+
}
|
|
380947
|
+
}
|
|
380948
|
+
}
|
|
380949
|
+
});
|
|
380950
|
+
}
|
|
380951
|
+
};
|
|
380952
|
+
for (const cell of code) {
|
|
380953
|
+
if (cell.kind === "query" && !restrictedCells.has(cell)) {
|
|
380954
|
+
await checkBoundary(cell.text, cell.startLine);
|
|
380955
|
+
}
|
|
380956
|
+
}
|
|
380957
|
+
for (const expression of tileExpressions) {
|
|
380958
|
+
const key = normalizeTileExpression(expression);
|
|
380959
|
+
if (!restrictedTiles.has(key) && !unparsedTiles.has(key)) {
|
|
380960
|
+
await checkBoundary(`run: ${expression}`, undefined);
|
|
380961
|
+
}
|
|
380962
|
+
}
|
|
380963
|
+
if (boundaryProblems.length > 0)
|
|
380964
|
+
return { problems: boundaryProblems };
|
|
380965
|
+
const readable = [
|
|
380966
|
+
...code.filter((cell) => cell.kind === "query" && !restrictedCells.has(cell)).map((cell) => cell.text),
|
|
380967
|
+
...tileExpressions.filter((expression) => {
|
|
380968
|
+
const key = normalizeTileExpression(expression);
|
|
380969
|
+
return !restrictedTiles.has(key) && !unparsedTiles.has(key);
|
|
380970
|
+
}).map((expression) => `run: ${expression}`)
|
|
380971
|
+
];
|
|
380972
|
+
for (const query of readable.length > 0 ? readable : [""]) {
|
|
380973
|
+
gates.nameVisible(query, definitions);
|
|
380974
|
+
}
|
|
380975
|
+
const compiledText = blankSpans(source, [...restrictedCells]);
|
|
380976
|
+
await gates.document(compiledText);
|
|
380977
|
+
const extended = base.extendModel(compiledText);
|
|
380978
|
+
let model;
|
|
380979
|
+
try {
|
|
380980
|
+
model = await extended.getModel();
|
|
380981
|
+
} catch (error2) {
|
|
380982
|
+
if (error2 instanceof MalloyError4)
|
|
380983
|
+
return { problems: [...tileProblems, ...error2.problems] };
|
|
380984
|
+
throw error2;
|
|
380985
|
+
}
|
|
380986
|
+
const modelDef = model._modelDef;
|
|
380987
|
+
const registry2 = modelDef.givens ?? {};
|
|
380988
|
+
const sources = extractSourcesFromModelDef(modelDef, []).sources;
|
|
380989
|
+
const settle2 = async (runnable, onDenied) => {
|
|
380990
|
+
try {
|
|
380991
|
+
await gates.compiled(runnable);
|
|
380992
|
+
} catch (error2) {
|
|
380993
|
+
if (error2 instanceof AccessDeniedError)
|
|
380994
|
+
onDenied();
|
|
380995
|
+
else
|
|
380996
|
+
throw error2;
|
|
380997
|
+
}
|
|
380998
|
+
};
|
|
380999
|
+
const compiledBoundary = async (runnable, prepared, query) => {
|
|
381000
|
+
try {
|
|
381001
|
+
await gates.boundaryCompiled(runnable, readsSource(prepared), query, definitions);
|
|
381002
|
+
} catch (error2) {
|
|
381003
|
+
if (!(error2 instanceof OffSurfaceError))
|
|
381004
|
+
throw error2;
|
|
381005
|
+
boundaryProblems.push({
|
|
381006
|
+
code: "query-not-queryable",
|
|
381007
|
+
severity: "error",
|
|
381008
|
+
message: error2.message
|
|
381009
|
+
});
|
|
381010
|
+
}
|
|
381011
|
+
};
|
|
381012
|
+
for (const cell of code) {
|
|
381013
|
+
if (cell.kind !== "query" || restrictedCells.has(cell))
|
|
381014
|
+
continue;
|
|
381015
|
+
const runnable = extended.loadRestrictedQuery(cell.text);
|
|
381016
|
+
let denied2 = false;
|
|
381017
|
+
await settle2(runnable, () => {
|
|
381018
|
+
denied2 = true;
|
|
381019
|
+
restrictedCells.add(cell);
|
|
381020
|
+
});
|
|
381021
|
+
if (denied2)
|
|
381022
|
+
continue;
|
|
381023
|
+
try {
|
|
381024
|
+
await compiledBoundary(runnable, await runnable.getPreparedQuery(), cell.text);
|
|
381025
|
+
} catch (error2) {
|
|
381026
|
+
if (!(error2 instanceof MalloyError4))
|
|
381027
|
+
throw error2;
|
|
381028
|
+
}
|
|
381029
|
+
}
|
|
381030
|
+
const compiledTiles = await compileTileGivens(tileExpressions, { loadQuery: (text) => extended.loadRestrictedQuery(text) }, registry2, (sourceName) => gateGivenSource(sources, sourceName), new Set([...restrictedTiles, ...unparsedTiles]), async (tile, prepared) => {
|
|
381031
|
+
let denied2 = false;
|
|
381032
|
+
await settle2({ getPreparedQuery: async () => prepared }, () => {
|
|
381033
|
+
denied2 = true;
|
|
381034
|
+
restrictedTiles.add(normalizeTileExpression(tile));
|
|
381035
|
+
});
|
|
381036
|
+
if (!denied2) {
|
|
381037
|
+
await compiledBoundary({ getPreparedQuery: async () => prepared }, prepared, `run: ${tile}`);
|
|
381038
|
+
}
|
|
381039
|
+
}, (tile, error2) => {
|
|
381040
|
+
if (!(error2 instanceof MalloyError4))
|
|
381041
|
+
return;
|
|
381042
|
+
gates.nameVisible(`run: ${tile}`, definitions);
|
|
381043
|
+
tileProblems.push(tileProblem(tile, error2.problems.map((problem) => problem.message).join("; "), "compile"));
|
|
381044
|
+
});
|
|
381045
|
+
if (boundaryProblems.length > 0)
|
|
381046
|
+
return { problems: boundaryProblems };
|
|
381047
|
+
const spans = [...restrictedCells];
|
|
381048
|
+
const problems = [...tileProblems, ...model.problems].filter((problem) => {
|
|
381049
|
+
const line = problemLine(problem);
|
|
381050
|
+
return line === undefined || !spans.some((cell) => line >= cell.startLine && line <= cell.endLine);
|
|
381051
|
+
});
|
|
381052
|
+
const slug = modelName.replace(/^.*\//, "").replace(/\.malloy$/, "");
|
|
381053
|
+
const path13 = `${slug}.malloy`;
|
|
381054
|
+
const facts = readReportModelFacts(path13, modelDef, Object.values(registry2).map((given) => given.name), new Map(sources.flatMap((entry) => entry.name ? [
|
|
381055
|
+
[
|
|
381056
|
+
entry.name,
|
|
381057
|
+
gateGivenSource(sources, entry.name) ?? []
|
|
381058
|
+
]
|
|
381059
|
+
] : [])));
|
|
381060
|
+
const manifest = buildReportManifest({ ...facts, compiledTileGivens: compiledTiles }, { restrictedTiles });
|
|
381061
|
+
const cells = read.cells.filter((cell) => cell.kind === "definition").map((cell) => {
|
|
381062
|
+
const restricted = restrictedCells.has(cell);
|
|
381063
|
+
if (cell.kind === "markdown") {
|
|
381064
|
+
return { type: "markdown", kind: "markdown", text: cell.text };
|
|
381065
|
+
}
|
|
381066
|
+
return {
|
|
381067
|
+
type: "code",
|
|
381068
|
+
kind: cell.kind,
|
|
381069
|
+
text: cell.text,
|
|
381070
|
+
...cell.markdown !== undefined && { markdown: cell.markdown },
|
|
381071
|
+
...cell.proseLines && { proseLines: cell.proseLines },
|
|
381072
|
+
...cell.codeLine !== undefined && { codeLine: cell.codeLine },
|
|
381073
|
+
...cell.caption !== undefined && { caption: cell.caption },
|
|
381074
|
+
...restricted && { restricted: true }
|
|
381075
|
+
};
|
|
381076
|
+
});
|
|
381077
|
+
if (!manifest) {
|
|
381078
|
+
return { problems, document: { layout: tag.layout, cells } };
|
|
381079
|
+
}
|
|
381080
|
+
const { entryFile: _entry, ...rest } = manifest;
|
|
381081
|
+
return {
|
|
381082
|
+
problems,
|
|
381083
|
+
document: {
|
|
381084
|
+
layout: manifest.layout,
|
|
381085
|
+
manifest: { ...rest, name: slug },
|
|
381086
|
+
cells
|
|
381087
|
+
}
|
|
381088
|
+
};
|
|
381089
|
+
}
|
|
381090
|
+
|
|
381129
381091
|
// src/service/environment.ts
|
|
381130
381092
|
init_constants();
|
|
381131
381093
|
init_errors();
|
|
@@ -385488,7 +385450,7 @@ function assertEveryCallerJoinPlaced(prepared, found, isCaller) {
|
|
|
385488
385450
|
}
|
|
385489
385451
|
}
|
|
385490
385452
|
}
|
|
385491
|
-
function derivationTerminals(start, basesOf, isModelSource, maxNames = DERIVATION_CHAIN_MAX_NAMES) {
|
|
385453
|
+
function derivationTerminals(start, basesOf, isModelSource, maxNames = DERIVATION_CHAIN_MAX_NAMES, modelQuerySource) {
|
|
385492
385454
|
const seen = new Set;
|
|
385493
385455
|
const terminals = [];
|
|
385494
385456
|
const worklist = [start];
|
|
@@ -385504,8 +385466,13 @@ function derivationTerminals(start, basesOf, isModelSource, maxNames = DERIVATIO
|
|
|
385504
385466
|
continue;
|
|
385505
385467
|
}
|
|
385506
385468
|
const bases = basesOf.get(name);
|
|
385507
|
-
if (!bases || bases.size === 0)
|
|
385508
|
-
|
|
385469
|
+
if (!bases || bases.size === 0) {
|
|
385470
|
+
const querySource = modelQuerySource?.(name);
|
|
385471
|
+
if (!querySource)
|
|
385472
|
+
return { proven: false, at: name };
|
|
385473
|
+
worklist.push(querySource);
|
|
385474
|
+
continue;
|
|
385475
|
+
}
|
|
385509
385476
|
for (const base of bases)
|
|
385510
385477
|
worklist.push(base);
|
|
385511
385478
|
}
|
|
@@ -385530,7 +385497,7 @@ function resolveCallerJoin(callerJoin, compiledModelDef, region, context) {
|
|
|
385530
385497
|
if (forBoundary)
|
|
385531
385498
|
boundaryNames.add(name);
|
|
385532
385499
|
};
|
|
385533
|
-
const chainOf = (start) => derivationTerminals(start, text.derivations(), (name) => context.isModelSource(name));
|
|
385500
|
+
const chainOf = (start) => derivationTerminals(start, text.derivations(), (name) => context.isModelSource(name), undefined, (name) => context.modelQuerySource(name));
|
|
385534
385501
|
const byContentsKey = (key, forBoundary) => {
|
|
385535
385502
|
const entry = contentsStruct(compiledModelDef, key);
|
|
385536
385503
|
if (entry && isCaller(entry.location)) {
|
|
@@ -386160,7 +386127,47 @@ function fieldUsageClosure(declaring, refSummary) {
|
|
|
386160
386127
|
}
|
|
386161
386128
|
return { paths, truncated: false };
|
|
386162
386129
|
}
|
|
386163
|
-
function
|
|
386130
|
+
function isCompositePlaceholder(field) {
|
|
386131
|
+
return field.e?.node === "compositeField";
|
|
386132
|
+
}
|
|
386133
|
+
function isComposite(struct) {
|
|
386134
|
+
return struct?.type === "composite";
|
|
386135
|
+
}
|
|
386136
|
+
function compositeMembers(composite, out = [], depth = 0) {
|
|
386137
|
+
if (depth > MAX_JOIN_RECURSION_DEPTH)
|
|
386138
|
+
return out;
|
|
386139
|
+
const members = composite.sources;
|
|
386140
|
+
for (const member of members ?? []) {
|
|
386141
|
+
out.push(member);
|
|
386142
|
+
if (isComposite(member))
|
|
386143
|
+
compositeMembers(member, out, depth + 1);
|
|
386144
|
+
}
|
|
386145
|
+
return out;
|
|
386146
|
+
}
|
|
386147
|
+
function withCompositeMembersResolved(declaring, executed, composite) {
|
|
386148
|
+
if (!composite || !isComposite(declaring) || !isComposite(composite)) {
|
|
386149
|
+
return declaring;
|
|
386150
|
+
}
|
|
386151
|
+
const leaf = (member) => !isComposite(member);
|
|
386152
|
+
const declared = new Set(compositeMembers(declaring).filter(leaf).map((member) => JSON.stringify(strip(member))));
|
|
386153
|
+
const memberFields = new Set(compositeMembers(composite).filter((member) => leaf(member) && declared.has(JSON.stringify(strip(member)))).flatMap((member) => member.fields ?? []));
|
|
386154
|
+
let resolved = false;
|
|
386155
|
+
const fields = (declaring.fields ?? []).map((field) => {
|
|
386156
|
+
if (!isCompositePlaceholder(field))
|
|
386157
|
+
return field;
|
|
386158
|
+
const executedField = executed.fields?.find((f5) => activeName2(f5) === activeName2(field));
|
|
386159
|
+
if (!executedField || !memberFields.has(executedField))
|
|
386160
|
+
return field;
|
|
386161
|
+
resolved = true;
|
|
386162
|
+
return executedField;
|
|
386163
|
+
});
|
|
386164
|
+
return resolved ? { ...declaring, fields } : declaring;
|
|
386165
|
+
}
|
|
386166
|
+
function membersDeclaringCondition(composite, condition) {
|
|
386167
|
+
return compositeMembers(composite).filter((member) => member.filterList?.includes(condition));
|
|
386168
|
+
}
|
|
386169
|
+
function assertFilterConditionBindsToDeclaringSource(declaringStructAsWritten, executedStruct, condition, executedComposite = undefined) {
|
|
386170
|
+
const declaringStruct = withCompositeMembersResolved(declaringStructAsWritten, executedStruct, executedComposite);
|
|
386164
386171
|
const { paths, truncated, unrecordedJoin } = fieldUsageClosure(declaringStruct, condition.refSummary);
|
|
386165
386172
|
if (truncated) {
|
|
386166
386173
|
throw new Error("a row-security filter's field-usage closure exceeded the resolution bound");
|
|
@@ -386429,13 +386436,14 @@ function isOwnFreshFilter(struct, condition, freshness) {
|
|
|
386429
386436
|
}
|
|
386430
386437
|
return !!freshness.compiledUrl && at2.url === freshness.compiledUrl;
|
|
386431
386438
|
}
|
|
386432
|
-
function assertInheritedSourceFiltersBind(struct, modelDef, freshness = {}, resolveSibling = undefined, depth = 0, visited = new Set, alreadyProven = new Set) {
|
|
386439
|
+
function assertInheritedSourceFiltersBind(struct, modelDef, freshness = {}, resolveSibling = undefined, depth = 0, visited = new Set, alreadyProven = new Set, unresolved = undefined) {
|
|
386433
386440
|
if (visited.has(struct))
|
|
386434
386441
|
return;
|
|
386435
386442
|
if (depth > MAX_JOIN_RECURSION_DEPTH) {
|
|
386436
386443
|
throw new Error("row-security filter recursion exceeded the join-depth resolution bound");
|
|
386437
386444
|
}
|
|
386438
386445
|
visited.add(struct);
|
|
386446
|
+
const composite = isComposite(unresolved) ? unresolved : undefined;
|
|
386439
386447
|
for (const condition of struct.filterList ?? []) {
|
|
386440
386448
|
if (alreadyProven.has(condition))
|
|
386441
386449
|
continue;
|
|
@@ -386443,16 +386451,24 @@ function assertInheritedSourceFiltersBind(struct, modelDef, freshness = {}, reso
|
|
|
386443
386451
|
continue;
|
|
386444
386452
|
const origin2 = findFilterOrigin(struct, condition, modelDef, resolveSibling);
|
|
386445
386453
|
if (origin2 !== struct) {
|
|
386446
|
-
assertFilterConditionBindsToDeclaringSource(origin2, struct, condition);
|
|
386454
|
+
assertFilterConditionBindsToDeclaringSource(origin2, struct, condition, composite);
|
|
386447
386455
|
continue;
|
|
386448
386456
|
}
|
|
386449
386457
|
if (isOwnFreshFilter(struct, condition, freshness))
|
|
386450
386458
|
continue;
|
|
386459
|
+
const members = composite ? membersDeclaringCondition(composite, condition) : [];
|
|
386460
|
+
if (members.length > 0) {
|
|
386461
|
+
for (const member of members) {
|
|
386462
|
+
assertFilterConditionBindsToDeclaringSource(member, struct, condition);
|
|
386463
|
+
}
|
|
386464
|
+
continue;
|
|
386465
|
+
}
|
|
386451
386466
|
throw new Error("a row-security filter's declaring source could not be resolved");
|
|
386452
386467
|
}
|
|
386453
386468
|
for (const field of struct.fields ?? []) {
|
|
386454
386469
|
if (isJoined6(field) && isSourceDef8(field)) {
|
|
386455
|
-
|
|
386470
|
+
const unresolvedJoin = unresolved?.fields?.find((f5) => isJoined6(f5) && activeName2(f5) === activeName2(field));
|
|
386471
|
+
assertInheritedSourceFiltersBind(field, modelDef, freshness, resolveSibling, depth + 1, visited, alreadyProven, unresolvedJoin);
|
|
386456
386472
|
}
|
|
386457
386473
|
}
|
|
386458
386474
|
}
|
|
@@ -386670,6 +386686,9 @@ class Model {
|
|
|
386670
386686
|
preaggregateRollupPlans = [];
|
|
386671
386687
|
preaggregatePlansVersion = 0;
|
|
386672
386688
|
compiledSourceText;
|
|
386689
|
+
reportModelFacts;
|
|
386690
|
+
reportTagCarried;
|
|
386691
|
+
sharedQueryModels = new WeakMap;
|
|
386673
386692
|
compiledReportFacts;
|
|
386674
386693
|
settledCompiledReportFacts;
|
|
386675
386694
|
sources;
|
|
@@ -387020,13 +387039,15 @@ class Model {
|
|
|
387020
387039
|
await this.authorizeAndBindRunnable(runnable, givens, {
|
|
387021
387040
|
bypassAuthorize,
|
|
387022
387041
|
checkOnly: options?.checkOnly,
|
|
387042
|
+
compileCallerText: options?.callerRegion?.text,
|
|
387023
387043
|
callerJoins: options?.callerRegion ? {
|
|
387024
387044
|
runnable,
|
|
387025
387045
|
region: options.callerRegion
|
|
387026
387046
|
} : undefined
|
|
387027
387047
|
});
|
|
387028
387048
|
}
|
|
387029
|
-
async collectAuthorizeEntryPointGates(runnable, givens, graftScope,
|
|
387049
|
+
async collectAuthorizeEntryPointGates(runnable, givens, graftScope, options = {}) {
|
|
387050
|
+
const { skipOwnSourceGate = false, callerText } = options;
|
|
387030
387051
|
const ownSourceName = await this.resolveAuthorizeSourceFromRunnable(runnable);
|
|
387031
387052
|
if (!skipOwnSourceGate) {
|
|
387032
387053
|
await this.assertAuthorized(ownSourceName, givens, false, graftScope);
|
|
@@ -387049,8 +387070,29 @@ class Model {
|
|
|
387049
387070
|
entryPointGates = Array.from(byKey.values());
|
|
387050
387071
|
}
|
|
387051
387072
|
}
|
|
387073
|
+
if (callerText && !skipOwnSourceGate && ownSourceName) {
|
|
387074
|
+
entryPointGates = this.foldRequestDeclaredTwins(ownSourceName, callerText, entryPointGates);
|
|
387075
|
+
}
|
|
387052
387076
|
return { entryPointGates, modelDef, struct };
|
|
387053
387077
|
}
|
|
387078
|
+
foldRequestDeclaredTwins(ownSourceName, callerText, walked) {
|
|
387079
|
+
if (this.entryPointGatesBySource.has(ownSourceName))
|
|
387080
|
+
return walked;
|
|
387081
|
+
const proof = this.requestChainGates(ownSourceName, callerText);
|
|
387082
|
+
if (!proof.proven)
|
|
387083
|
+
return walked;
|
|
387084
|
+
return this.swapForOnDiskTwins(walked, proof.gatesByBase.flatMap(([, gates]) => gates));
|
|
387085
|
+
}
|
|
387086
|
+
swapForOnDiskTwins(walked, twins) {
|
|
387087
|
+
const used = new Set;
|
|
387088
|
+
return walked.map((entry) => {
|
|
387089
|
+
const twin = twins.find((t3) => !used.has(t3) && t3.route === entry.route && t3.exprs.length === entry.exprs.length && t3.exprs.every((expr, i2) => expr === entry.exprs[i2]));
|
|
387090
|
+
if (!twin)
|
|
387091
|
+
return entry;
|
|
387092
|
+
used.add(twin);
|
|
387093
|
+
return twin;
|
|
387094
|
+
});
|
|
387095
|
+
}
|
|
387054
387096
|
async assertAuthorizedFromCompiledRunnable(runnable, givens) {
|
|
387055
387097
|
await this.authorizeAndBindRunnable(runnable, givens, {
|
|
387056
387098
|
skipOwnSourceGate: true,
|
|
@@ -387068,8 +387110,8 @@ class Model {
|
|
|
387068
387110
|
queryHadRowLevelFilterAttached(runnable) {
|
|
387069
387111
|
return this.rowLevelFilteredRunnables.has(runnable);
|
|
387070
387112
|
}
|
|
387071
|
-
async probeEntryPointGates(runnable, givens, graftScope,
|
|
387072
|
-
const { entryPointGates, modelDef } = await this.collectAuthorizeEntryPointGates(runnable, givens, graftScope,
|
|
387113
|
+
async probeEntryPointGates(runnable, givens, graftScope, options = {}) {
|
|
387114
|
+
const { entryPointGates, modelDef } = await this.collectAuthorizeEntryPointGates(runnable, givens, graftScope, options);
|
|
387073
387115
|
const rowLevel = [];
|
|
387074
387116
|
for (const entry of entryPointGates) {
|
|
387075
387117
|
const resolution = modelDef ? await this.resolveGateShape(entry, modelDef, graftScope) : { shape: "rejected", cause: undefined };
|
|
@@ -387118,10 +387160,10 @@ class Model {
|
|
|
387118
387160
|
return;
|
|
387119
387161
|
if (this.entryPointGatesBySource.has(entryPoint))
|
|
387120
387162
|
return;
|
|
387121
|
-
const proof = this.
|
|
387163
|
+
const proof = this.requestChainGates(entryPoint, query);
|
|
387122
387164
|
if (proof.proven) {
|
|
387123
|
-
for (const base of proof.
|
|
387124
|
-
for (const entry of
|
|
387165
|
+
for (const [base, gates] of proof.gatesByBase) {
|
|
387166
|
+
for (const entry of gates) {
|
|
387125
387167
|
const resolution = this.modelDef ? await this.resolveGateShape(entry, this.modelDef, graftScope) : { shape: "rejected", cause: undefined };
|
|
387126
387168
|
if (resolution.shape === "row_level") {
|
|
387127
387169
|
this.denyLaunderedEntryPoint(entryPoint, "row_filter_not_graftable", base);
|
|
@@ -387133,6 +387175,15 @@ class Model {
|
|
|
387133
387175
|
}
|
|
387134
387176
|
this.denyLaunderedEntryPoint(entryPoint, proof.reason, proof.at);
|
|
387135
387177
|
}
|
|
387178
|
+
requestChainGates(entryPoint, text) {
|
|
387179
|
+
const proof = this.requestChainProvesUngated(entryPoint, buildDerivationBaseMap(text));
|
|
387180
|
+
if (!proof.proven)
|
|
387181
|
+
return proof;
|
|
387182
|
+
return {
|
|
387183
|
+
proven: true,
|
|
387184
|
+
gatesByBase: proof.gatedBases.map((base) => [base, this.entryPointGatesBySource.get(base) ?? []])
|
|
387185
|
+
};
|
|
387186
|
+
}
|
|
387136
387187
|
async assertLocksOnRequestDeclaredBases(entryPoint, query, givens, bypassAuthorize) {
|
|
387137
387188
|
if (!this.declaresAnyGate())
|
|
387138
387189
|
return;
|
|
@@ -387170,7 +387221,7 @@ class Model {
|
|
|
387170
387221
|
return this.declaresAnyGateMemo;
|
|
387171
387222
|
}
|
|
387172
387223
|
requestChainProvesUngated(entryPoint, basesOf) {
|
|
387173
|
-
const chain = derivationTerminals(entryPoint, basesOf, (name) => this.entryPointGatesBySource.has(name), REQUEST_CHAIN_MAX_NAMES);
|
|
387224
|
+
const chain = derivationTerminals(entryPoint, basesOf, (name) => this.entryPointGatesBySource.has(name), REQUEST_CHAIN_MAX_NAMES, (name) => this.modelQuerySource(name));
|
|
387174
387225
|
if (!chain.proven) {
|
|
387175
387226
|
return {
|
|
387176
387227
|
proven: false,
|
|
@@ -387183,6 +387234,9 @@ class Model {
|
|
|
387183
387234
|
gatedBases: chain.terminals.filter((name) => (this.entryPointGatesBySource.get(name)?.length ?? 0) > 0)
|
|
387184
387235
|
};
|
|
387185
387236
|
}
|
|
387237
|
+
modelQuerySource(name) {
|
|
387238
|
+
return this.queries?.find((q3) => q3.name === name)?.sourceName;
|
|
387239
|
+
}
|
|
387186
387240
|
resolvedCallerJoins(runnable, region) {
|
|
387187
387241
|
const cached4 = this.callerJoinResolutions.get(runnable);
|
|
387188
387242
|
if (cached4 && cached4.region === region)
|
|
@@ -387207,6 +387261,7 @@ class Model {
|
|
|
387207
387261
|
const context = {
|
|
387208
387262
|
isModelSource: (name) => this.entryPointGatesBySource.has(name),
|
|
387209
387263
|
isModelQuery: (name) => this.modelDef?.contents[name]?.type === "query",
|
|
387264
|
+
modelQuerySource: (name) => this.modelQuerySource(name),
|
|
387210
387265
|
authorUrls
|
|
387211
387266
|
};
|
|
387212
387267
|
return collectCallerJoins(prepared, region, authorUrls).map((callerJoin) => ({
|
|
@@ -387248,7 +387303,9 @@ class Model {
|
|
|
387248
387303
|
async decideCallerSource(source, compiledModelDef, alias, givens, graftScope) {
|
|
387249
387304
|
const gates = this.collectEntryPointGates(source.struct, compiledModelDef, new Set, true);
|
|
387250
387305
|
if (gates.length > 0) {
|
|
387251
|
-
|
|
387306
|
+
const twins = source.chain.proven ? source.chain.terminals.flatMap((base) => this.entryPointGatesBySource.get(base) ?? []) : [];
|
|
387307
|
+
const swapped = this.swapForOnDiskTwins(gates, twins);
|
|
387308
|
+
return Promise.all(swapped.map((entry, i2) => entry === gates[i2] ? this.resolveGateShape(entry, compiledModelDef, graftScope) : this.resolveGateShape(entry, this.modelDef ?? compiledModelDef, graftScope)));
|
|
387252
387309
|
}
|
|
387253
387310
|
if (!source.chain.proven) {
|
|
387254
387311
|
this.denyCallerJoin(alias, "chain_not_established", source.chain.at);
|
|
@@ -387450,7 +387507,10 @@ ${query}`;
|
|
|
387450
387507
|
return runnable;
|
|
387451
387508
|
}
|
|
387452
387509
|
const graftScope = options?.graftScope ?? this.defaultGraftScope();
|
|
387453
|
-
const entryPointRowLevel = await this.probeEntryPointGates(runnable, givens, graftScope,
|
|
387510
|
+
const entryPointRowLevel = await this.probeEntryPointGates(runnable, givens, graftScope, {
|
|
387511
|
+
skipOwnSourceGate: options?.skipOwnSourceGate,
|
|
387512
|
+
callerText: options?.compileCallerText ?? options?.callerQueryText
|
|
387513
|
+
});
|
|
387454
387514
|
if (entryPointRowLevel.length === 0) {
|
|
387455
387515
|
if (options?.callerQueryText && !options?.skipOwnSourceGate) {
|
|
387456
387516
|
await this.assertRequestDeclaredEntryPointIsNotLaundered(runnable, options.callerQueryText, givens, graftScope);
|
|
@@ -387480,6 +387540,7 @@ ${query}`;
|
|
|
387480
387540
|
g2
|
|
387481
387541
|
])).values());
|
|
387482
387542
|
const graftedMaterializer = this.getOrBuildGraftedMaterializer(grafts, graftScope);
|
|
387543
|
+
await this.ensureSharedQueryModel(graftedMaterializer);
|
|
387483
387544
|
const recompiled = options.recompile(graftedMaterializer, grafts);
|
|
387484
387545
|
if (options.proveGraft) {
|
|
387485
387546
|
if (callerJoinRowLevel.length > 0) {
|
|
@@ -387644,14 +387705,15 @@ ${query}`;
|
|
|
387644
387705
|
if (!target)
|
|
387645
387706
|
return;
|
|
387646
387707
|
try {
|
|
387647
|
-
assertInheritedSourceFiltersBind(target, modelDef, { compiledUrl, queryLocation }, this.siblingModelDefResolver, undefined, undefined, alreadyProven);
|
|
387708
|
+
assertInheritedSourceFiltersBind(target, modelDef, { compiledUrl, queryLocation }, this.siblingModelDefResolver, undefined, undefined, alreadyProven, struct);
|
|
387648
387709
|
} catch (err) {
|
|
387649
387710
|
recordRowLevelGateDecision("denied_by_gate", site);
|
|
387650
387711
|
logger.debug("Inherited source filter binding check failed; denying", {
|
|
387651
387712
|
modelPath: this.modelPath,
|
|
387652
387713
|
error: err instanceof Error ? err.message : String(err)
|
|
387653
387714
|
});
|
|
387654
|
-
const
|
|
387715
|
+
const named = struct ?? target;
|
|
387716
|
+
const label = named.as || named.name;
|
|
387655
387717
|
throw new AccessDeniedError(`Access denied for source "${label}".`);
|
|
387656
387718
|
}
|
|
387657
387719
|
}
|
|
@@ -387946,6 +388008,27 @@ ${query}`;
|
|
|
387946
388008
|
model.preparedPreaggregateCompanion = data.preaggregateCompanion;
|
|
387947
388009
|
return model;
|
|
387948
388010
|
}
|
|
388011
|
+
ensureSharedQueryModel(materializer) {
|
|
388012
|
+
if (!materializer)
|
|
388013
|
+
return Promise.resolve();
|
|
388014
|
+
let built = this.sharedQueryModels.get(materializer);
|
|
388015
|
+
if (!built) {
|
|
388016
|
+
built = (async () => {
|
|
388017
|
+
try {
|
|
388018
|
+
const base = await materializer.getModel();
|
|
388019
|
+
base.queryModel;
|
|
388020
|
+
} catch (error2) {
|
|
388021
|
+
logger.warn("Could not build a shared QueryModel; each query builds its own", {
|
|
388022
|
+
packageName: this.packageName,
|
|
388023
|
+
modelPath: this.modelPath,
|
|
388024
|
+
error: error2 instanceof Error ? error2.message : String(error2)
|
|
388025
|
+
});
|
|
388026
|
+
}
|
|
388027
|
+
})();
|
|
388028
|
+
this.sharedQueryModels.set(materializer, built);
|
|
388029
|
+
}
|
|
388030
|
+
return built;
|
|
388031
|
+
}
|
|
387949
388032
|
static fromCompilationError(packageName, modelPath, modelType, error2, sourceText) {
|
|
387950
388033
|
const model = new Model(packageName, modelPath, {}, modelType, undefined, undefined, undefined, undefined, undefined, undefined, error2);
|
|
387951
388034
|
model.compiledSourceText = sourceText;
|
|
@@ -388029,6 +388112,11 @@ ${query}`;
|
|
|
388029
388112
|
return this.compiledSourceText;
|
|
388030
388113
|
}
|
|
388031
388114
|
getReportModelFacts() {
|
|
388115
|
+
return (this.reportModelFacts ??= {
|
|
388116
|
+
value: this.deriveReportModelFacts()
|
|
388117
|
+
}).value;
|
|
388118
|
+
}
|
|
388119
|
+
deriveReportModelFacts() {
|
|
388032
388120
|
if (!this.modelDef)
|
|
388033
388121
|
return;
|
|
388034
388122
|
return readReportModelFacts(this.modelPath, this.modelDef, (this.givens ?? []).map((given) => given.name).filter((name) => name !== undefined), new Map((this.sources ?? []).flatMap((source) => source.name ? [
|
|
@@ -388264,6 +388352,9 @@ ${query}`;
|
|
|
388264
388352
|
return this.modelPath.endsWith(NOTEBOOK_FILE_SUFFIX) ? "malloynb" : "malloy";
|
|
388265
388353
|
}
|
|
388266
388354
|
carriesReportTag() {
|
|
388355
|
+
return this.reportTagCarried ??= this.deriveCarriesReportTag();
|
|
388356
|
+
}
|
|
388357
|
+
deriveCarriesReportTag() {
|
|
388267
388358
|
if (!isReportEligiblePath(this.modelPath))
|
|
388268
388359
|
return false;
|
|
388269
388360
|
const facts = this.getReportModelFacts();
|
|
@@ -388365,7 +388456,9 @@ ${query}`;
|
|
|
388365
388456
|
];
|
|
388366
388457
|
const findings = [];
|
|
388367
388458
|
const carriesReportTag = this.carriesReportTag();
|
|
388459
|
+
const yielder = createEventLoopYielder();
|
|
388368
388460
|
for (const { label, result } of prepared) {
|
|
388461
|
+
await yielder.maybeYield();
|
|
388369
388462
|
const logs = filterPublisherOwnedRenderLogs(validateRenderTags2(result), carriesReportTag);
|
|
388370
388463
|
if (logs.length > 0) {
|
|
388371
388464
|
logger.warn(`Render tag findings on '${label}': ${logs.map((e2) => `[${e2.severity}] ${e2.message}`).join("; ")}`);
|
|
@@ -388382,8 +388475,11 @@ ${query}`;
|
|
|
388382
388475
|
}
|
|
388383
388476
|
preparedRenderTagResults;
|
|
388384
388477
|
async prepareRenderTagTargets(mm, targets) {
|
|
388478
|
+
await this.ensureSharedQueryModel(mm);
|
|
388479
|
+
const yielder = createEventLoopYielder();
|
|
388385
388480
|
const prepared = [];
|
|
388386
388481
|
for (const target of targets) {
|
|
388482
|
+
await yielder.maybeYield();
|
|
388387
388483
|
try {
|
|
388388
388484
|
const result = await mm.loadQuery(target.queryString).getPreparedResult();
|
|
388389
388485
|
prepared.push({
|
|
@@ -388459,48 +388555,19 @@ ${query}`;
|
|
|
388459
388555
|
const read = readNotebookCells(parse5, modelDef, text);
|
|
388460
388556
|
if (read.error)
|
|
388461
388557
|
return refuse(read.error);
|
|
388462
|
-
const anonymousQueries = this.modelInfo?.anonymous_queries ?? [];
|
|
388463
388558
|
this.notebookAnnotations = read.annotations;
|
|
388464
388559
|
const layout = this.readNotebookLayout();
|
|
388465
388560
|
this.notebookLayout = layout;
|
|
388466
|
-
const
|
|
388467
|
-
|
|
388468
|
-
|
|
388469
|
-
|
|
388470
|
-
|
|
388471
|
-
|
|
388472
|
-
|
|
388473
|
-
|
|
388474
|
-
|
|
388475
|
-
|
|
388476
|
-
markdown: cell.markdown,
|
|
388477
|
-
proseLines: cell.proseLines,
|
|
388478
|
-
codeLine: cell.codeLine,
|
|
388479
|
-
caption: cell.caption,
|
|
388480
|
-
modelDef
|
|
388481
|
-
};
|
|
388482
|
-
}
|
|
388483
|
-
const k2 = cell.queryIndex ?? -1;
|
|
388484
|
-
const anonymous = anonymousQueries[k2];
|
|
388485
|
-
const compiled = modelDef.queryList[k2];
|
|
388486
|
-
return {
|
|
388487
|
-
type: "code",
|
|
388488
|
-
kind: "query",
|
|
388489
|
-
text: cell.text,
|
|
388490
|
-
markdown: cell.markdown,
|
|
388491
|
-
proseLines: cell.proseLines,
|
|
388492
|
-
codeLine: cell.codeLine,
|
|
388493
|
-
caption: cell.caption,
|
|
388494
|
-
queryIndex: cell.queryIndex,
|
|
388495
|
-
runnable: materializer.loadQuery(cell.text),
|
|
388496
|
-
modelMaterializer: materializer,
|
|
388497
|
-
modelDef,
|
|
388498
|
-
queryInfo: anonymous && {
|
|
388499
|
-
...anonymous,
|
|
388500
|
-
name: compiled?.as || compiled?.name || ""
|
|
388501
|
-
}
|
|
388502
|
-
};
|
|
388503
|
-
});
|
|
388561
|
+
const cells = read.cells.filter((cell) => cell.kind === "definition").map((cell) => ({
|
|
388562
|
+
type: "code",
|
|
388563
|
+
kind: "definition",
|
|
388564
|
+
text: cell.text,
|
|
388565
|
+
markdown: cell.markdown,
|
|
388566
|
+
proseLines: cell.proseLines,
|
|
388567
|
+
codeLine: cell.codeLine,
|
|
388568
|
+
caption: cell.caption,
|
|
388569
|
+
modelDef
|
|
388570
|
+
}));
|
|
388504
388571
|
if (layout) {
|
|
388505
388572
|
for (const tile of layout.tiles ?? []) {
|
|
388506
388573
|
if (tile.kind === "text") {
|
|
@@ -388567,7 +388634,7 @@ ${query}`;
|
|
|
388567
388634
|
throw readerError;
|
|
388568
388635
|
return this.getNotebookModel();
|
|
388569
388636
|
} else {
|
|
388570
|
-
throw new ModelNotFoundError(`${this.modelPath} is not a valid notebook name. Notebook files must end in .malloynb, or be a .malloy with a model-level ## artifact { layout=linear } tag.`);
|
|
388637
|
+
throw new ModelNotFoundError(`${this.modelPath} is not a valid notebook name. Notebook files must end in .malloynb, or be a .malloy report with a model-level ## artifact { layout=linear tiles=[…] } tag.`);
|
|
388571
388638
|
}
|
|
388572
388639
|
}
|
|
388573
388640
|
setServeDestinationConfig(provider) {
|
|
@@ -388615,6 +388682,7 @@ ${query}`;
|
|
|
388615
388682
|
...ordinary,
|
|
388616
388683
|
...groups.flatMap((g2) => g2.members)
|
|
388617
388684
|
]);
|
|
388685
|
+
await this.ensureSharedQueryModel(this.serveShapeCache.materializer);
|
|
388618
388686
|
const runnable = this.serveShapeCache.materializer.loadRestrictedQuery(queryString);
|
|
388619
388687
|
const probeSQL = await runnable.getSQL({ virtualMap, givens });
|
|
388620
388688
|
const rollupPaths = [
|
|
@@ -388900,6 +388968,7 @@ run: ${sourceName ? `${quoteMalloyIdentifier2(sourceName)} -> ` : ""}${quoteMall
|
|
|
388900
388968
|
}
|
|
388901
388969
|
}
|
|
388902
388970
|
}
|
|
388971
|
+
await this.ensureSharedQueryModel(this.modelMaterializer);
|
|
388903
388972
|
runnable = this.modelMaterializer.loadRestrictedQuery(queryString);
|
|
388904
388973
|
liveRunnable = runnable;
|
|
388905
388974
|
querySurfaceGivens = this.filterGivensToModelSurface(givens, await this.givenNamesReadByQuery(runnable, givens));
|
|
@@ -389251,6 +389320,7 @@ run: ${sourceName ? `${quoteMalloyIdentifier2(sourceName)} -> ` : ""}${quoteMall
|
|
|
389251
389320
|
return {
|
|
389252
389321
|
type: "source",
|
|
389253
389322
|
packageName: this.packageName,
|
|
389323
|
+
path: this.modelPath,
|
|
389254
389324
|
modelPath: this.modelPath,
|
|
389255
389325
|
malloyVersion: MALLOY_VERSION,
|
|
389256
389326
|
dataStyles: JSON.stringify(this.dataStyles),
|
|
@@ -389920,9 +389990,11 @@ init_constants();
|
|
|
389920
389990
|
init_logger();
|
|
389921
389991
|
async function compilePackageBuildPlan(pkg, signal) {
|
|
389922
389992
|
const parts = emptyBuildPlanParts();
|
|
389993
|
+
const yielder = createEventLoopYielder();
|
|
389923
389994
|
for (const modelPath of pkg.getModelPaths()) {
|
|
389924
389995
|
if (!modelPath.endsWith(MODEL_FILE_SUFFIX))
|
|
389925
389996
|
continue;
|
|
389997
|
+
await yielder.maybeYield();
|
|
389926
389998
|
if (signal?.aborted)
|
|
389927
389999
|
throw new Error("Build cancelled");
|
|
389928
390000
|
const { runtime, modelURL, importBaseURL } = await Model.getModelRuntime(pkg.getPackagePath(), modelPath, pkg.getMalloyConfig());
|
|
@@ -391066,8 +391138,11 @@ class Package {
|
|
|
391066
391138
|
const { packageName, packagePath, malloyConfig, buildManifest } = ctx;
|
|
391067
391139
|
const models = new Map;
|
|
391068
391140
|
const renderTagWarnings = [];
|
|
391141
|
+
const timings = { hydrateMs: 0, renderValidationMs: 0 };
|
|
391069
391142
|
const placeholder = (sm, err) => Model.fromCompilationError(packageName, sm.modelPath, sm.modelType, err, sm.modelPath === ctx.replacement?.modelPath ? ctx.replacement.source : undefined);
|
|
391143
|
+
const yielder = createEventLoopYielder();
|
|
391070
391144
|
for (const sm of outcome.models) {
|
|
391145
|
+
await yielder.maybeYield();
|
|
391071
391146
|
if (sm.compilationError) {
|
|
391072
391147
|
const err = Model.deserializeCompilationError(sm.compilationError);
|
|
391073
391148
|
if (onCompileError === "throw") {
|
|
@@ -391089,6 +391164,7 @@ class Package {
|
|
|
391089
391164
|
continue;
|
|
391090
391165
|
}
|
|
391091
391166
|
let model;
|
|
391167
|
+
const hydrateStart = performance.now();
|
|
391092
391168
|
try {
|
|
391093
391169
|
model = Model.fromSerialized(packageName, packagePath, malloyConfig, sm, {
|
|
391094
391170
|
buildManifest,
|
|
@@ -391109,8 +391185,11 @@ class Package {
|
|
|
391109
391185
|
});
|
|
391110
391186
|
models.set(sm.modelPath, placeholder(sm, hydrateErr instanceof Error ? hydrateErr : new Error(String(hydrateErr))));
|
|
391111
391187
|
continue;
|
|
391188
|
+
} finally {
|
|
391189
|
+
timings.hydrateMs += performance.now() - hydrateStart;
|
|
391112
391190
|
}
|
|
391113
391191
|
let warnings;
|
|
391192
|
+
const validationStart = performance.now();
|
|
391114
391193
|
try {
|
|
391115
391194
|
warnings = await model.validateRenderTags();
|
|
391116
391195
|
} catch (renderErr) {
|
|
@@ -391131,6 +391210,8 @@ class Package {
|
|
|
391131
391210
|
}
|
|
391132
391211
|
models.set(sm.modelPath, placeholder(sm, err));
|
|
391133
391212
|
continue;
|
|
391213
|
+
} finally {
|
|
391214
|
+
timings.renderValidationMs += performance.now() - validationStart;
|
|
391134
391215
|
}
|
|
391135
391216
|
for (const w2 of warnings) {
|
|
391136
391217
|
renderTagWarnings.push({
|
|
@@ -391140,10 +391221,12 @@ class Package {
|
|
|
391140
391221
|
severity: w2.severity
|
|
391141
391222
|
});
|
|
391142
391223
|
}
|
|
391224
|
+
const afterHydrateStart = performance.now();
|
|
391143
391225
|
await afterHydrate?.(sm);
|
|
391226
|
+
timings.hydrateMs += performance.now() - afterHydrateStart;
|
|
391144
391227
|
models.set(sm.modelPath, model);
|
|
391145
391228
|
}
|
|
391146
|
-
return { models, renderTagWarnings };
|
|
391229
|
+
return { models, renderTagWarnings, timings };
|
|
391147
391230
|
}
|
|
391148
391231
|
static async lintWorkerOutcome(environmentName, packageName, packagePath, malloyConfig, outcome, buildManifest, replacement) {
|
|
391149
391232
|
const { models, renderTagWarnings } = await Package.hydrateWorkerModels(outcome, {
|
|
@@ -391213,8 +391296,13 @@ class Package {
|
|
|
391213
391296
|
const packageConfig = Package.packageConfigFromOutcome(environmentName, packageName, outcome);
|
|
391214
391297
|
let models;
|
|
391215
391298
|
let renderTagWarnings;
|
|
391299
|
+
let hydrationTimings;
|
|
391216
391300
|
try {
|
|
391217
|
-
({
|
|
391301
|
+
({
|
|
391302
|
+
models,
|
|
391303
|
+
renderTagWarnings,
|
|
391304
|
+
timings: hydrationTimings
|
|
391305
|
+
} = await Package.hydrateWorkerModels(outcome, { packageName, packagePath, malloyConfig }, "throw", async (sm) => {
|
|
391218
391306
|
if (sm.modelPath.endsWith(MODEL_FILE_SUFFIX)) {
|
|
391219
391307
|
const modelSource = await fs14.readFile(path16.join(packagePath, sm.modelPath), "utf-8");
|
|
391220
391308
|
assertPersistNamesQuoted(modelSource, sm.modelPath);
|
|
@@ -391237,15 +391325,16 @@ class Package {
|
|
|
391237
391325
|
});
|
|
391238
391326
|
const pkg = new Package(environmentName, packageName, packagePath, packageConfig, databases, models, malloyConfig);
|
|
391239
391327
|
pkg.renderTagWarnings = renderTagWarnings;
|
|
391240
|
-
await pkg.discoverReports("load");
|
|
391328
|
+
const reportTimings = await pkg.discoverReports("load");
|
|
391241
391329
|
pkg.manifestWarnings = outcome.packageMetadata.manifestWarnings ?? [];
|
|
391242
391330
|
pkg.recordDeprecatedUsage(outcome);
|
|
391243
391331
|
pkg.retrievalSettings = outcome.packageMetadata.retrieval ?? DEFAULT_PACKAGE_RETRIEVAL;
|
|
391244
391332
|
pkg.rawAgents = outcome.packageMetadata.agents;
|
|
391245
391333
|
pkg.wireFreshnessResolvers();
|
|
391246
391334
|
pkg.refreshServingIdentity();
|
|
391335
|
+
let buildPlanMs;
|
|
391336
|
+
const buildPlanPhaseStart = performance.now();
|
|
391247
391337
|
try {
|
|
391248
|
-
const buildPlanStart = Date.now();
|
|
391249
391338
|
const workerPlan = outcome.buildPlan;
|
|
391250
391339
|
for (const [reason, count4] of Object.entries(workerPlan?.eligibilityRefused ?? {})) {
|
|
391251
391340
|
for (let i2 = 0;i2 < (count4 ?? 0); i2++) {
|
|
@@ -391278,7 +391367,8 @@ class Package {
|
|
|
391278
391367
|
sourceEntityId: source.sourceEntityId,
|
|
391279
391368
|
declaration: incrementalDeclarations[sourceID]
|
|
391280
391369
|
}));
|
|
391281
|
-
recordBuildPlanComputeDuration(workerPlan ? workerPlan.durationMs :
|
|
391370
|
+
recordBuildPlanComputeDuration(workerPlan ? workerPlan.durationMs : performance.now() - buildPlanPhaseStart, workerPlan ? "worker" : "main_thread");
|
|
391371
|
+
buildPlanMs = performance.now() - buildPlanPhaseStart;
|
|
391282
391372
|
} catch (err) {
|
|
391283
391373
|
recordBuildPlanComputeFailed();
|
|
391284
391374
|
logger.warn(`Failed to compute build plan for package ${packageName}`, {
|
|
@@ -391334,6 +391424,15 @@ class Package {
|
|
|
391334
391424
|
}
|
|
391335
391425
|
await pkg.pushPreaggregateServeModels();
|
|
391336
391426
|
pkg.logEmptyDiscoveryWarnings();
|
|
391427
|
+
recordPackageLoadPhaseDurations({
|
|
391428
|
+
worker: workerDoneTime - dispatchTime,
|
|
391429
|
+
hydrate: hydrationTimings.hydrateMs,
|
|
391430
|
+
render_validation: hydrationTimings.renderValidationMs,
|
|
391431
|
+
discovery: reportTimings.discoveryMs,
|
|
391432
|
+
lint: reportTimings.lintMs,
|
|
391433
|
+
build_plan: buildPlanMs,
|
|
391434
|
+
total: performance.now() - startTime
|
|
391435
|
+
});
|
|
391337
391436
|
return pkg;
|
|
391338
391437
|
}
|
|
391339
391438
|
getPackageName() {
|
|
@@ -391987,8 +392086,11 @@ class Package {
|
|
|
391987
392086
|
const started = performance.now();
|
|
391988
392087
|
const discovery = await this.discoverReportsIn(this.models, during);
|
|
391989
392088
|
this.installReports(discovery);
|
|
392089
|
+
const linting = performance.now();
|
|
391990
392090
|
await this.relintReports({ textLint: during !== "compile" });
|
|
391991
|
-
|
|
392091
|
+
const finished = performance.now();
|
|
392092
|
+
this.reportDiscovered(during, discovery, finished - started);
|
|
392093
|
+
return { discoveryMs: linting - started, lintMs: finished - linting };
|
|
391992
392094
|
}
|
|
391993
392095
|
reportDiscovered(during, discovery, durationMs) {
|
|
391994
392096
|
recordReportDiscoveryDuration(during, durationMs);
|
|
@@ -392089,19 +392191,17 @@ class Package {
|
|
|
392089
392191
|
model: modelPath,
|
|
392090
392192
|
error: errMessage(err)
|
|
392091
392193
|
});
|
|
392092
|
-
|
|
392093
|
-
|
|
392094
|
-
continue;
|
|
392095
|
-
}
|
|
392194
|
+
files.set(modelPath, { status: "dropped", name });
|
|
392195
|
+
continue;
|
|
392096
392196
|
}
|
|
392097
|
-
if (
|
|
392197
|
+
if (facts && !manifest) {
|
|
392098
392198
|
files.set(modelPath, { status: "tileless", name, facts });
|
|
392099
392199
|
continue;
|
|
392100
392200
|
}
|
|
392101
|
-
if (
|
|
392201
|
+
if (!facts) {
|
|
392102
392202
|
manifest = {
|
|
392103
392203
|
name,
|
|
392104
|
-
layout:
|
|
392204
|
+
layout: tag.layout,
|
|
392105
392205
|
title: name,
|
|
392106
392206
|
autorun: true,
|
|
392107
392207
|
entryFile: modelPath,
|
|
@@ -392397,7 +392497,7 @@ class Package {
|
|
|
392397
392497
|
layout: report.layout,
|
|
392398
392498
|
title: manifest?.title ?? listing.title ?? report.name,
|
|
392399
392499
|
description: manifest?.description ?? listing.description,
|
|
392400
|
-
editable: report.path.endsWith(MODEL_FILE_SUFFIX)
|
|
392500
|
+
editable: report.path.endsWith(MODEL_FILE_SUFFIX),
|
|
392401
392501
|
...error2 !== undefined && { error: error2 }
|
|
392402
392502
|
};
|
|
392403
392503
|
}
|
|
@@ -394166,7 +394266,7 @@ ${query}`);
|
|
|
394166
394266
|
}
|
|
394167
394267
|
}
|
|
394168
394268
|
// package.json
|
|
394169
|
-
var version2 = "0.9.
|
|
394269
|
+
var version2 = "0.9.11";
|
|
394170
394270
|
|
|
394171
394271
|
// src/version.ts
|
|
394172
394272
|
var SERVER_VERSION = version2;
|