@refinedev/core 4.34.0 → 4.35.0
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 +13 -1
- package/dist/contexts/refine/IRefineContext.d.ts +2 -0
- package/dist/contexts/refine/IRefineContext.d.ts.map +1 -1
- package/dist/definitions/helpers/handleRefineOptions/index.d.ts.map +1 -1
- package/dist/definitions/helpers/index.d.ts +3 -1
- package/dist/definitions/helpers/index.d.ts.map +1 -1
- package/dist/definitions/helpers/keys/index.d.ts +75 -0
- package/dist/definitions/helpers/keys/index.d.ts.map +1 -0
- package/dist/definitions/helpers/queryKeys/index.d.ts +4 -0
- package/dist/definitions/helpers/queryKeys/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/hooks/accessControl/useCan/index.d.ts.map +1 -1
- package/dist/hooks/auditLog/useLog/index.d.ts.map +1 -1
- package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
- package/dist/hooks/auth/useForgotPassword/index.d.ts.map +1 -1
- package/dist/hooks/auth/useGetIdentity/index.d.ts.map +1 -1
- package/dist/hooks/auth/useInvalidateAuthStore/index.d.ts.map +1 -1
- package/dist/hooks/auth/useIsAuthenticated/index.d.ts.map +1 -1
- package/dist/hooks/auth/useLogin/index.d.ts.map +1 -1
- package/dist/hooks/auth/useLogout/index.d.ts.map +1 -1
- package/dist/hooks/auth/useOnError/index.d.ts.map +1 -1
- package/dist/hooks/auth/usePermissions/index.d.ts.map +1 -1
- package/dist/hooks/auth/useRegister/index.d.ts.map +1 -1
- package/dist/hooks/auth/useUpdatePassword/index.d.ts.map +1 -1
- package/dist/hooks/data/useCreate.d.ts.map +1 -1
- package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
- package/dist/hooks/data/useCustom.d.ts.map +1 -1
- package/dist/hooks/data/useCustomMutation.d.ts.map +1 -1
- package/dist/hooks/data/useDelete.d.ts.map +1 -1
- package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
- package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
- package/dist/hooks/data/useList.d.ts.map +1 -1
- package/dist/hooks/data/useMany.d.ts.map +1 -1
- package/dist/hooks/data/useOne.d.ts.map +1 -1
- package/dist/hooks/data/useUpdate.d.ts.map +1 -1
- package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
- package/dist/hooks/invalidate/index.d.ts.map +1 -1
- package/dist/hooks/live/useResourceSubscription/index.d.ts.map +1 -1
- package/dist/hooks/useKeys/index.d.ts +5 -0
- package/dist/hooks/useKeys/index.d.ts.map +1 -0
- package/dist/iife/index.js +6 -6
- package/dist/iife/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -6
- package/dist/index.js.map +1 -1
- package/dist/interfaces/mutationMode.d.ts +3 -0
- package/dist/interfaces/mutationMode.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/contexts/refine/IRefineContext.ts +2 -0
- package/src/definitions/helpers/handleRefineOptions/index.ts +1 -0
- package/src/definitions/helpers/index.ts +3 -1
- package/src/definitions/helpers/keys/index.ts +336 -0
- package/src/definitions/helpers/queryKeys/index.ts +68 -0
- package/src/hooks/accessControl/useCan/index.ts +9 -7
- package/src/hooks/auditLog/useLog/index.ts +15 -8
- package/src/hooks/auditLog/useLogList/index.ts +8 -4
- package/src/hooks/auth/useForgotPassword/index.ts +29 -20
- package/src/hooks/auth/useGetIdentity/index.ts +7 -2
- package/src/hooks/auth/useInvalidateAuthStore/index.ts +11 -3
- package/src/hooks/auth/useIsAuthenticated/index.ts +11 -2
- package/src/hooks/auth/useLogin/index.ts +35 -26
- package/src/hooks/auth/useLogout/index.ts +7 -2
- package/src/hooks/auth/useOnError/index.ts +26 -16
- package/src/hooks/auth/usePermissions/index.ts +7 -2
- package/src/hooks/auth/useRegister/index.ts +34 -24
- package/src/hooks/auth/useUpdatePassword/index.ts +8 -2
- package/src/hooks/data/useCreate.ts +3 -0
- package/src/hooks/data/useCreateMany.ts +6 -0
- package/src/hooks/data/useCustom.ts +12 -7
- package/src/hooks/data/useCustomMutation.ts +6 -0
- package/src/hooks/data/useDelete.ts +24 -6
- package/src/hooks/data/useDeleteMany.ts +32 -7
- package/src/hooks/data/useInfiniteList.ts +21 -20
- package/src/hooks/data/useList.ts +21 -15
- package/src/hooks/data/useMany.ts +11 -3
- package/src/hooks/data/useOne.ts +11 -3
- package/src/hooks/data/useUpdate.ts +29 -7
- package/src/hooks/data/useUpdateMany.ts +31 -7
- package/src/hooks/invalidate/index.tsx +24 -10
- package/src/hooks/live/useResourceSubscription/index.ts +8 -3
- package/src/hooks/useKeys/index.tsx +13 -0
- package/src/index.tsx +2 -0
- package/src/interfaces/mutationMode.ts +3 -0
|
@@ -5,6 +5,9 @@ export declare type QueryResponse<T = BaseRecord> = GetListResponse<T> | GetOneR
|
|
|
5
5
|
export declare type PreviousQuery<TData> = [QueryKey, TData | unknown];
|
|
6
6
|
export declare type PrevContext<TData> = {
|
|
7
7
|
previousQueries: PreviousQuery<TData>[];
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated `QueryKeys` is deprecated in favor of `keys`. Please use `keys` instead to construct query keys for queries and mutations.
|
|
10
|
+
*/
|
|
8
11
|
queryKey: IQueryKeys;
|
|
9
12
|
};
|
|
10
13
|
export declare type Context = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mutationMode.d.ts","sourceRoot":"","sources":["../../src/interfaces/mutationMode.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,eAAe,EACf,cAAc,EACd,UAAU,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,oBAAY,YAAY,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,CAAC;AAErE,oBAAY,aAAa,CAAC,CAAC,GAAG,UAAU,IAClC,eAAe,CAAC,CAAC,CAAC,GAClB,cAAc,CAAC,CAAC,CAAC,CAAC;AAExB,oBAAY,aAAa,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC;AAE/D,oBAAY,WAAW,CAAC,KAAK,IAAI;IAC7B,eAAe,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;IACxC,QAAQ,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,oBAAY,OAAO,GAAG;IAClB,eAAe,EAAE,YAAY,EAAE,CAAC;CACnC,CAAC;AAEF,oBAAY,YAAY,CAAC,CAAC,GAAG,UAAU,IAAI;IACvC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;CACtB,CAAC"}
|
|
1
|
+
{"version":3,"file":"mutationMode.d.ts","sourceRoot":"","sources":["../../src/interfaces/mutationMode.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,UAAU,EACV,eAAe,EACf,cAAc,EACd,UAAU,EACb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEjD,oBAAY,YAAY,GAAG,aAAa,GAAG,YAAY,GAAG,UAAU,CAAC;AAErE,oBAAY,aAAa,CAAC,CAAC,GAAG,UAAU,IAClC,eAAe,CAAC,CAAC,CAAC,GAClB,cAAc,CAAC,CAAC,CAAC,CAAC;AAExB,oBAAY,aAAa,CAAC,KAAK,IAAI,CAAC,QAAQ,EAAE,KAAK,GAAG,OAAO,CAAC,CAAC;AAE/D,oBAAY,WAAW,CAAC,KAAK,IAAI;IAC7B,eAAe,EAAE,aAAa,CAAC,KAAK,CAAC,EAAE,CAAC;IACxC;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,oBAAY,OAAO,GAAG;IAClB,eAAe,EAAE,YAAY,EAAE,CAAC;CACnC,CAAC;AAEF,oBAAY,YAAY,CAAC,CAAC,GAAG,UAAU,IAAI;IACvC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,CAAC;IACxB,QAAQ,EAAE,QAAQ,CAAC;CACtB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@refinedev/core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.35.0",
|
|
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,
|
|
@@ -44,6 +44,7 @@ export interface IRefineOptions {
|
|
|
44
44
|
* The project id of your refine project. Will be set automatically. Don't modify.
|
|
45
45
|
*/
|
|
46
46
|
projectId?: string;
|
|
47
|
+
useNewQueryKeys?: boolean;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
export interface IRefineContextOptions {
|
|
@@ -62,6 +63,7 @@ export interface IRefineContextOptions {
|
|
|
62
63
|
textTransformers: Required<TextTransformers>;
|
|
63
64
|
disableServerSideValidation: boolean;
|
|
64
65
|
projectId?: string;
|
|
66
|
+
useNewQueryKeys?: boolean;
|
|
65
67
|
}
|
|
66
68
|
|
|
67
69
|
export interface IRefineContext {
|
|
@@ -2,7 +2,7 @@ export { userFriendlySecond } from "./userFriendlySeconds";
|
|
|
2
2
|
export { importCSVMapper } from "./importCSVMapper";
|
|
3
3
|
export { userFriendlyResourceName } from "./userFriendlyResourceName";
|
|
4
4
|
export { handleUseParams } from "./handleUseParams";
|
|
5
|
-
export { queryKeys } from "./queryKeys";
|
|
5
|
+
export { queryKeys, queryKeysReplacement } from "./queryKeys";
|
|
6
6
|
export { hasPermission } from "./hasPermission";
|
|
7
7
|
export { routeGenerator } from "./routeGenerator";
|
|
8
8
|
export { createTreeView } from "./treeView/createTreeView";
|
|
@@ -26,3 +26,5 @@ export { handlePaginationParams } from "./handlePaginationParams";
|
|
|
26
26
|
export { useMediaQuery } from "./useMediaQuery";
|
|
27
27
|
export { generateDefaultDocumentTitle } from "./generateDocumentTitle";
|
|
28
28
|
export { useUserFriendlyName } from "./useUserFriendlyName";
|
|
29
|
+
export { keys, stripUndefined } from "./keys";
|
|
30
|
+
export { KeyBuilder } from "./keys";
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { BaseKey } from "src/interfaces";
|
|
2
|
+
|
|
3
|
+
type ParametrizedDataActions = "list" | "infinite";
|
|
4
|
+
type IdRequiredDataActions = "one";
|
|
5
|
+
type IdsRequiredDataActions = "many";
|
|
6
|
+
type DataMutationActions =
|
|
7
|
+
| "custom"
|
|
8
|
+
| "customMutation"
|
|
9
|
+
| "create"
|
|
10
|
+
| "createMany"
|
|
11
|
+
| "update"
|
|
12
|
+
| "updateMany"
|
|
13
|
+
| "delete"
|
|
14
|
+
| "deleteMany";
|
|
15
|
+
|
|
16
|
+
type AuthActionType =
|
|
17
|
+
| "login"
|
|
18
|
+
| "logout"
|
|
19
|
+
| "identity"
|
|
20
|
+
| "register"
|
|
21
|
+
| "forgotPassword"
|
|
22
|
+
| "check"
|
|
23
|
+
| "onError"
|
|
24
|
+
| "permissions"
|
|
25
|
+
| "updatePassword";
|
|
26
|
+
|
|
27
|
+
type AuditActionType = "list" | "log" | "rename";
|
|
28
|
+
|
|
29
|
+
type IdType = BaseKey;
|
|
30
|
+
type IdsType = IdType[];
|
|
31
|
+
|
|
32
|
+
type ParamsType = any;
|
|
33
|
+
|
|
34
|
+
type KeySegment = string | IdType | IdsType | ParamsType;
|
|
35
|
+
|
|
36
|
+
export function arrayFindIndex<T>(array: T[], slice: T[]): number {
|
|
37
|
+
return array.findIndex(
|
|
38
|
+
(item, index) =>
|
|
39
|
+
index <= array.length - slice.length &&
|
|
40
|
+
slice.every(
|
|
41
|
+
(sliceItem, sliceIndex) =>
|
|
42
|
+
array[index + sliceIndex] === sliceItem,
|
|
43
|
+
),
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function arrayReplace<T>(
|
|
48
|
+
array: T[],
|
|
49
|
+
partToBeReplaced: T[],
|
|
50
|
+
newPart: T[],
|
|
51
|
+
): T[] {
|
|
52
|
+
const newArray: T[] = [...array];
|
|
53
|
+
const startIndex = arrayFindIndex(array, partToBeReplaced);
|
|
54
|
+
|
|
55
|
+
if (startIndex !== -1) {
|
|
56
|
+
newArray.splice(startIndex, partToBeReplaced.length, ...newPart);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return newArray;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export function stripUndefined(segments: KeySegment[]) {
|
|
63
|
+
return segments.filter((segment) => segment !== undefined);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function convertToLegacy(segments: KeySegment[]) {
|
|
67
|
+
// for `list`, `many` and `one`
|
|
68
|
+
if (segments[0] === "data") {
|
|
69
|
+
// [data, dpName, resource, action, ...];
|
|
70
|
+
const newSegments = segments.slice(1);
|
|
71
|
+
|
|
72
|
+
if (newSegments[2] === "many") {
|
|
73
|
+
newSegments[2] = "getMany";
|
|
74
|
+
} else if (newSegments[2] === "infinite") {
|
|
75
|
+
newSegments[2] = "list";
|
|
76
|
+
} else if (newSegments[2] === "one") {
|
|
77
|
+
newSegments[2] = "detail";
|
|
78
|
+
} else if (newSegments[1] === "custom") {
|
|
79
|
+
const newParams = {
|
|
80
|
+
...newSegments[2],
|
|
81
|
+
};
|
|
82
|
+
delete newParams.method;
|
|
83
|
+
delete newParams.url;
|
|
84
|
+
|
|
85
|
+
return [
|
|
86
|
+
newSegments[0],
|
|
87
|
+
newSegments[1],
|
|
88
|
+
newSegments[2].method,
|
|
89
|
+
newSegments[2].url,
|
|
90
|
+
newParams,
|
|
91
|
+
];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return newSegments;
|
|
95
|
+
}
|
|
96
|
+
// for `audit` -> `logList`
|
|
97
|
+
if (segments[0] === "audit") {
|
|
98
|
+
// [audit, resource, action, params] (for log and list)
|
|
99
|
+
// or
|
|
100
|
+
// [audit, action, params] (for rename)
|
|
101
|
+
if (segments[2] === "list") {
|
|
102
|
+
return ["logList", segments[1], segments[3]];
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
// for `access` -> `useCan`
|
|
106
|
+
if (segments[0] === "access") {
|
|
107
|
+
// [access, resource, action, params]
|
|
108
|
+
if (segments.length === 4) {
|
|
109
|
+
return [
|
|
110
|
+
"useCan",
|
|
111
|
+
{
|
|
112
|
+
resource: segments[1],
|
|
113
|
+
action: segments[2],
|
|
114
|
+
...segments[3], // params: { params, enabled }
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
// for `auth`
|
|
120
|
+
if (segments[0] === "auth") {
|
|
121
|
+
if (arrayFindIndex(segments, ["auth", "login"]) !== -1) {
|
|
122
|
+
return ["useLogin"];
|
|
123
|
+
}
|
|
124
|
+
if (arrayFindIndex(segments, ["auth", "logout"]) !== -1) {
|
|
125
|
+
return ["useLogout"];
|
|
126
|
+
}
|
|
127
|
+
if (arrayFindIndex(segments, ["auth", "identity"]) !== -1) {
|
|
128
|
+
return ["getUserIdentity"];
|
|
129
|
+
}
|
|
130
|
+
if (arrayFindIndex(segments, ["auth", "register"]) !== -1) {
|
|
131
|
+
return ["useRegister"];
|
|
132
|
+
}
|
|
133
|
+
if (arrayFindIndex(segments, ["auth", "forgotPassword"]) !== -1) {
|
|
134
|
+
return ["useForgotPassword"];
|
|
135
|
+
}
|
|
136
|
+
if (arrayFindIndex(segments, ["auth", "check"]) !== -1) {
|
|
137
|
+
return ["useAuthenticated", segments[2]]; // [auth, check, params]
|
|
138
|
+
}
|
|
139
|
+
if (arrayFindIndex(segments, ["auth", "onError"]) !== -1) {
|
|
140
|
+
return ["useCheckError"];
|
|
141
|
+
}
|
|
142
|
+
if (arrayFindIndex(segments, ["auth", "permissions"]) !== -1) {
|
|
143
|
+
return ["usePermissions"];
|
|
144
|
+
}
|
|
145
|
+
if (arrayFindIndex(segments, ["auth", "updatePassword"]) !== -1) {
|
|
146
|
+
return ["useUpdatePassword"];
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return segments;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
class BaseKeyBuilder {
|
|
153
|
+
segments: KeySegment[] = [];
|
|
154
|
+
|
|
155
|
+
constructor(segments: KeySegment[] = []) {
|
|
156
|
+
this.segments = segments;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
key() {
|
|
160
|
+
return this.segments;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
legacy() {
|
|
164
|
+
return convertToLegacy(this.segments);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
get(legacy?: boolean) {
|
|
168
|
+
return legacy ? this.legacy() : this.segments;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
class ParamsKeyBuilder extends BaseKeyBuilder {
|
|
173
|
+
constructor(segments: KeySegment[]) {
|
|
174
|
+
super(segments);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
params(paramsValue?: ParamsType) {
|
|
178
|
+
return new BaseKeyBuilder([...this.segments, paramsValue]);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
class DataIdRequiringKeyBuilder extends BaseKeyBuilder {
|
|
183
|
+
constructor(segments: KeySegment[]) {
|
|
184
|
+
super(segments);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
id(idValue?: IdType) {
|
|
188
|
+
return new ParamsKeyBuilder([
|
|
189
|
+
...this.segments,
|
|
190
|
+
idValue ? String(idValue) : undefined,
|
|
191
|
+
]);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
class DataIdsRequiringKeyBuilder extends BaseKeyBuilder {
|
|
196
|
+
constructor(segments: KeySegment[]) {
|
|
197
|
+
super(segments);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
ids(...idsValue: IdsType) {
|
|
201
|
+
return new ParamsKeyBuilder([
|
|
202
|
+
...this.segments,
|
|
203
|
+
...(idsValue.length ? [idsValue.map((el) => String(el))] : []),
|
|
204
|
+
]);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
class DataResourceKeyBuilder extends BaseKeyBuilder {
|
|
209
|
+
constructor(segments: KeySegment[]) {
|
|
210
|
+
super(segments);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
action(actionType: ParametrizedDataActions): ParamsKeyBuilder;
|
|
214
|
+
action(actionType: IdRequiredDataActions): DataIdRequiringKeyBuilder;
|
|
215
|
+
action(actionType: IdsRequiredDataActions): DataIdsRequiringKeyBuilder;
|
|
216
|
+
action(
|
|
217
|
+
actionType:
|
|
218
|
+
| ParametrizedDataActions
|
|
219
|
+
| IdRequiredDataActions
|
|
220
|
+
| IdsRequiredDataActions,
|
|
221
|
+
):
|
|
222
|
+
| ParamsKeyBuilder
|
|
223
|
+
| DataIdRequiringKeyBuilder
|
|
224
|
+
| DataIdsRequiringKeyBuilder {
|
|
225
|
+
if (actionType === "one") {
|
|
226
|
+
return new DataIdRequiringKeyBuilder([
|
|
227
|
+
...this.segments,
|
|
228
|
+
actionType,
|
|
229
|
+
]);
|
|
230
|
+
} else if (actionType === "many") {
|
|
231
|
+
return new DataIdsRequiringKeyBuilder([
|
|
232
|
+
...this.segments,
|
|
233
|
+
actionType,
|
|
234
|
+
]);
|
|
235
|
+
} else if (["list", "infinite"].includes(actionType)) {
|
|
236
|
+
return new ParamsKeyBuilder([...this.segments, actionType]);
|
|
237
|
+
} else {
|
|
238
|
+
throw new Error("Invalid action type");
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
class DataKeyBuilder extends BaseKeyBuilder {
|
|
244
|
+
constructor(segments: KeySegment[]) {
|
|
245
|
+
super(segments);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
resource(resourceName?: string) {
|
|
249
|
+
return new DataResourceKeyBuilder([...this.segments, resourceName]);
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
mutation(mutationName: DataMutationActions) {
|
|
253
|
+
return new ParamsKeyBuilder([
|
|
254
|
+
...(mutationName === "custom" ? this.segments : [this.segments[0]]),
|
|
255
|
+
mutationName,
|
|
256
|
+
]);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
class AuthKeyBuilder extends BaseKeyBuilder {
|
|
261
|
+
constructor(segments: KeySegment[]) {
|
|
262
|
+
super(segments);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
action(actionType: AuthActionType) {
|
|
266
|
+
return new ParamsKeyBuilder([...this.segments, actionType]);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
class AccessResourceKeyBuilder extends BaseKeyBuilder {
|
|
271
|
+
constructor(segments: KeySegment[]) {
|
|
272
|
+
super(segments);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
action(resourceName: string) {
|
|
276
|
+
return new ParamsKeyBuilder([...this.segments, resourceName]);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
class AccessKeyBuilder extends BaseKeyBuilder {
|
|
281
|
+
constructor(segments: KeySegment[]) {
|
|
282
|
+
super(segments);
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
resource(resourceName?: string) {
|
|
286
|
+
return new AccessResourceKeyBuilder([...this.segments, resourceName]);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
class AuditActionKeyBuilder extends BaseKeyBuilder {
|
|
291
|
+
constructor(segments: KeySegment[]) {
|
|
292
|
+
super(segments);
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
action(actionType: Extract<AuditActionType, "list">) {
|
|
296
|
+
return new ParamsKeyBuilder([...this.segments, actionType]);
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
class AuditKeyBuilder extends BaseKeyBuilder {
|
|
301
|
+
constructor(segments: KeySegment[]) {
|
|
302
|
+
super(segments);
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
resource(resourceName?: string) {
|
|
306
|
+
return new AuditActionKeyBuilder([...this.segments, resourceName]);
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
action(actionType: Extract<AuditActionType, "rename" | "log">) {
|
|
310
|
+
return new ParamsKeyBuilder([...this.segments, actionType]);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
export class KeyBuilder extends BaseKeyBuilder {
|
|
315
|
+
constructor(segments: KeySegment[]) {
|
|
316
|
+
super(segments);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
data(name?: string) {
|
|
320
|
+
return new DataKeyBuilder(["data", name || "default"]);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
auth() {
|
|
324
|
+
return new AuthKeyBuilder(["auth"]);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
access() {
|
|
328
|
+
return new AccessKeyBuilder(["access"]);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
audit() {
|
|
332
|
+
return new AuditKeyBuilder(["audit"]);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export const keys = () => new KeyBuilder([]);
|
|
@@ -3,7 +3,11 @@ import { QueryKey } from "@tanstack/react-query";
|
|
|
3
3
|
|
|
4
4
|
import { MetaQuery } from "src/interfaces";
|
|
5
5
|
import { pickNotDeprecated } from "../pickNotDeprecated";
|
|
6
|
+
import { keys as newKeys } from "../keys";
|
|
6
7
|
|
|
8
|
+
/**
|
|
9
|
+
* @deprecated `queryKeys` is deprecated. Please use `keys` instead.
|
|
10
|
+
*/
|
|
7
11
|
export const queryKeys = (
|
|
8
12
|
resource?: string,
|
|
9
13
|
dataProviderName?: string,
|
|
@@ -45,3 +49,67 @@ export const queryKeys = (
|
|
|
45
49
|
};
|
|
46
50
|
return keys;
|
|
47
51
|
};
|
|
52
|
+
|
|
53
|
+
export const queryKeysReplacement = (preferLegacyKeys?: boolean) => {
|
|
54
|
+
return (
|
|
55
|
+
resource?: string,
|
|
56
|
+
dataProviderName?: string,
|
|
57
|
+
meta?: MetaQuery,
|
|
58
|
+
/**
|
|
59
|
+
* @deprecated `metaData` is deprecated with refine@4, refine will pass `meta` instead, however, we still support `metaData` for backward compatibility.
|
|
60
|
+
*/
|
|
61
|
+
metaData?: MetaQuery | undefined,
|
|
62
|
+
): IQueryKeys => {
|
|
63
|
+
const providerName = dataProviderName || "default";
|
|
64
|
+
|
|
65
|
+
const keys: IQueryKeys = {
|
|
66
|
+
all: newKeys().data(providerName).get(preferLegacyKeys),
|
|
67
|
+
resourceAll: newKeys()
|
|
68
|
+
.data(dataProviderName)
|
|
69
|
+
.resource(resource ?? "")
|
|
70
|
+
.get(preferLegacyKeys),
|
|
71
|
+
list: (config) =>
|
|
72
|
+
newKeys()
|
|
73
|
+
.data(dataProviderName)
|
|
74
|
+
.resource(resource ?? "")
|
|
75
|
+
.action("list")
|
|
76
|
+
.params({
|
|
77
|
+
...config,
|
|
78
|
+
...(pickNotDeprecated(meta, metaData) || {}),
|
|
79
|
+
})
|
|
80
|
+
.get(preferLegacyKeys),
|
|
81
|
+
many: (ids) =>
|
|
82
|
+
newKeys()
|
|
83
|
+
.data(dataProviderName)
|
|
84
|
+
.resource(resource ?? "")
|
|
85
|
+
.action("many")
|
|
86
|
+
.ids(...(ids ?? []))
|
|
87
|
+
.params({
|
|
88
|
+
...(pickNotDeprecated(meta, metaData) || {}),
|
|
89
|
+
})
|
|
90
|
+
.get(preferLegacyKeys),
|
|
91
|
+
detail: (id) =>
|
|
92
|
+
newKeys()
|
|
93
|
+
.data(dataProviderName)
|
|
94
|
+
.resource(resource ?? "")
|
|
95
|
+
.action("one")
|
|
96
|
+
.id(id ?? "")
|
|
97
|
+
.params({
|
|
98
|
+
...(pickNotDeprecated(meta, metaData) || {}),
|
|
99
|
+
})
|
|
100
|
+
.get(preferLegacyKeys),
|
|
101
|
+
logList: (meta) =>
|
|
102
|
+
[
|
|
103
|
+
...newKeys()
|
|
104
|
+
.audit()
|
|
105
|
+
.resource(resource)
|
|
106
|
+
.action("list")
|
|
107
|
+
.params(meta)
|
|
108
|
+
.get(preferLegacyKeys),
|
|
109
|
+
metaData as QueryKey,
|
|
110
|
+
].filter((item) => item !== undefined),
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
return keys;
|
|
114
|
+
};
|
|
115
|
+
};
|
|
@@ -8,6 +8,7 @@ import { useContext } from "react";
|
|
|
8
8
|
import { AccessControlContext } from "@contexts/accessControl";
|
|
9
9
|
import { sanitizeResource } from "@definitions/helpers/sanitize-resource";
|
|
10
10
|
import { CanParams, CanReturnType } from "../../../interfaces";
|
|
11
|
+
import { useKeys } from "@hooks/useKeys";
|
|
11
12
|
|
|
12
13
|
export type UseCanProps = CanParams & {
|
|
13
14
|
/**
|
|
@@ -31,6 +32,7 @@ export const useCan = ({
|
|
|
31
32
|
queryOptions,
|
|
32
33
|
}: UseCanProps): UseQueryResult<CanReturnType> => {
|
|
33
34
|
const { can } = useContext(AccessControlContext);
|
|
35
|
+
const { keys, preferLegacyKeys } = useKeys();
|
|
34
36
|
|
|
35
37
|
/**
|
|
36
38
|
* Since `react-query` stringifies the query keys, it will throw an error for a circular dependency if we include `React.ReactNode` elements inside the keys.
|
|
@@ -43,15 +45,15 @@ export const useCan = ({
|
|
|
43
45
|
|
|
44
46
|
/* eslint-enable @typescript-eslint/no-unused-vars */
|
|
45
47
|
const queryResponse = useQuery<CanReturnType>(
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
keys()
|
|
49
|
+
.access()
|
|
50
|
+
.resource(resource)
|
|
51
|
+
.action(action)
|
|
52
|
+
.params({
|
|
51
53
|
params: { ...paramsRest, resource: sanitizedResource },
|
|
52
54
|
enabled: queryOptions?.enabled,
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
+
})
|
|
56
|
+
.get(preferLegacyKeys),
|
|
55
57
|
// Enabled check for `can` is enough to be sure that it's defined in the query function but TS is not smart enough to know that.
|
|
56
58
|
() =>
|
|
57
59
|
can?.({
|
|
@@ -10,13 +10,10 @@ import { AuditLogContext } from "@contexts/auditLog";
|
|
|
10
10
|
import { ResourceContext } from "@contexts/resource";
|
|
11
11
|
import { useGetIdentity } from "@hooks/auth";
|
|
12
12
|
import { BaseKey, LogParams } from "../../../interfaces";
|
|
13
|
-
import {
|
|
14
|
-
hasPermission,
|
|
15
|
-
pickNotDeprecated,
|
|
16
|
-
queryKeys,
|
|
17
|
-
} from "@definitions/helpers";
|
|
13
|
+
import { hasPermission, pickNotDeprecated } from "@definitions/helpers";
|
|
18
14
|
import { pickResource } from "@definitions/helpers/pick-resource";
|
|
19
15
|
import { useActiveAuthProvider } from "@definitions/helpers";
|
|
16
|
+
import { useKeys } from "@hooks/useKeys";
|
|
20
17
|
|
|
21
18
|
type LogRenameData =
|
|
22
19
|
| {
|
|
@@ -72,6 +69,7 @@ export const useLog = <
|
|
|
72
69
|
> => {
|
|
73
70
|
const queryClient = useQueryClient();
|
|
74
71
|
const auditLogContext = useContext(AuditLogContext);
|
|
72
|
+
const { keys, preferLegacyKeys } = useKeys();
|
|
75
73
|
|
|
76
74
|
const authProvider = useActiveAuthProvider();
|
|
77
75
|
|
|
@@ -112,7 +110,10 @@ export const useLog = <
|
|
|
112
110
|
author: identityData ?? authorData?.data,
|
|
113
111
|
});
|
|
114
112
|
},
|
|
115
|
-
|
|
113
|
+
{
|
|
114
|
+
mutationKey: keys().audit().action("log").get(),
|
|
115
|
+
...logMutationOptions,
|
|
116
|
+
},
|
|
116
117
|
);
|
|
117
118
|
|
|
118
119
|
const rename = useMutation<
|
|
@@ -127,10 +128,16 @@ export const useLog = <
|
|
|
127
128
|
{
|
|
128
129
|
onSuccess: (data) => {
|
|
129
130
|
if (data?.resource) {
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
queryClient.invalidateQueries(
|
|
132
|
+
keys()
|
|
133
|
+
.audit()
|
|
134
|
+
.resource(data?.resource ?? "")
|
|
135
|
+
.action("list")
|
|
136
|
+
.get(preferLegacyKeys),
|
|
137
|
+
);
|
|
132
138
|
}
|
|
133
139
|
},
|
|
140
|
+
mutationKey: keys().audit().action("rename").get(),
|
|
134
141
|
...renameMutationOptions,
|
|
135
142
|
},
|
|
136
143
|
);
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
} from "@tanstack/react-query";
|
|
7
7
|
|
|
8
8
|
import { AuditLogContext } from "@contexts/auditLog";
|
|
9
|
-
import { queryKeys } from "@definitions/helpers";
|
|
10
9
|
import { HttpError, MetaQuery } from "../../../interfaces";
|
|
10
|
+
import { useKeys } from "@hooks/useKeys";
|
|
11
11
|
|
|
12
12
|
export type UseLogProps<TQueryFnData, TError, TData> = {
|
|
13
13
|
resource: string;
|
|
@@ -41,11 +41,15 @@ export const useLogList = <
|
|
|
41
41
|
queryOptions,
|
|
42
42
|
}: UseLogProps<TQueryFnData, TError, TData>): UseQueryResult<TData> => {
|
|
43
43
|
const { get } = useContext(AuditLogContext);
|
|
44
|
-
|
|
45
|
-
const queryKey = queryKeys(resource, undefined, metaData);
|
|
44
|
+
const { keys, preferLegacyKeys } = useKeys();
|
|
46
45
|
|
|
47
46
|
const queryResponse = useQuery<TQueryFnData, TError, TData>(
|
|
48
|
-
|
|
47
|
+
keys()
|
|
48
|
+
.audit()
|
|
49
|
+
.resource(resource)
|
|
50
|
+
.action("list")
|
|
51
|
+
.params(meta)
|
|
52
|
+
.get(preferLegacyKeys),
|
|
49
53
|
() =>
|
|
50
54
|
get?.({
|
|
51
55
|
resource,
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
OpenNotificationParams,
|
|
14
14
|
TForgotPasswordData,
|
|
15
15
|
} from "../../../interfaces";
|
|
16
|
+
import { useKeys } from "@hooks/useKeys";
|
|
16
17
|
|
|
17
18
|
export type UseForgotPasswordLegacyProps<TVariables> = {
|
|
18
19
|
v3LegacyAuthProviderCompatible: true;
|
|
@@ -112,35 +113,40 @@ export function useForgotPassword<TVariables = {}>({
|
|
|
112
113
|
const { forgotPassword: forgotPasswordFromContext } =
|
|
113
114
|
useAuthBindingsContext();
|
|
114
115
|
const { close, open } = useNotification();
|
|
116
|
+
const { keys, preferLegacyKeys } = useKeys();
|
|
115
117
|
|
|
116
118
|
const mutation = useMutation<
|
|
117
119
|
AuthActionResponse,
|
|
118
120
|
Error | RefineError,
|
|
119
121
|
TVariables,
|
|
120
122
|
unknown
|
|
121
|
-
>(
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
123
|
+
>(
|
|
124
|
+
keys().auth().action("forgotPassword").get(preferLegacyKeys),
|
|
125
|
+
forgotPasswordFromContext,
|
|
126
|
+
{
|
|
127
|
+
onSuccess: ({ success, redirectTo, error }) => {
|
|
128
|
+
if (success) {
|
|
129
|
+
close?.("forgot-password-error");
|
|
130
|
+
}
|
|
126
131
|
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
132
|
+
if (error || !success) {
|
|
133
|
+
open?.(buildNotification(error));
|
|
134
|
+
}
|
|
130
135
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
if (redirectTo) {
|
|
137
|
+
if (routerType === "legacy") {
|
|
138
|
+
replace(redirectTo);
|
|
139
|
+
} else {
|
|
140
|
+
go({ to: redirectTo, type: "replace" });
|
|
141
|
+
}
|
|
136
142
|
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
143
|
+
},
|
|
144
|
+
onError: (error: any) => {
|
|
145
|
+
open?.(buildNotification(error));
|
|
146
|
+
},
|
|
147
|
+
...(v3LegacyAuthProviderCompatible === true ? {} : mutationOptions),
|
|
141
148
|
},
|
|
142
|
-
|
|
143
|
-
});
|
|
149
|
+
);
|
|
144
150
|
|
|
145
151
|
const v3LegacyAuthProviderCompatibleMutation = useMutation<
|
|
146
152
|
TForgotPasswordData,
|
|
@@ -148,7 +154,10 @@ export function useForgotPassword<TVariables = {}>({
|
|
|
148
154
|
TVariables,
|
|
149
155
|
unknown
|
|
150
156
|
>(
|
|
151
|
-
[
|
|
157
|
+
[
|
|
158
|
+
...keys().auth().action("forgotPassword").get(preferLegacyKeys),
|
|
159
|
+
"v3LegacyAuthProviderCompatible",
|
|
160
|
+
],
|
|
152
161
|
v3LegacyAuthProviderCompatibleForgotPasswordFromContext,
|
|
153
162
|
{
|
|
154
163
|
onSuccess: (redirectPathFromAuth) => {
|