@malloy-publisher/sdk 0.0.248 → 0.0.250

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 (202) hide show
  1. package/README.md +37 -17
  2. package/TREE_SHAKING.md +5 -0
  3. package/bunfig.toml +3 -0
  4. package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
  5. package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
  6. package/dist/client/api.d.ts +306 -9
  7. package/dist/client/index.cjs.js +1 -1
  8. package/dist/client/index.es.js +74 -70
  9. package/dist/components/Dashboard/Dashboard.d.ts +49 -0
  10. package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
  11. package/dist/components/Dashboard/index.d.ts +2 -0
  12. package/dist/components/Notebook/Notebook.d.ts +46 -8
  13. package/dist/components/Notebook/NotebookCell.d.ts +37 -3
  14. package/dist/components/Notebook/runPlan.d.ts +29 -0
  15. package/dist/components/Notebook/types.d.ts +10 -0
  16. package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
  17. package/dist/components/Package/Package.d.ts +1 -4
  18. package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
  19. package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
  20. package/dist/components/ResultsDialog.d.ts +4 -1
  21. package/dist/components/ServerProvider.d.ts +2 -1
  22. package/dist/components/click_helper.d.ts +10 -1
  23. package/dist/components/drill/index.d.ts +3 -0
  24. package/dist/components/drill/markDrillableCells.d.ts +55 -0
  25. package/dist/components/drill/resolveDrill.d.ts +139 -0
  26. package/dist/components/drill/useDrill.d.ts +63 -0
  27. package/dist/components/given/GivenInput.d.ts +27 -3
  28. package/dist/components/given/GivensPanel.d.ts +36 -7
  29. package/dist/components/given/filterValue.d.ts +97 -0
  30. package/dist/components/given/index.d.ts +1 -1
  31. package/dist/components/given/paramCodec.d.ts +60 -0
  32. package/dist/components/index.d.ts +4 -1
  33. package/dist/components/styles.d.ts +31 -0
  34. package/dist/constants/docLinks.d.ts +6 -0
  35. package/dist/{core-C86Rb7tJ.cjs.js → core-CVXEUnnm.cjs.js} +1 -1
  36. package/dist/{core-BuvlzSIX.es.js → core-Cr-9Wkp3.es.js} +1 -1
  37. package/dist/hooks/givenValue.d.ts +10 -0
  38. package/dist/hooks/index.d.ts +3 -1
  39. package/dist/hooks/useGivensState.d.ts +64 -0
  40. package/dist/hooks/useSuggestOptions.d.ts +78 -0
  41. package/dist/index-C-KeIwsG.cjs.js +339 -0
  42. package/dist/{index-BdtAZ5k6.es.js → index-DVkelll3.es.js} +40981 -39669
  43. package/dist/index.cjs.js +1 -1
  44. package/dist/index.es.js +77 -62
  45. package/dist/theme/types.d.ts +9 -0
  46. package/dist/utils/malloyString.d.ts +7 -0
  47. package/package.json +3 -1
  48. package/src/client-entry.ts +3 -0
  49. package/src/components/AnalyzePackageButton.tsx +3 -0
  50. package/src/components/ApiErrorDisplay.tsx +3 -0
  51. package/src/components/Connections/AddConnectionDialog.tsx +13 -1
  52. package/src/components/Connections/DeleteConnectionDialog.tsx +3 -0
  53. package/src/components/Connections/EditConnectionDialog.tsx +3 -0
  54. package/src/components/Connections/common.ts +3 -0
  55. package/src/components/DOMElement/DOMElement.tsx +3 -0
  56. package/src/components/DOMElement/index.ts +3 -0
  57. package/src/components/Dashboard/Dashboard.tsx +398 -0
  58. package/src/components/Dashboard/DashboardTile.tsx +153 -0
  59. package/src/components/Dashboard/index.ts +5 -0
  60. package/src/components/DataAppViewer/DataAppViewer.tsx +3 -0
  61. package/src/components/DataAppViewer/index.ts +3 -0
  62. package/src/components/Environment/About.tsx +3 -0
  63. package/src/components/Environment/AddPackageDialog.tsx +3 -0
  64. package/src/components/Environment/ConnectionExplorer.tsx +3 -0
  65. package/src/components/Environment/Connections.tsx +3 -0
  66. package/src/components/Environment/DeletePackageDialog.tsx +3 -0
  67. package/src/components/Environment/EditPackageDialog.tsx +3 -0
  68. package/src/components/Environment/Environment.tsx +3 -0
  69. package/src/components/Environment/Packages.tsx +3 -0
  70. package/src/components/Environment/index.ts +3 -0
  71. package/src/components/Home/AddEnvironmentDialog.tsx +3 -0
  72. package/src/components/Home/DeleteEnvironmentDialog.tsx +3 -0
  73. package/src/components/Home/EditEnvironmentDialog.tsx +3 -0
  74. package/src/components/Home/Home.tsx +113 -23
  75. package/src/components/Home/index.ts +3 -0
  76. package/src/components/Loading.tsx +3 -0
  77. package/src/components/Materializations/CreateEnvMaterializationDialog.tsx +3 -0
  78. package/src/components/Materializations/CreateMaterializationDialog.tsx +3 -0
  79. package/src/components/Materializations/DeleteMaterializationDialog.tsx +3 -0
  80. package/src/components/Materializations/EnvironmentMaterializations.tsx +3 -0
  81. package/src/components/Materializations/ManifestView.tsx +3 -0
  82. package/src/components/Materializations/MaterializationDetailDialog.tsx +3 -0
  83. package/src/components/Materializations/MaterializationRunsList.tsx +3 -0
  84. package/src/components/Materializations/Materializations.tsx +3 -0
  85. package/src/components/Materializations/ScheduleCard.tsx +3 -0
  86. package/src/components/Materializations/SectionLabel.tsx +3 -0
  87. package/src/components/Materializations/SetScheduleDialog.tsx +3 -0
  88. package/src/components/Materializations/TriggerChip.tsx +3 -0
  89. package/src/components/Materializations/cron.ts +3 -0
  90. package/src/components/Materializations/index.ts +3 -0
  91. package/src/components/Materializations/utils.ts +3 -0
  92. package/src/components/Model/Model.tsx +3 -0
  93. package/src/components/Model/ModelCell.tsx +3 -0
  94. package/src/components/Model/ModelExplorer.tsx +3 -0
  95. package/src/components/Model/ModelExplorerDialog.tsx +3 -0
  96. package/src/components/Model/SourcesExplorer.tsx +3 -0
  97. package/src/components/Model/index.ts +3 -0
  98. package/src/components/Model/useModelData.ts +3 -0
  99. package/src/components/Notebook/Notebook.tsx +447 -390
  100. package/src/components/Notebook/NotebookCell.tsx +120 -3
  101. package/src/components/Notebook/index.ts +3 -0
  102. package/src/components/Notebook/runPlan.spec.ts +155 -0
  103. package/src/components/Notebook/runPlan.ts +67 -0
  104. package/src/components/Notebook/types.ts +14 -0
  105. package/src/components/Package/ContentTypeIcon.spec.ts +91 -0
  106. package/src/components/Package/ContentTypeIcon.tsx +80 -6
  107. package/src/components/Package/FileTreeView.tsx +3 -0
  108. package/src/components/Package/Models.tsx +3 -0
  109. package/src/components/Package/Package.tsx +151 -38
  110. package/src/components/Package/index.ts +3 -0
  111. package/src/components/QueryResult/QueryResult.tsx +3 -0
  112. package/src/components/QueryResult/index.ts +3 -0
  113. package/src/components/RenderedResult/RenderedResult.tsx +312 -19
  114. package/src/components/RenderedResult/ResultContainer.tsx +31 -1
  115. package/src/components/RenderedResult/index.ts +3 -0
  116. package/src/components/RenderedResult/renderLogs.spec.ts +3 -0
  117. package/src/components/RenderedResult/renderLogs.ts +3 -0
  118. package/src/components/ResultsDialog.tsx +8 -0
  119. package/src/components/ServerProvider.tsx +5 -0
  120. package/src/components/Workbook/BrowserWorkbookStorage.ts +3 -0
  121. package/src/components/Workbook/EditableMalloyCell.tsx +3 -0
  122. package/src/components/Workbook/ModelPicker.tsx +3 -0
  123. package/src/components/Workbook/MutableCell.tsx +3 -0
  124. package/src/components/Workbook/Workbook.tsx +3 -0
  125. package/src/components/Workbook/WorkbookList.tsx +3 -0
  126. package/src/components/Workbook/WorkbookManager.ts +3 -0
  127. package/src/components/Workbook/WorkbookStorage.ts +3 -0
  128. package/src/components/Workbook/WorkbookStorageProvider.tsx +3 -0
  129. package/src/components/Workbook/index.ts +3 -0
  130. package/src/components/click_helper.ts +17 -1
  131. package/src/components/drill/index.ts +28 -0
  132. package/src/components/drill/markDrillableCells.dom.spec.ts +313 -0
  133. package/src/components/drill/markDrillableCells.spec.ts +109 -0
  134. package/src/components/drill/markDrillableCells.ts +314 -0
  135. package/src/components/drill/resolveDrill.spec.ts +449 -0
  136. package/src/components/drill/resolveDrill.ts +375 -0
  137. package/src/components/drill/useDrill.tsx +203 -0
  138. package/src/components/filter/DimensionFilter.tsx +3 -0
  139. package/src/components/filter/index.ts +3 -0
  140. package/src/components/filter/utils.ts +16 -5
  141. package/src/components/given/GivenInput.spec.tsx +498 -15
  142. package/src/components/given/GivenInput.tsx +565 -30
  143. package/src/components/given/GivensPanel.spec.tsx +175 -0
  144. package/src/components/given/GivensPanel.tsx +142 -32
  145. package/src/components/given/filterValue.spec.ts +364 -0
  146. package/src/components/given/filterValue.ts +207 -0
  147. package/src/components/given/index.ts +8 -1
  148. package/src/components/given/paramCodec.spec.ts +857 -0
  149. package/src/components/given/paramCodec.ts +483 -0
  150. package/src/components/given/utils.spec.ts +3 -0
  151. package/src/components/given/utils.ts +3 -0
  152. package/src/components/highlighter.ts +3 -0
  153. package/src/components/index.ts +7 -1
  154. package/src/components/styles.ts +38 -3
  155. package/src/constants/docLinks.spec.ts +54 -0
  156. package/src/constants/docLinks.ts +29 -0
  157. package/src/hooks/givenValue.ts +13 -0
  158. package/src/hooks/index.ts +9 -4
  159. package/src/hooks/useDimensionFilters.ts +4 -7
  160. package/src/hooks/useDimensionFiltersFromSpec.ts +3 -0
  161. package/src/hooks/useDimensionFiltersQuery.ts +4 -7
  162. package/src/hooks/useDimensionalFilterRangeData.ts +4 -7
  163. package/src/hooks/useGivensState.spec.ts +449 -0
  164. package/src/hooks/useGivensState.ts +340 -0
  165. package/src/hooks/useModelGivens.ts +3 -0
  166. package/src/hooks/useQueryWithApiError.ts +3 -0
  167. package/src/hooks/useRawQueryData.ts +3 -0
  168. package/src/hooks/useSuggestOptions.spec.ts +112 -0
  169. package/src/hooks/useSuggestOptions.ts +263 -0
  170. package/src/index.ts +3 -0
  171. package/src/react-app-env.d.ts +3 -0
  172. package/src/theme/ThemeContext.tsx +3 -0
  173. package/src/theme/buildMalloyExplicitTheme.ts +3 -0
  174. package/src/theme/buildTableCssVars.spec.ts +3 -0
  175. package/src/theme/buildTableCssVars.ts +7 -0
  176. package/src/theme/buildVegaThemeOverride.spec.ts +3 -0
  177. package/src/theme/buildVegaThemeOverride.ts +3 -0
  178. package/src/theme/defaults.ts +3 -0
  179. package/src/theme/index.ts +3 -0
  180. package/src/theme/keys.ts +3 -0
  181. package/src/theme/readChartAnnotations.spec.ts +3 -0
  182. package/src/theme/readChartAnnotations.ts +3 -0
  183. package/src/theme/resolveTheme.spec.ts +16 -0
  184. package/src/theme/resolveTheme.ts +6 -0
  185. package/src/theme/types.ts +12 -0
  186. package/src/utils/dataAppEmbed.spec.ts +3 -0
  187. package/src/utils/dataAppEmbed.ts +3 -0
  188. package/src/utils/formatting.spec.ts +3 -0
  189. package/src/utils/formatting.ts +3 -0
  190. package/src/utils/malloyString.spec.ts +24 -0
  191. package/src/utils/malloyString.ts +12 -0
  192. package/src/utils/parsing.spec.ts +3 -0
  193. package/src/utils/parsing.ts +3 -0
  194. package/src/utils/queryClient.ts +3 -0
  195. package/test/README.md +21 -10
  196. package/test/setup.ts +3 -0
  197. package/vite.config.ts +3 -0
  198. package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
  199. package/dist/hooks/useGivensForm.d.ts +0 -35
  200. package/dist/index-MES4MGpQ.cjs.js +0 -309
  201. package/src/hooks/useGivensForm.spec.ts +0 -99
  202. package/src/hooks/useGivensForm.ts +0 -107
