@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.
- package/README.md +32 -17
- package/dist/ServerProvider-CcfeBpt3.cjs.js +1 -0
- package/dist/{ServerProvider-BxEh3nFI.es.js → ServerProvider-EqBlMMqx.es.js} +1056 -905
- package/dist/client/api.d.ts +297 -6
- package/dist/client/index.cjs.js +1 -1
- package/dist/client/index.es.js +74 -70
- package/dist/components/Dashboard/Dashboard.d.ts +49 -0
- package/dist/components/Dashboard/DashboardTile.d.ts +48 -0
- package/dist/components/Dashboard/index.d.ts +2 -0
- package/dist/components/Notebook/Notebook.d.ts +46 -8
- package/dist/components/Notebook/NotebookCell.d.ts +37 -3
- package/dist/components/Notebook/runPlan.d.ts +29 -0
- package/dist/components/Notebook/types.d.ts +10 -0
- package/dist/components/Package/ContentTypeIcon.d.ts +17 -1
- package/dist/components/Package/Package.d.ts +1 -4
- package/dist/components/RenderedResult/RenderedResult.d.ts +7 -1
- package/dist/components/RenderedResult/ResultContainer.d.ts +3 -1
- package/dist/components/ResultsDialog.d.ts +4 -1
- package/dist/components/ServerProvider.d.ts +2 -1
- package/dist/components/click_helper.d.ts +10 -1
- package/dist/components/drill/index.d.ts +3 -0
- package/dist/components/drill/markDrillableCells.d.ts +55 -0
- package/dist/components/drill/resolveDrill.d.ts +159 -0
- package/dist/components/drill/useDrill.d.ts +63 -0
- package/dist/components/given/GivenInput.d.ts +27 -3
- package/dist/components/given/GivensPanel.d.ts +36 -7
- package/dist/components/given/filterValue.d.ts +117 -0
- package/dist/components/given/index.d.ts +1 -1
- package/dist/components/given/paramCodec.d.ts +60 -0
- package/dist/components/index.d.ts +4 -1
- package/dist/components/styles.d.ts +23 -0
- package/dist/constants/docLinks.d.ts +6 -0
- package/dist/{core-BuvlzSIX.es.js → core-DFBwNhvb.es.js} +1 -1
- package/dist/{core-C86Rb7tJ.cjs.js → core-DZk7z7ko.cjs.js} +1 -1
- package/dist/hooks/givenValue.d.ts +10 -0
- package/dist/hooks/index.d.ts +3 -1
- package/dist/hooks/useGivensState.d.ts +64 -0
- package/dist/hooks/useSuggestOptions.d.ts +78 -0
- package/dist/{index-BdtAZ5k6.es.js → index-CLcRrkxd.es.js} +41221 -39894
- package/dist/index-CWQXhe0D.cjs.js +338 -0
- package/dist/index.cjs.js +1 -1
- package/dist/index.es.js +77 -62
- package/dist/theme/types.d.ts +9 -0
- package/package.json +3 -1
- package/src/components/Connections/AddConnectionDialog.tsx +10 -1
- package/src/components/Dashboard/Dashboard.tsx +395 -0
- package/src/components/Dashboard/DashboardTile.tsx +150 -0
- package/src/components/Dashboard/index.ts +2 -0
- package/src/components/Home/Home.tsx +114 -23
- package/src/components/Notebook/Notebook.tsx +444 -390
- package/src/components/Notebook/NotebookCell.tsx +117 -3
- package/src/components/Notebook/runPlan.spec.ts +152 -0
- package/src/components/Notebook/runPlan.ts +64 -0
- package/src/components/Notebook/types.ts +11 -0
- package/src/components/Package/ContentTypeIcon.spec.ts +88 -0
- package/src/components/Package/ContentTypeIcon.tsx +77 -6
- package/src/components/Package/Package.tsx +148 -38
- package/src/components/RenderedResult/RenderedResult.tsx +309 -19
- package/src/components/RenderedResult/ResultContainer.tsx +28 -1
- package/src/components/ResultsDialog.tsx +5 -0
- package/src/components/ServerProvider.tsx +2 -0
- package/src/components/click_helper.ts +14 -1
- package/src/components/drill/index.ts +25 -0
- package/src/components/drill/markDrillableCells.dom.spec.ts +310 -0
- package/src/components/drill/markDrillableCells.spec.ts +106 -0
- package/src/components/drill/markDrillableCells.ts +311 -0
- package/src/components/drill/resolveDrill.spec.ts +446 -0
- package/src/components/drill/resolveDrill.ts +372 -0
- package/src/components/drill/useDrill.tsx +200 -0
- package/src/components/given/GivenInput.spec.tsx +495 -15
- package/src/components/given/GivenInput.tsx +562 -30
- package/src/components/given/GivensPanel.spec.tsx +172 -0
- package/src/components/given/GivensPanel.tsx +139 -32
- package/src/components/given/filterValue.spec.ts +361 -0
- package/src/components/given/filterValue.ts +204 -0
- package/src/components/given/index.ts +5 -1
- package/src/components/given/paramCodec.spec.ts +854 -0
- package/src/components/given/paramCodec.ts +480 -0
- package/src/components/index.ts +4 -1
- package/src/components/styles.ts +27 -3
- package/src/constants/docLinks.spec.ts +51 -0
- package/src/constants/docLinks.ts +26 -0
- package/src/hooks/givenValue.ts +10 -0
- package/src/hooks/index.ts +6 -4
- package/src/hooks/useGivensState.spec.ts +446 -0
- package/src/hooks/useGivensState.ts +337 -0
- package/src/hooks/useSuggestOptions.spec.ts +109 -0
- package/src/hooks/useSuggestOptions.ts +260 -0
- package/src/theme/buildTableCssVars.ts +4 -0
- package/src/theme/resolveTheme.spec.ts +13 -0
- package/src/theme/resolveTheme.ts +3 -0
- package/src/theme/types.ts +9 -0
- package/test/README.md +16 -10
- package/dist/ServerProvider-Dg5S1qBU.cjs.js +0 -1
- package/dist/hooks/useGivensForm.d.ts +0 -35
- package/dist/index-MES4MGpQ.cjs.js +0 -309
- package/src/hooks/useGivensForm.spec.ts +0 -99
- package/src/hooks/useGivensForm.ts +0 -107
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "bun:test";
|
|
2
|
-
import { act, renderHook } from "@testing-library/react";
|
|
3
|
-
import type { Given } from "../client";
|
|
4
|
-
import { useGivensForm } from "./useGivensForm";
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Hook-testing pattern for this package: `renderHook` to mount the hook,
|
|
8
|
-
* `act()` around anything that sets state, then assert on `result.current`.
|
|
9
|
-
* No JSX is involved, so this is a plain `.spec.ts`.
|
|
10
|
-
*
|
|
11
|
-
* A migration note, since #935 replaces this hook with `useGivensState`:
|
|
12
|
-
* these tests describe behaviours a replacement has to preserve, not an API
|
|
13
|
-
* contract worth keeping, so rewrite them alongside the hook. The last one
|
|
14
|
-
* matters most. It guards a defect that was live here, and a replacement that
|
|
15
|
-
* rebuilds its state on every run of the sync effect will reintroduce it.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const givens = (...names: string[]): Given[] =>
|
|
19
|
-
names.map((name) => ({ name, type: "string" }));
|
|
20
|
-
|
|
21
|
-
describe("useGivensForm", () => {
|
|
22
|
-
it("starts with no overrides, so every given uses its model default", () => {
|
|
23
|
-
const { result } = renderHook(() => useGivensForm(givens("region")));
|
|
24
|
-
expect(result.current.givenValues.size).toBe(0);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
it("records an override and reports it as active", () => {
|
|
28
|
-
const { result } = renderHook(() => useGivensForm(givens("region")));
|
|
29
|
-
|
|
30
|
-
act(() => result.current.updateGiven("region", "CA"));
|
|
31
|
-
|
|
32
|
-
expect(result.current.givenValues.get("region")).toBe("CA");
|
|
33
|
-
expect([...result.current.getActiveGivens()]).toEqual([["region", "CA"]]);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it("treats null as a revert, deleting the key rather than storing null", () => {
|
|
37
|
-
const { result } = renderHook(() => useGivensForm(givens("region")));
|
|
38
|
-
|
|
39
|
-
act(() => result.current.updateGiven("region", "CA"));
|
|
40
|
-
act(() => result.current.updateGiven("region", null));
|
|
41
|
-
|
|
42
|
-
// Deleted, not set to null. A stored null would still be an entry, and
|
|
43
|
-
// the request builder would send the given rather than omitting it.
|
|
44
|
-
expect(result.current.givenValues.has("region")).toBe(false);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it("keeps an explicit empty string, which is an override not a revert", () => {
|
|
48
|
-
const { result } = renderHook(() => useGivensForm(givens("region")));
|
|
49
|
-
|
|
50
|
-
act(() => result.current.updateGiven("region", ""));
|
|
51
|
-
|
|
52
|
-
expect(result.current.givenValues.get("region")).toBe("");
|
|
53
|
-
expect(result.current.getActiveGivens().has("region")).toBe(true);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it("clearAll drops every override", () => {
|
|
57
|
-
const { result } = renderHook(() => useGivensForm(givens("a", "b")));
|
|
58
|
-
|
|
59
|
-
act(() => result.current.updateGiven("a", "1"));
|
|
60
|
-
act(() => result.current.updateGiven("b", "2"));
|
|
61
|
-
act(() => result.current.clearAll());
|
|
62
|
-
|
|
63
|
-
expect(result.current.givenValues.size).toBe(0);
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
it("drops overrides for givens the model no longer declares", () => {
|
|
67
|
-
const { result, rerender } = renderHook(
|
|
68
|
-
({ declared }) => useGivensForm(declared),
|
|
69
|
-
{ initialProps: { declared: givens("a", "b") } },
|
|
70
|
-
);
|
|
71
|
-
|
|
72
|
-
act(() => result.current.updateGiven("a", "1"));
|
|
73
|
-
act(() => result.current.updateGiven("b", "2"));
|
|
74
|
-
|
|
75
|
-
// The model reloaded and "b" is gone.
|
|
76
|
-
rerender({ declared: givens("a") });
|
|
77
|
-
|
|
78
|
-
expect(result.current.givenValues.get("a")).toBe("1");
|
|
79
|
-
expect(result.current.givenValues.has("b")).toBe(false);
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
it("settles when `givens` is a fresh array on every render", () => {
|
|
83
|
-
// This hook is a published SDK export, so a consumer can reasonably call
|
|
84
|
-
// it with an array literal instead of a memoized one. The sync effect
|
|
85
|
-
// keys on `givens` identity, so an unmemoized array re-fires it on every
|
|
86
|
-
// render; if it returns a new Map each time, state identity changes,
|
|
87
|
-
// that re-renders, and the two drive each other until React throws
|
|
88
|
-
// "Maximum update depth exceeded". In-repo callers are shielded only
|
|
89
|
-
// because `useModelGivens` happens to memoize.
|
|
90
|
-
let renders = 0;
|
|
91
|
-
const { result } = renderHook(() => {
|
|
92
|
-
renders++;
|
|
93
|
-
return useGivensForm([{ name: "region", type: "string" }]);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
expect(result.current.givenValues.size).toBe(0);
|
|
97
|
-
expect(renders).toBeLessThan(5);
|
|
98
|
-
});
|
|
99
|
-
});
|
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useState } from "react";
|
|
2
|
-
import { Given } from "../client";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* UI-side value for a given. Mirrors the JS shapes the server accepts
|
|
6
|
-
* for `givens` runtime values, plus `Date` (serialized to ISO before send).
|
|
7
|
-
*/
|
|
8
|
-
export type GivenValue =
|
|
9
|
-
| string
|
|
10
|
-
| number
|
|
11
|
-
| boolean
|
|
12
|
-
| Date
|
|
13
|
-
| string[]
|
|
14
|
-
| number[]
|
|
15
|
-
| null;
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* Result from the useGivensForm hook
|
|
19
|
-
*/
|
|
20
|
-
export interface UseGivensFormResult {
|
|
21
|
-
/** Current value for each given, keyed by given name. Missing keys mean "use the model default". */
|
|
22
|
-
givenValues: Map<string, GivenValue>;
|
|
23
|
-
/** Update a given's value. Pass `null` to revert to model default. */
|
|
24
|
-
updateGiven: (name: string, value: GivenValue) => void;
|
|
25
|
-
/** Remove all overrides. */
|
|
26
|
-
clearAll: () => void;
|
|
27
|
-
/** Map of just the givens that have a user-supplied (non-null) override. */
|
|
28
|
-
getActiveGivens: () => Map<string, Exclude<GivenValue, null>>;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Manages user-supplied values for model `given:` parameters.
|
|
33
|
-
*
|
|
34
|
-
* Mirrors the shape of [`useDimensionFilters`](./useDimensionFilters.ts):
|
|
35
|
-
* keyed by given name, with no source qualifier, because givens are
|
|
36
|
-
* model-level rather than per-source. One entry per OVERRIDE, not per
|
|
37
|
-
* declared given: the map starts empty and a missing key means "use the
|
|
38
|
-
* model default".
|
|
39
|
-
*
|
|
40
|
-
* When `givens` (the introspected list) changes (e.g., after the notebook
|
|
41
|
-
* loads), existing user overrides are preserved for matching names and
|
|
42
|
-
* overrides for names that are no longer declared are dropped. A newly
|
|
43
|
-
* declared given gets no entry: the map holds overrides only, and a missing
|
|
44
|
-
* key already means "use the model default".
|
|
45
|
-
*/
|
|
46
|
-
export function useGivensForm(givens: Given[]): UseGivensFormResult {
|
|
47
|
-
const [givenValues, setGivenValues] = useState<Map<string, GivenValue>>(
|
|
48
|
-
() => new Map(),
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
// Sync the form when the declared givens list changes (e.g., model reloaded).
|
|
52
|
-
// Preserve existing values for givens that still exist; drop values for givens
|
|
53
|
-
// that no longer exist.
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
setGivenValues((prev) => {
|
|
56
|
-
const declared = new Set(
|
|
57
|
-
givens.map((g) => g.name).filter((n): n is string => !!n),
|
|
58
|
-
);
|
|
59
|
-
const next = new Map<string, GivenValue>();
|
|
60
|
-
prev.forEach((value, name) => {
|
|
61
|
-
if (declared.has(name)) next.set(name, value);
|
|
62
|
-
});
|
|
63
|
-
// `next` is `prev` minus undeclared names, so equal sizes means
|
|
64
|
-
// nothing was dropped. Return `prev` itself in that case: handing back
|
|
65
|
-
// a fresh Map every time changes state identity on every run, and a
|
|
66
|
-
// caller passing an unmemoized `givens` array then re-renders, which
|
|
67
|
-
// re-fires this effect, until React gives up.
|
|
68
|
-
return next.size === prev.size ? prev : next;
|
|
69
|
-
});
|
|
70
|
-
}, [givens]);
|
|
71
|
-
|
|
72
|
-
const updateGiven = useCallback((name: string, value: GivenValue) => {
|
|
73
|
-
setGivenValues((prev) => {
|
|
74
|
-
const next = new Map(prev);
|
|
75
|
-
if (value === null) {
|
|
76
|
-
next.delete(name);
|
|
77
|
-
} else {
|
|
78
|
-
next.set(name, value);
|
|
79
|
-
}
|
|
80
|
-
return next;
|
|
81
|
-
});
|
|
82
|
-
}, []);
|
|
83
|
-
|
|
84
|
-
const clearAll = useCallback(() => {
|
|
85
|
-
setGivenValues((prev) => (prev.size === 0 ? prev : new Map()));
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
const getActiveGivens = useCallback((): Map<
|
|
89
|
-
string,
|
|
90
|
-
Exclude<GivenValue, null>
|
|
91
|
-
> => {
|
|
92
|
-
const active = new Map<string, Exclude<GivenValue, null>>();
|
|
93
|
-
givenValues.forEach((value, name) => {
|
|
94
|
-
if (value !== null && value !== undefined) {
|
|
95
|
-
active.set(name, value);
|
|
96
|
-
}
|
|
97
|
-
});
|
|
98
|
-
return active;
|
|
99
|
-
}, [givenValues]);
|
|
100
|
-
|
|
101
|
-
return {
|
|
102
|
-
givenValues,
|
|
103
|
-
updateGiven,
|
|
104
|
-
clearAll,
|
|
105
|
-
getActiveGivens,
|
|
106
|
-
};
|
|
107
|
-
}
|