@refinedev/core 4.52.0 → 4.54.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 +363 -2
  2. package/dist/components/pages/auth/components/login/index.d.cts.map +1 -1
  3. package/dist/components/pages/auth/components/login/index.d.ts.map +1 -1
  4. package/dist/definitions/types/index.d.cts +12 -0
  5. package/dist/definitions/types/index.d.cts.map +1 -0
  6. package/dist/definitions/types/index.d.mts +12 -0
  7. package/dist/definitions/types/index.d.mts.map +12 -0
  8. package/dist/definitions/types/index.d.ts +12 -0
  9. package/dist/definitions/types/index.d.ts.map +1 -0
  10. package/dist/hooks/data/useCreate.d.cts +7 -6
  11. package/dist/hooks/data/useCreate.d.cts.map +1 -1
  12. package/dist/hooks/data/useCreate.d.mts +7 -6
  13. package/dist/hooks/data/useCreate.d.mts.map +7 -6
  14. package/dist/hooks/data/useCreate.d.ts +7 -6
  15. package/dist/hooks/data/useCreate.d.ts.map +1 -1
  16. package/dist/hooks/data/useCreateMany.d.cts +9 -9
  17. package/dist/hooks/data/useCreateMany.d.cts.map +1 -1
  18. package/dist/hooks/data/useCreateMany.d.mts +9 -9
  19. package/dist/hooks/data/useCreateMany.d.mts.map +9 -9
  20. package/dist/hooks/data/useCreateMany.d.ts +9 -9
  21. package/dist/hooks/data/useCreateMany.d.ts.map +1 -1
  22. package/dist/hooks/data/useUpdate.d.cts +8 -7
  23. package/dist/hooks/data/useUpdate.d.cts.map +1 -1
  24. package/dist/hooks/data/useUpdate.d.mts +8 -7
  25. package/dist/hooks/data/useUpdate.d.mts.map +8 -7
  26. package/dist/hooks/data/useUpdate.d.ts +8 -7
  27. package/dist/hooks/data/useUpdate.d.ts.map +1 -1
  28. package/dist/hooks/data/useUpdateMany.d.cts +9 -9
  29. package/dist/hooks/data/useUpdateMany.d.cts.map +1 -1
  30. package/dist/hooks/data/useUpdateMany.d.mts +9 -9
  31. package/dist/hooks/data/useUpdateMany.d.mts.map +9 -9
  32. package/dist/hooks/data/useUpdateMany.d.ts +9 -9
  33. package/dist/hooks/data/useUpdateMany.d.ts.map +1 -1
  34. package/dist/hooks/form/index.d.cts.map +1 -1
  35. package/dist/hooks/form/index.d.ts.map +1 -1
  36. package/dist/hooks/form/types.d.cts +8 -0
  37. package/dist/hooks/form/types.d.cts.map +1 -1
  38. package/dist/hooks/form/types.d.mts +8 -0
  39. package/dist/hooks/form/types.d.mts.map +8 -0
  40. package/dist/hooks/form/types.d.ts +8 -0
  41. package/dist/hooks/form/types.d.ts.map +1 -1
  42. package/dist/hooks/show/index.d.cts.map +1 -1
  43. package/dist/hooks/show/index.d.ts.map +1 -1
  44. package/dist/hooks/show/types.d.cts +4 -0
  45. package/dist/hooks/show/types.d.cts.map +1 -1
  46. package/dist/hooks/show/types.d.mts +4 -0
  47. package/dist/hooks/show/types.d.mts.map +4 -0
  48. package/dist/hooks/show/types.d.ts +4 -0
  49. package/dist/hooks/show/types.d.ts.map +1 -1
  50. package/dist/hooks/useSelect/index.d.cts +10 -2
  51. package/dist/hooks/useSelect/index.d.cts.map +1 -1
  52. package/dist/hooks/useSelect/index.d.mts +10 -2
  53. package/dist/hooks/useSelect/index.d.mts.map +10 -2
  54. package/dist/hooks/useSelect/index.d.ts +10 -2
  55. package/dist/hooks/useSelect/index.d.ts.map +1 -1
  56. package/dist/hooks/useTable/index.d.cts +4 -0
  57. package/dist/hooks/useTable/index.d.cts.map +1 -1
  58. package/dist/hooks/useTable/index.d.mts +4 -0
  59. package/dist/hooks/useTable/index.d.mts.map +4 -0
  60. package/dist/hooks/useTable/index.d.ts +4 -0
  61. package/dist/hooks/useTable/index.d.ts.map +1 -1
  62. package/dist/index.cjs +10 -10
  63. package/dist/index.cjs.map +1 -1
  64. package/dist/index.mjs +10 -10
  65. package/dist/index.mjs.map +1 -1
  66. package/package.json +2 -2
  67. package/src/components/pages/auth/components/login/index.tsx +7 -2
  68. package/src/definitions/types/index.ts +40 -0
  69. package/src/hooks/data/useCreate.ts +93 -32
  70. package/src/hooks/data/useCreateMany.ts +96 -33
  71. package/src/hooks/data/useUpdate.ts +137 -53
  72. package/src/hooks/data/useUpdateMany.ts +140 -51
  73. package/src/hooks/form/index.ts +2 -0
  74. package/src/hooks/form/types.ts +10 -0
  75. package/src/hooks/show/index.ts +1 -0
  76. package/src/hooks/show/types.ts +4 -0
  77. package/src/hooks/useSelect/index.ts +50 -28
  78. package/src/hooks/useTable/index.ts +5 -0
  79. package/dist/hooks/show/useShow.d.cts +0 -57
  80. package/dist/hooks/show/useShow.d.cts.map +0 -1
  81. package/dist/hooks/show/useShow.d.mts +0 -57
  82. package/dist/hooks/show/useShow.d.mts.map +0 -57
  83. package/dist/hooks/show/useShow.d.ts +0 -57
  84. package/dist/hooks/show/useShow.d.ts.map +0 -1
  85. package/src/hooks/show/useShow.ts +0 -179
