reactjrx 1.62.0 → 1.65.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 +656 -361
- package/dist/index.d.ts +1 -0
- package/dist/index.js +651 -356
- package/dist/lib/queries/client/createClient.d.ts +14 -3
- package/dist/lib/queries/client/mutations/Mutation.d.ts +22 -10
- package/dist/lib/queries/client/mutations/cache/MutationCache.d.ts +43 -0
- package/dist/lib/queries/client/mutations/cache/mutationCache.test.d.ts +1 -0
- package/dist/lib/queries/client/mutations/cache/types.d.ts +61 -0
- package/dist/lib/queries/client/mutations/defaultMutationState.d.ts +1 -1
- package/dist/lib/queries/client/mutations/filters.d.ts +1 -1
- package/dist/lib/queries/client/mutations/observers/MutationObserver.d.ts +25 -0
- package/dist/lib/queries/client/mutations/observers/mutationObserver.test.d.ts +1 -0
- package/dist/lib/queries/client/mutations/observers/types.d.ts +59 -0
- package/dist/lib/queries/client/mutations/operators.d.ts +1 -1
- package/dist/lib/queries/client/mutations/runners/MutationRunner.d.ts +19 -0
- package/dist/lib/queries/client/mutations/runners/MutationRunners.d.ts +54 -0
- package/dist/lib/queries/client/mutations/types.d.ts +13 -66
- package/dist/lib/queries/client/tests/utils.d.ts +4 -0
- package/dist/lib/queries/client/utils/functionAsObservable.d.ts +2 -0
- package/dist/lib/queries/client/utils/wrapInPromise.d.ts +3 -0
- package/dist/lib/queries/react/Provider.d.ts +3 -71
- package/dist/lib/queries/react/mutations/useIsMutating.d.ts +1 -1
- package/dist/lib/queries/react/mutations/useMutation.cancel.test.d.ts +1 -0
- package/dist/lib/queries/react/mutations/useMutation.d.ts +8 -7
- package/dist/lib/queries/react/mutations/useMutationState.d.ts +2 -1
- package/dist/lib/queries/react/{helpers.d.ts → queries/helpers.d.ts} +5 -5
- package/dist/lib/queries/react/{types.d.ts → queries/types.d.ts} +1 -1
- package/dist/lib/queries/react/queries/useQuery.d.ts +1 -1
- package/dist/lib/queries/react/triggers/activityTrigger.d.ts +1 -1
- package/dist/lib/queries/react/triggers/networkTrigger.d.ts +1 -1
- package/dist/tests/utils.d.ts +4 -1
- package/package.json +2 -1
- package/dist/lib/queries/client/mutations/MutationClient.d.ts +0 -91
- package/dist/lib/queries/client/mutations/MutationResultObserver.d.ts +0 -32
- package/dist/lib/queries/client/mutations/createMutationRunner.d.ts +0 -15
- /package/dist/lib/queries/{react → client}/keys/nanoid.d.ts +0 -0
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { type Observable, BehaviorSubject } from "rxjs";
|
|
2
2
|
import { type QueryOptions, type QueryFn, type QueryTrigger, type QueryResult } from "./types";
|
|
3
3
|
import { type QueryKey } from "./keys/types";
|
|
4
|
-
import {
|
|
4
|
+
import { MutationRunners } from "./mutations/runners/MutationRunners";
|
|
5
|
+
import { type MutationOptions } from "./mutations/types";
|
|
6
|
+
import { MutationCache } from "./mutations/cache/MutationCache";
|
|
7
|
+
import { MutationObserver } from "./mutations/observers/MutationObserver";
|
|
5
8
|
export declare const createClient: () => {
|
|
6
9
|
destroy: () => void;
|
|
7
10
|
pipeQueryResult: <R extends Partial<QueryResult<T>>, T>({ options$ }: {
|
|
@@ -69,9 +72,17 @@ export declare const createClient: () => {
|
|
|
69
72
|
size: () => number;
|
|
70
73
|
start: () => () => void;
|
|
71
74
|
};
|
|
72
|
-
mutationClient: MutationClient;
|
|
73
75
|
};
|
|
74
76
|
export declare class QueryClient {
|
|
75
77
|
client: ReturnType<typeof createClient>;
|
|
76
|
-
|
|
78
|
+
protected mutationCache: MutationCache;
|
|
79
|
+
mutationRunners: MutationRunners;
|
|
80
|
+
mutationObserver: MutationObserver;
|
|
81
|
+
constructor({ mutationCache }?: {
|
|
82
|
+
mutationCache: MutationCache;
|
|
83
|
+
});
|
|
84
|
+
mount(): () => void;
|
|
85
|
+
getMutationCache(): MutationCache;
|
|
86
|
+
defaultMutationOptions<T extends MutationOptions<any, any, any, any>>(options?: T): T;
|
|
87
|
+
clear(): void;
|
|
77
88
|
}
|
|
@@ -1,15 +1,27 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Subject, Observable, BehaviorSubject } from "rxjs";
|
|
2
2
|
import { type MutationState, type MutationOptions } from "./types";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
import { type DefaultError } from "../types";
|
|
4
|
+
import { type MutationCache } from "./cache/MutationCache";
|
|
5
|
+
export declare class Mutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> {
|
|
6
|
+
state: MutationState<TData, TError, TVariables, TContext>;
|
|
7
|
+
state$: Observable<typeof this.state>;
|
|
8
|
+
options: MutationOptions<TData, TError, TVariables, TContext>;
|
|
9
|
+
mutationCache: MutationCache;
|
|
10
|
+
protected observerCount: BehaviorSubject<number>;
|
|
11
|
+
observerCount$: Observable<number>;
|
|
12
|
+
protected cancelSubject: Subject<void>;
|
|
13
|
+
protected executeSubject: Subject<TVariables>;
|
|
14
|
+
constructor({ options, mutationCache }: {
|
|
15
|
+
mutationCache: MutationCache;
|
|
16
|
+
options: MutationOptions<TData, TError, TVariables, TContext>;
|
|
17
|
+
});
|
|
18
|
+
createMutation(variables: TVariables): Observable<MutationState<TData, TError, TVariables, TContext>>;
|
|
19
|
+
observeTillFinished(): Observable<MutationState<TData, TError, TVariables, TContext>>;
|
|
5
20
|
/**
|
|
6
21
|
* @important
|
|
7
|
-
*
|
|
22
|
+
* The resulting observable will complete as soon as the mutation
|
|
23
|
+
* is over, unlike the state which can be re-subscribed later.
|
|
8
24
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
mutation$: Observable<MutationState<Data>>;
|
|
12
|
-
constructor({ args, ...options }: {
|
|
13
|
-
args: any;
|
|
14
|
-
} & MutationOptions<Data, any>);
|
|
25
|
+
execute(variables: TVariables): Observable<MutationState<TData, TError, TVariables, TContext>>;
|
|
26
|
+
cancel(): void;
|
|
15
27
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type DefaultError } from "@tanstack/react-query";
|
|
2
|
+
import { Mutation } from "../Mutation";
|
|
3
|
+
import { type QueryClient } from "../../createClient";
|
|
4
|
+
import { type MutationFilters, type MutationOptions, type MutationState } from "../types";
|
|
5
|
+
import { BehaviorSubject, type Subscription } from "rxjs";
|
|
6
|
+
import { type MutationCacheNotifyEvent } from "./types";
|
|
7
|
+
interface MutationCacheConfig {
|
|
8
|
+
onError?: <Data = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(error: DefaultError, variables: unknown, context: unknown, mutation: Mutation<Data, TError, TVariables, TContext>) => Promise<unknown> | unknown;
|
|
9
|
+
onSuccess?: (data: unknown, variables: unknown, context: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
|
|
10
|
+
onMutate?: (variables: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
|
|
11
|
+
onSettled?: (data: unknown | undefined, error: DefaultError | null, variables: unknown, context: unknown, mutation: Mutation<unknown, unknown, unknown>) => Promise<unknown> | unknown;
|
|
12
|
+
}
|
|
13
|
+
export declare class MutationCache {
|
|
14
|
+
config: MutationCacheConfig;
|
|
15
|
+
protected readonly mutationsSubject: BehaviorSubject<{
|
|
16
|
+
mutation: Mutation<any, any, any, any>;
|
|
17
|
+
sub: Subscription;
|
|
18
|
+
}[]>;
|
|
19
|
+
mutations$: import("rxjs").Observable<Mutation<any, any, any, any>[]>;
|
|
20
|
+
added$: import("rxjs").Observable<Mutation<any, any, any, any>>;
|
|
21
|
+
removed$: import("rxjs").Observable<Mutation<any, any, any, any>>;
|
|
22
|
+
stateChange$: import("rxjs").Observable<Mutation<any, any, any, any>>;
|
|
23
|
+
constructor(config?: MutationCacheConfig);
|
|
24
|
+
subscribe(listener: (event: MutationCacheNotifyEvent) => void): () => void;
|
|
25
|
+
build<TData, TError, TVariables, TContext>(client: QueryClient, options: MutationOptions<TData, TError, TVariables, TContext>): Mutation<TData, TError, TVariables, TContext>;
|
|
26
|
+
getAll(): Mutation<any, any, any, any>[];
|
|
27
|
+
remove(mutation: Mutation<any, any, any, any>): void;
|
|
28
|
+
removeBy<TData = unknown, TError = DefaultError, TVariables = any, TContext = unknown>(filters: MutationFilters<TData, TError, TVariables, TContext>): void;
|
|
29
|
+
find<TData = unknown, TError = DefaultError, TVariables = any, TContext = unknown>(filters: MutationFilters<TData, TError, TVariables, TContext>): Mutation<TData, TError, TVariables, TContext> | undefined;
|
|
30
|
+
findLatest<TData = unknown, TError = DefaultError, TVariables = any, TContext = unknown>(filters: MutationFilters<TData, TError, TVariables, TContext>): Mutation<TData, TError, TVariables, TContext> | undefined;
|
|
31
|
+
findAll(filters?: MutationFilters): Array<Mutation<any, any, any, any>>;
|
|
32
|
+
mutationsBy<TData = unknown, TError = DefaultError, TVariables = any, TContext = unknown>(filters: MutationFilters<TData, TError, TVariables, TContext>): import("rxjs").Observable<Mutation<any, any, any, any>[]>;
|
|
33
|
+
mutationStateBy<TData, MutationStateSelected = MutationState<TData>>({ filters, select }?: {
|
|
34
|
+
filters?: MutationFilters<TData>;
|
|
35
|
+
select?: (mutation: Mutation<TData>) => MutationStateSelected;
|
|
36
|
+
}): {
|
|
37
|
+
value$: import("rxjs").Observable<MutationStateSelected[]>;
|
|
38
|
+
lastValue: MutationStateSelected[];
|
|
39
|
+
};
|
|
40
|
+
cancelBy(filters: MutationFilters): void;
|
|
41
|
+
clear(): void;
|
|
42
|
+
}
|
|
43
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Mutation } from "../Mutation";
|
|
2
|
+
import { type MutationObserver } from "../observers/MutationObserver";
|
|
3
|
+
export type NotifyEventType = "added" | "removed" | "updated" | "observerAdded" | "observerRemoved" | "observerResultsUpdated" | "observerOptionsUpdated";
|
|
4
|
+
export interface NotifyEvent {
|
|
5
|
+
type: NotifyEventType;
|
|
6
|
+
}
|
|
7
|
+
interface FailedAction<TError> {
|
|
8
|
+
type: "failed";
|
|
9
|
+
failureCount: number;
|
|
10
|
+
error: TError | null;
|
|
11
|
+
}
|
|
12
|
+
interface PendingAction<TVariables, TContext> {
|
|
13
|
+
type: "pending";
|
|
14
|
+
variables?: TVariables;
|
|
15
|
+
context?: TContext;
|
|
16
|
+
}
|
|
17
|
+
interface SuccessAction<TData> {
|
|
18
|
+
type: "success";
|
|
19
|
+
data: TData;
|
|
20
|
+
}
|
|
21
|
+
interface ErrorAction<TError> {
|
|
22
|
+
type: "error";
|
|
23
|
+
error: TError;
|
|
24
|
+
}
|
|
25
|
+
interface PauseAction {
|
|
26
|
+
type: "pause";
|
|
27
|
+
}
|
|
28
|
+
interface ContinueAction {
|
|
29
|
+
type: "continue";
|
|
30
|
+
}
|
|
31
|
+
export type Action<TData, TError, TVariables, TContext> = ContinueAction | ErrorAction<TError> | FailedAction<TError> | PendingAction<TVariables, TContext> | PauseAction | SuccessAction<TData>;
|
|
32
|
+
interface NotifyEventMutationAdded extends NotifyEvent {
|
|
33
|
+
type: "added";
|
|
34
|
+
mutation: Mutation<any, any, any, any>;
|
|
35
|
+
}
|
|
36
|
+
interface NotifyEventMutationRemoved extends NotifyEvent {
|
|
37
|
+
type: "removed";
|
|
38
|
+
mutation: Mutation<any, any, any, any>;
|
|
39
|
+
}
|
|
40
|
+
interface NotifyEventMutationObserverAdded extends NotifyEvent {
|
|
41
|
+
type: "observerAdded";
|
|
42
|
+
mutation: Mutation<any, any, any, any>;
|
|
43
|
+
observer: MutationObserver<any, any, any>;
|
|
44
|
+
}
|
|
45
|
+
interface NotifyEventMutationObserverRemoved extends NotifyEvent {
|
|
46
|
+
type: "observerRemoved";
|
|
47
|
+
mutation: Mutation<any, any, any, any>;
|
|
48
|
+
observer: MutationObserver<any, any, any>;
|
|
49
|
+
}
|
|
50
|
+
interface NotifyEventMutationObserverOptionsUpdated extends NotifyEvent {
|
|
51
|
+
type: "observerOptionsUpdated";
|
|
52
|
+
mutation?: Mutation<any, any, any, any>;
|
|
53
|
+
observer: MutationObserver<any, any, any, any>;
|
|
54
|
+
}
|
|
55
|
+
interface NotifyEventMutationUpdated extends NotifyEvent {
|
|
56
|
+
type: "updated";
|
|
57
|
+
mutation: Mutation<any, any, any, any>;
|
|
58
|
+
action: Action<any, any, any, any>;
|
|
59
|
+
}
|
|
60
|
+
export type MutationCacheNotifyEvent = NotifyEventMutationAdded | NotifyEventMutationRemoved | NotifyEventMutationObserverAdded | NotifyEventMutationObserverRemoved | NotifyEventMutationObserverOptionsUpdated | NotifyEventMutationUpdated;
|
|
61
|
+
export {};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type MutationState } from "./types";
|
|
2
|
-
export declare const getDefaultMutationState: <TData>() => MutationState<TData,
|
|
2
|
+
export declare const getDefaultMutationState: <TData = unknown, TError = unknown, TVariables = void, TContext = unknown>() => MutationState<TData, TError, TVariables, TContext>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { type MutationFilters } from "./types";
|
|
2
|
-
export declare const createPredicateForFilters: <TData>({ mutationKey, status, predicate }?: MutationFilters<TData>) => (mutation: import("./Mutation").Mutation<TData>) => boolean;
|
|
2
|
+
export declare const createPredicateForFilters: <TData = unknown, TError = Error, TVariables = any, TContext = unknown>({ mutationKey, status, predicate, exact }?: MutationFilters<TData, TError, TVariables, TContext>) => (mutation: import("./Mutation").Mutation<TData, TError, TVariables, TContext>) => boolean;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type Observable } from "rxjs";
|
|
2
|
+
import { type MutationOptions, type MutateOptions, type MutationState, type MutationFilters } from "../types";
|
|
3
|
+
import { type QueryClient } from "../../createClient";
|
|
4
|
+
import { type DefaultError } from "../../types";
|
|
5
|
+
import { type Mutation } from "../Mutation";
|
|
6
|
+
import { type MutationObserverResult } from "./types";
|
|
7
|
+
/**
|
|
8
|
+
* Provide API to observe mutations results globally.
|
|
9
|
+
* Observe runners and map their results in a hash map.
|
|
10
|
+
*/
|
|
11
|
+
export declare class MutationObserver<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> {
|
|
12
|
+
protected client: QueryClient;
|
|
13
|
+
protected options?: Partial<MutationOptions<TData, TError, TVariables, TContext>> | undefined;
|
|
14
|
+
constructor(client: QueryClient, options?: Partial<MutationOptions<TData, TError, TVariables, TContext>> | undefined);
|
|
15
|
+
protected getDerivedState: (state: MutationState<any, any, any, any>) => MutationObserverResult;
|
|
16
|
+
observeBy<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(filters: MutationFilters): {
|
|
17
|
+
result$: Observable<MutationObserverResult<TData, TError, TVariables, TContext>>;
|
|
18
|
+
lastValue: MutationObserverResult<TData, TError, TVariables, TContext>;
|
|
19
|
+
};
|
|
20
|
+
observe(mutation: Mutation): Observable<MutationState<unknown, Error, void, unknown>>;
|
|
21
|
+
subscribe(subscription: () => void): () => void;
|
|
22
|
+
mutate(variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TContext>): Promise<MutationState<TData, TVariables, void, unknown>>;
|
|
23
|
+
reset(): void;
|
|
24
|
+
destroy(): void;
|
|
25
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { type DefaultError } from "../../types";
|
|
2
|
+
import { type MutationState, type MutationStatus } from "../types";
|
|
3
|
+
export interface MutationObserverBaseResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationState<TData, TError, TVariables, TContext> {
|
|
4
|
+
isError: boolean;
|
|
5
|
+
isIdle: boolean;
|
|
6
|
+
isPending: boolean;
|
|
7
|
+
isSuccess: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface MutationObserverIdleResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
10
|
+
data: undefined;
|
|
11
|
+
variables: undefined;
|
|
12
|
+
error: null;
|
|
13
|
+
isError: false;
|
|
14
|
+
isIdle: true;
|
|
15
|
+
isPending: false;
|
|
16
|
+
isSuccess: false;
|
|
17
|
+
status: "idle";
|
|
18
|
+
}
|
|
19
|
+
export interface MutationObserverLoadingResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
20
|
+
data: undefined;
|
|
21
|
+
variables: TVariables;
|
|
22
|
+
error: null;
|
|
23
|
+
isError: false;
|
|
24
|
+
isIdle: false;
|
|
25
|
+
isPending: true;
|
|
26
|
+
isSuccess: false;
|
|
27
|
+
status: "pending";
|
|
28
|
+
}
|
|
29
|
+
export interface MutationObserverErrorResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
30
|
+
data: undefined;
|
|
31
|
+
error: TError;
|
|
32
|
+
variables: TVariables;
|
|
33
|
+
isError: true;
|
|
34
|
+
isIdle: false;
|
|
35
|
+
isPending: false;
|
|
36
|
+
isSuccess: false;
|
|
37
|
+
status: "error";
|
|
38
|
+
}
|
|
39
|
+
export interface MutationObserverSuccessResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
40
|
+
data: TData;
|
|
41
|
+
error: null;
|
|
42
|
+
variables: TVariables;
|
|
43
|
+
isError: false;
|
|
44
|
+
isIdle: false;
|
|
45
|
+
isPending: false;
|
|
46
|
+
isSuccess: true;
|
|
47
|
+
status: "success";
|
|
48
|
+
}
|
|
49
|
+
export interface MutationObserverAnyResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
50
|
+
data: TData | undefined;
|
|
51
|
+
error: TError | null;
|
|
52
|
+
variables: TVariables;
|
|
53
|
+
isError: boolean;
|
|
54
|
+
isIdle: boolean;
|
|
55
|
+
isPending: boolean;
|
|
56
|
+
isSuccess: boolean;
|
|
57
|
+
status: MutationStatus;
|
|
58
|
+
}
|
|
59
|
+
export type MutationObserverResult<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> = MutationObserverAnyResult<TData, TError, TVariables, TContext>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type Observable } from "rxjs";
|
|
2
2
|
import { type MutationState } from "./types";
|
|
3
|
-
export declare const mergeResults: <
|
|
3
|
+
export declare const mergeResults: <TData = unknown, TError = unknown, TVariables = unknown, TContext = unknown>(stream$: Observable<Partial<MutationState<TData, TError, TVariables, TContext>>>) => Observable<MutationState<TData, TError, TVariables, TContext>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Subject } from "rxjs";
|
|
2
|
+
import { type MutationOptions } from "../types";
|
|
3
|
+
import { type MutationCache } from "../cache/MutationCache";
|
|
4
|
+
import { type QueryClient } from "../../createClient";
|
|
5
|
+
export type MutationRunner = ReturnType<typeof createMutationRunner>;
|
|
6
|
+
export declare const createMutationRunner: <TData, TError = Error, MutationArg = void, TContext = unknown>({ __queryFinalizeHook, __queryInitHook, __queryTriggerHook, mutationKey, mutationCache, }: {
|
|
7
|
+
mutationCache: MutationCache;
|
|
8
|
+
client: QueryClient;
|
|
9
|
+
} & Pick<MutationOptions<TData, TError, MutationArg, TContext>, "__queryInitHook" | "__queryTriggerHook" | "__queryFinalizeHook" | "mutationKey">) => {
|
|
10
|
+
mutationKey: import("../types").MutationKey;
|
|
11
|
+
runner$: import("rxjs").Observable<import("../types").MutationState<unknown, unknown, unknown, unknown>>;
|
|
12
|
+
trigger: ({ args, options }: {
|
|
13
|
+
args: MutationArg;
|
|
14
|
+
options: MutationOptions<TData, TError, MutationArg, TContext>;
|
|
15
|
+
}) => void;
|
|
16
|
+
cancel$: Subject<void>;
|
|
17
|
+
destroy: () => void;
|
|
18
|
+
getClosed: () => boolean;
|
|
19
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { BehaviorSubject } from "rxjs";
|
|
2
|
+
import { type MutationOptions } from "../types";
|
|
3
|
+
import { createMutationRunner } from "./MutationRunner";
|
|
4
|
+
import { type QueryClient } from "../../createClient";
|
|
5
|
+
import { type DefaultError } from "../../types";
|
|
6
|
+
export declare class MutationRunners {
|
|
7
|
+
client: QueryClient;
|
|
8
|
+
/**
|
|
9
|
+
* Contain all active mutation for a given key.
|
|
10
|
+
* A mutation ca have several triggers running (it is not necessarily one function running)
|
|
11
|
+
*
|
|
12
|
+
* @important
|
|
13
|
+
* - automatically cleaned as soon as the last mutation is done for a given key
|
|
14
|
+
*/
|
|
15
|
+
mutationRunnersByKey$: BehaviorSubject<Map<string, {
|
|
16
|
+
mutationKey: import("../types").MutationKey;
|
|
17
|
+
runner$: import("rxjs").Observable<import("../types").MutationState<unknown, unknown, unknown, unknown>>;
|
|
18
|
+
trigger: ({ args, options }: {
|
|
19
|
+
args: any;
|
|
20
|
+
options: MutationOptions<any, any, any, any>;
|
|
21
|
+
}) => void;
|
|
22
|
+
cancel$: import("rxjs").Subject<void>;
|
|
23
|
+
destroy: () => void;
|
|
24
|
+
getClosed: () => boolean;
|
|
25
|
+
}>>;
|
|
26
|
+
constructor(client: QueryClient);
|
|
27
|
+
/**
|
|
28
|
+
* @helper
|
|
29
|
+
*/
|
|
30
|
+
setMutationRunnersByKey(key: string, value: ReturnType<typeof createMutationRunner>): void;
|
|
31
|
+
/**
|
|
32
|
+
* @helper
|
|
33
|
+
*/
|
|
34
|
+
deleteMutationRunnersByKey(key: string): void;
|
|
35
|
+
/**
|
|
36
|
+
* @helper
|
|
37
|
+
*/
|
|
38
|
+
getMutationRunnersByKey(key: string): {
|
|
39
|
+
mutationKey: import("../types").MutationKey;
|
|
40
|
+
runner$: import("rxjs").Observable<import("../types").MutationState<unknown, unknown, unknown, unknown>>;
|
|
41
|
+
trigger: ({ args, options }: {
|
|
42
|
+
args: any;
|
|
43
|
+
options: MutationOptions<any, any, any, any>;
|
|
44
|
+
}) => void;
|
|
45
|
+
cancel$: import("rxjs").Subject<void>;
|
|
46
|
+
destroy: () => void;
|
|
47
|
+
getClosed: () => boolean;
|
|
48
|
+
} | undefined;
|
|
49
|
+
mutate<TData, TError = DefaultError, TVariables = void, TContext = unknown>(params: {
|
|
50
|
+
options: MutationOptions<TData, TError, TVariables, TContext>;
|
|
51
|
+
args: TVariables;
|
|
52
|
+
}): Promise<import("../types").MutationState<TData, TError, TVariables, TContext>>;
|
|
53
|
+
destroy(): void;
|
|
54
|
+
}
|
|
@@ -26,14 +26,15 @@ export type MutationKey = unknown[];
|
|
|
26
26
|
/**
|
|
27
27
|
* @todo this should be used in a lot of place so we can probably make a helper for that
|
|
28
28
|
*/
|
|
29
|
-
export interface MutationFilters<TData> {
|
|
29
|
+
export interface MutationFilters<TData = unknown, TError = DefaultError, TVariables = any, TContext = unknown> {
|
|
30
30
|
/**
|
|
31
31
|
* Match mutation key exactly
|
|
32
32
|
*/
|
|
33
|
+
exact?: boolean;
|
|
33
34
|
/**
|
|
34
35
|
* Include mutations matching this predicate function
|
|
35
36
|
*/
|
|
36
|
-
predicate?: (mutation: Mutation<TData>) => boolean;
|
|
37
|
+
predicate?: (mutation: Mutation<TData, TError, TVariables, TContext>) => boolean;
|
|
37
38
|
/**
|
|
38
39
|
* Include mutations matching this mutation key
|
|
39
40
|
*/
|
|
@@ -44,9 +45,10 @@ export interface MutationFilters<TData> {
|
|
|
44
45
|
status?: MutationStatus;
|
|
45
46
|
}
|
|
46
47
|
export type MutationFn<Data, MutationArg> = Observable<Data> | ((arg: MutationArg) => Promise<Data>) | ((arg: MutationArg) => Observable<Data>);
|
|
47
|
-
export interface MutationOptions<
|
|
48
|
+
export interface MutationOptions<TData, TError = DefaultError, TVariables = void, TContext = unknown> {
|
|
48
49
|
enabled?: boolean;
|
|
49
50
|
retry?: false | number | ((attempt: number, error: unknown) => boolean);
|
|
51
|
+
gcTime?: number;
|
|
50
52
|
/**
|
|
51
53
|
* @important
|
|
52
54
|
* The hook with the lowest value will be taken into account
|
|
@@ -62,17 +64,19 @@ export interface MutationOptions<Result, MutationArg> {
|
|
|
62
64
|
* interval is paused until the query finish fetching. This avoid infinite
|
|
63
65
|
* loop of refetch
|
|
64
66
|
*/
|
|
65
|
-
refetchInterval?: number | false | ((data: QueryResult<
|
|
67
|
+
refetchInterval?: number | false | ((data: QueryResult<TData>["data"] | undefined, query: Query) => number | false);
|
|
66
68
|
terminateOnFirstResult?: boolean;
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
69
|
+
onMutate?: (variables: TVariables) => Promise<TContext | undefined> | TContext | undefined;
|
|
70
|
+
onError?: (error: TError, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
71
|
+
onSuccess?: (data: TData, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
72
|
+
onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => Promise<unknown> | unknown;
|
|
73
|
+
mutationFn: MutationFn<TData, TVariables>;
|
|
70
74
|
mutationKey: MutationKey;
|
|
71
75
|
mapOperator?: MapOperator;
|
|
72
76
|
__queryInitHook?: MonoTypeOperatorFunction<any>;
|
|
73
77
|
__queryRunnerHook?: MonoTypeOperatorFunction<any>;
|
|
74
|
-
__queryTriggerHook?: MonoTypeOperatorFunction<Partial<
|
|
75
|
-
__queryFinalizeHook?: MonoTypeOperatorFunction<Partial<
|
|
78
|
+
__queryTriggerHook?: MonoTypeOperatorFunction<Partial<TData>>;
|
|
79
|
+
__queryFinalizeHook?: MonoTypeOperatorFunction<Partial<TData>>;
|
|
76
80
|
}
|
|
77
81
|
export interface MutationState<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> {
|
|
78
82
|
context: TContext | undefined;
|
|
@@ -88,60 +92,3 @@ export interface MutateOptions<TData = unknown, TError = DefaultError, TVariable
|
|
|
88
92
|
onSettled?: (data: TData | undefined, error: TError | null, variables: TVariables, context: TContext | undefined) => void;
|
|
89
93
|
}
|
|
90
94
|
export type MutateFunction<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> = (variables: TVariables, options?: MutateOptions<TData, TError, TVariables, TContext>) => Promise<TData>;
|
|
91
|
-
export interface MutationObserverBaseResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationState<TData, TError, TVariables, TContext> {
|
|
92
|
-
isError: boolean;
|
|
93
|
-
isIdle: boolean;
|
|
94
|
-
isPending: boolean;
|
|
95
|
-
isSuccess: boolean;
|
|
96
|
-
}
|
|
97
|
-
export interface MutationObserverIdleResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
98
|
-
data: undefined;
|
|
99
|
-
variables: undefined;
|
|
100
|
-
error: null;
|
|
101
|
-
isError: false;
|
|
102
|
-
isIdle: true;
|
|
103
|
-
isPending: false;
|
|
104
|
-
isSuccess: false;
|
|
105
|
-
status: "idle";
|
|
106
|
-
}
|
|
107
|
-
export interface MutationObserverLoadingResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
108
|
-
data: undefined;
|
|
109
|
-
variables: TVariables;
|
|
110
|
-
error: null;
|
|
111
|
-
isError: false;
|
|
112
|
-
isIdle: false;
|
|
113
|
-
isPending: true;
|
|
114
|
-
isSuccess: false;
|
|
115
|
-
status: "pending";
|
|
116
|
-
}
|
|
117
|
-
export interface MutationObserverErrorResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
118
|
-
data: undefined;
|
|
119
|
-
error: TError;
|
|
120
|
-
variables: TVariables;
|
|
121
|
-
isError: true;
|
|
122
|
-
isIdle: false;
|
|
123
|
-
isPending: false;
|
|
124
|
-
isSuccess: false;
|
|
125
|
-
status: "error";
|
|
126
|
-
}
|
|
127
|
-
export interface MutationObserverSuccessResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
128
|
-
data: TData;
|
|
129
|
-
error: null;
|
|
130
|
-
variables: TVariables;
|
|
131
|
-
isError: false;
|
|
132
|
-
isIdle: false;
|
|
133
|
-
isPending: false;
|
|
134
|
-
isSuccess: true;
|
|
135
|
-
status: "success";
|
|
136
|
-
}
|
|
137
|
-
export interface MutationObserverAnyResult<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends MutationObserverBaseResult<TData, TError, TVariables, TContext> {
|
|
138
|
-
data: TData | undefined;
|
|
139
|
-
error: TError | null;
|
|
140
|
-
variables: TVariables;
|
|
141
|
-
isError: boolean;
|
|
142
|
-
isIdle: boolean;
|
|
143
|
-
isPending: boolean;
|
|
144
|
-
isSuccess: boolean;
|
|
145
|
-
status: MutationStatus;
|
|
146
|
-
}
|
|
147
|
-
export type MutationObserverResult<TData = unknown, TError = unknown, TVariables = void, TContext = unknown> = MutationObserverAnyResult<TData, TError, TVariables, TContext>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type QueryClient } from "../createClient";
|
|
2
|
+
import { type MutationOptions } from "../mutations/types";
|
|
3
|
+
export declare function queryKey(): string[];
|
|
4
|
+
export declare const executeMutation: <TVariables>(queryClient: QueryClient, options: MutationOptions<any, any, TVariables, any>, variables: TVariables) => Promise<import("../mutations/types").MutationState<any, any, TVariables, any>>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
import { type QueryClient
|
|
2
|
+
import { type QueryClient } from "../client/createClient";
|
|
3
3
|
export declare const Context: import("react").Context<{
|
|
4
|
-
client:
|
|
4
|
+
client: QueryClient;
|
|
5
5
|
}>;
|
|
6
6
|
export declare const QueryClientProvider: import("react").MemoExoticComponent<({ children, client }: {
|
|
7
7
|
children: ReactNode;
|
|
@@ -9,72 +9,4 @@ export declare const QueryClientProvider: import("react").MemoExoticComponent<({
|
|
|
9
9
|
}) => import("react/jsx-runtime").JSX.Element>;
|
|
10
10
|
export declare const useQueryClient: ({ unsafe }?: {
|
|
11
11
|
unsafe?: boolean | undefined;
|
|
12
|
-
}) =>
|
|
13
|
-
destroy: () => void;
|
|
14
|
-
pipeQueryResult: <R extends Partial<import("../client/types").QueryResult<T>>, T>({ options$ }: {
|
|
15
|
-
key: string;
|
|
16
|
-
queryStore: {
|
|
17
|
-
set: (key: string, value: import("../client/store/createQueryStore").StoreObject<unknown>) => void;
|
|
18
|
-
get: <T_1>(serializedKey: string) => import("../client/store/createQueryStore").StoreObject<T_1> | undefined;
|
|
19
|
-
get$: (key: string) => import("rxjs").Observable<import("../client/store/createQueryStore").StoreObject<unknown>>;
|
|
20
|
-
delete: (key: string) => void;
|
|
21
|
-
update: <T_2>(key: string, value: Partial<import("../client/store/createQueryStore").StoreObject<T_2>> | ((value: import("../client/store/createQueryStore").StoreObject<T_2>) => import("../client/store/createQueryStore").StoreObject<T_2>)) => void;
|
|
22
|
-
keys: () => IterableIterator<string>;
|
|
23
|
-
updateMany: (value: Partial<import("../client/store/createQueryStore").StoreObject<unknown>>, predicate?: (storeObject: import("../client/store/createQueryStore").StoreObject<unknown>) => boolean) => void;
|
|
24
|
-
addRunner: <T_3>(key: string, stream: import("rxjs").Observable<{
|
|
25
|
-
options: import("../client/types").QueryOptions<T_3>;
|
|
26
|
-
}>) => () => void;
|
|
27
|
-
store$: import("rxjs").BehaviorSubject<Map<string, import("rxjs").BehaviorSubject<import("../client/store/createQueryStore").StoreObject<unknown>>>>;
|
|
28
|
-
queryEvent$: import("rxjs").Observable<import("../client/store/createQueryStore").QueryEvent>;
|
|
29
|
-
dispatchQueryEvent: (event: import("../client/store/createQueryStore").QueryEvent) => void;
|
|
30
|
-
queryTrigger$: import("rxjs").Observable<import("../client/store/createQueryStore").QueryTriggerEvent>;
|
|
31
|
-
dispatchQueryTrigger: (event: import("../client/store/createQueryStore").QueryTriggerEvent) => void;
|
|
32
|
-
size: () => number;
|
|
33
|
-
start: () => () => void;
|
|
34
|
-
};
|
|
35
|
-
options$: import("rxjs").Observable<import("../client/types").QueryOptions<T>>;
|
|
36
|
-
refetch$: import("rxjs").Observable<import("../client/types").QueryTrigger>;
|
|
37
|
-
}) => import("rxjs").MonoTypeOperatorFunction<R>;
|
|
38
|
-
refetchQueries: (_: {
|
|
39
|
-
queryKey: import("../client/keys/types").QueryKey;
|
|
40
|
-
}) => void;
|
|
41
|
-
setQueryData: ({ queryKey, updater }: {
|
|
42
|
-
queryKey: import("../client/keys/types").QueryKey;
|
|
43
|
-
updater: unknown;
|
|
44
|
-
}) => void;
|
|
45
|
-
invalidateQueries: ({ queryKey, exact, predicate }?: {
|
|
46
|
-
queryKey?: import("../client/keys/types").QueryKey | undefined;
|
|
47
|
-
exact?: boolean | undefined;
|
|
48
|
-
predicate?: ((storeObject: import("../client/store/createQueryStore").StoreObject<unknown>) => boolean) | undefined;
|
|
49
|
-
}) => void;
|
|
50
|
-
start: () => () => void;
|
|
51
|
-
query: <T_4>({ key, fn$: maybeFn$, fn: maybeFn, trigger$: externalTrigger$, options$ }: {
|
|
52
|
-
key: import("../client/keys/types").QueryKey;
|
|
53
|
-
fn?: import("../client/types").QueryFn<T_4> | undefined;
|
|
54
|
-
fn$?: import("rxjs").Observable<import("../client/types").QueryFn<T_4>> | undefined;
|
|
55
|
-
trigger$?: import("rxjs").Observable<import("../client/types").QueryTrigger> | undefined;
|
|
56
|
-
options$?: import("rxjs").Observable<import("../client/types").QueryOptions<T_4>> | undefined;
|
|
57
|
-
}) => {
|
|
58
|
-
result$: import("rxjs").Observable<import("../client/types").QueryResult<T_4>>;
|
|
59
|
-
};
|
|
60
|
-
queryStore: {
|
|
61
|
-
set: (key: string, value: import("../client/store/createQueryStore").StoreObject<unknown>) => void;
|
|
62
|
-
get: <T_1>(serializedKey: string) => import("../client/store/createQueryStore").StoreObject<T_1> | undefined;
|
|
63
|
-
get$: (key: string) => import("rxjs").Observable<import("../client/store/createQueryStore").StoreObject<unknown>>;
|
|
64
|
-
delete: (key: string) => void;
|
|
65
|
-
update: <T_2>(key: string, value: Partial<import("../client/store/createQueryStore").StoreObject<T_2>> | ((value: import("../client/store/createQueryStore").StoreObject<T_2>) => import("../client/store/createQueryStore").StoreObject<T_2>)) => void;
|
|
66
|
-
keys: () => IterableIterator<string>;
|
|
67
|
-
updateMany: (value: Partial<import("../client/store/createQueryStore").StoreObject<unknown>>, predicate?: (storeObject: import("../client/store/createQueryStore").StoreObject<unknown>) => boolean) => void;
|
|
68
|
-
addRunner: <T_3>(key: string, stream: import("rxjs").Observable<{
|
|
69
|
-
options: import("../client/types").QueryOptions<T_3>;
|
|
70
|
-
}>) => () => void;
|
|
71
|
-
store$: import("rxjs").BehaviorSubject<Map<string, import("rxjs").BehaviorSubject<import("../client/store/createQueryStore").StoreObject<unknown>>>>;
|
|
72
|
-
queryEvent$: import("rxjs").Observable<import("../client/store/createQueryStore").QueryEvent>;
|
|
73
|
-
dispatchQueryEvent: (event: import("../client/store/createQueryStore").QueryEvent) => void;
|
|
74
|
-
queryTrigger$: import("rxjs").Observable<import("../client/store/createQueryStore").QueryTriggerEvent>;
|
|
75
|
-
dispatchQueryTrigger: (event: import("../client/store/createQueryStore").QueryTriggerEvent) => void;
|
|
76
|
-
size: () => number;
|
|
77
|
-
start: () => () => void;
|
|
78
|
-
};
|
|
79
|
-
mutationClient: import("../client/mutations/MutationClient").MutationClient;
|
|
80
|
-
};
|
|
12
|
+
}) => QueryClient;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { type MutationFilters } from "../../client/mutations/types";
|
|
2
2
|
import { type QueryClient } from "../../client/createClient";
|
|
3
|
-
export declare const useIsMutating: <TData>(filters?: MutationFilters<TData>, queryClient?: QueryClient) => number;
|
|
3
|
+
export declare const useIsMutating: <TData>(filters?: MutationFilters<TData, Error, any, unknown>, queryClient?: QueryClient) => number;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,20 +1,21 @@
|
|
|
1
1
|
import { type MutationKey, type MutationOptions } from "../../client/mutations/types";
|
|
2
2
|
import { type QueryClient } from "../../client/createClient";
|
|
3
|
-
|
|
3
|
+
import { type DefaultError } from "../../client/types";
|
|
4
|
+
export type AsyncQueryOptions<Result, Params> = Omit<MutationOptions<Result, Error, Params>, "mutationKey"> & {
|
|
4
5
|
mutationKey?: MutationKey;
|
|
5
6
|
cancelOnUnMount?: boolean;
|
|
6
7
|
};
|
|
7
|
-
export declare function useMutation<
|
|
8
|
-
data:
|
|
9
|
-
error:
|
|
10
|
-
variables:
|
|
8
|
+
export declare function useMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(options: AsyncQueryOptions<TData, TVariables>, queryClient?: QueryClient): {
|
|
9
|
+
data: TData | undefined;
|
|
10
|
+
error: TError | null;
|
|
11
|
+
variables: TVariables;
|
|
11
12
|
isError: boolean;
|
|
12
13
|
isIdle: boolean;
|
|
13
14
|
isPending: boolean;
|
|
14
15
|
isSuccess: boolean;
|
|
15
16
|
status: import("../../client/mutations/types").MutationStatus;
|
|
16
|
-
context:
|
|
17
|
+
context: TContext | undefined;
|
|
17
18
|
submittedAt: number;
|
|
18
|
-
mutate: (mutationArgs:
|
|
19
|
+
mutate: (mutationArgs: TVariables) => void;
|
|
19
20
|
cancel: () => void;
|
|
20
21
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { type MutationState, type MutationFilters } from "../../client/mutations/types";
|
|
2
2
|
import { type Mutation } from "../../client/mutations/Mutation";
|
|
3
|
+
import { type QueryClient } from "../../client/createClient";
|
|
3
4
|
export interface MutationStateOptions<TResult, TData> {
|
|
4
5
|
filters?: MutationFilters<TData>;
|
|
5
6
|
select?: (mutation: Mutation<any>) => TResult;
|
|
6
7
|
}
|
|
7
|
-
export declare const useMutationState: <TData, TResult = MutationState<unknown, unknown, void, unknown>>({ filters, select }?: MutationStateOptions<TResult, TData
|
|
8
|
+
export declare const useMutationState: <TData, TResult = MutationState<unknown, unknown, void, unknown>>({ filters, select }?: MutationStateOptions<TResult, TData>, queryClient?: QueryClient) => TResult[];
|