@malloy-publisher/sdk 0.17.0 → 0.17.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/README.md +32 -50
  2. package/dist/{RenderedResult-BcEDcw0V.es.js → RenderedResult-CYJ2Y9Fm.es.js} +24 -24
  3. package/dist/{RenderedResult-uT2oc6ke.cjs.js → RenderedResult-hRvgFMAF.cjs.js} +1 -1
  4. package/dist/ServerProvider-DeVejmVr.cjs.js +1 -0
  5. package/dist/{ServerProvider-vmEUjlEu.es.js → ServerProvider-DzzfVDg_.es.js} +1314 -1712
  6. package/dist/builder/index.cjs.js +12 -12
  7. package/dist/builder/index.es.js +4 -9
  8. package/dist/client/api.d.ts +63 -506
  9. package/dist/client/configuration.d.ts +1 -1
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.d.ts +1 -1
  12. package/dist/client/index.es.js +132 -144
  13. package/dist/components/Dashboard/DashboardGrid.d.ts +1 -1
  14. package/dist/components/Model/ExplorerPage.d.ts +1 -3
  15. package/dist/components/Model/Model.d.ts +1 -4
  16. package/dist/components/Model/ModelExplorer.d.ts +1 -2
  17. package/dist/components/Package/reportQueries.d.ts +2 -4
  18. package/dist/components/Report/Report.d.ts +20 -9
  19. package/dist/components/{legacy → Report}/malloynb/CellRunnerView.d.ts +13 -16
  20. package/dist/components/Report/malloynb/MalloynbReport.d.ts +11 -0
  21. package/dist/components/{legacy → Report}/malloynb/cellKind.d.ts +1 -1
  22. package/dist/components/ServerProvider.d.ts +1 -3
  23. package/dist/components/drill/drillClauses.d.ts +8 -9
  24. package/dist/components/drill/rowsTarget.d.ts +7 -9
  25. package/dist/components/legacy/index.d.ts +3 -7
  26. package/dist/components/modelPage.d.ts +2 -5
  27. package/dist/hooks/useModelGivens.d.ts +2 -2
  28. package/dist/hooks/useQueryResult.d.ts +7 -0
  29. package/dist/index.cjs.js +33 -33
  30. package/dist/index.es.js +8799 -8903
  31. package/dist/{useCompiledDocument-h5-Kc1Zh.cjs.js → useCompiledDocument-BCr-xB_i.cjs.js} +4 -4
  32. package/dist/{useCompiledDocument-rOwDSK_s.es.js → useCompiledDocument-E0tU5KzP.es.js} +266 -277
  33. package/package.json +1 -1
  34. package/src/components/Dashboard/DashboardGrid.tsx +1 -1
  35. package/src/components/Dashboard/DashboardTile.spec.tsx +1 -1
  36. package/src/components/Model/ExplorerPage.tsx +1 -3
  37. package/src/components/Model/Model.tsx +1 -4
  38. package/src/components/Model/ModelExplorer.tsx +1 -2
  39. package/src/components/Package/Package.tsx +1 -5
  40. package/src/components/Package/reportQueries.ts +3 -15
  41. package/src/components/Report/Report.malloynb.spec.tsx +230 -0
  42. package/src/components/Report/Report.spec.tsx +429 -38
  43. package/src/components/Report/Report.telemetry.spec.tsx +51 -10
  44. package/src/components/Report/Report.tsx +63 -44
  45. package/src/components/{legacy → Report}/malloynb/CellRunnerView.spec.tsx +11 -44
  46. package/src/components/{legacy → Report}/malloynb/CellRunnerView.tsx +63 -107
  47. package/src/components/Report/malloynb/MalloynbReport.tsx +110 -0
  48. package/src/components/{legacy → Report}/malloynb/cellKind.ts +5 -4
  49. package/src/components/ReportBuilder/EditorSurface.tsx +3 -3
  50. package/src/components/ReportBuilder/ReportBuilder.spec.tsx +2 -2
  51. package/src/components/ReportBuilder/ReportEditor.notebook.spec.tsx +0 -4
  52. package/src/components/ReportBuilder/ReportEditor.queryVersion.spec.tsx +0 -1
  53. package/src/components/ReportBuilder/ReportEditor.resourceUri.spec.tsx +3 -3
  54. package/src/components/ReportBuilder/ReportEditor.tsx +1 -1
  55. package/src/components/ReportBuilder/loadMalloy.ts +1 -4
  56. package/src/components/ReportBuilder/useSaveChannel.ts +1 -6
  57. package/src/components/ServerProvider.tsx +0 -4
  58. package/src/components/drill/drillClauses.ts +8 -9
  59. package/src/components/drill/rowsTarget.ts +7 -9
  60. package/src/components/index.ts +2 -3
  61. package/src/components/legacy/index.ts +3 -7
  62. package/src/components/modelPage.ts +2 -5
  63. package/src/hooks/useGivensState.ts +8 -8
  64. package/src/hooks/useModelGivens.ts +2 -2
  65. package/src/hooks/useQueryResult.ts +30 -18
  66. package/test/README.md +4 -4
  67. package/dist/ServerProvider-DDRwHiPz.cjs.js +0 -1
  68. package/dist/components/legacy/Dashboard.d.ts +0 -68
  69. package/dist/components/legacy/malloynb/MalloynbCells.d.ts +0 -13
  70. package/dist/components/legacy/malloynb/Notebook.d.ts +0 -15
  71. package/dist/components/legacy/queryKeys.d.ts +0 -8
  72. package/src/components/legacy/Dashboard.spec.tsx +0 -242
  73. package/src/components/legacy/Dashboard.tsx +0 -181
  74. package/src/components/legacy/malloynb/MalloynbCells.tsx +0 -88
  75. package/src/components/legacy/malloynb/Notebook.layout.spec.tsx +0 -103
  76. package/src/components/legacy/malloynb/Notebook.served.spec.tsx +0 -84
  77. package/src/components/legacy/malloynb/Notebook.spec.tsx +0 -223
  78. package/src/components/legacy/malloynb/Notebook.tsx +0 -46
  79. package/src/components/legacy/queryKeys.ts +0 -26
  80. /package/dist/components/{legacy → Report}/malloynb/NotebookCell.d.ts +0 -0
  81. /package/dist/components/{legacy → Report}/malloynb/runPlan.d.ts +0 -0
  82. /package/dist/components/{legacy → Report}/malloynb/types.d.ts +0 -0
  83. /package/src/components/{legacy → Report}/malloynb/NotebookCell.tsx +0 -0
  84. /package/src/components/{legacy → Report}/malloynb/cellKind.spec.ts +0 -0
  85. /package/src/components/{legacy → Report}/malloynb/runPlan.spec.ts +0 -0
  86. /package/src/components/{legacy → Report}/malloynb/runPlan.ts +0 -0
  87. /package/src/components/{legacy → Report}/malloynb/types.ts +0 -0
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.17.0",
4
+ "version": "0.17.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -185,7 +185,7 @@ export const readingOrder = (tile: GridTile) =>
185
185
  * The composite dashboard's grid: the column track, and each tile's place on
