@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,14 @@
1
+ import { FilterSelection } from '../hooks/useDimensionFilters';
2
+ /**
3
+ * One dimension filter's selection as a Malloy condition on `fieldName` (an
4
+ * already-quoted path such as `` `name` ``), or "" when the selection says
5
+ * nothing a condition can.
6
+ *
7
+ * The one place a dimension filter's value becomes Malloy text. A "Contains"
8
+ * value is written in the string filter grammar, where `,` separates
9
+ * alternatives and `%` and `_` are wildcards, so it goes out through
10
+ * `@malloydata/malloy-filter`'s own printer rather than being spliced into
11
+ * `%…%`: spliced, "a,b" matched `a` and `b` but not "a,b", and "50%" also
12
+ * matched "500".
13
+ */
14
+ export declare function filterCondition(fieldName: string, selection: FilterSelection): string;
@@ -9,5 +9,24 @@
9
9
  * value, or one the type cannot spell.
10
10
  */
11
11
  export declare function malloyLiteral(value: unknown, type?: string): string | undefined;
12
- /** A filter value as a Malloy literal; unlike `malloyLiteral`, a Date is spelled as a local-time day. */
12
+ /**
13
+ * Filter text as a Malloy filter literal: `f'…'`.
14
+ *
15
+ * Malloy hands the text between the quotes to the filter parser as written, so
16
+ * the filter grammar's own escapes (`\,` for a comma that is part of a value,
17
+ * `\%` for a percent sign) have to reach it untouched. Only a quote the text
18
+ * leaves bare is escaped, and a lone trailing backslash is doubled so it cannot
19
+ * swallow the closing quote. Escaping filter text the way a string literal is
20
+ * escaped doubles every backslash, and `a\,b`, the one value "a,b", runs as
21
+ * "a\" or "b".
22
+ */
23
+ export declare function malloyFilterLiteral(filter: string): string;
24
+ /**
25
+ * A filter value as a Malloy literal; unlike `malloyLiteral`, a Date is spelled
26
+ * as a local-time day. A string is a quoted string, whatever it holds, except
27
+ * where `isDate` says the dimension is a date and the string is an ISO date or
28
+ * timestamp, which is written as a date literal (`@2024-01-31`). Any other
29
+ * string stays quoted with `isDate` too: written after `@` unquoted, a value
30
+ * like `2024-01-31 or true` became Malloy.
31
+ */
13
32
  export declare function formatMalloyValue(value: string | number | boolean | Date | null | undefined, isDate?: boolean): string;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.12.0",
4
+ "version": "0.12.2",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -75,7 +75,7 @@
75
75
  "build": "bun generate-api-types && bunx vite build",
76
76
  "postbuild": "cp ../../node_modules/@malloydata/malloy-explorer/dist/malloy-explorer.css ./dist/malloy-explorer.css && echo '/* SDK Styles */\n@import \"./malloy-explorer.css\";' > ./dist/styles.css",
77
77
  "test": "bun test",
78
- "test:tz": "bun test ./src/components/given/GivenInput.spec.tsx ./src/components/given/filterSummary.spec.ts ./src/components/given/paramCodec.spec.ts ./src/utils/malloyLiteral.spec.ts ./src/components/drill/resolveDrill.spec.ts ./src/components/ReportBuilder/preview.spec.ts ./src/components/Materializations/cron.spec.ts ./src/components/Materializations/utils.spec.ts",
78
+ "test:tz": "bun test ./src/components/given/GivenInput.spec.tsx ./src/components/given/filterSummary.spec.ts ./src/components/given/paramCodec.spec.ts ./src/utils/malloyLiteral.spec.ts ./src/utils/filterCondition.spec.ts ./src/hooks/useDimensionalFilterRangeData.spec.ts ./src/components/drill/resolveDrill.spec.ts ./src/components/ReportBuilder/preview.spec.ts ./src/components/Materializations/cron.spec.ts ./src/components/Materializations/utils.spec.ts",
79
79
  "lint": "bunx eslint ./src ./test --fix",
