reactjrx 1.60.0 → 1.61.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.
package/dist/index.cjs CHANGED
@@ -481,21 +481,21 @@ function useMutation(options, queryClient) {
481
481
  },
482
482
  [finalQueryClient, key]
483
483
  );
484
- const reset = react.useCallback(() => {
485
- finalQueryClient.mutationClient.reset({
484
+ const cancel = react.useCallback(() => {
485
+ finalQueryClient.mutationClient.cancel({
486
486
  key: optionsRef.current.mutationKey ?? defaultKey.current
487
487
  });
488
488
  }, [finalQueryClient]);
489
489
  react.useEffect(() => {
490
490
  return () => {
491
491
  if (optionsRef.current.cancelOnUnMount) {
492
- finalQueryClient.mutationClient.reset({
492
+ finalQueryClient.mutationClient.cancel({
493
493
  key: optionsRef.current.mutationKey ?? defaultKey.current
494
494
  });
495
495
  }
496
496
  };
497
497
  }, []);
498
- return { mutate, reset, ...result };
498
+ return { mutate, cancel, ...result };
499
499
  }
500
500
  const arrayEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
501
501
  function shallowEqual(objA, objB) {
@@ -1473,7 +1473,9 @@ const mergeResults = (stream$) => stream$.pipe(
1473
1473
  (acc, current) => {
1474
1474
  return {
1475
1475
  ...acc,
1476
- ...current
1476
+ ...current,
1477
+ data: current.data ?? acc.data,
1478
+ error: current.error ?? acc.error
1477
1479
  };
1478
1480
  },
1479
1481
  {
@@ -1486,25 +1488,99 @@ const mergeResults = (stream$) => stream$.pipe(
1486
1488
  ({ data: prevData, ...prev }, { data: currData, ...curr }) => shallowEqual(prev, curr) && shallowEqual(prevData, currData)
1487
1489
  )
1488
1490
  );
1491
+ const getDefaultMutationState = () => ({
1492
+ context: {},
1493
+ data: void 0,
1494
+ error: null,
1495
+ status: "idle",
1496
+ submittedAt: 0,
1497
+ variables: void 0
1498
+ });
1499
+ class Mutation {
1500
+ constructor({
1501
+ args,
1502
+ ...options
1503
+ }) {
1504
+ __publicField(this, "stateSubject", new rxjs.BehaviorSubject(
1505
+ getDefaultMutationState()
1506
+ ));
1507
+ /**
1508
+ * @important
1509
+ * proxy for rect-query, not really useful
1510
+ */
1511
+ __publicField(this, "state", this.stateSubject.getValue());
1512
+ __publicField(this, "options");
1513
+ __publicField(this, "mutation$");
1514
+ this.options = options;
1515
+ const mutationFn = options.mutationFn;
1516
+ this.state.variables = args;
1517
+ this.stateSubject.next(this.state);
1518
+ const mutationFnObservable = typeof mutationFn === "function" ? rxjs.defer(() => rxjs.from(mutationFn(args))) : mutationFn;
1519
+ const queryRunner$ = mutationFnObservable.pipe(
1520
+ retryOnError(options),
1521
+ rxjs.take(1),
1522
+ rxjs.map((data) => ({ data, isError: false })),
1523
+ rxjs.catchError((error) => {
1524
+ console.error(error);
1525
+ if (options.onError != null) {
1526
+ options.onError(error, args);
1527
+ }
1528
+ return rxjs.of({ data: error, isError: true });
1529
+ })
1530
+ );
1531
+ const loading$ = rxjs.of({
1532
+ status: "pending"
1533
+ });
1534
+ this.mutation$ = rxjs.merge(
1535
+ loading$,
1536
+ queryRunner$.pipe(
1537
+ rxjs.map(({ data, isError }) => {
1538
+ if (!isError) {
1539
+ if (options.onSuccess != null)
1540
+ options.onSuccess(data, args);
1541
+ }
1542
+ return isError ? {
1543
+ status: "error",
1544
+ error: data,
1545
+ data: void 0
1546
+ } : {
1547
+ status: "success",
1548
+ error: null,
1549
+ data
1550
+ };
1551
+ })
1552
+ )
1553
+ ).pipe(
1554
+ mergeResults,
1555
+ rxjs.tap((value) => {
1556
+ this.state = { ...this.state, ...value };
1557
+ this.stateSubject.next(this.state);
1558
+ }),
1559
+ options.__queryRunnerHook ?? rxjs.identity,
1560
+ rxjs.share()
1561
+ );
1562
+ }
1563
+ }
1489
1564
  const createMutationRunner = ({
1490
1565
  __queryFinalizeHook,
1491
1566
  __queryInitHook,
1492
1567
  __queryTriggerHook
1493
1568
  }) => {
1494
1569
  const trigger$ = new rxjs.Subject();
1495
- const reset$ = new rxjs.Subject();
1570
+ const cancel$ = new rxjs.Subject();
1496
1571
  let closed = false;
1497
1572
  const mapOperator$ = new rxjs.BehaviorSubject("merge");
1498
- const mutationsRunning$ = new rxjs.BehaviorSubject(0);
1573
+ const mutationsSubject = new rxjs.BehaviorSubject([]);
1499
1574
  const destroy = () => {
1500
1575
  if (closed) {
1501
1576
  throw new Error("Trying to close an already closed mutation");
1502
1577
  }
1503
1578
  closed = true;
1504
1579
  mapOperator$.complete();
1505
- mutationsRunning$.complete();
1580
+ mutationsSubject.complete();
1506
1581
  trigger$.complete();
1507
- reset$.complete();
1582
+ cancel$.next();
1583
+ cancel$.complete();
1508
1584
  };
1509
1585
  const stableMapOperator$ = mapOperator$.pipe(
1510
1586
  rxjs.filter(isDefined),
@@ -1514,29 +1590,35 @@ const createMutationRunner = ({
1514
1590
  __queryInitHook ?? rxjs.identity,
1515
1591
  rxjs.mergeMap((mapOperator) => {
1516
1592
  const switchOperator = mapOperator === "concat" ? rxjs.concatMap : mapOperator === "switch" ? rxjs.switchMap : rxjs.mergeMap;
1593
+ let mutationsForCurrentMapOperatorSubject = [];
1594
+ const removeMutation = (mutation) => {
1595
+ mutationsForCurrentMapOperatorSubject = mutationsForCurrentMapOperatorSubject.filter(
1596
+ (item) => item !== mutation
1597
+ );
1598
+ mutationsSubject.next(
1599
+ mutationsSubject.getValue().filter((item) => item !== mutation)
1600
+ );
1601
+ };
1517
1602
  return trigger$.pipe(
1518
1603
  rxjs.takeUntil(stableMapOperator$.pipe(rxjs.skip(1))),
1519
- rxjs.tap(() => {
1520
- mutationsRunning$.next(mutationsRunning$.getValue() + 1);
1604
+ rxjs.map(({ args, options }) => {
1605
+ const mutation = new Mutation({
1606
+ args,
1607
+ ...options,
1608
+ mapOperator
1609
+ });
1610
+ mutationsForCurrentMapOperatorSubject = [
1611
+ ...mutationsForCurrentMapOperatorSubject,
1612
+ mutation
1613
+ ];
1614
+ mutationsSubject.next([...mutationsSubject.getValue(), mutation]);
1615
+ return mutation;
1521
1616
  }),
1522
- switchOperator(({ args, options }) => {
1523
- const mutationFn = options.mutationFn;
1524
- const mutationFnObservable = typeof mutationFn === "function" ? rxjs.defer(() => rxjs.from(mutationFn(args))) : mutationFn;
1525
- const queryRunner$ = mutationFnObservable.pipe(
1526
- retryOnError(options),
1527
- rxjs.take(1),
1528
- rxjs.map((data) => ({ data, isError: false })),
1529
- rxjs.catchError((error) => {
1530
- console.error(error);
1531
- if (options.onError != null) {
1532
- options.onError(error, args);
1533
- }
1534
- return rxjs.of({ data: error, isError: true });
1535
- }),
1536
- rxjs.share()
1537
- );
1538
- const queryIsOver$ = queryRunner$.pipe(
1539
- rxjs.map(({ data, isError }) => isError || data)
1617
+ switchOperator((mutation) => {
1618
+ if (!mutationsSubject.getValue().includes(mutation))
1619
+ return rxjs.of({});
1620
+ const queryIsOver$ = mutation.mutation$.pipe(
1621
+ rxjs.map(({ data, error }) => error || data)
1540
1622
  );
1541
1623
  const isThisCurrentFunctionLastOneCalled = trigger$.pipe(
1542
1624
  rxjs.take(1),
@@ -1544,48 +1626,35 @@ const createMutationRunner = ({
1544
1626
  rxjs.startWith(true),
1545
1627
  rxjs.takeUntil(queryIsOver$)
1546
1628
  );
1547
- const loading$ = rxjs.of({
1548
- status: "pending"
1549
- });
1550
- return rxjs.merge(
1551
- loading$,
1552
- rxjs.combineLatest([
1553
- queryRunner$,
1554
- isThisCurrentFunctionLastOneCalled
1555
- ]).pipe(
1556
- rxjs.map(([{ data, isError }, isLastMutationCalled]) => {
1557
- if (!isError) {
1558
- if (options.onSuccess != null)
1559
- options.onSuccess(data, args);
1560
- }
1561
- if (isLastMutationCalled) {
1562
- return isError ? {
1563
- status: "error",
1564
- error: data,
1565
- data: void 0
1566
- } : {
1567
- status: "success",
1568
- error: void 0,
1569
- data
1570
- };
1571
- }
1629
+ const result$ = rxjs.combineLatest([
1630
+ mutation.mutation$,
1631
+ isThisCurrentFunctionLastOneCalled
1632
+ ]).pipe(
1633
+ rxjs.map(([result, isLastMutationCalled]) => {
1634
+ if ((result.status === "success" || result.status === "error") && !isLastMutationCalled) {
1572
1635
  return {};
1573
- }),
1574
- rxjs.takeUntil(reset$)
1575
- )
1576
- ).pipe(
1577
- options.__queryRunnerHook ?? rxjs.identity,
1636
+ }
1637
+ return result;
1638
+ }),
1639
+ rxjs.takeUntil(cancel$.pipe()),
1640
+ mergeResults,
1578
1641
  rxjs.finalize(() => {
1579
- mutationsRunning$.next(mutationsRunning$.getValue() - 1);
1642
+ removeMutation(mutation);
1580
1643
  })
1581
1644
  );
1645
+ return result$;
1582
1646
  }),
1583
- __queryTriggerHook ?? rxjs.identity,
1584
- mergeResults
1647
+ mergeResults,
1648
+ __queryTriggerHook ?? rxjs.identity
1585
1649
  );
1586
1650
  }),
1587
1651
  __queryFinalizeHook ?? rxjs.identity
1588
1652
  );
1653
+ cancel$.subscribe(() => {
1654
+ if (mutationsSubject.getValue().length === 0)
1655
+ return;
1656
+ mutationsSubject.next([]);
1657
+ });
1589
1658
  return {
1590
1659
  mutation$,
1591
1660
  trigger: ({
@@ -1595,12 +1664,29 @@ const createMutationRunner = ({
1595
1664
  mapOperator$.next(options.mapOperator);
1596
1665
  trigger$.next({ args, options });
1597
1666
  },
1598
- reset$,
1667
+ cancel$,
1599
1668
  destroy,
1600
- mutationsRunning$,
1669
+ mutationsSubject,
1601
1670
  getClosed: () => closed
1602
1671
  };
1603
1672
  };
1673
+ const createPredicateForFilters = ({
1674
+ mutationKey,
1675
+ status,
1676
+ predicate
1677
+ } = {}) => {
1678
+ const defaultPredicate = (mutation) => {
1679
+ if (mutationKey !== void 0 && // @todo optimize
1680
+ serializeKey(mutation.options.mutationKey) !== serializeKey(mutationKey)) {
1681
+ return false;
1682
+ }
1683
+ if (status && mutation.stateSubject.getValue().status !== status)
1684
+ return false;
1685
+ return true;
1686
+ };
1687
+ const finalPredicate = predicate ?? defaultPredicate;
1688
+ return finalPredicate;
1689
+ };
1604
1690
  class MutationClient {
1605
1691
  constructor() {
1606
1692
  /**
@@ -1620,11 +1706,15 @@ class MutationClient {
1620
1706
  */
1621
1707
  __publicField(this, "mutationResults$", new rxjs.BehaviorSubject(/* @__PURE__ */ new Map()));
1622
1708
  __publicField(this, "mutate$", new rxjs.Subject());
1623
- __publicField(this, "reset$", new rxjs.Subject());
1709
+ __publicField(this, "cancel$", new rxjs.Subject());
1624
1710
  /**
1625
1711
  * Observable to track how many running mutations per runner
1626
1712
  */
1627
1713
  __publicField(this, "isMutatingSubject", new rxjs.BehaviorSubject([]));
1714
+ /**
1715
+ * List of all mutations running
1716
+ */
1717
+ __publicField(this, "mutationsSubject", new rxjs.BehaviorSubject([]));
1628
1718
  this.mutate$.pipe(
1629
1719
  rxjs.tap(({ options, args }) => {
1630
1720
  const { mutationKey } = options;
@@ -1649,9 +1739,10 @@ class MutationClient {
1649
1739
  resultForKeySubject == null ? void 0 : resultForKeySubject.next(result);
1650
1740
  }
1651
1741
  });
1652
- mutationForKey.mutationsRunning$.pipe(
1742
+ mutationForKey.mutationsSubject.pipe(
1743
+ rxjs.distinctUntilChanged(shallowEqual),
1653
1744
  rxjs.skip(1),
1654
- rxjs.filter((number) => number === 0)
1745
+ rxjs.filter((items) => items.length === 0)
1655
1746
  ).subscribe(() => {
1656
1747
  mutationForKey == null ? void 0 : mutationForKey.destroy();
1657
1748
  const resultMap = this.mutationResults$.getValue();
@@ -1663,28 +1754,32 @@ class MutationClient {
1663
1754
  mutationForKey.trigger({ args, options });
1664
1755
  })
1665
1756
  ).subscribe();
1666
- this.reset$.pipe(
1757
+ this.cancel$.pipe(
1667
1758
  rxjs.tap(({ key }) => {
1668
1759
  var _a;
1669
1760
  const serializedKey = serializeKey(key);
1670
- (_a = this.mutationRunnersByKey$.getValue().get(serializedKey)) == null ? void 0 : _a.reset$.next();
1761
+ (_a = this.mutationRunnersByKey$.getValue().get(serializedKey)) == null ? void 0 : _a.cancel$.next();
1671
1762
  })
1672
1763
  ).subscribe();
1673
1764
  this.mutationRunnersByKey$.pipe(
1674
1765
  rxjs.switchMap((mapItem) => {
1675
- const mutationRunners = Array.from(mapItem.entries()).map(
1676
- ([, value]) => value.mutationsRunning$.pipe(
1677
- rxjs.map((number) => [value.mutationKey, number])
1766
+ const mutationRunners = Array.from(mapItem.values());
1767
+ const mutations$ = rxjs.combineLatest(
1768
+ mutationRunners.map(
1769
+ (runner) => runner.mutationsSubject.pipe(
1770
+ rxjs.map((mutations) => mutations.map((mutation) => mutation))
1771
+ )
1678
1772
  )
1679
1773
  );
1680
- const mutationRunnersMutationsRunning$ = rxjs.combineLatest([
1681
- // when map is empty we still need to push 0
1682
- rxjs.of([[], 0]),
1683
- ...mutationRunners
1684
- ]);
1685
- return mutationRunnersMutationsRunning$;
1686
- })
1687
- ).subscribe(this.isMutatingSubject);
1774
+ return mutations$.pipe(
1775
+ rxjs.map(
1776
+ (mutationsByKeys) => mutationsByKeys.reduce((acc, value) => [...acc, ...value], [])
1777
+ )
1778
+ );
1779
+ }),
1780
+ rxjs.startWith([]),
1781
+ rxjs.distinctUntilChanged(shallowEqual)
1782
+ ).subscribe(this.mutationsSubject);
1688
1783
  }
1689
1784
  /**
1690
1785
  * @helper
@@ -1708,22 +1803,48 @@ class MutationClient {
1708
1803
  getMutationRunnersByKey(key) {
1709
1804
  return this.mutationRunnersByKey$.getValue().get(key);
1710
1805
  }
1711
- useIsMutating({ mutationKey, predicate } = {}) {
1712
- const defaultPredicate = ({ options }) => mutationKey ? (
1713
- // @todo optimize
1714
- serializeKey(options.mutationKey) === serializeKey(mutationKey)
1715
- ) : true;
1716
- const finalPredicate = predicate ?? defaultPredicate;
1717
- const reduceByNumber = (entries) => entries.reduce((acc, [mutationKey2, value]) => {
1718
- return finalPredicate({ options: { mutationKey: mutationKey2 } }) ? value + acc : acc;
1806
+ useIsMutating(filters = {}) {
1807
+ const predicate = createPredicateForFilters(filters);
1808
+ const reduceByNumber = (entries) => entries.reduce((acc, mutation) => {
1809
+ return predicate(mutation) && mutation.stateSubject.getValue().status === "pending" ? 1 + acc : acc;
1719
1810
  }, 0);
1720
- const lastValue = reduceByNumber(this.isMutatingSubject.getValue());
1721
- const value$ = this.isMutatingSubject.pipe(
1722
- rxjs.map((mutationRunningByKeys) => reduceByNumber(mutationRunningByKeys)),
1811
+ const lastValue = reduceByNumber(this.mutationsSubject.getValue());
1812
+ const value$ = this.mutationsSubject.pipe(
1813
+ rxjs.switchMap((mutations) => {
1814
+ const mutationsOnStateUpdate = mutations.map(
1815
+ (mutation) => mutation.stateSubject.pipe(rxjs.map(() => mutation))
1816
+ );
1817
+ return mutationsOnStateUpdate.length === 0 ? rxjs.of([]) : rxjs.combineLatest(mutationsOnStateUpdate);
1818
+ }),
1819
+ rxjs.map(reduceByNumber),
1723
1820
  rxjs.distinctUntilChanged()
1724
1821
  );
1725
1822
  return { value$, lastValue };
1726
1823
  }
1824
+ mutationState({
1825
+ filters,
1826
+ select
1827
+ } = {}) {
1828
+ const predicate = createPredicateForFilters(filters);
1829
+ const finalSelect = select ?? ((mutation) => mutation.stateSubject.getValue());
1830
+ const lastValue = this.mutationsSubject.getValue().reduce((acc, mutation) => {
1831
+ const result = [...acc, mutation];
1832
+ return result;
1833
+ }, []).filter(predicate).map((mutation) => finalSelect(mutation));
1834
+ const value$ = this.mutationsSubject.pipe(
1835
+ rxjs.switchMap((mutations) => {
1836
+ const mutationsOnStateUpdate = mutations.map(
1837
+ (mutation) => mutation.stateSubject.pipe(
1838
+ rxjs.filter(() => predicate(mutation)),
1839
+ rxjs.map(() => finalSelect(mutation))
1840
+ )
1841
+ );
1842
+ return mutationsOnStateUpdate.length === 0 ? rxjs.of([]) : rxjs.combineLatest(mutationsOnStateUpdate);
1843
+ }),
1844
+ rxjs.distinctUntilChanged(shallowEqual)
1845
+ );
1846
+ return { value$, lastValue };
1847
+ }
1727
1848
  observe({ key }) {
1728
1849
  var _a;
1729
1850
  const currentResultValue = (_a = this.mutationResults$.getValue().get(key)) == null ? void 0 : _a.getValue();
@@ -1762,18 +1883,19 @@ class MutationClient {
1762
1883
  this.mutate$.next(params);
1763
1884
  }
1764
1885
  /**
1765
- * This will reset any current mutation runnings.
1886
+ * This will cancel any current mutation runnings.
1766
1887
  * No discrimination process
1767
1888
  */
1768
- reset(params) {
1769
- this.reset$.next(params);
1889
+ cancel(params) {
1890
+ this.cancel$.next(params);
1770
1891
  }
1771
1892
  destroy() {
1772
- this.reset$.complete();
1893
+ this.cancel$.complete();
1773
1894
  this.mutate$.complete();
1774
1895
  this.mutationResults$.complete();
1775
1896
  this.mutationRunnersByKey$.complete();
1776
1897
  this.isMutatingSubject.complete();
1898
+ this.mutationsSubject.complete();
1777
1899
  }
1778
1900
  }
1779
1901
  const createClient = () => {
package/dist/index.js CHANGED
@@ -479,21 +479,21 @@ function useMutation(options, queryClient) {
479
479
  },
480
480
  [finalQueryClient, key]
481
481
  );
482
- const reset = useCallback(() => {
483
- finalQueryClient.mutationClient.reset({
482
+ const cancel = useCallback(() => {
483
+ finalQueryClient.mutationClient.cancel({
484
484
  key: optionsRef.current.mutationKey ?? defaultKey.current
485
485
  });
486
486
  }, [finalQueryClient]);
487
487
  useEffect(() => {
488
488
  return () => {
489
489
  if (optionsRef.current.cancelOnUnMount) {
490
- finalQueryClient.mutationClient.reset({
490
+ finalQueryClient.mutationClient.cancel({
491
491
  key: optionsRef.current.mutationKey ?? defaultKey.current
492
492
  });
493
493
  }
494
494
  };
495
495
  }, []);
496
- return { mutate, reset, ...result };
496
+ return { mutate, cancel, ...result };
497
497
  }
498
498
  const arrayEqual = (a, b) => a.length === b.length && a.every((v, i) => v === b[i]);
499
499
  function shallowEqual(objA, objB) {
@@ -1471,7 +1471,9 @@ const mergeResults = (stream$) => stream$.pipe(
1471
1471
  (acc, current) => {
1472
1472
  return {
1473
1473
  ...acc,
1474
- ...current
1474
+ ...current,
1475
+ data: current.data ?? acc.data,
1476
+ error: current.error ?? acc.error
1475
1477
  };
1476
1478
  },
1477
1479
  {
@@ -1484,25 +1486,99 @@ const mergeResults = (stream$) => stream$.pipe(
1484
1486
  ({ data: prevData, ...prev }, { data: currData, ...curr }) => shallowEqual(prev, curr) && shallowEqual(prevData, currData)
1485
1487
  )
1486
1488
  );
1489
+ const getDefaultMutationState = () => ({
1490
+ context: {},
1491
+ data: void 0,
1492
+ error: null,
1493
+ status: "idle",
1494
+ submittedAt: 0,
1495
+ variables: void 0
1496
+ });
1497
+ class Mutation {
1498
+ constructor({
1499
+ args,
1500
+ ...options
1501
+ }) {
1502
+ __publicField(this, "stateSubject", new BehaviorSubject(
1503
+ getDefaultMutationState()
1504
+ ));
1505
+ /**
1506
+ * @important
1507
+ * proxy for rect-query, not really useful
1508
+ */
1509
+ __publicField(this, "state", this.stateSubject.getValue());
1510
+ __publicField(this, "options");
1511
+ __publicField(this, "mutation$");
1512
+ this.options = options;
1513
+ const mutationFn = options.mutationFn;
1514
+ this.state.variables = args;
1515
+ this.stateSubject.next(this.state);
1516
+ const mutationFnObservable = typeof mutationFn === "function" ? defer(() => from(mutationFn(args))) : mutationFn;
1517
+ const queryRunner$ = mutationFnObservable.pipe(
1518
+ retryOnError(options),
1519
+ take(1),
1520
+ map((data) => ({ data, isError: false })),
1521
+ catchError((error) => {
1522
+ console.error(error);
1523
+ if (options.onError != null) {
1524
+ options.onError(error, args);
1525
+ }
1526
+ return of({ data: error, isError: true });
1527
+ })
1528
+ );
1529
+ const loading$ = of({
1530
+ status: "pending"
1531
+ });
1532
+ this.mutation$ = merge(
1533
+ loading$,
1534
+ queryRunner$.pipe(
1535
+ map(({ data, isError }) => {
1536
+ if (!isError) {
1537
+ if (options.onSuccess != null)
1538
+ options.onSuccess(data, args);
1539
+ }
1540
+ return isError ? {
1541
+ status: "error",
1542
+ error: data,
1543
+ data: void 0
1544
+ } : {
1545
+ status: "success",
1546
+ error: null,
1547
+ data
1548
+ };
1549
+ })
1550
+ )
1551
+ ).pipe(
1552
+ mergeResults,
1553
+ tap((value) => {
1554
+ this.state = { ...this.state, ...value };
1555
+ this.stateSubject.next(this.state);
1556
+ }),
1557
+ options.__queryRunnerHook ?? identity,
1558
+ share()
1559
+ );
1560
+ }
1561
+ }
1487
1562
  const createMutationRunner = ({
1488
1563
  __queryFinalizeHook,
1489
1564
  __queryInitHook,
1490
1565
  __queryTriggerHook
1491
1566
  }) => {
1492
1567
  const trigger$ = new Subject();
1493
- const reset$ = new Subject();
1568
+ const cancel$ = new Subject();
1494
1569
  let closed = false;
1495
1570
  const mapOperator$ = new BehaviorSubject("merge");
1496
- const mutationsRunning$ = new BehaviorSubject(0);
1571
+ const mutationsSubject = new BehaviorSubject([]);
1497
1572
  const destroy = () => {
1498
1573
  if (closed) {
1499
1574
  throw new Error("Trying to close an already closed mutation");
1500
1575
  }
1501
1576
  closed = true;
1502
1577
  mapOperator$.complete();
1503
- mutationsRunning$.complete();
1578
+ mutationsSubject.complete();
1504
1579
  trigger$.complete();
1505
- reset$.complete();
1580
+ cancel$.next();
1581
+ cancel$.complete();
1506
1582
  };
1507
1583
  const stableMapOperator$ = mapOperator$.pipe(
1508
1584
  filter(isDefined),
@@ -1512,29 +1588,35 @@ const createMutationRunner = ({
1512
1588
  __queryInitHook ?? identity,
1513
1589
  mergeMap((mapOperator) => {
1514
1590
  const switchOperator = mapOperator === "concat" ? concatMap$1 : mapOperator === "switch" ? switchMap : mergeMap;
1591
+ let mutationsForCurrentMapOperatorSubject = [];
1592
+ const removeMutation = (mutation) => {
1593
+ mutationsForCurrentMapOperatorSubject = mutationsForCurrentMapOperatorSubject.filter(
1594
+ (item) => item !== mutation
1595
+ );
1596
+ mutationsSubject.next(
1597
+ mutationsSubject.getValue().filter((item) => item !== mutation)
1598
+ );
1599
+ };
1515
1600
  return trigger$.pipe(
1516
1601
  takeUntil(stableMapOperator$.pipe(skip(1))),
1517
- tap(() => {
1518
- mutationsRunning$.next(mutationsRunning$.getValue() + 1);
1602
+ map(({ args, options }) => {
1603
+ const mutation = new Mutation({
1604
+ args,
1605
+ ...options,
1606
+ mapOperator
1607
+ });
1608
+ mutationsForCurrentMapOperatorSubject = [
1609
+ ...mutationsForCurrentMapOperatorSubject,
1610
+ mutation
1611
+ ];
1612
+ mutationsSubject.next([...mutationsSubject.getValue(), mutation]);
1613
+ return mutation;
1519
1614
  }),
1520
- switchOperator(({ args, options }) => {
1521
- const mutationFn = options.mutationFn;
1522
- const mutationFnObservable = typeof mutationFn === "function" ? defer(() => from(mutationFn(args))) : mutationFn;
1523
- const queryRunner$ = mutationFnObservable.pipe(
1524
- retryOnError(options),
1525
- take(1),
1526
- map((data) => ({ data, isError: false })),
1527
- catchError((error) => {
1528
- console.error(error);
1529
- if (options.onError != null) {
1530
- options.onError(error, args);
1531
- }
1532
- return of({ data: error, isError: true });
1533
- }),
1534
- share()
1535
- );
1536
- const queryIsOver$ = queryRunner$.pipe(
1537
- map(({ data, isError }) => isError || data)
1615
+ switchOperator((mutation) => {
1616
+ if (!mutationsSubject.getValue().includes(mutation))
1617
+ return of({});
1618
+ const queryIsOver$ = mutation.mutation$.pipe(
1619
+ map(({ data, error }) => error || data)
1538
1620
  );
1539
1621
  const isThisCurrentFunctionLastOneCalled = trigger$.pipe(
1540
1622
  take(1),
@@ -1542,48 +1624,35 @@ const createMutationRunner = ({
1542
1624
  startWith(true),
1543
1625
  takeUntil(queryIsOver$)
1544
1626
  );
1545
- const loading$ = of({
1546
- status: "pending"
1547
- });
1548
- return merge(
1549
- loading$,
1550
- combineLatest([
1551
- queryRunner$,
1552
- isThisCurrentFunctionLastOneCalled
1553
- ]).pipe(
1554
- map(([{ data, isError }, isLastMutationCalled]) => {
1555
- if (!isError) {
1556
- if (options.onSuccess != null)
1557
- options.onSuccess(data, args);
1558
- }
1559
- if (isLastMutationCalled) {
1560
- return isError ? {
1561
- status: "error",
1562
- error: data,
1563
- data: void 0
1564
- } : {
1565
- status: "success",
1566
- error: void 0,
1567
- data
1568
- };
1569
- }
1627
+ const result$ = combineLatest([
1628
+ mutation.mutation$,
1629
+ isThisCurrentFunctionLastOneCalled
1630
+ ]).pipe(
1631
+ map(([result, isLastMutationCalled]) => {
1632
+ if ((result.status === "success" || result.status === "error") && !isLastMutationCalled) {
1570
1633
  return {};
1571
- }),
1572
- takeUntil(reset$)
1573
- )
1574
- ).pipe(
1575
- options.__queryRunnerHook ?? identity,
1634
+ }
1635
+ return result;
1636
+ }),
1637
+ takeUntil(cancel$.pipe()),
1638
+ mergeResults,
1576
1639
  finalize(() => {
1577
- mutationsRunning$.next(mutationsRunning$.getValue() - 1);
1640
+ removeMutation(mutation);
1578
1641
  })
1579
1642
  );
1643
+ return result$;
1580
1644
  }),
1581
- __queryTriggerHook ?? identity,
1582
- mergeResults
1645
+ mergeResults,
1646
+ __queryTriggerHook ?? identity
1583
1647
  );
1584
1648
  }),
1585
1649
  __queryFinalizeHook ?? identity
1586
1650
  );
1651
+ cancel$.subscribe(() => {
1652
+ if (mutationsSubject.getValue().length === 0)
1653
+ return;
1654
+ mutationsSubject.next([]);
1655
+ });
1587
1656
  return {
1588
1657
  mutation$,
1589
1658
  trigger: ({
@@ -1593,12 +1662,29 @@ const createMutationRunner = ({
1593
1662
  mapOperator$.next(options.mapOperator);
1594
1663
  trigger$.next({ args, options });
1595
1664
  },
1596
- reset$,
1665
+ cancel$,
1597
1666
  destroy,
1598
- mutationsRunning$,
1667
+ mutationsSubject,
1599
1668
  getClosed: () => closed
1600
1669
  };
1601
1670
  };
1671
+ const createPredicateForFilters = ({
1672
+ mutationKey,
1673
+ status,
1674
+ predicate
1675
+ } = {}) => {
1676
+ const defaultPredicate = (mutation) => {
1677
+ if (mutationKey !== void 0 && // @todo optimize
1678
+ serializeKey(mutation.options.mutationKey) !== serializeKey(mutationKey)) {
1679
+ return false;
1680
+ }
1681
+ if (status && mutation.stateSubject.getValue().status !== status)
1682
+ return false;
1683
+ return true;
1684
+ };
1685
+ const finalPredicate = predicate ?? defaultPredicate;
1686
+ return finalPredicate;
1687
+ };
1602
1688
  class MutationClient {
1603
1689
  constructor() {
1604
1690
  /**
@@ -1618,11 +1704,15 @@ class MutationClient {
1618
1704
  */
1619
1705
  __publicField(this, "mutationResults$", new BehaviorSubject(/* @__PURE__ */ new Map()));
1620
1706
  __publicField(this, "mutate$", new Subject());
1621
- __publicField(this, "reset$", new Subject());
1707
+ __publicField(this, "cancel$", new Subject());
1622
1708
  /**
1623
1709
  * Observable to track how many running mutations per runner
1624
1710
  */
1625
1711
  __publicField(this, "isMutatingSubject", new BehaviorSubject([]));
1712
+ /**
1713
+ * List of all mutations running
1714
+ */
1715
+ __publicField(this, "mutationsSubject", new BehaviorSubject([]));
1626
1716
  this.mutate$.pipe(
1627
1717
  tap(({ options, args }) => {
1628
1718
  const { mutationKey } = options;
@@ -1647,9 +1737,10 @@ class MutationClient {
1647
1737
  resultForKeySubject == null ? void 0 : resultForKeySubject.next(result);
1648
1738
  }
1649
1739
  });
1650
- mutationForKey.mutationsRunning$.pipe(
1740
+ mutationForKey.mutationsSubject.pipe(
1741
+ distinctUntilChanged(shallowEqual),
1651
1742
  skip(1),
1652
- filter((number) => number === 0)
1743
+ filter((items) => items.length === 0)
1653
1744
  ).subscribe(() => {
1654
1745
  mutationForKey == null ? void 0 : mutationForKey.destroy();
1655
1746
  const resultMap = this.mutationResults$.getValue();
@@ -1661,28 +1752,32 @@ class MutationClient {
1661
1752
  mutationForKey.trigger({ args, options });
1662
1753
  })
1663
1754
  ).subscribe();
1664
- this.reset$.pipe(
1755
+ this.cancel$.pipe(
1665
1756
  tap(({ key }) => {
1666
1757
  var _a;
1667
1758
  const serializedKey = serializeKey(key);
1668
- (_a = this.mutationRunnersByKey$.getValue().get(serializedKey)) == null ? void 0 : _a.reset$.next();
1759
+ (_a = this.mutationRunnersByKey$.getValue().get(serializedKey)) == null ? void 0 : _a.cancel$.next();
1669
1760
  })
1670
1761
  ).subscribe();
1671
1762
  this.mutationRunnersByKey$.pipe(
1672
1763
  switchMap((mapItem) => {
1673
- const mutationRunners = Array.from(mapItem.entries()).map(
1674
- ([, value]) => value.mutationsRunning$.pipe(
1675
- map((number) => [value.mutationKey, number])
1764
+ const mutationRunners = Array.from(mapItem.values());
1765
+ const mutations$ = combineLatest(
1766
+ mutationRunners.map(
1767
+ (runner) => runner.mutationsSubject.pipe(
1768
+ map((mutations) => mutations.map((mutation) => mutation))
1769
+ )
1676
1770
  )
1677
1771
  );
1678
- const mutationRunnersMutationsRunning$ = combineLatest([
1679
- // when map is empty we still need to push 0
1680
- of([[], 0]),
1681
- ...mutationRunners
1682
- ]);
1683
- return mutationRunnersMutationsRunning$;
1684
- })
1685
- ).subscribe(this.isMutatingSubject);
1772
+ return mutations$.pipe(
1773
+ map(
1774
+ (mutationsByKeys) => mutationsByKeys.reduce((acc, value) => [...acc, ...value], [])
1775
+ )
1776
+ );
1777
+ }),
1778
+ startWith([]),
1779
+ distinctUntilChanged(shallowEqual)
1780
+ ).subscribe(this.mutationsSubject);
1686
1781
  }
1687
1782
  /**
1688
1783
  * @helper
@@ -1706,22 +1801,48 @@ class MutationClient {
1706
1801
  getMutationRunnersByKey(key) {
1707
1802
  return this.mutationRunnersByKey$.getValue().get(key);
1708
1803
  }
1709
- useIsMutating({ mutationKey, predicate } = {}) {
1710
- const defaultPredicate = ({ options }) => mutationKey ? (
1711
- // @todo optimize
1712
- serializeKey(options.mutationKey) === serializeKey(mutationKey)
1713
- ) : true;
1714
- const finalPredicate = predicate ?? defaultPredicate;
1715
- const reduceByNumber = (entries) => entries.reduce((acc, [mutationKey2, value]) => {
1716
- return finalPredicate({ options: { mutationKey: mutationKey2 } }) ? value + acc : acc;
1804
+ useIsMutating(filters = {}) {
1805
+ const predicate = createPredicateForFilters(filters);
1806
+ const reduceByNumber = (entries) => entries.reduce((acc, mutation) => {
1807
+ return predicate(mutation) && mutation.stateSubject.getValue().status === "pending" ? 1 + acc : acc;
1717
1808
  }, 0);
1718
- const lastValue = reduceByNumber(this.isMutatingSubject.getValue());
1719
- const value$ = this.isMutatingSubject.pipe(
1720
- map((mutationRunningByKeys) => reduceByNumber(mutationRunningByKeys)),
1809
+ const lastValue = reduceByNumber(this.mutationsSubject.getValue());
1810
+ const value$ = this.mutationsSubject.pipe(
1811
+ switchMap((mutations) => {
1812
+ const mutationsOnStateUpdate = mutations.map(
1813
+ (mutation) => mutation.stateSubject.pipe(map(() => mutation))
1814
+ );
1815
+ return mutationsOnStateUpdate.length === 0 ? of([]) : combineLatest(mutationsOnStateUpdate);
1816
+ }),
1817
+ map(reduceByNumber),
1721
1818
  distinctUntilChanged()
1722
1819
  );
1723
1820
  return { value$, lastValue };
1724
1821
  }
1822
+ mutationState({
1823
+ filters,
1824
+ select
1825
+ } = {}) {
1826
+ const predicate = createPredicateForFilters(filters);
1827
+ const finalSelect = select ?? ((mutation) => mutation.stateSubject.getValue());
1828
+ const lastValue = this.mutationsSubject.getValue().reduce((acc, mutation) => {
1829
+ const result = [...acc, mutation];
1830
+ return result;
1831
+ }, []).filter(predicate).map((mutation) => finalSelect(mutation));
1832
+ const value$ = this.mutationsSubject.pipe(
1833
+ switchMap((mutations) => {
1834
+ const mutationsOnStateUpdate = mutations.map(
1835
+ (mutation) => mutation.stateSubject.pipe(
1836
+ filter(() => predicate(mutation)),
1837
+ map(() => finalSelect(mutation))
1838
+ )
1839
+ );
1840
+ return mutationsOnStateUpdate.length === 0 ? of([]) : combineLatest(mutationsOnStateUpdate);
1841
+ }),
1842
+ distinctUntilChanged(shallowEqual)
1843
+ );
1844
+ return { value$, lastValue };
1845
+ }
1725
1846
  observe({ key }) {
1726
1847
  var _a;
1727
1848
  const currentResultValue = (_a = this.mutationResults$.getValue().get(key)) == null ? void 0 : _a.getValue();
@@ -1760,18 +1881,19 @@ class MutationClient {
1760
1881
  this.mutate$.next(params);
1761
1882
  }
1762
1883
  /**
1763
- * This will reset any current mutation runnings.
1884
+ * This will cancel any current mutation runnings.
1764
1885
  * No discrimination process
1765
1886
  */
1766
- reset(params) {
1767
- this.reset$.next(params);
1887
+ cancel(params) {
1888
+ this.cancel$.next(params);
1768
1889
  }
1769
1890
  destroy() {
1770
- this.reset$.complete();
1891
+ this.cancel$.complete();
1771
1892
  this.mutate$.complete();
1772
1893
  this.mutationResults$.complete();
1773
1894
  this.mutationRunnersByKey$.complete();
1774
1895
  this.isMutatingSubject.complete();
1896
+ this.mutationsSubject.complete();
1775
1897
  }
1776
1898
  }
1777
1899
  const createClient = () => {
@@ -0,0 +1,15 @@
1
+ import { BehaviorSubject, type Observable } from "rxjs";
2
+ import { type MutationState, type MutationOptions, type MutationResult } from "./types";
3
+ export declare class Mutation<Data> {
4
+ stateSubject: BehaviorSubject<MutationState<Data, unknown, void, unknown>>;
5
+ /**
6
+ * @important
7
+ * proxy for rect-query, not really useful
8
+ */
9
+ state: MutationState<Data>;
10
+ options: MutationOptions<Data, any>;
11
+ mutation$: Observable<MutationResult<Data>>;
12
+ constructor({ args, ...options }: {
13
+ args: any;
14
+ } & MutationOptions<Data, any>);
15
+ }
@@ -1,6 +1,7 @@
1
1
  import { Subject, BehaviorSubject, type Observable } from "rxjs";
2
- import { type MutationResult, type MutationOptions, type MutationObservedResult, type MutationFilters, type MutationKey } from "./types";
2
+ import { type MutationResult, type MutationOptions, type MutationObservedResult, type MutationFilters, type MutationKey, type MutationState } from "./types";
3
3
  import { type QueryKey } from "../keys/types";
4
+ import { type Mutation } from "./Mutation";
4
5
  export declare class MutationClient {
5
6
  /**
6
7
  * Contain all active mutation for a given key.
@@ -15,9 +16,9 @@ export declare class MutationClient {
15
16
  args: unknown;
16
17
  options: MutationOptions<unknown, unknown>;
17
18
  }) => void;
18
- reset$: Subject<void>;
19
+ cancel$: Subject<void>;
19
20
  destroy: () => void;
20
- mutationsRunning$: BehaviorSubject<number>;
21
+ mutationsSubject: BehaviorSubject<Mutation<any>[]>;
21
22
  getClosed: () => boolean;
22
23
  } & {
23
24
  mutationKey: MutationKey;
@@ -34,13 +35,17 @@ export declare class MutationClient {
34
35
  options: MutationOptions<any, any>;
35
36
  args: any;
36
37
  }>;
37
- reset$: Subject<{
38
+ cancel$: Subject<{
38
39
  key: QueryKey;
39
40
  }>;
40
41
  /**
41
42
  * Observable to track how many running mutations per runner
42
43
  */
43
44
  isMutatingSubject: BehaviorSubject<(readonly [MutationKey, number])[]>;
45
+ /**
46
+ * List of all mutations running
47
+ */
48
+ mutationsSubject: BehaviorSubject<Mutation<any>[]>;
44
49
  constructor();
45
50
  /**
46
51
  * @helper
@@ -59,17 +64,24 @@ export declare class MutationClient {
59
64
  args: unknown;
60
65
  options: MutationOptions<unknown, unknown>;
61
66
  }) => void;
62
- reset$: Subject<void>;
67
+ cancel$: Subject<void>;
63
68
  destroy: () => void;
64
- mutationsRunning$: BehaviorSubject<number>;
69
+ mutationsSubject: BehaviorSubject<Mutation<any>[]>;
65
70
  getClosed: () => boolean;
66
71
  } & {
67
72
  mutationKey: MutationKey;
68
73
  }) | undefined;
69
- useIsMutating({ mutationKey, predicate }?: MutationFilters): {
74
+ useIsMutating<TData>(filters?: MutationFilters<TData>): {
70
75
  value$: Observable<number>;
71
76
  lastValue: number;
72
77
  };
78
+ mutationState<TData, Selected = MutationState<TData>>({ filters, select }?: {
79
+ filters?: MutationFilters<TData>;
80
+ select?: (mutation: Mutation<TData>) => Selected;
81
+ }): {
82
+ value$: Observable<Selected[]>;
83
+ lastValue: Selected[];
84
+ };
73
85
  observe<Result>({ key }: {
74
86
  key: string;
75
87
  }): {
@@ -81,10 +93,10 @@ export declare class MutationClient {
81
93
  args: MutationArgs;
82
94
  }): void;
83
95
  /**
84
- * This will reset any current mutation runnings.
96
+ * This will cancel any current mutation runnings.
85
97
  * No discrimination process
86
98
  */
87
- reset(params: {
99
+ cancel(params: {
88
100
  key: QueryKey;
89
101
  }): void;
90
102
  destroy(): void;
@@ -1,13 +1,15 @@
1
1
  import { BehaviorSubject, Subject } from "rxjs";
2
- import { type MutationOptions, type MutationResult } from "./types";
2
+ import { type MutationOptions } from "./types";
3
+ import { Mutation } from "./Mutation";
4
+ export type MutationRunner = ReturnType<typeof createMutationRunner>;
3
5
  export declare const createMutationRunner: <T, MutationArg>({ __queryFinalizeHook, __queryInitHook, __queryTriggerHook }: Pick<MutationOptions<any, any>, "__queryInitHook" | "__queryTriggerHook" | "__queryFinalizeHook">) => {
4
- mutation$: import("rxjs").Observable<MutationResult<T>>;
6
+ mutation$: import("rxjs").Observable<import("./types").MutationResult<unknown>>;
5
7
  trigger: ({ args, options }: {
6
8
  args: MutationArg;
7
9
  options: MutationOptions<T, MutationArg>;
8
10
  }) => void;
9
- reset$: Subject<void>;
11
+ cancel$: Subject<void>;
10
12
  destroy: () => void;
11
- mutationsRunning$: BehaviorSubject<number>;
13
+ mutationsSubject: BehaviorSubject<Mutation<any>[]>;
12
14
  getClosed: () => boolean;
13
15
  };
@@ -0,0 +1,2 @@
1
+ import { type MutationState } from "./types";
2
+ export declare const getDefaultMutationState: <TData>() => MutationState<TData, unknown, void, unknown>;
@@ -0,0 +1,2 @@
1
+ import { type MutationFilters } from "./types";
2
+ export declare const createPredicateForFilters: <TData>({ mutationKey, status, predicate }?: MutationFilters<TData>) => (mutation: import("./Mutation").Mutation<TData>) => boolean;
@@ -1,5 +1,6 @@
1
1
  import { type MonoTypeOperatorFunction, type Observable } from "rxjs";
2
2
  import { type Query, type QueryResult } from "../types";
3
+ import { type Mutation } from "./Mutation";
3
4
  /**
4
5
  * The default value `merge` is suitable for most use case.
5
6
  * You should not have to worry too much about it and only consider changing
@@ -25,19 +26,14 @@ export type MutationKey = unknown[];
25
26
  /**
26
27
  * @todo this should be used in a lot of place so we can probably make a helper for that
27
28
  */
28
- export interface MutationFilters {
29
+ export interface MutationFilters<TData> {
29
30
  /**
30
31
  * Match mutation key exactly
31
32
  */
32
- exact?: boolean;
33
33
  /**
34
34
  * Include mutations matching this predicate function
35
35
  */
36
- predicate?: (mutation: {
37
- options: {
38
- mutationKey: MutationKey;
39
- };
40
- }) => boolean;
36
+ predicate?: (mutation: Mutation<TData>) => boolean;
41
37
  /**
42
38
  * Include mutations matching this mutation key
43
39
  */
@@ -59,7 +55,7 @@ export interface MutationObservedResult<R> extends MutationResult<R> {
59
55
  isPending: boolean;
60
56
  isPaused: boolean;
61
57
  }
62
- export type MutationFn<T, MutationArg> = Observable<T> | ((arg: MutationArg) => Promise<T>) | ((arg: MutationArg) => Observable<T>);
58
+ export type MutationFn<Data, MutationArg> = Observable<Data> | ((arg: MutationArg) => Promise<Data>) | ((arg: MutationArg) => Observable<Data>);
63
59
  export interface MutationOptions<Result, MutationArg> {
64
60
  enabled?: boolean;
65
61
  retry?: false | number | ((attempt: number, error: unknown) => boolean);
@@ -90,3 +86,11 @@ export interface MutationOptions<Result, MutationArg> {
90
86
  __queryTriggerHook?: MonoTypeOperatorFunction<Partial<Result>>;
91
87
  __queryFinalizeHook?: MonoTypeOperatorFunction<Partial<Result>>;
92
88
  }
89
+ export interface MutationState<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> {
90
+ context: TContext | undefined;
91
+ data: TData | undefined;
92
+ error: TError;
93
+ status: MutationStatus;
94
+ variables: TVariables | undefined;
95
+ submittedAt: number;
96
+ }
@@ -9,6 +9,11 @@ export interface QueryResult<T> {
9
9
  status: "loading" | "error" | "success";
10
10
  error: unknown;
11
11
  }
12
+ export interface Register {
13
+ }
14
+ export type DefaultError = Register extends {
15
+ defaultError: infer TError;
16
+ } ? TError : Error;
12
17
  export interface Query {
13
18
  }
14
19
  export interface QueryCommand<T> {
@@ -0,0 +1,3 @@
1
+ import { type MutationFilters } from "../../client/mutations/types";
2
+ import { type QueryClient } from "../../client/createClient";
3
+ export declare const useIsMutating: <TData>(filters?: MutationFilters<TData>, queryClient?: QueryClient) => number;
@@ -14,5 +14,5 @@ export declare function useMutation<Args = void, R = undefined>(options: AsyncQu
14
14
  status: import("../../client/mutations/types").MutationStatus;
15
15
  error: unknown;
16
16
  mutate: (mutationArgs: Args) => void;
17
- reset: () => void;
17
+ cancel: () => void;
18
18
  };
@@ -1,3 +1,7 @@
1
- import { type MutationFilters } from "../../client/mutations/types";
2
- import { type QueryClient } from "../../client/createClient";
3
- export declare const useIsMutating: ({ mutationKey, predicate }?: MutationFilters, queryClient?: QueryClient) => number;
1
+ import { type MutationState, type MutationFilters } from "../../client/mutations/types";
2
+ import { type Mutation } from "../../client/mutations/Mutation";
3
+ export interface MutationStateOptions<TResult, TData> {
4
+ filters?: MutationFilters<TData>;
5
+ select?: (mutation: Mutation<any>) => TResult;
6
+ }
7
+ export declare const useMutationState: <TData, TResult = MutationState<unknown, unknown, void, unknown>>({ filters, select }?: MutationStateOptions<TResult, TData>) => TResult[];
@@ -19,3 +19,4 @@ export declare function renderWithClient(client: QueryClient, ui: React.ReactEle
19
19
  * @see https://github.com/TanStack/query/blob/main/packages/react-query/src/__tests__/utils.tsx
20
20
  */
21
21
  export declare function createQueryClient(): QueryClient;
22
+ export declare const doNotExecute: (_func: () => void) => boolean;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.60.0",
4
+ "version": "1.61.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"