@go-avro/avro-js 0.0.21 → 0.0.23
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,21 +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
|
-
|
|
15
|
-
* Subscribe to a raw socket event for UI-only side-effects (toasts,
|
|
16
|
-
* alerts, etc.) without managing on/off yourself. Query invalidation
|
|
17
|
-
* is already handled automatically — this is only for presentation.
|
|
18
|
-
*
|
|
19
|
-
* @example
|
|
20
|
-
* useSocketEvent<{ msg: string }>("scheduling_error", (data) => {
|
|
21
|
-
* toast({ title: "Error", description: data.msg });
|
|
22
|
-
* });
|
|
23
|
-
*/
|
|
24
|
-
export declare const useSocketEvent: <T = unknown>(eventName: string, callback: (data: T) => void) => void;
|
|
14
|
+
export declare const useSocketEvent: (eventName: string, callback: (data: Record<string, unknown>) => void) => void;
|
|
25
15
|
export default AvroQueryClientProvider;
|
|
@@ -1,22 +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
|
-
|
|
6
|
-
* Inner component that has access to the tanstack QueryClient via
|
|
7
|
-
* useQueryClient() and wires up socket → query invalidation.
|
|
8
|
-
*/
|
|
9
|
-
const SocketInvalidationBridge = ({ client }) => {
|
|
10
|
-
const queryClient = useQueryClient();
|
|
11
|
-
useEffect(() => {
|
|
12
|
-
client.setupSocketInvalidation(queryClient);
|
|
13
|
-
return () => {
|
|
14
|
-
client.teardownSocketInvalidation();
|
|
15
|
-
};
|
|
16
|
-
}, [client, queryClient]);
|
|
17
|
-
return null;
|
|
18
|
-
};
|
|
19
|
-
export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides, children, }) => {
|
|
4
|
+
export const AvroQueryClientProvider = ({ baseUrl, authManager, queryClient, configOverrides, children, }) => {
|
|
20
5
|
const client = useMemo(() => {
|
|
21
6
|
const cfg = {
|
|
22
7
|
baseUrl,
|
|
@@ -26,6 +11,9 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
26
11
|
return new AvroQueryClient(cfg);
|
|
27
12
|
}, [baseUrl, authManager, configOverrides]);
|
|
28
13
|
useEffect(() => {
|
|
14
|
+
if (queryClient) {
|
|
15
|
+
client.setupSocketInvalidation(queryClient);
|
|
16
|
+
}
|
|
29
17
|
return () => {
|
|
30
18
|
try {
|
|
31
19
|
client.teardownSocketInvalidation();
|
|
@@ -35,10 +23,8 @@ export const AvroQueryClientProvider = ({ baseUrl, authManager, configOverrides,
|
|
|
35
23
|
// ignore
|
|
36
24
|
}
|
|
37
25
|
};
|
|
38
|
-
}, [client]);
|
|
39
|
-
return (React.createElement(AvroQueryClientContext.Provider, { value: client },
|
|
40
|
-
React.createElement(SocketInvalidationBridge, { client: client }),
|
|
41
|
-
children));
|
|
26
|
+
}, [client, queryClient]);
|
|
27
|
+
return (React.createElement(AvroQueryClientContext.Provider, { value: client }, children));
|
|
42
28
|
};
|
|
43
29
|
export const useAvroQueryClient = () => {
|
|
44
30
|
const ctx = useContext(AvroQueryClientContext);
|
|
@@ -47,16 +33,6 @@ export const useAvroQueryClient = () => {
|
|
|
47
33
|
}
|
|
48
34
|
return ctx;
|
|
49
35
|
};
|
|
50
|
-
/**
|
|
51
|
-
* Subscribe to a raw socket event for UI-only side-effects (toasts,
|
|
52
|
-
* alerts, etc.) without managing on/off yourself. Query invalidation
|
|
53
|
-
* is already handled automatically — this is only for presentation.
|
|
54
|
-
*
|
|
55
|
-
* @example
|
|
56
|
-
* useSocketEvent<{ msg: string }>("scheduling_error", (data) => {
|
|
57
|
-
* toast({ title: "Error", description: data.msg });
|
|
58
|
-
* });
|
|
59
|
-
*/
|
|
60
36
|
export const useSocketEvent = (eventName, callback) => {
|
|
61
37
|
const client = useAvroQueryClient();
|
|
62
38
|
const callbackRef = useRef(callback);
|