@malloy-publisher/sdk 0.12.0 → 0.12.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.
Files changed (214) hide show
  1. package/README.md +79 -6
  2. package/dist/{RenderedResult-SgDlxzs9.cjs.js → RenderedResult-Cgw4iqev.cjs.js} +1 -1
  3. package/dist/{RenderedResult-D8bCgThO.es.js → RenderedResult-DEjFM1DL.es.js} +2 -2
  4. package/dist/ServerProvider-BRQl_cBo.cjs.js +1 -0
  5. package/dist/{ServerProvider-DBw-thY0.es.js → ServerProvider-RnliA2Ao.es.js} +1084 -723
  6. package/dist/builder/index.cjs.js +1 -1
  7. package/dist/builder/index.es.js +3 -3
  8. package/dist/client/api.d.ts +754 -41
  9. package/dist/client/index.cjs.js +1 -1
  10. package/dist/client/index.es.js +120 -110
  11. package/dist/components/Materializations/MaterializationDetailDialog.d.ts +16 -1
  12. package/dist/components/Model/ExplorerPage.d.ts +9 -0
  13. package/dist/components/Model/Model.d.ts +27 -11
  14. package/dist/components/ModelViewer/AccessChips.d.ts +34 -0
  15. package/dist/components/ModelViewer/EmptyRow.d.ts +23 -0
  16. package/dist/components/ModelViewer/Facts.d.ts +15 -0
  17. package/dist/components/ModelViewer/FieldGroup.d.ts +31 -0
  18. package/dist/components/ModelViewer/FieldRow.d.ts +69 -0
  19. package/dist/components/ModelViewer/GivenFacts.d.ts +21 -0
  20. package/dist/components/ModelViewer/HeaderBar.d.ts +75 -0
  21. package/dist/components/ModelViewer/InlineDoc.d.ts +13 -0
  22. package/dist/components/ModelViewer/ModelGivensSection.d.ts +32 -0
  23. package/dist/components/ModelViewer/ModelSection.d.ts +21 -0
  24. package/dist/components/ModelViewer/ModelViewer.d.ts +91 -0
  25. package/dist/components/ModelViewer/QueriesGroup.d.ts +15 -0
  26. package/dist/components/ModelViewer/RowGlyph.d.ts +27 -0
  27. package/dist/components/ModelViewer/RunResult.d.ts +46 -0
  28. package/dist/components/ModelViewer/SampleValues.d.ts +20 -0
  29. package/dist/components/ModelViewer/SchemaJoin.d.ts +51 -0
  30. package/dist/components/ModelViewer/SchemaView.d.ts +52 -0
  31. package/dist/components/ModelViewer/SegmentIcons.d.ts +70 -0
  32. package/dist/components/ModelViewer/SourcesDropdown.d.ts +53 -0
  33. package/dist/components/ModelViewer/SourcesNav.d.ts +25 -0
  34. package/dist/components/ModelViewer/StatusPill.d.ts +56 -0
  35. package/dist/components/ModelViewer/ValueChip.d.ts +17 -0
  36. package/dist/components/ModelViewer/ViewRow.d.ts +36 -0
  37. package/dist/components/ModelViewer/clickableBox.d.ts +29 -0
  38. package/dist/components/ModelViewer/codeDisplay.d.ts +44 -0
  39. package/dist/components/ModelViewer/docAnnotations.d.ts +90 -0
  40. package/dist/components/ModelViewer/explorerModel.d.ts +12 -0
  41. package/dist/components/ModelViewer/extensions.d.ts +94 -0
  42. package/dist/components/ModelViewer/fieldCode.d.ts +74 -0
  43. package/dist/components/ModelViewer/fieldEntities.d.ts +45 -0
  44. package/dist/components/ModelViewer/fieldExpansion.d.ts +41 -0
  45. package/dist/components/ModelViewer/givenUsage.d.ts +71 -0
  46. package/dist/components/ModelViewer/headerCard.d.ts +31 -0
  47. package/dist/components/ModelViewer/httpStatus.d.ts +4 -0
  48. package/dist/components/ModelViewer/icons.d.ts +31 -0
  49. package/dist/components/ModelViewer/index.d.ts +9 -0
  50. package/dist/components/ModelViewer/joinAccess.d.ts +52 -0
  51. package/dist/components/ModelViewer/malloyRunText.d.ts +22 -0
  52. package/dist/components/ModelViewer/malloyText.d.ts +21 -0
  53. package/dist/components/ModelViewer/modelGivens.d.ts +61 -0
  54. package/dist/components/ModelViewer/modelGivensContext.d.ts +9 -0
  55. package/dist/components/ModelViewer/modelHeaderPresentation.d.ts +28 -0
  56. package/dist/components/ModelViewer/modelTextDeclarations.d.ts +32 -0
  57. package/dist/components/ModelViewer/modelTextParse.d.ts +27 -0
  58. package/dist/components/ModelViewer/namedQueryCode.d.ts +12 -0
  59. package/dist/components/ModelViewer/offSurface.d.ts +54 -0
  60. package/dist/components/ModelViewer/rowLayers.d.ts +30 -0
  61. package/dist/components/ModelViewer/runGate.d.ts +49 -0
  62. package/dist/components/ModelViewer/schemaModel.d.ts +109 -0
  63. package/dist/components/ModelViewer/sectionOpenCommand.d.ts +45 -0
  64. package/dist/components/ModelViewer/sourceAccess.d.ts +67 -0
  65. package/dist/components/ModelViewer/sourceLineage.d.ts +14 -0
  66. package/dist/components/ModelViewer/sourcePicker.d.ts +66 -0
  67. package/dist/components/ModelViewer/surface.d.ts +47 -0
  68. package/dist/components/ModelViewer/text.d.ts +6 -0
  69. package/dist/components/ModelViewer/theme.d.ts +63 -0
  70. package/dist/components/ModelViewer/tokens.d.ts +52 -0
  71. package/dist/components/ModelViewer/ui.d.ts +48 -0
  72. package/dist/components/ModelViewer/useDimensionSamples.d.ts +76 -0
  73. package/dist/components/ModelViewer/useModelSources.d.ts +92 -0
  74. package/dist/components/ModelViewer/useRunQuery.d.ts +115 -0
  75. package/dist/components/ReportBuilder/loadMalloy.d.ts +4 -0
  76. package/dist/components/ServerProvider.d.ts +17 -2
  77. package/dist/components/filter/utils.d.ts +1 -1
  78. package/dist/components/given/GivenInput.d.ts +7 -1
  79. package/dist/components/given/GivensPanel.d.ts +3 -1
  80. package/dist/components/given/filterSummary.d.ts +6 -0
  81. package/dist/components/given/useGivenUrlParams.d.ts +11 -0
  82. package/dist/components/index.d.ts +2 -1
  83. package/dist/components/modelPage.d.ts +36 -0
  84. package/dist/hooks/useDimensionalFilterRangeData.d.ts +9 -0
  85. package/dist/hooks/useSuggestOptions.d.ts +26 -2
  86. package/dist/index.cjs.js +47 -19
  87. package/dist/index.es.js +14137 -9697
  88. package/dist/useCompiledDocument-D88_2cGS.cjs.js +143 -0
  89. package/dist/{useCompiledDocument-CXMPtJkJ.es.js → useCompiledDocument-Dmm6xkom.es.js} +6975 -6893
  90. package/dist/utils/filterCondition.d.ts +14 -0
  91. package/dist/utils/malloyLiteral.d.ts +20 -1
  92. package/package.json +2 -2
  93. package/src/components/Materializations/MaterializationDetailDialog.tsx +33 -7
  94. package/src/components/Materializations/Materializations.tsx +47 -4
  95. package/src/components/Materializations/Materializations.versions.spec.tsx +140 -1
  96. package/src/components/Model/ExplorerPage.tsx +269 -0
  97. package/src/components/Model/Model.tsx +66 -250
  98. package/src/components/Model/ModelExplorer.spec.tsx +64 -1
  99. package/src/components/ModelViewer/AccessChips.tsx +149 -0
  100. package/src/components/ModelViewer/EmptyRow.tsx +71 -0
  101. package/src/components/ModelViewer/Facts.tsx +46 -0
  102. package/src/components/ModelViewer/FieldGroup.tsx +137 -0
  103. package/src/components/ModelViewer/FieldRow.tsx +566 -0
  104. package/src/components/ModelViewer/GivenFacts.tsx +89 -0
  105. package/src/components/ModelViewer/HeaderBar.tsx +362 -0
  106. package/src/components/ModelViewer/InlineDoc.tsx +50 -0
  107. package/src/components/ModelViewer/ModelGivensSection.tsx +142 -0
  108. package/src/components/ModelViewer/ModelSection.tsx +98 -0
  109. package/src/components/ModelViewer/ModelViewer.spec.tsx +937 -0
  110. package/src/components/ModelViewer/ModelViewer.tsx +777 -0
  111. package/src/components/ModelViewer/QueriesGroup.tsx +107 -0
  112. package/src/components/ModelViewer/RowGlyph.tsx +138 -0
  113. package/src/components/ModelViewer/RunResult.tsx +298 -0
  114. package/src/components/ModelViewer/SampleValues.tsx +97 -0
  115. package/src/components/ModelViewer/SchemaJoin.tsx +258 -0
  116. package/src/components/ModelViewer/SchemaView.tsx +222 -0
  117. package/src/components/ModelViewer/SegmentIcons.tsx +129 -0
  118. package/src/components/ModelViewer/SourcesDropdown.tsx +265 -0
  119. package/src/components/ModelViewer/SourcesNav.tsx +75 -0
  120. package/src/components/ModelViewer/StatusPill.tsx +145 -0
  121. package/src/components/ModelViewer/ValueChip.tsx +39 -0
  122. package/src/components/ModelViewer/ViewRow.tsx +274 -0
  123. package/src/components/ModelViewer/clickableBox.ts +59 -0
  124. package/src/components/ModelViewer/codeDisplay.spec.ts +176 -0
  125. package/src/components/ModelViewer/codeDisplay.ts +118 -0
  126. package/src/components/ModelViewer/docAnnotations.spec.ts +181 -0
  127. package/src/components/ModelViewer/docAnnotations.ts +244 -0
  128. package/src/components/ModelViewer/docAnnotations.typeDetail.spec.ts +114 -0
  129. package/src/components/ModelViewer/explorerModel.spec.ts +43 -0
  130. package/src/components/ModelViewer/explorerModel.ts +31 -0
  131. package/src/components/ModelViewer/extensions.tsx +112 -0
  132. package/src/components/ModelViewer/fieldCode.spec.ts +168 -0
  133. package/src/components/ModelViewer/fieldCode.ts +118 -0
  134. package/src/components/ModelViewer/fieldEntities.ts +63 -0
  135. package/src/components/ModelViewer/fieldExpansion.spec.ts +116 -0
  136. package/src/components/ModelViewer/fieldExpansion.ts +95 -0
  137. package/src/components/ModelViewer/givenUsage.spec.ts +304 -0
  138. package/src/components/ModelViewer/givenUsage.ts +325 -0
  139. package/src/components/ModelViewer/headerCard.tsx +102 -0
  140. package/src/components/ModelViewer/httpStatus.ts +15 -0
  141. package/src/components/ModelViewer/icons.tsx +67 -0
  142. package/src/components/ModelViewer/index.ts +26 -0
  143. package/src/components/ModelViewer/joinAccess.spec.ts +95 -0
  144. package/src/components/ModelViewer/joinAccess.ts +54 -0
  145. package/src/components/ModelViewer/malloyRunText.spec.ts +48 -0
  146. package/src/components/ModelViewer/malloyRunText.ts +51 -0
  147. package/src/components/ModelViewer/malloyText.spec.ts +47 -0
  148. package/src/components/ModelViewer/malloyText.ts +77 -0
  149. package/src/components/ModelViewer/modelGivens.ts +228 -0
  150. package/src/components/ModelViewer/modelGivensContext.ts +13 -0
  151. package/src/components/ModelViewer/modelHeaderPresentation.spec.ts +31 -0
  152. package/src/components/ModelViewer/modelHeaderPresentation.ts +41 -0
  153. package/src/components/ModelViewer/modelTextDeclarations.spec.ts +336 -0
  154. package/src/components/ModelViewer/modelTextDeclarations.ts +228 -0
  155. package/src/components/ModelViewer/modelTextParse.ts +112 -0
  156. package/src/components/ModelViewer/namedQueryCode.spec.ts +58 -0
  157. package/src/components/ModelViewer/namedQueryCode.ts +26 -0
  158. package/src/components/ModelViewer/offSurface.tsx +124 -0
  159. package/src/components/ModelViewer/rowLayers.tsx +104 -0
  160. package/src/components/ModelViewer/runGate.spec.ts +219 -0
  161. package/src/components/ModelViewer/runGate.ts +145 -0
  162. package/src/components/ModelViewer/schemaModel.defaultSource.spec.ts +126 -0
  163. package/src/components/ModelViewer/schemaModel.queries.spec.ts +37 -0
  164. package/src/components/ModelViewer/schemaModel.ts +300 -0
  165. package/src/components/ModelViewer/sectionOpenCommand.tsx +125 -0
  166. package/src/components/ModelViewer/sourceAccess.spec.ts +130 -0
  167. package/src/components/ModelViewer/sourceAccess.ts +194 -0
  168. package/src/components/ModelViewer/sourceLineage.spec.ts +73 -0
  169. package/src/components/ModelViewer/sourceLineage.ts +38 -0
  170. package/src/components/ModelViewer/sourcePicker.spec.ts +294 -0
  171. package/src/components/ModelViewer/sourcePicker.ts +162 -0
  172. package/src/components/ModelViewer/surface.ts +51 -0
  173. package/src/components/ModelViewer/text.tsx +33 -0
  174. package/src/components/ModelViewer/theme.spec.ts +38 -0
  175. package/src/components/ModelViewer/theme.ts +58 -0
  176. package/src/components/ModelViewer/tokens.ts +87 -0
  177. package/src/components/ModelViewer/ui.tsx +201 -0
  178. package/src/components/ModelViewer/useDimensionSamples.spec.tsx +139 -0
  179. package/src/components/ModelViewer/useDimensionSamples.ts +220 -0
  180. package/src/components/ModelViewer/useModelSources.spec.ts +110 -0
  181. package/src/components/ModelViewer/useModelSources.ts +238 -0
  182. package/src/components/ModelViewer/useRunQuery.spec.ts +50 -0
  183. package/src/components/ModelViewer/useRunQuery.ts +223 -0
  184. package/src/components/Package/Package.agents.spec.tsx +5 -4
  185. package/src/components/Package/Package.tsx +8 -1
  186. package/src/components/ReportBuilder/emptyStart.spec.ts +8 -0
  187. package/src/components/ReportBuilder/loadMalloy.ts +8 -1
  188. package/src/components/ServerProvider.tsx +29 -3
  189. package/src/components/filter/utils.ts +4 -60
  190. package/src/components/given/FilterButton.tsx +4 -1
  191. package/src/components/given/GivenInput.tsx +8 -0
  192. package/src/components/given/GivensPanel.tsx +6 -1
  193. package/src/components/given/filterSummary.spec.ts +31 -1
  194. package/src/components/given/filterSummary.ts +41 -19
  195. package/src/components/given/useGivenUrlParams.spec.tsx +32 -0
  196. package/src/components/given/useGivenUrlParams.ts +49 -14
  197. package/src/components/index.ts +6 -1
  198. package/src/components/legacy/malloynb/Notebook.spec.tsx +38 -4
  199. package/src/components/legacy/malloynb/NotebookCell.tsx +8 -2
  200. package/src/components/modelPage.spec.ts +79 -0
  201. package/src/components/modelPage.ts +48 -0
  202. package/src/hooks/useDimensionFilters.ts +3 -58
  203. package/src/hooks/useDimensionFiltersQuery.ts +3 -58
  204. package/src/hooks/useDimensionalFilterRangeData.spec.ts +57 -0
  205. package/src/hooks/useDimensionalFilterRangeData.ts +8 -63
  206. package/src/hooks/useSuggestOptions.dom.spec.ts +54 -1
  207. package/src/hooks/useSuggestOptions.spec.ts +71 -0
  208. package/src/hooks/useSuggestOptions.ts +102 -12
  209. package/src/utils/filterCondition.spec.ts +87 -0
  210. package/src/utils/filterCondition.ts +66 -0
  211. package/src/utils/malloyLiteral.spec.ts +53 -1
  212. package/src/utils/malloyLiteral.ts +47 -12
  213. package/dist/ServerProvider-BHfg1Ed6.cjs.js +0 -1
  214. package/dist/useCompiledDocument-D7X_K6YU.cjs.js +0 -142
