@malloy-publisher/sdk 0.0.248 → 0.0.249

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 (98) hide show
  1. package/README.md +32 -17
  2. package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
  3. package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
  4. package/dist/client/api.d.ts +297 -6
  5. package/dist/client/index.cjs.js +1 -1
  6. package/dist/client/index.es.js +74 -70
  7. package/dist/components/Dashboard/Dashboard.d.ts +49 -0
  8. package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
  9. package/dist/components/Dashboard/index.d.ts +2 -0
  10. package/dist/components/Notebook/Notebook.d.ts +46 -8
  11. package/dist/components/Notebook/NotebookCell.d.ts +37 -3
  12. package/dist/components/Notebook/runPlan.d.ts +29 -0
  13. package/dist/components/Notebook/types.d.ts +10 -0
  14. package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
  15. package/dist/components/Package/Package.d.ts +1 -4
  16. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  17. package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
  18. package/dist/components/ResultsDialog.d.ts +4 -1
  19. package/dist/components/ServerProvider.d.ts +2 -1
  20. package/dist/components/click_helper.d.ts +10 -1
  21. package/dist/components/drill/index.d.ts +3 -0
  22. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  23. package/dist/components/drill/resolveDrill.d.ts +159 -0
  24. package/dist/components/drill/useDrill.d.ts +63 -0
  25. package/dist/components/given/GivenInput.d.ts +27 -3
  26. package/dist/components/given/GivensPanel.d.ts +36 -7
  27. package/dist/components/given/filterValue.d.ts +117 -0
  28. package/dist/components/given/index.d.ts +1 -1
  29. package/dist/components/given/paramCodec.d.ts +60 -0
  30. package/dist/components/index.d.ts +4 -1
  31. package/dist/components/styles.d.ts +23 -0
  32. package/dist/constants/docLinks.d.ts +6 -0
  33. package/dist/{core-BuvlzSIX.es.js → core-DFBwNhvb.es.js} +1 -1
  34. package/dist/{core-C86Rb7tJ.cjs.js → core-DZk7z7ko.cjs.js} +1 -1
  35. package/dist/hooks/givenValue.d.ts +10 -0
  36. package/dist/hooks/index.d.ts +3 -1
  37. package/dist/hooks/useGivensState.d.ts +64 -0
  38. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  39. package/dist/{index-BdtAZ5k6.es.js → index-CLcRrkxd.es.js} +41221 -39894
  40. package/dist/index-CWQXhe0D.cjs.js +338 -0
  41. package/dist/index.cjs.js +1 -1
  42. package/dist/index.es.js +77 -62
  43. package/dist/theme/types.d.ts +9 -0
  44. package/package.json +3 -1
  45. package/src/components/Connections/AddConnectionDialog.tsx +10 -1
  46. package/src/components/Dashboard/Dashboard.tsx +395 -0
  47. package/src/components/Dashboard/DashboardTile.tsx +150 -0
  48. package/src/components/Dashboard/index.ts +2 -0
  49. package/src/components/Home/Home.tsx +114 -23
  50. package/src/components/Notebook/Notebook.tsx +444 -390
  51. package/src/components/Notebook/NotebookCell.tsx +117 -3
  52. package/src/components/Notebook/runPlan.spec.ts +152 -0
  53. package/src/components/Notebook/runPlan.ts +64 -0
  54. package/src/components/Notebook/types.ts +11 -0
  55. package/src/components/Package/ContentTypeIcon.spec.ts +88 -0
  56. package/src/components/Package/ContentTypeIcon.tsx +77 -6
  57. package/src/components/Package/Package.tsx +148 -38
  58. package/src/components/RenderedResult/RenderedResult.tsx +309 -19
  59. package/src/components/RenderedResult/ResultContainer.tsx +28 -1
  60. package/src/components/ResultsDialog.tsx +5 -0
  61. package/src/components/ServerProvider.tsx +2 -0
  62. package/src/components/click_helper.ts +14 -1
  63. package/src/components/drill/index.ts +25 -0
  64. package/src/components/drill/markDrillableCells.dom.spec.ts +310 -0
  65. package/src/components/drill/markDrillableCells.spec.ts +106 -0
  66. package/src/components/drill/markDrillableCells.ts +311 -0
  67. package/src/components/drill/resolveDrill.spec.ts +446 -0
  68. package/src/components/drill/resolveDrill.ts +372 -0
  69. package/src/components/drill/useDrill.tsx +200 -0
  70. package/src/components/given/GivenInput.spec.tsx +495 -15
  71. package/src/components/given/GivenInput.tsx +562 -30
  72. package/src/components/given/GivensPanel.spec.tsx +172 -0
  73. package/src/components/given/GivensPanel.tsx +139 -32
  74. package/src/components/given/filterValue.spec.ts +361 -0
  75. package/src/components/given/filterValue.ts +204 -0
  76. package/src/components/given/index.ts +5 -1
  77. package/src/components/given/paramCodec.spec.ts +854 -0
  78. package/src/components/given/paramCodec.ts +480 -0
  79. package/src/components/index.ts +4 -1
  80. package/src/components/styles.ts +27 -3
  81. package/src/constants/docLinks.spec.ts +51 -0
  82. package/src/constants/docLinks.ts +26 -0
  83. package/src/hooks/givenValue.ts +10 -0
  84. package/src/hooks/index.ts +6 -4
  85. package/src/hooks/useGivensState.spec.ts +446 -0
  86. package/src/hooks/useGivensState.ts +337 -0
  87. package/src/hooks/useSuggestOptions.spec.ts +109 -0
  88. package/src/hooks/useSuggestOptions.ts +260 -0
  89. package/src/theme/buildTableCssVars.ts +4 -0
  90. package/src/theme/resolveTheme.spec.ts +13 -0
  91. package/src/theme/resolveTheme.ts +3 -0
  92. package/src/theme/types.ts +9 -0
  93. package/test/README.md +16 -10
  94. package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
  95. package/dist/hooks/useGivensForm.d.ts +0 -35
  96. package/dist/index-MES4MGpQ.cjs.js +0 -309
  97. package/src/hooks/useGivensForm.spec.ts +0 -99
  98. package/src/hooks/useGivensForm.ts +0 -107
