@tanstack/vue-query 4.16.1 → 4.17.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/build/lib/__mocks__/useBaseQuery.d.ts +1 -0
- package/build/lib/devtools/devtools.esm.js +1 -1
- package/build/lib/devtools/devtools.esm.js.map +1 -1
- package/build/lib/devtools/devtools.js +1 -1
- package/build/lib/devtools/devtools.js.map +1 -1
- package/build/lib/devtools/devtools.mjs +1 -1
- package/build/lib/devtools/devtools.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +1 -0
- package/build/lib/queryClient.esm.js +2 -0
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +2 -0
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs +2 -0
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/useBaseQuery.d.ts +4 -2
- package/build/lib/useBaseQuery.esm.js +55 -42
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +54 -40
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +55 -42
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.d.ts +3 -3
- package/build/lib/useIsFetching.esm.js +10 -9
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js +9 -8
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs +10 -9
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useIsMutating.d.ts +3 -3
- package/build/lib/useIsMutating.esm.js +12 -11
- package/build/lib/useIsMutating.esm.js.map +1 -1
- package/build/lib/useIsMutating.js +11 -10
- package/build/lib/useIsMutating.js.map +1 -1
- package/build/lib/useIsMutating.mjs +12 -11
- package/build/lib/useIsMutating.mjs.map +1 -1
- package/build/lib/useQueries.esm.js +28 -18
- package/build/lib/useQueries.esm.js.map +1 -1
- package/build/lib/useQueries.js +27 -17
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQueries.mjs +28 -18
- package/build/lib/useQueries.mjs.map +1 -1
- package/build/lib/vueQueryPlugin.d.ts +7 -9
- package/build/lib/vueQueryPlugin.esm.js +13 -0
- package/build/lib/vueQueryPlugin.esm.js.map +1 -1
- package/build/lib/vueQueryPlugin.js +13 -0
- package/build/lib/vueQueryPlugin.js.map +1 -1
- package/build/lib/vueQueryPlugin.mjs +13 -0
- package/build/lib/vueQueryPlugin.mjs.map +1 -1
- package/build/umd/index.development.js +132 -93
- 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 +6 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsMutating.mjs","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { onScopeDispose, ref, watch } from 'vue-demi'\nimport type { Ref } from 'vue-demi'\nimport type { MutationKey, MutationFilters as MF } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, isQueryKey } from './utils'\nimport type { MaybeRefDeep, WithQueryClientKey } from './types'\n\nexport type MutationFilters = MaybeRefDeep<WithQueryClientKey<MF>>\n\nexport function useIsMutating(filters?: MutationFilters): Ref<number>\nexport function useIsMutating(\n mutationKey?: MutationKey
|
|
1
|
+
{"version":3,"file":"useIsMutating.mjs","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { computed, isRef, onScopeDispose, ref, watch } from 'vue-demi'\nimport type { Ref } from 'vue-demi'\nimport type { MutationKey, MutationFilters as MF } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, isQueryKey } from './utils'\nimport type { MaybeRef, MaybeRefDeep, WithQueryClientKey } from './types'\n\nexport type MutationFilters = MaybeRefDeep<WithQueryClientKey<MF>>\n\nexport function useIsMutating(filters?: MutationFilters): Ref<number>\nexport function useIsMutating(\n mutationKey?: MaybeRef<MutationKey>,\n filters?: Omit<MutationFilters, 'mutationKey'>,\n): Ref<number>\nexport function useIsMutating(\n arg1?: MaybeRef<MutationKey> | MutationFilters,\n arg2?: Omit<MutationFilters, 'mutationKey'>,\n): Ref<number> {\n const filters = computed(() => parseFilterArgs(arg1, arg2))\n const queryClient =\n filters.value.queryClient ?? useQueryClient(filters.value.queryClientKey)\n\n const isMutating = ref(queryClient.isMutating(filters))\n\n const unsubscribe = queryClient.getMutationCache().subscribe(() => {\n isMutating.value = queryClient.isMutating(filters)\n })\n\n watch(\n filters,\n () => {\n isMutating.value = queryClient.isMutating(filters)\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isMutating\n}\n\nexport function parseFilterArgs(\n arg1?: MaybeRef<MutationKey> | MutationFilters,\n arg2: MutationFilters = {},\n) {\n const plainArg1 = isRef(arg1) ? arg1.value : arg1\n const plainArg2 = isRef(arg2) ? arg2.value : arg2\n\n let options = plainArg1\n\n if (isQueryKey(plainArg1)) {\n options = { ...plainArg2, mutationKey: plainArg1 }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n options = plainArg1 || {}\n }\n\n return cloneDeepUnref(options) as WithQueryClientKey<MF>\n}\n"],"names":["useIsMutating","arg1","arg2","filters","computed","parseFilterArgs","queryClient","value","useQueryClient","queryClientKey","isMutating","ref","unsubscribe","getMutationCache","subscribe","watch","deep","onScopeDispose","plainArg1","isRef","plainArg2","options","isQueryKey","mutationKey","cloneDeepUnref"],"mappings":";;;;AAeO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGQ;AAAA,EAAA,IAAA,qBAAA,CAAA;;EACb,MAAMC,OAAO,GAAGC,QAAQ,CAAC,MAAMC,eAAe,CAACJ,IAAD,EAAOC,IAAP,CAAtB,CAAxB,CAAA;AACA,EAAA,MAAMI,WAAW,GAAA,CAAA,qBAAA,GACfH,OAAO,CAACI,KAAR,CAAcD,WADC,KACcE,IAAAA,GAAAA,qBAAAA,GAAAA,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@ -1,37 +1,47 @@
|
|
|
1
1
|
import { QueriesObserver } from '@tanstack/query-core';
|
|
2
|
-
import { reactive, watch, onScopeDispose, readonly } from 'vue-demi';
|
|
2
|
+
import { computed, reactive, ref, watch, onScopeDispose, readonly } from 'vue-demi';
|
|
3
3
|
import { useQueryClient } from './useQueryClient.esm.js';
|
|
4
4
|
import { cloneDeepUnref } from './utils.esm.js';
|
|
5
5
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
|
|
8
7
|
function useQueries({
|
|
9
8
|
queries
|
|
10
9
|
}) {
|
|
11
|
-
var _unreffedQueries
|
|
10
|
+
var _unreffedQueries$valu, _unreffedQueries$valu2;
|
|
12
11
|
|
|
13
|
-
const unreffedQueries = cloneDeepUnref(queries);
|
|
14
|
-
const queryClientKey = (_unreffedQueries$ = unreffedQueries[0]) == null ? void 0 : _unreffedQueries
|
|
15
|
-
const optionsQueryClient = (_unreffedQueries$
|
|
12
|
+
const unreffedQueries = computed(() => cloneDeepUnref(queries));
|
|
13
|
+
const queryClientKey = (_unreffedQueries$valu = unreffedQueries.value[0]) == null ? void 0 : _unreffedQueries$valu.queryClientKey;
|
|
14
|
+
const optionsQueryClient = (_unreffedQueries$valu2 = unreffedQueries.value[0]) == null ? void 0 : _unreffedQueries$valu2.queryClient;
|
|
16
15
|
const queryClient = optionsQueryClient != null ? optionsQueryClient : useQueryClient(queryClientKey);
|
|
17
|
-
const defaultedQueries = unreffedQueries.map(options => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const defaultedQueries = computed(() => unreffedQueries.value.map(options => {
|
|
17
|
+
const defaulted = queryClient.defaultQueryOptions(options);
|
|
18
|
+
defaulted._optimisticResults = queryClient.isRestoring.value ? 'isRestoring' : 'optimistic';
|
|
19
|
+
return defaulted;
|
|
20
|
+
}));
|
|
21
|
+
const observer = new QueriesObserver(queryClient, defaultedQueries.value);
|
|
21
22
|
const state = reactive(observer.getCurrentResult());
|
|
22
|
-
const unsubscribe =
|
|
23
|
-
|
|
23
|
+
const unsubscribe = ref(() => {// noop
|
|
24
|
+
});
|
|
25
|
+
watch(queryClient.isRestoring, isRestoring => {
|
|
26
|
+
if (!isRestoring) {
|
|
27
|
+
unsubscribe.value();
|
|
28
|
+
unsubscribe.value = observer.subscribe(result => {
|
|
29
|
+
state.splice(0, result.length, ...result);
|
|
30
|
+
}); // Subscription would not fire for persisted results
|
|
31
|
+
|
|
32
|
+
state.splice(0, state.length, ...observer.getOptimisticResult(defaultedQueries.value));
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
immediate: true
|
|
24
36
|
});
|
|
25
|
-
watch(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
observer.setQueries(defaulted);
|
|
37
|
+
watch(unreffedQueries, () => {
|
|
38
|
+
observer.setQueries(defaultedQueries.value);
|
|
39
|
+
state.splice(0, state.length, ...observer.getCurrentResult());
|
|
30
40
|
}, {
|
|
31
41
|
deep: true
|
|
32
42
|
});
|
|
33
43
|
onScopeDispose(() => {
|
|
34
|
-
unsubscribe();
|
|
44
|
+
unsubscribe.value();
|
|
35
45
|
});
|
|
36
46
|
return readonly(state);
|
|
37
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueries.esm.js","sources":["../../src/useQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { QueriesObserver } from '@tanstack/query-core'\nimport {
|
|
1
|
+
{"version":3,"file":"useQueries.esm.js","sources":["../../src/useQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { QueriesObserver } from '@tanstack/query-core'\nimport {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n ref,\n watch,\n} from 'vue-demi'\nimport type { Ref } from 'vue-demi'\n\nimport type { QueryFunction, QueryObserverResult } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { UseQueryOptions } from './useQuery'\nimport type { QueryClient } from './queryClient'\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\ntype GetOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptions<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptions<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptions<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptions<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptions<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptions<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>\n select: (data: any) => infer TData\n }\n ? UseQueryOptions<TQueryFnData, unknown, TData, TQueryKey>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> }\n ? UseQueryOptions<TQueryFnData, unknown, TQueryFnData, TQueryKey>\n : // Fallback\n UseQueryOptions\n\ntype GetResults<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? QueryObserverResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? QueryObserverResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? QueryObserverResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? QueryObserverResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<unknown, any>\n select: (data: any) => infer TData\n }\n ? QueryObserverResult<TData>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, any> }\n ? QueryObserverResult<TQueryFnData>\n : // Fallback\n QueryObserverResult\n\n/**\n * UseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param\n */\nexport type UseQueriesOptions<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? UseQueryOptions[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetOptions<Head>]\n : T extends [infer Head, ...infer Tail]\n ? UseQueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]>\n : unknown[] extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends UseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >[]\n ? UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>[]\n : // Fallback\n UseQueryOptions[]\n\n/**\n * UseQueriesResults reducer recursively maps type param to results\n */\nexport type UseQueriesResults<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? QueryObserverResult[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetResults<Head>]\n : T extends [infer Head, ...infer Tail]\n ? UseQueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]>\n : T extends UseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n any\n >[]\n ? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results\n QueryObserverResult<unknown extends TData ? TQueryFnData : TData, TError>[]\n : // Fallback\n QueryObserverResult[]\n\ntype UseQueriesOptionsArg<T extends any[]> = readonly [...UseQueriesOptions<T>]\n\nexport function useQueries<T extends any[]>({\n queries,\n}: {\n queries: Ref<UseQueriesOptionsArg<T>> | UseQueriesOptionsArg<T>\n}): Readonly<UseQueriesResults<T>> {\n const unreffedQueries = computed(\n () => cloneDeepUnref(queries) as UseQueriesOptionsArg<T>,\n )\n\n const queryClientKey = unreffedQueries.value[0]?.queryClientKey\n const optionsQueryClient = unreffedQueries.value[0]?.queryClient as\n | QueryClient\n | undefined\n const queryClient = optionsQueryClient ?? useQueryClient(queryClientKey)\n const defaultedQueries = computed(() =>\n unreffedQueries.value.map((options) => {\n const defaulted = queryClient.defaultQueryOptions(options)\n defaulted._optimisticResults = queryClient.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n }),\n )\n\n const observer = new QueriesObserver(queryClient, defaultedQueries.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = ref(() => {\n // noop\n })\n\n watch(\n queryClient.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe.value()\n unsubscribe.value = observer.subscribe((result) => {\n state.splice(0, result.length, ...result)\n })\n // Subscription would not fire for persisted results\n state.splice(\n 0,\n state.length,\n ...observer.getOptimisticResult(defaultedQueries.value),\n )\n }\n },\n { immediate: true },\n )\n\n watch(\n unreffedQueries,\n () => {\n observer.setQueries(defaultedQueries.value)\n state.splice(0, state.length, ...observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe.value()\n })\n\n return readonly(state) as UseQueriesResults<T>\n}\n"],"names":["useQueries","queries","unreffedQueries","computed","cloneDeepUnref","queryClientKey","value","optionsQueryClient","queryClient","useQueryClient","defaultedQueries","map","options","defaulted","defaultQueryOptions","_optimisticResults","isRestoring","observer","QueriesObserver","state","reactive","getCurrentResult","unsubscribe","ref","watch","subscribe","result","splice","length","getOptimisticResult","immediate","setQueries","deep","onScopeDispose","readonly"],"mappings":";;;;;AAAA;AAuI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KAAK,CACHhB,WAAW,CAACQ,WADT,EAEFA,WAAD,IAAiB;IACf,IAAI,CAACA,WAAL,EAAkB;AAChBM,MAAAA,WAAW,CAAChB,KAAZ,EAAA,CAAA;MACAgB,WAAW,CAAChB,KAAZ,GAAoBW,QAAQ,CAACQ,SAAT,CAAoBC,MAAD,IAAY;QACjDP,KAAK,CAACQ,MAAN,CAAa,CAAb,EAAgBD,MAAM,CAACE,MAAvB,EAA+B,GAAGF,MAAlC,CAAA,CAAA;OADkB,CAApB,CAFgB;;AAMhBP,MAAAA,KAAK,CAACQ,MAAN,CACE,CADF,EAEER,KAAK,CAACS,MAFR,EAGE,GAAGX,QAAQ,CAACY,mBAAT,CAA6BnB,gBAAgB,CAACJ,KAA9C,CAHL,CAAA,CAAA;AAKD,KAAA;AACF,GAfE,EAgBH;AAAEwB,IAAAA,SAAS,EAAE,IAAA;AAAb,GAhBG,CAAL,CAAA;EAmBAN,KAAK,CACHtB,eADG,EAEH,MAAM;AACJe,IAAAA,QAAQ,CAACc,UAAT,CAAoBrB,gBAAgB,CAACJ,KAArC,CAAA,CAAA;AACAa,IAAAA,KAAK,CAACQ,MAAN,CAAa,CAAb,EAAgBR,KAAK,CAACS,MAAtB,EAA8B,GAAGX,QAAQ,CAACI,gBAAT,EAAjC,CAAA,CAAA;AACD,GALE,EAMH;AAAEW,IAAAA,IAAI,EAAE,IAAA;AAAR,GANG,CAAL,CAAA;AASAC,EAAAA,cAAc,CAAC,MAAM;AACnBX,IAAAA,WAAW,CAAChB,KAAZ,EAAA,CAAA;AACD,GAFa,CAAd,CAAA;EAIA,OAAO4B,QAAQ,CAACf,KAAD,CAAf,CAAA;AACD;;;;"}
|
package/build/lib/useQueries.js
CHANGED
|
@@ -8,34 +8,44 @@ var useQueryClient = require('./useQueryClient.js');
|
|
|
8
8
|
var utils = require('./utils.js');
|
|
9
9
|
|
|
10
10
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
11
|
-
|
|
12
11
|
function useQueries({
|
|
13
12
|
queries
|
|
14
13
|
}) {
|
|
15
|
-
var _unreffedQueries
|
|
14
|
+
var _unreffedQueries$valu, _unreffedQueries$valu2;
|
|
16
15
|
|
|
17
|
-
const unreffedQueries = utils.cloneDeepUnref(queries);
|
|
18
|
-
const queryClientKey = (_unreffedQueries$ = unreffedQueries[0]) == null ? void 0 : _unreffedQueries
|
|
19
|
-
const optionsQueryClient = (_unreffedQueries$
|
|
16
|
+
const unreffedQueries = vueDemi.computed(() => utils.cloneDeepUnref(queries));
|
|
17
|
+
const queryClientKey = (_unreffedQueries$valu = unreffedQueries.value[0]) == null ? void 0 : _unreffedQueries$valu.queryClientKey;
|
|
18
|
+
const optionsQueryClient = (_unreffedQueries$valu2 = unreffedQueries.value[0]) == null ? void 0 : _unreffedQueries$valu2.queryClient;
|
|
20
19
|
const queryClient = optionsQueryClient != null ? optionsQueryClient : useQueryClient.useQueryClient(queryClientKey);
|
|
21
|
-
const defaultedQueries = unreffedQueries.map(options => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
20
|
+
const defaultedQueries = vueDemi.computed(() => unreffedQueries.value.map(options => {
|
|
21
|
+
const defaulted = queryClient.defaultQueryOptions(options);
|
|
22
|
+
defaulted._optimisticResults = queryClient.isRestoring.value ? 'isRestoring' : 'optimistic';
|
|
23
|
+
return defaulted;
|
|
24
|
+
}));
|
|
25
|
+
const observer = new queryCore.QueriesObserver(queryClient, defaultedQueries.value);
|
|
25
26
|
const state = vueDemi.reactive(observer.getCurrentResult());
|
|
26
|
-
const unsubscribe =
|
|
27
|
-
|
|
27
|
+
const unsubscribe = vueDemi.ref(() => {// noop
|
|
28
|
+
});
|
|
29
|
+
vueDemi.watch(queryClient.isRestoring, isRestoring => {
|
|
30
|
+
if (!isRestoring) {
|
|
31
|
+
unsubscribe.value();
|
|
32
|
+
unsubscribe.value = observer.subscribe(result => {
|
|
33
|
+
state.splice(0, result.length, ...result);
|
|
34
|
+
}); // Subscription would not fire for persisted results
|
|
35
|
+
|
|
36
|
+
state.splice(0, state.length, ...observer.getOptimisticResult(defaultedQueries.value));
|
|
37
|
+
}
|
|
38
|
+
}, {
|
|
39
|
+
immediate: true
|
|
28
40
|
});
|
|
29
|
-
vueDemi.watch(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
});
|
|
33
|
-
observer.setQueries(defaulted);
|
|
41
|
+
vueDemi.watch(unreffedQueries, () => {
|
|
42
|
+
observer.setQueries(defaultedQueries.value);
|
|
43
|
+
state.splice(0, state.length, ...observer.getCurrentResult());
|
|
34
44
|
}, {
|
|
35
45
|
deep: true
|
|
36
46
|
});
|
|
37
47
|
vueDemi.onScopeDispose(() => {
|
|
38
|
-
unsubscribe();
|
|
48
|
+
unsubscribe.value();
|
|
39
49
|
});
|
|
40
50
|
return vueDemi.readonly(state);
|
|
41
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueries.js","sources":["../../src/useQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { QueriesObserver } from '@tanstack/query-core'\nimport {
|
|
1
|
+
{"version":3,"file":"useQueries.js","sources":["../../src/useQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { QueriesObserver } from '@tanstack/query-core'\nimport {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n ref,\n watch,\n} from 'vue-demi'\nimport type { Ref } from 'vue-demi'\n\nimport type { QueryFunction, QueryObserverResult } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { UseQueryOptions } from './useQuery'\nimport type { QueryClient } from './queryClient'\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\ntype GetOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptions<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptions<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptions<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptions<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptions<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptions<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>\n select: (data: any) => infer TData\n }\n ? UseQueryOptions<TQueryFnData, unknown, TData, TQueryKey>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> }\n ? UseQueryOptions<TQueryFnData, unknown, TQueryFnData, TQueryKey>\n : // Fallback\n UseQueryOptions\n\ntype GetResults<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? QueryObserverResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? QueryObserverResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? QueryObserverResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? QueryObserverResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<unknown, any>\n select: (data: any) => infer TData\n }\n ? QueryObserverResult<TData>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, any> }\n ? QueryObserverResult<TQueryFnData>\n : // Fallback\n QueryObserverResult\n\n/**\n * UseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param\n */\nexport type UseQueriesOptions<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? UseQueryOptions[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetOptions<Head>]\n : T extends [infer Head, ...infer Tail]\n ? UseQueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]>\n : unknown[] extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends UseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >[]\n ? UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>[]\n : // Fallback\n UseQueryOptions[]\n\n/**\n * UseQueriesResults reducer recursively maps type param to results\n */\nexport type UseQueriesResults<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? QueryObserverResult[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetResults<Head>]\n : T extends [infer Head, ...infer Tail]\n ? UseQueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]>\n : T extends UseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n any\n >[]\n ? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results\n QueryObserverResult<unknown extends TData ? TQueryFnData : TData, TError>[]\n : // Fallback\n QueryObserverResult[]\n\ntype UseQueriesOptionsArg<T extends any[]> = readonly [...UseQueriesOptions<T>]\n\nexport function useQueries<T extends any[]>({\n queries,\n}: {\n queries: Ref<UseQueriesOptionsArg<T>> | UseQueriesOptionsArg<T>\n}): Readonly<UseQueriesResults<T>> {\n const unreffedQueries = computed(\n () => cloneDeepUnref(queries) as UseQueriesOptionsArg<T>,\n )\n\n const queryClientKey = unreffedQueries.value[0]?.queryClientKey\n const optionsQueryClient = unreffedQueries.value[0]?.queryClient as\n | QueryClient\n | undefined\n const queryClient = optionsQueryClient ?? useQueryClient(queryClientKey)\n const defaultedQueries = computed(() =>\n unreffedQueries.value.map((options) => {\n const defaulted = queryClient.defaultQueryOptions(options)\n defaulted._optimisticResults = queryClient.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n }),\n )\n\n const observer = new QueriesObserver(queryClient, defaultedQueries.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = ref(() => {\n // noop\n })\n\n watch(\n queryClient.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe.value()\n unsubscribe.value = observer.subscribe((result) => {\n state.splice(0, result.length, ...result)\n })\n // Subscription would not fire for persisted results\n state.splice(\n 0,\n state.length,\n ...observer.getOptimisticResult(defaultedQueries.value),\n )\n }\n },\n { immediate: true },\n )\n\n watch(\n unreffedQueries,\n () => {\n observer.setQueries(defaultedQueries.value)\n state.splice(0, state.length, ...observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe.value()\n })\n\n return readonly(state) as UseQueriesResults<T>\n}\n"],"names":["useQueries","queries","unreffedQueries","computed","cloneDeepUnref","queryClientKey","value","optionsQueryClient","queryClient","useQueryClient","defaultedQueries","map","options","defaulted","defaultQueryOptions","_optimisticResults","isRestoring","observer","QueriesObserver","state","reactive","getCurrentResult","unsubscribe","ref","watch","subscribe","result","splice","length","getOptimisticResult","immediate","setQueries","deep","onScopeDispose","readonly"],"mappings":";;;;;;;;;AAAA;AAuIO,SAASA,UAAT,CAAqC;AAC1CC,EAAAA,OAAAA;AAD0C,CAArC,EAI4B;AAAA,EAAA,IAAA,qBAAA,EAAA,sBAAA,CAAA;;EACjC,MAAMC,eAAe,GAAGC,gBAAQ,CAC9B,MAAMC,oBAAc,CAACH,OAAD,CADU,CAAhC,CAAA;EAIA,MAAMI,cAAc,GAAGH,CAAAA,qBAAAA,GAAAA,eAAe,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AAgBD,MAAM,CAACE,MAAvB,EAA+B,GAAGF,MAAlC,CAAA,CAAA;OADkB,CAApB,CAFgB;;AAMhBP,MAAAA,KAAK,CAACQ,MAAN,CACE,CADF,EAEER,KAAK,CAACS,MAFR,EAGE,GAAGX,QAAQ,CAACY,mBAAT,CAA6BnB,gBAAgB,CAACJ,KAA9C,CAHL,CAAA,CAAA;AAKD,KAAA;AACF,GAfE,EAgBH;AAAEwB,IAAAA,SAAS,EAAE,IAAA;AAAb,GAhBG,CAAL,CAAA;EAmBAN,aAAK,CACHtB,eADG,EAEH,MAAM;AACJe,IAAAA,QAAQ,CAACc,UAAT,CAAoBrB,gBAAgB,CAACJ,KAArC,CAAA,CAAA;AACAa,IAAAA,KAAK,CAACQ,MAAN,CAAa,CAAb,EAAgBR,KAAK,CAACS,MAAtB,EAA8B,GAAGX,QAAQ,CAACI,gBAAT,EAAjC,CAAA,CAAA;AACD,GALE,EAMH;AAAEW,IAAAA,IAAI,EAAE,IAAA;AAAR,GANG,CAAL,CAAA;AASAC,EAAAA,sBAAc,CAAC,MAAM;AACnBX,IAAAA,WAAW,CAAChB,KAAZ,EAAA,CAAA;AACD,GAFa,CAAd,CAAA;EAIA,OAAO4B,gBAAQ,CAACf,KAAD,CAAf,CAAA;AACD;;;;"}
|
package/build/lib/useQueries.mjs
CHANGED
|
@@ -1,37 +1,47 @@
|
|
|
1
1
|
import { QueriesObserver } from '@tanstack/query-core';
|
|
2
|
-
import { reactive, watch, onScopeDispose, readonly } from 'vue-demi';
|
|
2
|
+
import { computed, reactive, ref, watch, onScopeDispose, readonly } from 'vue-demi';
|
|
3
3
|
import { useQueryClient } from './useQueryClient.mjs';
|
|
4
4
|
import { cloneDeepUnref } from './utils.mjs';
|
|
5
5
|
|
|
6
6
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
|
|
8
7
|
function useQueries({
|
|
9
8
|
queries
|
|
10
9
|
}) {
|
|
11
|
-
var _unreffedQueries
|
|
10
|
+
var _unreffedQueries$valu, _unreffedQueries$valu2;
|
|
12
11
|
|
|
13
|
-
const unreffedQueries = cloneDeepUnref(queries);
|
|
14
|
-
const queryClientKey = (_unreffedQueries$ = unreffedQueries[0]) == null ? void 0 : _unreffedQueries
|
|
15
|
-
const optionsQueryClient = (_unreffedQueries$
|
|
12
|
+
const unreffedQueries = computed(() => cloneDeepUnref(queries));
|
|
13
|
+
const queryClientKey = (_unreffedQueries$valu = unreffedQueries.value[0]) == null ? void 0 : _unreffedQueries$valu.queryClientKey;
|
|
14
|
+
const optionsQueryClient = (_unreffedQueries$valu2 = unreffedQueries.value[0]) == null ? void 0 : _unreffedQueries$valu2.queryClient;
|
|
16
15
|
const queryClient = optionsQueryClient != null ? optionsQueryClient : useQueryClient(queryClientKey);
|
|
17
|
-
const defaultedQueries = unreffedQueries.map(options => {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const defaultedQueries = computed(() => unreffedQueries.value.map(options => {
|
|
17
|
+
const defaulted = queryClient.defaultQueryOptions(options);
|
|
18
|
+
defaulted._optimisticResults = queryClient.isRestoring.value ? 'isRestoring' : 'optimistic';
|
|
19
|
+
return defaulted;
|
|
20
|
+
}));
|
|
21
|
+
const observer = new QueriesObserver(queryClient, defaultedQueries.value);
|
|
21
22
|
const state = reactive(observer.getCurrentResult());
|
|
22
|
-
const unsubscribe =
|
|
23
|
-
|
|
23
|
+
const unsubscribe = ref(() => {// noop
|
|
24
|
+
});
|
|
25
|
+
watch(queryClient.isRestoring, isRestoring => {
|
|
26
|
+
if (!isRestoring) {
|
|
27
|
+
unsubscribe.value();
|
|
28
|
+
unsubscribe.value = observer.subscribe(result => {
|
|
29
|
+
state.splice(0, result.length, ...result);
|
|
30
|
+
}); // Subscription would not fire for persisted results
|
|
31
|
+
|
|
32
|
+
state.splice(0, state.length, ...observer.getOptimisticResult(defaultedQueries.value));
|
|
33
|
+
}
|
|
34
|
+
}, {
|
|
35
|
+
immediate: true
|
|
24
36
|
});
|
|
25
|
-
watch(
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
});
|
|
29
|
-
observer.setQueries(defaulted);
|
|
37
|
+
watch(unreffedQueries, () => {
|
|
38
|
+
observer.setQueries(defaultedQueries.value);
|
|
39
|
+
state.splice(0, state.length, ...observer.getCurrentResult());
|
|
30
40
|
}, {
|
|
31
41
|
deep: true
|
|
32
42
|
});
|
|
33
43
|
onScopeDispose(() => {
|
|
34
|
-
unsubscribe();
|
|
44
|
+
unsubscribe.value();
|
|
35
45
|
});
|
|
36
46
|
return readonly(state);
|
|
37
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueries.mjs","sources":["../../src/useQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { QueriesObserver } from '@tanstack/query-core'\nimport {
|
|
1
|
+
{"version":3,"file":"useQueries.mjs","sources":["../../src/useQueries.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { QueriesObserver } from '@tanstack/query-core'\nimport {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n ref,\n watch,\n} from 'vue-demi'\nimport type { Ref } from 'vue-demi'\n\nimport type { QueryFunction, QueryObserverResult } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref } from './utils'\nimport type { UseQueryOptions } from './useQuery'\nimport type { QueryClient } from './queryClient'\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\ntype GetOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptions<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptions<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptions<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptions<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptions<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptions<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>\n select: (data: any) => infer TData\n }\n ? UseQueryOptions<TQueryFnData, unknown, TData, TQueryKey>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> }\n ? UseQueryOptions<TQueryFnData, unknown, TQueryFnData, TQueryKey>\n : // Fallback\n UseQueryOptions\n\ntype GetResults<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? QueryObserverResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? QueryObserverResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? QueryObserverResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? QueryObserverResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? QueryObserverResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<unknown, any>\n select: (data: any) => infer TData\n }\n ? QueryObserverResult<TData>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, any> }\n ? QueryObserverResult<TQueryFnData>\n : // Fallback\n QueryObserverResult\n\n/**\n * UseQueriesOptions reducer recursively unwraps function arguments to infer/enforce type param\n */\nexport type UseQueriesOptions<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? UseQueryOptions[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetOptions<Head>]\n : T extends [infer Head, ...infer Tail]\n ? UseQueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]>\n : unknown[] extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends UseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >[]\n ? UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>[]\n : // Fallback\n UseQueryOptions[]\n\n/**\n * UseQueriesResults reducer recursively maps type param to results\n */\nexport type UseQueriesResults<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? QueryObserverResult[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetResults<Head>]\n : T extends [infer Head, ...infer Tail]\n ? UseQueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]>\n : T extends UseQueryOptions<\n infer TQueryFnData,\n infer TError,\n infer TData,\n any\n >[]\n ? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results\n QueryObserverResult<unknown extends TData ? TQueryFnData : TData, TError>[]\n : // Fallback\n QueryObserverResult[]\n\ntype UseQueriesOptionsArg<T extends any[]> = readonly [...UseQueriesOptions<T>]\n\nexport function useQueries<T extends any[]>({\n queries,\n}: {\n queries: Ref<UseQueriesOptionsArg<T>> | UseQueriesOptionsArg<T>\n}): Readonly<UseQueriesResults<T>> {\n const unreffedQueries = computed(\n () => cloneDeepUnref(queries) as UseQueriesOptionsArg<T>,\n )\n\n const queryClientKey = unreffedQueries.value[0]?.queryClientKey\n const optionsQueryClient = unreffedQueries.value[0]?.queryClient as\n | QueryClient\n | undefined\n const queryClient = optionsQueryClient ?? useQueryClient(queryClientKey)\n const defaultedQueries = computed(() =>\n unreffedQueries.value.map((options) => {\n const defaulted = queryClient.defaultQueryOptions(options)\n defaulted._optimisticResults = queryClient.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n }),\n )\n\n const observer = new QueriesObserver(queryClient, defaultedQueries.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = ref(() => {\n // noop\n })\n\n watch(\n queryClient.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe.value()\n unsubscribe.value = observer.subscribe((result) => {\n state.splice(0, result.length, ...result)\n })\n // Subscription would not fire for persisted results\n state.splice(\n 0,\n state.length,\n ...observer.getOptimisticResult(defaultedQueries.value),\n )\n }\n },\n { immediate: true },\n )\n\n watch(\n unreffedQueries,\n () => {\n observer.setQueries(defaultedQueries.value)\n state.splice(0, state.length, ...observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe.value()\n })\n\n return readonly(state) as UseQueriesResults<T>\n}\n"],"names":["useQueries","queries","unreffedQueries","computed","cloneDeepUnref","queryClientKey","value","optionsQueryClient","queryClient","useQueryClient","defaultedQueries","map","options","defaulted","defaultQueryOptions","_optimisticResults","isRestoring","observer","QueriesObserver","state","reactive","getCurrentResult","unsubscribe","ref","watch","subscribe","result","splice","length","getOptimisticResult","immediate","setQueries","deep","onScopeDispose","readonly"],"mappings":";;;;;AAAA;AAuIO,SAASA,UAAT,CAAqC;AAC1CC,EAAAA,OAAAA;AAD0C,CAArC,EAI4B;AAAA,EAAA,IAAA,qBAAA,EAAA,sBAAA,CAAA;;EACjC,MAAMC,eAAe,GAAGC,QAAQ,CAC9B,MAAMC,cAAc,CAACH,OAAD,CADU,CAAhC,CAAA;EAIA,MAAMI,cAAc,GAAGH,CAAAA,qBAAAA,GAAAA,eAAe,CAACI,KAAhB,CAAsB,CAAtB,CAAH,KAAG,IAAA,GAAA,KAAA,CAAA,GAAA,qBAAA,CAA0BD,cAAjD,CAAA;EACA,MAAME,kBAAkB,GAAGL,CAAAA,sBAAAA,GAAAA,eAAe,CAACI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AAQ,CAACY,mBAAT,CAA6BnB,gBAAgB,CAACJ,KAA9C,CAHL,CAAA,CAAA;AAKD,KAAA;AACF,GAfE,EAgBH;AAAEwB,IAAAA,SAAS,EAAE,IAAA;AAAb,GAhBG,CAAL,CAAA;EAmBAN,KAAK,CACHtB,eADG,EAEH,MAAM;AACJe,IAAAA,QAAQ,CAACc,UAAT,CAAoBrB,gBAAgB,CAACJ,KAArC,CAAA,CAAA;AACAa,IAAAA,KAAK,CAACQ,MAAN,CAAa,CAAb,EAAgBR,KAAK,CAACS,MAAtB,EAA8B,GAAGX,QAAQ,CAACI,gBAAT,EAAjC,CAAA,CAAA;AACD,GALE,EAMH;AAAEW,IAAAA,IAAI,EAAE,IAAA;AAAR,GANG,CAAL,CAAA;AASAC,EAAAA,cAAc,CAAC,MAAM;AACnBX,IAAAA,WAAW,CAAChB,KAAZ,EAAA,CAAA;AACD,GAFa,CAAd,CAAA;EAIA,OAAO4B,QAAQ,CAACf,KAAD,CAAf,CAAA;AACD;;;;"}
|
|
@@ -6,19 +6,17 @@ declare global {
|
|
|
6
6
|
__VUE_QUERY_CONTEXT__?: QueryClient;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
queryClientKey: string;
|
|
12
|
-
}
|
|
13
|
-
interface ConfigOptions {
|
|
14
|
-
queryClientConfig?: MaybeRefDeep<QueryClientConfig>;
|
|
9
|
+
declare type ClientPersister = (client: QueryClient) => [() => void, Promise<void>];
|
|
10
|
+
interface CommonOptions {
|
|
15
11
|
queryClientKey?: string;
|
|
16
12
|
contextSharing?: boolean;
|
|
13
|
+
clientPersister?: ClientPersister;
|
|
14
|
+
}
|
|
15
|
+
interface ConfigOptions extends CommonOptions {
|
|
16
|
+
queryClientConfig?: MaybeRefDeep<QueryClientConfig>;
|
|
17
17
|
}
|
|
18
|
-
interface ClientOptions {
|
|
18
|
+
interface ClientOptions extends CommonOptions {
|
|
19
19
|
queryClient?: QueryClient;
|
|
20
|
-
queryClientKey?: string;
|
|
21
|
-
contextSharing?: boolean;
|
|
22
20
|
}
|
|
23
21
|
export declare type VueQueryPluginOptions = ConfigOptions | ClientOptions;
|
|
24
22
|
export declare const VueQueryPlugin: {
|
|
@@ -27,12 +27,25 @@ const VueQueryPlugin = {
|
|
|
27
27
|
|
|
28
28
|
client.mount();
|
|
29
29
|
|
|
30
|
+
let persisterUnmount = () => {// noop
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (options.clientPersister) {
|
|
34
|
+
client.isRestoring.value = true;
|
|
35
|
+
const [unmount, promise] = options.clientPersister(client);
|
|
36
|
+
persisterUnmount = unmount;
|
|
37
|
+
promise.then(() => {
|
|
38
|
+
client.isRestoring.value = false;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
if (process.env.NODE_ENV !== 'production' && options.contextSharing) {
|
|
31
43
|
client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
const cleanup = () => {
|
|
35
47
|
client.unmount();
|
|
48
|
+
persisterUnmount();
|
|
36
49
|
};
|
|
37
50
|
|
|
38
51
|
if (app.onUnmount) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vueQueryPlugin.esm.js","sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport type { QueryClientConfig } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { MaybeRefDeep } from './types'\n\ndeclare global {\n interface Window {\n __VUE_QUERY_CONTEXT__?: QueryClient\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"vueQueryPlugin.esm.js","sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport type { QueryClientConfig } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { MaybeRefDeep } from './types'\n\ndeclare global {\n interface Window {\n __VUE_QUERY_CONTEXT__?: QueryClient\n }\n}\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n contextSharing?: boolean\n clientPersister?: ClientPersister\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: MaybeRefDeep<QueryClientConfig>\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n if (options.contextSharing && typeof window !== 'undefined') {\n if (!window.__VUE_QUERY_CONTEXT__) {\n const clientConfig =\n 'queryClientConfig' in options\n ? options.queryClientConfig\n : undefined\n client = new QueryClient(clientConfig)\n window.__VUE_QUERY_CONTEXT__ = client\n } else {\n client = window.__VUE_QUERY_CONTEXT__\n }\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n }\n\n client.mount()\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n })\n }\n\n if (process.env.NODE_ENV !== 'production' && options.contextSharing) {\n client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n /* istanbul ignore next */\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"names":["VueQueryPlugin","install","app","options","clientKey","getClientKey","queryClientKey","client","queryClient","contextSharing","window","__VUE_QUERY_CONTEXT__","clientConfig","queryClientConfig","undefined","QueryClient","mount","persisterUnmount","clientPersister","isRestoring","value","unmount","promise","then","process","env","NODE_ENV","getLogger","error","cleanup","onUnmount","originalUnmount","vueQueryUnmount","isVue2","mixin","beforeCreate","_provided","provideCache","Object","defineProperty","get","set","v","assign","$root","setupDevtools","provide"],"mappings":";;;;;AAgCO,MAAMA,cAAc,GAAG;AAC5BC,EAAAA,OAAO,EAAE,CAACC,GAAD,EAAWC,OAA8B,GAAG,EAA5C,KAAmD;AAC1D,IAAA,MAAMC,SAAS,GAAGC,YAAY,CAACF,OAAO,CAACG,cAAT,CAA9B,CAAA;AACA,IAAA,IAAIC,MAAJ,CAAA;;AAEA,IAAA,IAAI,iBAAiBJ,OAAjB,IAA4BA,OAAO,CAACK,WAAxC,EAAqD;MACnDD,MAAM,GAAGJ,OAAO,CAACK,WAAjB,CAAA;AACD,KAFD,MAEO;MACL,IAAIL,OAAO,CAACM,cAAR,IAA0B,OAAOC,MAAP,KAAkB,WAAhD,EAA6D;AAC3D,QAAA,IAAI,CAACA,MAAM,CAACC,qBAAZ,EAAmC;UACjC,MAAMC,YAAY,GAChB,mBAAuBT,IAAAA,OAAvB,GACIA,OAAO,CAACU,iBADZ,GAEIC,SAHN,CAAA;AAIAP,UAAAA,MAAM,GAAG,IAAIQ,WAAJ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VueQueryPlugin = {
|
|
|
31
31
|
|
|
32
32
|
client.mount();
|
|
33
33
|
|
|
34
|
+
let persisterUnmount = () => {// noop
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
if (options.clientPersister) {
|
|
38
|
+
client.isRestoring.value = true;
|
|
39
|
+
const [unmount, promise] = options.clientPersister(client);
|
|
40
|
+
persisterUnmount = unmount;
|
|
41
|
+
promise.then(() => {
|
|
42
|
+
client.isRestoring.value = false;
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
if (process.env.NODE_ENV !== 'production' && options.contextSharing) {
|
|
35
47
|
client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
|
|
36
48
|
}
|
|
37
49
|
|
|
38
50
|
const cleanup = () => {
|
|
39
51
|
client.unmount();
|
|
52
|
+
persisterUnmount();
|
|
40
53
|
};
|
|
41
54
|
|
|
42
55
|
if (app.onUnmount) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vueQueryPlugin.js","sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport type { QueryClientConfig } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { MaybeRefDeep } from './types'\n\ndeclare global {\n interface Window {\n __VUE_QUERY_CONTEXT__?: QueryClient\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"vueQueryPlugin.js","sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport type { QueryClientConfig } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { MaybeRefDeep } from './types'\n\ndeclare global {\n interface Window {\n __VUE_QUERY_CONTEXT__?: QueryClient\n }\n}\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n contextSharing?: boolean\n clientPersister?: ClientPersister\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: MaybeRefDeep<QueryClientConfig>\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n if (options.contextSharing && typeof window !== 'undefined') {\n if (!window.__VUE_QUERY_CONTEXT__) {\n const clientConfig =\n 'queryClientConfig' in options\n ? options.queryClientConfig\n : undefined\n client = new QueryClient(clientConfig)\n window.__VUE_QUERY_CONTEXT__ = client\n } else {\n client = window.__VUE_QUERY_CONTEXT__\n }\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n }\n\n client.mount()\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n })\n }\n\n if (process.env.NODE_ENV !== 'production' && options.contextSharing) {\n client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n /* istanbul ignore next */\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"names":["VueQueryPlugin","install","app","options","clientKey","getClientKey","queryClientKey","client","queryClient","contextSharing","window","__VUE_QUERY_CONTEXT__","clientConfig","queryClientConfig","undefined","QueryClient","mount","persisterUnmount","clientPersister","isRestoring","value","unmount","promise","then","process","env","NODE_ENV","getLogger","error","cleanup","onUnmount","originalUnmount","vueQueryUnmount","isVue2","mixin","beforeCreate","_provided","provideCache","Object","defineProperty","get","set","v","assign","$root","setupDevtools","provide"],"mappings":";;;;;;;;;AAgCO,MAAMA,cAAc,GAAG;AAC5BC,EAAAA,OAAO,EAAE,CAACC,GAAD,EAAWC,OAA8B,GAAG,EAA5C,KAAmD;AAC1D,IAAA,MAAMC,SAAS,GAAGC,kBAAY,CAACF,OAAO,CAACG,cAAT,CAA9B,CAAA;AACA,IAAA,IAAIC,MAAJ,CAAA;;AAEA,IAAA,IAAI,iBAAiBJ,OAAjB,IAA4BA,OAAO,CAACK,WAAxC,EAAqD;MACnDD,MAAM,GAAGJ,OAAO,CAACK,WAAjB,CAAA;AACD,KAFD,MAEO;MACL,IAAIL,OAAO,CAACM,cAAR,IAA0B,OAAOC,MAAP,KAAkB,WAAhD,EAA6D;AAC3D,QAAA,IAAI,CAACA,MAAM,CAACC,qBAAZ,EAAmC;UACjC,MAAMC,YAAY,GAChB,mBAAuBT,IAAAA,OAAvB,GACIA,OAAO,CAACU,iBADZ,GAEIC,SAHN,CAAA;AAIAP,UAAAA,MAAM,GAAG,IAAIQ,uBAAJ,CAAgBH,YAAhB,CAAT,CAAA;UACAF,MAAM,CAACC,qBAAP,GAA+BJ,MAA/B,CAAA;AACD,SAPD,MAOO;UACLA,MAAM,GAAGG,MAAM,CAACC,qBAAhB,CAAA;AACD,SAAA;AACF,OAXD,MAWO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e,EAAA,CAAA;OAFjB,CAAA;AAID,KAAA;AAED;;;AACA,IAAA,IAAIE,cAAJ,EAAY;MACV/B,GAAG,CAACgC,KAAJ,CAAU;AACRC,QAAAA,YAAY,GAAG;AACb;UACA,IAAI,CAAC,IAAKC,CAAAA,SAAV,EAAqB;YACnB,MAAMC,YAAY,GAAG,EAArB,CAAA;AACAC,YAAAA,MAAM,CAACC,cAAP,CAAsB,IAAtB,EAA4B,WAA5B,EAAyC;cACvCC,GAAG,EAAE,MAAMH,YAD4B;cAEvCI,GAAG,EAAGC,CAAD,IAAOJ,MAAM,CAACK,MAAP,CAAcN,YAAd,EAA4BK,CAA5B,CAAA;aAFd,CAAA,CAAA;AAID,WAAA;;AAED,UAAA,IAAA,CAAKN,SAAL,CAAehC,SAAf,CAAA,GAA4BG,MAA5B,CAAA;;AAEA,UAAA,IAAIiB,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,aAA7B,EAA4C;YAC1C,IAAI,IAAA,KAAS,IAAKkB,CAAAA,KAAlB,EAAyB;AACvBC,cAAAA,sBAAa,CAAC,IAAD,EAAOtC,MAAP,CAAb,CAAA;AACD,aAAA;AACF,WAAA;AACF,SAAA;;OAlBH,CAAA,CAAA;AAoBD,KArBD,MAqBO;AACLL,MAAAA,GAAG,CAAC4C,OAAJ,CAAY1C,SAAZ,EAAuBG,MAAvB,CAAA,CAAA;;AAEA,MAAA,IAAIiB,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,aAA7B,EAA4C;AAC1CmB,QAAAA,sBAAa,CAAC3C,GAAD,EAAMK,MAAN,CAAb,CAAA;AACD,OAAA;AACF,KAAA;AACF,GAAA;AA5F2B;;;;"}
|
|
@@ -27,12 +27,25 @@ const VueQueryPlugin = {
|
|
|
27
27
|
|
|
28
28
|
client.mount();
|
|
29
29
|
|
|
30
|
+
let persisterUnmount = () => {// noop
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (options.clientPersister) {
|
|
34
|
+
client.isRestoring.value = true;
|
|
35
|
+
const [unmount, promise] = options.clientPersister(client);
|
|
36
|
+
persisterUnmount = unmount;
|
|
37
|
+
promise.then(() => {
|
|
38
|
+
client.isRestoring.value = false;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
|
|
30
42
|
if (process.env.NODE_ENV !== 'production' && options.contextSharing) {
|
|
31
43
|
client.getLogger().error("The contextSharing option has been deprecated and will be removed in the next major version");
|
|
32
44
|
}
|
|
33
45
|
|
|
34
46
|
const cleanup = () => {
|
|
35
47
|
client.unmount();
|
|
48
|
+
persisterUnmount();
|
|
36
49
|
};
|
|
37
50
|
|
|
38
51
|
if (app.onUnmount) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vueQueryPlugin.mjs","sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport type { QueryClientConfig } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { MaybeRefDeep } from './types'\n\ndeclare global {\n interface Window {\n __VUE_QUERY_CONTEXT__?: QueryClient\n }\n}\n\
|
|
1
|
+
{"version":3,"file":"vueQueryPlugin.mjs","sources":["../../src/vueQueryPlugin.ts"],"sourcesContent":["import { isVue2 } from 'vue-demi'\nimport type { QueryClientConfig } from '@tanstack/query-core'\n\nimport { QueryClient } from './queryClient'\nimport { getClientKey } from './utils'\nimport { setupDevtools } from './devtools/devtools'\nimport type { MaybeRefDeep } from './types'\n\ndeclare global {\n interface Window {\n __VUE_QUERY_CONTEXT__?: QueryClient\n }\n}\n\ntype ClientPersister = (client: QueryClient) => [() => void, Promise<void>]\n\ninterface CommonOptions {\n queryClientKey?: string\n contextSharing?: boolean\n clientPersister?: ClientPersister\n}\n\ninterface ConfigOptions extends CommonOptions {\n queryClientConfig?: MaybeRefDeep<QueryClientConfig>\n}\n\ninterface ClientOptions extends CommonOptions {\n queryClient?: QueryClient\n}\n\nexport type VueQueryPluginOptions = ConfigOptions | ClientOptions\n\nexport const VueQueryPlugin = {\n install: (app: any, options: VueQueryPluginOptions = {}) => {\n const clientKey = getClientKey(options.queryClientKey)\n let client: QueryClient\n\n if ('queryClient' in options && options.queryClient) {\n client = options.queryClient\n } else {\n if (options.contextSharing && typeof window !== 'undefined') {\n if (!window.__VUE_QUERY_CONTEXT__) {\n const clientConfig =\n 'queryClientConfig' in options\n ? options.queryClientConfig\n : undefined\n client = new QueryClient(clientConfig)\n window.__VUE_QUERY_CONTEXT__ = client\n } else {\n client = window.__VUE_QUERY_CONTEXT__\n }\n } else {\n const clientConfig =\n 'queryClientConfig' in options ? options.queryClientConfig : undefined\n client = new QueryClient(clientConfig)\n }\n }\n\n client.mount()\n let persisterUnmount = () => {\n // noop\n }\n\n if (options.clientPersister) {\n client.isRestoring.value = true\n const [unmount, promise] = options.clientPersister(client)\n persisterUnmount = unmount\n promise.then(() => {\n client.isRestoring.value = false\n })\n }\n\n if (process.env.NODE_ENV !== 'production' && options.contextSharing) {\n client\n .getLogger()\n .error(\n `The contextSharing option has been deprecated and will be removed in the next major version`,\n )\n }\n\n const cleanup = () => {\n client.unmount()\n persisterUnmount()\n }\n\n if (app.onUnmount) {\n app.onUnmount(cleanup)\n } else {\n const originalUnmount = app.unmount\n app.unmount = function vueQueryUnmount() {\n cleanup()\n originalUnmount()\n }\n }\n\n /* istanbul ignore next */\n if (isVue2) {\n app.mixin({\n beforeCreate() {\n // HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30\n if (!this._provided) {\n const provideCache = {}\n Object.defineProperty(this, '_provided', {\n get: () => provideCache,\n set: (v) => Object.assign(provideCache, v),\n })\n }\n\n this._provided[clientKey] = client\n\n if (process.env.NODE_ENV === 'development') {\n if (this === this.$root) {\n setupDevtools(this, client)\n }\n }\n },\n })\n } else {\n app.provide(clientKey, client)\n\n if (process.env.NODE_ENV === 'development') {\n setupDevtools(app, client)\n }\n }\n },\n}\n"],"names":["VueQueryPlugin","install","app","options","clientKey","getClientKey","queryClientKey","client","queryClient","contextSharing","window","__VUE_QUERY_CONTEXT__","clientConfig","queryClientConfig","undefined","QueryClient","mount","persisterUnmount","clientPersister","isRestoring","value","unmount","promise","then","process","env","NODE_ENV","getLogger","error","cleanup","onUnmount","originalUnmount","vueQueryUnmount","isVue2","mixin","beforeCreate","_provided","provideCache","Object","defineProperty","get","set","v","assign","$root","setupDevtools","provide"],"mappings":";;;;;AAgCO,MAAMA,cAAc,GAAG;AAC5BC,EAAAA,OAAO,EAAE,CAACC,GAAD,EAAWC,OAA8B,GAAG,EAA5C,KAAmD;AAC1D,IAAA,MAAMC,SAAS,GAAGC,YAAY,CAACF,OAAO,CAACG,cAAT,CAA9B,CAAA;AACA,IAAA,IAAIC,MAAJ,CAAA;;AAEA,IAAA,IAAI,iBAAiBJ,OAAjB,IAA4BA,OAAO,CAACK,WAAxC,EAAqD;MACnDD,MAAM,GAAGJ,OAAO,CAACK,WAAjB,CAAA;AACD,KAFD,MAEO;MACL,IAAIL,OAAO,CAACM,cAAR,IAA0B,OAAOC,MAAP,KAAkB,WAAhD,EAA6D;AAC3D,QAAA,IAAI,CAACA,MAAM,CAACC,qBAAZ,EAAmC;UACjC,MAAMC,YAAY,GAChB,mBAAuBT,IAAAA,OAAvB,GACIA,OAAO,CAACU,iBADZ,GAEIC,SAHN,CAAA;AAIAP,UAAAA,MAAM,GAAG,IAAIQ,WAAJ,CAAgBH,YAAhB,CAAT,CAAA;UACAF,MAAM,CAACC,qBAAP,GAA+BJ,MAA/B,CAAA;AACD,SAPD,MAOO;UACLA,MAAM,GAAGG,MAAM,CAACC,qBAAhB,CAAA;AACD,SAAA;AACF,OAXD,MAWO;QACL,MAAMC,YAAY,GAChB,mBAAuBT,IAAAA,OAAvB,GAAiCA,OAAO,CAACU,iBAAzC,GAA6DC,SAD/D,CAAA;AAEAP,QAAAA,MAAM,GAAG,IAAIQ,WAAJ,CAAgBH,YAAhB,CAAT,C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