80
80
  "format": "bunx prettier --write --parser typescript '**/*.{ts,tsx}'",
81
81
  "analyze": "bunx vite-bundle-visualizer",
@@ -18,6 +18,7 @@ import {
18
18
  Typography,
19
19
  } from "@mui/material";
20
20
  import { BuildPlan, Materialization } from "../../client";
21
+ import { Loading, LOADING_COPY } from "../Loading";
21
22
  import { MONO_FONT_FAMILY } from "../styles";
22
23
  import ManifestView from "./ManifestView";
23
24
  import SectionLabel from "./SectionLabel";
@@ -33,13 +34,21 @@ import {
33
34
  statusLabel,
34
35
  } from "./utils";
35
36
 
37
+ /**
38
+ * The package's current build plan (GET …/build-plan), shown for context. It
39
+ * is a property of the package version, not the historical run. A ready plan
40
+ * is null for a package with no persist sources, which is why the section
41
+ * renders an empty state rather than disappearing; a plan the server could not
42
+ * produce is `unavailable`, which must not read as that empty state.
43
+ */
44
+ export type BuildPlanState =
45
+ | { status: "loading" }
46
+ | { status: "unavailable" }
47
+ | { status: "ready"; plan: BuildPlan | null };
48
+
36
49
  type MaterializationDetailDialogProps = {
37
50
  materialization: Materialization | null;
38
- // The compiled package's current build plan (Package.buildPlan), shown for
39
- // context. It is a property of the package version, not the historical run,
40
- // and it is null for a package with no persist sources — which is why the
41
- // section renders an empty state rather than disappearing.
42
- buildPlan: BuildPlan | null;
51
+ buildPlan: BuildPlanState;
43
52
  onClose: () => void;
44
53
  };
45
54
 
