@malloy-publisher/sdk 0.0.41 → 0.0.43

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 (34) hide show
  1. package/dist/{RenderedResult-BX2zW03q.cjs → RenderedResult-qA34vdbd.cjs} +1 -1
  2. package/dist/{RenderedResult-gQPXZIVQ.js → RenderedResult-wM3HaFcq.js} +2 -2
  3. package/dist/components/MutableNotebook/MutableCell.d.ts +3 -1
  4. package/dist/components/Notebook/Notebook.d.ts +4 -3
  5. package/dist/hooks/useQueryWithApiError.d.ts +10 -0
  6. package/dist/{index-DCLrfHfE.js → index-ClVlSQMk.js} +27933 -27929
  7. package/dist/{index-xo1oaGoD.cjs → index-nsXS-gBw.cjs} +598 -598
  8. package/dist/index.cjs.js +1 -1
  9. package/dist/index.es.js +16 -15
  10. package/dist/{vendor-BCM56_2K.js → vendor-BKsYdkmG.js} +5456 -5458
  11. package/dist/{vendor-Bg9-K32d.cjs → vendor-hHfbZ4ZT.cjs} +30 -30
  12. package/openapitools.json +1 -1
  13. package/package.json +2 -2
  14. package/src/components/ApiErrorDisplay.tsx +12 -12
  15. package/src/components/Home/Home.tsx +9 -14
  16. package/src/components/Model/Model.tsx +18 -45
  17. package/src/components/Model/NamedQueries.tsx +38 -42
  18. package/src/components/Model/SourcesExplorer.tsx +47 -51
  19. package/src/components/MutableNotebook/ModelPicker.tsx +12 -18
  20. package/src/components/MutableNotebook/MutableCell.tsx +120 -62
  21. package/src/components/MutableNotebook/MutableNotebook.tsx +45 -27
  22. package/src/components/Notebook/Notebook.tsx +37 -60
  23. package/src/components/Package/Config.tsx +28 -34
  24. package/src/components/Package/Connections.tsx +12 -18
  25. package/src/components/Package/Databases.tsx +12 -18
  26. package/src/components/Package/Models.tsx +12 -20
  27. package/src/components/Package/Notebooks.tsx +13 -12
  28. package/src/components/Package/Schedules.tsx +12 -18
  29. package/src/components/Project/About.tsx +12 -18
  30. package/src/components/Project/ConnectionExplorer.tsx +49 -65
  31. package/src/components/Project/Packages.tsx +12 -18
  32. package/src/components/QueryResult/QueryResult.tsx +24 -30
  33. package/src/hooks/useQueryWithApiError.ts +114 -0
  34. package/src/index.ts +5 -0
package/openapitools.json CHANGED
@@ -2,6 +2,6 @@
2
2
  "$schema": "./node_modules/@openapitools/openapi-generator-cli/config.schema.json",
3
3
  "spaces": 2,
4
4
  "generator-cli": {
5
- "version": "7.8.0"
5
+ "version": "7.13.0"
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@malloy-publisher/sdk",
3
3
  "description": "Malloy Publisher SDK",
4
- "version": "0.0.41",
4
+ "version": "0.0.43",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs.js",
7
7
  "module": "dist/index.es.js",
@@ -49,7 +49,7 @@
49
49
  "markdown-to-jsx": "^7.7.6"
50
50
  },
