@tanstack/vue-query 5.0.0-beta.11 → 5.0.0-beta.12
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 +11 -0
- package/build/legacy/useBaseQuery.cjs.map +1 -1
- package/build/legacy/useBaseQuery.js +12 -1
- package/build/legacy/useBaseQuery.js.map +1 -1
- package/build/legacy/useMutation.cjs +8 -0
- package/build/legacy/useMutation.cjs.map +1 -1
- package/build/legacy/useMutation.js +9 -1
- package/build/legacy/useMutation.js.map +1 -1
- package/build/legacy/utils.cjs +8 -0
- package/build/legacy/utils.cjs.map +1 -1
- package/build/legacy/utils.d.cts +2 -1
- package/build/legacy/utils.d.ts +2 -1
- package/build/legacy/utils.js +7 -0
- package/build/legacy/utils.js.map +1 -1
- package/build/modern/useBaseQuery.cjs +11 -0
- package/build/modern/useBaseQuery.cjs.map +1 -1
- package/build/modern/useBaseQuery.js +12 -1
- package/build/modern/useBaseQuery.js.map +1 -1
- package/build/modern/useMutation.cjs +8 -0
- package/build/modern/useMutation.cjs.map +1 -1
- package/build/modern/useMutation.js +9 -1
- package/build/modern/useMutation.js.map +1 -1
- package/build/modern/utils.cjs +8 -0
- package/build/modern/utils.cjs.map +1 -1
- package/build/modern/utils.d.cts +2 -1
- package/build/modern/utils.d.ts +2 -1
- package/build/modern/utils.js +7 -0
- package/build/modern/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/useMutation.test.ts +20 -0
- package/src/__tests__/useQuery.test.ts +22 -0
- package/src/useBaseQuery.ts +18 -1
- package/src/useMutation.ts +13 -1
- package/src/utils.ts +12 -0
|
@@ -84,6 +84,17 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
84
84
|
}
|
|
85
85
|
);
|
|
86
86
|
};
|
|
87
|
+
(0, import_vue_demi.watch)(
|
|
88
|
+
() => state.error,
|
|
89
|
+
(error) => {
|
|
90
|
+
if (state.isError && !state.isFetching && (0, import_utils.shouldThrowError)(defaultedOptions.value.throwOnError, [
|
|
91
|
+
error,
|
|
92
|
+
observer.getCurrentQuery()
|
|
93
|
+
])) {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
);
|
|
87
98
|
return {
|
|
88
99
|
...(0, import_vue_demi.toRefs)((0, import_vue_demi.readonly)(state)),
|
|
89
100
|
suspense
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AACP,4BAA+B;AAC/B,
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AACP,4BAA+B;AAC/B,mBAA8D;AAsCvD,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,QAAM,SAAS,mBAAe,sCAAe;AAE7C,QAAM,uBAAmB,0BAAS,MAAM;AACtC,UAAM,YAMF,OAAO,wBAAoB,6BAAe,OAAc,CAAC;AAE7D,cAAU,qBAAqB,OAAO,YAAY,QAC9C,gBACA;AAEJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;AAC5D,QAAM,YAAQ,0BAAS,SAAS,iBAAiB,CAAC;AAElD,MAAI,cAAc,MAAM;AAAA,EAExB;AAEA;AAAA,IACE,OAAO;AAAA,IACP,CAAC,gBAAgB;AAEf,UAAI,CAAC,aAAa;AAChB,oBAAY;AACZ,sBAAc,SAAS,UAAU,CAAC,WAAW;AAC3C,wCAAY,OAAO,MAAM;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,iBAAiB,KAAK;AAC1C,oCAAY,OAAO,SAAS,iBAAiB,CAAC;AAAA,IAChD;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,WAAW,MAAM;AACrB,WAAO,IAAI;AAAA,MACT,CAAC,SAAS,WAAW;AACnB,YAAI,YAAY,MAAM;AAAA,QAEtB;AACA,cAAM,MAAM,MAAM;AAChB,cAAI,iBAAiB,MAAM,YAAY,OAAO;AAC5C,kBAAM,mBAAmB,SAAS;AAAA,cAChC,iBAAiB;AAAA,YACnB;AACA,gBAAI,iBAAiB,SAAS;AAC5B,wBAAU;AACV,uBACG,gBAAgB,iBAAiB,KAAK,EACtC,KAAK,SAAS,MAAM;AAAA,YACzB,OAAO;AACL,wBAAU;AACV,sBAAQ,gBAAgB;AAAA,YAC1B;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AAEJ,wBAAY,uBAAM,kBAAkB,KAAK,EAAE,MAAM,KAAK,CAAC;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AAGA;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,MAAM,WACN,CAAC,MAAM,kBACP,+BAAiB,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,QACA,SAAS,gBAAgB;AAAA,MAC3B,CAAC,GACD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAI,4BAAO,0BAAS,KAAK,CAAC;AAAA,IAG1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
watch
|
|
9
9
|
} from "vue-demi";
|
|
10
10
|
import { useQueryClient } from "./useQueryClient.js";
|
|
11
|
-
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
11
|
+
import { cloneDeepUnref, shouldThrowError, updateState } from "./utils.js";
|
|
12
12
|
function useBaseQuery(Observer, options, queryClient) {
|
|
13
13
|
const client = queryClient || useQueryClient();
|
|
14
14
|
const defaultedOptions = computed(() => {
|
|
@@ -67,6 +67,17 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
67
67
|
}
|
|
68
68
|
);
|
|
69
69
|
};
|
|
70
|
+
watch(
|
|
71
|
+
() => state.error,
|
|
72
|
+
(error) => {
|
|
73
|
+
if (state.isError && !state.isFetching && shouldThrowError(defaultedOptions.value.throwOnError, [
|
|
74
|
+
error,
|
|
75
|
+
observer.getCurrentQuery()
|
|
76
|
+
])) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
70
81
|
return {
|
|
71
82
|
...toRefs(readonly(state)),
|
|
72
83
|
suspense
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,kBAAkB,mBAAmB;AAsCvD,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,QAAM,SAAS,eAAe,eAAe;AAE7C,QAAM,mBAAmB,SAAS,MAAM;AACtC,UAAM,YAMF,OAAO,oBAAoB,eAAe,OAAc,CAAC;AAE7D,cAAU,qBAAqB,OAAO,YAAY,QAC9C,gBACA;AAEJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;AAC5D,QAAM,QAAQ,SAAS,SAAS,iBAAiB,CAAC;AAElD,MAAI,cAAc,MAAM;AAAA,EAExB;AAEA;AAAA,IACE,OAAO;AAAA,IACP,CAAC,gBAAgB;AAEf,UAAI,CAAC,aAAa;AAChB,oBAAY;AACZ,sBAAc,SAAS,UAAU,CAAC,WAAW;AAC3C,sBAAY,OAAO,MAAM;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,iBAAiB,KAAK;AAC1C,kBAAY,OAAO,SAAS,iBAAiB,CAAC;AAAA,IAChD;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,WAAW,MAAM;AACrB,WAAO,IAAI;AAAA,MACT,CAAC,SAAS,WAAW;AACnB,YAAI,YAAY,MAAM;AAAA,QAEtB;AACA,cAAM,MAAM,MAAM;AAChB,cAAI,iBAAiB,MAAM,YAAY,OAAO;AAC5C,kBAAM,mBAAmB,SAAS;AAAA,cAChC,iBAAiB;AAAA,YACnB;AACA,gBAAI,iBAAiB,SAAS;AAC5B,wBAAU;AACV,uBACG,gBAAgB,iBAAiB,KAAK,EACtC,KAAK,SAAS,MAAM;AAAA,YACzB,OAAO;AACL,wBAAU;AACV,sBAAQ,gBAAgB;AAAA,YAC1B;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AAEJ,oBAAY,MAAM,kBAAkB,KAAK,EAAE,MAAM,KAAK,CAAC;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AAGA;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,MAAM,WACN,CAAC,MAAM,cACP,iBAAiB,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,QACA,SAAS,gBAAgB;AAAA,MAC3B,CAAC,GACD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAI,OAAO,SAAS,KAAK,CAAC;AAAA,IAG1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -52,6 +52,14 @@ function useMutation(mutationOptions, queryClient) {
|
|
|
52
52
|
unsubscribe();
|
|
53
53
|
});
|
|
54
54
|
const resultRefs = (0, import_vue_demi.toRefs)((0, import_vue_demi.readonly)(state));
|
|
55
|
+
(0, import_vue_demi.watch)(
|
|
56
|
+
() => state.error,
|
|
57
|
+
(error) => {
|
|
58
|
+
if (error && (0, import_utils.shouldThrowError)(options.value.throwOnError, [error])) {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
);
|
|
55
63
|
return {
|
|
56
64
|
...resultRefs,
|
|
57
65
|
mutate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AACP,wBAAiC;AACjC,
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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 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,sBAOO;AACP,wBAAiC;AACjC,mBAA8D;AAC9D,4BAA+B;AA6CxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,QAAM,SAAS,mBAAe,sCAAe;AAC7C,QAAM,cAAU,0BAAS,MAAM;AAC7B,WAAO,OAAO,2BAAuB,6BAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,mCAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,YAAQ,0BAAS,SAAS,iBAAiB,CAAC;AAElD,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,kCAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,QAAQ,KAAK;AAAA,IACnC;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,iBAAa,4BAAO,0BAAS,KAAK,CAAC;AAIzC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,aACA,+BAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
watch
|
|
9
9
|
} from "vue-demi";
|
|
10
10
|
import { MutationObserver } from "@tanstack/query-core";
|
|
11
|
-
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
11
|
+
import { cloneDeepUnref, shouldThrowError, updateState } from "./utils.js";
|
|
12
12
|
import { useQueryClient } from "./useQueryClient.js";
|
|
13
13
|
function useMutation(mutationOptions, queryClient) {
|
|
14
14
|
const client = queryClient || useQueryClient();
|
|
@@ -35,6 +35,14 @@ function useMutation(mutationOptions, queryClient) {
|
|
|
35
35
|
unsubscribe();
|
|
36
36
|
});
|
|
37
37
|
const resultRefs = toRefs(readonly(state));
|
|
38
|
+
watch(
|
|
39
|
+
() => state.error,
|
|
40
|
+
(error) => {
|
|
41
|
+
if (error && shouldThrowError(options.value.throwOnError, [error])) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
38
46
|
return {
|
|
39
47
|
...resultRefs,
|
|
40
48
|
mutate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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 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,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB,kBAAkB,mBAAmB;AAC9D,SAAS,sBAAsB;AA6CxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,QAAM,SAAS,eAAe,eAAe;AAC7C,QAAM,UAAU,SAAS,MAAM;AAC7B,WAAO,OAAO,uBAAuB,eAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,iBAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,QAAQ,SAAS,SAAS,iBAAiB,CAAC;AAElD,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,gBAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,QAAQ,KAAK;AAAA,IACnC;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC;AAIzC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,SACA,iBAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
package/build/legacy/utils.cjs
CHANGED
|
@@ -24,6 +24,7 @@ __export(utils_exports, {
|
|
|
24
24
|
cloneDeep: () => cloneDeep,
|
|
25
25
|
cloneDeepUnref: () => cloneDeepUnref,
|
|
26
26
|
getClientKey: () => getClientKey,
|
|
27
|
+
shouldThrowError: () => shouldThrowError,
|
|
27
28
|
updateState: () => updateState
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -75,12 +76,19 @@ function isPlainObject(value) {
|
|
|
75
76
|
const prototype = Object.getPrototypeOf(value);
|
|
76
77
|
return prototype === null || prototype === Object.prototype;
|
|
77
78
|
}
|
|
79
|
+
function shouldThrowError(throwOnError, params) {
|
|
80
|
+
if (typeof throwOnError === "function") {
|
|
81
|
+
return throwOnError(...params);
|
|
82
|
+
}
|
|
83
|
+
return !!throwOnError;
|
|
84
|
+
}
|
|
78
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
86
|
0 && (module.exports = {
|
|
80
87
|
VUE_QUERY_CLIENT,
|
|
81
88
|
cloneDeep,
|
|
82
89
|
cloneDeepUnref,
|
|
83
90
|
getClientKey,
|
|
91
|
+
shouldThrowError,
|
|
84
92
|
updateState
|
|
85
93
|
});
|
|
86
94
|
//# 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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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"],"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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,YAAI,uBAAM,GAAG,GAAG;AACd,aAAO,mBAAe,uBAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;","names":[]}
|
|
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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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\nexport function shouldThrowError<T extends (...args: any[]) => boolean>(\n throwOnError: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow throwOnError function to override throwing behavior on a per-error basis\n if (typeof throwOnError === 'function') {\n return throwOnError(...params)\n }\n\n return !!throwOnError\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,YAAI,uBAAM,GAAG,GAAG;AACd,aAAO,mBAAe,uBAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;AAEO,SAAS,iBACd,cACA,QACS;AAET,MAAI,OAAO,iBAAiB,YAAY;AACtC,WAAO,aAAa,GAAG,MAAM;AAAA,EAC/B;AAEA,SAAO,CAAC,CAAC;AACX;","names":[]}
|
package/build/legacy/utils.d.cts
CHANGED
|
@@ -6,5 +6,6 @@ declare function getClientKey(key?: string): string;
|
|
|
6
6
|
declare function updateState(state: Record<string, unknown>, update: Record<string, any>): void;
|
|
7
7
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customizer?: (val: MaybeRefDeep<T>) => T | undefined): T;
|
|
8
8
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T;
|
|
9
|
+
declare function shouldThrowError<T extends (...args: any[]) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
9
10
|
|
|
10
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, shouldThrowError, updateState };
|
package/build/legacy/utils.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ declare function getClientKey(key?: string): string;
|
|
|
6
6
|
declare function updateState(state: Record<string, unknown>, update: Record<string, any>): void;
|
|
7
7
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customizer?: (val: MaybeRefDeep<T>) => T | undefined): T;
|
|
8
8
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T;
|
|
9
|
+
declare function shouldThrowError<T extends (...args: any[]) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
9
10
|
|
|
10
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, shouldThrowError, updateState };
|
package/build/legacy/utils.js
CHANGED
|
@@ -47,11 +47,18 @@ function isPlainObject(value) {
|
|
|
47
47
|
const prototype = Object.getPrototypeOf(value);
|
|
48
48
|
return prototype === null || prototype === Object.prototype;
|
|
49
49
|
}
|
|
50
|
+
function shouldThrowError(throwOnError, params) {
|
|
51
|
+
if (typeof throwOnError === "function") {
|
|
52
|
+
return throwOnError(...params);
|
|
53
|
+
}
|
|
54
|
+
return !!throwOnError;
|
|
55
|
+
}
|
|
50
56
|
export {
|
|
51
57
|
VUE_QUERY_CLIENT,
|
|
52
58
|
cloneDeep,
|
|
53
59
|
cloneDeepUnref,
|
|
54
60
|
getClientKey,
|
|
61
|
+
shouldThrowError,
|
|
55
62
|
updateState
|
|
56
63
|
};
|
|
57
64
|
//# 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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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"],"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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,QAAI,WAAW,UAAa,MAAM,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,QAAI,MAAM,GAAG,GAAG;AACd,aAAO,eAAe,MAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;","names":[]}
|
|
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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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\nexport function shouldThrowError<T extends (...args: any[]) => boolean>(\n throwOnError: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow throwOnError function to override throwing behavior on a per-error basis\n if (typeof throwOnError === 'function') {\n return throwOnError(...params)\n }\n\n return !!throwOnError\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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,QAAI,WAAW,UAAa,MAAM,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,QAAI,MAAM,GAAG,GAAG;AACd,aAAO,eAAe,MAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;AAEO,SAAS,iBACd,cACA,QACS;AAET,MAAI,OAAO,iBAAiB,YAAY;AACtC,WAAO,aAAa,GAAG,MAAM;AAAA,EAC/B;AAEA,SAAO,CAAC,CAAC;AACX;","names":[]}
|
|
@@ -84,6 +84,17 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
84
84
|
}
|
|
85
85
|
);
|
|
86
86
|
};
|
|
87
|
+
(0, import_vue_demi.watch)(
|
|
88
|
+
() => state.error,
|
|
89
|
+
(error) => {
|
|
90
|
+
if (state.isError && !state.isFetching && (0, import_utils.shouldThrowError)(defaultedOptions.value.throwOnError, [
|
|
91
|
+
error,
|
|
92
|
+
observer.getCurrentQuery()
|
|
93
|
+
])) {
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
);
|
|
87
98
|
return {
|
|
88
99
|
...(0, import_vue_demi.toRefs)((0, import_vue_demi.readonly)(state)),
|
|
89
100
|
suspense
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AACP,4BAA+B;AAC/B,
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AACP,4BAA+B;AAC/B,mBAA8D;AAsCvD,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,QAAM,SAAS,mBAAe,sCAAe;AAE7C,QAAM,uBAAmB,0BAAS,MAAM;AACtC,UAAM,YAMF,OAAO,wBAAoB,6BAAe,OAAc,CAAC;AAE7D,cAAU,qBAAqB,OAAO,YAAY,QAC9C,gBACA;AAEJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;AAC5D,QAAM,YAAQ,0BAAS,SAAS,iBAAiB,CAAC;AAElD,MAAI,cAAc,MAAM;AAAA,EAExB;AAEA;AAAA,IACE,OAAO;AAAA,IACP,CAAC,gBAAgB;AAEf,UAAI,CAAC,aAAa;AAChB,oBAAY;AACZ,sBAAc,SAAS,UAAU,CAAC,WAAW;AAC3C,wCAAY,OAAO,MAAM;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,iBAAiB,KAAK;AAC1C,oCAAY,OAAO,SAAS,iBAAiB,CAAC;AAAA,IAChD;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,WAAW,MAAM;AACrB,WAAO,IAAI;AAAA,MACT,CAAC,SAAS,WAAW;AACnB,YAAI,YAAY,MAAM;AAAA,QAEtB;AACA,cAAM,MAAM,MAAM;AAChB,cAAI,iBAAiB,MAAM,YAAY,OAAO;AAC5C,kBAAM,mBAAmB,SAAS;AAAA,cAChC,iBAAiB;AAAA,YACnB;AACA,gBAAI,iBAAiB,SAAS;AAC5B,wBAAU;AACV,uBACG,gBAAgB,iBAAiB,KAAK,EACtC,KAAK,SAAS,MAAM;AAAA,YACzB,OAAO;AACL,wBAAU;AACV,sBAAQ,gBAAgB;AAAA,YAC1B;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AAEJ,wBAAY,uBAAM,kBAAkB,KAAK,EAAE,MAAM,KAAK,CAAC;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AAGA;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,MAAM,WACN,CAAC,MAAM,kBACP,+BAAiB,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,QACA,SAAS,gBAAgB;AAAA,MAC3B,CAAC,GACD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,OAAI,4BAAO,0BAAS,KAAK,CAAC;AAAA,IAG1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
watch
|
|
9
9
|
} from "vue-demi";
|
|
10
10
|
import { useQueryClient } from "./useQueryClient.js";
|
|
11
|
-
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
11
|
+
import { cloneDeepUnref, shouldThrowError, updateState } from "./utils.js";
|
|
12
12
|
function useBaseQuery(Observer, options, queryClient) {
|
|
13
13
|
const client = queryClient || useQueryClient();
|
|
14
14
|
const defaultedOptions = computed(() => {
|
|
@@ -67,6 +67,17 @@ function useBaseQuery(Observer, options, queryClient) {
|
|
|
67
67
|
}
|
|
68
68
|
);
|
|
69
69
|
};
|
|
70
|
+
watch(
|
|
71
|
+
() => state.error,
|
|
72
|
+
(error) => {
|
|
73
|
+
if (state.isError && !state.isFetching && shouldThrowError(defaultedOptions.value.throwOnError, [
|
|
74
|
+
error,
|
|
75
|
+
observer.getCurrentQuery()
|
|
76
|
+
])) {
|
|
77
|
+
throw error;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
);
|
|
70
81
|
return {
|
|
71
82
|
...toRefs(readonly(state)),
|
|
72
83
|
suspense
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { useQueryClient } from './useQueryClient'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultedQueryObserverOptions,\n QueryKey,\n QueryObserver,\n QueryObserverResult,\n} from '@tanstack/query-core'\nimport type { QueryClient } from './queryClient'\nimport type { UseQueryOptions } from './useQuery'\nimport type { UseInfiniteQueryOptions } from './useInfiniteQuery'\n\nexport type UseBaseQueryReturnType<\n TData,\n TError,\n Result = QueryObserverResult<TData, TError>,\n> = ToRefs<Readonly<Result>> & {\n suspense: () => Promise<Result>\n}\n\ntype UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n> =\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryData, TQueryKey>\n | UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n TPageParam,\n>(\n Observer: typeof QueryObserver,\n options: UseQueryOptionsGeneric<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseBaseQueryReturnType<TData, TError> {\n const client = queryClient || useQueryClient()\n\n const defaultedOptions = computed(() => {\n const defaulted: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n > = client.defaultQueryOptions(cloneDeepUnref(options as any))\n\n defaulted._optimisticResults = client.isRestoring.value\n ? 'isRestoring'\n : 'optimistic'\n\n return defaulted\n })\n\n const observer = new Observer(client, defaultedOptions.value)\n const state = reactive(observer.getCurrentResult())\n\n let unsubscribe = () => {\n // noop\n }\n\n watch(\n client.isRestoring,\n (isRestoring) => {\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (!isRestoring) {\n unsubscribe()\n unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n }\n },\n { immediate: true },\n )\n\n watch(\n defaultedOptions,\n () => {\n observer.setOptions(defaultedOptions.value)\n updateState(state, observer.getCurrentResult())\n },\n { deep: true },\n )\n\n onScopeDispose(() => {\n unsubscribe()\n })\n\n const suspense = () => {\n return new Promise<QueryObserverResult<TData, TError>>(\n (resolve, reject) => {\n let stopWatch = () => {\n //noop\n }\n const run = () => {\n if (defaultedOptions.value.enabled !== false) {\n const optimisticResult = observer.getOptimisticResult(\n defaultedOptions.value,\n )\n if (optimisticResult.isStale) {\n stopWatch()\n observer\n .fetchOptimistic(defaultedOptions.value)\n .then(resolve, reject)\n } else {\n stopWatch()\n resolve(optimisticResult)\n }\n }\n }\n\n run()\n\n stopWatch = watch(defaultedOptions, run, { deep: true })\n },\n )\n }\n\n // Handle error boundary\n watch(\n () => state.error,\n (error) => {\n if (\n state.isError &&\n !state.isFetching &&\n shouldThrowError(defaultedOptions.value.throwOnError, [\n error as TError,\n observer.getCurrentQuery(),\n ])\n ) {\n throw error\n }\n },\n )\n\n return {\n ...(toRefs(readonly(state)) as ToRefs<\n Readonly<QueryObserverResult<TData, TError>>\n >),\n suspense,\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,sBAAsB;AAC/B,SAAS,gBAAgB,kBAAkB,mBAAmB;AAsCvD,SAAS,aAQd,UACA,SAQA,aACuC;AACvC,QAAM,SAAS,eAAe,eAAe;AAE7C,QAAM,mBAAmB,SAAS,MAAM;AACtC,UAAM,YAMF,OAAO,oBAAoB,eAAe,OAAc,CAAC;AAE7D,cAAU,qBAAqB,OAAO,YAAY,QAC9C,gBACA;AAEJ,WAAO;AAAA,EACT,CAAC;AAED,QAAM,WAAW,IAAI,SAAS,QAAQ,iBAAiB,KAAK;AAC5D,QAAM,QAAQ,SAAS,SAAS,iBAAiB,CAAC;AAElD,MAAI,cAAc,MAAM;AAAA,EAExB;AAEA;AAAA,IACE,OAAO;AAAA,IACP,CAAC,gBAAgB;AAEf,UAAI,CAAC,aAAa;AAChB,oBAAY;AACZ,sBAAc,SAAS,UAAU,CAAC,WAAW;AAC3C,sBAAY,OAAO,MAAM;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AAAA,IACA,EAAE,WAAW,KAAK;AAAA,EACpB;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,iBAAiB,KAAK;AAC1C,kBAAY,OAAO,SAAS,iBAAiB,CAAC;AAAA,IAChD;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,WAAW,MAAM;AACrB,WAAO,IAAI;AAAA,MACT,CAAC,SAAS,WAAW;AACnB,YAAI,YAAY,MAAM;AAAA,QAEtB;AACA,cAAM,MAAM,MAAM;AAChB,cAAI,iBAAiB,MAAM,YAAY,OAAO;AAC5C,kBAAM,mBAAmB,SAAS;AAAA,cAChC,iBAAiB;AAAA,YACnB;AACA,gBAAI,iBAAiB,SAAS;AAC5B,wBAAU;AACV,uBACG,gBAAgB,iBAAiB,KAAK,EACtC,KAAK,SAAS,MAAM;AAAA,YACzB,OAAO;AACL,wBAAU;AACV,sBAAQ,gBAAgB;AAAA,YAC1B;AAAA,UACF;AAAA,QACF;AAEA,YAAI;AAEJ,oBAAY,MAAM,kBAAkB,KAAK,EAAE,MAAM,KAAK,CAAC;AAAA,MACzD;AAAA,IACF;AAAA,EACF;AAGA;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,MAAM,WACN,CAAC,MAAM,cACP,iBAAiB,iBAAiB,MAAM,cAAc;AAAA,QACpD;AAAA,QACA,SAAS,gBAAgB;AAAA,MAC3B,CAAC,GACD;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAI,OAAO,SAAS,KAAK,CAAC;AAAA,IAG1B;AAAA,EACF;AACF;","names":[]}
|
|
@@ -52,6 +52,14 @@ function useMutation(mutationOptions, queryClient) {
|
|
|
52
52
|
unsubscribe();
|
|
53
53
|
});
|
|
54
54
|
const resultRefs = (0, import_vue_demi.toRefs)((0, import_vue_demi.readonly)(state));
|
|
55
|
+
(0, import_vue_demi.watch)(
|
|
56
|
+
() => state.error,
|
|
57
|
+
(error) => {
|
|
58
|
+
if (error && (0, import_utils.shouldThrowError)(options.value.throwOnError, [error])) {
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
);
|
|
55
63
|
return {
|
|
56
64
|
...resultRefs,
|
|
57
65
|
mutate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAOO;AACP,wBAAiC;AACjC,
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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 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,sBAOO;AACP,wBAAiC;AACjC,mBAA8D;AAC9D,4BAA+B;AA6CxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,QAAM,SAAS,mBAAe,sCAAe;AAC7C,QAAM,cAAU,0BAAS,MAAM;AAC7B,WAAO,OAAO,2BAAuB,6BAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,mCAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,YAAQ,0BAAS,SAAS,iBAAiB,CAAC;AAElD,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,kCAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,QAAQ,KAAK;AAAA,IACnC;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,sCAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,iBAAa,4BAAO,0BAAS,KAAK,CAAC;AAIzC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,aACA,+BAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
watch
|
|
9
9
|
} from "vue-demi";
|
|
10
10
|
import { MutationObserver } from "@tanstack/query-core";
|
|
11
|
-
import { cloneDeepUnref, updateState } from "./utils.js";
|
|
11
|
+
import { cloneDeepUnref, shouldThrowError, updateState } from "./utils.js";
|
|
12
12
|
import { useQueryClient } from "./useQueryClient.js";
|
|
13
13
|
function useMutation(mutationOptions, queryClient) {
|
|
14
14
|
const client = queryClient || useQueryClient();
|
|
@@ -35,6 +35,14 @@ function useMutation(mutationOptions, queryClient) {
|
|
|
35
35
|
unsubscribe();
|
|
36
36
|
});
|
|
37
37
|
const resultRefs = toRefs(readonly(state));
|
|
38
|
+
watch(
|
|
39
|
+
() => state.error,
|
|
40
|
+
(error) => {
|
|
41
|
+
if (error && shouldThrowError(options.value.throwOnError, [error])) {
|
|
42
|
+
throw error;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
);
|
|
38
46
|
return {
|
|
39
47
|
...resultRefs,
|
|
40
48
|
mutate,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB,mBAAmB;
|
|
1
|
+
{"version":3,"sources":["../../src/useMutation.ts"],"sourcesContent":["import {\n computed,\n onScopeDispose,\n reactive,\n readonly,\n toRefs,\n watch,\n} from 'vue-demi'\nimport { MutationObserver } from '@tanstack/query-core'\nimport { cloneDeepUnref, shouldThrowError, updateState } from './utils'\nimport { useQueryClient } from './useQueryClient'\nimport type { ToRefs } from 'vue-demi'\nimport type {\n DefaultError,\n MutateFunction,\n MutateOptions,\n MutationObserverOptions,\n MutationObserverResult,\n} from '@tanstack/query-core'\nimport type { DistributiveOmit, MaybeRefDeep } from './types'\nimport type { QueryClient } from './queryClient'\n\ntype MutationResult<TData, TError, TVariables, TContext> = DistributiveOmit<\n MutationObserverResult<TData, TError, TVariables, TContext>,\n 'mutate' | 'reset'\n>\n\nexport type UseMutationOptions<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = MaybeRefDeep<MutationObserverOptions<TData, TError, TVariables, TContext>>\n\ntype MutateSyncFunction<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n> = (\n ...options: Parameters<MutateFunction<TData, TError, TVariables, TContext>>\n) => void\n\nexport type UseMutationReturnType<\n TData,\n TError,\n TVariables,\n TContext,\n Result = MutationResult<TData, TError, TVariables, TContext>,\n> = ToRefs<Readonly<Result>> & {\n mutate: MutateSyncFunction<TData, TError, TVariables, TContext>\n mutateAsync: MutateFunction<TData, TError, TVariables, TContext>\n reset: MutationObserverResult<TData, TError, TVariables, TContext>['reset']\n}\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n mutationOptions: MaybeRefDeep<\n MutationObserverOptions<TData, TError, TVariables, TContext>\n >,\n queryClient?: QueryClient,\n): UseMutationReturnType<TData, TError, TVariables, TContext> {\n const client = queryClient || useQueryClient()\n const options = computed(() => {\n return client.defaultMutationOptions(cloneDeepUnref(mutationOptions))\n })\n const observer = new MutationObserver(client, options.value)\n const state = reactive(observer.getCurrentResult())\n\n const unsubscribe = observer.subscribe((result) => {\n updateState(state, result)\n })\n\n const mutate = (\n variables: TVariables,\n mutateOptions?: MutateOptions<TData, TError, TVariables, TContext>,\n ) => {\n observer.mutate(variables, mutateOptions).catch(() => {\n // This is intentional\n })\n }\n\n watch(\n options,\n () => {\n observer.setOptions(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 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,OACK;AACP,SAAS,wBAAwB;AACjC,SAAS,gBAAgB,kBAAkB,mBAAmB;AAC9D,SAAS,sBAAsB;AA6CxB,SAAS,YAMd,iBAGA,aAC4D;AAC5D,QAAM,SAAS,eAAe,eAAe;AAC7C,QAAM,UAAU,SAAS,MAAM;AAC7B,WAAO,OAAO,uBAAuB,eAAe,eAAe,CAAC;AAAA,EACtE,CAAC;AACD,QAAM,WAAW,IAAI,iBAAiB,QAAQ,QAAQ,KAAK;AAC3D,QAAM,QAAQ,SAAS,SAAS,iBAAiB,CAAC;AAElD,QAAM,cAAc,SAAS,UAAU,CAAC,WAAW;AACjD,gBAAY,OAAO,MAAM;AAAA,EAC3B,CAAC;AAED,QAAM,SAAS,CACb,WACA,kBACG;AACH,aAAS,OAAO,WAAW,aAAa,EAAE,MAAM,MAAM;AAAA,IAEtD,CAAC;AAAA,EACH;AAEA;AAAA,IACE;AAAA,IACA,MAAM;AACJ,eAAS,WAAW,QAAQ,KAAK;AAAA,IACnC;AAAA,IACA,EAAE,MAAM,KAAK;AAAA,EACf;AAEA,iBAAe,MAAM;AACnB,gBAAY;AAAA,EACd,CAAC;AAED,QAAM,aAAa,OAAO,SAAS,KAAK,CAAC;AAIzC;AAAA,IACE,MAAM,MAAM;AAAA,IACZ,CAAC,UAAU;AACT,UACE,SACA,iBAAiB,QAAQ,MAAM,cAAc,CAAC,KAAe,CAAC,GAC9D;AACA,cAAM;AAAA,MACR;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,GAAG;AAAA,IACH;AAAA,IACA,aAAa,MAAM;AAAA,IACnB,OAAO,MAAM;AAAA,EACf;AACF;","names":[]}
|
package/build/modern/utils.cjs
CHANGED
|
@@ -24,6 +24,7 @@ __export(utils_exports, {
|
|
|
24
24
|
cloneDeep: () => cloneDeep,
|
|
25
25
|
cloneDeepUnref: () => cloneDeepUnref,
|
|
26
26
|
getClientKey: () => getClientKey,
|
|
27
|
+
shouldThrowError: () => shouldThrowError,
|
|
27
28
|
updateState: () => updateState
|
|
28
29
|
});
|
|
29
30
|
module.exports = __toCommonJS(utils_exports);
|
|
@@ -75,12 +76,19 @@ function isPlainObject(value) {
|
|
|
75
76
|
const prototype = Object.getPrototypeOf(value);
|
|
76
77
|
return prototype === null || prototype === Object.prototype;
|
|
77
78
|
}
|
|
79
|
+
function shouldThrowError(throwOnError, params) {
|
|
80
|
+
if (typeof throwOnError === "function") {
|
|
81
|
+
return throwOnError(...params);
|
|
82
|
+
}
|
|
83
|
+
return !!throwOnError;
|
|
84
|
+
}
|
|
78
85
|
// Annotate the CommonJS export names for ESM import in node:
|
|
79
86
|
0 && (module.exports = {
|
|
80
87
|
VUE_QUERY_CLIENT,
|
|
81
88
|
cloneDeep,
|
|
82
89
|
cloneDeepUnref,
|
|
83
90
|
getClientKey,
|
|
91
|
+
shouldThrowError,
|
|
84
92
|
updateState
|
|
85
93
|
});
|
|
86
94
|
//# 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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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"],"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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,YAAI,uBAAM,GAAG,GAAG;AACd,aAAO,mBAAe,uBAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;","names":[]}
|
|
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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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\nexport function shouldThrowError<T extends (...args: any[]) => boolean>(\n throwOnError: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow throwOnError function to override throwing behavior on a per-error basis\n if (typeof throwOnError === 'function') {\n return throwOnError(...params)\n }\n\n return !!throwOnError\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,YAAI,uBAAM,GAAG,GAAG;AACd,aAAO,mBAAe,uBAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;AAEO,SAAS,iBACd,cACA,QACS;AAET,MAAI,OAAO,iBAAiB,YAAY;AACtC,WAAO,aAAa,GAAG,MAAM;AAAA,EAC/B;AAEA,SAAO,CAAC,CAAC;AACX;","names":[]}
|
package/build/modern/utils.d.cts
CHANGED
|
@@ -6,5 +6,6 @@ declare function getClientKey(key?: string): string;
|
|
|
6
6
|
declare function updateState(state: Record<string, unknown>, update: Record<string, any>): void;
|
|
7
7
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customizer?: (val: MaybeRefDeep<T>) => T | undefined): T;
|
|
8
8
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T;
|
|
9
|
+
declare function shouldThrowError<T extends (...args: any[]) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
9
10
|
|
|
10
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, shouldThrowError, updateState };
|
package/build/modern/utils.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ declare function getClientKey(key?: string): string;
|
|
|
6
6
|
declare function updateState(state: Record<string, unknown>, update: Record<string, any>): void;
|
|
7
7
|
declare function cloneDeep<T>(value: MaybeRefDeep<T>, customizer?: (val: MaybeRefDeep<T>) => T | undefined): T;
|
|
8
8
|
declare function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T;
|
|
9
|
+
declare function shouldThrowError<T extends (...args: any[]) => boolean>(throwOnError: boolean | T | undefined, params: Parameters<T>): boolean;
|
|
9
10
|
|
|
10
|
-
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, updateState };
|
|
11
|
+
export { VUE_QUERY_CLIENT, cloneDeep, cloneDeepUnref, getClientKey, shouldThrowError, updateState };
|
package/build/modern/utils.js
CHANGED
|
@@ -47,11 +47,18 @@ function isPlainObject(value) {
|
|
|
47
47
|
const prototype = Object.getPrototypeOf(value);
|
|
48
48
|
return prototype === null || prototype === Object.prototype;
|
|
49
49
|
}
|
|
50
|
+
function shouldThrowError(throwOnError, params) {
|
|
51
|
+
if (typeof throwOnError === "function") {
|
|
52
|
+
return throwOnError(...params);
|
|
53
|
+
}
|
|
54
|
+
return !!throwOnError;
|
|
55
|
+
}
|
|
50
56
|
export {
|
|
51
57
|
VUE_QUERY_CLIENT,
|
|
52
58
|
cloneDeep,
|
|
53
59
|
cloneDeepUnref,
|
|
54
60
|
getClientKey,
|
|
61
|
+
shouldThrowError,
|
|
55
62
|
updateState
|
|
56
63
|
};
|
|
57
64
|
//# 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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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"],"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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,QAAI,WAAW,UAAa,MAAM,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,QAAI,MAAM,GAAG,GAAG;AACd,aAAO,eAAe,MAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;","names":[]}
|
|
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, unknown>,\n update: Record<string, any>,\n): void {\n Object.keys(state).forEach((key) => {\n state[key] = update[key]\n })\n}\n\nexport function cloneDeep<T>(\n value: MaybeRefDeep<T>,\n customizer?: (val: MaybeRefDeep<T>) => T | undefined,\n): T {\n if (customizer) {\n const result = customizer(value)\n // If it's a ref of undefined, return undefined\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) => cloneDeep(val, customizer)) 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, customizer),\n ])\n return Object.fromEntries(entries)\n }\n\n return value as T\n}\n\nexport function cloneDeepUnref<T>(obj: MaybeRefDeep<T>): T {\n return cloneDeep(obj, (val) => {\n if (isRef(val)) {\n return cloneDeepUnref(unref(val))\n }\n\n return undefined\n })\n}\n\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\nexport function shouldThrowError<T extends (...args: any[]) => boolean>(\n throwOnError: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow throwOnError function to override throwing behavior on a per-error basis\n if (typeof throwOnError === 'function') {\n return throwOnError(...params)\n }\n\n return !!throwOnError\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;AAEO,SAAS,UACd,OACA,YACG;AACH,MAAI,YAAY;AACd,UAAM,SAAS,WAAW,KAAK;AAE/B,QAAI,WAAW,UAAa,MAAM,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,IAAI,CAAC,QAAQ,UAAU,KAAK,UAAU,CAAC;AAAA,EACtD;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,UAAU,KAAK,UAAU;AAAA,IAC3B,CAAC;AACD,WAAO,OAAO,YAAY,OAAO;AAAA,EACnC;AAEA,SAAO;AACT;AAEO,SAAS,eAAkB,KAAyB;AACzD,SAAO,UAAU,KAAK,CAAC,QAAQ;AAC7B,QAAI,MAAM,GAAG,GAAG;AACd,aAAO,eAAe,MAAM,GAAG,CAAC;AAAA,IAClC;AAEA,WAAO;AAAA,EACT,CAAC;AACH;AAEA,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;AAEO,SAAS,iBACd,cACA,QACS;AAET,MAAI,OAAO,iBAAiB,YAAY;AACtC,WAAO,aAAa,GAAG,MAAM;AAAA,EAC/B;AAEA,SAAO,CAAC,CAAC;AACX;","names":[]}
|
package/package.json
CHANGED
|
@@ -332,4 +332,24 @@ describe('useMutation', () => {
|
|
|
332
332
|
})
|
|
333
333
|
})
|
|
334
334
|
})
|
|
335
|
+
|
|
336
|
+
describe('throwOnError', () => {
|
|
337
|
+
test('should evaluate throwOnError when mutation is expected to throw', async () => {
|
|
338
|
+
const err = new Error('Expected mock error. All is well!')
|
|
339
|
+
const boundaryFn = vi.fn()
|
|
340
|
+
const { mutate } = useMutation({
|
|
341
|
+
mutationFn: () => {
|
|
342
|
+
return Promise.reject(err)
|
|
343
|
+
},
|
|
344
|
+
throwOnError: boundaryFn,
|
|
345
|
+
})
|
|
346
|
+
|
|
347
|
+
mutate()
|
|
348
|
+
|
|
349
|
+
await flushPromises()
|
|
350
|
+
|
|
351
|
+
expect(boundaryFn).toHaveBeenCalledTimes(1)
|
|
352
|
+
expect(boundaryFn).toHaveBeenCalledWith(err)
|
|
353
|
+
})
|
|
354
|
+
})
|
|
335
355
|
})
|
|
@@ -235,6 +235,28 @@ describe('useQuery', () => {
|
|
|
235
235
|
expect(status.value).toStrictEqual('pending')
|
|
236
236
|
})
|
|
237
237
|
|
|
238
|
+
describe('throwOnError', () => {
|
|
239
|
+
test('should evaluate throwOnError when query is expected to throw', async () => {
|
|
240
|
+
const boundaryFn = vi.fn()
|
|
241
|
+
useQuery({
|
|
242
|
+
queryKey: ['key0'],
|
|
243
|
+
queryFn: rejectFetcher,
|
|
244
|
+
retry: false,
|
|
245
|
+
throwOnError: boundaryFn,
|
|
246
|
+
})
|
|
247
|
+
|
|
248
|
+
await flushPromises()
|
|
249
|
+
|
|
250
|
+
expect(boundaryFn).toHaveBeenCalledTimes(1)
|
|
251
|
+
expect(boundaryFn).toHaveBeenCalledWith(
|
|
252
|
+
Error('Some error'),
|
|
253
|
+
expect.objectContaining({
|
|
254
|
+
state: expect.objectContaining({ status: 'error' }),
|
|
255
|
+
}),
|
|
256
|
+
)
|
|
257
|
+
})
|
|
258
|
+
})
|
|
259
|
+
|
|
238
260
|
describe('suspense', () => {
|
|
239
261
|
test('should return a Promise', () => {
|
|
240
262
|
const getCurrentInstanceSpy = getCurrentInstance as Mock
|
package/src/useBaseQuery.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
watch,
|
|
8
8
|
} from 'vue-demi'
|
|
9
9
|
import { useQueryClient } from './useQueryClient'
|
|
10
|
-
import { cloneDeepUnref, updateState } from './utils'
|
|
10
|
+
import { cloneDeepUnref, shouldThrowError, updateState } from './utils'
|
|
11
11
|
import type { ToRefs } from 'vue-demi'
|
|
12
12
|
import type {
|
|
13
13
|
DefaultedQueryObserverOptions,
|
|
@@ -146,6 +146,23 @@ export function useBaseQuery<
|
|
|
146
146
|
)
|
|
147
147
|
}
|
|
148
148
|
|
|
149
|
+
// Handle error boundary
|
|
150
|
+
watch(
|
|
151
|
+
() => state.error,
|
|
152
|
+
(error) => {
|
|
153
|
+
if (
|
|
154
|
+
state.isError &&
|
|
155
|
+
!state.isFetching &&
|
|
156
|
+
shouldThrowError(defaultedOptions.value.throwOnError, [
|
|
157
|
+
error as TError,
|
|
158
|
+
observer.getCurrentQuery(),
|
|
159
|
+
])
|
|
160
|
+
) {
|
|
161
|
+
throw error
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
)
|
|
165
|
+
|
|
149
166
|
return {
|
|
150
167
|
...(toRefs(readonly(state)) as ToRefs<
|
|
151
168
|
Readonly<QueryObserverResult<TData, TError>>
|
package/src/useMutation.ts
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
watch,
|
|
8
8
|
} from 'vue-demi'
|
|
9
9
|
import { MutationObserver } from '@tanstack/query-core'
|
|
10
|
-
import { cloneDeepUnref, updateState } from './utils'
|
|
10
|
+
import { cloneDeepUnref, shouldThrowError, updateState } from './utils'
|
|
11
11
|
import { useQueryClient } from './useQueryClient'
|
|
12
12
|
import type { ToRefs } from 'vue-demi'
|
|
13
13
|
import type {
|
|
@@ -100,6 +100,18 @@ export function useMutation<
|
|
|
100
100
|
Readonly<MutationResult<TData, TError, TVariables, TContext>>
|
|
101
101
|
>
|
|
102
102
|
|
|
103
|
+
watch(
|
|
104
|
+
() => state.error,
|
|
105
|
+
(error) => {
|
|
106
|
+
if (
|
|
107
|
+
error &&
|
|
108
|
+
shouldThrowError(options.value.throwOnError, [error as TError])
|
|
109
|
+
) {
|
|
110
|
+
throw error
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
)
|
|
114
|
+
|
|
103
115
|
return {
|
|
104
116
|
...resultRefs,
|
|
105
117
|
mutate,
|
package/src/utils.ts
CHANGED
|
@@ -65,3 +65,15 @@ function isPlainObject(value: unknown): value is Object {
|
|
|
65
65
|
const prototype = Object.getPrototypeOf(value)
|
|
66
66
|
return prototype === null || prototype === Object.prototype
|
|
67
67
|
}
|
|
68
|
+
|
|
69
|
+
export function shouldThrowError<T extends (...args: any[]) => boolean>(
|
|
70
|
+
throwOnError: boolean | T | undefined,
|
|
71
|
+
params: Parameters<T>,
|
|
72
|
+
): boolean {
|
|
73
|
+
// Allow throwOnError function to override throwing behavior on a per-error basis
|
|
74
|
+
if (typeof throwOnError === 'function') {
|
|
75
|
+
return throwOnError(...params)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return !!throwOnError
|
|
79
|
+
}
|