@malloy-publisher/sdk 0.9.7 → 0.9.8

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 (350) hide show
  1. package/README.md +117 -17
  2. package/dist/{RenderedResult-qnpbr4tc.cjs.js → RenderedResult-BrvrMDAP.cjs.js} +1 -1
  3. package/dist/{RenderedResult-CkUS04tl.es.js → RenderedResult-DZj-FnOJ.es.js} +2 -2
  4. package/dist/{ServerProvider-DnLLeXEX.es.js → ServerProvider-B_bPAsu2.es.js} +583 -398
  5. package/dist/ServerProvider-DuEOzwPc.cjs.js +1 -0
  6. package/dist/builder/index.cjs.js +93 -93
  7. package/dist/builder/index.es.js +4630 -4562
  8. package/dist/builder-entry.d.ts +13 -12
  9. package/dist/client/api.d.ts +472 -94
  10. package/dist/client/index.cjs.js +1 -1
  11. package/dist/client/index.es.js +105 -95
  12. package/dist/components/Dashboard/DashboardTile.d.ts +3 -1
  13. package/dist/components/Dashboard/DashboardView.d.ts +1 -3
  14. package/dist/components/Dashboard/index.d.ts +0 -2
  15. package/dist/components/DocumentCreate/createDocument.d.ts +29 -9
  16. package/dist/components/DocumentCreate/documentPath.d.ts +21 -6
  17. package/dist/components/DocumentCreate/guards.d.ts +2 -3
  18. package/dist/components/DocumentCreate/index.d.ts +2 -3
  19. package/dist/components/DocumentCreate/newNotebook.d.ts +14 -5
  20. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +6 -0
  21. package/dist/components/DocumentStorage/DocumentStorage.d.ts +52 -24
  22. package/dist/components/Loading.d.ts +1 -1
  23. package/dist/components/Package/DataSchemaDialog.d.ts +26 -0
  24. package/dist/components/Package/NewDocumentDialog.d.ts +19 -10
  25. package/dist/components/Package/Package.d.ts +14 -9
  26. package/dist/components/Package/documentLocation.d.ts +66 -23
  27. package/dist/components/Package/index.d.ts +3 -2
  28. package/dist/components/Package/reportQueries.d.ts +8 -0
  29. package/dist/components/Package/useDocumentLocation.d.ts +36 -6
  30. package/dist/components/Package/useDraftLayout.d.ts +20 -0
  31. package/dist/components/Report/CellReport.d.ts +89 -0
  32. package/dist/components/Report/LinearReport.d.ts +18 -0
  33. package/dist/components/Report/Report.d.ts +62 -0
  34. package/dist/components/Report/index.d.ts +2 -0
  35. package/dist/components/Report/telemetry.d.ts +163 -0
  36. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderDialogs.d.ts +2 -2
  37. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderGrid.d.ts +2 -2
  38. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderHeader.d.ts +5 -4
  39. package/dist/components/{DashboardBuilder → ReportBuilder}/BuilderToolbar.d.ts +5 -1
  40. package/dist/components/{DashboardBuilder → ReportBuilder}/EditorSurface.d.ts +10 -7
  41. package/dist/components/{DashboardBuilder/DashboardBuilder.d.ts → ReportBuilder/ReportBuilder.d.ts} +17 -8
  42. package/dist/components/{DashboardBuilder/DashboardEditor.d.ts → ReportBuilder/ReportEditor.d.ts} +41 -14
  43. package/dist/components/ReportBuilder/builderReport.d.ts +14 -0
  44. package/dist/components/{DashboardBuilder → ReportBuilder}/catalog.d.ts +8 -5
  45. package/dist/components/{DashboardBuilder → ReportBuilder}/document.d.ts +3 -4
  46. package/dist/components/{DashboardBuilder → ReportBuilder}/documentSession.d.ts +1 -1
  47. package/dist/components/{DashboardBuilder → ReportBuilder}/imports.d.ts +5 -1
  48. package/dist/components/{DashboardBuilder → ReportBuilder}/malloyTree.d.ts +9 -0
  49. package/dist/components/{DashboardBuilder → ReportBuilder}/newDashboard.d.ts +7 -1
  50. package/dist/components/{DashboardBuilder → ReportBuilder}/readDocument.d.ts +7 -5
  51. package/dist/components/{DashboardBuilder → ReportBuilder}/readForEditor.d.ts +1 -1
  52. package/dist/components/ReportBuilder/reportTag.d.ts +52 -0
  53. package/dist/components/{DashboardBuilder → ReportBuilder}/spliceDocument.d.ts +1 -7
  54. package/dist/components/{DashboardBuilder → ReportBuilder}/useBuilderSelection.d.ts +2 -2
  55. package/dist/components/{DashboardBuilder → ReportBuilder}/useControlBindings.d.ts +2 -2
  56. package/dist/components/ReportBuilder/useEditorCatalog.d.ts +25 -0
  57. package/dist/components/{DashboardBuilder → ReportBuilder}/useHostCopy.d.ts +5 -3
  58. package/dist/components/{DashboardBuilder → ReportBuilder}/useOpenedDocument.d.ts +7 -5
  59. package/dist/components/{DashboardBuilder/useDashboardEditor.d.ts → ReportBuilder/useReportEditor.d.ts} +3 -7
  60. package/dist/components/{DashboardBuilder → ReportBuilder}/useSaveChannel.d.ts +6 -4
  61. package/dist/components/{DashboardBuilder → ReportBuilder}/useTileEditing.d.ts +2 -2
  62. package/dist/components/ServerProvider.d.ts +2 -1
  63. package/dist/components/drill/resolveDrill.d.ts +8 -1
  64. package/dist/components/drill/useDrillSelf.d.ts +4 -2
  65. package/dist/components/index.d.ts +2 -1
  66. package/dist/components/{Dashboard → legacy}/Dashboard.d.ts +15 -9
  67. package/dist/components/legacy/MalloynbCells.d.ts +13 -0
  68. package/dist/components/legacy/Notebook.d.ts +15 -0
  69. package/dist/components/{DashboardBuilder → legacy}/NotebookEditor.d.ts +3 -3
  70. package/dist/components/legacy/builderNames.d.ts +10 -0
  71. package/dist/components/legacy/index.d.ts +11 -0
  72. package/dist/components/legacy/kindAdapter.d.ts +11 -0
  73. package/dist/components/legacy/kindTypedDrafts.d.ts +10 -0
  74. package/dist/components/legacy/nameAlias.d.ts +44 -0
  75. package/dist/components/legacy/queryKeys.d.ts +8 -0
  76. package/dist/index.cjs.js +19 -19
  77. package/dist/index.es.js +7984 -7452
  78. package/dist/text/index.es.js +2 -2
  79. package/dist/{text-entry-CA0LZ1xL.es.js → text-entry-72YFLeNk.es.js} +10 -10
  80. package/dist/useCompiledDocument-oocN5cGE.cjs.js +141 -0
  81. package/dist/{useCompiledDocument-Bf72Ob5v.es.js → useCompiledDocument-x0B2RAH3.es.js} +4593 -4395
  82. package/package.json +2 -2
  83. package/src/builder-entry.ts +32 -24
  84. package/src/components/Dashboard/DashboardTile.tsx +17 -0
  85. package/src/components/Dashboard/DashboardView.spec.tsx +0 -21
  86. package/src/components/Dashboard/DashboardView.tsx +8 -24
  87. package/src/components/Dashboard/dropValueUrlTags.spec.ts +1 -4
  88. package/src/components/Dashboard/index.ts +0 -2
  89. package/src/components/DocumentCreate/createDocument.spec.ts +346 -53
  90. package/src/components/DocumentCreate/createDocument.ts +143 -63
  91. package/src/components/DocumentCreate/documentPath.ts +41 -12
  92. package/src/components/DocumentCreate/guards.ts +7 -15
  93. package/src/components/DocumentCreate/index.ts +3 -7
  94. package/src/components/DocumentCreate/newNotebook.spec.ts +113 -43
  95. package/src/components/DocumentCreate/newNotebook.ts +32 -10
  96. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +130 -28
  97. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +78 -40
  98. package/src/components/DocumentStorage/DocumentStorage.contract.spec.tsx +426 -0
  99. package/src/components/DocumentStorage/DocumentStorage.ts +57 -24
  100. package/src/components/Home/AddEnvironmentDialog.tsx +1 -1
  101. package/src/components/Home/Home.tsx +1 -1
  102. package/src/components/Loading.tsx +1 -1
  103. package/src/components/Model/SourcesExplorer.tsx +1 -1
  104. package/src/components/Notebook/NotebookCell.tsx +6 -5
  105. package/src/components/Notebook/cellKind.spec.ts +15 -7
  106. package/src/components/Package/DataSchemaDialog.spec.tsx +85 -0
  107. package/src/components/Package/DataSchemaDialog.tsx +367 -0
  108. package/src/components/Package/NewDocumentDialog.spec.tsx +145 -88
  109. package/src/components/Package/NewDocumentDialog.tsx +93 -48
  110. package/src/components/Package/Package.artifacts.spec.tsx +79 -60
  111. package/src/components/Package/Package.create.spec.tsx +126 -112
  112. package/src/components/Package/Package.notebooks.spec.tsx +46 -27
  113. package/src/components/Package/Package.spec.tsx +43 -30
  114. package/src/components/Package/Package.tsx +173 -292
  115. package/src/components/Package/documentLocation.spec.ts +145 -50
  116. package/src/components/Package/documentLocation.ts +118 -39
  117. package/src/components/Package/index.ts +12 -3
  118. package/src/components/Package/reportQueries.ts +25 -0
  119. package/src/components/Package/useDocumentLocation.spec.ts +58 -0
  120. package/src/components/Package/useDocumentLocation.ts +90 -32
  121. package/src/components/Package/useDraftLayout.spec.tsx +143 -0
  122. package/src/components/Package/useDraftLayout.ts +81 -0
  123. package/src/components/Prose.spec.tsx +3 -3
  124. package/src/components/RenderedResult/RenderedResult.tsx +1 -1
  125. package/src/components/Report/CellReport.spec.tsx +155 -0
  126. package/src/components/{Notebook/Notebook.tsx → Report/CellReport.tsx} +178 -220
  127. package/src/components/Report/LinearReport.tsx +71 -0
  128. package/src/components/Report/Report.spec.tsx +238 -0
  129. package/src/components/Report/Report.telemetry.spec.tsx +292 -0
  130. package/src/components/Report/Report.tsx +277 -0
  131. package/src/components/Report/index.ts +12 -0
  132. package/src/components/Report/telemetry.spec.ts +90 -0
  133. package/src/components/Report/telemetry.ts +250 -0
  134. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderDialogs.tsx +5 -5
  135. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderGrid.tsx +2 -2
  136. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderHeader.tsx +6 -7
  137. package/src/components/{DashboardBuilder → ReportBuilder}/BuilderToolbar.tsx +33 -0
  138. package/src/components/{DashboardBuilder → ReportBuilder}/DrillDialog.tsx +2 -2
  139. package/src/components/{DashboardBuilder → ReportBuilder}/EditorSurface.tsx +67 -107
  140. package/src/components/{DashboardBuilder → ReportBuilder}/FilterDialog.tsx +3 -4
  141. package/src/components/{DashboardBuilder/DashboardBuilder.charts.spec.tsx → ReportBuilder/ReportBuilder.charts.spec.tsx} +4 -4
  142. package/src/components/{DashboardBuilder/DashboardBuilder.exit.spec.tsx → ReportBuilder/ReportBuilder.exit.spec.tsx} +5 -5
  143. package/src/components/{DashboardBuilder/DashboardBuilder.inline.spec.tsx → ReportBuilder/ReportBuilder.inline.spec.tsx} +4 -4
  144. package/src/components/ReportBuilder/ReportBuilder.layoutSwitch.spec.tsx +145 -0
  145. package/src/components/{DashboardBuilder/DashboardBuilder.notebook.spec.tsx → ReportBuilder/ReportBuilder.notebook.spec.tsx} +22 -21
  146. package/src/components/{DashboardBuilder/DashboardBuilder.openDraft.spec.tsx → ReportBuilder/ReportBuilder.openDraft.spec.tsx} +3 -3
  147. package/src/components/{DashboardBuilder/DashboardBuilder.sources.spec.tsx → ReportBuilder/ReportBuilder.sources.spec.tsx} +19 -8
  148. package/src/components/{DashboardBuilder/DashboardBuilder.spec.tsx → ReportBuilder/ReportBuilder.spec.tsx} +34 -34
  149. package/src/components/{DashboardBuilder/DashboardBuilder.textTiles.spec.tsx → ReportBuilder/ReportBuilder.textTiles.spec.tsx} +5 -5
  150. package/src/components/{DashboardBuilder/DashboardBuilder.tsx → ReportBuilder/ReportBuilder.tsx} +46 -21
  151. package/src/components/{DashboardBuilder/DashboardEditor.authoritative.spec.tsx → ReportBuilder/ReportEditor.authoritative.spec.tsx} +28 -20
  152. package/src/components/{DashboardBuilder/DashboardEditor.emptyStart.spec.tsx → ReportBuilder/ReportEditor.emptyStart.spec.tsx} +19 -11
  153. package/src/components/{DashboardBuilder/DashboardEditor.filterTag.spec.tsx → ReportBuilder/ReportEditor.filterTag.spec.tsx} +7 -7
  154. package/src/components/{DashboardBuilder/DashboardEditor.notebook.spec.tsx → ReportBuilder/ReportEditor.notebook.spec.tsx} +70 -49
  155. package/src/components/{DashboardBuilder/DashboardEditor.package.spec.tsx → ReportBuilder/ReportEditor.package.spec.tsx} +52 -8
  156. package/src/components/{DashboardBuilder/DashboardEditor.resourceUri.spec.tsx → ReportBuilder/ReportEditor.resourceUri.spec.tsx} +50 -18
  157. package/src/components/{DashboardBuilder/DashboardEditor.spec.tsx → ReportBuilder/ReportEditor.spec.tsx} +65 -20
  158. package/src/components/{DashboardBuilder/DashboardEditor.textSource.spec.tsx → ReportBuilder/ReportEditor.textSource.spec.tsx} +6 -6
  159. package/src/components/{DashboardBuilder/DashboardEditor.tsx → ReportBuilder/ReportEditor.tsx} +92 -35
  160. package/src/components/{DashboardBuilder → ReportBuilder}/addTile.compile.spec.ts +1 -3
  161. package/src/components/{DashboardBuilder → ReportBuilder}/addTileToDocument.spec.ts +1 -0
  162. package/src/components/{DashboardBuilder → ReportBuilder}/artifactBlock.spec.ts +21 -29
  163. package/src/components/ReportBuilder/builderReport.ts +53 -0
  164. package/src/components/{DashboardBuilder → ReportBuilder}/catalog.spec.ts +28 -10
  165. package/src/components/{DashboardBuilder → ReportBuilder}/catalog.ts +17 -10
  166. package/src/components/{DashboardBuilder → ReportBuilder}/controls.spec.ts +1 -0
  167. package/src/components/{DashboardBuilder → ReportBuilder}/document.ts +4 -7
  168. package/src/components/{DashboardBuilder → ReportBuilder}/documentSession.spec.ts +5 -5
  169. package/src/components/{DashboardBuilder → ReportBuilder}/documentSession.ts +1 -1
  170. package/src/components/{DashboardBuilder → ReportBuilder}/imports.spec.ts +6 -2
  171. package/src/components/{DashboardBuilder → ReportBuilder}/imports.ts +8 -4
  172. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.chart.spec.ts +1 -1
  173. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.convert.spec.ts +9 -13
  174. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.read.spec.ts +15 -15
  175. package/src/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.ts +7 -2
  176. package/src/components/{DashboardBuilder → ReportBuilder}/malloyTree.ts +25 -0
  177. package/src/components/{DashboardBuilder → ReportBuilder}/newDashboard.spec.ts +12 -4
  178. package/src/components/{DashboardBuilder → ReportBuilder}/newDashboard.ts +11 -24
  179. package/src/components/{DashboardBuilder → ReportBuilder}/preview.spec.ts +1 -0
  180. package/src/components/{DashboardBuilder → ReportBuilder}/readDocument.spec.ts +64 -36
  181. package/src/components/{DashboardBuilder → ReportBuilder}/readDocument.ts +33 -32
  182. package/src/components/ReportBuilder/readForEditor.spec.ts +96 -0
  183. package/src/components/{DashboardBuilder → ReportBuilder}/readForEditor.ts +3 -11
  184. package/src/components/ReportBuilder/reportTag.ts +108 -0
  185. package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.imports.spec.ts +28 -1
  186. package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.spec.ts +32 -3
  187. package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.ts +37 -60
  188. package/src/components/{DashboardBuilder → ReportBuilder}/tagParse.spec.ts +3 -3
  189. package/src/components/{DashboardBuilder → ReportBuilder}/testing/artifactTagParity.json +2 -2
  190. package/src/components/ReportBuilder/testing/drillResolution.json +279 -0
  191. package/src/components/ReportBuilder/testing/reportLayoutParity.json +125 -0
  192. package/src/components/{DashboardBuilder → ReportBuilder}/textTiles.spec.ts +66 -143
  193. package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderSelection.ts +2 -2
  194. package/src/components/{DashboardBuilder → ReportBuilder}/useControlBindings.ts +2 -2
  195. package/src/components/ReportBuilder/useEditorCatalog.spec.tsx +156 -0
  196. package/src/components/ReportBuilder/useEditorCatalog.ts +119 -0
  197. package/src/components/{DashboardBuilder → ReportBuilder}/useHostCopy.ts +7 -5
  198. package/src/components/{DashboardBuilder → ReportBuilder}/useOpenedDocument.ts +56 -35
  199. package/src/components/{DashboardBuilder/useDashboardEditor.spec.ts → ReportBuilder/useReportEditor.spec.ts} +6 -6
  200. package/src/components/{DashboardBuilder/useDashboardEditor.ts → ReportBuilder/useReportEditor.ts} +6 -17
  201. package/src/components/{DashboardBuilder → ReportBuilder}/useSaveChannel.ts +36 -35
  202. package/src/components/{DashboardBuilder → ReportBuilder}/useTileEditing.ts +2 -2
  203. package/src/components/ServerProvider.tsx +2 -0
  204. package/src/components/drill/resolveDrill.ts +9 -2
  205. package/src/components/drill/useDrill.tsx +1 -0
  206. package/src/components/drill/useDrillSelf.spec.tsx +60 -7
  207. package/src/components/drill/useDrillSelf.ts +29 -12
  208. package/src/components/index.ts +2 -1
  209. package/src/components/{Dashboard → legacy}/Dashboard.spec.tsx +1 -1
  210. package/src/components/{Dashboard → legacy}/Dashboard.tsx +40 -28
  211. package/src/components/legacy/MalloynbCells.tsx +88 -0
  212. package/src/components/{Notebook → legacy}/Notebook.served.spec.tsx +17 -13
  213. package/src/components/{Notebook → legacy}/Notebook.spec.tsx +24 -20
  214. package/src/components/legacy/Notebook.tsx +44 -0
  215. package/src/components/{DashboardBuilder → legacy}/NotebookEditor.tsx +7 -4
  216. package/src/components/legacy/builderNames.ts +25 -0
  217. package/src/components/legacy/index.ts +20 -0
  218. package/src/components/legacy/kindAdapter.ts +19 -0
  219. package/src/components/legacy/kindTypedDrafts.ts +34 -0
  220. package/src/components/legacy/nameAlias.spec.ts +124 -0
  221. package/src/components/legacy/nameAlias.ts +95 -0
  222. package/src/components/legacy/queryKeys.ts +26 -0
  223. package/src/hooks/useGivensState.spec.ts +9 -9
  224. package/src/mainEntry.spec.ts +1 -1
  225. package/src/textEntry.spec.ts +9 -9
  226. package/src/utils/formatting.spec.ts +5 -5
  227. package/src/utils/parsing.spec.ts +1 -1
  228. package/src/utils/parsing.ts +1 -1
  229. package/dist/ServerProvider-Gj-im5VD.cjs.js +0 -1
  230. package/dist/components/Dashboard/telemetry.d.ts +0 -73
  231. package/dist/components/DashboardBuilder/builderReport.d.ts +0 -13
  232. package/dist/components/DashboardBuilder/telemetry.d.ts +0 -43
  233. package/dist/components/DocumentCreate/events.d.ts +0 -10
  234. package/dist/components/Notebook/Notebook.d.ts +0 -52
  235. package/dist/components/Notebook/index.d.ts +0 -1
  236. package/dist/useCompiledDocument-tBejqZ7s.cjs.js +0 -142
  237. package/src/components/Dashboard/telemetry.ts +0 -75
  238. package/src/components/DashboardBuilder/builderReport.ts +0 -74
  239. package/src/components/DashboardBuilder/readForEditor.spec.ts +0 -80
  240. package/src/components/DashboardBuilder/telemetry.ts +0 -47
  241. package/src/components/DashboardBuilder/testing/documentKindRule.json +0 -40
  242. package/src/components/DocumentCreate/events.ts +0 -15
  243. package/src/components/Notebook/index.ts +0 -4
  244. /package/dist/components/{DashboardBuilder → ReportBuilder}/AddTileDialog.d.ts +0 -0
  245. /package/dist/components/{DashboardBuilder → ReportBuilder}/ChartPicker.d.ts +0 -0
  246. /package/dist/components/{DashboardBuilder → ReportBuilder}/DrillDialog.d.ts +0 -0
  247. /package/dist/components/{DashboardBuilder → ReportBuilder}/FilterDialog.d.ts +0 -0
  248. /package/dist/components/{DashboardBuilder → ReportBuilder}/FilterStrip.d.ts +0 -0
  249. /package/dist/components/{DashboardBuilder → ReportBuilder}/InlineMarkdown.d.ts +0 -0
  250. /package/dist/components/{DashboardBuilder → ReportBuilder}/InlineText.d.ts +0 -0
  251. /package/dist/components/{DashboardBuilder → ReportBuilder}/SourceViewPicker.d.ts +0 -0
  252. /package/dist/components/{DashboardBuilder → ReportBuilder}/TextTileBody.d.ts +0 -0
  253. /package/dist/components/{DashboardBuilder → ReportBuilder}/TileFrame.d.ts +0 -0
  254. /package/dist/components/{DashboardBuilder → ReportBuilder}/TileMenu.d.ts +0 -0
  255. /package/dist/components/{DashboardBuilder → ReportBuilder}/addTileToDocument.d.ts +0 -0
  256. /package/dist/components/{DashboardBuilder → ReportBuilder}/annotationText.d.ts +0 -0
  257. /package/dist/components/{DashboardBuilder → ReportBuilder}/changedTile.d.ts +0 -0
  258. /package/dist/components/{DashboardBuilder → ReportBuilder}/chartLine.d.ts +0 -0
  259. /package/dist/components/{DashboardBuilder → ReportBuilder}/controls.d.ts +0 -0
  260. /package/dist/components/{DashboardBuilder → ReportBuilder}/inlineEdit.d.ts +0 -0
  261. /package/dist/components/{DashboardBuilder → ReportBuilder}/layout.d.ts +0 -0
  262. /package/dist/components/{DashboardBuilder → ReportBuilder}/legacyNotebook.d.ts +0 -0
  263. /package/dist/components/{DashboardBuilder → ReportBuilder}/loadMalloy.d.ts +0 -0
  264. /package/dist/components/{DashboardBuilder → ReportBuilder}/openDraft.d.ts +0 -0
  265. /package/dist/components/{DashboardBuilder → ReportBuilder}/preview.d.ts +0 -0
  266. /package/dist/components/{DashboardBuilder → ReportBuilder}/sortable.d.ts +0 -0
  267. /package/dist/components/{DashboardBuilder → ReportBuilder}/spliceResult.d.ts +0 -0
  268. /package/dist/components/{DashboardBuilder → ReportBuilder}/tagParse.d.ts +0 -0
  269. /package/dist/components/{DashboardBuilder → ReportBuilder}/testing/fixtures.d.ts +0 -0
  270. /package/dist/components/{DashboardBuilder → ReportBuilder}/testing/inline.d.ts +0 -0
  271. /package/dist/components/{DashboardBuilder → ReportBuilder}/testing/resize.d.ts +0 -0
  272. /package/dist/components/{DashboardBuilder → ReportBuilder}/tileDisplayTitle.d.ts +0 -0
  273. /package/dist/components/{DashboardBuilder → ReportBuilder}/useBuilderSession.d.ts +0 -0
  274. /package/dist/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.d.ts +0 -0
  275. /package/dist/components/{DashboardBuilder → ReportBuilder}/useConversionConfirm.d.ts +0 -0
  276. /package/dist/components/{DashboardBuilder → ReportBuilder}/useDocumentEditor.d.ts +0 -0
  277. /package/dist/components/{DashboardBuilder → ReportBuilder}/useDraft.d.ts +0 -0
  278. /package/dist/components/{DashboardBuilder → ReportBuilder}/useExitGuard.d.ts +0 -0
  279. /package/dist/components/{DashboardBuilder → ReportBuilder}/useFilterForm.d.ts +0 -0
  280. /package/dist/components/{DashboardBuilder → ReportBuilder}/useOpenDraftCommit.d.ts +0 -0
  281. /package/dist/components/{DashboardBuilder → ReportBuilder}/useTileReorder.d.ts +0 -0
  282. /package/dist/components/{DashboardBuilder → ReportBuilder}/useTileResize.d.ts +0 -0
  283. /package/src/components/{DashboardBuilder → ReportBuilder}/AddTileDialog.spec.tsx +0 -0
  284. /package/src/components/{DashboardBuilder → ReportBuilder}/AddTileDialog.tsx +0 -0
  285. /package/src/components/{DashboardBuilder → ReportBuilder}/ChartPicker.render.spec.tsx +0 -0
  286. /package/src/components/{DashboardBuilder → ReportBuilder}/ChartPicker.spec.ts +0 -0
  287. /package/src/components/{DashboardBuilder → ReportBuilder}/ChartPicker.tsx +0 -0
  288. /package/src/components/{DashboardBuilder → ReportBuilder}/FilterStrip.tsx +0 -0
  289. /package/src/components/{DashboardBuilder → ReportBuilder}/InlineMarkdown.tsx +0 -0
  290. /package/src/components/{DashboardBuilder → ReportBuilder}/InlineText.tsx +0 -0
  291. /package/src/components/{DashboardBuilder → ReportBuilder}/SourceViewPicker.tsx +0 -0
  292. /package/src/components/{DashboardBuilder → ReportBuilder}/TextTileBody.tsx +0 -0
  293. /package/src/components/{DashboardBuilder → ReportBuilder}/TileFrame.tsx +0 -0
  294. /package/src/components/{DashboardBuilder → ReportBuilder}/TileMenu.tsx +0 -0
  295. /package/src/components/{DashboardBuilder → ReportBuilder}/__test__/inventory.ts +0 -0
  296. /package/src/components/{DashboardBuilder → ReportBuilder}/addTileToDocument.ts +0 -0
  297. /package/src/components/{DashboardBuilder → ReportBuilder}/annotationText.spec.ts +0 -0
  298. /package/src/components/{DashboardBuilder → ReportBuilder}/annotationText.ts +0 -0
  299. /package/src/components/{DashboardBuilder → ReportBuilder}/artifactTagParity.spec.ts +0 -0
  300. /package/src/components/{DashboardBuilder → ReportBuilder}/catalog.aggregate.spec.ts +0 -0
  301. /package/src/components/{DashboardBuilder → ReportBuilder}/changedTile.spec.ts +0 -0
  302. /package/src/components/{DashboardBuilder → ReportBuilder}/changedTile.ts +0 -0
  303. /package/src/components/{DashboardBuilder → ReportBuilder}/chartLine.spec.ts +0 -0
  304. /package/src/components/{DashboardBuilder → ReportBuilder}/chartLine.ts +0 -0
  305. /package/src/components/{DashboardBuilder → ReportBuilder}/controls.ts +0 -0
  306. /package/src/components/{DashboardBuilder → ReportBuilder}/emptyStart.spec.ts +0 -0
  307. /package/src/components/{DashboardBuilder → ReportBuilder}/inlineEdit.tsx +0 -0
  308. /package/src/components/{DashboardBuilder → ReportBuilder}/invariants.spec.ts +0 -0
  309. /package/src/components/{DashboardBuilder → ReportBuilder}/keepRowStructure.spec.ts +0 -0
  310. /package/src/components/{DashboardBuilder → ReportBuilder}/layout.ts +0 -0
  311. /package/src/components/{DashboardBuilder → ReportBuilder}/loadMalloy.spec.ts +0 -0
  312. /package/src/components/{DashboardBuilder → ReportBuilder}/loadMalloy.ts +0 -0
  313. /package/src/components/{DashboardBuilder → ReportBuilder}/malloyTree.spec.ts +0 -0
  314. /package/src/components/{DashboardBuilder → ReportBuilder}/moveIntoGap.spec.ts +0 -0
  315. /package/src/components/{DashboardBuilder → ReportBuilder}/openDraft.ts +0 -0
  316. /package/src/components/{DashboardBuilder → ReportBuilder}/preview.shapes.spec.ts +0 -0
  317. /package/src/components/{DashboardBuilder → ReportBuilder}/preview.ts +0 -0
  318. /package/src/components/{DashboardBuilder → ReportBuilder}/scannerShapes.spec.ts +0 -0
  319. /package/src/components/{DashboardBuilder → ReportBuilder}/sortable.spec.ts +0 -0
  320. /package/src/components/{DashboardBuilder → ReportBuilder}/sortable.tsx +0 -0
  321. /package/src/components/{DashboardBuilder → ReportBuilder}/spliceDocument.chart.spec.ts +0 -0
  322. /package/src/components/{DashboardBuilder → ReportBuilder}/spliceResult.ts +0 -0
  323. /package/src/components/{DashboardBuilder → ReportBuilder}/statementExtent.spec.ts +0 -0
  324. /package/src/components/{DashboardBuilder → ReportBuilder}/tagParse.ts +0 -0
  325. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/fixtures.ts +0 -0
  326. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/inline.ts +0 -0
  327. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/resize.ts +0 -0
  328. /package/src/components/{DashboardBuilder → ReportBuilder}/testing/urlRenderTags.json +0 -0
  329. /package/src/components/{DashboardBuilder → ReportBuilder}/tileDisplayTitle.ts +0 -0
  330. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderSession.spec.ts +0 -0
  331. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderSession.ts +0 -0
  332. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.overlay.spec.tsx +0 -0
  333. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.spec.tsx +0 -0
  334. /package/src/components/{DashboardBuilder → ReportBuilder}/useBuilderShortcuts.ts +0 -0
  335. /package/src/components/{DashboardBuilder → ReportBuilder}/useConversionConfirm.ts +0 -0
  336. /package/src/components/{DashboardBuilder → ReportBuilder}/useDocumentEditor.spec.ts +0 -0
  337. /package/src/components/{DashboardBuilder → ReportBuilder}/useDocumentEditor.ts +0 -0
  338. /package/src/components/{DashboardBuilder → ReportBuilder}/useDraft.ts +0 -0
  339. /package/src/components/{DashboardBuilder → ReportBuilder}/useExitGuard.spec.ts +0 -0
  340. /package/src/components/{DashboardBuilder → ReportBuilder}/useExitGuard.ts +0 -0
  341. /package/src/components/{DashboardBuilder → ReportBuilder}/useFilterForm.existing.spec.tsx +0 -0
  342. /package/src/components/{DashboardBuilder → ReportBuilder}/useFilterForm.spec.tsx +0 -0
  343. /package/src/components/{DashboardBuilder → ReportBuilder}/useFilterForm.ts +0 -0
  344. /package/src/components/{DashboardBuilder → ReportBuilder}/useOpenDraftCommit.ts +0 -0
  345. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileReorder.spec.tsx +0 -0
  346. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileReorder.ts +0 -0
  347. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileResize.spec.tsx +0 -0
  348. /package/src/components/{DashboardBuilder → ReportBuilder}/useTileResize.ts +0 -0
  349. /package/src/components/{DashboardBuilder → ReportBuilder}/withGaps.spec.ts +0 -0
  350. /package/src/components/{Notebook → legacy}/Notebook.layout.spec.tsx +0 -0
