@malloy-publisher/sdk 0.9.0 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{Dashboard-H1kJlDFo.es.js → DashboardTile-BFcxdv7R.es.js} +15918 -17760
- package/dist/DashboardTile-sg8LjUk8.cjs.js +137 -0
- package/dist/RenderedResult-B48wAjM8.cjs.js +141 -0
- package/dist/{RenderedResult-BRgIgxWh.es.js → RenderedResult-CBLHr32C.es.js} +193 -183
- package/dist/{ServerProvider-Boxrv6Ym.es.js → ServerProvider-DCV8BUWD.es.js} +529 -521
- package/dist/ServerProvider-HRqT3w1C.cjs.js +1 -0
- package/dist/builder/index.cjs.js +146 -58
- package/dist/builder/index.es.js +9076 -6479
- package/dist/builder-entry.d.ts +4 -0
- package/dist/client/api.d.ts +82 -48
- 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 +84 -82
- package/dist/components/Dashboard/Dashboard.d.ts +8 -15
- package/dist/components/Dashboard/DashboardGrid.d.ts +23 -6
- package/dist/components/Dashboard/DashboardTile.d.ts +10 -1
- package/dist/components/Dashboard/DashboardView.d.ts +36 -0
- package/dist/components/Dashboard/TileCard.d.ts +15 -4
- package/dist/components/Dashboard/TileFilterTag.d.ts +12 -0
- package/dist/components/Dashboard/index.d.ts +3 -0
- package/dist/components/Dashboard/telemetry.d.ts +15 -3
- package/dist/components/DashboardBuilder/AddTileDialog.d.ts +8 -1
- package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +16 -5
- package/dist/components/DashboardBuilder/ChartPicker.d.ts +29 -0
- package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +48 -21
- package/dist/components/DashboardBuilder/DashboardEditor.d.ts +17 -4
- package/dist/components/DashboardBuilder/DiffDialog.d.ts +2 -10
- package/dist/components/DashboardBuilder/FilterDialog.d.ts +2 -2
- package/dist/components/DashboardBuilder/FilterStrip.d.ts +3 -1
- 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/SaveNotice.d.ts +27 -0
- package/dist/components/DashboardBuilder/SettingsPopover.d.ts +19 -7
- package/dist/components/DashboardBuilder/SourceViewPicker.d.ts +9 -0
- package/dist/components/DashboardBuilder/TextTileBody.d.ts +7 -0
- package/dist/components/DashboardBuilder/TileFrame.d.ts +14 -12
- package/dist/components/DashboardBuilder/TileMenu.d.ts +11 -3
- package/dist/components/DashboardBuilder/annotationText.d.ts +4 -0
- package/dist/components/DashboardBuilder/catalog.d.ts +4 -0
- 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/legacyNotebook.d.ts +73 -0
- package/dist/components/DashboardBuilder/loadMalloy.d.ts +15 -0
- package/dist/components/DashboardBuilder/malloyText.d.ts +45 -5
- 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 +4 -1
- package/dist/components/DashboardBuilder/readForEditor.d.ts +16 -0
- package/dist/components/DashboardBuilder/sortable.d.ts +14 -0
- package/dist/components/DashboardBuilder/spliceDocument.d.ts +13 -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/useBuilderSession.d.ts +89 -0
- package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +9 -6
- package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +17 -55
- package/dist/components/DashboardBuilder/useDocumentEditor.d.ts +105 -0
- package/dist/components/DashboardBuilder/useExitGuard.d.ts +19 -0
- package/dist/components/DashboardBuilder/useFilterForm.d.ts +3 -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/NarrowEditGate.d.ts +8 -0
- package/dist/components/Notebook/Notebook.d.ts +1 -1
- package/dist/components/Package/NewDocumentDialog.d.ts +33 -0
- package/dist/components/Package/Package.d.ts +1 -0
- package/dist/components/Package/documentLocation.d.ts +28 -0
- package/dist/components/Package/index.d.ts +4 -0
- package/dist/components/Package/useDocumentLocation.d.ts +12 -0
- package/dist/components/PackageSection.d.ts +2 -2
- 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/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/index.d.ts +2 -0
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/useNarrowScreen.d.ts +4 -0
- package/dist/hooks/useQueryResult.d.ts +2 -0
- package/dist/hooks/useSettled.d.ts +14 -0
- package/dist/index.cjs.js +23 -24
- package/dist/index.es.js +9714 -7072
- 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-CbbBcZl8.es.js +196 -0
- package/dist/text-entry.d.ts +2 -0
- package/dist/utils/clock.d.ts +2 -0
- package/package.json +10 -1
- package/src/builder-entry.ts +35 -0
- package/src/components/Dashboard/Dashboard.tsx +27 -278
- package/src/components/Dashboard/DashboardGrid.tsx +68 -7
- package/src/components/Dashboard/DashboardTile.spec.tsx +24 -0
- package/src/components/Dashboard/DashboardTile.tsx +31 -4
- package/src/components/Dashboard/DashboardView.spec.tsx +212 -0
- package/src/components/Dashboard/DashboardView.tsx +352 -0
- package/src/components/Dashboard/RowsDialog.tsx +1 -1
- package/src/components/Dashboard/TileCard.tsx +44 -10
- 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/index.ts +3 -0
- package/src/components/Dashboard/telemetry.ts +16 -5
- package/src/components/DashboardBuilder/AddTileDialog.spec.tsx +88 -0
- package/src/components/DashboardBuilder/AddTileDialog.tsx +137 -111
- package/src/components/DashboardBuilder/BuilderToolbar.tsx +85 -27
- 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 +153 -0
- package/src/components/DashboardBuilder/DashboardBuilder.charts.spec.tsx +205 -0
- package/src/components/DashboardBuilder/DashboardBuilder.exit.spec.tsx +192 -0
- package/src/components/DashboardBuilder/DashboardBuilder.inline.spec.tsx +329 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notebook.spec.tsx +363 -0
- package/src/components/DashboardBuilder/DashboardBuilder.notice.spec.tsx +194 -0
- package/src/components/DashboardBuilder/DashboardBuilder.openDraft.spec.tsx +157 -0
- package/src/components/DashboardBuilder/DashboardBuilder.sources.spec.tsx +124 -0
- package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +103 -78
- package/src/components/DashboardBuilder/DashboardBuilder.textTiles.spec.tsx +177 -0
- package/src/components/DashboardBuilder/DashboardBuilder.tsx +610 -315
- package/src/components/DashboardBuilder/DashboardEditor.authoritative.spec.tsx +58 -8
- package/src/components/DashboardBuilder/DashboardEditor.emptyStart.spec.tsx +191 -0
- package/src/components/DashboardBuilder/DashboardEditor.filterTag.spec.tsx +162 -0
- package/src/components/DashboardBuilder/DashboardEditor.notebook.spec.tsx +316 -0
- package/src/components/DashboardBuilder/DashboardEditor.package.spec.tsx +56 -10
- package/src/components/DashboardBuilder/DashboardEditor.resourceUri.spec.tsx +5 -22
- package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +96 -14
- package/src/components/DashboardBuilder/DashboardEditor.tsx +482 -332
- package/src/components/DashboardBuilder/DiffDialog.spec.tsx +25 -0
- package/src/components/DashboardBuilder/DiffDialog.tsx +5 -24
- package/src/components/DashboardBuilder/DrillDialog.tsx +1 -1
- package/src/components/DashboardBuilder/FilterDialog.tsx +10 -3
- package/src/components/DashboardBuilder/FilterStrip.tsx +26 -4
- package/src/components/DashboardBuilder/InlineMarkdown.tsx +184 -0
- package/src/components/DashboardBuilder/InlineText.tsx +106 -0
- package/src/components/DashboardBuilder/NotebookEditor.tsx +44 -0
- package/src/components/DashboardBuilder/SaveNotice.tsx +113 -0
- package/src/components/DashboardBuilder/SettingsPopover.spec.tsx +87 -0
- package/src/components/DashboardBuilder/SettingsPopover.tsx +225 -67
- package/src/components/DashboardBuilder/SourceViewPicker.tsx +122 -0
- package/src/components/DashboardBuilder/TextTileBody.tsx +28 -0
- package/src/components/DashboardBuilder/TileFrame.tsx +89 -115
- package/src/components/DashboardBuilder/TileMenu.tsx +168 -90
- 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 +41 -0
- package/src/components/DashboardBuilder/catalog.aggregate.spec.ts +49 -0
- package/src/components/DashboardBuilder/catalog.spec.ts +2 -0
- package/src/components/DashboardBuilder/catalog.ts +61 -21
- 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 +257 -0
- package/src/components/DashboardBuilder/emptyStart.spec.ts +131 -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/malloyText.spec.ts +48 -0
- package/src/components/DashboardBuilder/malloyText.ts +181 -27
- package/src/components/DashboardBuilder/malloyTree.ts +155 -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 +139 -27
- package/src/components/DashboardBuilder/readDocument.ts +130 -44
- package/src/components/DashboardBuilder/readForEditor.spec.ts +80 -0
- package/src/components/DashboardBuilder/readForEditor.ts +47 -0
- package/src/components/DashboardBuilder/scannerShapes.spec.ts +14 -13
- package/src/components/DashboardBuilder/sortable.spec.ts +65 -0
- package/src/components/DashboardBuilder/sortable.tsx +2 -12
- 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 +762 -130
- 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 +197 -0
- package/src/components/DashboardBuilder/testing/fixtures.ts +16 -1
- package/src/components/DashboardBuilder/testing/inline.ts +25 -0
- package/src/components/DashboardBuilder/textTiles.spec.ts +718 -0
- package/src/components/DashboardBuilder/useBuilderSession.spec.ts +335 -0
- package/src/components/DashboardBuilder/useBuilderSession.ts +292 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.overlay.spec.tsx +65 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.spec.tsx +60 -0
- package/src/components/DashboardBuilder/useBuilderShortcuts.ts +36 -10
- package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +16 -13
- package/src/components/DashboardBuilder/useDashboardEditor.ts +54 -181
- package/src/components/DashboardBuilder/useDocumentEditor.spec.ts +565 -0
- package/src/components/DashboardBuilder/useDocumentEditor.ts +399 -0
- 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/useTileReorder.spec.tsx +28 -5
- package/src/components/DashboardBuilder/useTileReorder.ts +5 -7
- 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/Model/ModelExplorer.spec.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 +66 -27
- 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 +190 -0
- package/src/components/Package/Package.create.spec.tsx +380 -0
- package/src/components/Package/Package.notebooks.spec.tsx +18 -0
- package/src/components/Package/Package.tsx +366 -171
- package/src/components/Package/documentLocation.spec.ts +81 -0
- package/src/components/Package/documentLocation.ts +55 -0
- package/src/components/Package/index.ts +13 -0
- package/src/components/Package/useDocumentLocation.ts +59 -0
- package/src/components/PackageSection.tsx +2 -2
- package/src/components/RenderedResult/RenderedResult.tsx +18 -1
- package/src/components/RenderedResult/ResultContainer.tsx +44 -11
- package/src/components/RenderedResult/ResultPanel.tsx +4 -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/GivensPanel.spec.tsx +6 -6
- package/src/components/given/GivensPanel.tsx +3 -3
- package/src/components/index.ts +2 -0
- package/src/hooks/index.ts +3 -0
- package/src/hooks/useNarrowScreen.ts +21 -0
- package/src/hooks/useQueryResult.ts +16 -0
- package/src/hooks/useSettled.spec.ts +41 -0
- package/src/hooks/useSettled.ts +27 -0
- package/src/mainEntry.spec.ts +145 -0
- package/src/text-entry.ts +12 -0
- package/src/textEntry.spec.ts +118 -0
- package/src/utils/clock.spec.ts +12 -0
- package/src/utils/clock.ts +6 -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/DashboardBuilder/useTileResize.d.ts +0 -29
- package/dist/components/Package/NewDashboardDialog.d.ts +0 -18
- package/src/components/DashboardBuilder/useTileResize.spec.tsx +0 -121
- package/src/components/DashboardBuilder/useTileResize.ts +0 -110
- package/src/components/Package/NewDashboardDialog.spec.tsx +0 -129
- package/src/components/Package/NewDashboardDialog.tsx +0 -265
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/** What a writer hands back: the patched file, or why it refused to write one. */
|
|
5
|
+
|
|
6
|
+
export interface SpliceFailure {
|
|
7
|
+
ok: false;
|
|
8
|
+
reason: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type SpliceResult = { ok: true; source: string } | SpliceFailure;
|
|
12
|
+
|
|
13
|
+
/** Narrow to the failure arm; see `readFailed` in `readDocument.ts` for why a guard. */
|
|
14
|
+
export const spliceFailed = (result: SpliceResult): result is SpliceFailure =>
|
|
15
|
+
result.ok === false;
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { describe, expect, it } from "bun:test";
|
|
5
5
|
import { openDocument, refused, spliced } from "./testing/fixtures";
|
|
6
6
|
import { syntaxErrors } from "./spliceDocument";
|
|
7
|
+
import { queryTile } from "./testing/fixtures";
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* Malloy's unit is the statement; every scan in this directory works a line at
|
|
@@ -37,7 +38,7 @@ ${stage}
|
|
|
37
38
|
// builder has to declare off limits.
|
|
38
39
|
it("reads every clause of a continued list", async () => {
|
|
39
40
|
const d = await openDocument(CONTINUED_LIST);
|
|
40
|
-
expect(d
|
|
41
|
+
expect(queryTile(d, 0).filters).toEqual([
|
|
41
42
|
{ field: "a", given: "A" },
|
|
42
43
|
{ field: "b", given: "B" },
|
|
43
44
|
]);
|
|
@@ -45,7 +46,7 @@ ${stage}
|
|
|
45
46
|
|
|
46
47
|
it("does not read a continued predicate as a binding", async () => {
|
|
47
48
|
const d = await openDocument(CONTINUED_PREDICATE);
|
|
48
|
-
expect(d
|
|
49
|
+
expect(queryTile(d, 0).filters).toBeUndefined();
|
|
49
50
|
});
|
|
50
51
|
|
|
51
52
|
// Unticking used to delete the first line and leave `b ~ $B` behind as a
|
|
@@ -53,7 +54,7 @@ ${stage}
|
|
|
53
54
|
// aggregate beside it does not.
|
|
54
55
|
it("removes a continued clause list whole when the tile is unbound", async () => {
|
|
55
56
|
const out = await spliced(CONTINUED_LIST, (d) => {
|
|
56
|
-
delete d
|
|
57
|
+
delete queryTile(d, 0).filters;
|
|
57
58
|
d.tiles[0].colspan = 4;
|
|
58
59
|
});
|
|
59
60
|
expect(out).not.toContain("where:");
|
|
@@ -66,7 +67,7 @@ ${stage}
|
|
|
66
67
|
// all -- the half-read that stranded text on `main`.
|
|
67
68
|
it("drops one clause of a continued list and keeps the other", async () => {
|
|
68
69
|
const out = await spliced(CONTINUED_LIST, (d) => {
|
|
69
|
-
d
|
|
70
|
+
queryTile(d, 0).filters = [{ field: "a", given: "A" }];
|
|
70
71
|
});
|
|
71
72
|
expect(out).toContain(" where: a ~ $A\n aggregate: n is count()");
|
|
72
73
|
expect(out).not.toContain("b ~ $B");
|
|
@@ -78,7 +79,7 @@ ${stage}
|
|
|
78
79
|
// unmanaged, and the control would silently stop filtering.
|
|
79
80
|
it("still reads a binding whose line ends in a separator comma", async () => {
|
|
80
81
|
const d = await openDocument(body(" where: a ~ $A,"));
|
|
81
|
-
expect(d
|
|
82
|
+
expect(queryTile(d, 0).filters).toEqual([{ field: "a", given: "A" }]);
|
|
82
83
|
});
|
|
83
84
|
|
|
84
85
|
it("still reads one where the comma is the last thing in the stage", async () => {
|
|
@@ -93,12 +94,12 @@ source: a is one extend {
|
|
|
93
94
|
}
|
|
94
95
|
}`;
|
|
95
96
|
const d = await openDocument(trailing);
|
|
96
|
-
expect(d
|
|
97
|
+
expect(queryTile(d, 0).filters).toEqual([{ field: "a", given: "A" }]);
|
|
97
98
|
});
|
|
98
99
|
|
|
99
100
|
it("leaves a continued predicate whole when the tile changes", async () => {
|
|
100
101
|
const out = await spliced(CONTINUED_PREDICATE, (d) => {
|
|
101
|
-
delete d
|
|
102
|
+
delete queryTile(d, 0).filters;
|
|
102
103
|
d.tiles[0].colspan = 4;
|
|
103
104
|
});
|
|
104
105
|
expect(out).toContain(" where: a ~ $A\n and c = 1");
|
|
@@ -124,7 +125,7 @@ source: a is one extend {
|
|
|
124
125
|
|
|
125
126
|
it("does not read it as a binding", async () => {
|
|
126
127
|
const d = await openDocument(COMPOUND);
|
|
127
|
-
expect(d
|
|
128
|
+
expect(queryTile(d, 0).filters).toBeUndefined();
|
|
128
129
|
});
|
|
129
130
|
|
|
130
131
|
it("survives an unrelated change to the tile", async () => {
|
|
@@ -138,7 +139,7 @@ source: a is one extend {
|
|
|
138
139
|
// managed clause for it would filter on $A twice.
|
|
139
140
|
it("refuses to bind a given it already filters on", async () => {
|
|
140
141
|
const reason = await refused(COMPOUND, (d) => {
|
|
141
|
-
d
|
|
142
|
+
queryTile(d, 0).filters = [{ field: "a2", given: "A" }];
|
|
142
143
|
});
|
|
143
144
|
expect(reason).toContain("already filters on `$A`");
|
|
144
145
|
});
|
|
@@ -147,7 +148,7 @@ source: a is one extend {
|
|
|
147
148
|
// clause, because Malloy rejects a comma after some statement forms.
|
|
148
149
|
it("keeps the compound when a different given is bound", async () => {
|
|
149
150
|
const out = await spliced(COMPOUND, (d) => {
|
|
150
|
-
d
|
|
151
|
+
queryTile(d, 0).filters = [{ field: "b", given: "B" }];
|
|
151
152
|
});
|
|
152
153
|
expect(out).toContain("vx + { where: a ~ $A and c = 1 where: b ~ $B }");
|
|
153
154
|
});
|
|
@@ -176,12 +177,12 @@ ${declaration}
|
|
|
176
177
|
|
|
177
178
|
it("does not read a filtered measure's predicate as a tile filter", async () => {
|
|
178
179
|
const d = await openDocument(MEASURE);
|
|
179
|
-
expect(d
|
|
180
|
+
expect(queryTile(d, 0).filters).toBeUndefined();
|
|
180
181
|
});
|
|
181
182
|
|
|
182
183
|
it("does not delete that predicate when the tile is edited", async () => {
|
|
183
184
|
const out = await spliced(MEASURE, (d) => {
|
|
184
|
-
delete d
|
|
185
|
+
delete queryTile(d, 0).filters;
|
|
185
186
|
d.tiles[0].colspan = 4;
|
|
186
187
|
});
|
|
187
188
|
expect(out).toContain("aggregate: big is count() { where: amt > $MIN }");
|
|
@@ -189,7 +190,7 @@ ${declaration}
|
|
|
189
190
|
|
|
190
191
|
it("does not read a nest's own where: as a tile filter", async () => {
|
|
191
192
|
const d = await openDocument(NESTED);
|
|
192
|
-
expect(d
|
|
193
|
+
expect(queryTile(d, 0).filters).toBeUndefined();
|
|
193
194
|
});
|
|
194
195
|
|
|
195
196
|
// This one used to LIFT the nest's filter out to tile level on an edit that
|
|
@@ -221,7 +222,7 @@ source: a is one extend {
|
|
|
221
222
|
// rather than doubling it, which is the outcome the refusal stood in for.
|
|
222
223
|
it("rebinds a given used only on a continuation line, without doubling it", async () => {
|
|
223
224
|
const out = await spliced(CONTINUED, (d) => {
|
|
224
|
-
d
|
|
225
|
+
queryTile(d, 0).filters = [{ field: "b2", given: "B" }];
|
|
225
226
|
});
|
|
226
227
|
expect(out.match(/\$B\b/g)).toHaveLength(1);
|
|
227
228
|
expect(out).toContain(" where: b2 ~ $B");
|
|
@@ -239,7 +240,7 @@ source: a is one extend {
|
|
|
239
240
|
view: kpis is vx + { where: label = 'costs $B' }
|
|
240
241
|
}`,
|
|
241
242
|
(d) => {
|
|
242
|
-
d
|
|
243
|
+
queryTile(d, 0).filters = [{ field: "b", given: "B" }];
|
|
243
244
|
},
|
|
244
245
|
);
|
|
245
246
|
expect(out).toContain("where: label = 'costs $B'");
|
|
@@ -297,7 +298,7 @@ ${stage}
|
|
|
297
298
|
const reason = await refused(
|
|
298
299
|
body(" // don't remove\n where: b ~ $B and c = 1"),
|
|
299
300
|
(d) => {
|
|
300
|
-
d
|
|
301
|
+
queryTile(d, 0).filters = [{ field: "b2", given: "B" }];
|
|
301
302
|
},
|
|
302
303
|
);
|
|
303
304
|
expect(reason).toContain("already filters on `$B`");
|
|
@@ -307,7 +308,7 @@ ${stage}
|
|
|
307
308
|
const out = await spliced(
|
|
308
309
|
body(" // TODO: maybe filter on $B later\n group_by: c"),
|
|
309
310
|
(d) => {
|
|
310
|
-
d
|
|
311
|
+
queryTile(d, 0).filters = [{ field: "b", given: "B" }];
|
|
311
312
|
},
|
|
312
313
|
);
|
|
313
314
|
expect(out).toContain("where: b ~ $B");
|
|
@@ -321,7 +322,9 @@ ${stage}
|
|
|
321
322
|
const out = await spliced(
|
|
322
323
|
body(" where: amt > $MIN\n group_by: big is amt > $MIN"),
|
|
323
324
|
(d) => {
|
|
324
|
-
d
|
|
325
|
+
queryTile(d, 0).filters = [
|
|
326
|
+
{ field: "amt", given: "MIN", op: ">=" },
|
|
327
|
+
];
|
|
325
328
|
},
|
|
326
329
|
);
|
|
327
330
|
expect(out).toContain("where: amt >= $MIN");
|
|
@@ -347,7 +350,7 @@ source: a is one extend {
|
|
|
347
350
|
|
|
348
351
|
it("does not report a partial filter set", async () => {
|
|
349
352
|
const d = await openDocument(CHAINED);
|
|
350
|
-
expect(d
|
|
353
|
+
expect(queryTile(d, 0).filters).toBeUndefined();
|
|
351
354
|
});
|
|
352
355
|
|
|
353
356
|
// Declared HERE, in a body with no one block a binding belongs in. Saying
|
|
@@ -357,7 +360,7 @@ source: a is one extend {
|
|
|
357
360
|
const d = await openDocument(
|
|
358
361
|
CHAINED.replace(" view: kpis", " # colspan=6\n view: kpis"),
|
|
359
362
|
);
|
|
360
|
-
expect(d
|
|
363
|
+
expect(queryTile(d, 0).declaration).toEqual({
|
|
361
364
|
kind: "opaque",
|
|
362
365
|
why: "a chained refinement",
|
|
363
366
|
});
|
|
@@ -375,7 +378,7 @@ source: a is one extend {
|
|
|
375
378
|
// given already filtered on in the other would be bound a second time.
|
|
376
379
|
it("refuses a filter change rather than writing into one block", async () => {
|
|
377
380
|
const reason = await refused(CHAINED, (d) => {
|
|
378
|
-
d
|
|
381
|
+
queryTile(d, 0).filters = [{ field: "n", given: "N" }];
|
|
379
382
|
});
|
|
380
383
|
expect(reason).toContain("chained refinement");
|
|
381
384
|
// The view is declared right here; blaming the model would send whoever
|
|
@@ -403,12 +406,12 @@ source: a is one extend {
|
|
|
403
406
|
|
|
404
407
|
it("reads as declared here, with a reason, and keeps its tags", async () => {
|
|
405
408
|
const d = await openDocument(PIPELINE);
|
|
406
|
-
expect(d
|
|
409
|
+
expect(queryTile(d, 0).declaration).toEqual({
|
|
407
410
|
kind: "opaque",
|
|
408
411
|
why: "a `->` pipeline from a named view",
|
|
409
412
|
});
|
|
410
413
|
expect(d.tiles[0].colspan).toBe(6);
|
|
411
|
-
expect(d
|
|
414
|
+
expect(queryTile(d, 0).filters).toBeUndefined();
|
|
412
415
|
});
|
|
413
416
|
|
|
414
417
|
it("survives an unrelated change untouched", async () => {
|
|
@@ -421,7 +424,7 @@ source: a is one extend {
|
|
|
421
424
|
|
|
422
425
|
it("refuses a filter change rather than writing into a stage", async () => {
|
|
423
426
|
const reason = await refused(PIPELINE, (d) => {
|
|
424
|
-
d
|
|
427
|
+
queryTile(d, 0).filters = [{ field: "n", given: "N" }];
|
|
425
428
|
});
|
|
426
429
|
expect(reason).toContain("pipeline");
|
|
427
430
|
expect(reason).not.toContain("declared on its source");
|
|
@@ -451,7 +454,7 @@ source: a is one extend {
|
|
|
451
454
|
}
|
|
452
455
|
}`,
|
|
453
456
|
(d) => {
|
|
454
|
-
d
|
|
457
|
+
queryTile(d, 0).filters = [{ field: "b", given: "B" }];
|
|
455
458
|
},
|
|
456
459
|
);
|
|
457
460
|
expect(reason).toContain("// keep");
|
|
@@ -472,7 +475,7 @@ source: a is one extend {
|
|
|
472
475
|
}
|
|
473
476
|
}`,
|
|
474
477
|
(d) => {
|
|
475
|
-
delete d
|
|
478
|
+
delete queryTile(d, 0).filters;
|
|
476
479
|
},
|
|
477
480
|
);
|
|
478
481
|
expect(reason).toContain("// why both");
|
|
@@ -490,7 +493,7 @@ source: a is one extend {
|
|
|
490
493
|
}
|
|
491
494
|
}`,
|
|
492
495
|
(d) => {
|
|
493
|
-
delete d
|
|
496
|
+
delete queryTile(d, 0).filters;
|
|
494
497
|
},
|
|
495
498
|
);
|
|
496
499
|
expect(reason).toContain("// only this quarter");
|
|
@@ -509,7 +512,7 @@ source: a is one extend {
|
|
|
509
512
|
}
|
|
510
513
|
}`,
|
|
511
514
|
(d) => {
|
|
512
|
-
d
|
|
515
|
+
queryTile(d, 0).filters = [{ field: "b", given: "B" }];
|
|
513
516
|
},
|
|
514
517
|
);
|
|
515
518
|
expect(reason).toContain("/* keep both */");
|
|
@@ -524,7 +527,7 @@ source: a is one extend {
|
|
|
524
527
|
+ { where: a ~ $A }
|
|
525
528
|
}`,
|
|
526
529
|
(d) => {
|
|
527
|
-
delete d
|
|
530
|
+
delete queryTile(d, 0).filters;
|
|
528
531
|
},
|
|
529
532
|
);
|
|
530
533
|
expect(reason).toContain("// note");
|
|
@@ -543,7 +546,7 @@ source: a is one extend {
|
|
|
543
546
|
}
|
|
544
547
|
}`,
|
|
545
548
|
(d) => {
|
|
546
|
-
d
|
|
549
|
+
queryTile(d, 0).filters = [{ field: "b", given: "B" }];
|
|
547
550
|
},
|
|
548
551
|
);
|
|
549
552
|
expect(out).toContain(
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { conversionRefused, convertLegacyNotebook } from "./legacyNotebook";
|
|
6
|
+
import { quoteFilterLiterals } from "./tagParse";
|
|
7
|
+
import { readDashboardDocument, readFailed } from "./readDocument";
|
|
8
|
+
import { spliceDashboardDocument, spliceFailed } from "./spliceDocument";
|
|
9
|
+
|
|
10
|
+
const BODY = `import "../models/orders.malloy"
|
|
11
|
+
|
|
12
|
+
source: orders_tiles is orders extend {
|
|
13
|
+
view: by_cat is by_category
|
|
14
|
+
}
|
|
15
|
+
`;
|
|
16
|
+
const LINE = `##! experimental.givens
|
|
17
|
+
## artifact { title="T" tiles=["orders_tiles -> by_cat"] autorun=false givens { REGION=f'US' } }
|
|
18
|
+
${BODY}`;
|
|
19
|
+
const BLOCK = `##! experimental.givens
|
|
20
|
+
##| artifact { title="T" tiles=["orders_tiles -> by_cat"]
|
|
21
|
+
autorun=false
|
|
22
|
+
givens { REGION=f'US' }
|
|
23
|
+
}
|
|
24
|
+
|##
|
|
25
|
+
${BODY}`;
|
|
26
|
+
const LEGACY = (tag: string) => `##! experimental.givens
|
|
27
|
+
${tag}
|
|
28
|
+
import "../models/orders.malloy"
|
|
29
|
+
|
|
30
|
+
##(markdown) Hello
|
|
31
|
+
|
|
32
|
+
run: orders -> kpis
|
|
33
|
+
`;
|
|
34
|
+
|
|
35
|
+
describe("filter-literal givens in the artifact tag", () => {
|
|
36
|
+
for (const [name, text] of [
|
|
37
|
+
["line", LINE],
|
|
38
|
+
["block", BLOCK],
|
|
39
|
+
]) {
|
|
40
|
+
it(`reads the ${name} form`, async () => {
|
|
41
|
+
const read = await readDashboardDocument(text);
|
|
42
|
+
if (readFailed(read)) throw new Error(read.reason);
|
|
43
|
+
expect(read.document.startingGivens).toEqual({ REGION: "f'US'" });
|
|
44
|
+
expect(read.document.autorun).toBe(false);
|
|
45
|
+
expect(read.document.tiles.map((t) => t.name)).toEqual(["by_cat"]);
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it(`round-trips the ${name} form byte for byte`, async () => {
|
|
49
|
+
const read = await readDashboardDocument(text);
|
|
50
|
+
if (readFailed(read)) throw new Error(read.reason);
|
|
51
|
+
const out = await spliceDashboardDocument(text, {
|
|
52
|
+
...read.document,
|
|
53
|
+
title: "T",
|
|
54
|
+
});
|
|
55
|
+
if (spliceFailed(out)) throw new Error(out.reason);
|
|
56
|
+
expect(out.source).toBe(text);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const [name, tag] of [
|
|
61
|
+
[
|
|
62
|
+
"line",
|
|
63
|
+
"## artifact { kind=notebook autorun=false givens { REGION=f'US' } }",
|
|
64
|
+
],
|
|
65
|
+
[
|
|
66
|
+
"block",
|
|
67
|
+
"##| artifact { kind=notebook\n autorun=false\n givens { REGION=f'US' }\n}\n|##",
|
|
68
|
+
],
|
|
69
|
+
]) {
|
|
70
|
+
it(`converts a legacy notebook with the ${name} tag and keeps the literal as written`, async () => {
|
|
71
|
+
const result = await convertLegacyNotebook(LEGACY(tag));
|
|
72
|
+
if (conversionRefused(result)) throw new Error(result.refused);
|
|
73
|
+
expect(result.text).toContain("givens { REGION=f'US' }");
|
|
74
|
+
const read = await readDashboardDocument(result.text);
|
|
75
|
+
if (readFailed(read)) throw new Error(read.reason);
|
|
76
|
+
expect(read.document.startingGivens).toEqual({ REGION: "f'US'" });
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
it("reads a legacy notebook with a filter literal as a legacy notebook", async () => {
|
|
81
|
+
const read = await readDashboardDocument(
|
|
82
|
+
LEGACY(
|
|
83
|
+
"## artifact { kind=notebook autorun=false givens { REGION=f'US' } }",
|
|
84
|
+
),
|
|
85
|
+
);
|
|
86
|
+
if (!readFailed(read)) throw new Error("expected a refusal");
|
|
87
|
+
expect(read.legacyNotebook).toBe(true);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it("surfaces the tag's own syntax error when it does not parse", async () => {
|
|
91
|
+
const read = await readDashboardDocument(
|
|
92
|
+
LINE.replace("tiles=[", "tiles=[[[[").replace("autorun=false", "="),
|
|
93
|
+
);
|
|
94
|
+
if (!readFailed(read)) throw new Error("expected a refusal");
|
|
95
|
+
expect(read.reason).toContain("does not parse");
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("a filter literal holding a quote", () => {
|
|
100
|
+
const QUOTED = LINE.replace("f'US'", `f"it's"`);
|
|
101
|
+
|
|
102
|
+
it("reads as the wrapped body, and a givens edit re-emits it quoted, reading back the same", async () => {
|
|
103
|
+
const read = await readDashboardDocument(QUOTED);
|
|
104
|
+
if (readFailed(read)) throw new Error(read.reason);
|
|
105
|
+
expect(read.document.startingGivens).toEqual({ REGION: "f'it's'" });
|
|
106
|
+
const out = await spliceDashboardDocument(QUOTED, {
|
|
107
|
+
...read.document,
|
|
108
|
+
startingGivens: { ...read.document.startingGivens, OTHER: "x" },
|
|
109
|
+
});
|
|
110
|
+
if (spliceFailed(out)) throw new Error(out.reason);
|
|
111
|
+
// The bare f"…" spelling does not survive an edit of the givens block.
|
|
112
|
+
expect(out.source).toContain(`givens { REGION="f'it's'" OTHER="x" }`);
|
|
113
|
+
const again = await readDashboardDocument(out.source);
|
|
114
|
+
if (readFailed(again)) throw new Error(again.reason);
|
|
115
|
+
expect(again.document.startingGivens).toEqual({
|
|
116
|
+
REGION: "f'it's'",
|
|
117
|
+
OTHER: "x",
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("leaves the spelling alone when the givens are not what changed", async () => {
|
|
122
|
+
const read = await readDashboardDocument(QUOTED);
|
|
123
|
+
if (readFailed(read)) throw new Error(read.reason);
|
|
124
|
+
const out = await spliceDashboardDocument(QUOTED, {
|
|
125
|
+
...read.document,
|
|
126
|
+
title: "T",
|
|
127
|
+
});
|
|
128
|
+
if (spliceFailed(out)) throw new Error(out.reason);
|
|
129
|
+
expect(out.source).toBe(QUOTED);
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
describe("a tag value Tag.text() throws on", () => {
|
|
134
|
+
it("is refused with a reason rather than thrown, so the editor can say why", async () => {
|
|
135
|
+
const read = await readDashboardDocument(
|
|
136
|
+
LINE.replace("f'US'", "@2024-13-01"),
|
|
137
|
+
);
|
|
138
|
+
if (!readFailed(read)) throw new Error("expected a refusal");
|
|
139
|
+
expect(read.reason).toContain("cannot be read");
|
|
140
|
+
});
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
describe("quoteFilterLiterals", () => {
|
|
144
|
+
it("quotes bare literals after = [ and , but not inside strings", () => {
|
|
145
|
+
expect(quoteFilterLiterals(`# a=f'US' b=[f'x', f"y"] c="=f'z'"`)).toBe(
|
|
146
|
+
`# a="f'US'" b=["f'x'", "f'y'"] c="=f'z'"`,
|
|
147
|
+
);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/** A MOTLY parse as `parseAnnotation` returns it; only the reads this file makes. */
|
|
5
|
+
type Parsed<T> = { tag: T; log: Array<{ message: string }> };
|
|
6
|
+
type ParseAnnotation<T> = (lines: string[]) => Parsed<T>;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Index just past the delimited region starting at `start` (a quoted string,
|
|
10
|
+
* quoted identifier or heredoc), or `start` when nothing is delimited there.
|
|
11
|
+
* Unterminated regions run to the end so the caller never rewrites inside one.
|
|
12
|
+
*/
|
|
13
|
+
function endOfDelimited(text: string, start: number): number {
|
|
14
|
+
const char = text[start];
|
|
15
|
+
if (char === "`") {
|
|
16
|
+
for (let i = start + 1; i < text.length; i++) {
|
|
17
|
+
if (text[i] === "\\") i++;
|
|
18
|
+
else if (text[i] === "`") return i + 1;
|
|
19
|
+
else if (text[i] === "\n") return text.length;
|
|
20
|
+
}
|
|
21
|
+
return text.length;
|
|
22
|
+
}
|
|
23
|
+
if (text.startsWith("<<<", start)) {
|
|
24
|
+
// Split on `\n` only and compare with `trim()`, as MOTLY does; a `/m` regex also breaks at `\r`.
|
|
25
|
+
let lineStart = start + 3;
|
|
26
|
+
for (;;) {
|
|
27
|
+
const newline = text.indexOf("\n", lineStart);
|
|
28
|
+
const lineEnd = newline === -1 ? text.length : newline;
|
|
29
|
+
if (text.slice(lineStart, lineEnd).trim() === ">>>") return lineEnd;
|
|
30
|
+
if (newline === -1) return text.length;
|
|
31
|
+
lineStart = newline + 1;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (char === '"' || char === "'") {
|
|
35
|
+
const triple = char.repeat(3);
|
|
36
|
+
if (text.startsWith(triple, start)) {
|
|
37
|
+
for (let i = start + 3; i < text.length; i++) {
|
|
38
|
+
if (text[i] === "\\") i++;
|
|
39
|
+
else if (text.startsWith(triple, i)) return i + 3;
|
|
40
|
+
}
|
|
41
|
+
return text.length;
|
|
42
|
+
}
|
|
43
|
+
for (let i = start + 1; i < text.length; i++) {
|
|
44
|
+
if (text[i] === "\\") i++;
|
|
45
|
+
else if (text[i] === char) return i + 1;
|
|
46
|
+
else if (text[i] === "\n") return i;
|
|
47
|
+
}
|
|
48
|
+
return text.length;
|
|
49
|
+
}
|
|
50
|
+
return start;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Quote each bare filter literal (`f'US'`) so MOTLY reads it as a string, as
|
|
55
|
+
* the server does. The rewritten line is never spliced into the file; a changed
|
|
56
|
+
* `givens { … }` block is re-emitted, quoted, from the values parsed out of it.
|
|
57
|
+
*/
|
|
58
|
+
export function quoteFilterLiterals(annotation: string): string {
|
|
59
|
+
const BARE_FILTER_LITERAL = /^([ \t]*)f(['"])((?:\\.|(?!\2)[^\\])*)\2/;
|
|
60
|
+
let out = "";
|
|
61
|
+
let i = 0;
|
|
62
|
+
while (i < annotation.length) {
|
|
63
|
+
const delimited = endOfDelimited(annotation, i);
|
|
64
|
+
if (delimited > i) {
|
|
65
|
+
out += annotation.slice(i, delimited);
|
|
66
|
+
i = delimited;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
const char = annotation[i];
|
|
70
|
+
if (/[=[,]/.test(char)) {
|
|
71
|
+
const match = BARE_FILTER_LITERAL.exec(annotation.slice(i + 1));
|
|
72
|
+
if (match) {
|
|
73
|
+
const body = match[3].replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
74
|
+
out += `${char}${match[1]}"f'${body}'"`;
|
|
75
|
+
i += 1 + match[0].length;
|
|
76
|
+
continue;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
out += char;
|
|
80
|
+
i += 1;
|
|
81
|
+
}
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* `parseAnnotation` that rescues bare filter literals. Parse-first: only a line
|
|
87
|
+
* MOTLY rejects is rewritten, and only kept if the rewrite parses, so a valid
|
|
88
|
+
* tag is never altered. `errors` are the parse messages that remain.
|
|
89
|
+
*/
|
|
90
|
+
export function parseTagLines<T>(
|
|
91
|
+
parseAnnotation: ParseAnnotation<T>,
|
|
92
|
+
lines: string[],
|
|
93
|
+
): { tag: T; errors: string[] } {
|
|
94
|
+
const direct = parseAnnotation(lines);
|
|
95
|
+
if (direct.log.length === 0) return { tag: direct.tag, errors: [] };
|
|
96
|
+
const rescued = lines.map((line) => {
|
|
97
|
+
if (parseAnnotation([line]).log.length === 0) return line;
|
|
98
|
+
const rewritten = quoteFilterLiterals(line);
|
|
99
|
+
return parseAnnotation([rewritten]).log.length === 0 ? rewritten : line;
|
|
100
|
+
});
|
|
101
|
+
const after = parseAnnotation(rescued);
|
|
102
|
+
return { tag: after.tag, errors: after.log.map((e) => e.message) };
|
|
103
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { DashboardEvent } from "../Dashboard/telemetry";
|
|
5
|
+
import type { SavesTo } from "./documentSession";
|
|
6
|
+
import type { NotebookCreatedEvent } from "../DocumentCreate/events";
|
|
7
|
+
|
|
8
|
+
/** What the notebook editor reports about itself, for the host to log; context-free like `DashboardEvent`. A one-column dashboard document reports these too. */
|
|
9
|
+
export type NotebookEvent =
|
|
10
|
+
| {
|
|
11
|
+
type: "notebook.opened";
|
|
12
|
+
/** The package file, or the host's own copy when that copy is the record. */
|
|
13
|
+
from: "package" | "record";
|
|
14
|
+
cells: number;
|
|
15
|
+
durationMs: number;
|
|
16
|
+
}
|
|
17
|
+
| { type: "notebook.open_refused"; reason: string }
|
|
18
|
+
| {
|
|
19
|
+
type: "notebook.saved";
|
|
20
|
+
cells: number;
|
|
21
|
+
where: SavesTo;
|
|
22
|
+
/** The save added or removed a cell. */
|
|
23
|
+
structural: boolean;
|
|
24
|
+
/** The save rewrote a notebook in the cell format as a layout notebook. */
|
|
25
|
+
converted?: boolean;
|
|
26
|
+
/** The host workspace that took the write; never set for a package save. */
|
|
27
|
+
workspace?: string;
|
|
28
|
+
durationMs: number;
|
|
29
|
+
}
|
|
30
|
+
| { type: "notebook.save_refused"; reason: string }
|
|
31
|
+
| {
|
|
32
|
+
/** Undo save wrote the file back as it was before the last save. */
|
|
33
|
+
type: "notebook.save_undone";
|
|
34
|
+
cells: number;
|
|
35
|
+
where: SavesTo;
|
|
36
|
+
/** Whether the save it took back added or removed a cell. */
|
|
37
|
+
structural: boolean;
|
|
38
|
+
workspace?: string;
|
|
39
|
+
durationMs: number;
|
|
40
|
+
}
|
|
41
|
+
| { type: "notebook.save_undo_refused"; reason: string }
|
|
42
|
+
| NotebookCreatedEvent;
|
|
43
|
+
|
|
44
|
+
export type NotebookEventHandler = (event: NotebookEvent) => void;
|
|
45
|
+
|
|
46
|
+
/** Whatever the one builder reports: a notebook-kind document speaks `notebook.*`, a dashboard `dashboard.*`. */
|
|
47
|
+
export type BuilderEvent = DashboardEvent | NotebookEvent;
|