@refinedev/core 4.46.1 → 4.46.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.
Files changed (51) hide show
  1. package/CHANGELOG.md +69 -0
  2. package/dist/definitions/helpers/flatten-object-keys/index.d.ts.map +1 -1
  3. package/dist/esm/index.js +6 -6
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/hooks/accessControl/useCan/index.d.ts.map +1 -1
  6. package/dist/hooks/auditLog/useLogList/index.d.ts.map +1 -1
  7. package/dist/hooks/auth/useOnError/index.d.ts.map +1 -1
  8. package/dist/hooks/data/useCreate.d.ts.map +1 -1
  9. package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
  10. package/dist/hooks/data/useDelete.d.ts.map +1 -1
  11. package/dist/hooks/data/useDeleteMany.d.ts.map +1 -1
  12. package/dist/hooks/data/useInfiniteList.d.ts.map +1 -1
  13. package/dist/hooks/data/useList.d.ts.map +1 -1
  14. package/dist/hooks/data/useMany.d.ts.map +1 -1
  15. package/dist/hooks/data/useOne.d.ts.map +1 -1
  16. package/dist/hooks/data/useUpdate.d.ts.map +1 -1
  17. package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
  18. package/dist/hooks/router/use-go/index.d.ts +2 -0
  19. package/dist/hooks/router/use-go/index.d.ts.map +1 -1
  20. package/dist/iife/index.js +6 -6
  21. package/dist/iife/index.js.map +1 -1
  22. package/dist/index.js +6 -6
  23. package/dist/index.js.map +1 -1
  24. package/dist/interfaces/auth.d.ts +6 -6
  25. package/dist/interfaces/auth.d.ts.map +1 -1
  26. package/package.json +1 -1
  27. package/src/definitions/helpers/flatten-object-keys/index.ts +2 -0
  28. package/src/hooks/accessControl/useCan/index.ts +10 -12
  29. package/src/hooks/auditLog/useLogList/index.ts +10 -12
  30. package/src/hooks/auth/useForgotPassword/index.ts +51 -54
  31. package/src/hooks/auth/useGetIdentity/index.ts +23 -26
  32. package/src/hooks/auth/useIsAuthenticated/index.ts +20 -20
  33. package/src/hooks/auth/useLogin/index.ts +33 -35
  34. package/src/hooks/auth/useLogout/index.ts +32 -34
  35. package/src/hooks/auth/useOnError/index.ts +29 -33
  36. package/src/hooks/auth/usePermissions/index.ts +19 -22
  37. package/src/hooks/auth/useRegister/index.ts +60 -66
  38. package/src/hooks/auth/useUpdatePassword/index.ts +51 -54
  39. package/src/hooks/data/useCreate.ts +115 -117
  40. package/src/hooks/data/useCreateMany.ts +113 -118
  41. package/src/hooks/data/useDelete.ts +212 -227
  42. package/src/hooks/data/useDeleteMany.ts +230 -248
  43. package/src/hooks/data/useInfiniteList.ts +36 -42
  44. package/src/hooks/data/useList.ts +56 -62
  45. package/src/hooks/data/useMany.ts +36 -37
  46. package/src/hooks/data/useOne.ts +54 -55
  47. package/src/hooks/data/useUpdate.ts +288 -315
  48. package/src/hooks/data/useUpdateMany.ts +294 -325
  49. package/src/hooks/menu/useMenu.tsx +1 -1
  50. package/src/hooks/router/use-go/index.tsx +3 -0
  51. package/src/interfaces/auth.tsx +6 -6
@@ -173,8 +173,8 @@ export const useDeleteMany = <
173
173
  TError,
174
174
  DeleteManyParams<TData, TError, TVariables>,
175
175
  DeleteContext<TData>