@@ -50,7 +59,10 @@ export default function MaterializationDetailDialog({
50
59
  }: MaterializationDetailDialogProps) {
51
60
  const meta = materialization ? parseMetadata(materialization) : {};
52
61
  const refused = materialization ? refusedSourcesOf(materialization) : [];
53
- const planSources = Object.values(buildPlan?.sources ?? {});
62
+ const planSources =
63
+ buildPlan.status === "ready"
64
+ ? Object.values(buildPlan.plan?.sources ?? {})
65
+ : [];
54
66
 
55
67
  return (
56
68
  <Dialog
@@ -218,7 +230,21 @@ export default function MaterializationDetailDialog({
218
230
 
219
231
  <Box sx={{ mb: 3 }}>
220
232
  <SectionLabel>Build plan</SectionLabel>
221
- {planSources.length === 0 ? (
233
+ {buildPlan.status === "loading" ? (
234
+ <Loading
235
+ text={LOADING_COPY.loading}
236
+ size={16}
237
+ centered={false}
238
+ />
239
+ ) : buildPlan.status === "unavailable" ? (
240
+ <Typography
241
+ variant="body2"
242
+ color="text.secondary"
243
+ sx={{ fontStyle: "italic" }}
244
+ >
245
+ The build plan is unavailable.
246
+ </Typography>
247
+ ) : planSources.length === 0 ? (
222
248
  <Typography
223
249
  variant="body2"
224
250
  color="text.secondary"
@@ -21,7 +21,9 @@ import { PackageSection } from "../PackageSection";
21
21
  import { useServer } from "../ServerProvider";
22
22
  import { describeCron, formatNextRun } from "./cron";
23
23
  import CreateMaterializationDialog from "./CreateMaterializationDialog";
24
- import MaterializationDetailDialog from "./MaterializationDetailDialog";
24
+ import MaterializationDetailDialog, {
25
+ type BuildPlanState,
26
+ } from "./MaterializationDetailDialog";
25
27
  import MaterializationRunsList from "./MaterializationRunsList";
26
28
  import ScopeButton from "./ScopeButton";
27
29
  import SetScheduleDialog from "./SetScheduleDialog";
@@ -85,8 +87,7 @@ export default function Materializations({
85
87
  },
86
88
  });
87
89
 
88
- // The build plan is a property of the compiled package (Package.buildPlan),
89
- // not of a historical run, so fetch it from the package for the detail view.
90
+ // The package's materialization settings (schedule, freshness, scope).
90
91
  const packageQuery = useQueryWithApiError({
91
92
  queryKey: ["package", environmentName, packageName, versionId],
92
93
  queryFn: () =>
@@ -97,6 +98,34 @@ export default function Materializations({
97
98
  ),
98
99
  });
99
100
 
101
+ // The build plan of the package as loaded, from its own route. Only the
102
+ // detail dialog shows it, so it is fetched when a run is opened rather than
103
+ // on mount. A server that predates the route answers 404, and its package
104
+ // response still carries the plan inline, so that is read instead (`inline`
105
+ // below). Any other failure — a plan that failed at load answers 409
106
+ // BUILD_PLAN_UNAVAILABLE — is shown as unavailable, never as "no persist
107
+ // sources".
108
+ const buildPlanQuery = useQueryWithApiError({
109
+ queryKey: ["package-build-plan", environmentName, packageName, versionId],
110
+ queryFn: async ({ signal }) => {
111
+ try {
112
+ const response = await apiClients.packages.getPackageBuildPlan(
113
+ environmentName,
114
+ packageName,
115
+ versionId,
116
+ { signal },
117
+ );
118
+ return { inline: false, plan: response.data };
119
+ } catch (error) {
120
+ const status = (error as { response?: { status?: number } })
121
+ ?.response?.status;
122
+ if (status === 404) return { inline: true, plan: null };
123
+ throw error;
124
+ }
125
+ },
126
+ enabled: selectedId !== null,
127
+ });
128
+
100
129
  const invalidateList = () =>
101
130
  queryClient.invalidateQueries({
102
131
  queryKey: ["materializations", environmentName, packageName],
@@ -243,6 +272,20 @@ export default function Materializations({
243
272
  stopMaterialization.isPending ||
244
273
  deleteMaterialization.isPending;
245
274
 
275
+ const buildPlan: BuildPlanState = buildPlanQuery.isError
276
+ ? { status: "unavailable" }
277
+ : !buildPlanQuery.isSuccess
278
+ ? { status: "loading" }
279
+ : !buildPlanQuery.data.inline
280
+ ? { status: "ready", plan: buildPlanQuery.data.plan }
281
+ : packageQuery.isSuccess
282
+ ? // `buildPlan` is deprecated on the package response; it is read
283
+ // only from a server old enough to lack the route.
284
+ { status: "ready", plan: currentPackage?.buildPlan ?? null }
285
+ : packageQuery.isError
286
+ ? { status: "unavailable" }
287
+ : { status: "loading" };
288
+
246
289
  const schedule = currentPackage?.materialization?.schedule ?? null;
247
290
  const scope =
248
291
  currentPackage?.scope === PackageScopeEnum.Version
@@ -357,7 +400,7 @@ export default function Materializations({
357
400
 
358
401
  <MaterializationDetailDialog
359
402
  materialization={selected}
360
- buildPlan={packageQuery.data?.data?.buildPlan ?? null}
403
+ buildPlan={buildPlan}
361
404
  onClose={() => setSelectedId(null)}
362
405
  />
363
406
 
@@ -5,6 +5,10 @@
5
5
  * A pinned version's runs are that version's: the section lists them for it,
6
6
  * and deleting one names it too, so the server refuses a run of another
7
7
  * version (404) or of an archived one (410) rather than deleting by id alone.
8
+ *
9
+ * The build plan the detail dialog shows is fetched only once a run is opened,
10
+ * falls back to the package response's inline plan on a server without the
11
+ * route (404), and reads as unavailable on any other failure.
8
12
  */
9
13
  import { beforeEach, expect, it, mock } from "bun:test";
10
14
  import { fireEvent, render, screen, waitFor } from "@testing-library/react";
@@ -41,9 +45,50 @@ const deleteMaterialization = mock(
41
45
  ) => Promise.resolve({ data: undefined }),
42
46
  );
43
47
 
48
+ const EMPTY_PLAN = { graphs: [], sources: {} };
49
+
50
+ const PLAN_SOURCE = {
51
+ name: "orders_daily",
52
+ sourceID: "orders_daily@model.malloy",
53
+ connectionName: "duckdb",
54
+ dialect: "duckdb",
55
+ columns: [],
56
+ sourceEntityId: "entity-1",
57
+ };
58
+
59
+ function planWith(name: string) {
60
+ return {
61
+ graphs: [],
62
+ sources: { [name]: { ...PLAN_SOURCE, name, sourceID: name } },
63
+ };
64
+ }
65
+
66
+ function httpError(status: number, data: Record<string, unknown>) {
67
+ return Object.assign(
68
+ new Error(`Request failed with status code ${status}`),
69
+ { response: { status, data } },
70
+ );
71
+ }
72
+
73
+ const getPackageBuildPlan = mock(
74
+ (
75
+ _environmentName: string,
76
+ _packageName: string,
77
+ _versionId?: string,
78
+ _options?: unknown,
79
+ ): Promise<{ data: unknown }> => Promise.resolve({ data: EMPTY_PLAN }),
80
+ );
81
+ const getPackage = mock(
82
+ (
83
+ _environmentName: string,
84
+ _packageName: string,
85
+ _versionId?: string,
86
+ ): Promise<{ data: unknown }> => pending(),
87
+ );
88
+
44
89
  mockServerProvider(
45
90
  {
46
- packages: { getPackage: pending },
91
+ packages: { getPackage, getPackageBuildPlan },
47
92
  materializations: { listMaterializations, deleteMaterialization },
48
93
  },
49
94
  { mutable: true },
@@ -55,8 +100,26 @@ beforeEach(() => {
55
100
  clearCache();
56
101
  listMaterializations.mockClear();
57
102
  deleteMaterialization.mockClear();
103
+ getPackageBuildPlan.mockReset();
104
+ getPackageBuildPlan.mockImplementation(() =>
105
+ Promise.resolve({ data: EMPTY_PLAN }),
106
+ );
107
+ getPackage.mockReset();
108
+ getPackage.mockImplementation(() => pending());
58
109
  });
59
110
 
111
+ async function openTheRun(resourceUri: string) {
112
+ render(<Materializations resourceUri={resourceUri} />, {
113
+ wrapper: serverWrapper,
114
+ });
115
+ fireEvent.click(
116
+ await screen.findByRole("button", {
117
+ name: "View materialization run-1 details",
118
+ }),
119
+ );
120
+ await screen.findByRole("dialog");
121
+ }
122
+
60
123
  async function deleteTheRun(resourceUri: string) {
61
124
  render(<Materializations resourceUri={resourceUri} />, {
62
125
  wrapper: serverWrapper,
@@ -99,3 +162,79 @@ it("deletes with no version when none is pinned, as before", async () => {
99
162
  undefined,
100
163
  ]);
101
164
  });
165
+
166
+ it("fetches the build plan only when a run is opened, for the pinned version", async () => {
167
+ await openTheRun("publisher://environments/env/packages/pkg?versionId=v2");
168
+
169
+ await waitFor(() => expect(getPackageBuildPlan).toHaveBeenCalledTimes(1));
170
+ expect(getPackageBuildPlan.mock.calls[0]?.slice(0, 3)).toEqual([
171
+ "env",
172
+ "pkg",
173
+ "v2",
174
+ ]);
175
+ expect(
176
+ await screen.findByText("This package has no persist sources."),
177
+ ).toBeTruthy();
178
+ });
179
+
180
+ it("does not fetch the build plan before a run is opened", async () => {
181
+ render(
182
+ <Materializations resourceUri="publisher://environments/env/packages/pkg" />,
183
+ {
184
+ wrapper: serverWrapper,
185
+ },
186
+ );
187
+ await screen.findByRole("button", {
188
+ name: "View materialization run-1 details",
189
+ });
190
+
191
+ expect(getPackageBuildPlan).not.toHaveBeenCalled();
192
+ });
193
+
194
+ it("shows the route's plan when the server answers it", async () => {
195
+ getPackageBuildPlan.mockImplementation(() =>
196
+ Promise.resolve({ data: planWith("orders_daily") }),
197
+ );
198
+
199
+ await openTheRun("publisher://environments/env/packages/pkg");
200
+
201
+ expect(await screen.findByText("orders_daily")).toBeTruthy();
202
+ });
203
+
204
+ it("falls back to the package's inline plan on a server without the route", async () => {
205
+ getPackageBuildPlan.mockImplementation(() =>
206
+ Promise.reject(httpError(404, { message: "Not Found" })),
207
+ );
208
+ getPackage.mockImplementation(() =>
209
+ Promise.resolve({
210
+ data: { name: "pkg", buildPlan: planWith("inline_source") },
211
+ }),
212
+ );
213
+
214
+ await openTheRun("publisher://environments/env/packages/pkg");
215
+
216
+ expect(await screen.findByText("inline_source")).toBeTruthy();
217
+ expect(
218
+ screen.queryByText("This package has no persist sources."),
219
+ ).toBeNull();
220
+ });
221
+
222
+ it("says the plan is unavailable, not empty, when the server cannot produce it", async () => {
223
+ getPackageBuildPlan.mockImplementation(() =>
224
+ Promise.reject(
225
+ httpError(409, {
226
+ code: "BUILD_PLAN_UNAVAILABLE",
227
+ message: "The build plan failed at load",
228
+ }),
229
+ ),
230
+ );
231
+
232
+ await openTheRun("publisher://environments/env/packages/pkg");
233
+
234
+ expect(
235
+ await screen.findByText("The build plan is unavailable."),
236
+ ).toBeTruthy();
237
+ expect(
238
+ screen.queryByText("This package has no persist sources."),
239
+ ).toBeNull();
240
+ });
@@ -0,0 +1,269 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import "@malloydata/malloy-explorer/styles.css";
5
+ import LinkOutlinedIcon from "@mui/icons-material/LinkOutlined";
6
+ import SearchIcon from "@mui/icons-material/Search";
7
+ import {
8
+ Box,
9
+ IconButton,
10
+ Snackbar,
11
+ Stack,
12
+ Tooltip,
13
+ Typography,
14
+ } from "@mui/material";
15
+ import React, { useState } from "react";
16
+ import { parseResourceUri } from "../../utils/formatting";
17
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
18
+ import { FloatingIconButton } from "../FloatingIconButton";
19
+ import { Loading } from "../Loading";
20
+ import { ModelCell } from "./ModelCell";
21
+ import { ModelExplorer } from "./ModelExplorer";
22
+ import type { ModelProps } from "./Model";
23
+ import { ModelExplorerDialog } from "./ModelExplorerDialog";
24
+ import { QueryExplorerResult } from "./SourcesExplorer";
25
+ import { useModelData } from "./useModelData";
26
+
27
+ // Note: For this to properly render outside of publisher,
28
+ // you must explicitly import the styles from the package:
29
+ // import "@malloy-publisher/sdk/malloy-explorer.css";
30
+
31
+ /**
32
+ * The model page on a server whose `PUBLISHER_MODEL_PAGE` is `explorer`, the
33
+ * default: the Malloy Explorer over the model's sources, and its named
34
+ * queries. The Explorer writes the queries it builds back to Malloy text
35
+ * through `@malloydata/malloy-interfaces`, which puts a string value in
36
+ * unescaped, so a drilled value holding a double quote rewrites its query.
37
+ */
38
+ export function ExplorerPage({
39
+ onChange,
40
+ resourceUri,
41
+ runOnDemand = false,
42
+ maxResultSize = 0,
43
+ givens,
44
+ onGivensChange,
45
+ }: ModelProps) {
46
+ const { modelPath } = parseResourceUri(resourceUri);
47
+ const { data, isError, isLoading, error } = useModelData(resourceUri);
48
+ const [dialogOpen, setDialogOpen] = React.useState(false);
49
+ const [sharedQuery, setSharedQuery] = React.useState<
50
+ QueryExplorerResult | undefined
51
+ >();
52
+ const [sharedSourceIndex, setSharedSourceIndex] = React.useState(0);
53
+ const [copyMessage, setCopyMessage] = useState("");
54
+ // Held here only when the host passes neither prop, so the embedded
55
+ // explorer and the maximized dialog still agree on one set of values
56
+ // rather than each defaulting independently.
57
+ const [localGivens, setLocalGivens] = React.useState<Record<string, string>>(
58
+ {},
59
+ );
60
+ const effectiveGivens = givens ?? localGivens;
61
+ const effectiveOnGivensChange =
62
+ onGivensChange ??
63
+ ((applied: Record<string, string>) => setLocalGivens(applied));
64
+
65
+ // Whether the model imports other files — drives the empty-state hint for
66
+ // import-only models, whose discovery surface is legitimately empty (no
67
+ // local sources, no export{}) but whose page would otherwise render blank.
68
+ // `modelDef` is returned by the server but intentionally absent from the
69
+ // typed CompiledModel schema (internal compiler blob), hence the cast.
70
+ const modelDefJson = (data as { modelDef?: string } | undefined)?.modelDef;
71
+ const hasImports = React.useMemo(() => {
72
+ if (!modelDefJson) return false;
73
+ try {
74
+ const def = JSON.parse(modelDefJson) as { imports?: unknown[] };
75
+ return Array.isArray(def.imports) && def.imports.length > 0;
76
+ } catch {
77
+ return false;
78
+ }
79
+ }, [modelDefJson]);
80
+
81
+ if (isLoading) {
82
+ return <Loading text="Fetching Model..." />;
83
+ }
84
+
85
+ if (isError) {
86
+ console.log("error", error);
87
+ return <ApiErrorDisplay error={error} context={`Model > ${modelPath}`} />;
88
+ }
89
+
90
+ // Shared handlers for both embedded and dialog explorers
91
+ const handleQueryChange = (query: QueryExplorerResult) => {
92
+ setSharedQuery(query);
93
+ if (onChange) {
94
+ onChange(query);
95
+ }
96
+ };
97
+
98
+ const handleSourceChange = (index: number) => {
99
+ setSharedSourceIndex(index);
100
+ };
101
+
102
+ const copyToClipboard = () => {
103
+ const url = window.location.href;
104
+ navigator.clipboard
105
+ .writeText(url)
106
+ .then(() => setCopyMessage("URL copied to clipboard!"))
107
+ .catch(() => setCopyMessage("Failed to copy URL"));
108
+ };
109
+
110
+ return (
111
+ <>
112
+ <Box
113
+ sx={{
114
+ position: "relative",
115
+ maxWidth: "1200px",
116
+ margin: "0 auto",
117
+ paddingTop: "24px",
118
+ }}
119
+ >
120
+ {/* Sources Section */}
121
+ {Array.isArray(data?.sourceInfos) &&
122
+ data.sourceInfos.length > 0 && (
123
+ <Stack spacing={2} component="section">
124
+ {/* Sources Header */}
125
+ <Box
126
+ sx={{
127
+ padding: "0 0 16px 0",
128
+ display: "flex",
129
+ alignItems: "center",
130
+ justifyContent: "space-between",
131
+ }}
132
+ >
133
+ <Typography
134
+ variant="h1"
135
+ sx={{
136
+ fontSize: "28px",
137
+ fontWeight: "600",
138
+ color: "#1a1a1a",
139
+ marginBottom: "8px",
140
+ marginTop: "0",
141
+ paddingLeft: "0",
142
+ }}
143
+ >
144
+ Sources
145
+ </Typography>
146
+ <Tooltip title="Copy link">
147
+ <IconButton
148
+ size="small"
149
+ aria-label="Copy link"
150
+ onClick={copyToClipboard}
151
+ sx={{ color: "text.secondary" }}
152
+ >
153
+ <LinkOutlinedIcon fontSize="small" />
154
+ </IconButton>
155
+ </Tooltip>
156
+ </Box>
157
+
158
+ <ModelExplorer
159
+ data={data}
160
+ onChange={handleQueryChange}
161
+ onSourceChange={handleSourceChange}
162
+ existingQuery={sharedQuery}
163
+ initialSelectedSourceIndex={sharedSourceIndex}
164
+ resourceUri={resourceUri}
165
+ givens={effectiveGivens}
166
+ onGivensChange={effectiveOnGivensChange}
167
+ />
168
+
169
+ {/* Magnifying glass icon */}
170
+ <FloatingIconButton
171
+ aria-label="Expand results"
172
+ sx={{
173
+ position: "absolute",
174
+ top: "90px",
175
+ right: "4px",
176
+ zIndex: 2,
177
+ }}
178
+ onClick={() => setDialogOpen(true)}
179
+ >
180
+ <SearchIcon />
181
+ </FloatingIconButton>
182
+ </Stack>
183
+ )}
184
+
185
+ {/* Named Queries Section */}
186
+ {data?.queries?.length > 0 && (
187
+ <Stack
188
+ spacing={2}
189
+ component="section"
190
+ sx={{ marginTop: "24px" }}
191
+ >
192
+ {/* Named Queries Header */}
193
+ <Box sx={{ padding: "0 0 16px 0" }}>
194
+ <Typography
195
+ variant="h2"
196
+ sx={{
197
+ fontSize: "24px",
198
+ fontWeight: "600",
199
+ color: "#1a1a1a",
200
+ marginBottom: "0",
201
+ marginTop: "8px",
202
+ paddingLeft: "0",
203
+ }}
204
+ >
205
+ Named Queries
206
+ </Typography>
207
+ </Box>
208
+
209
+ {/* Render the named queries */}
210
+ {data.queries.map((query) => (
211
+ <ModelCell
212
+ key={query.name}
213
+ queryName={query.name}
214
+ annotations={query.annotations}
215
+ resourceUri={resourceUri}
216
+ runOnDemand={runOnDemand}
217
+ maxResultSize={maxResultSize}
218
+ />
219
+ ))}
220
+ </Stack>
221
+ )}
222
+
223
+ {/* Empty discovery surface: nothing exported, nothing to render.
224
+ For import-only models, say why and how to fix it — otherwise
225
+ the page reads as broken. */}
226
+ {(!Array.isArray(data?.sourceInfos) ||
227
+ data.sourceInfos.length === 0) &&
228
+ !(data?.queries && data.queries.length > 0) && (
229
+ <Box sx={{ textAlign: "center", py: 6 }}>
230
+ <Typography
231
+ variant="body1"
232
+ sx={{ color: "text.secondary", marginBottom: "8px" }}
233
+ >
234
+ This model exposes no sources or queries.
235
+ </Typography>
236
+ {hasImports && (
237
+ <Typography variant="body2" color="text.secondary">
238
+ It imports other files but re-exports nothing. Add{" "}
239
+ <code>export {"{ source_name }"}</code> to surface
240
+ imported sources here.
241
+ </Typography>
242
+ )}
243
+ </Box>
244
+ )}
245
+
246
+ {/* Model Explorer Dialog */}
247
+ <ModelExplorerDialog
248
+ open={dialogOpen}
249
+ onClose={() => setDialogOpen(false)}
250
+ resourceUri={resourceUri}
251
+ data={data}
252
+ title={`Model: ${modelPath.split("/").pop()}`}
253
+ existingQuery={sharedQuery}
254
+ initialSelectedSourceIndex={sharedSourceIndex}
255
+ onChange={handleQueryChange}
256
+ onSourceChange={handleSourceChange}
257
+ givens={effectiveGivens}
258
+ onGivensChange={effectiveOnGivensChange}
259
+ />
260
+ </Box>
261
+ <Snackbar
262
+ open={copyMessage !== ""}
263
+ autoHideDuration={6000}
264
+ onClose={() => setCopyMessage("")}
265
+ message={copyMessage}
266
+ />
267
+ </>
268
+ );
269
+ }