@refinedev/core 4.46.0 → 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 (59) hide show
  1. package/CHANGELOG.md +109 -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/hooks/useMeta/index.d.ts +2 -0
  21. package/dist/hooks/useMeta/index.d.ts.map +1 -1
  22. package/dist/iife/index.js +6 -6
  23. package/dist/iife/index.js.map +1 -1
  24. package/dist/index.js +6 -6
  25. package/dist/index.js.map +1 -1
  26. package/dist/interfaces/auth.d.ts +6 -6
  27. package/dist/interfaces/auth.d.ts.map +1 -1
  28. package/dist/interfaces/metaData/graphqlQueryOptions.d.ts +6 -0
  29. package/dist/interfaces/metaData/graphqlQueryOptions.d.ts.map +1 -0
  30. package/dist/interfaces/metaData/metaQuery.d.ts +2 -1
  31. package/dist/interfaces/metaData/metaQuery.d.ts.map +1 -1
  32. package/package.json +2 -1
  33. package/src/definitions/helpers/flatten-object-keys/index.ts +2 -0
  34. package/src/hooks/accessControl/useCan/index.ts +10 -12
  35. package/src/hooks/auditLog/useLogList/index.ts +10 -12
  36. package/src/hooks/auth/useForgotPassword/index.ts +51 -54
  37. package/src/hooks/auth/useGetIdentity/index.ts +23 -26
  38. package/src/hooks/auth/useIsAuthenticated/index.ts +20 -20
  39. package/src/hooks/auth/useLogin/index.ts +33 -35
  40. package/src/hooks/auth/useLogout/index.ts +32 -34
  41. package/src/hooks/auth/useOnError/index.ts +29 -33
  42. package/src/hooks/auth/usePermissions/index.ts +19 -22
  43. package/src/hooks/auth/useRegister/index.ts +60 -66
  44. package/src/hooks/auth/useUpdatePassword/index.ts +51 -54
  45. package/src/hooks/data/useCreate.ts +115 -117
  46. package/src/hooks/data/useCreateMany.ts +113 -118
  47. package/src/hooks/data/useDelete.ts +212 -223
  48. package/src/hooks/data/useDeleteMany.ts +230 -244
  49. package/src/hooks/data/useInfiniteList.ts +36 -42
  50. package/src/hooks/data/useList.ts +56 -62
  51. package/src/hooks/data/useMany.ts +36 -37
  52. package/src/hooks/data/useOne.ts +54 -55
  53. package/src/hooks/data/useUpdate.ts +288 -311
  54. package/src/hooks/data/useUpdateMany.ts +294 -320
  55. package/src/hooks/menu/useMenu.tsx +1 -1
  56. package/src/hooks/router/use-go/index.tsx +3 -0
  57. package/src/interfaces/auth.tsx +6 -6
  58. package/src/interfaces/metaData/graphqlQueryOptions.ts +6 -0
  59. package/src/interfaces/metaData/metaQuery.ts +3 -1
@@ -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,259 +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 preferredMeta = pickNotDeprecated(meta, metaData);
387
+ const dataProviderName = pickDataProvider(
388
+ identifier,
389
+ dataProviderNameFromProp,
390
+ resources,
391
+ );
270
392
 
271
- const queryKey = queryKeysReplacement(preferLegacyKeys)(
272
- identifier,
273
- pickDataProvider(identifier, dataProviderName, resources),
274
- preferredMeta,
275
- );
393
+ const combinedMeta = getMeta({
394
+ resource,
395
+ meta: pickNotDeprecated(meta, metaData),
396
+ });
276
397
 
277
- const resourceKeys = keys()
278
- .data(
279
- pickDataProvider(
280
- identifier,
281
- dataProviderName,
282
- resources,
283
- ),
284
- )
285
- .resource(identifier);
398
+ // Remove the queries from the cache:
399
+ queryClient.removeQueries(context?.queryKey.detail(id));
286
400
 
