@malloy-publisher/sdk 0.0.41 → 0.0.42

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 (31) hide show
  1. package/dist/{RenderedResult-gQPXZIVQ.js → RenderedResult-D4wHWzQL.js} +2 -2
  2. package/dist/{RenderedResult-BX2zW03q.cjs → RenderedResult-DR4Ejhm0.cjs} +1 -1
  3. package/dist/components/Notebook/Notebook.d.ts +4 -3
  4. package/dist/hooks/useQueryWithApiError.d.ts +10 -0
  5. package/dist/{index-xo1oaGoD.cjs → index-C7HUzsul.cjs} +522 -522
  6. package/dist/{index-DCLrfHfE.js → index-wBKeSKqo.js} +21302 -21344
  7. package/dist/index.cjs.js +1 -1
  8. package/dist/index.es.js +16 -15
  9. package/dist/{vendor-BCM56_2K.js → vendor-BKsYdkmG.js} +5456 -5458
  10. package/dist/{vendor-Bg9-K32d.cjs → vendor-hHfbZ4ZT.cjs} +30 -30
  11. package/openapitools.json +1 -1
  12. package/package.json +2 -2
  13. package/src/components/ApiErrorDisplay.tsx +12 -12
  14. package/src/components/Home/Home.tsx +9 -14
  15. package/src/components/Model/Model.tsx +18 -45
  16. package/src/components/Model/NamedQueries.tsx +38 -42
  17. package/src/components/Model/SourcesExplorer.tsx +47 -51
  18. package/src/components/MutableNotebook/ModelPicker.tsx +12 -18
  19. package/src/components/Notebook/Notebook.tsx +37 -60
  20. package/src/components/Package/Config.tsx +28 -34
  21. package/src/components/Package/Connections.tsx +12 -18
  22. package/src/components/Package/Databases.tsx +12 -18
  23. package/src/components/Package/Models.tsx +12 -20
  24. package/src/components/Package/Notebooks.tsx +13 -12
  25. package/src/components/Package/Schedules.tsx +12 -18
  26. package/src/components/Project/About.tsx +12 -18
  27. package/src/components/Project/ConnectionExplorer.tsx +49 -65
  28. package/src/components/Project/Packages.tsx +12 -18
  29. package/src/components/QueryResult/QueryResult.tsx +24 -30
  30. package/src/hooks/useQueryWithApiError.ts +114 -0
  31. package/src/index.ts +5 -0
@@ -1,14 +1,13 @@
1
1
  import { Suspense, lazy } from "react";
2
2
  import { Configuration, QueryresultsApi } from "../../client";
3
- import { QueryClient, useQuery } from "@tanstack/react-query";
4
3
  import { usePackage } from "../Package/PackageProvider";
5
4
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
6
5
  import { Loading } from "../Loading";
6
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
7
7
 
8
8
  const RenderedResult = lazy(() => import("../RenderedResult/RenderedResult"));
9
9
 
10
10
  const queryResultsApi = new QueryresultsApi(new Configuration());
11
- const queryClient = new QueryClient();
12
11
 
