@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.
Files changed (85) hide show
  1. package/CHANGELOG.md +13 -1
  2. package/dist/contexts/refine/IRefineContext.d.ts +2 -0
  3. package/dist/contexts/refine/IRefineContext.d.ts.map +1 -1
  4. package/dist/definitions/helpers/handleRefineOptions/index.d.ts.map +1 -1
  5. package/dist/definitions/helpers/index.d.ts +3 -1
  6. package/dist/definitions/helpers/index.d.ts.map +1 -1
  7. package/dist/definitions/helpers/keys/index.d.ts +75 -0
  8. package/dist/definitions/helpers/keys/index.d.ts.map +1 -0
  9. package/dist/definitions/helpers/queryKeys/index.d.ts +4 -0
  10. package/dist/definitions/helpers/queryKeys/index.d.ts.map +1 -1
  11. package/dist/esm/index.js +6 -6
  12. package/dist/esm/index.js.map +1 -1
  13. package/dist/hooks/accessControl/useCan/index.d.ts.map +1 -1
  14. package/dist/hooks/auditLog/useLog/index.d.ts.map +1 -1
  15. package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
  16. package/dist/hooks/auth/useForgotPassword/index.d.ts.map +1 -1
  17. package/dist/hooks/auth/useGetIdentity/index.d.ts.map +1 -1
  18. package/dist/hooks/auth/useInvalidateAuthStore/index.d.ts.map +1 -1
  19. package/dist/hooks/auth/useIsAuthenticated/index.d.ts.map +1 -1
  20. package/dist/hooks/auth/useLogin/index.d.ts.map +1 -1
  21. package/dist/hooks/auth/useLogout/index.d.ts.map +1 -1
  22. package/dist/hooks/auth/useOnError/index.d.ts.map +1 -1
  23. package/dist/hooks/auth/usePermissions/index.d.ts.map +1 -1
  24. package/dist/hooks/auth/useRegister/index.d.ts.map +1 -1
  25. package/dist/hooks/auth/useUpdatePassword/index.d.ts.map +1 -1
  26. package/dist/hooks/data/useCreate.d.ts.map +1 -1
  27. package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
  28. package/dist/hooks/data/useCustom.d.ts.map +1 -1
  29. package/dist/hooks/data/useCustomMutation.d.ts.map +1 -1
  30. package/dist/hooks/data/useDelete.d.ts.map +1 -1
  31. package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
  32. package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
  33. package/dist/hooks/data/useList.d.ts.map +1 -1
  34. package/dist/hooks/data/useMany.d.ts.map +1 -1
  35. package/dist/hooks/data/useOne.d.ts.map +1 -1
  36. package/dist/hooks/data/useUpdate.d.ts.map +1 -1
  37. package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
  38. package/dist/hooks/invalidate/index.d.ts.map +1 -1
  39. package/dist/hooks/live/useResourceSubscription/index.d.ts.map +1 -1
  40. package/dist/hooks/useKeys/index.d.ts +5 -0
  41. package/dist/hooks/useKeys/index.d.ts.map +1 -0
  42. package/dist/iife/index.js +6 -6
  43. package/dist/iife/index.js.map +1 -1
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +6 -6
  47. package/dist/index.js.map +1 -1
  48. package/dist/interfaces/mutationMode.d.ts +3 -0
  49. package/dist/interfaces/mutationMode.d.ts.map +1 -1
  50. package/package.json +1 -1
  51. package/src/contexts/refine/IRefineContext.ts +2 -0
  52. package/src/definitions/helpers/handleRefineOptions/index.ts +1 -0
  53. package/src/definitions/helpers/index.ts +3 -1
  54. package/src/definitions/helpers/keys/index.ts +336 -0
  55. package/src/definitions/helpers/queryKeys/index.ts +68 -0
  56. package/src/hooks/accessControl/useCan/index.ts +9 -7
  57. package/src/hooks/auditLog/useLog/index.ts +15 -8
  58. package/src/hooks/auditLog/useLogList/index.ts +8 -4
  59. package/src/hooks/auth/useForgotPassword/index.ts +29 -20
  60. package/src/hooks/auth/useGetIdentity/index.ts +7 -2
  61. package/src/hooks/auth/useInvalidateAuthStore/index.ts +11 -3
  62. package/src/hooks/auth/useIsAuthenticated/index.ts +11 -2
  63. package/src/hooks/auth/useLogin/index.ts +35 -26
  64. package/src/hooks/auth/useLogout/index.ts +7 -2
  65. package/src/hooks/auth/useOnError/index.ts +26 -16
  66. package/src/hooks/auth/usePermissions/index.ts +7 -2
  67. package/src/hooks/auth/useRegister/index.ts +34 -24
  68. package/src/hooks/auth/useUpdatePassword/index.ts +8 -2
  69. package/src/hooks/data/useCreate.ts +3 -0
  70. package/src/hooks/data/useCreateMany.ts +6 -0
  71. package/src/hooks/data/useCustom.ts +12 -7
  72. package/src/hooks/data/useCustomMutation.ts +6 -0
  73. package/src/hooks/data/useDelete.ts +24 -6
  74. package/src/hooks/data/useDeleteMany.ts +32 -7
  75. package/src/hooks/data/useInfiniteList.ts +21 -20
  76. package/src/hooks/data/useList.ts +21 -15
  77. package/src/hooks/data/useMany.ts +11 -3
  78. package/src/hooks/data/useOne.ts +11 -3
  79. package/src/hooks/data/useUpdate.ts +29 -7
  80. package/src/hooks/data/useUpdateMany.ts +31 -7
  81. package/src/hooks/invalidate/index.tsx +24 -10
  82. package/src/hooks/live/useResourceSubscription/index.ts +8 -3
  83. package/src/hooks/useKeys/index.tsx +13 -0
  84. package/src/index.tsx +2 -0
  85. package/src/interfaces/mutationMode.ts +3 -0
