@malloy-publisher/sdk 0.2.7 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (221) hide show
  1. package/README.md +180 -204
  2. package/dist/DocumentStorageProvider-BeBD0uWc.cjs.js +134 -0
  3. package/dist/DocumentStorageProvider-tGvodI8f.es.js +24268 -0
  4. package/dist/RenderedResult-CPi6uQWq.cjs.js +115 -0
  5. package/dist/RenderedResult-mDE-4u8S.es.js +542 -0
  6. package/dist/{ServerProvider-xXW1HJOJ.cjs.js → ServerProvider-CH71GsoL.cjs.js} +1 -1
  7. package/dist/{ServerProvider-ksC5Su_x.es.js → ServerProvider-X2Ma0HRs.es.js} +324 -359
  8. package/dist/builder/index.cjs.js +105 -0
  9. package/dist/builder/index.d.ts +2 -0
  10. package/dist/builder/index.es.js +9561 -0
  11. package/dist/builder-entry.d.ts +8 -0
  12. package/dist/client/api.d.ts +13 -1
  13. package/dist/client/index.cjs.js +1 -1
  14. package/dist/client/index.es.js +1 -1
  15. package/dist/components/ApiErrorDisplay.d.ts +1 -2
  16. package/dist/components/Dashboard/Dashboard.d.ts +23 -16
  17. package/dist/components/Dashboard/DashboardGrid.d.ts +67 -0
  18. package/dist/components/Dashboard/DashboardTile.d.ts +6 -1
  19. package/dist/components/Dashboard/ExploreDialog.d.ts +18 -0
  20. package/dist/components/Dashboard/RowsDialog.d.ts +47 -0
  21. package/dist/components/Dashboard/TileCard.d.ts +44 -0
  22. package/dist/components/Dashboard/index.d.ts +2 -0
  23. package/dist/components/Dashboard/promoteMeasureRow.d.ts +40 -0
  24. package/dist/components/Dashboard/telemetry.d.ts +43 -0
  25. package/dist/components/DashboardBuilder/AddTileDialog.d.ts +35 -0
  26. package/dist/components/DashboardBuilder/BuilderToolbar.d.ts +29 -0
  27. package/dist/components/DashboardBuilder/DashboardBuilder.d.ts +112 -0
  28. package/dist/components/DashboardBuilder/DashboardEditor.d.ts +32 -0
  29. package/dist/components/DashboardBuilder/DiffDialog.d.ts +15 -0
  30. package/dist/components/DashboardBuilder/DrillDialog.d.ts +15 -0
  31. package/dist/components/DashboardBuilder/FilterDialog.d.ts +54 -0
  32. package/dist/components/DashboardBuilder/FilterStrip.d.ts +17 -0
  33. package/dist/components/DashboardBuilder/SettingsPopover.d.ts +20 -0
  34. package/dist/components/DashboardBuilder/TileFrame.d.ts +42 -0
  35. package/dist/components/DashboardBuilder/TileMenu.d.ts +24 -0
  36. package/dist/components/DashboardBuilder/catalog.d.ts +62 -0
  37. package/dist/components/DashboardBuilder/controls.d.ts +157 -0
  38. package/dist/components/DashboardBuilder/diff.d.ts +35 -0
  39. package/dist/components/DashboardBuilder/document.d.ts +218 -0
  40. package/dist/components/DashboardBuilder/layout.d.ts +71 -0
  41. package/dist/components/DashboardBuilder/malloyText.d.ts +45 -0
  42. package/dist/components/DashboardBuilder/preview.d.ts +60 -0
  43. package/dist/components/DashboardBuilder/readDocument.d.ts +106 -0
  44. package/dist/components/DashboardBuilder/sortable.d.ts +51 -0
  45. package/dist/components/DashboardBuilder/spliceDocument.d.ts +44 -0
  46. package/dist/components/DashboardBuilder/testing/fixtures.d.ts +10 -0
  47. package/dist/components/DashboardBuilder/useBuilderShortcuts.d.ts +22 -0
  48. package/dist/components/DashboardBuilder/useDashboardEditor.d.ts +63 -0
  49. package/dist/components/DashboardBuilder/useDraft.d.ts +13 -0
  50. package/dist/components/DashboardBuilder/useFilterForm.d.ts +65 -0
  51. package/dist/components/DashboardBuilder/useTileReorder.d.ts +22 -0
  52. package/dist/components/DashboardBuilder/useTileResize.d.ts +29 -0
  53. package/dist/components/DocumentStorage/BrowserDocumentStorage.d.ts +14 -0
  54. package/dist/components/DocumentStorage/DocumentStorage.d.ts +58 -0
  55. package/dist/components/DocumentStorage/DocumentStorageProvider.d.ts +25 -0
  56. package/dist/components/DocumentStorage/index.d.ts +3 -0
  57. package/dist/components/FloatingIconButton.d.ts +16 -0
  58. package/dist/components/Model/index.d.ts +0 -1
  59. package/dist/components/Prose.d.ts +46 -0
  60. package/dist/components/RenderedResult/RenderedResult.d.ts +12 -0
  61. package/dist/components/RenderedResult/ResultContainer.d.ts +7 -1
  62. package/dist/components/RenderedResult/ResultPanel.d.ts +30 -0
  63. package/dist/components/RenderedResult/index.d.ts +2 -0
  64. package/dist/components/RenderedResult/resultSizing.d.ts +183 -0
  65. package/dist/components/drill/index.d.ts +2 -1
  66. package/dist/components/drill/resolveDrill.d.ts +22 -0
  67. package/dist/components/drill/useDrill.d.ts +11 -2
  68. package/dist/components/drill/useDrillSelf.d.ts +46 -0
  69. package/dist/components/given/filterValue.d.ts +63 -0
  70. package/dist/components/given/index.d.ts +1 -0
  71. package/dist/components/given/useGivenUrlParams.d.ts +39 -0
  72. package/dist/components/index.d.ts +3 -3
  73. package/dist/components/styles.d.ts +3 -7
  74. package/dist/core-8NVBCLZh.cjs.js +148 -0
  75. package/dist/{core-BY7vB5gN.es.js → core-B8oMW4sm.es.js} +3540 -2335
  76. package/dist/hooks/index.d.ts +3 -1
  77. package/dist/hooks/useDocumentControls.d.ts +70 -0
  78. package/dist/hooks/useQueryResult.d.ts +40 -0
  79. package/dist/hooks/useSuggestOptions.d.ts +28 -12
  80. package/dist/index.cjs.js +34 -1
  81. package/dist/index.es.js +21487 -79
  82. package/dist/sdk.css +1 -1
  83. package/dist/styles.css +0 -1
  84. package/dist/utils/malloyLiteral.d.ts +11 -0
  85. package/package.json +25 -14
  86. package/src/builder-entry.ts +55 -0
  87. package/src/components/ApiErrorDisplay.tsx +1 -1
  88. package/src/components/Connections/EditConnectionDialog.tsx +96 -86
  89. package/src/components/Dashboard/Dashboard.spec.tsx +7 -10
  90. package/src/components/Dashboard/Dashboard.tsx +184 -229
  91. package/src/components/Dashboard/DashboardGrid.tsx +124 -0
  92. package/src/components/Dashboard/DashboardTile.spec.tsx +30 -6
  93. package/src/components/Dashboard/DashboardTile.tsx +67 -101
  94. package/src/components/Dashboard/ExploreDialog.tsx +84 -0
  95. package/src/components/Dashboard/RowsDialog.spec.ts +42 -0
  96. package/src/components/Dashboard/RowsDialog.tsx +234 -0
  97. package/src/components/Dashboard/TileCard.tsx +120 -0
  98. package/src/components/Dashboard/index.ts +2 -0
  99. package/src/components/Dashboard/promoteMeasureRow.spec.ts +207 -0
  100. package/src/components/Dashboard/promoteMeasureRow.ts +160 -0
  101. package/src/components/Dashboard/telemetry.ts +44 -0
  102. package/src/components/Dashboard/tileGridColumn.spec.ts +1 -1
  103. package/src/components/DashboardBuilder/AddTileDialog.tsx +249 -0
  104. package/src/components/DashboardBuilder/BuilderToolbar.tsx +270 -0
  105. package/src/components/DashboardBuilder/DashboardBuilder.spec.tsx +858 -0
  106. package/src/components/DashboardBuilder/DashboardBuilder.tsx +653 -0
  107. package/src/components/DashboardBuilder/DashboardEditor.spec.tsx +211 -0
  108. package/src/components/DashboardBuilder/DashboardEditor.tsx +493 -0
  109. package/src/components/DashboardBuilder/DiffDialog.tsx +129 -0
  110. package/src/components/DashboardBuilder/DrillDialog.tsx +281 -0
  111. package/src/components/DashboardBuilder/FilterDialog.tsx +581 -0
  112. package/src/components/DashboardBuilder/FilterStrip.tsx +125 -0
  113. package/src/components/DashboardBuilder/SettingsPopover.tsx +168 -0
  114. package/src/components/DashboardBuilder/TileFrame.tsx +380 -0
  115. package/src/components/DashboardBuilder/TileMenu.tsx +188 -0
  116. package/src/components/DashboardBuilder/catalog.spec.ts +215 -0
  117. package/src/components/DashboardBuilder/catalog.ts +225 -0
  118. package/src/components/DashboardBuilder/controls.spec.ts +243 -0
  119. package/src/components/DashboardBuilder/controls.ts +398 -0
  120. package/src/components/DashboardBuilder/diff.spec.ts +44 -0
  121. package/src/components/DashboardBuilder/diff.ts +93 -0
  122. package/src/components/DashboardBuilder/document.ts +209 -0
  123. package/src/components/DashboardBuilder/keepRowStructure.spec.ts +84 -0
  124. package/src/components/DashboardBuilder/layout.ts +143 -0
  125. package/src/components/DashboardBuilder/malloyText.spec.ts +84 -0
  126. package/src/components/DashboardBuilder/malloyText.ts +151 -0
  127. package/src/components/DashboardBuilder/moveIntoGap.spec.ts +90 -0
  128. package/src/components/DashboardBuilder/preview.spec.ts +149 -0
  129. package/src/components/DashboardBuilder/preview.ts +172 -0
  130. package/src/components/DashboardBuilder/readDocument.spec.ts +375 -0
  131. package/src/components/DashboardBuilder/readDocument.ts +467 -0
  132. package/src/components/DashboardBuilder/sortable.tsx +151 -0
  133. package/src/components/DashboardBuilder/spliceDocument.spec.ts +1108 -0
  134. package/src/components/DashboardBuilder/spliceDocument.ts +1098 -0
  135. package/src/components/DashboardBuilder/testing/fixtures.ts +48 -0
  136. package/src/components/DashboardBuilder/useBuilderShortcuts.ts +88 -0
  137. package/src/components/DashboardBuilder/useDashboardEditor.spec.ts +255 -0
  138. package/src/components/DashboardBuilder/useDashboardEditor.ts +193 -0
  139. package/src/components/DashboardBuilder/useDraft.ts +43 -0
  140. package/src/components/DashboardBuilder/useFilterForm.spec.tsx +144 -0
  141. package/src/components/DashboardBuilder/useFilterForm.ts +352 -0
  142. package/src/components/DashboardBuilder/useTileReorder.spec.tsx +97 -0
  143. package/src/components/DashboardBuilder/useTileReorder.ts +115 -0
  144. package/src/components/DashboardBuilder/useTileResize.spec.tsx +121 -0
  145. package/src/components/DashboardBuilder/useTileResize.ts +110 -0
  146. package/src/components/DashboardBuilder/withGaps.spec.ts +96 -0
  147. package/src/components/DocumentStorage/BrowserDocumentStorage.spec.ts +81 -0
  148. package/src/components/DocumentStorage/BrowserDocumentStorage.ts +105 -0
  149. package/src/components/DocumentStorage/DocumentStorage.ts +73 -0
  150. package/src/components/DocumentStorage/DocumentStorageProvider.tsx +58 -0
  151. package/src/components/DocumentStorage/index.ts +16 -0
  152. package/src/components/Environment/About.tsx +4 -36
  153. package/src/components/FloatingIconButton.tsx +41 -0
  154. package/src/components/Model/Model.tsx +6 -23
  155. package/src/components/Model/ModelCell.tsx +34 -72
  156. package/src/components/Model/index.ts +0 -1
  157. package/src/components/Notebook/Notebook.tsx +27 -156
  158. package/src/components/Notebook/NotebookCell.tsx +37 -191
  159. package/src/components/Prose.spec.tsx +85 -0
  160. package/src/components/Prose.tsx +179 -0
  161. package/src/components/QueryResult/QueryResult.tsx +15 -43
  162. package/src/components/RenderedResult/RenderedResult.tsx +86 -76
  163. package/src/components/RenderedResult/ResultContainer.tsx +25 -36
  164. package/src/components/RenderedResult/ResultPanel.spec.tsx +49 -0
  165. package/src/components/RenderedResult/ResultPanel.tsx +73 -0
  166. package/src/components/RenderedResult/index.ts +16 -0
  167. package/src/components/RenderedResult/resultSizing.spec.ts +249 -0
  168. package/src/components/RenderedResult/resultSizing.ts +308 -0
  169. package/src/components/ResultsDialog.tsx +2 -1
  170. package/src/components/drill/index.ts +6 -0
  171. package/src/components/drill/resolveDrill.ts +22 -1
  172. package/src/components/drill/useDrill.spec.tsx +94 -0
  173. package/src/components/drill/useDrill.tsx +52 -12
  174. package/src/components/drill/useDrillSelf.spec.tsx +64 -0
  175. package/src/components/drill/useDrillSelf.ts +110 -0
  176. package/src/components/given/GivenInput.spec.tsx +196 -2
  177. package/src/components/given/GivenInput.tsx +300 -25
  178. package/src/components/given/GivensPanel.tsx +1 -1
  179. package/src/components/given/filterValue.spec.ts +112 -0
  180. package/src/components/given/filterValue.ts +188 -0
  181. package/src/components/given/index.ts +4 -0
  182. package/src/components/given/useGivenUrlParams.spec.tsx +74 -0
  183. package/src/components/given/useGivenUrlParams.ts +87 -0
  184. package/src/components/index.ts +11 -3
  185. package/src/components/styles.ts +0 -37
  186. package/src/hooks/index.ts +13 -1
  187. package/src/hooks/useDocumentControls.ts +170 -0
  188. package/src/hooks/useGivensState.spec.ts +158 -0
  189. package/src/hooks/useGivensState.ts +114 -23
  190. package/src/hooks/useQueryResult.ts +82 -0
  191. package/src/hooks/useSuggestOptions.dom.spec.ts +60 -1
  192. package/src/hooks/useSuggestOptions.ts +94 -51
  193. package/src/utils/malloyLiteral.spec.ts +43 -0
  194. package/src/utils/malloyLiteral.ts +76 -0
  195. package/vite.config.ts +5 -1
  196. package/dist/components/AnalyzePackageButton.d.ts +0 -6
  197. package/dist/components/Workbook/BrowserWorkbookStorage.d.ts +0 -9
  198. package/dist/components/Workbook/EditableMalloyCell.d.ts +0 -11
  199. package/dist/components/Workbook/ModelPicker.d.ts +0 -11
  200. package/dist/components/Workbook/MutableCell.d.ts +0 -17
  201. package/dist/components/Workbook/Workbook.d.ts +0 -7
  202. package/dist/components/Workbook/WorkbookList.d.ts +0 -7
  203. package/dist/components/Workbook/WorkbookManager.d.ts +0 -84
  204. package/dist/components/Workbook/WorkbookStorage.d.ts +0 -17
  205. package/dist/components/Workbook/WorkbookStorageProvider.d.ts +0 -12
  206. package/dist/components/Workbook/index.d.ts +0 -7
  207. package/dist/core-CWKmWEg2.cjs.js +0 -148
  208. package/dist/index-B0WyZAUA.es.js +0 -66412
  209. package/dist/index-kxVD1RjY.cjs.js +0 -356
  210. package/dist/markdown-editor.css +0 -341
  211. package/src/components/AnalyzePackageButton.tsx +0 -319
  212. package/src/components/Workbook/BrowserWorkbookStorage.ts +0 -64
  213. package/src/components/Workbook/EditableMalloyCell.tsx +0 -49
  214. package/src/components/Workbook/ModelPicker.tsx +0 -134
  215. package/src/components/Workbook/MutableCell.tsx +0 -458
  216. package/src/components/Workbook/Workbook.tsx +0 -501
  217. package/src/components/Workbook/WorkbookList.tsx +0 -110
  218. package/src/components/Workbook/WorkbookManager.ts +0 -214
  219. package/src/components/Workbook/WorkbookStorage.ts +0 -35
  220. package/src/components/Workbook/WorkbookStorageProvider.tsx +0 -40
  221. package/src/components/Workbook/index.ts +0 -10
