@malloy-publisher/sdk 0.9.1 → 0.9.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 (292) hide show
  1. package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
  2. package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
  3. package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
  4. package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
  5. package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
  6. package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
  7. package/dist/builder/index.cjs.js +146 -58
  8. package/dist/builder/index.es.js +9076 -6479
  9. package/dist/builder-entry.d.ts +4 -0
  10. package/dist/client/api.d.ts +77 -47
  11. package/dist/client/configuration.d.ts +1 -1
  12. package/dist/client/index.cjs.js +1 -1
  13. package/dist/client/index.d.ts +1 -1
  14. package/dist/client/index.es.js +84 -82
  15. package/dist/components/Dashboard/Dashboard.d.ts +8 -15
  16. package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
  17. package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
  18. package/dist/components/Dashboard/DashboardView.d.ts +36 -0
  19. package/dist/components/Dashboard/TileCard.d.ts +15 -4
  20. package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
  21. package/dist/components/Dashboard/index.d.ts +3 -0
  22. package/dist/components/Dashboard/telemetry.d.ts +15 -3
  23. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
  24. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
  25. package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
  26. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
  27. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
  28. package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
  29. package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
  30. package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
  31. package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
  32. package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
  33. package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
  34. package/dist/components/DashboardBuilder/SaveNotice.d.ts +27 -0
  35. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
  36. package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
  37. package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
  38. package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
  39. package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
  40. package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
  41. package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
  42. package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
  43. package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
  44. package/dist/components/DashboardBuilder/controls.d.ts +2 -2
  45. package/dist/components/DashboardBuilder/document.d.ts +42 -26
  46. package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
  47. package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
  48. package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
  49. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
  50. package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
  51. package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
  52. package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
  53. package/dist/components/DashboardBuilder/preview.d.ts +24 -4
  54. package/dist/components/DashboardBuilder/readDocument.d.ts +4 -1
  55. package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
  56. package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
  57. package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -13
  58. package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
  59. package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
  60. package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
  61. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
  62. package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
  63. package/dist/components/DashboardBuilder/useBuilderSession.d.ts +89 -0
  64. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
  65. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
  66. package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
  67. package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
  68. package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
  69. package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
  70. package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
  71. package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
  72. package/dist/components/DocumentCreate/events.d.ts +10 -0
  73. package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
  74. package/dist/components/DocumentCreate/guards.d.ts +12 -0
  75. package/dist/components/DocumentCreate/index.d.ts +6 -0
  76. package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
  77. package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
  78. package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
  79. package/dist/components/NarrowEditGate.d.ts +8 -0
  80. package/dist/components/Notebook/Notebook.d.ts +1 -1
  81. package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
  82. package/dist/components/Package/Package.d.ts +1 -0
  83. package/dist/components/Package/documentLocation.d.ts +28 -0
  84. package/dist/components/Package/index.d.ts +4 -0
  85. package/dist/components/Package/useDocumentLocation.d.ts +12 -0
  86. package/dist/components/PackageSection.d.ts +2 -2
  87. package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
  88. package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
  89. package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
  90. package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
  91. package/dist/components/ServerProvider.d.ts +2 -1
  92. package/dist/components/UnsavedChangesDialog.d.ts +9 -0
  93. package/dist/components/given/GivensPanel.d.ts +2 -2
  94. package/dist/components/index.d.ts +2 -0
  95. package/dist/hooks/index.d.ts +1 -0
  96. package/dist/hooks/useNarrowScreen.d.ts +4 -0
  97. package/dist/hooks/useQueryResult.d.ts +2 -0
  98. package/dist/hooks/useSettled.d.ts +14 -0
  99. package/dist/index.cjs.js +23 -24
  100. package/dist/index.es.js +9714 -7072
  101. package/dist/text/index.cjs.js +1 -0
  102. package/dist/text/index.d.ts +2 -0
  103. package/dist/text/index.es.js +6 -0
  104. package/dist/text-entry-BJwltZiy.cjs.js +7 -0
  105. package/dist/text-entry-CbbBcZl8.es.js +196 -0
  106. package/dist/text-entry.d.ts +2 -0
  107. package/dist/utils/clock.d.ts +2 -0
  108. package/package.json +10 -1
  109. package/src/builder-entry.ts +35 -0
  110. package/src/components/Dashboard/Dashboard.tsx +27 -278
  111. package/src/components/Dashboard/DashboardGrid.tsx +68 -7
  112. package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
  113. package/src/components/Dashboard/DashboardTile.tsx +31 -4
  114. package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
  115. package/src/components/Dashboard/DashboardView.tsx +352 -0
  116. package/src/components/Dashboard/RowsDialog.tsx +1 -1
  117. package/src/components/Dashboard/TileCard.tsx +44 -10
  118. package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
  119. package/src/components/Dashboard/TileFilterTag.tsx +78 -0
  120. package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
  121. package/src/components/Dashboard/index.ts +3 -0
  122. package/src/components/Dashboard/telemetry.ts +16 -5
  123. package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
  124. package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
  125. package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
  126. package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
  127. package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
  128. package/src/components/DashboardBuilder/ChartPicker.tsx +153 -0
  129. package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
  130. package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
  131. package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
  132. package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
  133. package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
  134. package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
  135. package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
  136. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
  137. package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
  138. package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
  139. package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
  140. package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
  141. package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
  142. package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
  143. package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
  144. package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
  145. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
  146. package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
  147. package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
  148. package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
  149. package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
  150. package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
  151. package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
  152. package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
  153. package/src/components/DashboardBuilder/InlineText.tsx +106 -0
  154. package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
  155. package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
  156. package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
  157. package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
  158. package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
  159. package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
  160. package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
  161. package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
  162. package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
  163. package/src/components/DashboardBuilder/annotationText.ts +17 -0
  164. package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
  165. package/src/components/DashboardBuilder/artifactTagParity.spec.ts +41 -0
  166. package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
  167. package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
  168. package/src/components/DashboardBuilder/catalog.ts +61 -21
  169. package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
  170. package/src/components/DashboardBuilder/changedTile.ts +28 -0
  171. package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
  172. package/src/components/DashboardBuilder/chartLine.ts +121 -0
  173. package/src/components/DashboardBuilder/controls.spec.ts +21 -10
  174. package/src/components/DashboardBuilder/controls.ts +22 -8
  175. package/src/components/DashboardBuilder/document.ts +53 -5
  176. package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
  177. package/src/components/DashboardBuilder/documentSession.ts +257 -0
  178. package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
  179. package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
  180. package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
  181. package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
  182. package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
  183. package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
  184. package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
  185. package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
  186. package/src/components/DashboardBuilder/malloyText.spec.ts +48 -0
  187. package/src/components/DashboardBuilder/malloyText.ts +181 -27
  188. package/src/components/DashboardBuilder/malloyTree.ts +155 -7
  189. package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
  190. package/src/components/DashboardBuilder/newDashboard.ts +30 -3
  191. package/src/components/DashboardBuilder/openDraft.ts +52 -0
  192. package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
  193. package/src/components/DashboardBuilder/preview.spec.ts +159 -12
  194. package/src/components/DashboardBuilder/preview.ts +83 -9
  195. package/src/components/DashboardBuilder/readDocument.spec.ts +139 -27
  196. package/src/components/DashboardBuilder/readDocument.ts +130 -44
  197. package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
  198. package/src/components/DashboardBuilder/readForEditor.ts +47 -0
  199. package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
  200. package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
  201. package/src/components/DashboardBuilder/sortable.tsx +2 -12
  202. package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
  203. package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
  204. package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
  205. package/src/components/DashboardBuilder/spliceDocument.ts +762 -130
  206. package/src/components/DashboardBuilder/spliceResult.ts +15 -0
  207. package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
  208. package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
  209. package/src/components/DashboardBuilder/tagParse.ts +103 -0
  210. package/src/components/DashboardBuilder/telemetry.ts +47 -0
  211. package/src/components/DashboardBuilder/testing/artifactTagParity.json +197 -0
  212. package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
  213. package/src/components/DashboardBuilder/testing/inline.ts +25 -0
  214. package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
  215. package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
  216. package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
  217. package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
  218. package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
  219. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
  220. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
  221. package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
  222. package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
  223. package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
  224. package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
  225. package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
  226. package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
  227. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
  228. package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
  229. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
  230. package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
  231. package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
  232. package/src/components/DocumentCreate/canRetry.ts +19 -0
  233. package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
  234. package/src/components/DocumentCreate/createDocument.ts +159 -0
  235. package/src/components/DocumentCreate/documentPath.ts +40 -0
  236. package/src/components/DocumentCreate/events.ts +15 -0
  237. package/src/components/DocumentCreate/exportedSources.ts +25 -0
  238. package/src/components/DocumentCreate/guards.ts +45 -0
  239. package/src/components/DocumentCreate/index.ts +27 -0
  240. package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
  241. package/src/components/DocumentCreate/newNotebook.ts +44 -0
  242. package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
  243. package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
  244. package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
  245. package/src/components/Model/ModelExplorer.spec.tsx +2 -2
  246. package/src/components/Model/SourcesExplorer.tsx +2 -4
  247. package/src/components/NarrowEditGate.spec.tsx +73 -0
  248. package/src/components/NarrowEditGate.tsx +29 -0
  249. package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
  250. package/src/components/Notebook/Notebook.tsx +66 -27
  251. package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
  252. package/src/components/Package/NewDocumentDialog.tsx +401 -0
  253. package/src/components/Package/Package.artifacts.spec.tsx +190 -0
  254. package/src/components/Package/Package.create.spec.tsx +380 -0
  255. package/src/components/Package/Package.notebooks.spec.tsx +18 -0
  256. package/src/components/Package/Package.tsx +366 -171
  257. package/src/components/Package/documentLocation.spec.ts +81 -0
  258. package/src/components/Package/documentLocation.ts +55 -0
  259. package/src/components/Package/index.ts +13 -0
  260. package/src/components/Package/useDocumentLocation.ts +59 -0
  261. package/src/components/PackageSection.tsx +2 -2
  262. package/src/components/RenderedResult/RenderedResult.tsx +18 -1
  263. package/src/components/RenderedResult/ResultContainer.tsx +44 -11
  264. package/src/components/RenderedResult/ResultPanel.tsx +4 -0
  265. package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
  266. package/src/components/RenderedResult/resultSizing.ts +14 -3
  267. package/src/components/ServerProvider.tsx +2 -1
  268. package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
  269. package/src/components/UnsavedChangesDialog.tsx +49 -0
  270. package/src/components/given/GivensPanel.spec.tsx +6 -6
  271. package/src/components/given/GivensPanel.tsx +3 -3
  272. package/src/components/index.ts +2 -0
  273. package/src/hooks/index.ts +3 -0
  274. package/src/hooks/useNarrowScreen.ts +21 -0
  275. package/src/hooks/useQueryResult.ts +16 -0
  276. package/src/hooks/useSettled.spec.ts +41 -0
  277. package/src/hooks/useSettled.ts +27 -0
  278. package/src/mainEntry.spec.ts +145 -0
  279. package/src/text-entry.ts +12 -0
  280. package/src/textEntry.spec.ts +118 -0
  281. package/src/utils/clock.spec.ts +12 -0
  282. package/src/utils/clock.ts +6 -0
  283. package/vite.config.ts +4 -0
  284. package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
  285. package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
  286. package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
  287. package/dist/components/DashboardBuilder/useTileResize.d.ts +0 -29
  288. package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
  289. package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
  290. package/src/components/DashboardBuilder/useTileResize.ts +0 -110
  291. package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
  292. package/src/components/Package/NewDashboardDialog.tsx +0 -265