@@ -0,0 +1,150 @@
1
+ import { Box, Paper, Typography } from "@mui/material";
2
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
3
+ import type { GivenValue } from "../../hooks/givenValue";
4
+ import { CHART_RESULT_QUERY_OPTIONS } from "../../utils/queryClient";
5
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
6
+ import { humanizeSlug, type DrillBinding } from "../drill";
7
+ import { givensToRequest } from "../given/paramCodec";
8
+ import { Loading } from "../Loading";
9
+ import ResultContainer from "../RenderedResult/ResultContainer";
10
+ import { useServer } from "../ServerProvider";
11
+
12
+ export interface DashboardTileProps {
13
+ environmentName: string;
14
+ packageName: string;
15
+ modelPath: string;
16
+ /** A named query (the single-query form). */
17
+ queryName?: string;
18
+ /** A run expression (a composite tile). */
19
+ tile?: string;
20
+ /**
21
+ * The whole applied control row, NOT this tile's share of it. The narrowing
22
+ * happens here, in `givensToRequest` below, using {@link givenNames}: the
23
+ * caller does not know which givens a tile references and this component
24
+ * does.
25
+ */
26
+ givens: Map<string, GivenValue>;
27
+ /** Declared type per given name, which decides how a value is encoded. */
28
+ declaredTypes: ReadonlyMap<string, string | undefined>;
29
+ /**
30
+ * Given names this tile references, or undefined when discovery could not
31
+ * resolve the tile. Undefined means "send the whole control row", which the
32
+ * server accepts: a surfaced given a query does not reference is ignored.
33
+ */
34
+ givenNames?: string[];
35
+ height: number;
36
+ maxResultSize?: number;
37
+ /** Cell clicks and their affordance, for the dashboard's `# drill`. */
38
+ drill?: DrillBinding;
39
+ }
40
+
41
+ /**
42
+ * A composite tile's heading, read off its run expression: the last step's name
43
+ * as a sentence, so `scoped_sales -> sales_by_month` is titled "Sales by month".
44
+ *
45
+ * A tile in the single-query form gets its heading from a `# label` on the nest,
46
+ * and a composite tile has no nest to label: the entry is a string in
47
+ * `tiles=[…]`. Deriving it keeps the two forms reading alike instead of one
48
+ * showing titles and the other showing code.
49
+ */
50
+ export function tileTitle(tile: string): string {
51
+ const lastStep = tile.split("->").at(-1)?.trim() ?? tile;
52
+ // Anything that is not a bare name (an inline `{ … }` stage, say) has no
53
+ // sensible title to derive, so it keeps the expression as written.
54
+ return /^[A-Za-z_][\w-]*$/.test(lastStep) ? humanizeSlug(lastStep) : tile;
55
+ }
56
+
57
+ /**
58
+ * One result panel: run it, render it, and keep its failure to itself.
59
+ *
60
+ * A tile owning its own query is what lets a composite dashboard survive a bad
61
+ * tile: the broken one shows its error in place and the rest of the grid still
62
+ * renders, rather than one failure blanking the page.
63
+ */
64
+ export function DashboardTile({
65
+ environmentName,
66
+ packageName,
67
+ modelPath,
68
+ queryName,
69
+ tile,
70
+ givens,
71
+ declaredTypes,
72
+ givenNames,
73
+ height,
74
+ maxResultSize,
75
+ drill,
76
+ }: DashboardTileProps) {
77
+ const { apiClients } = useServer();
78
+ const requestGivens = givensToRequest(givens, declaredTypes, givenNames);
79
+
80
+ const { data, isSuccess, isError, error } = useQueryWithApiError({
81
+ queryKey: [
82
+ "dashboardTile",
83
+ environmentName,
84
+ packageName,
85
+ modelPath,
86
+ queryName,
87
+ tile,
88
+ // Re-runs when the applied values change, which is the whole point of
89
+ // the control row.
90
+ JSON.stringify(requestGivens),
91
+ ],
92
+ queryFn: () =>
93
+ apiClients.models.executeQueryModel(
94
+ environmentName,
95
+ packageName,
96
+ modelPath,
97
+ {
98
+ queryName,
99
+ query: tile !== undefined ? `run: ${tile}` : undefined,
100
+ givens: requestGivens,
101
+ },
102
+ ),
103
+ ...CHART_RESULT_QUERY_OPTIONS,
104
+ });
105
+
106
+ return (
107
+ <Paper
108
+ elevation={0}
109
+ sx={{
110
+ border: 1,
111
+ borderColor: "divider",
112
+ borderRadius: 1,
113
+ overflow: "hidden",
114
+ minHeight: 120,
115
+ }}
116
+ >
117
+ {tile !== undefined && (
118
+ <Box sx={{ px: 2.5, pt: 2 }}>
119
+ <Typography
120
+ variant="subtitle2"
121
+ sx={{ fontWeight: 500, color: "text.secondary" }}
122
+ // The expression is what actually ran, so it stays reachable
123
+ // as a tooltip rather than as the heading.
124
+ title={tile}
125
+ >
126
+ {tileTitle(tile)}
127
+ </Typography>
128
+ </Box>
129
+ )}
130
+ {!isSuccess && !isError && <Loading text="Running…" />}
131
+ {isSuccess && (
132
+ <ResultContainer
133
+ result={data.data.result}
134
+ maxHeight={height}
135
+ maxResultSize={maxResultSize}
136
+ renderLogs={data.data.renderLogs}
137
+ drill={drill}
138
+ />
139
+ )}
140
+ {isError && (
141
+ <Box sx={{ p: 2 }}>
142
+ <ApiErrorDisplay
143
+ context={tile ?? queryName ?? modelPath}
144
+ error={error}
145
+ />
146
+ </Box>
147
+ )}
148
+ </Paper>
149
+ );
150
+ }
@@ -0,0 +1,2 @@
1
+ export { Dashboard, type DashboardProps } from "./Dashboard";
2
+ export { DashboardTile, type DashboardTileProps } from "./DashboardTile";
@@ -17,6 +17,7 @@ import {
17
17
  import { useState } from "react";
18
18
  import { Environment } from "../../client";
19
19
  import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
20
+ import { serverBaseUrl } from "../../utils/dataAppEmbed";
20
21
  import { getEnvironmentDescription } from "../../utils/parsing";
21
22
  import { DOC_LINKS } from "../../constants/docLinks";
22
23
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
@@ -30,26 +31,80 @@ interface HomeProps {
30
31
  onClickEnvironment?: (to: string, event?: React.MouseEvent) => void;
31
32
  }
32
33
 
34
+ /**
35
+ * What this server can do, in the order someone meets it: exploring first, then
36
+ * the three analytics surfaces a package can hold, then the endpoint agents come
37
+ * in through and the rules that govern all of it. Anything that does not earn a
38
+ * card is named in the closing paragraph rather than crowding this list.
39
+ */
33
40
  const FEATURES: Array<{ title: string; body: string; href: string }> = [
34
41
  {
35
42
  title: "Ad-hoc analysis",
36
- body: "Browse semantic sources, build queries, and run nested logic in Explorer — no code.",
43
+ body: "Browse the semantic sources on this server and build nested queries in Explorer. Every click writes valid Malloy, so metrics stay correct even across joins.",
37
44
  href: DOC_LINKS.explorer,
38
45
  },
39
46
  {
40
- title: "Notebook dashboards",
41
- body: "Code-first dashboards using Malloy notebooks. Versioned alongside your models.",
42
- href: DOC_LINKS.publishing,
47
+ title: "Notebooks",
48
+ body: "A data story: markdown and live query cells in one file, versioned beside the model it reads. Any givens it imports become a panel of filter controls above the cells.",
49
+ href: DOC_LINKS.surfaces,
50
+ },
51
+ {
52
+ title: "Dashboards",
53
+ body: "A tagged Malloy file is the page. Tags lay out the grid, the filter row is rendered from the query's parameters, and a tagged dimension clicks through to a detail page. No front-end code.",
54
+ href: DOC_LINKS.dashboards,
55
+ },
56
+ {
57
+ title: "Data apps",
58
+ body: "Hand-author an HTML page in a package's public directory and Publisher serves it, backed by that package's models. No build step, and it embeds in a host page.",
59
+ href: DOC_LINKS.dataApps,
43
60
  },
44
61
  {
45
62
  title: "AI data agents",
46
- body: "Expose models via MCP so agents can discover sources and ask well-formed questions.",
63
+ body: "One MCP endpoint. Agents discover the sources, compile-check the Malloy they write, and ask well-formed questions instead of guessing at raw tables.",
47
64
  href: DOC_LINKS.mcpAgents,
48
65
  },
66
+ {
67
+ // Deliberately not "so every caller sees only their rows". Givens are
68
+ // caller-asserted (docs/row-level-access.md), so a row-level filter is not
69
+ // a boundary on its own; `#(authorize)` is the thing that refuses. What is
70
+ // true, and what this says, is that the declarations live in the model, so
71
+ // no surface can define its own.
72
+ title: "Governed access",
73
+ body: "Runtime parameters, row-level filters, and per-source access gates are declared in the model, so every surface reads the same rules rather than reimplementing them.",
74
+ href: DOC_LINKS.givens,
75
+ },
49
76
  ];
50
77
 
78
+ function InlineLink({
79
+ href,
80
+ external = true,
81
+ children,
82
+ }: {
83
+ href: string;
84
+ /**
85
+ * Whether to open in a new tab. False for the API spec, which is served by
86
+ * the Publisher server and replaces the console deliberately; true for
87
+ * off-site targets. `target` and `rel` are both driven from this one flag so
88
+ * they cannot desynchronise.
89
+ */
90
+ external?: boolean;
91
+ children: React.ReactNode;
92
+ }) {
93
+ return (
94
+ <Box
95
+ component="a"
96
+ href={href}
97
+ target={external ? "_blank" : undefined}
98
+ rel={external ? "noopener noreferrer" : undefined}
99
+ sx={{ color: "text.primary", textDecoration: "underline" }}
100
+ >
101
+ {children}
102
+ </Box>
103
+ );
104
+ }
105
+
51
106
  export default function Home({ onClickEnvironment }: HomeProps) {
52
- const { apiClients, mutable } = useServer();
107
+ const { apiClients, mutable, server } = useServer();
53
108
 
54
109
  const { data, isSuccess, isError, error } = useQueryWithApiError({
55
110
  queryKey: ["environments"],
@@ -85,16 +140,24 @@ export default function Home({ onClickEnvironment }: HomeProps) {
85
140
  color="text.secondary"
86
141
  sx={{ maxWidth: 720, lineHeight: 1.6 }}
87
142
  >
88
- Define semantic models once — and use them everywhere. Publisher
89
- serves Malloy models through clean APIs, enabling consistent,
90
- interpretable, and AI-ready data access for tools, applications,
91
- and agents.
143
+ Define semantic models once and use them everywhere. Publisher
144
+ serves Malloy models over a REST API and a single MCP endpoint,
145
+ so applications, BI tools, and AI agents compose queries against
146
+ the model instead of writing SQL, and the numbers come back right
147
+ by construction.
92
148
  </Typography>
93
149
  </Box>
94
150
 
151
+ {/* Two columns at every width above the phone breakpoint, and
152
+ deliberately not the three the environment grid below uses: these
153
+ bodies are prose rather than a name. Measured at 1440px, two across
154
+ gives every card a 410px column and a uniform three lines. Three
155
+ across is narrower than a third of the container, since the grid
156
+ subtracts its gutters, and the bodies then wrap unevenly so the row
157
+ heights stop matching. */}
95
158
  <Grid container spacing={4} sx={{ mb: 5 }}>
96
159
  {FEATURES.map((feature) => (
97
- <Grid size={{ xs: 12, md: 4 }} key={feature.title}>
160
+ <Grid size={{ xs: 12, sm: 6 }} key={feature.title}>
98
161
  <Stack spacing={1}>
99
162
  <Typography
100
163
  variant="body2"
@@ -198,21 +261,49 @@ export default function Home({ onClickEnvironment }: HomeProps) {
198
261
 
199
262
  <Divider sx={{ my: 4 }} />
200
263
 
201
- <Typography variant="body2" color="text.secondary">
264
+ <Typography
265
+ variant="body2"
266
+ color="text.secondary"
267
+ sx={{ maxWidth: 720, lineHeight: 1.6 }}
268
+ >
269
+ {/* Six of the ten types in the api-doc.yaml enum. connections.md
270
+ names eight. Two of the six named here, mysql and trino,
271
+ appear in connections.md exactly once, in the parenthetical that
272
+ ends "etc."; Databricks and MotherDuck it never names at all. "And more"
273
+ rather than a full list, because a list that reads as complete
274
+ while omitting Databricks is worse than a short one that says
275
+ it is short. */}
276
+ Also here:{" "}
277
+ <InlineLink href={DOC_LINKS.connections}>connections</InlineLink> to
278
+ BigQuery, Snowflake, Postgres, MySQL, Trino, DuckDB and more;{" "}
279
+ <InlineLink href={DOC_LINKS.materialization}>
280
+ materialized tables
281
+ </InlineLink>{" "}
282
+ built on demand or on a schedule; and a{" "}
283
+ {/* Built from the configured server rather than written as
284
+ "/api-doc.html". The spec is a static file off the Publisher
285
+ server's root, and an SDK consumer's page origin need not be
286
+ that server: a root-relative href resolves against the host and
287
+ 404s. serverBaseUrl exists for exactly this. */}
288
+ <InlineLink
289
+ href={`${serverBaseUrl(server)}/api-doc.html`}
290
+ external={false}
291
+ >
292
+ REST API
293
+ </InlineLink>{" "}
294
+ that does everything this console does.
295
+ </Typography>
296
+
297
+ <Typography
298
+ variant="body2"
299
+ color="text.secondary"
300
+ sx={{ maxWidth: 720, lineHeight: 1.6, mt: 2 }}
301
+ >
202
302
  Publisher is built on fully open infrastructure and designed for the
203
303
  AI era. Join the{" "}
204
- <Box
205
- component="a"
206
- href="https://join.slack.com/t/malloy-community/shared_invite/zt-1kgfwgi5g-CrsdaRqs81QY67QW0~t_uw"
207
- target="_blank"
208
- rel="noopener noreferrer"
209
- sx={{
210
- color: "text.primary",
211
- textDecoration: "underline",
212
- }}
213
- >
304
+ <InlineLink href="https://join.slack.com/t/malloy-community/shared_invite/zt-1kgfwgi5g-CrsdaRqs81QY67QW0~t_uw">
214
305
  Malloy Slack community
215
- </Box>{" "}
306
+ </InlineLink>{" "}
216
307
  to ask questions, share ideas, and contribute.
217
308
  </Typography>
218
309
  </Container>