reactjrx 1.110.0 → 1.111.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
@@ -801,29 +801,28 @@ function useMutation$(options, queryClient) {
801
801
  isSuccess: false,
802
802
  isIdle: true
803
803
  });
804
- const mutationFnAsync = (variables) => {
805
- let lastData;
806
- return new Promise((resolve, reject) => {
807
- const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
808
- source.pipe(rxjs.take(1)).subscribe({
809
- next: (data) => {
810
- lastData = { value: data };
811
- },
812
- error: (error) => {
813
- reject(error);
814
- },
815
- complete: () => {
816
- if (lastData === void 0)
817
- return reject(new Error("Stream completed without any data"));
818
- resolve(lastData.value);
819
- }
820
- });
821
- });
822
- };
823
804
  const result = reactQuery.useMutation(
824
805
  {
825
806
  ...options,
826
- mutationFn: mutationFnAsync
807
+ mutationFn: (variables) => {
808
+ let lastData;
809
+ return new Promise((resolve, reject) => {
810
+ const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
811
+ source.pipe(rxjs.take(1)).subscribe({
812
+ next: (data) => {
813
+ lastData = { value: data };
814
+ },
815
+ error: (error) => {
816
+ reject(error);
817
+ },
818
+ complete: () => {
819
+ if (lastData === void 0)
820
+ return reject(new Error("Stream completed without any data"));
821
+ resolve(lastData.value);
822
+ }
823
+ });
824
+ });
825
+ }
827
826
  },
828
827
  queryClient
829
828
  );
@@ -848,7 +847,7 @@ function useSwitchMutation$(options, queryClient) {
848
847
  const mutateSwitch = React.useCallback(
849
848
  (variables) => {
850
849
  cancel();
851
- mutate(variables);
850
+ return mutate(variables);
852
851
  },
853
852
  [mutate, cancel]
854
853
  );
@@ -861,6 +860,65 @@ function useSwitchMutation$(options, queryClient) {
861
860
  );
862
861
  return { ...rest, mutate: mutateSwitch, mutateAsync: mutateAsyncSwitch };
863
862
  }
863
+ function useContactMutation$(options, queryClient) {
864
+ const client = reactQuery.useQueryClient(queryClient);
865
+ const mutationKey = options.mutationKey;
866
+ const { mutateAsync, ...rest } = useMutation$(
867
+ {
868
+ ...options,
869
+ onMutate({ variables }) {
870
+ var _a;
871
+ return (_a = options.onMutate) == null ? void 0 : _a.call(options, variables);
872
+ },
873
+ onSuccess(data, variables, context) {
874
+ var _a;
875
+ return (_a = options.onSuccess) == null ? void 0 : _a.call(options, data, variables.variables, context);
876
+ },
877
+ onError(error, variables, context) {
878
+ var _a;
879
+ return (_a = options.onError) == null ? void 0 : _a.call(options, error, variables.variables, context);
880
+ },
881
+ onSettled(data, error, variables, context) {
882
+ var _a;
883
+ return (_a = options.onSettled) == null ? void 0 : _a.call(options, data, error, variables.variables, context);
884
+ },
885
+ mutationFn: ({ ready$, variables }) => {
886
+ const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
887
+ return ready$.pipe(
888
+ rxjs.filter((isReady) => isReady),
889
+ rxjs.first(),
890
+ rxjs.switchMap(() => source)
891
+ );
892
+ }
893
+ },
894
+ queryClient
895
+ );
896
+ const mutateAsyncConcat = React.useCallback(
897
+ async (variables) => {
898
+ const mutations = client.getMutationCache().findAll({
899
+ mutationKey,
900
+ exact: true
901
+ });
902
+ const subject = new rxjs.BehaviorSubject(false);
903
+ const result = mutateAsync({ variables, ready$: subject });
904
+ await Promise.all(
905
+ mutations.map((mutation) => mutation.continue().catch(rxjs.noop))
906
+ );
907
+ subject.next(true);
908
+ return await result.finally(() => {
909
+ subject.complete();
910
+ });
911
+ },
912
+ [mutateAsync, client, mutationKey]
913
+ );
914
+ const mutateConcat = React.useCallback(
915
+ (variables) => {
916
+ mutateAsyncConcat(variables).catch(rxjs.noop);
917
+ },
918
+ [mutateAsyncConcat]
919
+ );
920
+ return { ...rest, mutate: mutateConcat, mutateAsync: mutateAsyncConcat };
921
+ }
864
922
  function hasObjectPrototype(o) {
865
923
  return Object.prototype.toString.call(o) === "[object Object]";
866
924
  }
