@tanstack/vue-query 5.0.0-alpha.1 → 5.0.0-alpha.2
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/build/lib/mutationCache.d.ts +2 -2
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +2 -2
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +6 -6
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/useInfiniteQuery.d.ts +3 -3
- package/build/lib/useInfiniteQuery.esm.js.map +1 -1
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.mjs.map +1 -1
- package/build/lib/useMutation.d.ts +4 -4
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/lib/useQuery.d.ts +4 -4
- package/build/lib/useQuery.esm.js.map +1 -1
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/useQuery.mjs.map +1 -1
- package/build/umd/index.development.js +10 -5
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.mjs","sources":["../../src/useQuery.ts"],"sourcesContent":["import type { ToRefs, UnwrapRef } from 'vue-demi'\nimport { QueryObserver } from '@tanstack/query-core'\nimport type {\n QueryKey,\n QueryObserverResult,\n DefinedQueryObserverResult,\n WithRequired,\n QueryObserverOptions,\n
|
|
1
|
+
{"version":3,"file":"useQuery.mjs","sources":["../../src/useQuery.ts"],"sourcesContent":["import type { ToRefs, UnwrapRef } from 'vue-demi'\nimport { QueryObserver } from '@tanstack/query-core'\nimport type {\n QueryKey,\n QueryObserverResult,\n DefinedQueryObserverResult,\n WithRequired,\n QueryObserverOptions,\n DefaultError,\n} from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = {\n [Property in keyof QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >]: Property extends 'queryFn'\n ? QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n UnwrapRef<TQueryKey>\n >[Property]\n : MaybeRefDeep<\n WithRequired<\n QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n 'queryKey'\n >[Property]\n >\n}\n\nexport type UseQueryReturnType<TData, TError> = DistributiveOmit<\n UseBaseQueryReturnType<TData, TError>,\n 'refetch'\n> & {\n refetch: QueryObserverResult<TData, TError>['refetch']\n}\n\nexport type UseQueryDefinedReturnType<TData, TError> = DistributiveOmit<\n ToRefs<Readonly<DefinedQueryObserverResult<TData, TError>>>,\n 'refetch'\n> & {\n suspense: () => Promise<QueryObserverResult<TData, TError>>\n refetch: QueryObserverResult<TData, TError>['refetch']\n}\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n > & {\n initialData?: undefined\n },\n queryClient?: QueryClient,\n): UseQueryReturnType<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n > & {\n initialData: TQueryFnData | (() => TQueryFnData)\n },\n queryClient?: QueryClient,\n): UseQueryDefinedReturnType<TData, TError>\n\nexport function useQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey\n >,\n queryClient?: QueryClient,\n):\n | UseQueryReturnType<TData, TError>\n | UseQueryDefinedReturnType<TData, TError> {\n const result = useBaseQuery(QueryObserver, options, queryClient)\n\n return {\n ...result,\n refetch: result.refetch.value,\n }\n}\n"],"names":["useQuery","options","queryClient","result","useBaseQuery","QueryObserver","refetch","value"],"mappings":";;;AAqGO,SAASA,QAAQ,CAMtBC,OAMC,EACDC,WAAyB,EAGkB;EAC3C,MAAMC,MAAM,GAAGC,YAAY,CAACC,aAAa,EAAEJ,OAAO,EAAEC,WAAW,CAAC,CAAA;EAEhE,OAAO;AACL,IAAA,GAAGC,MAAM;AACTG,IAAAA,OAAO,EAAEH,MAAM,CAACG,OAAO,CAACC,KAAAA;GACzB,CAAA;AACH;;;;"}
|
|
@@ -889,6 +889,7 @@
|
|
|
889
889
|
if (!isCancelledError(error)) {
|
|
890
890
|
// Notify cache callback
|
|
891
891
|
this.#cache.config.onError?.(error, this);
|
|
892
|
+
this.#cache.config.onSettled?.(this.state.data, error, this);
|
|
892
893
|
}
|
|
893
894
|
if (!this.isFetchingOptimistic) {
|
|
894
895
|
// Schedule query gc after fetching
|
|
@@ -913,6 +914,7 @@
|
|
|
913
914
|
|
|
914
915
|
// Notify cache callback
|
|
915
916
|
this.#cache.config.onSuccess?.(data, this);
|
|
917
|
+
this.#cache.config.onSettled?.(data, this.state.error, this);
|
|
916
918
|
if (!this.isFetchingOptimistic) {
|
|
917
919
|
// Schedule query gc after fetching
|
|
918
920
|
this.scheduleGc();
|
|
@@ -1258,6 +1260,9 @@
|
|
|
1258
1260
|
// Notify cache callback
|
|
1259
1261
|
await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this);
|
|
1260
1262
|
await this.options.onSuccess?.(data, variables, this.state.context);
|
|
1263
|
+
|
|
1264
|
+
// Notify cache callback
|
|
1265
|
+
await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this);
|
|
1261
1266
|
await this.options.onSettled?.(data, null, variables, this.state.context);
|
|
1262
1267
|
this.#dispatch({
|
|
1263
1268
|
type: 'success',
|
|
@@ -1269,6 +1274,9 @@
|
|
|
1269
1274
|
// Notify cache callback
|
|
1270
1275
|
await this.#mutationCache.config.onError?.(error, variables, this.state.context, this);
|
|
1271
1276
|
await this.options.onError?.(error, variables, this.state.context);
|
|
1277
|
+
|
|
1278
|
+
// Notify cache callback
|
|
1279
|
+
await this.#mutationCache.config.onSettled?.(undefined, error, this.state.variables, this.state.context, this);
|
|
1272
1280
|
await this.options.onSettled?.(undefined, error, variables, this.state.context);
|
|
1273
1281
|
throw error;
|
|
1274
1282
|
} finally {
|
|
@@ -2266,14 +2274,12 @@
|
|
|
2266
2274
|
#result;
|
|
2267
2275
|
#queries;
|
|
2268
2276
|
#observers;
|
|
2269
|
-
#observersMap;
|
|
2270
2277
|
constructor(client, queries) {
|
|
2271
2278
|
super();
|
|
2272
2279
|
this.#client = client;
|
|
2273
2280
|
this.#queries = [];
|
|
2274
2281
|
this.#result = [];
|
|
2275
2282
|
this.#observers = [];
|
|
2276
|
-
this.#observersMap = {};
|
|
2277
2283
|
if (queries) {
|
|
2278
2284
|
this.setQueries(queries);
|
|
2279
2285
|
}
|
|
@@ -2307,14 +2313,12 @@
|
|
|
2307
2313
|
// set options for the new observers to notify of changes
|
|
2308
2314
|
newObserverMatches.forEach(match => match.observer.setOptions(match.defaultedQueryOptions, notifyOptions));
|
|
2309
2315
|
const newObservers = newObserverMatches.map(match => match.observer);
|
|
2310
|
-
const newObserversMap = Object.fromEntries(newObservers.map(observer => [observer.options.queryHash, observer]));
|
|
2311
2316
|
const newResult = newObservers.map(observer => observer.getCurrentResult());
|
|
2312
2317
|
const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
|
|
2313
2318
|
if (prevObservers.length === newObservers.length && !hasIndexChange) {
|
|
2314
2319
|
return;
|
|
2315
2320
|
}
|
|
2316
2321
|
this.#observers = newObservers;
|
|
2317
|
-
this.#observersMap = newObserversMap;
|
|
2318
2322
|
this.#result = newResult;
|
|
2319
2323
|
if (!this.hasListeners()) {
|
|
2320
2324
|
return;
|
|
@@ -2359,7 +2363,7 @@
|
|
|
2359
2363
|
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
|
|
2360
2364
|
const getObserver = options => {
|
|
2361
2365
|
const defaultedOptions = this.#client.defaultQueryOptions(options);
|
|
2362
|
-
const currentObserver = this.#
|
|
2366
|
+
const currentObserver = this.#observers.find(o => o.options.queryHash === defaultedOptions.queryHash);
|
|
2363
2367
|
return currentObserver ?? new QueryObserver(this.#client, defaultedOptions);
|
|
2364
2368
|
};
|
|
2365
2369
|
const newOrReusedObservers = unmatchedQueries.map(options => {
|
|
@@ -4164,6 +4168,7 @@
|
|
|
4164
4168
|
exports.isCancelledError = isCancelledError;
|
|
4165
4169
|
exports.isServer = isServer;
|
|
4166
4170
|
exports.keepPreviousData = keepPreviousData;
|
|
4171
|
+
exports.matchQuery = matchQuery;
|
|
4167
4172
|
exports.notifyManager = notifyManager;
|
|
4168
4173
|
exports.onlineManager = onlineManager;
|
|
4169
4174
|
exports.replaceEqualDeep = replaceEqualDeep;
|