@malloy-publisher/sdk 0.0.45 → 0.0.46

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 (39) hide show
  1. package/dist/{RenderedResult-wM3HaFcq.js → RenderedResult-Bn1ONmkh.js} +2 -2
  2. package/dist/{RenderedResult-qA34vdbd.cjs → RenderedResult-eQGiBJrZ.cjs} +1 -1
  3. package/dist/components/Home/Home.d.ts +1 -2
  4. package/dist/components/Package/PackageProvider.d.ts +1 -3
  5. package/dist/components/Project/Project.d.ts +1 -3
  6. package/dist/components/ServerProvider.d.ts +12 -0
  7. package/dist/components/index.d.ts +2 -0
  8. package/dist/hooks/useQueryWithApiError.d.ts +4 -3
  9. package/dist/{index-nsXS-gBw.cjs → index-CRJL0zjn.cjs} +558 -573
  10. package/dist/{index-ClVlSQMk.js → index-GV49y9rz.js} +16580 -16687
  11. package/dist/index.cjs.js +1 -1
  12. package/dist/index.es.js +12 -10
  13. package/dist/{vendor-BKsYdkmG.js → vendor-Cr_5VY0T.js} +6361 -6352
  14. package/dist/{vendor-hHfbZ4ZT.cjs → vendor-CxEyd3N4.cjs} +120 -120
  15. package/package.json +1 -1
  16. package/src/components/Home/Home.tsx +3 -10
  17. package/src/components/Model/Model.tsx +6 -26
  18. package/src/components/Model/ModelCell.tsx +0 -16
  19. package/src/components/Model/NamedQueries.tsx +3 -10
  20. package/src/components/Model/SourcesExplorer.tsx +3 -10
  21. package/src/components/MutableNotebook/ModelPicker.tsx +4 -11
  22. package/src/components/MutableNotebook/MutableNotebook.tsx +4 -3
  23. package/src/components/Notebook/Notebook.tsx +6 -44
  24. package/src/components/Package/Config.tsx +10 -11
  25. package/src/components/Package/Connections.tsx +3 -10
  26. package/src/components/Package/Databases.tsx +9 -11
  27. package/src/components/Package/Models.tsx +4 -12
  28. package/src/components/Package/Notebooks.tsx +6 -15
  29. package/src/components/Package/Package.tsx +0 -1
  30. package/src/components/Package/PackageProvider.tsx +1 -7
  31. package/src/components/Package/Schedules.tsx +9 -11
  32. package/src/components/Project/About.tsx +3 -10
  33. package/src/components/Project/ConnectionExplorer.tsx +16 -36
  34. package/src/components/Project/Packages.tsx +3 -10
  35. package/src/components/Project/Project.tsx +1 -5
  36. package/src/components/QueryResult/QueryResult.tsx +3 -11
  37. package/src/components/ServerProvider.tsx +37 -0
  38. package/src/components/index.ts +2 -0
  39. package/src/hooks/useQueryWithApiError.ts +28 -5