186
186
  * it.
187
187
  *
188
- * Shared by the READER ({@link Dashboard}) and the BUILDER, which is the whole
188
+ * Shared by the READER (`DashboardView`) and the BUILDER, which is the whole
189
189
  * point of it being a component rather than a rule each surface applies. An
190
190
  * author arranging a dashboard is arranging the thing a reader will open, so
191
191
  * the two cannot be allowed to lay tiles out even slightly differently; a
@@ -2,7 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  /**
5
- * The tile's own query key, asserted directly rather than through `Dashboard`.
5
+ * The tile's own query key, asserted directly rather than through `DashboardView`.
6
6
  *
7
7
  * `DashboardTile` is exported from the package root, so a host can mount one
8
8
  * itself, and `versionId` has to land in both the request and the key from the
@@ -31,9 +31,7 @@ import { useModelData } from "./useModelData";
31
31
  /**
32
32
  * The model page on a server whose `PUBLISHER_MODEL_PAGE` is `explorer`, the
33
33
  * default: the Malloy Explorer over the model's sources, and its named
34
- * queries. The Explorer writes the queries it builds back to Malloy text
35
- * through `@malloydata/malloy-interfaces`, which puts a string value in
36
- * unescaped, so a drilled value holding a double quote rewrites its query.
34
+ * queries.
37
35
  */