@@ -4,7 +4,9 @@
4
4
  import { useQueries } from "@tanstack/react-query";
5
5
  import { useMemo } from "react";
6
6
  import type { Given } from "../client";
7
+ import { givensToRequest } from "../components/given/paramCodec";
7
8
  import { useServer } from "../components/ServerProvider";
9
+ import type { GivenValue } from "./givenValue";
8
10
 
9
11
  /**
10
12
  * How many options a generated `suggest { source=… dimension=… }` asks for.
@@ -69,18 +71,41 @@ export function buildSuggestQuery(source: string, dimension: string): string {
69
71
  * flat row form is what the widget needs, and asking for the full Malloy result
70
72
  * would mean parsing rendering metadata to get at a list of strings.
71
73
  *
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.
74
+ * The request carries the givens the suggest query NEEDS and no others. An
75
+ * `#(authorize)` gate is evaluated against the request's givens, so a suggest
76
+ * over a gated source was denied outright and its dropdown read "Options
77
+ * unavailable". Sending every applied value would have fixed that but made the
78
+ * option list depend on the page's other filters, which this hook's caching
79
+ * deliberately avoids. So the server says, per suggest, which givens its source
80
+ * is gated or scoped by (`suggest.givenNames`), and {@link suggestRequestGivens}
81
+ * sends the current values of exactly those; the cache is keyed on them too.
82
+ * A server too old to name them sends none, and the request is as before.
83
83
  */