@@ -37,7 +37,7 @@ interface ConnectionExplorerProps {
37
37
  export default function ConnectionExplorer({
38
38
  connectionName,
39
39
  }: ConnectionExplorerProps) {
40
- const { server, projectName, accessToken } = useProject();
40
+ const { projectName } = useProject();
41
41
 
42
42
  const [selectedTable, setSelectedTable] = React.useState<string | undefined>(
43
43
  undefined,
@@ -47,15 +47,9 @@ export default function ConnectionExplorer({
47
47
  );
48
48
  const [showHiddenSchemas, setShowHiddenSchemas] = React.useState(false);
49
49
  const { data, isSuccess, isError, error, isLoading } = useQueryWithApiError({
50
- queryKey: ["tablePath", server, projectName, connectionName],
51
- queryFn: () =>
52
- connectionsApi.listSchemas(projectName, connectionName, {
53
- baseURL: server,
54
- withCredentials: !accessToken,
55
- headers: {
56
- Authorization: accessToken && `Bearer ${accessToken}`,
57
- },
58
- }),
50
+ queryKey: ["tablePath", projectName, connectionName],
51
+ queryFn: (config) =>
52
+ connectionsApi.listSchemas(projectName, connectionName, config),
59
53
  });
60
54
 
61
55
  return (
@@ -166,30 +160,23 @@ function TableViewer({
166
160
  tableName,
167
161
  onClose,
168
162
  }: TableViewerProps) {
169
- const { server, projectName, accessToken } = useProject();
163
+ const { projectName } = useProject();
170
164
 
171
165
  const { data, isSuccess, isError, error, isLoading } = useQueryWithApiError({
172
166
  queryKey: [
173
167
  "tablePathSchema",
174
- server,
175
168
  projectName,
176
169
  connectionName,
177
170
  schemaName,
178
171
  tableName,
179
172
  ],
180
- queryFn: () =>
173
+ queryFn: (config) =>
181
174
  connectionsApi.getTablesource(
182
175
  projectName,
183
176
  connectionName,
184
177
  tableName,
185
178
  `${schemaName}.${tableName}`,
186
- {
187
- baseURL: server,
188
- withCredentials: !accessToken,
189
- headers: {
190
- Authorization: accessToken && `Bearer ${accessToken}`,
191
- },
192
- },
179
+ config,
193
180
  ),
194
181
  });
195
182
 
@@ -276,24 +263,17 @@ function TablesInSchema({
276
263
  schemaName,
277
264
  onTableClick,
278
265
  }: TablesInSchemaProps) {
279
- const { server, projectName, accessToken } = useProject();
266
+ const { projectName } = useProject();
280
267
 
281
268
  const { data, isSuccess, isError, error, isLoading } = useQueryWithApiError({
282
- queryKey: [
283
- "tablesInSchema",
284
- server,
285
- projectName,
286
- connectionName,
287
- schemaName,
288
- ],
289
- queryFn: () =>
290
- connectionsApi.listTables(projectName, connectionName, schemaName, {
291
- baseURL: server,
292
- withCredentials: !accessToken,
293
- headers: {
294
- Authorization: accessToken && `Bearer ${accessToken}`,
295
- },
296
- }),
269
+ queryKey: ["tablesInSchema", projectName, connectionName, schemaName],
270
+ queryFn: (config) =>
271
+ connectionsApi.listTables(
272
+ projectName,
273
+ connectionName,
274
+ schemaName,
275
+ config,
276
+ ),
297
277
  });
298
278
 
299
279
  return (
@@ -13,18 +13,11 @@ interface PackagesProps {
13
13
  }
14
14
 
15
15
  export default function Packages({ navigate }: PackagesProps) {
16
- const { server, projectName, accessToken } = useProject();
16
+ const { projectName } = useProject();
17
17
 
18
18
  const { data, isSuccess, isError, error } = useQueryWithApiError({
19
- queryKey: ["packages", server, projectName],
20
- queryFn: () =>
21
- packagesApi.listPackages(projectName, {
22
- baseURL: server,
23
- withCredentials: !accessToken,
24
- headers: {
25
- Authorization: accessToken && `Bearer ${accessToken}`,
26
- },
27
- }),
19
+ queryKey: ["packages", projectName],
20
+ queryFn: (config) => packagesApi.listPackages(projectName, config),
28
21
  });
29
22
 
30
23
  return (
@@ -4,9 +4,7 @@ import Packages from "./Packages";
4
4
  import { createContext, useContext, ReactNode } from "react";
5
5
 
6
6
  export interface ProjectContextProps {
7
- server?: string;
8
7
  projectName: string;
9
- accessToken?: string;
10
8
  }
11
9
 
12
10
  const ProjectContext = createContext<ProjectContextProps | undefined>(
@@ -18,13 +16,11 @@ interface ProjectProviderProps extends ProjectContextProps {
18
16
  }
19
17
 
20
18
  export const ProjectProvider = ({
21
- server,
22
19
  projectName,
23
- accessToken,
24
20
  children,
25
21
  }: ProjectProviderProps) => {
26
22
  return (
27
- <ProjectContext.Provider value={{ server, projectName, accessToken }}>
23
+ <ProjectContext.Provider value={{ projectName }}>
28
24
  {children}
29
25
  </ProjectContext.Provider>
30
26
  );
@@ -22,13 +22,11 @@ export default function QueryResult({
22
22
  sourceName,
23
23
  queryName,
24
24
  }: QueryResultProps) {
25
- const { server, projectName, packageName, versionId, accessToken } =
26
- usePackage();
25
+ const { projectName, packageName, versionId } = usePackage();
27
26
 
28
27
  const { data, isSuccess, isError, error } = useQueryWithApiError({
29
28
  queryKey: [
30
29
  "queryResult",
31
- server,
32
30
  projectName,
33
31
  packageName,
34
32
  modelPath,
@@ -37,7 +35,7 @@ export default function QueryResult({
37
35
  sourceName,
38
36
  queryName,
39
37
  ],
40
- queryFn: () =>
38
+ queryFn: (config) =>
41
39
  queryResultsApi.executeQuery(
42
40
  projectName,
43
41
  packageName,
@@ -46,13 +44,7 @@ export default function QueryResult({
46
44
  sourceName,
47
45
  queryName,
48
46
  versionId,
49
- {
50
- baseURL: server,
51
- withCredentials: !accessToken,
52
- headers: {
53
- Authorization: accessToken && `Bearer ${accessToken}`,
54
- },
55
- },
47
+ config,
56
48
  ),
57
49
  });
58
50
 
@@ -0,0 +1,37 @@
1
+ import React, { createContext, useContext, ReactNode } from "react";
2
+
3
+ export interface ServerContextValue {
4
+ server: string;
5
+ accessToken?: string;
6
+ }
7
+
8
+ const ServerContext = createContext<ServerContextValue | undefined>(undefined);
9
+
10
+ export interface ServerProviderProps {
11
+ server?: string;
12
+ accessToken?: string;
13
+ children: ReactNode;
14
+ }
15
+
16
+ export const ServerProvider: React.FC<ServerProviderProps> = ({
17
+ server = `${window.location.protocol}//${window.location.host}/api/v0`,
18
+ accessToken,
19
+ children,
20
+ }) => {
21
+ const value: ServerContextValue = {
22
+ server,
23
+ accessToken,
24
+ };
25
+
26
+ return (
27
+ <ServerContext.Provider value={value}>{children}</ServerContext.Provider>
28
+ );
29
+ };
30
+
31
+ export const useServer = (): ServerContextValue => {
32
+ const context = useContext(ServerContext);
33
+ if (context === undefined) {
34
+ throw new Error("useServer must be used within a ServerProvider");
35
+ }
36
+ return context;
37
+ };
@@ -7,3 +7,5 @@ export * from "./QueryResult";
7
7
  export * from "./Home";
8
8
  export * from "./Loading";
9
9
  export { useRouterClickHandler } from "./click_helper";
10
+ export { ServerProvider, useServer } from "./ServerProvider";
11
+ export type { ServerContextValue, ServerProviderProps } from "./ServerProvider";
@@ -8,6 +8,8 @@ import {
8
8
  UseMutationResult,
9
9
  } from "@tanstack/react-query";
10
10
  import { ApiError } from "../components/ApiErrorDisplay";
11
+ import { useServer } from "../components";
12
+ import { RawAxiosRequestConfig } from "axios";
11
13
 
12
14
  // Global QueryClient instance
13
15
  const globalQueryClient = new QueryClient({
@@ -25,14 +27,24 @@ const globalQueryClient = new QueryClient({
25
27
 
26
28
  export function useQueryWithApiError<TData = unknown, TError = ApiError>(
27
29
  options: Omit<UseQueryOptions<TData, TError>, "throwOnError" | "retry"> & {
28
- queryFn: () => Promise<TData>;
30
+ queryFn: (config: RawAxiosRequestConfig) => Promise<TData>;
29
31
  },
30
32
  ): UseQueryResult<TData, TError> {
33
+ const { server, accessToken } = useServer();
34
+ const config = {
35
+ baseURL: server,
36
+ withCredentials: !accessToken,
37
+ headers: {
38
+ Authorization: accessToken && `Bearer ${accessToken}`,
39
+ },
40
+ } as RawAxiosRequestConfig;
31
41
  const enhancedOptions: UseQueryOptions<TData, TError> = {
32
42
  ...options,
43
+ // Add in the server to the query key so that we can have a per-server caches.
44
+ queryKey: [...options.queryKey, server],
33
45
  queryFn: async () => {
34
46
  try {
35
- return await options.queryFn();
47
+ return await options.queryFn(config);
36
48
  } catch (err) {
37
49
  // Standardized error handling for axios errors
38
50
  if (err && typeof err === "object" && "response" in err) {
@@ -70,16 +82,27 @@ export function useMutationWithApiError<
70
82
  >(
71
83
  options: Omit<
72
84
  UseMutationOptions<TData, TError, TVariables>,
73
- "throwOnError" | "retry"
85
+ "throwOnError" | "retry" | "mutationFn"
74
86
  > & {
75
- mutationFn: (variables: TVariables) => Promise<TData>;
87
+ mutationFn: (
88
+ variables: TVariables,
89
+ config: RawAxiosRequestConfig,
90
+ ) => Promise<TData>;
76
91
  },
77
92
  ): UseMutationResult<TData, TError, TVariables> {
93
+ const { server, accessToken } = useServer();
94
+ const config = {
95
+ baseURL: server,
96
+ withCredentials: !accessToken,
97
+ headers: {
98
+ Authorization: accessToken && `Bearer ${accessToken}`,
99
+ },
100
+ } as RawAxiosRequestConfig;
78
101
  const enhancedOptions: UseMutationOptions<TData, TError, TVariables> = {
79
102
  ...options,
80
103
  mutationFn: async (variables: TVariables) => {
81
104
  try {
82
- return await options.mutationFn(variables);
105
+ return await options.mutationFn(variables, config);
83
106
  } catch (err) {
84
107
  // Standardized error handling for axios errors
85
108
  if (err && typeof err === "object" && "response" in err) {