@@ -1,7 +1,7 @@
1
1
  import { getXRay } from "@refinedev/devtools-internal";
2
2
  import {
3
3
  type UseMutationOptions,
4
- type UseMutationResult,
4
+ type MutateOptions,
5
5
  useMutation,
6
6
  useQueryClient,
7
7
  } from "@tanstack/react-query";
@@ -42,6 +42,7 @@ import type {
42
42
  PreviousQuery,
43
43
  UpdateResponse,
44
44
  } from "../../contexts/data/types";
45
+ import type { UseMutationResult } from "../../definitions/types";
45
46
  import type { SuccessErrorNotification } from "../../contexts/notification/types";
46
47
  import { ActionTypes } from "../../contexts/undoableQueue/types";
47
48
  import {
@@ -78,11 +79,11 @@ export type UpdateParams<TData, TError, TVariables> = {
78
79
  /**
79
80
  * Resource name for API data interactions
80
81
  */
81
- resource: string;
82
+ resource?: string;
82
83
  /**
83
84
  * id for mutation function
84
85
  */
85
- id: BaseKey;
86
+ id?: BaseKey;
86
87
  /**
87
88
  * [Determines when mutations are executed](/advanced-tutorials/mutation-mode.md)
88
89
  */
@@ -98,7 +99,7 @@ export type UpdateParams<TData, TError, TVariables> = {
98
99
  /**
99
100
  * Values for mutation function
100
101
  */
101
- values: TVariables;
102
+ values?: TVariables;
102
103
  /**
103
104
  * Metadata query for dataProvider
104
105
  */
@@ -156,9 +157,10 @@ export type UseUpdateProps<
156
157
  UpdateParams<TData, TError, TVariables>,
157
158
  UpdateContext<TData>
158
159
  >,
159
- "mutationFn" | "onError" | "onSuccess" | "onSettled" | "onMutate"
160
+ "mutationFn" | "onMutate"
160
161
  >;
161
- } & UseLoadingOvertimeOptionsProps;
162
+ } & UseLoadingOvertimeOptionsProps &
163
+ UpdateParams<TData, TError, TVariables>;
162
164
 
163
165
  /**
164
166
  * `useUpdate` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for update mutations.
@@ -177,6 +179,19 @@ export const useUpdate = <
177
179
  TError extends HttpError = HttpError,
178
180
  TVariables = {},
179
181
  >({
182
+ id: idFromProps,
183
+ resource: resourceFromProps,
184
+ values: valuesFromProps,
185
+ dataProviderName: dataProviderNameFromProps,
186
+ successNotification: successNotificationFromProps,
187
+ errorNotification: errorNotificationFromProps,
188
+ meta: metaFromProps,
189
+ metaData: metaDataFromProps,
190
+ mutationMode: mutationModeFromProps,
191
+ undoableTimeout: undoableTimeoutFromProps,
192
+ onCancel: onCancelFromProps,
193
+ optimisticUpdateMap: optimisticUpdateMapFromProps,
194
+ invalidates: invalidatesFromProps,
180
195
  mutationOptions,
181
196
  overtimeOptions,
182
197
  }: UseUpdateProps<TData, TError, TVariables> = {}): UseUpdateReturnType<
@@ -208,23 +223,27 @@ export const useUpdate = <
208
223
  } = useRefineContext();
209
224
  const { keys, preferLegacyKeys } = useKeys();
210
225
 
211
- const mutation = useMutation<
226
+ const mutationResult = useMutation<
212
227
  UpdateResponse<TData>,
213
228
  TError,
214
229
  UpdateParams<TData, TError, TVariables>,
215
230
  UpdateContext<TData>
216
231
  >({
217
232
  mutationFn: ({
218
- id,
219
- values,
220
- resource: resourceName,
221
- mutationMode,
222
- undoableTimeout,
223
- onCancel,
224
- meta,
225
- metaData,
226
- dataProviderName,
233
+ id = idFromProps,
234
+ values = valuesFromProps,
235
+ resource: resourceName = resourceFromProps,
236
+ mutationMode = mutationModeFromProps,
237
+ undoableTimeout = undoableTimeoutFromProps,
238
+ onCancel = onCancelFromProps,
239
+ meta = metaFromProps,
240
+ metaData = metaDataFromProps,
241
+ dataProviderName = dataProviderNameFromProps,
227
242
  }) => {
243
+ if (!id) throw missingIdError;
244
+ if (!values) throw missingValuesError;
245
+ if (!resourceName) throw missingResourceError;
246
+
228
247
  const { resource, identifier } = select(resourceName);
229
248
 
230
249
  const combinedMeta = getMeta({
@@ -289,15 +308,23 @@ export const useUpdate = <
289
308
  return updatePromise;
290
309
  },
291
310
  onMutate: async ({
292
- resource: resourceName,
293
- id,
294
- mutationMode,
295
- values,
296
- dataProviderName,
297
- meta,
298
- metaData,
299
- optimisticUpdateMap = { list: true, many: true, detail: true },
311
+ resource: resourceName = resourceFromProps,
312
+ id = idFromProps,
313
+ mutationMode = mutationModeFromProps,
314
+ values = valuesFromProps,
315
+ dataProviderName = dataProviderNameFromProps,
316
+ meta = metaFromProps,
317
+ metaData = metaDataFromProps,
318
+ optimisticUpdateMap = optimisticUpdateMapFromProps ?? {
319
+ list: true,
320
+ many: true,
321
+ detail: true,
322
+ },
300
323
  }) => {
324
+ if (!id) throw missingIdError;
325
+ if (!values) throw missingValuesError;
326
+ if (!resourceName) throw missingResourceError;
327
+
301
328
  const { identifier } = select(resourceName);
302
329
 
303
330
  const {
@@ -428,16 +455,16 @@ export const useUpdate = <
428
455
  queryKey,
429
456
  };
430
457
  },
431
- onSettled: (
432
- _data,
433
- _error,
434
- {
435
- id,
436
- resource: resourceName,
437
- dataProviderName,
438
- invalidates = ["list", "many", "detail"],
439
- },
440
- ) => {
458
+ onSettled: (data, error, variables, context) => {
459
+ const {
460
+ id = idFromProps,
461
+ resource: resourceName = resourceFromProps,
462
+ dataProviderName = dataProviderNameFromProps,
463
+ invalidates = invalidatesFromProps ?? ["list", "many", "detail"],
464
+ } = variables;
465
+ if (!id) throw missingIdError;
466
+ if (!resourceName) throw missingResourceError;
467
+
441
468
  const { identifier } = select(resourceName);
442
469
 
443
470
  invalidateStore({
@@ -455,20 +482,23 @@ export const useUpdate = <
455
482
  type: ActionTypes.REMOVE,
456
483
  payload: { id, resource: identifier },
457
484
  });
485
+
486
+ mutationOptions?.onSettled?.(data, error, variables, context);
458
487
  },
459
- onSuccess: (
460
- data,
461
- {
462
- id,
463
- resource: resourceName,
464
- successNotification,
465
- dataProviderName: dataProviderNameFromProp,
466
- values,
467
- meta,
468
- metaData,
469
- },
470
- context,
471
- ) => {
488
+ onSuccess: (data, variables, context) => {
489
+ const {
490
+ id = idFromProps,
491
+ resource: resourceName = resourceFromProps,
492
+ successNotification = successNotificationFromProps,
493
+ dataProviderName: dataProviderNameFromProp = dataProviderNameFromProps,
494
+ values = valuesFromProps,
495
+ meta = metaFromProps,
496
+ metaData = metaDataFromProps,
497
+ } = variables;
498
+ if (!id) throw missingIdError;
499
+ if (!values) throw missingValuesError;
500
+ if (!resourceName) throw missingResourceError;
501
+
472
502
  const { resource, identifier } = select(resourceName);
473
503
  const resourceSingular = textTransformers.singular(identifier);
474
504
 
@@ -546,12 +576,20 @@ export const useUpdate = <
546
576
  ...rest,
547
577
  },
548
578
  });
579
+
580
+ mutationOptions?.onSuccess?.(data, variables, context);
549
581
  },
550
- onError: (
551
- err: TError,
552
- { id, resource: resourceName, errorNotification, values },
553
- context,
554
- ) => {
582
+ onError: (err: TError, variables, context) => {
583
+ const {
584
+ id = idFromProps,
585
+ resource: resourceName = resourceFromProps,
586
+ errorNotification = errorNotificationFromProps,
587
+ values = valuesFromProps,
588
+ } = variables;
589
+ if (!id) throw missingIdError;
590
+ if (!values) throw missingValuesError;
591
+ if (!resourceName) throw missingResourceError;
592
+
555
593
  const { identifier } = select(resourceName);
556
594
 
557
595
  // set back the queries to the context:
@@ -588,6 +626,8 @@ export const useUpdate = <
588
626
  type: "error",
589
627
  });
590
628
  }
629
+
630
+ mutationOptions?.onError?.(err, variables, context);
591
631
  },
592
632
  mutationKey: keys().data().mutation("update").get(preferLegacyKeys),
593
633
  ...mutationOptions,
@@ -596,6 +636,7 @@ export const useUpdate = <
596
636
  ...getXRay("useUpdate", preferLegacyKeys),
597
637
  },
598
638
  });
639
+ const { mutate, mutateAsync, ...mutation } = mutationResult;
599
640
 
600
641
  const { elapsedTime } = useLoadingOvertime({
601
642
  isLoading: mutation.isLoading,
@@ -603,5 +644,48 @@ export const useUpdate = <
603
644
  onInterval: overtimeOptions?.onInterval,
604
645
  });
605
646
 
606
- return { ...mutation, overtime: { elapsedTime } };
647
+ // this function is used to make the `variables` parameter optional
648
+ const handleMutation = (
649
+ variables?: UpdateParams<TData, TError, TVariables>,
650
+ options?: MutateOptions<
651
+ UpdateResponse<TData>,
652
+ TError,
653
+ UpdateParams<TData, TError, TVariables>,
654
+ UpdateContext<TData>
655
+ >,
656
+ ) => {
657
+ return mutate(variables || {}, options);
658
+ };
659
+
660
+ // this function is used to make the `variables` parameter optional
661
+ const handleMutateAsync = (
662
+ variables?: UpdateParams<TData, TError, TVariables>,
663
+ options?: MutateOptions<
664
+ UpdateResponse<TData>,
665
+ TError,
666
+ UpdateParams<TData, TError, TVariables>,
667
+ UpdateContext<TData>
668
+ >,
669
+ ) => {
670
+ return mutateAsync(variables || {}, options);
671
+ };
672
+
673
+ return {
674
+ ...mutation,
675
+ mutate: handleMutation,
676
+ mutateAsync: handleMutateAsync,
677
+ overtime: { elapsedTime },
678
+ };
607
679
  };
680
+
681
+ const missingResourceError = new Error(
682
+ "[useUpdate]: `resource` is not defined or not matched but is required",
683
+ );
684
+
685
+ const missingIdError = new Error(
686
+ "[useUpdate]: `id` is not defined but is required in edit and clone actions",
687
+ );
688
+
689
+ const missingValuesError = new Error(
690
+ "[useUpdate]: `values` is not provided but is required",
691
+ );
@@ -1,7 +1,7 @@
1
1
  import { getXRay } from "@refinedev/devtools-internal";
2
2
  import {
3
3
  type UseMutationOptions,
4
- type UseMutationResult,
4
+ type MutateOptions,
5
5
  useMutation,
6
6
  useQueryClient,
7
7
  } from "@tanstack/react-query";
@@ -43,6 +43,7 @@ import type {
43
43
  QueryResponse,
44
44
  UpdateManyResponse,
45
45
  } from "../../contexts/data/types";
46
+ import type { UseMutationResult } from "../../definitions/types";
46
47
  import {
47
48
  type UseLoadingOvertimeOptionsProps,
48
49
  type UseLoadingOvertimeReturnType,
@@ -76,15 +77,15 @@ export type OptimisticUpdateManyMapType<TData, TVariables> = {
76
77
  | boolean;
77
78
  };
78
79
 
79
- type UpdateManyParams<TData, TError, TVariables> = {
80
+ export type UpdateManyParams<TData, TError, TVariables> = {
80
81
  /**
81
82
  * ids for mutation function
82
83
  */
83
- ids: BaseKey[];
84
+ ids?: BaseKey[];
84
85
  /**
85
86
  * Resource name for API data interactions
86
87
  */
87
- resource: string;
88
+ resource?: string;
88
89
  /**
89
90
  * [Determines when mutations are executed](/advanced-tutorials/mutation-mode.md)
90
91
  */
@@ -100,7 +101,7 @@ type UpdateManyParams<TData, TError, TVariables> = {
100
101
  /**
101
102
  * Values for mutation function
102
103
  */
103
- values: TVariables;
104
+ values?: TVariables;
104
105
  /**
105
106
  * meta data for `dataProvider`
106
107
  */
@@ -158,9 +159,10 @@ export type UseUpdateManyProps<
158
159
  UpdateManyParams<TData, TError, TVariables>,
159
160
  UpdateContext<TData>
160
161
  >,
161
- "mutationFn" | "onError" | "onSuccess" | "onSettled" | "onMutate"
162
+ "mutationFn" | "onMutate"
162
163
  >;
163
- } & UseLoadingOvertimeOptionsProps;
164
+ } & UseLoadingOvertimeOptionsProps &
165
+ UpdateManyParams<TData, TError, TVariables>;
164
166
 
