@malloy-publisher/sdk 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +19 -0
- package/dist/{DocumentStorageProvider-CyOJ0hqf.es.js → DocumentStorage-B04sZ5Ie.es.js} +2307 -2334
- package/dist/{DocumentStorageProvider-DGPQEd_l.cjs.js → DocumentStorage-B_MMJ0Ot.cjs.js} +20 -20
- package/dist/{RenderedResult-BnPzJ9Jf.es.js → RenderedResult-BB7eokcf.es.js} +100 -80
- package/dist/RenderedResult-DVuGhatg.cjs.js +135 -0
- package/dist/ServerProvider-D-jjzfE5.cjs.js +1 -0
- package/dist/{ServerProvider-BWOEKg0O.es.js → ServerProvider-Do-GBvpn.es.js} +492 -481
- package/dist/builder/index.cjs.js +57 -52
- package/dist/builder/index.es.js +4421 -3738
- package/dist/client/api.d.ts +14 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/Dashboard/TileCard.d.ts +7 -3
- package/dist/components/Dashboard/telemetry.d.ts +20 -8
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +16 -4
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +31 -8
- package/dist/components/DashboardBuilder/controls.d.ts +8 -6
- package/dist/components/DashboardBuilder/document.d.ts +19 -5
- package/dist/components/DashboardBuilder/malloyText.d.ts +0 -30
- package/dist/components/DashboardBuilder/malloyTree.d.ts +232 -0
- package/dist/components/DashboardBuilder/preview.d.ts +17 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +23 -28
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +12 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +69 -5
- package/dist/components/DocumentStorage/index.d.ts +1 -0
- package/dist/index.cjs.js +9 -9
- package/dist/index.es.js +508 -506
- package/dist/theme/resolveTheme.d.ts +1 -1
- package/dist/theme/types.d.ts +12 -2
- package/package.json +1 -1
- package/src/components/Dashboard/TileCard.tsx +8 -4
- package/src/components/Dashboard/telemetry.ts +20 -8
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +4 -5
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +21 -3
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +706 -0
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +356 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +468 -103
- package/src/components/DashboardBuilder/FilterDialog.tsx +19 -6
- package/src/components/DashboardBuilder/TileFrame.tsx +11 -2
- package/src/components/DashboardBuilder/TileMenu.tsx +6 -0
- package/src/components/DashboardBuilder/__test__/inventory.ts +367 -0
- package/src/components/DashboardBuilder/controls.spec.ts +53 -3
- package/src/components/DashboardBuilder/controls.ts +9 -7
- package/src/components/DashboardBuilder/document.ts +17 -5
- package/src/components/DashboardBuilder/invariants.spec.ts +297 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +27 -66
- package/src/components/DashboardBuilder/malloyText.ts +4 -109
- package/src/components/DashboardBuilder/malloyTree.spec.ts +362 -0
- package/src/components/DashboardBuilder/malloyTree.ts +954 -0
- package/src/components/DashboardBuilder/preview.spec.ts +18 -0
- package/src/components/DashboardBuilder/preview.ts +24 -6
- package/src/components/DashboardBuilder/readDocument.spec.ts +312 -21
- package/src/components/DashboardBuilder/readDocument.ts +144 -165
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +550 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +955 -21
- package/src/components/DashboardBuilder/spliceDocument.ts +509 -119
- package/src/components/DashboardBuilder/statementExtent.spec.ts +606 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.ts +7 -6
- package/src/components/DocumentStorage/DocumentStorage.ts +78 -5
- package/src/components/DocumentStorage/index.ts +1 -0
- package/src/components/Package/Package.tsx +12 -7
- package/src/components/RenderedResult/RenderedResult.tsx +21 -1
- package/src/components/given/GivensPanel.tsx +15 -3
- package/src/theme/buildTableCssVars.spec.ts +3 -0
- package/src/theme/buildTableCssVars.ts +6 -0
- package/src/theme/defaults.ts +16 -12
- package/src/theme/resolveTheme.spec.ts +14 -7
- package/src/theme/resolveTheme.ts +14 -8
- package/src/theme/types.ts +12 -2
- package/tsconfig.spec.json +5 -1
- package/dist/RenderedResult-Dp22kZsQ.cjs.js +0 -115
- package/dist/ServerProvider-Cc489A3f.cjs.js +0 -1
|
@@ -135,6 +135,24 @@ describe("previewTileQuery", () => {
|
|
|
135
135
|
).toBe("overview -> v");
|
|
136
136
|
});
|
|
137
137
|
|
|
138
|
+
it("runs an inline tile the same as a reference, on its own name", () => {
|
|
139
|
+
// An inline body still names a view of the extension — `view: x is {
|
|
140
|
+
// … }` is as much a named view as `view: x is base_view` — so a
|
|
141
|
+
// binding takes the same `source -> x + { where: … }` path a reference
|
|
142
|
+
// tile does, rather than being sent unrefined.
|
|
143
|
+
const inline: DashboardTile = {
|
|
144
|
+
name: "kpis",
|
|
145
|
+
source: "overview",
|
|
146
|
+
declaration: { kind: "inline" },
|
|
147
|
+
filters: [{ field: "category", given: "CATEGORY" }],
|
|
148
|
+
};
|
|
149
|
+
const q = previewTileQuery(document, inline, runnable);
|
|
150
|
+
expect(q.expression).toBe(
|
|
151
|
+
"overview -> kpis + { where: category ~ $CATEGORY }",
|
|
152
|
+
);
|
|
153
|
+
expect(q.givenNames).toEqual(["CATEGORY"]);
|
|
154
|
+
});
|
|
155
|
+
|
|
138
156
|
it("runs an inherited tile as the model has it, sending the whole row", () => {
|
|
139
157
|
const inherited: DashboardTile = {
|
|
140
158
|
name: "by_brand",
|
|
@@ -121,6 +121,23 @@ export interface PreviewTileQuery {
|
|
|
121
121
|
* `where: brand ~ f'Nike'`, from `values` and the declaration's type; with no
|
|
122
122
|
* value yet it is left out, which is what an empty filter means. A binding to
|
|
123
123
|
* a given neither side knows is left out too.
|
|
124
|
+
*
|
|
125
|
+
* An inline tile takes the SAME path as a reference: `view: x is { … }` names
|
|
126
|
+
* a view on the extension exactly as `view: x is base_view` does, so
|
|
127
|
+
* `source -> x + { where: … }` runs it refined. Without this, a bound control
|
|
128
|
+
* on an inline tile — most tiles in practice — looked like it did nothing in
|
|
129
|
+
* the live editor, and sent no given at all once saved.
|
|
130
|
+
*
|
|
131
|
+
* ADDITIVE, though, where a reference is exact. A reference tile refines its
|
|
132
|
+
* BASE view, which carries no bindings, so the preview is what the writer is
|
|
133
|
+
* about to produce. An inline tile has no base to name: `x` is the saved view,
|
|
134
|
+
* whose body already holds whatever bindings were saved into it, and this runs
|
|
135
|
+
* against the package's own model rather than the edited text. So adding a
|
|
136
|
+
* binding previews correctly, while REMOVING one leaves the saved `where:`
|
|
137
|
+
* filtering and CHANGING one applies the old and the new together, until the
|
|
138
|
+
* file is saved. Previewing those exactly would need the body re-emitted
|
|
139
|
+
* without its bindings, which this builder deliberately does not do: it
|
|
140
|
+
* splices, and never writes a view's body out from the document.
|
|
124
141
|
*/
|
|
125
142
|
export function previewTileQuery(
|
|
126
143
|
document: DashboardDocument,
|
|
@@ -128,12 +145,12 @@ export function previewTileQuery(
|
|
|
128
145
|
runnable: ReadonlySet<string>,
|
|
129
146
|
values: ReadonlyMap<string, GivenValue> = new Map(),
|
|
130
147
|
): PreviewTileQuery {
|
|
131
|
-
if (tile.declaration.kind
|
|
132
|
-
//
|
|
133
|
-
//
|
|
148
|
+
if (tile.declaration.kind === "inherited") {
|
|
149
|
+
// Declared in the model; bindings live there too, out of this
|
|
150
|
+
// document's reach, so the server is sent the whole row as it does.
|
|
134
151
|
return {
|
|
135
152
|
expression: `${tile.source} -> ${tile.name}`,
|
|
136
|
-
givenNames:
|
|
153
|
+
givenNames: undefined,
|
|
137
154
|
};
|
|
138
155
|
}
|
|
139
156
|
// Run on the dashboard's OWN extension, not the model source it extends.
|
|
@@ -143,6 +160,8 @@ export function previewTileQuery(
|
|
|
143
160
|
// Running on the base showed unscoped numbers for a dashboard that scopes
|
|
144
161
|
// its source, and the saved page then differed from what the author watched.
|
|
145
162
|
const on = tile.source;
|
|
163
|
+
const baseView =
|
|
164
|
+
tile.declaration.kind === "reference" ? tile.declaration.from : tile.name;
|
|
146
165
|
const localTypes = new Map(
|
|
147
166
|
(document.localGivens ?? []).map((local) => [local.name, local.type]),
|
|
148
167
|
);
|
|
@@ -165,8 +184,7 @@ export function previewTileQuery(
|
|
|
165
184
|
const refinement = clauses.join(", ");
|
|
166
185
|
return {
|
|
167
186
|
expression:
|
|
168
|
-
`${on} -> ${
|
|
169
|
-
(refinement ? ` + { ${refinement} }` : ""),
|
|
187
|
+
`${on} -> ${baseView}` + (refinement ? ` + { ${refinement} }` : ""),
|
|
170
188
|
givenNames: sent,
|
|
171
189
|
};
|
|
172
190
|
}
|
|
@@ -6,6 +6,7 @@ import { openDocument } from "./testing/fixtures";
|
|
|
6
6
|
import * as fs from "fs";
|
|
7
7
|
import * as path from "path";
|
|
8
8
|
import { blockAbove, readDashboardDocument, readFailed } from "./readDocument";
|
|
9
|
+
import { parseMalloy, parseRefused } from "./malloyTree";
|
|
9
10
|
|
|
10
11
|
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
11
12
|
|
|
@@ -27,39 +28,109 @@ source: a is scoped_orders extend {
|
|
|
27
28
|
}`;
|
|
28
29
|
|
|
29
30
|
describe("blockAbove", () => {
|
|
31
|
+
// Real sources, parsed: where the block STARTS comes from the lexer's own
|
|
32
|
+
// comments now, and a synthetic array of lines could not exercise that.
|
|
33
|
+
const block = async (source: string, declLine: number) => {
|
|
34
|
+
const parse = await parseMalloy(source);
|
|
35
|
+
if (parseRefused(parse)) throw new Error(parse.reason);
|
|
36
|
+
return blockAbove(parse.parsed, source.split("\n"), declLine);
|
|
37
|
+
};
|
|
38
|
+
|
|
30
39
|
// The boundary is a blank line, because that is the author's own separator.
|
|
31
40
|
// Validated against the bundled dashboard, where the block above
|
|
32
41
|
// `revenue_trend` is fourteen lines of comment plus three tags.
|
|
33
|
-
it("collects tags and comments up to the blank line", () => {
|
|
34
|
-
const
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
it("collects tags and comments up to the blank line", async () => {
|
|
43
|
+
const at = await block(
|
|
44
|
+
[
|
|
45
|
+
"source: s is a extend {",
|
|
46
|
+
"",
|
|
47
|
+
" // why this row is six and six",
|
|
48
|
+
" # colspan=6",
|
|
49
|
+
' # label="Revenue"',
|
|
50
|
+
" view: revenue is sales",
|
|
51
|
+
"}",
|
|
52
|
+
].join("\n"),
|
|
53
|
+
5,
|
|
54
|
+
);
|
|
55
|
+
expect(at.start).toBe(2);
|
|
56
|
+
expect(at.tags.map((t) => t.text)).toEqual([
|
|
45
57
|
"# colspan=6",
|
|
46
58
|
'# label="Revenue"',
|
|
47
59
|
]);
|
|
48
60
|
// The writer patches a tag in place, so the line number is load-bearing.
|
|
49
|
-
expect(
|
|
61
|
+
expect(at.tags.map((t) => t.line)).toEqual([3, 4]);
|
|
50
62
|
});
|
|
51
63
|
|
|
52
|
-
it("stops at the blank line rather than running into the tile above", () => {
|
|
53
|
-
const
|
|
54
|
-
|
|
55
|
-
|
|
64
|
+
it("stops at the blank line rather than running into the tile above", async () => {
|
|
65
|
+
const at = await block(
|
|
66
|
+
[
|
|
67
|
+
"source: s is a extend {",
|
|
68
|
+
" # colspan=12",
|
|
69
|
+
" view: a is x",
|
|
70
|
+
"",
|
|
71
|
+
" view: b is y",
|
|
72
|
+
"}",
|
|
73
|
+
].join("\n"),
|
|
74
|
+
4,
|
|
75
|
+
);
|
|
76
|
+
expect(at.start).toBe(4);
|
|
77
|
+
expect(at.tags).toEqual([]);
|
|
56
78
|
});
|
|
57
79
|
|
|
58
80
|
// `##` is a MODEL annotation and never belongs to a declaration below it.
|
|
59
|
-
it("ignores model-level annotations", () => {
|
|
60
|
-
const
|
|
61
|
-
|
|
81
|
+
it("ignores model-level annotations", async () => {
|
|
82
|
+
const at = await block(
|
|
83
|
+
'## artifact { title="T" }\nsource: a is b extend {\n view: v is x\n}',
|
|
84
|
+
1,
|
|
85
|
+
);
|
|
86
|
+
expect(at.tags).toEqual([]);
|
|
62
87
|
});
|
|
88
|
+
|
|
89
|
+
it("does not collect a `#` line written inside a block comment", async () => {
|
|
90
|
+
const source = [
|
|
91
|
+
"source: s is a extend {",
|
|
92
|
+
"",
|
|
93
|
+
" /* Notes:",
|
|
94
|
+
" # colspan is chosen below",
|
|
95
|
+
" */",
|
|
96
|
+
" # colspan=6",
|
|
97
|
+
" view: revenue is sales",
|
|
98
|
+
"}",
|
|
99
|
+
].join("\n");
|
|
100
|
+
const at = await block(source, 6);
|
|
101
|
+
expect(at.start).toBe(2);
|
|
102
|
+
expect(at.tags.map((t) => t.text)).toEqual(["# colspan=6"]);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
// Malloy spells a comment three ways. Each of the two this used to read as
|
|
106
|
+
// code stopped the walk early and hid every tag above it from the WRITER,
|
|
107
|
+
// while the reader took its tags from the parser and saw them -- so a retag
|
|
108
|
+
// wrote a second copy below the comment and the read-back gate passed.
|
|
109
|
+
for (const [kind, comment] of [
|
|
110
|
+
["a `--` line", " -- six across, to sit beside the trend"],
|
|
111
|
+
["a `/* ... */` line", " /* six across, to sit beside the trend */"],
|
|
112
|
+
[
|
|
113
|
+
"a block comment over several lines",
|
|
114
|
+
" /* six across,\n to sit beside the trend */",
|
|
115
|
+
],
|
|
116
|
+
] as const) {
|
|
117
|
+
it(`reads ${kind} as part of the block, not the end of it`, async () => {
|
|
118
|
+
const source = [
|
|
119
|
+
"source: s is a extend {",
|
|
120
|
+
"",
|
|
121
|
+
" # colspan=6",
|
|
122
|
+
comment,
|
|
123
|
+
" view: revenue is sales",
|
|
124
|
+
"}",
|
|
125
|
+
].join("\n");
|
|
126
|
+
const declLine = source
|
|
127
|
+
.split("\n")
|
|
128
|
+
.indexOf(" view: revenue is sales");
|
|
129
|
+
const at = await block(source, declLine);
|
|
130
|
+
expect(at.start).toBe(2);
|
|
131
|
+
expect(at.tags.map((t) => t.text)).toEqual(["# colspan=6"]);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
63
134
|
});
|
|
64
135
|
|
|
65
136
|
describe("readDashboardDocument", () => {
|
|
@@ -202,6 +273,226 @@ source: a is one extend {
|
|
|
202
273
|
});
|
|
203
274
|
});
|
|
204
275
|
|
|
276
|
+
describe("readDashboardDocument: inline body filters", () => {
|
|
277
|
+
// A binding on an inline body is a depth-1 `where:` statement in the body's
|
|
278
|
+
// own first stage, not a `+ { … }` refinement — the writer's job is to
|
|
279
|
+
// locate the same statements, so both sides read the shape the same way.
|
|
280
|
+
it("reads a depth-1 where: line as the tile's filter", async () => {
|
|
281
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
282
|
+
import "../m.malloy"
|
|
283
|
+
|
|
284
|
+
source: a is one extend {
|
|
285
|
+
view: x is {
|
|
286
|
+
where: category ~ $CATEGORY
|
|
287
|
+
group_by: category
|
|
288
|
+
aggregate: n is count()
|
|
289
|
+
}
|
|
290
|
+
}`);
|
|
291
|
+
expect(doc.tiles[0].declaration).toEqual({ kind: "inline" });
|
|
292
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
293
|
+
{ field: "category", given: "CATEGORY" },
|
|
294
|
+
]);
|
|
295
|
+
});
|
|
296
|
+
|
|
297
|
+
it("reads it at the end, or between two other statements, the same way", async () => {
|
|
298
|
+
const last = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
299
|
+
import "../m.malloy"
|
|
300
|
+
|
|
301
|
+
source: a is one extend {
|
|
302
|
+
view: x is {
|
|
303
|
+
group_by: category
|
|
304
|
+
aggregate: n is count()
|
|
305
|
+
where: category ~ $CATEGORY
|
|
306
|
+
}
|
|
307
|
+
}`);
|
|
308
|
+
expect(last.tiles[0].filters).toEqual([
|
|
309
|
+
{ field: "category", given: "CATEGORY" },
|
|
310
|
+
]);
|
|
311
|
+
|
|
312
|
+
const middle = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
313
|
+
import "../m.malloy"
|
|
314
|
+
|
|
315
|
+
source: a is one extend {
|
|
316
|
+
view: x is {
|
|
317
|
+
group_by: category
|
|
318
|
+
where: category ~ $CATEGORY
|
|
319
|
+
aggregate: n is count()
|
|
320
|
+
}
|
|
321
|
+
}`);
|
|
322
|
+
expect(middle.tiles[0].filters).toEqual([
|
|
323
|
+
{ field: "category", given: "CATEGORY" },
|
|
324
|
+
]);
|
|
325
|
+
});
|
|
326
|
+
|
|
327
|
+
// A `nest:`'s own `where:` is depth 2, one level inside the nest's own
|
|
328
|
+
// brace, not depth 1 of the tile's body — it is that nested view's filter,
|
|
329
|
+
// not this tile's, and must not be reported as one.
|
|
330
|
+
it("does not read a nest's own where: as the tile's filter", async () => {
|
|
331
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
332
|
+
import "../m.malloy"
|
|
333
|
+
|
|
334
|
+
source: a is one extend {
|
|
335
|
+
view: x is {
|
|
336
|
+
group_by: category
|
|
337
|
+
nest: by_period is {
|
|
338
|
+
where: period ~ $PERIOD
|
|
339
|
+
aggregate: n is count()
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}`);
|
|
343
|
+
expect(doc.tiles[0].filters).toBeUndefined();
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// "Whose ENTIRE text is one or more binding clauses" — `a ~ $A and c = 1`
|
|
347
|
+
// matches BINDING_CLAUSE once, for `a ~ $A` alone, and the ` and c = 1`
|
|
348
|
+
// left over means the line is not READ as a binding at all.
|
|
349
|
+
it("does not read a compound predicate as a binding", async () => {
|
|
350
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
351
|
+
import "../m.malloy"
|
|
352
|
+
|
|
353
|
+
source: a is one extend {
|
|
354
|
+
view: x is {
|
|
355
|
+
where: category ~ $CATEGORY and status = 'open'
|
|
356
|
+
aggregate: n is count()
|
|
357
|
+
}
|
|
358
|
+
}`);
|
|
359
|
+
expect(doc.tiles[0].filters).toBeUndefined();
|
|
360
|
+
});
|
|
361
|
+
|
|
362
|
+
// `cleanBindingClauses` accepts a following statement keyword as a clean
|
|
363
|
+
// clause's own boundary — the rule a one-liner's binding needs to share a
|
|
364
|
+
// line with its query — so two clean clauses either side of a real
|
|
365
|
+
// statement can each pass in isolation while the statement between them
|
|
366
|
+
// goes unnoticed. The whole-line check has to reject this shape: read as
|
|
367
|
+
// binding-only, a splice that owns the line would drop `aggregate:` along
|
|
368
|
+
// with the bindings.
|
|
369
|
+
// Two `where:` statements with a measure between them. Each clause has its
|
|
370
|
+
// own span, so both are ordinary bindings -- the writer removes one without
|
|
371
|
+
// touching the measure, which is what the old "not ours" rule stood in for.
|
|
372
|
+
it("reads two bindings with a statement between them", async () => {
|
|
373
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
374
|
+
import "../m.malloy"
|
|
375
|
+
|
|
376
|
+
source: a is one extend {
|
|
377
|
+
view: x is {
|
|
378
|
+
where: a ~ $A, aggregate: n is count(), where: b ~ $B
|
|
379
|
+
}
|
|
380
|
+
}`);
|
|
381
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
382
|
+
{ field: "a", given: "A" },
|
|
383
|
+
{ field: "b", given: "B" },
|
|
384
|
+
]);
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
// Two bindings alone on one line, comma-joined, are still binding-only —
|
|
388
|
+
// the gap between them is nothing but the separator, so the tightening
|
|
389
|
+
// above must not catch this shape too.
|
|
390
|
+
it("still reads two bindings on one line as binding-only", async () => {
|
|
391
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
392
|
+
import "../m.malloy"
|
|
393
|
+
|
|
394
|
+
source: a is one extend {
|
|
395
|
+
view: x is {
|
|
396
|
+
where: a ~ $A, where: b ~ $B
|
|
397
|
+
}
|
|
398
|
+
}`);
|
|
399
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
400
|
+
{ field: "a", given: "A" },
|
|
401
|
+
{ field: "b", given: "B" },
|
|
402
|
+
]);
|
|
403
|
+
});
|
|
404
|
+
|
|
405
|
+
// A second stage does not stop the FIRST stage's own binding from being
|
|
406
|
+
// read; only the WRITER refuses to touch a body shaped like this.
|
|
407
|
+
it("still reads a first-stage binding when a second stage follows", async () => {
|
|
408
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
409
|
+
import "../m.malloy"
|
|
410
|
+
|
|
411
|
+
source: a is one extend {
|
|
412
|
+
view: x is {
|
|
413
|
+
where: category ~ $CATEGORY
|
|
414
|
+
group_by: category
|
|
415
|
+
aggregate: n is count()
|
|
416
|
+
} -> {
|
|
417
|
+
where: n > 10
|
|
418
|
+
select: category, n
|
|
419
|
+
}
|
|
420
|
+
}`);
|
|
421
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
422
|
+
{ field: "category", given: "CATEGORY" },
|
|
423
|
+
]);
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
it("reads a one-line body's binding alongside its query", async () => {
|
|
427
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
428
|
+
import "../m.malloy"
|
|
429
|
+
|
|
430
|
+
source: a is one extend {
|
|
431
|
+
view: x is { aggregate: n is count() where: category ~ $CATEGORY }
|
|
432
|
+
}`);
|
|
433
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
434
|
+
{ field: "category", given: "CATEGORY" },
|
|
435
|
+
]);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
// The boundary after a where: clause is the next statement keyword, not
|
|
439
|
+
// only the next binding clause or the end of the content — a one-line
|
|
440
|
+
// body's binding is followed by comma-joined query text, not nothing.
|
|
441
|
+
it("reads a one-line body's where: even when a comma joins it to more query text", async () => {
|
|
442
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
443
|
+
import "../m.malloy"
|
|
444
|
+
|
|
445
|
+
source: a is one extend {
|
|
446
|
+
view: x is { where: category ~ $CATEGORY, aggregate: n is count() }
|
|
447
|
+
}`);
|
|
448
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
449
|
+
{ field: "category", given: "CATEGORY" },
|
|
450
|
+
]);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
// A where: sharing the line that opens the body's brace, or the line that
|
|
454
|
+
// closes it, is still read as the tile's own binding.
|
|
455
|
+
it("reads a where: sharing a line with the body's opening or closing brace", async () => {
|
|
456
|
+
const opening = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
457
|
+
import "../m.malloy"
|
|
458
|
+
|
|
459
|
+
source: a is one extend {
|
|
460
|
+
view: x is { where: category ~ $CATEGORY
|
|
461
|
+
aggregate: n is count()
|
|
462
|
+
}
|
|
463
|
+
}`);
|
|
464
|
+
expect(opening.tiles[0].filters).toEqual([
|
|
465
|
+
{ field: "category", given: "CATEGORY" },
|
|
466
|
+
]);
|
|
467
|
+
|
|
468
|
+
const closing = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
469
|
+
import "../m.malloy"
|
|
470
|
+
|
|
471
|
+
source: a is one extend {
|
|
472
|
+
view: x is {
|
|
473
|
+
aggregate: n is count()
|
|
474
|
+
where: category ~ $CATEGORY }
|
|
475
|
+
}`);
|
|
476
|
+
expect(closing.tiles[0].filters).toEqual([
|
|
477
|
+
{ field: "category", given: "CATEGORY" },
|
|
478
|
+
]);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
// A source-level `where:` sits outside every view's extent; it is read as
|
|
482
|
+
// part of no tile's filters, the same as it always was.
|
|
483
|
+
it("never attributes a source-level where: to a tile", async () => {
|
|
484
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
485
|
+
import "../m.malloy"
|
|
486
|
+
|
|
487
|
+
source: a is one extend {
|
|
488
|
+
where: brand_name ~ $BRAND
|
|
489
|
+
|
|
490
|
+
view: x is { aggregate: n is count() }
|
|
491
|
+
}`);
|
|
492
|
+
expect(doc.tiles[0].filters).toBeUndefined();
|
|
493
|
+
});
|
|
494
|
+
});
|
|
495
|
+
|
|
205
496
|
describe("readDashboardDocument: the dashboard's own givens", () => {
|
|
206
497
|
// The spelling `givens.malloy` and the docs use, and the one the builder
|
|
207
498
|
// writes: one declaration per `given:` line, its control contract above it.
|
|
@@ -366,7 +657,7 @@ describe("every composite dashboard in the repository opens", () => {
|
|
|
366
657
|
describe("the compiler stays lazy", () => {
|
|
367
658
|
it("is never imported statically", () => {
|
|
368
659
|
const source = fs.readFileSync(
|
|
369
|
-
path.join(import.meta.dir, "
|
|
660
|
+
path.join(import.meta.dir, "malloyTree.ts"),
|
|
370
661
|
"utf8",
|
|
371
662
|
);
|
|
372
663
|
expect(source).not.toMatch(/^\s*import\s[^(]*@malloydata\/malloy/m);
|