51
51
  "devDependencies": {
52
- "@openapitools/openapi-generator-cli": "^2.13.5",
52
+ "@openapitools/openapi-generator-cli": "^2.20.2",
53
53
  "@types/k6": "^1.0.2",
54
54
  "@types/react": "^19.1.7",
55
55
  "@types/react-dom": "^19.1.6",
@@ -14,6 +14,7 @@ interface ApiErrorDisplayProps {
14
14
  }
15
15
 
16
16
  export function ApiErrorDisplay({ error, context }: ApiErrorDisplayProps) {
17
+ const errorMessage = error.data?.message || "Unknown Error";
17
18
  return (
18
19
  <>
19
20
  {context && (
@@ -21,18 +22,17 @@ export function ApiErrorDisplay({ error, context }: ApiErrorDisplayProps) {
21
22
  {context}
22
23
  </Typography>
23
24
  )}
24
- {error.data && (
25
- <pre
26
- style={{
27
- whiteSpace: "pre-wrap",
28
- color: "red",
29
- padding: "10px",
30
- margin: "auto",
31
- }}
32
- >
33
- {error.data.message}
34
- </pre>
35
- )}
25
+
26
+ <pre
27
+ style={{
28
+ whiteSpace: "pre-wrap",
29
+ color: "red",
30
+ padding: "10px",
31
+ margin: "auto",
32
+ }}
33
+ >
34
+ {errorMessage}
35
+ </pre>
36
36
  </>
37
37
  );
38
38
  }
@@ -1,11 +1,10 @@
1
1
  import { Grid, Typography } from "@mui/material";
2
- import { QueryClient, useQuery } from "@tanstack/react-query";
3
2
  import { ProjectsApi, Configuration } from "../../client";
4
3
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
5
4
  import { Loading } from "../Loading";
5
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
6
6
 
7
7
  const projectsApi = new ProjectsApi(new Configuration());
8
- const queryClient = new QueryClient();
9
8
 
10
9
  interface HomeProps {
11
10
  server?: string;
@@ -13,18 +12,14 @@ interface HomeProps {
13
12
  }
14
13
 
15
14
  export default function Home({ server, navigate }: HomeProps) {
16
- const { data, isSuccess, isError, error } = useQuery(
17
- {
18
- queryKey: ["projects", server],
19
- queryFn: () =>
20
- projectsApi.listProjects({
21
- baseURL: server,
22
- }),
23
- retry: false,
24
- throwOnError: false,
25
- },
26
- queryClient,
27
- );
15
+ const { data, isSuccess, isError, error } = useQueryWithApiError({
16
+ queryKey: ["projects", server],
17
+ queryFn: () =>
18
+ projectsApi.listProjects({
19
+ baseURL: server,
20
+ withCredentials: true,
21
+ }),
22
+ });
28
23
 
29
24
  console.log(JSON.stringify(data?.data, null, 2));
30
25
 
@@ -12,23 +12,21 @@ import {
12
12
  Tooltip,
13
13
  Typography,
14
14
  } from "@mui/material";
15
- import { QueryClient, useQuery } from "@tanstack/react-query";
16
15
  import React, { useEffect } from "react";
17
16
  import { Configuration, ModelsApi, CompiledModel } from "../../client";
18
17
  import { highlight } from "../highlighter";
19
18
  import { StyledCard, StyledCardContent, StyledCardMedia } from "../styles";
20
19
  import { ModelCell } from "./ModelCell";
21
- import { ApiErrorDisplay, ApiError } from "../ApiErrorDisplay";
20
+ import { ApiErrorDisplay } from "../ApiErrorDisplay";
22
21
 
23
22
  import "@malloydata/malloy-explorer/styles.css";
24
23
  import { usePackage } from "../Package/PackageProvider";
25
24
  import { SourceExplorerComponent } from "./SourcesExplorer";
26
25
  import { Loading } from "../Loading";
26
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
27
27
 
28
28
  const modelsApi = new ModelsApi(new Configuration());
29
29
 
30
- const queryClient = new QueryClient();
31
-
32
30
  interface ModelProps {
33
31
  modelPath: string;
34
32
  versionId?: string;
@@ -64,11 +62,8 @@ export default function Model({
64
62
  });
65
63
  }, [embeddingExpanded, modelCodeSnippet]);
66
64
 
67
- const { data, isError, isLoading, error } = useQuery<
68
- CompiledModel,
69
- ApiError
70
- >(
71
- {
65
+ const { data, isError, isLoading, error } =
66
+ useQueryWithApiError<CompiledModel>({
72
67
  queryKey: [
73
68
  "package",
74
69
  server,
@@ -78,44 +73,22 @@ export default function Model({
78
73
  versionId,
79
74
  ],
80
75
  queryFn: async () => {
81
- try {
82
- const response = await modelsApi.getModel(
83
- projectName,
84
- packageName,
85
- modelPath,
86
- versionId,
87
- {
88
- baseURL: server,
89
- withCredentials: !accessToken,
90
- headers: {
91
- Authorization: accessToken && `Bearer ${accessToken}`,
92
- },
76
+ const response = await modelsApi.getModel(
77
+ projectName,
78
+ packageName,
79
+ modelPath,
80
+ versionId,
81
+ {
82
+ baseURL: server,
83
+ withCredentials: !accessToken,
84
+ headers: {
85
+ Authorization: accessToken && `Bearer ${accessToken}`,
93
86
  },
94
- );
95
- return response.data;
96
- } catch (err) {
97
- // If it's an Axios error, it will have response data
98
- if (err && typeof err === "object" && "response" in err) {
99
- console.log("axios err", err);
100
- const axiosError = err as any;
101
- if (axiosError.response?.data) {
102
- const apiError: ApiError = new Error(
103
- axiosError.response.data.message || axiosError.message,
104
- );
105
- apiError.status = axiosError.response.status;
106
- apiError.data = axiosError.response.data;
107
- throw apiError;
108
- }
109
- }
110
- // For other errors, throw as is
111
- throw err;
112
- }
87
+ },
88
+ );
89
+ return response.data;
113
90
  },
114
- retry: false,
115
- throwOnError: false,
116
- },
117
- queryClient,
118
- );
91
+ });
119
92
 
120
93
  if (isLoading) {
121
94
  return <Loading text="Fetching Model..." />;
@@ -8,14 +8,13 @@ import { Box } from "@mui/system";
8
8
  import { Query, QueryresultsApi } from "../../client/api";
9
9
  import { StyledCard, StyledCardContent } from "../styles";
10
10
 
11
- import { QueryClient, useMutation } from "@tanstack/react-query";
12
11
  import React from "react";
13
12
  import { Configuration } from "../../client";
14
13
  import { usePackage } from "../Package";
15
14
  import ResultContainer from "../RenderedResult/ResultContainer";
15
+ import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
16
16
 
17
17
  const queryResultsApi = new QueryresultsApi(new Configuration());
18
- const queryClient = new QueryClient();
19
18
 
20
19
  interface NamedQueryProps {
21
20
  modelPath: string;
@@ -35,52 +34,49 @@ export default function NamedQueries({
35
34
  Record<string, boolean>
36
35
  >({});
37
36
 
38
- const mutation = useMutation(
39
- {
40
- mutationFn: ({ query }: { query: Query }) => {
41
- const val = queryResultsApi.executeQuery(
42
- projectName,
43
- packageName,
44
- modelPath,
45
- undefined,
46
- undefined,
47
- query.name,
48
- versionId,
49
- {
50
- baseURL: server,
51
- withCredentials: !accessToken,
52
- headers: {
53
- Authorization: accessToken && `Bearer ${accessToken}`,
54
- },
37
+ const mutation = useMutationWithApiError({
38
+ mutationFn: ({ query }: { query: Query }) => {
39
+ const val = queryResultsApi.executeQuery(
40
+ projectName,
41
+ packageName,
42
+ modelPath,
43
+ undefined,
44
+ undefined,
45
+ query.name,
46
+ versionId,
47
+ {
48
+ baseURL: server,
49
+ withCredentials: !accessToken,
50
+ headers: {
51
+ Authorization: accessToken && `Bearer ${accessToken}`,
55
52
  },
56
- );
57
- return val;
58
- },
59
- onSuccess: (data, { query }: { query: Query }) => {
60
- if (data) {
61
- setNamedQueryResults((prev) => ({
62
- ...prev,
63
- [query.name]: data.data.result,
64
- }));
65
- }
66
- },
53
+ },
54
+ );
55
+ return val;
67
56
  },
68
- queryClient,
69
- );
57
+ onSuccess: (data, { query }: { query: Query }) => {
58
+ if (data) {
59
+ setNamedQueryResults((prev) => ({
60
+ ...prev,
61
+ [query.name]: data.data.result,
62
+ }));
63
+ }
64
+ },
65
+ });
70
66
 
71
67
  const handleAccordionChange =
72
68
  (query: Query, queryKey: string) =>
73
- (_event: React.SyntheticEvent, isExpanded: boolean) => {
74
- setExpandedAccordions((prev) => ({
75
- ...prev,
76
- [queryKey]: isExpanded,
77
- }));
69
+ (_event: React.SyntheticEvent, isExpanded: boolean) => {
70
+ setExpandedAccordions((prev) => ({
71
+ ...prev,
72
+ [queryKey]: isExpanded,
73
+ }));
78
74
 
79
- // Trigger mutation only if expanding and we haven't executed this query before
80
- if (isExpanded && !namedQueryResults[query.name]) {
81
- mutation.mutate({ query });
82
- }
83
- };
75
+ // Trigger mutation only if expanding and we haven't executed this query before
76
+ if (isExpanded && !namedQueryResults[query.name]) {
77
+ mutation.mutate({ query });
78
+ }
79
+ };
84
80
 
85
81
  if (!namedQueries) {
86
82
  return <div> Loading Named Queries</div>;
@@ -18,13 +18,12 @@ import {
18
18
  SourcePanel,
19
19
  } from "@malloydata/malloy-explorer";
20
20
  import { styled } from "@mui/material/styles";
21
- import { QueryClient, useMutation } from "@tanstack/react-query";
22
21
  import React from "react";
23
22
  import { Configuration, QueryresultsApi } from "../../client";
24
23
  import { usePackage } from "../Package/PackageProvider";
24
+ import { useMutationWithApiError } from "../../hooks/useQueryWithApiError";
25
25
 
26
26
  const queryResultsApi = new QueryresultsApi(new Configuration());
27
- const queryClient = new QueryClient();
28
27
 
29
28
  export interface SourceAndPath {
30
29
  modelPath: string;
@@ -83,8 +82,8 @@ export function SourcesExplorer({
83
82
  const [selectedTab, setSelectedTab] = React.useState(
84
83
  existingSourceName
85
84
  ? sourceAndPaths.findIndex(
86
- (entry) => entry.sourceInfo.name === existingSourceName,
87
- )
85
+ (entry) => entry.sourceInfo.name === existingSourceName,
86
+ )
88
87
  : 0,
89
88
  );
90
89
 
@@ -174,47 +173,44 @@ export function SourceExplorerComponent({
174
173
  }, [onChange, query]);
175
174
  const { server, projectName, packageName, versionId, accessToken } =
176
175
  usePackage();
177
- const mutation = useMutation(
178
- {
179
- mutationFn: () => {
180
- const malloy = new QueryBuilder.ASTQuery({
181
- source: sourceAndPath.sourceInfo,
182
- query: query?.malloyQuery,
183
- }).toMalloy();
176
+ const mutation = useMutationWithApiError({
177
+ mutationFn: () => {
178
+ const malloy = new QueryBuilder.ASTQuery({
179
+ source: sourceAndPath.sourceInfo,
180
+ query: query?.malloyQuery,
181
+ }).toMalloy();
182
+ setQuery({
183
+ ...query,
184
+ query: malloy,
185
+ });
186
+ return queryResultsApi.executeQuery(
187
+ projectName,
188
+ packageName,
189
+ sourceAndPath.modelPath,
190
+ malloy,
191
+ undefined,
192
+ // sourceInfo.name,
193
+ undefined,
194
+ versionId,
195
+ {
196
+ baseURL: server,
197
+ withCredentials: !accessToken,
198
+ headers: {
199
+ Authorization: accessToken && `Bearer ${accessToken}`,
200
+ },
201
+ },
202
+ );
203
+ },
204
+ onSuccess: (data) => {
205
+ if (data) {
206
+ const parsedResult = JSON.parse(data.data.result);
184
207
  setQuery({
185
208
  ...query,
186
- query: malloy,
209
+ malloyResult: parsedResult as Malloy.Result,
187
210
  });
188
- return queryResultsApi.executeQuery(
189
- projectName,
190
- packageName,
191
- sourceAndPath.modelPath,
192
- malloy,
193
- undefined,
194
- // sourceInfo.name,
195
- undefined,
196
- versionId,
197
- {
198
- baseURL: server,
199
- withCredentials: !accessToken,
200
- headers: {
201
- Authorization: accessToken && `Bearer ${accessToken}`,
202
- },
203
- },
204
- );
205
- },
206
- onSuccess: (data) => {
207
- if (data) {
208
- const parsedResult = JSON.parse(data.data.result);
209
- setQuery({
210
- ...query,
211
- malloyResult: parsedResult as Malloy.Result,
212
- });
213
- }
214
- },
211
+ }
215
212
  },
216
- queryClient,
217
- );
213
+ });
218
214
 
219
215
  const [oldSourceInfo, setOldSourceInfo] = React.useState(
220
216
  sourceAndPath.sourceInfo.name,
@@ -303,16 +299,16 @@ export function SourceExplorerComponent({
303
299
  submittedQuery={
304
300
  query?.malloyQuery
305
301
  ? {
306
- executionState: mutation.isPending
307
- ? "running"
308
- : "finished",
309
- response: {
310
- result: query.malloyResult,
311
- },
312
- query: query.malloyQuery,
313
- queryResolutionStartMillis: Date.now(),
314
- onCancel: mutation.reset,
315
- }
302
+ executionState: mutation.isPending
303
+ ? "running"
304
+ : "finished",
305
+ response: {
306
+ result: query.malloyResult,
307
+ },
308
+ query: query.malloyQuery,
309
+ queryResolutionStartMillis: Date.now(),
310
+ onCancel: mutation.reset,
311
+ }
316
312
  : undefined
317
313
  }
318
314
  options={{ showRawQuery: true }}
@@ -10,14 +10,13 @@ import {
10
10
  Stack,
11
11
  Typography,
12
12
  } from "@mui/material";
13
- import { QueryClient, useQuery } from "@tanstack/react-query";
14
13
  import React from "react";
15
14
  import { Configuration, ModelsApi } from "../../client";
16
15
  import { ApiErrorDisplay } from "../ApiErrorDisplay";
17
16
  import { usePackage } from "../Package/PackageProvider";
17
+ import { useQueryWithApiError } from "../../hooks/useQueryWithApiError";
18
18
 
19
19
  const modelsApi = new ModelsApi(new Configuration());
20
- const queryClient = new QueryClient();
21
20
 
22
21
  interface ModelPickerProps {
23
22
  initialSelectedModels: string[];
@@ -34,22 +33,17 @@ export function ModelPicker({
34
33
  }: ModelPickerProps) {
35
34
  const { server, projectName, packageName, versionId, accessToken } =
36
35
  usePackage();
37
- const { data, isLoading, isSuccess, isError, error } = useQuery(
38
- {
39
- queryKey: ["models", server, projectName, packageName, versionId],
40
- queryFn: () =>
41
- modelsApi.listModels(projectName, packageName, versionId, {
42
- baseURL: server,
43
- withCredentials: !accessToken,
44
- headers: {
45
- Authorization: accessToken && `Bearer ${accessToken}`,
46
- },
47
- }),
48
- retry: false,
49
- throwOnError: false,
50
- },
51
- queryClient,
52
- );
36
+ const { data, isLoading, isSuccess, isError, error } = useQueryWithApiError({
37
+ queryKey: ["models", server, projectName, packageName, versionId],
38
+ queryFn: () =>
39
+ modelsApi.listModels(projectName, packageName, versionId, {
40
+ baseURL: server,
41
+ withCredentials: !accessToken,
42
+ headers: {
43
+ Authorization: accessToken && `Bearer ${accessToken}`,
44
+ },
45
+ }),
46
+ });
53
47
  const [selectedModels, setSelectedModels] = React.useState<string[]>(
54
48
  initialSelectedModels || [],
55
49
  );