@refinedev/core 4.36.0 → 4.36.2
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/CHANGELOG.md +24 -0
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/auth/useInvalidateAuthStore/index.d.ts.map +1 -1
- package/dist/hooks/invalidate/index.d.ts +4 -1
- package/dist/hooks/invalidate/index.d.ts.map +1 -1
- package/dist/hooks/live/useResourceSubscription/index.d.ts.map +1 -1
- package/dist/iife/index.js +6 -6
- package/dist/iife/index.js.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/hooks/auth/useInvalidateAuthStore/index.ts +6 -10
- package/src/hooks/invalidate/index.tsx +56 -37
- package/src/hooks/live/useResourceSubscription/index.ts +22 -18
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.36.
|
|
3
|
+
"version": "4.36.2",
|
|
4
4
|
"description": "refine is a React-based framework for building internal tools, rapidly. It ships with Ant Design System, an enterprise-level UI toolkit.",
|
|
5
5
|
"private": false,
|
|
6
6
|
"sideEffects": false,
|
|
@@ -6,17 +6,13 @@ export const useInvalidateAuthStore = () => {
|
|
|
6
6
|
const { keys, preferLegacyKeys } = useKeys();
|
|
7
7
|
|
|
8
8
|
const invalidate = async () => {
|
|
9
|
-
await Promise.all(
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
await Promise.all(
|
|
10
|
+
(["check", "identity", "permissions"] as const).map((action) =>
|
|
11
|
+
queryClient.invalidateQueries(
|
|
12
|
+
keys().auth().action(action).get(preferLegacyKeys),
|
|
13
|
+
),
|
|
12
14
|
),
|
|
13
|
-
|
|
14
|
-
keys().auth().action("identity").get(preferLegacyKeys),
|
|
15
|
-
),
|
|
16
|
-
queryClient.invalidateQueries(
|
|
17
|
-
keys().auth().action("permissions").get(preferLegacyKeys),
|
|
18
|
-
),
|
|
19
|
-
]);
|
|
15
|
+
);
|
|
20
16
|
};
|
|
21
17
|
|
|
22
18
|
return invalidate;
|
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { useCallback } from "react";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
InvalidateOptions,
|
|
4
|
+
InvalidateQueryFilters,
|
|
5
|
+
useQueryClient,
|
|
6
|
+
} from "@tanstack/react-query";
|
|
3
7
|
|
|
4
8
|
import { useResource } from "@hooks/resource";
|
|
5
9
|
import { pickDataProvider } from "@definitions";
|
|
@@ -11,19 +15,25 @@ export type UseInvalidateProp = {
|
|
|
11
15
|
id?: BaseKey;
|
|
12
16
|
dataProviderName?: string;
|
|
13
17
|
invalidates: Array<keyof IQueryKeys> | false;
|
|
18
|
+
invalidationFilters?: InvalidateQueryFilters;
|
|
19
|
+
invalidationOptions?: InvalidateOptions;
|
|
14
20
|
};
|
|
15
21
|
|
|
16
|
-
export const useInvalidate = (): ((
|
|
22
|
+
export const useInvalidate = (): ((
|
|
23
|
+
props: UseInvalidateProp,
|
|
24
|
+
) => Promise<void>) => {
|
|
17
25
|
const { resources } = useResource();
|
|
18
26
|
const queryClient = useQueryClient();
|
|
19
27
|
const { keys, preferLegacyKeys } = useKeys();
|
|
20
28
|
|
|
21
29
|
const invalidate = useCallback(
|
|
22
|
-
({
|
|
30
|
+
async ({
|
|
23
31
|
resource,
|
|
24
32
|
dataProviderName,
|
|
25
33
|
invalidates,
|
|
26
34
|
id,
|
|
35
|
+
invalidationFilters = { type: "all", refetchType: "active" },
|
|
36
|
+
invalidationOptions = { cancelRefetch: false },
|
|
27
37
|
}: UseInvalidateProp) => {
|
|
28
38
|
if (invalidates === false) {
|
|
29
39
|
return;
|
|
@@ -34,40 +44,49 @@ export const useInvalidate = (): ((props: UseInvalidateProp) => void) => {
|
|
|
34
44
|
.data(dp)
|
|
35
45
|
.resource(resource ?? "");
|
|
36
46
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
47
|
+
await Promise.all(
|
|
48
|
+
invalidates.map((key) => {
|
|
49
|
+
switch (key) {
|
|
50
|
+
case "all":
|
|
51
|
+
return queryClient.invalidateQueries(
|
|
52
|
+
keys().data(dp).get(preferLegacyKeys),
|
|
53
|
+
invalidationFilters,
|
|
54
|
+
invalidationOptions,
|
|
55
|
+
);
|
|
56
|
+
case "list":
|
|
57
|
+
return queryClient.invalidateQueries(
|
|
58
|
+
queryKey.action("list").get(preferLegacyKeys),
|
|
59
|
+
invalidationFilters,
|
|
60
|
+
invalidationOptions,
|
|
61
|
+
);
|
|
62
|
+
case "many":
|
|
63
|
+
return queryClient.invalidateQueries(
|
|
64
|
+
queryKey.action("many").get(preferLegacyKeys),
|
|
65
|
+
invalidationFilters,
|
|
66
|
+
invalidationOptions,
|
|
67
|
+
);
|
|
68
|
+
case "resourceAll":
|
|
69
|
+
return queryClient.invalidateQueries(
|
|
70
|
+
queryKey.get(preferLegacyKeys),
|
|
71
|
+
invalidationFilters,
|
|
72
|
+
invalidationOptions,
|
|
73
|
+
);
|
|
74
|
+
case "detail":
|
|
75
|
+
return queryClient.invalidateQueries(
|
|
76
|
+
queryKey
|
|
77
|
+
.action("one")
|
|
78
|
+
.id(id || "")
|
|
79
|
+
.get(preferLegacyKeys),
|
|
80
|
+
invalidationFilters,
|
|
81
|
+
invalidationOptions,
|
|
82
|
+
);
|
|
83
|
+
default:
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
}),
|
|
87
|
+
);
|
|
88
|
+
|
|
89
|
+
return;
|
|
71
90
|
},
|
|
72
91
|
[],
|
|
73
92
|
);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { useContext, useEffect } from "react";
|
|
2
|
-
import { useQueryClient } from "@tanstack/react-query";
|
|
3
2
|
import {
|
|
4
3
|
BaseKey,
|
|
5
4
|
CrudFilters,
|
|
@@ -14,7 +13,7 @@ import {
|
|
|
14
13
|
import { LiveContext } from "@contexts/live";
|
|
15
14
|
import { RefineContext } from "@contexts/refine";
|
|
16
15
|
import { useResource } from "@hooks/resource";
|
|
17
|
-
import {
|
|
16
|
+
import { useInvalidate } from "@hooks/invalidate";
|
|
18
17
|
|
|
19
18
|
export type UseResourceSubscriptionProps = {
|
|
20
19
|
channel: string;
|
|
@@ -58,10 +57,7 @@ export const useResourceSubscription = ({
|
|
|
58
57
|
liveMode: liveModeFromProp,
|
|
59
58
|
onLiveEvent,
|
|
60
59
|
}: UseResourceSubscriptionProps): void => {
|
|
61
|
-
const queryClient = useQueryClient();
|
|
62
|
-
|
|
63
60
|
const { resource, identifier } = useResource(resourceFromProp);
|
|
64
|
-
const { keys, preferLegacyKeys } = useKeys();
|
|
65
61
|
|
|
66
62
|
const liveDataContext = useContext<ILiveContext>(LiveContext);
|
|
67
63
|
const {
|
|
@@ -71,9 +67,29 @@ export const useResourceSubscription = ({
|
|
|
71
67
|
|
|
72
68
|
const liveMode = liveModeFromProp ?? liveModeFromContext;
|
|
73
69
|
|
|
70
|
+
const invalidate = useInvalidate();
|
|
71
|
+
|
|
74
72
|
useEffect(() => {
|
|
75
73
|
let subscription: any;
|
|
76
74
|
|
|
75
|
+
const callback = (event: LiveEvent) => {
|
|
76
|
+
if (liveMode === "auto") {
|
|
77
|
+
invalidate({
|
|
78
|
+
resource: identifier,
|
|
79
|
+
dataProviderName: resource?.meta?.dataProviderName,
|
|
80
|
+
invalidates: ["resourceAll"],
|
|
81
|
+
invalidationFilters: {
|
|
82
|
+
type: "active",
|
|
83
|
+
refetchType: "active",
|
|
84
|
+
},
|
|
85
|
+
invalidationOptions: { cancelRefetch: false },
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
onLiveEvent?.(event);
|
|
90
|
+
onLiveEventContextCallback?.(event);
|
|
91
|
+
};
|
|
92
|
+
|
|
77
93
|
if (liveMode && liveMode !== "off" && enabled) {
|
|
78
94
|
subscription = liveDataContext?.subscribe({
|
|
79
95
|
channel,
|
|
@@ -82,19 +98,7 @@ export const useResourceSubscription = ({
|
|
|
82
98
|
...params,
|
|
83
99
|
},
|
|
84
100
|
types,
|
|
85
|
-
callback
|
|
86
|
-
if (liveMode === "auto") {
|
|
87
|
-
queryClient.invalidateQueries(
|
|
88
|
-
keys()
|
|
89
|
-
.data(resource?.meta?.dataProviderName)
|
|
90
|
-
.resource(identifier)
|
|
91
|
-
.get(preferLegacyKeys),
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
onLiveEvent?.(event);
|
|
96
|
-
onLiveEventContextCallback?.(event);
|
|
97
|
-
},
|
|
101
|
+
callback,
|
|
98
102
|
});
|
|
99
103
|
}
|
|
100
104
|
|