@tanstack/vue-query 4.20.4 → 4.20.5
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/useBaseQuery.esm.js +4 -4
- package/build/lib/useBaseQuery.esm.js.map +1 -1
- package/build/lib/useBaseQuery.js +3 -3
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useBaseQuery.mjs +4 -4
- package/build/lib/useBaseQuery.mjs.map +1 -1
- package/build/lib/useIsFetching.esm.js +3 -3
- package/build/lib/useIsFetching.esm.js.map +1 -1
- package/build/lib/useIsFetching.js +2 -2
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useIsFetching.mjs +3 -3
- package/build/lib/useIsFetching.mjs.map +1 -1
- package/build/lib/useIsMutating.esm.js +3 -3
- package/build/lib/useIsMutating.esm.js.map +1 -1
- package/build/lib/useIsMutating.js +2 -2
- package/build/lib/useIsMutating.js.map +1 -1
- package/build/lib/useIsMutating.mjs +3 -3
- package/build/lib/useIsMutating.mjs.map +1 -1
- package/build/lib/useMutation.esm.js +4 -4
- package/build/lib/useMutation.esm.js.map +1 -1
- package/build/lib/useMutation.js +3 -3
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutation.mjs +4 -4
- package/build/lib/useMutation.mjs.map +1 -1
- package/build/umd/index.development.js +10 -10
- 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 +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, reactive, ref, watch, onScopeDispose, toRefs, readonly,
|
|
1
|
+
import { computed, reactive, ref, watch, onScopeDispose, toRefs, readonly, unref } from 'vue-demi';
|
|
2
2
|
import { useQueryClient } from './useQueryClient.esm.js';
|
|
3
3
|
import { updateState, isQueryKey, cloneDeepUnref } from './utils.esm.js';
|
|
4
4
|
|
|
@@ -68,9 +68,9 @@ function useBaseQuery(Observer, arg1, arg2 = {}, arg3 = {}) {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
function parseQueryArgs(arg1, arg2 = {}, arg3 = {}) {
|
|
71
|
-
const plainArg1 =
|
|
72
|
-
const plainArg2 =
|
|
73
|
-
const plainArg3 =
|
|
71
|
+
const plainArg1 = unref(arg1);
|
|
72
|
+
const plainArg2 = unref(arg2);
|
|
73
|
+
const plainArg3 = unref(arg3);
|
|
74
74
|
let options = plainArg1;
|
|
75
75
|
|
|
76
76
|
if (!isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.esm.js","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n onScopeDispose,\n toRefs,\n readonly,\n reactive,\n watch,\n ref,\n computed,\n
|
|
1
|
+
{"version":3,"file":"useBaseQuery.esm.js","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n onScopeDispose,\n toRefs,\n readonly,\n reactive,\n watch,\n ref,\n computed,\n unref,\n} from 'vue-demi'\nimport type { ToRefs, UnwrapRef } from 'vue-demi'\nimport type {\n QueryObserver,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n QueryFunction,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { updateState, isQueryKey, cloneDeepUnref } from './utils'\nimport type { MaybeRef, WithQueryClientKey } from './types'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseQueryReturnType<\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 TQueryKey extends QueryKey = QueryKey,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n Observer: typeof QueryObserver,\n arg1:\n | TQueryKey\n | UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>,\n arg2:\n | QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>\n | UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},\n arg3: UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},\n): UseQueryReturnType<TData, TError> {\n const options = computed(() => parseQueryArgs(arg1, arg2, arg3))\n\n const queryClient =\n options.value.queryClient ?? useQueryClient(options.value.queryClientKey)\n\n const defaultedOptions = computed(() => {\n const defaulted = queryClient.defaultQueryOptions(options.value)\n defaulted._optimisticResults = queryClient.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(queryClient, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = ref(() => {\n // noop\n })\n\n watch(\n queryClient.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe.value()\n unsubscribe.value = 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 { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe.value()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>((resolve) => {\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 resolve(observer.fetchOptimistic(defaultedOptions.value))\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n })\n }\n\n return {\n ...(toRefs(readonly(state)) as UseQueryReturnType<TData, TError>),\n suspense,\n }\n}\n\nexport function parseQueryArgs<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1:\n | MaybeRef<TQueryKey>\n | MaybeRef<UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>>,\n arg2:\n | MaybeRef<QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>>\n | MaybeRef<\n UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>\n > = {},\n arg3: MaybeRef<\n UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>\n > = {},\n): WithQueryClientKey<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n> {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n const plainArg3 = unref(arg3)\n\n let options = plainArg1\n\n if (!isQueryKey(plainArg1)) {\n options = plainArg1\n } else if (typeof plainArg2 === 'function') {\n options = { ...plainArg3, queryKey: plainArg1, queryFn: plainArg2 }\n } else {\n options = { ...plainArg2, queryKey: plainArg1 }\n }\n\n return cloneDeepUnref(options) as WithQueryClientKey<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n >\n}\n"],"names":["useBaseQuery","Observer","arg1","arg2","arg3","options","computed","parseQueryArgs","queryClient","value","useQueryClient","queryClientKey","defaultedOptions","defaulted","defaultQueryOptions","_optimisticResults","isRestoring","observer","state","reactive","getCurrentResult","unsubscribe","ref","watch","subscribe","result","updateState","immediate","setOptions","deep","onScopeDispose","suspense","Promise","resolve","stopWatch","run","enabled","optimisticResult","getOptimisticResult","isStale","fetchOptimistic","toRefs","readonly","plainArg1","unref","plainArg2","plainArg3","isQueryKey","queryKey","queryFn","cloneDeepUnref"],"mappings":";;;;AAyCO,SAASA,YAAT,CAMLC,QANK,EAOLC,IAPK,EAULC,IAEkE,GAAG,EAZhE,EAaLC,IAAoE,GAAG,EAblE,EAc8B;AAAA,EAA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AAQ,CAACxB,KAAD,CAAT,CADL;AAELa,IAAAA,QAAAA;GAFF,CAAA;AAID,CAAA;AAEM,SAASxB,cAAT,CAOLL,IAPK,EAULC,IAIK,GAAG,EAdH,EAeLC,IAEC,GAAG,EAjBC,EAoBL;AACA,EAAA,MAAMuC,SAAS,GAAGC,KAAK,CAAC1C,IAAD,CAAvB,CAAA;AACA,EAAA,MAAM2C,SAAS,GAAGD,KAAK,CAACzC,IAAD,CAAvB,CAAA;AACA,EAAA,MAAM2C,SAAS,GAAGF,KAAK,CAACxC,IAAD,CAAvB,CAAA;EAEA,IAAIC,OAAO,GAAGsC,SAAd,CAAA;;AAEA,EAAA,IAAI,CAACI,UAAU,CAACJ,SAAD,CAAf,EAA4B;AAC1BtC,IAAAA,OAAO,GAAGsC,SAAV,CAAA;AACD,GAFD,MAEO,IAAI,OAAOE,SAAP,KAAqB,UAAzB,EAAqC;IAC1CxC,OAAO,GAAG,EAAE,GAAGyC,SAAL;AAAgBE,MAAAA,QAAQ,EAAEL,SAA1B;AAAqCM,MAAAA,OAAO,EAAEJ,SAAAA;KAAxD,CAAA;AACD,GAFM,MAEA;IACLxC,OAAO,GAAG,EAAE,GAAGwC,SAAL;AAAgBG,MAAAA,QAAQ,EAAEL,SAAAA;KAApC,CAAA;AACD,GAAA;;EAED,OAAOO,cAAc,CAAC7C,OAAD,CAArB,CAAA;AAGD;;;;"}
|
|
@@ -72,9 +72,9 @@ function useBaseQuery(Observer, arg1, arg2 = {}, arg3 = {}) {
|
|
|
72
72
|
};
|
|
73
73
|
}
|
|
74
74
|
function parseQueryArgs(arg1, arg2 = {}, arg3 = {}) {
|
|
75
|
-
const plainArg1 = vueDemi.
|
|
76
|
-
const plainArg2 = vueDemi.
|
|
77
|
-
const plainArg3 = vueDemi.
|
|
75
|
+
const plainArg1 = vueDemi.unref(arg1);
|
|
76
|
+
const plainArg2 = vueDemi.unref(arg2);
|
|
77
|
+
const plainArg3 = vueDemi.unref(arg3);
|
|
78
78
|
let options = plainArg1;
|
|
79
79
|
|
|
80
80
|
if (!utils.isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.js","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n onScopeDispose,\n toRefs,\n readonly,\n reactive,\n watch,\n ref,\n computed,\n
|
|
1
|
+
{"version":3,"file":"useBaseQuery.js","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n onScopeDispose,\n toRefs,\n readonly,\n reactive,\n watch,\n ref,\n computed,\n unref,\n} from 'vue-demi'\nimport type { ToRefs, UnwrapRef } from 'vue-demi'\nimport type {\n QueryObserver,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n QueryFunction,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { updateState, isQueryKey, cloneDeepUnref } from './utils'\nimport type { MaybeRef, WithQueryClientKey } from './types'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseQueryReturnType<\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 TQueryKey extends QueryKey = QueryKey,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n Observer: typeof QueryObserver,\n arg1:\n | TQueryKey\n | UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>,\n arg2:\n | QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>\n | UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},\n arg3: UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},\n): UseQueryReturnType<TData, TError> {\n const options = computed(() => parseQueryArgs(arg1, arg2, arg3))\n\n const queryClient =\n options.value.queryClient ?? useQueryClient(options.value.queryClientKey)\n\n const defaultedOptions = computed(() => {\n const defaulted = queryClient.defaultQueryOptions(options.value)\n defaulted._optimisticResults = queryClient.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(queryClient, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = ref(() => {\n // noop\n })\n\n watch(\n queryClient.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe.value()\n unsubscribe.value = 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 { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe.value()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>((resolve) => {\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 resolve(observer.fetchOptimistic(defaultedOptions.value))\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n })\n }\n\n return {\n ...(toRefs(readonly(state)) as UseQueryReturnType<TData, TError>),\n suspense,\n }\n}\n\nexport function parseQueryArgs<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1:\n | MaybeRef<TQueryKey>\n | MaybeRef<UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>>,\n arg2:\n | MaybeRef<QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>>\n | MaybeRef<\n UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>\n > = {},\n arg3: MaybeRef<\n UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>\n > = {},\n): WithQueryClientKey<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n> {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n const plainArg3 = unref(arg3)\n\n let options = plainArg1\n\n if (!isQueryKey(plainArg1)) {\n options = plainArg1\n } else if (typeof plainArg2 === 'function') {\n options = { ...plainArg3, queryKey: plainArg1, queryFn: plainArg2 }\n } else {\n options = { ...plainArg2, queryKey: plainArg1 }\n }\n\n return cloneDeepUnref(options) as WithQueryClientKey<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n >\n}\n"],"names":["useBaseQuery","Observer","arg1","arg2","arg3","options","computed","parseQueryArgs","queryClient","value","useQueryClient","queryClientKey","defaultedOptions","defaulted","defaultQueryOptions","_optimisticResults","isRestoring","observer","state","reactive","getCurrentResult","unsubscribe","ref","watch","subscribe","result","updateState","immediate","setOptions","deep","onScopeDispose","suspense","Promise","resolve","stopWatch","run","enabled","optimisticResult","getOptimisticResult","isStale","fetchOptimistic","toRefs","readonly","plainArg1","unref","plainArg2","plainArg3","isQueryKey","queryKey","queryFn","cloneDeepUnref"],"mappings":";;;;;;;;AAyCO,SAASA,YAAT,CAMLC,QANK,EAOLC,IAPK,EAULC,IAEkE,GAAG,EAZhE,EAaLC,IAAoE,GAAG,EAblE,EAc8B;AAAA,EAAA,IAAA,qBAAA,CAAA;;AACnC,EAAA,MAAMC,OAAO,GAAGC,gBAAQ,CAAC,MAAMC,cAAc,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAArB,CAAxB,CAAA;AAEA,EAAA,MAAMI,WAAW,GAAA,CAAA,qBAAA,GACfH,OAAO,CAACI,KAAR,CAAcD,WADC,KACcE,IAAAA,GAAAA,qBAAAA,GAAAA,6BAAc,CAAC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GD,aAAK,CAACzC,IAAD,CAAvB,CAAA;AACA,EAAA,MAAM2C,SAAS,GAAGF,aAAK,CAACxC,IAAD,CAAvB,CAAA;EAEA,IAAIC,OAAO,GAAGsC,SAAd,CAAA;;AAEA,EAAA,IAAI,CAACI,gBAAU,CAACJ,SAAD,CAAf,EAA4B;AAC1BtC,IAAAA,OAAO,GAAGsC,SAAV,CAAA;AACD,GAFD,MAEO,IAAI,OAAOE,SAAP,KAAqB,UAAzB,EAAqC;IAC1CxC,OAAO,GAAG,EAAE,GAAGyC,SAAL;AAAgBE,MAAAA,QAAQ,EAAEL,SAA1B;AAAqCM,MAAAA,OAAO,EAAEJ,SAAAA;KAAxD,CAAA;AACD,GAFM,MAEA;IACLxC,OAAO,GAAG,EAAE,GAAGwC,SAAL;AAAgBG,MAAAA,QAAQ,EAAEL,SAAAA;KAApC,CAAA;AACD,GAAA;;EAED,OAAOO,oBAAc,CAAC7C,OAAD,CAArB,CAAA;AAGD;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, reactive, ref, watch, onScopeDispose, toRefs, readonly,
|
|
1
|
+
import { computed, reactive, ref, watch, onScopeDispose, toRefs, readonly, unref } from 'vue-demi';
|
|
2
2
|
import { useQueryClient } from './useQueryClient.mjs';
|
|
3
3
|
import { updateState, isQueryKey, cloneDeepUnref } from './utils.mjs';
|
|
4
4
|
|
|
@@ -68,9 +68,9 @@ function useBaseQuery(Observer, arg1, arg2 = {}, arg3 = {}) {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
function parseQueryArgs(arg1, arg2 = {}, arg3 = {}) {
|
|
71
|
-
const plainArg1 =
|
|
72
|
-
const plainArg2 =
|
|
73
|
-
const plainArg3 =
|
|
71
|
+
const plainArg1 = unref(arg1);
|
|
72
|
+
const plainArg2 = unref(arg2);
|
|
73
|
+
const plainArg3 = unref(arg3);
|
|
74
74
|
let options = plainArg1;
|
|
75
75
|
|
|
76
76
|
if (!isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.mjs","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n onScopeDispose,\n toRefs,\n readonly,\n reactive,\n watch,\n ref,\n computed,\n
|
|
1
|
+
{"version":3,"file":"useBaseQuery.mjs","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n onScopeDispose,\n toRefs,\n readonly,\n reactive,\n watch,\n ref,\n computed,\n unref,\n} from 'vue-demi'\nimport type { ToRefs, UnwrapRef } from 'vue-demi'\nimport type {\n QueryObserver,\n QueryKey,\n QueryObserverOptions,\n QueryObserverResult,\n QueryFunction,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { updateState, isQueryKey, cloneDeepUnref } from './utils'\nimport type { MaybeRef, WithQueryClientKey } from './types'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseQueryReturnType<\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 TQueryKey extends QueryKey = QueryKey,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n | UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey>\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryKey extends QueryKey,\n>(\n Observer: typeof QueryObserver,\n arg1:\n | TQueryKey\n | UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>,\n arg2:\n | QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>\n | UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},\n arg3: UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey> = {},\n): UseQueryReturnType<TData, TError> {\n const options = computed(() => parseQueryArgs(arg1, arg2, arg3))\n\n const queryClient =\n options.value.queryClient ?? useQueryClient(options.value.queryClientKey)\n\n const defaultedOptions = computed(() => {\n const defaulted = queryClient.defaultQueryOptions(options.value)\n defaulted._optimisticResults = queryClient.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(queryClient, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = ref(() => {\n // noop\n })\n\n watch(\n queryClient.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe.value()\n unsubscribe.value = 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 { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe.value()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>((resolve) => {\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 resolve(observer.fetchOptimistic(defaultedOptions.value))\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n })\n }\n\n return {\n ...(toRefs(readonly(state)) as UseQueryReturnType<TData, TError>),\n suspense,\n }\n}\n\nexport function parseQueryArgs<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1:\n | MaybeRef<TQueryKey>\n | MaybeRef<UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>>,\n arg2:\n | MaybeRef<QueryFunction<TQueryFnData, UnwrapRef<TQueryKey>>>\n | MaybeRef<\n UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>\n > = {},\n arg3: MaybeRef<\n UseQueryOptionsGeneric<TQueryFnData, TError, TData, TQueryKey>\n > = {},\n): WithQueryClientKey<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n> {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n const plainArg3 = unref(arg3)\n\n let options = plainArg1\n\n if (!isQueryKey(plainArg1)) {\n options = plainArg1\n } else if (typeof plainArg2 === 'function') {\n options = { ...plainArg3, queryKey: plainArg1, queryFn: plainArg2 }\n } else {\n options = { ...plainArg2, queryKey: plainArg1 }\n }\n\n return cloneDeepUnref(options) as WithQueryClientKey<\n QueryObserverOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n >\n}\n"],"names":["useBaseQuery","Observer","arg1","arg2","arg3","options","computed","parseQueryArgs","queryClient","value","useQueryClient","queryClientKey","defaultedOptions","defaulted","defaultQueryOptions","_optimisticResults","isRestoring","observer","state","reactive","getCurrentResult","unsubscribe","ref","watch","subscribe","result","updateState","immediate","setOptions","deep","onScopeDispose","suspense","Promise","resolve","stopWatch","run","enabled","optimisticResult","getOptimisticResult","isStale","fetchOptimistic","toRefs","readonly","plainArg1","unref","plainArg2","plainArg3","isQueryKey","queryKey","queryFn","cloneDeepUnref"],"mappings":";;;;AAyCO,SAASA,YAAT,CAMLC,QANK,EAOLC,IAPK,EAULC,IAEkE,GAAG,EAZhE,EAaLC,IAAoE,GAAG,EAblE,EAc8B;AAAA,EAAA,IAAA,qBAAA,CAAA;;AACnC,EAAA,MAAMC,OAAO,GAAGC,QAAQ,CAAC,MAAMC,cAAc,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAArB,CAAxB,CAAA;AAEA,EAAA,MAAMI,WAAW,GAAA,CAAA,qBAAA,GACfH,OAAO,CAACI,KAAR,CAAcD,WADC,KACcE,IAAAA,GAAAA,qBAAAA,GAAAA,cAAc,CAACL,OAAO,CAACI,KAAR,CAAcE,cAAf,CAD7C,CAAA;AAGA,EAA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AGF,KAAK,CAACxC,IAAD,CAAvB,CAAA;EAEA,IAAIC,OAAO,GAAGsC,SAAd,CAAA;;AAEA,EAAA,IAAI,CAACI,UAAU,CAACJ,SAAD,CAAf,EAA4B;AAC1BtC,IAAAA,OAAO,GAAGsC,SAAV,CAAA;AACD,GAFD,MAEO,IAAI,OAAOE,SAAP,KAAqB,UAAzB,EAAqC;IAC1CxC,OAAO,GAAG,EAAE,GAAGyC,SAAL;AAAgBE,MAAAA,QAAQ,EAAEL,SAA1B;AAAqCM,MAAAA,OAAO,EAAEJ,SAAAA;KAAxD,CAAA;AACD,GAFM,MAEA;IACLxC,OAAO,GAAG,EAAE,GAAGwC,SAAL;AAAgBG,MAAAA,QAAQ,EAAEL,SAAAA;KAApC,CAAA;AACD,GAAA;;EAED,OAAOO,cAAc,CAAC7C,OAAD,CAArB,CAAA;AAGD;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, ref, watch, onScopeDispose,
|
|
1
|
+
import { computed, ref, watch, onScopeDispose, unref } from 'vue-demi';
|
|
2
2
|
import { useQueryClient } from './useQueryClient.esm.js';
|
|
3
3
|
import { isQueryKey, cloneDeepUnref } from './utils.esm.js';
|
|
4
4
|
|
|
@@ -22,8 +22,8 @@ function useIsFetching(arg1, arg2) {
|
|
|
22
22
|
return isFetching;
|
|
23
23
|
}
|
|
24
24
|
function parseFilterArgs(arg1, arg2 = {}) {
|
|
25
|
-
const plainArg1 =
|
|
26
|
-
const plainArg2 =
|
|
25
|
+
const plainArg1 = unref(arg1);
|
|
26
|
+
const plainArg2 = unref(arg2);
|
|
27
27
|
let options = plainArg1;
|
|
28
28
|
|
|
29
29
|
if (isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.esm.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { computed,
|
|
1
|
+
{"version":3,"file":"useIsFetching.esm.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { computed, unref, onScopeDispose, ref, watch } from 'vue-demi'\nimport type { Ref } from 'vue-demi'\nimport type { QueryKey, QueryFilters as QF } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, isQueryKey } from './utils'\nimport type { MaybeRef, MaybeRefDeep, WithQueryClientKey } from './types'\n\nexport type QueryFilters = MaybeRefDeep<WithQueryClientKey<QF>>\n\nexport function useIsFetching(filters?: QueryFilters): Ref<number>\nexport function useIsFetching(\n queryKey?: MaybeRef<QueryKey>,\n filters?: Omit<QueryFilters, 'queryKey'>,\n): Ref<number>\nexport function useIsFetching(\n arg1?: MaybeRef<QueryKey> | QueryFilters,\n arg2?: Omit<QueryFilters, 'queryKey'>,\n): Ref<number> {\n const filters = computed(() => parseFilterArgs(arg1, arg2))\n const queryClient =\n filters.value.queryClient ?? useQueryClient(filters.value.queryClientKey)\n\n const isFetching = ref(queryClient.isFetching(filters))\n\n const unsubscribe = queryClient.getQueryCache().subscribe(() => {\n isFetching.value = queryClient.isFetching(filters)\n })\n\n watch(\n filters,\n () => {\n isFetching.value = queryClient.isFetching(filters)\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n\nexport function parseFilterArgs(\n arg1?: MaybeRef<QueryKey> | QueryFilters,\n arg2: QueryFilters = {},\n) {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n\n let options = plainArg1\n\n if (isQueryKey(plainArg1)) {\n options = { ...plainArg2, queryKey: plainArg1 }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n options = plainArg1 || {}\n }\n\n return cloneDeepUnref(options) as WithQueryClientKey<QF>\n}\n"],"names":["useIsFetching","arg1","arg2","filters","computed","parseFilterArgs","queryClient","value","useQueryClient","queryClientKey","isFetching","ref","unsubscribe","getQueryCache","subscribe","watch","deep","onScopeDispose","plainArg1","unref","plainArg2","options","isQueryKey","queryKey","cloneDeepUnref"],"mappings":";;;;AAeO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,OAAO,GAAG,EAAE,GAAGD,SAAL;AAAgBG,MAAAA,QAAQ,EAAEL,SAAAA;KAApC,CAAA;AACD,GAFD,MAEO;AACL;IACAG,OAAO,GAAGH,SAAS,IAAI,EAAvB,CAAA;AACD,GAAA;;EAED,OAAOM,cAAc,CAACH,OAAD,CAArB,CAAA;AACD;;;;"}
|
|
@@ -26,8 +26,8 @@ function useIsFetching(arg1, arg2) {
|
|
|
26
26
|
return isFetching;
|
|
27
27
|
}
|
|
28
28
|
function parseFilterArgs(arg1, arg2 = {}) {
|
|
29
|
-
const plainArg1 = vueDemi.
|
|
30
|
-
const plainArg2 = vueDemi.
|
|
29
|
+
const plainArg1 = vueDemi.unref(arg1);
|
|
30
|
+
const plainArg2 = vueDemi.unref(arg2);
|
|
31
31
|
let options = plainArg1;
|
|
32
32
|
|
|
33
33
|
if (utils.isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { computed,
|
|
1
|
+
{"version":3,"file":"useIsFetching.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { computed, unref, onScopeDispose, ref, watch } from 'vue-demi'\nimport type { Ref } from 'vue-demi'\nimport type { QueryKey, QueryFilters as QF } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, isQueryKey } from './utils'\nimport type { MaybeRef, MaybeRefDeep, WithQueryClientKey } from './types'\n\nexport type QueryFilters = MaybeRefDeep<WithQueryClientKey<QF>>\n\nexport function useIsFetching(filters?: QueryFilters): Ref<number>\nexport function useIsFetching(\n queryKey?: MaybeRef<QueryKey>,\n filters?: Omit<QueryFilters, 'queryKey'>,\n): Ref<number>\nexport function useIsFetching(\n arg1?: MaybeRef<QueryKey> | QueryFilters,\n arg2?: Omit<QueryFilters, 'queryKey'>,\n): Ref<number> {\n const filters = computed(() => parseFilterArgs(arg1, arg2))\n const queryClient =\n filters.value.queryClient ?? useQueryClient(filters.value.queryClientKey)\n\n const isFetching = ref(queryClient.isFetching(filters))\n\n const unsubscribe = queryClient.getQueryCache().subscribe(() => {\n isFetching.value = queryClient.isFetching(filters)\n })\n\n watch(\n filters,\n () => {\n isFetching.value = queryClient.isFetching(filters)\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n\nexport function parseFilterArgs(\n arg1?: MaybeRef<QueryKey> | QueryFilters,\n arg2: QueryFilters = {},\n) {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n\n let options = plainArg1\n\n if (isQueryKey(plainArg1)) {\n options = { ...plainArg2, queryKey: plainArg1 }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n options = plainArg1 || {}\n }\n\n return cloneDeepUnref(options) as WithQueryClientKey<QF>\n}\n"],"names":["useIsFetching","arg1","arg2","filters","computed","parseFilterArgs","queryClient","value","useQueryClient","queryClientKey","isFetching","ref","unsubscribe","getQueryCache","subscribe","watch","deep","onScopeDispose","plainArg1","unref","plainArg2","options","isQueryKey","queryKey","cloneDeepUnref"],"mappings":";;;;;;;;AAeO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGQ;AAAA,EAAA,IAAA,qBAAA,CAAA;;EACb,MAAMC,OAAO,GAAGC,gBAAQ,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,6BAAc,CAACL,OAAO,CAACI,KAAR,CAAcE,cAAf,CAD7C,CAAA;EAGA,MAAMC,UAAU,GAAGC,WAAG,CAACL,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAD,CAAtB,CAAA;EAEA,MAAMS,WAAW,GAAGN,WAAW,CAACO,aAAZ,EAA4BC,CAAAA,SAA5B,CAAsC,MAAM;IAC9DJ,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAFmB,CAApB,CAAA;EAIAY,aAAK,CACHZ,OADG,EAEH,MAAM;IACJO,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAJE,EAKH;AAAEa,IAAAA,IAAI,EAAE,IAAA;AAAR,GALG,CAAL,CAAA;AAQAC,EAAAA,sBAAc,CAAC,MAAM;IACnBL,WAAW,EAAA,CAAA;AACZ,GAFa,CAAd,CAAA;AAIA,EAAA,OAAOF,UAAP,CAAA;AACD,CAAA;AAEM,SAASL,eAAT,CACLJ,IADK,EAELC,IAAkB,GAAG,EAFhB,EAGL;AACA,EAAA,MAAMgB,SAAS,GAAGC,aAAK,CAAClB,IAAD,CAAvB,CAAA;AACA,EAAA,MAAMmB,SAAS,GAAGD,aAAK,CAACjB,IAAD,CAAvB,CAAA;EAEA,IAAImB,OAAO,GAAGH,SAAd,CAAA;;AAEA,EAAA,IAAII,gBAAU,CAACJ,SAAD,CAAd,EAA2B;IACzBG,OAAO,GAAG,EAAE,GAAGD,SAAL;AAAgBG,MAAAA,QAAQ,EAAEL,SAAAA;KAApC,CAAA;AACD,GAFD,MAEO;AACL;IACAG,OAAO,GAAGH,SAAS,IAAI,EAAvB,CAAA;AACD,GAAA;;EAED,OAAOM,oBAAc,CAACH,OAAD,CAArB,CAAA;AACD;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, ref, watch, onScopeDispose,
|
|
1
|
+
import { computed, ref, watch, onScopeDispose, unref } from 'vue-demi';
|
|
2
2
|
import { useQueryClient } from './useQueryClient.mjs';
|
|
3
3
|
import { isQueryKey, cloneDeepUnref } from './utils.mjs';
|
|
4
4
|
|
|
@@ -22,8 +22,8 @@ function useIsFetching(arg1, arg2) {
|
|
|
22
22
|
return isFetching;
|
|
23
23
|
}
|
|
24
24
|
function parseFilterArgs(arg1, arg2 = {}) {
|
|
25
|
-
const plainArg1 =
|
|
26
|
-
const plainArg2 =
|
|
25
|
+
const plainArg1 = unref(arg1);
|
|
26
|
+
const plainArg2 = unref(arg2);
|
|
27
27
|
let options = plainArg1;
|
|
28
28
|
|
|
29
29
|
if (isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.mjs","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { computed,
|
|
1
|
+
{"version":3,"file":"useIsFetching.mjs","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import { computed, unref, onScopeDispose, ref, watch } from 'vue-demi'\nimport type { Ref } from 'vue-demi'\nimport type { QueryKey, QueryFilters as QF } from '@tanstack/query-core'\n\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, isQueryKey } from './utils'\nimport type { MaybeRef, MaybeRefDeep, WithQueryClientKey } from './types'\n\nexport type QueryFilters = MaybeRefDeep<WithQueryClientKey<QF>>\n\nexport function useIsFetching(filters?: QueryFilters): Ref<number>\nexport function useIsFetching(\n queryKey?: MaybeRef<QueryKey>,\n filters?: Omit<QueryFilters, 'queryKey'>,\n): Ref<number>\nexport function useIsFetching(\n arg1?: MaybeRef<QueryKey> | QueryFilters,\n arg2?: Omit<QueryFilters, 'queryKey'>,\n): Ref<number> {\n const filters = computed(() => parseFilterArgs(arg1, arg2))\n const queryClient =\n filters.value.queryClient ?? useQueryClient(filters.value.queryClientKey)\n\n const isFetching = ref(queryClient.isFetching(filters))\n\n const unsubscribe = queryClient.getQueryCache().subscribe(() => {\n isFetching.value = queryClient.isFetching(filters)\n })\n\n watch(\n filters,\n () => {\n isFetching.value = queryClient.isFetching(filters)\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n return isFetching\n}\n\nexport function parseFilterArgs(\n arg1?: MaybeRef<QueryKey> | QueryFilters,\n arg2: QueryFilters = {},\n) {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n\n let options = plainArg1\n\n if (isQueryKey(plainArg1)) {\n options = { ...plainArg2, queryKey: plainArg1 }\n } else {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n options = plainArg1 || {}\n }\n\n return cloneDeepUnref(options) as WithQueryClientKey<QF>\n}\n"],"names":["useIsFetching","arg1","arg2","filters","computed","parseFilterArgs","queryClient","value","useQueryClient","queryClientKey","isFetching","ref","unsubscribe","getQueryCache","subscribe","watch","deep","onScopeDispose","plainArg1","unref","plainArg2","options","isQueryKey","queryKey","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,cAAc,CAACL,OAAO,CAACI,KAAR,CAAcE,cAAf,CAD7C,CAAA;EAGA,MAAMC,UAAU,GAAGC,GAAG,CAACL,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAD,CAAtB,CAAA;EAEA,MAAMS,WAAW,GAAGN,WAAW,CAACO,aAAZ,EAA4BC,CAAAA,SAA5B,CAAsC,MAAM;IAC9DJ,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAFmB,CAApB,CAAA;EAIAY,KAAK,CACHZ,OADG,EAEH,MAAM;IACJO,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAJE,EAKH;AAAEa,IAAAA,IAAI,EAAE,IAAA;AAAR,GALG,CAAL,CAAA;AAQAC,EAAAA,cAAc,CAAC,MAAM;IACnBL,WAAW,EAAA,CAAA;AACZ,GAFa,CAAd,CAAA;AAIA,EAAA,OAAOF,UAAP,CAAA;AACD,CAAA;AAEM,SAASL,eAAT,CACLJ,IADK,EAELC,IAAkB,GAAG,EAFhB,EAGL;AACA,EAAA,MAAMgB,SAAS,GAAGC,KAAK,CAAClB,IAAD,CAAvB,CAAA;AACA,EAAA,MAAMmB,SAAS,GAAGD,KAAK,CAACjB,IAAD,CAAvB,CAAA;EAEA,IAAImB,OAAO,GAAGH,SAAd,CAAA;;AAEA,EAAA,IAAII,UAAU,CAACJ,SAAD,CAAd,EAA2B;IACzBG,OAAO,GAAG,EAAE,GAAGD,SAAL;AAAgBG,MAAAA,QAAQ,EAAEL,SAAAA;KAApC,CAAA;AACD,GAFD,MAEO;AACL;IACAG,OAAO,GAAGH,SAAS,IAAI,EAAvB,CAAA;AACD,GAAA;;EAED,OAAOM,cAAc,CAACH,OAAD,CAArB,CAAA;AACD;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, ref, watch, onScopeDispose,
|
|
1
|
+
import { computed, ref, watch, onScopeDispose, unref } from 'vue-demi';
|
|
2
2
|
import { useQueryClient } from './useQueryClient.esm.js';
|
|
3
3
|
import { isQueryKey, cloneDeepUnref } from './utils.esm.js';
|
|
4
4
|
|
|
@@ -22,8 +22,8 @@ function useIsMutating(arg1, arg2) {
|
|
|
22
22
|
return isMutating;
|
|
23
23
|
}
|
|
24
24
|
function parseFilterArgs(arg1, arg2 = {}) {
|
|
25
|
-
const plainArg1 =
|
|
26
|
-
const plainArg2 =
|
|
25
|
+
const plainArg1 = unref(arg1);
|
|
26
|
+
const plainArg2 = unref(arg2);
|
|
27
27
|
let options = plainArg1;
|
|
28
28
|
|
|
29
29
|
if (isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsMutating.esm.js","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { computed,
|
|
1
|
+
{"version":3,"file":"useIsMutating.esm.js","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { computed, unref, 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 = unref(arg1)\n const plainArg2 = unref(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","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AGH,SAAd,CAAA;;AAEA,EAAA,IAAII,UAAU,CAACJ,SAAD,CAAd,EAA2B;IACzBG,OAAO,GAAG,EAAE,GAAGD,SAAL;AAAgBG,MAAAA,WAAW,EAAEL,SAAAA;KAAvC,CAAA;AACD,GAFD,MAEO;AACL;IACAG,OAAO,GAAGH,SAAS,IAAI,EAAvB,CAAA;AACD,GAAA;;EAED,OAAOM,cAAc,CAACH,OAAD,CAArB,CAAA;AACD;;;;"}
|
|
@@ -26,8 +26,8 @@ function useIsMutating(arg1, arg2) {
|
|
|
26
26
|
return isMutating;
|
|
27
27
|
}
|
|
28
28
|
function parseFilterArgs(arg1, arg2 = {}) {
|
|
29
|
-
const plainArg1 = vueDemi.
|
|
30
|
-
const plainArg2 = vueDemi.
|
|
29
|
+
const plainArg1 = vueDemi.unref(arg1);
|
|
30
|
+
const plainArg2 = vueDemi.unref(arg2);
|
|
31
31
|
let options = plainArg1;
|
|
32
32
|
|
|
33
33
|
if (utils.isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsMutating.js","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { computed,
|
|
1
|
+
{"version":3,"file":"useIsMutating.js","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { computed, unref, 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 = unref(arg1)\n const plainArg2 = unref(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","unref","plainArg2","options","isQueryKey","mutationKey","cloneDeepUnref"],"mappings":";;;;;;;;AAeO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGQ;AAAA,EAAA,IAAA,qBAAA,CAAA;;EACb,MAAMC,OAAO,GAAGC,gBAAQ,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,6BAAc,CAACL,OAAO,CAACI,KAAR,CAAcE,cAAf,CAD7C,CAAA;EAGA,MAAMC,UAAU,GAAGC,WAAG,CAACL,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAD,CAAtB,CAAA;EAEA,MAAMS,WAAW,GAAGN,WAAW,CAACO,gBAAZ,EAA+BC,CAAAA,SAA/B,CAAyC,MAAM;IACjEJ,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAFmB,CAApB,CAAA;EAIAY,aAAK,CACHZ,OADG,EAEH,MAAM;IACJO,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAJE,EAKH;AAAEa,IAAAA,IAAI,EAAE,IAAA;AAAR,GALG,CAAL,CAAA;AAQAC,EAAAA,sBAAc,CAAC,MAAM;IACnBL,WAAW,EAAA,CAAA;AACZ,GAFa,CAAd,CAAA;AAIA,EAAA,OAAOF,UAAP,CAAA;AACD,CAAA;AAEM,SAASL,eAAT,CACLJ,IADK,EAELC,IAAqB,GAAG,EAFnB,EAGL;AACA,EAAA,MAAMgB,SAAS,GAAGC,aAAK,CAAClB,IAAD,CAAvB,CAAA;AACA,EAAA,MAAMmB,SAAS,GAAGD,aAAK,CAACjB,IAAD,CAAvB,CAAA;EAEA,IAAImB,OAAO,GAAGH,SAAd,CAAA;;AAEA,EAAA,IAAII,gBAAU,CAACJ,SAAD,CAAd,EAA2B;IACzBG,OAAO,GAAG,EAAE,GAAGD,SAAL;AAAgBG,MAAAA,WAAW,EAAEL,SAAAA;KAAvC,CAAA;AACD,GAFD,MAEO;AACL;IACAG,OAAO,GAAGH,SAAS,IAAI,EAAvB,CAAA;AACD,GAAA;;EAED,OAAOM,oBAAc,CAACH,OAAD,CAArB,CAAA;AACD;;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, ref, watch, onScopeDispose,
|
|
1
|
+
import { computed, ref, watch, onScopeDispose, unref } from 'vue-demi';
|
|
2
2
|
import { useQueryClient } from './useQueryClient.mjs';
|
|
3
3
|
import { isQueryKey, cloneDeepUnref } from './utils.mjs';
|
|
4
4
|
|
|
@@ -22,8 +22,8 @@ function useIsMutating(arg1, arg2) {
|
|
|
22
22
|
return isMutating;
|
|
23
23
|
}
|
|
24
24
|
function parseFilterArgs(arg1, arg2 = {}) {
|
|
25
|
-
const plainArg1 =
|
|
26
|
-
const plainArg2 =
|
|
25
|
+
const plainArg1 = unref(arg1);
|
|
26
|
+
const plainArg2 = unref(arg2);
|
|
27
27
|
let options = plainArg1;
|
|
28
28
|
|
|
29
29
|
if (isQueryKey(plainArg1)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useIsMutating.mjs","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { computed,
|
|
1
|
+
{"version":3,"file":"useIsMutating.mjs","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import { computed, unref, 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 = unref(arg1)\n const plainArg2 = unref(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","unref","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,cAAc,CAACL,OAAO,CAACI,KAAR,CAAcE,cAAf,CAD7C,CAAA;EAGA,MAAMC,UAAU,GAAGC,GAAG,CAACL,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAD,CAAtB,CAAA;EAEA,MAAMS,WAAW,GAAGN,WAAW,CAACO,gBAAZ,EAA+BC,CAAAA,SAA/B,CAAyC,MAAM;IACjEJ,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAFmB,CAApB,CAAA;EAIAY,KAAK,CACHZ,OADG,EAEH,MAAM;IACJO,UAAU,CAACH,KAAX,GAAmBD,WAAW,CAACI,UAAZ,CAAuBP,OAAvB,CAAnB,CAAA;AACD,GAJE,EAKH;AAAEa,IAAAA,IAAI,EAAE,IAAA;AAAR,GALG,CAAL,CAAA;AAQAC,EAAAA,cAAc,CAAC,MAAM;IACnBL,WAAW,EAAA,CAAA;AACZ,GAFa,CAAd,CAAA;AAIA,EAAA,OAAOF,UAAP,CAAA;AACD,CAAA;AAEM,SAASL,eAAT,CACLJ,IADK,EAELC,IAAqB,GAAG,EAFnB,EAGL;AACA,EAAA,MAAMgB,SAAS,GAAGC,KAAK,CAAClB,IAAD,CAAvB,CAAA;AACA,EAAA,MAAMmB,SAAS,GAAGD,KAAK,CAACjB,IAAD,CAAvB,CAAA;EAEA,IAAImB,OAAO,GAAGH,SAAd,CAAA;;AAEA,EAAA,IAAII,UAAU,CAACJ,SAAD,CAAd,EAA2B;IACzBG,OAAO,GAAG,EAAE,GAAGD,SAAL;AAAgBG,MAAAA,WAAW,EAAEL,SAAAA;KAAvC,CAAA;AACD,GAFD,MAEO;AACL;IACAG,OAAO,GAAGH,SAAS,IAAI,EAAvB,CAAA;AACD,GAAA;;EAED,OAAOM,cAAc,CAACH,OAAD,CAArB,CAAA;AACD;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { computed, reactive, watch, onScopeDispose, toRefs, readonly,
|
|
1
|
+
import { computed, reactive, watch, onScopeDispose, toRefs, readonly, unref } from 'vue-demi';
|
|
2
2
|
import { MutationObserver } from '@tanstack/query-core';
|
|
3
3
|
import { updateState, isMutationKey, cloneDeepUnref } from './utils.esm.js';
|
|
4
4
|
import { useQueryClient } from './useQueryClient.esm.js';
|
|
@@ -37,13 +37,13 @@ function useMutation(arg1, arg2, arg3) {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
function parseMutationArgs(arg1, arg2, arg3) {
|
|
40
|
-
const plainArg1 =
|
|
41
|
-
const plainArg2 =
|
|
40
|
+
const plainArg1 = unref(arg1);
|
|
41
|
+
const plainArg2 = unref(arg2);
|
|
42
42
|
let options = plainArg1;
|
|
43
43
|
|
|
44
44
|
if (isMutationKey(plainArg1)) {
|
|
45
45
|
if (typeof plainArg2 === 'function') {
|
|
46
|
-
const plainArg3 =
|
|
46
|
+
const plainArg3 = unref(arg3);
|
|
47
47
|
options = { ...plainArg3,
|
|
48
48
|
mutationKey: plainArg1,
|
|
49
49
|
mutationFn: plainArg2
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.esm.js","sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n computed,\n
|
|
1
|
+
{"version":3,"file":"useMutation.esm.js","sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n computed,\n unref,\n} from 'vue-demi'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n MutateOptions,\n MutationFunction,\n MutationKey,\n MutateFunction,\n MutationObserverResult,\n MutationObserverOptions,\n} from '@tanstack/query-core'\nimport type {\n WithQueryClientKey,\n MaybeRef,\n MaybeRefDeep,\n DistributiveOmit,\n} from './types'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState, isMutationKey } from './utils'\nimport { useQueryClient } from './useQueryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<TData, TError, TVariables, TContext> =\n WithQueryClientKey<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >\n\nexport type VueMutationObserverOptions<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n> = {\n [Property in keyof UseMutationOptions<\n TData,\n TError,\n TVariables,\n TContext\n >]: MaybeRefDeep<\n UseMutationOptions<TData, TError, TVariables, TContext>[Property]\n >\n}\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = unknown,\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 = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n options: MaybeRef<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationFn: MaybeRef<MutationFunction<TData, TVariables>>,\n options?: MaybeRef<\n Omit<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>,\n 'mutationFn'\n >\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MaybeRef<MutationKey>,\n options?: MaybeRef<\n Omit<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>,\n 'mutationKey'\n >\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MaybeRef<MutationKey>,\n mutationFn?: MaybeRef<MutationFunction<TData, TVariables>>,\n options?: MaybeRef<\n Omit<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>,\n 'mutationKey' | 'mutationFn'\n >\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n arg1:\n | MaybeRef<MutationKey>\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg2?:\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg3?: MaybeRef<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const options = computed(() => {\n return parseMutationArgs(arg1, arg2, arg3)\n })\n const queryClient =\n options.value.queryClient ?? useQueryClient(options.value.queryClientKey)\n const observer = new MutationObserver(\n queryClient,\n queryClient.defaultMutationOptions(options.value),\n )\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(queryClient.defaultMutationOptions(options.value))\n },\n { deep: true },\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 return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n\nexport function parseMutationArgs<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n arg1:\n | MaybeRef<MutationKey>\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg2?:\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg3?: MaybeRef<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n): WithQueryClientKey<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n> {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n let options = plainArg1\n if (isMutationKey(plainArg1)) {\n if (typeof plainArg2 === 'function') {\n const plainArg3 = unref(arg3)\n options = { ...plainArg3, mutationKey: plainArg1, mutationFn: plainArg2 }\n } else {\n options = { ...plainArg2, mutationKey: plainArg1 }\n }\n }\n\n if (typeof plainArg1 === 'function') {\n options = { ...plainArg2, mutationFn: plainArg1 }\n }\n\n return cloneDeepUnref(options) as UseMutationOptions<\n TData,\n TError,\n TVariables,\n TContext\n >\n}\n"],"names":["useMutation","arg1","arg2","arg3","options","computed","parseMutationArgs","queryClient","value","useQueryClient","queryClientKey","observer","MutationObserver","defaultMutationOptions","state","reactive","getCurrentResult","unsubscribe","subscribe","result","updateState","mutate","variables","mutateOptions","catch","watch","setOptions","deep","onScopeDispose","resultRefs","toRefs","readonly","mutateAsync","reset","plainArg1","unref","plainArg2","isMutationKey","plainArg3","mutationKey","mutationFn","cloneDeepUnref"],"mappings":";;;;;AAgIO,SAASA,WAAT,CAMLC,IANK,EAULC,IAVK,EAaLC,IAbK,EAgBuD;AAAA,EAAA,IAAA,qBAAA,CAAA;;AAC5D,EAAA,MAAMC,OAAO,GAAGC,QAAQ,CAAC,MAAM;AAC7B,IAAA,OAAOC,iBAAiB,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAAxB,CAAA;AACD,GAFuB,CAAxB,CAAA;AAGA,EAAA,MAAMI,WAAW,GAAA,CAAA,qBAAA,GACfH,OAAO,CAACI,KAAR,CAAcD,WADC,KACcE,IAAAA,GAAAA,qBAAAA,GAAAA,cAAc,CAACL,OAAO,CAACI,KAAR,CAAcE,cAAf,CAD7C,CAAA;AAEA,EAAA,MAAMC,QAAQ,GAAG,IAAIC,gBAAJ,CACfL,WADe,EAEfA,WAAW,CAACM,sBAAZ,CAAmCT,OAAO,CAACI,KAA3C,CAFe,CAAjB,CAAA;EAIA,MAAMM,KAAK,GAAGC,QAAQ,CAACJ,QAAQ,CAACK,gBAAT,EAAD,CAAtB,CAAA;AAEA,EAAA,MAAMC,WAAW,GAAGN,QAAQ,CAACO,SAAT,CAAoBC,MAAD,IAAY;AACjDC,IAAAA,WAAW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AEL,SAA7B;AAAwCM,QAAAA,UAAU,EAAEJ,SAAAA;OAA9D,CAAA;AACD,KAHD,MAGO;MACLhC,OAAO,GAAG,EAAE,GAAGgC,SAAL;AAAgBG,QAAAA,WAAW,EAAEL,SAAAA;OAAvC,CAAA;AACD,KAAA;AACF,GAAA;;AAED,EAAA,IAAI,OAAOA,SAAP,KAAqB,UAAzB,EAAqC;IACnC9B,OAAO,GAAG,EAAE,GAAGgC,SAAL;AAAgBI,MAAAA,UAAU,EAAEN,SAAAA;KAAtC,CAAA;AACD,GAAA;;EAED,OAAOO,cAAc,CAACrC,OAAD,CAArB,CAAA;AAMD;;;;"}
|
package/build/lib/useMutation.js
CHANGED
|
@@ -41,13 +41,13 @@ function useMutation(arg1, arg2, arg3) {
|
|
|
41
41
|
};
|
|
42
42
|
}
|
|
43
43
|
function parseMutationArgs(arg1, arg2, arg3) {
|
|
44
|
-
const plainArg1 = vueDemi.
|
|
45
|
-
const plainArg2 = vueDemi.
|
|
44
|
+
const plainArg1 = vueDemi.unref(arg1);
|
|
45
|
+
const plainArg2 = vueDemi.unref(arg2);
|
|
46
46
|
let options = plainArg1;
|
|
47
47
|
|
|
48
48
|
if (utils.isMutationKey(plainArg1)) {
|
|
49
49
|
if (typeof plainArg2 === 'function') {
|
|
50
|
-
const plainArg3 = vueDemi.
|
|
50
|
+
const plainArg3 = vueDemi.unref(arg3);
|
|
51
51
|
options = { ...plainArg3,
|
|
52
52
|
mutationKey: plainArg1,
|
|
53
53
|
mutationFn: plainArg2
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.js","sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n computed,\n
|
|
1
|
+
{"version":3,"file":"useMutation.js","sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n computed,\n unref,\n} from 'vue-demi'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n MutateOptions,\n MutationFunction,\n MutationKey,\n MutateFunction,\n MutationObserverResult,\n MutationObserverOptions,\n} from '@tanstack/query-core'\nimport type {\n WithQueryClientKey,\n MaybeRef,\n MaybeRefDeep,\n DistributiveOmit,\n} from './types'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState, isMutationKey } from './utils'\nimport { useQueryClient } from './useQueryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<TData, TError, TVariables, TContext> =\n WithQueryClientKey<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >\n\nexport type VueMutationObserverOptions<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n> = {\n [Property in keyof UseMutationOptions<\n TData,\n TError,\n TVariables,\n TContext\n >]: MaybeRefDeep<\n UseMutationOptions<TData, TError, TVariables, TContext>[Property]\n >\n}\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = unknown,\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 = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n options: MaybeRef<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationFn: MaybeRef<MutationFunction<TData, TVariables>>,\n options?: MaybeRef<\n Omit<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>,\n 'mutationFn'\n >\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MaybeRef<MutationKey>,\n options?: MaybeRef<\n Omit<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>,\n 'mutationKey'\n >\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MaybeRef<MutationKey>,\n mutationFn?: MaybeRef<MutationFunction<TData, TVariables>>,\n options?: MaybeRef<\n Omit<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>,\n 'mutationKey' | 'mutationFn'\n >\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n arg1:\n | MaybeRef<MutationKey>\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg2?:\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg3?: MaybeRef<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const options = computed(() => {\n return parseMutationArgs(arg1, arg2, arg3)\n })\n const queryClient =\n options.value.queryClient ?? useQueryClient(options.value.queryClientKey)\n const observer = new MutationObserver(\n queryClient,\n queryClient.defaultMutationOptions(options.value),\n )\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(queryClient.defaultMutationOptions(options.value))\n },\n { deep: true },\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 return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n\nexport function parseMutationArgs<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n arg1:\n | MaybeRef<MutationKey>\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg2?:\n | MaybeRef<MutationFunction<TData, TVariables>>\n | MaybeRef<VueMutationObserverOptions<TData, TError, TVariables, TContext>>,\n arg3?: MaybeRef<\n VueMutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n): WithQueryClientKey<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n> {\n const plainArg1 = unref(arg1)\n const plainArg2 = unref(arg2)\n let options = plainArg1\n if (isMutationKey(plainArg1)) {\n if (typeof plainArg2 === 'function') {\n const plainArg3 = unref(arg3)\n options = { ...plainArg3, mutationKey: plainArg1, mutationFn: plainArg2 }\n } else {\n options = { ...plainArg2, mutationKey: plainArg1 }\n }\n }\n\n if (typeof plainArg1 === 'function') {\n options = { ...plainArg2, mutationFn: plainArg1 }\n }\n\n return cloneDeepUnref(options) as UseMutationOptions<\n TData,\n TError,\n TVariables,\n TContext\n >\n}\n"],"names":["useMutation","arg1","arg2","arg3","options","computed","parseMutationArgs","queryClient","value","useQueryClient","queryClientKey","observer","MutationObserver","defaultMutationOptions","state","reactive","getCurrentResult","unsubscribe","subscribe","result","updateState","mutate","variables","mutateOptions","catch","watch","setOptions","deep","onScopeDispose","resultRefs","toRefs","readonly","mutateAsync","reset","plainArg1","unref","plainArg2","isMutationKey","plainArg3","mutationKey","mutationFn","cloneDeepUnref"],"mappings":";;;;;;;;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
+
import { computed, reactive, watch, onScopeDispose, toRefs, readonly, unref } from 'vue-demi';
|
|
2
2
|
import { MutationObserver } from '@tanstack/query-core';
|
|
3
3
|
import { updateState, isMutationKey, cloneDeepUnref } from './utils.mjs';
|
|
4
4
|
import { useQueryClient } from './useQueryClient.mjs';
|
|
@@ -37,13 +37,13 @@ function useMutation(arg1, arg2, arg3) {
|
|
|
37
37
|
};
|
|
38
38
|
}
|
|
39
39
|
function parseMutationArgs(arg1, arg2, arg3) {
|
|
40
|
-
const plainArg1 =
|
|
41
|
-
const plainArg2 =
|
|
40
|
+
const plainArg1 = unref(arg1);
|
|
41
|
+
const plainArg2 = unref(arg2);
|
|
42
42
|
let options = plainArg1;
|
|
43
43
|
|
|
44
44
|
if (isMutationKey(plainArg1)) {
|
|
45
45
|
if (typeof plainArg2 === 'function') {
|
|
46
|
-
const plainArg3 =
|
|
46
|
+
const plainArg3 = unref(arg3);
|
|
47
47
|
options = { ...plainArg3,
|
|
48
48
|
mutationKey: plainArg1,
|
|
49
49
|
mutationFn: plainArg2
|