@@ -0,0 +1,263 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { useQueries } from "@tanstack/react-query";
5
+ import { useMemo } from "react";
6
+ import type { Given } from "../client";
7
+ import { useServer } from "../components/ServerProvider";
8
+
9
+ /**
10
+ * How many options a generated `suggest { source=… dimension=… }` asks for.
11
+ *
12
+ * Stated here rather than left to the server's `DEFAULT_QUERY_ROW_LIMIT`, which
13
+ * is also 1000 but caps silently and in whatever order the warehouse returns.
14
+ * An explicit limit with an explicit order makes a truncated list the same list
15
+ * every time, and makes the cap something a reader of this file can see.
16
+ * A dimension with more distinct values than this needs a hand-written
17
+ * `suggest { query=… }`: a picker over thousands of options is the wrong
18
+ * control anyway.
19
+ */
20
+ export const SUGGEST_OPTION_LIMIT = 1000;
21
+
22
+ /**
23
+ * The name a `group_by` gives its output column, which is the last segment of a
24
+ * field path.
25
+ *
26
+ * `order_by` takes an output field name, not a path: `order_by:
27
+ * products.category` is refused outright ("order_by takes the name of a field in
28
+ * the query output, not a path"), while `group_by: products.category` names its
29
+ * column `category`. A joined dimension is the ordinary case for a `suggest`, so
30
+ * getting this wrong would have failed the option query for most of them.
31
+ */
32
+ function outputFieldName(dimension: string): string {
33
+ const segments = dimension.split(".");
34
+ return segments[segments.length - 1];
35
+ }
36
+
37
+ /**
38
+ * The query a `suggest { source=… dimension=… }` runs.
39
+ *
40
+ * Exported so the spec can assert the text this hook actually sends. A test that
41
+ * rebuilds the same string alongside it proves only that the test agrees with
42
+ * itself, and this text has already been wrong once: `order_by` takes an output
43
+ * field name, not a path, so a joined dimension failed the query outright.
44
+ */
45
+ export function buildSuggestQuery(source: string, dimension: string): string {
46
+ return (
47
+ `run: ${source} -> {\n` +
48
+ ` group_by: ${dimension}\n` +
49
+ ` order_by: ${outputFieldName(dimension)} asc\n` +
50
+ ` limit: ${SUGGEST_OPTION_LIMIT}\n` +
51
+ `}`
52
+ );
53
+ }
54
+
55
+ /**
56
+ * Resolve the option lists behind `select` / `multiselect` controls.
57
+ *
58
+ * A `suggest` is an ordinary query: either a named one (`suggest { query=… }`)
59
+ * or a grouping over a dimension (`suggest { source=… dimension=… }`), so this
60
+ * runs it on the same governed query endpoint everything else uses. No new
61
+ * endpoint, and the row caps and authorize gates that apply to a surface's own
62
+ * queries apply to its dropdowns too.
63
+ *
64
+ * Takes plain `Given`s: `suggest` is declared on the given, so a notebook's
65
+ * Parameters panel and a dashboard's control row fill the same dropdown from
66
+ * the same declaration.
67
+ *
68
+ * Requested with `compactJson` because these results are never rendered: the
69
+ * flat row form is what the widget needs, and asking for the full Malloy result
70
+ * would mean parsing rendering metadata to get at a list of strings.
71
+ *
72
+ * KNOWN GAP, latent until something populates `suggest`. The request carries no
73
+ * `givens`, and `QueryRequest` has a field for them. That is fine for row caps
74
+ * but not for `#(authorize)`: a gate is evaluated against the request's givens,
75
+ * so a `suggest` over a gated source is denied and every dropdown on it resolves
76
+ * to "Options unavailable": the failure surfaces honestly, but the control is
77
+ * unusable. Deliberately not guessed at here, because *which* givens a suggest
78
+ * should carry is a real decision: the applied ones make the option list depend
79
+ * on the current filters, which this hook's caching deliberately avoids, while
80
+ * only the gate-relevant ones means knowing which those are. Whoever populates
81
+ * `suggest` server-side should settle it, and this hook's signature will need
82
+ * the values passed in.
83
+ */
84
+ export function useSuggestOptions(
85
+ environmentName: string,
86
+ packageName: string,
87
+ modelPath: string | undefined,
88
+ specs: Given[],
89
+ ): {
90
+ options: Map<string, string[]>;
91
+ isLoading: boolean;
92
+ /**
93
+ * Givens whose suggest query failed.
94
+ *
95
+ * Reported separately from an empty option list because the two look
96
+ * identical in a dropdown and mean opposite things: "this dimension has no
97
+ * values" is data, "the query did not run" is a fault, and a reader offered
98
+ * an empty picker has no way to tell which they are looking at.
99
+ */
100
+ failed: Set<string>;
101
+ } {
102
+ const { apiClients } = useServer();
103
+
104
+ // Only a picker needs options; a text box or a slider would just be issuing
105
+ // a query whose answer it never shows.
106
+ const suggestable = useMemo(
107
+ () =>
108
+ specs.filter(
109
+ (spec) =>
110
+ spec.name !== undefined &&
111
+ (spec.control === "select" || spec.control === "multiselect") &&
112
+ (spec.suggest?.query !== undefined ||
113
+ (spec.suggest?.source !== undefined &&
114
+ spec.suggest?.dimension !== undefined)),
115
+ ),
116
+ [specs],
117
+ );
118
+
119
+ const results = useQueries({
120
+ queries: suggestable.map((spec) => ({
121
+ queryKey: [
122
+ "givenSuggest",
123
+ environmentName,
124
+ packageName,
125
+ modelPath,
126
+ spec.name,
127
+ spec.suggest?.query,
128
+ spec.suggest?.source,
129
+ spec.suggest?.dimension,
130
+ ],
131
+ enabled: modelPath !== undefined,
132
+ // Option lists change with the data, not with the filters, so they are
133
+ // cached well past a single control interaction.
134
+ staleTime: 5 * 60 * 1000,
135
+ refetchOnWindowFocus: false,
136
+ queryFn: async () => {
137
+ const suggest = spec.suggest ?? {};
138
+ const response = await apiClients.models.executeQueryModel(
139
+ environmentName,
140
+ packageName,
141
+ modelPath as string,
142
+ suggest.query !== undefined
143
+ ? { queryName: suggest.query, compactJson: true }
144
+ : {
145
+ query: buildSuggestQuery(
146
+ suggest.source as string,
147
+ suggest.dimension as string,
148
+ ),
149
+ compactJson: true,
150
+ },
151
+ );
152
+ return readOptionValues(
153
+ response.data.result,
154
+ suggest.dimension === undefined
155
+ ? undefined
156
+ : outputFieldName(suggest.dimension),
157
+ );
158
+ },
159
+ })),
160
+ });
161
+
162
+ const options = useMemo(() => {
163
+ const byName = new Map<string, string[]>();
164
+ suggestable.forEach((spec, index) => {
165
+ const value = results[index]?.data;
166
+ if (spec.name && value) byName.set(spec.name, value);
167
+ });
168
+ return byName;
169
+ // `results` is a fresh array each render; its data identity is what
170
+ // matters, so depend on that rather than the wrapper objects.
171
+ //
172
+ // `JSON.stringify`, not `join("|")`. `join` flattens a nested array with
173
+ // commas and renders undefined as empty, so genuinely different option
174
+ // lists produced the SAME key: `[["a","b"]]` and `[["a,b"]]` both give
175
+ // `a,b`, and `[undefined]`, `[[]]` and `[[""]]` all give `""`. A refetch
176
+ // between two colliding lists left the previous dropdown in place.
177
+ // eslint-disable-next-line react-hooks/exhaustive-deps
178
+ }, [suggestable, JSON.stringify(results.map((result) => result.data))]);
179
+
180
+ const failed = useMemo(() => {
181
+ const names = new Set<string>();
182
+ suggestable.forEach((spec, index) => {
183
+ if (spec.name && results[index]?.isError) names.add(spec.name);
184
+ });
185
+ return names;
186
+ // Same reasoning as `options`: `results` is a fresh array each render.
187
+ // eslint-disable-next-line react-hooks/exhaustive-deps
188
+ }, [suggestable, results.map((result) => result.isError).join("|")]);
189
+
190
+ return {
191
+ options,
192
+ isLoading: results.some((result) => result.isLoading),
193
+ failed,
194
+ };
195
+ }
196
+
197
+ /**
198
+ * Pull the option strings out of a compact-JSON result.
199
+ *
200
+ * Prefers the named column and otherwise takes the first, which covers a
201
+ * `suggest { query=… }` whose column is named something else. Nulls are
202
+ * dropped: "no value" is expressed by clearing the control, not by picking an
203
+ * empty option.
204
+ *
205
+ * The name to pass is the OUTPUT column, so a joined `products.category` is
206
+ * looked up as `category`. Passing the path found nothing and fell through to
207
+ * the first column, which happened to be right only because the generated query
208
+ * selects exactly one.
209
+ */
210
+ export function readOptionValues(
211
+ result: string | undefined,
212
+ dimension: string | undefined,
213
+ ): string[] {
214
+ // Absent is tolerated: `result` is optional in the API contract, so a
215
+ // missing one is a shape the server is allowed to send and "no values" is
216
+ // the honest reading of it.
217
+ if (!result) return [];
218
+
219
+ // Corrupt is NOT tolerated, and the difference matters. This hook exists to
220
+ // separate "this dimension has no values" from "the option query failed",
221
+ // and returning `[]` for a response that could not be read collapsed the
222
+ // second into the first: the control rendered "No matching values" and told
223
+ // the reader a populated dimension was empty. Thrown, so react-query marks
224
+ // the query errored and `failed` reports it, which is what puts "Options
225
+ // unavailable" on the control.
226
+ let rows: unknown;
227
+ try {
228
+ rows = JSON.parse(result);
229
+ } catch {
230
+ throw new Error("Suggest query returned a result that is not JSON.");
231
+ }
232
+ if (!Array.isArray(rows)) {
233
+ throw new Error(
234
+ "Suggest query returned JSON that is not a list of rows.",
235
+ );
236
+ }
237
+
238
+ const values: string[] = [];
239
+ const seen = new Set<string>();
240
+ for (const row of rows) {
241
+ if (row === null || typeof row !== "object") continue;
242
+ const record = row as Record<string, unknown>;
243
+ const keys = Object.keys(record);
244
+ // `hasOwnProperty`, not `in`: `record` comes from `JSON.parse`, so `in`
245
+ // walks its prototype and reports `constructor`, `toString` and friends
246
+ // as present. A dimension with one of those names would select a
247
+ // function off the prototype instead of falling back to the first
248
+ // column. The same hazard was fixed in the app's URL merge; this is the
249
+ // other place the rule lives.
250
+ const key =
251
+ dimension !== undefined &&
252
+ Object.prototype.hasOwnProperty.call(record, dimension)
253
+ ? dimension
254
+ : keys[0];
255
+ const value = key === undefined ? undefined : record[key];
256
+ if (value === null || value === undefined) continue;
257
+ const text = String(value);
258
+ if (seen.has(text)) continue;
259
+ seen.add(text);
260
+ values.push(text);
261
+ }
262
+ return values;
263
+ }
package/src/index.ts CHANGED
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  export * from "./components";
2
5
  export { default as ConnectionExplorer } from "./components/Environment/ConnectionExplorer";
