@malloy-publisher/sdk 0.2.7 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +180 -204
- package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
- package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
- package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
- package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
- package/dist/{ServerProvider-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
- package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
- package/dist/builder/index.cjs.js +105 -0
- package/dist/builder/index.d.ts +2 -0
- package/dist/builder/index.es.js +9561 -0
- package/dist/builder-entry.d.ts +8 -0
- package/dist/client/api.d.ts +13 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +1 -1
- package/dist/components/ApiErrorDisplay.d.ts +1 -2
- package/dist/components/Dashboard/Dashboard.d.ts +23 -16
- package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
- package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
- package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
- package/dist/components/Dashboard/TileCard.d.ts +44 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
- package/dist/components/Dashboard/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
- package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
- package/dist/components/DashboardBuilder/controls.d.ts +157 -0
- package/dist/components/DashboardBuilder/diff.d.ts +35 -0
- package/dist/components/DashboardBuilder/document.d.ts +218 -0
- package/dist/components/DashboardBuilder/layout.d.ts +71 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
- package/dist/components/DashboardBuilder/preview.d.ts +60 -0
- package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
- package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
- package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
- package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
- package/dist/components/DocumentStorage/index.d.ts +3 -0
- package/dist/components/FloatingIconButton.d.ts +16 -0
- package/dist/components/Model/index.d.ts +0 -1
- package/dist/components/Prose.d.ts +46 -0
- package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
- package/dist/components/RenderedResult/index.d.ts +2 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
- package/dist/components/drill/index.d.ts +2 -1
- package/dist/components/drill/resolveDrill.d.ts +22 -0
- package/dist/components/drill/useDrill.d.ts +11 -2
- package/dist/components/drill/useDrillSelf.d.ts +46 -0
- package/dist/components/given/filterValue.d.ts +63 -0
- package/dist/components/given/index.d.ts +1 -0
- package/dist/components/given/useGivenUrlParams.d.ts +39 -0
- package/dist/components/index.d.ts +3 -3
- package/dist/components/styles.d.ts +3 -7
- package/dist/core-8NVBCLZh.cjs.js +148 -0
- package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useDocumentControls.d.ts +70 -0
- package/dist/hooks/useQueryResult.d.ts +40 -0
- package/dist/hooks/useSuggestOptions.d.ts +28 -12
- package/dist/index.cjs.js +34 -1
- package/dist/index.es.js +21487 -79
- package/dist/sdk.css +1 -1
- package/dist/styles.css +0 -1
- package/dist/utils/malloyLiteral.d.ts +11 -0
- package/package.json +25 -14
- package/src/builder-entry.ts +55 -0
- package/src/components/ApiErrorDisplay.tsx +1 -1
- package/src/components/Connections/EditConnectionDialog.tsx +96 -86
- package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
- package/src/components/Dashboard/Dashboard.tsx +184 -229
- package/src/components/Dashboard/DashboardGrid.tsx +124 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
- package/src/components/Dashboard/DashboardTile.tsx +67 -101
- package/src/components/Dashboard/ExploreDialog.tsx +84 -0
- package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
- package/src/components/Dashboard/RowsDialog.tsx +234 -0
- package/src/components/Dashboard/TileCard.tsx +120 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
- package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
- package/src/components/Dashboard/telemetry.ts +44 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
- package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
- package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
- package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
- package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
- package/src/components/DashboardBuilder/catalog.ts +225 -0
- package/src/components/DashboardBuilder/controls.spec.ts +243 -0
- package/src/components/DashboardBuilder/controls.ts +398 -0
- package/src/components/DashboardBuilder/diff.spec.ts +44 -0
- package/src/components/DashboardBuilder/diff.ts +93 -0
- package/src/components/DashboardBuilder/document.ts +209 -0
- package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
- package/src/components/DashboardBuilder/layout.ts +143 -0
- package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
- package/src/components/DashboardBuilder/malloyText.ts +151 -0
- package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
- package/src/components/DashboardBuilder/preview.spec.ts +149 -0
- package/src/components/DashboardBuilder/preview.ts +172 -0
- package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
- package/src/components/DashboardBuilder/readDocument.ts +467 -0
- package/src/components/DashboardBuilder/sortable.tsx +151 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
- package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
- package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
- package/src/components/DashboardBuilder/useDraft.ts +43 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
- package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
- package/src/components/DashboardBuilder/useTileResize.ts +110 -0
- package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
- package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
- package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
- package/src/components/DocumentStorage/index.ts +16 -0
- package/src/components/Environment/About.tsx +4 -36
- package/src/components/FloatingIconButton.tsx +41 -0
- package/src/components/Model/Model.tsx +6 -23
- package/src/components/Model/ModelCell.tsx +34 -72
- package/src/components/Model/index.ts +0 -1
- package/src/components/Notebook/Notebook.tsx +27 -156
- package/src/components/Notebook/NotebookCell.tsx +37 -191
- package/src/components/Prose.spec.tsx +85 -0
- package/src/components/Prose.tsx +179 -0
- package/src/components/QueryResult/QueryResult.tsx +15 -43
- package/src/components/RenderedResult/RenderedResult.tsx +86 -76
- package/src/components/RenderedResult/ResultContainer.tsx +25 -36
- package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
- package/src/components/RenderedResult/ResultPanel.tsx +73 -0
- package/src/components/RenderedResult/index.ts +16 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
- package/src/components/RenderedResult/resultSizing.ts +308 -0
- package/src/components/ResultsDialog.tsx +2 -1
- package/src/components/drill/index.ts +6 -0
- package/src/components/drill/resolveDrill.ts +22 -1
- package/src/components/drill/useDrill.spec.tsx +94 -0
- package/src/components/drill/useDrill.tsx +52 -12
- package/src/components/drill/useDrillSelf.spec.tsx +64 -0
- package/src/components/drill/useDrillSelf.ts +110 -0
- package/src/components/given/GivenInput.spec.tsx +196 -2
- package/src/components/given/GivenInput.tsx +300 -25
- package/src/components/given/GivensPanel.tsx +1 -1
- package/src/components/given/filterValue.spec.ts +112 -0
- package/src/components/given/filterValue.ts +188 -0
- package/src/components/given/index.ts +4 -0
- package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
- package/src/components/given/useGivenUrlParams.ts +87 -0
- package/src/components/index.ts +11 -3
- package/src/components/styles.ts +0 -37
- package/src/hooks/index.ts +13 -1
- package/src/hooks/useDocumentControls.ts +170 -0
- package/src/hooks/useGivensState.spec.ts +158 -0
- package/src/hooks/useGivensState.ts +114 -23
- package/src/hooks/useQueryResult.ts +82 -0
- package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
- package/src/hooks/useSuggestOptions.ts +94 -51
- package/src/utils/malloyLiteral.spec.ts +43 -0
- package/src/utils/malloyLiteral.ts +76 -0
- package/vite.config.ts +5 -1
- package/dist/components/AnalyzePackageButton.d.ts +0 -6
- package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
- package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
- package/dist/components/Workbook/ModelPicker.d.ts +0 -11
- package/dist/components/Workbook/MutableCell.d.ts +0 -17
- package/dist/components/Workbook/Workbook.d.ts +0 -7
- package/dist/components/Workbook/WorkbookList.d.ts +0 -7
- package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
- package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
- package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
- package/dist/components/Workbook/index.d.ts +0 -7
- package/dist/core-CWKmWEg2.cjs.js +0 -148
- package/dist/index-B0WyZAUA.es.js +0 -66412
- package/dist/index-kxVD1RjY.cjs.js +0 -356
- package/dist/markdown-editor.css +0 -341
- package/src/components/AnalyzePackageButton.tsx +0 -319
- package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
- package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
- package/src/components/Workbook/ModelPicker.tsx +0 -134
- package/src/components/Workbook/MutableCell.tsx +0 -458
- package/src/components/Workbook/Workbook.tsx +0 -501
- package/src/components/Workbook/WorkbookList.tsx +0 -110
- package/src/components/Workbook/WorkbookManager.ts +0 -214
- package/src/components/Workbook/WorkbookStorage.ts +0 -35
- package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
- package/src/components/Workbook/index.ts +0 -10
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { openDocument } from "./testing/fixtures";
|
|
6
|
+
import * as fs from "fs";
|
|
7
|
+
import * as path from "path";
|
|
8
|
+
import { blockAbove, readDashboardDocument, readFailed } from "./readDocument";
|
|
9
|
+
|
|
10
|
+
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
11
|
+
|
|
12
|
+
const read = openDocument;
|
|
13
|
+
|
|
14
|
+
const SIMPLE = `##! experimental.givens
|
|
15
|
+
|
|
16
|
+
##" A narrative header.
|
|
17
|
+
##" Second paragraph.
|
|
18
|
+
## artifact { title="Probe" tiles=["a -> by_cat"] givens { CATEGORY="Jeans" } } dashboard { columns=12 }
|
|
19
|
+
import "../data_app.malloy"
|
|
20
|
+
import { products, regions } from "../storefront.malloy"
|
|
21
|
+
|
|
22
|
+
source: a is scoped_orders extend {
|
|
23
|
+
# colspan=6
|
|
24
|
+
# break
|
|
25
|
+
# label="By category"
|
|
26
|
+
view: by_cat is by_category
|
|
27
|
+
}`;
|
|
28
|
+
|
|
29
|
+
describe("blockAbove", () => {
|
|
30
|
+
// The boundary is a blank line, because that is the author's own separator.
|
|
31
|
+
// Validated against the bundled dashboard, where the block above
|
|
32
|
+
// `revenue_trend` is fourteen lines of comment plus three tags.
|
|
33
|
+
it("collects tags and comments up to the blank line", () => {
|
|
34
|
+
const lines = [
|
|
35
|
+
" }",
|
|
36
|
+
"",
|
|
37
|
+
" // why this row is six and six",
|
|
38
|
+
" # colspan=6",
|
|
39
|
+
' # label="Revenue"',
|
|
40
|
+
" view: revenue is sales",
|
|
41
|
+
];
|
|
42
|
+
const block = blockAbove(lines, 5);
|
|
43
|
+
expect(block.start).toBe(2);
|
|
44
|
+
expect(block.tags.map((t) => t.text)).toEqual([
|
|
45
|
+
"# colspan=6",
|
|
46
|
+
'# label="Revenue"',
|
|
47
|
+
]);
|
|
48
|
+
// The writer patches a tag in place, so the line number is load-bearing.
|
|
49
|
+
expect(block.tags.map((t) => t.line)).toEqual([3, 4]);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("stops at the blank line rather than running into the tile above", () => {
|
|
53
|
+
const lines = [" # colspan=12", " view: a is x", "", " view: b is y"];
|
|
54
|
+
expect(blockAbove(lines, 3).start).toBe(3);
|
|
55
|
+
expect(blockAbove(lines, 3).tags).toEqual([]);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// `##` is a MODEL annotation and never belongs to a declaration below it.
|
|
59
|
+
it("ignores model-level annotations", () => {
|
|
60
|
+
const lines = ['## artifact { title="T" }', "source: a is b extend {"];
|
|
61
|
+
expect(blockAbove(lines, 1).tags).toEqual([]);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("readDashboardDocument", () => {
|
|
66
|
+
it("reads the whole shape", async () => {
|
|
67
|
+
const doc = await read(SIMPLE);
|
|
68
|
+
expect(doc.title).toBe("Probe");
|
|
69
|
+
expect(doc.description).toBe("A narrative header.\nSecond paragraph.");
|
|
70
|
+
expect(doc.columns).toBe(12);
|
|
71
|
+
expect(doc.startingGivens).toEqual({ CATEGORY: "Jeans" });
|
|
72
|
+
expect(doc.sources).toEqual([{ name: "a", base: "scoped_orders" }]);
|
|
73
|
+
expect(doc.tiles).toEqual([
|
|
74
|
+
{
|
|
75
|
+
name: "by_cat",
|
|
76
|
+
source: "a",
|
|
77
|
+
declaration: { kind: "reference", from: "by_category" },
|
|
78
|
+
label: "By category",
|
|
79
|
+
colspan: 6,
|
|
80
|
+
break: true,
|
|
81
|
+
},
|
|
82
|
+
]);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Both forms, and they are not interchangeable: a bare import is not
|
|
86
|
+
// transitive, so a `suggest { source=products }` needs `products` named.
|
|
87
|
+
it("reads both import forms", async () => {
|
|
88
|
+
const doc = await read(SIMPLE);
|
|
89
|
+
expect(doc.imports).toEqual([
|
|
90
|
+
{ kind: "all", from: "../data_app.malloy" },
|
|
91
|
+
{
|
|
92
|
+
kind: "names",
|
|
93
|
+
names: ["products", "regions"],
|
|
94
|
+
from: "../storefront.malloy",
|
|
95
|
+
},
|
|
96
|
+
]);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// The reason the document holds a LIST of sources: a composite exists to
|
|
100
|
+
// combine queries no single Malloy result can span.
|
|
101
|
+
it("reads a dashboard spanning two sources", async () => {
|
|
102
|
+
const doc =
|
|
103
|
+
await read(`## artifact { title="T" tiles=["a -> x", "b -> y"] }
|
|
104
|
+
import "../m.malloy"
|
|
105
|
+
|
|
106
|
+
source: a is one extend {
|
|
107
|
+
view: x is vx
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
source: b is two extend {
|
|
111
|
+
view: y is vy
|
|
112
|
+
}`);
|
|
113
|
+
expect(doc.sources.map((s) => s.name)).toEqual(["a", "b"]);
|
|
114
|
+
expect(doc.tiles.map((t) => `${t.source}.${t.name}`)).toEqual([
|
|
115
|
+
"a.x",
|
|
116
|
+
"b.y",
|
|
117
|
+
]);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("reads a filter binding written as a refinement", async () => {
|
|
121
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
122
|
+
import "../m.malloy"
|
|
123
|
+
|
|
124
|
+
source: a is one extend {
|
|
125
|
+
view: x is vx + { where: products.brand ~ $BRAND }
|
|
126
|
+
}`);
|
|
127
|
+
expect(doc.tiles[0].declaration).toEqual({
|
|
128
|
+
kind: "reference",
|
|
129
|
+
from: "vx",
|
|
130
|
+
});
|
|
131
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
132
|
+
{ field: "products.brand", given: "BRAND" },
|
|
133
|
+
]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// Drill is authorable in the dashboard file, so the document carries it.
|
|
137
|
+
it("reads a drill dimension", async () => {
|
|
138
|
+
const doc = await read(`## artifact { title="T" tiles=["a -> x"] }
|
|
139
|
+
import "../m.malloy"
|
|
140
|
+
|
|
141
|
+
source: a is one extend {
|
|
142
|
+
# drill { to=self given=CATEGORY }
|
|
143
|
+
dimension: cat is products.category
|
|
144
|
+
|
|
145
|
+
view: x is vx
|
|
146
|
+
}`);
|
|
147
|
+
expect(doc.drills).toEqual([
|
|
148
|
+
{
|
|
149
|
+
source: "a",
|
|
150
|
+
name: "cat",
|
|
151
|
+
expression: "products.category",
|
|
152
|
+
to: ["self"],
|
|
153
|
+
given: "CATEGORY",
|
|
154
|
+
},
|
|
155
|
+
]);
|
|
156
|
+
// And the dimension itself, tagged or not, is where a drill can go.
|
|
157
|
+
expect(doc.sources[0].dimensions).toEqual([
|
|
158
|
+
{ name: "cat", expression: "products.category" },
|
|
159
|
+
]);
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
// Givens are the one declaration the parser's symbol tree does not cover.
|
|
163
|
+
it("reads a dashboard-local given", async () => {
|
|
164
|
+
const doc = await read(`##! experimental.givens
|
|
165
|
+
## artifact { title="T" tiles=["a -> x"] }
|
|
166
|
+
import "../m.malloy"
|
|
167
|
+
|
|
168
|
+
given:
|
|
169
|
+
# label="Local" control=select
|
|
170
|
+
LOCAL_X :: filter<string> is f'Jeans'
|
|
171
|
+
|
|
172
|
+
source: a is one extend {
|
|
173
|
+
view: x is vx
|
|
174
|
+
}`);
|
|
175
|
+
expect(doc.localGivens).toEqual([
|
|
176
|
+
{
|
|
177
|
+
name: "LOCAL_X",
|
|
178
|
+
type: "filter<string>",
|
|
179
|
+
default: "f'Jeans'",
|
|
180
|
+
label: "Local",
|
|
181
|
+
control: "select",
|
|
182
|
+
},
|
|
183
|
+
]);
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe("readDashboardDocument: how a tile binds", () => {
|
|
188
|
+
// A `filter<…>` binds with `~`; a plain `date` is a value and binds with a
|
|
189
|
+
// comparison. The reader keeps `~` implicit so the common case stays small.
|
|
190
|
+
it("reads the comparison a binding uses", async () => {
|
|
191
|
+
const doc = await read(`##! experimental.givens
|
|
192
|
+
## artifact { title="T" tiles=["a -> x"] }
|
|
193
|
+
import "../m.malloy"
|
|
194
|
+
|
|
195
|
+
source: a is one extend {
|
|
196
|
+
view: x is vx + { where: category ~ $CATEGORY, where: created_at >= $SINCE, limit: 5 }
|
|
197
|
+
}`);
|
|
198
|
+
expect(doc.tiles[0].filters).toEqual([
|
|
199
|
+
{ field: "category", given: "CATEGORY" },
|
|
200
|
+
{ field: "created_at", given: "SINCE", op: ">=" },
|
|
201
|
+
]);
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
describe("readDashboardDocument: the dashboard's own givens", () => {
|
|
206
|
+
// The spelling `givens.malloy` and the docs use, and the one the builder
|
|
207
|
+
// writes: one declaration per `given:` line, its control contract above it.
|
|
208
|
+
it("reads one-line givens with their whole control contract", async () => {
|
|
209
|
+
const doc = await read(`##! experimental.givens
|
|
210
|
+
## artifact { title="T" tiles=["a -> x"] }
|
|
211
|
+
import { one, products } from "../m.malloy"
|
|
212
|
+
|
|
213
|
+
# description="Narrow to one category" label="Category" control=select suggest { source=products dimension=category }
|
|
214
|
+
given: CATEGORY :: filter<string> is f''
|
|
215
|
+
|
|
216
|
+
# label="Minimum line total" range_min=0 range_max=250
|
|
217
|
+
given: MIN_SALE :: filter<number> is f''
|
|
218
|
+
|
|
219
|
+
source: a is one extend {
|
|
220
|
+
view: x is vx + { where: category ~ $CATEGORY }
|
|
221
|
+
}`);
|
|
222
|
+
expect(doc.localGivens).toEqual([
|
|
223
|
+
{
|
|
224
|
+
name: "CATEGORY",
|
|
225
|
+
type: "filter<string>",
|
|
226
|
+
default: "f''",
|
|
227
|
+
label: "Category",
|
|
228
|
+
description: "Narrow to one category",
|
|
229
|
+
control: "select",
|
|
230
|
+
suggest: { source: "products", dimension: "category" },
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
name: "MIN_SALE",
|
|
234
|
+
type: "filter<number>",
|
|
235
|
+
default: "f''",
|
|
236
|
+
label: "Minimum line total",
|
|
237
|
+
rangeMin: 0,
|
|
238
|
+
rangeMax: 250,
|
|
239
|
+
},
|
|
240
|
+
]);
|
|
241
|
+
});
|
|
242
|
+
|
|
243
|
+
it("reads both spellings from one file, in file order", async () => {
|
|
244
|
+
const doc = await read(`##! experimental.givens
|
|
245
|
+
## artifact { title="T" tiles=["a -> x"] }
|
|
246
|
+
import "../m.malloy"
|
|
247
|
+
|
|
248
|
+
given: FIRST :: date is @2023-01-01
|
|
249
|
+
|
|
250
|
+
given:
|
|
251
|
+
# control=multiselect suggest { query=brand_suggest dimension=brand }
|
|
252
|
+
BRAND :: filter<string> is f''
|
|
253
|
+
|
|
254
|
+
source: a is one extend {
|
|
255
|
+
view: x is vx
|
|
256
|
+
}`);
|
|
257
|
+
expect(doc.localGivens?.map((g) => g.name)).toEqual(["FIRST", "BRAND"]);
|
|
258
|
+
expect(doc.localGivens?.[1].suggest).toEqual({
|
|
259
|
+
query: "brand_suggest",
|
|
260
|
+
dimension: "brand",
|
|
261
|
+
});
|
|
262
|
+
});
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
describe("readDashboardDocument: what it refuses", () => {
|
|
266
|
+
// All-or-nothing, and every refusal names what it could not understand.
|
|
267
|
+
// "Cannot open this dashboard" with no reason reads as a bug.
|
|
268
|
+
it("refuses a file with no artifact tag", async () => {
|
|
269
|
+
const r = await readDashboardDocument("source: a is b extend { }");
|
|
270
|
+
expect(r.ok).toBe(false);
|
|
271
|
+
if (readFailed(r)) expect(r.reason).toContain("composite dashboard");
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
it("refuses a tile that is not a source -> view expression", async () => {
|
|
275
|
+
const r = await readDashboardDocument(
|
|
276
|
+
`## artifact { title="T" tiles=["just_a_name"] }\nsource: a is b extend { view: x is y }`,
|
|
277
|
+
);
|
|
278
|
+
expect(r.ok).toBe(false);
|
|
279
|
+
if (readFailed(r)) expect(r.reason).toContain("source -> view");
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
// NOT a refusal, and the tripwire is what taught us so: a dashboard whose
|
|
283
|
+
// only tile reads a view on an IMPORTED source declares nothing at all, and
|
|
284
|
+
// is a complete dashboard. It opens, and that tile is read-only because its
|
|
285
|
+
// tags live on the model's view.
|
|
286
|
+
it("opens a tile whose view belongs to an imported source", async () => {
|
|
287
|
+
const doc = await read(
|
|
288
|
+
`## artifact { title="T" tiles=["orders -> by_brand"] }\nimport { orders } from '../orders.malloy'`,
|
|
289
|
+
);
|
|
290
|
+
expect(doc.sources).toEqual([]);
|
|
291
|
+
expect(doc.tiles).toEqual([
|
|
292
|
+
{
|
|
293
|
+
name: "by_brand",
|
|
294
|
+
source: "orders",
|
|
295
|
+
declaration: { kind: "inherited" },
|
|
296
|
+
},
|
|
297
|
+
]);
|
|
298
|
+
});
|
|
299
|
+
|
|
300
|
+
// Same principle for an inline body: the tags are editable, the query is not.
|
|
301
|
+
it("opens a tile declared with an inline body", async () => {
|
|
302
|
+
const doc = await read(
|
|
303
|
+
`## artifact { title="T" tiles=["a -> x"] }\nimport "../m.malloy"\nsource: a is one extend {\n # colspan=6\n view: x is { aggregate: n }\n}`,
|
|
304
|
+
);
|
|
305
|
+
expect(doc.tiles[0].declaration).toEqual({ kind: "inline" });
|
|
306
|
+
expect(doc.tiles[0].colspan).toBe(6);
|
|
307
|
+
});
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
/**
|
|
311
|
+
* The tripwire. All-or-nothing refusal is only reasonable while real dashboards
|
|
312
|
+
* open, so this asserts that every composite dashboard in the repository does.
|
|
313
|
+
* If that stops being true, this fails in CI rather than in a support thread,
|
|
314
|
+
* and it is the signal to reconsider opening files partially.
|
|
315
|
+
*/
|
|
316
|
+
describe("every composite dashboard in the repository opens", () => {
|
|
317
|
+
const roots = ["examples", "packages/server/tests/fixtures"];
|
|
318
|
+
const found: string[] = [];
|
|
319
|
+
const walk = (dir: string) => {
|
|
320
|
+
if (!fs.existsSync(dir)) return;
|
|
321
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
322
|
+
const full = path.join(dir, entry.name);
|
|
323
|
+
if (entry.isDirectory()) walk(full);
|
|
324
|
+
else if (entry.name.endsWith(".malloy") && full.includes("dashboards"))
|
|
325
|
+
found.push(full);
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
for (const root of roots) walk(path.join(REPO, root));
|
|
329
|
+
|
|
330
|
+
const composites = found.filter((f) =>
|
|
331
|
+
/##\s*artifact[\s\S]*tiles\s*=/.test(fs.readFileSync(f, "utf8")),
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
it("finds composites to check", () => {
|
|
335
|
+
expect(composites.length).toBeGreaterThan(0);
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
for (const file of composites) {
|
|
339
|
+
const name = path.relative(REPO, file);
|
|
340
|
+
// The lint fixtures exist to BE broken; they are exercised by the refusal
|
|
341
|
+
// tests above rather than expected to open.
|
|
342
|
+
const expectBroken = name.includes("dashboards-lint");
|
|
343
|
+
it(`${expectBroken ? "refuses" : "opens"} ${name}`, async () => {
|
|
344
|
+
const result = await readDashboardDocument(
|
|
345
|
+
fs.readFileSync(file, "utf8"),
|
|
346
|
+
);
|
|
347
|
+
if (expectBroken) return; // either outcome is acceptable for these
|
|
348
|
+
if (readFailed(result)) throw new Error(result.reason);
|
|
349
|
+
// Tiles, always. Sources NOT always: a dashboard whose tiles all read
|
|
350
|
+
// imported sources declares no extension at all, which the tripwire
|
|
351
|
+
// taught us on its first run.
|
|
352
|
+
expect(result.document.tiles.length).toBeGreaterThan(0);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* The bundle guard. `@malloydata/malloy` is ~440 KB gzipped, and it is only
|
|
359
|
+
* worth adding because it loads when the builder does and not before. One
|
|
360
|
+
* STATIC import anywhere eagerly reachable hoists it into the entry chunk and
|
|
361
|
+
* every Console user pays for it — silently, visible only in a bundle diff.
|
|
362
|
+
*
|
|
363
|
+
* So the rule is enforced rather than reviewed: the reader reaches the compiler
|
|
364
|
+
* through `await import(…)` and nothing else.
|
|
365
|
+
*/
|
|
366
|
+
describe("the compiler stays lazy", () => {
|
|
367
|
+
it("is never imported statically", () => {
|
|
368
|
+
const source = fs.readFileSync(
|
|
369
|
+
path.join(import.meta.dir, "readDocument.ts"),
|
|
370
|
+
"utf8",
|
|
371
|
+
);
|
|
372
|
+
expect(source).not.toMatch(/^\s*import\s[^(]*@malloydata\/malloy/m);
|
|
373
|
+
expect(source).toContain('await import("@malloydata/malloy")');
|
|
374
|
+
});
|
|
375
|
+
});
|