176
- >(
177
- ({
176
+ >({
177
+ mutationFn: ({
178
178
  resource: resourceName,
179
179
  ids,
180
180
  mutationMode,
@@ -261,293 +261,275 @@ export const useDeleteMany = <
261
261
  );
262
262
  return updatePromise;
263
263
  },
264
- {
265
- onMutate: async ({
266
- ids,
267
- resource: resourceName,
268
- mutationMode,
269
- dataProviderName,
270
- meta,
271
- metaData,
272
- }) => {
273
- const { identifier } = select(resourceName);
264
+ onMutate: async ({
265
+ ids,
266
+ resource: resourceName,
267
+ mutationMode,
268
+ dataProviderName,
269
+ meta,
270
+ metaData,
271
+ }) => {
272
+ const { identifier } = select(resourceName);
274
273
 
275
- const {
276
- gqlMutation: _,
277
- gqlQuery: __,
278
- ...preferredMeta
279
- } = pickNotDeprecated(meta, metaData) ?? {};
274
+ const {
275
+ gqlMutation: _,
276
+ gqlQuery: __,
277
+ ...preferredMeta
278
+ } = pickNotDeprecated(meta, metaData) ?? {};
280
279
 
281
- const queryKey = queryKeysReplacement(preferLegacyKeys)(
282
- identifier,
283
- pickDataProvider(identifier, dataProviderName, resources),
284
- preferredMeta,
285
- );
280
+ const queryKey = queryKeysReplacement(preferLegacyKeys)(
281
+ identifier,
282
+ pickDataProvider(identifier, dataProviderName, resources),
283
+ preferredMeta,
284
+ );
286
285
 
287
- const resourceKeys = keys()
288
- .data(
289
- pickDataProvider(
290
- identifier,
291
- dataProviderName,
292
- resources,
293
- ),
294
- )
295
- .resource(identifier);
286
+ const resourceKeys = keys()
287
+ .data(pickDataProvider(identifier, dataProviderName, resources))
288
+ .resource(identifier);
296
289
 
297
- const mutationModePropOrContext =
298
- mutationMode ?? mutationModeContext;
290
+ const mutationModePropOrContext =
291
+ mutationMode ?? mutationModeContext;
299
292
 
300
- await queryClient.cancelQueries(
301
- resourceKeys.get(preferLegacyKeys),
302
- undefined,
303
- {
304
- silent: true,
293
+ await queryClient.cancelQueries(
294
+ resourceKeys.get(preferLegacyKeys),
295
+ undefined,
296
+ {
297
+ silent: true,
298
+ },
299
+ );
300
+
301
+ const previousQueries: PreviousQuery<TData>[] =
302
+ queryClient.getQueriesData(resourceKeys.get(preferLegacyKeys));
303
+
304
+ if (mutationModePropOrContext !== "pessimistic") {
305
+ // Set the previous queries to the new ones:
306
+ queryClient.setQueriesData(
307
+ resourceKeys
308
+ .action("list")
309
+ .params(preferredMeta ?? {})
310
+ .get(preferLegacyKeys),
311
+ (previous?: GetListResponse<TData> | null) => {
312
+ if (!previous) {
313
+ return null;
314
+ }
315
+
316
+ const data = previous.data.filter(
317
+ (item) =>
318
+ item.id &&
319
+ !ids.map(String).includes(item.id.toString()),
320
+ );
321
+
322
+ return {
323
+ data,
324
+ total: previous.total - 1,
325
+ };
305
326
  },
306
327
  );
307
328
 
308
- const previousQueries: PreviousQuery<TData>[] =
309
- queryClient.getQueriesData(
310
- resourceKeys.get(preferLegacyKeys),
311
- );
329
+ queryClient.setQueriesData(
330
+ resourceKeys.action("many").get(preferLegacyKeys),
331
+ (previous?: GetListResponse<TData> | null) => {
332
+ if (!previous) {
333
+ return null;
334
+ }
335
+
336
+ const data = previous.data.filter((record: TData) => {
337
+ if (record.id) {
338
+ return !ids
339
+ .map(String)
340
+ .includes(record.id.toString());
341
+ }
342
+ return false;
343
+ });
344
+
345
+ return {
346
+ ...previous,
347
+ data,
348
+ };
349
+ },
350
+ );
312
351
 
313
- if (mutationModePropOrContext !== "pessimistic") {
314
- // Set the previous queries to the new ones:
352
+ for (const id of ids) {
315
353
  queryClient.setQueriesData(
316
354
  resourceKeys
317
- .action("list")
318
- .params(preferredMeta ?? {})
355
+ .action("one")
356
+ .id(id)
357
+ .params(preferredMeta)
319
358
  .get(preferLegacyKeys),
320
- (previous?: GetListResponse<TData> | null) => {
321
- if (!previous) {
359
+ (previous?: any | null) => {
360
+ if (!previous || previous.data.id == id) {
322
361
  return null;
323
362
  }
324
-
325
- const data = previous.data.filter(
326
- (item) =>
327
- item.id &&
328
- !ids
329
- .map(String)
330
- .includes(item.id.toString()),
331
- );
332
-
333
363
  return {
334
- data,
335
- total: previous.total - 1,
364
+ ...previous,
336
365
  };
337
366
  },
338
367
  );
368
+ }
369
+ }
339
370
 
340
- queryClient.setQueriesData(
341
- resourceKeys.action("many").get(preferLegacyKeys),
342
- (previous?: GetListResponse<TData> | null) => {
343
- if (!previous) {
344
- return null;
345
- }
371
+ return {
372
+ previousQueries,
373
+ queryKey,
374
+ };
375
+ },
376
+ // Always refetch after error or success:
377
+ onSettled: (
378
+ _data,
379
+ _error,
380
+ {
381
+ resource: resourceName,
382
+ ids,
383
+ dataProviderName,
384
+ invalidates = ["list", "many"],
385
+ },
386
+ ) => {
387
+ const { identifier } = select(resourceName);
346
388
 
347
- const data = previous.data.filter(
348
- (record: TData) => {
349
- if (record.id) {
350
- return !ids
351
- .map(String)
352
- .includes(record.id.toString());
353
- }
354
- return false;
355
- },
356
- );
389
+ // invalidate the cache for the list and many queries:
390
+ invalidateStore({
391
+ resource: identifier,
392
+ dataProviderName: pickDataProvider(
393
+ identifier,
394
+ dataProviderName,
395
+ resources,
396
+ ),
397
+ invalidates,
398
+ });
357
399
 
358
- return {
359
- ...previous,
360
- data,
361
- };
362
- },
363
- );
400
+ notificationDispatch({
401
+ type: ActionTypes.REMOVE,
402
+ payload: { id: ids, resource: identifier },
403
+ });
404
+ },
405
+ onSuccess: (
406
+ _data,
407
+ {
408
+ ids,
409
+ resource: resourceName,
410
+ meta,
411
+ metaData,
412
+ dataProviderName: dataProviderNameFromProp,
413
+ successNotification,
414
+ },
415
+ context,
416
+ ) => {
417
+ const { resource, identifier } = select(resourceName);
364
418
 
365
- for (const id of ids) {
366
- queryClient.setQueriesData(
367
- resourceKeys
368
- .action("one")
369
- .id(id)
370
- .params(preferredMeta)
371
- .get(preferLegacyKeys),
372
- (previous?: any | null) => {
373
- if (!previous || previous.data.id == id) {
374
- return null;
375
- }
376
- return {
377
- ...previous,
378
- };
379
- },
380
- );
381
- }
382
- }
419
+ const dataProviderName = pickDataProvider(
420
+ identifier,
421
+ dataProviderNameFromProp,
422
+ resources,
423
+ );
383
424
 
384
- return {
385
- previousQueries,
386
- queryKey,
387
- };
388
- },
389
- // Always refetch after error or success:
390
- onSettled: (
391
- _data,
392
- _error,
393
- {
394
- resource: resourceName,
395
- ids,
425
+ const combinedMeta = getMeta({
426
+ resource,
427
+ meta: pickNotDeprecated(meta, metaData),
428
+ });
429
+
430
+ // Remove the queries from the cache:
431
+ ids.forEach((id) =>
432
+ queryClient.removeQueries(context?.queryKey.detail(id)),
433
+ );
434
+
435
+ const notificationConfig =
436
+ typeof successNotification === "function"
437
+ ? successNotification(_data, ids, identifier)
438
+ : successNotification;
439
+
440
+ handleNotification(notificationConfig, {
441
+ key: `${ids}-${identifier}-notification`,
442
+ description: translate("notifications.success", "Success"),
443
+ message: translate(
444
+ "notifications.deleteSuccess",
445
+ {
446
+ resource: translate(
447
+ `${identifier}.${identifier}`,
448
+ identifier,
449
+ ),
450
+ },
451
+ `Successfully deleted ${identifier}`,
452
+ ),
453
+ type: "success",
454
+ });
455
+
456
+ publish?.({
457
+ channel: `resources/${resource.name}`,
458
+ type: "deleted",
459
+ payload: { ids },
460
+ date: new Date(),
461
+ meta: {
462
+ ...combinedMeta,
396
463
  dataProviderName,
397
- invalidates = ["list", "many"],
398
464
  },
399
- ) => {
400
- const { identifier } = select(resourceName);
401
-
402
- // invalidate the cache for the list and many queries:
403
- invalidateStore({
404
- resource: identifier,
405
- dataProviderName: pickDataProvider(
406
- identifier,
407
- dataProviderName,
408
- resources,
409
- ),
410
- invalidates,
411
- });
465
+ });
412
466
 
413
- notificationDispatch({
414
- type: ActionTypes.REMOVE,
415
- payload: { id: ids, resource: identifier },
416
- });
417
- },
418
- onSuccess: (
419
- _data,
420
- {
467
+ const {
468
+ fields: _fields,
469
+ operation: _operation,
470
+ variables: _variables,
471
+ ...rest
472
+ } = combinedMeta || {};
473
+ log?.mutate({
474
+ action: "deleteMany",
475
+ resource: resource.name,
476
+ meta: {
421
477
  ids,
422
- resource: resourceName,
423
- meta,
424
- metaData,
425
- dataProviderName: dataProviderNameFromProp,
426
- successNotification,
478
+ dataProviderName,
479
+ ...rest,
427
480
  },
428
- context,
429
- ) => {
430
- const { resource, identifier } = select(resourceName);
431
-
432
- const dataProviderName = pickDataProvider(
433
- identifier,
434
- dataProviderNameFromProp,
435
- resources,
436
- );
481
+ });
437
482
 
438
- const combinedMeta = getMeta({
439
- resource,
440
- meta: pickNotDeprecated(meta, metaData),
441
- });
483
+ // Remove the queries from the cache:
484
+ ids.forEach((id) =>
485
+ queryClient.removeQueries(context?.queryKey.detail(id)),
486
+ );
487
+ },
488
+ onError: (
489
+ err,
490
+ { ids, resource: resourceName, errorNotification },
491
+ context,
492
+ ) => {
493
+ const { identifier } = select(resourceName);
494
+
495
+ // set back the queries to the context:
496
+ if (context) {
497
+ for (const query of context.previousQueries) {
498
+ queryClient.setQueryData(query[0], query[1]);
499
+ }
500
+ }
442
501
 
443
- // Remove the queries from the cache:
444
- ids.forEach((id) =>
445
- queryClient.removeQueries(context?.queryKey.detail(id)),
446
- );
502
+ if (err.message !== "mutationCancelled") {
503
+ checkError(err);
504
+ const resourceSingular = textTransformers.singular(identifier);
447
505
 
448
506
  const notificationConfig =
449
- typeof successNotification === "function"
450
- ? successNotification(_data, ids, identifier)
451
- : successNotification;
507
+ typeof errorNotification === "function"
508
+ ? errorNotification(err, ids, identifier)
509
+ : errorNotification;
452
510
 
453
511
  handleNotification(notificationConfig, {
454
512
  key: `${ids}-${identifier}-notification`,
455
- description: translate("notifications.success", "Success"),
456
513
  message: translate(
457
- "notifications.deleteSuccess",
514
+ "notifications.deleteError",
458
515
  {
459
- resource: translate(
460
- `${identifier}.${identifier}`,
461
- identifier,
462
- ),
516
+ resource: resourceSingular,
517
+ statusCode: err.statusCode,
463
518
  },
464
- `Successfully deleted ${identifier}`,
519
+ `Error (status code: ${err.statusCode})`,
465
520
  ),
466
- type: "success",
467
- });
468
-
469
- publish?.({
470
- channel: `resources/${resource.name}`,
471
- type: "deleted",
472
- payload: { ids },
473
- date: new Date(),
474
- meta: {
475
- ...combinedMeta,
476
- dataProviderName,
477
- },
478
- });
479
-
480
- const {
481
- fields: _fields,
482
- operation: _operation,
483
- variables: _variables,
484
- ...rest
485
- } = combinedMeta || {};
486
- log?.mutate({
487
- action: "deleteMany",
488
- resource: resource.name,
489
- meta: {
490
- ids,
491
- dataProviderName,
492
- ...rest,
493
- },
521
+ description: err.message,
522
+ type: "error",
494
523
  });
495
-
496
- // Remove the queries from the cache:
497
- ids.forEach((id) =>
498
- queryClient.removeQueries(context?.queryKey.detail(id)),
499
- );
500
- },
501
- onError: (
502
- err,
503
- { ids, resource: resourceName, errorNotification },
504
- context,
505
- ) => {
506
- const { identifier } = select(resourceName);
507
-
508
- // set back the queries to the context:
509
- if (context) {
510
- for (const query of context.previousQueries) {
511
- queryClient.setQueryData(query[0], query[1]);
512
- }
513
- }
514
-
515
- if (err.message !== "mutationCancelled") {
516
- checkError(err);
517
- const resourceSingular =
518
- textTransformers.singular(identifier);
519
-
520
- const notificationConfig =
521
- typeof errorNotification === "function"
522
- ? errorNotification(err, ids, identifier)
523
- : errorNotification;
524
-
525
- handleNotification(notificationConfig, {
526
- key: `${ids}-${identifier}-notification`,
527
- message: translate(
528
- "notifications.deleteError",
529
- {
530
- resource: resourceSingular,
531
- statusCode: err.statusCode,
532
- },
533
- `Error (status code: ${err.statusCode})`,
534
- ),
535
- description: err.message,
536
- type: "error",
537
- });
538
- }
539
- },
540
- mutationKey: keys()
541
- .data()
542
- .mutation("deleteMany")
543
- .get(preferLegacyKeys),
544
- ...mutationOptions,
545
- meta: {
546
- ...mutationOptions?.meta,
547
- ...getXRay("useDeleteMany", preferLegacyKeys),
548
- },
524
+ }
525
+ },
526
+ mutationKey: keys().data().mutation("deleteMany").get(preferLegacyKeys),
527
+ ...mutationOptions,
528
+ meta: {
529
+ ...mutationOptions?.meta,
530
+ ...getXRay("useDeleteMany", preferLegacyKeys),
549
531
  },
550
- );
532
+ });
551
533
 
552
534
  const { elapsedTime } = useLoadingOvertime({
553
535
  isLoading: mutation.isLoading,
@@ -230,8 +230,8 @@ export const useInfiniteList = <
230
230
  GetListResponse<TQueryFnData>,
231
231
  TError,
232
232
  GetListResponse<TData>
233
- >(
234
- keys()
233
+ >({
234
+ queryKey: keys()
235
235
  .data(pickedDataProvider)
236
236
  .resource(identifier)
237
237
  .action("infinite")
@@ -250,7 +250,7 @@ export const useInfiniteList = <
250
250
  }),
251
251
  })
252
252
  .get(preferLegacyKeys),
253
- ({ queryKey, pageParam, signal }) => {
253
+ queryFn: ({ queryKey, pageParam, signal }) => {
254
254
  const paginationProperties = {
255
255
  ...prefferedPagination,
256
256
  current: pageParam,
@@ -288,50 +288,44 @@ export const useInfiniteList = <
288
288
  };
289
289
  });
290
290
  },
291
- {
292
- getNextPageParam: (lastPage) => getNextPageParam(lastPage),
293
- getPreviousPageParam: (lastPage) => getPreviousPageParam(lastPage),
294
- ...queryOptions,
295
- onSuccess: (data) => {
296
- queryOptions?.onSuccess?.(data);
291
+ getNextPageParam: (lastPage) => getNextPageParam(lastPage),
292
+ getPreviousPageParam: (lastPage) => getPreviousPageParam(lastPage),
293
+ ...queryOptions,
294
+ onSuccess: (data) => {
295
+ queryOptions?.onSuccess?.(data);
297
296
 
298
- const notificationConfig =
299
- typeof successNotification === "function"
300
- ? successNotification(
301
- data,
302
- notificationValues,
303
- identifier,
304
- )
305
- : successNotification;
297
+ const notificationConfig =
298
+ typeof successNotification === "function"
299
+ ? successNotification(data, notificationValues, identifier)
300
+ : successNotification;
306
301
 
307
- handleNotification(notificationConfig);
308
- },
309
- onError: (err: TError) => {
310
- checkError(err);
311
- queryOptions?.onError?.(err);
302
+ handleNotification(notificationConfig);
303
+ },
304
+ onError: (err: TError) => {
305
+ checkError(err);
306
+ queryOptions?.onError?.(err);
312
307
 
313
- const notificationConfig =
314
- typeof errorNotification === "function"
315
- ? errorNotification(err, notificationValues, identifier)
316
- : errorNotification;
308
+ const notificationConfig =
309
+ typeof errorNotification === "function"
310
+ ? errorNotification(err, notificationValues, identifier)
311
+ : errorNotification;
317
312
 
318
- handleNotification(notificationConfig, {
319
- key: `${identifier}-useInfiniteList-notification`,
320
- message: translate(
321
- "notifications.error",
322
- { statusCode: err.statusCode },
323
- `Error (status code: ${err.statusCode})`,
324
- ),
325
- description: err.message,
326
- type: "error",
327
- });
328
- },
329
- meta: {
330
- ...queryOptions?.meta,
331
- ...getXRay("useInfiniteList", preferLegacyKeys),
332
- },
313
+ handleNotification(notificationConfig, {
314
+ key: `${identifier}-useInfiniteList-notification`,
315
+ message: translate(
316
+ "notifications.error",
317
+ { statusCode: err.statusCode },
318
+ `Error (status code: ${err.statusCode})`,
319
+ ),
320
+ description: err.message,
321
+ type: "error",
322
+ });
333
323
  },
334
- );
324
+ meta: {
325
+ ...queryOptions?.meta,
326
+ ...getXRay("useInfiniteList", preferLegacyKeys),
327
+ },
328
+ });
335
329
 
336
330
  const { elapsedTime } = useLoadingOvertime({
337
331
  isLoading: queryResponse.isFetching,