@@ -34,7 +34,7 @@ import {
34
34
  } from "@hooks";
35
35
  import { ActionTypes } from "@contexts/undoableQueue";
36
36
  import {
37
- queryKeys,
37
+ queryKeysReplacement,
38
38
  pickDataProvider,
39
39
  handleMultiple,
40
40
  pickNotDeprecated,
@@ -45,6 +45,7 @@ import {
45
45
  UseLoadingOvertimeOptionsProps,
46
46
  UseLoadingOvertimeReturnType,
47
47
  } from "../useLoadingOvertime";
48
+ import { useKeys } from "@hooks/useKeys";
48
49
 
49
50
  export type DeleteManyParams<TData, TError, TVariables> = {
50
51
  /**
@@ -164,6 +165,7 @@ export const useDeleteMany = <
164
165
  const {
165
166
  options: { textTransformers },
166
167
  } = useRefineContext();
168
+ const { keys, preferLegacyKeys } = useKeys();
167
169
 
168
170
  const mutation = useMutation<
169
171
  DeleteManyResponse<TData>,
@@ -271,17 +273,27 @@ export const useDeleteMany = <
271
273
 
272
274
  const preferredMeta = pickNotDeprecated(meta, metaData);
273
275
 
274
- const queryKey = queryKeys(
276
+ const queryKey = queryKeysReplacement(preferLegacyKeys)(
275
277
  identifier,
276
278
  pickDataProvider(identifier, dataProviderName, resources),
277
279
  preferredMeta,
278
280
  );
279
281
 
282
+ const resourceKeys = keys()
283
+ .data(
284
+ pickDataProvider(
285
+ identifier,
286
+ dataProviderName,
287
+ resources,
288
+ ),
289
+ )
290
+ .resource(identifier);
291
+
280
292
  const mutationModePropOrContext =
281
293
  mutationMode ?? mutationModeContext;
282
294
 
283
295
  await queryClient.cancelQueries(
284
- queryKey.resourceAll,
296
+ resourceKeys.get(preferLegacyKeys),
285
297
  undefined,
286
298
  {
287
299
  silent: true,
@@ -289,12 +301,17 @@ export const useDeleteMany = <
289
301
  );
290
302
 
291
303
  const previousQueries: PreviousQuery<TData>[] =
292
- queryClient.getQueriesData(queryKey.resourceAll);
304
+ queryClient.getQueriesData(
305
+ resourceKeys.get(preferLegacyKeys),
306
+ );
293
307
 
294
308
  if (mutationModePropOrContext !== "pessimistic") {
295
309
  // Set the previous queries to the new ones:
296
310
  queryClient.setQueriesData(
297
- queryKey.list(),
311
+ resourceKeys
312
+ .action("list")
313
+ .params(preferredMeta ?? {})
314
+ .get(preferLegacyKeys),
298
315
  (previous?: GetListResponse<TData> | null) => {
299
316
  if (!previous) {
300
317
  return null;
@@ -316,7 +333,7 @@ export const useDeleteMany = <
316
333
  );
317
334
 
318
335
  queryClient.setQueriesData(
319
- queryKey.many(),
336
+ resourceKeys.action("many").get(preferLegacyKeys),
320
337
  (previous?: GetListResponse<TData> | null) => {
321
338
  if (!previous) {
322
339
  return null;
@@ -342,7 +359,11 @@ export const useDeleteMany = <
342
359
 
343
360
  for (const id of ids) {
344
361
  queryClient.setQueriesData(
345
- queryKey.detail(id),
362
+ resourceKeys
363
+ .action("one")
364
+ .id(id)
365
+ .params(preferredMeta)
366
+ .get(preferLegacyKeys),
346
367
  (previous?: any | null) => {
347
368
  if (!previous || previous.data.id == id) {
348
369
  return null;
@@ -502,6 +523,10 @@ export const useDeleteMany = <
502
523
  });
503
524
  }
504
525
  },
526
+ mutationKey: keys()
527
+ .data()
528
+ .mutation("deleteMany")
529
+ .get(preferLegacyKeys),
505
530
  ...mutationOptions,
506
531
  },
507
532
  );
@@ -40,6 +40,7 @@ import {
40
40
  UseLoadingOvertimeOptionsProps,
41
41
  UseLoadingOvertimeReturnType,
42
42
  } from "../useLoadingOvertime";
43
+ import { useKeys } from "@hooks/useKeys";
43
44
 
44
45
  export interface UseInfiniteListConfig {
45
46
  pagination?: Pagination;
@@ -159,6 +160,7 @@ export const useInfiniteList = <
159
160
  });
160
161
  const handleNotification = useHandleNotification();
161
162
  const getMeta = useMeta();
163
+ const { keys, preferLegacyKeys } = useKeys();
162
164
 
163
165
  const pickedDataProvider = pickDataProvider(
164
166
  identifier,
@@ -194,13 +196,6 @@ export const useInfiniteList = <
194
196
  const isEnabled =
195
197
  queryOptions?.enabled === undefined || queryOptions?.enabled === true;
196
198
 
197
- const queryKey = queryKeys(
198
- identifier,
199
- pickedDataProvider,
200
- preferredMeta,
201
- preferredMeta,
202
- );
203
-
204
199
  const combinedMeta = getMeta({ resource, meta: preferredMeta });
205
200
 
206
201
  const { getList } = dataProvider(pickedDataProvider);
@@ -230,19 +225,25 @@ export const useInfiniteList = <
230
225
  TError,
231
226
  GetListResponse<TData>
232
227
  >(
233
- queryKey.list({
234
- filters: prefferedFilters,
235
- hasPagination: isServerPagination,
236
- ...(isServerPagination && {
237
- pagination: prefferedPagination,
238
- }),
239
- ...(sorters && {
240
- sorters,
241
- }),
242
- ...(config?.sort && {
243
- sort: config?.sort,
244
- }),
245
- }),
228
+ keys()
229
+ .data(pickedDataProvider)
230
+ .resource(identifier)
231
+ .action("infinite")
232
+ .params({
233
+ ...(preferredMeta || {}),
234
+ filters: prefferedFilters,
235
+ hasPagination: isServerPagination,
236
+ ...(isServerPagination && {
237
+ pagination: prefferedPagination,
238
+ }),
239
+ ...(sorters && {
240
+ sorters,
241
+ }),
242
+ ...(config?.sort && {
243
+ sort: config?.sort,
244
+ }),
245
+ })
246
+ .get(preferLegacyKeys),
246
247
  ({ queryKey, pageParam, signal }) => {
247
248
  const paginationProperties = {
248
249
  ...prefferedPagination,
@@ -36,6 +36,7 @@ import {
36
36
  UseLoadingOvertimeOptionsProps,
37
37
  UseLoadingOvertimeReturnType,
38
38
  } from "../useLoadingOvertime";
39
+ import { useKeys } from "@hooks/useKeys";
39
40
 
40
41
  export interface UseListConfig {
41
42
  pagination?: Pagination;
@@ -155,6 +156,7 @@ export const useList = <
155
156
  });
156
157
  const handleNotification = useHandleNotification();
157
158
  const getMeta = useMeta();
159
+ const { keys, preferLegacyKeys } = useKeys();
158
160
 
159
161
  const pickedDataProvider = pickDataProvider(
160
162
  identifier,
@@ -193,8 +195,6 @@ export const useList = <
193
195
  const isEnabled =
194
196
  queryOptions?.enabled === undefined || queryOptions?.enabled === true;
195
197
 
196
- const queryKey = queryKeys(identifier, pickedDataProvider, preferredMeta);
197
-
198
198
  const { getList } = dataProvider(pickedDataProvider);
199
199
 
200
200
  useResourceSubscription({
@@ -222,19 +222,25 @@ export const useList = <
222
222
  TError,
223
223
  GetListResponse<TData>
224
224
  >(
225
- queryKey.list({
226
- filters: prefferedFilters,
227
- hasPagination: isServerPagination,
228
- ...(isServerPagination && {
229
- pagination: prefferedPagination,
230
- }),
231
- ...(sorters && {
232
- sorters,
233
- }),
234
- ...(config?.sort && {
235
- sort: config?.sort,
236
- }),
237
- }),
225
+ keys()
226
+ .data(pickedDataProvider)
227
+ .resource(identifier ?? "")
228
+ .action("list")
229
+ .params({
230
+ ...(preferredMeta || {}),
231
+ filters: prefferedFilters,
232
+ hasPagination: isServerPagination,
233
+ ...(isServerPagination && {
234
+ pagination: prefferedPagination,
235
+ }),
236
+ ...(sorters && {
237
+ sorters,
238
+ }),
239
+ ...(config?.sort && {
240
+ sort: config?.sort,
241
+ }),
242
+ })
243
+ .get(preferLegacyKeys),
238
244
  ({ queryKey, pageParam, signal }) => {
239
245
  return getList<TQueryFnData>({
240
246
  resource: resource?.name ?? "",
@@ -34,6 +34,7 @@ import {
34
34
  UseLoadingOvertimeOptionsProps,
35
35
  UseLoadingOvertimeReturnType,
36
36
  } from "../useLoadingOvertime";
37
+ import { useKeys } from "@hooks/useKeys";
37
38
 
38
39
  export type UseManyProps<TQueryFnData, TError, TData> = {
39
40
  /**
@@ -114,6 +115,7 @@ export const useMany = <
114
115
  });
115
116
  const handleNotification = useHandleNotification();
116
117
  const getMeta = useMeta();
118
+ const { keys, preferLegacyKeys } = useKeys();
117
119
 
118
120
  const preferredMeta = pickNotDeprecated(meta, metaData);
119
121
  const pickedDataProvider = pickDataProvider(
@@ -124,8 +126,6 @@ export const useMany = <
124
126
  const isEnabled =
125
127
  queryOptions?.enabled === undefined || queryOptions?.enabled === true;
126
128
 
127
- const queryKey = queryKeys(identifier, pickedDataProvider, preferredMeta);
128
-
129
129
  const { getMany, getOne } = dataProvider(pickedDataProvider);
130
130
 
131
131
  const combinedMeta = getMeta({ resource, meta: preferredMeta });
@@ -151,7 +151,15 @@ export const useMany = <
151
151
  TError,
152
152
  GetManyResponse<TData>
153
153
  >(
154
- queryKey.many(ids),
154
+ keys()
155
+ .data(pickedDataProvider)
156
+ .resource(identifier)
157
+ .action("many")
158
+ .ids(...ids)
159
+ .params({
160
+ ...(preferredMeta || {}),
161
+ })
162
+ .get(preferLegacyKeys),
155
163
  ({ queryKey, pageParam, signal }) => {
156
164
  if (getMany) {
157
165
  return getMany({
@@ -34,6 +34,7 @@ import {
34
34
  UseLoadingOvertimeOptionsProps,
35
35
  UseLoadingOvertimeReturnType,
36
36
  } from "../useLoadingOvertime";
37
+ import { useKeys } from "@hooks/useKeys";
37
38
 
38
39
  export type UseOneProps<TQueryFnData, TError, TData> = {
39
40
  /**
@@ -119,6 +120,7 @@ export const useOne = <
119
120
  });
120
121
  const handleNotification = useHandleNotification();
121
122
  const getMeta = useMeta();
123
+ const { keys, preferLegacyKeys } = useKeys();
122
124
 
123
125
  const preferredMeta = pickNotDeprecated(meta, metaData);
124
126
  const pickedDataProvider = pickDataProvider(
@@ -127,8 +129,6 @@ export const useOne = <
127
129
  resources,
128
130
  );
129
131
 
130
- const queryKey = queryKeys(identifier, pickedDataProvider, preferredMeta);
131
-
132
132
  const { getOne } = dataProvider(pickedDataProvider);
133
133
 
134
134
  const combinedMeta = getMeta({ resource, meta: preferredMeta });
@@ -159,7 +159,15 @@ export const useOne = <
159
159
  TError,
160
160
  GetOneResponse<TData>
161
161
  >(
162
- queryKey.detail(id),
162
+ keys()
163
+ .data(pickedDataProvider)
164
+ .resource(identifier ?? "")
165
+ .action("one")
166
+ .id(id ?? "")
167
+ .params({
168
+ ...(preferredMeta || {}),
169
+ })
170
+ .get(preferLegacyKeys),
163
171
  ({ queryKey, pageParam, signal }) =>
164
172
  getOne<TQueryFnData>({
165
173
  resource: resource?.name ?? "",
@@ -34,7 +34,7 @@ import {
34
34
  useRefineContext,
35
35
  } from "@hooks";
36
36
  import {
37
- queryKeys,
37
+ queryKeysReplacement,
38
38
  pickDataProvider,
39
39
  pickNotDeprecated,
40
40
  useActiveAuthProvider,
@@ -44,6 +44,7 @@ import {
44
44
  UseLoadingOvertimeOptionsProps,
45
45
  UseLoadingOvertimeReturnType,
46
46
  } from "../useLoadingOvertime";
47
+ import { useKeys } from "@hooks/useKeys";
47
48
 
48
49
  export type UpdateParams<TData, TError, TVariables> = {
49
50
  /**
@@ -168,6 +169,7 @@ export const useUpdate = <
168
169
  const {
169
170
  options: { textTransformers },
170
171
  } = useRefineContext();
172
+ const { keys, preferLegacyKeys } = useKeys();
171
173
 
172
174
  const mutation = useMutation<
173
175
  UpdateResponse<TData>,
@@ -268,20 +270,32 @@ export const useUpdate = <
268
270
 
269
271
  const preferredMeta = pickNotDeprecated(meta, metaData);
270
272
 
271
- const queryKey = queryKeys(
273
+ const queryKey = queryKeysReplacement(preferLegacyKeys)(
272
274
  identifier,
273
275
  pickDataProvider(identifier, dataProviderName, resources),
274
276
  preferredMeta,
275
277
  );
276
278
 
279
+ const resourceKeys = keys()
280
+ .data(
281
+ pickDataProvider(
282
+ identifier,
283
+ dataProviderName,
284
+ resources,
285
+ ),
286
+ )
287
+ .resource(identifier);
288
+
277
289
  const previousQueries: PreviousQuery<TData>[] =
278
- queryClient.getQueriesData(queryKey.resourceAll);
290
+ queryClient.getQueriesData(
291
+ resourceKeys.get(preferLegacyKeys),
292
+ );
279
293
 
280
294
  const mutationModePropOrContext =
281
295
  mutationMode ?? mutationModeContext;
282
296
 
283
297
  await queryClient.cancelQueries(
284
- queryKey.resourceAll,
298
+ resourceKeys.get(preferLegacyKeys),
285
299
  undefined,
286
300
  {
287
301
  silent: true,
@@ -291,7 +305,10 @@ export const useUpdate = <
291
305
  if (mutationModePropOrContext !== "pessimistic") {
292
306
  // Set the previous queries to the new ones:
293
307
  queryClient.setQueriesData(
294
- queryKey.list(),
308
+ resourceKeys
309
+ .action("list")
310
+ .params(preferredMeta ?? {})
311
+ .get(preferLegacyKeys),
295
312
  (previous?: GetListResponse<TData> | null) => {
296
313
  if (!previous) {
297
314
  return null;
@@ -315,7 +332,7 @@ export const useUpdate = <
315
332
  );
316
333
 
317
334
  queryClient.setQueriesData(
318
- queryKey.many(),
335
+ resourceKeys.action("many").get(preferLegacyKeys),
319
336
  (previous?: GetListResponse<TData> | null) => {
320
337
  if (!previous) {
321
338
  return null;
@@ -339,7 +356,11 @@ export const useUpdate = <
339
356
  );
340
357
 
341
358
  queryClient.setQueriesData(
342
- queryKey.detail(id),
359
+ resourceKeys
360
+ .action("one")
361
+ .id(id)
362
+ .params(preferredMeta ?? {})
363
+ .get(preferLegacyKeys),
343
364
  (previous?: GetListResponse<TData> | null) => {
344
365
  if (!previous) {
345
366
  return null;
@@ -516,6 +537,7 @@ export const useUpdate = <
516
537
  });
517
538
  }
518
539
  },
540
+ mutationKey: keys().data().mutation("update").get(preferLegacyKeys),
519
541
  ...mutationOptions,
520
542
  },
521
543
  );
@@ -34,7 +34,7 @@ import {
34
34
  IQueryKeys,
35
35
  } from "../../interfaces";
36
36
  import {
37
- queryKeys,
37
+ queryKeysReplacement,
38
38
  pickDataProvider,
39
39
  handleMultiple,
40
40
  pickNotDeprecated,
@@ -45,6 +45,7 @@ import {
45
45
  UseLoadingOvertimeOptionsProps,
46
46
  UseLoadingOvertimeReturnType,
47
47
  } from "../useLoadingOvertime";
48
+ import { useKeys } from "@hooks/useKeys";
48
49
 
49
50
  type UpdateManyParams<TData, TError, TVariables> = {
50
51
  /**
@@ -168,6 +169,7 @@ export const useUpdateMany = <
168
169
  const {
169
170
  options: { textTransformers },
170
171
  } = useRefineContext();
172
+ const { keys, preferLegacyKeys } = useKeys();
171
173
 
172
174
  const mutation = useMutation<
173
175
  UpdateManyResponse<TData>,
@@ -275,17 +277,27 @@ export const useUpdateMany = <
275
277
  }) => {
276
278
  const { identifier } = select(resourceName);
277
279
 
278
- const queryKey = queryKeys(
280
+ const queryKey = queryKeysReplacement(preferLegacyKeys)(
279
281
  identifier,
280
282
  pickDataProvider(identifier, dataProviderName, resources),
281
283
  pickNotDeprecated(meta, metaData),
282
284
  );
283
285
 
286
+ const resourceKeys = keys()
287
+ .data(
288
+ pickDataProvider(
289
+ identifier,
290
+ dataProviderName,
291
+ resources,
292
+ ),
293
+ )
294
+ .resource(identifier);
295
+
284
296
  const mutationModePropOrContext =
285
297
  mutationMode ?? mutationModeContext;
286
298
 
287
299
  await queryClient.cancelQueries(
288
- queryKey.resourceAll,
300
+ resourceKeys.get(preferLegacyKeys),
289
301
  undefined,
290
302
  {
291
303
  silent: true,
@@ -294,12 +306,15 @@ export const useUpdateMany = <
294
306
 
295
307
  const previousQueries = queryClient.getQueriesData<
296
308
  QueryResponse<TData>
297
- >(queryKey.resourceAll);
309
+ >(resourceKeys.get(preferLegacyKeys));
298
310
 
299
311
  if (mutationModePropOrContext !== "pessimistic") {
300
312
  // Set the previous queries to the new ones:
301
313
  queryClient.setQueriesData(
302
- queryKey.list(),
314
+ resourceKeys
315
+ .action("list")
316
+ .params(pickNotDeprecated(meta, metaData) ?? {})
317
+ .get(preferLegacyKeys),
303
318
  (previous?: GetListResponse<TData> | null) => {
304
319
  if (!previous) {
305
320
  return null;
@@ -330,7 +345,7 @@ export const useUpdateMany = <
330
345
  );
331
346
 
332
347
  queryClient.setQueriesData(
333
- queryKey.many(),
348
+ resourceKeys.action("many").get(preferLegacyKeys),
334
349
  (previous?: GetListResponse<TData> | null) => {
335
350
  if (!previous) {
336
351
  return null;
@@ -357,9 +372,14 @@ export const useUpdateMany = <
357
372
  };
358
373
  },
359
374
  );
375
+
360
376
  for (const id of ids) {
361
377
  queryClient.setQueriesData(
362
- queryKey.detail(id),
378
+ resourceKeys
379
+ .action("one")
380
+ .id(id)
381
+ .params(pickNotDeprecated(meta, metaData))
382
+ .get(preferLegacyKeys),
363
383
  (previous?: GetListResponse<TData> | null) => {
364
384
  if (!previous) {
365
385
  return null;
@@ -556,6 +576,10 @@ export const useUpdateMany = <
556
576
  });
557
577
  }
558
578
  },
579
+ mutationKey: keys()
580
+ .data()
581
+ .mutation("updateMany")
582
+ .get(preferLegacyKeys),
559
583
  ...mutationOptions,
560
584
  },
561
585
  );
@@ -2,8 +2,9 @@ import { useCallback } from "react";
2
2
  import { useQueryClient } from "@tanstack/react-query";
3
3
 
4
4
  import { useResource } from "@hooks/resource";
5
- import { queryKeys, pickDataProvider } from "@definitions";
5
+ import { pickDataProvider } from "@definitions";
6
6
  import { BaseKey, IQueryKeys } from "../../interfaces";
7
+ import { useKeys } from "@hooks/useKeys";
7
8
 
8
9
  export type UseInvalidateProp = {
9
10
  resource?: string;
@@ -15,6 +16,7 @@ export type UseInvalidateProp = {
15
16
  export const useInvalidate = (): ((props: UseInvalidateProp) => void) => {
16
17
  const { resources } = useResource();
17
18
  const queryClient = useQueryClient();
19
+ const { keys, preferLegacyKeys } = useKeys();
18
20
 
19
21
  const invalidate = useCallback(
20
22
  ({
@@ -26,28 +28,40 @@ export const useInvalidate = (): ((props: UseInvalidateProp) => void) => {
26
28
  if (invalidates === false) {
27
29
  return;
28
30
  }
29
- const queryKey = queryKeys(
30
- resource,
31
- pickDataProvider(resource, dataProviderName, resources),
32
- );
31
+ const dp = pickDataProvider(resource, dataProviderName, resources);
32
+
33
+ const queryKey = keys()
34
+ .data(dp)
35
+ .resource(resource ?? "");
33
36
 
34
37
  invalidates.forEach((key) => {
35
38
  switch (key) {
36
39
  case "all":
37
- queryClient.invalidateQueries(queryKey.all);
40
+ queryClient.invalidateQueries(
41
+ keys().data(dp).get(preferLegacyKeys),
42
+ );
38
43
  break;
39
44
  case "list":
40
- queryClient.invalidateQueries(queryKey.list());
45
+ queryClient.invalidateQueries(
46
+ queryKey.action("list").get(preferLegacyKeys),
47
+ );
41
48
  break;
42
49
  case "many":
43
- queryClient.invalidateQueries(queryKey.many());
50
+ queryClient.invalidateQueries(
51
+ queryKey.action("many").get(preferLegacyKeys),
52
+ );
44
53
  break;
45
54
  case "resourceAll":
46
- queryClient.invalidateQueries(queryKey.resourceAll);
55
+ queryClient.invalidateQueries(
56
+ queryKey.get(preferLegacyKeys),
57
+ );
47
58
  break;
48
59
  case "detail":
49
60
  queryClient.invalidateQueries(
50
- queryKey.detail(id || ""),
61
+ queryKey
62
+ .action("one")
63
+ .id(id || "")
64
+ .get(preferLegacyKeys),
51
65
  );
52
66
  break;
53
67
  default:
@@ -13,8 +13,8 @@ import {
13
13
  } from "../../../interfaces";
14
14
  import { LiveContext } from "@contexts/live";
15
15
  import { RefineContext } from "@contexts/refine";
16
- import { queryKeys } from "@definitions";
17
16
  import { useResource } from "@hooks/resource";
17
+ import { useKeys } from "@hooks/useKeys";
18
18
 
19
19
  export type UseResourceSubscriptionProps = {
20
20
  channel: string;
@@ -61,7 +61,7 @@ export const useResourceSubscription = ({
61
61
  const queryClient = useQueryClient();
62
62
 
63
63
  const { resource, identifier } = useResource(resourceFromProp);
64
- const queryKey = queryKeys(identifier);
64
+ const { keys, preferLegacyKeys } = useKeys();
65
65
 
66
66
  const liveDataContext = useContext<ILiveContext>(LiveContext);
67
67
  const {
@@ -84,7 +84,12 @@ export const useResourceSubscription = ({
84
84
  types,
85
85
  callback: (event) => {
86
86
  if (liveMode === "auto") {
87
- queryClient.invalidateQueries(queryKey.resourceAll);
87
+ queryClient.invalidateQueries(
88
+ keys()
89
+ .data(resource?.meta?.dataProviderName)
90
+ .resource(identifier)
91
+ .get(preferLegacyKeys),
92
+ );
88
93
  }
89
94
 
90
95
  onLiveEvent?.(event);
@@ -0,0 +1,13 @@
1
+ import { useRefineContext } from "..";
2
+ import { keys } from "@definitions/index";
3
+
4
+ export const useKeys = () => {
5
+ const {
6
+ options: { useNewQueryKeys },
7
+ } = useRefineContext();
8
+
9
+ return {
10
+ keys,
11
+ preferLegacyKeys: !useNewQueryKeys,
12
+ };
13
+ };
package/src/index.tsx CHANGED
@@ -119,6 +119,8 @@ export {
119
119
  useUserFriendlyName,
120
120
  queryKeys,
121
121
  pickDataProvider,
122
+ keys,
123
+ KeyBuilder,
122
124
  } from "./definitions/helpers";
123
125
  export { file2Base64 } from "./definitions/upload";
124
126
  export { generateDefaultDocumentTitle } from "./definitions";
@@ -16,6 +16,9 @@ export type PreviousQuery<TData> = [QueryKey, TData | unknown];
16
16
 
17
17
  export type PrevContext<TData> = {
18
18
  previousQueries: PreviousQuery<TData>[];
19
+ /**
20
+ * @deprecated `QueryKeys` is deprecated in favor of `keys`. Please use `keys` instead to construct query keys for queries and mutations.
21
+ */
19
22
  queryKey: IQueryKeys;
20
23
  };
21
24