@@ -0,0 +1,102 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { Box, Tooltip } from "@mui/material";
5
+ import { createContext, useContext, type ReactNode } from "react";
6
+ import { focusRingSx } from "./clickableBox";
7
+ import type { RowLayer } from "./rowLayers";
8
+
9
+ /**
10
+ * The source header's facts card, as the chips on its status row see it: which
11
+ * layer it is open on (none: shut), and how a chip opens or shuts it. Provided
12
+ * by HeaderBar; absent anywhere else, where a chip is only a tooltip.
13
+ */
14
+ export interface HeaderCard {
15
+ openLayer: RowLayer | undefined;
16
+ /** The layers the card has facts for; a chip for any other stays a tooltip. */
17
+ layers: ReadonlyArray<RowLayer>;
18
+ toggle: (layer: RowLayer) => void;
19
+ cardId: string;
20
+ }
21
+
22
+ export const HeaderCardContext = createContext<HeaderCard | undefined>(
23
+ undefined,
24
+ );
25
+
26
+ /**
27
+ * A status-row chip that is also the way into the facts behind it: the chip is a
28
+ * button, `aria-expanded` saying whether its card is open; the pointer and a
29
+ * shade on hover say it opens, and it stays shaded while open. A chip whose
30
+ * layer the card has no facts for (or outside the header) is the plain focusable
31
+ * chip it always was: a tab stop whose name is its meaning. So is a chip with no layer at all
32
+ * (a file's Public / Private), which has no facts to open, only its why.
33
+ */
34
+ export function HeaderChip({
35
+ layer,
36
+ title,
37
+ children,
38
+ testId,
39
+ }: {
40
+ /** The card layer it opens; none for a chip that only says what it means. */
41
+ layer?: RowLayer;
42
+ /** The tooltip and accessible name: what the chip means. */
43
+ title: string;
44
+ children: ReactNode;
45
+ testId?: string;
46
+ }) {
47
+ const card = useContext(HeaderCardContext);
48
+ if (!card || !layer || !card.layers.includes(layer)) {
49
+ return (
50
+ <Tooltip title={title}>
51
+ <Box
52
+ component="span"
53
+ tabIndex={0}
54
+ role="img"
55
+ aria-label={title}
56
+ data-testid={testId}
57
+ sx={{ display: "inline-flex", borderRadius: 1, ...focusRingSx }}
58
+ >
59
+ {children}
60
+ </Box>
61
+ </Tooltip>
62
+ );
63
+ }
64
+ const open = card.openLayer === layer;
65
+ return (
66
+ <Tooltip title={title}>
67
+ <Box
68
+ component="button"
69
+ type="button"
70
+ onClick={() => card.toggle(layer)}
71
+ aria-expanded={open}
72
+ aria-controls={card.cardId}
73
+ aria-label={`${title} ${open ? "Hide" : "Show"} details.`}
74
+ data-testid={testId}
75
+ data-header-chip={layer}
76
+ sx={{
77
+ appearance: "none",
78
+ border: "none",
79
+ background: "none",
80
+ font: "inherit",
81
+ p: 0,
82
+ cursor: "pointer",
83
+ display: "inline-flex",
84
+ alignItems: "center",
85
+ borderRadius: 1,
86
+ // The pointer and a shade on hover say it opens; it holds the shade
87
+ // while its card is open.
88
+ "& [data-pill-tone]": {
89
+ transition: "filter 120ms ease",
90
+ ...(open ? { filter: "brightness(0.9)" } : {}),
91
+ },
92
+ "&:hover [data-pill-tone]": {
93
+ filter: open ? "brightness(0.9)" : "brightness(0.94)",
94
+ },
95
+ ...focusRingSx,
96
+ }}
97
+ >
98
+ {children}
99
+ </Box>
100
+ </Tooltip>
101
+ );
102
+ }
@@ -0,0 +1,15 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /** The HTTP status a rejected request carries (axios's `response.status`), if any. */
5
+ export function httpStatusOf(error: unknown): number | undefined {
6
+ const status = (error as { response?: { status?: unknown } } | null)
7
+ ?.response?.status;
8
+ return typeof status === "number" ? status : undefined;
9
+ }
10
+
11
+ /** A refused read: 403, or 404 for something this caller may not know exists. */
12
+ export function isNotFoundOrForbidden(error: unknown): boolean {
13
+ const status = httpStatusOf(error);
14
+ return status === 403 || status === 404;
15
+ }
@@ -0,0 +1,67 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import AbcOutlined from "@mui/icons-material/AbcOutlined";
5
+ import ArrowOutward from "@mui/icons-material/ArrowOutward";
6
+ import BarChartOutlined from "@mui/icons-material/BarChartOutlined";
7
+ import CalculateOutlined from "@mui/icons-material/CalculateOutlined";
8
+ import CalendarTodayOutlined from "@mui/icons-material/CalendarTodayOutlined";
9
+ import CallMergeOutlined from "@mui/icons-material/CallMergeOutlined";
10
+ import CodeOutlined from "@mui/icons-material/CodeOutlined";
11
+ import DataArrayOutlined from "@mui/icons-material/DataArrayOutlined";
12
+ import DataObjectOutlined from "@mui/icons-material/DataObjectOutlined";
13
+ import ExpandLess from "@mui/icons-material/ExpandLess";
14
+ import ExpandMore from "@mui/icons-material/ExpandMore";
15
+ import FormatListBulletedOutlined from "@mui/icons-material/FormatListBulletedOutlined";
16
+ import KeyboardArrowDown from "@mui/icons-material/KeyboardArrowDown";
17
+ import LockOutlined from "@mui/icons-material/LockOutlined";
18
+ import NumbersOutlined from "@mui/icons-material/NumbersOutlined";
19
+ import ScheduleOutlined from "@mui/icons-material/ScheduleOutlined";
20
+ import SellOutlined from "@mui/icons-material/SellOutlined";
21
+ import ToggleOnOutlined from "@mui/icons-material/ToggleOnOutlined";
22
+ import TuneOutlined from "@mui/icons-material/TuneOutlined";
23
+ import ViewColumnOutlined from "@mui/icons-material/ViewColumnOutlined";
24
+ import WarningAmberOutlined from "@mui/icons-material/WarningAmberOutlined";
25
+ import type { SvgIconProps } from "@mui/material";
26
+ import type { ComponentType } from "react";
27
+
28
+ /**
29
+ * The viewer's glyphs, each a Material icon drawn at a pixel size: `size` is
30
+ * the one prop a row passes, so a glyph is the same call whichever icon it is.
31
+ */
32
+ export interface IconProps {
33
+ size: number;
34
+ "aria-hidden"?: boolean;
35
+ }
36
+
37
+ export type Icon = ComponentType<IconProps>;
38
+
39
+ function sized(Glyph: ComponentType<SvgIconProps>, name: string): Icon {
40
+ const Sized = ({ size, ...rest }: IconProps) => (
41
+ <Glyph {...rest} sx={{ fontSize: size }} />
42
+ );
43
+ Sized.displayName = name;
44
+ return Sized;
45
+ }
46
+
47
+ export const IconText = sized(AbcOutlined, "IconText");
48
+ export const IconOpen = sized(ArrowOutward, "IconOpen");
49
+ export const IconResult = sized(BarChartOutlined, "IconResult");
50
+ export const IconCalculation = sized(CalculateOutlined, "IconCalculation");
51
+ export const IconDate = sized(CalendarTodayOutlined, "IconDate");
52
+ export const IconJoin = sized(CallMergeOutlined, "IconJoin");
53
+ export const IconCode = sized(CodeOutlined, "IconCode");
54
+ export const IconList = sized(DataArrayOutlined, "IconList");
55
+ export const IconRecord = sized(DataObjectOutlined, "IconRecord");
56
+ export const IconCollapse = sized(ExpandLess, "IconCollapse");
57
+ export const IconExpand = sized(ExpandMore, "IconExpand");
58
+ export const IconFields = sized(FormatListBulletedOutlined, "IconFields");
59
+ export const IconDropdown = sized(KeyboardArrowDown, "IconDropdown");
60
+ export const IconLock = sized(LockOutlined, "IconLock");
61
+ export const IconNumber = sized(NumbersOutlined, "IconNumber");
62
+ export const IconTimestamp = sized(ScheduleOutlined, "IconTimestamp");
63
+ export const IconValues = sized(SellOutlined, "IconValues");
64
+ export const IconBoolean = sized(ToggleOnOutlined, "IconBoolean");
65
+ export const IconGivens = sized(TuneOutlined, "IconGivens");
66
+ export const IconColumn = sized(ViewColumnOutlined, "IconColumn");
67
+ export const IconWarning = sized(WarningAmberOutlined, "IconWarning");
@@ -0,0 +1,26 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ export { ModelViewer, type ModelViewerProps } from "./ModelViewer";
5
+ export {
6
+ type FieldContext,
7
+ type ModelViewerExtensions,
8
+ type PickerSourceExtras,
9
+ type RunActionContext,
10
+ type SourceContext,
11
+ } from "./extensions";
12
+ export {
13
+ groupEntitiesBySource,
14
+ type FieldEntity,
15
+ type FieldEntityTable,
16
+ } from "./fieldEntities";
17
+ export { malloyIdentifier } from "./malloyRunText";
18
+ export type { ShownRun } from "./RunResult";
19
+ export type { ExplorerField as ModelViewerField } from "./schemaModel";
20
+ export type {
21
+ SampleValuesFetcher,
22
+ SampleValuesPage,
23
+ SampleValuesRequest,
24
+ } from "./useDimensionSamples";
25
+ export { modelQueryKey } from "./useModelSources";
26
+ export { runQueryKey, type QueryRunEvent } from "./useRunQuery";
@@ -0,0 +1,95 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { joinAccess } from "./joinAccess";
6
+
7
+ const browsable = (entries: Record<string, string[]>) =>
8
+ new Map(
9
+ Object.entries(entries).map(([path, names]) => [path, new Set(names)]),
10
+ );
11
+
12
+ describe("joinAccess", () => {
13
+ it("a served source gets a page", () => {
14
+ expect(
15
+ joinAccess(
16
+ { modelPath: "flights.malloy", sourceName: "carriers" },
17
+ browsable({ "flights.malloy": ["flights", "carriers"] }),
18
+ ),
19
+ ).toEqual({ kind: "link" });
20
+ });
21
+
22
+ // The whole point: the entities artifact records every join the model
23
+ // compiles, including into sources the package's `explores`/`export {}`
24
+ // kept off the served surface. Following such a link lands on a
25
+ // "no source named …" page, so the row must not offer one.
26
+ it("a source the model did not serve is join-only", () => {
27
+ expect(
28
+ joinAccess(
29
+ { modelPath: "flights.malloy", sourceName: "aircraft_models" },
30
+ browsable({ "flights.malloy": ["flights", "carriers"] }),
31
+ ),
32
+ ).toEqual({ kind: "join-only" });
33
+ });
34
+
35
+ it("judges a cross-model target against ITS model's served list", () => {
36
+ const sets = browsable({
37
+ "flights.malloy": ["flights"],
38
+ "airports.malloy": ["airports"],
39
+ });
40
+ expect(
41
+ joinAccess(
42
+ { modelPath: "airports.malloy", sourceName: "airports" },
43
+ sets,
44
+ ),
45
+ ).toEqual({
46
+ kind: "link",
47
+ });
48
+ // Same NAME, served by the other model — the model path is what decides.
49
+ expect(
50
+ joinAccess(
51
+ { modelPath: "flights.malloy", sourceName: "airports" },
52
+ sets,
53
+ ),
54
+ ).toEqual({
55
+ kind: "join-only",
56
+ });
57
+ });
58
+
59
+ // Absent means in flight *or failed*, not absent-from-the-surface.
60
+ // Rendering the note here would flash "only accessible via join" on every
61
+ // cross-model join before its model answers — and a timeout would look
62
+ // like the package curated the source away.
63
+ it("says nothing about a model that has not answered yet", () => {
64
+ expect(
65
+ joinAccess(
66
+ { modelPath: "airports.malloy", sourceName: "airports" },
67
+ browsable({}),
68
+ ),
69
+ ).toEqual({ kind: "unknown" });
70
+ });
71
+
72
+ it("a model that served nothing is join-only, not unknown", () => {
73
+ expect(
74
+ joinAccess(
75
+ { modelPath: "internal.malloy", sourceName: "staging" },
76
+ browsable({ "internal.malloy": [] }),
77
+ ),
78
+ ).toEqual({ kind: "join-only" });
79
+ });
80
+
81
+ it("incomplete join metadata is unknown", () => {
82
+ const sets = browsable({ "flights.malloy": ["carriers"] });
83
+ expect(joinAccess(undefined, sets)).toEqual({ kind: "unknown" });
84
+ expect(
85
+ joinAccess({ modelPath: "", sourceName: "carriers" }, sets),
86
+ ).toEqual({
87
+ kind: "unknown",
88
+ });
89
+ expect(
90
+ joinAccess({ modelPath: "flights.malloy", sourceName: "" }, sets),
91
+ ).toEqual({
92
+ kind: "unknown",
93
+ });
94
+ });
95
+ });
@@ -0,0 +1,54 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * Whether a join's target source is a place you can go, or only something you
6
+ * can read through this join.
7
+ *
8
+ * A package curates what it serves: `explores` in the manifest picks the model
9
+ * files, `export {}` picks the sources within them, and the publisher omits
10
+ * everything else from `listModels`/`sourceInfos`. Those omitted sources still
11
+ * compile, import and join — a served source can legitimately join one — but
12
+ * they are not addressable, and with the default `queryableSources: "declared"`
13
+ * they are not directly queryable either.
14
+ *
15
+ * The join metadata comes from a host's entities, which may record every join
16
+ * the model compiles, curated or not. So the target of a join is not evidence
17
+ * that the target has a page. The browsable set — what the publisher actually
18
+ * served us — is.
19
+ *
20
+ * Showing the joined source's fields inline is a separate question and stays
21
+ * allowed: those fields are reachable through the join path at query time
22
+ * anyway, so the curation boundary is about entry points, not field secrecy.
23
+ */
24
+ export type JoinAccess =
25
+ /** Served as its own source: the row gets its "open" arrow. */
26
+ | { kind: "link" }
27
+ /** Not served as its own source: reachable only through this join. */
28
+ | { kind: "join-only" }
29
+ /** Not established yet — say nothing rather than guess. */
30
+ | { kind: "unknown" };
31
+
32
+ export function joinAccess(
33
+ target: { modelPath: string; sourceName: string } | undefined,
34
+ /**
35
+ * modelPath → the source names that model served, for every model whose
36
+ * source list has settled successfully. A model still in flight or whose
37
+ * fetch failed is simply absent (`unknown`), so a timeout cannot look like
38
+ * curation.
39
+ */
40
+ browsableByModel: ReadonlyMap<string, ReadonlySet<string>>,
41
+ ): JoinAccess {
42
+ if (!target?.modelPath || !target.sourceName) return { kind: "unknown" };
43
+ const served = browsableByModel.get(target.modelPath);
44
+ if (!served) return { kind: "unknown" };
45
+ return served.has(target.sourceName)
46
+ ? { kind: "link" }
47
+ : { kind: "join-only" };
48
+ }
49
+
50
+ /** A resolved join target as the row renders it: the access plus, for a
51
+ * linkable one, where the arrow goes — an `href` to navigate to, or `onOpen`
52
+ * when the target is a selection on the page already showing (a join to
53
+ * another source of the same model). */
54
+ export type JoinLink = JoinAccess & { href?: string; onOpen?: () => void };
@@ -0,0 +1,48 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import {
6
+ malloyIdentifier,
7
+ namedQueryRunQuery,
8
+ viewRunQuery,
9
+ } from "./malloyRunText";
10
+
11
+ describe("malloyIdentifier", () => {
12
+ it("backtick-quotes every identifier, so a reserved word is as safe as any other name", () => {
13
+ expect(malloyIdentifier("top_carriers")).toBe("`top_carriers`");
14
+ expect(malloyIdentifier("year")).toBe("`year`");
15
+ expect(malloyIdentifier("source")).toBe("`source`");
16
+ });
17
+
18
+ it("quotes names no bare identifier could spell", () => {
19
+ expect(malloyIdentifier("order-items")).toBe("`order-items`");
20
+ expect(malloyIdentifier("1st")).toBe("`1st`");
21
+ expect(malloyIdentifier("with space")).toBe("`with space`");
22
+ });
23
+
24
+ it("escapes backslashes and backticks inside the quotes, backslashes first", () => {
25
+ expect(malloyIdentifier("a`b")).toBe("`a\\`b`");
26
+ expect(malloyIdentifier("a\\b")).toBe("`a\\\\b`");
27
+ // A trailing backslash must not escape the closing backtick.
28
+ expect(malloyIdentifier("a\\")).toBe("`a\\\\`");
29
+ expect(malloyIdentifier("a\\`")).toBe("`a\\\\\\``");
30
+ });
31
+ });
32
+
33
+ describe("run text", () => {
34
+ it("runs a view by source and name", () => {
35
+ expect(viewRunQuery("flights", "top_carriers")).toBe(
36
+ "run: `flights` -> `top_carriers`",
37
+ );
38
+ expect(viewRunQuery("order-items", "by carrier")).toBe(
39
+ "run: `order-items` -> `by carrier`",
40
+ );
41
+ });
42
+
43
+ it("runs a named query by name", () => {
44
+ expect(namedQueryRunQuery("genre_movie_map")).toBe(
45
+ "run: `genre_movie_map`",
46
+ );
47
+ });
48
+ });
@@ -0,0 +1,51 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * The Malloy text the viewer runs. Pure string building, kept apart from the
6
+ * hooks that send it so it can be tested without a DOM. Every name is quoted
7
+ * by {@link malloyIdentifier}, and no value is ever written into the text.
8
+ */
9
+
10
+ /**
11
+ * A Malloy identifier, always backtick-quoted. Quoting unconditionally is what
12
+ * makes this safe: a name that LOOKS plain can still be a reserved word (`year`,
13
+ * `source`, `count`), and the quotes are the only spelling the grammar accepts
14
+ * for one of those. Inside the quotes, backslashes are escaped before backticks
15
+ * so neither can end the quoted name early.
16
+ */
17
+ export function malloyIdentifier(name: string): string {
18
+ const escaped = name.replace(/\\/g, "\\\\").replace(/`/g, "\\`");
19
+ return `\`${escaped}\``;
20
+ }
21
+
22
+ /** The Malloy that runs a source's view by name. */
23
+ export function viewRunQuery(sourceName: string, viewName: string): string {
24
+ return `run: ${malloyIdentifier(sourceName)} -> ${malloyIdentifier(viewName)}`;
25
+ }
26
+
27
+ /** The Malloy that runs a model-level named query. */
28
+ export function namedQueryRunQuery(queryName: string): string {
29
+ return `run: ${malloyIdentifier(queryName)}`;
30
+ }
31
+
32
+ /**
33
+ * The Malloy that reads a dimension's most common values, most common first:
34
+ * what a field's Values card shows when its host has no index to ask.
35
+ */
36
+ export function sampleValuesQuery(
37
+ sourceName: string,
38
+ fieldName: string,
39
+ limit: number,
40
+ ): string {
41
+ const field = malloyIdentifier(fieldName);
42
+ return [
43
+ `run: ${malloyIdentifier(sourceName)} -> {`,
44
+ ` where: ${field} is not null`,
45
+ ` group_by: ${field}`,
46
+ ` aggregate: \`__sample_rows\` is count()`,
47
+ ` order_by: \`__sample_rows\` desc`,
48
+ ` limit: ${limit}`,
49
+ `}`,
50
+ ].join("\n");
51
+ }
@@ -0,0 +1,47 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { escapeRegExp, maskCommentsAndStrings } from "./malloyText";
6
+
7
+ describe("maskCommentsAndStrings", () => {
8
+ it("blanks line and block comments, keeping the lines", () => {
9
+ const text = "a // $X\nb -- $Y\nc /* $Z\n $W */ d";
10
+ const masked = maskCommentsAndStrings(text);
11
+ expect(masked).not.toMatch(/\$[XYZW]/);
12
+ expect(masked.split("\n")).toHaveLength(4);
13
+ expect(masked).toContain("a ");
14
+ expect(masked).toContain(" d");
15
+ expect(masked).toHaveLength(text.length);
16
+ });
17
+
18
+ it("blanks a string's contents, so a comment marker in it ends nothing", () => {
19
+ const masked = maskCommentsAndStrings(
20
+ "where: code = 'A--B' and region = $REGION",
21
+ );
22
+ expect(masked).toContain("$REGION");
23
+ expect(masked).toContain("code = ' '");
24
+ });
25
+
26
+ it("blanks escapes, double quotes, prefixes' bodies and triple quotes", () => {
27
+ const masked = maskCommentsAndStrings(
28
+ `x = 'it\\'s $A' y = "q $B" z ~ f'$C%' sql("""\nselect '$D' -- {\n""")`,
29
+ );
30
+ expect(masked).not.toMatch(/\$[ABCD]/);
31
+ expect(masked).not.toContain("{");
32
+ expect(masked).toContain("f'");
33
+ });
34
+
35
+ it("keeps a quoted identifier, which is code", () => {
36
+ expect(maskCommentsAndStrings("group_by: `order items`")).toBe(
37
+ "group_by: `order items`",
38
+ );
39
+ });
40
+ });
41
+
42
+ describe("escapeRegExp", () => {
43
+ it("matches its text literally", () => {
44
+ expect(new RegExp(escapeRegExp("a.b(c)*")).test("a.b(c)*")).toBe(true);
45
+ expect(new RegExp(escapeRegExp("a.b")).test("axb")).toBe(false);
46
+ });
47
+ });
@@ -0,0 +1,77 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * What the viewer's scans of a model file's text share: the givens a source
6
+ * reads, the order an `export { … }` lists, the source a derived one builds on.
7
+ * They read the text with regular expressions rather than the parser (which
8
+ * loads lazily), so each first masks what is not code.
9
+ */
10
+
11
+ /**
12
+ * The text with every comment and the contents of every string literal blanked
13
+ * to spaces, line breaks kept, so a scan sees only code: a `$GIVEN`, a brace or
14
+ * a keyword inside a comment or a string is not one. Offsets and line numbers
15
+ * are unchanged.
16
+ *
17
+ * Comments are `//` and `--` to the line's end, and `/* … *\/`. Strings are
18
+ * `'…'` and `"…"` (a backslash escapes the next character; a string ends at the
19
+ * line's end, as Malloy's do), with any prefix (`f'…'`, `r'…'`) left as code,
20
+ * and `"""…"""` across lines. A quoted identifier (`` `order items` ``) is code
21
+ * and is kept.
22
+ */
23
+ export function maskCommentsAndStrings(text: string): string {
24
+ let out = "";
25
+ let i = 0;
26
+ const blank = (from: number, to: number) => {
27
+ out += text.slice(from, to).replace(/[^\n]/g, " ");
28
+ i = to;
29
+ };
30
+ while (i < text.length) {
31
+ const c = text[i];
32
+ const two = text.slice(i, i + 2);
33
+ if (two === "//" || two === "--") {
34
+ const end = text.indexOf("\n", i);
35
+ blank(i, end === -1 ? text.length : end);
36
+ } else if (two === "/*") {
37
+ const end = text.indexOf("*/", i + 2);
38
+ blank(i, end === -1 ? text.length : end + 2);
39
+ } else if (text.startsWith('"""', i)) {
40
+ const end = text.indexOf('"""', i + 3);
41
+ const close = end === -1 ? text.length : end;
42
+ out += '"""';
43
+ i += 3;
44
+ blank(i, close);
45
+ if (end !== -1) {
46
+ out += '"""';
47
+ i += 3;
48
+ }
49
+ } else if (c === "'" || c === '"') {
50
+ out += c;
51
+ let j = i + 1;
52
+ while (j < text.length && text[j] !== c && text[j] !== "\n")
53
+ j += text[j] === "\\" && text[j + 1] !== "\n" ? 2 : 1;
54
+ blank(i + 1, Math.min(j, text.length));
55
+ if (text[i] === c) {
56
+ out += c;
57
+ i += 1;
58
+ }
59
+ } else if (c === "`") {
60
+ let j = i + 1;
61
+ while (j < text.length && text[j] !== "`" && text[j] !== "\n")
62
+ j += text[j] === "\\" ? 2 : 1;
63
+ const end = Math.min(j + 1, text.length);
64
+ out += text.slice(i, end);
65
+ i = end;
66
+ } else {
67
+ out += c;
68
+ i += 1;
69
+ }
70
+ }
71
+ return out;
72
+ }
73
+
74
+ /** A string matched literally inside a `RegExp`. */
75
+ export function escapeRegExp(value: string): string {
76
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
77
+ }