@@ -0,0 +1,209 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { QueryClient } from "@tanstack/react-query";
5
+ import { describe, expect, it, mock } from "bun:test";
6
+ import type { ApiClients } from "../ServerProvider";
7
+ import {
8
+ resolveEditorTarget,
9
+ withWorkspace,
10
+ writePackageFile,
11
+ } from "./documentSession";
12
+
13
+ const clientWith = (
14
+ updateModelSource: (...args: unknown[]) => Promise<unknown>,
15
+ ) => ({ models: { updateModelSource } }) as unknown as ApiClients;
16
+
17
+ const base = {
18
+ environmentName: "env",
19
+ packageName: "pkg",
20
+ modelPath: "dashboards/a.malloy",
21
+ source: "new text",
22
+ expectedHash: "h0",
23
+ };
24
+
25
+ /** A client whose invalidations are recorded in call order. */
26
+ const spyingClient = () => {
27
+ const queryClient = new QueryClient();
28
+ const calls: { queryKey: unknown; refetchType?: string }[] = [];
29
+ queryClient.invalidateQueries = mock((filters: never) => {
30
+ calls.push(filters);
31
+ return Promise.resolve();
32
+ }) as never;
33
+ return { queryClient, calls };
34
+ };
35
+
36
+ describe("writePackageFile", () => {
37
+ it("sends the source against the expected hash and returns the server's hash", async () => {
38
+ const update = mock(async () => ({ data: { contentHash: "h1" } }));
39
+ const { queryClient } = spyingClient();
40
+ const hash = await writePackageFile({
41
+ ...base,
42
+ apiClients: clientWith(update),
43
+ queryClient,
44
+ invalidateOnError: [],
45
+ invalidate: [],
46
+ });
47
+ expect(hash).toBe("h1");
48
+ expect(update).toHaveBeenCalledWith("env", "pkg", "dashboards/a.malloy", {
49
+ source: "new text",
50
+ expectedHash: "h0",
51
+ });
52
+ });
53
+
54
+ it("invalidates exactly the caller's list, in order, after afterWrite", async () => {
55
+ const { queryClient, calls } = spyingClient();
56
+ const order: string[] = [];
57
+ await writePackageFile({
58
+ ...base,
59
+ apiClients: clientWith(async () => ({ data: { contentHash: "h1" } })),
60
+ queryClient,
61
+ invalidateOnError: [["on-error"]],
62
+ afterWrite: (hash) => {
63
+ order.push(`after:${hash}:${calls.length}`);
64
+ },
65
+ invalidate: [
66
+ { queryKey: ["a"], wait: true },
67
+ { queryKey: ["b"], refetchType: "none" },
68
+ ],
69
+ });
70
+ expect(order).toEqual(["after:h1:0"]);
71
+ expect(calls).toEqual([
72
+ { queryKey: ["a"] },
73
+ { queryKey: ["b"], refetchType: "none" },
74
+ ]);
75
+ });
76
+
77
+ it("holds the result until a waited invalidation lands, and not for the rest", async () => {
78
+ const queryClient = new QueryClient();
79
+ let release = () => {};
80
+ queryClient.invalidateQueries = mock((filters: { queryKey: string[] }) =>
81
+ filters.queryKey[0] === "slow"
82
+ ? new Promise<void>((r) => {
83
+ release = r;
84
+ })
85
+ : new Promise<void>(() => {}),
86
+ ) as never;
87
+ let done = false;
88
+ const written = writePackageFile({
89
+ ...base,
90
+ apiClients: clientWith(async () => ({ data: { contentHash: "h1" } })),
91
+ queryClient,
92
+ invalidateOnError: [],
93
+ invalidate: [
94
+ { queryKey: ["slow"], wait: true },
95
+ { queryKey: ["never-settles"] },
96
+ ],
97
+ }).then(() => {
98
+ done = true;
99
+ });
100
+ await new Promise((r) => setTimeout(r, 0));
101
+ expect(done).toBe(false);
102
+ release();
103
+ await written;
104
+ expect(done).toBe(true);
105
+ });
106
+
107
+ it("invalidates the error list, skips success work, and throws the server's reason on a refused write", async () => {
108
+ const { queryClient, calls } = spyingClient();
109
+ const afterWrite = mock(() => {});
110
+ const refused = Object.assign(new Error("Request failed"), {
111
+ response: { data: { message: "file changed since you opened it" } },
112
+ });
113
+ await expect(
114
+ writePackageFile({
115
+ ...base,
116
+ apiClients: clientWith(async () => {
117
+ throw refused;
118
+ }),
119
+ queryClient,
120
+ invalidateOnError: [["model"], ["other"]],
121
+ afterWrite,
122
+ invalidate: [{ queryKey: ["success-only"] }],
123
+ }),
124
+ ).rejects.toThrow("file changed since you opened it");
125
+ expect(calls).toEqual([{ queryKey: ["model"] }, { queryKey: ["other"] }]);
126
+ expect(afterWrite).not.toHaveBeenCalled();
127
+ });
128
+ });
129
+
130
+ describe("resolveEditorTarget", () => {
131
+ it("reads the environment, package and version off a resource URI", () => {
132
+ expect(
133
+ resolveEditorTarget({
134
+ resourceUri:
135
+ "publisher://environments/prod/packages/sales?versionId=v7",
136
+ }),
137
+ ).toEqual({
138
+ environmentName: "prod",
139
+ packageName: "sales",
140
+ versionId: "v7",
141
+ namesBoth: true,
142
+ });
143
+ });
144
+
145
+ it("takes the deprecated form as given, with no version", () => {
146
+ expect(
147
+ resolveEditorTarget({ environmentName: "prod", packageName: "sales" }),
148
+ ).toEqual({
149
+ environmentName: "prod",
150
+ packageName: "sales",
151
+ versionId: undefined,
152
+ namesBoth: true,
153
+ });
154
+ });
155
+
156
+ it("degrades a string that is not a publisher URI instead of throwing", () => {
157
+ expect(resolveEditorTarget({ resourceUri: "not a uri" })).toEqual({
158
+ environmentName: "",
159
+ packageName: "",
160
+ versionId: undefined,
161
+ namesBoth: false,
162
+ });
163
+ });
164
+
165
+ it("says so when the URI names an environment but no package", () => {
166
+ const target = resolveEditorTarget({
167
+ resourceUri: "publisher://environments/prod",
168
+ });
169
+ expect(target.namesBoth).toBe(false);
170
+ });
171
+ });
172
+
173
+ describe("withWorkspace", () => {
174
+ const saved: { type: string; where: string; workspace?: string } = {
175
+ type: "dashboard.saved",
176
+ where: "host",
177
+ };
178
+
179
+ it("names the workspace on a save a workspace took", () => {
180
+ expect(withWorkspace(saved, "records")).toEqual({
181
+ ...saved,
182
+ workspace: "records",
183
+ });
184
+ });
185
+
186
+ it("names the workspace on an undone save a workspace took, and not on a refused one", () => {
187
+ const undone: { type: string; where: string; workspace?: string } = {
188
+ type: "notebook.save_undone",
189
+ where: "host",
190
+ };
191
+ expect(withWorkspace(undone, "records")).toEqual({
192
+ ...undone,
193
+ workspace: "records",
194
+ });
195
+ const refused = { type: "notebook.save_undo_refused", reason: "x" };
196
+ expect(withWorkspace(refused, "records")).toBe(refused);
197
+ });
198
+
199
+ it("leaves a package save alone", () => {
200
+ const pkg = { type: "notebook.saved", where: "package" };
201
+ expect(withWorkspace(pkg, "records")).toBe(pkg);
202
+ });
203
+
204
+ it("leaves other events and an unnamed workspace alone", () => {
205
+ const refused = { type: "dashboard.save_refused", reason: "x" };
206
+ expect(withWorkspace(refused, "records")).toBe(refused);
207
+ expect(withWorkspace(saved, undefined)).toBe(saved);
208
+ });
209
+ });
@@ -0,0 +1,257 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import type { QueryClient, QueryKey } from "@tanstack/react-query";
5
+ import { parseResourceUri } from "../../utils/formatting";
6
+ import { sha256Hex } from "../../utils/sha256";
7
+ import type { Workspace } from "../DocumentStorage";
8
+ import type { ApiClients } from "../ServerProvider";
9
+
10
+ // The pure half of an editor host's session with its document: which
11
+ // workspace it opens against, where Save goes, and the hash a package write
12
+ // carries. The dashboard and notebook hosts both decide these the same way.
13
+
14
+ /** Where a host's Save lands. */
15
+ export type SavesTo = "package" | "browser" | "host";
16
+
17
+ /**
18
+ * The record when one declares itself, and otherwise the first writeable
19
+ * workspace. Pass every workspace, not only the writeable ones: a reader who
20
+ * cannot write to the record still has to be shown the record.
21
+ */
22
+ export function chooseWorkspace(
23
+ all: readonly Workspace[],
24
+ ): Workspace | undefined {
25
+ return (
26
+ all.find((candidate) => candidate.authoritative) ??
27
+ all.find((candidate) => candidate.writeable)
28
+ );
29
+ }
30
+
31
+ /**
32
+ * Where Save goes, and which writer takes it, or `undefined` for no Save.
33
+ *
34
+ * `authoritative` wins outright rather than breaking a tie: a host whose store
35
+ * is the record may well sit on a server that reports itself writable, and
36
+ * writing the package there would edit a deploy of the record instead of the
37
+ * record.
38
+ */
39
+ export function saveTarget({
40
+ authoritative,
41
+ mutable,
42
+ versionId,
43
+ canStore,
44
+ readFailed,
45
+ }: {
46
+ authoritative: boolean;
47
+ mutable: boolean;
48
+ versionId?: string;
49
+ /** The host keeps documents and the chosen workspace takes writes. */
50
+ canStore: boolean;
51
+ /** The host's copy could not be read. */
52
+ readFailed: boolean;
53
+ }): {
54
+ savesTo: SavesTo;
55
+ pinnedPackageSave: boolean;
56
+ writer: "storage" | "package" | undefined;
57
+ } {
58
+ const savesTo = authoritative ? "host" : mutable ? "package" : "browser";
59
+ // A version is an immutable checkpoint, and `updateModelSource` cannot be
60
+ // told to write against one (the server answers 501). Without this guard,
61
+ // `expectedHash` would be the hash of the pinned text, the server would
62
+ // refuse every save against the current file, and the catch would refetch
63
+ // the same pinned text: a dead end with no way out. Storage-backed saves are
64
+ // unaffected, since they never touch the package's compare-and-swap.
65
+ const pinnedPackageSave = versionId !== undefined && savesTo === "package";
66
+ const writer = authoritative
67
+ ? canStore
68
+ ? "storage"
69
+ : undefined
70
+ : pinnedPackageSave
71
+ ? undefined
72
+ : mutable
73
+ ? "package"
74
+ : canStore
75
+ ? "storage"
76
+ : undefined;
77
+ // A copy that could not be read is not a copy that is not there. Saving on
78
+ // that belief is what rewinds the record, so Save is off until a reader can
79
+ // be told what actually happened.
80
+ return {
81
+ savesTo,
82
+ pinnedPackageSave,
83
+ writer: readFailed ? undefined : writer,
84
+ };
85
+ }
86
+
87
+ /**
88
+ * The `expectedHash` a package write carries: the server's own hash after this
89
+ * editor's last write, else the hash of the package file the editor opened on.
90
+ * Never the latest fetch's, which may already hold someone else's change.
91
+ */
92
+ export async function expectedHashFor(
93
+ savedHash: string | undefined,
94
+ base: string | undefined,
95
+ ): Promise<string | undefined> {
96
+ return savedHash ?? (base === undefined ? undefined : await sha256Hex(base));
97
+ }
98
+
99
+ /**
100
+ * What the toolbar says about where Save goes, in the backend's own words
101
+ * wherever it has any: a workspace carries a `description` precisely so the
102
+ * editor does not have to guess, and "this browser" is one host's answer
103
+ * rather than the interface's.
104
+ */
105
+ export function saveCaption({
106
+ authoritative,
107
+ mutable,
108
+ pinnedPackageSave,
109
+ workspace,
110
+ readFailure,
111
+ versionId,
112
+ }: {
113
+ authoritative: boolean;
114
+ mutable: boolean;
115
+ pinnedPackageSave: boolean;
116
+ workspace?: Workspace;
117
+ readFailure?: string;
118
+ versionId?: string;
119
+ }): string {
120
+ if (readFailure !== undefined)
121
+ return `The saved copy could not be read, so Save is off: ${readFailure}`;
122
+ if (authoritative && workspace)
123
+ return workspace.writeable
124
+ ? workspace.description
125
+ : `${workspace.description}: you cannot save into it.`;
126
+ if (pinnedPackageSave)
127
+ return `Reading version ${versionId}: a version is a fixed point in history, so Save is off.`;
128
+ if (mutable) return "Save writes the file into the package.";
129
+ if (workspace)
130
+ return `${workspace.description}: this server does not take writes.`;
131
+ return "This server does not take writes.";
132
+ }
133
+
134
+ /** What a storage backend said went wrong, for a reader who has to act on it. */
135
+ export function storageErrorMessage(error: unknown): string {
136
+ return error instanceof Error ? error.message : String(error);
137
+ }
138
+
139
+ /** The server's own reason for a refused write, when it gave one. */
140
+ export function apiErrorMessage(error: unknown): string {
141
+ const data = (error as { response?: { data?: { message?: string } } })
142
+ .response?.data;
143
+ if (data?.message) return data.message;
144
+ return error instanceof Error ? error.message : String(error);
145
+ }
146
+
147
+ /** A query family a package write marks stale. */
148
+ export interface Invalidation {
149
+ queryKey: QueryKey;
150
+ /** `"none"` marks the family stale without refetching it. */
151
+ refetchType?: "none";
152
+ /** Hold the write's result until the refetch lands. */
153
+ wait?: boolean;
154
+ }
155
+
156
+ /**
157
+ * Writes a package file against `expectedHash` and returns the server's hash
158
+ * of what it wrote. A refused write invalidates `invalidateOnError`, since it
159
+ * usually means the file moved, and throws the server's own reason.
160
+ * `afterWrite` runs once the write has landed and before the invalidations, so
161
+ * the caller's bookkeeping is in place when a refetch arrives.
162
+ */
163
+ export async function writePackageFile({
164
+ apiClients,
165
+ queryClient,
166
+ environmentName,
167
+ packageName,
168
+ modelPath,
169
+ source,
170
+ expectedHash,
171
+ invalidateOnError,
172
+ invalidate,
173
+ afterWrite,
174
+ }: {
175
+ apiClients: ApiClients;
176
+ queryClient: QueryClient;
177
+ environmentName: string;
178
+ packageName: string;
179
+ modelPath: string;
180
+ source: string;
181
+ expectedHash: string;
182
+ invalidateOnError: readonly QueryKey[];
183
+ invalidate: readonly Invalidation[];
184
+ afterWrite?: (contentHash: string) => Promise<void> | void;
185
+ }): Promise<string> {
186
+ let result;
187
+ try {
188
+ result = await apiClients.models.updateModelSource(
189
+ environmentName,
190
+ packageName,
191
+ modelPath,
192
+ { source, expectedHash },
193
+ );
194
+ } catch (error) {
195
+ for (const queryKey of invalidateOnError)
196
+ void queryClient.invalidateQueries({ queryKey });
197
+ throw new Error(apiErrorMessage(error));
198
+ }
199
+ const contentHash = result.data.contentHash;
200
+ await afterWrite?.(contentHash);
201
+ for (const { queryKey, refetchType, wait } of invalidate) {
202
+ const pending = queryClient.invalidateQueries({
203
+ queryKey,
204
+ ...(refetchType ? { refetchType } : {}),
205
+ });
206
+ if (wait) await pending;
207
+ else void pending;
208
+ }
209
+ return contentHash;
210
+ }
211
+
212
+ /** The host workspace that took a save or its undo, named on the event; a package save was taken by none. */
213
+ export function withWorkspace<E extends { type: string }>(
214
+ event: E,
215
+ workspace: string | undefined,
216
+ ): E {
217
+ if (
218
+ workspace === undefined ||
219
+ !/\.(saved|save_undone)$/.test(event.type) ||
220
+ (event as { where?: SavesTo }).where === "package"
221
+ )
222
+ return event;
223
+ return { ...event, workspace };
224
+ }
225
+
226
+ /** The environment, package and version an editor was asked for, from either prop form; a render body must not throw, so a URI `parseResourceUri` rejects reads as naming neither. */
227
+ export function resolveEditorTarget(
228
+ props:
229
+ | { resourceUri: string }
230
+ | { environmentName: string; packageName: string },
231
+ ): {
232
+ environmentName: string;
233
+ packageName: string;
234
+ versionId: string | undefined;
235
+ /** False when a resource URI did not name both an environment and a package. */
236
+ namesBoth: boolean;
237
+ } {
238
+ if (!("resourceUri" in props))
239
+ return {
240
+ environmentName: props.environmentName,
241
+ packageName: props.packageName,
242
+ versionId: undefined,
243
+ namesBoth: true,
244
+ };
245
+ let parsed: ReturnType<typeof parseResourceUri> | undefined;
246
+ try {
247
+ parsed = parseResourceUri(props.resourceUri);
248
+ } catch {
249
+ parsed = undefined;
250
+ }
251
+ return {
252
+ environmentName: parsed?.environmentName ?? "",
253
+ packageName: parsed?.packageName ?? "",
254
+ versionId: parsed?.versionId,
255
+ namesBoth: !!parsed?.environmentName && !!parsed?.packageName,
256
+ };
257
+ }
@@ -0,0 +1,131 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import {
6
+ buildSuggestQuery,
7
+ SUGGEST_OPTION_LIMIT,
8
+ } from "../../hooks/useSuggestOptions";
9
+ import { newLocalGiven } from "./controls";
10
+ import { readDashboardDocument, readFailed } from "./readDocument";
11
+ import { openDocument, refused, splice, spliced } from "./testing/fixtures";
12
+ import { spliceFailed } from "./spliceDocument";
13
+ import { queryTile } from "./testing/fixtures";
14
+ import { tileKey } from "./document";
15
+
16
+ const EMPTY = `##! experimental.givens
17
+ ## artifact { title="T" tiles=[] } dashboard { columns=12 }
18
+ import { one } from "../m.malloy"
19
+ `;
20
+
21
+ const ONE_TILE = `##! experimental.givens
22
+ ## artifact { title="T" tiles=["a -> x"] } dashboard { columns=12 }
23
+ import { one } from "../m.malloy"
24
+
25
+ source: a is one extend {
26
+ view: x is vx
27
+ }`;
28
+
29
+ describe("a dashboard with an explicit, empty tile list", () => {
30
+ it("opens with no tiles", async () => {
31
+ const doc = await openDocument(EMPTY);
32
+ expect(doc.tiles).toEqual([]);
33
+ expect(doc.title).toBe("T");
34
+ });
35
+
36
+ it("still refuses a file whose artifact tag has no tiles key", async () => {
37
+ const result = await readDashboardDocument(
38
+ '## artifact { title="T" } dashboard { columns=12 }\nimport "../m.malloy"\n',
39
+ );
40
+ expect(readFailed(result)).toBe(true);
41
+ });
42
+
43
+ it("still refuses a list holding entries the builder cannot read", async () => {
44
+ const result = await readDashboardDocument(
45
+ '## artifact { title="T" tiles=[text intro] }\nimport "../m.malloy"\n',
46
+ );
47
+ expect(readFailed(result)).toBe(true);
48
+ });
49
+
50
+ it("takes its first tile, creating the extension", async () => {
51
+ const out = await spliced(EMPTY, (d) => {
52
+ d.sources.push({ name: "one_tiles", base: "one" });
53
+ d.tiles.push({
54
+ name: "vx_tile",
55
+ source: "one_tiles",
56
+ declaration: { kind: "reference", from: "vx" },
57
+ colspan: 6,
58
+ });
59
+ });
60
+ expect(out).toContain('tiles=["one_tiles -> vx_tile"]');
61
+ const back = await openDocument(out);
62
+ expect(back.tiles.map(tileKey)).toEqual(["one_tiles.vx_tile"]);
63
+ });
64
+
65
+ it("refuses to remove the last tile, because an empty file is not served", async () => {
66
+ const reason = await refused(ONE_TILE, (d) => {
67
+ d.tiles = [];
68
+ });
69
+ expect(reason).toContain("not served");
70
+ });
71
+
72
+ it("still removes a tile when another remains", async () => {
73
+ const two = ONE_TILE.replace(
74
+ '["a -> x"]',
75
+ '["a -> x", "a -> y"]',
76
+ ).replace("view: x is vx", "view: x is vx\n view: y is vy");
77
+ const result = await splice(two, (d) => {
78
+ d.tiles.splice(1, 1);
79
+ });
80
+ expect(spliceFailed(result)).toBe(false);
81
+ });
82
+ });
83
+
84
+ describe("a filter on a joined dimension", () => {
85
+ it("keeps the whole path on the declared control", () => {
86
+ const given = newLocalGiven({
87
+ name: "CATEGORY",
88
+ label: "Category",
89
+ kind: "select",
90
+ field: "products.category",
91
+ source: "order_items",
92
+ });
93
+ expect(given.suggest).toEqual({
94
+ source: "order_items",
95
+ dimension: "products.category",
96
+ });
97
+ });
98
+
99
+ it("is written quoted, reads back whole, and forms the options query", async () => {
100
+ const source = `##! experimental.givens
101
+ ## artifact { title="T" tiles=["a -> x"] }
102
+ import { one, products } from "../m.malloy"
103
+
104
+ source: a is one extend {
105
+ view: x is vx
106
+ }`;
107
+ const out = await spliced(source, (d) => {
108
+ d.localGivens = [
109
+ newLocalGiven({
110
+ name: "CATEGORY",
111
+ label: "Category",
112
+ kind: "select",
113
+ field: "products.category",
114
+ source: "a",
115
+ }),
116
+ ];
117
+ queryTile(d, 0).filters = [
118
+ { field: "products.category", given: "CATEGORY" },
119
+ ];
120
+ });
121
+ expect(out).toContain(
122
+ '# label="Category" control=select suggest { source=a dimension="products.category" }',
123
+ );
124
+ const back = await openDocument(out);
125
+ const suggest = back.localGivens?.[0].suggest;
126
+ expect(suggest).toEqual({ source: "a", dimension: "products.category" });
127
+ expect(buildSuggestQuery(suggest!.source!, suggest!.dimension)).toBe(
128
+ `run: a -> {\n group_by: products.category\n order_by: category asc\n limit: ${SUGGEST_OPTION_LIMIT}\n}`,
129
+ );
130
+ });
131
+ });
@@ -2,7 +2,11 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
- import type { DashboardDocument } from "./document";
5
+ import {
6
+ isQueryTile,
7
+ type DashboardDocument,
8
+ type QueryTile,
9
+ } from "./document";
6
10
  import { readDashboardDocument, readFailed } from "./readDocument";