38
36
  export function ExplorerPage({
39
37
  onChange,
@@ -61,10 +61,7 @@ function CopyLinkButton() {
61
61
  * `viewer` server never flashes the Explorer.
62
62
  *
63
63
  * - `explorer`, the default: the Malloy Explorer over the model's sources
64
- * ({@link ExplorerPage}), and its named queries. The Explorer writes the
65
- * queries it builds back to Malloy text through
66
- * `@malloydata/malloy-interfaces`, whose string escaping is a TODO, so a
67
- * drilled value holding a double quote rewrites its query.
64
+ * ({@link ExplorerPage}), and its named queries.
68
65
  * - `viewer`: the model viewer ({@link ModelViewer}) with a Copy link action
69
66
  * on its heading. Each source's views, measures, calculations, dimensions
70
67
  * and joins, the model's named queries, and the givens they read. It writes
@@ -71,8 +71,7 @@ export interface ModelExplorerProps {
71
71
  * `givens` alone says which parameters to write but not which to REMOVE, so
72
72
  * a host that guesses by deleting everything it did not just receive
73
73
  * deletes the unrelated parameters it has no business touching. Same
74
- * contract as `Dashboard` and `Notebook`, so a host can treat every surface
75
- * alike.
74
+ * contract as `Report`, so a host can treat every surface alike.
76
75
  */
77
76
  onGivensChange?: (
78
77
  givens: Record<string, string>,
@@ -486,11 +486,7 @@ export default function Package({
486
486
  onClose={() => setCreating(false)}
487
487
  onCreated={(created) => {
488
488
  setCreating(false);
489
- invalidateReportQueries(
490
- queryClient,
491
- environmentName,
492
- packageName,
493
- );
489
+ invalidateReportQueries(queryClient);
494
490
  void queryClient.invalidateQueries({ queryKey: ["models"] });
495
491
  openDocument({
496
492
  path: created.path,
@@ -2,24 +2,12 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import type { QueryClient } from "@tanstack/react-query";
5
- import { legacyReportQueryKeys } from "../legacy/queryKeys";
6
5
 
7
6
  /**
8
7
  * Drop every cached read of a package's reports after a write changed them:
9
- * each report's manifest, the listing, and the deprecated readers' copies,
10
- * whose listings a layout switch moves a report between. With `modelPath`,
11
- * the one report's own cached reads too.
8
+ * each report's manifest and the package's report listing.
12
9
  */
13
- export function invalidateReportQueries(
14
- queryClient: QueryClient,
15
- environmentName: string,
16
- packageName: string,
17
- modelPath?: string,
18
- ): void {
19
- for (const queryKey of [
20
- ["report"],
21
- ["reports"],
22
- ...legacyReportQueryKeys(environmentName, packageName, modelPath),
23
- ])
10
+ export function invalidateReportQueries(queryClient: QueryClient): void {
11
+ for (const queryKey of [["report"], ["reports"]])
24
12
  void queryClient.invalidateQueries({ queryKey });
25
13
  }
@@ -0,0 +1,230 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ // DEPRECATED FEATURE COVERAGE — delete together with
5
+ // `.malloynb` notebooks (see RELEASE_NOTES deprecations).
6
+
7
+ /**
8
+ * What a `.malloynb`'s cells offer around their results, drawn by `Report`:
9
+ * the cell's "Data sources" dialog, which is the Malloy Explorer and so is
10
+ * offered only where the server's model page allows it and opens on the
11
+ * report's current values; the copy-link icon on a leading markdown cell; and
12
+ * suggest queries pinned to the version the report was opened at.
13
+ */
14
+ import { beforeEach, expect, it, mock } from "bun:test";
15
+ import { fireEvent, render, screen, waitFor } from "@testing-library/react";
16
+ import type { ReactNode } from "react";
17
+ import {
18
+ cacheKeys,
19
+ clearCache,
20
+ mockServerProvider,
21
+ pending,
22
+ serverWrapper,
23
+ } from "../../../test/serverProvider";
24
+ import type { ReportManifest } from "../../client";
25
+
26
+ const PATH = "notebooks/ops.malloynb";
27
+
28
+ const NOTEBOOK = {
29
+ path: PATH,
30
+ name: "ops",
31
+ layout: "linear",
32
+ editable: false,
33
+ notebook: {
34
+ format: "malloynb",
35
+ notebookCells: [
36
+ { type: "markdown", text: "Ops prose" },
37
+ {
38
+ type: "code",
39
+ text: "import { orders } from './orders.malloy'",
40
+ // What makes the cell's "Data sources" icon appear.
41
+ newSources: [JSON.stringify({ name: "orders" })],
42
+ },
43
+ ],
44
+ sources: [
45
+ {
46
+ name: "orders",
47
+ givens: [
48
+ {
49
+ name: "REGION",
50
+ control: "select",
51
+ suggest: { source: "orders", dimension: "region" },
52
+ },
53
+ // Plain text, so the dialog test can type a value directly.
54
+ { name: "TENANT", type: "string" },
55
+ ],
56
+ },
57
+ ],
58
+ },
59
+ } as ReportManifest;
60
+
61
+ let manifest: ReportManifest = NOTEBOOK;
62
+ const getReport = mock(() => Promise.resolve({ data: manifest }));
63
+ const executeQueryModel = mock(
64
+ (
65
+ _environmentName: string,
66
+ _packageName: string,
67
+ _modelPath: string,
68
+ _request: { versionId?: string },
69
+ ): Promise<never> => pending(),
70
+ );
71
+
72
+ // The Explorer itself is lazy, WASM-backed and not under test: only what the
73
+ // cell hands it is, so the stub records its props.
74
+ const dataSourcesDialogProps = mock(
75
+ (_props: {
76
+ open: boolean;
77
+ startingGivens?: Record<string, string>;
78
+ data?: { givens?: { name?: string }[] };
79
+ }) => {},
80
+ );
81
+ mock.module("../Model/ModelExplorerDialog", () => ({
82
+ ModelExplorerDialog: (props: {
83
+ open: boolean;
84
+ startingGivens?: Record<string, string>;
85
+ data?: { givens?: { name?: string }[] };
86
+ }) => {
87
+ dataSourcesDialogProps(props);
88
+ return null as ReactNode;
89
+ },
90
+ }));
91
+
92
+ // The server's /status answer: the model page a test switches to `viewer`.
93
+ const serverContext: { modelPage?: string; isLoadingStatus?: boolean } = {};
94
+ mockServerProvider(
95
+ {
96
+ reports: { getReport },
97
+ models: { executeQueryModel, getModel: () => pending() },
98
+ },
99
+ serverContext,
100
+ );
101
+
102
+ // Imported after the stub is registered: a static import would hoist above it.
103
+ const { Report } = await import("./Report");
104
+
105
+ const URI = "publisher://environments/env/packages/pkg";
106
+
107
+ beforeEach(() => {
108
+ manifest = NOTEBOOK;
109
+ clearCache();
110
+ getReport.mockClear();
111
+ executeQueryModel.mockClear();
112
+ dataSourcesDialogProps.mockClear();
113
+ });
114
+
115
+ it("runs its suggest queries on the notebook's path, at the version it was opened at", async () => {
116
+ render(<Report resourceUri={`${URI}?versionId=v2`} path={PATH} />, {
117
+ wrapper: serverWrapper,
118
+ });
119
+
120
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
121
+ expect(executeQueryModel.mock.calls[0][2]).toBe(PATH);
122
+ expect(executeQueryModel.mock.calls[0][3].versionId).toBe("v2");
123
+ expect(cacheKeys("givenSuggest")[0]).toContain('"v2"');
124
+ });
125
+
126
+ it("sends no version on a suggest query when the report was opened without one", async () => {
127
+ render(<Report resourceUri={URI} path={PATH} />, {
128
+ wrapper: serverWrapper,
129
+ });
130
+
131
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
132
+ expect(executeQueryModel.mock.calls[0][3].versionId).toBeUndefined();
133
+ });
134
+
135
+ it("opens a cell's 'Data sources' dialog with the report's current values", async () => {
136
+ render(<Report resourceUri={URI} path={PATH} />, {
137
+ wrapper: serverWrapper,
138
+ });
139
+
140
+ // The control sits in its filter button's popover.
141
+ fireEvent.click(await screen.findByRole("button", { name: /^TENANT: / }));
142
+ const input = (await screen.findByLabelText("TENANT")) as HTMLInputElement;
143
+ fireEvent.change(input, { target: { value: "acme" } });
144
+ // The control re-renders with the value before the dialog opens, or the
145
+ // click lands on a render that has not carried it yet.
146
+ await waitFor(() => expect(input.value).toBe("acme"));
147
+
148
+ fireEvent.click(await screen.findByLabelText("Data sources"));
149
+
150
+ await waitFor(() =>
151
+ expect(dataSourcesDialogProps.mock.calls.at(-1)?.[0]?.open).toBe(true),
152
+ );
153
+ const lastCall = dataSourcesDialogProps.mock.calls.at(-1)?.[0];
154
+ expect(lastCall?.startingGivens).toEqual({ TENANT: "acme" });
155
+ // The values alone render nothing: the dialog needs the declarations too.
156
+ expect(lastCall?.data?.givens?.map((given) => given.name)).toContain(
157
+ "TENANT",
158
+ );
159
+ });
160
+
161
+ // A server with PUBLISHER_MODEL_PAGE=viewer takes the Explorer out of the
162
+ // Console, and the "Data sources" dialog is the Explorer.
163
+ it("offers no 'Data sources' dialog on a server whose model page is the viewer", async () => {
164
+ serverContext.modelPage = "viewer";
165
+ try {
166
+ render(<Report resourceUri={URI} path={PATH} />, {
167
+ wrapper: serverWrapper,
168
+ });
169
+ await screen.findByText("Ops prose");
170
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
171
+ expect(screen.queryByLabelText("Data sources")).toBeNull();
172
+ expect(dataSourcesDialogProps).not.toHaveBeenCalledWith(
173
+ expect.objectContaining({ open: true }),
174
+ );
175
+ } finally {
176
+ delete serverContext.modelPage;
177
+ }
178
+ });
179
+
180
+ // Nor while /status loads: until the server has said which page it shows, a
181
+ // viewer server must not offer the Explorer even briefly.
182
+ it("offers no 'Data sources' dialog while /status loads", async () => {
183
+ serverContext.isLoadingStatus = true;
184
+ try {
185
+ render(<Report resourceUri={URI} path={PATH} />, {
186
+ wrapper: serverWrapper,
187
+ });
188
+ await screen.findByText("Ops prose");
189
+ await waitFor(() => expect(executeQueryModel).toHaveBeenCalled());
190
+ expect(screen.queryByLabelText("Data sources")).toBeNull();
191
+ } finally {
192
+ delete serverContext.isLoadingStatus;
193
+ }
194
+ });
195
+
196
+ it("offers the 'Data sources' dialog once the server allows it", async () => {
197
+ render(<Report resourceUri={URI} path={PATH} />, {
198
+ wrapper: serverWrapper,
199
+ });
200
+ expect(await screen.findByLabelText("Data sources")).toBeTruthy();
201
+ });
202
+
203
+ it("puts the copy-link icon on a leading markdown cell", async () => {
204
+ render(<Report resourceUri={URI} path={PATH} />, {
205
+ wrapper: serverWrapper,
206
+ });
207
+
208
+ await screen.findByText("Ops prose");
209
+ expect(screen.getAllByTestId("LinkOutlinedIcon")).toHaveLength(1);
210
+ expect(screen.getByRole("button", { name: "Copy link" })).toBeTruthy();
211
+ });
212
+
213
+ it("keeps the copy-link icon off a notebook that opens with a code cell", async () => {
214
+ manifest = {
215
+ ...NOTEBOOK,
216
+ notebook: {
217
+ format: "malloynb",
218
+ notebookCells: [
219
+ { type: "code", text: "import { orders } from './orders.malloy'" },
220
+ { type: "markdown", text: "Later prose" },
221
+ ],
222
+ },
223
+ } as ReportManifest;
224
+ render(<Report resourceUri={URI} path={PATH} />, {
225
+ wrapper: serverWrapper,
226
+ });
227
+
228
+ await screen.findByText("Later prose");
229
+ expect(screen.queryAllByTestId("LinkOutlinedIcon")).toHaveLength(0);
230
+ });