@tanstack/react-query 5.0.0-alpha.48 → 5.0.0-alpha.49
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/package.json +2 -2
- package/build/lib/HydrationBoundary.esm.js +0 -29
- package/build/lib/HydrationBoundary.esm.js.map +0 -1
- package/build/lib/QueryClientProvider.esm.js +0 -31
- package/build/lib/QueryClientProvider.esm.js.map +0 -1
- package/build/lib/QueryErrorResetBoundary.esm.js +0 -38
- package/build/lib/QueryErrorResetBoundary.esm.js.map +0 -1
- package/build/lib/errorBoundaryUtils.esm.js +0 -28
- package/build/lib/errorBoundaryUtils.esm.js.map +0 -1
- package/build/lib/index.esm.js +0 -12
- package/build/lib/index.esm.js.map +0 -1
- package/build/lib/isRestoring.esm.js +0 -9
- package/build/lib/isRestoring.esm.js.map +0 -1
- package/build/lib/suspense.esm.js +0 -17
- package/build/lib/suspense.esm.js.map +0 -1
- package/build/lib/useBaseQuery.esm.js +0 -52
- package/build/lib/useBaseQuery.esm.js.map +0 -1
- package/build/lib/useInfiniteQuery.esm.js +0 -13
- package/build/lib/useInfiniteQuery.esm.js.map +0 -1
- package/build/lib/useIsFetching.esm.js +0 -13
- package/build/lib/useIsFetching.esm.js.map +0 -1
- package/build/lib/useMutation.esm.js +0 -33
- package/build/lib/useMutation.esm.js.map +0 -1
- package/build/lib/useMutationState.esm.js +0 -38
- package/build/lib/useMutationState.esm.js.map +0 -1
- package/build/lib/useQueries.esm.js +0 -81
- package/build/lib/useQueries.esm.js.map +0 -1
- package/build/lib/useQuery.esm.js +0 -16
- package/build/lib/useQuery.esm.js.map +0 -1
- package/build/lib/utils.esm.js +0 -10
- package/build/lib/utils.esm.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/react-query",
|
|
3
|
-
"version": "5.0.0-alpha.
|
|
3
|
+
"version": "5.0.0-alpha.49",
|
|
4
4
|
"description": "Hooks for managing, caching and syncing asynchronous and remote data in React",
|
|
5
5
|
"author": "tannerlinsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"type": "commonjs",
|
|
14
14
|
"types": "build/lib/index.d.ts",
|
|
15
15
|
"main": "build/lib/index.js",
|
|
16
|
-
"module": "build/lib/index.
|
|
16
|
+
"module": "build/lib/index.mjs",
|
|
17
17
|
"exports": {
|
|
18
18
|
".": {
|
|
19
19
|
"types": "./build/lib/index.d.ts",
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { hydrate } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
|
|
6
|
-
const HydrationBoundary = ({
|
|
7
|
-
children,
|
|
8
|
-
options = {},
|
|
9
|
-
state,
|
|
10
|
-
queryClient
|
|
11
|
-
}) => {
|
|
12
|
-
const client = useQueryClient(queryClient);
|
|
13
|
-
const optionsRef = React.useRef(options);
|
|
14
|
-
optionsRef.current = options;
|
|
15
|
-
|
|
16
|
-
// Running hydrate again with the same queries is safe,
|
|
17
|
-
// it wont overwrite or initialize existing queries,
|
|
18
|
-
// relying on useMemo here is only a performance optimization.
|
|
19
|
-
// hydrate can and should be run *during* render here for SSR to work properly
|
|
20
|
-
React.useMemo(() => {
|
|
21
|
-
if (state) {
|
|
22
|
-
hydrate(client, state, optionsRef.current);
|
|
23
|
-
}
|
|
24
|
-
}, [client, state]);
|
|
25
|
-
return children;
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export { HydrationBoundary };
|
|
29
|
-
//# sourceMappingURL=HydrationBoundary.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"HydrationBoundary.esm.js","sources":["../../src/HydrationBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { HydrateOptions, QueryClient } from '@tanstack/query-core'\nimport { hydrate } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\n\nexport interface HydrationBoundaryProps {\n state?: unknown\n options?: HydrateOptions\n children?: React.ReactNode\n queryClient?: QueryClient\n}\n\nexport const HydrationBoundary = ({\n children,\n options = {},\n state,\n queryClient,\n}: HydrationBoundaryProps) => {\n const client = useQueryClient(queryClient)\n\n const optionsRef = React.useRef(options)\n optionsRef.current = options\n\n // Running hydrate again with the same queries is safe,\n // it wont overwrite or initialize existing queries,\n // relying on useMemo here is only a performance optimization.\n // hydrate can and should be run *during* render here for SSR to work properly\n React.useMemo(() => {\n if (state) {\n hydrate(client, state, optionsRef.current)\n }\n }, [client, state])\n\n return children as React.ReactElement\n}\n"],"names":["queryClient"],"mappings":";;;;;AAcO;;;;AAILA;AACsB;AACtB;AAEA;;;AAGA;AACA;AACA;AACA;;AAEE;;AAEA;AACF;AAEA;AACF;;"}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
const QueryClientContext = /*#__PURE__*/React.createContext(undefined);
|
|
5
|
-
const useQueryClient = queryClient => {
|
|
6
|
-
const client = React.useContext(QueryClientContext);
|
|
7
|
-
if (queryClient) {
|
|
8
|
-
return queryClient;
|
|
9
|
-
}
|
|
10
|
-
if (!client) {
|
|
11
|
-
throw new Error('No QueryClient set, use QueryClientProvider to set one');
|
|
12
|
-
}
|
|
13
|
-
return client;
|
|
14
|
-
};
|
|
15
|
-
const QueryClientProvider = ({
|
|
16
|
-
client,
|
|
17
|
-
children
|
|
18
|
-
}) => {
|
|
19
|
-
React.useEffect(() => {
|
|
20
|
-
client.mount();
|
|
21
|
-
return () => {
|
|
22
|
-
client.unmount();
|
|
23
|
-
};
|
|
24
|
-
}, [client]);
|
|
25
|
-
return /*#__PURE__*/React.createElement(QueryClientContext.Provider, {
|
|
26
|
-
value: client
|
|
27
|
-
}, children);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export { QueryClientContext, QueryClientProvider, useQueryClient };
|
|
31
|
-
//# sourceMappingURL=QueryClientProvider.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryClientProvider.esm.js","sources":["../../src/QueryClientProvider.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type { QueryClient } from '@tanstack/query-core'\n\nexport const QueryClientContext = React.createContext<QueryClient | undefined>(\n undefined,\n)\n\nexport const useQueryClient = (queryClient?: QueryClient) => {\n const client = React.useContext(QueryClientContext)\n\n if (queryClient) {\n return queryClient\n }\n\n if (!client) {\n throw new Error('No QueryClient set, use QueryClientProvider to set one')\n }\n\n return client\n}\n\nexport type QueryClientProviderProps = {\n client: QueryClient\n children?: React.ReactNode\n}\n\nexport const QueryClientProvider = ({\n client,\n children,\n}: QueryClientProviderProps): JSX.Element => {\n React.useEffect(() => {\n client.mount()\n return () => {\n client.unmount()\n }\n }, [client])\n\n return (\n <QueryClientContext.Provider value={client}>\n {children}\n </QueryClientContext.Provider>\n )\n}\n"],"names":["useQueryClient","children","value"],"mappings":";;;AAKO;AAIMA;AACX;AAEA;AACE;AACF;;AAGE;AACF;AAEA;AACF;AAOO;;AAELC;AACwB;;;AAGtB;;;AAGF;AAEA;AAC+BC;AAAc;AAI/C;;"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
// CONTEXT
|
|
5
|
-
|
|
6
|
-
function createValue() {
|
|
7
|
-
let isReset = false;
|
|
8
|
-
return {
|
|
9
|
-
clearReset: () => {
|
|
10
|
-
isReset = false;
|
|
11
|
-
},
|
|
12
|
-
reset: () => {
|
|
13
|
-
isReset = true;
|
|
14
|
-
},
|
|
15
|
-
isReset: () => {
|
|
16
|
-
return isReset;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
const QueryErrorResetBoundaryContext = /*#__PURE__*/React.createContext(createValue());
|
|
21
|
-
|
|
22
|
-
// HOOK
|
|
23
|
-
|
|
24
|
-
const useQueryErrorResetBoundary = () => React.useContext(QueryErrorResetBoundaryContext);
|
|
25
|
-
|
|
26
|
-
// COMPONENT
|
|
27
|
-
|
|
28
|
-
const QueryErrorResetBoundary = ({
|
|
29
|
-
children
|
|
30
|
-
}) => {
|
|
31
|
-
const [value] = React.useState(() => createValue());
|
|
32
|
-
return /*#__PURE__*/React.createElement(QueryErrorResetBoundaryContext.Provider, {
|
|
33
|
-
value: value
|
|
34
|
-
}, typeof children === 'function' ? children(value) : children);
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export { QueryErrorResetBoundary, useQueryErrorResetBoundary };
|
|
38
|
-
//# sourceMappingURL=QueryErrorResetBoundary.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"QueryErrorResetBoundary.esm.js","sources":["../../src/QueryErrorResetBoundary.tsx"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\n// CONTEXT\n\nexport interface QueryErrorResetBoundaryValue {\n clearReset: () => void\n isReset: () => boolean\n reset: () => void\n}\n\nfunction createValue(): QueryErrorResetBoundaryValue {\n let isReset = false\n return {\n clearReset: () => {\n isReset = false\n },\n reset: () => {\n isReset = true\n },\n isReset: () => {\n return isReset\n },\n }\n}\n\nconst QueryErrorResetBoundaryContext = React.createContext(createValue())\n\n// HOOK\n\nexport const useQueryErrorResetBoundary = () =>\n React.useContext(QueryErrorResetBoundaryContext)\n\n// COMPONENT\n\nexport interface QueryErrorResetBoundaryProps {\n children:\n | ((value: QueryErrorResetBoundaryValue) => React.ReactNode)\n | React.ReactNode\n}\n\nexport const QueryErrorResetBoundary = ({\n children,\n}: QueryErrorResetBoundaryProps) => {\n const [value] = React.useState(() => createValue())\n return (\n <QueryErrorResetBoundaryContext.Provider value={value}>\n {typeof children === 'function'\n ? (children as Function)(value)\n : children}\n </QueryErrorResetBoundaryContext.Provider>\n )\n}\n"],"names":["isReset","children","value"],"mappings":";;;AAGA;;AAQA;;;;AAIMA;;;AAGAA;;;AAGA;AACF;;AAEJ;AAEA;;AAEA;;AAEO;;AAGP;;AAQO;AACLC;AAC4B;AAC5B;AACA;AAC2CC;;AAM7C;;"}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { shouldThrowError } from './utils.esm.js';
|
|
4
|
-
|
|
5
|
-
const ensurePreventErrorBoundaryRetry = (options, errorResetBoundary) => {
|
|
6
|
-
if (options.suspense || options.throwOnError) {
|
|
7
|
-
// Prevent retrying failed query if the error boundary has not been reset yet
|
|
8
|
-
if (!errorResetBoundary.isReset()) {
|
|
9
|
-
options.retryOnMount = false;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
const useClearResetErrorBoundary = errorResetBoundary => {
|
|
14
|
-
React.useEffect(() => {
|
|
15
|
-
errorResetBoundary.clearReset();
|
|
16
|
-
}, [errorResetBoundary]);
|
|
17
|
-
};
|
|
18
|
-
const getHasError = ({
|
|
19
|
-
result,
|
|
20
|
-
errorResetBoundary,
|
|
21
|
-
throwOnError,
|
|
22
|
-
query
|
|
23
|
-
}) => {
|
|
24
|
-
return result.isError && !errorResetBoundary.isReset() && !result.isFetching && shouldThrowError(throwOnError, [result.error, query]);
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
export { ensurePreventErrorBoundaryRetry, getHasError, useClearResetErrorBoundary };
|
|
28
|
-
//# sourceMappingURL=errorBoundaryUtils.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"errorBoundaryUtils.esm.js","sources":["../../src/errorBoundaryUtils.ts"],"sourcesContent":["'use client'\nimport type {\n DefaultedQueryObserverOptions,\n Query,\n QueryKey,\n QueryObserverResult,\n ThrowOnError,\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.throwOnError) {\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 throwOnError,\n query,\n}: {\n result: QueryObserverResult<TData, TError>\n errorResetBoundary: QueryErrorResetBoundaryValue\n throwOnError: ThrowOnError<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(throwOnError, [result.error, query])\n )\n}\n"],"names":["useClearResetErrorBoundary","query"],"mappings":";;;;;AA4BE;AACE;AACA;;AAEA;AACF;AACF;AAEaA;;;AAKX;AACF;AAEO;;;;AAULC;AAMF;;AAOA;;"}
|
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 { queryOptions, 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":";;;;;;;;;;"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
|
|
4
|
-
const IsRestoringContext = /*#__PURE__*/React.createContext(false);
|
|
5
|
-
const useIsRestoring = () => React.useContext(IsRestoringContext);
|
|
6
|
-
const IsRestoringProvider = IsRestoringContext.Provider;
|
|
7
|
-
|
|
8
|
-
export { IsRestoringProvider, useIsRestoring };
|
|
9
|
-
//# 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":["IsRestoringProvider"],"mappings":";;;AAGA;AAEO;AACMA;;"}
|
|
@@ -1,17 +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).catch(() => {
|
|
13
|
-
errorResetBoundary.clearReset();
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
export { ensureStaleTime, fetchOptimistic, shouldSuspend, willFetch };
|
|
17
|
-
//# sourceMappingURL=suspense.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"suspense.esm.js","sources":["../../src/suspense.ts"],"sourcesContent":["import type {\n DefaultedQueryObserverOptions,\n QueryObserverResult,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport type { QueryErrorResetBoundaryValue } from './QueryErrorResetBoundary'\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.fetchOptimistic(defaultedOptions).catch(() => {\n errorResetBoundary.clearReset()\n })\n"],"names":["ensureStaleTime","defaultedOptions","suspense","staleTime","willFetch","result","isRestoring","isLoading","isFetching","shouldSuspend","fetchOptimistic","observer","errorResetBoundary","catch","clearReset"],"mappings":"AAQaA,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,GAAGA,CACvBC,MAAqC,EACrCC,WAAoB,KACjBD,MAAM,CAACE,SAAS,IAAIF,MAAM,CAACG,UAAU,IAAI,CAACF,YAAW;AAEnD,MAAMG,aAAa,GAAGA,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,GAAGA,CAO7BT,gBAMC,EACDU,QAA2E,EAC3EC,kBAAgD,KAEhDD,QAAQ,CAACD,eAAe,CAACT,gBAAgB,CAAC,CAACY,KAAK,CAAC,MAAM;EACrDD,kBAAkB,CAACE,UAAU,EAAE,CAAA;AACjC,CAAC;;;;"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.esm.js';
|
|
5
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
6
|
-
import { useIsRestoring } from './isRestoring.esm.js';
|
|
7
|
-
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.esm.js';
|
|
8
|
-
import { ensureStaleTime, shouldSuspend, fetchOptimistic } from './suspense.esm.js';
|
|
9
|
-
|
|
10
|
-
function useBaseQuery(options, Observer, queryClient) {
|
|
11
|
-
const client = useQueryClient(queryClient);
|
|
12
|
-
const isRestoring = useIsRestoring();
|
|
13
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
14
|
-
const defaultedOptions = client.defaultQueryOptions(options);
|
|
15
|
-
|
|
16
|
-
// Make sure results are optimistically set in fetching state before subscribing or updating options
|
|
17
|
-
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
18
|
-
ensureStaleTime(defaultedOptions);
|
|
19
|
-
ensurePreventErrorBoundaryRetry(defaultedOptions, errorResetBoundary);
|
|
20
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
21
|
-
const [observer] = React.useState(() => new Observer(client, defaultedOptions));
|
|
22
|
-
const result = observer.getOptimisticResult(defaultedOptions);
|
|
23
|
-
React.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
24
|
-
React.useEffect(() => {
|
|
25
|
-
// Do not notify on updates because of changes in the options because
|
|
26
|
-
// these changes should already be reflected in the optimistic result.
|
|
27
|
-
observer.setOptions(defaultedOptions, {
|
|
28
|
-
listeners: false
|
|
29
|
-
});
|
|
30
|
-
}, [defaultedOptions, observer]);
|
|
31
|
-
|
|
32
|
-
// Handle suspense
|
|
33
|
-
if (shouldSuspend(defaultedOptions, result, isRestoring)) {
|
|
34
|
-
throw fetchOptimistic(defaultedOptions, observer, errorResetBoundary);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// Handle error boundary
|
|
38
|
-
if (getHasError({
|
|
39
|
-
result,
|
|
40
|
-
errorResetBoundary,
|
|
41
|
-
throwOnError: defaultedOptions.throwOnError,
|
|
42
|
-
query: observer.getCurrentQuery()
|
|
43
|
-
})) {
|
|
44
|
-
throw result.error;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Handle result property usage tracking
|
|
48
|
-
return !defaultedOptions.notifyOnChangeProps ? observer.trackResult(result) : result;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
export { useBaseQuery };
|
|
52
|
-
//# sourceMappingURL=useBaseQuery.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useBaseQuery.esm.js","sources":["../../src/useBaseQuery.ts"],"sourcesContent":["'use client'\nimport * 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 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 throwOnError: defaultedOptions.throwOnError,\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":["defaultedOptions","ensurePreventErrorBoundaryRetry","observer","listeners","query"],"mappings":";;;;;;;;;AAgBO;AAiBL;AACA;AACA;AACA;;AAEA;AACAA;;AAKAC;;AAIA;AAQA;;;AAeE;AACA;AACAC;AAAwCC;AAAiB;AAC3D;;AAEA;;AAEE;AACF;;AAEA;AACA;;;;AAKIC;AACF;;AAGF;;AAEA;AACA;AAGF;;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { InfiniteQueryObserver } from '@tanstack/query-core';
|
|
3
|
-
import { useBaseQuery } from './useBaseQuery.esm.js';
|
|
4
|
-
|
|
5
|
-
// HOOK
|
|
6
|
-
function useInfiniteQuery(options, queryClient) {
|
|
7
|
-
return useBaseQuery(options,
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
9
|
-
InfiniteQueryObserver, queryClient);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { useInfiniteQuery };
|
|
13
|
-
//# sourceMappingURL=useInfiniteQuery.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useInfiniteQuery.esm.js","sources":["../../src/useInfiniteQuery.ts"],"sourcesContent":["'use client'\nimport 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":[],"mappings":";;;;AAYA;AACO;;AAmBH;;AAIJ;;"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
|
|
6
|
-
function useIsFetching(filters, queryClient) {
|
|
7
|
-
const client = useQueryClient(queryClient);
|
|
8
|
-
const queryCache = client.getQueryCache();
|
|
9
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => client.isFetching(filters), () => client.isFetching(filters));
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export { useIsFetching };
|
|
13
|
-
//# sourceMappingURL=useIsFetching.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useIsFetching.esm.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["'use client'\nimport * 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":[],"mappings":";;;;;AAOO;AAIL;AACA;AAEA;AASF;;"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { MutationObserver, notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
import { shouldThrowError } from './utils.esm.js';
|
|
6
|
-
|
|
7
|
-
// HOOK
|
|
8
|
-
|
|
9
|
-
function useMutation(options, queryClient) {
|
|
10
|
-
const client = useQueryClient(queryClient);
|
|
11
|
-
const [observer] = React.useState(() => new MutationObserver(client, options));
|
|
12
|
-
React.useEffect(() => {
|
|
13
|
-
observer.setOptions(options);
|
|
14
|
-
}, [observer, options]);
|
|
15
|
-
const result = React.useSyncExternalStore(React.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
16
|
-
const mutate = React.useCallback((variables, mutateOptions) => {
|
|
17
|
-
observer.mutate(variables, mutateOptions).catch(noop);
|
|
18
|
-
}, [observer]);
|
|
19
|
-
if (result.error && shouldThrowError(observer.options.throwOnError, [result.error])) {
|
|
20
|
-
throw result.error;
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
...result,
|
|
24
|
-
mutate,
|
|
25
|
-
mutateAsync: result.mutate
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
30
|
-
function noop() {}
|
|
31
|
-
|
|
32
|
-
export { useMutation };
|
|
33
|
-
//# sourceMappingURL=useMutation.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.esm.js","sources":["../../src/useMutation.ts"],"sourcesContent":["'use client'\nimport * 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.throwOnError, [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":["observer"],"mappings":";;;;;;AAYA;;AAEO;AASL;AAEA;;AASEA;AACF;AAEA;;;AAeE;AAIF;;AAKA;;AAES;;;;AACX;;AAEA;AACA;;"}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { replaceEqualDeep, notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
|
|
6
|
-
function useIsMutating(filters, queryClient) {
|
|
7
|
-
const client = useQueryClient(queryClient);
|
|
8
|
-
return useMutationState({
|
|
9
|
-
filters: {
|
|
10
|
-
...filters,
|
|
11
|
-
status: 'pending'
|
|
12
|
-
}
|
|
13
|
-
}, client).length;
|
|
14
|
-
}
|
|
15
|
-
function getResult(mutationCache, options) {
|
|
16
|
-
return mutationCache.findAll(options.filters).map(mutation => options.select ? options.select(mutation) : mutation.state);
|
|
17
|
-
}
|
|
18
|
-
function useMutationState(options = {}, queryClient) {
|
|
19
|
-
const mutationCache = useQueryClient(queryClient).getMutationCache();
|
|
20
|
-
const optionsRef = React.useRef(options);
|
|
21
|
-
const result = React.useRef();
|
|
22
|
-
if (!result.current) {
|
|
23
|
-
result.current = getResult(mutationCache, options);
|
|
24
|
-
}
|
|
25
|
-
React.useEffect(() => {
|
|
26
|
-
optionsRef.current = options;
|
|
27
|
-
});
|
|
28
|
-
return React.useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(() => {
|
|
29
|
-
const nextResult = replaceEqualDeep(result.current, getResult(mutationCache, optionsRef.current));
|
|
30
|
-
if (result.current !== nextResult) {
|
|
31
|
-
result.current = nextResult;
|
|
32
|
-
notifyManager.schedule(onStoreChange);
|
|
33
|
-
}
|
|
34
|
-
}), [mutationCache]), () => result.current, () => result.current);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
export { useIsMutating, useMutationState };
|
|
38
|
-
//# sourceMappingURL=useMutationState.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMutationState.esm.js","sources":["../../src/useMutationState.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type {\n MutationFilters,\n QueryClient,\n Mutation,\n MutationCache,\n DefaultError,\n MutationState,\n} from '@tanstack/query-core'\nimport { notifyManager, replaceEqualDeep } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\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 = MutationState> = {\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 = MutationState>(\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":["filters","status","notifyManager"],"mappings":";;;;;AAcO;AAIL;AACA;AACIA;AAAW;AAAYC;AAAkB;AAAE;AAGjD;AASA;;AAcA;AAEO;;AAKL;AACA;AACA;;AAEA;;;AAIA;AAEA;AAIQ;AAIA;;AAEEC;AACF;AACF;AAMR;;"}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import * as React from 'react';
|
|
3
|
-
import { QueriesObserver, notifyManager } from '@tanstack/query-core';
|
|
4
|
-
import { useQueryClient } from './QueryClientProvider.esm.js';
|
|
5
|
-
import { useIsRestoring } from './isRestoring.esm.js';
|
|
6
|
-
import { useQueryErrorResetBoundary } from './QueryErrorResetBoundary.esm.js';
|
|
7
|
-
import { ensurePreventErrorBoundaryRetry, useClearResetErrorBoundary, getHasError } from './errorBoundaryUtils.esm.js';
|
|
8
|
-
import { ensureStaleTime, shouldSuspend, fetchOptimistic, willFetch } from './suspense.esm.js';
|
|
9
|
-
|
|
10
|
-
// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.
|
|
11
|
-
// `placeholderData` function does not have a parameter
|
|
12
|
-
// Avoid TS depth-limit error in case of large array literal
|
|
13
|
-
/**
|
|
14
|
-
* QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param
|
|
15
|
-
*/
|
|
16
|
-
/**
|
|
17
|
-
* QueriesResults reducer recursively maps type param to results
|
|
18
|
-
*/
|
|
19
|
-
function useQueries({
|
|
20
|
-
queries,
|
|
21
|
-
...options
|
|
22
|
-
}, queryClient) {
|
|
23
|
-
const client = useQueryClient(queryClient);
|
|
24
|
-
const isRestoring = useIsRestoring();
|
|
25
|
-
const errorResetBoundary = useQueryErrorResetBoundary();
|
|
26
|
-
const defaultedQueries = React.useMemo(() => queries.map(opts => {
|
|
27
|
-
const defaultedOptions = client.defaultQueryOptions(opts);
|
|
28
|
-
|
|
29
|
-
// Make sure the results are already in fetching state before subscribing or updating options
|
|
30
|
-
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
31
|
-
return defaultedOptions;
|
|
32
|
-
}), [queries, client, isRestoring]);
|
|
33
|
-
defaultedQueries.forEach(query => {
|
|
34
|
-
ensureStaleTime(query);
|
|
35
|
-
ensurePreventErrorBoundaryRetry(query, errorResetBoundary);
|
|
36
|
-
});
|
|
37
|
-
useClearResetErrorBoundary(errorResetBoundary);
|
|
38
|
-
const [observer] = React.useState(() => new QueriesObserver(client, defaultedQueries, options));
|
|
39
|
-
const [optimisticResult, getCombinedResult, trackResult] = observer.getOptimisticResult(defaultedQueries);
|
|
40
|
-
React.useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
41
|
-
React.useEffect(() => {
|
|
42
|
-
// Do not notify on updates because of changes in the options because
|
|
43
|
-
// these changes should already be reflected in the optimistic result.
|
|
44
|
-
observer.setQueries(defaultedQueries, options, {
|
|
45
|
-
listeners: false
|
|
46
|
-
});
|
|
47
|
-
}, [defaultedQueries, options, observer]);
|
|
48
|
-
const shouldAtLeastOneSuspend = optimisticResult.some((result, index) => shouldSuspend(defaultedQueries[index], result, isRestoring));
|
|
49
|
-
const suspensePromises = shouldAtLeastOneSuspend ? optimisticResult.flatMap((result, index) => {
|
|
50
|
-
const opts = defaultedQueries[index];
|
|
51
|
-
const queryObserver = observer.getObservers()[index];
|
|
52
|
-
if (opts && queryObserver) {
|
|
53
|
-
if (shouldSuspend(opts, result, isRestoring)) {
|
|
54
|
-
return fetchOptimistic(opts, queryObserver, errorResetBoundary);
|
|
55
|
-
} else if (willFetch(result, isRestoring)) {
|
|
56
|
-
void fetchOptimistic(opts, queryObserver, errorResetBoundary);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
return [];
|
|
60
|
-
}) : [];
|
|
61
|
-
if (suspensePromises.length > 0) {
|
|
62
|
-
throw Promise.all(suspensePromises);
|
|
63
|
-
}
|
|
64
|
-
const observerQueries = observer.getQueries();
|
|
65
|
-
const firstSingleResultWhichShouldThrow = optimisticResult.find((result, index) => {
|
|
66
|
-
var _defaultedQueries$ind, _defaultedQueries$ind2;
|
|
67
|
-
return getHasError({
|
|
68
|
-
result,
|
|
69
|
-
errorResetBoundary,
|
|
70
|
-
throwOnError: (_defaultedQueries$ind = (_defaultedQueries$ind2 = defaultedQueries[index]) == null ? void 0 : _defaultedQueries$ind2.throwOnError) != null ? _defaultedQueries$ind : false,
|
|
71
|
-
query: observerQueries[index]
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
if (firstSingleResultWhichShouldThrow != null && firstSingleResultWhichShouldThrow.error) {
|
|
75
|
-
throw firstSingleResultWhichShouldThrow.error;
|
|
76
|
-
}
|
|
77
|
-
return getCombinedResult(trackResult());
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export { useQueries };
|
|
81
|
-
//# sourceMappingURL=useQueries.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useQueries.esm.js","sources":["../../src/useQueries.ts"],"sourcesContent":["'use client'\nimport * as React from 'react'\n\nimport type {\n QueryKey,\n QueryFunction,\n QueriesPlaceholderDataFunction,\n QueryClient,\n DefaultError,\n QueriesObserverOptions,\n} from '@tanstack/query-core'\nimport { notifyManager, QueriesObserver } from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport type { UseQueryOptions, UseQueryResult } from './types'\nimport { useIsRestoring } from './isRestoring'\nimport { useQueryErrorResetBoundary } from './QueryErrorResetBoundary'\nimport {\n ensurePreventErrorBoundaryRetry,\n getHasError,\n useClearResetErrorBoundary,\n} from './errorBoundaryUtils'\nimport {\n ensureStaleTime,\n shouldSuspend,\n fetchOptimistic,\n willFetch,\n} from './suspense'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// `placeholderData` function does not have a parameter\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'placeholderData'\n> & {\n placeholderData?: TQueryFnData | QueriesPlaceholderDataFunction<TQueryFnData>\n}\n\n// Avoid TS depth-limit error in case of large array literal\ntype MAXIMUM_DEPTH = 20\n\ntype GetOptions<T> =\n // Part 1: responsible for applying explicit type parameter to function arguments, if object { queryFnData: TQueryFnData, error: TError, data: TData }\n T extends {\n queryFnData: infer TQueryFnData\n error?: infer TError\n data: infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryOptionsForUseQueries<unknown, TError, TData>\n : // Part 2: responsible for applying explicit type parameter to function arguments, if tuple [TQueryFnData, TError, TData]\n T extends [infer TQueryFnData, infer TError, infer TData]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryOptionsForUseQueries<TQueryFnData>\n : // Part 3: responsible for inferring and enforcing type if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey>\n select: (data: any) => infer TData\n }\n ? UseQueryOptionsForUseQueries<TQueryFnData, Error, TData, TQueryKey>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> }\n ? UseQueryOptionsForUseQueries<TQueryFnData, Error, TQueryFnData, TQueryKey>\n : // Fallback\n UseQueryOptionsForUseQueries\n\ntype GetResults<T> =\n // Part 1: responsible for mapping explicit type parameter to function result, if object\n T extends { queryFnData: any; error?: infer TError; data: infer TData }\n ? UseQueryResult<TData, TError>\n : T extends { queryFnData: infer TQueryFnData; error?: infer TError }\n ? UseQueryResult<TQueryFnData, TError>\n : T extends { data: infer TData; error?: infer TError }\n ? UseQueryResult<TData, TError>\n : // Part 2: responsible for mapping explicit type parameter to function result, if tuple\n T extends [any, infer TError, infer TData]\n ? UseQueryResult<TData, TError>\n : T extends [infer TQueryFnData, infer TError]\n ? UseQueryResult<TQueryFnData, TError>\n : T extends [infer TQueryFnData]\n ? UseQueryResult<TQueryFnData>\n : // Part 3: responsible for mapping inferred type to results, if no explicit parameter was provided\n T extends {\n queryFn?: QueryFunction<unknown, any>\n select: (data: any) => infer TData\n }\n ? UseQueryResult<TData>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, any> }\n ? UseQueryResult<TQueryFnData>\n : // Fallback\n UseQueryResult\n\n/**\n * QueriesOptions reducer recursively unwraps function arguments to infer/enforce type param\n */\nexport type QueriesOptions<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? UseQueryOptionsForUseQueries[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetOptions<Head>]\n : T extends [infer Head, ...infer Tail]\n ? QueriesOptions<[...Tail], [...Result, GetOptions<Head>], [...Depth, 1]>\n : unknown[] extends T\n ? T\n : // If T is *some* array but we couldn't assign unknown[] to it, then it must hold some known/homogenous type!\n // use this to infer the param types in the case of Array.map() argument\n T extends UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n infer TQueryKey\n >[]\n ? UseQueryOptionsForUseQueries<TQueryFnData, TError, TData, TQueryKey>[]\n : // Fallback\n UseQueryOptionsForUseQueries[]\n\n/**\n * QueriesResults reducer recursively maps type param to results\n */\nexport type QueriesResults<\n T extends any[],\n Result extends any[] = [],\n Depth extends ReadonlyArray<number> = [],\n> = Depth['length'] extends MAXIMUM_DEPTH\n ? UseQueryResult[]\n : T extends []\n ? []\n : T extends [infer Head]\n ? [...Result, GetResults<Head>]\n : T extends [infer Head, ...infer Tail]\n ? QueriesResults<[...Tail], [...Result, GetResults<Head>], [...Depth, 1]>\n : T extends UseQueryOptionsForUseQueries<\n infer TQueryFnData,\n infer TError,\n infer TData,\n any\n >[]\n ? // Dynamic-size (homogenous) UseQueryOptions array: map directly to array of results\n UseQueryResult<\n unknown extends TData ? TQueryFnData : TData,\n unknown extends TError ? DefaultError : TError\n >[]\n : // Fallback\n UseQueryResult[]\n\nexport function useQueries<\n T extends any[],\n TCombinedResult = QueriesResults<T>,\n>(\n {\n queries,\n ...options\n }: {\n queries: readonly [...QueriesOptions<T>]\n combine?: (result: QueriesResults<T>) => TCombinedResult\n },\n queryClient?: QueryClient,\n): TCombinedResult {\n const client = useQueryClient(queryClient)\n const isRestoring = useIsRestoring()\n const errorResetBoundary = useQueryErrorResetBoundary()\n\n const defaultedQueries = React.useMemo(\n () =>\n queries.map((opts) => {\n const defaultedOptions = client.defaultQueryOptions(opts)\n\n // Make sure the results are already in fetching state before subscribing or updating options\n defaultedOptions._optimisticResults = isRestoring\n ? 'isRestoring'\n : 'optimistic'\n\n return defaultedOptions\n }),\n [queries, client, isRestoring],\n )\n\n defaultedQueries.forEach((query) => {\n ensureStaleTime(query)\n ensurePreventErrorBoundaryRetry(query, errorResetBoundary)\n })\n\n useClearResetErrorBoundary(errorResetBoundary)\n\n const [observer] = React.useState(\n () =>\n new QueriesObserver<TCombinedResult>(\n client,\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n ),\n )\n\n const [optimisticResult, getCombinedResult, trackResult] =\n observer.getOptimisticResult(defaultedQueries)\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.setQueries(\n defaultedQueries,\n options as QueriesObserverOptions<TCombinedResult>,\n {\n listeners: false,\n },\n )\n }, [defaultedQueries, options, observer])\n\n const shouldAtLeastOneSuspend = optimisticResult.some((result, index) =>\n shouldSuspend(defaultedQueries[index], result, isRestoring),\n )\n\n const suspensePromises = shouldAtLeastOneSuspend\n ? optimisticResult.flatMap((result, index) => {\n const opts = defaultedQueries[index]\n const queryObserver = observer.getObservers()[index]\n\n if (opts && queryObserver) {\n if (shouldSuspend(opts, result, isRestoring)) {\n return fetchOptimistic(opts, queryObserver, errorResetBoundary)\n } else if (willFetch(result, isRestoring)) {\n void fetchOptimistic(opts, queryObserver, errorResetBoundary)\n }\n }\n return []\n })\n : []\n\n if (suspensePromises.length > 0) {\n throw Promise.all(suspensePromises)\n }\n const observerQueries = observer.getQueries()\n const firstSingleResultWhichShouldThrow = optimisticResult.find(\n (result, index) =>\n getHasError({\n result,\n errorResetBoundary,\n throwOnError: defaultedQueries[index]?.throwOnError ?? false,\n query: observerQueries[index]!,\n }),\n )\n\n if (firstSingleResultWhichShouldThrow?.error) {\n throw firstSingleResultWhichShouldThrow.error\n }\n\n return getCombinedResult(trackResult())\n}\n"],"names":["defaultedOptions","defaultedQueries","ensurePreventErrorBoundaryRetry","observer","listeners","throwOnError"],"mappings":";;;;;;;;;AA4BA;AACA;AAaA;AA2DA;AACA;AACA;AA2BA;AACA;AACA;AA2BO;;;AAUL;AAGA;AACA;AACA;AAEA;AAGM;;AAEA;AACAA;AAIA;;AAKNC;;AAEEC;AACF;;AAIA;AASA;;;AAgBE;AACA;AACAC;AAIIC;AACF;;;AAQJ;AAEM;;;;AAKI;;AAEA;AACF;AACF;AACA;;AAIN;AACE;AACF;AACA;;;AAEgB;;;AAIVC;;AAEF;AAAE;AAGN;;AAEA;AAEA;AACF;;"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
import { QueryObserver } from '@tanstack/query-core';
|
|
3
|
-
import { useBaseQuery } from './useBaseQuery.esm.js';
|
|
4
|
-
|
|
5
|
-
function queryOptions(options) {
|
|
6
|
-
return options;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// HOOK
|
|
10
|
-
|
|
11
|
-
function useQuery(options, queryClient) {
|
|
12
|
-
return useBaseQuery(options, QueryObserver, queryClient);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export { queryOptions, useQuery };
|
|
16
|
-
//# sourceMappingURL=useQuery.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.esm.js","sources":["../../src/useQuery.ts"],"sourcesContent":["'use client'\nimport type { QueryClient, QueryKey, DefaultError } from '@tanstack/query-core'\nimport { QueryObserver } from '@tanstack/query-core'\nimport type {\n DefinedUseQueryResult,\n UseQueryOptions,\n UseQueryResult,\n} from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>\n\nexport function queryOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n): DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>\n\nexport function queryOptions(options: unknown) {\n return options\n}\n\n// HOOK\ntype UndefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData?: undefined\n}\n\ntype DefinedInitialDataOptions<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = UseQueryOptions<TQueryFnData, TError, TData, TQueryKey> & {\n initialData: TQueryFnData | (() => TQueryFnData)\n}\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UndefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: DefinedInitialDataOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = DefaultError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n queryClient?: QueryClient,\n) {\n return useBaseQuery(options, QueryObserver, queryClient)\n}\n"],"names":[],"mappings":";;;;AA4BO;AACL;AACF;;AAEA;;AAuCO;AASL;AACF;;"}
|
package/build/lib/utils.esm.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
function shouldThrowError(throwError, params) {
|
|
2
|
-
// Allow throwError function to override throwing behavior on a per-error basis
|
|
3
|
-
if (typeof throwError === 'function') {
|
|
4
|
-
return throwError(...params);
|
|
5
|
-
}
|
|
6
|
-
return !!throwError;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export { shouldThrowError };
|
|
10
|
-
//# sourceMappingURL=utils.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["export function shouldThrowError<T extends (...args: any[]) => boolean>(\n throwError: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow throwError function to override throwing behavior on a per-error basis\n if (typeof throwError === 'function') {\n return throwError(...params)\n }\n\n return !!throwError\n}\n"],"names":["shouldThrowError","throwError","params"],"mappings":"AAAO,SAASA,gBAAgBA,CAC9BC,UAAmC,EACnCC,MAAqB,EACZ;AACT;AACA,EAAA,IAAI,OAAOD,UAAU,KAAK,UAAU,EAAE;AACpC,IAAA,OAAOA,UAAU,CAAC,GAAGC,MAAM,CAAC,CAAA;AAC9B,GAAA;EAEA,OAAO,CAAC,CAACD,UAAU,CAAA;AACrB;;;;"}
|