@@ -3626,6 +3684,7 @@ exports.isServer = isServer;
3626
3684
  exports.retryBackoff = retryBackoff;
3627
3685
  exports.signal = signal;
3628
3686
  exports.useBehaviorSubject = useBehaviorSubject;
3687
+ exports.useContactMutation$ = useContactMutation$;
3629
3688
  exports.useEffectOnce = useEffectOnce;
3630
3689
  exports.useForeverQuery = useForeverQuery;
3631
3690
  exports.useLiveBehaviorSubject = useLiveBehaviorSubject;
package/dist/index.d.ts CHANGED
@@ -17,6 +17,7 @@ export * from './lib/utils';
17
17
  export * from './lib/queries/useQuery$';
18
18
  export * from './lib/queries/useMutation$';
19
19
  export * from './lib/queries/useSwitchMutation$';
20
+ export * from './lib/queries/useConcatMutation$';
20
21
  export * from './lib/queries/QueryClientProvider$';
21
22
  export * from './lib/deprecated/react/mutations/useMutation';
22
23
  export * from './lib/deprecated/react/queries/useQuery';
package/dist/index.js CHANGED
@@ -11,7 +11,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
11
11
  var _trigger$, _mutationRunner, _currentMutationSubject, _visibility$, _focusedSubject, _client, _currentQuery, _fetchSubject, _currentQueryInitialState, _lastResult, _lastQueryWithDefinedData, _observers, _observerCount, _cancelSubject, _executeSubject, _store, _defaultOptions, _initialState, _notifySubject, _store2, _mutationCache, _queryCache, _mutationDefaults, _queryDefaults, _defaultOptions2;
12
12
  import * as React from "react";
13
13
  import { useRef, useMemo, useCallback, useSyncExternalStore, useEffect, useState, createContext, memo, useContext } from "react";
14
- import { isObservable, from, of, defer, startWith, identity, distinctUntilChanged, tap, catchError, EMPTY, Subject, BehaviorSubject, skip, first, map, switchMap, zip, share, merge, throttleTime, asyncScheduler, concatMap, scan, throwError, timer, takeUntil, fromEvent, take, delay, defaultIfEmpty, Observable, takeWhile, filter, last, mergeMap as mergeMap$1, shareReplay, ignoreElements, noop as noop$1, pairwise, NEVER, interval, withLatestFrom, retry, iif, isEmpty, concat, toArray, combineLatest, endWith, lastValueFrom } from "rxjs";
14
+ import { isObservable, from, of, defer, startWith, identity, distinctUntilChanged, tap, catchError, EMPTY, Subject, BehaviorSubject, skip, first, map, switchMap, zip, share, merge, throttleTime, asyncScheduler, concatMap, scan, throwError, timer, takeUntil, fromEvent, take, delay, defaultIfEmpty, filter, noop as noop$1, Observable, takeWhile, last, mergeMap as mergeMap$1, shareReplay, ignoreElements, pairwise, NEVER, interval, withLatestFrom, retry, iif, isEmpty, concat, toArray, combineLatest, endWith, lastValueFrom } from "rxjs";
15
15
  import { catchError as catchError$1, mergeMap, retryWhen, concatMap as concatMap$1, first as first$1, tap as tap$1 } from "rxjs/operators";
16
16
  import { hashKey as hashKey$1, useQueryClient as useQueryClient$1, useQuery as useQuery$1, useMutation as useMutation$1 } from "@tanstack/react-query";
17
17
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -783,29 +783,28 @@ function useMutation$(options, queryClient) {
783
783
  isSuccess: false,
784
784
  isIdle: true
785
785
  });