7
11
  import {
8
12
  spliceDashboardDocument,
@@ -117,7 +121,7 @@ run: a -> kpis
117
121
  `;
118
122
 
119
123
  const tile = (d: DashboardDocument, name: string) =>
120
- d.tiles.find((t) => t.name === name)!;
124
+ d.tiles.find((t): t is QueryTile => isQueryTile(t) && t.name === name)!;
121
125
 
122
126
  interface Row {
123
127
  what: string;
@@ -0,0 +1,77 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import {
6
+ notebookSourceRefused,
7
+ readNotebookSource,
8
+ type NotebookSource,
9
+ } from "./legacyNotebook";
10
+
11
+ const HEAD =
12
+ '## artifact { kind=notebook }\nsource: a is duckdb.sql("select 1 as x")\n\n';
13
+
14
+ async function read(text: string): Promise<NotebookSource> {
15
+ const result = await readNotebookSource(text);
16
+ if (notebookSourceRefused(result)) throw new Error(result.refused);
17
+ return result.source;
18
+ }
19
+
20
+ describe("readNotebookSource: chart lines", () => {
21
+ it("records the recognized chart line's span and where a new one goes", async () => {
22
+ const cell = `#" Caption\n# -bar_chart line_chart\n// c\nrun: a -> { select: x }\n`;
23
+ const source = await read(HEAD + cell);
24
+ const chart = source.cells[1].chart!;
25
+ expect(chart.lines.map((l) => l.text)).toEqual([
26
+ "# -bar_chart line_chart",
27
+ ]);
28
+ const [line] = chart.lines;
29
+ expect(source.text.slice(line.span.start, line.span.end)).toBe(
30
+ "# -bar_chart line_chart\n",
31
+ );
32
+ expect(source.text.slice(chart.insertAt)).toBe(
33
+ "run: a -> { select: x }\n",
34
+ );
35
+ expect(chart.unmodelled).toBeUndefined();
36
+ });
37
+
38
+ it("places a new line at the run when there are no tags, and reads CRLF", async () => {
39
+ const source = await read(
40
+ (HEAD + "run: a -> { select: x }\n").replace(/\n/g, "\r\n"),
41
+ );
42
+ const chart = source.cells[1].chart!;
43
+ expect(chart.lines).toEqual([]);
44
+ expect(source.text.slice(chart.insertAt)).toBe(
45
+ "run: a -> { select: x }\r\n",
46
+ );
47
+ });
48
+
49
+ it("leaves a tag with properties, or a label, as unmodelled and never as a chart line", async () => {
50
+ for (const line of [
51
+ "# bar_chart { size=spark }",
52
+ '# line_chart label="Revenue"',
53
+ "# viz=line",
54
+ ]) {
55
+ const source = await read(`${HEAD}${line}\nrun: a -> { select: x }\n`);
56
+ const chart = source.cells[1].chart!;
57
+ expect(chart.lines).toEqual([]);
58
+ expect(chart.unmodelled).toBe(line);
59
+ }
60
+ });
61
+
62
+ it("ignores chart words in captions and keeps definitions free of chart state", async () => {
63
+ const source = await read(
64
+ `${HEAD}#" The bar_chart story\nrun: a -> { select: x }\n`,
65
+ );
66
+ expect(source.cells[1].chart!.lines).toEqual([]);
67
+ expect(source.cells[1].chart!.unmodelled).toBeUndefined();
68
+ expect(source.cells[0].chart).toBeUndefined();
69
+ });
70
+
71
+ it("does not take a word inside a quoted tag value for a chart line", async () => {
72
+ const source = await read(
73
+ `${HEAD}# label="Sales viz"\nrun: a -> { select: x }\n`,
74
+ );
75
+ expect(source.cells[1].chart!.unmodelled).toBeUndefined();
76
+ });
77
+ });