13
12
  interface QueryResultProps {
14
13
  modelPath: string;
@@ -26,41 +25,36 @@ export default function QueryResult({
26
25
  const { server, projectName, packageName, versionId, accessToken } =
27
26
  usePackage();
28
27
 
29
- const { data, isSuccess, isError, error } = useQuery(
30
- {
31
- queryKey: [
32
- "queryResult",
33
- server,
28
+ const { data, isSuccess, isError, error } = useQueryWithApiError({
29
+ queryKey: [
30
+ "queryResult",
31
+ server,
32
+ projectName,
33
+ packageName,
34
+ modelPath,
35
+ versionId,
36
+ query,
37
+ sourceName,
38
+ queryName,
39
+ ],
40
+ queryFn: () =>
41
+ queryResultsApi.executeQuery(
34
42
  projectName,
35
43
  packageName,
36
44
  modelPath,
37
- versionId,
38
45
  query,
39
46
  sourceName,
40
47
  queryName,
41
- ],
42
- queryFn: () =>
43
- queryResultsApi.executeQuery(
44
- projectName,
45
- packageName,
46
- modelPath,
47
- query,
48
- sourceName,
49
- queryName,
50
- versionId,
51
- {
52
- baseURL: server,
53
- withCredentials: !accessToken,
54
- headers: {
55
- Authorization: accessToken && `Bearer ${accessToken}`,
56
- },
48
+ versionId,
49
+ {
50
+ baseURL: server,
51
+ withCredentials: !accessToken,
52
+ headers: {
53
+ Authorization: accessToken && `Bearer ${accessToken}`,
57
54
  },
58
- ),
59
- retry: false,
60
- throwOnError: false,
61
- },
62
- queryClient,
63
- );
55
+ },
56
+ ),
57
+ });
64
58
 
65
59
  return (
66
60
  <>
@@ -0,0 +1,114 @@
1
+ import {
2
+ useQuery,
3
+ useMutation,
4
+ QueryClient,
5
+ UseQueryOptions,
6
+ UseQueryResult,
7
+ UseMutationOptions,
8
+ UseMutationResult,
9
+ } from "@tanstack/react-query";
10
+ import { ApiError } from "../components/ApiErrorDisplay";
11
+
12
+ // Global QueryClient instance
13
+ const globalQueryClient = new QueryClient({
14
+ defaultOptions: {
15
+ queries: {
16
+ retry: false,
17
+ throwOnError: false,
18
+ },
19
+ mutations: {
20
+ retry: false,
21
+ throwOnError: false,
22
+ },
23
+ },
24
+ });
25
+
26
+ export function useQueryWithApiError<TData = unknown, TError = ApiError>(
27
+ options: Omit<UseQueryOptions<TData, TError>, "throwOnError" | "retry"> & {
28
+ queryFn: () => Promise<TData>;
29
+ },
30
+ ): UseQueryResult<TData, TError> {
31
+ const enhancedOptions: UseQueryOptions<TData, TError> = {
32
+ ...options,
33
+ queryFn: async () => {
34
+ try {
35
+ return await options.queryFn();
36
+ } catch (err) {
37
+ // Standardized error handling for axios errors
38
+ if (err && typeof err === "object" && "response" in err) {
39
+ const axiosError = err as {
40
+ response?: {
41
+ status: number;
42
+ data: { code: number; message: string };
43
+ };
44
+ message: string;
45
+ };
46
+ if (axiosError.response?.data) {
47
+ const apiError: ApiError = new Error(
48
+ axiosError.response.data.message || axiosError.message,
49
+ );
50
+ apiError.status = axiosError.response.status;
51
+ apiError.data = axiosError.response.data;
52
+ throw apiError;
53
+ }
54
+ }
55
+ // For other errors, throw as is
56
+ throw err;
57
+ }
58
+ },
59
+ retry: false,
60
+ throwOnError: false,
61
+ };
62
+
63
+ return useQuery(enhancedOptions, globalQueryClient);
64
+ }
65
+
66
+ export function useMutationWithApiError<
67
+ TData = unknown,
68
+ TError = ApiError,
69
+ TVariables = void,
70
+ >(
71
+ options: Omit<
72
+ UseMutationOptions<TData, TError, TVariables>,
73
+ "throwOnError" | "retry"
74
+ > & {
75
+ mutationFn: (variables: TVariables) => Promise<TData>;
76
+ },
77
+ ): UseMutationResult<TData, TError, TVariables> {
78
+ const enhancedOptions: UseMutationOptions<TData, TError, TVariables> = {
79
+ ...options,
80
+ mutationFn: async (variables: TVariables) => {
81
+ try {
82
+ return await options.mutationFn(variables);
83
+ } catch (err) {
84
+ // Standardized error handling for axios errors
85
+ if (err && typeof err === "object" && "response" in err) {
86
+ const axiosError = err as {
87
+ response?: {
88
+ status: number;
89
+ data: { code: number; message: string };
90
+ };
91
+ message: string;
92
+ };
93
+ if (axiosError.response?.data) {
94
+ const apiError: ApiError = new Error(
95
+ axiosError.response.data.message || axiosError.message,
96
+ );
97
+ apiError.status = axiosError.response.status;
98
+ apiError.data = axiosError.response.data;
99
+ throw apiError;
100
+ }
101
+ }
102
+ // For other errors, throw as is
103
+ throw err;
104
+ }
105
+ },
106
+ retry: false,
107
+ throwOnError: false,
108
+ };
109
+
110
+ return useMutation(enhancedOptions, globalQueryClient);
111
+ }
112
+
113
+ // Export the global query client for direct access if needed
114
+ export { globalQueryClient };
package/src/index.ts CHANGED
@@ -1,2 +1,7 @@
1
1
  export * from "./components";
2
2
  export { default as ConnectionExplorer } from "./components/Project/ConnectionExplorer";
3
+ import axios from "axios";
4
+
5
+ // There's a bug in the OpenAPI generator that causes it to ignore baseURL in the
6
+ // axios request if defaults.baseURL is not set.
7
+ axios.defaults.baseURL = "IfYouAreSeeingThis_baseURL_IsNotSet";