@malloy-publisher/sdk 0.9.0 → 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 +82 -48
  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
@@ -4,7 +4,7 @@
4
4
  import { describe, expect, it } from "bun:test";
5
5
  import * as fs from "fs";
6
6
  import * as path from "path";
7
- import type { DashboardDocument } from "./document";
7
+ import { isQueryTile, tileKey, type DashboardDocument } from "./document";
8
8
  import { readDashboardDocument, readFailed } from "./readDocument";
9
9
  import {
10
10
  spliceDashboardDocument,
@@ -14,6 +14,7 @@ import {
14
14
  import { openDocument, refused, splice, spliced } from "./testing/fixtures";
15
15
  import { whatMoved } from "./__test__/inventory";
16
16
  import { lintNotebookText } from "../../../../server/src/service/notebook_lint";
17
+ import { queryTile } from "./testing/fixtures";
17
18
 
18
19
  const REPO = path.resolve(import.meta.dir, "../../../../..");
19
20
 
@@ -61,8 +62,8 @@ describe("spliceDashboardDocument: what it preserves", () => {
61
62
  ' # label="By category"\n # big_value\n # currency\n',
62
63
  );
63
64
  const out = await spliced(source, (d) => {
64
- d.tiles[0].label = "Categories";
65
- d.tiles[0].filters = [{ field: "cat", given: "CATEGORY" }];
65
+ queryTile(d, 0).label = "Categories";
66
+ queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
66
67
  });
67
68
  expect(out).toContain(
68
69
  ' # label="Categories"\n # big_value\n # currency\n',
@@ -75,7 +76,7 @@ describe("spliceDashboardDocument: what it preserves", () => {
75
76
  // Byte-minimal: one property changed, one line different.
76
77
  it("changes only the line it had to", async () => {
77
78
  const out = await spliced(SOURCE, (d) => {
78
- d.tiles[0].label = "Categories";
79
+ queryTile(d, 0).label = "Categories";
79
80
  });
80
81
  const before = SOURCE.split("\n");
81
82
  const after = out.split("\n");
@@ -109,12 +110,25 @@ source: a is scoped_orders extend {
109
110
  it("writes both when the tile had no tags at all", async () => {
110
111
  const out = await spliced(UNTAGGED, (d) => {
111
112
  d.tiles[0].colspan = 4;
112
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
113
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
113
114
  });
114
115
  expect(out).toContain(
115
116
  " # colspan=4\n view: by_cat is by_category + { where: category ~ $CATEGORY }",
116
117
  );
117
118
  });
119
+
120
+ it("back-quotes a reserved filter field, and refuses a reserved new given name", async () => {
121
+ const out = await spliced(UNTAGGED, (d) => {
122
+ queryTile(d, 0).filters = [{ field: "date", given: "WHEN_" }];
123
+ });
124
+ expect(out).toContain("+ { where: `date` ~ $WHEN_ }");
125
+ const reason = await refused(UNTAGGED, (d) => {
126
+ d.localGivens = [
127
+ { name: "DATE", type: "filter<string>", default: "f''" },
128
+ ];
129
+ });
130
+ expect(reason).toContain("cannot be written as a Malloy name");
131
+ });
118
132
  });
119
133
 
120
134
  /**
@@ -138,7 +152,7 @@ ${declaration}
138
152
  }`;
139
153
 
140
154
  const bind = (d: DashboardDocument) => {
141
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
155
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
142
156
  };
143
157
 
144
158
  it("puts the binding before the comment, not inside it", async () => {
@@ -166,7 +180,7 @@ ${declaration}
166
180
  " view: by_cat is by_category + { where: category ~ $CATEGORY } // the lead tile",
167
181
  );
168
182
  const out = await spliced(source, (d) => {
169
- delete d.tiles[0].filters;
183
+ delete queryTile(d, 0).filters;
170
184
  d.tiles[0].colspan = 4;
171
185
  });
172
186
  expect(out).toContain(" view: by_cat is by_category // the lead tile");
@@ -187,7 +201,7 @@ ${declaration}
187
201
  describe("spliceDashboardDocument: what it writes", () => {
188
202
  it("adds a tag that was not there", async () => {
189
203
  const out = await spliced(SOURCE, (d) => {
190
- d.tiles[1].label = "By brand";
204
+ queryTile(d, 1).label = "By brand";
191
205
  });
192
206
  expect(out).toContain(' # label="By brand"\n view: by_brand');
193
207
  expect(await openDocument(out)).toMatchObject({
@@ -206,14 +220,16 @@ describe("spliceDashboardDocument: what it writes", () => {
206
220
  // The filter binding lives in the declaration, as a refinement.
207
221
  it("writes and clears a filter binding", async () => {
208
222
  const bound = await spliced(SOURCE, (d) => {
209
- d.tiles[0].filters = [{ field: "products.brand", given: "BRAND" }];
223
+ queryTile(d, 0).filters = [
224
+ { field: "products.brand", given: "BRAND" },
225
+ ];
210
226
  });
211
227
  expect(bound).toContain(
212
228
  "view: by_cat is by_category + { where: products.brand ~ $BRAND }",
213
229
  );
214
230
 
215
231
  const cleared = await spliced(bound, (d) => {
216
- delete d.tiles[0].filters;
232
+ delete queryTile(d, 0).filters;
217
233
  });
218
234
  expect(cleared).toContain("view: by_cat is by_category\n");
219
235
  expect(cleared).not.toContain("where:");
@@ -275,14 +291,14 @@ describe("spliceDashboardDocument: reordering", () => {
275
291
  const r = await splice(SOURCE, (d) => {
276
292
  d.tiles.reverse();
277
293
  // Matched by identity, not position: this is the tile now FIRST.
278
- d.tiles[0].label = "Brands";
294
+ queryTile(d, 0).label = "Brands";
279
295
  });
280
296
  expect(r.ok).toBe(true);
281
297
  if (!spliceFailed(r)) {
282
298
  const back = await openDocument(r.source);
283
299
  expect(back.tiles.map((t) => t.name)).toEqual(["by_brand", "by_cat"]);
284
- expect(back.tiles[0].label).toBe("Brands");
285
- expect(back.tiles[1].label).toBe("By category");
300
+ expect(queryTile(back, 0).label).toBe("Brands");
301
+ expect(queryTile(back, 1).label).toBe("By category");
286
302
  }
287
303
  });
288
304
  });
@@ -290,7 +306,7 @@ describe("spliceDashboardDocument: reordering", () => {
290
306
  describe("spliceDashboardDocument: bindings", () => {
291
307
  it("writes a binding with the comparison it was given", async () => {
292
308
  const out = await spliced(SOURCE, (d) => {
293
- d.tiles[0].filters = [
309
+ queryTile(d, 0).filters = [
294
310
  { field: "created_at", given: "SINCE", op: ">=" },
295
311
  ];
296
312
  });
@@ -307,7 +323,7 @@ describe("spliceDashboardDocument: bindings", () => {
307
323
  "view: by_cat is by_category + { limit: 5 where: category ~ $CATEGORY }",
308
324
  );
309
325
  const out = await spliced(source, (d) => {
310
- d.tiles[0].filters = [
326
+ queryTile(d, 0).filters = [
311
327
  { field: "category", given: "CATEGORY" },
312
328
  { field: "brand", given: "BRAND" },
313
329
  ];
@@ -317,7 +333,7 @@ describe("spliceDashboardDocument: bindings", () => {
317
333
  );
318
334
  // And clearing the bindings leaves the clause that was never ours.
319
335
  const cleared = await spliced(source, (d) => {
320
- delete d.tiles[0].filters;
336
+ delete queryTile(d, 0).filters;
321
337
  });
322
338
  expect(cleared).toContain("view: by_cat is by_category + { limit: 5 }");
323
339
  });
@@ -344,7 +360,7 @@ source: a is one extend {
344
360
 
345
361
  it("adds a binding as a new depth-1 where: line before the closing brace", async () => {
346
362
  const out = await spliced(MULTILINE, (d) => {
347
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
363
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
348
364
  });
349
365
  expect(out).toContain(
350
366
  " view: kpis is {\n group_by: category\n aggregate: n is count()\n where: category ~ $CATEGORY\n }",
@@ -357,7 +373,7 @@ source: a is one extend {
357
373
  "view: kpis is {\n where: category ~ $CATEGORY\n group_by: category",
358
374
  );
359
375
  const out = await spliced(source, (d) => {
360
- d.tiles[0].filters = [{ field: "brand_name", given: "CATEGORY" }];
376
+ queryTile(d, 0).filters = [{ field: "brand_name", given: "CATEGORY" }];
361
377
  });
362
378
  expect(out).toContain(
363
379
  " view: kpis is {\n where: brand_name ~ $CATEGORY\n group_by: category",
@@ -372,7 +388,7 @@ source: a is one extend {
372
388
  "view: kpis is {\n where: category ~ $CATEGORY\n group_by: category",
373
389
  );
374
390
  const out = await spliced(source, (d) => {
375
- delete d.tiles[0].filters;
391
+ delete queryTile(d, 0).filters;
376
392
  });
377
393
  expect(out).toContain(MULTILINE);
378
394
  expect(out).not.toContain("where:");
@@ -396,7 +412,7 @@ source: a is one extend {
396
412
  }
397
413
  }`;
398
414
  const out = await spliced(source, (d) => {
399
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
415
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
400
416
  });
401
417
  expect(out).toContain("where: mth ~ $MONTH");
402
418
  expect(out).toContain(
@@ -418,7 +434,7 @@ source: a is one extend {
418
434
  }
419
435
  }`;
420
436
  const out = await spliced(source, (d) => {
421
- d.tiles[0].filters = [{ field: "region", given: "REGION" }];
437
+ queryTile(d, 0).filters = [{ field: "region", given: "REGION" }];
422
438
  });
423
439
  expect(out).toContain("where: category ~ $CATEGORY and status = 'open'");
424
440
  expect(out).toContain(
@@ -454,7 +470,7 @@ source: a is one extend {
454
470
  // in any of those spans. What used to need a refusal is now just an edit.
455
471
  it("drops one binding and leaves the measure between them", async () => {
456
472
  const out = await spliced(TWO_BINDINGS_ONE_STATEMENT, (d) => {
457
- d.tiles[0].filters = [{ field: "a", given: "A" }];
473
+ queryTile(d, 0).filters = [{ field: "a", given: "A" }];
458
474
  });
459
475
  expect(out).toContain(" where: a ~ $A, aggregate: n is count()");
460
476
  expect(out).not.toContain("$B");
@@ -462,7 +478,7 @@ source: a is one extend {
462
478
 
463
479
  it("rewrites each binding in place, measure untouched", async () => {
464
480
  const out = await spliced(TWO_BINDINGS_ONE_STATEMENT, (d) => {
465
- d.tiles[0].filters = [
481
+ queryTile(d, 0).filters = [
466
482
  { field: "a2", given: "A" },
467
483
  { field: "b", given: "B" },
468
484
  ];
@@ -494,9 +510,11 @@ source: a is one extend {
494
510
  view: kpis is { where: c ~ $C, aggregate: n is count() }
495
511
  }`;
496
512
  const before = await openDocument(oneLiner);
497
- expect(before.tiles[0].filters).toEqual([{ field: "c", given: "C" }]);
513
+ expect(queryTile(before, 0).filters).toEqual([
514
+ { field: "c", given: "C" },
515
+ ]);
498
516
  const out = await spliced(oneLiner, (d) => {
499
- d.tiles[0].filters = [{ field: "c", given: "C2" }];
517
+ queryTile(d, 0).filters = [{ field: "c", given: "C2" }];
500
518
  });
501
519
  expect(out).toContain(
502
520
  "view: kpis is { aggregate: n is count() where: c ~ $C2 }",
@@ -511,14 +529,14 @@ source: a is one extend {
511
529
  view: kpis is { aggregate: n is count() }
512
530
  }`;
513
531
  const out = await spliced(oneLiner, (d) => {
514
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
532
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
515
533
  });
516
534
  expect(out).toContain(
517
535
  "view: kpis is { aggregate: n is count() where: category ~ $CATEGORY }",
518
536
  );
519
537
  // And unbinding restores the file exactly as it was.
520
538
  const restored = await spliced(out, (d) => {
521
- delete d.tiles[0].filters;
539
+ delete queryTile(d, 0).filters;
522
540
  });
523
541
  expect(restored).toBe(oneLiner);
524
542
  });
@@ -540,7 +558,7 @@ source: a is one extend {
540
558
  }
541
559
  }`;
542
560
  const out = await spliced(source, (d) => {
543
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
561
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
544
562
  });
545
563
  expect(out).toContain(
546
564
  " aggregate: n is count()\n where: category ~ $CATEGORY\n } -> {",
@@ -557,7 +575,9 @@ source: a is one extend {
557
575
  }`;
558
576
  expect(
559
577
  await refused(source, (d) => {
560
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
578
+ queryTile(d, 0).filters = [
579
+ { field: "category", given: "CATEGORY" },
580
+ ];
561
581
  }),
562
582
  ).toContain("compound refinement");
563
583
  });
@@ -575,7 +595,7 @@ source: a is one extend {
575
595
  view: other is { aggregate: m is count() }
576
596
  }`;
577
597
  const out = await spliced(source, (d) => {
578
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
598
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
579
599
  });
580
600
  expect(out).toContain(" where: brand_name ~ $BRAND\n");
581
601
  expect(out).toContain(
@@ -585,18 +605,18 @@ source: a is one extend {
585
605
 
586
606
  it("round-trips: bind, read back, unbind, read back to the original bytes", async () => {
587
607
  const bound = await spliced(MULTILINE, (d) => {
588
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
608
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
589
609
  });
590
610
  const reopened = await openDocument(bound);
591
- expect(reopened.tiles[0].filters).toEqual([
611
+ expect(queryTile(reopened, 0).filters).toEqual([
592
612
  { field: "category", given: "CATEGORY" },
593
613
  ]);
594
614
  const unbound = await spliced(bound, (d) => {
595
- delete d.tiles[0].filters;
615
+ delete queryTile(d, 0).filters;
596
616
  });
597
617
  expect(unbound).toBe(MULTILINE);
598
618
  const reread = await openDocument(unbound);
599
- expect(reread.tiles[0].filters).toBeUndefined();
619
+ expect(queryTile(reread, 0).filters).toBeUndefined();
600
620
  });
601
621
 
602
622
  // The end-to-end shape of the corruption a quoted literal's brace used to
@@ -620,7 +640,7 @@ source: a is scoped_orders extend {
620
640
  view: other is { aggregate: m is count() }
621
641
  }`;
622
642
  const out = await spliced(source, (d) => {
623
- d.tiles[0].filters = [{ field: "cat", given: "CATEGORY" }];
643
+ queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
624
644
  });
625
645
  expect(out).toContain(
626
646
  " view: kpis is {\n where: path ~ 'a{b'\n aggregate: n is count()\n where: cat ~ $CATEGORY\n }",
@@ -628,7 +648,7 @@ source: a is scoped_orders extend {
628
648
  expect(out).toContain(" view: other is { aggregate: m is count() }\n}");
629
649
  expect(out.match(/where: cat ~ \$CATEGORY/g)).toHaveLength(1);
630
650
  const reopened = await openDocument(out);
631
- expect(reopened.tiles[0].filters).toEqual([
651
+ expect(queryTile(reopened, 0).filters).toEqual([
632
652
  { field: "cat", given: "CATEGORY" },
633
653
  ]);
634
654
  });
@@ -649,7 +669,7 @@ source: a is scoped_orders extend {
649
669
  view: other is { aggregate: m is count() }
650
670
  }`;
651
671
  const out = await spliced(source, (d) => {
652
- d.tiles[0].filters = [{ field: "cat", given: "CATEGORY" }];
672
+ queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
653
673
  });
654
674
  expect(out).toContain(
655
675
  " view: kpis is {\n where: path ~ 'a}b'\n aggregate: n is count()\n where: cat ~ $CATEGORY\n }",
@@ -668,16 +688,16 @@ source: a is one extend {
668
688
  view: kpis is { where: category ~ $CATEGORY, aggregate: n is count() }
669
689
  }`;
670
690
  const before = await openDocument(boundOneLiner);
671
- expect(before.tiles[0].filters).toEqual([
691
+ expect(queryTile(before, 0).filters).toEqual([
672
692
  { field: "category", given: "CATEGORY" },
673
693
  ]);
674
694
  const rebound = await spliced(boundOneLiner, (d) => {
675
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
695
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
676
696
  });
677
697
  expect(rebound).toBe(boundOneLiner);
678
698
  expect(rebound.match(/where:/g)).toHaveLength(1);
679
699
  const after = await openDocument(rebound);
680
- expect(after.tiles[0].filters).toEqual([
700
+ expect(queryTile(after, 0).filters).toEqual([
681
701
  { field: "category", given: "CATEGORY" },
682
702
  ]);
683
703
  });
@@ -695,16 +715,16 @@ source: a is one extend {
695
715
  }
696
716
  }`;
697
717
  const before = await openDocument(sharedOpen);
698
- expect(before.tiles[0].filters).toEqual([
718
+ expect(queryTile(before, 0).filters).toEqual([
699
719
  { field: "category", given: "CATEGORY" },
700
720
  ]);
701
721
  const rebound = await spliced(sharedOpen, (d) => {
702
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
722
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
703
723
  });
704
724
  expect(rebound).toBe(sharedOpen);
705
725
  expect(rebound.match(/where:/g)).toHaveLength(1);
706
726
  const after = await openDocument(rebound);
707
- expect(after.tiles[0].filters).toEqual([
727
+ expect(queryTile(after, 0).filters).toEqual([
708
728
  { field: "category", given: "CATEGORY" },
709
729
  ]);
710
730
  });
@@ -719,16 +739,16 @@ source: a is one extend {
719
739
  where: category ~ $CATEGORY }
720
740
  }`;
721
741
  const before = await openDocument(sharedClose);
722
- expect(before.tiles[0].filters).toEqual([
742
+ expect(queryTile(before, 0).filters).toEqual([
723
743
  { field: "category", given: "CATEGORY" },
724
744
  ]);
725
745
  const rebound = await spliced(sharedClose, (d) => {
726
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
746
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
727
747
  });
728
748
  expect(rebound).toBe(sharedClose);
729
749
  expect(rebound.match(/where:/g)).toHaveLength(1);
730
750
  const after = await openDocument(rebound);
731
- expect(after.tiles[0].filters).toEqual([
751
+ expect(queryTile(after, 0).filters).toEqual([
732
752
  { field: "category", given: "CATEGORY" },
733
753
  ]);
734
754
  });
@@ -745,14 +765,14 @@ source: a is one extend {
745
765
  where: category ~ $CATEGORY }
746
766
  }`;
747
767
  const out = await spliced(sharedClose, (d) => {
748
- delete d.tiles[0].filters;
768
+ delete queryTile(d, 0).filters;
749
769
  });
750
770
  // The closing brace itself, not just the text before it: dropped whole
751
771
  // line and all, the view's own `}` would go with the where: clause.
752
772
  expect(out).toContain(" aggregate: n is count()\n }\n}");
753
773
  expect(out).not.toContain("where:");
754
774
  const reopened = await openDocument(out);
755
- expect(reopened.tiles[0].declaration).toEqual({ kind: "inline" });
775
+ expect(queryTile(reopened, 0).declaration).toEqual({ kind: "inline" });
756
776
  });
757
777
 
758
778
  // Adding a second binding when the first already shares the closing
@@ -768,7 +788,7 @@ source: a is one extend {
768
788
  where: category ~ $CATEGORY }
769
789
  }`;
770
790
  const out = await spliced(sharedClose, (d) => {
771
- d.tiles[0].filters = [
791
+ queryTile(d, 0).filters = [
772
792
  { field: "category", given: "CATEGORY" },
773
793
  { field: "brand", given: "BRAND" },
774
794
  ];
@@ -777,7 +797,7 @@ source: a is one extend {
777
797
  " where: category ~ $CATEGORY\n where: brand ~ $BRAND }",
778
798
  );
779
799
  const reopened = await openDocument(out);
780
- expect(reopened.tiles[0].filters).toEqual([
800
+ expect(queryTile(reopened, 0).filters).toEqual([
781
801
  { field: "category", given: "CATEGORY" },
782
802
  { field: "brand", given: "BRAND" },
783
803
  ]);
@@ -806,13 +826,13 @@ source: a is one extend {
806
826
  suggest: { source: "products", dimension: "category" },
807
827
  },
808
828
  ];
809
- d.tiles[0].filters = [{ field: "category", given: "CATEGORY" }];
829
+ queryTile(d, 0).filters = [{ field: "category", given: "CATEGORY" }];
810
830
  });
811
831
  expect(out.startsWith("##! experimental.givens\n")).toBe(true);
812
832
  expect(out).toContain(
813
833
  `import { one, products } from "../m.malloy"
814
834
 
815
- # label="Category" control=select suggest { source=products dimension=category }
835
+ # label="Category" control=select suggest { source=products dimension="category" }
816
836
  given: CATEGORY :: filter<string> is f''
817
837
  `,
818
838
  );
@@ -919,6 +939,41 @@ given: CATEGORY :: filter<string> is f''`);
919
939
  });
920
940
  });
921
941
 
942
+ describe("spliceDashboardDocument: a given's suggest", () => {
943
+ const SUGGESTED = `##! experimental.givens
944
+ ## artifact { title="T" tiles=["a -> x"] }
945
+ import "../m.malloy"
946
+
947
+ # label="Brand" suggest { query=brand_suggest dimension="brand" }
948
+ given: BRAND :: filter<string> is f''
949
+
950
+ source: a is one extend {
951
+ view: x is vx
952
+ }`;
953
+
954
+ it("relabels a given whose suggest is a query, writing the query quoted", async () => {
955
+ const out = await spliced(SUGGESTED, (d) => {
956
+ d.localGivens![0].label = "Brand name";
957
+ });
958
+ expect(out).toContain(
959
+ `# label="Brand name" suggest { query="brand_suggest" dimension="brand" }`,
960
+ );
961
+ expect((await openDocument(out)).localGivens![0].suggest).toEqual({
962
+ query: "brand_suggest",
963
+ dimension: "brand",
964
+ });
965
+ });
966
+
967
+ it("refuses a changed suggest dimension or query that reads as an access-control tag", async () => {
968
+ for (const field of ["dimension", "query"] as const) {
969
+ const reason = await refused(SUGGESTED, (d) => {
970
+ d.localGivens![0].suggest![field] = "# authorize";
971
+ });
972
+ expect(reason).toContain("access-control");
973
+ }
974
+ });
975
+ });
976
+
922
977
  describe("spliceDashboardDocument: drills", () => {
923
978
  const WITH_DIMENSION = `## artifact { title="T" tiles=["a -> x"] }
924
979
  import "../m.malloy"
@@ -1070,6 +1125,48 @@ describe("spliceDashboardDocument: the page's own settings", () => {
1070
1125
  ).toBe(true);
1071
1126
  });
1072
1127
 
1128
+ describe('how many `##"` lines a description writes', () => {
1129
+ const NB = `##" Old\n## artifact { kind=notebook title="T" tiles=["a -> x"] }\nimport "../m.malloy"\n\nsource: a is one extend {\n view: x is vx\n}`;
1130
+
1131
+ it("writes one line for a one-line description, however it ends", async () => {
1132
+ for (const description of [
1133
+ "Walk description",
1134
+ "Walk description\n\n",
1135
+ ]) {
1136
+ const out = await spliced(NB, (d) => {
1137
+ d.description = description;
1138
+ });
1139
+ expect(out.startsWith('##" Walk description\n## artifact {')).toBe(
1140
+ true,
1141
+ );
1142
+ }
1143
+ });
1144
+
1145
+ it("writes N lines for N lines, keeping a blank paragraph between them", async () => {
1146
+ const out = await spliced(NB, (d) => {
1147
+ d.description = "\nOne\n\nTwo\n";
1148
+ });
1149
+ expect(out.startsWith('##" One\n##"\n##" Two\n## artifact {')).toBe(
1150
+ true,
1151
+ );
1152
+ });
1153
+
1154
+ it("round-trips an unchanged description byte for byte", async () => {
1155
+ const source = NB.replace('##" Old', '##" One\n##"\n##" Two');
1156
+ expect(
1157
+ await spliced(source, (d) => {
1158
+ d.title = "Retitled";
1159
+ }),
1160
+ ).toBe(source.replace('title="T"', 'title="Retitled"'));
1161
+ // The same text written back is the same file.
1162
+ expect(
1163
+ await spliced(source, (d) => {
1164
+ d.description = "One\n\nTwo";
1165
+ }),
1166
+ ).toBe(source);
1167
+ });
1168
+ });
1169
+
1073
1170
  // The saved file is what the server lints, so it is linted here rather than re-read.
1074
1171
  const lintCodes = (source: string) =>
1075
1172
  lintNotebookText("dashboards/d.malloy", source).map((f) => f.code);
@@ -1097,25 +1194,31 @@ describe("spliceDashboardDocument: the page's own settings", () => {
1097
1194
  });
1098
1195
  });
1099
1196
 
1100
- it("refuses to reorder, add or remove tiles when tiles holds a text tile, and leaves the file alone", async () => {
1101
- const source = fs.readFileSync(
1102
- path.join(
1103
- REPO,
1104
- "packages/server/tests/fixtures/notebooks-malloyyo/dashboards/text_tiles.malloy",
1105
- ),
1106
- "utf8",
1107
- );
1108
- // The file has one quoted tile beside the text tile, so removal is the edit that reaches the list.
1109
- const reason = await refused(source, (d) => {
1110
- d.tiles.pop();
1111
- });
1112
- expect(reason).toContain("text tile");
1113
- // A settings edit that does not touch the tile list still works.
1197
+ it("reorders a list holding a text tile, keeping its entry as written", async () => {
1198
+ const source = fs
1199
+ .readFileSync(
1200
+ path.join(
1201
+ REPO,
1202
+ "packages/server/tests/fixtures/notebooks-malloyyo/dashboards/text_tiles.malloy",
1203
+ ),
1204
+ "utf8",
1205
+ )
1206
+ .replace(/\r\n/g, "\n");
1114
1207
  const out = await spliced(source, (d) => {
1208
+ d.tiles.reverse();
1209
+ });
1210
+ expect(out).toContain(
1211
+ 'tiles=["orders -> kpis", intro { kind=text colspan=12 }]',
1212
+ );
1213
+ expect(out).toContain(
1214
+ "##|(markdown) intro\n## How to read this page\n|##",
1215
+ );
1216
+ // A settings edit that does not touch the tile list leaves the entry alone too.
1217
+ const renamed = await spliced(source, (d) => {
1115
1218
  d.title = "Renamed";
1116
1219
  });
1117
- expect(out).toContain("intro { kind=text colspan=12 }");
1118
- expect(out).toContain('title="Renamed"');
1220
+ expect(renamed).toContain("intro { kind=text colspan=12 }");
1221
+ expect(renamed).toContain('title="Renamed"');
1119
1222
  });
1120
1223
 
1121
1224
  it("changes the width of a file whose title holds dashboard { }", async () => {
@@ -1375,7 +1478,7 @@ describe("spliceDashboardDocument: what it refuses", () => {
1375
1478
  d.imports.push({ kind: "all", from: "../more.malloy" });
1376
1479
  });
1377
1480
  expect(r.ok).toBe(false);
1378
- if (spliceFailed(r)) expect(r.reason).toContain("imports");
1481
+ if (spliceFailed(r)) expect(r.reason).toContain("whole-file");
1379
1482
  });
1380
1483
 
1381
1484
  // An inherited tile's tags live on the model's view, and the builder never
@@ -1551,7 +1654,7 @@ describe("every composite dashboard survives an edit", () => {
1551
1654
  const doc = await readDashboardDocument(source);
1552
1655
  if (readFailed(doc)) throw new Error(doc.reason);
1553
1656
  const target = doc.document.tiles.findIndex(
1554
- (t) => t.declaration.kind !== "inherited",
1657
+ (t) => isQueryTile(t) && t.declaration.kind !== "inherited",
1555
1658
  );
1556
1659
  // A file whose tiles are all declared on their sources has nothing
1557
1660
  // here to patch, which is a real shape rather than a gap.
@@ -1585,7 +1688,7 @@ describe("every composite dashboard survives an edit", () => {
1585
1688
  const doc = await readDashboardDocument(source);
1586
1689
  if (readFailed(doc)) throw new Error(doc.reason);
1587
1690
  const target = doc.document.tiles.findIndex(
1588
- (t) => t.declaration.kind !== "inherited",
1691
+ (t) => isQueryTile(t) && t.declaration.kind !== "inherited",
1589
1692
  );
1590
1693
  // No tile declared here: a real shape, not a gap in the sweep.
1591
1694
  if (target < 0) return;
@@ -1596,8 +1699,8 @@ describe("every composite dashboard survives an edit", () => {
1596
1699
 
1597
1700
  const next = structuredClone(doc.document);
1598
1701
  const binding = { field: "_probe", given };
1599
- next.tiles[target].filters = [
1600
- ...(next.tiles[target].filters ?? []),
1702
+ queryTile(next, target).filters = [
1703
+ ...(queryTile(next, target).filters ?? []),
1601
1704
  binding,
1602
1705
  ];
1603
1706
  const result = await spliceDashboardDocument(source, next);
@@ -1611,7 +1714,9 @@ describe("every composite dashboard survives an edit", () => {
1611
1714
  expect(await syntaxErrors(result.source)).toEqual([]);
1612
1715
  const reread = await readDashboardDocument(result.source);
1613
1716
  if (readFailed(reread)) throw new Error(reread.reason);
1614
- expect(reread.document.tiles[target].filters).toContainEqual(binding);
1717
+ expect(queryTile(reread.document, target).filters).toContainEqual(
1718
+ binding,
1719
+ );
1615
1720
  const moved = await whatMoved(source, result.source);
1616
1721
  expect(moved.comments).toEqual([]);
1617
1722
  expect(moved.attached).toEqual([]);
@@ -1653,7 +1758,7 @@ describe("every composite dashboard survives an edit", () => {
1653
1758
  const doc = await readDashboardDocument(source);
1654
1759
  if (readFailed(doc)) throw new Error(doc.reason);
1655
1760
  const target = doc.document.tiles.findIndex(
1656
- (t) => t.declaration.kind !== "inherited",
1761
+ (t) => isQueryTile(t) && t.declaration.kind !== "inherited",
1657
1762
  );
1658
1763
  // One tile left, or every tile declared on its source: nothing here
1659
1764
  // reaches the declaration-deletion path.
@@ -1671,30 +1776,31 @@ describe("every composite dashboard survives an edit", () => {
1671
1776
  expect(reread.document.tiles.map((t) => t.name)).not.toContain(
1672
1777
  gone.name,
1673
1778
  );
1674
- await survives(source, result.source, [
1675
- `-view:${gone.source}.${gone.name}`,
1676
- ]);
1779
+ await survives(source, result.source, [`-view:${tileKey(gone)}`]);
1677
1780
  });
1678
1781
 
1679
1782
  it(`unbinds a filter in ${name} and disturbs nothing beside it`, async () => {
1680
1783
  const source = fs.readFileSync(file, "utf8");
1681
1784
  const doc = await readDashboardDocument(source);
1682
1785
  if (readFailed(doc)) throw new Error(doc.reason);
1683
- const target = doc.document.tiles.findIndex((t) => t.filters?.length);
1786
+ const target = doc.document.tiles.findIndex(
1787
+ (t) => isQueryTile(t) && t.filters?.length,
1788
+ );
1684
1789
  // No tile binds a control here: a real shape, not a gap.
1685
1790
  if (target < 0) return;
1686
1791
 
1687
1792
  const next = structuredClone(doc.document);
1688
- next.tiles[target].filters = next.tiles[target].filters!.slice(0, -1);
1793
+ queryTile(next, target).filters = queryTile(
1794
+ next,
1795
+ target,
1796
+ ).filters!.slice(0, -1);
1689
1797
  const result = await spliceDashboardDocument(source, next);
1690
1798
  if (spliceFailed(result)) {
1691
1799
  expect(result.reason.length).toBeGreaterThan(0);
1692
1800
  return;
1693
1801
  }
1694
1802
  const tile = next.tiles[target];
1695
- await survives(source, result.source, [
1696
- `~view:${tile.source}.${tile.name}`,
1697
- ]);
1803
+ await survives(source, result.source, [`~view:${tileKey(tile)}`]);
1698
1804
  });
1699
1805
 
1700
1806
  it(`removes a control from ${name} and disturbs nothing beside it`, async () => {
@@ -1985,10 +2091,10 @@ source: a is one extend {
1985
2091
  it("keeps a quote in a tile label, and reads it back", async () => {
1986
2092
  const label = 'Revenue (the "good" kind)';
1987
2093
  const result = await spliced(FILE, (d) => {
1988
- d.tiles[0].label = label;
2094
+ queryTile(d, 0).label = label;
1989
2095
  });
1990
2096
  const reread = await openDocument(result);
1991
- expect(reread.tiles[0].label).toBe(label);
2097
+ expect(queryTile(reread, 0).label).toBe(label);
1992
2098
  });
1993
2099
 
1994
2100
  it("keeps a trailing backslash in a given's label", async () => {
@@ -2012,10 +2118,10 @@ source: a is one extend {
2012
2118
  it("keeps a quote in a tile subtitle", async () => {
2013
2119
  const subtitle = 'by "region"';
2014
2120
  const result = await spliced(FILE, (d) => {
2015
- d.tiles[0].subtitle = subtitle;
2121
+ queryTile(d, 0).subtitle = subtitle;
2016
2122
  });
2017
2123
  const reread = await openDocument(result);
2018
- expect(reread.tiles[0].subtitle).toBe(subtitle);
2124
+ expect(queryTile(reread, 0).subtitle).toBe(subtitle);
2019
2125
  });
2020
2126
  });
2021
2127
 
@@ -2046,7 +2152,7 @@ source: a is one extend {
2046
2152
  },
2047
2153
  (d: DashboardDocument) => {
2048
2154
  d.localGivens = d.localGivens ?? [];
2049
- d.tiles[0].filters = [];
2155
+ queryTile(d, 0).filters = [];
2050
2156
  },
2051
2157
  ]) {
2052
2158
  expect(await spliced(FILE, materialise)).toBe(FILE);
@@ -2108,7 +2214,7 @@ source: b is scoped_orders extend {
2108
2214
 
2109
2215
  it("retags the second source's view without touching the first's", async () => {
2110
2216
  const out = await spliced(SHARED, (d) => {
2111
- const tile = d.tiles.find((t) => t.source === "b");
2217
+ const tile = d.tiles.filter(isQueryTile).find((t) => t.source === "b");
2112
2218
  if (!tile) throw new Error("no tile on b");
2113
2219
  tile.label = "B by month";
2114
2220
  });
@@ -2127,7 +2233,7 @@ source: b is scoped_orders extend {
2127
2233
 
2128
2234
  it("edits the first source's view when that is the tile", async () => {
2129
2235
  const out = await spliced(SHARED, (d) => {
2130
- const tile = d.tiles.find((t) => t.source === "a");
2236
+ const tile = d.tiles.filter(isQueryTile).find((t) => t.source === "a");
2131
2237
  if (!tile) throw new Error("no tile on a");
2132
2238
  tile.label = "A by month";
2133
2239
  });
@@ -2271,7 +2377,7 @@ source: a is scoped_orders extend {
2271
2377
 
2272
2378
  it("binds inside kpis's own body and never touches the unrelated view", async () => {
2273
2379
  const out = await spliced(SOURCE, (d) => {
2274
- d.tiles[0].filters = [{ field: "cat", given: "CATEGORY" }];
2380
+ queryTile(d, 0).filters = [{ field: "cat", given: "CATEGORY" }];
2275
2381
  });
2276
2382
  expect(out).toContain(
2277
2383
  " view: kpis is {\n group_by: cat // the { brace here is unbalanced\n aggregate: n is count()\n where: cat ~ $CATEGORY\n }",
@@ -2311,11 +2417,15 @@ source: a is one extend {
2311
2417
  expect(result.source).toBe(TEXT_TILE);
2312
2418
  });
2313
2419
 
2314
- it("still refuses a tile-list edit over the text tile", async () => {
2315
- const reason = await refused(TEXT_TILE, (d) => {
2420
+ it("removes a query tile beside a text tile without touching the text tile", async () => {
2421
+ const out = await spliced(TEXT_TILE, (d) => {
2316
2422
  d.tiles.pop();
2317
2423
  });
2318
- expect(reason).toContain("text tile");
2424
+ expect(out).toContain("tiles=[intro { kind=text colspan=12 }]");
2425
+ expect(out).toContain(
2426
+ "##|(markdown) intro\n## How to read this page\n|##\n",
2427
+ );
2428
+ expect(out).not.toContain("view: x");
2319
2429
  });
2320
2430
 
2321
2431
  it("rewrites a description and a tile's colspan without touching the markdown around them", async () => {
@@ -2487,3 +2597,28 @@ source: a is one extend {
2487
2597
  expect(given?.label).toBeUndefined();
2488
2598
  });
2489
2599
  });
2600
+
2601
+ describe("spliceDashboardDocument: a CRLF file", () => {
2602
+ const CRLF = SOURCE.replace(/\n/g, "\r\n");
2603
+ const bareNewlines = (text: string) => text.match(/(?<!\r)\n/g)?.length ?? 0;
2604
+
2605
+ it("writes its own line ending into every line it inserts", async () => {
2606
+ const out = await spliced(CRLF, (d) => {
2607
+ queryTile(d, 0).label = "Categories";
2608
+ queryTile(d, 1).filters = [{ field: "brand", given: "BRAND" }];
2609
+ queryTile(d, 1).subtitle = "Top brands";
2610
+ d.tiles.push({
2611
+ name: "by_state",
2612
+ source: "a",
2613
+ declaration: { kind: "reference", from: "by_state_view" },
2614
+ });
2615
+ });
2616
+ expect(out).toContain('# label="Categories"\r\n');
2617
+ expect(out).toContain("by_state");
2618
+ expect(bareNewlines(out)).toBe(0);
2619
+ });
2620
+
2621
+ it("leaves it byte-identical when nothing changed", async () => {
2622
+ expect(await spliced(CRLF, () => {})).toBe(CRLF);
2623
+ });
2624
+ });