@malloy-publisher/sdk 0.9.1 → 0.9.3
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.
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-DwB0-9Yx.es.js} +219 -210
- package/dist/RenderedResult-hKjFEqaN.cjs.js +141 -0
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-CcSrGaRN.es.js} +1473 -1326
- package/dist/ServerProvider-Gbf1YPOP.cjs.js +1 -0
- package/dist/builder/index.cjs.js +143 -58
- package/dist/builder/index.es.js +12179 -9318
- package/dist/builder-entry.d.ts +5 -1
- package/dist/client/api.d.ts +247 -56
- package/dist/client/configuration.d.ts +1 -1
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.es.js +94 -88
- package/dist/client-entry.d.ts +2 -0
- package/dist/components/ApiErrorDisplay.d.ts +11 -0
- package/dist/components/AppDialog.d.ts +6 -6
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +38 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +21 -2
- package/dist/components/Dashboard/DashboardView.d.ts +71 -0
- package/dist/components/Dashboard/TileCard.d.ts +30 -5
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/dropValueUrlTags.d.ts +6 -0
- package/dist/components/Dashboard/index.d.ts +5 -1
- package/dist/components/Dashboard/telemetry.d.ts +16 -3
- package/dist/components/Dashboard/textSource.d.ts +19 -0
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +15 -9
- package/dist/components/DashboardBuilder/BuilderDialogs.d.ts +25 -0
- package/dist/components/DashboardBuilder/BuilderGrid.d.ts +31 -0
- package/dist/components/DashboardBuilder/BuilderHeader.d.ts +17 -0
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +23 -15
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +31 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +56 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +44 -5
- package/dist/components/DashboardBuilder/EditorSurface.d.ts +33 -0
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +8 -4
- package/dist/components/DashboardBuilder/InlineMarkdown.d.ts +18 -0
- package/dist/components/DashboardBuilder/InlineText.d.ts +19 -0
- package/dist/components/DashboardBuilder/NotebookEditor.d.ts +15 -0
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +10 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +51 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +12 -6
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/builderReport.d.ts +13 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -18
- package/dist/components/DashboardBuilder/changedTile.d.ts +7 -0
- package/dist/components/DashboardBuilder/chartLine.d.ts +33 -0
- package/dist/components/DashboardBuilder/controls.d.ts +2 -2
- package/dist/components/DashboardBuilder/document.d.ts +42 -26
- package/dist/components/DashboardBuilder/documentSession.d.ts +100 -0
- package/dist/components/DashboardBuilder/imports.d.ts +19 -0
- package/dist/components/DashboardBuilder/inlineEdit.d.ts +18 -0
- package/dist/components/DashboardBuilder/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyTree.d.ts +119 -0
- package/dist/components/DashboardBuilder/newDashboard.d.ts +3 -1
- package/dist/components/DashboardBuilder/openDraft.d.ts +10 -0
- package/dist/components/DashboardBuilder/preview.d.ts +24 -4
- package/dist/components/DashboardBuilder/readDocument.d.ts +6 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +16 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +15 -13
- package/dist/components/DashboardBuilder/spliceResult.d.ts +11 -0
- package/dist/components/DashboardBuilder/tagParse.d.ts +24 -0
- package/dist/components/DashboardBuilder/telemetry.d.ts +43 -0
- package/dist/components/DashboardBuilder/testing/fixtures.d.ts +3 -1
- package/dist/components/DashboardBuilder/testing/inline.d.ts +4 -0
- package/dist/components/DashboardBuilder/testing/resize.d.ts +7 -0
- package/dist/components/DashboardBuilder/tileDisplayTitle.d.ts +7 -0
- package/dist/components/DashboardBuilder/useBuilderSelection.d.ts +53 -0
- package/dist/components/DashboardBuilder/useBuilderSession.d.ts +86 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useControlBindings.d.ts +30 -0
- package/dist/components/DashboardBuilder/useConversionConfirm.d.ts +20 -0
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +19 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useDraft.d.ts +3 -1
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -3
- package/dist/components/DashboardBuilder/useHostCopy.d.ts +26 -0
- package/dist/components/DashboardBuilder/useOpenDraftCommit.d.ts +17 -0
- package/dist/components/DashboardBuilder/useOpenedDocument.d.ts +71 -0
- package/dist/components/DashboardBuilder/useSaveChannel.d.ts +50 -0
- package/dist/components/DashboardBuilder/useTileEditing.d.ts +33 -0
- package/dist/components/DashboardBuilder/useTileResize.d.ts +6 -3
- package/dist/components/DocumentCreate/canRetry.d.ts +6 -0
- package/dist/components/DocumentCreate/createDocument.d.ts +58 -0
- package/dist/components/DocumentCreate/documentPath.d.ts +10 -0
- package/dist/components/DocumentCreate/events.d.ts +10 -0
- package/dist/components/DocumentCreate/exportedSources.d.ts +7 -0
- package/dist/components/DocumentCreate/guards.d.ts +12 -0
- package/dist/components/DocumentCreate/index.d.ts +6 -0
- package/dist/components/DocumentCreate/newNotebook.d.ts +9 -0
- package/dist/components/DocumentCreate/useDocumentChoices.d.ts +32 -0
- package/dist/components/DocumentStorage/DocumentStorage.d.ts +2 -1
- package/dist/components/Loading.d.ts +13 -0
- package/dist/components/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Notebook/NotebookCell.d.ts +1 -5
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +17 -1
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +5 -1
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- package/dist/components/Prose.d.ts +1 -1
- package/dist/components/RenderedResult/RenderedResult.d.ts +2 -0
- package/dist/components/RenderedResult/ResultContainer.d.ts +8 -1
- package/dist/components/RenderedResult/ResultPanel.d.ts +3 -1
- package/dist/components/RenderedResult/loadRenderer.d.ts +7 -0
- package/dist/components/RenderedResult/resultSizing.d.ts +9 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/UnsavedChangesDialog.d.ts +9 -0
- package/dist/components/given/GivensPanel.d.ts +2 -2
- package/dist/components/given/paramCodec.d.ts +8 -1
- package/dist/components/index.d.ts +3 -2
- package/dist/components/styles.d.ts +4 -4
- package/dist/hooks/givenValue.d.ts +6 -0
- package/dist/hooks/index.d.ts +2 -0
- package/dist/hooks/useCompiledDocument.d.ts +23 -0
- package/dist/hooks/useDocumentControls.d.ts +6 -1
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useNearViewport.d.ts +16 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useQueryWithApiError.d.ts +7 -2
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/hooks/useSuggestOptions.d.ts +9 -2
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9041 -7002
- package/dist/text/index.cjs.js +1 -0
- package/dist/text/index.d.ts +2 -0
- package/dist/text/index.es.js +6 -0
- package/dist/text-entry-BJwltZiy.cjs.js +7 -0
- package/dist/text-entry-CA0LZ1xL.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/theme/accent.d.ts +29 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +3 -3
- package/dist/theme/index.d.ts +3 -0
- package/dist/theme/keys.d.ts +1 -1
- package/dist/theme/motion.d.ts +31 -0
- package/dist/theme/readChartAnnotations.d.ts +1 -1
- package/dist/theme/resolveTheme.d.ts +4 -4
- package/dist/theme/types.d.ts +33 -5
- package/dist/{Dashboard-H1kJlDFo.es.js → useCompiledDocument-BU6d8FPp.es.js} +17904 -19057
- package/dist/useCompiledDocument-pOg2W-Yt.cjs.js +142 -0
- package/dist/utils/clock.d.ts +2 -0
- package/dist/utils/malloyText.d.ts +104 -0
- package/package.json +20 -11
- package/src/builder-entry.ts +36 -0
- package/src/client-entry.ts +8 -0
- package/src/clientEntry.spec.ts +17 -0
- package/src/components/ApiErrorDisplay.tsx +37 -18
- package/src/components/AppDialog.tsx +8 -7
- package/src/components/Dashboard/Dashboard.spec.tsx +3 -32
- package/src/components/Dashboard/Dashboard.tsx +29 -280
- package/src/components/Dashboard/DashboardGrid.tsx +87 -8
- package/src/components/Dashboard/DashboardTile.spec.tsx +121 -2
- package/src/components/Dashboard/DashboardTile.tsx +121 -30
- package/src/components/Dashboard/DashboardView.spec.tsx +368 -0
- package/src/components/Dashboard/DashboardView.tsx +428 -0
- package/src/components/Dashboard/RowsDialog.tsx +4 -3
- package/src/components/Dashboard/TileCard.tsx +60 -11
- package/src/components/Dashboard/TileFilterTag.spec.tsx +73 -0
- package/src/components/Dashboard/TileFilterTag.tsx +78 -0
- package/src/components/Dashboard/defaultTileSpan.spec.ts +32 -0
- package/src/components/Dashboard/dropValueUrlTags.spec.ts +177 -0
- package/src/components/Dashboard/dropValueUrlTags.ts +108 -0
- package/src/components/Dashboard/index.ts +13 -1
- package/src/components/Dashboard/telemetry.ts +17 -5
- package/src/components/Dashboard/textSource.spec.ts +36 -0
- package/src/components/Dashboard/textSource.ts +39 -0
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +124 -138
- package/src/components/DashboardBuilder/BuilderDialogs.tsx +162 -0
- package/src/components/DashboardBuilder/BuilderGrid.tsx +245 -0
- package/src/components/DashboardBuilder/BuilderHeader.tsx +107 -0
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +111 -80
- package/src/components/DashboardBuilder/ChartPicker.render.spec.tsx +25 -0
- package/src/components/DashboardBuilder/ChartPicker.spec.ts +77 -0
- package/src/components/DashboardBuilder/ChartPicker.tsx +156 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +183 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +373 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +310 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +105 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +117 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +146 -108
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +179 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +330 -512
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +55 -25
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +142 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +310 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +39 -13
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +9 -26
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +102 -25
- package/src/components/DashboardBuilder/DashboardEditor.textSource.spec.tsx +317 -0
- package/src/components/DashboardBuilder/DashboardEditor.tsx +252 -780
- package/src/components/DashboardBuilder/DrillDialog.tsx +2 -2
- package/src/components/DashboardBuilder/EditorSurface.tsx +471 -0
- package/src/components/DashboardBuilder/FilterDialog.tsx +23 -11
- package/src/components/DashboardBuilder/FilterStrip.tsx +130 -70
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +182 -0
- package/src/components/DashboardBuilder/InlineText.tsx +112 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +31 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +302 -163
- package/src/components/DashboardBuilder/TileMenu.tsx +125 -97
- package/src/components/DashboardBuilder/annotationText.spec.ts +33 -0
- package/src/components/DashboardBuilder/annotationText.ts +17 -0
- package/src/components/DashboardBuilder/artifactBlock.spec.ts +248 -0
- package/src/components/DashboardBuilder/artifactTagParity.spec.ts +46 -0
- package/src/components/DashboardBuilder/builderReport.ts +74 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -44
- package/src/components/DashboardBuilder/catalog.ts +61 -57
- package/src/components/DashboardBuilder/changedTile.spec.ts +46 -0
- package/src/components/DashboardBuilder/changedTile.ts +28 -0
- package/src/components/DashboardBuilder/chartLine.spec.ts +180 -0
- package/src/components/DashboardBuilder/chartLine.ts +121 -0
- package/src/components/DashboardBuilder/controls.spec.ts +21 -10
- package/src/components/DashboardBuilder/controls.ts +22 -8
- package/src/components/DashboardBuilder/document.ts +53 -5
- package/src/components/DashboardBuilder/documentSession.spec.ts +209 -0
- package/src/components/DashboardBuilder/documentSession.ts +258 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -0
- package/src/components/DashboardBuilder/imports.spec.ts +61 -0
- package/src/components/DashboardBuilder/imports.ts +93 -0
- package/src/components/DashboardBuilder/inlineEdit.tsx +78 -0
- package/src/components/DashboardBuilder/invariants.spec.ts +6 -2
- package/src/components/DashboardBuilder/legacyNotebook.chart.spec.ts +77 -0
- package/src/components/DashboardBuilder/legacyNotebook.convert.spec.ts +630 -0
- package/src/components/DashboardBuilder/legacyNotebook.read.spec.ts +338 -0
- package/src/components/DashboardBuilder/legacyNotebook.ts +1117 -0
- package/src/components/DashboardBuilder/loadMalloy.spec.ts +80 -0
- package/src/components/DashboardBuilder/loadMalloy.ts +39 -0
- package/src/components/DashboardBuilder/malloyTree.ts +159 -7
- package/src/components/DashboardBuilder/newDashboard.spec.ts +46 -2
- package/src/components/DashboardBuilder/newDashboard.ts +30 -3
- package/src/components/DashboardBuilder/openDraft.ts +52 -0
- package/src/components/DashboardBuilder/preview.shapes.spec.ts +75 -0
- package/src/components/DashboardBuilder/preview.spec.ts +159 -12
- package/src/components/DashboardBuilder/preview.ts +83 -9
- package/src/components/DashboardBuilder/readDocument.spec.ts +174 -26
- package/src/components/DashboardBuilder/readDocument.ts +137 -45
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +52 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +89 -0
- package/src/components/DashboardBuilder/sortable.tsx +11 -10
- package/src/components/DashboardBuilder/spliceDocument.chart.spec.ts +340 -0
- package/src/components/DashboardBuilder/spliceDocument.imports.spec.ts +167 -0
- package/src/components/DashboardBuilder/spliceDocument.spec.ts +229 -94
- package/src/components/DashboardBuilder/spliceDocument.ts +768 -131
- package/src/components/DashboardBuilder/spliceResult.ts +15 -0
- package/src/components/DashboardBuilder/statementExtent.spec.ts +33 -30
- package/src/components/DashboardBuilder/tagParse.spec.ts +149 -0
- package/src/components/DashboardBuilder/tagParse.ts +103 -0
- package/src/components/DashboardBuilder/telemetry.ts +47 -0
- package/src/components/DashboardBuilder/testing/artifactTagParity.json +253 -0
- package/src/components/DashboardBuilder/testing/documentKindRule.json +40 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/testing/resize.ts +48 -0
- package/src/components/DashboardBuilder/testing/urlRenderTags.json +62 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +760 -0
- package/src/components/DashboardBuilder/tileDisplayTitle.ts +13 -0
- package/src/components/DashboardBuilder/useBuilderSelection.ts +121 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +250 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +255 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +97 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +45 -9
- package/src/components/DashboardBuilder/useControlBindings.ts +152 -0
- package/src/components/DashboardBuilder/useConversionConfirm.ts +55 -0
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +57 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- package/src/components/DashboardBuilder/useDraft.ts +15 -2
- package/src/components/DashboardBuilder/useExitGuard.spec.ts +159 -0
- package/src/components/DashboardBuilder/useExitGuard.ts +89 -0
- package/src/components/DashboardBuilder/useFilterForm.existing.spec.tsx +41 -0
- package/src/components/DashboardBuilder/useFilterForm.spec.tsx +24 -2
- package/src/components/DashboardBuilder/useFilterForm.ts +41 -13
- package/src/components/DashboardBuilder/useHostCopy.ts +104 -0
- package/src/components/DashboardBuilder/useOpenDraftCommit.ts +47 -0
- package/src/components/DashboardBuilder/useOpenedDocument.ts +314 -0
- package/src/components/DashboardBuilder/useSaveChannel.ts +275 -0
- package/src/components/DashboardBuilder/useTileEditing.ts +141 -0
- package/src/components/DashboardBuilder/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +30 -5
- package/src/components/DashboardBuilder/useTileResize.ts +31 -8
- package/src/components/DataAppViewer/DataAppViewer.tsx +7 -4
- package/src/components/DocumentCreate/canRetry.spec.ts +32 -0
- package/src/components/DocumentCreate/canRetry.ts +19 -0
- package/src/components/DocumentCreate/createDocument.spec.ts +310 -0
- package/src/components/DocumentCreate/createDocument.ts +159 -0
- package/src/components/DocumentCreate/documentPath.ts +40 -0
- package/src/components/DocumentCreate/events.ts +15 -0
- package/src/components/DocumentCreate/exportedSources.ts +25 -0
- package/src/components/DocumentCreate/guards.ts +45 -0
- package/src/components/DocumentCreate/index.ts +27 -0
- package/src/components/DocumentCreate/newNotebook.spec.ts +156 -0
- package/src/components/DocumentCreate/newNotebook.ts +44 -0
- package/src/components/DocumentCreate/useDocumentChoices.spec.tsx +138 -0
- package/src/components/DocumentCreate/useDocumentChoices.ts +113 -0
- package/src/components/DocumentStorage/DocumentStorage.ts +2 -1
- package/src/components/Environment/Environment.tsx +0 -10
- package/src/components/Loading.tsx +14 -0
- package/src/components/Model/Model.tsx +16 -9
- package/src/components/Model/ModelExplorer.spec.tsx +2 -2
- package/src/components/Model/ModelExplorer.tsx +2 -2
- package/src/components/Model/SourcesExplorer.tsx +2 -4
- package/src/components/NarrowEditGate.spec.tsx +73 -0
- package/src/components/NarrowEditGate.tsx +29 -0
- package/src/components/Notebook/Notebook.layout.spec.tsx +94 -0
- package/src/components/Notebook/Notebook.tsx +72 -29
- package/src/components/Notebook/NotebookCell.tsx +90 -215
- package/src/components/Package/NewDocumentDialog.spec.tsx +749 -0
- package/src/components/Package/NewDocumentDialog.tsx +401 -0
- package/src/components/Package/Package.artifacts.spec.tsx +186 -0
- package/src/components/Package/Package.create.spec.tsx +401 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +396 -177
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +14 -1
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/Prose.spec.tsx +37 -0
- package/src/components/Prose.tsx +35 -5
- package/src/components/RenderedResult/RenderedResult.tsx +23 -8
- package/src/components/RenderedResult/ResultContainer.tsx +51 -13
- package/src/components/RenderedResult/ResultPanel.tsx +24 -5
- package/src/components/RenderedResult/loadRenderer.ts +42 -0
- package/src/components/RenderedResult/resultSizing.spec.ts +68 -0
- package/src/components/RenderedResult/resultSizing.ts +14 -3
- package/src/components/ServerProvider.tsx +2 -1
- package/src/components/UnsavedChangesDialog.spec.tsx +70 -0
- package/src/components/UnsavedChangesDialog.tsx +49 -0
- package/src/components/given/GivenInput.spec.tsx +5 -5
- package/src/components/given/GivenInput.tsx +46 -38
- package/src/components/given/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +5 -11
- package/src/components/given/paramCodec.ts +27 -1
- package/src/components/index.ts +3 -2
- package/src/components/styles.ts +4 -5
- package/src/hooks/givenValue.ts +9 -0
- package/src/hooks/index.ts +7 -0
- package/src/hooks/useCompiledDocument.spec.tsx +86 -0
- package/src/hooks/useCompiledDocument.ts +59 -0
- package/src/hooks/useDimensionalFilterRangeData.ts +3 -1
- package/src/hooks/useDocumentControls.ts +13 -1
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useNearViewport.spec.tsx +150 -0
- package/src/hooks/useNearViewport.ts +102 -0
- package/src/hooks/useQueryResult.ts +23 -1
- package/src/hooks/useQueryWithApiError.ts +10 -3
- package/src/hooks/useRawQueryData.ts +3 -1
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/hooks/useSuggestOptions.dom.spec.ts +40 -1
- package/src/hooks/useSuggestOptions.ts +42 -10
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +112 -0
- package/src/theme/accent.spec.ts +116 -0
- package/src/theme/accent.ts +148 -0
- package/src/theme/buildTableCssVars.spec.ts +24 -0
- package/src/theme/buildTableCssVars.ts +1 -2
- package/src/theme/buildVegaThemeOverride.spec.ts +38 -2
- package/src/theme/buildVegaThemeOverride.ts +5 -5
- package/src/theme/defaults.ts +34 -0
- package/src/theme/index.ts +9 -0
- package/src/theme/keys.ts +6 -0
- package/src/theme/motion.ts +44 -0
- package/src/theme/readChartAnnotations.spec.ts +18 -0
- package/src/theme/readChartAnnotations.ts +1 -1
- package/src/theme/resolveTheme.spec.ts +73 -0
- package/src/theme/resolveTheme.ts +61 -20
- package/src/theme/types.ts +30 -5
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -0
- package/src/{components/DashboardBuilder → utils}/malloyText.spec.ts +48 -0
- package/src/utils/malloyText.ts +368 -0
- package/src/utils/queryClient.ts +8 -0
- package/vite.config.ts +4 -0
- package/dist/Dashboard-ChyylkTD.cjs.js +0 -136
- package/dist/RenderedResult-AJPMUkAD.cjs.js +0 -135
- package/dist/ServerProvider-CXrOKD6g.cjs.js +0 -1
- package/dist/components/Dashboard/DashboardBar.d.ts +0 -21
- package/dist/components/Dashboard/ExploreDialog.d.ts +0 -20
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +0 -15
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +0 -20
- package/dist/components/DashboardBuilder/diff.d.ts +0 -35
- package/dist/components/DashboardBuilder/malloyText.d.ts +0 -64
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/Dashboard/DashboardBar.tsx +0 -88
- package/src/components/Dashboard/ExploreDialog.tsx +0 -89
- package/src/components/DashboardBuilder/DiffDialog.tsx +0 -122
- package/src/components/DashboardBuilder/SettingsPopover.tsx +0 -168
- package/src/components/DashboardBuilder/diff.spec.ts +0 -44
- package/src/components/DashboardBuilder/diff.ts +0 -93
- package/src/components/DashboardBuilder/malloyText.ts +0 -214
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -0,0 +1,630 @@
|
|
|
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 { fileURLToPath, pathToFileURL } from "url";
|
|
8
|
+
import { isQueryTile, isTextTile } from "./document";
|
|
9
|
+
import {
|
|
10
|
+
conversionRefused,
|
|
11
|
+
convertLegacyNotebook,
|
|
12
|
+
notebookSourceRefused,
|
|
13
|
+
readNotebookSource,
|
|
14
|
+
} from "./legacyNotebook";
|
|
15
|
+
import { readDashboardDocument, readFailed } from "./readDocument";
|
|
16
|
+
import {
|
|
17
|
+
spliceDashboardDocument,
|
|
18
|
+
spliceFailed,
|
|
19
|
+
syntaxErrors,
|
|
20
|
+
} from "./spliceDocument";
|
|
21
|
+
|
|
22
|
+
const REPO = path.resolve(import.meta.dir, "../../../../..");
|
|
23
|
+
const CATEGORY_REVIEW = path.join(
|
|
24
|
+
REPO,
|
|
25
|
+
"examples/storefront/notebooks/category-review.malloy",
|
|
26
|
+
);
|
|
27
|
+
const FIXTURES = path.join(
|
|
28
|
+
REPO,
|
|
29
|
+
"packages/server/tests/fixtures/notebooks-malloyyo/notebooks",
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const read = (file: string) =>
|
|
33
|
+
fs.readFileSync(file, "utf8").replace(/\r\n/g, "\n");
|
|
34
|
+
|
|
35
|
+
/** The converted text, or a thrown reason. */
|
|
36
|
+
async function convert(text: string): Promise<string> {
|
|
37
|
+
const result = await convertLegacyNotebook(text);
|
|
38
|
+
if (conversionRefused(result)) throw new Error(result.refused);
|
|
39
|
+
return result.text;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** Why the converter refuses `text`. */
|
|
43
|
+
async function refusal(text: string) {
|
|
44
|
+
const result = await convertLegacyNotebook(text);
|
|
45
|
+
if (!conversionRefused(result)) throw new Error("expected a refusal");
|
|
46
|
+
return result;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async function document(text: string) {
|
|
50
|
+
const result = await readDashboardDocument(text);
|
|
51
|
+
if (readFailed(result)) throw new Error(result.reason);
|
|
52
|
+
return result.document;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** Compiles `text` as `file` inside the package at `pkg` on DuckDB, and hands back a way to run a tile's view. */
|
|
56
|
+
async function compiled(pkg: string, file: string, text: string) {
|
|
57
|
+
const { Runtime } = await import("@malloydata/malloy");
|
|
58
|
+
const { DuckDBConnection } = await import("@malloydata/db-duckdb");
|
|
59
|
+
const url = new URL(pathToFileURL(path.join(pkg, file)).href);
|
|
60
|
+
const connection = new DuckDBConnection("duckdb", ":memory:", pkg);
|
|
61
|
+
const runtime = new Runtime({
|
|
62
|
+
urlReader: {
|
|
63
|
+
readURL: async (at: URL) =>
|
|
64
|
+
at.href === url.href
|
|
65
|
+
? text
|
|
66
|
+
: fs.readFileSync(fileURLToPath(at.href), "utf8"),
|
|
67
|
+
},
|
|
68
|
+
connections: { lookupConnection: async () => connection },
|
|
69
|
+
} as never);
|
|
70
|
+
const model = runtime.loadModel(url);
|
|
71
|
+
await model.getModel();
|
|
72
|
+
return {
|
|
73
|
+
rows: async (source: string, view: string) =>
|
|
74
|
+
(
|
|
75
|
+
await model.loadQuery(`run: ${source} -> ${view}`).run()
|
|
76
|
+
).data.toObject(),
|
|
77
|
+
close: () => connection.close(),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const HEAD = `##! experimental.givens
|
|
82
|
+
## artifact { kind=notebook title="T" }
|
|
83
|
+
import "../models/orders.malloy"
|
|
84
|
+
`;
|
|
85
|
+
|
|
86
|
+
describe("convertLegacyNotebook: the storefront category review", () => {
|
|
87
|
+
it("becomes a layout notebook that reads back tile for tile", async () => {
|
|
88
|
+
const original = read(CATEGORY_REVIEW);
|
|
89
|
+
const converted = await convert(original);
|
|
90
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
91
|
+
|
|
92
|
+
const doc = await document(converted);
|
|
93
|
+
expect(doc.kind).toBe("notebook");
|
|
94
|
+
expect(doc.title).toBe("Category review");
|
|
95
|
+
expect(doc.description).toContain("One category at a time");
|
|
96
|
+
expect(
|
|
97
|
+
doc.tiles.map((t) => `${isTextTile(t) ? "text" : "query"}`),
|
|
98
|
+
).toEqual(["text", "text", "query", "text", "query", "text", "query"]);
|
|
99
|
+
|
|
100
|
+
const texts = doc.tiles.filter(isTextTile).map((t) => t.markdown);
|
|
101
|
+
expect(texts[0]).toStartWith("# Category review\n\nPick a **Category**");
|
|
102
|
+
expect(texts[1]).toBe(
|
|
103
|
+
"The monthly trend says which way revenue is moving.",
|
|
104
|
+
);
|
|
105
|
+
expect(texts[3]).toBe(
|
|
106
|
+
"Last, the best-selling products, defined once as a named query and then run.",
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
const queries = doc.tiles.filter(isQueryTile);
|
|
110
|
+
expect(queries.map((t) => t.source)).toEqual([
|
|
111
|
+
"order_items_tiles",
|
|
112
|
+
"order_items_tiles",
|
|
113
|
+
"order_items_tiles",
|
|
114
|
+
]);
|
|
115
|
+
expect(queries.map((t) => t.label)).toEqual([
|
|
116
|
+
"Revenue by month",
|
|
117
|
+
"Top brands",
|
|
118
|
+
"The ten best-selling products in the selected category",
|
|
119
|
+
]);
|
|
120
|
+
expect(queries.map((t) => t.subtitle)).toEqual([
|
|
121
|
+
"Revenue by month for the selected category",
|
|
122
|
+
"The eight brands with the most revenue in the selected category",
|
|
123
|
+
undefined,
|
|
124
|
+
]);
|
|
125
|
+
expect(queries.map((t) => t.chart)).toEqual([
|
|
126
|
+
"line_chart",
|
|
127
|
+
"bar_chart",
|
|
128
|
+
undefined,
|
|
129
|
+
]);
|
|
130
|
+
expect(doc.localGivens?.map((g) => g.name)).toEqual(["CATEGORY"]);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it("carries the header and the givens over as written, and leaves no run behind", async () => {
|
|
134
|
+
const original = read(CATEGORY_REVIEW);
|
|
135
|
+
const converted = await convert(original);
|
|
136
|
+
const header = original.slice(0, original.indexOf("import {"));
|
|
137
|
+
expect(converted).toContain(
|
|
138
|
+
header
|
|
139
|
+
.replace("## artifact {", "##| artifact {")
|
|
140
|
+
.replace(" }\n", "\n tiles=["),
|
|
141
|
+
);
|
|
142
|
+
expect(converted).toContain(
|
|
143
|
+
'# description="Narrow to one product category. Leave empty for all"\n# label="Category" control=select suggest { source=products dimension=category }\ngiven: CATEGORY :: filter<string> is f\'\'\n',
|
|
144
|
+
);
|
|
145
|
+
expect(converted).not.toMatch(/^run:/m);
|
|
146
|
+
// The named query was run once and nowhere else, so it became its view.
|
|
147
|
+
expect(converted).not.toContain("query: top_products_in_category");
|
|
148
|
+
expect(converted).toContain(
|
|
149
|
+
"view: the_ten_best_selling_products_in_the is top_products + { where: category ~ $CATEGORY }",
|
|
150
|
+
);
|
|
151
|
+
expect(converted).not.toMatch(/\n\n\n/);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it("is a file the writer opens and writes back byte for byte", async () => {
|
|
155
|
+
const converted = await convert(read(CATEGORY_REVIEW));
|
|
156
|
+
const result = await spliceDashboardDocument(
|
|
157
|
+
converted,
|
|
158
|
+
await document(converted),
|
|
159
|
+
);
|
|
160
|
+
if (spliceFailed(result)) throw new Error(result.reason);
|
|
161
|
+
expect(result.source).toBe(converted);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("compiles under Malloy and its views run", async () => {
|
|
165
|
+
const pkg = path.join(REPO, "examples/storefront");
|
|
166
|
+
const converted = await convert(read(CATEGORY_REVIEW));
|
|
167
|
+
const model = await compiled(
|
|
168
|
+
pkg,
|
|
169
|
+
"notebooks/converted.malloy",
|
|
170
|
+
converted,
|
|
171
|
+
);
|
|
172
|
+
try {
|
|
173
|
+
for (const view of [
|
|
174
|
+
"revenue_by_month",
|
|
175
|
+
"top_brands_2",
|
|
176
|
+
"the_ten_best_selling_products_in_the",
|
|
177
|
+
])
|
|
178
|
+
expect(
|
|
179
|
+
(await model.rows("order_items_tiles", view)).length,
|
|
180
|
+
).toBeGreaterThan(0);
|
|
181
|
+
} finally {
|
|
182
|
+
await model.close();
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe("convertLegacyNotebook: a named query that ends in a line comment", () => {
|
|
188
|
+
const PKG = path.dirname(FIXTURES);
|
|
189
|
+
for (const [name, comment] of [
|
|
190
|
+
["//", "// c"],
|
|
191
|
+
["--", "-- c"],
|
|
192
|
+
] as const)
|
|
193
|
+
it(`keeps a refinement out of a ${name} comment`, async () => {
|
|
194
|
+
const converted = await convert(
|
|
195
|
+
`${HEAD}\nquery: q is orders -> { group_by: region } ${comment}\n\nrun: q + { limit: 1 }\n`,
|
|
196
|
+
);
|
|
197
|
+
expect(converted).toMatch(
|
|
198
|
+
new RegExp(`${comment}\\n\\s*\\+ \\{ limit: 1 \\}`),
|
|
199
|
+
);
|
|
200
|
+
const model = await compiled(PKG, "notebooks/c.malloy", converted);
|
|
201
|
+
try {
|
|
202
|
+
const [tile] = (await document(converted)).tiles.filter(
|
|
203
|
+
isQueryTile,
|
|
204
|
+
);
|
|
205
|
+
expect(await model.rows(tile.source, tile.name)).toHaveLength(1);
|
|
206
|
+
} finally {
|
|
207
|
+
await model.close();
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
|
|
211
|
+
it("keeps a following stage out of the comment", async () => {
|
|
212
|
+
const converted = await convert(
|
|
213
|
+
`${HEAD}\nquery: q is orders -> { group_by: region } // c\n\nrun: q -> { select: region }\n`,
|
|
214
|
+
);
|
|
215
|
+
expect(converted).toMatch(/\/\/ c\n\s*-> \{ select: region \}/);
|
|
216
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
describe("convertLegacyNotebook: every cell-format notebook in the corpus", () => {
|
|
221
|
+
const files = fs
|
|
222
|
+
.readdirSync(FIXTURES)
|
|
223
|
+
.filter(
|
|
224
|
+
(f) =>
|
|
225
|
+
f.endsWith(".malloy") &&
|
|
226
|
+
f !== "refused.malloy" &&
|
|
227
|
+
f !== "layout.malloy",
|
|
228
|
+
);
|
|
229
|
+
for (const file of files) {
|
|
230
|
+
it(`converts ${file} to one tile per cell, with its prose`, async () => {
|
|
231
|
+
const original = read(path.join(FIXTURES, file));
|
|
232
|
+
const source = await readNotebookSource(original);
|
|
233
|
+
if (notebookSourceRefused(source)) throw new Error(source.refused);
|
|
234
|
+
const expected = source.source.cells.reduce(
|
|
235
|
+
(n, cell) =>
|
|
236
|
+
n +
|
|
237
|
+
(cell.kind === "markdown" ? 1 : 0) +
|
|
238
|
+
(cell.kind === "query" ? 1 : 0) +
|
|
239
|
+
(cell.kind !== "markdown" && cell.markdown !== undefined
|
|
240
|
+
? 1
|
|
241
|
+
: 0),
|
|
242
|
+
0,
|
|
243
|
+
);
|
|
244
|
+
const converted = await convert(original);
|
|
245
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
246
|
+
const doc = await document(converted);
|
|
247
|
+
expect(doc.tiles).toHaveLength(expected);
|
|
248
|
+
// Syntax is not enough: the file compiles against its package and every view tile runs.
|
|
249
|
+
const model = await compiled(
|
|
250
|
+
path.dirname(FIXTURES),
|
|
251
|
+
`notebooks/${file}`,
|
|
252
|
+
converted,
|
|
253
|
+
);
|
|
254
|
+
try {
|
|
255
|
+
for (const tile of doc.tiles.filter(isQueryTile))
|
|
256
|
+
await model.rows(tile.source, tile.name);
|
|
257
|
+
} finally {
|
|
258
|
+
await model.close();
|
|
259
|
+
}
|
|
260
|
+
// Every prose cell's text survives as a text tile.
|
|
261
|
+
const prose = source.source.cells.flatMap((c) =>
|
|
262
|
+
c.markdown === undefined ? [] : [c.markdown],
|
|
263
|
+
);
|
|
264
|
+
expect(doc.tiles.filter(isTextTile).map((t) => t.markdown)).toEqual(
|
|
265
|
+
prose,
|
|
266
|
+
);
|
|
267
|
+
// And a converted notebook is a layout one: nothing left to convert.
|
|
268
|
+
expect((await refusal(converted)).refused).toContain(
|
|
269
|
+
"already lists its tiles",
|
|
270
|
+
);
|
|
271
|
+
});
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
it("passes a notebook the cell reader refuses through with its reason", async () => {
|
|
275
|
+
const result = await refusal(read(path.join(FIXTURES, "refused.malloy")));
|
|
276
|
+
expect(result.line).toBeGreaterThan(0);
|
|
277
|
+
});
|
|
278
|
+
|
|
279
|
+
it("refuses a tag whose artifact property is not the first, rather than rewriting it", async () => {
|
|
280
|
+
const result = await refusal(
|
|
281
|
+
`##! experimental.givens\n## dashboard { columns=2 } artifact { kind=notebook title="T" }\nimport "../m.malloy"\n\nrun: orders -> kpis\n`,
|
|
282
|
+
);
|
|
283
|
+
expect(result.refused).toContain("`artifact { … }` first");
|
|
284
|
+
expect(result.line).toBe(2);
|
|
285
|
+
});
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
describe("convertLegacyNotebook: shapes", () => {
|
|
289
|
+
it("keeps a named query that more than one run, or anything else, names", async () => {
|
|
290
|
+
const converted = await convert(
|
|
291
|
+
`${HEAD}\nquery: q is orders -> kpis\n\nrun: q\n\nrun: q + { limit: 1 }\n`,
|
|
292
|
+
);
|
|
293
|
+
expect(converted).toContain("query: q is orders -> kpis");
|
|
294
|
+
expect(converted).toContain("view: tile_1 is kpis\n");
|
|
295
|
+
expect(converted).toContain("view: tile_2 is kpis + { limit: 1 }");
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("keeps a run-once named query that a definition also names", async () => {
|
|
299
|
+
const converted = await convert(
|
|
300
|
+
`${HEAD}\nquery: q is orders -> kpis\n\nquery: r is q + { limit: 1 }\n\nrun: q\n`,
|
|
301
|
+
);
|
|
302
|
+
expect(converted).toContain("query: q is orders -> kpis");
|
|
303
|
+
expect(converted).toContain("view: tile_1 is kpis");
|
|
304
|
+
});
|
|
305
|
+
|
|
306
|
+
it("runs a query of a query as its source's view with the later stages", async () => {
|
|
307
|
+
const converted = await convert(
|
|
308
|
+
`${HEAD}\nquery: q is orders -> kpis\n\nrun: q -> { select: order_count }\n`,
|
|
309
|
+
);
|
|
310
|
+
expect(converted).toContain(
|
|
311
|
+
"view: tile_1 is kpis -> { select: order_count }",
|
|
312
|
+
);
|
|
313
|
+
const doc = await document(converted);
|
|
314
|
+
expect(doc.tiles[0]).toMatchObject({
|
|
315
|
+
name: "tile_1",
|
|
316
|
+
source: "orders_tiles",
|
|
317
|
+
declaration: { kind: "opaque" },
|
|
318
|
+
});
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
it("refuses a refinement of a query with more than one stage", async () => {
|
|
322
|
+
const result = await refusal(
|
|
323
|
+
`${HEAD}\nquery: q is orders -> kpis -> { select: order_count }\n\nrun: q + { limit: 1 }\n`,
|
|
324
|
+
);
|
|
325
|
+
expect(result.refused).toContain("more than one stage");
|
|
326
|
+
expect(result.line).toBe(7);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
it("groups views by source, in the order the sources first run", async () => {
|
|
330
|
+
const converted = await convert(
|
|
331
|
+
`${HEAD}\nsource: other is orders extend { where: region = 'US' }\n\nrun: orders -> a\n\nrun: other -> b\n\nrun: orders -> c\n`,
|
|
332
|
+
);
|
|
333
|
+
const doc = await document(converted);
|
|
334
|
+
expect(
|
|
335
|
+
doc.tiles.map((t) => (isQueryTile(t) ? `${t.source}.${t.name}` : "")),
|
|
336
|
+
).toEqual([
|
|
337
|
+
"orders_tiles.tile_1",
|
|
338
|
+
"other_tiles.tile_2",
|
|
339
|
+
"orders_tiles.tile_3",
|
|
340
|
+
]);
|
|
341
|
+
expect(doc.sources.map((s) => s.name)).toEqual([
|
|
342
|
+
"other",
|
|
343
|
+
"orders_tiles",
|
|
344
|
+
"other_tiles",
|
|
345
|
+
]);
|
|
346
|
+
// The extension comes after the source it extends.
|
|
347
|
+
expect(converted.indexOf("source: other is")).toBeLessThan(
|
|
348
|
+
converted.indexOf("source: other_tiles is"),
|
|
349
|
+
);
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
it("puts a caption on the tile as its label, or as its subtitle beside a label", async () => {
|
|
353
|
+
const converted = await convert(
|
|
354
|
+
`${HEAD}\n#" Plain caption\nrun: orders -> a\n\n#" Second caption\n# label="Given label"\nrun: orders -> b\n\n#" Third\n# label="L"\n# subtitle="S"\nrun: orders -> c\n`,
|
|
355
|
+
);
|
|
356
|
+
const queries = (await document(converted)).tiles.filter(isQueryTile);
|
|
357
|
+
expect(queries.map((t) => [t.label, t.subtitle])).toEqual([
|
|
358
|
+
["Plain caption", undefined],
|
|
359
|
+
["Given label", "Second caption"],
|
|
360
|
+
["L", "S"],
|
|
361
|
+
]);
|
|
362
|
+
// Nothing is lost when both are taken: the caption stays as a doc note.
|
|
363
|
+
expect(converted).toContain(' # subtitle="S"\n #" Third\n view: l');
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it("keeps a caption it cannot write into a tag as a doc note", async () => {
|
|
367
|
+
const converted = await convert(
|
|
368
|
+
`${HEAD}\n#" # authorize everyone\nrun: orders -> a\n`,
|
|
369
|
+
);
|
|
370
|
+
expect(converted).toContain(' #" # authorize everyone\n');
|
|
371
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
372
|
+
});
|
|
373
|
+
|
|
374
|
+
it("escapes quotes and backslashes in a caption", async () => {
|
|
375
|
+
const converted = await convert(
|
|
376
|
+
`${HEAD}\n#" Say "hi" \\ there\nrun: orders -> a\n`,
|
|
377
|
+
);
|
|
378
|
+
const [tile] = (await document(converted)).tiles.filter(isQueryTile);
|
|
379
|
+
expect(tile.label).toBe('Say "hi" \\ there');
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
it("keeps comments and unmodelled tags above a run, in order, with the view", async () => {
|
|
383
|
+
const converted = await convert(
|
|
384
|
+
`${HEAD}\n// why this one\n# big_value\n/* and a block\n comment */\n# label="K"\nrun: orders -> kpis\n`,
|
|
385
|
+
);
|
|
386
|
+
expect(converted).toContain(
|
|
387
|
+
' // why this one\n # big_value\n /* and a block\n comment */\n # label="K"\n view: k is kpis',
|
|
388
|
+
);
|
|
389
|
+
const [tile] = (await document(converted)).tiles.filter(isQueryTile);
|
|
390
|
+
expect(tile.label).toBe("K");
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
it("keeps a (text) note above a run as it was rather than dropping it", async () => {
|
|
394
|
+
const converted = await convert(
|
|
395
|
+
`${HEAD}\n#(text) a side note\nrun: orders -> kpis\n`,
|
|
396
|
+
);
|
|
397
|
+
expect(converted).toContain(" #(text) a side note\n view: tile_1");
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
it("indents a multi-line view body under its declaration", async () => {
|
|
401
|
+
const converted = await convert(
|
|
402
|
+
`${HEAD}\nrun: orders -> {\n group_by: region\n aggregate: order_count\n}\n`,
|
|
403
|
+
);
|
|
404
|
+
expect(converted).toContain(
|
|
405
|
+
" view: tile_1 is {\n group_by: region\n aggregate: order_count\n }",
|
|
406
|
+
);
|
|
407
|
+
const [tile] = (await document(converted)).tiles.filter(isQueryTile);
|
|
408
|
+
expect(tile.declaration.kind).toBe("inline");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("moves a comment above a prose cell with it", async () => {
|
|
412
|
+
const converted = await convert(
|
|
413
|
+
`${HEAD}\n// the lead-in\n##(markdown) Hello\n\nrun: orders -> kpis\n`,
|
|
414
|
+
);
|
|
415
|
+
expect(converted).toContain(
|
|
416
|
+
"// the lead-in\n##|(markdown) text_1\nHello\n|##\n",
|
|
417
|
+
);
|
|
418
|
+
});
|
|
419
|
+
|
|
420
|
+
it("collapses the blank lines a removed run leaves", async () => {
|
|
421
|
+
const converted = await convert(
|
|
422
|
+
`${HEAD}\nrun: orders -> a\n\n\n\nrun: orders -> b\n\n##(markdown) After\n`,
|
|
423
|
+
);
|
|
424
|
+
expect(converted).not.toMatch(/\n\n\n/);
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
it("keeps a stray model note and trailing comment where they were", async () => {
|
|
428
|
+
const converted = await convert(
|
|
429
|
+
`${HEAD}\nrun: orders -> a\n\n##(filters) ["orders.region"]\n\n// the end\n`,
|
|
430
|
+
);
|
|
431
|
+
expect(converted).toContain('##(filters) ["orders.region"]');
|
|
432
|
+
expect(
|
|
433
|
+
converted.trimEnd().endsWith("}") || converted.includes("// the end"),
|
|
434
|
+
).toBe(true);
|
|
435
|
+
expect(converted).toContain("// the end");
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it("gives a prose line that would close its block one space of indent", async () => {
|
|
439
|
+
const converted = await convert(
|
|
440
|
+
`${HEAD}\n##(markdown) |## not a closer\n`,
|
|
441
|
+
);
|
|
442
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
443
|
+
const [tile] = (await document(converted)).tiles.filter(isTextTile);
|
|
444
|
+
expect(tile.markdown).toBe(" |## not a closer");
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
it("takes names that cannot collide with what the file already declares", async () => {
|
|
448
|
+
const converted = await convert(
|
|
449
|
+
`${HEAD}\nsource: orders_tiles is orders extend { dimension: tile_1 is 1 }\n\nrun: orders -> kpis\n`,
|
|
450
|
+
);
|
|
451
|
+
const doc = await document(converted);
|
|
452
|
+
expect(doc.tiles[0]).toMatchObject({
|
|
453
|
+
name: "tile_1_2",
|
|
454
|
+
source: "orders_tiles_2",
|
|
455
|
+
});
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it("names the extension for a backtick-quoted source with a valid identifier", async () => {
|
|
459
|
+
const converted = await convert(
|
|
460
|
+
`${HEAD}\nrun: \`order-items\` -> kpis\n`,
|
|
461
|
+
);
|
|
462
|
+
expect(converted).toContain(
|
|
463
|
+
"source: order_items_tiles is `order-items` extend {",
|
|
464
|
+
);
|
|
465
|
+
expect(converted).toContain('"order_items_tiles -> tile_1"');
|
|
466
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
467
|
+
expect((await document(converted)).tiles[0]).toMatchObject({
|
|
468
|
+
source: "order_items_tiles",
|
|
469
|
+
});
|
|
470
|
+
});
|
|
471
|
+
|
|
472
|
+
it("converts a statement with a very long run of spaces in linear time", async () => {
|
|
473
|
+
const started = performance.now();
|
|
474
|
+
const converted = await convert(
|
|
475
|
+
`${HEAD}\nrun: orders ->${" ".repeat(80_000)}kpis\n`,
|
|
476
|
+
);
|
|
477
|
+
expect(performance.now() - started).toBeLessThan(2000);
|
|
478
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
479
|
+
});
|
|
480
|
+
|
|
481
|
+
it("converts a CRLF notebook", async () => {
|
|
482
|
+
const original =
|
|
483
|
+
`${HEAD}\n##(markdown) Hello\n\n# label="K"\nrun: orders -> kpis\n`.replace(
|
|
484
|
+
/\n/g,
|
|
485
|
+
"\r\n",
|
|
486
|
+
);
|
|
487
|
+
const converted = await convert(original);
|
|
488
|
+
expect(converted).not.toMatch(/(?<!\r)\n/);
|
|
489
|
+
const doc = await document(converted.replace(/\r\n/g, "\n"));
|
|
490
|
+
expect(doc.tiles.map((t) => t.name)).toEqual(["text_1", "k"]);
|
|
491
|
+
});
|
|
492
|
+
|
|
493
|
+
it("keeps the blank lines inside a block comment between cells", async () => {
|
|
494
|
+
const converted = await convert(
|
|
495
|
+
`${HEAD}\nrun: orders -> kpis\n\n/* first\n\n\n indented */\n\nrun: orders -> by_month\n`,
|
|
496
|
+
);
|
|
497
|
+
expect(converted).toContain("/* first\n\n\n indented */");
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
it("writes the tag as a block with a tile per line, whether it was a line or a block", async () => {
|
|
501
|
+
const cells = "\n##(markdown) Hello\n\nrun: orders -> kpis\n";
|
|
502
|
+
const fromLine = await convert(`${HEAD}${cells}`);
|
|
503
|
+
expect(fromLine).toContain(
|
|
504
|
+
'##| artifact { kind=notebook title="T"\n tiles=[\n text_1 { kind=text },\n "orders_tiles -> tile_1"\n ]\n}\n|##\n',
|
|
505
|
+
);
|
|
506
|
+
const block = `##! experimental.givens\n##| artifact { kind=notebook\n title="T"\n}\n|##\nimport "../models/orders.malloy"\n${cells}`;
|
|
507
|
+
const fromBlock = await convert(block);
|
|
508
|
+
expect(fromBlock).toContain(
|
|
509
|
+
'##| artifact { kind=notebook\n title="T"\n tiles=[\n text_1 { kind=text },\n "orders_tiles -> tile_1"\n ]\n}\n|##\n',
|
|
510
|
+
);
|
|
511
|
+
expect(await syntaxErrors(fromBlock)).toEqual([]);
|
|
512
|
+
expect((await document(fromBlock)).tiles.map((t) => t.name)).toEqual([
|
|
513
|
+
"text_1",
|
|
514
|
+
"tile_1",
|
|
515
|
+
]);
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
it("converts a notebook with no run or prose cells to an empty tile list", async () => {
|
|
519
|
+
const converted = await convert(HEAD);
|
|
520
|
+
const doc = await document(converted);
|
|
521
|
+
expect(doc.tiles).toEqual([]);
|
|
522
|
+
expect(doc.kind).toBe("notebook");
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
it("carries the tags above a consumed query onto the view it becomes, and names the view from its label", async () => {
|
|
526
|
+
const converted = await convert(
|
|
527
|
+
`${HEAD}\n# label="Mine"\n# big_value\nquery: q is orders -> kpis\n\nrun: q\n`,
|
|
528
|
+
);
|
|
529
|
+
expect(converted).not.toContain("query: q");
|
|
530
|
+
expect(converted).toContain(
|
|
531
|
+
'source: orders_tiles is orders extend {\n # label="Mine"\n # big_value\n view: mine is kpis\n}',
|
|
532
|
+
);
|
|
533
|
+
const [tile] = (await document(converted)).tiles.filter(isQueryTile);
|
|
534
|
+
expect(tile).toMatchObject({ name: "mine", label: "Mine" });
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
it("names a text tile around an identifier the file already declares", async () => {
|
|
538
|
+
const converted = await convert(
|
|
539
|
+
`${HEAD}\nsource: text_1 is orders extend {}\n\n##(markdown) Hello\n\nrun: orders -> kpis\n\n##(markdown) Two\n`,
|
|
540
|
+
);
|
|
541
|
+
const doc = await document(converted);
|
|
542
|
+
expect(doc.tiles.map((t) => t.name)).toEqual([
|
|
543
|
+
"text_1_2",
|
|
544
|
+
"tile_1",
|
|
545
|
+
"text_2",
|
|
546
|
+
]);
|
|
547
|
+
expect(converted).toContain("source: text_1 is orders extend {}");
|
|
548
|
+
expect(converted).toContain("##|(markdown) text_1_2\nHello\n|##");
|
|
549
|
+
expect(doc.tiles.filter(isTextTile).map((t) => t.markdown)).toEqual([
|
|
550
|
+
"Hello",
|
|
551
|
+
"Two",
|
|
552
|
+
]);
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
it("extends a backquoted source and keeps the quotes on it", async () => {
|
|
556
|
+
const converted = await convert(`${HEAD}\nrun: \`orders\` -> kpis\n`);
|
|
557
|
+
expect(converted).toContain(
|
|
558
|
+
"source: orders_tiles is `orders` extend {\n view: tile_1 is kpis\n}",
|
|
559
|
+
);
|
|
560
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
561
|
+
const [tile] = (await document(converted)).tiles.filter(isQueryTile);
|
|
562
|
+
expect(tile).toMatchObject({ source: "orders_tiles", name: "tile_1" });
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("refuses a run with nothing after the arrow, at the line the reader names", async () => {
|
|
566
|
+
// The cell reader's parse refuses it before the converter's own empty-body check can run.
|
|
567
|
+
const result = await refusal(`${HEAD}\nrun: orders ->\n`);
|
|
568
|
+
expect(result.line).toBeGreaterThan(0);
|
|
569
|
+
expect(result.refused).toContain("could not parse");
|
|
570
|
+
});
|
|
571
|
+
|
|
572
|
+
it("follows a chain of ten named queries and refuses an eleventh instead of making a source of a query", async () => {
|
|
573
|
+
const chain = (length: number) => {
|
|
574
|
+
let text = `${HEAD}\nquery: q1 is orders -> kpis\n\n`;
|
|
575
|
+
for (let i = 2; i <= length; i++)
|
|
576
|
+
text += `query: q${i} is q${i - 1} -> { limit: ${i} }\n\n`;
|
|
577
|
+
return `${text}run: q${length}\n`;
|
|
578
|
+
};
|
|
579
|
+
const ten = await convert(chain(10));
|
|
580
|
+
expect(ten).toContain(
|
|
581
|
+
"view: tile_1 is kpis -> { limit: 2 } -> { limit: 3 }",
|
|
582
|
+
);
|
|
583
|
+
expect(ten).not.toContain("query:");
|
|
584
|
+
const result = await refusal(chain(11));
|
|
585
|
+
expect(result.refused).toContain("more than 10 other queries");
|
|
586
|
+
expect(result.line).toBe(27);
|
|
587
|
+
});
|
|
588
|
+
|
|
589
|
+
it("leaves a given: block of several givens in place above the tiles' sources", async () => {
|
|
590
|
+
const given =
|
|
591
|
+
"given:\n REGION :: filter<string> is f''\n SINCE :: date is @2023-01-01\n";
|
|
592
|
+
const converted = await convert(
|
|
593
|
+
`${HEAD}\n${given}\nrun: orders -> kpis\n`,
|
|
594
|
+
);
|
|
595
|
+
expect(converted).toContain(
|
|
596
|
+
`import "../models/orders.malloy"\n\n${given}\nsource: orders_tiles is orders extend {`,
|
|
597
|
+
);
|
|
598
|
+
expect(await syntaxErrors(converted)).toEqual([]);
|
|
599
|
+
const doc = await document(converted);
|
|
600
|
+
expect(doc.localGivens?.map((g) => g.name)).toEqual(["REGION", "SINCE"]);
|
|
601
|
+
});
|
|
602
|
+
|
|
603
|
+
describe("refusals", () => {
|
|
604
|
+
it("refuses a run that extends its source inline, naming the line", async () => {
|
|
605
|
+
const result = await refusal(
|
|
606
|
+
`${HEAD}\nrun: orders extend { dimension: x is 1 } -> { select: x }\n`,
|
|
607
|
+
);
|
|
608
|
+
expect(result.refused).toContain("extends its source inline");
|
|
609
|
+
expect(result.line).toBe(5);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
it("refuses a run whose source is not a name", async () => {
|
|
613
|
+
const result = await refusal(
|
|
614
|
+
`${HEAD}\nrun: duckdb.table('x') -> { select: y }\n`,
|
|
615
|
+
);
|
|
616
|
+
expect(result.refused).toContain("not a name");
|
|
617
|
+
expect(result.line).toBe(5);
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
it("refuses a run that is not source -> view", async () => {
|
|
621
|
+
const result = await refusal(`${HEAD}\nrun: something\n`);
|
|
622
|
+
expect(result.refused).toContain("source -> view");
|
|
623
|
+
});
|
|
624
|
+
|
|
625
|
+
it("refuses a file that is not a notebook the cell reader can place", async () => {
|
|
626
|
+
const result = await refusal(`${HEAD}\n;;[ "stray" ]\n`);
|
|
627
|
+
expect(result.line).toBeGreaterThan(0);
|
|
628
|
+
});
|
|
629
|
+
});
|
|
630
|
+
});
|