287
- const mutationModePropOrContext =
288
- mutationMode ?? mutationModeContext;
401
+ const notificationConfig =
402
+ typeof successNotification === "function"
403
+ ? successNotification(_data, id, identifier)
404
+ : successNotification;
289
405
 
290
- await queryClient.cancelQueries(
291
- resourceKeys.get(preferLegacyKeys),
292
- undefined,
406
+ handleNotification(notificationConfig, {
407
+ key: `${id}-${identifier}-notification`,
408
+ description: translate("notifications.success", "Success"),
409
+ message: translate(
410
+ "notifications.deleteSuccess",
293
411
  {
294
- silent: true,
412
+ resource: translate(
413
+ `${identifier}.${identifier}`,
414
+ resourceSingular,
415
+ ),
295
416
  },
296
- );
297
-
298
- const previousQueries: PreviousQuery<TData>[] =
299
- queryClient.getQueriesData(
300
- resourceKeys.get(preferLegacyKeys),
301
- );
302
-
303
- if (mutationModePropOrContext !== "pessimistic") {
304
- // Set the previous queries to the new ones:
305
- queryClient.setQueriesData(
306
- resourceKeys
307
- .action("list")
308
- .params(preferredMeta ?? {})
309
- .get(preferLegacyKeys),
310
- (previous?: GetListResponse<TData> | null) => {
311
- if (!previous) {
312
- return null;
313
- }
314
- const data = previous.data.filter(
315
- (record: TData) =>
316
- record.id?.toString() !== id.toString(),
317
- );
318
-
319
- return {
320
- data,
321
- total: previous.total - 1,
322
- };
323
- },
324
- );
325
-
326
- queryClient.setQueriesData(
327
- resourceKeys.action("many").get(preferLegacyKeys),
328
- (previous?: GetListResponse<TData> | null) => {
329
- if (!previous) {
330
- return null;
331
- }
332
- const data = previous.data.filter(
333
- (record: TData) => {
334
- return (
335
- record.id?.toString() !== id?.toString()
336
- );
337
- },
338
- );
339
-
340
- return {
341
- ...previous,
342
- data,
343
- };
344
- },
345
- );
346
- }
417
+ `Successfully deleted a ${resourceSingular}`,
418
+ ),
419
+ type: "success",
420
+ });
347
421
 
348
- return {
349
- previousQueries,
350
- queryKey,
351
- };
352
- },
353
- onSettled: (
354
- _data,
355
- _error,
356
- {
357
- id,
358
- 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,
359
431
  dataProviderName,
360
- invalidates = ["list", "many"],
361
432
  },
362
- ) => {
363
- const { identifier } = select(resourceName);
364
-
365
- // invalidate the cache for the list and many queries:
366
- invalidateStore({
367
- resource: identifier,
368
- dataProviderName: pickDataProvider(
369
- identifier,
370
- dataProviderName,
371
- resources,
372
- ),
373
- invalidates,
374
- });
433
+ });
375
434
 
376
- notificationDispatch({
377
- type: ActionTypes.REMOVE,
378
- payload: { id, resource: identifier },
379
- });
380
- },
381
- onSuccess: (
382
- _data,
383
- {
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: {
384
445
  id,
385
- resource: resourceName,
386
- successNotification,
387
- dataProviderName: dataProviderNameFromProp,
388
- meta,
389
- metaData,
446
+ dataProviderName,
447
+ ...rest,
390
448
  },
391
- context,
392
- ) => {
393
- const { resource, identifier } = select(resourceName);
394
- const resourceSingular = textTransformers.singular(identifier);
449
+ });
395
450
 
396
- const dataProviderName = pickDataProvider(
397
- identifier,
398
- dataProviderNameFromProp,
399
- resources,
400
- );
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
+ }
401
467
 