@@ -7,6 +7,7 @@ import * as fs from "fs";
7
7
  import * as path from "path";
8
8
  import { blockAbove, readDashboardDocument, readFailed } from "./readDocument";
9
9
  import { readForEditor } from "./readForEditor";
10
+ import { readReportTagOfText } from "./reportTag";
10
11
  import { parseMalloy, parseRefused } from "./malloyTree";
11
12
  import { queryTile } from "./testing/fixtures";
12
13
  import { tileKey } from "./document";
@@ -798,7 +799,7 @@ describe("readDashboardDocument: what it refuses", () => {
798
799
  it("refuses a file with no artifact tag", async () => {
799
800
  const r = await readDashboardDocument("source: a is b extend { }");
800
801
  expect(r.ok).toBe(false);
801
- if (readFailed(r)) expect(r.reason).toContain("composite dashboard");
802
+ if (readFailed(r)) expect(r.reason).toContain("not a report");
802
803
  });
803
804
 
804
805
  it("refuses a tile that is not a source -> view expression", async () => {
@@ -863,8 +864,7 @@ describe("a tag whose artifact property is not the first", () => {
863
864
 
864
865
  it("is refused, not converted, for a cell-format notebook", async () => {
865
866
  const open = await readForEditor(
866
- `##! experimental.givens\n## dashboard { columns=2 } artifact { kind=notebook title="T" }\nrun: a -> by_cat`,
867
- "notebooks/n.malloy",
867
+ `##! experimental.givens\n## dashboard { columns=2 } artifact { layout=linear title="T" }\nrun: a -> by_cat`,
868
868
  );
869
869
  expect(open.ok === false && open.reason).toContain(
870
870
  "`artifact { … }` first",
@@ -882,11 +882,11 @@ describe("a tag whose artifact property is not the first", () => {
882
882
 
883
883
  /**
884
884
  * The tripwire. All-or-nothing refusal is only reasonable while real dashboards
885
- * open, so this asserts that every composite dashboard in the repository does.
885
+ * open, so this asserts that every not a report in the repository does.
886
886
  * If that stops being true, this fails in CI rather than in a support thread,
887
887
  * and it is the signal to reconsider opening files partially.
888
888
  */
889
- describe("every composite dashboard in the repository opens", () => {
889
+ describe("every not a report in the repository opens", () => {
890
890
  const roots = ["examples", "packages/server/tests/fixtures"];
891
891
  const found: string[] = [];
892
892
  const walk = (dir: string) => {
@@ -900,9 +900,15 @@ describe("every composite dashboard in the repository opens", () => {
900
900
  };
901
901
  for (const root of roots) walk(path.join(REPO, root));
902
902
 
903
- const composites = found.filter((f) =>
904
- /##\s*artifact[\s\S]*tiles\s*=/.test(fs.readFileSync(f, "utf8")),
905
- );
903
+ // A report whose one tile is a named query is not one the builder lays
904
+ // out (it edits `source -> view` tiles), so it is not expected to open.
905
+ const composites = found.filter((f) => {
906
+ const text = fs.readFileSync(f, "utf8");
907
+ return (
908
+ /##\s*artifact[\s\S]*tiles\s*=/.test(text) &&
909
+ !/tiles=\["[A-Za-z_]\w*"\]/.test(text)
910
+ );
911
+ });
906
912
 
907
913
  it("finds composites to check", () => {
908
914
  expect(composites.length).toBeGreaterThan(0);
@@ -956,38 +962,60 @@ describe("the compiler stays lazy", () => {
956
962
  });
957
963
  });
958
964
 
959
- describe("the kind of a document held as text", () => {
965
+ describe("the layout of a report", () => {
966
+ it("reads the same layout wherever the file lives: the folder no longer matters", async () => {
967
+ const cases = [
968
+ ["## artifact { }\nrun: q -> { aggregate: c }\n", true],
969
+ [`## artifact { tiles=["a -> v"] }\n`, false],
970
+ [`## artifact { layout=linear tiles=["a -> v"] }\n`, true],
971
+ ["## artifact { layout=grid tiles=[] }\n", false],
972
+ ] as const;
973
+ for (const [source, linear] of cases)
974
+ for (const where of [
975
+ undefined,
976
+ "x.malloy",
977
+ "notebooks/x.malloy",
978
+ "dashboards/x.malloy",
979
+ "sales/q3/x.malloy",
980
+ ]) {
981
+ const result = await readDashboardDocument(source, where);
982
+ const isLinear = readFailed(result)
983
+ ? result.legacyNotebook === true
984
+ : result.document.layout === "linear";
985
+ expect([where, isLinear]).toEqual([where, linear]);
986
+ }
987
+ });
988
+ });
989
+
990
+ /**
991
+ * The layout parity table the server's one reader is held to
992
+ * (`report_layout_parity.spec.ts`): the SDK's tag reader gives the same
993
+ * answer on every case, and the builder opens a file it can open with that
994
+ * layout.
995
+ */
996
+ describe("report layout parity: the SDK reader", () => {
960
997
  const { cases } = JSON.parse(
961
998
  fs.readFileSync(
962
- path.join(import.meta.dir, "testing/documentKindRule.json"),
999
+ path.join(import.meta.dir, "testing/reportLayoutParity.json"),
963
1000
  "utf8",
964
1001
  ),
965
- ) as { cases: { name: string; source: string; kind: string }[] };
966
-
967
- // One case table for this reader and the server's `submittedTextKind`, whose spec reads the same file.
968
- for (const { name, source, kind } of cases) {
969
- it(`${name}: ${kind}`, async () => {
970
- const result = await readDashboardDocument(source, undefined, true);
971
- const notebook = readFailed(result)
972
- ? result.legacyNotebook === true
973
- : result.document.kind === "notebook";
974
- expect(notebook).toBe(kind === "notebook");
1002
+ ) as {
1003
+ cases: {
1004
+ name: string;
1005
+ source: string;
1006
+ expected: "grid" | "linear" | null;
1007
+ }[];
1008
+ };
1009
+
1010
+ for (const testCase of cases) {
1011
+ it(testCase.name, async () => {
1012
+ const tag = await readReportTagOfText(testCase.source);
1013
+ expect(tag.status === "report" ? tag.layout : null).toBe(
1014
+ testCase.expected,
1015
+ );
1016
+ const read = await readDashboardDocument(testCase.source);
1017
+ if (!readFailed(read))
1018
+ expect(read.document.layout).toBe(testCase.expected);
975
1019
  });
976
1020
  }
977
-
978
- it("still takes the folder's kind when the host has a folder", async () => {
979
- const source = "## artifact { }\nrun: q -> { aggregate: c }\n";
980
- const inNotebooks = await readDashboardDocument(
981
- source,
982
- "notebooks/x.malloy",
983
- );
984
- expect(readFailed(inNotebooks) && inNotebooks.legacyNotebook).toBe(true);
985
- const inDashboards = await readDashboardDocument(
986
- source,
987
- "dashboards/x.malloy",
988
- );
989
- expect(
990
- readFailed(inDashboards) && inDashboards.legacyNotebook,
991
- ).toBeFalsy();
992
- });
993
1021
  });
@@ -16,6 +16,7 @@ import type {
16
16
  } from "./document";
17
17
  import { isTextTile } from "./document";
18
18
  import { loadMalloyTag } from "./loadMalloy";
19
+ import { kindRemovedReason, readReportTag } from "./reportTag";
19
20
  import { parseTagLines } from "./tagParse";
20
21
  import {
21
22
  parseMalloy,
@@ -37,7 +38,7 @@ import {
37
38
  } from "../../utils/malloyText";
38
39
 
39
40
  /**
40
- * Read a `dashboards/*.malloy` file into a {@link DashboardDocument}.
41
+ * Read a report file (either layout, anywhere in the package) into a {@link DashboardDocument}.
41
42
  *
42
43
  * PURE: source text in, document out. No server, no schema, no connection.
43
44
  * `Malloy.parse` needs none of those — only `Malloy.compile` does — so this runs
@@ -66,7 +67,7 @@ export interface ReadFailure {
66
67
  reason: string;
67
68
  /** 1-based, for a message that can point at the line. */
68
69
  line?: number;
69
- /** The file is a `kind=notebook` in the run-cell format, which `convertLegacyNotebook` turns into a layout notebook. */
70
+ /** The file is a linear report in the run-cell format, which `convertLegacyNotebook` turns into a tile layout. */
70
71
  legacyNotebook?: true;
71
72
  }
72
73
 
@@ -161,9 +162,8 @@ function chartField(tags: Array<{ text: string }>): {
161
162
  * is exactly `field <op> $GIVEN`.
162
163
  *
163
164
  * A clause that is anything else — a compound predicate, a literal comparison
164
- * — is not a binding and is left exactly as written. That is a STRUCTURAL
165
- * test now, so the isolation heuristics this used to need are gone along with
166
- * the shapes that defeated them.
165
+ * — is not a binding and is left exactly as written. The test is structural,
166
+ * read off the tree, not a text heuristic.
167
167
  */
168
168
  function filtersOf(
169
169
  stage: TreeStage | undefined,
@@ -281,12 +281,13 @@ const TEXT_ENTRY = /^([A-Za-z_][A-Za-z0-9_]*)\s*\{/;
281
281
  /** Refuses rather than throws: `Tag.text()` throws on a malformed date literal such as `@2024-13-01`, and dropping the value would lose it on the next save. */
282
282
  export async function readDashboardDocument(
283
283
  sourceText: string,
284
- modelPath?: string,
285
- /** A document the host keeps as text has no folder to take a kind from, so the layout decides. */
286
- textHeld = false,
284
+ /** The file's path. Kept for callers; where a report lives never decides its layout. */
285
+ _modelPath?: string,
286
+ /** Kept for callers: text held by a host is read by the same rule as a file. */
287
+ _textHeld = false,
287
288
  ): Promise<ReadResult> {
288
289
  try {
289
- return await readDocumentText(sourceText, modelPath, textHeld);
290
+ return await readDocumentText(sourceText);
290
291
  } catch (error) {
291
292
  return {
292
293
  ok: false,
@@ -295,11 +296,7 @@ export async function readDashboardDocument(
295
296
  }
296
297
  }
297
298
 
298
- async function readDocumentText(
299
- sourceText: string,
300
- modelPath: string | undefined,
301
- textHeld: boolean,
302
- ): Promise<ReadResult> {
299
+ async function readDocumentText(sourceText: string): Promise<ReadResult> {
303
300
  const { parseAnnotation } = await loadMalloyTag();
304
301
  const lines = splitSourceLines(sourceText);
305
302
 
@@ -313,14 +310,28 @@ async function readDocumentText(
313
310
  const parsed = parse.parsed;
314
311
 
315
312
  const description = descriptionNotes(lines).text;
313
+ // What the file is, by the server's rule over the same model-level notes.
314
+ const reportTag = readReportTag(parsed.modelNotes, parseAnnotation as never);
315
+ if (reportTag.status === "none")
316
+ return {
317
+ ok: false,
318
+ reason: "No `## artifact { … }` tag, so this file is not a report.",
319
+ };
320
+ if (reportTag.status === "unparsed")
321
+ return {
322
+ ok: false,
323
+ reason: `The \`## artifact\` tag does not parse${reportTag.errors[0] ? `: ${reportTag.errors[0]}` : "."}`,
324
+ };
325
+ if (reportTag.status === "kind-removed")
326
+ return { ok: false, reason: kindRemovedReason(reportTag.kind) };
327
+ const layout = reportTag.layout;
328
+
316
329
  const artifactAt = locateArtifactTag(lines);
317
- if (artifactAt === undefined) {
330
+ if (artifactAt === undefined)
318
331
  return {
319
332
  ok: false,
320
- reason:
321
- "No `## artifact { … }` tag, so this file is not a composite dashboard.",
333
+ reason: "No `## artifact { … }` tag, so this file is not a report.",
322
334
  };
323
- }
324
335
  if (!artifactLeads(artifactAt.text))
325
336
  return {
326
337
  ok: false,
@@ -332,16 +343,6 @@ async function readDocumentText(
332
343
  tagAnnotation(artifactAt.text),
333
344
  ]);
334
345
  const artifactTag = tag?.tag("artifact");
335
- const tagKind = artifactTag?.text("kind");
336
- // The server's rule: a tag that names no kind takes the folder's, and submitted text has none, so tiles or a grid width make it a dashboard.
337
- const listsLayout =
338
- artifactTag?.has("tiles") === true || tag?.tag("dashboard") !== undefined;
339
- const kind =
340
- tagKind === "notebook" ||
341
- (tagKind !== "dashboard" &&
342
- (textHeld ? !listsLayout : modelPath?.startsWith("notebooks/")))
343
- ? ("notebook" as const)
344
- : undefined;
345
346
  const list = readTileList(artifactAt.text);
346
347
  if (list === undefined) {
347
348
  if (tagErrors.length > 0)
@@ -349,13 +350,13 @@ async function readDocumentText(
349
350
  ok: false,
350
351
  reason: `The \`## artifact\` tag does not parse: ${tagErrors[0]}`,
351
352
  };
352
- // A notebook is told from a layout one by whether it lists tiles at all.
353
- if (kind === "notebook")
353
+ // A linear report is told from a tile layout by whether it lists tiles at all.
354
+ if (layout === "linear")
354
355
  return {
355
356
  ok: false,
356
357
  legacyNotebook: true,
357
358
  reason:
358
- "This notebook is in the cell format, with no `tiles=[…]` list.",
359
+ "This report is in the cell format, with no `tiles=[…]` list.",
359
360
  };
360
361
  return {
361
362
  ok: false,
@@ -558,7 +559,7 @@ async function readDocumentText(
558
559
  return {
559
560
  ok: true,
560
561
  document: {
561
- ...(kind ? { kind } : {}),
562
+ layout,
562
563
  title: artifactTag?.text("title") ?? "",
563
564
  ...(description ? { description } : {}),
564
565
  ...(columnsTag === undefined ? {} : { columns: columnsTag }),
@@ -0,0 +1,96 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import * as fs from "fs";
6
+ import * as path from "path";
7
+ import { readForEditor } from "./readForEditor";
8
+
9
+ const REPO = path.resolve(import.meta.dir, "../../../../..");
10
+ const LEGACY = fs
11
+ .readFileSync(
12
+ path.join(REPO, "examples/storefront/category-review.malloy"),
13
+ "utf8",
14
+ )
15
+ .replace(/\r\n/g, "\n");
16
+
17
+ describe("readForEditor", () => {
18
+ it("opens a layout file as it is, with no conversion", async () => {
19
+ const result = await readForEditor(
20
+ `## artifact { title="D" tiles=["a -> x"] }\nsource: a is b extend {\n view: x is v\n}\n`,
21
+ );
22
+ expect(result.ok).toBe(true);
23
+ expect(result.ok && result.conversion).toBeUndefined();
24
+ });
25
+
26
+ it("converts a cell-format notebook, keeping the disk text to hand back", async () => {
27
+ const result = await readForEditor(LEGACY);
28
+ if (result.ok === false) throw new Error(result.reason);
29
+ expect(result.conversion?.from).toBe(LEGACY);
30
+ expect(result.conversion?.to).toContain(
31
+ "tiles=[\n text_1 { kind=text }",
32
+ );
33
+ expect(result.document.layout).toBe("linear");
34
+ expect(result.document.tiles).toHaveLength(7);
35
+ });
36
+
37
+ it("refuses a conversion it cannot make, naming the line", async () => {
38
+ const result = await readForEditor(
39
+ `## artifact { layout=linear }\nimport { o } from "../m.malloy"\n\nrun: o extend { dimension: z is 1 } -> { select: z }\n`,
40
+ );
41
+ expect(result.ok).toBe(false);
42
+ expect(result.ok === false && result.reason).toMatch(/line 4/i);
43
+ });
44
+
45
+ it("says why a file that is not a notebook will not open, with its line", async () => {
46
+ const result = await readForEditor(`source: a is b\n`);
47
+ expect(result.ok).toBe(false);
48
+ });
49
+
50
+ // The reader takes no path: a report's layout is its tag's, wherever it lives.
51
+ describe("a report's layout is its tags'", () => {
52
+ const LAYOUT = `## artifact { title="D" tiles=["a -> x"] }\nsource: a is b extend {\n view: x is v\n}\n`;
53
+
54
+ it("opens a tile list with no layout as a grid", async () => {
55
+ const result = await readForEditor(LAYOUT);
56
+ expect(result.ok && result.document.layout).toBe("grid");
57
+ });
58
+
59
+ it("opens it linear when layout=linear says so", async () => {
60
+ const result = await readForEditor(
61
+ LAYOUT.replace("{ title", "{ layout=linear title"),
62
+ );
63
+ expect(result.ok && result.document.layout).toBe("linear");
64
+ });
65
+
66
+ it("refuses a tag that sets the removed kind=, naming the layout= to write", async () => {
67
+ const result = await readForEditor(
68
+ LAYOUT.replace("{ title", "{ kind=notebook title"),
69
+ );
70
+ expect(result.ok).toBe(false);
71
+ expect(result.ok === false && result.reason).toContain(
72
+ "`kind=notebook` is no longer read",
73
+ );
74
+ expect(result.ok === false && result.reason).toContain(
75
+ "`layout=grid` or `layout=linear`",
76
+ );
77
+ });
78
+
79
+ it("converts a cell-format file with no layout rather than refusing it", async () => {
80
+ const layoutless = LEGACY.replace("layout=linear ", "");
81
+ expect(layoutless).not.toBe(LEGACY);
82
+ const result = await readForEditor(layoutless);
83
+ if (result.ok === false) throw new Error(result.reason);
84
+ expect(result.conversion?.from).toBe(layoutless);
85
+ });
86
+
87
+ // A tile list with no `layout=` reads as grid, so the converter writes `layout=linear`.
88
+ it("converts a cell-format file with no layout into a LINEAR report", async () => {
89
+ const layoutless = LEGACY.replace("layout=linear ", "");
90
+ const result = await readForEditor(layoutless);
91
+ if (result.ok === false) throw new Error(result.reason);
92
+ expect(result.document.layout).toBe("linear");
93
+ expect(result.conversion?.to).toContain("layout=linear");
94
+ });
95
+ });
96
+ });
@@ -21,12 +21,8 @@ const withLine = (reason: string, line: number | undefined) =>
21
21
  : reason;
22
22
 
23
23
  /** Read `text` for the builder, converting a cell-format notebook rather than refusing it. */
24
- export async function readForEditor(
25
- text: string,
26
- modelPath?: string,
27
- textHeld = false,
28
- ): Promise<EditorOpen> {
29
- const read = await readDashboardDocument(text, modelPath, textHeld);
24
+ export async function readForEditor(text: string): Promise<EditorOpen> {
25
+ const read = await readDashboardDocument(text);
30
26
  if (!readFailed(read)) return { ok: true, document: read.document };
31
27
  if (!read.legacyNotebook)
32
28
  return { ok: false, reason: withLine(read.reason, read.line) };
@@ -34,11 +30,7 @@ export async function readForEditor(
34
30
  const converted = await convertLegacyNotebook(text);
35
31
  if (conversionRefused(converted))
36
32
  return { ok: false, reason: withLine(converted.refused, converted.line) };
37
- const reread = await readDashboardDocument(
38
- converted.text,
39
- modelPath,
40
- textHeld,
41
- );
33
+ const reread = await readDashboardDocument(converted.text);
42
34
  if (readFailed(reread))
43
35
  return {
44
36
  ok: false,
@@ -0,0 +1,108 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { setsArtifactProperty, tagAnnotation } from "../../utils/malloyText";
5
+ import type { ReportLayout } from "../Package/documentLocation";
6
+ import { loadMalloyTag } from "./loadMalloy";
7
+ import {
8
+ isRule,
9
+ readModelNotes,
10
+ Reader,
11
+ translate,
12
+ type Ctx,
13
+ } from "./malloyTree";
14
+ import { parseTagLines } from "./tagParse";
15
+
16
+ /**
17
+ * What a file's model-level notes make it, by the server's rule
18
+ * (`readReportTag`, `docs/reports-design.md` §1, §2):
19
+ *
20
+ * - `none`: no model-level `## artifact` note, so not a report.
21
+ * - `unparsed`: an artifact note the tag parser rejects, so not a report.
22
+ * - `kind-removed`: the tag sets the removed `kind=`, so not a report.
23
+ * - `report`: a report, with its layout.
24
+ */
25
+ export type ReportTag =
26
+ | { status: "none" }
27
+ | { status: "unparsed"; errors: string[] }
28
+ | { status: "kind-removed"; kind: string }
29
+ | { status: "report"; layout: ReportLayout };
30
+
31
+ type Parsed = { tag: TagReads; log: Array<{ message: string }> };
32
+ type TagReads = {
33
+ tag(key: string): TagReads | undefined;
34
+ text(key: string): string | undefined;
35
+ has(key: string): boolean;
36
+ };
37
+
38
+ /** A tag property as text; `text()` throws on a malformed date literal, which reads as no value. */
39
+ const textOf = (tag: TagReads, key: string): string | undefined => {
40
+ try {
41
+ return tag.text(key);
42
+ } catch {
43
+ return undefined;
44
+ }
45
+ };
46
+
47
+ /** Malloy's route rule: a routed note (`##(markdown)`, `##"`) or a flag (`##!`) is never a tag. */
48
+ const onTagRoute = (note: string) => /^##\|?(?:[ \t\r\n]|$)/.test(note);
49
+
50
+ /** Why a `kind=` tag makes no report, and the fix: the server's message, word for word. */
51
+ export const kindRemovedReason = (kind: string) =>
52
+ `\`kind=${kind}\` is no longer read, so this file is not a report. Fix: remove \`kind=${kind}\` and write \`layout=grid\` or \`layout=linear\`.`;
53
+
54
+ /**
55
+ * The one reader of a report's tag in the SDK, over a file's model-level
56
+ * notes (`ParsedMalloy.modelNotes`). The server's `readReportTag` is the same
57
+ * rule over the same notes; `reportLayoutParity.json` holds the two together.
58
+ *
59
+ * The layout, first match wins: `layout=grid|linear`; else grid when the tag
60
+ * lists `tiles` (an empty list counts) or a model-level `dashboard { … }` grid
61
+ * tag is present; else linear.
62
+ */
63
+ export function readReportTag(
64
+ modelNotes: readonly string[],
65
+ parseAnnotation: (lines: string[]) => Parsed,
66
+ ): ReportTag {
67
+ // A note naming an environment value is dropped before parsing, as the server drops it.
68
+ const motly = modelNotes
69
+ .filter(onTagRoute)
70
+ .filter((note) => !note.includes("@env."))
71
+ .map(tagAnnotation);
72
+ const { tag, errors } =
73
+ motly.length > 0
74
+ ? parseTagLines(parseAnnotation, motly)
75
+ : { tag: undefined, errors: [] };
76
+ const artifact = tag?.tag("artifact");
77
+ if (!artifact)
78
+ return modelNotes.some(setsArtifactProperty)
79
+ ? { status: "unparsed", errors }
80
+ : { status: "none" };
81
+ const kind = textOf(artifact, "kind");
82
+ if (kind !== undefined) return { status: "kind-removed", kind };
83
+ const layout = textOf(artifact, "layout");
84
+ if (layout === "grid" || layout === "linear")
85
+ return { status: "report", layout };
86
+ if (artifact.has("tiles") || tag?.tag("dashboard") !== undefined)
87
+ return { status: "report", layout: "grid" };
88
+ return { status: "report", layout: "linear" };
89
+ }
90
+
91
+ /**
92
+ * {@link readReportTag} over raw text, parsed for its notes and nothing else:
93
+ * the answer for a file whatever else is wrong with it, as the server reads a
94
+ * file that does not compile.
95
+ */
96
+ export async function readReportTagOfText(text: string): Promise<ReportTag> {
97
+ const { parseAnnotation } = await loadMalloyTag();
98
+ let notes: string[] = [];
99
+ try {
100
+ const root = (await translate(text, "file://report.malloy")).parse
101
+ ?.root as Ctx | undefined;
102
+ if (root && isRule(root) && typeof root.getChild === "function")
103
+ notes = readModelNotes(new Reader(text), root);
104
+ } catch {
105
+ notes = [];
106
+ }
107
+ return readReportTag(notes, parseAnnotation as never);
108
+ }
@@ -2,6 +2,7 @@
2
2
  // SPDX-License-Identifier: MIT
3
3
 
4
4
  import { describe, expect, it } from "bun:test";
5
+ import { addTileToDocument } from "./addTileToDocument";
5
6
  import { openDocument, refused, spliced } from "./testing/fixtures";
6
7
 
7
8
  const SOURCE = `## artifact { title="Probe" tiles=["a -> by_cat"] } dashboard { columns=12 }
@@ -53,6 +54,32 @@ describe("spliceDashboardDocument: imports", () => {
53
54
  });
54
55
  });
55
56
 
57
+ it("puts a new import above a new extension when the file ends on its import", async () => {
58
+ const blank = `## artifact { title="Blank" tiles=[] }\nimport { orders } from '../orders.malloy'\n`;
59
+ const out = await spliced(blank, (d) => {
60
+ addTileToDocument(
61
+ d,
62
+ {
63
+ base: "recent_orders",
64
+ modelPath: "dashboards/_shared.malloy",
65
+ exporters: ["dashboards/_shared.malloy"],
66
+ view: "totals",
67
+ colspan: 6,
68
+ },
69
+ {
70
+ modelPath: "dashboards/blank.malloy",
71
+ textHeld: false,
72
+ notebook: false,
73
+ },
74
+ );
75
+ });
76
+ const imported = out.indexOf(
77
+ 'import { recent_orders } from "_shared.malloy"',
78
+ );
79
+ expect(imported).toBeGreaterThan(-1);
80
+ expect(imported).toBeLessThan(out.indexOf("source: recent_orders_tiles"));
81
+ });
82
+
56
83
  it("takes a name off the statement", async () => {
57
84
  const out = await spliced(SOURCE, (d) => {
58
85
  const names = d.imports[1];
@@ -158,7 +185,7 @@ describe("spliceDashboardDocument: imports", () => {
158
185
  });
159
186
 
160
187
  it("has nowhere to put a first import", async () => {
161
- const source = `## artifact { kind=notebook title="T" tiles=[intro { kind=text }] }\n\n##|(markdown) intro\nHi\n|##\n`;
188
+ const source = `## artifact { layout=linear title="T" tiles=[intro { kind=text }] }\n\n##|(markdown) intro\nHi\n|##\n`;
162
189
  const reason = await refused(source, (d) => {
163
190
  d.imports.push({ kind: "names", names: ["x"], from: "../m.malloy" });
164
191
  });
@@ -1033,6 +1033,31 @@ source: a is one extend {
1033
1033
  expect(removed).toContain(" dimension: brand is products.brand");
1034
1034
  });
1035
1035
 
1036
+ it("writes a path target quoted, and it reads back as the same path", async () => {
1037
+ for (const to of ["sales/overview", "overview-story"]) {
1038
+ const out = await spliced(WITH_DIMENSION, (d) => {
1039
+ d.drills = [{ ...(d.drills ?? [])[0], to: [to] }];
1040
+ });
1041
+ expect(out).toContain(
1042
+ ` # drill { to="${to}" given=BRAND }\n dimension: brand is products.brand`,
1043
+ );
1044
+ const reread = await readDashboardDocument(out);
1045
+ if (readFailed(reread)) throw new Error(reread.reason);
1046
+ expect(reread.document.drills?.[0].to).toEqual([to]);
1047
+ }
1048
+ });
1049
+
1050
+ it("escapes a quote or backslash in a target, so it reads back unchanged", async () => {
1051
+ for (const to of [[`odd "name"`], ["back\\slash/x"], [`a"b`, "c\\d"]]) {
1052
+ const out = await spliced(WITH_DIMENSION, (d) => {
1053
+ d.drills = [{ ...(d.drills ?? [])[0], to }];
1054
+ });
1055
+ const reread = await readDashboardDocument(out);
1056
+ if (readFailed(reread)) throw new Error(reread.reason);
1057
+ expect(reread.document.drills?.[0].to).toEqual(to);
1058
+ }
1059
+ });
1060
+
1036
1061
  it("refuses a drill on a dimension the model declares", async () => {
1037
1062
  const r = await splice(WITH_DIMENSION, (d) => {
1038
1063
  d.drills = [
@@ -1126,7 +1151,7 @@ describe("spliceDashboardDocument: the page's own settings", () => {
1126
1151
  });
1127
1152
 
1128
1153
  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}`;
1154
+ const NB = `##" Old\n## artifact { layout=linear title="T" tiles=["a -> x"] }\nimport "../m.malloy"\n\nsource: a is one extend {\n view: x is vx\n}`;
1130
1155
 
1131
1156
  it("writes one line for a one-line description, however it ends", async () => {
1132
1157
  for (const description of [
@@ -1561,6 +1586,7 @@ describe("spliceDashboardDocument: what it refuses", () => {
1561
1586
 
1562
1587
  it("refuses to edit a file that will not open", async () => {
1563
1588
  const r = await spliceDashboardDocument("not malloy at all", {
1589
+ layout: "grid",
1564
1590
  title: "x",
1565
1591
  imports: [],
1566
1592
  sources: [],
@@ -1633,7 +1659,7 @@ function unmodelledTagsByDeclaration(text: string): Record<string, string[]> {
1633
1659
  return out;
1634
1660
  }
1635
1661
 
1636
- describe("every composite dashboard survives an edit", () => {
1662
+ describe("every not a report survives an edit", () => {
1637
1663
  const found: string[] = [];
1638
1664
  const walk = (dir: string) => {
1639
1665
  if (!fs.existsSync(dir)) return;
@@ -1650,7 +1676,10 @@ describe("every composite dashboard survives an edit", () => {
1650
1676
  const editable = found.filter((f) => {
1651
1677
  const text = fs.readFileSync(f, "utf8");
1652
1678
  return (
1653
- /##\s*artifact[\s\S]*tiles\s*=/.test(text) && !/-lint[\\/]/.test(f)
1679
+ /##\s*artifact[\s\S]*tiles\s*=/.test(text) &&
1680
+ !/-lint[\\/]/.test(f) &&
1681
+ // A report whose one tile is a named query is not one the builder edits.
1682
+ !/tiles=\["[A-Za-z_]\w*"\]/.test(text)
1654
1683
  );
1655
1684
  });
1656
1685