84
+ /**
85
+ * The current values a suggest query has to carry: the applied values of the
86
+ * givens the server named on it, encoded for the request. Undefined when the
87
+ * suggest names none, or when the caller has no applied values to offer.
88
+ */
89
+ export function suggestRequestGivens(
90
+ spec: Given,
91
+ applied: AppliedGivens | undefined,
92
+ ): Record<string, unknown> | undefined {
93
+ const names = spec.suggest?.givenNames;
94
+ if (!applied || !names || names.length === 0) return undefined;
95
+ const request = givensToRequest(
96
+ applied.values,
97
+ applied.declaredTypes,
98
+ names,
99
+ );
100
+ return Object.keys(request).length > 0 ? request : undefined;
101
+ }
102
+
103
+ /** The applied control row and the declared types that encode it. */
104
+ export interface AppliedGivens {
105
+ values: ReadonlyMap<string, GivenValue>;
106
+ declaredTypes: ReadonlyMap<string, string | undefined>;
107
+ }
108
+
84
109
  export function useSuggestOptions(
85
110
  environmentName: string,
86
111
  packageName: string,
@@ -89,6 +114,12 @@ export function useSuggestOptions(
89
114
  // Trailing and optional because this hook is exported from the package, so
90
115
  // a slot beside `packageName` where it belongs would break every caller.
91
116
  versionId?: string,
117
+ /**
118
+ * The page's applied values, so a suggest can carry the givens its source
119
+ * is gated or scoped by. Optional for the same reason as `versionId`; a
120
+ * caller that omits it gets the pre-gating behaviour.
121
+ */
122
+ applied?: AppliedGivens,
92
123
  ): {
93
124
  options: Map<string, string[]>;
94
125
  isLoading: boolean;
@@ -120,48 +151,60 @@ export function useSuggestOptions(
120
151
  );
121
152
 
122
153
  const results = useQueries({
123
- queries: suggestable.map((spec) => ({
124
- queryKey: [
125
- "givenSuggest",
126
- environmentName,
127
- packageName,
128
- versionId,
129
- modelPath,
130
- spec.name,
131
- spec.suggest?.query,
132
- spec.suggest?.source,
133
- spec.suggest?.dimension,
134
- ],
135
- enabled: modelPath !== undefined,
136
- // Option lists change with the data, not with the filters, so they are
137
- // cached well past a single control interaction.
138
- staleTime: 5 * 60 * 1000,
139
- refetchOnWindowFocus: false,
140
- queryFn: async () => {
141
- const suggest = spec.suggest ?? {};
142
- const response = await apiClients.models.executeQueryModel(
154
+ queries: suggestable.map((spec) => {
155
+ const givens = suggestRequestGivens(spec, applied);
156
+ return {
157
+ queryKey: [
158
+ "givenSuggest",
143
159
  environmentName,
144
160
  packageName,
145
- modelPath as string,
146
- suggest.query !== undefined
147
- ? { queryName: suggest.query, compactJson: true, versionId }
148
- : {
149
- query: buildSuggestQuery(
150
- suggest.source as string,
151
- suggest.dimension as string,
152
- ),
153
- compactJson: true,
154
- versionId,
155
- },
156
- );
157
- return readOptionValues(
158
- response.data.result,
159
- suggest.dimension === undefined
160
- ? undefined
161
- : outputFieldName(suggest.dimension),
162
- );
163
- },
164
- })),
161
+ versionId,
162
+ modelPath,
163
+ spec.name,
164
+ spec.suggest?.query,
165
+ spec.suggest?.source,
166
+ spec.suggest?.dimension,
167
+ // Only the givens the suggest carries, so a change to any OTHER
168
+ // control leaves the cached list alone.
169
+ givens === undefined ? null : JSON.stringify(givens),
170
+ ],
171
+ enabled: modelPath !== undefined,
172
+ // Option lists change with the data, not with the filters, so they
173
+ // are cached well past a single control interaction.
174
+ staleTime: 5 * 60 * 1000,
175
+ refetchOnWindowFocus: false,
176
+ queryFn: async () => {
177
+ const suggest = spec.suggest ?? {};
178
+ const response = await apiClients.models.executeQueryModel(
179
+ environmentName,
180
+ packageName,
181
+ modelPath as string,
182
+ suggest.query !== undefined
183
+ ? {
184
+ queryName: suggest.query,
185
+ compactJson: true,
186
+ versionId,
187
+ givens,
188
+ }
189
+ : {
190
+ query: buildSuggestQuery(
191
+ suggest.source as string,
192
+ suggest.dimension as string,
193
+ ),
194
+ compactJson: true,
195
+ versionId,
196
+ givens,
197
+ },
198
+ );
199
+ return readOptionValues(
200
+ response.data.result,
201
+ suggest.dimension === undefined
202
+ ? undefined
203
+ : outputFieldName(suggest.dimension),
204
+ );
205
+ },
206
+ };
207
+ }),
165
208
  });
166
209
 
167
210
  const options = useMemo(() => {
@@ -0,0 +1,43 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { describe, expect, it } from "bun:test";
5
+ import { malloyLiteral } from "./malloyLiteral";
6
+
7
+ describe("malloyLiteral", () => {
8
+ it("spells a value the way its given's type reads it", () => {
9
+ expect(malloyLiteral("Nike", "filter<string>")).toBe("f'Nike'");
10
+ expect(malloyLiteral(">= 10", "filter<number>")).toBe("f'>= 10'");
11
+ expect(malloyLiteral("O'Neil", "string")).toBe("'O\\'Neil'");
12
+ expect(malloyLiteral("42", "number")).toBe("42");
13
+ expect(malloyLiteral("forty", "number")).toBeUndefined();
14
+ expect(malloyLiteral(true, "boolean")).toBe("true");
15
+ expect(malloyLiteral("2024-01-31", "date")).toBe("@2024-01-31");
16
+ expect(malloyLiteral(new Date("2024-01-31T09:30:00Z"), "timestamp")).toBe(
17
+ "@2024-01-31 09:30:00",
18
+ );
19
+ });
20
+
21
+ it("spells a value by its own type when no given is involved", () => {
22
+ expect(malloyLiteral("Jeans")).toBe("'Jeans'");
23
+ expect(malloyLiteral("Ben's & Jerry\\s")).toBe("'Ben\\'s & Jerry\\\\s'");
24
+ expect(malloyLiteral(42)).toBe("42");
25
+ expect(malloyLiteral(true)).toBe("true");
26
+ expect(malloyLiteral(new Date("2024-03-05T00:00:00Z"))).toBe(
27
+ "@2024-03-05",
28
+ );
29
+ expect(malloyLiteral(new Date("2024-03-05T13:45:00Z"))).toBe(
30
+ "@2024-03-05 13:45:00",
31
+ );
32
+ });
33
+
34
+ it("has nothing to write for an empty value or a type it cannot spell", () => {
35
+ expect(malloyLiteral("", "filter<string>")).toBeUndefined();
36
+ expect(malloyLiteral(null, "filter<string>")).toBeUndefined();
37
+ expect(malloyLiteral("x", "geometry")).toBeUndefined();
38
+ expect(malloyLiteral(null)).toBeUndefined();
39
+ expect(malloyLiteral(Number.NaN)).toBeUndefined();
40
+ expect(malloyLiteral({})).toBeUndefined();
41
+ expect(malloyLiteral(new Date("nope"))).toBeUndefined();
42
+ });
43
+ });
@@ -0,0 +1,76 @@
1
+ // Copyright (c) Credible Data Inc.
2
+ // SPDX-License-Identifier: MIT
3
+
4
+ import { escapeMalloyString } from "./malloyString";
5
+
6
+ /**
7
+ * A value as a Malloy literal: `'text'`, `42`, `true`, `@2024-01-31`,
8
+ * `@2024-01-31 09:30:00`, or `f'…'` for a `filter<…>` type.
9
+ *
10
+ * With `type` — a given's declared type — the value is spelled the way that
11
+ * type reads it, so `"42"` for a `number` given is `42` and `true` for a
12
+ * `boolean` is `true`. Without it the JavaScript type decides, which is what a
13
+ * clicked cell's value needs. Undefined when there is nothing to write: no
14
+ * value, or one the type cannot spell.
15
+ */
16
+ export function malloyLiteral(
17
+ value: unknown,
18
+ type?: string,
19
+ ): string | undefined {
20
+ if (value === undefined || value === null || value === "") return undefined;
21
+ const quote = (text: string) => `'${escapeMalloyString(text)}'`;
22
+ const scalar =
23
+ type === undefined
24
+ ? inferredType(value)
25
+ : type.startsWith("filter<")
26
+ ? "filter"
27
+ : type;
28
+ switch (scalar) {
29
+ case "filter":
30
+ return `f${quote(String(value))}`;
31
+ case "string":
32
+ return quote(String(value));
33
+ case "number": {
34
+ const n = typeof value === "number" ? value : Number(value);
35
+ return Number.isFinite(n) ? String(n) : undefined;
36
+ }
37
+ case "boolean":
38
+ return value === true || value === "true" ? "true" : "false";
39
+ case "date": {
40
+ const day = datePart(value);
41
+ return day && `@${day}`;
42
+ }
43
+ case "timestamp": {
44
+ const day = datePart(value);
45
+ if (!day) return undefined;
46
+ const time =
47
+ value instanceof Date
48
+ ? value.toISOString().slice(11, 19)
49
+ : (/[T ](\d{2}:\d{2}(?::\d{2})?)/.exec(String(value))?.[1] ??
50
+ "00:00:00");
51
+ return `@${day} ${time}`;
52
+ }
53
+ default:
54
+ return undefined;
55
+ }
56
+ }
57
+
58
+ function inferredType(value: unknown): string | undefined {
59
+ if (typeof value === "string") return "string";
60
+ if (typeof value === "number") return "number";
61
+ if (typeof value === "boolean") return "boolean";
62
+ if (value instanceof Date && !Number.isNaN(value.getTime()))
63
+ return value.toISOString().slice(11, 19) === "00:00:00"
64
+ ? "date"
65
+ : "timestamp";
66
+ return undefined;
67
+ }
68
+
69
+ /** `2024-01-31` out of a Date (UTC) or an ISO-ish string, else undefined. */
70
+ function datePart(value: unknown): string | undefined {
71
+ if (value instanceof Date)
72
+ return Number.isNaN(value.getTime())
73
+ ? undefined
74
+ : value.toISOString().slice(0, 10);
75
+ return /^(\d{4}-\d{2}-\d{2})/.exec(String(value))?.[1];
76
+ }
package/vite.config.ts CHANGED
@@ -23,6 +23,9 @@ export default ({ mode }) => {
23
23
  entry: {
24
24
  index: "./src/index.ts",
25
25
  "client/index": "./src/client-entry.ts",
26
+ // The dashboard builder, and with it the Malloy parser: its own
27
+ // entry so a host loads it only when someone opens the builder.
28
+ "builder/index": "./src/builder-entry.ts",
26
29
  },
27
30
  name: "@malloy-publisher/sdk",
28
31
  fileName: (format, entryName) => {
@@ -30,6 +33,8 @@ export default ({ mode }) => {
30
33
  return `index.${format}.js`;
31
34
  } else if (entryName === "client/index") {
32
35
  return `client/index.${format}.js`;
36
+ } else if (entryName === "builder/index") {
37
+ return `builder/index.${format}.js`;
33
38
  }
34
39
  return `${entryName}.${format}.js`;
35
40
  },
@@ -66,7 +71,6 @@ export default ({ mode }) => {
66
71
  // Other large React libraries
67
72
  "@react-spring/web",
68
73
  "@tanstack/react-query",
69
- "@uiw/react-md-editor",
70
74
 
71
75
  // Malloy dependencies (should be provided by host)
72
76
  "@malloydata/malloy-explorer",
@@ -1,6 +0,0 @@
1
- import { default as React } from 'react';
2
- import { WorkbookLocator } from './Workbook/WorkbookStorage';
3
- export interface AnalyzePackageButtonProps {
4
- onWorkbookSelect: (workbook: WorkbookLocator, event: React.MouseEvent) => void;
5
- }
6
- export declare function AnalyzePackageButton({ onWorkbookSelect, }: AnalyzePackageButtonProps): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +0,0 @@
1
- import { WorkbookLocator, WorkbookStorage, Workspace } from './WorkbookStorage';
2
- export declare class BrowserWorkbookStorage implements WorkbookStorage {
3
- listWorkspaces(writeableOnly: boolean): Promise<Workspace[]>;
4
- listWorkbooks(_workspace: Workspace): Promise<WorkbookLocator[]>;
5
- getWorkbook(path: WorkbookLocator): Promise<string>;
6
- deleteWorkbook(path: WorkbookLocator): Promise<void>;
7
- saveWorkbook(path: WorkbookLocator, notebook: string): Promise<void>;
8
- moveWorkbook(from: WorkbookLocator, to: WorkbookLocator): Promise<void>;
9
- }
@@ -1,11 +0,0 @@
1
- import { SourceAndPath, QueryExplorerResult } from '../Model/SourcesExplorer';
2
- import { WorkbookCellValue } from './WorkbookManager';
3
- interface EditableMalloyCellProps {
4
- cell: WorkbookCellValue;
5
- sourceAndPaths: SourceAndPath[];
6
- resourceUri: string;
7
- onQueryChange: (query: QueryExplorerResult) => void;
8
- onSourceChange?: (index: number) => void;
9
- }
10
- export declare function EditableMalloyCell({ cell, sourceAndPaths, resourceUri, onQueryChange, onSourceChange, }: EditableMalloyCellProps): import("react/jsx-runtime").JSX.Element;
11
- export {};
@@ -1,11 +0,0 @@
1
- interface ModelPickerProps {
2
- initialSelectedModels: string[];
3
- onModelChange: (models: string[]) => void;
4
- resourceUri: string;
5
- }
6
- /**
7
- * Picks Models that are available in the package.
8
- * Only "malloy" model files are shown.
9
- */
10
- export declare function ModelPicker({ initialSelectedModels, onModelChange, resourceUri, }: ModelPickerProps): import("react/jsx-runtime").JSX.Element;
11
- export {};
@@ -1,17 +0,0 @@
1
- import { default as React } from 'react';
2
- import { SourceAndPath } from '../Model/SourcesExplorer';
3
- import { WorkbookCellValue } from './WorkbookManager';
4
- interface NotebookCellProps {
5
- cell: WorkbookCellValue;
6
- editingMalloy?: boolean;
7
- editingMarkdown?: boolean;
8
- sourceAndPaths: SourceAndPath[];
9
- resourceUri: string;
10
- onCellChange: (cell: WorkbookCellValue) => void;
11
- onClose: () => void;
12
- onEdit: () => void;
13
- onDelete: () => void;
14
- addButtonCallback: (isMarkdown: boolean) => React.ReactNode;
15
- }
16
- export declare function MutableCell({ cell, editingMalloy, editingMarkdown, sourceAndPaths, resourceUri, onCellChange, onClose, onEdit, onDelete, addButtonCallback, }: NotebookCellProps): import("react/jsx-runtime").JSX.Element;
17
- export {};
@@ -1,7 +0,0 @@
1
- import { WorkbookLocator } from './WorkbookStorage';
2
- interface WorkbookProps {
3
- workbookPath?: WorkbookLocator;
4
- resourceUri: string;
5
- }
6
- export default function Workbook({ workbookPath, resourceUri }: WorkbookProps): import("react/jsx-runtime").JSX.Element;
7
- export {};
@@ -1,7 +0,0 @@
1
- import { default as React } from 'react';
2
- import { WorkbookLocator } from './WorkbookStorage';
3
- interface WorkbookListProps {
4
- onWorkbookClick: (workbook: WorkbookLocator, event: React.MouseEvent) => void;
5
- }
6
- export declare function WorkbookList({ onWorkbookClick }: WorkbookListProps): import("react/jsx-runtime").JSX.Element;
7
- export {};
@@ -1,84 +0,0 @@
1
- import { WorkbookLocator, WorkbookStorage } from './WorkbookStorage';
2
- /**
3
- * Interface representing the data structure of a Mutable Workbook
4
- * @interface WorkbookData
5
- * @property {string[]} models - Array of model paths used in the workbook
6
- * @property {WorkbookCellValue[]} cells - Array of cells in the workbook
7
- * @property {WorkbookLocator} workbookPath - Path to the workbook file (relative to project/package)
8
- */
9
- export interface WorkbookData {
10
- models: string[];
11
- cells: WorkbookCellValue[];
12
- workbookPath: WorkbookLocator;
13
- }
14
- /**
15
- * Interface representing a cell in the workbook
16
- * @interface WorkbookCellValue
17
- * @property {boolean} isMarkdown - Whether the cell is a markdown cell
18
- * @property {string} [value] - The content of the cell
19
- * @property {string} [result] - The result of executing the cell
20
- * @property {string} [modelPath] - modelPath associated with the query in the cell
21
- * @property {string} [sourceName] - Name of the source associated with the cell
22
- * @property {string} [queryInfo] - Information about the query in the cell
23
- */
24
- export interface WorkbookCellValue {
25
- isMarkdown: boolean;
26
- value?: string;
27
- result?: string;
28
- modelPath?: string;
29
- sourceName?: string;
30
- queryInfo?: string;
31
- }
32
- /**
33
- * Class for managing workbook operations
34
- * @class WorkbookManager
35
- */
36
- export declare class WorkbookManager {
37
- private workbookData;
38
- private isSaved;
39
- private workbookStorage;
40
- /**
41
- * Creates a new WorkbookManager instance
42
- * @param {WorkbookStorage} workbookStorage - Storage implementation
43
- * @param {WorkbookData} workbookData - Initial workbook data
44
- */
45
- constructor(workbookStorage: WorkbookStorage, workbookData: WorkbookData);
46
- /**
47
- * Gets the current workbook data
48
- * @returns {WorkbookData} The current workbook data
49
- */
50
- getWorkbookData(): WorkbookData;
51
- /**
52
- * Gets the current workbook path
53
- * @returns {string} The path to the workbook
54
- */
55
- getWorkbookPath(): WorkbookLocator;
56
- /**
57
- * Renames the workbook and updates storage
58
- * @param {string} workbookPath - New path for the workbook
59
- * @returns {WorkbookManager} The updated WorkbookManager instance
60
- */
61
- renameWorkbook(workbookPath: string): Promise<WorkbookManager>;
62
- getCells(): WorkbookCellValue[];
63
- deleteCell(index: number): WorkbookManager;
64
- insertCell(index: number, cell: WorkbookCellValue): WorkbookManager;
65
- setCell(index: number, cell: WorkbookCellValue): WorkbookManager;
66
- setModels(models: string[]): WorkbookManager;
67
- getModels(): string[];
68
- updateWorkbookData(workbookData: WorkbookData): WorkbookManager;
69
- saveWorkbook(): Promise<WorkbookManager>;
70
- /**
71
- * Converts the workbook data to a Malloy workbook string.
72
- * @returns {string} The Malloy workbook string
73
- */
74
- toMalloyWorkbook(): string;
75
- static newWorkbook(workbookStorage: WorkbookStorage): WorkbookManager;
76
- /**
77
- * Creates a new workbook manager by loading from local storage.
78
- * Returns an empty instance if the workbook is not found.
79
- * @param workbookStorage - The storage implementation
80
- * @param userContext - The user context for storage
81
- * @param workbookPath - The path to the workbook file (relative to project/package)
82
- */
83
- static loadWorkbook(workbookStorage: WorkbookStorage, workbookPath: WorkbookLocator): Promise<WorkbookManager>;
84
- }
@@ -1,17 +0,0 @@
1
- export interface Workspace {
2
- name: string;
3
- writeable: boolean;
4
- description: string;
5
- }
6
- export interface WorkbookLocator {
7
- path: string;
8
- workspace: string;
9
- }
10
- export interface WorkbookStorage {
11
- listWorkspaces(writeableOnly: boolean): Promise<Workspace[]>;
12
- listWorkbooks(workspace: Workspace): Promise<WorkbookLocator[]>;
13
- getWorkbook(path: WorkbookLocator): Promise<string>;
14
- deleteWorkbook(path: WorkbookLocator): Promise<void>;
15
- saveWorkbook(path: WorkbookLocator, workbook: string): Promise<void>;
16
- moveWorkbook(from: WorkbookLocator, to: WorkbookLocator): Promise<void>;
17
- }
@@ -1,12 +0,0 @@
1
- import { default as React } from 'react';
2
- import { WorkbookStorage } from './WorkbookStorage';
3
- export interface WorkbookStorageProviderProps {
4
- children: React.ReactNode;
5
- workbookStorage: WorkbookStorage;
6
- }
7
- interface WorkbookStorageContextValue {
8
- workbookStorage: WorkbookStorage;
9
- }
10
- export declare function WorkbookStorageProvider({ children, workbookStorage, }: WorkbookStorageProviderProps): import("react/jsx-runtime").JSX.Element;
11
- export declare function useWorkbookStorage(): WorkbookStorageContextValue;
12
- export {};
@@ -1,7 +0,0 @@
1
- export type { WorkbookStorage } from './WorkbookStorage';
2
- export { default as Workbook } from './Workbook';
3
- export { WorkbookList } from './WorkbookList';
4
- export { WorkbookStorageProvider } from './WorkbookStorageProvider';
5
- export type { WorkbookLocator, Workspace } from './WorkbookStorage';
6
- export { BrowserWorkbookStorage } from './BrowserWorkbookStorage';
7
- export { WorkbookManager } from './WorkbookManager';