reactjrx 1.67.4 → 1.69.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/README.md +6 -2
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.js +2058 -1491
- package/dist/lib/binding/types.d.ts +2 -0
- package/dist/lib/binding/useObservableEvent.d.ts +5 -0
- package/dist/lib/binding/useObservableState.d.ts +16 -0
- package/dist/lib/binding/useSubscribe.d.ts +2 -3
- package/dist/lib/binding/useSubscribeEffect.d.ts +11 -0
- package/dist/lib/queries/client/QueryClient.d.ts +48 -0
- package/dist/lib/queries/client/focusManager.d.ts +19 -0
- package/dist/lib/queries/client/keys/hashKey.d.ts +3 -0
- package/dist/lib/queries/client/keys/{compareKeys.d.ts → matchKey.d.ts} +1 -1
- package/dist/lib/queries/client/keys/partialMatchKey.d.ts +5 -0
- package/dist/lib/queries/client/mutations/cache/MutationCache.d.ts +5 -16
- package/dist/lib/queries/client/mutations/mutation/Mutation.d.ts +4 -10
- package/dist/lib/queries/client/mutations/mutation/delayWhenNetworkOnline.d.ts +4 -0
- package/dist/lib/queries/client/mutations/mutation/observeUntilFinished.d.ts +3 -0
- package/dist/lib/queries/client/mutations/mutation/types.d.ts +4 -3
- package/dist/lib/queries/client/mutations/mutation/waitForNetworkOnError.d.ts +6 -0
- package/dist/lib/queries/client/mutations/observers/MutationObserver.d.ts +8 -11
- package/dist/lib/queries/client/mutations/runner/MutationRunner.d.ts +9 -9
- package/dist/lib/queries/client/onlineManager.d.ts +10 -0
- package/dist/lib/queries/client/queries/cache/QueryCache.d.ts +33 -0
- package/dist/lib/queries/client/queries/cache/types.d.ts +45 -0
- package/dist/lib/queries/client/queries/observer/QueryObserver.d.ts +65 -0
- package/dist/lib/queries/client/queries/observer/queryStateHelpers.d.ts +9 -0
- package/dist/lib/queries/client/queries/observer/types.d.ts +241 -0
- package/dist/lib/queries/client/queries/query/Query.d.ts +71 -0
- package/dist/lib/queries/client/queries/query/delayOnNetworkMode.d.ts +6 -0
- package/dist/lib/queries/client/queries/query/delayUntilFocus.d.ts +2 -0
- package/dist/lib/queries/client/queries/query/executeQuery.d.ts +17 -0
- package/dist/lib/queries/client/queries/query/getDefaultState.d.ts +4 -0
- package/dist/lib/queries/client/queries/query/operators.d.ts +13 -0
- package/dist/lib/queries/client/queries/query/types.d.ts +93 -0
- package/dist/lib/queries/client/queries/retryer/CancelledError.d.ts +6 -0
- package/dist/lib/queries/client/queries/retryer/types.d.ts +4 -0
- package/dist/lib/queries/client/queries/retryer/utils.d.ts +2 -0
- package/dist/lib/queries/client/queries/types.d.ts +112 -0
- package/dist/lib/queries/client/queries/utils.d.ts +8 -0
- package/dist/lib/queries/client/store.d.ts +25 -0
- package/dist/lib/queries/client/tests/utils.d.ts +7 -1
- package/dist/lib/queries/client/types.d.ts +20 -11
- package/dist/lib/queries/client/utils/keepPreviousData.d.ts +1 -0
- package/dist/lib/queries/client/utils/makeObservable.d.ts +6 -0
- package/dist/lib/queries/react/QueryClientProvider.d.ts +7 -0
- package/dist/lib/queries/react/QueryClientProvider.rq.test.d.ts +1 -0
- package/dist/lib/queries/react/mutations/useIsMutating.d.ts +1 -1
- package/dist/lib/queries/react/mutations/useMutation.d.ts +1 -1
- package/dist/lib/queries/react/mutations/useMutation.switch.test.d.ts +1 -0
- package/dist/lib/queries/react/mutations/useMutationState.d.ts +2 -2
- package/dist/lib/queries/react/queries/QueryErrorResetBoundary.d.ts +11 -0
- package/dist/lib/queries/react/queries/QueryOptions.rq.types.test.d.ts +1 -0
- package/dist/lib/queries/react/queries/errorBoundaryUtils.d.ts +12 -0
- package/dist/lib/queries/react/queries/isRestoring.d.ts +3 -0
- package/dist/lib/queries/react/queries/queryOptions.d.ts +18 -0
- package/dist/lib/queries/react/queries/types.d.ts +9 -11
- package/dist/lib/queries/react/queries/useBaseQuery.d.ts +6 -0
- package/dist/lib/queries/react/queries/useIsFetching.d.ts +3 -0
- package/dist/lib/queries/react/queries/useIsFetching.rq.test.d.ts +1 -0
- package/dist/lib/queries/react/queries/useQuery.d.ts +8 -6
- package/dist/lib/queries/react/queries/useQuery.rq.test.d.ts +1 -0
- package/dist/lib/queries/react/queries/useQuery.rq.types.test.d.ts +1 -0
- package/dist/lib/queries/react/useQueryClient.d.ts +2 -0
- package/dist/lib/utils/filterObjectByKey.d.ts +1 -0
- package/dist/lib/utils/hasObjectPrototype.d.ts +1 -0
- package/dist/lib/utils/index.d.ts +1 -0
- package/dist/lib/utils/isPlainArray.d.ts +1 -0
- package/dist/lib/utils/isPlainObject.d.ts +1 -0
- package/dist/lib/utils/isPromiseLike.d.ts +1 -0
- package/dist/lib/utils/isServer.d.ts +1 -0
- package/dist/lib/utils/operators/retryBackoff.d.ts +7 -5
- package/dist/lib/utils/replaceEqualDeep.d.ts +6 -0
- package/dist/lib/utils/types.d.ts +7 -0
- package/dist/tests/testUtils.d.ts +1 -1
- package/dist/tests/utils.d.ts +12 -6
- package/package.json +10 -11
- package/dist/lib/binding/trigger.d.ts +0 -4
- package/dist/lib/binding/useObserveCallback.d.ts +0 -5
- package/dist/lib/queries/client/cache/cacheClient.d.ts +0 -12
- package/dist/lib/queries/client/cache/invalidateCache.d.ts +0 -5
- package/dist/lib/queries/client/cache/logger.d.ts +0 -24
- package/dist/lib/queries/client/cache/registerResultInCache.d.ts +0 -8
- package/dist/lib/queries/client/createClient.d.ts +0 -90
- package/dist/lib/queries/client/deduplication/deduplicate.d.ts +0 -3
- package/dist/lib/queries/client/fetch/notifyQueryResult.d.ts +0 -3
- package/dist/lib/queries/client/fetch/queryFetch.d.ts +0 -12
- package/dist/lib/queries/client/invalidation/invalidationClient.d.ts +0 -11
- package/dist/lib/queries/client/invalidation/logger.d.ts +0 -24
- package/dist/lib/queries/client/invalidation/markAsStale.d.ts +0 -8
- package/dist/lib/queries/client/keys/serializeKey.d.ts +0 -4
- package/dist/lib/queries/client/keys/withKeyComparison.d.ts +0 -16
- package/dist/lib/queries/client/operators.d.ts +0 -8
- package/dist/lib/queries/client/refetch/client.d.ts +0 -17
- package/dist/lib/queries/client/refetch/dispatchExternalRefetchToAllQueries.d.ts +0 -3
- package/dist/lib/queries/client/refetch/logger.d.ts +0 -24
- package/dist/lib/queries/client/refetch/markQueryAsStaleIfRefetch.d.ts +0 -3
- package/dist/lib/queries/client/store/createQueryStore.d.ts +0 -55
- package/dist/lib/queries/client/store/debugger.d.ts +0 -3
- package/dist/lib/queries/client/store/garbageCache.d.ts +0 -5
- package/dist/lib/queries/client/store/initializeQueryInStore.d.ts +0 -8
- package/dist/lib/queries/client/store/mapStoreQueryToRunnerOptions.d.ts +0 -4
- package/dist/lib/queries/client/store/queryListener.d.ts +0 -3
- package/dist/lib/queries/client/store/updateStoreWithNewQuery.d.ts +0 -10
- package/dist/lib/queries/client/triggers.d.ts +0 -8
- package/dist/lib/queries/client/utils/functionAsObservable.d.ts +0 -2
- package/dist/lib/queries/client/utils/wrapInPromise.d.ts +0 -3
- package/dist/lib/queries/react/Provider.d.ts +0 -12
- package/dist/lib/queries/react/queries/helpers.d.ts +0 -28
- package/dist/lib/queries/react/triggers/activityTrigger.d.ts +0 -11
- package/dist/lib/queries/react/triggers/networkTrigger.d.ts +0 -8
- package/dist/lib/queries/react/useSubscribeEffect.d.ts +0 -10
- /package/dist/lib/queries/client/{cache/cache.garbage.test.d.ts → QueryClient.types.rq.test.d.ts} +0 -0
- /package/dist/lib/queries/client/{cache/cacheClient.test.d.ts → focusManager.rq.test.d.ts} +0 -0
- /package/dist/lib/queries/client/{deduplication/deduplicate.test.d.ts → keys/hashKey.test.d.ts} +0 -0
- /package/dist/lib/queries/client/{invalidation/invalidation.test.d.ts → keys/matchKey.test.d.ts} +0 -0
- /package/dist/lib/queries/client/keys/{compareKeys.test.d.ts → partialMatchKey.rq.test.d.ts} +0 -0
- /package/dist/lib/queries/client/{keys/keys.test.d.ts → mutations/cache/mutationCache.rq.test.d.ts} +0 -0
- /package/dist/lib/queries/client/{keys/serializeKey.test.d.ts → queries/observer/QueryObserver.rq.test.d.ts} +0 -0
- /package/dist/lib/queries/client/{mutations/cache/mutationCache.test.d.ts → queries/observer/QueryObserver.types.rq.test.d.ts} +0 -0
- /package/dist/lib/queries/client/{refetch/refetch.test.d.ts → queries/query/query.rq.test.d.ts} +0 -0
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { type NonFunctionGuard, type WithRequired } from "../../../../utils/types";
|
|
2
|
+
import { type QueryKey } from "../../keys/types";
|
|
3
|
+
import { type DefaultError } from "../../types";
|
|
4
|
+
import { type Query } from "../query/Query";
|
|
5
|
+
import { type ThrowOnError, type QueryOptions, type PlaceholderDataFunction, type NotifyOnChangeProps, type RefetchOptions, type QueryStatus, type FetchStatus, type FetchNextPageOptions, type FetchPreviousPageOptions } from "../types";
|
|
6
|
+
export interface QueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> extends QueryOptions<TQueryFnData, TError, TQueryData, TQueryKey, TPageParam> {
|
|
7
|
+
/**
|
|
8
|
+
* Set this to `false` to disable automatic refetching when the query mounts or changes query keys.
|
|
9
|
+
* To refetch the query, use the `refetch` method returned from the `useQuery` instance.
|
|
10
|
+
* Defaults to `true`.
|
|
11
|
+
*/
|
|
12
|
+
enabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* The time in milliseconds after data is considered stale.
|
|
15
|
+
* If set to `Infinity`, the data will never be considered stale.
|
|
16
|
+
*/
|
|
17
|
+
staleTime?: number;
|
|
18
|
+
/**
|
|
19
|
+
* If set to a number, the query will continuously refetch at this frequency in milliseconds.
|
|
20
|
+
* If set to a function, the function will be executed with the latest data and query to compute a frequency
|
|
21
|
+
* Defaults to `false`.
|
|
22
|
+
*/
|
|
23
|
+
refetchInterval?: number | false | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => number | false | undefined);
|
|
24
|
+
/**
|
|
25
|
+
* If set to `true`, the query will continue to refetch while their tab/window is in the background.
|
|
26
|
+
* Defaults to `false`.
|
|
27
|
+
*/
|
|
28
|
+
refetchIntervalInBackground?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* If set to `true`, the query will refetch on window focus if the data is stale.
|
|
31
|
+
* If set to `false`, the query will not refetch on window focus.
|
|
32
|
+
* If set to `'always'`, the query will always refetch on window focus.
|
|
33
|
+
* If set to a function, the function will be executed with the latest data and query to compute the value.
|
|
34
|
+
* Defaults to `true`.
|
|
35
|
+
*/
|
|
36
|
+
refetchOnWindowFocus?: boolean | "always" | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => boolean | "always");
|
|
37
|
+
/**
|
|
38
|
+
* If set to `true`, the query will refetch on reconnect if the data is stale.
|
|
39
|
+
* If set to `false`, the query will not refetch on reconnect.
|
|
40
|
+
* If set to `'always'`, the query will always refetch on reconnect.
|
|
41
|
+
* If set to a function, the function will be executed with the latest data and query to compute the value.
|
|
42
|
+
* Defaults to the value of `networkOnline` (`true`)
|
|
43
|
+
*/
|
|
44
|
+
refetchOnReconnect?: boolean | "always" | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => boolean | "always");
|
|
45
|
+
/**
|
|
46
|
+
* If set to `true`, the query will refetch on mount if the data is stale.
|
|
47
|
+
* If set to `false`, will disable additional instances of a query to trigger background refetches.
|
|
48
|
+
* If set to `'always'`, the query will always refetch on mount.
|
|
49
|
+
* If set to a function, the function will be executed with the latest data and query to compute the value
|
|
50
|
+
* Defaults to `true`.
|
|
51
|
+
*/
|
|
52
|
+
refetchOnMount?: boolean | "always" | ((query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => boolean | "always");
|
|
53
|
+
/**
|
|
54
|
+
* If set to `false`, the query will not be retried on mount if it contains an error.
|
|
55
|
+
* Defaults to `true`.
|
|
56
|
+
*/
|
|
57
|
+
retryOnMount?: boolean;
|
|
58
|
+
/**
|
|
59
|
+
* If set, the component will only re-render if any of the listed properties change.
|
|
60
|
+
* When set to `['data', 'error']`, the component will only re-render when the `data` or `error` properties change.
|
|
61
|
+
* When set to `'all'`, the component will re-render whenever a query is updated.
|
|
62
|
+
* When set to a function, the function will be executed to compute the list of properties.
|
|
63
|
+
* By default, access to properties will be tracked, and the component will only re-render when one of the tracked properties change.
|
|
64
|
+
*/
|
|
65
|
+
notifyOnChangeProps?: NotifyOnChangeProps;
|
|
66
|
+
/**
|
|
67
|
+
* Whether errors should be thrown instead of setting the `error` property.
|
|
68
|
+
* If set to `true` or `suspense` is `true`, all errors will be thrown to the error boundary.
|
|
69
|
+
* If set to `false` and `suspense` is `false`, errors are returned as state.
|
|
70
|
+
* If set to a function, it will be passed the error and the query, and it should return a boolean indicating whether to show the error in an error boundary (`true`) or return the error as state (`false`).
|
|
71
|
+
* Defaults to `false`.
|
|
72
|
+
*/
|
|
73
|
+
throwOnError?: ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey>;
|
|
74
|
+
/**
|
|
75
|
+
* This option can be used to transform or select a part of the data returned by the query function.
|
|
76
|
+
*/
|
|
77
|
+
select?: (data: TQueryData) => TData;
|
|
78
|
+
/**
|
|
79
|
+
* If set to `true`, the query will suspend when `status === 'pending'`
|
|
80
|
+
* and throw errors when `status === 'error'`.
|
|
81
|
+
* Defaults to `false`.
|
|
82
|
+
*/
|
|
83
|
+
suspense?: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* If set, this value will be used as the placeholder data for this particular query observer while the query is still in the `loading` data and no initialData has been provided.
|
|
86
|
+
*/
|
|
87
|
+
placeholderData?: NonFunctionGuard<TQueryData> | PlaceholderDataFunction<NonFunctionGuard<TQueryData>, TError, NonFunctionGuard<TQueryData>, TQueryKey>;
|
|
88
|
+
_optimisticResults?: "optimistic" | "isRestoring";
|
|
89
|
+
}
|
|
90
|
+
export type DefaultedQueryObserverOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = WithRequired<QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>, "throwOnError" | "refetchOnReconnect" | "queryHash">;
|
|
91
|
+
export interface QueryObserverBaseResult<TData = unknown, TError = DefaultError> {
|
|
92
|
+
data: TData | undefined;
|
|
93
|
+
dataUpdatedAt: number;
|
|
94
|
+
error: TError | null;
|
|
95
|
+
errorUpdatedAt: number;
|
|
96
|
+
failureCount: number;
|
|
97
|
+
failureReason: TError | null;
|
|
98
|
+
errorUpdateCount: number;
|
|
99
|
+
isError: boolean;
|
|
100
|
+
isFetched: boolean;
|
|
101
|
+
isFetchedAfterMount: boolean;
|
|
102
|
+
isFetching: boolean;
|
|
103
|
+
isLoading: boolean;
|
|
104
|
+
isPending: boolean;
|
|
105
|
+
isLoadingError: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* @deprecated isInitialLoading is being deprecated in favor of isLoading
|
|
108
|
+
* and will be removed in the next major version.
|
|
109
|
+
*/
|
|
110
|
+
isInitialLoading: boolean;
|
|
111
|
+
isPaused: boolean;
|
|
112
|
+
isPlaceholderData: boolean;
|
|
113
|
+
isRefetchError: boolean;
|
|
114
|
+
isRefetching: boolean;
|
|
115
|
+
isStale: boolean;
|
|
116
|
+
isSuccess: boolean;
|
|
117
|
+
refetch: (options?: RefetchOptions) => Promise<QueryObserverResult<TData, TError>>;
|
|
118
|
+
status: QueryStatus;
|
|
119
|
+
fetchStatus: FetchStatus;
|
|
120
|
+
}
|
|
121
|
+
export interface QueryObserverPendingResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
122
|
+
data: undefined;
|
|
123
|
+
error: null;
|
|
124
|
+
isError: false;
|
|
125
|
+
isPending: true;
|
|
126
|
+
isLoadingError: false;
|
|
127
|
+
isRefetchError: false;
|
|
128
|
+
isSuccess: false;
|
|
129
|
+
status: "pending";
|
|
130
|
+
}
|
|
131
|
+
export interface QueryObserverLoadingErrorResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
132
|
+
data: undefined;
|
|
133
|
+
error: TError;
|
|
134
|
+
isError: true;
|
|
135
|
+
isPending: false;
|
|
136
|
+
isLoading: false;
|
|
137
|
+
isLoadingError: true;
|
|
138
|
+
isRefetchError: false;
|
|
139
|
+
isSuccess: false;
|
|
140
|
+
status: "error";
|
|
141
|
+
}
|
|
142
|
+
export interface QueryObserverRefetchErrorResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
143
|
+
data: TData;
|
|
144
|
+
error: TError;
|
|
145
|
+
isError: true;
|
|
146
|
+
isPending: false;
|
|
147
|
+
isLoading: false;
|
|
148
|
+
isLoadingError: false;
|
|
149
|
+
isRefetchError: true;
|
|
150
|
+
isSuccess: false;
|
|
151
|
+
status: "error";
|
|
152
|
+
}
|
|
153
|
+
export interface InfiniteQueryObserverSuccessResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
|
|
154
|
+
data: TData;
|
|
155
|
+
error: null;
|
|
156
|
+
isError: false;
|
|
157
|
+
isPending: false;
|
|
158
|
+
isLoading: false;
|
|
159
|
+
isLoadingError: false;
|
|
160
|
+
isRefetchError: false;
|
|
161
|
+
isSuccess: true;
|
|
162
|
+
status: "success";
|
|
163
|
+
}
|
|
164
|
+
export interface InfiniteQueryObserverRefetchErrorResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
|
|
165
|
+
data: TData;
|
|
166
|
+
error: TError;
|
|
167
|
+
isError: true;
|
|
168
|
+
isPending: false;
|
|
169
|
+
isLoading: false;
|
|
170
|
+
isLoadingError: false;
|
|
171
|
+
isRefetchError: true;
|
|
172
|
+
isSuccess: false;
|
|
173
|
+
status: "error";
|
|
174
|
+
}
|
|
175
|
+
export type DefinedInfiniteQueryObserverResult<TData = unknown, TError = DefaultError> = InfiniteQueryObserverRefetchErrorResult<TData, TError> | InfiniteQueryObserverSuccessResult<TData, TError>;
|
|
176
|
+
export interface InfiniteQueryObserverBaseResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
177
|
+
fetchNextPage: (options?: FetchNextPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
178
|
+
fetchPreviousPage: (options?: FetchPreviousPageOptions) => Promise<InfiniteQueryObserverResult<TData, TError>>;
|
|
179
|
+
hasNextPage: boolean;
|
|
180
|
+
hasPreviousPage: boolean;
|
|
181
|
+
isFetchingNextPage: boolean;
|
|
182
|
+
isFetchingPreviousPage: boolean;
|
|
183
|
+
}
|
|
184
|
+
export interface QueryObserverSuccessResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
185
|
+
data: TData;
|
|
186
|
+
error: null;
|
|
187
|
+
isError: false;
|
|
188
|
+
isPending: false;
|
|
189
|
+
isLoading: false;
|
|
190
|
+
isLoadingError: false;
|
|
191
|
+
isRefetchError: false;
|
|
192
|
+
isSuccess: true;
|
|
193
|
+
status: "success";
|
|
194
|
+
}
|
|
195
|
+
export interface QueryObserverLoadingResult<TData = unknown, TError = DefaultError> extends QueryObserverBaseResult<TData, TError> {
|
|
196
|
+
data: undefined;
|
|
197
|
+
error: null;
|
|
198
|
+
isError: false;
|
|
199
|
+
isPending: true;
|
|
200
|
+
isLoading: true;
|
|
201
|
+
isLoadingError: false;
|
|
202
|
+
isRefetchError: false;
|
|
203
|
+
isSuccess: false;
|
|
204
|
+
status: "pending";
|
|
205
|
+
}
|
|
206
|
+
export type DefinedQueryObserverResult<TData = unknown, TError = DefaultError> = QueryObserverRefetchErrorResult<TData, TError> | QueryObserverSuccessResult<TData, TError>;
|
|
207
|
+
export interface InfiniteQueryObserverPendingResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
|
|
208
|
+
data: undefined;
|
|
209
|
+
error: null;
|
|
210
|
+
isError: false;
|
|
211
|
+
isPending: true;
|
|
212
|
+
isLoadingError: false;
|
|
213
|
+
isRefetchError: false;
|
|
214
|
+
isSuccess: false;
|
|
215
|
+
status: "pending";
|
|
216
|
+
}
|
|
217
|
+
export interface InfiniteQueryObserverLoadingResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
|
|
218
|
+
data: undefined;
|
|
219
|
+
error: null;
|
|
220
|
+
isError: false;
|
|
221
|
+
isPending: true;
|
|
222
|
+
isLoading: true;
|
|
223
|
+
isLoadingError: false;
|
|
224
|
+
isRefetchError: false;
|
|
225
|
+
isSuccess: false;
|
|
226
|
+
status: "pending";
|
|
227
|
+
}
|
|
228
|
+
export interface InfiniteQueryObserverLoadingErrorResult<TData = unknown, TError = DefaultError> extends InfiniteQueryObserverBaseResult<TData, TError> {
|
|
229
|
+
data: undefined;
|
|
230
|
+
error: TError;
|
|
231
|
+
isError: true;
|
|
232
|
+
isPending: false;
|
|
233
|
+
isLoading: false;
|
|
234
|
+
isLoadingError: true;
|
|
235
|
+
isRefetchError: false;
|
|
236
|
+
isSuccess: false;
|
|
237
|
+
status: "error";
|
|
238
|
+
}
|
|
239
|
+
export type QueryObserverResult<TData = unknown, TError = DefaultError> = DefinedQueryObserverResult<TData, TError> | QueryObserverLoadingErrorResult<TData, TError> | QueryObserverLoadingResult<TData, TError> | QueryObserverPendingResult<TData, TError>;
|
|
240
|
+
export type InfiniteQueryObserverResult<TData = unknown, TError = DefaultError> = DefinedInfiniteQueryObserverResult<TData, TError> | InfiniteQueryObserverLoadingErrorResult<TData, TError> | InfiniteQueryObserverLoadingResult<TData, TError> | InfiniteQueryObserverPendingResult<TData, TError>;
|
|
241
|
+
export type QueryObserverListener<TData, TError> = (result: QueryObserverResult<TData, TError>) => void;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type Observable, Subject, BehaviorSubject } from "rxjs";
|
|
2
|
+
import { type QueryKey } from "../../keys/types";
|
|
3
|
+
import { type DefaultError } from "../../types";
|
|
4
|
+
import { type QueryCache } from "../cache/QueryCache";
|
|
5
|
+
import { type SetDataOptions, type QueryOptions } from "../types";
|
|
6
|
+
import { type QueryMeta, type FetchOptions, type QueryState } from "./types";
|
|
7
|
+
import { type CancelOptions } from "../retryer/types";
|
|
8
|
+
import { type QueryObserver } from "../observer/QueryObserver";
|
|
9
|
+
interface QueryConfig<TQueryFnData, TError, TData, TQueryKey extends QueryKey = QueryKey> {
|
|
10
|
+
cache: QueryCache;
|
|
11
|
+
queryKey: TQueryKey;
|
|
12
|
+
queryHash: string;
|
|
13
|
+
options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>;
|
|
14
|
+
defaultOptions?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>;
|
|
15
|
+
state?: QueryState<TData, TError>;
|
|
16
|
+
}
|
|
17
|
+
export declare class Query<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
|
|
18
|
+
#private;
|
|
19
|
+
queryKey: TQueryKey;
|
|
20
|
+
queryHash: string;
|
|
21
|
+
gcTime: number;
|
|
22
|
+
options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>;
|
|
23
|
+
state: QueryState<TData, TError>;
|
|
24
|
+
protected executeSubject: Subject<FetchOptions | undefined>;
|
|
25
|
+
protected cancelSubject: Subject<CancelOptions | undefined>;
|
|
26
|
+
protected setDataSubject: Subject<{
|
|
27
|
+
data: TData;
|
|
28
|
+
options?: (SetDataOptions & {
|
|
29
|
+
manual: boolean;
|
|
30
|
+
}) | undefined;
|
|
31
|
+
}>;
|
|
32
|
+
protected invalidatedSubject: Subject<void>;
|
|
33
|
+
protected resetSubject: Subject<void>;
|
|
34
|
+
protected destroySubject: Subject<void>;
|
|
35
|
+
protected observersSubject: BehaviorSubject<QueryObserver<unknown, Error, unknown, unknown, QueryKey>[]>;
|
|
36
|
+
protected abortSignalConsumed: boolean;
|
|
37
|
+
observerCount$: Observable<number>;
|
|
38
|
+
observers$: Observable<QueryObserver<unknown, Error, unknown, unknown, QueryKey>[]>;
|
|
39
|
+
state$: Observable<typeof this.state>;
|
|
40
|
+
constructor(config: QueryConfig<TQueryFnData, TError, TData, TQueryKey>);
|
|
41
|
+
setOptions(options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>): QueryOptions<TQueryFnData, TError, TData, TQueryKey, never>;
|
|
42
|
+
get meta(): QueryMeta | undefined;
|
|
43
|
+
get success$(): Observable<{
|
|
44
|
+
data: TData | undefined;
|
|
45
|
+
status: import("../types").QueryStatus;
|
|
46
|
+
}>;
|
|
47
|
+
get error$(): Observable<{
|
|
48
|
+
error: TError | null;
|
|
49
|
+
status: import("../types").QueryStatus;
|
|
50
|
+
}>;
|
|
51
|
+
get settled$(): Observable<{
|
|
52
|
+
status: import("../types").QueryStatus;
|
|
53
|
+
}>;
|
|
54
|
+
observe(observer: QueryObserver<any, any, any, any, any>): Observable<QueryState<TData, TError>>;
|
|
55
|
+
getObserversCount(): number;
|
|
56
|
+
protected updateGcTime(newGcTime: number | undefined): number;
|
|
57
|
+
isActive(): boolean;
|
|
58
|
+
isDisabled(): boolean;
|
|
59
|
+
isStale(): boolean;
|
|
60
|
+
isStaleByTime(staleTime?: number): boolean;
|
|
61
|
+
getFetchResultAsPromise(): Promise<TData>;
|
|
62
|
+
fetch(options?: QueryOptions<TQueryFnData, TError, TData, TQueryKey>, fetchOptions?: FetchOptions): Promise<TData>;
|
|
63
|
+
setData(newData: TData, options?: SetDataOptions & {
|
|
64
|
+
manual: boolean;
|
|
65
|
+
}): TData;
|
|
66
|
+
invalidate(): void;
|
|
67
|
+
cancel(options?: CancelOptions): Promise<void>;
|
|
68
|
+
destroy(): void;
|
|
69
|
+
reset(): void;
|
|
70
|
+
}
|
|
71
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Observable } from "rxjs";
|
|
2
|
+
import { type QueryOptions } from "../types";
|
|
3
|
+
import { type QueryState } from "./types";
|
|
4
|
+
type Result<TData, TError> = Partial<QueryState<TData, TError>>;
|
|
5
|
+
export declare const delayOnNetworkMode: <TData, TError>(options: Pick<QueryOptions, "networkMode">) => (source: Observable<Partial<QueryState<TData, TError>>>) => Observable<Partial<QueryState<TData, TError>>>;
|
|
6
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type QueryKey } from "../../keys/types";
|
|
2
|
+
import { type QueryState } from "./types";
|
|
3
|
+
import { type QueryOptions } from "../types";
|
|
4
|
+
export declare const executeQuery: <TQueryFnData = unknown, TError = Error, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(options: QueryOptions<TQueryFnData, TError, TData, TQueryKey, never> & {
|
|
5
|
+
queryKey: TQueryKey;
|
|
6
|
+
onSignalConsumed: () => void;
|
|
7
|
+
retry: (attempt: number, error: TError) => boolean;
|
|
8
|
+
retryAfterDelay: (attempt: number, error: TError) => boolean;
|
|
9
|
+
}) => {
|
|
10
|
+
state$: import("rxjs").Observable<Partial<QueryState<TData, TError>> | {
|
|
11
|
+
status: "pending";
|
|
12
|
+
fetchStatus: "fetching" | "paused";
|
|
13
|
+
} | {
|
|
14
|
+
fetchStatus: "idle";
|
|
15
|
+
}>;
|
|
16
|
+
abortController: AbortController;
|
|
17
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type QueryKey } from "../../keys/types";
|
|
2
|
+
import { type QueryOptions } from "../types";
|
|
3
|
+
import { type QueryState } from "./types";
|
|
4
|
+
export declare function getDefaultState<TQueryFnData, TError, TData, TQueryKey extends QueryKey>(options: QueryOptions<TQueryFnData, TError, TData, TQueryKey>): QueryState<TData, TError>;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Observable } from "rxjs";
|
|
2
|
+
import { type QueryOptions } from "../types";
|
|
3
|
+
import { type QueryState } from "./types";
|
|
4
|
+
export declare const reduceState: <TQueryFnData = unknown, TError = Error, TData = TQueryFnData>({ getOptions, getState, initialState }: {
|
|
5
|
+
initialState: QueryState<TData, TError>;
|
|
6
|
+
getState: () => QueryState<TData, TError>;
|
|
7
|
+
getOptions: () => QueryOptions<TQueryFnData, TError, TData, any, never>;
|
|
8
|
+
}) => (source: Observable<{
|
|
9
|
+
command: "invalidate" | "cancel" | "reset" | "setData" | "execute";
|
|
10
|
+
state: Partial<QueryState<TData, TError>>;
|
|
11
|
+
}>) => Observable<QueryState<TData, TError>>;
|
|
12
|
+
export declare const isQueryFinished: <TQueryFnData = unknown, TError = Error, TData = TQueryFnData>(source: Observable<Partial<QueryState<TData, TError>>>) => Observable<boolean>;
|
|
13
|
+
export declare const takeUntilFinished: <TQueryFnData = unknown, TError = Error, TData = TQueryFnData>(source: Observable<Partial<QueryState<TData, TError>>>) => Observable<Partial<QueryState<TData, TError>>>;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { type Observable } from "rxjs";
|
|
2
|
+
import { type QueryKey } from "../../keys/types";
|
|
3
|
+
import { type DefaultError, type Register } from "../../types";
|
|
4
|
+
import { type FetchStatus, type QueryStatus, type QueryOptions } from "../types";
|
|
5
|
+
import { type Query } from "./Query";
|
|
6
|
+
export interface SetStateOptions {
|
|
7
|
+
meta?: any;
|
|
8
|
+
}
|
|
9
|
+
export type FetchDirection = "forward" | "backward";
|
|
10
|
+
export interface QueryState<TData = unknown, TError = DefaultError> {
|
|
11
|
+
data: TData | undefined;
|
|
12
|
+
dataUpdateCount: number;
|
|
13
|
+
dataUpdatedAt: number;
|
|
14
|
+
error: TError | null;
|
|
15
|
+
errorUpdateCount: number;
|
|
16
|
+
errorUpdatedAt: number;
|
|
17
|
+
fetchFailureCount: number;
|
|
18
|
+
fetchFailureReason: TError | null;
|
|
19
|
+
fetchMeta: FetchMeta | null;
|
|
20
|
+
isInvalidated: boolean;
|
|
21
|
+
status: QueryStatus;
|
|
22
|
+
fetchStatus: FetchStatus;
|
|
23
|
+
}
|
|
24
|
+
export type QueryMeta = Register extends {
|
|
25
|
+
queryMeta: infer TQueryMeta;
|
|
26
|
+
} ? TQueryMeta extends Record<string, unknown> ? TQueryMeta : Record<string, unknown> : Record<string, unknown>;
|
|
27
|
+
export type QueryFunctionContext<TQueryKey extends QueryKey = QueryKey, TPageParam = never> = [TPageParam] extends [never] ? {
|
|
28
|
+
queryKey: TQueryKey;
|
|
29
|
+
signal: AbortSignal;
|
|
30
|
+
meta: QueryMeta | undefined;
|
|
31
|
+
} : {
|
|
32
|
+
queryKey: TQueryKey;
|
|
33
|
+
signal: AbortSignal;
|
|
34
|
+
pageParam: TPageParam;
|
|
35
|
+
direction: FetchDirection;
|
|
36
|
+
meta: QueryMeta | undefined;
|
|
37
|
+
};
|
|
38
|
+
export type QueryFunction<T = unknown, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = ((context: QueryFunctionContext<TQueryKey, TPageParam>) => T | Promise<T> | Observable<T>) | Observable<T>;
|
|
39
|
+
export interface FetchMeta {
|
|
40
|
+
fetchMore?: {
|
|
41
|
+
direction: FetchDirection;
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export interface FetchOptions {
|
|
45
|
+
cancelRefetch?: boolean;
|
|
46
|
+
meta?: FetchMeta;
|
|
47
|
+
}
|
|
48
|
+
export interface FetchContext<TQueryFnData, TError, TData, TQueryKey extends QueryKey = QueryKey> {
|
|
49
|
+
fetchFn: () => unknown | Promise<unknown>;
|
|
50
|
+
fetchOptions?: FetchOptions;
|
|
51
|
+
signal: AbortSignal;
|
|
52
|
+
options: QueryOptions<TQueryFnData, TError, TData, any>;
|
|
53
|
+
queryKey: TQueryKey;
|
|
54
|
+
state: QueryState<TData, TError>;
|
|
55
|
+
}
|
|
56
|
+
export interface QueryBehavior<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> {
|
|
57
|
+
onFetch: (context: FetchContext<TQueryFnData, TError, TData, TQueryKey>, query: Query) => void;
|
|
58
|
+
}
|
|
59
|
+
interface FailedAction<TError> {
|
|
60
|
+
type: "failed";
|
|
61
|
+
failureCount: number;
|
|
62
|
+
error: TError;
|
|
63
|
+
}
|
|
64
|
+
interface FetchAction {
|
|
65
|
+
type: "fetch";
|
|
66
|
+
meta?: FetchMeta;
|
|
67
|
+
}
|
|
68
|
+
interface SuccessAction<TData> {
|
|
69
|
+
data: TData | undefined;
|
|
70
|
+
type: "success";
|
|
71
|
+
dataUpdatedAt?: number;
|
|
72
|
+
manual?: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface ErrorAction<TError> {
|
|
75
|
+
type: "error";
|
|
76
|
+
error: TError;
|
|
77
|
+
}
|
|
78
|
+
interface InvalidateAction {
|
|
79
|
+
type: "invalidate";
|
|
80
|
+
}
|
|
81
|
+
interface PauseAction {
|
|
82
|
+
type: "pause";
|
|
83
|
+
}
|
|
84
|
+
interface ContinueAction {
|
|
85
|
+
type: "continue";
|
|
86
|
+
}
|
|
87
|
+
interface SetStateAction<TData, TError> {
|
|
88
|
+
type: "setState";
|
|
89
|
+
state: Partial<QueryState<TData, TError>>;
|
|
90
|
+
setStateOptions?: SetStateOptions;
|
|
91
|
+
}
|
|
92
|
+
export type Action<TData, TError> = ContinueAction | ErrorAction<TError> | FailedAction<TError> | FetchAction | InvalidateAction | PauseAction | SetStateAction<TData, TError> | SuccessAction<TData>;
|
|
93
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { type NoInfer, type WithRequired } from "../../../utils/types";
|
|
2
|
+
import { type QueryKey } from "../keys/types";
|
|
3
|
+
import { type DefaultError } from "../types";
|
|
4
|
+
import { type InfiniteQueryObserverResult } from "./observer/types";
|
|
5
|
+
import { type Query } from "./query/Query";
|
|
6
|
+
import { type QueryMeta, type QueryFunction, type QueryFunctionContext, type QueryBehavior } from "./query/types";
|
|
7
|
+
export declare const dataTagSymbol: unique symbol;
|
|
8
|
+
export type DataTag<Type, Value> = Type & {
|
|
9
|
+
[dataTagSymbol]: Value;
|
|
10
|
+
};
|
|
11
|
+
export type Updater<TInput, TOutput> = TOutput | ((input: TInput) => TOutput);
|
|
12
|
+
export interface SetDataOptions {
|
|
13
|
+
updatedAt?: number;
|
|
14
|
+
}
|
|
15
|
+
export type QueryStatus = "pending" | "error" | "success";
|
|
16
|
+
export type FetchStatus = "fetching" | "paused" | "idle";
|
|
17
|
+
export type NetworkMode = "online" | "always" | "offlineFirst";
|
|
18
|
+
export type QueryKeyHashFunction<TQueryKey extends QueryKey> = (queryKey: TQueryKey) => string;
|
|
19
|
+
export type InitialDataFunction<T> = () => T | undefined;
|
|
20
|
+
export interface ResultOptions {
|
|
21
|
+
throwOnError?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface RefetchOptions extends ResultOptions {
|
|
24
|
+
cancelRefetch?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface FetchNextPageOptions extends ResultOptions {
|
|
27
|
+
cancelRefetch?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface FetchPreviousPageOptions extends ResultOptions {
|
|
30
|
+
cancelRefetch?: boolean;
|
|
31
|
+
}
|
|
32
|
+
export type NotifyOnChangeProps = Array<keyof InfiniteQueryObserverResult> | "all" | (() => Array<keyof InfiniteQueryObserverResult> | "all");
|
|
33
|
+
export type ThrowOnError<TQueryFnData, TError, TQueryData, TQueryKey extends QueryKey> = boolean | ((error: TError, query: Query<TQueryFnData, TError, TQueryData, TQueryKey>) => boolean);
|
|
34
|
+
export type QueryPersister<T = unknown, TQueryKey extends QueryKey = QueryKey, TPageParam = never> = [TPageParam] extends [never] ? (queryFn: QueryFunction<T, TQueryKey, never>, context: QueryFunctionContext<TQueryKey>, query: Query) => T | Promise<T> : (queryFn: QueryFunction<T, TQueryKey, TPageParam>, context: QueryFunctionContext<TQueryKey>, query: Query) => T | Promise<T>;
|
|
35
|
+
export interface QueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> {
|
|
36
|
+
/**
|
|
37
|
+
* If `false`, failed queries will not retry by default.
|
|
38
|
+
* If `true`, failed queries will retry infinitely., failureCount: num
|
|
39
|
+
* If set to an integer number, e.g. 3, failed queries will retry until the failed query count meets that number.
|
|
40
|
+
* If set to a function `(failureCount, error) => boolean` failed queries will retry until the function returns false.
|
|
41
|
+
*/
|
|
42
|
+
retry?: boolean | number | ((failureCount: number, error: TError) => boolean);
|
|
43
|
+
retryDelay?: number | ((failureCount: number, error: TError) => number);
|
|
44
|
+
networkMode?: NetworkMode;
|
|
45
|
+
/**
|
|
46
|
+
* The time in milliseconds that unused/inactive cache data remains in memory.
|
|
47
|
+
* When a query's cache becomes unused or inactive, that cache data will be garbage collected after this duration.
|
|
48
|
+
* When different garbage collection times are specified, the longest one will be used.
|
|
49
|
+
* Setting it to `Infinity` will disable garbage collection.
|
|
50
|
+
*/
|
|
51
|
+
gcTime?: number;
|
|
52
|
+
queryFn?: QueryFunction<TQueryFnData, TQueryKey, TPageParam>;
|
|
53
|
+
persister?: QueryPersister<NoInfer<TQueryFnData>, NoInfer<TQueryKey>, NoInfer<TPageParam>>;
|
|
54
|
+
queryHash?: string;
|
|
55
|
+
queryKey?: TQueryKey;
|
|
56
|
+
queryKeyHashFn?: QueryKeyHashFunction<TQueryKey>;
|
|
57
|
+
initialData?: TData | InitialDataFunction<TData>;
|
|
58
|
+
initialDataUpdatedAt?: number | (() => number | undefined);
|
|
59
|
+
behavior?: QueryBehavior<TQueryFnData, TError, TData, TQueryKey>;
|
|
60
|
+
/**
|
|
61
|
+
* Set this to `false` to disable structural sharing between query results.
|
|
62
|
+
* Set this to a function which accepts the old and new data and returns resolved data of the same type to implement custom structural sharing logic.
|
|
63
|
+
* Defaults to `true`.
|
|
64
|
+
*/
|
|
65
|
+
structuralSharing?: boolean | (<T>(oldData: T | undefined, newData: T) => T);
|
|
66
|
+
_defaulted?: boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Additional payload to be stored on each query.
|
|
69
|
+
* Use this property to pass information that can be used in other places.
|
|
70
|
+
*/
|
|
71
|
+
meta?: QueryMeta;
|
|
72
|
+
/**
|
|
73
|
+
* Maximum number of pages to store in the data of an infinite query.
|
|
74
|
+
*/
|
|
75
|
+
maxPages?: number;
|
|
76
|
+
}
|
|
77
|
+
export type QueryTypeFilter = "all" | "active" | "inactive";
|
|
78
|
+
export interface QueryFilters {
|
|
79
|
+
/**
|
|
80
|
+
* Filter to active queries, inactive queries or all queries
|
|
81
|
+
*/
|
|
82
|
+
type?: QueryTypeFilter;
|
|
83
|
+
/**
|
|
84
|
+
* Match query key exactly
|
|
85
|
+
*/
|
|
86
|
+
exact?: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Include queries matching this predicate function
|
|
89
|
+
*/
|
|
90
|
+
predicate?: (query: Query) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Include queries matching this query key
|
|
93
|
+
*/
|
|
94
|
+
queryKey?: QueryKey;
|
|
95
|
+
/**
|
|
96
|
+
* Include or exclude stale queries
|
|
97
|
+
*/
|
|
98
|
+
stale?: boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Include queries matching their fetchStatus
|
|
101
|
+
*/
|
|
102
|
+
fetchStatus?: FetchStatus;
|
|
103
|
+
}
|
|
104
|
+
export type PlaceholderDataFunction<TQueryFnData = unknown, TError = DefaultError, TQueryData = TQueryFnData, TQueryKey extends QueryKey = QueryKey> = (previousData: TQueryData | undefined, previousQuery: Query<TQueryFnData, TError, TQueryData, TQueryKey> | undefined) => TQueryData | undefined;
|
|
105
|
+
export interface FetchQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey, TPageParam = never> extends WithRequired<QueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, "queryKey"> {
|
|
106
|
+
/**
|
|
107
|
+
* The time in milliseconds after data is considered stale.
|
|
108
|
+
* If the data is fresh it will be returned from the cache.
|
|
109
|
+
*/
|
|
110
|
+
staleTime?: number;
|
|
111
|
+
}
|
|
112
|
+
export type QueriesPlaceholderDataFunction<TQueryData> = (previousData: undefined, previousQuery: undefined) => TQueryData | undefined;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type QueryKey } from "../keys/types";
|
|
2
|
+
import { type Query } from "./query/Query";
|
|
3
|
+
import { type QueryOptions, type QueryFilters, type Updater } from "./types";
|
|
4
|
+
export declare function hashQueryKeyByOptions<TQueryKey extends QueryKey = QueryKey>(queryKey: TQueryKey, options?: QueryOptions<any, any, any, TQueryKey>): string;
|
|
5
|
+
export declare function matchQuery(filters: QueryFilters, query: Query<any, any, any, any>): boolean;
|
|
6
|
+
export declare function timeUntilStale(updatedAt: number, staleTime?: number): number;
|
|
7
|
+
export declare function functionalUpdate<TInput, TOutput>(updater: Updater<TInput, TOutput>, input: TInput): TOutput;
|
|
8
|
+
export declare function replaceData<TData, TOptions extends QueryOptions<any, any, any, any>>(prevData: TData | undefined, data: TData, options: TOptions): TData;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { BehaviorSubject, type Observable, Subject } from "rxjs";
|
|
2
|
+
export declare class Store<Entity extends {
|
|
3
|
+
state$: Observable<any>;
|
|
4
|
+
}> {
|
|
5
|
+
/**
|
|
6
|
+
* @important
|
|
7
|
+
* Query store. Could be turned into a map for more performance.
|
|
8
|
+
*/
|
|
9
|
+
protected readonly entriesSubject: BehaviorSubject<Entity[]>;
|
|
10
|
+
protected readonly changeSubject: Subject<{
|
|
11
|
+
entity: Entity;
|
|
12
|
+
} & ({
|
|
13
|
+
type: "added";
|
|
14
|
+
} | {
|
|
15
|
+
type: "removed";
|
|
16
|
+
})>;
|
|
17
|
+
readonly entries$: Observable<Entity[]>;
|
|
18
|
+
readonly added$: Observable<Entity>;
|
|
19
|
+
readonly removed$: Observable<Entity>;
|
|
20
|
+
readonly stateChange$: Observable<Entity>;
|
|
21
|
+
getValues(): Entity[];
|
|
22
|
+
remove(entity: Entity): void;
|
|
23
|
+
add(entity: Entity): void;
|
|
24
|
+
find(predicate: (entity: Entity) => boolean): Entity | undefined;
|
|
25
|
+
}
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { type QueryClient } from "../
|
|
1
|
+
import { type QueryClient } from "../QueryClient";
|
|
2
2
|
import { type MutationOptions } from "../mutations/mutation/types";
|
|
3
|
+
import { type SpyInstance } from "vitest";
|
|
3
4
|
export declare function queryKey(): string[];
|
|
4
5
|
export declare const executeMutation: <TVariables>(queryClient: QueryClient, options: MutationOptions<any, any, TVariables, any>, variables: TVariables) => Promise<import("../mutations/mutation/types").MutationState<any, any, TVariables, any>>;
|
|
6
|
+
export declare function mockOnlineManagerIsOnline(value: boolean): {
|
|
7
|
+
mockReturnValue: (_: boolean) => void;
|
|
8
|
+
mockRestore: () => void;
|
|
9
|
+
};
|
|
10
|
+
export declare function mockVisibilityState(value: DocumentVisibilityState): SpyInstance<[], DocumentVisibilityState>;
|