@malloy-publisher/sdk 0.0.382-dev → 0.2.1
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/README.md +115 -95
- package/TREE_SHAKING.md +16 -11
- package/bunfig.toml +7 -0
- package/dist/ServerProvider-Cn_LhKda.cjs.js +1 -0
- package/dist/ServerProvider-sfabtriY.es.js +4076 -0
- package/dist/client/api.d.ts +3773 -1515
- 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 +86 -59
- package/dist/components/Connections/EditConnectionDialog.d.ts +2 -1
- package/dist/components/Connections/common.d.ts +8 -2
- package/dist/components/Dashboard/Dashboard.d.ts +62 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +57 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/DataAppViewer/DataAppViewer.d.ts +23 -0
- package/dist/components/DataAppViewer/index.d.ts +1 -0
- package/dist/components/Environment/Environment.d.ts +6 -0
- package/dist/components/Environment/index.d.ts +2 -0
- package/dist/components/Home/AddEnvironmentDialog.d.ts +1 -0
- package/dist/components/Home/DeleteEnvironmentDialog.d.ts +5 -0
- package/dist/components/Home/EditEnvironmentDialog.d.ts +7 -0
- package/dist/components/Home/Home.d.ts +2 -2
- package/dist/components/Materializations/CreateEnvMaterializationDialog.d.ts +14 -0
- package/dist/components/Materializations/CreateMaterializationDialog.d.ts +10 -0
- package/dist/components/Materializations/DeleteMaterializationDialog.d.ts +7 -0
- package/dist/components/Materializations/EnvironmentMaterializations.d.ts +7 -0
- package/dist/components/Materializations/ManifestView.d.ts +13 -0
- package/dist/components/Materializations/MaterializationDetailDialog.d.ts +9 -0
- package/dist/components/Materializations/MaterializationRunsList.d.ts +15 -0
- package/dist/components/Materializations/Materializations.d.ts +7 -0
- package/dist/components/Materializations/ScheduleCard.d.ts +20 -0
- package/dist/components/Materializations/SectionLabel.d.ts +10 -0
- package/dist/components/Materializations/SetScheduleDialog.d.ts +11 -0
- package/dist/components/Materializations/TriggerChip.d.ts +10 -0
- package/dist/components/Materializations/cron.d.ts +23 -0
- package/dist/components/Materializations/index.d.ts +2 -0
- package/dist/components/Materializations/utils.d.ts +46 -0
- package/dist/components/Notebook/Notebook.d.ts +47 -4
- package/dist/components/Notebook/NotebookCell.d.ts +37 -1
- package/dist/components/Notebook/runPlan.d.ts +29 -0
- package/dist/components/Notebook/types.d.ts +10 -0
- package/dist/components/Package/ContentTypeIcon.d.ts +31 -0
- package/dist/components/Package/Package.d.ts +1 -4
- package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +5 -1
- package/dist/components/RenderedResult/renderLogs.d.ts +6 -0
- package/dist/components/ResultsDialog.d.ts +6 -1
- package/dist/components/ServerProvider.d.ts +28 -4
- package/dist/components/click_helper.d.ts +10 -1
- package/dist/components/drill/index.d.ts +3 -0
- package/dist/components/drill/markDrillableCells.d.ts +55 -0
- package/dist/components/drill/resolveDrill.d.ts +139 -0
- package/dist/components/drill/useDrill.d.ts +63 -0
- package/dist/components/given/GivenInput.d.ts +52 -0
- package/dist/components/given/GivensPanel.d.ts +47 -0
- package/dist/components/given/filterValue.d.ts +97 -0
- package/dist/components/given/index.d.ts +2 -0
- package/dist/components/given/paramCodec.d.ts +60 -0
- package/dist/components/given/utils.d.ts +17 -0
- package/dist/components/highlighter.d.ts +6 -1
- package/dist/components/index.d.ts +7 -2
- package/dist/components/styles.d.ts +47 -0
- package/dist/constants/docLinks.d.ts +12 -0
- package/dist/{core-YNpOLuB1.cjs.js → core-CqRKhtoy.cjs.js} +1 -1
- package/dist/{core-CjeTkq8O.es.js → core-DyU47reh.es.js} +1 -1
- package/dist/github-dark-BKL9xNgN.cjs.js +1 -0
- package/dist/github-dark-DenFmJkN.es.js +4 -0
- package/dist/hooks/givenValue.d.ts +10 -0
- package/dist/hooks/index.d.ts +4 -0
- package/dist/hooks/useDimensionFiltersFromSpec.d.ts +3 -3
- package/dist/hooks/useDimensionFiltersQuery.d.ts +3 -3
- package/dist/hooks/useDimensionalFilterRangeData.d.ts +4 -4
- package/dist/hooks/useGivensState.d.ts +64 -0
- package/dist/hooks/useModelGivens.d.ts +10 -0
- package/dist/hooks/useSuggestOptions.d.ts +78 -0
- package/dist/{index-DRDu9kIV.es.js → index-CAkFE4Ol.es.js} +41278 -28504
- package/dist/index-DD4b_bt0.cjs.js +356 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.es.js +79 -48
- package/dist/malloy-explorer.css +12 -1
- package/dist/sdk.css +1 -1
- package/dist/theme/ThemeContext.d.ts +45 -0
- package/dist/theme/buildMalloyExplicitTheme.d.ts +34 -0
- package/dist/theme/buildTableCssVars.d.ts +41 -0
- package/dist/theme/buildVegaThemeOverride.d.ts +16 -0
- package/dist/theme/defaults.d.ts +7 -0
- package/dist/theme/index.d.ts +8 -0
- package/dist/theme/keys.d.ts +20 -0
- package/dist/theme/readChartAnnotations.d.ts +23 -0
- package/dist/theme/resolveTheme.d.ts +22 -0
- package/dist/theme/types.d.ts +70 -0
- package/dist/utils/dataAppEmbed.d.ts +44 -0
- package/dist/utils/formatting.d.ts +1 -1
- package/dist/utils/malloyString.d.ts +7 -0
- package/dist/utils/parsing.d.ts +2 -2
- package/dist/utils/queryClient.d.ts +5 -0
- package/package.json +19 -8
- package/src/client-entry.ts +3 -0
- package/src/components/AnalyzePackageButton.tsx +9 -3
- package/src/components/ApiErrorDisplay.tsx +3 -0
- package/src/components/Connections/AddConnectionDialog.tsx +132 -25
- package/src/components/Connections/DeleteConnectionDialog.tsx +14 -3
- package/src/components/Connections/EditConnectionDialog.tsx +167 -37
- package/src/components/Connections/common.ts +94 -3
- package/src/components/DOMElement/DOMElement.tsx +3 -0
- package/src/components/DOMElement/index.ts +3 -0
- package/src/components/Dashboard/Dashboard.spec.tsx +216 -0
- package/src/components/Dashboard/Dashboard.tsx +458 -0
- package/src/components/Dashboard/DashboardTile.spec.tsx +81 -0
- package/src/components/Dashboard/DashboardTile.tsx +199 -0
- package/src/components/Dashboard/index.ts +5 -0
- package/src/components/Dashboard/tileGridColumn.spec.ts +35 -0
- package/src/components/DataAppViewer/DataAppViewer.tsx +214 -0
- package/src/components/DataAppViewer/index.ts +4 -0
- package/src/components/{Project → Environment}/About.tsx +11 -4
- package/src/components/Environment/AddPackageDialog.tsx +202 -0
- package/src/components/{Project → Environment}/ConnectionExplorer.tsx +17 -14
- package/src/components/Environment/Connections.tsx +391 -0
- package/src/components/{Project → Environment}/DeletePackageDialog.tsx +8 -4
- package/src/components/{Project → Environment}/EditPackageDialog.tsx +21 -13
- package/src/components/Environment/Environment.tsx +89 -0
- package/src/components/Environment/Packages.tsx +206 -0
- package/src/components/Environment/index.ts +5 -0
- package/src/components/Home/{AddProjectDialog.tsx → AddEnvironmentDialog.tsx} +25 -19
- package/src/components/Home/{DeleteProjectDialog.tsx → DeleteEnvironmentDialog.tsx} +20 -15
- package/src/components/Home/{EditProjectDialog.tsx → EditEnvironmentDialog.tsx} +35 -28
- package/src/components/Home/Home.tsx +386 -408
- package/src/components/Home/index.ts +3 -0
- package/src/components/Loading.tsx +3 -0
- package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +179 -0
- package/src/components/Materializations/CreateMaterializationDialog.tsx +112 -0
- package/src/components/Materializations/DeleteMaterializationDialog.tsx +109 -0
- package/src/components/Materializations/EnvironmentMaterializations.tsx +267 -0
- package/src/components/Materializations/ManifestView.tsx +87 -0
- package/src/components/Materializations/MaterializationDetailDialog.tsx +259 -0
- package/src/components/Materializations/MaterializationRunsList.tsx +256 -0
- package/src/components/Materializations/Materializations.tsx +355 -0
- package/src/components/Materializations/ScheduleCard.tsx +231 -0
- package/src/components/Materializations/SectionLabel.tsx +30 -0
- package/src/components/Materializations/SetScheduleDialog.tsx +162 -0
- package/src/components/Materializations/TriggerChip.tsx +44 -0
- package/src/components/Materializations/cron.ts +124 -0
- package/src/components/Materializations/index.ts +5 -0
- package/src/components/Materializations/utils.ts +145 -0
- package/src/components/Model/Model.tsx +44 -2
- package/src/components/Model/ModelCell.tsx +14 -5
- package/src/components/Model/ModelExplorer.tsx +3 -0
- package/src/components/Model/ModelExplorerDialog.tsx +4 -1
- package/src/components/Model/SourcesExplorer.tsx +9 -6
- package/src/components/Model/index.ts +3 -0
- package/src/components/Model/useModelData.ts +6 -3
- package/src/components/Notebook/Notebook.spec.tsx +88 -0
- package/src/components/Notebook/Notebook.tsx +476 -339
- package/src/components/Notebook/NotebookCell.tsx +264 -25
- package/src/components/Notebook/index.ts +3 -0
- package/src/components/Notebook/runPlan.spec.ts +155 -0
- package/src/components/Notebook/runPlan.ts +67 -0
- package/src/components/Notebook/types.ts +14 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
- package/src/components/Package/ContentTypeIcon.tsx +177 -0
- package/src/components/Package/FileTreeView.tsx +3 -0
- package/src/components/Package/Models.tsx +7 -4
- package/src/components/Package/Package.spec.tsx +113 -0
- package/src/components/Package/Package.tsx +692 -59
- package/src/components/Package/index.ts +3 -0
- package/src/components/QueryResult/QueryResult.tsx +17 -8
- package/src/components/QueryResult/index.ts +3 -0
- package/src/components/RenderedResult/RenderedResult.tsx +725 -67
- package/src/components/RenderedResult/ResultContainer.tsx +71 -2
- package/src/components/RenderedResult/index.ts +3 -0
- package/src/components/RenderedResult/renderLogs.spec.ts +58 -0
- package/src/components/RenderedResult/renderLogs.ts +43 -0
- package/src/components/ResultsDialog.tsx +13 -1
- package/src/components/ServerProvider.tsx +175 -51
- package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
- package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
- package/src/components/Workbook/ModelPicker.tsx +7 -4
- package/src/components/Workbook/MutableCell.tsx +10 -5
- package/src/components/Workbook/Workbook.tsx +8 -5
- package/src/components/Workbook/WorkbookList.tsx +3 -0
- package/src/components/Workbook/WorkbookManager.ts +3 -0
- package/src/components/Workbook/WorkbookStorage.ts +3 -0
- package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
- package/src/components/Workbook/index.ts +3 -0
- package/src/components/click_helper.ts +17 -1
- package/src/components/drill/index.ts +28 -0
- package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
- package/src/components/drill/markDrillableCells.spec.ts +109 -0
- package/src/components/drill/markDrillableCells.ts +314 -0
- package/src/components/drill/resolveDrill.spec.ts +449 -0
- package/src/components/drill/resolveDrill.ts +375 -0
- package/src/components/drill/useDrill.tsx +203 -0
- package/src/components/filter/DimensionFilter.tsx +3 -0
- package/src/components/filter/index.ts +3 -0
- package/src/components/filter/utils.ts +16 -5
- package/src/components/given/GivenInput.spec.tsx +689 -0
- package/src/components/given/GivenInput.tsx +801 -0
- package/src/components/given/GivensPanel.spec.tsx +175 -0
- package/src/components/given/GivensPanel.tsx +195 -0
- package/src/components/given/filterValue.spec.ts +364 -0
- package/src/components/given/filterValue.ts +207 -0
- package/src/components/given/index.ts +9 -0
- package/src/components/given/paramCodec.spec.ts +857 -0
- package/src/components/given/paramCodec.ts +483 -0
- package/src/components/given/utils.spec.ts +60 -0
- package/src/components/given/utils.ts +79 -0
- package/src/components/highlighter.ts +22 -5
- package/src/components/index.ts +10 -2
- package/src/components/styles.ts +82 -33
- package/src/constants/docLinks.spec.ts +54 -0
- package/src/constants/docLinks.ts +46 -0
- package/src/hooks/givenValue.ts +13 -0
- package/src/hooks/index.ts +13 -0
- package/src/hooks/useDimensionFilters.ts +4 -7
- package/src/hooks/useDimensionFiltersFromSpec.ts +8 -5
- package/src/hooks/useDimensionFiltersQuery.ts +10 -13
- package/src/hooks/useDimensionalFilterRangeData.ts +11 -14
- package/src/hooks/useGivensState.spec.ts +449 -0
- package/src/hooks/useGivensState.ts +340 -0
- package/src/hooks/useModelGivens.ts +29 -0
- package/src/hooks/useQueryWithApiError.ts +3 -0
- package/src/hooks/useRawQueryData.ts +6 -3
- package/src/hooks/useSuggestOptions.dom.spec.ts +91 -0
- package/src/hooks/useSuggestOptions.spec.ts +112 -0
- package/src/hooks/useSuggestOptions.ts +268 -0
- package/src/index.ts +10 -1
- package/src/react-app-env.d.ts +3 -0
- package/src/theme/ThemeContext.tsx +86 -0
- package/src/theme/buildMalloyExplicitTheme.ts +61 -0
- package/src/theme/buildTableCssVars.spec.ts +86 -0
- package/src/theme/buildTableCssVars.ts +98 -0
- package/src/theme/buildVegaThemeOverride.spec.ts +56 -0
- package/src/theme/buildVegaThemeOverride.ts +47 -0
- package/src/theme/defaults.ts +78 -0
- package/src/theme/index.ts +11 -0
- package/src/theme/keys.ts +32 -0
- package/src/theme/readChartAnnotations.spec.ts +58 -0
- package/src/theme/readChartAnnotations.ts +69 -0
- package/src/theme/resolveTheme.spec.ts +160 -0
- package/src/theme/resolveTheme.ts +121 -0
- package/src/theme/types.ts +79 -0
- package/src/utils/dataAppEmbed.spec.ts +63 -0
- package/src/utils/dataAppEmbed.ts +84 -0
- package/src/utils/formatting.spec.ts +25 -21
- package/src/utils/formatting.ts +11 -7
- package/src/utils/malloyString.spec.ts +24 -0
- package/src/utils/malloyString.ts +12 -0
- package/src/utils/parsing.spec.ts +26 -19
- package/src/utils/parsing.ts +11 -6
- package/src/utils/queryClient.ts +17 -0
- package/test/README.md +185 -0
- package/test/serverProvider.tsx +72 -0
- package/test/setup.ts +29 -0
- package/tsconfig.json +12 -1
- package/tsconfig.spec.json +22 -0
- package/vite.config.ts +3 -0
- package/dist/ServerProvider-lOQXDlqB.cjs.js +0 -1
- package/dist/ServerProvider-on-8FH5Z.es.js +0 -3060
- package/dist/components/Home/AddProjectDialog.d.ts +0 -1
- package/dist/components/Home/DeleteProjectDialog.d.ts +0 -5
- package/dist/components/Home/EditProjectDialog.d.ts +0 -7
- package/dist/components/Package/Config.d.ts +0 -5
- package/dist/components/Package/Databases.d.ts +0 -5
- package/dist/components/Package/Notebooks.d.ts +0 -6
- package/dist/components/Project/Project.d.ts +0 -6
- package/dist/components/Project/index.d.ts +0 -2
- package/dist/index-BOLBP6_i.cjs.js +0 -233
- package/src/components/Package/Config.tsx +0 -97
- package/src/components/Package/Connections.tsx +0 -373
- package/src/components/Package/Databases.tsx +0 -228
- package/src/components/Package/Notebooks.tsx +0 -77
- package/src/components/Project/AddPackageDialog.tsx +0 -159
- package/src/components/Project/Packages.tsx +0 -191
- package/src/components/Project/Project.tsx +0 -52
- package/src/components/Project/index.ts +0 -2
- /package/dist/components/{Project → Environment}/About.d.ts +0 -0
- /package/dist/components/{Project → Environment}/AddPackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/ConnectionExplorer.d.ts +0 -0
- /package/dist/components/{Package → Environment}/Connections.d.ts +0 -0
- /package/dist/components/{Project → Environment}/DeletePackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/EditPackageDialog.d.ts +0 -0
- /package/dist/components/{Project → Environment}/Packages.d.ts +0 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import type { Theme } from "../client";
|
|
5
|
+
|
|
6
|
+
export type { Theme };
|
|
7
|
+
|
|
8
|
+
export type ThemeMode = "light" | "dark";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A Theme with every field downstream consumers need actually filled in.
|
|
12
|
+
* Produced by `resolveTheme(layers, mode)`, which flattens the cascade
|
|
13
|
+
* and the per-mode colour split into a single mode-agnostic shape — so
|
|
14
|
+
* `buildTableCssVars`, `buildVegaThemeOverride`, and
|
|
15
|
+
* `buildMalloyExplicitTheme` never have to branch on mode themselves.
|
|
16
|
+
*
|
|
17
|
+
* The seven `palette.*` colour keys are stored per-mode on the raw Theme
|
|
18
|
+
* (one of light/dark per field) and collapse to the active mode here.
|
|
19
|
+
* The five "derived" fields (border, pinnedBorder, valueColor,
|
|
20
|
+
* foreground, axisFaint) are computed once from the resolved mode so
|
|
21
|
+
* the same hex literal isn't repeated across three builders.
|
|
22
|
+
*/
|
|
23
|
+
export interface ResolvedTheme {
|
|
24
|
+
mode: ThemeMode;
|
|
25
|
+
|
|
26
|
+
series: string[];
|
|
27
|
+
font: {
|
|
28
|
+
family: string;
|
|
29
|
+
size: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
background: string;
|
|
33
|
+
tableHeader: string;
|
|
34
|
+
tableHeaderBackground: string;
|
|
35
|
+
tableBody: string;
|
|
36
|
+
tile: string;
|
|
37
|
+
tileTitle: string;
|
|
38
|
+
/**
|
|
39
|
+
* Saturated end of the gradient used by sequential color scales
|
|
40
|
+
* (choropleth maps, heatmaps). The renderer pairs it with a
|
|
41
|
+
* near-neutral low-end so the operator only picks the brand end.
|
|
42
|
+
*/
|
|
43
|
+
mapColor: string;
|
|
44
|
+
|
|
45
|
+
border: string;
|
|
46
|
+
pinnedBorder: string;
|
|
47
|
+
valueColor: string;
|
|
48
|
+
foreground: string;
|
|
49
|
+
axisFaint: string;
|
|
50
|
+
/**
|
|
51
|
+
* Background for the renderer's HTML chrome (the area between
|
|
52
|
+
* dashboard tiles). Mode-keyed and intentionally NOT
|
|
53
|
+
* operator-customizable — when an operator picks a bold accent
|
|
54
|
+
* for `palette.background` (the chart canvas), the surrounding
|
|
55
|
+
* panel should stay neutral so the accent reads cleanly. In dark
|
|
56
|
+
* mode it paints slate so the panel doesn't sit as a stark white
|
|
57
|
+
* box on the dark page chrome.
|
|
58
|
+
*/
|
|
59
|
+
dashboardRoot: string;
|
|
60
|
+
/**
|
|
61
|
+
* Colour a `# drill` cell takes on hover, when it reads as a link. A link
|
|
62
|
+
* blue rather than anything from `palette.series`, deliberately: the
|
|
63
|
+
* affordance has to stay legible as a link against whatever the operator
|
|
64
|
+
* picked for the data, and a drillable bar or cell should not look like it
|
|
65
|
+
* belongs to a series. Mode-keyed and not operator-customizable, like
|
|
66
|
+
* `dashboardRoot`.
|
|
67
|
+
*/
|
|
68
|
+
drillLink: string;
|
|
69
|
+
/**
|
|
70
|
+
* Background for the renderer's table interior. Follows the
|
|
71
|
+
* operator's `palette.background` (the chart canvas colour) so
|
|
72
|
+
* tables and charts share a single "viz surface" colour. In dark
|
|
73
|
+
* mode this also keeps the (light-slate) header/body text from
|
|
74
|
+
* painting unreadable light-on-white against the renderer's
|
|
75
|
+
* hardcoded default. Distinct from `dashboardRoot`, which is the
|
|
76
|
+
* panel BETWEEN tiles and stays mode-keyed / neutral.
|
|
77
|
+
*/
|
|
78
|
+
tableBackground: string;
|
|
79
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import {
|
|
6
|
+
isPublisherResizeMessage,
|
|
7
|
+
PUBLISHER_RESIZE_MESSAGE_TYPE,
|
|
8
|
+
serverBaseUrl,
|
|
9
|
+
} from "./dataAppEmbed";
|
|
10
|
+
|
|
11
|
+
describe("serverBaseUrl", () => {
|
|
12
|
+
it("strips a trailing /api/v0", () => {
|
|
13
|
+
expect(serverBaseUrl("https://pub.example.com/api/v0")).toBe(
|
|
14
|
+
"https://pub.example.com",
|
|
15
|
+
);
|
|
16
|
+
});
|
|
17
|
+
it("strips a trailing /api/v0/", () => {
|
|
18
|
+
expect(serverBaseUrl("https://pub.example.com/api/v0/")).toBe(
|
|
19
|
+
"https://pub.example.com",
|
|
20
|
+
);
|
|
21
|
+
});
|
|
22
|
+
it("leaves a base without the API prefix untouched", () => {
|
|
23
|
+
expect(serverBaseUrl("https://pub.example.com")).toBe(
|
|
24
|
+
"https://pub.example.com",
|
|
25
|
+
);
|
|
26
|
+
});
|
|
27
|
+
it("only strips the suffix, not an interior /api/v0", () => {
|
|
28
|
+
expect(serverBaseUrl("https://host/api/v0/proxy/api/v0")).toBe(
|
|
29
|
+
"https://host/api/v0/proxy",
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
describe("isPublisherResizeMessage", () => {
|
|
35
|
+
it("accepts a well-formed resize message", () => {
|
|
36
|
+
expect(
|
|
37
|
+
isPublisherResizeMessage({
|
|
38
|
+
type: PUBLISHER_RESIZE_MESSAGE_TYPE,
|
|
39
|
+
height: 420,
|
|
40
|
+
}),
|
|
41
|
+
).toBe(true);
|
|
42
|
+
});
|
|
43
|
+
it("rejects a wrong type", () => {
|
|
44
|
+
expect(isPublisherResizeMessage({ type: "other", height: 1 })).toBe(
|
|
45
|
+
false,
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
it("rejects a missing/non-numeric height", () => {
|
|
49
|
+
expect(
|
|
50
|
+
isPublisherResizeMessage({ type: PUBLISHER_RESIZE_MESSAGE_TYPE }),
|
|
51
|
+
).toBe(false);
|
|
52
|
+
expect(
|
|
53
|
+
isPublisherResizeMessage({
|
|
54
|
+
type: PUBLISHER_RESIZE_MESSAGE_TYPE,
|
|
55
|
+
height: "420",
|
|
56
|
+
}),
|
|
57
|
+
).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
it("rejects null / non-objects", () => {
|
|
60
|
+
expect(isPublisherResizeMessage(null)).toBe(false);
|
|
61
|
+
expect(isPublisherResizeMessage("publisher:resize")).toBe(false);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
// Shared contract for serving and embedding in-package HTML data apps.
|
|
5
|
+
//
|
|
6
|
+
// Both the Publisher SPA host (DataAppViewer.tsx, Package.tsx) and the
|
|
7
|
+
// build-step-free browser runtime (packages/server/src/runtime/publisher.js)
|
|
8
|
+
// speak this protocol. publisher.js cannot import from here — it ships as
|
|
9
|
+
// standalone vanilla JS — so it carries a cross-reference comment pointing at
|
|
10
|
+
// this file as the single source of truth. Keep the two in sync.
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* postMessage `type` an embedded data app emits to its host frame as its
|
|
14
|
+
* content height changes, so the host can resize the iframe to avoid nested
|
|
15
|
+
* scrollbars. Payload shape is {@link PublisherResizeMessage}.
|
|
16
|
+
*/
|
|
17
|
+
export const PUBLISHER_RESIZE_MESSAGE_TYPE = "publisher:resize";
|
|
18
|
+
|
|
19
|
+
/** Resize message posted by an embedded data app's publisher.js runtime. */
|
|
20
|
+
export interface PublisherResizeMessage {
|
|
21
|
+
type: typeof PUBLISHER_RESIZE_MESSAGE_TYPE;
|
|
22
|
+
/** Content height in CSS pixels. */
|
|
23
|
+
height: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** Type guard for a {@link PublisherResizeMessage} arriving via postMessage. */
|
|
27
|
+
export function isPublisherResizeMessage(
|
|
28
|
+
data: unknown,
|
|
29
|
+
): data is PublisherResizeMessage {
|
|
30
|
+
return (
|
|
31
|
+
typeof data === "object" &&
|
|
32
|
+
data !== null &&
|
|
33
|
+
(data as { type?: unknown }).type === PUBLISHER_RESIZE_MESSAGE_TYPE &&
|
|
34
|
+
typeof (data as { height?: unknown }).height === "number"
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Derive the Publisher data origin (where static package files are served)
|
|
40
|
+
* from the configured API base URL by stripping the trailing `/api/v0`.
|
|
41
|
+
*
|
|
42
|
+
* The static-file routes live off the server root, not under the API prefix,
|
|
43
|
+
* and the data origin can differ from the SPA origin in multi-host
|
|
44
|
+
* deployments — so a data app's standalone URL is `serverBaseUrl(server)`
|
|
45
|
+
* joined with its root-relative `resource`.
|
|
46
|
+
*/
|
|
47
|
+
export function serverBaseUrl(server: string): string {
|
|
48
|
+
return server.replace(/\/api\/v0\/?$/, "");
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Absolute URL of a file inside a package, as Publisher serves it:
|
|
53
|
+
* `<data origin>/environments/<env>/packages/<pkg>/<path>`.
|
|
54
|
+
*
|
|
55
|
+
* The one home for this string. Both the data app viewer's iframe and the
|
|
56
|
+
* "this is not a model" page point at it, and hand-building it in each place is
|
|
57
|
+
* how the two drift.
|
|
58
|
+
*
|
|
59
|
+
* `path` is relative to the package's `public/` directory and is inserted as
|
|
60
|
+
* given, since it may contain slashes. A leading `public/` is dropped, because
|
|
61
|
+
* the served path does not include it and a caller passing a path a reader typed
|
|
62
|
+
* would otherwise produce `public/public/<file>`, which 404s. The server's own
|
|
63
|
+
* redirect drops it for the same reason.
|
|
64
|
+
*/
|
|
65
|
+
export function packageFileUrl({
|
|
66
|
+
server,
|
|
67
|
+
environmentName,
|
|
68
|
+
packageName,
|
|
69
|
+
path,
|
|
70
|
+
}: {
|
|
71
|
+
server: string;
|
|
72
|
+
environmentName: string;
|
|
73
|
+
packageName: string;
|
|
74
|
+
path: string;
|
|
75
|
+
}): string {
|
|
76
|
+
const relative = path.startsWith("public/")
|
|
77
|
+
? path.slice("public/".length)
|
|
78
|
+
: path;
|
|
79
|
+
return (
|
|
80
|
+
`${serverBaseUrl(server)}/environments/${encodeURIComponent(
|
|
81
|
+
environmentName,
|
|
82
|
+
)}/packages/${encodeURIComponent(packageName)}/` + relative
|
|
83
|
+
);
|
|
84
|
+
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
import { describe, expect, it } from "bun:test";
|
|
2
5
|
import { encodeResourceUri, parseResourceUri } from "./formatting";
|
|
3
6
|
|
|
4
7
|
describe("parseResourceUri", () => {
|
|
5
8
|
it("should parse a package URI", () => {
|
|
6
|
-
const resourceUri =
|
|
9
|
+
const resourceUri =
|
|
10
|
+
"publisher://environments/malloy-samples/packages/names";
|
|
7
11
|
const parsedResource = parseResourceUri(resourceUri);
|
|
8
12
|
expect(parsedResource).toEqual({
|
|
9
|
-
|
|
13
|
+
environmentName: "malloy-samples",
|
|
10
14
|
packageName: "names",
|
|
11
15
|
connectionName: undefined,
|
|
12
16
|
modelPath: undefined,
|
|
@@ -15,10 +19,10 @@ describe("parseResourceUri", () => {
|
|
|
15
19
|
});
|
|
16
20
|
it("should parse a connection URI", () => {
|
|
17
21
|
const resourceUri =
|
|
18
|
-
"publisher://
|
|
22
|
+
"publisher://environments/malloy-samples/connections/bigquery";
|
|
19
23
|
const parsedResource = parseResourceUri(resourceUri);
|
|
20
24
|
expect(parsedResource).toEqual({
|
|
21
|
-
|
|
25
|
+
environmentName: "malloy-samples",
|
|
22
26
|
packageName: undefined,
|
|
23
27
|
connectionName: "bigquery",
|
|
24
28
|
modelPath: undefined,
|
|
@@ -28,10 +32,10 @@ describe("parseResourceUri", () => {
|
|
|
28
32
|
|
|
29
33
|
it("should parse a modelPath URI", () => {
|
|
30
34
|
const resourceUri =
|
|
31
|
-
"publisher://
|
|
35
|
+
"publisher://environments/malloy-samples/packages/names/models/names1.malloynb";
|
|
32
36
|
const parsedResource = parseResourceUri(resourceUri);
|
|
33
37
|
expect(parsedResource).toEqual({
|
|
34
|
-
|
|
38
|
+
environmentName: "malloy-samples",
|
|
35
39
|
packageName: "names",
|
|
36
40
|
connectionName: undefined,
|
|
37
41
|
modelPath: "names1.malloynb",
|
|
@@ -41,13 +45,13 @@ describe("parseResourceUri", () => {
|
|
|
41
45
|
|
|
42
46
|
it("should throw an error if the resource URI has the wrong protocol", () => {
|
|
43
47
|
const resourceUri =
|
|
44
|
-
"http://
|
|
48
|
+
"http://environments/malloy-samples/packages/names/models/names1.malloynb";
|
|
45
49
|
expect(() => parseResourceUri(resourceUri)).toThrow(
|
|
46
50
|
`Failed to parse resource URI: ${resourceUri}`,
|
|
47
51
|
);
|
|
48
52
|
});
|
|
49
53
|
|
|
50
|
-
it("should throw an error if the resource URI is missing the
|
|
54
|
+
it("should throw an error if the resource URI is missing the environment name", () => {
|
|
51
55
|
const resourceUri = "publisher://";
|
|
52
56
|
expect(() => parseResourceUri(resourceUri)).toThrow(
|
|
53
57
|
/Failed to parse resource URI/,
|
|
@@ -56,10 +60,10 @@ describe("parseResourceUri", () => {
|
|
|
56
60
|
|
|
57
61
|
it("should parse the optional versionId parameter if present", () => {
|
|
58
62
|
const resourceUri =
|
|
59
|
-
"publisher://
|
|
63
|
+
"publisher://environments/malloy-samples/packages/names?versionId=1.0.0";
|
|
60
64
|
const parsedResource = parseResourceUri(resourceUri);
|
|
61
65
|
expect(parsedResource).toEqual({
|
|
62
|
-
|
|
66
|
+
environmentName: "malloy-samples",
|
|
63
67
|
packageName: "names",
|
|
64
68
|
connectionName: undefined,
|
|
65
69
|
modelPath: undefined,
|
|
@@ -71,65 +75,65 @@ describe("parseResourceUri", () => {
|
|
|
71
75
|
describe("encodeResourceUri", () => {
|
|
72
76
|
it("should encode a package URI with no versionId", () => {
|
|
73
77
|
const resourceUri = encodeResourceUri({
|
|
74
|
-
|
|
78
|
+
environmentName: "malloy-samples",
|
|
75
79
|
packageName: "names",
|
|
76
80
|
connectionName: undefined,
|
|
77
81
|
modelPath: undefined,
|
|
78
82
|
versionId: undefined,
|
|
79
83
|
});
|
|
80
84
|
expect(resourceUri).toEqual(
|
|
81
|
-
"publisher://
|
|
85
|
+
"publisher://environments/malloy-samples/packages/names",
|
|
82
86
|
);
|
|
83
87
|
});
|
|
84
88
|
|
|
85
89
|
it("should encode a package URI with a versionId", () => {
|
|
86
90
|
const resourceUri = encodeResourceUri({
|
|
87
|
-
|
|
91
|
+
environmentName: "malloy-samples",
|
|
88
92
|
packageName: "names",
|
|
89
93
|
versionId: "1.0.0",
|
|
90
94
|
connectionName: undefined,
|
|
91
95
|
modelPath: undefined,
|
|
92
96
|
});
|
|
93
97
|
expect(resourceUri).toEqual(
|
|
94
|
-
"publisher://
|
|
98
|
+
"publisher://environments/malloy-samples/packages/names?versionId=1.0.0",
|
|
95
99
|
);
|
|
96
100
|
});
|
|
97
101
|
|
|
98
102
|
it("should encode a connection URI", () => {
|
|
99
103
|
const resourceUri = encodeResourceUri({
|
|
100
|
-
|
|
104
|
+
environmentName: "malloy-samples",
|
|
101
105
|
packageName: undefined,
|
|
102
106
|
connectionName: "bigquery",
|
|
103
107
|
modelPath: undefined,
|
|
104
108
|
versionId: undefined,
|
|
105
109
|
});
|
|
106
110
|
expect(resourceUri).toEqual(
|
|
107
|
-
"publisher://
|
|
111
|
+
"publisher://environments/malloy-samples/connections/bigquery",
|
|
108
112
|
);
|
|
109
113
|
});
|
|
110
114
|
|
|
111
115
|
it("should encode a modelPath URI", () => {
|
|
112
116
|
const resourceUri = encodeResourceUri({
|
|
113
|
-
|
|
117
|
+
environmentName: "malloy-samples",
|
|
114
118
|
packageName: "names",
|
|
115
119
|
connectionName: undefined,
|
|
116
120
|
modelPath: "names1.malloynb",
|
|
117
121
|
versionId: undefined,
|
|
118
122
|
});
|
|
119
123
|
expect(resourceUri).toEqual(
|
|
120
|
-
"publisher://
|
|
124
|
+
"publisher://environments/malloy-samples/packages/names/models/names1.malloynb",
|
|
121
125
|
);
|
|
122
126
|
});
|
|
123
127
|
|
|
124
|
-
it("should throw an error if the resource URI is missing the
|
|
128
|
+
it("should throw an error if the resource URI is missing the environment name", () => {
|
|
125
129
|
expect(() =>
|
|
126
130
|
encodeResourceUri({
|
|
127
|
-
|
|
131
|
+
environmentName: "",
|
|
128
132
|
packageName: "names",
|
|
129
133
|
connectionName: undefined,
|
|
130
134
|
modelPath: undefined,
|
|
131
135
|
versionId: undefined,
|
|
132
136
|
}),
|
|
133
|
-
).toThrow(/Failed to encode resource URI, missing
|
|
137
|
+
).toThrow(/Failed to encode resource URI, missing environment name/);
|
|
134
138
|
});
|
|
135
139
|
});
|
package/src/utils/formatting.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
export type ParsedResource = {
|
|
2
|
-
|
|
5
|
+
environmentName: string;
|
|
3
6
|
packageName?: string | undefined;
|
|
4
7
|
connectionName?: string | undefined;
|
|
5
8
|
versionId?: string | undefined;
|
|
@@ -15,8 +18,9 @@ export const parseResourceUri = (resourceUri: string) => {
|
|
|
15
18
|
const pathParts = (parsedUri.hostname + parsedUri.pathname).split("/");
|
|
16
19
|
for (let i = 0; i < pathParts.length; i += 2) {
|
|
17
20
|
const part = pathParts[i];
|
|
18
|
-
if (part === "
|
|
19
|
-
parsedResource.
|
|
21
|
+
if (part === "environments") {
|
|
22
|
+
parsedResource.environmentName =
|
|
23
|
+
decodeURI(pathParts[i + 1]) || undefined;
|
|
20
24
|
} else if (part === "packages") {
|
|
21
25
|
parsedResource.packageName = decodeURI(pathParts[i + 1]) || undefined;
|
|
22
26
|
} else if (part === "connections") {
|
|
@@ -30,19 +34,19 @@ export const parseResourceUri = (resourceUri: string) => {
|
|
|
30
34
|
|
|
31
35
|
parsedResource.versionId =
|
|
32
36
|
parsedUri.searchParams.get("versionId") || undefined;
|
|
33
|
-
if (!parsedResource.
|
|
37
|
+
if (!parsedResource.environmentName) {
|
|
34
38
|
throw new Error(`Failed to parse resource URI: ${resourceUri}`);
|
|
35
39
|
}
|
|
36
40
|
return parsedResource;
|
|
37
41
|
};
|
|
38
42
|
|
|
39
43
|
export const encodeResourceUri = (resource: ParsedResource) => {
|
|
40
|
-
if (!resource.
|
|
44
|
+
if (!resource.environmentName) {
|
|
41
45
|
throw new Error(
|
|
42
|
-
`Failed to encode resource URI, missing
|
|
46
|
+
`Failed to encode resource URI, missing environment name: ${resource}`,
|
|
43
47
|
);
|
|
44
48
|
}
|
|
45
|
-
let uri = `publisher://
|
|
49
|
+
let uri = `publisher://environments/${resource.environmentName}`;
|
|
46
50
|
if (resource.packageName) {
|
|
47
51
|
uri += `/packages/${resource.packageName}`;
|
|
48
52
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
import { describe, expect, it } from "bun:test";
|
|
5
|
+
import { escapeMalloyString } from "./malloyString";
|
|
6
|
+
|
|
7
|
+
describe("escapeMalloyString", () => {
|
|
8
|
+
it("escapes a quote", () => {
|
|
9
|
+
expect(escapeMalloyString("O'Brien")).toBe("O\\'Brien");
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("escapes a backslash", () => {
|
|
13
|
+
expect(escapeMalloyString("C:\\temp")).toBe("C:\\\\temp");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("escapes backslashes before quotes, so the quote escape is not doubled", () => {
|
|
17
|
+
// Quote-then-backslash order would turn ' into \' and then \\' .
|
|
18
|
+
expect(escapeMalloyString("a'\\b")).toBe("a\\'\\\\b");
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("leaves a plain string alone", () => {
|
|
22
|
+
expect(escapeMalloyString("plain value")).toBe("plain value");
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Escape a value for use inside a single-quoted Malloy string literal.
|
|
6
|
+
*
|
|
7
|
+
* Backslashes are escaped first, then quotes: doing it the other way round
|
|
8
|
+
* would re-escape the backslash that the quote escape introduced.
|
|
9
|
+
*/
|
|
10
|
+
export function escapeMalloyString(value: string): string {
|
|
11
|
+
return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
|
12
|
+
}
|
|
@@ -1,11 +1,18 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
generateEnvironmentReadme,
|
|
7
|
+
getEnvironmentDescription,
|
|
8
|
+
} from "./parsing";
|
|
3
9
|
|
|
4
|
-
describe("
|
|
10
|
+
describe("getEnvironmentDescription", () => {
|
|
5
11
|
it("should return the first paragraph of the README", () => {
|
|
6
|
-
const readme =
|
|
7
|
-
|
|
8
|
-
|
|
12
|
+
const readme =
|
|
13
|
+
"# Environment Description\nThis is an environment description";
|
|
14
|
+
expect(getEnvironmentDescription(readme)).toBe(
|
|
15
|
+
"Environment Description\nThis is an environment description",
|
|
9
16
|
);
|
|
10
17
|
});
|
|
11
18
|
|
|
@@ -14,42 +21,42 @@ describe("getProjectDescription", () => {
|
|
|
14
21
|
const readme = `${longDescription}`;
|
|
15
22
|
// 5 characters per word + space, so 20 words = 120 characters
|
|
16
23
|
const truncatedDescription = Array(20).fill("abcde").join(" ") + "...";
|
|
17
|
-
expect(
|
|
24
|
+
expect(getEnvironmentDescription(readme)).toBe(truncatedDescription);
|
|
18
25
|
});
|
|
19
26
|
|
|
20
27
|
it("should return a placeholder description if the README is empty", () => {
|
|
21
28
|
const readme = "";
|
|
22
|
-
expect(
|
|
29
|
+
expect(getEnvironmentDescription(readme)).toBe(
|
|
23
30
|
"Explore semantic models, run queries, and build dashboards",
|
|
24
31
|
);
|
|
25
32
|
});
|
|
26
33
|
});
|
|
27
34
|
|
|
28
|
-
describe("
|
|
35
|
+
describe("generateEnvironmentReadme", () => {
|
|
29
36
|
it("should preserve the existing readme if it exists", () => {
|
|
30
|
-
const
|
|
31
|
-
name: "Test
|
|
37
|
+
const environment = {
|
|
38
|
+
name: "Test Environment",
|
|
32
39
|
readme: "# Test Readme",
|
|
33
40
|
};
|
|
34
|
-
expect(
|
|
41
|
+
expect(generateEnvironmentReadme(environment)).toBe("# Test Readme");
|
|
35
42
|
});
|
|
36
43
|
|
|
37
|
-
it("should generate
|
|
38
|
-
const
|
|
39
|
-
name: "Test
|
|
44
|
+
it("should generate an environment readme with the description if it does not exist", () => {
|
|
45
|
+
const environment = {
|
|
46
|
+
name: "Test Environment",
|
|
40
47
|
readme: "",
|
|
41
48
|
};
|
|
42
|
-
expect(
|
|
43
|
-
"# Test
|
|
49
|
+
expect(generateEnvironmentReadme(environment, "Test Description")).toBe(
|
|
50
|
+
"# Test Environment\n\nTest Description",
|
|
44
51
|
);
|
|
45
52
|
});
|
|
46
53
|
|
|
47
54
|
it("should insert the description in the existing readme if both exist", () => {
|
|
48
|
-
const
|
|
49
|
-
name: "Test
|
|
55
|
+
const environment = {
|
|
56
|
+
name: "Test Environment",
|
|
50
57
|
readme: "# Test Readme\n\nOld Description\n\nMore stuff",
|
|
51
58
|
};
|
|
52
|
-
expect(
|
|
59
|
+
expect(generateEnvironmentReadme(environment, "New Description")).toBe(
|
|
53
60
|
"# Test Readme\n\nNew Description\n\nMore stuff",
|
|
54
61
|
);
|
|
55
62
|
});
|
package/src/utils/parsing.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
// Helper function to extract a brief description from README content
|
|
2
|
-
export const
|
|
5
|
+
export const getEnvironmentDescription = (
|
|
6
|
+
readme: string | undefined,
|
|
7
|
+
): string => {
|
|
3
8
|
if (!readme) {
|
|
4
9
|
return "Explore semantic models, run queries, and build dashboards";
|
|
5
10
|
}
|
|
@@ -28,19 +33,19 @@ export const getProjectDescription = (readme: string | undefined): string => {
|
|
|
28
33
|
return truncated.join(" ") + "...";
|
|
29
34
|
};
|
|
30
35
|
|
|
31
|
-
export const
|
|
32
|
-
|
|
36
|
+
export const generateEnvironmentReadme = (
|
|
37
|
+
environment: {
|
|
33
38
|
name: string;
|
|
34
39
|
readme?: string;
|
|
35
40
|
},
|
|
36
41
|
description?: string,
|
|
37
42
|
): string => {
|
|
38
|
-
const readmeLines = (
|
|
43
|
+
const readmeLines = (environment.readme || undefined)?.split("\n") ?? [];
|
|
39
44
|
if (readmeLines.length === 0) {
|
|
40
|
-
readmeLines.push(`# ${
|
|
45
|
+
readmeLines.push(`# ${environment.name}`);
|
|
41
46
|
readmeLines.push("");
|
|
42
47
|
}
|
|
43
|
-
if ((
|
|
48
|
+
if ((environment.readme?.length ?? 0) > 0 && description) {
|
|
44
49
|
readmeLines.splice(2, 1, description);
|
|
45
50
|
} else if (description) {
|
|
46
51
|
readmeLines.push(description);
|
package/src/utils/queryClient.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
// Copyright (c) Credible Data Inc.
|
|
2
|
+
// SPDX-License-Identifier: MIT
|
|
3
|
+
|
|
1
4
|
import { QueryClient } from "@tanstack/react-query";
|
|
2
5
|
|
|
3
6
|
// Global QueryClient instance - isolated to avoid circular dependencies
|
|
@@ -13,3 +16,17 @@ export const globalQueryClient = new QueryClient({
|
|
|
13
16
|
},
|
|
14
17
|
},
|
|
15
18
|
});
|
|
19
|
+
|
|
20
|
+
// Refetch policy for chart/query-RESULT queries. A Malloy query result is a
|
|
21
|
+
// pure function of the query text + filters, which are already in each query
|
|
22
|
+
// key, so re-executing the query on tab refocus or reconnect only repaints the
|
|
23
|
+
// same result and can cause a visible chart flicker. Treat results as fresh
|
|
24
|
+
// for a few minutes and don't auto-refetch on focus/reconnect. Kept scoped to
|
|
25
|
+
// the result queries (spread into their useQuery options) rather than set on
|
|
26
|
+
// the global client, so other SDK queries (metadata lists, status) keep
|
|
27
|
+
// react-query's default freshness behavior.
|
|
28
|
+
export const CHART_RESULT_QUERY_OPTIONS = {
|
|
29
|
+
staleTime: 5 * 60 * 1000,
|
|
30
|
+
refetchOnWindowFocus: false,
|
|
31
|
+
refetchOnReconnect: false,
|
|
32
|
+
} as const;
|