@tanstack/vue-query 5.0.0-beta.20 → 5.0.0-beta.23
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/legacy/index.d.cts +1 -1
- package/build/legacy/index.d.ts +1 -1
- package/build/legacy/types.cjs.map +1 -1
- package/build/legacy/types.d.cts +7 -2
- package/build/legacy/types.d.ts +7 -2
- package/build/legacy/useBaseQuery.cjs +15 -4
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.d.cts +1 -1
- package/build/legacy/useBaseQuery.d.ts +1 -1
- package/build/legacy/useBaseQuery.js +16 -4
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useInfiniteQuery.cjs.map +1 -1
- package/build/legacy/useInfiniteQuery.d.cts +1 -1
- package/build/legacy/useInfiniteQuery.d.ts +1 -1
- package/build/legacy/useInfiniteQuery.js.map +1 -1
- package/build/legacy/useIsFetching.cjs +7 -0
- package/build/legacy/useIsFetching.cjs.map +1 -1
- package/build/legacy/useIsFetching.js +8 -1
- package/build/legacy/useIsFetching.js.map +1 -1
- package/build/legacy/useMutation.cjs +14 -3
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.js +15 -3
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/useMutationState.cjs +7 -0
- package/build/legacy/useMutationState.cjs.map +1 -1
- package/build/legacy/useMutationState.js +15 -1
- package/build/legacy/useMutationState.js.map +1 -1
- package/build/legacy/useQueries.cjs +21 -10
- package/build/legacy/useQueries.cjs.map +1 -1
- package/build/legacy/useQueries.d.cts +1 -1
- package/build/legacy/useQueries.d.ts +1 -1
- package/build/legacy/useQueries.js +29 -11
- package/build/legacy/useQueries.js.map +1 -1
- package/build/legacy/{useQuery-ebff9211.d.ts → useQuery-42d67167.d.ts} +6 -6
- package/build/legacy/{useQuery-846c66db.d.ts → useQuery-ac350b9a.d.ts} +6 -6
- package/build/legacy/useQuery.cjs.map +1 -1
- package/build/legacy/useQuery.d.cts +1 -1
- package/build/legacy/useQuery.d.ts +1 -1
- package/build/legacy/useQuery.js.map +1 -1
- package/build/legacy/useQueryClient.cjs +4 -4
- package/build/legacy/useQueryClient.cjs.map +1 -1
- package/build/legacy/useQueryClient.js +5 -5
- package/build/legacy/useQueryClient.js.map +1 -1
- package/build/legacy/vueQueryPlugin.cjs +2 -0
- package/build/legacy/vueQueryPlugin.cjs.map +1 -1
- package/build/legacy/vueQueryPlugin.d.cts +1 -0
- package/build/legacy/vueQueryPlugin.d.ts +1 -0
- package/build/legacy/vueQueryPlugin.js +2 -0
- package/build/legacy/vueQueryPlugin.js.map +1 -1
- package/build/modern/index.d.cts +1 -1
- package/build/modern/index.d.ts +1 -1
- package/build/modern/types.cjs.map +1 -1
- package/build/modern/types.d.cts +7 -2
- package/build/modern/types.d.ts +7 -2
- package/build/modern/useBaseQuery.cjs +15 -4
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.d.cts +1 -1
- package/build/modern/useBaseQuery.d.ts +1 -1
- package/build/modern/useBaseQuery.js +16 -4
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useInfiniteQuery.cjs.map +1 -1
- package/build/modern/useInfiniteQuery.d.cts +1 -1
- package/build/modern/useInfiniteQuery.d.ts +1 -1
- package/build/modern/useInfiniteQuery.js.map +1 -1
- package/build/modern/useIsFetching.cjs +7 -0
- package/build/modern/useIsFetching.cjs.map +1 -1
- package/build/modern/useIsFetching.js +8 -1
- package/build/modern/useIsFetching.js.map +1 -1
- package/build/modern/useMutation.cjs +14 -3
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.js +15 -3
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/useMutationState.cjs +7 -0
- package/build/modern/useMutationState.cjs.map +1 -1
- package/build/modern/useMutationState.js +15 -1
- package/build/modern/useMutationState.js.map +1 -1
- package/build/modern/useQueries.cjs +21 -10
- package/build/modern/useQueries.cjs.map +1 -1
- package/build/modern/useQueries.d.cts +1 -1
- package/build/modern/useQueries.d.ts +1 -1
- package/build/modern/useQueries.js +29 -11
- package/build/modern/useQueries.js.map +1 -1
- package/build/modern/{useQuery-ebff9211.d.ts → useQuery-42d67167.d.ts} +6 -6
- package/build/modern/{useQuery-846c66db.d.ts → useQuery-ac350b9a.d.ts} +6 -6
- package/build/modern/useQuery.cjs.map +1 -1
- package/build/modern/useQuery.d.cts +1 -1
- package/build/modern/useQuery.d.ts +1 -1
- package/build/modern/useQuery.js.map +1 -1
- package/build/modern/useQueryClient.cjs +4 -3
- package/build/modern/useQueryClient.cjs.map +1 -1
- package/build/modern/useQueryClient.js +5 -4
- package/build/modern/useQueryClient.js.map +1 -1
- package/build/modern/vueQueryPlugin.cjs +1 -0
- package/build/modern/vueQueryPlugin.cjs.map +1 -1
- package/build/modern/vueQueryPlugin.d.cts +1 -0
- package/build/modern/vueQueryPlugin.d.ts +1 -0
- package/build/modern/vueQueryPlugin.js +1 -0
- package/build/modern/vueQueryPlugin.js.map +1 -1
- package/package.json +6 -6
- package/src/__tests__/useQuery.test.ts +35 -6
- package/src/__tests__/useQueryClient.test.ts +4 -4
- package/src/types.ts +23 -1
- package/src/useBaseQuery.ts +17 -4
- package/src/useInfiniteQuery.ts +2 -3
- package/src/useIsFetching.ts +9 -1
- package/src/useMutation.ts +16 -3
- package/src/useMutationState.ts +16 -1
- package/src/useQueries.ts +30 -11
- package/src/useQuery.ts +10 -5
- package/src/useQueryClient.ts +6 -5
- package/src/vueQueryPlugin.ts +2 -0
package/build/legacy/index.d.cts
CHANGED
|
@@ -4,7 +4,7 @@ export { VueQueryPlugin, VueQueryPluginOptions } from './vueQueryPlugin.cjs';
|
|
|
4
4
|
export { QueryClient } from './queryClient.cjs';
|
|
5
5
|
export { QueryCache } from './queryCache.cjs';
|
|
6
6
|
export { MutationCache } from './mutationCache.cjs';
|
|
7
|
-
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, a as useInfiniteQuery, u as useQuery } from './useQuery-
|
|
7
|
+
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, a as useInfiniteQuery, u as useQuery } from './useQuery-42d67167.js';
|
|
8
8
|
export { UseQueriesOptions, UseQueriesResults, useQueries } from './useQueries.cjs';
|
|
9
9
|
export { UseMutationOptions, UseMutationReturnType, useMutation } from './useMutation.cjs';
|
|
10
10
|
export { QueryFilters, useIsFetching } from './useIsFetching.cjs';
|
package/build/legacy/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { VueQueryPlugin, VueQueryPluginOptions } from './vueQueryPlugin.js';
|
|
|
4
4
|
export { QueryClient } from './queryClient.js';
|
|
5
5
|
export { QueryCache } from './queryCache.js';
|
|
6
6
|
export { MutationCache } from './mutationCache.js';
|
|
7
|
-
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, a as useInfiniteQuery, u as useQuery } from './useQuery-
|
|
7
|
+
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, c as UseQueryDefinedReturnType, U as UseQueryOptions, b as UseQueryReturnType, a as useInfiniteQuery, u as useQuery } from './useQuery-ac350b9a.js';
|
|
8
8
|
export { UseQueriesOptions, UseQueriesResults, useQueries } from './useQueries.js';
|
|
9
9
|
export { UseMutationOptions, UseMutationReturnType, useMutation } from './useMutation.js';
|
|
10
10
|
export { QueryFilters, useIsFetching } from './useIsFetching.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { Ref } from 'vue-demi'\n\nexport type MaybeRef<T> = Ref<T> | T\n\nexport type MaybeRefDeep<T> = MaybeRef<\n T extends Function\n ? T\n : T extends object\n ? {\n [Property in keyof T]: MaybeRefDeep<T[Property]>\n }\n : T\n>\n\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../../src/types.ts"],"sourcesContent":["import type { Ref, UnwrapRef } from 'vue-demi'\n\ntype Primitive = string | number | boolean | bigint | symbol | undefined | null\ntype UnwrapLeaf =\n | Primitive\n | Function\n | Date\n | Error\n | RegExp\n | Map<any, any>\n | WeakMap<any, any>\n | Set<any>\n | WeakSet<any>\n\nexport type MaybeRef<T> = Ref<T> | T\n\nexport type MaybeRefDeep<T> = MaybeRef<\n T extends Function\n ? T\n : T extends object\n ? {\n [Property in keyof T]: MaybeRefDeep<T[Property]>\n }\n : T\n>\n\nexport type DeepUnwrapRef<T> = T extends UnwrapLeaf\n ? T\n : T extends Ref<infer U>\n ? DeepUnwrapRef<U>\n : T extends {}\n ? {\n [Property in keyof T]: DeepUnwrapRef<T[Property]>\n }\n : UnwrapRef<T>\n\nexport type DistributiveOmit<T, K extends keyof any> = T extends any\n ? Omit<T, K>\n : never\n"],"mappings":";;;;;;;;;;;;;;;;AAAA;AAAA;","names":[]}
|
package/build/legacy/types.d.cts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { Ref } from 'vue-demi';
|
|
1
|
+
import { Ref, UnwrapRef } from 'vue-demi';
|
|
2
2
|
|
|
3
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
4
|
+
type UnwrapLeaf = Primitive | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any>;
|
|
3
5
|
type MaybeRef<T> = Ref<T> | T;
|
|
4
6
|
type MaybeRefDeep<T> = MaybeRef<T extends Function ? T : T extends object ? {
|
|
5
7
|
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
|
6
8
|
} : T>;
|
|
9
|
+
type DeepUnwrapRef<T> = T extends UnwrapLeaf ? T : T extends Ref<infer U> ? DeepUnwrapRef<U> : T extends {} ? {
|
|
10
|
+
[Property in keyof T]: DeepUnwrapRef<T[Property]>;
|
|
11
|
+
} : UnwrapRef<T>;
|
|
7
12
|
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
8
13
|
|
|
9
|
-
export { DistributiveOmit, MaybeRef, MaybeRefDeep };
|
|
14
|
+
export { DeepUnwrapRef, DistributiveOmit, MaybeRef, MaybeRefDeep };
|
package/build/legacy/types.d.ts
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
-
import { Ref } from 'vue-demi';
|
|
1
|
+
import { Ref, UnwrapRef } from 'vue-demi';
|
|
2
2
|
|
|
3
|
+
type Primitive = string | number | boolean | bigint | symbol | undefined | null;
|
|
4
|
+
type UnwrapLeaf = Primitive | Function | Date | Error | RegExp | Map<any, any> | WeakMap<any, any> | Set<any> | WeakSet<any>;
|
|
3
5
|
type MaybeRef<T> = Ref<T> | T;
|
|
4
6
|
type MaybeRefDeep<T> = MaybeRef<T extends Function ? T : T extends object ? {
|
|
5
7
|
[Property in keyof T]: MaybeRefDeep<T[Property]>;
|
|
6
8
|
} : T>;
|
|
9
|
+
type DeepUnwrapRef<T> = T extends UnwrapLeaf ? T : T extends Ref<infer U> ? DeepUnwrapRef<U> : T extends {} ? {
|
|
10
|
+
[Property in keyof T]: DeepUnwrapRef<T[Property]>;
|
|
11
|
+
} : UnwrapRef<T>;
|
|
7
12
|
type DistributiveOmit<T, K extends keyof any> = T extends any ? Omit<T, K> : never;
|
|
8
13
|
|
|
9
|
-
export { DistributiveOmit, MaybeRef, MaybeRefDeep };
|
|
14
|
+
export { DeepUnwrapRef, DistributiveOmit, MaybeRef, MaybeRefDeep };
|
|
@@ -27,6 +27,13 @@ var import_vue_demi = require("vue-demi");
|
|
|
27
27
|
var import_useQueryClient = require("./useQueryClient.cjs");
|
|
28
28
|
var import_utils = require("./utils.cjs");
|
|
29
29
|
function useBaseQuery(Observer, options, queryClient) {
|
|
30
|
+
if (process.env.NODE_ENV === "development") {
|
|
31
|
+
if (!(0, import_vue_demi.getCurrentScope)()) {
|
|
32
|
+
console.warn(
|
|
33
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
34
|
+
);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
30
37
|
const client = queryClient || (0, import_useQueryClient.useQueryClient)();
|
|
31
38
|
const defaultedOptions = (0, import_vue_demi.computed)(() => {
|
|
32
39
|
const defaulted = client.defaultQueryOptions((0, import_utils.cloneDeepUnref)(options));
|
|
@@ -49,10 +56,14 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
49
56
|
},
|
|
50
57
|
{ immediate: true }
|
|
51
58
|
);
|
|
52
|
-
(0, import_vue_demi.watch)(
|
|
53
|
-
|
|
54
|
-
(
|
|
55
|
-
|
|
59
|
+
(0, import_vue_demi.watch)(
|
|
60
|
+
defaultedOptions,
|
|
61
|
+
() => {
|
|
62
|
+
observer.setOptions(defaultedOptions.value);
|
|
63
|
+
(0, import_utils.updateState)(state, observer.getCurrentResult());
|
|
64
|
+
},
|
|
65
|
+
{ flush: "sync" }
|
|
66
|
+
);
|
|
56
67
|
(0, import_vue_demi.onScopeDispose)(() => {
|
|
57
68
|
unsubscribe();
|
|
58
69
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(defaultedOptions
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { flush: 'sync' },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAQO;AACP,4BAA+B;AAC/B,mBAA8D;AAsCvD,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,KAAC,iCAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,mBAAe,sCAAe;AAE7C,QAAM,uBAAmB,0BAAS,MAAM;AACtC,UAAM,YAMF,OAAO,wBAAoB,6BAAe,OAAc,CAAC;AAE7D,cAAU,qBAAqB,OAAO,YAAY,QAC9C,gBACA;AAEJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;AAC5D,QAAM,YAAQ,0BAAS,SAAS,iBAAiB,CAAC;AAElD,MAAI,cAAc,MAAM;AAAA,EAExB;AAEA;AAAA,IACE,OAAO;AAAA,IACP,CAAC,gBAAgB;AAEf,UAAI,CAAC,aAAa;AAChB,oBAAY;AACZ,sBAAc,SAAS,UAAU,CAAC,WAAW;AAC3C,wCAAY,OAAO,MAAM;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,iBAAiB,KAAK;AAC1C,oCAAY,OAAO,SAAS,iBAAiB,CAAC;AAAA,IAChD;AAAA,IACA,EAAE,OAAO,OAAO;AAAA,EAClB;AAEA,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,WAAW,MAAM;AACrB,WAAO,IAAI;AAAA,MACT,CAAC,SAAS,WAAW;AACnB,YAAI,YAAY,MAAM;AAAA,QAEtB;AACA,cAAM,MAAM,MAAM;AAChB,cAAI,iBAAiB,MAAM,YAAY,OAAO;AAC5C,kBAAM,mBAAmB,SAAS;AAAA,cAChC,iBAAiB;AAAA,YACnB;AACA,gBAAI,iBAAiB,SAAS;AAC5B,wBAAU;AACV,uBACG,gBAAgB,iBAAiB,KAAK,EACtC,KAAK,SAAS,MAAM;AAAA,YACzB,OAAO;AACL,wBAAU;AACV,sBAAQ,gBAAgB;AAAA,YAC1B;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AAEJ,wBAAY,uBAAM,kBAAkB,GAAG;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAGA;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,MAAM,WACN,CAAC,MAAM,kBACP,+BAAiB,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,QACA,SAAS,gBAAgB;AAAA,MAC3B,CAAC,GACD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAI,4BAAO,0BAAS,KAAK,CAAC;AAAA,IAG1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'vue-demi';
|
|
2
2
|
import '@tanstack/query-core';
|
|
3
3
|
import './queryClient.cjs';
|
|
4
|
-
export { f as UseBaseQueryReturnType, g as useBaseQuery } from './useQuery-
|
|
4
|
+
export { f as UseBaseQueryReturnType, g as useBaseQuery } from './useQuery-42d67167.js';
|
|
5
5
|
import './types.cjs';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import 'vue-demi';
|
|
2
2
|
import '@tanstack/query-core';
|
|
3
3
|
import './queryClient.js';
|
|
4
|
-
export { f as UseBaseQueryReturnType, g as useBaseQuery } from './useQuery-
|
|
4
|
+
export { f as UseBaseQueryReturnType, g as useBaseQuery } from './useQuery-ac350b9a.js';
|
|
5
5
|
import './types.js';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/useBaseQuery.ts
|
|
2
2
|
import {
|
|
3
3
|
computed,
|
|
4
|
+
getCurrentScope,
|
|
4
5
|
onScopeDispose,
|
|
5
6
|
reactive,
|
|
6
7
|
readonly,
|
|
@@ -10,6 +11,13 @@ import {
|
|
|
10
11
|
import { useQueryClient } from "./useQueryClient.js";
|
|
11
12
|
import { cloneDeepUnref, shouldThrowError, updateState } from "./utils.js";
|
|
12
13
|
function useBaseQuery(Observer, options, queryClient) {
|
|
14
|
+
if (process.env.NODE_ENV === "development") {
|
|
15
|
+
if (!getCurrentScope()) {
|
|
16
|
+
console.warn(
|
|
17
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
13
21
|
const client = queryClient || useQueryClient();
|
|
14
22
|
const defaultedOptions = computed(() => {
|
|
15
23
|
const defaulted = client.defaultQueryOptions(cloneDeepUnref(options));
|
|
@@ -32,10 +40,14 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
32
40
|
},
|
|
33
41
|
{ immediate: true }
|
|
34
42
|
);
|
|
35
|
-
watch(
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
watch(
|
|
44
|
+
defaultedOptions,
|
|
45
|
+
() => {
|
|
46
|
+
observer.setOptions(defaultedOptions.value);
|
|
47
|
+
updateState(state, observer.getCurrentResult());
|
|
48
|
+
},
|
|
49
|
+
{ flush: "sync" }
|
|
50
|
+
);
|
|
39
51
|
onScopeDispose(() => {
|
|
40
52
|
unsubscribe();
|
|
41
53
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(defaultedOptions
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { flush: 'sync' },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,kBAAkB,mBAAmB;AAsCvD,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,gBAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,eAAe,eAAe;AAE7C,QAAM,mBAAmB,SAAS,MAAM;AACtC,UAAM,YAMF,OAAO,oBAAoB,eAAe,OAAc,CAAC;AAE7D,cAAU,qBAAqB,OAAO,YAAY,QAC9C,gBACA;AAEJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;AAC5D,QAAM,QAAQ,SAAS,SAAS,iBAAiB,CAAC;AAElD,MAAI,cAAc,MAAM;AAAA,EAExB;AAEA;AAAA,IACE,OAAO;AAAA,IACP,CAAC,gBAAgB;AAEf,UAAI,CAAC,aAAa;AAChB,oBAAY;AACZ,sBAAc,SAAS,UAAU,CAAC,WAAW;AAC3C,sBAAY,OAAO,MAAM;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,iBAAiB,KAAK;AAC1C,kBAAY,OAAO,SAAS,iBAAiB,CAAC;AAAA,IAChD;AAAA,IACA,EAAE,OAAO,OAAO;AAAA,EAClB;AAEA,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,WAAW,MAAM;AACrB,WAAO,IAAI;AAAA,MACT,CAAC,SAAS,WAAW;AACnB,YAAI,YAAY,MAAM;AAAA,QAEtB;AACA,cAAM,MAAM,MAAM;AAChB,cAAI,iBAAiB,MAAM,YAAY,OAAO;AAC5C,kBAAM,mBAAmB,SAAS;AAAA,cAChC,iBAAiB;AAAA,YACnB;AACA,gBAAI,iBAAiB,SAAS;AAC5B,wBAAU;AACV,uBACG,gBAAgB,iBAAiB,KAAK,EACtC,KAAK,SAAS,MAAM;AAAA,YACzB,OAAO;AACL,wBAAU;AACV,sBAAQ,gBAAgB;AAAA,YAC1B;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AAEJ,oBAAY,MAAM,kBAAkB,GAAG;AAAA,MACzC;AAAA,IACF;AAAA,EACF;AAGA;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,MAAM,WACN,CAAC,MAAM,cACP,iBAAiB,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,QACA,SAAS,gBAAgB;AAAA,MAC3B,CAAC,GACD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAI,OAAO,SAAS,KAAK,CAAC;AAAA,IAG1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n WithRequired,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\
|
|
1
|
+
{"version":3,"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n WithRequired,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type { DeepUnwrapRef, DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >]: Property extends 'queryFn'\n ? InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n : MaybeRefDeep<\n WithRequired<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n 'queryKey'\n >[Property]\n >\n}\n\ntype InfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\nexport type UseInfiniteQueryReturnType<TData, TError> = DistributiveOmit<\n InfiniteQueryReturnType<TData, TError>,\n 'fetchNextPage' | 'fetchPreviousPage' | 'refetch'\n> & {\n fetchNextPage: InfiniteQueryObserverResult<TData, TError>['fetchNextPage']\n fetchPreviousPage: InfiniteQueryObserverResult<\n TData,\n TError\n >['fetchPreviousPage']\n refetch: InfiniteQueryObserverResult<TData, TError>['refetch']\n}\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError> {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const result = useBaseQuery(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n ) as InfiniteQueryReturnType<TData, TError>\n return {\n ...result,\n fetchNextPage: result.fetchNextPage.value,\n fetchPreviousPage: result.fetchPreviousPage.value,\n refetch: result.refetch.value,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAsC;AACtC,0BAA6B;AAwEtB,SAAS,iBAOd,SAQA,aAC2C;AAE3C,QAAM,aAAS;AAAA;AAAA,IAEb;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,eAAe,OAAO,cAAc;AAAA,IACpC,mBAAmB,OAAO,kBAAkB;AAAA,IAC5C,SAAS,OAAO,QAAQ;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@tanstack/query-core';
|
|
2
|
-
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, a as useInfiniteQuery } from './useQuery-
|
|
2
|
+
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, a as useInfiniteQuery } from './useQuery-42d67167.js';
|
|
3
3
|
import './types.cjs';
|
|
4
4
|
import './queryClient.cjs';
|
|
5
5
|
import 'vue-demi';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import '@tanstack/query-core';
|
|
2
|
-
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, a as useInfiniteQuery } from './useQuery-
|
|
2
|
+
export { d as UseInfiniteQueryOptions, e as UseInfiniteQueryReturnType, a as useInfiniteQuery } from './useQuery-ac350b9a.js';
|
|
3
3
|
import './types.js';
|
|
4
4
|
import './queryClient.js';
|
|
5
5
|
import 'vue-demi';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n WithRequired,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\
|
|
1
|
+
{"version":3,"sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import { InfiniteQueryObserver } from '@tanstack/query-core'\nimport { useBaseQuery } from './useBaseQuery'\nimport type {\n DefaultError,\n InfiniteData,\n InfiniteQueryObserverOptions,\n InfiniteQueryObserverResult,\n QueryKey,\n QueryObserver,\n WithRequired,\n} from '@tanstack/query-core'\n\nimport type { UseBaseQueryReturnType } from './useBaseQuery'\n\nimport type { DeepUnwrapRef, DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type UseInfiniteQueryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> = {\n [Property in keyof InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >]: Property extends 'queryFn'\n ? InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n DeepUnwrapRef<TQueryKey>,\n TPageParam\n >[Property]\n : MaybeRefDeep<\n WithRequired<\n InfiniteQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n 'queryKey'\n >[Property]\n >\n}\n\ntype InfiniteQueryReturnType<TData, TError> = UseBaseQueryReturnType<\n TData,\n TError,\n InfiniteQueryObserverResult<TData, TError>\n>\nexport type UseInfiniteQueryReturnType<TData, TError> = DistributiveOmit<\n InfiniteQueryReturnType<TData, TError>,\n 'fetchNextPage' | 'fetchPreviousPage' | 'refetch'\n> & {\n fetchNextPage: InfiniteQueryObserverResult<TData, TError>['fetchNextPage']\n fetchPreviousPage: InfiniteQueryObserverResult<\n TData,\n TError\n >['fetchPreviousPage']\n refetch: InfiniteQueryObserverResult<TData, TError>['refetch']\n}\n\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryReturnType<TData, TError> {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n const result = useBaseQuery(\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n InfiniteQueryObserver as typeof QueryObserver,\n options,\n queryClient,\n ) as InfiniteQueryReturnType<TData, TError>\n return {\n ...result,\n fetchNextPage: result.fetchNextPage.value,\n fetchPreviousPage: result.fetchPreviousPage.value,\n refetch: result.refetch.value,\n }\n}\n"],"mappings":";AAAA,SAAS,6BAA6B;AACtC,SAAS,oBAAoB;AAwEtB,SAAS,iBAOd,SAQA,aAC2C;AAE3C,QAAM,SAAS;AAAA;AAAA,IAEb;AAAA,IACA;AAAA,IACA;AAAA,EACF;AACA,SAAO;AAAA,IACL,GAAG;AAAA,IACH,eAAe,OAAO,cAAc;AAAA,IACpC,mBAAmB,OAAO,kBAAkB;AAAA,IAC5C,SAAS,OAAO,QAAQ;AAAA,EAC1B;AACF;","names":[]}
|
|
@@ -26,6 +26,13 @@ module.exports = __toCommonJS(useIsFetching_exports);
|
|
|
26
26
|
var import_vue_demi = require("vue-demi");
|
|
27
27
|
var import_useQueryClient = require("./useQueryClient.cjs");
|
|
28
28
|
function useIsFetching(fetchingFilters = {}, queryClient) {
|
|
29
|
+
if (process.env.NODE_ENV === "development") {
|
|
30
|
+
if (!(0, import_vue_demi.getCurrentScope)()) {
|
|
31
|
+
console.warn(
|
|
32
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
29
36
|
const client = queryClient || (0, import_useQueryClient.useQueryClient)();
|
|
30
37
|
const isFetching = (0, import_vue_demi.ref)();
|
|
31
38
|
const listener = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { onScopeDispose, ref, watchSyncEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters as QF } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type QueryFilters = MaybeRefDeep<QF>\n\nexport function useIsFetching(\n fetchingFilters: MaybeRefDeep<QF> = {},\n queryClient?: QueryClient,\n): Ref<number> {\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n isFetching.value = client.isFetching(fetchingFilters)\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchSyncEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,
|
|
1
|
+
{"version":3,"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchSyncEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters as QF } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type QueryFilters = MaybeRefDeep<QF>\n\nexport function useIsFetching(\n fetchingFilters: MaybeRefDeep<QF> = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n isFetching.value = client.isFetching(fetchingFilters)\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchSyncEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAAsE;AACtE,4BAA+B;AAQxB,SAAS,cACd,kBAAoC,CAAC,GACrC,aACa;AACb,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,KAAC,iCAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,mBAAe,sCAAe;AAE7C,QAAM,iBAAa,qBAAI;AAEvB,QAAM,WAAW,MAAM;AACrB,eAAW,QAAQ,OAAO,WAAW,eAAe;AAAA,EACtD;AAEA,QAAM,cAAc,OAAO,cAAc,EAAE,UAAU,QAAQ;AAE7D,uCAAgB,QAAQ;AAExB,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
// src/useIsFetching.ts
|
|
2
|
-
import { onScopeDispose, ref, watchSyncEffect } from "vue-demi";
|
|
2
|
+
import { getCurrentScope, onScopeDispose, ref, watchSyncEffect } from "vue-demi";
|
|
3
3
|
import { useQueryClient } from "./useQueryClient.js";
|
|
4
4
|
function useIsFetching(fetchingFilters = {}, queryClient) {
|
|
5
|
+
if (process.env.NODE_ENV === "development") {
|
|
6
|
+
if (!getCurrentScope()) {
|
|
7
|
+
console.warn(
|
|
8
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
5
12
|
const client = queryClient || useQueryClient();
|
|
6
13
|
const isFetching = ref();
|
|
7
14
|
const listener = () => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { onScopeDispose, ref, watchSyncEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters as QF } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type QueryFilters = MaybeRefDeep<QF>\n\nexport function useIsFetching(\n fetchingFilters: MaybeRefDeep<QF> = {},\n queryClient?: QueryClient,\n): Ref<number> {\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n isFetching.value = client.isFetching(fetchingFilters)\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchSyncEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";AAAA,SAAS,gBAAgB,KAAK,uBAAuB;
|
|
1
|
+
{"version":3,"sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { getCurrentScope, onScopeDispose, ref, watchSyncEffect } from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport type { Ref } from 'vue-demi'\nimport type { QueryFilters as QF } from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\nexport type QueryFilters = MaybeRefDeep<QF>\n\nexport function useIsFetching(\n fetchingFilters: MaybeRefDeep<QF> = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const isFetching = ref()\n\n const listener = () => {\n isFetching.value = client.isFetching(fetchingFilters)\n }\n\n const unsubscribe = client.getQueryCache().subscribe(listener)\n\n watchSyncEffect(listener)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n"],"mappings":";AAAA,SAAS,iBAAiB,gBAAgB,KAAK,uBAAuB;AACtE,SAAS,sBAAsB;AAQxB,SAAS,cACd,kBAAoC,CAAC,GACrC,aACa;AACb,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,gBAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,eAAe,eAAe;AAE7C,QAAM,aAAa,IAAI;AAEvB,QAAM,WAAW,MAAM;AACrB,eAAW,QAAQ,OAAO,WAAW,eAAe;AAAA,EACtD;AAEA,QAAM,cAAc,OAAO,cAAc,EAAE,UAAU,QAAQ;AAE7D,kBAAgB,QAAQ;AAExB,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,SAAO;AACT;","names":[]}
|
|
@@ -28,6 +28,13 @@ var import_query_core = require("@tanstack/query-core");
|
|
|
28
28
|
var import_utils = require("./utils.cjs");
|
|
29
29
|
var import_useQueryClient = require("./useQueryClient.cjs");
|
|
30
30
|
function useMutation(mutationOptions, queryClient) {
|
|
31
|
+
if (process.env.NODE_ENV === "development") {
|
|
32
|
+
if (!(0, import_vue_demi.getCurrentScope)()) {
|
|
33
|
+
console.warn(
|
|
34
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
31
38
|
const client = queryClient || (0, import_useQueryClient.useQueryClient)();
|
|
32
39
|
const options = (0, import_vue_demi.computed)(() => {
|
|
33
40
|
return client.defaultMutationOptions((0, import_utils.cloneDeepUnref)(mutationOptions));
|
|
@@ -41,9 +48,13 @@ function useMutation(mutationOptions, queryClient) {
|
|
|
41
48
|
observer.mutate(variables, mutateOptions).catch(() => {
|
|
42
49
|
});
|
|
43
50
|
};
|
|
44
|
-
(0, import_vue_demi.watch)(
|
|
45
|
-
|
|
46
|
-
|
|
51
|
+
(0, import_vue_demi.watch)(
|
|
52
|
+
options,
|
|
53
|
+
() => {
|
|
54
|
+
observer.setOptions(options.value);
|
|
55
|
+
},
|
|
56
|
+
{ flush: "sync" }
|
|
57
|
+
);
|
|
47
58
|
(0, import_vue_demi.onScopeDispose)(() => {
|
|
48
59
|
unsubscribe();
|
|
49
60
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(options
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(options.value)\n },\n { flush: 'sync' },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const resultRefs = toRefs(readonly(state)) as unknown as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TContext>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(options.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAQO;AACP,wBAAiC;AACjC,mBAA8D;AAC9D,4BAA+B;AA6CxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,KAAC,iCAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,mBAAe,sCAAe;AAC7C,QAAM,cAAU,0BAAS,MAAM;AAC7B,WAAO,OAAO,2BAAuB,6BAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,mCAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,YAAQ,0BAAS,SAAS,iBAAiB,CAAC;AAElD,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,kCAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,QAAQ,KAAK;AAAA,IACnC;AAAA,IACA,EAAE,OAAO,OAAO;AAAA,EAClB;AAEA,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,iBAAa,4BAAO,0BAAS,KAAK,CAAC;AAIzC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,aACA,+BAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/useMutation.ts
|
|
2
2
|
import {
|
|
3
3
|
computed,
|
|
4
|
+
getCurrentScope,
|
|
4
5
|
onScopeDispose,
|
|
5
6
|
reactive,
|
|
6
7
|
readonly,
|
|
@@ -11,6 +12,13 @@ import { MutationObserver } from "@tanstack/query-core";
|
|
|
11
12
|
import { cloneDeepUnref, shouldThrowError, updateState } from "./utils.js";
|
|
12
13
|
import { useQueryClient } from "./useQueryClient.js";
|
|
13
14
|
function useMutation(mutationOptions, queryClient) {
|
|
15
|
+
if (process.env.NODE_ENV === "development") {
|
|
16
|
+
if (!getCurrentScope()) {
|
|
17
|
+
console.warn(
|
|
18
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
14
22
|
const client = queryClient || useQueryClient();
|
|
15
23
|
const options = computed(() => {
|
|
16
24
|
return client.defaultMutationOptions(cloneDeepUnref(mutationOptions));
|
|
@@ -24,9 +32,13 @@ function useMutation(mutationOptions, queryClient) {
|
|
|
24
32
|
observer.mutate(variables, mutateOptions).catch(() => {
|
|
25
33
|
});
|
|
26
34
|
};
|
|
27
|
-
watch(
|
|
28
|
-
|
|
29
|
-
|
|
35
|
+
watch(
|
|
36
|
+
options,
|
|
37
|
+
() => {
|
|
38
|
+
observer.setOptions(options.value);
|
|
39
|
+
},
|
|
40
|
+
{ flush: "sync" }
|
|
41
|
+
);
|
|
30
42
|
onScopeDispose(() => {
|
|
31
43
|
unsubscribe();
|
|
32
44
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(options
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(options.value)\n },\n { flush: 'sync' },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const resultRefs = toRefs(readonly(state)) as unknown as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TContext>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(options.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB,kBAAkB,mBAAmB;AAC9D,SAAS,sBAAsB;AA6CxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,gBAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,eAAe,eAAe;AAC7C,QAAM,UAAU,SAAS,MAAM;AAC7B,WAAO,OAAO,uBAAuB,eAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,iBAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,QAAQ,SAAS,SAAS,iBAAiB,CAAC;AAElD,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,gBAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,QAAQ,KAAK;AAAA,IACnC;AAAA,IACA,EAAE,OAAO,OAAO;AAAA,EAClB;AAEA,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC;AAIzC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,SACA,iBAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
|
@@ -28,6 +28,13 @@ var import_vue_demi = require("vue-demi");
|
|
|
28
28
|
var import_useQueryClient = require("./useQueryClient.cjs");
|
|
29
29
|
var import_utils = require("./utils.cjs");
|
|
30
30
|
function useIsMutating(filters = {}, queryClient) {
|
|
31
|
+
if (process.env.NODE_ENV === "development") {
|
|
32
|
+
if (!(0, import_vue_demi.getCurrentScope)()) {
|
|
33
|
+
console.warn(
|
|
34
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
31
38
|
const client = queryClient || (0, import_useQueryClient.useQueryClient)();
|
|
32
39
|
const unreffedFilters = (0, import_vue_demi.computed)(() => ({
|
|
33
40
|
...(0, import_utils.cloneDeepUnref)(filters),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n readonly,\n ref,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { DeepReadonly, Ref } from 'vue-demi'\nimport type {\n DefaultError,\n MutationFilters as MF,\n Mutation,\n MutationState,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\nimport type { MutationCache } from './mutationCache'\n\nexport type MutationFilters = MaybeRefDeep<MF>\n\nexport function useIsMutating(\n filters: MutationFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const unreffedFilters = computed(() => ({\n ...cloneDeepUnref(filters),\n status: 'pending' as const,\n }))\n\n const mutationState = useMutationState({ filters: unreffedFilters }, client)\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\nexport type MutationStateOptions<TResult = MutationState> = {\n filters?: MutationFilters\n select?: (\n mutation: Mutation<unknown, DefaultError, unknown, unknown>,\n ) => TResult\n}\n\nfunction getResult<TResult = MutationState>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(\n mutation as Mutation<unknown, DefaultError, unknown, unknown>,\n )\n : mutation.state) as TResult,\n )\n}\n\nexport function useMutationState<TResult = MutationState>(\n options: MutationStateOptions<TResult> = {},\n queryClient?: QueryClient,\n): DeepReadonly<Ref<Array<TResult>>> {\n const filters = computed(() => cloneDeepUnref(options.filters))\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = ref(getResult(mutationCache, options)) as Ref<Array<TResult>>\n const unsubscribe = mutationCache.subscribe(() => {\n const result = getResult(mutationCache, options)\n state.value = result\n })\n\n watch(filters, () => {\n state.value = getResult(mutationCache, options)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return readonly(state)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AACP,4BAA+B;AAC/B,mBAA+B;AAcxB,SAAS,cACd,UAA2B,CAAC,GAC5B,aACa;AACb,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,KAAC,iCAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,mBAAe,sCAAe;AAC7C,QAAM,sBAAkB,0BAAS,OAAO;AAAA,IACtC,OAAG,6BAAe,OAAO;AAAA,IACzB,QAAQ;AAAA,EACV,EAAE;AAEF,QAAM,gBAAgB,iBAAiB,EAAE,SAAS,gBAAgB,GAAG,MAAM;AAC3E,QAAM,aAAS,0BAAS,MAAM,cAAc,MAAM,MAAM;AAExD,SAAO;AACT;AASA,SAAS,UACP,eACA,SACgB;AAChB,SAAO,cACJ,QAAQ,QAAQ,OAAO,EACvB;AAAA,IACC,CAAC,aACE,QAAQ,SACL,QAAQ;AAAA,MACN;AAAA,IACF,IACA,SAAS;AAAA,EACjB;AACJ;AAEO,SAAS,iBACd,UAAyC,CAAC,GAC1C,aACmC;AACnC,QAAM,cAAU,0BAAS,UAAM,6BAAe,QAAQ,OAAO,CAAC;AAC9D,QAAM,iBAAiB,mBAAe,sCAAe,GAAG,iBAAiB;AACzE,QAAM,YAAQ,qBAAI,UAAU,eAAe,OAAO,CAAC;AACnD,QAAM,cAAc,cAAc,UAAU,MAAM;AAChD,UAAM,SAAS,UAAU,eAAe,OAAO;AAC/C,UAAM,QAAQ;AAAA,EAChB,CAAC;AAED,6BAAM,SAAS,MAAM;AACnB,UAAM,QAAQ,UAAU,eAAe,OAAO;AAAA,EAChD,CAAC;AAED,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,aAAO,0BAAS,KAAK;AACvB;","names":[]}
|
|
@@ -1,8 +1,22 @@
|
|
|
1
1
|
// src/useMutationState.ts
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
computed,
|
|
4
|
+
getCurrentScope,
|
|
5
|
+
onScopeDispose,
|
|
6
|
+
readonly,
|
|
7
|
+
ref,
|
|
8
|
+
watch
|
|
9
|
+
} from "vue-demi";
|
|
3
10
|
import { useQueryClient } from "./useQueryClient.js";
|
|
4
11
|
import { cloneDeepUnref } from "./utils.js";
|
|
5
12
|
function useIsMutating(filters = {}, queryClient) {
|
|
13
|
+
if (process.env.NODE_ENV === "development") {
|
|
14
|
+
if (!getCurrentScope()) {
|
|
15
|
+
console.warn(
|
|
16
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
6
20
|
const client = queryClient || useQueryClient();
|
|
7
21
|
const unreffedFilters = computed(() => ({
|
|
8
22
|
...cloneDeepUnref(filters),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"sources":["../../src/useMutationState.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n readonly,\n ref,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { DeepReadonly, Ref } from 'vue-demi'\nimport type {\n DefaultError,\n MutationFilters as MF,\n Mutation,\n MutationState,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { MaybeRefDeep } from './types'\nimport type { MutationCache } from './mutationCache'\n\nexport type MutationFilters = MaybeRefDeep<MF>\n\nexport function useIsMutating(\n filters: MutationFilters = {},\n queryClient?: QueryClient,\n): Ref<number> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composables like \"uesQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const unreffedFilters = computed(() => ({\n ...cloneDeepUnref(filters),\n status: 'pending' as const,\n }))\n\n const mutationState = useMutationState({ filters: unreffedFilters }, client)\n const length = computed(() => mutationState.value.length)\n\n return length\n}\n\nexport type MutationStateOptions<TResult = MutationState> = {\n filters?: MutationFilters\n select?: (\n mutation: Mutation<unknown, DefaultError, unknown, unknown>,\n ) => TResult\n}\n\nfunction getResult<TResult = MutationState>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(\n mutation as Mutation<unknown, DefaultError, unknown, unknown>,\n )\n : mutation.state) as TResult,\n )\n}\n\nexport function useMutationState<TResult = MutationState>(\n options: MutationStateOptions<TResult> = {},\n queryClient?: QueryClient,\n): DeepReadonly<Ref<Array<TResult>>> {\n const filters = computed(() => cloneDeepUnref(options.filters))\n const mutationCache = (queryClient || useQueryClient()).getMutationCache()\n const state = ref(getResult(mutationCache, options)) as Ref<Array<TResult>>\n const unsubscribe = mutationCache.subscribe(() => {\n const result = getResult(mutationCache, options)\n state.value = result\n })\n\n watch(filters, () => {\n state.value = getResult(mutationCache, options)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return readonly(state)\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAcxB,SAAS,cACd,UAA2B,CAAC,GAC5B,aACa;AACb,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,gBAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,eAAe,eAAe;AAC7C,QAAM,kBAAkB,SAAS,OAAO;AAAA,IACtC,GAAG,eAAe,OAAO;AAAA,IACzB,QAAQ;AAAA,EACV,EAAE;AAEF,QAAM,gBAAgB,iBAAiB,EAAE,SAAS,gBAAgB,GAAG,MAAM;AAC3E,QAAM,SAAS,SAAS,MAAM,cAAc,MAAM,MAAM;AAExD,SAAO;AACT;AASA,SAAS,UACP,eACA,SACgB;AAChB,SAAO,cACJ,QAAQ,QAAQ,OAAO,EACvB;AAAA,IACC,CAAC,aACE,QAAQ,SACL,QAAQ;AAAA,MACN;AAAA,IACF,IACA,SAAS;AAAA,EACjB;AACJ;AAEO,SAAS,iBACd,UAAyC,CAAC,GAC1C,aACmC;AACnC,QAAM,UAAU,SAAS,MAAM,eAAe,QAAQ,OAAO,CAAC;AAC9D,QAAM,iBAAiB,eAAe,eAAe,GAAG,iBAAiB;AACzE,QAAM,QAAQ,IAAI,UAAU,eAAe,OAAO,CAAC;AACnD,QAAM,cAAc,cAAc,UAAU,MAAM;AAChD,UAAM,SAAS,UAAU,eAAe,OAAO;AAC/C,UAAM,QAAQ;AAAA,EAChB,CAAC;AAED,QAAM,SAAS,MAAM;AACnB,UAAM,QAAQ,UAAU,eAAe,OAAO;AAAA,EAChD,CAAC;AAED,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,SAAO,SAAS,KAAK;AACvB;","names":[]}
|
|
@@ -31,6 +31,13 @@ function useQueries({
|
|
|
31
31
|
queries,
|
|
32
32
|
...options
|
|
33
33
|
}, queryClient) {
|
|
34
|
+
if (process.env.NODE_ENV === "development") {
|
|
35
|
+
if (!(0, import_vue_demi.getCurrentScope)()) {
|
|
36
|
+
console.warn(
|
|
37
|
+
'vue-query composables like "uesQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
34
41
|
const client = queryClient || (0, import_useQueryClient.useQueryClient)();
|
|
35
42
|
const defaultedQueries = (0, import_vue_demi.computed)(
|
|
36
43
|
() => (0, import_utils.cloneDeepUnref)(queries).map((queryOptions) => {
|
|
@@ -69,16 +76,20 @@ function useQueries({
|
|
|
69
76
|
},
|
|
70
77
|
{ immediate: true }
|
|
71
78
|
);
|
|
72
|
-
(0, import_vue_demi.watch)(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
(0, import_vue_demi.watch)(
|
|
80
|
+
defaultedQueries,
|
|
81
|
+
() => {
|
|
82
|
+
observer.setQueries(
|
|
83
|
+
defaultedQueries.value,
|
|
84
|
+
options
|
|
85
|
+
);
|
|
86
|
+
const [, getCombinedResultPersisted] = observer.getOptimisticResult(
|
|
87
|
+
defaultedQueries.value
|
|
88
|
+
);
|
|
89
|
+
state.value = getCombinedResultPersisted();
|
|
90
|
+
},
|
|
91
|
+
{ flush: "sync" }
|
|
92
|
+
);
|
|
82
93
|
(0, import_vue_demi.onScopeDispose)(() => {
|
|
83
94
|
unsubscribe();
|
|
84
95
|
});
|