@tanstack/react-query 5.0.0-alpha.6 → 5.0.0-alpha.62
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/codemods/__testfixtures__/default-import.input.tsx +94 -0
- package/build/codemods/__testfixtures__/default-import.output.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.input.tsx +96 -0
- package/build/codemods/__testfixtures__/named-import.output.tsx +98 -0
- package/build/codemods/__testfixtures__/namespaced-import.input.tsx +86 -0
- package/build/codemods/__testfixtures__/namespaced-import.output.tsx +88 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.input.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-identifier.output.tsx +49 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.input.tsx +128 -0
- package/build/codemods/__testfixtures__/parameter-is-object-expression.output.tsx +175 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.input.tsx +10 -0
- package/build/codemods/__testfixtures__/replace-import-specifier.output.tsx +10 -0
- package/build/codemods/__testfixtures__/type-arguments.input.tsx +25 -0
- package/build/codemods/__testfixtures__/type-arguments.output.tsx +31 -0
- package/build/codemods/__tests__/key-transformation.test.js +32 -0
- package/build/codemods/__tests__/replace-import-specifier.test.js +12 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.input.tsx +199 -0
- package/build/codemods/remove-overloads/__testfixtures__/default-import.output.tsx +484 -0
- package/build/codemods/remove-overloads/__tests__/remove-overloads.test.js +6 -0
- package/build/codemods/remove-overloads/remove-overloads.js +59 -0
- package/build/codemods/remove-overloads/transformers/filter-aware-usage-transformer.js +153 -0
- package/build/codemods/remove-overloads/transformers/query-fn-aware-usage-transformer.js +188 -0
- package/build/codemods/remove-overloads/utils/index.js +124 -0
- package/build/codemods/remove-overloads/utils/unknown-usage-error.js +27 -0
- package/build/codemods/src/utils/index.js +205 -0
- package/build/codemods/src/v4/key-transformation.js +138 -0
- package/build/codemods/src/v4/replace-import-specifier.js +25 -0
- package/build/codemods/transformers/query-cache-transformer.js +116 -0
- package/build/codemods/transformers/query-client-transformer.js +48 -0
- package/build/codemods/transformers/use-query-like-transformer.js +32 -0
- package/build/codemods/utils/replacers/key-replacer.js +164 -0
- package/build/lib/HydrationBoundary.cjs +50 -0
- package/build/lib/{HydrationBoundary.mjs.map → HydrationBoundary.cjs.map} +1 -1
- package/build/lib/HydrationBoundary.d.ts +1 -0
- package/build/lib/HydrationBoundary.d.ts.map +1 -0
- package/build/lib/HydrationBoundary.js +9 -29
- package/build/lib/HydrationBoundary.js.map +1 -1
- package/build/lib/QueryClientProvider.cjs +54 -0
- package/build/lib/QueryClientProvider.cjs.map +1 -0
- package/build/lib/QueryClientProvider.d.ts +2 -1
- package/build/lib/QueryClientProvider.d.ts.map +1 -0
- package/build/lib/QueryClientProvider.js +7 -29
- package/build/lib/QueryClientProvider.js.map +1 -1
- package/build/lib/QueryErrorResetBoundary.cjs +60 -0
- package/build/lib/{QueryErrorResetBoundary.mjs.map → QueryErrorResetBoundary.cjs.map} +1 -1
- package/build/lib/QueryErrorResetBoundary.d.ts +2 -1
- package/build/lib/QueryErrorResetBoundary.d.ts.map +1 -0
- package/build/lib/QueryErrorResetBoundary.js +7 -28
- package/build/lib/QueryErrorResetBoundary.js.map +1 -1
- package/build/lib/__tests__/HydrationBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/HydrationBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts +1 -0
- package/build/lib/__tests__/QueryClientProvider.test.d.ts.map +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts +1 -0
- package/build/lib/__tests__/QueryResetErrorBoundary.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts +1 -0
- package/build/lib/__tests__/ssr-hydration.test.d.ts.map +1 -0
- package/build/lib/__tests__/ssr.test.d.ts +1 -0
- package/build/lib/__tests__/ssr.test.d.ts.map +1 -0
- package/build/lib/__tests__/suspense.test.d.ts +1 -0
- package/build/lib/__tests__/suspense.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts +1 -0
- package/build/lib/__tests__/useInfiniteQuery.type.test.d.ts.map +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts.map +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts +1 -0
- package/build/lib/__tests__/useMutationState.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts.map +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.types.test.d.ts.map +1 -0
- package/build/lib/__tests__/utils.d.ts +6 -5
- package/build/lib/__tests__/utils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.cjs +51 -0
- package/build/lib/errorBoundaryUtils.cjs.map +1 -0
- package/build/lib/errorBoundaryUtils.d.ts +4 -3
- package/build/lib/errorBoundaryUtils.d.ts.map +1 -0
- package/build/lib/errorBoundaryUtils.js +8 -30
- package/build/lib/errorBoundaryUtils.js.map +1 -1
- package/build/lib/index.cjs +39 -0
- package/build/lib/index.cjs.map +1 -0
- package/build/lib/index.d.ts +2 -1
- package/build/lib/index.d.ts.map +1 -0
- package/build/lib/index.js +11 -37
- package/build/lib/index.js.map +1 -1
- package/build/lib/isRestoring.cjs +31 -0
- package/build/lib/isRestoring.cjs.map +1 -0
- package/build/lib/isRestoring.d.ts +1 -0
- package/build/lib/isRestoring.d.ts.map +1 -0
- package/build/lib/isRestoring.js +5 -26
- package/build/lib/isRestoring.js.map +1 -1
- package/build/lib/{suspense.mjs → suspense.cjs} +8 -10
- package/build/lib/suspense.cjs.map +1 -0
- package/build/lib/suspense.d.ts +3 -5
- package/build/lib/suspense.d.ts.map +1 -0
- package/build/lib/suspense.js +3 -15
- package/build/lib/suspense.js.map +1 -1
- package/build/lib/types.d.ts +11 -10
- package/build/lib/types.d.ts.map +1 -0
- package/build/lib/useBaseQuery.cjs +80 -0
- package/build/lib/useBaseQuery.cjs.map +1 -0
- package/build/lib/useBaseQuery.d.ts +1 -0
- package/build/lib/useBaseQuery.d.ts.map +1 -0
- package/build/lib/useBaseQuery.js +30 -54
- package/build/lib/useBaseQuery.js.map +1 -1
- package/build/lib/useInfiniteQuery.cjs +15 -0
- package/build/lib/useInfiniteQuery.cjs.map +1 -0
- package/build/lib/useInfiniteQuery.d.ts +1 -0
- package/build/lib/useInfiniteQuery.d.ts.map +1 -0
- package/build/lib/useInfiniteQuery.js +6 -7
- package/build/lib/useInfiniteQuery.js.map +1 -1
- package/build/lib/useIsFetching.cjs +34 -0
- package/build/lib/useIsFetching.cjs.map +1 -0
- package/build/lib/useIsFetching.d.ts +1 -0
- package/build/lib/useIsFetching.d.ts.map +1 -0
- package/build/lib/useIsFetching.js +7 -27
- package/build/lib/useIsFetching.js.map +1 -1
- package/build/lib/useMutation.cjs +54 -0
- package/build/lib/useMutation.cjs.map +1 -0
- package/build/lib/useMutation.d.ts +1 -0
- package/build/lib/useMutation.d.ts.map +1 -0
- package/build/lib/useMutation.js +12 -32
- package/build/lib/useMutation.js.map +1 -1
- package/build/lib/useMutationState.cjs +60 -0
- package/build/lib/useMutationState.cjs.map +1 -0
- package/build/lib/useMutationState.d.ts +4 -3
- package/build/lib/useMutationState.d.ts.map +1 -0
- package/build/lib/useMutationState.js +13 -34
- package/build/lib/useMutationState.js.map +1 -1
- package/build/lib/useQueries.cjs +99 -0
- package/build/lib/useQueries.cjs.map +1 -0
- package/build/lib/useQueries.d.ts +10 -8
- package/build/lib/useQueries.d.ts.map +1 -0
- package/build/lib/useQueries.js +52 -67
- package/build/lib/useQueries.js.map +1 -1
- package/build/lib/useQuery.cjs +19 -0
- package/build/lib/useQuery.cjs.map +1 -0
- package/build/lib/useQuery.d.ts +5 -2
- package/build/lib/useQuery.d.ts.map +1 -0
- package/build/lib/useQuery.js +8 -5
- package/build/lib/useQuery.js.map +1 -1
- package/build/lib/{utils.esm.js → utils.cjs} +4 -2
- package/build/lib/{utils.mjs.map → utils.cjs.map} +1 -1
- package/build/lib/utils.d.ts +1 -0
- package/build/lib/utils.d.ts.map +1 -0
- package/build/lib/utils.js +1 -3
- package/build/lib/utils.js.map +1 -1
- package/package.json +24 -15
- package/src/__tests__/QueryResetErrorBoundary.test.tsx +752 -620
- package/src/__tests__/ssr-hydration.test.tsx +2 -2
- package/src/__tests__/suspense.test.tsx +6 -88
- package/src/__tests__/useInfiniteQuery.type.test.tsx +0 -27
- package/src/__tests__/useMutation.test.tsx +4 -4
- package/src/__tests__/useMutationState.test.tsx +23 -0
- package/src/__tests__/useQueries.test.tsx +206 -83
- package/src/__tests__/useQuery.test.tsx +246 -338
- package/src/__tests__/useQuery.types.test.tsx +21 -1
- package/src/errorBoundaryUtils.ts +6 -5
- package/src/index.ts +1 -1
- package/src/suspense.ts +9 -15
- package/src/useBaseQuery.ts +12 -23
- package/src/useInfiniteQuery.ts +1 -0
- package/src/useIsFetching.ts +1 -0
- package/src/useMutation.ts +2 -1
- package/src/useMutationState.ts +4 -3
- package/src/useQueries.ts +44 -26
- package/src/useQuery.ts +23 -0
- package/build/lib/HydrationBoundary.esm.js +0 -28
- package/build/lib/HydrationBoundary.esm.js.map +0 -1
- package/build/lib/HydrationBoundary.mjs +0 -28
- package/build/lib/QueryClientProvider.esm.js +0 -30
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.mjs +0 -30
- package/build/lib/QueryClientProvider.mjs.map +0 -1
- package/build/lib/QueryErrorResetBoundary.esm.js +0 -37
- package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.mjs +0 -37
- package/build/lib/errorBoundaryUtils.esm.js +0 -27
- package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
- package/build/lib/errorBoundaryUtils.mjs +0 -27
- package/build/lib/errorBoundaryUtils.mjs.map +0 -1
- package/build/lib/index.esm.js +0 -12
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/index.mjs +0 -12
- package/build/lib/index.mjs.map +0 -1
- package/build/lib/isRestoring.esm.js +0 -8
- package/build/lib/isRestoring.esm.js.map +0 -1
- package/build/lib/isRestoring.mjs +0 -8
- package/build/lib/isRestoring.mjs.map +0 -1
- package/build/lib/suspense.esm.js +0 -24
- package/build/lib/suspense.esm.js.map +0 -1
- package/build/lib/suspense.mjs.map +0 -1
- package/build/lib/useBaseQuery.esm.js +0 -62
- package/build/lib/useBaseQuery.esm.js.map +0 -1
- package/build/lib/useBaseQuery.mjs +0 -62
- package/build/lib/useBaseQuery.mjs.map +0 -1
- package/build/lib/useInfiniteQuery.esm.js +0 -12
- package/build/lib/useInfiniteQuery.esm.js.map +0 -1
- package/build/lib/useInfiniteQuery.mjs +0 -12
- package/build/lib/useInfiniteQuery.mjs.map +0 -1
- package/build/lib/useIsFetching.esm.js +0 -12
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useIsFetching.mjs +0 -12
- package/build/lib/useIsFetching.mjs.map +0 -1
- package/build/lib/useMutation.esm.js +0 -32
- package/build/lib/useMutation.esm.js.map +0 -1
- package/build/lib/useMutation.mjs +0 -32
- package/build/lib/useMutation.mjs.map +0 -1
- package/build/lib/useMutationState.esm.js +0 -37
- package/build/lib/useMutationState.esm.js.map +0 -1
- package/build/lib/useMutationState.mjs +0 -37
- package/build/lib/useMutationState.mjs.map +0 -1
- package/build/lib/useQueries.esm.js +0 -72
- package/build/lib/useQueries.esm.js.map +0 -1
- package/build/lib/useQueries.mjs +0 -69
- package/build/lib/useQueries.mjs.map +0 -1
- package/build/lib/useQuery.esm.js +0 -11
- package/build/lib/useQuery.esm.js.map +0 -1
- package/build/lib/useQuery.mjs +0 -11
- package/build/lib/useQuery.mjs.map +0 -1
- package/build/lib/utils.esm.js.map +0 -1
- package/build/lib/utils.mjs +0 -10
- package/build/umd/index.development.js +0 -3040
- package/build/umd/index.development.js.map +0 -1
- package/build/umd/index.production.js +0 -2
- package/build/umd/index.production.js.map +0 -1
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { shouldThrowError } from './utils.mjs';
|
|
3
|
-
|
|
4
|
-
const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
5
|
-
if (options.suspense || options.throwErrors) {
|
|
6
|
-
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
7
|
-
if (!errorResetBoundary.isReset()) {
|
|
8
|
-
options.retryOnMount = false;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
};
|
|
12
|
-
const useClearResetErrorBoundary = errorResetBoundary => {
|
|
13
|
-
React.useEffect(() => {
|
|
14
|
-
errorResetBoundary.clearReset();
|
|
15
|
-
}, [errorResetBoundary]);
|
|
16
|
-
};
|
|
17
|
-
const getHasError = ({
|
|
18
|
-
result,
|
|
19
|
-
errorResetBoundary,
|
|
20
|
-
throwErrors,
|
|
21
|
-
query
|
|
22
|
-
}) => {
|
|
23
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(throwErrors, [result.error, query]);
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
export { ensurePreventErrorBoundaryRetry, getHasError, useClearResetErrorBoundary };
|
|
27
|
-
//# sourceMappingURL=errorBoundaryUtils.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorBoundaryUtils.mjs","sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["import type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowErrors,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\nimport * as React from 'react'\nimport { shouldThrowError } from './utils'\n\nexport const ensurePreventErrorBoundaryRetry = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n if (options.suspense || options.throwErrors) {\n // Prevent retrying failed query if the error boundary has not been reset yet\n if (!errorResetBoundary.isReset()) {\n options.retryOnMount = false\n }\n }\n}\n\nexport const useClearResetErrorBoundary = (\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) => {\n React.useEffect(() => {\n errorResetBoundary.clearReset()\n }, [errorResetBoundary])\n}\n\nexport const getHasError = <\n TData,\n TError,\n TQueryFnData,\n TQueryData,\n TQueryKey extends QueryKey,\n>({\n result,\n errorResetBoundary,\n throwErrors,\n query,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwErrors: ThrowErrors<TQueryFnData, TError, TQueryData, TQueryKey>\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>\n}) => {\n return (\n result.isError &&\n !errorResetBoundary.isReset() &&\n !result.isFetching &&\n shouldThrowError(throwErrors, [result.error, query])\n )\n}\n"],"names":["ensurePreventErrorBoundaryRetry","options","errorResetBoundary","suspense","throwErrors","isReset","retryOnMount","useClearResetErrorBoundary","React","useEffect","clearReset","getHasError","result","query","isError","isFetching","shouldThrowError","error"],"mappings":";;;MAWaA,+BAA+B,GAAG,CAO7CC,OAMC,EACDC,kBAAgD,KAC7C;AACH,EAAA,IAAID,OAAO,CAACE,QAAQ,IAAIF,OAAO,CAACG,WAAW,EAAE;AAC3C;AACA,IAAA,IAAI,CAACF,kBAAkB,CAACG,OAAO,EAAE,EAAE;MACjCJ,OAAO,CAACK,YAAY,GAAG,KAAK,CAAA;AAC9B,KAAA;AACF,GAAA;AACF,EAAC;AAEYC,MAAAA,0BAA0B,GACrCL,kBAAgD,IAC7C;EACHM,KAAK,CAACC,SAAS,CAAC,MAAM;IACpBP,kBAAkB,CAACQ,UAAU,EAAE,CAAA;AACjC,GAAC,EAAE,CAACR,kBAAkB,CAAC,CAAC,CAAA;AAC1B,EAAC;AAEM,MAAMS,WAAW,GAAG,CAMzB;EACAC,MAAM;EACNV,kBAAkB;EAClBE,WAAW;AACXS,EAAAA,KAAAA;AAMF,CAAC,KAAK;EACJ,OACED,MAAM,CAACE,OAAO,IACd,CAACZ,kBAAkB,CAACG,OAAO,EAAE,IAC7B,CAACO,MAAM,CAACG,UAAU,IAClBC,gBAAgB,CAACZ,WAAW,EAAE,CAACQ,MAAM,CAACK,KAAK,EAAEJ,KAAK,CAAC,CAAC,CAAA;AAExD;;;;"}
|
package/build/lib/index.esm.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/query-core';
|
|
2
|
-
export { useQueries } from './useQueries.esm.js';
|
|
3
|
-
export { useQuery } from './useQuery.esm.js';
|
|
4
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
export { HydrationBoundary } from './HydrationBoundary.esm.js';
|
|
6
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary } from './QueryErrorResetBoundary.esm.js';
|
|
7
|
-
export { useIsFetching } from './useIsFetching.esm.js';
|
|
8
|
-
export { useIsMutating, useMutationState } from './useMutationState.esm.js';
|
|
9
|
-
export { useMutation } from './useMutation.esm.js';
|
|
10
|
-
export { useInfiniteQuery } from './useInfiniteQuery.esm.js';
|
|
11
|
-
export { IsRestoringProvider, useIsRestoring } from './isRestoring.esm.js';
|
|
12
|
-
//# sourceMappingURL=index.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.esm.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
package/build/lib/index.mjs
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from '@tanstack/query-core';
|
|
2
|
-
export { useQueries } from './useQueries.mjs';
|
|
3
|
-
export { useQuery } from './useQuery.mjs';
|
|
4
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
export { HydrationBoundary } from './HydrationBoundary.mjs';
|
|
6
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary } from './QueryErrorResetBoundary.mjs';
|
|
7
|
-
export { useIsFetching } from './useIsFetching.mjs';
|
|
8
|
-
export { useIsMutating, useMutationState } from './useMutationState.mjs';
|
|
9
|
-
export { useMutation } from './useMutation.mjs';
|
|
10
|
-
export { useInfiniteQuery } from './useInfiniteQuery.mjs';
|
|
11
|
-
export { IsRestoringProvider, useIsRestoring } from './isRestoring.mjs';
|
|
12
|
-
//# sourceMappingURL=index.mjs.map
|
package/build/lib/index.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
const IsRestoringContext = /*#__PURE__*/React.createContext(false);
|
|
4
|
-
const useIsRestoring = () => React.useContext(IsRestoringContext);
|
|
5
|
-
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
6
|
-
|
|
7
|
-
export { IsRestoringProvider, useIsRestoring };
|
|
8
|
-
//# sourceMappingURL=isRestoring.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isRestoring.esm.js","sources":["../../src/isRestoring.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nconst IsRestoringContext = React.createContext(false)\n\nexport const useIsRestoring = () => React.useContext(IsRestoringContext)\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"names":["IsRestoringContext","React","createContext","useIsRestoring","useContext","IsRestoringProvider","Provider"],"mappings":";;AAGA,MAAMA,kBAAkB,gBAAGC,KAAK,CAACC,aAAa,CAAC,KAAK,CAAC,CAAA;AAE9C,MAAMC,cAAc,GAAG,MAAMF,KAAK,CAACG,UAAU,CAACJ,kBAAkB,EAAC;AAC3DK,MAAAA,mBAAmB,GAAGL,kBAAkB,CAACM;;;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
|
|
3
|
-
const IsRestoringContext = /*#__PURE__*/React.createContext(false);
|
|
4
|
-
const useIsRestoring = () => React.useContext(IsRestoringContext);
|
|
5
|
-
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
6
|
-
|
|
7
|
-
export { IsRestoringProvider, useIsRestoring };
|
|
8
|
-
//# sourceMappingURL=isRestoring.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"isRestoring.mjs","sources":["../../src/isRestoring.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nconst IsRestoringContext = React.createContext(false)\n\nexport const useIsRestoring = () => React.useContext(IsRestoringContext)\nexport const IsRestoringProvider = IsRestoringContext.Provider\n"],"names":["IsRestoringContext","React","createContext","useIsRestoring","useContext","IsRestoringProvider","Provider"],"mappings":";;AAGA,MAAMA,kBAAkB,gBAAGC,KAAK,CAACC,aAAa,CAAC,KAAK,CAAC,CAAA;AAE9C,MAAMC,cAAc,GAAG,MAAMF,KAAK,CAACG,UAAU,CAACJ,kBAAkB,EAAC;AAC3DK,MAAAA,mBAAmB,GAAGL,kBAAkB,CAACM;;;;"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const ensureStaleTime = defaultedOptions => {
|
|
2
|
-
if (defaultedOptions.suspense) {
|
|
3
|
-
// Always set stale time when using suspense to prevent
|
|
4
|
-
// fetching again when directly mounting after suspending
|
|
5
|
-
if (typeof defaultedOptions.staleTime !== 'number') {
|
|
6
|
-
defaultedOptions.staleTime = 1000;
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
const willFetch = (result, isRestoring) => result.isLoading && result.isFetching && !isRestoring;
|
|
11
|
-
const shouldSuspend = (defaultedOptions, result, isRestoring) => (defaultedOptions == null ? void 0 : defaultedOptions.suspense) && willFetch(result, isRestoring);
|
|
12
|
-
const fetchOptimistic = (defaultedOptions, observer, errorResetBoundary) => observer.fetchOptimistic(defaultedOptions).then(({
|
|
13
|
-
data
|
|
14
|
-
}) => {
|
|
15
|
-
defaultedOptions.onSuccess == null ? void 0 : defaultedOptions.onSuccess(data);
|
|
16
|
-
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(data, null);
|
|
17
|
-
}).catch(error => {
|
|
18
|
-
errorResetBoundary.clearReset();
|
|
19
|
-
defaultedOptions.onError == null ? void 0 : defaultedOptions.onError(error);
|
|
20
|
-
defaultedOptions.onSettled == null ? void 0 : defaultedOptions.onSettled(undefined, error);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
export { ensureStaleTime, fetchOptimistic, shouldSuspend, willFetch };
|
|
24
|
-
//# sourceMappingURL=suspense.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"suspense.esm.js","sources":["../../src/suspense.ts"],"sourcesContent":["import type { DefaultedQueryObserverOptions } from '@tanstack/query-core'\nimport type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\nimport type { QueryObserverResult } from '@tanstack/query-core'\nimport type { QueryKey } from '@tanstack/query-core'\n\nexport const ensureStaleTime = (\n defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,\n) => {\n if (defaultedOptions.suspense) {\n // Always set stale time when using suspense to prevent\n // fetching again when directly mounting after suspending\n if (typeof defaultedOptions.staleTime !== 'number') {\n defaultedOptions.staleTime = 1000\n }\n }\n}\n\nexport const willFetch = (\n result: QueryObserverResult<any, any>,\n isRestoring: boolean,\n) => result.isLoading && result.isFetching && !isRestoring\n\nexport const shouldSuspend = (\n defaultedOptions:\n | DefaultedQueryObserverOptions<any, any, any, any, any>\n | undefined,\n result: QueryObserverResult<any, any>,\n isRestoring: boolean,\n) => defaultedOptions?.suspense && willFetch(result, isRestoring)\n\nexport const fetchOptimistic = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n defaultedOptions: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) =>\n observer\n .fetchOptimistic(defaultedOptions)\n .then(({ data }) => {\n defaultedOptions.onSuccess?.(data as TData)\n defaultedOptions.onSettled?.(data, null)\n })\n .catch((error) => {\n errorResetBoundary.clearReset()\n defaultedOptions.onError?.(error)\n defaultedOptions.onSettled?.(undefined, error)\n })\n"],"names":["ensureStaleTime","defaultedOptions","suspense","staleTime","willFetch","result","isRestoring","isLoading","isFetching","shouldSuspend","fetchOptimistic","observer","errorResetBoundary","then","data","onSuccess","onSettled","catch","error","clearReset","onError","undefined"],"mappings":"AAMaA,MAAAA,eAAe,GAC1BC,gBAAwE,IACrE;EACH,IAAIA,gBAAgB,CAACC,QAAQ,EAAE;AAC7B;AACA;AACA,IAAA,IAAI,OAAOD,gBAAgB,CAACE,SAAS,KAAK,QAAQ,EAAE;MAClDF,gBAAgB,CAACE,SAAS,GAAG,IAAI,CAAA;AACnC,KAAA;AACF,GAAA;AACF,EAAC;MAEYC,SAAS,GAAG,CACvBC,MAAqC,EACrCC,WAAoB,KACjBD,MAAM,CAACE,SAAS,IAAIF,MAAM,CAACG,UAAU,IAAI,CAACF,YAAW;AAEnD,MAAMG,aAAa,GAAG,CAC3BR,gBAEa,EACbI,MAAqC,EACrCC,WAAoB,KACjB,CAAAL,gBAAgB,IAAhBA,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,gBAAgB,CAAEC,QAAQ,KAAIE,SAAS,CAACC,MAAM,EAAEC,WAAW,EAAC;MAEpDI,eAAe,GAAG,CAO7BT,gBAMC,EACDU,QAA2E,EAC3EC,kBAAgD,KAEhDD,QAAQ,CACLD,eAAe,CAACT,gBAAgB,CAAC,CACjCY,IAAI,CAAC,CAAC;AAAEC,EAAAA,IAAAA;AAAK,CAAC,KAAK;EAClBb,gBAAgB,CAACc,SAAS,IAA1Bd,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,gBAAgB,CAACc,SAAS,CAAGD,IAAI,CAAU,CAAA;EAC3Cb,gBAAgB,CAACe,SAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAA1Bf,gBAAgB,CAACe,SAAS,CAAGF,IAAI,EAAE,IAAI,CAAC,CAAA;AAC1C,CAAC,CAAC,CACDG,KAAK,CAAEC,KAAK,IAAK;EAChBN,kBAAkB,CAACO,UAAU,EAAE,CAAA;EAC/BlB,gBAAgB,CAACmB,OAAO,IAAxBnB,IAAAA,GAAAA,KAAAA,CAAAA,GAAAA,gBAAgB,CAACmB,OAAO,CAAGF,KAAK,CAAC,CAAA;EACjCjB,gBAAgB,CAACe,SAAS,IAAA,IAAA,GAAA,KAAA,CAAA,GAA1Bf,gBAAgB,CAACe,SAAS,CAAGK,SAAS,EAAEH,KAAK,CAAC,CAAA;AAChD,CAAC;;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"suspense.mjs","sources":["../../src/suspense.ts"],"sourcesContent":["import type { DefaultedQueryObserverOptions } from '@tanstack/query-core'\nimport type { QueryObserver } from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\nimport type { QueryObserverResult } from '@tanstack/query-core'\nimport type { QueryKey } from '@tanstack/query-core'\n\nexport const ensureStaleTime = (\n defaultedOptions: DefaultedQueryObserverOptions<any, any, any, any, any>,\n) => {\n if (defaultedOptions.suspense) {\n // Always set stale time when using suspense to prevent\n // fetching again when directly mounting after suspending\n if (typeof defaultedOptions.staleTime !== 'number') {\n defaultedOptions.staleTime = 1000\n }\n }\n}\n\nexport const willFetch = (\n result: QueryObserverResult<any, any>,\n isRestoring: boolean,\n) => result.isLoading && result.isFetching && !isRestoring\n\nexport const shouldSuspend = (\n defaultedOptions:\n | DefaultedQueryObserverOptions<any, any, any, any, any>\n | undefined,\n result: QueryObserverResult<any, any>,\n isRestoring: boolean,\n) => defaultedOptions?.suspense && willFetch(result, isRestoring)\n\nexport const fetchOptimistic = <\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n defaultedOptions: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n observer: QueryObserver<TQueryFnData, TError, TData, TQueryData, TQueryKey>,\n errorResetBoundary: QueryErrorResetBoundaryValue,\n) =>\n observer\n .fetchOptimistic(defaultedOptions)\n .then(({ data }) => {\n defaultedOptions.onSuccess?.(data as TData)\n defaultedOptions.onSettled?.(data, null)\n })\n .catch((error) => {\n errorResetBoundary.clearReset()\n defaultedOptions.onError?.(error)\n defaultedOptions.onSettled?.(undefined, error)\n })\n"],"names":["ensureStaleTime","defaultedOptions","suspense","staleTime","willFetch","result","isRestoring","isLoading","isFetching","shouldSuspend","fetchOptimistic","observer","errorResetBoundary","then","data","onSuccess","onSettled","catch","error","clearReset","onError","undefined"],"mappings":"AAMaA,MAAAA,eAAe,GAC1BC,gBAAwE,IACrE;EACH,IAAIA,gBAAgB,CAACC,QAAQ,EAAE;AAC7B;AACA;AACA,IAAA,IAAI,OAAOD,gBAAgB,CAACE,SAAS,KAAK,QAAQ,EAAE;MAClDF,gBAAgB,CAACE,SAAS,GAAG,IAAI,CAAA;AACnC,KAAA;AACF,GAAA;AACF,EAAC;MAEYC,SAAS,GAAG,CACvBC,MAAqC,EACrCC,WAAoB,KACjBD,MAAM,CAACE,SAAS,IAAIF,MAAM,CAACG,UAAU,IAAI,CAACF,YAAW;MAE7CG,aAAa,GAAG,CAC3BR,gBAEa,EACbI,MAAqC,EACrCC,WAAoB,KACjBL,gBAAgB,EAAEC,QAAQ,IAAIE,SAAS,CAACC,MAAM,EAAEC,WAAW,EAAC;MAEpDI,eAAe,GAAG,CAO7BT,gBAMC,EACDU,QAA2E,EAC3EC,kBAAgD,KAEhDD,QAAQ,CACLD,eAAe,CAACT,gBAAgB,CAAC,CACjCY,IAAI,CAAC,CAAC;AAAEC,EAAAA,IAAAA;AAAK,CAAC,KAAK;AAClBb,EAAAA,gBAAgB,CAACc,SAAS,GAAGD,IAAI,CAAU,CAAA;AAC3Cb,EAAAA,gBAAgB,CAACe,SAAS,GAAGF,IAAI,EAAE,IAAI,CAAC,CAAA;AAC1C,CAAC,CAAC,CACDG,KAAK,CAAEC,KAAK,IAAK;EAChBN,kBAAkB,CAACO,UAAU,EAAE,CAAA;AAC/BlB,EAAAA,gBAAgB,CAACmB,OAAO,GAAGF,KAAK,CAAC,CAAA;AACjCjB,EAAAA,gBAAgB,CAACe,SAAS,GAAGK,SAAS,EAAEH,KAAK,CAAC,CAAA;AAChD,CAAC;;;;"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.esm.js';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
import { useIsRestoring } from './isRestoring.esm.js';
|
|
6
|
-
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.esm.js';
|
|
7
|
-
import { ensureStaleTime, shouldSuspend, fetchOptimistic } from './suspense.esm.js';
|
|
8
|
-
|
|
9
|
-
function useBaseQuery(options, Observer, queryClient) {
|
|
10
|
-
const client = useQueryClient(queryClient);
|
|
11
|
-
const isRestoring = useIsRestoring();
|
|
12
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
13
|
-
const defaultedOptions = client.defaultQueryOptions(options);
|
|
14
|
-
|
|
15
|
-
// Make sure results are optimistically set in fetching state before subscribing or updating options
|
|
16
|
-
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
17
|
-
|
|
18
|
-
// Include callbacks in batch renders
|
|
19
|
-
if (defaultedOptions.onError) {
|
|
20
|
-
defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
|
|
21
|
-
}
|
|
22
|
-
if (defaultedOptions.onSuccess) {
|
|
23
|
-
defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
|
|
24
|
-
}
|
|
25
|
-
if (defaultedOptions.onSettled) {
|
|
26
|
-
defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
|
|
27
|
-
}
|
|
28
|
-
ensureStaleTime(defaultedOptions);
|
|
29
|
-
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
|
|
30
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
31
|
-
const [observer] = React.useState(() => new Observer(client, defaultedOptions));
|
|
32
|
-
const result = observer.getOptimisticResult(defaultedOptions);
|
|
33
|
-
React.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
34
|
-
React.useEffect(() => {
|
|
35
|
-
// Do not notify on updates because of changes in the options because
|
|
36
|
-
// these changes should already be reflected in the optimistic result.
|
|
37
|
-
observer.setOptions(defaultedOptions, {
|
|
38
|
-
listeners: false
|
|
39
|
-
});
|
|
40
|
-
}, [defaultedOptions, observer]);
|
|
41
|
-
|
|
42
|
-
// Handle suspense
|
|
43
|
-
if (shouldSuspend(defaultedOptions, result, isRestoring)) {
|
|
44
|
-
throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Handle error boundary
|
|
48
|
-
if (getHasError({
|
|
49
|
-
result,
|
|
50
|
-
errorResetBoundary,
|
|
51
|
-
throwErrors: defaultedOptions.throwErrors,
|
|
52
|
-
query: observer.getCurrentQuery()
|
|
53
|
-
})) {
|
|
54
|
-
throw result.error;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Handle result property usage tracking
|
|
58
|
-
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { useBaseQuery };
|
|
62
|
-
//# sourceMappingURL=useBaseQuery.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.esm.js","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import * as React from 'react'\n\nimport type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'\nimport { notifyManager } from '@tanstack/query-core'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { UseBaseQueryOptions } from './types'\nimport { useIsRestoring } from './isRestoring'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport { ensureStaleTime, shouldSuspend, fetchOptimistic } from './suspense'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n) {\n const client = useQueryClient(queryClient)\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const defaultedOptions = client.defaultQueryOptions(options)\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n // Include callbacks in batch renders\n if (defaultedOptions.onError) {\n defaultedOptions.onError = notifyManager.batchCalls(\n defaultedOptions.onError,\n )\n }\n\n if (defaultedOptions.onSuccess) {\n defaultedOptions.onSuccess = notifyManager.batchCalls(\n defaultedOptions.onSuccess,\n )\n }\n\n if (defaultedOptions.onSettled) {\n defaultedOptions.onSettled = notifyManager.batchCalls(\n defaultedOptions.onSettled,\n )\n }\n\n ensureStaleTime(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = React.useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n const result = observer.getOptimisticResult(defaultedOptions)\n\n React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n isRestoring\n ? () => undefined\n : observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer, isRestoring],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n React.useEffect(() => {\n // Do not notify on updates because of changes in the options because\n // these changes should already be reflected in the optimistic result.\n observer.setOptions(defaultedOptions, { listeners: false })\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result, isRestoring)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwErrors: defaultedOptions.throwErrors,\n query: observer.getCurrentQuery(),\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"names":["useBaseQuery","options","Observer","queryClient","client","useQueryClient","isRestoring","useIsRestoring","errorResetBoundary","useQueryErrorResetBoundary","defaultedOptions","defaultQueryOptions","_optimisticResults","onError","notifyManager","batchCalls","onSuccess","onSettled","ensureStaleTime","ensurePreventErrorBoundaryRetry","useClearResetErrorBoundary","observer","React","useState","result","getOptimisticResult","useSyncExternalStore","useCallback","onStoreChange","undefined","subscribe","getCurrentResult","useEffect","setOptions","listeners","shouldSuspend","fetchOptimistic","getHasError","throwErrors","query","getCurrentQuery","error","notifyOnChangeProps","trackResult"],"mappings":";;;;;;;;AAeO,SAASA,YAAY,CAO1BC,OAMC,EACDC,QAA8B,EAC9BC,WAAyB,EACzB;AACA,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;EAC1C,MAAMG,WAAW,GAAGC,cAAc,EAAE,CAAA;EACpC,MAAMC,kBAAkB,GAAGC,0BAA0B,EAAE,CAAA;AACvD,EAAA,MAAMC,gBAAgB,GAAGN,MAAM,CAACO,mBAAmB,CAACV,OAAO,CAAC,CAAA;;AAE5D;AACAS,EAAAA,gBAAgB,CAACE,kBAAkB,GAAGN,WAAW,GAC7C,aAAa,GACb,YAAY,CAAA;;AAEhB;EACA,IAAII,gBAAgB,CAACG,OAAO,EAAE;IAC5BH,gBAAgB,CAACG,OAAO,GAAGC,aAAa,CAACC,UAAU,CACjDL,gBAAgB,CAACG,OAAO,CACzB,CAAA;AACH,GAAA;EAEA,IAAIH,gBAAgB,CAACM,SAAS,EAAE;IAC9BN,gBAAgB,CAACM,SAAS,GAAGF,aAAa,CAACC,UAAU,CACnDL,gBAAgB,CAACM,SAAS,CAC3B,CAAA;AACH,GAAA;EAEA,IAAIN,gBAAgB,CAACO,SAAS,EAAE;IAC9BP,gBAAgB,CAACO,SAAS,GAAGH,aAAa,CAACC,UAAU,CACnDL,gBAAgB,CAACO,SAAS,CAC3B,CAAA;AACH,GAAA;EAEAC,eAAe,CAACR,gBAAgB,CAAC,CAAA;AACjCS,EAAAA,+BAA+B,CAACT,gBAAgB,EAAEF,kBAAkB,CAAC,CAAA;EAErEY,0BAA0B,CAACZ,kBAAkB,CAAC,CAAA;AAE9C,EAAA,MAAM,CAACa,QAAQ,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAC/B,MACE,IAAIrB,QAAQ,CACVE,MAAM,EACNM,gBAAgB,CACjB,CACJ,CAAA;AAED,EAAA,MAAMc,MAAM,GAAGH,QAAQ,CAACI,mBAAmB,CAACf,gBAAgB,CAAC,CAAA;EAE7DY,KAAK,CAACI,oBAAoB,CACxBJ,KAAK,CAACK,WAAW,CACdC,aAAa,IACZtB,WAAW,GACP,MAAMuB,SAAS,GACfR,QAAQ,CAACS,SAAS,CAAChB,aAAa,CAACC,UAAU,CAACa,aAAa,CAAC,CAAC,EACjE,CAACP,QAAQ,EAAEf,WAAW,CAAC,CACxB,EACD,MAAMe,QAAQ,CAACU,gBAAgB,EAAE,EACjC,MAAMV,QAAQ,CAACU,gBAAgB,EAAE,CAClC,CAAA;EAEDT,KAAK,CAACU,SAAS,CAAC,MAAM;AACpB;AACA;AACAX,IAAAA,QAAQ,CAACY,UAAU,CAACvB,gBAAgB,EAAE;AAAEwB,MAAAA,SAAS,EAAE,KAAA;AAAM,KAAC,CAAC,CAAA;AAC7D,GAAC,EAAE,CAACxB,gBAAgB,EAAEW,QAAQ,CAAC,CAAC,CAAA;;AAEhC;EACA,IAAIc,aAAa,CAACzB,gBAAgB,EAAEc,MAAM,EAAElB,WAAW,CAAC,EAAE;AACxD,IAAA,MAAM8B,eAAe,CAAC1B,gBAAgB,EAAEW,QAAQ,EAAEb,kBAAkB,CAAC,CAAA;AACvE,GAAA;;AAEA;AACA,EAAA,IACE6B,WAAW,CAAC;IACVb,MAAM;IACNhB,kBAAkB;IAClB8B,WAAW,EAAE5B,gBAAgB,CAAC4B,WAAW;IACzCC,KAAK,EAAElB,QAAQ,CAACmB,eAAe,EAAA;AACjC,GAAC,CAAC,EACF;IACA,MAAMhB,MAAM,CAACiB,KAAK,CAAA;AACpB,GAAA;;AAEA;AACA,EAAA,OAAO,CAAC/B,gBAAgB,CAACgC,mBAAmB,GACxCrB,QAAQ,CAACsB,WAAW,CAACnB,MAAM,CAAC,GAC5BA,MAAM,CAAA;AACZ;;;;"}
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.mjs';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
5
|
-
import { useIsRestoring } from './isRestoring.mjs';
|
|
6
|
-
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.mjs';
|
|
7
|
-
import { ensureStaleTime, shouldSuspend, fetchOptimistic } from './suspense.mjs';
|
|
8
|
-
|
|
9
|
-
function useBaseQuery(options, Observer, queryClient) {
|
|
10
|
-
const client = useQueryClient(queryClient);
|
|
11
|
-
const isRestoring = useIsRestoring();
|
|
12
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
13
|
-
const defaultedOptions = client.defaultQueryOptions(options);
|
|
14
|
-
|
|
15
|
-
// Make sure results are optimistically set in fetching state before subscribing or updating options
|
|
16
|
-
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
17
|
-
|
|
18
|
-
// Include callbacks in batch renders
|
|
19
|
-
if (defaultedOptions.onError) {
|
|
20
|
-
defaultedOptions.onError = notifyManager.batchCalls(defaultedOptions.onError);
|
|
21
|
-
}
|
|
22
|
-
if (defaultedOptions.onSuccess) {
|
|
23
|
-
defaultedOptions.onSuccess = notifyManager.batchCalls(defaultedOptions.onSuccess);
|
|
24
|
-
}
|
|
25
|
-
if (defaultedOptions.onSettled) {
|
|
26
|
-
defaultedOptions.onSettled = notifyManager.batchCalls(defaultedOptions.onSettled);
|
|
27
|
-
}
|
|
28
|
-
ensureStaleTime(defaultedOptions);
|
|
29
|
-
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
|
|
30
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
31
|
-
const [observer] = React.useState(() => new Observer(client, defaultedOptions));
|
|
32
|
-
const result = observer.getOptimisticResult(defaultedOptions);
|
|
33
|
-
React.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
34
|
-
React.useEffect(() => {
|
|
35
|
-
// Do not notify on updates because of changes in the options because
|
|
36
|
-
// these changes should already be reflected in the optimistic result.
|
|
37
|
-
observer.setOptions(defaultedOptions, {
|
|
38
|
-
listeners: false
|
|
39
|
-
});
|
|
40
|
-
}, [defaultedOptions, observer]);
|
|
41
|
-
|
|
42
|
-
// Handle suspense
|
|
43
|
-
if (shouldSuspend(defaultedOptions, result, isRestoring)) {
|
|
44
|
-
throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Handle error boundary
|
|
48
|
-
if (getHasError({
|
|
49
|
-
result,
|
|
50
|
-
errorResetBoundary,
|
|
51
|
-
throwErrors: defaultedOptions.throwErrors,
|
|
52
|
-
query: observer.getCurrentQuery()
|
|
53
|
-
})) {
|
|
54
|
-
throw result.error;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// Handle result property usage tracking
|
|
58
|
-
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
export { useBaseQuery };
|
|
62
|
-
//# sourceMappingURL=useBaseQuery.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.mjs","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["import * as React from 'react'\n\nimport type { QueryClient, QueryKey, QueryObserver } from '@tanstack/query-core'\nimport { notifyManager } from '@tanstack/query-core'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { UseBaseQueryOptions } from './types'\nimport { useIsRestoring } from './isRestoring'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport { ensureStaleTime, shouldSuspend, fetchOptimistic } from './suspense'\n\nexport function useBaseQuery<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey extends QueryKey,\n>(\n options: UseBaseQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n Observer: typeof QueryObserver,\n queryClient?: QueryClient,\n) {\n const client = useQueryClient(queryClient)\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n const defaultedOptions = client.defaultQueryOptions(options)\n\n // Make sure results are optimistically set in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n // Include callbacks in batch renders\n if (defaultedOptions.onError) {\n defaultedOptions.onError = notifyManager.batchCalls(\n defaultedOptions.onError,\n )\n }\n\n if (defaultedOptions.onSuccess) {\n defaultedOptions.onSuccess = notifyManager.batchCalls(\n defaultedOptions.onSuccess,\n )\n }\n\n if (defaultedOptions.onSettled) {\n defaultedOptions.onSettled = notifyManager.batchCalls(\n defaultedOptions.onSettled,\n )\n }\n\n ensureStaleTime(defaultedOptions)\n ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary)\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = React.useState(\n () =>\n new Observer<TQueryFnData, TError, TData, TQueryData, TQueryKey>(\n client,\n defaultedOptions,\n ),\n )\n\n const result = observer.getOptimisticResult(defaultedOptions)\n\n React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n isRestoring\n ? () => undefined\n : observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer, isRestoring],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n React.useEffect(() => {\n // Do not notify on updates because of changes in the options because\n // these changes should already be reflected in the optimistic result.\n observer.setOptions(defaultedOptions, { listeners: false })\n }, [defaultedOptions, observer])\n\n // Handle suspense\n if (shouldSuspend(defaultedOptions, result, isRestoring)) {\n throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary)\n }\n\n // Handle error boundary\n if (\n getHasError({\n result,\n errorResetBoundary,\n throwErrors: defaultedOptions.throwErrors,\n query: observer.getCurrentQuery(),\n })\n ) {\n throw result.error\n }\n\n // Handle result property usage tracking\n return !defaultedOptions.notifyOnChangeProps\n ? observer.trackResult(result)\n : result\n}\n"],"names":["useBaseQuery","options","Observer","queryClient","client","useQueryClient","isRestoring","useIsRestoring","errorResetBoundary","useQueryErrorResetBoundary","defaultedOptions","defaultQueryOptions","_optimisticResults","onError","notifyManager","batchCalls","onSuccess","onSettled","ensureStaleTime","ensurePreventErrorBoundaryRetry","useClearResetErrorBoundary","observer","React","useState","result","getOptimisticResult","useSyncExternalStore","useCallback","onStoreChange","undefined","subscribe","getCurrentResult","useEffect","setOptions","listeners","shouldSuspend","fetchOptimistic","getHasError","throwErrors","query","getCurrentQuery","error","notifyOnChangeProps","trackResult"],"mappings":";;;;;;;;AAeO,SAASA,YAAY,CAO1BC,OAMC,EACDC,QAA8B,EAC9BC,WAAyB,EACzB;AACA,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;EAC1C,MAAMG,WAAW,GAAGC,cAAc,EAAE,CAAA;EACpC,MAAMC,kBAAkB,GAAGC,0BAA0B,EAAE,CAAA;AACvD,EAAA,MAAMC,gBAAgB,GAAGN,MAAM,CAACO,mBAAmB,CAACV,OAAO,CAAC,CAAA;;AAE5D;AACAS,EAAAA,gBAAgB,CAACE,kBAAkB,GAAGN,WAAW,GAC7C,aAAa,GACb,YAAY,CAAA;;AAEhB;EACA,IAAII,gBAAgB,CAACG,OAAO,EAAE;IAC5BH,gBAAgB,CAACG,OAAO,GAAGC,aAAa,CAACC,UAAU,CACjDL,gBAAgB,CAACG,OAAO,CACzB,CAAA;AACH,GAAA;EAEA,IAAIH,gBAAgB,CAACM,SAAS,EAAE;IAC9BN,gBAAgB,CAACM,SAAS,GAAGF,aAAa,CAACC,UAAU,CACnDL,gBAAgB,CAACM,SAAS,CAC3B,CAAA;AACH,GAAA;EAEA,IAAIN,gBAAgB,CAACO,SAAS,EAAE;IAC9BP,gBAAgB,CAACO,SAAS,GAAGH,aAAa,CAACC,UAAU,CACnDL,gBAAgB,CAACO,SAAS,CAC3B,CAAA;AACH,GAAA;EAEAC,eAAe,CAACR,gBAAgB,CAAC,CAAA;AACjCS,EAAAA,+BAA+B,CAACT,gBAAgB,EAAEF,kBAAkB,CAAC,CAAA;EAErEY,0BAA0B,CAACZ,kBAAkB,CAAC,CAAA;AAE9C,EAAA,MAAM,CAACa,QAAQ,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAC/B,MACE,IAAIrB,QAAQ,CACVE,MAAM,EACNM,gBAAgB,CACjB,CACJ,CAAA;AAED,EAAA,MAAMc,MAAM,GAAGH,QAAQ,CAACI,mBAAmB,CAACf,gBAAgB,CAAC,CAAA;EAE7DY,KAAK,CAACI,oBAAoB,CACxBJ,KAAK,CAACK,WAAW,CACdC,aAAa,IACZtB,WAAW,GACP,MAAMuB,SAAS,GACfR,QAAQ,CAACS,SAAS,CAAChB,aAAa,CAACC,UAAU,CAACa,aAAa,CAAC,CAAC,EACjE,CAACP,QAAQ,EAAEf,WAAW,CAAC,CACxB,EACD,MAAMe,QAAQ,CAACU,gBAAgB,EAAE,EACjC,MAAMV,QAAQ,CAACU,gBAAgB,EAAE,CAClC,CAAA;EAEDT,KAAK,CAACU,SAAS,CAAC,MAAM;AACpB;AACA;AACAX,IAAAA,QAAQ,CAACY,UAAU,CAACvB,gBAAgB,EAAE;AAAEwB,MAAAA,SAAS,EAAE,KAAA;AAAM,KAAC,CAAC,CAAA;AAC7D,GAAC,EAAE,CAACxB,gBAAgB,EAAEW,QAAQ,CAAC,CAAC,CAAA;;AAEhC;EACA,IAAIc,aAAa,CAACzB,gBAAgB,EAAEc,MAAM,EAAElB,WAAW,CAAC,EAAE;AACxD,IAAA,MAAM8B,eAAe,CAAC1B,gBAAgB,EAAEW,QAAQ,EAAEb,kBAAkB,CAAC,CAAA;AACvE,GAAA;;AAEA;AACA,EAAA,IACE6B,WAAW,CAAC;IACVb,MAAM;IACNhB,kBAAkB;IAClB8B,WAAW,EAAE5B,gBAAgB,CAAC4B,WAAW;IACzCC,KAAK,EAAElB,QAAQ,CAACmB,eAAe,EAAA;AACjC,GAAC,CAAC,EACF;IACA,MAAMhB,MAAM,CAACiB,KAAK,CAAA;AACpB,GAAA;;AAEA;AACA,EAAA,OAAO,CAAC/B,gBAAgB,CAACgC,mBAAmB,GACxCrB,QAAQ,CAACsB,WAAW,CAACnB,MAAM,CAAC,GAC5BA,MAAM,CAAA;AACZ;;;;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import { useBaseQuery } from './useBaseQuery.esm.js';
|
|
3
|
-
|
|
4
|
-
// HOOK
|
|
5
|
-
function useInfiniteQuery(options, queryClient) {
|
|
6
|
-
return useBaseQuery(options,
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
8
|
-
InfiniteQueryObserver, queryClient);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { useInfiniteQuery };
|
|
12
|
-
//# sourceMappingURL=useInfiniteQuery.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.esm.js","sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import type {\n QueryObserver,\n QueryKey,\n QueryClient,\n DefaultError,\n InfiniteData,\n} from '@tanstack/query-core'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport type { UseInfiniteQueryOptions, UseInfiniteQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n// HOOK\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError> {\n return useBaseQuery(\n options,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n ) as UseInfiniteQueryResult<TData, TError>\n}\n"],"names":["useInfiniteQuery","options","queryClient","useBaseQuery","InfiniteQueryObserver"],"mappings":";;;AAWA;AACO,SAASA,gBAAgB,CAO9BC,OAOC,EACDC,WAAyB,EACc;EACvC,OAAOC,YAAY,CACjBF,OAAO;AACP;EACAG,qBAAqB,EACrBF,WAAW,CACZ,CAAA;AACH;;;;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core';
|
|
2
|
-
import { useBaseQuery } from './useBaseQuery.mjs';
|
|
3
|
-
|
|
4
|
-
// HOOK
|
|
5
|
-
function useInfiniteQuery(options, queryClient) {
|
|
6
|
-
return useBaseQuery(options,
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
8
|
-
InfiniteQueryObserver, queryClient);
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { useInfiniteQuery };
|
|
12
|
-
//# sourceMappingURL=useInfiniteQuery.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.mjs","sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["import type {\n QueryObserver,\n QueryKey,\n QueryClient,\n DefaultError,\n InfiniteData,\n} from '@tanstack/query-core'\nimport { InfiniteQueryObserver } from '@tanstack/query-core'\nimport type { UseInfiniteQueryOptions, UseInfiniteQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n// HOOK\nexport function useInfiniteQuery<\n TQueryFnData,\n TError = DefaultError,\n TData = InfiniteData<TQueryFnData>,\n TQueryKey extends QueryKey = QueryKey,\n TPageParam = unknown,\n>(\n options: UseInfiniteQueryOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryFnData,\n TQueryKey,\n TPageParam\n >,\n queryClient?: QueryClient,\n): UseInfiniteQueryResult<TData, TError> {\n return useBaseQuery(\n options,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n InfiniteQueryObserver as typeof QueryObserver,\n queryClient,\n ) as UseInfiniteQueryResult<TData, TError>\n}\n"],"names":["useInfiniteQuery","options","queryClient","useBaseQuery","InfiniteQueryObserver"],"mappings":";;;AAWA;AACO,SAASA,gBAAgB,CAO9BC,OAOC,EACDC,WAAyB,EACc;EACvC,OAAOC,YAAY,CACjBF,OAAO;AACP;EACAG,qBAAqB,EACrBF,WAAW,CACZ,CAAA;AACH;;;;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
4
|
-
|
|
5
|
-
function useIsFetching(filters, queryClient) {
|
|
6
|
-
const client = useQueryClient(queryClient);
|
|
7
|
-
const queryCache = client.getQueryCache();
|
|
8
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => client.isFetching(filters), () => client.isFetching(filters));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { useIsFetching };
|
|
12
|
-
//# sourceMappingURL=useIsFetching.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.esm.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import * as React from 'react'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\nimport { notifyManager } from '@tanstack/query-core'\n\nimport { useQueryClient } from './QueryClientProvider'\n\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n () => client.isFetching(filters),\n )\n}\n"],"names":["useIsFetching","filters","queryClient","client","useQueryClient","queryCache","getQueryCache","React","useSyncExternalStore","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isFetching"],"mappings":";;;;AAMO,SAASA,aAAa,CAC3BC,OAAsB,EACtBC,WAAyB,EACjB;AACR,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAC1C,EAAA,MAAMG,UAAU,GAAGF,MAAM,CAACG,aAAa,EAAE,CAAA;AAEzC,EAAA,OAAOC,KAAK,CAACC,oBAAoB,CAC/BD,KAAK,CAACE,WAAW,CACdC,aAAa,IACZL,UAAU,CAACM,SAAS,CAACC,aAAa,CAACC,UAAU,CAACH,aAAa,CAAC,CAAC,EAC/D,CAACL,UAAU,CAAC,CACb,EACD,MAAMF,MAAM,CAACW,UAAU,CAACb,OAAO,CAAC,EAChC,MAAME,MAAM,CAACW,UAAU,CAACb,OAAO,CAAC,CACjC,CAAA;AACH;;;;"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
-
|
|
5
|
-
function useIsFetching(filters, queryClient) {
|
|
6
|
-
const client = useQueryClient(queryClient);
|
|
7
|
-
const queryCache = client.getQueryCache();
|
|
8
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => client.isFetching(filters), () => client.isFetching(filters));
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { useIsFetching };
|
|
12
|
-
//# sourceMappingURL=useIsFetching.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.mjs","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import * as React from 'react'\nimport type { QueryClient, QueryFilters } from '@tanstack/query-core'\nimport { notifyManager } from '@tanstack/query-core'\n\nimport { useQueryClient } from './QueryClientProvider'\n\nexport function useIsFetching(\n filters?: QueryFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n const queryCache = client.getQueryCache()\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => client.isFetching(filters),\n () => client.isFetching(filters),\n )\n}\n"],"names":["useIsFetching","filters","queryClient","client","useQueryClient","queryCache","getQueryCache","React","useSyncExternalStore","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isFetching"],"mappings":";;;;AAMO,SAASA,aAAa,CAC3BC,OAAsB,EACtBC,WAAyB,EACjB;AACR,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAC1C,EAAA,MAAMG,UAAU,GAAGF,MAAM,CAACG,aAAa,EAAE,CAAA;AAEzC,EAAA,OAAOC,KAAK,CAACC,oBAAoB,CAC/BD,KAAK,CAACE,WAAW,CACdC,aAAa,IACZL,UAAU,CAACM,SAAS,CAACC,aAAa,CAACC,UAAU,CAACH,aAAa,CAAC,CAAC,EAC/D,CAACL,UAAU,CAAC,CACb,EACD,MAAMF,MAAM,CAACW,UAAU,CAACb,OAAO,CAAC,EAChC,MAAME,MAAM,CAACW,UAAU,CAACb,OAAO,CAAC,CACjC,CAAA;AACH;;;;"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { MutationObserver, notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
4
|
-
import { shouldThrowError } from './utils.esm.js';
|
|
5
|
-
|
|
6
|
-
// HOOK
|
|
7
|
-
|
|
8
|
-
function useMutation(options, queryClient) {
|
|
9
|
-
const client = useQueryClient(queryClient);
|
|
10
|
-
const [observer] = React.useState(() => new MutationObserver(client, options));
|
|
11
|
-
React.useEffect(() => {
|
|
12
|
-
observer.setOptions(options);
|
|
13
|
-
}, [observer, options]);
|
|
14
|
-
const result = React.useSyncExternalStore(React.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
15
|
-
const mutate = React.useCallback((variables, mutateOptions) => {
|
|
16
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
17
|
-
}, [observer]);
|
|
18
|
-
if (result.error && shouldThrowError(observer.options.throwErrors, [result.error])) {
|
|
19
|
-
throw result.error;
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
...result,
|
|
23
|
-
mutate,
|
|
24
|
-
mutateAsync: result.mutate
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
|
-
function noop() {}
|
|
30
|
-
|
|
31
|
-
export { useMutation };
|
|
32
|
-
//# sourceMappingURL=useMutation.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.esm.js","sources":["../../src/useMutation.ts"],"sourcesContent":["import * as React from 'react'\nimport type { QueryClient, DefaultError } from '@tanstack/query-core'\nimport { notifyManager, MutationObserver } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport { shouldThrowError } from './utils'\n\n// HOOK\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const client = useQueryClient(queryClient)\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n client,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n const mutate = React.useCallback<\n UseMutateFunction<TData, TError, TVariables, TContext>\n >(\n (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwErrors, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noop() {}\n"],"names":["useMutation","options","queryClient","client","useQueryClient","observer","React","useState","MutationObserver","useEffect","setOptions","result","useSyncExternalStore","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","getCurrentResult","mutate","variables","mutateOptions","catch","noop","error","shouldThrowError","throwErrors","mutateAsync"],"mappings":";;;;;AAWA;;AAEO,SAASA,WAAW,CAMzBC,OAAgE,EAChEC,WAAyB,EAC+B;AACxD,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAE1C,EAAA,MAAM,CAACG,QAAQ,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAC/B,MACE,IAAIC,gBAAgB,CAClBL,MAAM,EACNF,OAAO,CACR,CACJ,CAAA;EAEDK,KAAK,CAACG,SAAS,CAAC,MAAM;AACpBJ,IAAAA,QAAQ,CAACK,UAAU,CAACT,OAAO,CAAC,CAAA;AAC9B,GAAC,EAAE,CAACI,QAAQ,EAAEJ,OAAO,CAAC,CAAC,CAAA;AAEvB,EAAA,MAAMU,MAAM,GAAGL,KAAK,CAACM,oBAAoB,CACvCN,KAAK,CAACO,WAAW,CACdC,aAAa,IACZT,QAAQ,CAACU,SAAS,CAACC,aAAa,CAACC,UAAU,CAACH,aAAa,CAAC,CAAC,EAC7D,CAACT,QAAQ,CAAC,CACX,EACD,MAAMA,QAAQ,CAACa,gBAAgB,EAAE,EACjC,MAAMb,QAAQ,CAACa,gBAAgB,EAAE,CAClC,CAAA;EAED,MAAMC,MAAM,GAAGb,KAAK,CAACO,WAAW,CAG9B,CAACO,SAAS,EAAEC,aAAa,KAAK;IAC5BhB,QAAQ,CAACc,MAAM,CAACC,SAAS,EAAEC,aAAa,CAAC,CAACC,KAAK,CAACC,IAAI,CAAC,CAAA;AACvD,GAAC,EACD,CAAClB,QAAQ,CAAC,CACX,CAAA;AAED,EAAA,IACEM,MAAM,CAACa,KAAK,IACZC,gBAAgB,CAACpB,QAAQ,CAACJ,OAAO,CAACyB,WAAW,EAAE,CAACf,MAAM,CAACa,KAAK,CAAC,CAAC,EAC9D;IACA,MAAMb,MAAM,CAACa,KAAK,CAAA;AACpB,GAAA;EAEA,OAAO;AAAE,IAAA,GAAGb,MAAM;IAAEQ,MAAM;IAAEQ,WAAW,EAAEhB,MAAM,CAACQ,MAAAA;GAAQ,CAAA;AAC1D,CAAA;;AAEA;AACA,SAASI,IAAI,GAAG;;;;"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { MutationObserver, notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
-
import { shouldThrowError } from './utils.mjs';
|
|
5
|
-
|
|
6
|
-
// HOOK
|
|
7
|
-
|
|
8
|
-
function useMutation(options, queryClient) {
|
|
9
|
-
const client = useQueryClient(queryClient);
|
|
10
|
-
const [observer] = React.useState(() => new MutationObserver(client, options));
|
|
11
|
-
React.useEffect(() => {
|
|
12
|
-
observer.setOptions(options);
|
|
13
|
-
}, [observer, options]);
|
|
14
|
-
const result = React.useSyncExternalStore(React.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
15
|
-
const mutate = React.useCallback((variables, mutateOptions) => {
|
|
16
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
17
|
-
}, [observer]);
|
|
18
|
-
if (result.error && shouldThrowError(observer.options.throwErrors, [result.error])) {
|
|
19
|
-
throw result.error;
|
|
20
|
-
}
|
|
21
|
-
return {
|
|
22
|
-
...result,
|
|
23
|
-
mutate,
|
|
24
|
-
mutateAsync: result.mutate
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
29
|
-
function noop() {}
|
|
30
|
-
|
|
31
|
-
export { useMutation };
|
|
32
|
-
//# sourceMappingURL=useMutation.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.mjs","sources":["../../src/useMutation.ts"],"sourcesContent":["import * as React from 'react'\nimport type { QueryClient, DefaultError } from '@tanstack/query-core'\nimport { notifyManager, MutationObserver } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type {\n UseMutateFunction,\n UseMutationOptions,\n UseMutationResult,\n} from './types'\nimport { shouldThrowError } from './utils'\n\n// HOOK\n\nexport function useMutation<\n TData = unknown,\n TError = DefaultError,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n queryClient?: QueryClient,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const client = useQueryClient(queryClient)\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n client,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n observer.subscribe(notifyManager.batchCalls(onStoreChange)),\n [observer],\n ),\n () => observer.getCurrentResult(),\n () => observer.getCurrentResult(),\n )\n\n const mutate = React.useCallback<\n UseMutateFunction<TData, TError, TVariables, TContext>\n >(\n (variables, mutateOptions) => {\n observer.mutate(variables, mutateOptions).catch(noop)\n },\n [observer],\n )\n\n if (\n result.error &&\n shouldThrowError(observer.options.throwErrors, [result.error])\n ) {\n throw result.error\n }\n\n return { ...result, mutate, mutateAsync: result.mutate }\n}\n\n// eslint-disable-next-line @typescript-eslint/no-empty-function\nfunction noop() {}\n"],"names":["useMutation","options","queryClient","client","useQueryClient","observer","React","useState","MutationObserver","useEffect","setOptions","result","useSyncExternalStore","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","getCurrentResult","mutate","variables","mutateOptions","catch","noop","error","shouldThrowError","throwErrors","mutateAsync"],"mappings":";;;;;AAWA;;AAEO,SAASA,WAAW,CAMzBC,OAAgE,EAChEC,WAAyB,EAC+B;AACxD,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAE1C,EAAA,MAAM,CAACG,QAAQ,CAAC,GAAGC,KAAK,CAACC,QAAQ,CAC/B,MACE,IAAIC,gBAAgB,CAClBL,MAAM,EACNF,OAAO,CACR,CACJ,CAAA;EAEDK,KAAK,CAACG,SAAS,CAAC,MAAM;AACpBJ,IAAAA,QAAQ,CAACK,UAAU,CAACT,OAAO,CAAC,CAAA;AAC9B,GAAC,EAAE,CAACI,QAAQ,EAAEJ,OAAO,CAAC,CAAC,CAAA;AAEvB,EAAA,MAAMU,MAAM,GAAGL,KAAK,CAACM,oBAAoB,CACvCN,KAAK,CAACO,WAAW,CACdC,aAAa,IACZT,QAAQ,CAACU,SAAS,CAACC,aAAa,CAACC,UAAU,CAACH,aAAa,CAAC,CAAC,EAC7D,CAACT,QAAQ,CAAC,CACX,EACD,MAAMA,QAAQ,CAACa,gBAAgB,EAAE,EACjC,MAAMb,QAAQ,CAACa,gBAAgB,EAAE,CAClC,CAAA;EAED,MAAMC,MAAM,GAAGb,KAAK,CAACO,WAAW,CAG9B,CAACO,SAAS,EAAEC,aAAa,KAAK;IAC5BhB,QAAQ,CAACc,MAAM,CAACC,SAAS,EAAEC,aAAa,CAAC,CAACC,KAAK,CAACC,IAAI,CAAC,CAAA;AACvD,GAAC,EACD,CAAClB,QAAQ,CAAC,CACX,CAAA;AAED,EAAA,IACEM,MAAM,CAACa,KAAK,IACZC,gBAAgB,CAACpB,QAAQ,CAACJ,OAAO,CAACyB,WAAW,EAAE,CAACf,MAAM,CAACa,KAAK,CAAC,CAAC,EAC9D;IACA,MAAMb,MAAM,CAACa,KAAK,CAAA;AACpB,GAAA;EAEA,OAAO;AAAE,IAAA,GAAGb,MAAM;IAAEQ,MAAM;IAAEQ,WAAW,EAAEhB,MAAM,CAACQ,MAAAA;GAAQ,CAAA;AAC1D,CAAA;;AAEA;AACA,SAASI,IAAI,GAAG;;;;"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { replaceEqualDeep, notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
4
|
-
|
|
5
|
-
function useIsMutating(filters, queryClient) {
|
|
6
|
-
const client = useQueryClient(queryClient);
|
|
7
|
-
return useMutationState({
|
|
8
|
-
filters: {
|
|
9
|
-
...filters,
|
|
10
|
-
status: 'pending'
|
|
11
|
-
}
|
|
12
|
-
}, client).length;
|
|
13
|
-
}
|
|
14
|
-
function getResult(mutationCache, options) {
|
|
15
|
-
return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);
|
|
16
|
-
}
|
|
17
|
-
function useMutationState(options = {}, queryClient) {
|
|
18
|
-
const mutationCache = useQueryClient(queryClient).getMutationCache();
|
|
19
|
-
const optionsRef = React.useRef(options);
|
|
20
|
-
const result = React.useRef();
|
|
21
|
-
if (!result.current) {
|
|
22
|
-
result.current = getResult(mutationCache, options);
|
|
23
|
-
}
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
optionsRef.current = options;
|
|
26
|
-
});
|
|
27
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(() => {
|
|
28
|
-
const nextResult = replaceEqualDeep(result.current, getResult(mutationCache, optionsRef.current));
|
|
29
|
-
if (result.current !== nextResult) {
|
|
30
|
-
result.current = nextResult;
|
|
31
|
-
notifyManager.schedule(onStoreChange);
|
|
32
|
-
}
|
|
33
|
-
}), [mutationCache]), () => result.current, () => result.current);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { useIsMutating, useMutationState };
|
|
37
|
-
//# sourceMappingURL=useMutationState.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.esm.js","sources":["../../src/useMutationState.ts"],"sourcesContent":["import * as React from 'react'\n\nimport type {\n MutationFilters,\n QueryClient,\n Mutation,\n MutationCache,\n DefaultError,\n} from '@tanstack/query-core'\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { MutationState } from '@tanstack/query-core/build/lib/mutation'\n\nexport function useIsMutating(\n filters?: MutationFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n return useMutationState(\n { filters: { ...filters, status: 'pending' } },\n client,\n ).length\n}\n\ntype MutationStateOptions<TResult> = {\n filters?: MutationFilters\n select?: (\n mutation: Mutation<unknown, DefaultError, unknown, unknown>,\n ) => TResult\n}\n\nfunction getResult<TResult = MutationState>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(\n mutation as Mutation<unknown, DefaultError, unknown, unknown>,\n )\n : mutation.state) as TResult,\n )\n}\n\nexport function useMutationState<TResult = unknown>(\n options: MutationStateOptions<TResult> = {},\n queryClient?: QueryClient,\n): Array<TResult> {\n const mutationCache = useQueryClient(queryClient).getMutationCache()\n const optionsRef = React.useRef(options)\n const result = React.useRef<Array<TResult>>()\n if (!result.current) {\n result.current = getResult(mutationCache, options)\n }\n\n React.useEffect(() => {\n optionsRef.current = options\n })\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(\n result.current,\n getResult(mutationCache, optionsRef.current),\n )\n if (result.current !== nextResult) {\n result.current = nextResult\n notifyManager.schedule(onStoreChange)\n }\n }),\n [mutationCache],\n ),\n () => result.current,\n () => result.current,\n )!\n}\n"],"names":["useIsMutating","filters","queryClient","client","useQueryClient","useMutationState","status","length","getResult","mutationCache","options","findAll","map","mutation","select","state","getMutationCache","optionsRef","React","useRef","result","current","useEffect","useSyncExternalStore","useCallback","onStoreChange","subscribe","nextResult","replaceEqualDeep","notifyManager","schedule"],"mappings":";;;;AAaO,SAASA,aAAa,CAC3BC,OAAyB,EACzBC,WAAyB,EACjB;AACR,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAC1C,EAAA,OAAOG,gBAAgB,CACrB;AAAEJ,IAAAA,OAAO,EAAE;AAAE,MAAA,GAAGA,OAAO;AAAEK,MAAAA,MAAM,EAAE,SAAA;AAAU,KAAA;AAAE,GAAC,EAC9CH,MAAM,CACP,CAACI,MAAM,CAAA;AACV,CAAA;AASA,SAASC,SAAS,CAChBC,aAA4B,EAC5BC,OAAsC,EACtB;EAChB,OAAOD,aAAa,CACjBE,OAAO,CAACD,OAAO,CAACT,OAAO,CAAC,CACxBW,GAAG,CACDC,QAAQ,IACNH,OAAO,CAACI,MAAM,GACXJ,OAAO,CAACI,MAAM,CACZD,QAAQ,CACT,GACDA,QAAQ,CAACE,KAAiB,CACjC,CAAA;AACL,CAAA;AAEO,SAASV,gBAAgB,CAC9BK,OAAsC,GAAG,EAAE,EAC3CR,WAAyB,EACT;EAChB,MAAMO,aAAa,GAAGL,cAAc,CAACF,WAAW,CAAC,CAACc,gBAAgB,EAAE,CAAA;AACpE,EAAA,MAAMC,UAAU,GAAGC,KAAK,CAACC,MAAM,CAACT,OAAO,CAAC,CAAA;AACxC,EAAA,MAAMU,MAAM,GAAGF,KAAK,CAACC,MAAM,EAAkB,CAAA;AAC7C,EAAA,IAAI,CAACC,MAAM,CAACC,OAAO,EAAE;IACnBD,MAAM,CAACC,OAAO,GAAGb,SAAS,CAACC,aAAa,EAAEC,OAAO,CAAC,CAAA;AACpD,GAAA;EAEAQ,KAAK,CAACI,SAAS,CAAC,MAAM;IACpBL,UAAU,CAACI,OAAO,GAAGX,OAAO,CAAA;AAC9B,GAAC,CAAC,CAAA;AAEF,EAAA,OAAOQ,KAAK,CAACK,oBAAoB,CAC/BL,KAAK,CAACM,WAAW,CACdC,aAAa,IACZhB,aAAa,CAACiB,SAAS,CAAC,MAAM;AAC5B,IAAA,MAAMC,UAAU,GAAGC,gBAAgB,CACjCR,MAAM,CAACC,OAAO,EACdb,SAAS,CAACC,aAAa,EAAEQ,UAAU,CAACI,OAAO,CAAC,CAC7C,CAAA;AACD,IAAA,IAAID,MAAM,CAACC,OAAO,KAAKM,UAAU,EAAE;MACjCP,MAAM,CAACC,OAAO,GAAGM,UAAU,CAAA;AAC3BE,MAAAA,aAAa,CAACC,QAAQ,CAACL,aAAa,CAAC,CAAA;AACvC,KAAA;AACF,GAAC,CAAC,EACJ,CAAChB,aAAa,CAAC,CAChB,EACD,MAAMW,MAAM,CAACC,OAAO,EACpB,MAAMD,MAAM,CAACC,OAAO,CACrB,CAAA;AACH;;;;"}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { replaceEqualDeep, notifyManager } from '@tanstack/query-core';
|
|
3
|
-
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
-
|
|
5
|
-
function useIsMutating(filters, queryClient) {
|
|
6
|
-
const client = useQueryClient(queryClient);
|
|
7
|
-
return useMutationState({
|
|
8
|
-
filters: {
|
|
9
|
-
...filters,
|
|
10
|
-
status: 'pending'
|
|
11
|
-
}
|
|
12
|
-
}, client).length;
|
|
13
|
-
}
|
|
14
|
-
function getResult(mutationCache, options) {
|
|
15
|
-
return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);
|
|
16
|
-
}
|
|
17
|
-
function useMutationState(options = {}, queryClient) {
|
|
18
|
-
const mutationCache = useQueryClient(queryClient).getMutationCache();
|
|
19
|
-
const optionsRef = React.useRef(options);
|
|
20
|
-
const result = React.useRef();
|
|
21
|
-
if (!result.current) {
|
|
22
|
-
result.current = getResult(mutationCache, options);
|
|
23
|
-
}
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
optionsRef.current = options;
|
|
26
|
-
});
|
|
27
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(() => {
|
|
28
|
-
const nextResult = replaceEqualDeep(result.current, getResult(mutationCache, optionsRef.current));
|
|
29
|
-
if (result.current !== nextResult) {
|
|
30
|
-
result.current = nextResult;
|
|
31
|
-
notifyManager.schedule(onStoreChange);
|
|
32
|
-
}
|
|
33
|
-
}), [mutationCache]), () => result.current, () => result.current);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export { useIsMutating, useMutationState };
|
|
37
|
-
//# sourceMappingURL=useMutationState.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.mjs","sources":["../../src/useMutationState.ts"],"sourcesContent":["import * as React from 'react'\n\nimport type {\n MutationFilters,\n QueryClient,\n Mutation,\n MutationCache,\n DefaultError,\n} from '@tanstack/query-core'\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { MutationState } from '@tanstack/query-core/build/lib/mutation'\n\nexport function useIsMutating(\n filters?: MutationFilters,\n queryClient?: QueryClient,\n): number {\n const client = useQueryClient(queryClient)\n return useMutationState(\n { filters: { ...filters, status: 'pending' } },\n client,\n ).length\n}\n\ntype MutationStateOptions<TResult> = {\n filters?: MutationFilters\n select?: (\n mutation: Mutation<unknown, DefaultError, unknown, unknown>,\n ) => TResult\n}\n\nfunction getResult<TResult = MutationState>(\n mutationCache: MutationCache,\n options: MutationStateOptions<TResult>,\n): Array<TResult> {\n return mutationCache\n .findAll(options.filters)\n .map(\n (mutation): TResult =>\n (options.select\n ? options.select(\n mutation as Mutation<unknown, DefaultError, unknown, unknown>,\n )\n : mutation.state) as TResult,\n )\n}\n\nexport function useMutationState<TResult = unknown>(\n options: MutationStateOptions<TResult> = {},\n queryClient?: QueryClient,\n): Array<TResult> {\n const mutationCache = useQueryClient(queryClient).getMutationCache()\n const optionsRef = React.useRef(options)\n const result = React.useRef<Array<TResult>>()\n if (!result.current) {\n result.current = getResult(mutationCache, options)\n }\n\n React.useEffect(() => {\n optionsRef.current = options\n })\n\n return React.useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(() => {\n const nextResult = replaceEqualDeep(\n result.current,\n getResult(mutationCache, optionsRef.current),\n )\n if (result.current !== nextResult) {\n result.current = nextResult\n notifyManager.schedule(onStoreChange)\n }\n }),\n [mutationCache],\n ),\n () => result.current,\n () => result.current,\n )!\n}\n"],"names":["useIsMutating","filters","queryClient","client","useQueryClient","useMutationState","status","length","getResult","mutationCache","options","findAll","map","mutation","select","state","getMutationCache","optionsRef","React","useRef","result","current","useEffect","useSyncExternalStore","useCallback","onStoreChange","subscribe","nextResult","replaceEqualDeep","notifyManager","schedule"],"mappings":";;;;AAaO,SAASA,aAAa,CAC3BC,OAAyB,EACzBC,WAAyB,EACjB;AACR,EAAA,MAAMC,MAAM,GAAGC,cAAc,CAACF,WAAW,CAAC,CAAA;AAC1C,EAAA,OAAOG,gBAAgB,CACrB;AAAEJ,IAAAA,OAAO,EAAE;AAAE,MAAA,GAAGA,OAAO;AAAEK,MAAAA,MAAM,EAAE,SAAA;AAAU,KAAA;AAAE,GAAC,EAC9CH,MAAM,CACP,CAACI,MAAM,CAAA;AACV,CAAA;AASA,SAASC,SAAS,CAChBC,aAA4B,EAC5BC,OAAsC,EACtB;EAChB,OAAOD,aAAa,CACjBE,OAAO,CAACD,OAAO,CAACT,OAAO,CAAC,CACxBW,GAAG,CACDC,QAAQ,IACNH,OAAO,CAACI,MAAM,GACXJ,OAAO,CAACI,MAAM,CACZD,QAAQ,CACT,GACDA,QAAQ,CAACE,KAAiB,CACjC,CAAA;AACL,CAAA;AAEO,SAASV,gBAAgB,CAC9BK,OAAsC,GAAG,EAAE,EAC3CR,WAAyB,EACT;EAChB,MAAMO,aAAa,GAAGL,cAAc,CAACF,WAAW,CAAC,CAACc,gBAAgB,EAAE,CAAA;AACpE,EAAA,MAAMC,UAAU,GAAGC,KAAK,CAACC,MAAM,CAACT,OAAO,CAAC,CAAA;AACxC,EAAA,MAAMU,MAAM,GAAGF,KAAK,CAACC,MAAM,EAAkB,CAAA;AAC7C,EAAA,IAAI,CAACC,MAAM,CAACC,OAAO,EAAE;IACnBD,MAAM,CAACC,OAAO,GAAGb,SAAS,CAACC,aAAa,EAAEC,OAAO,CAAC,CAAA;AACpD,GAAA;EAEAQ,KAAK,CAACI,SAAS,CAAC,MAAM;IACpBL,UAAU,CAACI,OAAO,GAAGX,OAAO,CAAA;AAC9B,GAAC,CAAC,CAAA;AAEF,EAAA,OAAOQ,KAAK,CAACK,oBAAoB,CAC/BL,KAAK,CAACM,WAAW,CACdC,aAAa,IACZhB,aAAa,CAACiB,SAAS,CAAC,MAAM;AAC5B,IAAA,MAAMC,UAAU,GAAGC,gBAAgB,CACjCR,MAAM,CAACC,OAAO,EACdb,SAAS,CAACC,aAAa,EAAEQ,UAAU,CAACI,OAAO,CAAC,CAC7C,CAAA;AACD,IAAA,IAAID,MAAM,CAACC,OAAO,KAAKM,UAAU,EAAE;MACjCP,MAAM,CAACC,OAAO,GAAGM,UAAU,CAAA;AAC3BE,MAAAA,aAAa,CAACC,QAAQ,CAACL,aAAa,CAAC,CAAA;AACvC,KAAA;AACF,GAAC,CAAC,EACJ,CAAChB,aAAa,CAAC,CAChB,EACD,MAAMW,MAAM,CAACC,OAAO,EACpB,MAAMD,MAAM,CAACC,OAAO,CACrB,CAAA;AACH;;;;"}
|