@go-avro/avro-js 0.0.22 → 0.0.24
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.
|
@@ -5,11 +5,11 @@ import { AuthManager } from "../auth/AuthManager";
|
|
|
5
5
|
export interface AvroQueryClientProviderProps {
|
|
6
6
|
baseUrl: string;
|
|
7
7
|
authManager: AuthManager;
|
|
8
|
-
queryClient
|
|
8
|
+
queryClient: QueryClient;
|
|
9
9
|
configOverrides?: Partial<AvroQueryClientConfig>;
|
|
10
10
|
children: ReactNode;
|
|
11
11
|
}
|
|
12
|
-
export declare const AvroQueryClientProvider: ({ baseUrl, authManager, configOverrides, children, }: AvroQueryClientProviderProps) => React.JSX.Element;
|
|
12
|
+
export declare const AvroQueryClientProvider: ({ baseUrl, authManager, queryClient, configOverrides, children, }: AvroQueryClientProviderProps) => React.JSX.Element;
|
|
13
13
|
export declare const useAvroQueryClient: () => AvroQueryClient;
|
|
14
14
|
export declare const useSocketEvent: (eventName: string, callback: (data: Record<string, unknown>) => void) => void;
|
|
15
15
|
export default AvroQueryClientProvider;
|
|
@@ -1,18 +1,7 @@
|
|
|
1
1
|
import React, { createContext, useContext, useMemo, useEffect, useRef, useCallback } from "react";
|
|
2
|
-
import { useQueryClient } from "@tanstack/react-query";
|
|
3
2
|
import { AvroQueryClient } from "./QueryClient";
|
|
4
3
|
const AvroQueryClientContext = createContext(null);
|
|
5
|
-
const
|
|
6
|
-
const queryClient = useQueryClient();
|
|
7
|
-
useEffect(() => {
|
|
8
|
-
client.setupSocketInvalidation(queryClient);
|
|
9
|
-
return () => {
|
|
10
|
-
client.teardownSocketInvalidation();
|
|
11
|
-
};
|
|
12
|
-
}, [client, queryClient]);
|
|
13
|
-
return null;
|
|
14
|
-
};
|
|
15
|
-
export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides, children, }) => {
|
|
4
|
+
export const AvroQueryClientProvider = ({ baseUrl, authManager, queryClient, configOverrides, children, }) => {
|
|
16
5
|
const client = useMemo(() => {
|
|
17
6
|
const cfg = {
|
|
18
7
|
baseUrl,
|
|
@@ -22,6 +11,9 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
22
11
|
return new AvroQueryClient(cfg);
|
|
23
12
|
}, [baseUrl, authManager, configOverrides]);
|
|
24
13
|
useEffect(() => {
|
|
14
|
+
if (queryClient) {
|
|
15
|
+
client.setupSocketInvalidation(queryClient);
|
|
16
|
+
}
|
|
25
17
|
return () => {
|
|
26
18
|
try {
|
|
27
19
|
client.teardownSocketInvalidation();
|
|
@@ -31,10 +23,8 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
31
23
|
// ignore
|
|
32
24
|
}
|
|
33
25
|
};
|
|
34
|
-
}, [client]);
|
|
35
|
-
return (React.createElement(AvroQueryClientContext.Provider, { value: client },
|
|
36
|
-
React.createElement(SocketInvalidationBridge, { client: client }),
|
|
37
|
-
children));
|
|
26
|
+
}, [client, queryClient]);
|
|
27
|
+
return (React.createElement(AvroQueryClientContext.Provider, { value: client }, children));
|
|
38
28
|
};
|
|
39
29
|
export const useAvroQueryClient = () => {
|
|
40
30
|
const ctx = useContext(AvroQueryClientContext);
|
|
@@ -424,7 +424,7 @@ declare module '../client/QueryClient' {
|
|
|
424
424
|
breakId: string;
|
|
425
425
|
updates: Partial<Break>;
|
|
426
426
|
}>>;
|
|
427
|
-
|
|
427
|
+
useUpdateUser(userId: string): ReturnType<typeof useMutation<{
|
|
428
428
|
msg: string;
|
|
429
429
|
}, StandardError, Partial<User>>>;
|
|
430
430
|
useDeleteJobs(): ReturnType<typeof useMutation<{
|
|
@@ -59,12 +59,12 @@ AvroQueryClient.prototype.useCreateUser = function () {
|
|
|
59
59
|
},
|
|
60
60
|
});
|
|
61
61
|
};
|
|
62
|
-
AvroQueryClient.prototype.
|
|
62
|
+
AvroQueryClient.prototype.useUpdateUser = function (userId) {
|
|
63
63
|
const queryClient = this.getQueryClient();
|
|
64
64
|
return useMutation({
|
|
65
65
|
mutationFn: async (data) => {
|
|
66
66
|
return this.put({
|
|
67
|
-
path: `/user`,
|
|
67
|
+
path: `/user/${userId}`,
|
|
68
68
|
data: JSON.stringify(data),
|
|
69
69
|
headers: { "Content-Type": "application/json" }
|
|
70
70
|
});
|
|
@@ -72,19 +72,28 @@ AvroQueryClient.prototype.useUpdateSelf = function () {
|
|
|
72
72
|
// Optimistically update the user data in the cache
|
|
73
73
|
onMutate: async (data) => {
|
|
74
74
|
await queryClient.cancelQueries({ queryKey: ['user'] });
|
|
75
|
-
|
|
75
|
+
await queryClient.cancelQueries({ queryKey: ['users', userId] });
|
|
76
|
+
const previousSelf = queryClient.getQueryData(['user']);
|
|
77
|
+
const previousUser = queryClient.getQueryData(['users', userId]);
|
|
78
|
+
if (previousSelf && previousSelf.id === userId) {
|
|
79
|
+
queryClient.setQueryData(['user'], { ...previousSelf, ...data });
|
|
80
|
+
}
|
|
76
81
|
if (previousUser) {
|
|
77
|
-
queryClient.setQueryData(['
|
|
82
|
+
queryClient.setQueryData(['users', userId], { ...previousUser, ...data });
|
|
78
83
|
}
|
|
79
|
-
return { previousUser };
|
|
84
|
+
return { previousSelf, previousUser };
|
|
80
85
|
},
|
|
81
86
|
onError: (err, _, context) => {
|
|
87
|
+
if (context?.previousSelf) {
|
|
88
|
+
queryClient.setQueryData(['user'], context.previousSelf);
|
|
89
|
+
}
|
|
82
90
|
if (context?.previousUser) {
|
|
83
|
-
queryClient.setQueryData(['
|
|
91
|
+
queryClient.setQueryData(['users', userId], context.previousUser);
|
|
84
92
|
}
|
|
85
93
|
},
|
|
86
94
|
onSettled: () => {
|
|
87
95
|
queryClient.invalidateQueries({ queryKey: ['user'] });
|
|
96
|
+
queryClient.invalidateQueries({ queryKey: ['users', userId] });
|
|
88
97
|
},
|
|
89
98
|
});
|
|
90
99
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@go-avro/avro-js",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.24",
|
|
4
4
|
"description": "JS client for Avro backend integration.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -50,11 +50,7 @@
|
|
|
50
50
|
"access": "public"
|
|
51
51
|
},
|
|
52
52
|
"dependencies": {
|
|
53
|
+
"@tanstack/react-query": "^5.90.2",
|
|
53
54
|
"socket.io-client": "^4.8.1"
|
|
54
|
-
},
|
|
55
|
-
"peerDependencies": {
|
|
56
|
-
"react": "^18.0.0 || ^19.0.0",
|
|
57
|
-
"react-dom": "^18.0.0 || ^19.0.0",
|
|
58
|
-
"@tanstack/react-query": "^5.0.0"
|
|
59
55
|
}
|
|
60
56
|
}
|