402
- const combinedMeta = getMeta({
403
- resource,
404
- meta: pickNotDeprecated(meta, metaData),
405
- });
468
+ if (err.message !== "mutationCancelled") {
469
+ checkError(err);
406
470
 
407
- // Remove the queries from the cache:
408
- queryClient.removeQueries(context?.queryKey.detail(id));
471
+ const resourceSingular = textTransformers.singular(identifier);
409
472
 
410
473
  const notificationConfig =
411
- typeof successNotification === "function"
412
- ? successNotification(_data, id, identifier)
413
- : successNotification;
474
+ typeof errorNotification === "function"
475
+ ? errorNotification(err, id, identifier)
476
+ : errorNotification;
414
477
 
415
478
  handleNotification(notificationConfig, {
416
479
  key: `${id}-${identifier}-notification`,
417
- description: translate("notifications.success", "Success"),
418
480
  message: translate(
419
- "notifications.deleteSuccess",
481
+ "notifications.deleteError",
420
482
  {
421
- resource: translate(
422
- `${identifier}.${identifier}`,
423
- resourceSingular,
424
- ),
483
+ resource: resourceSingular,
484
+ statusCode: err.statusCode,
425
485
  },
426
- `Successfully deleted a ${resourceSingular}`,
486
+ `Error (status code: ${err.statusCode})`,
427
487
  ),
428
- type: "success",
429
- });
430
-
431
- publish?.({
432
- channel: `resources/${resource.name}`,
433
- type: "deleted",
434
- payload: {
435
- ids: [id],
436
- },
437
- date: new Date(),
438
- meta: {
439
- ...combinedMeta,
440
- dataProviderName,
441
- },
442
- });
443
-
444
- const {
445
- fields: _fields,
446
- operation: _operation,
447
- variables: _variables,
448
- ...rest
449
- } = combinedMeta || {};
450
- log?.mutate({
451
- action: "delete",
452
- resource: resource.name,
453
- meta: {
454
- id,
455
- dataProviderName,
456
- ...rest,
457
- },
488
+ description: err.message,
489
+ type: "error",
458
490
  });
459
-
460
- // Remove the queries from the cache:
461
- queryClient.removeQueries(context?.queryKey.detail(id));
462
- },
463
- onError: (
464
- err: TError,
465
- { id, resource: resourceName, errorNotification },
466
- context,
467
- ) => {
468
- const { identifier } = select(resourceName);
469
-
470
- // set back the queries to the context:
471
- if (context) {
472
- for (const query of context.previousQueries) {
473
- queryClient.setQueryData(query[0], query[1]);
474
- }
475
- }
476
-
477
- if (err.message !== "mutationCancelled") {
478
- checkError(err);
479
-
480
- const resourceSingular =
481
- textTransformers.singular(identifier);
482
-
483
- const notificationConfig =
484
- typeof errorNotification === "function"
485
- ? errorNotification(err, id, identifier)
486
- : errorNotification;
487
-
488
- handleNotification(notificationConfig, {
489
- key: `${id}-${identifier}-notification`,
490
- message: translate(
491
- "notifications.deleteError",
492
- {
493
- resource: resourceSingular,
494
- statusCode: err.statusCode,
495
- },
496
- `Error (status code: ${err.statusCode})`,
497
- ),
498
- description: err.message,
499
- type: "error",
500
- });
501
- }
502
- },
503
- mutationKey: keys().data().mutation("delete").get(preferLegacyKeys),
504
- ...mutationOptions,
505
- meta: {
506
- ...mutationOptions?.meta,
507
- ...getXRay("useDelete", preferLegacyKeys),
508
- },
491
+ }
492
+ },
493
+ mutationKey: keys().data().mutation("delete").get(preferLegacyKeys),
494
+ ...mutationOptions,
495
+ meta: {
496
+ ...mutationOptions?.meta,
497
+ ...getXRay("useDelete", preferLegacyKeys),
509
498
  },
510
- );
499
+ });
511
500
 
512
501
  const { elapsedTime } = useLoadingOvertime({
513
502
  isLoading: mutation.isLoading,