786
- const mutationFnAsync = (variables) => {
787
- let lastData;
788
- return new Promise((resolve, reject) => {
789
- const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
790
- source.pipe(take(1)).subscribe({
791
- next: (data) => {
792
- lastData = { value: data };
793
- },
794
- error: (error) => {
795
- reject(error);
796
- },
797
- complete: () => {
798
- if (lastData === void 0)
799
- return reject(new Error("Stream completed without any data"));
800
- resolve(lastData.value);
801
- }
802
- });
803
- });
804
- };
805
786
  const result = useMutation$1(
806
787
  {
807
788
  ...options,
808
- mutationFn: mutationFnAsync
789
+ mutationFn: (variables) => {
790
+ let lastData;
791
+ return new Promise((resolve, reject) => {
792
+ const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
793
+ source.pipe(take(1)).subscribe({
794
+ next: (data) => {
795
+ lastData = { value: data };
796
+ },
797
+ error: (error) => {
798
+ reject(error);
799
+ },
800
+ complete: () => {
801
+ if (lastData === void 0)
802
+ return reject(new Error("Stream completed without any data"));
803
+ resolve(lastData.value);
804
+ }
805
+ });
806
+ });
807
+ }
809
808
  },
810
809
  queryClient
811
810
  );
@@ -830,7 +829,7 @@ function useSwitchMutation$(options, queryClient) {
830
829
  const mutateSwitch = useCallback(
831
830
  (variables) => {
832
831
  cancel();
833
- mutate(variables);
832
+ return mutate(variables);
834
833
  },
835
834
  [mutate, cancel]
836
835
  );
@@ -843,6 +842,65 @@ function useSwitchMutation$(options, queryClient) {
843
842
  );
844
843
  return { ...rest, mutate: mutateSwitch, mutateAsync: mutateAsyncSwitch };
845
844
  }
845
+ function useContactMutation$(options, queryClient) {
846
+ const client = useQueryClient$1(queryClient);
847
+ const mutationKey = options.mutationKey;
848
+ const { mutateAsync, ...rest } = useMutation$(
849
+ {
850
+ ...options,
851
+ onMutate({ variables }) {
852
+ var _a;
853
+ return (_a = options.onMutate) == null ? void 0 : _a.call(options, variables);
854
+ },
855
+ onSuccess(data, variables, context) {
856
+ var _a;
857
+ return (_a = options.onSuccess) == null ? void 0 : _a.call(options, data, variables.variables, context);
858
+ },
859
+ onError(error, variables, context) {
860
+ var _a;
861
+ return (_a = options.onError) == null ? void 0 : _a.call(options, error, variables.variables, context);
862
+ },
863
+ onSettled(data, error, variables, context) {
864
+ var _a;
865
+ return (_a = options.onSettled) == null ? void 0 : _a.call(options, data, error, variables.variables, context);
866
+ },
867
+ mutationFn: ({ ready$, variables }) => {
868
+ const source = typeof options.mutationFn === "function" ? options.mutationFn(variables) : options.mutationFn;
869
+ return ready$.pipe(
870
+ filter((isReady) => isReady),
871
+ first(),
872
+ switchMap(() => source)
873
+ );
874
+ }
875
+ },
876
+ queryClient
877
+ );
878
+ const mutateAsyncConcat = useCallback(
879
+ async (variables) => {
880
+ const mutations = client.getMutationCache().findAll({
881
+ mutationKey,
882
+ exact: true
883
+ });
884
+ const subject = new BehaviorSubject(false);
885
+ const result = mutateAsync({ variables, ready$: subject });
886
+ await Promise.all(
887
+ mutations.map((mutation) => mutation.continue().catch(noop$1))
888
+ );
889
+ subject.next(true);
890
+ return await result.finally(() => {
891
+ subject.complete();
892
+ });
893
+ },
894
+ [mutateAsync, client, mutationKey]
895
+ );
896
+ const mutateConcat = useCallback(
897
+ (variables) => {
898
+ mutateAsyncConcat(variables).catch(noop$1);
899
+ },
900
+ [mutateAsyncConcat]
901
+ );
902
+ return { ...rest, mutate: mutateConcat, mutateAsync: mutateAsyncConcat };
903
+ }
846
904
  function hasObjectPrototype(o) {
847
905
  return Object.prototype.toString.call(o) === "[object Object]";
848
906
  }