165
167
  /**
166
168
  * `useUpdateMany` is a modified version of `react-query`'s {@link https://react-query.tanstack.com/reference/useMutation `useMutation`} for multiple update mutations.
@@ -179,6 +181,19 @@ export const useUpdateMany = <
179
181
  TError extends HttpError = HttpError,
180
182
  TVariables = {},
181
183
  >({
184
+ ids: idsFromProps,
185
+ resource: resourceFromProps,
186
+ values: valuesFromProps,
187
+ dataProviderName: dataProviderNameFromProps,
188
+ successNotification: successNotificationFromProps,
189
+ errorNotification: errorNotificationFromProps,
190
+ meta: metaFromProps,
191
+ metaData: metaDataFromProps,
192
+ mutationMode: mutationModeFromProps,
193
+ undoableTimeout: undoableTimeoutFromProps,
194
+ onCancel: onCancelFromProps,
195
+ optimisticUpdateMap: optimisticUpdateMapFromProps,
196
+ invalidates: invalidatesFromProps,
182
197
  mutationOptions,
183
198
  overtimeOptions,
184
199
  }: UseUpdateManyProps<TData, TError, TVariables> = {}): UseUpdateManyReturnType<
@@ -209,23 +224,27 @@ export const useUpdateMany = <
209
224
  } = useRefineContext();
210
225
  const { keys, preferLegacyKeys } = useKeys();
211
226
 
212
- const mutation = useMutation<
227
+ const mutationResult = useMutation<
213
228
  UpdateManyResponse<TData>,
214
229
  TError,
215
230
  UpdateManyParams<TData, TError, TVariables>,
216
231
  UpdateContext<TData>
217
232
  >({
218
233
  mutationFn: ({
219
- ids,
220
- values,
221
- resource: resourceName,
222
- onCancel,
223
- mutationMode,
224
- undoableTimeout,
225
- meta,
226
- metaData,
227
- dataProviderName,
234
+ ids = idsFromProps,
235
+ values = valuesFromProps,
236
+ resource: resourceName = resourceFromProps,
237
+ onCancel = onCancelFromProps,
238
+ mutationMode = mutationModeFromProps,
239
+ undoableTimeout = undoableTimeoutFromProps,
240
+ meta = metaFromProps,
241
+ metaData = metaDataFromProps,
242
+ dataProviderName = dataProviderNameFromProps,
228
243
  }: UpdateManyParams<TData, TError, TVariables>) => {
244
+ if (!ids) throw missingIdError;
245
+ if (!values) throw missingValuesError;
246
+ if (!resourceName) throw missingResourceError;
247
+
229
248
  const { resource, identifier } = select(resourceName);
230
249
 
231
250
  const combinedMeta = getMeta({
@@ -301,15 +320,23 @@ export const useUpdateMany = <
301
320
  return updatePromise;
302
321
  },
303
322
  onMutate: async ({
304
- resource: resourceName,
305
- ids,
306
- values,
307
- mutationMode,
308
- dataProviderName,
309
- meta,
310
- metaData,
311
- optimisticUpdateMap = { list: true, many: true, detail: true },
323
+ resource: resourceName = resourceFromProps,
324
+ ids = idsFromProps,
325
+ values = valuesFromProps,
326
+ mutationMode = mutationModeFromProps,
327
+ dataProviderName = dataProviderNameFromProps,
328
+ meta = metaFromProps,
329
+ metaData = metaDataFromProps,
330
+ optimisticUpdateMap = optimisticUpdateMapFromProps ?? {
331
+ list: true,
332
+ many: true,
333
+ detail: true,
334
+ },
312
335
  }) => {
336
+ if (!ids) throw missingIdError;
337
+ if (!values) throw missingValuesError;
338
+ if (!resourceName) throw missingResourceError;
339
+
313
340
  const { identifier } = select(resourceName);
314
341
  const {
315
342
  gqlMutation: _,
@@ -454,17 +481,22 @@ export const useUpdateMany = <
454
481
  queryKey,
455
482
  };
456
483
  },
457
- onSettled: (
458
- _data,
459
- _error,
460
- { ids, resource: resourceName, dataProviderName },
461
- ) => {
484
+ onSettled: (data, error, variables, context) => {
485
+ const {
486
+ ids = idsFromProps,
487
+ resource: resourceName = resourceFromProps,
488
+ dataProviderName = dataProviderNameFromProps,
489
+ invalidates = invalidatesFromProps,
490
+ } = variables;
491
+ if (!ids) throw missingIdError;
492
+ if (!resourceName) throw missingResourceError;
493
+
462
494
  const { identifier } = select(resourceName);
463
495
 
464
496
  // invalidate the cache for the list and many queries:
465
497
  invalidateStore({
466
498
  resource: identifier,
467
- invalidates: ["list", "many"],
499
+ invalidates: invalidates ?? ["list", "many"],
468
500
  dataProviderName: pickDataProvider(
469
501
  identifier,
470
502
  dataProviderName,
@@ -475,7 +507,7 @@ export const useUpdateMany = <
475
507
  ids.forEach((id) =>
476
508
  invalidateStore({
477
509
  resource: identifier,
478
- invalidates: ["detail"],
510
+ invalidates: invalidates ?? ["detail"],
479
511
  dataProviderName: pickDataProvider(
480
512
  identifier,
481
513
  dataProviderName,
@@ -489,20 +521,23 @@ export const useUpdateMany = <
489
521
  type: ActionTypes.REMOVE,
490
522
  payload: { id: ids, resource: identifier },
491
523
  });
524
+
525
+ mutationOptions?.onSettled?.(data, error, variables, context);
492
526
  },
493
- onSuccess: (
494
- data,
495
- {
496
- ids,
497
- resource: resourceName,
498
- meta,
499
- metaData,
500
- dataProviderName: dataProviderNameFromProp,
501
- successNotification,
502
- values,
503
- },
504
- context,
505
- ) => {
527
+ onSuccess: (data, variables, context) => {
528
+ const {
529
+ ids = idsFromProps,
530
+ resource: resourceName = resourceFromProps,
531
+ values = valuesFromProps,
532
+ meta = metaFromProps,
533
+ metaData = metaDataFromProps,
534
+ dataProviderName: dataProviderNameFromProp = dataProviderNameFromProps,
535
+ successNotification = successNotificationFromProps,
536
+ } = variables;
537
+ if (!ids) throw missingIdError;
538
+ if (!values) throw missingValuesError;
539
+ if (!resourceName) throw missingResourceError;
540
+
506
541
  const { resource, identifier } = select(resourceName);
507
542
  const resourceSingular = textTransformers.singular(identifier);
508
543
 
@@ -581,12 +616,20 @@ export const useUpdateMany = <
581
616
  ...rest,
582
617
  },
583
618
  });
619
+
620
+ mutationOptions?.onSuccess?.(data, variables, context);
584
621
  },
585
- onError: (
586
- err: TError,
587
- { ids, resource: resourceName, errorNotification, values },
588
- context,
589
- ) => {
622
+ onError: (err: TError, variables, context) => {
623
+ const {
624
+ ids = idsFromProps,
625
+ resource: resourceName = resourceFromProps,
626
+ errorNotification = errorNotificationFromProps,
627
+ values = valuesFromProps,
628
+ } = variables;
629
+ if (!ids) throw missingIdError;
630
+ if (!values) throw missingValuesError;
631
+ if (!resourceName) throw missingResourceError;
632
+
590
633
  const { identifier } = select(resourceName);
591
634
 
592
635
  // set back the queries to the context:
@@ -620,6 +663,8 @@ export const useUpdateMany = <
620
663
  type: "error",
621
664
  });
622
665
  }
666
+
667
+ mutationOptions?.onError?.(err, variables, context);
623
668
  },
624
669
  mutationKey: keys().data().mutation("updateMany").get(preferLegacyKeys),
625
670
  ...mutationOptions,
@@ -628,6 +673,7 @@ export const useUpdateMany = <
628
673
  ...getXRay("useUpdateMany", preferLegacyKeys),
629
674
  },
630
675
  });
676
+ const { mutate, mutateAsync, ...mutation } = mutationResult;
631
677
 
632
678
  const { elapsedTime } = useLoadingOvertime({
633
679
  isLoading: mutation.isLoading,
@@ -635,5 +681,48 @@ export const useUpdateMany = <
635
681
  onInterval: overtimeOptions?.onInterval,
636
682
  });
637
683
 
638
- return { ...mutation, overtime: { elapsedTime } };
684
+ // this function is used to make the `variables` parameter optional
685
+ const handleMutation = (
686
+ variables?: UpdateManyParams<TData, TError, TVariables>,
687
+ options?: MutateOptions<
688
+ UpdateManyResponse<TData>,
689
+ TError,
690
+ UpdateManyParams<TData, TError, TVariables>,
691
+ UpdateContext<TData>
692
+ >,
693
+ ) => {
694
+ return mutate(variables || {}, options);
695
+ };
696
+
697
+ // this function is used to make the `variables` parameter optional
698
+ const handleMutateAsync = (
699
+ variables?: UpdateManyParams<TData, TError, TVariables>,
700
+ options?: MutateOptions<
701
+ UpdateManyResponse<TData>,
702
+ TError,
703
+ UpdateManyParams<TData, TError, TVariables>,
704
+ UpdateContext<TData>
705
+ >,
706
+ ) => {
707
+ return mutateAsync(variables || {}, options);
708
+ };
709
+
710
+ return {
711
+ ...mutation,
712
+ mutate: handleMutation,
713
+ mutateAsync: handleMutateAsync,
714
+ overtime: { elapsedTime },
715
+ };
639
716
  };
717
+
718
+ const missingResourceError = new Error(
719
+ "[useUpdateMany]: `resource` is not defined or not matched but is required",
720
+ );
721
+
722
+ const missingIdError = new Error(
723
+ "[useUpdateMany]: `id` is not defined but is required in edit and clone actions",
724
+ );
725
+
726
+ const missingValuesError = new Error(
727
+ "[useUpdateMany]: `values` is not provided but is required",
728
+ );
@@ -322,7 +322,9 @@ export const useForm = <
322
322
  onFinishAutoSave,
323
323
  formLoading,
324
324
  mutationResult,
325
+ mutation: mutationResult,
325
326
  queryResult,
327
+ query: queryResult,
326
328
  autoSaveProps,
327
329
  id,
328
330
  setId,
@@ -226,7 +226,17 @@ export type UseFormReturnType<
226
226
  > = {
227
227
  id?: BaseKey;
228
228
  setId: Dispatch<SetStateAction<BaseKey | undefined>>;
229
+ query?: QueryObserverResult<GetOneResponse<TData>, TError>;
230
+ /**
231
+ * @deprecated use `query` instead
232
+ */
229
233
  queryResult?: QueryObserverResult<GetOneResponse<TData>, TError>;
