@malloy-publisher/sdk 0.0.78 → 0.0.80
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/dist/components/QueryResult/index.d.ts +1 -0
- package/dist/hooks/useRawQueryData.d.ts +16 -0
- package/dist/index.cjs.js +56 -56
- package/dist/index.d.ts +1 -0
- package/dist/index.es.js +2434 -2359
- package/package.json +1 -1
- package/src/components/QueryResult/index.ts +1 -0
- package/src/hooks/useQueryWithApiError.ts +7 -4
- package/src/hooks/useRawQueryData.ts +70 -0
- package/src/index.ts +1 -0
package/package.json
CHANGED
|
@@ -30,12 +30,15 @@ export const getAxiosConfig = async (
|
|
|
30
30
|
getAccessToken: () => Promise<string>,
|
|
31
31
|
): Promise<RawAxiosRequestConfig> => {
|
|
32
32
|
const accessToken = getAccessToken ? await getAccessToken() : undefined;
|
|
33
|
+
const headers = accessToken
|
|
34
|
+
? {
|
|
35
|
+
Authorization: `Bearer ${accessToken}`,
|
|
36
|
+
}
|
|
37
|
+
: {};
|
|
33
38
|
return {
|
|
34
39
|
baseURL: server,
|
|
35
|
-
withCredentials:
|
|
36
|
-
headers
|
|
37
|
-
Authorization: accessToken && `Bearer ${accessToken}`,
|
|
38
|
-
},
|
|
40
|
+
withCredentials: !!accessToken,
|
|
41
|
+
headers,
|
|
39
42
|
} as RawAxiosRequestConfig;
|
|
40
43
|
};
|
|
41
44
|
export function useQueryWithApiError<TData = unknown, TError = ApiError>(
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { Configuration, QueryresultsApi } from "../client";
|
|
2
|
+
import { usePackage } from "../components/Package/PackageProvider";
|
|
3
|
+
import { useQueryWithApiError } from "./useQueryWithApiError";
|
|
4
|
+
|
|
5
|
+
const queryResultsApi = new QueryresultsApi(new Configuration());
|
|
6
|
+
|
|
7
|
+
interface UseRawQueryDataProps {
|
|
8
|
+
modelPath: string;
|
|
9
|
+
query?: string;
|
|
10
|
+
sourceName?: string;
|
|
11
|
+
queryName?: string;
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function useRawQueryData({
|
|
16
|
+
modelPath,
|
|
17
|
+
query,
|
|
18
|
+
sourceName,
|
|
19
|
+
queryName,
|
|
20
|
+
enabled = true,
|
|
21
|
+
}: UseRawQueryDataProps) {
|
|
22
|
+
const { projectName, packageName, versionId } = usePackage();
|
|
23
|
+
|
|
24
|
+
const { data, isSuccess, isError, error, isLoading } = useQueryWithApiError({
|
|
25
|
+
queryKey: [
|
|
26
|
+
"rawQueryData",
|
|
27
|
+
projectName,
|
|
28
|
+
packageName,
|
|
29
|
+
modelPath,
|
|
30
|
+
versionId,
|
|
31
|
+
query,
|
|
32
|
+
sourceName,
|
|
33
|
+
queryName,
|
|
34
|
+
],
|
|
35
|
+
queryFn: (config) =>
|
|
36
|
+
queryResultsApi.executeQuery(
|
|
37
|
+
projectName,
|
|
38
|
+
packageName,
|
|
39
|
+
modelPath,
|
|
40
|
+
query,
|
|
41
|
+
sourceName,
|
|
42
|
+
queryName,
|
|
43
|
+
versionId,
|
|
44
|
+
config,
|
|
45
|
+
),
|
|
46
|
+
enabled,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Parse the JSON result string to get the raw data
|
|
50
|
+
const rawData = isSuccess && data?.data?.result
|
|
51
|
+
? (() => {
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(data.data.result);
|
|
54
|
+
// Return the data.array_value array which contains the actual rows
|
|
55
|
+
return parsed.data?.array_value || [];
|
|
56
|
+
} catch (e) {
|
|
57
|
+
console.error("Failed to parse query result:", e);
|
|
58
|
+
return [];
|
|
59
|
+
}
|
|
60
|
+
})()
|
|
61
|
+
: [];
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
data: rawData,
|
|
65
|
+
isSuccess,
|
|
66
|
+
isError,
|
|
67
|
+
error,
|
|
68
|
+
isLoading,
|
|
69
|
+
};
|
|
70
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./components";
|
|
2
2
|
export { default as ConnectionExplorer } from "./components/Project/ConnectionExplorer";
|
|
3
|
+
export { useRawQueryData } from "./hooks/useRawQueryData";
|
|
3
4
|
import axios from "axios";
|
|
4
5
|
|
|
5
6
|
// There's a bug in the OpenAPI generator that causes it to ignore baseURL in the
|