3
6
  export { useServer } from "./components/ServerProvider";
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  /* eslint-disable @typescript-eslint/triple-slash-reference */
2
5
  /// <reference types="node" />
3
6
  /// <reference types="react" />
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import React, {
2
5
  createContext,
3
6
  useContext,
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import type { MalloyExplicitTheme } from "@malloydata/render";
2
5
  import type { ResolvedTheme } from "./types";
3
6
 
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { describe, expect, it } from "bun:test";
2
5
  import { buildTableCssVars } from "./buildTableCssVars";
3
6
  import { resolveTheme } from "./resolveTheme";
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import type { ResolvedTheme } from "./types";
2
5
 
3
6
  /**
@@ -56,5 +59,9 @@ export function buildTableCssVars(
56
59
  // The numeric value rendered under each tile title. Not editable
57
60
  // in v1; computed from the active mode for readable contrast.
58
61
  "--malloy-render--value-color": theme.valueColor,
62
+ // Custom var. Drives the hover colour of a `# drill` cell via the
63
+ // .publisher-drill rule in injectRendererOverrides: the renderer
64
+ // has no notion of drill, so the affordance is entirely ours.
65
+ "--publisher-drill-link": theme.drillLink,
59
66
  };
60
67
  }
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { describe, expect, it } from "bun:test";
2
5
  import { buildVegaThemeOverride } from "./buildVegaThemeOverride";
3
6
  import { resolveTheme } from "./resolveTheme";
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import type { ResolvedTheme } from "./types";
2
5
 
3
6
  /**
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { MALLOY_BRAND } from "../components/styles";
2
5
  import type { Theme } from "./types";
3
6
 
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  export { buildMalloyExplicitTheme } from "./buildMalloyExplicitTheme";
2
5
  export { buildTableCssVars } from "./buildTableCssVars";
3
6
  export { buildVegaThemeOverride } from "./buildVegaThemeOverride";
package/src/theme/keys.ts CHANGED
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  /**
2
5
  * The set of palette colour keys that have separate light and dark
3
6
  * variants. This is the SDK-side canonical list, consumed by the
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { parseAnnotation } from "@malloydata/malloy-tag";
2
5
  import { describe, expect, it } from "bun:test";
3
6
  import { readChartAnnotations } from "./readChartAnnotations";
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import type { Tag } from "@malloydata/malloy-tag";
2
5
  import { PER_MODE_COLOR_KEYS } from "./keys";
3
6
  import type { Theme } from "./types";
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { describe, expect, it } from "bun:test";
2
5
  import { resolveMode, resolveTheme } from "./resolveTheme";
3
6
  import type { Theme } from "./types";
@@ -89,6 +92,19 @@ describe("resolveTheme cascade", () => {
89
92
  expect(dark.valueColor).toBe("#f1f5f9");
90
93
  });
91
94
 
95
+ it("drillLink is a link colour per mode, not a series colour", () => {
96
+ // A drillable cell has to read as a link against whatever the operator
97
+ // picked for the data, so this comes from the mode rather than the palette
98
+ //, and it lightens in dark mode to stay legible on the slate panel.
99
+ expect(resolveTheme([], "light").drillLink).toBe("#2563eb");
100
+ expect(resolveTheme([], "dark").drillLink).toBe("#60a5fa");
101
+ const branded = resolveTheme(
102
+ [{ palette: { series: ["#ff00aa", "#111111"] } }],
103
+ "light",
104
+ );
105
+ expect(branded.drillLink).toBe("#2563eb");
106
+ });
107
+
92
108
  it("dashboardRoot is mode-keyed and immune to operator background overrides", () => {
93
109
  // Light keeps white (no regression on existing installs).
94
110
  expect(resolveTheme([], "light").dashboardRoot).toBe("#ffffff");
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { DEFAULT_THEME } from "./defaults";
2
5
  import { PER_MODE_COLOR_KEYS, type PerModeColorKey } from "./keys";
3
6
  import type { ResolvedTheme, Theme, ThemeMode } from "./types";
@@ -95,6 +98,9 @@ export function resolveTheme(
95
98
  // panel stays neutral so a bold accent on the chart canvas
96
99
  // doesn't bleed into the surrounding chrome.
97
100
  dashboardRoot: isDark ? "#1e293b" : "#ffffff",
101
+ // Drill link hover. Light is Malloyyo's own blue, so the same drill reads
102
+ // the same in both; dark lightens it for contrast on the slate panel.
103
+ drillLink: isDark ? "#60a5fa" : "#2563eb",
98
104
  };
99
105
  }
100
106
 
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import type { Theme } from "../client";
2
5
 
3
6
  export type { Theme };
@@ -54,6 +57,15 @@ export interface ResolvedTheme {
54
57
  * box on the dark page chrome.
55
58
  */
56
59
  dashboardRoot: string;
60
+ /**
61
+ * Colour a `# drill` cell takes on hover, when it reads as a link. A link
62
+ * blue rather than anything from `palette.series`, deliberately: the
63
+ * affordance has to stay legible as a link against whatever the operator
64
+ * picked for the data, and a drillable bar or cell should not look like it
65
+ * belongs to a series. Mode-keyed and not operator-customizable, like
66
+ * `dashboardRoot`.
67
+ */
68
+ drillLink: string;
57
69
  /**
58
70
  * Background for the renderer's table interior. Follows the
59
71
  * operator's `palette.background` (the chart canvas colour) so
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { describe, expect, it } from "bun:test";
2
5
  import {
3
6
  isPublisherResizeMessage,
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  // Shared contract for serving and embedding in-package HTML data apps.
2
5
  //
3
6
  // Both the Publisher SPA host (DataAppViewer.tsx, Package.tsx) and the
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { describe, expect, it } from "bun:test";
2
5
  import { encodeResourceUri, parseResourceUri } from "./formatting";
3
6
 
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  export type ParsedResource = {
2
5
  environmentName: string;
3
6
  packageName?: string | undefined;
@@ -0,0 +1,24 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { escapeMalloyString } from "./malloyString";
6
+
7
+ describe("escapeMalloyString", () => {
8
+ it("escapes a quote", () => {
9
+ expect(escapeMalloyString("O'Brien")).toBe("O\\'Brien");
10
+ });
11
+
12
+ it("escapes a backslash", () => {
13
+ expect(escapeMalloyString("C:\\temp")).toBe("C:\\\\temp");
14
+ });
15
+
16
+ it("escapes backslashes before quotes, so the quote escape is not doubled", () => {
17
+ // Quote-then-backslash order would turn ' into \' and then \\' .
18
+ expect(escapeMalloyString("a'\\b")).toBe("a\\'\\\\b");
19
+ });
20
+
21
+ it("leaves a plain string alone", () => {
22
+ expect(escapeMalloyString("plain value")).toBe("plain value");
23
+ });
24
+ });
@@ -0,0 +1,12 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ /**
5
+ * Escape a value for use inside a single-quoted Malloy string literal.
6
+ *
7
+ * Backslashes are escaped first, then quotes: doing it the other way round
8
+ * would re-escape the backslash that the quote escape introduced.
9
+ */
10
+ export function escapeMalloyString(value: string): string {
11
+ return value.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
12
+ }
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { describe, expect, it } from "bun:test";
2
5
  import {
3
6
  generateEnvironmentReadme,
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  // Helper function to extract a brief description from README content
2
5
  export const getEnvironmentDescription = (
3
6
  readme: string | undefined,
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import { QueryClient } from "@tanstack/react-query";
2
5
 
3
6
  // Global QueryClient instance - isolated to avoid circular dependencies
package/test/README.md CHANGED
@@ -1,3 +1,8 @@
1
+ <!--
2
+ Copyright (c) Credible Data Inc.
3
+ SPDX-License-Identifier: MIT
4
+ -->
5
+
1
6
  # Testing React components and hooks in the SDK
2
7
 
3
8
  `bun test` in this package runs with a DOM, so components and hooks can be
@@ -40,7 +45,7 @@ using it would have meant bringing in a second test runner alongside `bun test`.
40
45
  ```tsx
41
46
  import { describe, expect, it, mock } from "bun:test";
42
47
  import { fireEvent, render, screen } from "@testing-library/react";
43
- import type { GivenValue } from "../../hooks/useGivensForm";
48
+ import type { GivenValue } from "../../hooks/givenValue";
44
49
  import { GivenInput } from "./GivenInput";
45
50
 
46
51
  it("reverts rather than blanking the field", () => {
@@ -72,23 +77,29 @@ No JSX is needed, so a hook spec is a plain `.spec.ts`.
72
77
  import { act, renderHook } from "@testing-library/react";
73
78
 
74
79
  const { result, rerender } = renderHook(
75
- ({ declared }) => useGivensForm(declared),
76
- { initialProps: { declared: [{ name: "region" }] } },
80
+ ({ types }) => useGivensState({ declaredTypes: types, autorun: true }),
81
+ { initialProps: { types: new Map([["REGION", "filter<string>"]]) } },
77
82
  );
78
83
 
79
- act(() => result.current.updateGiven("region", "CA"));
80
- expect(result.current.givenValues.get("region")).toBe("CA");
84
+ act(() => result.current.setGiven("REGION", "West"));
85
+ expect(result.current.applied.get("REGION")).toBe("West");
81
86
 
82
- rerender({ declared: [] }); // props change, effects flush
87
+ rerender({ types: new Map() }); // props change, effects flush
83
88
  ```
84
89
 
85
90
  `result.current` is re-read after every update, so hold onto the object rather
86
91
  than destructuring off it. Wrap anything that sets state in `act()`.
87
92
 
88
- `src/hooks/useGivensForm.spec.ts` is the worked example, and its last test is
89
- worth copying: it renders a hook with a deliberately unmemoized argument to
90
- prove the hook settles instead of re-rendering forever. That is a real defect
91
- class here, and it is invisible to a test that only ever passes stable inputs.
93
+ `src/hooks/useGivensState.spec.ts` is the worked example, and two things in it
94
+ are worth copying. The test named "settles when its inputs are fresh objects on
95
+ every render" passes deliberately unmemoized arguments to prove the hook settles
96
+ instead of re-rendering forever; that is a real defect class here, and it is
97
+ invisible to a test that only ever passes stable inputs. Named rather than
98
+ pointed at by position, because "its last test" stopped being that one the first
99
+ time a test was appended. And its `renderWithUrlHost` helper feeds the hook's own output back in
100
+ as props, the way the page hosts do through the URL. Several defects in that
101
+ hook only appear on the second half of that loop, so a spec that treats the
102
+ props as constant cannot see them.
92
103
 
93
104
  ## Where specs live, and what not to break
94
105
 
package/test/setup.ts CHANGED
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  /**
2
5
  * DOM environment for `bun test` in this package.
3
6
  *
package/vite.config.ts CHANGED
@@ -1,3 +1,6 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
1
4
  import react from "@vitejs/plugin-react";
2
5
  import { defineConfig } from "vite";
3
6
  import dts from "vite-plugin-dts";