@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
@@ -174,8 +174,8 @@ export const useDelete = <
174
174
  TError,
175
175
  DeleteParams<TData, TError, TVariables>,
176
176
  DeleteContext<TData>
177
- >(
178
- ({
177
+ >({
178
+ mutationFn: ({
179
179
  id,
180
180
  mutationMode,
181
181
  undoableTimeout,
@@ -255,263 +255,248 @@ export const useDelete = <
255
255
  );
256
256
  return deletePromise;
257
257
  },
258
- {
259
- onMutate: async ({
258
+ onMutate: async ({
259
+ id,
260
+ resource: resourceName,
261
+ mutationMode,
262
+ dataProviderName,
263
+ meta,
264
+ metaData,
265
+ }) => {
266
+ const { identifier } = select(resourceName);
267
+
268
+ const {
269
+ gqlMutation: _,
270
+ gqlQuery: __,
271
+ ...preferredMeta
272
+ } = pickNotDeprecated(meta, metaData) ?? {};
273
+
274
+ const queryKey = queryKeysReplacement(preferLegacyKeys)(
275
+ identifier,
276
+ pickDataProvider(identifier, dataProviderName, resources),
277
+ preferredMeta,
278
+ );
279
+
280
+ const resourceKeys = keys()
281
+ .data(pickDataProvider(identifier, dataProviderName, resources))
282
+ .resource(identifier);
283
+
284
+ const mutationModePropOrContext =
285
+ mutationMode ?? mutationModeContext;
286
+
287
+ await queryClient.cancelQueries(
288
+ resourceKeys.get(preferLegacyKeys),
289
+ undefined,
290
+ {
291
+ silent: true,
292
+ },
293
+ );
294
+
295
+ const previousQueries: PreviousQuery<TData>[] =
296
+ queryClient.getQueriesData(resourceKeys.get(preferLegacyKeys));
297
+
298
+ if (mutationModePropOrContext !== "pessimistic") {
299
+ // Set the previous queries to the new ones:
300
+ queryClient.setQueriesData(
301
+ resourceKeys
302
+ .action("list")
303
+ .params(preferredMeta ?? {})
304
+ .get(preferLegacyKeys),
305
+ (previous?: GetListResponse<TData> | null) => {
306
+ if (!previous) {
307
+ return null;
308
+ }
309
+ const data = previous.data.filter(
310
+ (record: TData) =>
311
+ record.id?.toString() !== id.toString(),
312
+ );
313
+
314
+ return {
315
+ data,
316
+ total: previous.total - 1,
317
+ };
318
+ },
319
+ );
320
+
321
+ queryClient.setQueriesData(
322
+ resourceKeys.action("many").get(preferLegacyKeys),
323
+ (previous?: GetListResponse<TData> | null) => {
324
+ if (!previous) {
325
+ return null;
326
+ }
327
+ const data = previous.data.filter((record: TData) => {
328
+ return record.id?.toString() !== id?.toString();
329
+ });
330
+
331
+ return {
332
+ ...previous,
333
+ data,
334
+ };
335
+ },
336
+ );
337
+ }
338
+
339
+ return {
340
+ previousQueries,
341
+ queryKey,
342
+ };
343
+ },
344
+ onSettled: (
345
+ _data,
346
+ _error,
347
+ {
260
348
  id,
261
349
  resource: resourceName,
262
- mutationMode,
263
350
  dataProviderName,
351
+ invalidates = ["list", "many"],
352
+ },
353
+ ) => {
354
+ const { identifier } = select(resourceName);
355
+
356
+ // invalidate the cache for the list and many queries:
357
+ invalidateStore({
358
+ resource: identifier,
359
+ dataProviderName: pickDataProvider(
360
+ identifier,
361
+ dataProviderName,
362
+ resources,
363
+ ),
364
+ invalidates,
365
+ });
366
+
367
+ notificationDispatch({
368
+ type: ActionTypes.REMOVE,
369
+ payload: { id, resource: identifier },
370
+ });
371
+ },
372
+ onSuccess: (
373
+ _data,
374
+ {
375
+ id,
376
+ resource: resourceName,
377
+ successNotification,
378
+ dataProviderName: dataProviderNameFromProp,
264
379
  meta,
265
380
  metaData,
266
- }) => {
267
- const { identifier } = select(resourceName);
381
+ },
382
+ context,
383
+ ) => {
384
+ const { resource, identifier } = select(resourceName);
385
+ const resourceSingular = textTransformers.singular(identifier);
268
386
 
269
- const {
270
- gqlMutation: _,
271
- gqlQuery: __,
272
- ...preferredMeta
273
- } = pickNotDeprecated(meta, metaData) ?? {};
387
+ const dataProviderName = pickDataProvider(
388
+ identifier,
389
+ dataProviderNameFromProp,
390
+ resources,
391
+ );
274
392
 
275
- const queryKey = queryKeysReplacement(preferLegacyKeys)(
276
- identifier,
277
- pickDataProvider(identifier, dataProviderName, resources),
278
- preferredMeta,
279
- );
393
+ const combinedMeta = getMeta({
394
+ resource,
395
+ meta: pickNotDeprecated(meta, metaData),
396
+ });
280
397
 
281
- const resourceKeys = keys()
282
- .data(
283
- pickDataProvider(
284
- identifier,
285
- dataProviderName,
286
- resources,
287
- ),
288
- )
289
- .resource(identifier);
398
+ // Remove the queries from the cache:
399
+ queryClient.removeQueries(context?.queryKey.detail(id));
290
400
 
291
- const mutationModePropOrContext =
292
- mutationMode ?? mutationModeContext;
401
+ const notificationConfig =
402
+ typeof successNotification === "function"
403
+ ? successNotification(_data, id, identifier)
404
+ : successNotification;
293
405
 
294
- await queryClient.cancelQueries(
295
- resourceKeys.get(preferLegacyKeys),
296
- undefined,
406
+ handleNotification(notificationConfig, {
407
+ key: `${id}-${identifier}-notification`,
408
+ description: translate("notifications.success", "Success"),
409
+ message: translate(
410
+ "notifications.deleteSuccess",
297
411
  {
298
- silent: true,
412
+ resource: translate(
413
+ `${identifier}.${identifier}`,
414
+ resourceSingular,
415
+ ),
299
416
  },
300
- );
301
-
302
- const previousQueries: PreviousQuery<TData>[] =
303
- queryClient.getQueriesData(
304
- resourceKeys.get(preferLegacyKeys),
305
- );
306
-
307
- if (mutationModePropOrContext !== "pessimistic") {
308
- // Set the previous queries to the new ones:
309
- queryClient.setQueriesData(
310
- resourceKeys
311
- .action("list")
312
- .params(preferredMeta ?? {})
313
- .get(preferLegacyKeys),
314
- (previous?: GetListResponse<TData> | null) => {
315
- if (!previous) {
316
- return null;
317
- }
318
- const data = previous.data.filter(
319
- (record: TData) =>
320
- record.id?.toString() !== id.toString(),
321
- );
322
-
323
- return {
324
- data,
325
- total: previous.total - 1,
326
- };
327
- },
328
- );
329
-
330
- queryClient.setQueriesData(
331
- resourceKeys.action("many").get(preferLegacyKeys),
332
- (previous?: GetListResponse<TData> | null) => {
333
- if (!previous) {
334
- return null;
335
- }
336
- const data = previous.data.filter(
337
- (record: TData) => {
338
- return (
339
- record.id?.toString() !== id?.toString()
340
- );
341
- },
342
- );
343
-
344
- return {
345
- ...previous,
346
- data,
347
- };
348
- },
349
- );
350
- }
417
+ `Successfully deleted a ${resourceSingular}`,
418
+ ),
419
+ type: "success",
420
+ });
351
421
 
352
- return {
353
- previousQueries,
354
- queryKey,
355
- };
356
- },
357
- onSettled: (
358
- _data,
359
- _error,
360
- {
361
- id,
362
- resource: resourceName,
422
+ publish?.({
423
+ channel: `resources/${resource.name}`,
424
+ type: "deleted",
425
+ payload: {
426
+ ids: [id],
427
+ },
428
+ date: new Date(),
429
+ meta: {
430
+ ...combinedMeta,
363
431
  dataProviderName,
364
- invalidates = ["list", "many"],
365
432
  },
366
- ) => {
367
- const { identifier } = select(resourceName);
368
-
369
- // invalidate the cache for the list and many queries:
370
- invalidateStore({
371
- resource: identifier,
372
- dataProviderName: pickDataProvider(
373
- identifier,
374
- dataProviderName,
375
- resources,
376
- ),
377
- invalidates,
378
- });
433
+ });
379
434
 
380
- notificationDispatch({
381
- type: ActionTypes.REMOVE,
382
- payload: { id, resource: identifier },
383
- });
384
- },
385
- onSuccess: (
386
- _data,
387
- {
435
+ const {
436
+ fields: _fields,
437
+ operation: _operation,
438
+ variables: _variables,
439
+ ...rest
440
+ } = combinedMeta || {};
441
+ log?.mutate({
442
+ action: "delete",
443
+ resource: resource.name,
444
+ meta: {
388
445
  id,
389
- resource: resourceName,
390
- successNotification,
391
- dataProviderName: dataProviderNameFromProp,
392
- meta,
393
- metaData,
446
+ dataProviderName,
447
+ ...rest,
394
448
  },
395
- context,
396
- ) => {
397
- const { resource, identifier } = select(resourceName);
398
- const resourceSingular = textTransformers.singular(identifier);
449
+ });
399
450
 
400
- const dataProviderName = pickDataProvider(
401
- identifier,
402
- dataProviderNameFromProp,
403
- resources,
404
- );
451
+ // Remove the queries from the cache:
452
+ queryClient.removeQueries(context?.queryKey.detail(id));
453
+ },
454
+ onError: (
455
+ err: TError,
456
+ { id, resource: resourceName, errorNotification },
457
+ context,
458
+ ) => {
459
+ const { identifier } = select(resourceName);
460
+
461
+ // set back the queries to the context:
462
+ if (context) {
463
+ for (const query of context.previousQueries) {
464
+ queryClient.setQueryData(query[0], query[1]);
465
+ }
466
+ }
405
467
 
406
- const combinedMeta = getMeta({
407
- resource,
408
- meta: pickNotDeprecated(meta, metaData),
409
- });
468
+ if (err.message !== "mutationCancelled") {
469
+ checkError(err);
410
470
 
411
- // Remove the queries from the cache:
412
- queryClient.removeQueries(context?.queryKey.detail(id));
471
+ const resourceSingular = textTransformers.singular(identifier);
413
472
 
414
473
  const notificationConfig =
415
- typeof successNotification === "function"
416
- ? successNotification(_data, id, identifier)
417
- : successNotification;
474
+ typeof errorNotification === "function"
475
+ ? errorNotification(err, id, identifier)
476
+ : errorNotification;
418
477
 
419
478
  handleNotification(notificationConfig, {
420
479
  key: `${id}-${identifier}-notification`,
421
- description: translate("notifications.success", "Success"),
422
480
  message: translate(
423
- "notifications.deleteSuccess",
481
+ "notifications.deleteError",
424
482
  {
425
- resource: translate(
426
- `${identifier}.${identifier}`,
427
- resourceSingular,
428
- ),
483
+ resource: resourceSingular,
484
+ statusCode: err.statusCode,
429
485
  },
430
- `Successfully deleted a ${resourceSingular}`,
486
+ `Error (status code: ${err.statusCode})`,
431
487
  ),
432
- type: "success",
433
- });
434
-
435
- publish?.({
436
- channel: `resources/${resource.name}`,
437
- type: "deleted",
438
- payload: {
439
- ids: [id],
440
- },
441
- date: new Date(),
442
- meta: {
443
- ...combinedMeta,
444
- dataProviderName,
445
- },
446
- });
447
-
448
- const {
449
- fields: _fields,
450
- operation: _operation,
451
- variables: _variables,
452
- ...rest
453
- } = combinedMeta || {};
454
- log?.mutate({
455
- action: "delete",
456
- resource: resource.name,
457
- meta: {
458
- id,
459
- dataProviderName,
460
- ...rest,
461
- },
488
+ description: err.message,
489
+ type: "error",
462
490
  });
463
-
464
- // Remove the queries from the cache:
465
- queryClient.removeQueries(context?.queryKey.detail(id));
466
- },
467
- onError: (
468
- err: TError,
469
- { id, resource: resourceName, errorNotification },
470
- context,
471
- ) => {
472
- const { identifier } = select(resourceName);
473
-
474
- // set back the queries to the context:
475
- if (context) {
476
- for (const query of context.previousQueries) {
477
- queryClient.setQueryData(query[0], query[1]);
478
- }
479
- }
480
-
481
- if (err.message !== "mutationCancelled") {
482
- checkError(err);
483
-
484
- const resourceSingular =
485
- textTransformers.singular(identifier);
486
-
487
- const notificationConfig =
488
- typeof errorNotification === "function"
489
- ? errorNotification(err, id, identifier)
490
- : errorNotification;
491
-
492
- handleNotification(notificationConfig, {
493
- key: `${id}-${identifier}-notification`,
494
- message: translate(
495
- "notifications.deleteError",
496
- {
497
- resource: resourceSingular,
498
- statusCode: err.statusCode,
499
- },
500
- `Error (status code: ${err.statusCode})`,
501
- ),
502
- description: err.message,
503
- type: "error",
504
- });
505
- }
506
- },
507
- mutationKey: keys().data().mutation("delete").get(preferLegacyKeys),
508
- ...mutationOptions,
509
- meta: {
510
- ...mutationOptions?.meta,
511
- ...getXRay("useDelete", preferLegacyKeys),
512
- },
491
+ }
492
+ },
493
+ mutationKey: keys().data().mutation("delete").get(preferLegacyKeys),
494
+ ...mutationOptions,
495
+ meta: {
496
+ ...mutationOptions?.meta,
497
+ ...getXRay("useDelete", preferLegacyKeys),
513
498
  },
514
- );
499
+ });
515
500
 
516
501
  const { elapsedTime } = useLoadingOvertime({
517
502
  isLoading: mutation.isLoading,