@@ -3609,6 +3667,7 @@ export {
3609
3667
  retryBackoff,
3610
3668
  signal,
3611
3669
  useBehaviorSubject,
3670
+ useContactMutation$,
3612
3671
  useEffectOnce,
3613
3672
  useForeverQuery,
3614
3673
  useLiveBehaviorSubject,
@@ -0,0 +1,99 @@
1
+ import { DefaultError, MutationKey, QueryClient } from '@tanstack/react-query';
2
+ import { BehaviorSubject, Subject } from 'rxjs';
3
+ import { UseMutation$Options } from './useMutation$';
4
+ export declare function useContactMutation$<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: UseMutation$Options<TData | null, TError, TVariables, TContext> & {
5
+ mutationKey: MutationKey;
6
+ }, queryClient?: QueryClient): {
7
+ mutate: (variables: TVariables) => void;
8
+ mutateAsync: (variables: TVariables) => Promise<TData | null>;
9
+ state$: BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, {
10
+ variables: TVariables;
11
+ ready$: Subject<boolean>;
12
+ }, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
13
+ data: undefined;
14
+ variables: undefined;
15
+ error: null;
16
+ isError: false;
17
+ isIdle: true;
18
+ isPending: false;
19
+ isSuccess: false;
20
+ status: "idle";
21
+ reset: () => void;
22
+ context: TContext | undefined;
23
+ failureCount: number;
24
+ failureReason: TError | null;
25
+ isPaused: boolean;
26
+ submittedAt: number;
27
+ } | {
28
+ mutate: (variables: TVariables) => void;
29
+ mutateAsync: (variables: TVariables) => Promise<TData | null>;
30
+ state$: BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, {
31
+ variables: TVariables;
32
+ ready$: Subject<boolean>;
33
+ }, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
34
+ data: undefined;
35
+ variables: {
36
+ variables: TVariables;
37
+ ready$: Subject<boolean>;
38
+ };
39
+ error: null;
40
+ isError: false;
41
+ isIdle: false;
42
+ isPending: true;
43
+ isSuccess: false;
44
+ status: "pending";
45
+ reset: () => void;
46
+ context: TContext | undefined;
47
+ failureCount: number;
48
+ failureReason: TError | null;
49
+ isPaused: boolean;
50
+ submittedAt: number;
51
+ } | {
52
+ mutate: (variables: TVariables) => void;
53
+ mutateAsync: (variables: TVariables) => Promise<TData | null>;
54
+ state$: BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, {
55
+ variables: TVariables;
56
+ ready$: Subject<boolean>;
57
+ }, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
58
+ data: undefined;
59
+ error: TError;
60
+ variables: {
61
+ variables: TVariables;
62
+ ready$: Subject<boolean>;
63
+ };
64
+ isError: true;
65
+ isIdle: false;
66
+ isPending: false;
67
+ isSuccess: false;
68
+ status: "error";
69
+ reset: () => void;
70
+ context: TContext | undefined;
71
+ failureCount: number;
72
+ failureReason: TError | null;
73
+ isPaused: boolean;
74
+ submittedAt: number;
75
+ } | {
76
+ mutate: (variables: TVariables) => void;
77
+ mutateAsync: (variables: TVariables) => Promise<TData | null>;
78
+ state$: BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, {
79
+ variables: TVariables;
80
+ ready$: Subject<boolean>;
81
+ }, TContext>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
82
+ data: TData | null;
83
+ error: null;
84
+ variables: {
85
+ variables: TVariables;
86
+ ready$: Subject<boolean>;
87
+ };
88
+ isError: false;
89
+ isIdle: false;
90
+ isPending: false;
91
+ isSuccess: true;
92
+ status: "success";
93
+ reset: () => void;
94
+ context: TContext | undefined;
95
+ failureCount: number;
96
+ failureReason: TError | null;
97
+ isPaused: boolean;
98
+ submittedAt: number;
99
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactjrx",
3
3
  "private": false,
4
- "version": "1.110.0",
4
+ "version": "1.111.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist"