@malloy-publisher/sdk 0.9.6 → 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-BUb2Xvr2.es.js → RenderedResult-DZj-FnOJ.es.js} +2 -2
  4. package/dist/{ServerProvider-C6QQVKPm.es.js → ServerProvider-B_bPAsu2.es.js} +595 -410
  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 +489 -111
  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-0sxonf6N.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 +6 -4
  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
@@ -13,6 +13,7 @@ import {
13
13
  createDocument,
14
14
  createRoute,
15
15
  MAX_SLUG_ATTEMPTS,
16
+ reportPathProblem,
16
17
  } from "./createDocument";
17
18
 
18
19
  const WORKSPACE: Workspace = {
@@ -29,17 +30,18 @@ const DOC = {
29
30
  view: "by_category",
30
31
  };
31
32
 
32
- /** A store whose `saveDocument` replaces what is there, like the interface says. */
33
+ /** A store keyed by path whose `saveDocument` replaces what is there, like the interface says. */
33
34
  class FakeStorage implements DocumentStorage {
34
35
  readonly files = new Map<string, string>();
36
+ readonly layouts = new Map<string, DocumentType>();
35
37
  readonly saves: string[] = [];
36
38
  /** What `listDocuments` reports; defaults to the files, a stale test sets it. */
37
39
  listing?: string[];
38
40
  getFailure?: Error;
39
41
 
40
- private key = (l: DocumentLocator) => `${l.type}:${l.path}`;
41
- seed(type: DocumentType, path: string, content = "original") {
42
- this.files.set(`${type}:${path}`, content);
42
+ seed(path: string, content = "original", layout: DocumentType = "grid") {
43
+ this.files.set(path, content);
44
+ this.layouts.set(path, layout);
43
45
  }
44
46
  async listWorkspaces() {
45
47
  return [WORKSPACE];
@@ -47,24 +49,25 @@ class FakeStorage implements DocumentStorage {
47
49
  async listDocuments(_w: Workspace, type?: DocumentType) {
48
50
  const paths =
49
51
  this.listing ??
50
- [...this.files.keys()]
51
- .filter((k) => type === undefined || k.startsWith(`${type}:`))
52
- .map((k) => k.slice(k.indexOf(":") + 1));
52
+ [...this.files.keys()].filter(
53
+ (path) => type === undefined || this.layouts.get(path) === type,
54
+ );
53
55
  return paths.map((path) => ({
54
56
  workspace: WORKSPACE.name,
55
- type: type ?? "dashboard",
57
+ type: this.layouts.get(path) ?? "grid",
56
58
  path,
57
59
  }));
58
60
  }
59
61
  async getDocument(locator: DocumentLocator) {
60
62
  if (this.getFailure) throw this.getFailure;
61
- const text = this.files.get(this.key(locator));
63
+ const text = this.files.get(locator.path);
62
64
  if (text === undefined) throw new DocumentNotFoundError("absent");
63
65
  return text;
64
66
  }
65
67
  async saveDocument(locator: DocumentLocator, content: string) {
66
68
  this.saves.push(locator.path);
67
- this.files.set(this.key(locator), content);
69
+ this.files.set(locator.path, content);
70
+ this.layouts.set(locator.path, locator.type);
68
71
  }
69
72
  async deleteDocument() {}
70
73
  async moveDocument() {}
@@ -85,56 +88,57 @@ describe("createDocument on the storage route", () => {
85
88
  const created: unknown[] = [];
86
89
  const events: unknown[] = [];
87
90
  const result = await createDocument({
88
- kind: "notebook",
91
+ layout: "linear",
89
92
  document: DOC,
90
93
  target: target(storage),
91
94
  onCreated: (c) => created.push(c),
92
95
  onEvent: (e) => events.push(e),
93
96
  });
94
- expect(result.path).toBe("notebooks/sales.malloy");
97
+ expect(result.path).toBe("sales.malloy");
95
98
  expect(result.slug).toBe("sales");
96
99
  expect(result.locator).toEqual({
97
100
  workspace: "record",
98
- type: "notebook",
99
- path: "env/pkg/notebooks/sales.malloy",
101
+ type: "linear",
102
+ path: "env/pkg/sales.malloy",
100
103
  });
101
- expect(storage.saves).toEqual(["env/pkg/notebooks/sales.malloy"]);
104
+ expect(storage.saves).toEqual(["env/pkg/sales.malloy"]);
102
105
  expect(created).toEqual([result]);
103
- expect(events).toEqual([{ type: "notebook.created", where: "host" }]);
106
+ expect(events).toMatchObject([
107
+ {
108
+ type: "report.created",
109
+ where: "host",
110
+ path: "sales.malloy",
111
+ layout: "linear",
112
+ },
113
+ ]);
104
114
  });
105
115
 
106
116
  it("takes the next name when the listing shows the slug", async () => {
107
117
  const storage = new FakeStorage();
108
- storage.seed("dashboard", "env/pkg/dashboards/sales.malloy");
118
+ storage.seed("env/pkg/sales.malloy");
109
119
  const result = await createDocument({
110
- kind: "dashboard",
120
+ layout: "grid",
111
121
  document: DOC,
112
122
  target: target(storage),
113
123
  });
114
124
  expect(result.slug).toBe("sales-2");
115
- expect(
116
- storage.files.get("dashboard:env/pkg/dashboards/sales.malloy"),
117
- ).toBe("original");
125
+ expect(storage.files.get("env/pkg/sales.malloy")).toBe("original");
118
126
  });
119
127
 
120
128
  it("never overwrites a file a stale listing misses", async () => {
121
129
  const storage = new FakeStorage();
122
- storage.seed("dashboard", "env/pkg/dashboards/sales.malloy");
123
- storage.seed("dashboard", "env/pkg/dashboards/sales-2.malloy", "two");
130
+ storage.seed("env/pkg/sales.malloy");
131
+ storage.seed("env/pkg/sales-2.malloy", "two");
124
132
  storage.listing = [];
125
133
  const result = await createDocument({
126
- kind: "dashboard",
134
+ layout: "grid",
127
135
  document: DOC,
128
136
  target: target(storage),
129
137
  });
130
138
  expect(result.slug).toBe("sales-3");
131
- expect(storage.saves).toEqual(["env/pkg/dashboards/sales-3.malloy"]);
132
- expect(
133
- storage.files.get("dashboard:env/pkg/dashboards/sales.malloy"),
134
- ).toBe("original");
135
- expect(
136
- storage.files.get("dashboard:env/pkg/dashboards/sales-2.malloy"),
137
- ).toBe("two");
139
+ expect(storage.saves).toEqual(["env/pkg/sales-3.malloy"]);
140
+ expect(storage.files.get("env/pkg/sales.malloy")).toBe("original");
141
+ expect(storage.files.get("env/pkg/sales-2.malloy")).toBe("two");
138
142
  });
139
143
 
140
144
  it("aborts, saving nothing, when the read fails for any reason but absence", async () => {
@@ -142,7 +146,7 @@ describe("createDocument on the storage route", () => {
142
146
  storage.getFailure = new Error("backend down");
143
147
  await expect(
144
148
  createDocument({
145
- kind: "dashboard",
149
+ layout: "grid",
146
150
  document: DOC,
147
151
  target: target(storage),
148
152
  }),
@@ -153,12 +157,12 @@ describe("createDocument on the storage route", () => {
153
157
  it("gives up after the attempt cap rather than looping", async () => {
154
158
  const storage = new FakeStorage();
155
159
  storage.listing = [];
156
- storage.seed("dashboard", "env/pkg/dashboards/sales.malloy");
160
+ storage.seed("env/pkg/sales.malloy");
157
161
  for (let n = 2; n <= MAX_SLUG_ATTEMPTS; n++)
158
- storage.seed("dashboard", `env/pkg/dashboards/sales-${n}.malloy`);
162
+ storage.seed(`env/pkg/sales-${n}.malloy`);
159
163
  await expect(
160
164
  createDocument({
161
- kind: "dashboard",
165
+ layout: "grid",
162
166
  document: DOC,
163
167
  target: target(storage),
164
168
  }),
@@ -171,7 +175,7 @@ describe("createDocument on the storage route", () => {
171
175
  for (const title of ["a\nb", "x ##(authorize) y", " "]) {
172
176
  await expect(
173
177
  createDocument({
174
- kind: "notebook",
178
+ layout: "linear",
175
179
  document: { ...DOC, title },
176
180
  target: target(storage),
177
181
  }),
@@ -186,11 +190,11 @@ describe("createDocument on the package route", () => {
186
190
  const writes: Array<[string, string]> = [];
187
191
  const events: unknown[] = [];
188
192
  const result = await createDocument({
189
- kind: "dashboard",
193
+ layout: "grid",
190
194
  document: DOC,
191
195
  target: {
192
196
  route: "package",
193
- existing: ["dashboards/sales.malloy", "notebooks/sales.malloy"],
197
+ existing: ["sales.malloy", "other/sales.malloy"],
194
198
  write: async (path, source) => {
195
199
  writes.push([path, source]);
196
200
  },
@@ -198,20 +202,27 @@ describe("createDocument on the package route", () => {
198
202
  onEvent: (e) => events.push(e),
199
203
  });
200
204
  expect(result).toEqual({
201
- kind: "dashboard",
202
- path: "dashboards/sales-2.malloy",
205
+ layout: "grid",
206
+ path: "sales-2.malloy",
203
207
  slug: "sales-2",
204
208
  });
205
- expect(writes.map(([p]) => p)).toEqual(["dashboards/sales-2.malloy"]);
206
- expect(writes[0][1]).toContain("## artifact");
207
- expect(events).toEqual([{ type: "dashboard.created", where: "package" }]);
209
+ expect(writes.map(([p]) => p)).toEqual(["sales-2.malloy"]);
210
+ expect(writes[0][1]).toContain("##| artifact { layout=grid");
211
+ expect(events).toMatchObject([
212
+ {
213
+ type: "report.created",
214
+ where: "package",
215
+ path: "sales-2.malloy",
216
+ layout: "grid",
217
+ },
218
+ ]);
208
219
  });
209
220
 
210
- it("does not report a create the server refused", async () => {
221
+ it("reports a create the server refused as refused, never as created", async () => {
211
222
  const events: unknown[] = [];
212
223
  await expect(
213
224
  createDocument({
214
- kind: "notebook",
225
+ layout: "linear",
215
226
  document: DOC,
216
227
  target: {
217
228
  route: "package",
@@ -223,7 +234,14 @@ describe("createDocument on the package route", () => {
223
234
  onEvent: (e) => events.push(e),
224
235
  }),
225
236
  ).rejects.toThrow("409");
226
- expect(events).toEqual([]);
237
+ expect(events).toEqual([
238
+ {
239
+ type: "report.create_refused",
240
+ reason: "409",
241
+ path: "",
242
+ layout: "linear",
243
+ },
244
+ ]);
227
245
  });
228
246
  });
229
247
 
@@ -231,11 +249,11 @@ describe("createDocument names", () => {
231
249
  it("on the storage route, skips a path the package listing has", async () => {
232
250
  const storage = new FakeStorage();
233
251
  const result = await createDocument({
234
- kind: "dashboard",
252
+ layout: "grid",
235
253
  document: DOC,
236
254
  target: {
237
255
  ...target(storage),
238
- existing: ["dashboards/sales.malloy"],
256
+ existing: ["sales.malloy"],
239
257
  },
240
258
  });
241
259
  expect(result.slug).toBe("sales-2");
@@ -244,7 +262,7 @@ describe("createDocument names", () => {
244
262
  it("on the package route, moves to the next name when the server answers 409", async () => {
245
263
  const tried: string[] = [];
246
264
  const result = await createDocument({
247
- kind: "dashboard",
265
+ layout: "grid",
248
266
  document: DOC,
249
267
  target: {
250
268
  route: "package",
@@ -259,9 +277,9 @@ describe("createDocument names", () => {
259
277
  },
260
278
  });
261
279
  expect(tried).toEqual([
262
- "dashboards/sales.malloy",
263
- "dashboards/sales-2.malloy",
264
- "dashboards/sales-3.malloy",
280
+ "sales.malloy",
281
+ "sales-2.malloy",
282
+ "sales-3.malloy",
265
283
  ]);
266
284
  expect(result.slug).toBe("sales-3");
267
285
  });
@@ -270,7 +288,7 @@ describe("createDocument names", () => {
270
288
  let writes = 0;
271
289
  await expect(
272
290
  createDocument({
273
- kind: "dashboard",
291
+ layout: "grid",
274
292
  document: DOC,
275
293
  target: {
276
294
  route: "package",
@@ -308,3 +326,278 @@ describe("createRoute", () => {
308
326
  ).toBeUndefined();
309
327
  });
310
328
  });
329
+
330
+ describe("createDocument at a path", () => {
331
+ const write = () => {
332
+ const writes: Array<[string, string]> = [];
333
+ return {
334
+ writes,
335
+ target: {
336
+ route: "package" as const,
337
+ existing: ["taken.malloy"],
338
+ write: async (path: string, source: string) => {
339
+ writes.push([path, source]);
340
+ },
341
+ },
342
+ };
343
+ };
344
+
345
+ it("writes `<slug>.malloy` at the package root, importing the model beside it", async () => {
346
+ const { writes, target: t } = write();
347
+ const result = await createDocument({
348
+ layout: "linear",
349
+ document: { ...DOC, modelPath: "storefront.malloy" },
350
+ target: t,
351
+ });
352
+ expect(result).toEqual({
353
+ layout: "linear",
354
+ path: "sales.malloy",
355
+ slug: "sales",
356
+ });
357
+ expect(writes[0][1]).toContain(
358
+ 'import { order_items } from "storefront.malloy"',
359
+ );
360
+ expect(writes[0][1]).toContain("layout=linear");
361
+ expect(writes[0][1]).not.toContain("kind=notebook");
362
+ });
363
+
364
+ it("defaults to a linear report", async () => {
365
+ const { target: t } = write();
366
+ const result = await createDocument({ document: DOC, target: t });
367
+ expect(result.layout).toBe("linear");
368
+ });
369
+
370
+ it("writes at a nested path, with the import relative to it", async () => {
371
+ const { writes, target: t } = write();
372
+ const result = await createDocument({
373
+ layout: "grid",
374
+ path: "team/sales.malloy",
375
+ document: { ...DOC, modelPath: "m.malloy" },
376
+ target: t,
377
+ });
378
+ expect(result.path).toBe("team/sales.malloy");
379
+ expect(result.slug).toBe("sales");
380
+ expect(writes[0][0]).toBe("team/sales.malloy");
381
+ expect(writes[0][1]).toContain('from "../m.malloy"');
382
+ expect(writes[0][1]).toContain("layout=grid");
383
+ });
384
+
385
+ it("puts a title-named file in a directory", async () => {
386
+ const { writes, target: t } = write();
387
+ await createDocument({
388
+ directory: "/team/",
389
+ document: DOC,
390
+ target: t,
391
+ });
392
+ expect(writes[0][0]).toBe("team/sales.malloy");
393
+ });
394
+
395
+ it("refuses a taken path rather than renaming it", async () => {
396
+ const { writes, target: t } = write();
397
+ await expect(
398
+ createDocument({ path: "taken.malloy", document: DOC, target: t }),
399
+ ).rejects.toThrow("taken.malloy already exists");
400
+ expect(writes).toEqual([]);
401
+ });
402
+
403
+ it("refuses a path the server answers 409 for, once", async () => {
404
+ const tried: string[] = [];
405
+ await expect(
406
+ createDocument({
407
+ path: "x.malloy",
408
+ document: DOC,
409
+ target: {
410
+ route: "package",
411
+ existing: [],
412
+ write: async (path) => {
413
+ tried.push(path);
414
+ throw Object.assign(new Error("exists"), {
415
+ response: { status: 409 },
416
+ });
417
+ },
418
+ },
419
+ }),
420
+ ).rejects.toThrow("already exists");
421
+ expect(tried).toEqual(["x.malloy"]);
422
+ });
423
+
424
+ it("refuses a path a report cannot live at, before writing", async () => {
425
+ for (const path of [
426
+ "public/x.malloy",
427
+ "index.malloy",
428
+ "../x.malloy",
429
+ "a/../x.malloy",
430
+ "/x.malloy",
431
+ "x.txt",
432
+ "x",
433
+ "dir/.malloy",
434
+ ]) {
435
+ const { writes, target: t } = write();
436
+ await expect(
437
+ createDocument({ path, document: DOC, target: t }),
438
+ ).rejects.toThrow();
439
+ expect(writes).toEqual([]);
440
+ }
441
+ });
442
+ });
443
+
444
+ describe("createDocument in a directory", () => {
445
+ const BAD_DIRECTORIES = [
446
+ "../x",
447
+ "a/../../x",
448
+ "public",
449
+ "Public/reports",
450
+ "./x",
451
+ ];
452
+
453
+ it("refuses a directory a report cannot live in, before the package is written", async () => {
454
+ for (const directory of BAD_DIRECTORIES) {
455
+ const writes: string[] = [];
456
+ await expect(
457
+ createDocument({
458
+ directory,
459
+ document: DOC,
460
+ target: {
461
+ route: "package",
462
+ existing: [],
463
+ write: async (path) => {
464
+ writes.push(path);
465
+ },
466
+ },
467
+ }),
468
+ ).rejects.toThrow();
469
+ expect(writes).toEqual([]);
470
+ }
471
+ });
472
+
473
+ it("refuses it before the store is asked anything", async () => {
474
+ for (const directory of BAD_DIRECTORIES) {
475
+ const storage = new FakeStorage();
476
+ let asked = 0;
477
+ storage.listDocuments = async () => {
478
+ asked++;
479
+ return [];
480
+ };
481
+ storage.getDocument = async () => {
482
+ asked++;
483
+ throw new DocumentNotFoundError("absent");
484
+ };
485
+ await expect(
486
+ createDocument({
487
+ directory,
488
+ document: DOC,
489
+ target: target(storage),
490
+ }),
491
+ ).rejects.toThrow();
492
+ expect(asked).toBe(0);
493
+ expect(storage.saves).toEqual([]);
494
+ }
495
+ });
496
+
497
+ it("still writes into a directory that is fine", async () => {
498
+ const writes: string[] = [];
499
+ const created = await createDocument({
500
+ directory: "team/q3",
501
+ document: DOC,
502
+ target: {
503
+ route: "package",
504
+ existing: [],
505
+ write: async (path) => {
506
+ writes.push(path);
507
+ },
508
+ },
509
+ });
510
+ expect(created.path).toBe("team/q3/sales.malloy");
511
+ expect(writes).toEqual(["team/q3/sales.malloy"]);
512
+ });
513
+ });
514
+
515
+ describe("reportPathProblem", () => {
516
+ it("accepts a path anywhere in the package outside public/", () => {
517
+ for (const path of [
518
+ "x.malloy",
519
+ "sales/q3.malloy",
520
+ "dashboards/x.malloy",
521
+ "notebooks/a/b.malloy",
522
+ "sub/index.malloy",
523
+ ])
524
+ expect(reportPathProblem(path)).toBeUndefined();
525
+ });
526
+
527
+ it("names why a path is refused", () => {
528
+ expect(reportPathProblem("public/x.malloy")).toContain("public/");
529
+ // On a case-insensitive file system these land in public/ too.
530
+ expect(reportPathProblem("Public/x.malloy")).toContain("public/");
531
+ expect(reportPathProblem("PUBLIC/a/x.malloy")).toContain("public/");
532
+ expect(reportPathProblem("publications/x.malloy")).toBeUndefined();
533
+ expect(reportPathProblem("index.malloy")).toContain("index.malloy");
534
+ // As the server refuses it: on a case-insensitive file system it is the surface.
535
+ expect(reportPathProblem("Index.malloy")).toContain("index.malloy");
536
+ expect(reportPathProblem("sales/Index.malloy")).toBeUndefined();
537
+ expect(reportPathProblem("../x.malloy")).toContain("inside the package");
538
+ expect(reportPathProblem("x.malloynb")).toContain(".malloy");
539
+ });
540
+ });
541
+
542
+ /**
543
+ * A host store that files documents by layout, as a host may:
544
+ * whatever path the locator asks for, the file lands in `dashboards/` or
545
+ * `notebooks/` under its basename.
546
+ */
547
+ class RelocatingStorage extends FakeStorage {
548
+ readonly written = new Map<string, string>();
549
+ relocate = (locator: DocumentLocator) => {
550
+ const base = locator.path.slice(locator.path.lastIndexOf("/") + 1);
551
+ return `${locator.type === "grid" ? "dashboards" : "notebooks"}/${base}`;
552
+ };
553
+ resolveDocumentPath(locator: DocumentLocator) {
554
+ return this.relocate(locator);
555
+ }
556
+ async saveDocument(locator: DocumentLocator, content: string) {
557
+ await super.saveDocument(locator, content);
558
+ this.written.set(this.relocate(locator), content);
559
+ }
560
+ }
561
+
562
+ describe("createDocument into a store that chooses the file's place", () => {
563
+ it("writes the import for where the store puts the file, and returns that path", async () => {
564
+ const storage = new RelocatingStorage();
565
+ const created = await createDocument({
566
+ layout: "grid",
567
+ document: DOC,
568
+ target: target(storage),
569
+ });
570
+ expect(created.path).toBe("dashboards/sales.malloy");
571
+ expect(created.slug).toBe("sales");
572
+ const text = storage.written.get("dashboards/sales.malloy")!;
573
+ expect(text).toContain(
574
+ 'import { order_items } from "../models/storefront.malloy"',
575
+ );
576
+ });
577
+
578
+ it("skips a name whose real place the package already has", async () => {
579
+ const storage = new RelocatingStorage();
580
+ const created = await createDocument({
581
+ layout: "linear",
582
+ document: DOC,
583
+ target: {
584
+ ...target(storage),
585
+ existing: ["notebooks/sales.malloy"],
586
+ },
587
+ });
588
+ expect(created.path).toBe("notebooks/sales-2.malloy");
589
+ });
590
+
591
+ it("falls back to the requested path for a store that says nothing", async () => {
592
+ const storage = new FakeStorage();
593
+ const created = await createDocument({
594
+ layout: "grid",
595
+ document: DOC,
596
+ target: target(storage),
597
+ });
598
+ expect(created.path).toBe("sales.malloy");
599
+ expect(storage.files.get("env/pkg/sales.malloy")).toContain(
600
+ 'from "models/storefront.malloy"',
601
+ );
602
+ });
603
+ });