reactjrx 4.0.6 → 4.0.8
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 +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/queries/createObservableQueryFn.d.ts +1 -1
- package/dist/lib/queries/mutationOptions.d.ts +0 -19
- package/dist/lib/queries/useSwitchMutation$.d.ts +22 -28
- package/dist/lib/utils/shouldRetry.d.ts +7 -0
- package/package.json +1 -1
|
@@ -14,4 +14,4 @@ export type ObservableQueryFn<TQueryFnData = unknown, TQueryKey extends QueryKey
|
|
|
14
14
|
* fetch in progress (a refetch replacing it, the last observer unmounting,
|
|
15
15
|
* `cancelQueries`, the query leaving the cache) stops the stream.
|
|
16
16
|
*/
|
|
17
|
-
export declare function createObservableQueryFn<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: ObservableQueryFn<TQueryFnData, TQueryKey>
|
|
17
|
+
export declare function createObservableQueryFn<TQueryFnData = unknown, TQueryKey extends QueryKey = QueryKey>(queryFn: ObservableQueryFn<TQueryFnData, TQueryKey>): typeof skipToken | ((context: QueryFunctionContext<TQueryKey>) => Promise<TQueryFnData>);
|
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
import { UseMutationOptions } from '@tanstack/react-query';
|
|
2
1
|
import { Observable } from 'rxjs';
|
|
3
2
|
/**
|
|
4
3
|
* Resolves the public `mutationFn` option — an Observable or a function
|
|
5
4
|
* returning one — to its source Observable for the given variables.
|
|
6
5
|
*/
|
|
7
6
|
export declare function resolveMutationFnSource<TData, TVariables>(mutationFn: ((variables: TVariables) => Observable<TData>) | Observable<TData>, variables: TVariables): Observable<TData>;
|
|
8
|
-
type MutationCallbacks<TData, TError, TVariables, TOnMutateResult> = Pick<UseMutationOptions<TData, TError, TVariables, TOnMutateResult>, "onMutate" | "onSuccess" | "onError" | "onSettled">;
|
|
9
|
-
/**
|
|
10
|
-
* Same callbacks, but keyed as required so that spreading the adapted
|
|
11
|
-
* callbacks after `...options` overrides (rather than unions with) the
|
|
12
|
-
* raw-variables callbacks still present in `options`.
|
|
13
|
-
*/
|
|
14
|
-
type AdaptedMutationCallbacks<TData, TError, TVariables, TOnMutateResult> = {
|
|
15
|
-
[K in "onMutate" | "onSuccess" | "onError" | "onSettled"]: MutationCallbacks<TData, TError, {
|
|
16
|
-
variables: TVariables;
|
|
17
|
-
}, TOnMutateResult>[K] | undefined;
|
|
18
|
-
};
|
|
19
|
-
/**
|
|
20
|
-
* `useSwitchMutation$` runs its inner mutation with the user variables
|
|
21
|
-
* wrapped in an envelope (`{ variables, abort }`). This adapts the
|
|
22
|
-
* user-facing callbacks, which expect the raw variables, to that envelope.
|
|
23
|
-
*/
|
|
24
|
-
export declare function adaptCallbacksToWrappedVariables<TData, TError, TVariables, TOnMutateResult>({ onMutate, onSuccess, onError, onSettled, }: MutationCallbacks<TData, TError, TVariables, TOnMutateResult>): AdaptedMutationCallbacks<TData, TError, TVariables, TOnMutateResult>;
|
|
25
|
-
export {};
|
|
@@ -3,13 +3,24 @@ import { UseMutation$Options } from './useMutation$';
|
|
|
3
3
|
export declare class SwitchMutationCancelError extends Error {
|
|
4
4
|
constructor(message?: string);
|
|
5
5
|
}
|
|
6
|
+
type SwitchVariables<TVariables> = {
|
|
7
|
+
variables: TVariables;
|
|
8
|
+
abort: AbortSignal;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Runs a mutation, and cancels the call still running when a new one starts.
|
|
12
|
+
* A cancelled call fails with `SwitchMutationCancelError` and is not retried.
|
|
13
|
+
* A call cancelled while TanStack waits to retry it settles once that wait
|
|
14
|
+
* ends.
|
|
15
|
+
*
|
|
16
|
+
* The callbacks, the client's defaults included, receive the variables given
|
|
17
|
+
* to `mutate`. A `MutationCache`, `result.variables` and `useMutationState`
|
|
18
|
+
* see the `{ variables, abort }` the hook runs the mutation with.
|
|
19
|
+
*/
|
|
6
20
|
export declare function useSwitchMutation$<TData = unknown, TError = DefaultError, TVariables = void, TOnMutateResult = unknown>({ mutationFn, ...options }: UseMutation$Options<TData | null, TError, TVariables, TOnMutateResult>, queryClient?: QueryClient): {
|
|
7
21
|
mutate: (variables: TVariables) => void;
|
|
8
22
|
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
9
|
-
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError,
|
|
10
|
-
variables: TVariables;
|
|
11
|
-
abort: AbortSignal;
|
|
12
|
-
}, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
23
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, SwitchVariables<TVariables>, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
13
24
|
data: undefined;
|
|
14
25
|
variables: undefined;
|
|
15
26
|
error: null;
|
|
@@ -27,15 +38,9 @@ export declare function useSwitchMutation$<TData = unknown, TError = DefaultErro
|
|
|
27
38
|
} | {
|
|
28
39
|
mutate: (variables: TVariables) => void;
|
|
29
40
|
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
30
|
-
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError,
|
|
31
|
-
variables: TVariables;
|
|
32
|
-
abort: AbortSignal;
|
|
33
|
-
}, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
41
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, SwitchVariables<TVariables>, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
34
42
|
data: undefined;
|
|
35
|
-
variables:
|
|
36
|
-
variables: TVariables;
|
|
37
|
-
abort: AbortSignal;
|
|
38
|
-
};
|
|
43
|
+
variables: SwitchVariables<TVariables>;
|
|
39
44
|
error: null;
|
|
40
45
|
isError: false;
|
|
41
46
|
isIdle: false;
|
|
@@ -51,16 +56,10 @@ export declare function useSwitchMutation$<TData = unknown, TError = DefaultErro
|
|
|
51
56
|
} | {
|
|
52
57
|
mutate: (variables: TVariables) => void;
|
|
53
58
|
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
54
|
-
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError,
|
|
55
|
-
variables: TVariables;
|
|
56
|
-
abort: AbortSignal;
|
|
57
|
-
}, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
59
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, SwitchVariables<TVariables>, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
58
60
|
data: undefined;
|
|
59
61
|
error: TError;
|
|
60
|
-
variables:
|
|
61
|
-
variables: TVariables;
|
|
62
|
-
abort: AbortSignal;
|
|
63
|
-
};
|
|
62
|
+
variables: SwitchVariables<TVariables>;
|
|
64
63
|
isError: true;
|
|
65
64
|
isIdle: false;
|
|
66
65
|
isPending: false;
|
|
@@ -75,16 +74,10 @@ export declare function useSwitchMutation$<TData = unknown, TError = DefaultErro
|
|
|
75
74
|
} | {
|
|
76
75
|
mutate: (variables: TVariables) => void;
|
|
77
76
|
mutateAsync: (variables: TVariables) => Promise<TData | null>;
|
|
78
|
-
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError,
|
|
79
|
-
variables: TVariables;
|
|
80
|
-
abort: AbortSignal;
|
|
81
|
-
}, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
77
|
+
state$: import('rxjs').BehaviorSubject<Pick<import('@tanstack/react-query').UseMutationResult<TData | null, TError, SwitchVariables<TVariables>, TOnMutateResult>, "status" | "isPending" | "isError" | "isSuccess" | "isIdle">>;
|
|
82
78
|
data: TData | null;
|
|
83
79
|
error: null;
|
|
84
|
-
variables:
|
|
85
|
-
variables: TVariables;
|
|
86
|
-
abort: AbortSignal;
|
|
87
|
-
};
|
|
80
|
+
variables: SwitchVariables<TVariables>;
|
|
88
81
|
isError: false;
|
|
89
82
|
isIdle: false;
|
|
90
83
|
isPending: false;
|
|
@@ -97,3 +90,4 @@ export declare function useSwitchMutation$<TData = unknown, TError = DefaultErro
|
|
|
97
90
|
isPaused: boolean;
|
|
98
91
|
submittedAt: number;
|
|
99
92
|
};
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether to retry after `attempt` retries (0 before the first one): a
|
|
3
|
+
* function decides, a number caps the retries, `true` never stops, and no
|
|
4
|
+
* value never retries. TanStack Query reads a mutation's `retry` the same
|
|
5
|
+
* way, in a check it does not export.
|
|
6
|
+
*/
|
|
7
|
+
export declare const shouldRetry: <TError>(retry: boolean | number | ((attempt: number, error: TError) => boolean) | undefined, attempt: number, error: TError) => boolean;
|