234
+ mutation:
235
+ | UseUpdateReturnType<TResponse, TResponseError, TVariables>
236
+ | UseCreateReturnType<TResponse, TResponseError, TVariables>;
237
+ /**
238
+ * @deprecated use `mutation` instead
239
+ */
230
240
  mutationResult:
231
241
  | UseUpdateReturnType<TResponse, TResponseError, TVariables>
232
242
  | UseCreateReturnType<TResponse, TResponseError, TVariables>;
@@ -82,6 +82,7 @@ export const useShow = <
82
82
 
83
83
  return {
84
84
  queryResult,
85
+ query: queryResult,
85
86
  showId,
86
87
  setShowId,
87
88
  overtime: { elapsedTime },
@@ -24,6 +24,10 @@ export type UseShowReturnType<
24
24
  TData extends BaseRecord = BaseRecord,
25
25
  TError extends HttpError = HttpError,
26
26
  > = {
27
+ query: QueryObserverResult<GetOneResponse<TData>, TError>;
28
+ /**
29
+ * @deprecated Use `query` instead.
30
+ */
27
31
  queryResult: QueryObserverResult<GetOneResponse<TData>, TError>;
28
32
  showId?: BaseKey;
29
33
  setShowId: React.Dispatch<React.SetStateAction<BaseKey | undefined>>;