@tanstack/vue-query 5.75.5 → 5.75.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/legacy/useBaseQuery.cjs +3 -2
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.js +2 -1
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useMutation.cjs +1 -1
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.js +2 -2
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/utils.cjs +0 -8
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +1 -2
- package/build/legacy/utils.d.ts +1 -2
- package/build/legacy/utils.js +0 -7
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/useBaseQuery.cjs +3 -2
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.js +2 -1
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useMutation.cjs +1 -1
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.js +2 -2
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/utils.cjs +0 -8
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +1 -2
- package/build/modern/utils.d.ts +1 -2
- package/build/modern/utils.js +0 -7
- package/build/modern/utils.js.map +1 -1
- package/package.json +4 -3
- package/src/useBaseQuery.ts +2 -1
- package/src/useMutation.ts +2 -2
- package/src/utils.ts +0 -12
|
@@ -24,6 +24,7 @@ __export(useBaseQuery_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(useBaseQuery_exports);
|
|
26
26
|
var import_vue_demi = require("vue-demi");
|
|
27
|
+
var import_query_core = require("@tanstack/query-core");
|
|
27
28
|
var import_useQueryClient = require("./useQueryClient.cjs");
|
|
28
29
|
var import_utils = require("./utils.cjs");
|
|
29
30
|
function useBaseQuery(Observer, options, queryClient) {
|
|
@@ -86,7 +87,7 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
86
87
|
if (optimisticResult.isStale) {
|
|
87
88
|
stopWatch();
|
|
88
89
|
observer.fetchOptimistic(defaultedOptions.value).then(resolve, (error) => {
|
|
89
|
-
if ((0,
|
|
90
|
+
if ((0, import_query_core.shouldThrowError)(defaultedOptions.value.throwOnError, [
|
|
90
91
|
error,
|
|
91
92
|
observer.getCurrentQuery()
|
|
92
93
|
])) {
|
|
@@ -109,7 +110,7 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
109
110
|
(0, import_vue_demi.watch)(
|
|
110
111
|
() => state.error,
|
|
111
112
|
(error) => {
|
|
112
|
-
if (state.isError && !state.isFetching && (0,
|
|
113
|
+
if (state.isError && !state.isFetching && (0, import_query_core.shouldThrowError)(defaultedOptions.value.throwOnError, [
|
|
113
114
|
error,
|
|
114
115
|
observer.getCurrentQuery()
|
|
115
116
|
])) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | 'refetch'\n ? TResult[K]\n : Ref<Readonly<TResult>[K]>\n} & {\n suspense: () => Promise<TResult>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const clonedOptions = cloneDeepUnref(options as any)\n\n if (typeof clonedOptions.enabled === 'function') {\n clonedOptions.enabled = clonedOptions.enabled()\n }\n\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(clonedOptions)\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n // @ts-expect-error\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910\n const refetch = (...args: Parameters<(typeof state)['refetch']>) => {\n updater()\n return state.refetch(...args)\n }\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, (error: TError) => {\n if (\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error,\n observer.getCurrentQuery(),\n ])\n ) {\n reject(error)\n } else {\n resolve(observer.getCurrentResult())\n }\n })\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n // @ts-expect-error\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const object: any = toRefs(readonlyState)\n for (const key in state) {\n if (typeof state[key as keyof typeof state] === 'function') {\n object[key] = state[key as keyof typeof state]\n }\n }\n\n object.suspense = suspense\n object.refetch = refetch\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AA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AAW;AAClB,SAAO,UAAU;AAEjB,SAAO;AACT;","names":[]}
|
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
toRefs,
|
|
11
11
|
watch
|
|
12
12
|
} from "vue-demi";
|
|
13
|
+
import { shouldThrowError } from "@tanstack/query-core";
|
|
13
14
|
import { useQueryClient } from "./useQueryClient.js";
|
|
14
|
-
import { cloneDeepUnref,
|
|
15
|
+
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
15
16
|
function useBaseQuery(Observer, options, queryClient) {
|
|
16
17
|
if (process.env.NODE_ENV === "development") {
|
|
17
18
|
if (!getCurrentScope()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | 'refetch'\n ? TResult[K]\n : Ref<Readonly<TResult>[K]>\n} & {\n suspense: () => Promise<TResult>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const clonedOptions = cloneDeepUnref(options as any)\n\n if (typeof clonedOptions.enabled === 'function') {\n clonedOptions.enabled = clonedOptions.enabled()\n }\n\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(clonedOptions)\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n // @ts-expect-error\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910\n const refetch = (...args: Parameters<(typeof state)['refetch']>) => {\n updater()\n return state.refetch(...args)\n }\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, (error: TError) => {\n if (\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error,\n observer.getCurrentQuery(),\n ])\n ) {\n reject(error)\n } else {\n resolve(observer.getCurrentResult())\n }\n })\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n // @ts-expect-error\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const object: any = toRefs(readonlyState)\n for (const key in state) {\n if (typeof state[key as keyof typeof state] === 'function') {\n object[key] = state[key as keyof typeof state]\n }\n }\n\n object.suspense = suspense\n object.refetch = refetch\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,mBAAmB;AA6CrC,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,MAAI,QA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
() => state.error,
|
|
61
61
|
(error) => {
|
|
62
|
-
if (error && (0,
|
|
62
|
+
if (error && (0, import_query_core.shouldThrowError)(options.value.throwOnError, [error])) {
|
|
63
63
|
throw error;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\ntype UseMutationOptionsBase<TData, TError, TVariables, TContext> =\n MutationObserverOptions<TData, TError, TVariables, TContext> & {\n /**\n * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.\n */\n shallow?: boolean\n }\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<UseMutationOptionsBase<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n TResult = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n UseMutationOptionsBase<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = options.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(options, () => {\n observer.setOptions(options.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = options.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TContext>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(options.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRef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G;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
toRefs,
|
|
11
11
|
watch
|
|
12
12
|
} from "vue-demi";
|
|
13
|
-
import { MutationObserver } from "@tanstack/query-core";
|
|
14
|
-
import { cloneDeepUnref,
|
|
13
|
+
import { MutationObserver, shouldThrowError } from "@tanstack/query-core";
|
|
14
|
+
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
15
15
|
import { useQueryClient } from "./useQueryClient.js";
|
|
16
16
|
function useMutation(mutationOptions, queryClient) {
|
|
17
17
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\ntype UseMutationOptionsBase<TData, TError, TVariables, TContext> =\n MutationObserverOptions<TData, TError, TVariables, TContext> & {\n /**\n * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.\n */\n shallow?: boolean\n }\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<UseMutationOptionsBase<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n TResult = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n UseMutationOptionsBase<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = options.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(options, () => {\n observer.setOptions(options.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = options.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TContext>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(options.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,wBAAwB;AACnD,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,sBAAsB;AAsDxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,gBAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,eAAe,eAAe;AAC7C,QAAM,UAAU,SAAS,MAAM;AAC7B,WAAO,OAAO,uBAAuB,eAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,iBAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,QAAQ,QAAQ,MAAM,UACxB,gBAAgB,SAAS,iBAAiB,CAAC,IAC3C,SAAS,SAAS,iBAAiB,CAAC;AAExC,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,gBAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,MAAM;AACnB,aAAS,WAAW,QAAQ,KAAK;AAAA,EACnC,CAAC;AAED,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,gBAAgB,QAAQ,MAAM,UAChC,gBAAgB,KAAK,IACrB,SAAS,KAAK;AAElB,QAAM,aAAa,OAAO,aAAa;AAIvC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,SACA,iBAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
package/build/legacy/utils.cjs
CHANGED
|
@@ -24,7 +24,6 @@ __export(utils_exports, {
|
|
|
24
24
|
cloneDeep: () => cloneDeep,
|
|
25
25
|
cloneDeepUnref: () => cloneDeepUnref,
|
|
26
26
|
getClientKey: () => getClientKey,
|
|
27
|
-
shouldThrowError: () => shouldThrowError,
|
|
28
27
|
updateState: () => updateState
|
|
29
28
|
});
|
|
30
29
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -90,19 +89,12 @@ function isPlainObject(value) {
|
|
|
90
89
|
function isFunction(value) {
|
|
91
90
|
return typeof value === "function";
|
|
92
91
|
}
|
|
93
|
-
function shouldThrowError(throwOnError, params) {
|
|
94
|
-
if (typeof throwOnError === "function") {
|
|
95
|
-
return throwOnError(...params);
|
|
96
|
-
}
|
|
97
|
-
return !!throwOnError;
|
|
98
|
-
}
|
|
99
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
93
|
0 && (module.exports = {
|
|
101
94
|
VUE_QUERY_CLIENT,
|
|
102
95
|
cloneDeep,
|
|
103
96
|
cloneDeepUnref,
|
|
104
97
|
getClientKey,
|
|
105
|
-
shouldThrowError,
|
|
106
98
|
updateState
|
|
107
99
|
});
|
|
108
100
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA6B;AAGtB,IAAM,mBAAmB;AAEzB,SAAS,aAAa,KAAc;AACzC,QAAM,SAAS,MAAM,IAAI,GAAG,KAAK;AACjC,SAAO,GAAG,gBAAgB,GAAG,MAAM;AACrC;AAEO,SAAS,YACd,OACA,QACM;AACN,SAAO,KAAK,KAAK,EAAE,QAAQ,CAAC,QAAQ;AAClC,UAAM,GAAG,IAAI,OAAO,GAAG;AAAA,EACzB,CAAC;AACH;AAIA,SAAS,WACP,OACA,WAKA,aAAqB,IACrB,eAAuB,GACpB;AACH,MAAI,WAAW;AACb,UAAM,SAAS,UAAU,OAAO,YAAY,YAAY;AACxD,QAAI,WAAW,cAAa,uBAAM,KAAK,GAAG;AACxC,aAAO;AAAA,IACT;AACA,QAAI,WAAW,QAAW;AACxB,aAAO;AAAA,IACT;AAAA,EACF;AAEA,MAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,WAAO,MAAM;AAAA,MAAI,CAAC,KAAK,UACrB,WAAW,KAAK,WAAW,OAAO,KAAK,GAAG,eAAe,CAAC;AAAA,IAC5D;AAAA,EACF;AAEA,MAAI,OAAO,UAAU,YAAY,cAAc,KAAK,GAAG;AACrD,UAAM,UAAU,OAAO,QAAQ,KAAK,EAAE,IAAI,CAAC,CAAC,KAAK,GAAG,MAAM;AAAA,MACxD;AAAA,MACA,WAAW,KAAK,WAAW,KAAK,eAAe,CAAC;AAAA,IAClD,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,UACd,OACA,WAKG;AACH,SAAO,WAAW,OAAO,SAAS;AACpC;AAEO,SAAS,eACd,KACA,eAAe,OACZ;AACH,SAAO,UAAU,KAAK,CAAC,KAAK,KAAK,UAAU;AAKzC,QAAI,UAAU,KAAK,QAAQ,YAAY;AACrC,aAAO,eAAe,KAAK,IAAI;AAAA,IACjC;AAGA,QAAI,gBAAgB,WAAW,GAAG,GAAG;AAGnC,aAAO,eAAgB,IAAiB,GAAG,YAAY;AAAA,IACzD;AAGA,YAAI,uBAAM,GAAG,GAAG;AACd,aAAO,mBAAe,uBAAM,GAAG,GAAG,YAAY;AAAA,IAChD;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAGA,SAAS,cAAc,OAAiC;AACtD,MAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,mBAAmB;AAC/D,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,SAAO,cAAc,QAAQ,cAAc,OAAO;AACpD;AAEA,SAAS,WAAW,OAAmC;AACrD,SAAO,OAAO,UAAU;AAC1B;","names":[]}
|
package/build/legacy/utils.d.cts
CHANGED
|
@@ -7,6 +7,5 @@ declare function getClientKey(key?: string): string;
|
|
|
7
7
|
declare function updateState(state: Record<string, any>, update: Record<string, any>): void;
|
|
8
8
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customize?: (val: MaybeRefDeep<T>, key: string, level: number) => T | undefined): T;
|
|
9
9
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>, unrefGetters?: boolean): T;
|
|
10
|
-
declare function shouldThrowError<T extends (...args: Array<any>) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
11
10
|
|
|
12
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey,
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
package/build/legacy/utils.d.ts
CHANGED
|
@@ -7,6 +7,5 @@ declare function getClientKey(key?: string): string;
|
|
|
7
7
|
declare function updateState(state: Record<string, any>, update: Record<string, any>): void;
|
|
8
8
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customize?: (val: MaybeRefDeep<T>, key: string, level: number) => T | undefined): T;
|
|
9
9
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>, unrefGetters?: boolean): T;
|
|
10
|
-
declare function shouldThrowError<T extends (...args: Array<any>) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
11
10
|
|
|
12
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey,
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
package/build/legacy/utils.js
CHANGED
|
@@ -61,18 +61,11 @@ function isPlainObject(value) {
|
|
|
61
61
|
function isFunction(value) {
|
|
62
62
|
return typeof value === "function";
|
|
63
63
|
}
|
|
64
|
-
function shouldThrowError(throwOnError, params) {
|
|
65
|
-
if (typeof throwOnError === "function") {
|
|
66
|
-
return throwOnError(...params);
|
|
67
|
-
}
|
|
68
|
-
return !!throwOnError;
|
|
69
|
-
}
|
|
70
64
|
export {
|
|
71
65
|
VUE_QUERY_CLIENT,
|
|
72
66
|
cloneDeep,
|
|
73
67
|
cloneDeepUnref,
|
|
74
68
|
getClientKey,
|
|
75
|
-
shouldThrowError,
|
|
76
69
|
updateState
|
|
77
70
|
};
|
|
78
71
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n"],"mappings":";AAAA,SAAS,OAAO,aAAa;AAGtB,IAAM,mBAAmB;AAEzB,SAAS,aAAa,KAAc;AACzC,QAAM,SAAS,MAAM,IAAI,GAAG,KAAK;AACjC,SAAO,GAAG,gBAAgB,GAAG,MAAM;AACrC;AAEO,SAAS,YACd,OACA,QACM;AACN,SAAO,KAAK,KAAK,EAAE,QAAQ,CAAC,QAAQ;AAClC,UAAM,GAAG,IAAI,OAAO,GAAG;AAAA,EACzB,CAAC;AACH;AAIA,SAAS,WACP,OACA,WAKA,aAAqB,IACrB,eAAuB,GACpB;AACH,MAAI,WAAW;AACb,UAAM,SAAS,UAAU,OAAO,YAAY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
|
@@ -24,6 +24,7 @@ __export(useBaseQuery_exports, {
|
|
|
24
24
|
});
|
|
25
25
|
module.exports = __toCommonJS(useBaseQuery_exports);
|
|
26
26
|
var import_vue_demi = require("vue-demi");
|
|
27
|
+
var import_query_core = require("@tanstack/query-core");
|
|
27
28
|
var import_useQueryClient = require("./useQueryClient.cjs");
|
|
28
29
|
var import_utils = require("./utils.cjs");
|
|
29
30
|
function useBaseQuery(Observer, options, queryClient) {
|
|
@@ -86,7 +87,7 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
86
87
|
if (optimisticResult.isStale) {
|
|
87
88
|
stopWatch();
|
|
88
89
|
observer.fetchOptimistic(defaultedOptions.value).then(resolve, (error) => {
|
|
89
|
-
if ((0,
|
|
90
|
+
if ((0, import_query_core.shouldThrowError)(defaultedOptions.value.throwOnError, [
|
|
90
91
|
error,
|
|
91
92
|
observer.getCurrentQuery()
|
|
92
93
|
])) {
|
|
@@ -109,7 +110,7 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
109
110
|
(0, import_vue_demi.watch)(
|
|
110
111
|
() => state.error,
|
|
111
112
|
(error) => {
|
|
112
|
-
if (state.isError && !state.isFetching && (0,
|
|
113
|
+
if (state.isError && !state.isFetching && (0, import_query_core.shouldThrowError)(defaultedOptions.value.throwOnError, [
|
|
113
114
|
error,
|
|
114
115
|
observer.getCurrentQuery()
|
|
115
116
|
])) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | 'refetch'\n ? TResult[K]\n : Ref<Readonly<TResult>[K]>\n} & {\n suspense: () => Promise<TResult>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const clonedOptions = cloneDeepUnref(options as any)\n\n if (typeof clonedOptions.enabled === 'function') {\n clonedOptions.enabled = clonedOptions.enabled()\n }\n\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(clonedOptions)\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n // @ts-expect-error\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910\n const refetch = (...args: Parameters<(typeof state)['refetch']>) => {\n updater()\n return state.refetch(...args)\n }\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, (error: TError) => {\n if (\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error,\n observer.getCurrentQuery(),\n ])\n ) {\n reject(error)\n } else {\n resolve(observer.getCurrentResult())\n }\n })\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n // @ts-expect-error\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const object: any = toRefs(readonlyState)\n for (const key in state) {\n if (typeof state[key as keyof typeof state] === 'function') {\n object[key] = state[key as keyof typeof state]\n }\n }\n\n object.suspense = suspense\n object.refetch = refetch\n\n return object as UseBaseQueryReturnType<TData, TError>\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAUO;AACP,wBAAiC;AACjC,4BAA+B;AAC/B,mBAA4C;AA6CrC,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,KAAC,iCAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,mBAAe,sCAAe;AAE7C,QAAM,uBAAmB,0BAAS,MAAM;AACtC,UAAM,oBAAgB,6BAAe,OAAc;AAEnD,QAAI,OAAO,cAAc,YAAY,YAAY;AAC/C,oBAAc,UAAU,cAAc,QAAQ;AAAA,IAChD;AAEA,UAAM,YAMF,OAAO,oBAAoB,aAAa;AAE5C,cAAU,qBAAqB,OAAO,YAAY,QAC9C,gBACA;AAEJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;AAE5D,QAAM,QAAQ,iBAAiB,MAAM,cACjC,iCAAgB,SAAS,iBAAiB,CAAC,QAC3C,0BAAS,SAAS,iBAAiB,CAAC;AAExC,MAAI,cAAc,MAAM;AAAA,EAExB;AAEA;AAAA,IACE,OAAO;AAAA,IACP,CAAC,gBAAgB;AACf,UAAI,CAAC,aAAa;AAChB,oBAAY;AACZ,sBAAc,SAAS,UAAU,CAAC,WAAW;AAC3C,wCAAY,OAAO,MAAM;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAA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,MACR;AAAA,IACF;AAAA,EACF;AAGA,QAAM,gBAAgB,iBAAiB,MAAM,cACzC,iCAAgB,KAAK,QACrB,0BAAS,KAAK;AAElB,QAAM,aAAc,wBAAO,aAAa;AACxC,aAAW,OAAO,OAAO;AACvB,QAAI,OAAO,MAAM,GAAyB,MAAM,YAAY;AAC1D,aAAO,GAAG,IAAI,MAAM,GAAyB;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO,WAAW;AAClB,SAAO,UAAU;AAEjB,SAAO;AACT;","names":[]}
|
|
@@ -10,8 +10,9 @@ import {
|
|
|
10
10
|
toRefs,
|
|
11
11
|
watch
|
|
12
12
|
} from "vue-demi";
|
|
13
|
+
import { shouldThrowError } from "@tanstack/query-core";
|
|
13
14
|
import { useQueryClient } from "./useQueryClient.js";
|
|
14
|
-
import { cloneDeepUnref,
|
|
15
|
+
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
15
16
|
function useBaseQuery(Observer, options, queryClient) {
|
|
16
17
|
if (process.env.NODE_ENV === "development") {
|
|
17
18
|
if (!getCurrentScope()) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { shouldThrowError } from '@tanstack/query-core'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { Ref } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n TResult = QueryObserverResult<TData, TError>,\n> = {\n [K in keyof TResult]: K extends\n | 'fetchNextPage'\n | 'fetchPreviousPage'\n | 'refetch'\n ? TResult[K]\n : Ref<Readonly<TResult>[K]>\n} & {\n suspense: () => Promise<TResult>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const clonedOptions = cloneDeepUnref(options as any)\n\n if (typeof clonedOptions.enabled === 'function') {\n clonedOptions.enabled = clonedOptions.enabled()\n }\n\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(clonedOptions)\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n // @ts-expect-error\n const state = defaultedOptions.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n const updater = () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n }\n\n watch(defaultedOptions, updater)\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n // fix #5910\n const refetch = (...args: Parameters<(typeof state)['refetch']>) => {\n updater()\n return state.refetch(...args)\n }\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n // noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n // fix #6133\n observer.setOptions(defaultedOptions.value)\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, (error: TError) => {\n if (\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error,\n observer.getCurrentQuery(),\n ])\n ) {\n reject(error)\n } else {\n resolve(observer.getCurrentResult())\n }\n })\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run)\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n // @ts-expect-error\n const readonlyState = defaultedOptions.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const object: any = toRefs(readonlyState)\n for (const key in state) {\n if (typeof state[key as keyof typeof state] === 'function') {\n object[key] = state[key as keyof typeof state]\n }\n }\n\n object.suspense = suspense\n object.refetch = refetch\n\n return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AW,OAAO,OAAO;AACvB,QAAI,OAAO,MAAM,GAAyB,MAAM,YAAY;AAC1D,aAAO,GAAG,IAAI,MAAM,GAAyB;AAAA,IAC/C;AAAA,EACF;AAEA,SAAO,WAAW;AAClB,SAAO,UAAU;AAEjB,SAAO;AACT;","names":[]}
|
|
@@ -59,7 +59,7 @@ function useMutation(mutationOptions, queryClient) {
|
|
|
59
59
|
(0, import_vue_demi.watch)(
|
|
60
60
|
() => state.error,
|
|
61
61
|
(error) => {
|
|
62
|
-
if (error && (0,
|
|
62
|
+
if (error && (0, import_query_core.shouldThrowError)(options.value.throwOnError, [error])) {
|
|
63
63
|
throw error;
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\ntype UseMutationOptionsBase<TData, TError, TVariables, TContext> =\n MutationObserverOptions<TData, TError, TVariables, TContext> & {\n /**\n * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.\n */\n shallow?: boolean\n }\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<UseMutationOptionsBase<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n TResult = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n UseMutationOptionsBase<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = options.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(options, () => {\n observer.setOptions(options.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = options.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TContext>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(options.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAUO;AACP,wBAAmD;AACnD,mBAA4C;AAC5C,4BAA+B;AAsDxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,KAAC,iCAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,mBAAe,sCAAe;AAC7C,QAAM,cAAU,0BAAS,MAAM;AAC7B,WAAO,OAAO,2BAAuB,6BAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,mCAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,QAAQ,QAAQ,MAAM,cACxB,iCAAgB,SAAS,iBAAiB,CAAC,QAC3C,0BAAS,SAAS,iBAAiB,CAAC;AAExC,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,kCAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA,6BAAM,SAAS,MAAM;AACnB,aAAS,WAAW,QAAQ,KAAK;AAAA,EACnC,CAAC;AAED,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,gBAAgB,QAAQ,MAAM,cAChC,iCAAgB,KAAK,QACrB,0BAAS,KAAK;AAElB,QAAM,iBAAa,wBAAO,aAAa;AAIvC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,aACA,oCAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
|
@@ -10,8 +10,8 @@ import {
|
|
|
10
10
|
toRefs,
|
|
11
11
|
watch
|
|
12
12
|
} from "vue-demi";
|
|
13
|
-
import { MutationObserver } from "@tanstack/query-core";
|
|
14
|
-
import { cloneDeepUnref,
|
|
13
|
+
import { MutationObserver, shouldThrowError } from "@tanstack/query-core";
|
|
14
|
+
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
15
15
|
import { useQueryClient } from "./useQueryClient.js";
|
|
16
16
|
function useMutation(mutationOptions, queryClient) {
|
|
17
17
|
if (process.env.NODE_ENV === "development") {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref,
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n getCurrentScope,\n onScopeDispose,\n reactive,\n readonly,\n shallowReactive,\n shallowReadonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver, shouldThrowError } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n DistributiveOmit,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\ntype UseMutationOptionsBase<TData, TError, TVariables, TContext> =\n MutationObserverOptions<TData, TError, TVariables, TContext> & {\n /**\n * Return data in a shallow ref object (it is `false` by default). It can be set to `true` to return data in a shallow ref object, which can improve performance if your data does not need to be deeply reactive.\n */\n shallow?: boolean\n }\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<UseMutationOptionsBase<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n TResult = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<TResult>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n UseMutationOptionsBase<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n if (process.env.NODE_ENV === 'development') {\n if (!getCurrentScope()) {\n console.warn(\n 'vue-query composable like \"useQuery()\" should only be used inside a \"setup()\" function or a running effect scope. They might otherwise lead to memory leaks.',\n )\n }\n }\n\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = options.value.shallow\n ? shallowReactive(observer.getCurrentResult())\n : reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(options, () => {\n observer.setOptions(options.value)\n })\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const readonlyState = options.value.shallow\n ? shallowReadonly(state)\n : readonly(state)\n\n const resultRefs = toRefs(readonlyState) as ToRefs<\n Readonly<MutationResult<TData, TError, TVariables, TContext>>\n >\n\n watch(\n () => state.error,\n (error) => {\n if (\n error &&\n shouldThrowError(options.value.throwOnError, [error as TError])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...resultRefs,\n mutate,\n mutateAsync: state.mutate,\n reset: state.reset,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,kBAAkB,wBAAwB;AACnD,SAAS,gBAAgB,mBAAmB;AAC5C,SAAS,sBAAsB;AAsDxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,MAAI,QAAQ,IAAI,aAAa,eAAe;AAC1C,QAAI,CAAC,gBAAgB,GAAG;AACtB,cAAQ;AAAA,QACN;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,SAAS,eAAe,eAAe;AAC7C,QAAM,UAAU,SAAS,MAAM;AAC7B,WAAO,OAAO,uBAAuB,eAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,iBAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,QAAQ,QAAQ,MAAM,UACxB,gBAAgB,SAAS,iBAAiB,CAAC,IAC3C,SAAS,SAAS,iBAAiB,CAAC;AAExC,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,gBAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA,QAAM,SAAS,MAAM;AACnB,aAAS,WAAW,QAAQ,KAAK;AAAA,EACnC,CAAC;AAED,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,gBAAgB,QAAQ,MAAM,UAChC,gBAAgB,KAAK,IACrB,SAAS,KAAK;AAElB,QAAM,aAAa,OAAO,aAAa;AAIvC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,SACA,iBAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
package/build/modern/utils.cjs
CHANGED
|
@@ -24,7 +24,6 @@ __export(utils_exports, {
|
|
|
24
24
|
cloneDeep: () => cloneDeep,
|
|
25
25
|
cloneDeepUnref: () => cloneDeepUnref,
|
|
26
26
|
getClientKey: () => getClientKey,
|
|
27
|
-
shouldThrowError: () => shouldThrowError,
|
|
28
27
|
updateState: () => updateState
|
|
29
28
|
});
|
|
30
29
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -90,19 +89,12 @@ function isPlainObject(value) {
|
|
|
90
89
|
function isFunction(value) {
|
|
91
90
|
return typeof value === "function";
|
|
92
91
|
}
|
|
93
|
-
function shouldThrowError(throwOnError, params) {
|
|
94
|
-
if (typeof throwOnError === "function") {
|
|
95
|
-
return throwOnError(...params);
|
|
96
|
-
}
|
|
97
|
-
return !!throwOnError;
|
|
98
|
-
}
|
|
99
92
|
// Annotate the CommonJS export names for ESM import in node:
|
|
100
93
|
0 && (module.exports = {
|
|
101
94
|
VUE_QUERY_CLIENT,
|
|
102
95
|
cloneDeep,
|
|
103
96
|
cloneDeepUnref,
|
|
104
97
|
getClientKey,
|
|
105
|
-
shouldThrowError,
|
|
106
98
|
updateState
|
|
107
99
|
});
|
|
108
100
|
//# sourceMappingURL=utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA6B;AAGtB,IAAM,mBAAmB;AAEzB,SAAS,aAAa,KAAc;AACzC,QAAM,SAAS,MAAM,IAAI,GAAG,KAAK;AACjC,SAAO,GAAG,gBAAgB,GAAG,MAAM;AACrC;AAEO,SAAS,YACd,OACA,QACM;AACN,SAAO,KAAK,KAAK,EAAE,QAAQ,CAA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BAAmB;AAC/D,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,SAAO,cAAc,QAAQ,cAAc,OAAO;AACpD;AAEA,SAAS,WAAW,OAAmC;AACrD,SAAO,OAAO,UAAU;AAC1B;","names":[]}
|
package/build/modern/utils.d.cts
CHANGED
|
@@ -7,6 +7,5 @@ declare function getClientKey(key?: string): string;
|
|
|
7
7
|
declare function updateState(state: Record<string, any>, update: Record<string, any>): void;
|
|
8
8
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customize?: (val: MaybeRefDeep<T>, key: string, level: number) => T | undefined): T;
|
|
9
9
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>, unrefGetters?: boolean): T;
|
|
10
|
-
declare function shouldThrowError<T extends (...args: Array<any>) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
11
10
|
|
|
12
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey,
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
package/build/modern/utils.d.ts
CHANGED
|
@@ -7,6 +7,5 @@ declare function getClientKey(key?: string): string;
|
|
|
7
7
|
declare function updateState(state: Record<string, any>, update: Record<string, any>): void;
|
|
8
8
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customize?: (val: MaybeRefDeep<T>, key: string, level: number) => T | undefined): T;
|
|
9
9
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>, unrefGetters?: boolean): T;
|
|
10
|
-
declare function shouldThrowError<T extends (...args: Array<any>) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
11
10
|
|
|
12
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey,
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
package/build/modern/utils.js
CHANGED
|
@@ -61,18 +61,11 @@ function isPlainObject(value) {
|
|
|
61
61
|
function isFunction(value) {
|
|
62
62
|
return typeof value === "function";
|
|
63
63
|
}
|
|
64
|
-
function shouldThrowError(throwOnError, params) {
|
|
65
|
-
if (typeof throwOnError === "function") {
|
|
66
|
-
return throwOnError(...params);
|
|
67
|
-
}
|
|
68
|
-
return !!throwOnError;
|
|
69
|
-
}
|
|
70
64
|
export {
|
|
71
65
|
VUE_QUERY_CLIENT,
|
|
72
66
|
cloneDeep,
|
|
73
67
|
cloneDeepUnref,
|
|
74
68
|
getClientKey,
|
|
75
|
-
shouldThrowError,
|
|
76
69
|
updateState
|
|
77
70
|
};
|
|
78
71
|
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils.ts"],"sourcesContent":["import { isRef, unref } from 'vue-demi'\nimport type { MaybeRefDeep } from './types'\n\nexport const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT'\n\nexport function getClientKey(key?: string) {\n const suffix = key ? `:${key}` : ''\n return `${VUE_QUERY_CLIENT}${suffix}`\n}\n\nexport function updateState(\n state: Record<string, any>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\n// Helper function for cloning deep objects where\n// the level and key is provided to the callback function.\nfunction _cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n currentKey: string = '',\n currentLevel: number = 0,\n): T {\n if (customize) {\n const result = customize(value, currentKey, currentLevel)\n if (result === undefined && isRef(value)) {\n return result as T\n }\n if (result !== undefined) {\n return result\n }\n }\n\n if (Array.isArray(value)) {\n return value.map((val, index) =>\n _cloneDeep(val, customize, String(index), currentLevel + 1),\n ) as unknown as T\n }\n\n if (typeof value === 'object' && isPlainObject(value)) {\n const entries = Object.entries(value).map(([key, val]) => [\n key,\n _cloneDeep(val, customize, key, currentLevel + 1),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customize?: (\n val: MaybeRefDeep<T>,\n key: string,\n level: number,\n ) => T | undefined,\n): T {\n return _cloneDeep(value, customize)\n}\n\nexport function cloneDeepUnref<T>(\n obj: MaybeRefDeep<T>,\n unrefGetters = false,\n): T {\n return cloneDeep(obj, (val, key, level) => {\n // Check if we're at the top level and the key is 'queryKey'\n //\n // If so, take the recursive descent where we resolve\n // getters to values as well as refs.\n if (level === 1 && key === 'queryKey') {\n return cloneDeepUnref(val, true)\n }\n\n // Resolve getters to values if specified.\n if (unrefGetters && isFunction(val)) {\n // Cast due to older TS versions not allowing calling\n // on certain intersection types.\n return cloneDeepUnref((val as Function)(), unrefGetters)\n }\n\n // Unref refs and continue to recurse into the value.\n if (isRef(val)) {\n return cloneDeepUnref(unref(val), unrefGetters)\n }\n\n return undefined\n })\n}\n\n// eslint-disable-next-line @typescript-eslint/no-wrapper-object-types\nfunction isPlainObject(value: unknown): value is Object {\n if (Object.prototype.toString.call(value) !== '[object Object]') {\n return false\n }\n\n const prototype = Object.getPrototypeOf(value)\n return prototype === null || prototype === Object.prototype\n}\n\nfunction isFunction(value: unknown): value is Function {\n return typeof value === 'function'\n}\n"],"mappings":";AAAA,SAAS,OAAO,aAAa;AAGtB,IAAM,mBAAmB;AAEzB,SAAS,aAAa,KAAc;AACzC,QAAM,SAAS,MAAM,IAAI,GAAG,KAAK;AACjC,SAAO,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AA,EACT,CAAC;AACH;AAGA,SAAS,cAAc,OAAiC;AACtD,MAAI,OAAO,UAAU,SAAS,KAAK,KAAK,MAAM,mBAAmB;AAC/D,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,OAAO,eAAe,KAAK;AAC7C,SAAO,cAAc,QAAQ,cAAc,OAAO;AACpD;AAEA,SAAS,WAAW,OAAmC;AACrD,SAAO,OAAO,UAAU;AAC1B;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/vue-query",
|
|
3
|
-
"version": "5.75.
|
|
3
|
+
"version": "5.75.7",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in Vue",
|
|
5
5
|
"author": "Damian Osipiuk",
|
|
6
6
|
"license": "MIT",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"@tanstack/match-sorter-utils": "^8.19.4",
|
|
43
43
|
"@vue/devtools-api": "^6.6.3",
|
|
44
44
|
"vue-demi": "^0.14.10",
|
|
45
|
-
"@tanstack/query-core": "5.75.
|
|
45
|
+
"@tanstack/query-core": "5.75.7"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@vitejs/plugin-vue": "^5.2.1",
|
|
@@ -50,7 +50,8 @@
|
|
|
50
50
|
"eslint-plugin-vue": "^9.27.0",
|
|
51
51
|
"vue": "^3.4.27",
|
|
52
52
|
"vue2": "npm:vue@2.6",
|
|
53
|
-
"vue2.7": "npm:vue@2.7"
|
|
53
|
+
"vue2.7": "npm:vue@2.7",
|
|
54
|
+
"@tanstack/query-test-utils": "0.0.0"
|
|
54
55
|
},
|
|
55
56
|
"peerDependencies": {
|
|
56
57
|
"@vue/composition-api": "^1.1.2",
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -9,8 +9,9 @@ import {
|
|
|
9
9
|
toRefs,
|
|
10
10
|
watch,
|
|
11
11
|
} from 'vue-demi'
|
|
12
|
+
import { shouldThrowError } from '@tanstack/query-core'
|
|
12
13
|
import { useQueryClient } from './useQueryClient'
|
|
13
|
-
import { cloneDeepUnref,
|
|
14
|
+
import { cloneDeepUnref, updateState } from './utils'
|
|
14
15
|
import type { Ref } from 'vue-demi'
|
|
15
16
|
import type {
|
|
16
17
|
DefaultedQueryObserverOptions,
|
package/src/useMutation.ts
CHANGED
|
@@ -9,8 +9,8 @@ import {
|
|
|
9
9
|
toRefs,
|
|
10
10
|
watch,
|
|
11
11
|
} from 'vue-demi'
|
|
12
|
-
import { MutationObserver } from '@tanstack/query-core'
|
|
13
|
-
import { cloneDeepUnref,
|
|
12
|
+
import { MutationObserver, shouldThrowError } from '@tanstack/query-core'
|
|
13
|
+
import { cloneDeepUnref, updateState } from './utils'
|
|
14
14
|
import { useQueryClient } from './useQueryClient'
|
|
15
15
|
import type { ToRefs } from 'vue-demi'
|
|
16
16
|
import type {
|
package/src/utils.ts
CHANGED
|
@@ -109,15 +109,3 @@ function isPlainObject(value: unknown): value is Object {
|
|
|
109
109
|
function isFunction(value: unknown): value is Function {
|
|
110
110
|
return typeof value === 'function'
|
|
111
111
|
}
|
|
112
|
-
|
|
113
|
-
export function shouldThrowError<T extends (...args: Array<any>) => boolean>(
|
|
114
|
-
throwOnError: boolean | T | undefined,
|
|
115
|
-
params: Parameters<T>,
|
|
116
|
-
): boolean {
|
|
117
|
-
// Allow throwOnError function to override throwing behavior on a per-error basis
|
|
118
|
-
if (typeof throwOnError === 'function') {
|
|
119
|
-
return throwOnError(...params)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return !!throwOnError
|
|
123
|
-
}
|