@tanstack/react-query 4.3.0-beta.1 → 4.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/lib/Hydrate.js +56 -0
- package/build/lib/Hydrate.js.map +1 -0
- package/build/lib/Hydrate.mjs +31 -0
- package/build/lib/Hydrate.mjs.map +1 -0
- package/build/lib/QueryClientProvider.js +86 -0
- package/build/lib/QueryClientProvider.js.map +1 -0
- package/build/lib/QueryClientProvider.mjs +60 -0
- package/build/lib/QueryClientProvider.mjs.map +1 -0
- package/build/lib/QueryErrorResetBoundary.js +57 -0
- package/build/lib/QueryErrorResetBoundary.js.map +1 -0
- package/build/lib/QueryErrorResetBoundary.mjs +32 -0
- package/build/lib/QueryErrorResetBoundary.mjs.map +1 -0
- package/build/lib/index.js +29 -613
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +11 -577
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/isRestoring.js +33 -0
- package/build/lib/isRestoring.js.map +1 -0
- package/build/lib/isRestoring.mjs +8 -0
- package/build/lib/isRestoring.mjs.map +1 -0
- package/build/lib/reactBatchedUpdates.js +30 -0
- package/build/lib/reactBatchedUpdates.js.map +1 -0
- package/build/lib/reactBatchedUpdates.mjs +6 -0
- package/build/lib/reactBatchedUpdates.mjs.map +1 -0
- package/build/lib/reactBatchedUpdates.native.js +13 -0
- package/build/lib/reactBatchedUpdates.native.js.map +1 -0
- package/build/lib/reactBatchedUpdates.native.mjs +2 -0
- package/build/lib/reactBatchedUpdates.native.mjs.map +1 -0
- package/build/lib/setBatchUpdatesFn.js +7 -0
- package/build/lib/setBatchUpdatesFn.js.map +1 -0
- package/build/lib/setBatchUpdatesFn.mjs +5 -0
- package/build/lib/setBatchUpdatesFn.mjs.map +1 -0
- package/build/lib/useBaseQuery.js +107 -0
- package/build/lib/useBaseQuery.js.map +1 -0
- package/build/lib/useBaseQuery.mjs +83 -0
- package/build/lib/useBaseQuery.mjs.map +1 -0
- package/build/lib/useInfiniteQuery.js +14 -0
- package/build/lib/useInfiniteQuery.js.map +1 -0
- package/build/lib/useInfiniteQuery.mjs +10 -0
- package/build/lib/useInfiniteQuery.mjs.map +1 -0
- package/build/lib/useIsFetching.js +40 -0
- package/build/lib/useIsFetching.js.map +1 -0
- package/build/lib/useIsFetching.mjs +16 -0
- package/build/lib/useIsFetching.mjs.map +1 -0
- package/build/lib/useIsMutating.js +40 -0
- package/build/lib/useIsMutating.js.map +1 -0
- package/build/lib/useIsMutating.mjs +16 -0
- package/build/lib/useIsMutating.mjs.map +1 -0
- package/build/lib/useMutation.js +58 -0
- package/build/lib/useMutation.js.map +1 -0
- package/build/lib/useMutation.mjs +34 -0
- package/build/lib/useMutation.mjs.map +1 -0
- package/build/lib/useQueries.js +61 -0
- package/build/lib/useQueries.js.map +1 -0
- package/build/lib/useQueries.mjs +37 -0
- package/build/lib/useQueries.mjs.map +1 -0
- package/build/lib/useQuery.js +14 -0
- package/build/lib/useQuery.js.map +1 -0
- package/build/lib/useQuery.mjs +10 -0
- package/build/lib/useQuery.mjs.map +1 -0
- package/build/lib/utils.js +15 -0
- package/build/lib/utils.js.map +1 -0
- package/build/lib/utils.mjs +11 -0
- package/build/lib/utils.mjs.map +1 -0
- package/build/umd/index.development.js +0 -20
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -22
- package/build/umd/index.production.js.map +1 -1
- package/package.json +3 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsFetching.js","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import * as React from 'react'\nimport {\n QueryKey,\n notifyManager,\n parseFilterArgs,\n QueryFilters,\n} from '@tanstack/query-core'\n\nimport { useSyncExternalStore } from './useSyncExternalStore'\nimport { ContextOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\n\ninterface Options extends ContextOptions {}\n\nexport function useIsFetching(filters?: QueryFilters, options?: Options): number\nexport function useIsFetching(\n queryKey?: QueryKey,\n filters?: QueryFilters,\n options?: Options,\n): number\nexport function useIsFetching(\n arg1?: QueryKey | QueryFilters,\n arg2?: QueryFilters | Options,\n arg3?: Options,\n): number {\n const [filters, options = {}] = parseFilterArgs(arg1, arg2, arg3)\n const queryClient = useQueryClient({ context: options.context })\n const queryCache = queryClient.getQueryCache()\n\n return useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => queryClient.isFetching(filters),\n () => queryClient.isFetching(filters),\n )\n}\n"],"names":["useIsFetching","arg1","arg2","arg3","filters","options","parseFilterArgs","queryClient","useQueryClient","context","queryCache","getQueryCache","useSyncExternalStore","React","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isFetching"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoBO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGLC,IAHK,EAIG;AACR,EAAA,MAAM,CAACC,OAAD,EAAUC,OAAO,GAAG,EAApB,CAAA,GAA0BC,yBAAe,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAA/C,CAAA;EACA,MAAMI,WAAW,GAAGC,kCAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,UAAU,GAAGH,WAAW,CAACI,aAAZ,EAAnB,CAAA;AAEA,EAAA,OAAOC,6BAAoB,CACzBC,gBAAK,CAACC,WAAN,CACGC,aAAD,IACEL,UAAU,CAACM,SAAX,CAAqBC,uBAAa,CAACC,UAAd,CAAyBH,aAAzB,CAArB,CAFJ,EAGE,CAACL,UAAD,CAHF,CADyB,EAMzB,MAAMH,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CANmB,EAOzB,MAAMG,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CAPmB,CAA3B,CAAA;AASD;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { parseFilterArgs, notifyManager } from '@tanstack/query-core';
|
|
3
|
+
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
5
|
+
|
|
6
|
+
function useIsFetching(arg1, arg2, arg3) {
|
|
7
|
+
const [filters, options = {}] = parseFilterArgs(arg1, arg2, arg3);
|
|
8
|
+
const queryClient = useQueryClient({
|
|
9
|
+
context: options.context
|
|
10
|
+
});
|
|
11
|
+
const queryCache = queryClient.getQueryCache();
|
|
12
|
+
return useSyncExternalStore(React.useCallback(onStoreChange => queryCache.subscribe(notifyManager.batchCalls(onStoreChange)), [queryCache]), () => queryClient.isFetching(filters), () => queryClient.isFetching(filters));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { useIsFetching };
|
|
16
|
+
//# sourceMappingURL=useIsFetching.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsFetching.mjs","sources":["../../src/useIsFetching.ts"],"sourcesContent":["import * as React from 'react'\nimport {\n QueryKey,\n notifyManager,\n parseFilterArgs,\n QueryFilters,\n} from '@tanstack/query-core'\n\nimport { useSyncExternalStore } from './useSyncExternalStore'\nimport { ContextOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\n\ninterface Options extends ContextOptions {}\n\nexport function useIsFetching(filters?: QueryFilters, options?: Options): number\nexport function useIsFetching(\n queryKey?: QueryKey,\n filters?: QueryFilters,\n options?: Options,\n): number\nexport function useIsFetching(\n arg1?: QueryKey | QueryFilters,\n arg2?: QueryFilters | Options,\n arg3?: Options,\n): number {\n const [filters, options = {}] = parseFilterArgs(arg1, arg2, arg3)\n const queryClient = useQueryClient({ context: options.context })\n const queryCache = queryClient.getQueryCache()\n\n return useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n queryCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [queryCache],\n ),\n () => queryClient.isFetching(filters),\n () => queryClient.isFetching(filters),\n )\n}\n"],"names":["useIsFetching","arg1","arg2","arg3","filters","options","parseFilterArgs","queryClient","useQueryClient","context","queryCache","getQueryCache","useSyncExternalStore","React","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isFetching"],"mappings":";;;;;AAoBO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGLC,IAHK,EAIG;AACR,EAAA,MAAM,CAACC,OAAD,EAAUC,OAAO,GAAG,EAApB,CAAA,GAA0BC,eAAe,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAA/C,CAAA;EACA,MAAMI,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,UAAU,GAAGH,WAAW,CAACI,aAAZ,EAAnB,CAAA;AAEA,EAAA,OAAOC,oBAAoB,CACzBC,KAAK,CAACC,WAAN,CACGC,aAAD,IACEL,UAAU,CAACM,SAAX,CAAqBC,aAAa,CAACC,UAAd,CAAyBH,aAAzB,CAArB,CAFJ,EAGE,CAACL,UAAD,CAHF,CADyB,EAMzB,MAAMH,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CANmB,EAOzB,MAAMG,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CAPmB,CAA3B,CAAA;AASD;;;;"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var queryCore = require('@tanstack/query-core');
|
|
7
|
+
var QueryClientProvider = require('./QueryClientProvider.js');
|
|
8
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
9
|
+
|
|
10
|
+
function _interopNamespace(e) {
|
|
11
|
+
if (e && e.__esModule) return e;
|
|
12
|
+
var n = Object.create(null);
|
|
13
|
+
if (e) {
|
|
14
|
+
Object.keys(e).forEach(function (k) {
|
|
15
|
+
if (k !== 'default') {
|
|
16
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
get: function () { return e[k]; }
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
n["default"] = e;
|
|
25
|
+
return Object.freeze(n);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
29
|
+
|
|
30
|
+
function useIsMutating(arg1, arg2, arg3) {
|
|
31
|
+
const [filters, options = {}] = queryCore.parseMutationFilterArgs(arg1, arg2, arg3);
|
|
32
|
+
const queryClient = QueryClientProvider.useQueryClient({
|
|
33
|
+
context: options.context
|
|
34
|
+
});
|
|
35
|
+
const mutationCache = queryClient.getMutationCache();
|
|
36
|
+
return index_js.useSyncExternalStore(React__namespace.useCallback(onStoreChange => mutationCache.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [mutationCache]), () => queryClient.isMutating(filters), () => queryClient.isMutating(filters));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.useIsMutating = useIsMutating;
|
|
40
|
+
//# sourceMappingURL=useIsMutating.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsMutating.js","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n notifyManager,\n MutationKey,\n MutationFilters,\n parseMutationFilterArgs,\n} from '@tanstack/query-core'\nimport { ContextOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\n\ninterface Options extends ContextOptions {}\n\nexport function useIsMutating(\n filters?: MutationFilters,\n options?: Options,\n): number\nexport function useIsMutating(\n mutationKey?: MutationKey,\n filters?: Omit<MutationFilters, 'mutationKey'>,\n options?: Options,\n): number\nexport function useIsMutating(\n arg1?: MutationKey | MutationFilters,\n arg2?: Omit<MutationFilters, 'mutationKey'> | Options,\n arg3?: Options,\n): number {\n const [filters, options = {}] = parseMutationFilterArgs(arg1, arg2, arg3)\n\n const queryClient = useQueryClient({ context: options.context })\n const mutationCache = queryClient.getMutationCache()\n\n return useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [mutationCache],\n ),\n () => queryClient.isMutating(filters),\n () => queryClient.isMutating(filters),\n )\n}\n"],"names":["useIsMutating","arg1","arg2","arg3","filters","options","parseMutationFilterArgs","queryClient","useQueryClient","context","mutationCache","getMutationCache","useSyncExternalStore","React","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isMutating"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAuBO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGLC,IAHK,EAIG;AACR,EAAA,MAAM,CAACC,OAAD,EAAUC,OAAO,GAAG,EAApB,CAAA,GAA0BC,iCAAuB,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAAvD,CAAA;EAEA,MAAMI,WAAW,GAAGC,kCAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,aAAa,GAAGH,WAAW,CAACI,gBAAZ,EAAtB,CAAA;AAEA,EAAA,OAAOC,6BAAoB,CACzBC,gBAAK,CAACC,WAAN,CACGC,aAAD,IACEL,aAAa,CAACM,SAAd,CAAwBC,uBAAa,CAACC,UAAd,CAAyBH,aAAzB,CAAxB,CAFJ,EAGE,CAACL,aAAD,CAHF,CADyB,EAMzB,MAAMH,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CANmB,EAOzB,MAAMG,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CAPmB,CAA3B,CAAA;AASD;;;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { parseMutationFilterArgs, notifyManager } from '@tanstack/query-core';
|
|
3
|
+
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
5
|
+
|
|
6
|
+
function useIsMutating(arg1, arg2, arg3) {
|
|
7
|
+
const [filters, options = {}] = parseMutationFilterArgs(arg1, arg2, arg3);
|
|
8
|
+
const queryClient = useQueryClient({
|
|
9
|
+
context: options.context
|
|
10
|
+
});
|
|
11
|
+
const mutationCache = queryClient.getMutationCache();
|
|
12
|
+
return useSyncExternalStore(React.useCallback(onStoreChange => mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)), [mutationCache]), () => queryClient.isMutating(filters), () => queryClient.isMutating(filters));
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export { useIsMutating };
|
|
16
|
+
//# sourceMappingURL=useIsMutating.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useIsMutating.mjs","sources":["../../src/useIsMutating.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n notifyManager,\n MutationKey,\n MutationFilters,\n parseMutationFilterArgs,\n} from '@tanstack/query-core'\nimport { ContextOptions } from './types'\nimport { useQueryClient } from './QueryClientProvider'\n\ninterface Options extends ContextOptions {}\n\nexport function useIsMutating(\n filters?: MutationFilters,\n options?: Options,\n): number\nexport function useIsMutating(\n mutationKey?: MutationKey,\n filters?: Omit<MutationFilters, 'mutationKey'>,\n options?: Options,\n): number\nexport function useIsMutating(\n arg1?: MutationKey | MutationFilters,\n arg2?: Omit<MutationFilters, 'mutationKey'> | Options,\n arg3?: Options,\n): number {\n const [filters, options = {}] = parseMutationFilterArgs(arg1, arg2, arg3)\n\n const queryClient = useQueryClient({ context: options.context })\n const mutationCache = queryClient.getMutationCache()\n\n return useSyncExternalStore(\n React.useCallback(\n (onStoreChange) =>\n mutationCache.subscribe(notifyManager.batchCalls(onStoreChange)),\n [mutationCache],\n ),\n () => queryClient.isMutating(filters),\n () => queryClient.isMutating(filters),\n )\n}\n"],"names":["useIsMutating","arg1","arg2","arg3","filters","options","parseMutationFilterArgs","queryClient","useQueryClient","context","mutationCache","getMutationCache","useSyncExternalStore","React","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","isMutating"],"mappings":";;;;;AAuBO,SAASA,aAAT,CACLC,IADK,EAELC,IAFK,EAGLC,IAHK,EAIG;AACR,EAAA,MAAM,CAACC,OAAD,EAAUC,OAAO,GAAG,EAApB,CAAA,GAA0BC,uBAAuB,CAACL,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAAvD,CAAA;EAEA,MAAMI,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AACA,EAAA,MAAMC,aAAa,GAAGH,WAAW,CAACI,gBAAZ,EAAtB,CAAA;AAEA,EAAA,OAAOC,oBAAoB,CACzBC,KAAK,CAACC,WAAN,CACGC,aAAD,IACEL,aAAa,CAACM,SAAd,CAAwBC,aAAa,CAACC,UAAd,CAAyBH,aAAzB,CAAxB,CAFJ,EAGE,CAACL,aAAD,CAHF,CADyB,EAMzB,MAAMH,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CANmB,EAOzB,MAAMG,WAAW,CAACY,UAAZ,CAAuBf,OAAvB,CAPmB,CAA3B,CAAA;AASD;;;;"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var queryCore = require('@tanstack/query-core');
|
|
7
|
+
var QueryClientProvider = require('./QueryClientProvider.js');
|
|
8
|
+
var utils = require('./utils.js');
|
|
9
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
10
|
+
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n["default"] = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
|
+
|
|
31
|
+
function useMutation(arg1, arg2, arg3) {
|
|
32
|
+
const options = queryCore.parseMutationArgs(arg1, arg2, arg3);
|
|
33
|
+
const queryClient = QueryClientProvider.useQueryClient({
|
|
34
|
+
context: options.context
|
|
35
|
+
});
|
|
36
|
+
const [observer] = React__namespace.useState(() => new queryCore.MutationObserver(queryClient, options));
|
|
37
|
+
React__namespace.useEffect(() => {
|
|
38
|
+
observer.setOptions(options);
|
|
39
|
+
}, [observer, options]);
|
|
40
|
+
const result = index_js.useSyncExternalStore(React__namespace.useCallback(onStoreChange => observer.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
41
|
+
const mutate = React__namespace.useCallback((variables, mutateOptions) => {
|
|
42
|
+
observer.mutate(variables, mutateOptions).catch(noop);
|
|
43
|
+
}, [observer]);
|
|
44
|
+
|
|
45
|
+
if (result.error && utils.shouldThrowError(observer.options.useErrorBoundary, [result.error])) {
|
|
46
|
+
throw result.error;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return { ...result,
|
|
50
|
+
mutate,
|
|
51
|
+
mutateAsync: result.mutate
|
|
52
|
+
};
|
|
53
|
+
} // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
54
|
+
|
|
55
|
+
function noop() {}
|
|
56
|
+
|
|
57
|
+
exports.useMutation = useMutation;
|
|
58
|
+
//# sourceMappingURL=useMutation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMutation.js","sources":["../../src/useMutation.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n notifyManager,\n parseMutationArgs,\n MutationObserver,\n MutationFunction,\n MutationKey,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\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 = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationFn: MutationFunction<TData, TVariables>,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationFn'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MutationKey,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationKey'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MutationKey,\n mutationFn?: MutationFunction<TData, TVariables>,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationKey' | 'mutationFn'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n arg1:\n | MutationKey\n | MutationFunction<TData, TVariables>\n | UseMutationOptions<TData, TError, TVariables, TContext>,\n arg2?:\n | MutationFunction<TData, TVariables>\n | UseMutationOptions<TData, TError, TVariables, TContext>,\n arg3?: UseMutationOptions<TData, TError, TVariables, TContext>,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const options = parseMutationArgs(arg1, arg2, arg3)\n const queryClient = useQueryClient({ context: options.context })\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n queryClient,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = 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.useErrorBoundary, [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","arg1","arg2","arg3","options","parseMutationArgs","queryClient","useQueryClient","context","observer","React","useState","MutationObserver","useEffect","setOptions","result","useSyncExternalStore","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","getCurrentResult","mutate","variables","mutateOptions","catch","noop","error","shouldThrowError","useErrorBoundary","mutateAsync"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEO,SAASA,WAAT,CAMLC,IANK,EAULC,IAVK,EAaLC,IAbK,EAcmD;EACxD,MAAMC,OAAO,GAAGC,2BAAiB,CAACJ,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAAjC,CAAA;EACA,MAAMG,WAAW,GAAGC,kCAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AAEA,EAAA,MAAM,CAACC,QAAD,CAAaC,GAAAA,gBAAK,CAACC,QAAN,CACjB,MACE,IAAIC,0BAAJ,CACEN,WADF,EAEEF,OAFF,CAFe,CAAnB,CAAA;EAQAM,gBAAK,CAACG,SAAN,CAAgB,MAAM;IACpBJ,QAAQ,CAACK,UAAT,CAAoBV,OAApB,CAAA,CAAA;AACD,GAFD,EAEG,CAACK,QAAD,EAAWL,OAAX,CAFH,CAAA,CAAA;AAIA,EAAA,MAAMW,MAAM,GAAGC,6BAAoB,CACjCN,gBAAK,CAACO,WAAN,CACGC,aAAD,IACET,QAAQ,CAACU,SAAT,CAAmBC,uBAAa,CAACC,UAAd,CAAyBH,aAAzB,CAAnB,CAFJ,EAGE,CAACT,QAAD,CAHF,CADiC,EAMjC,MAAMA,QAAQ,CAACa,gBAAT,EAN2B,EAOjC,MAAMb,QAAQ,CAACa,gBAAT,EAP2B,CAAnC,CAAA;EAUA,MAAMC,MAAM,GAAGb,gBAAK,CAACO,WAAN,CAGb,CAACO,SAAD,EAAYC,aAAZ,KAA8B;IAC5BhB,QAAQ,CAACc,MAAT,CAAgBC,SAAhB,EAA2BC,aAA3B,CAAA,CAA0CC,KAA1C,CAAgDC,IAAhD,CAAA,CAAA;AACD,GALY,EAMb,CAAClB,QAAD,CANa,CAAf,CAAA;;AASA,EAAA,IACEM,MAAM,CAACa,KAAP,IACAC,sBAAgB,CAACpB,QAAQ,CAACL,OAAT,CAAiB0B,gBAAlB,EAAoC,CAACf,MAAM,CAACa,KAAR,CAApC,CAFlB,EAGE;IACA,MAAMb,MAAM,CAACa,KAAb,CAAA;AACD,GAAA;;EAED,OAAO,EAAE,GAAGb,MAAL;IAAaQ,MAAb;IAAqBQ,WAAW,EAAEhB,MAAM,CAACQ,MAAAA;GAAhD,CAAA;AACD;;AAGD,SAASI,IAAT,GAAgB;;;;"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { parseMutationArgs, MutationObserver, notifyManager } from '@tanstack/query-core';
|
|
3
|
+
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
+
import { shouldThrowError } from './utils.mjs';
|
|
5
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
6
|
+
|
|
7
|
+
function useMutation(arg1, arg2, arg3) {
|
|
8
|
+
const options = parseMutationArgs(arg1, arg2, arg3);
|
|
9
|
+
const queryClient = useQueryClient({
|
|
10
|
+
context: options.context
|
|
11
|
+
});
|
|
12
|
+
const [observer] = React.useState(() => new MutationObserver(queryClient, options));
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
observer.setOptions(options);
|
|
15
|
+
}, [observer, options]);
|
|
16
|
+
const result = useSyncExternalStore(React.useCallback(onStoreChange => observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
17
|
+
const mutate = React.useCallback((variables, mutateOptions) => {
|
|
18
|
+
observer.mutate(variables, mutateOptions).catch(noop);
|
|
19
|
+
}, [observer]);
|
|
20
|
+
|
|
21
|
+
if (result.error && shouldThrowError(observer.options.useErrorBoundary, [result.error])) {
|
|
22
|
+
throw result.error;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return { ...result,
|
|
26
|
+
mutate,
|
|
27
|
+
mutateAsync: result.mutate
|
|
28
|
+
};
|
|
29
|
+
} // eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
30
|
+
|
|
31
|
+
function noop() {}
|
|
32
|
+
|
|
33
|
+
export { useMutation };
|
|
34
|
+
//# sourceMappingURL=useMutation.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useMutation.mjs","sources":["../../src/useMutation.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n notifyManager,\n parseMutationArgs,\n MutationObserver,\n MutationFunction,\n MutationKey,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport {\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 = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n options: UseMutationOptions<TData, TError, TVariables, TContext>,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationFn: MutationFunction<TData, TVariables>,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationFn'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MutationKey,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationKey'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n mutationKey: MutationKey,\n mutationFn?: MutationFunction<TData, TVariables>,\n options?: Omit<\n UseMutationOptions<TData, TError, TVariables, TContext>,\n 'mutationKey' | 'mutationFn'\n >,\n): UseMutationResult<TData, TError, TVariables, TContext>\nexport function useMutation<\n TData = unknown,\n TError = unknown,\n TVariables = void,\n TContext = unknown,\n>(\n arg1:\n | MutationKey\n | MutationFunction<TData, TVariables>\n | UseMutationOptions<TData, TError, TVariables, TContext>,\n arg2?:\n | MutationFunction<TData, TVariables>\n | UseMutationOptions<TData, TError, TVariables, TContext>,\n arg3?: UseMutationOptions<TData, TError, TVariables, TContext>,\n): UseMutationResult<TData, TError, TVariables, TContext> {\n const options = parseMutationArgs(arg1, arg2, arg3)\n const queryClient = useQueryClient({ context: options.context })\n\n const [observer] = React.useState(\n () =>\n new MutationObserver<TData, TError, TVariables, TContext>(\n queryClient,\n options,\n ),\n )\n\n React.useEffect(() => {\n observer.setOptions(options)\n }, [observer, options])\n\n const result = 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.useErrorBoundary, [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","arg1","arg2","arg3","options","parseMutationArgs","queryClient","useQueryClient","context","observer","React","useState","MutationObserver","useEffect","setOptions","result","useSyncExternalStore","useCallback","onStoreChange","subscribe","notifyManager","batchCalls","getCurrentResult","mutate","variables","mutateOptions","catch","noop","error","shouldThrowError","useErrorBoundary","mutateAsync"],"mappings":";;;;;;AAiEO,SAASA,WAAT,CAMLC,IANK,EAULC,IAVK,EAaLC,IAbK,EAcmD;EACxD,MAAMC,OAAO,GAAGC,iBAAiB,CAACJ,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAAjC,CAAA;EACA,MAAMG,WAAW,GAAGC,cAAc,CAAC;IAAEC,OAAO,EAAEJ,OAAO,CAACI,OAAAA;AAAnB,GAAD,CAAlC,CAAA;AAEA,EAAA,MAAM,CAACC,QAAD,CAAaC,GAAAA,KAAK,CAACC,QAAN,CACjB,MACE,IAAIC,gBAAJ,CACEN,WADF,EAEEF,OAFF,CAFe,CAAnB,CAAA;EAQAM,KAAK,CAACG,SAAN,CAAgB,MAAM;IACpBJ,QAAQ,CAACK,UAAT,CAAoBV,OAApB,CAAA,CAAA;AACD,GAFD,EAEG,CAACK,QAAD,EAAWL,OAAX,CAFH,CAAA,CAAA;AAIA,EAAA,MAAMW,MAAM,GAAGC,oBAAoB,CACjCN,KAAK,CAACO,WAAN,CACGC,aAAD,IACET,QAAQ,CAACU,SAAT,CAAmBC,aAAa,CAACC,UAAd,CAAyBH,aAAzB,CAAnB,CAFJ,EAGE,CAACT,QAAD,CAHF,CADiC,EAMjC,MAAMA,QAAQ,CAACa,gBAAT,EAN2B,EAOjC,MAAMb,QAAQ,CAACa,gBAAT,EAP2B,CAAnC,CAAA;EAUA,MAAMC,MAAM,GAAGb,KAAK,CAACO,WAAN,CAGb,CAACO,SAAD,EAAYC,aAAZ,KAA8B;IAC5BhB,QAAQ,CAACc,MAAT,CAAgBC,SAAhB,EAA2BC,aAA3B,CAAA,CAA0CC,KAA1C,CAAgDC,IAAhD,CAAA,CAAA;AACD,GALY,EAMb,CAAClB,QAAD,CANa,CAAf,CAAA;;AASA,EAAA,IACEM,MAAM,CAACa,KAAP,IACAC,gBAAgB,CAACpB,QAAQ,CAACL,OAAT,CAAiB0B,gBAAlB,EAAoC,CAACf,MAAM,CAACa,KAAR,CAApC,CAFlB,EAGE;IACA,MAAMb,MAAM,CAACa,KAAb,CAAA;AACD,GAAA;;EAED,OAAO,EAAE,GAAGb,MAAL;IAAaQ,MAAb;IAAqBQ,WAAW,EAAEhB,MAAM,CAACQ,MAAAA;GAAhD,CAAA;AACD;;AAGD,SAASI,IAAT,GAAgB;;;;"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var queryCore = require('@tanstack/query-core');
|
|
7
|
+
var QueryClientProvider = require('./QueryClientProvider.js');
|
|
8
|
+
var isRestoring = require('./isRestoring.js');
|
|
9
|
+
var index_js = require('use-sync-external-store/shim/index.js');
|
|
10
|
+
|
|
11
|
+
function _interopNamespace(e) {
|
|
12
|
+
if (e && e.__esModule) return e;
|
|
13
|
+
var n = Object.create(null);
|
|
14
|
+
if (e) {
|
|
15
|
+
Object.keys(e).forEach(function (k) {
|
|
16
|
+
if (k !== 'default') {
|
|
17
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
18
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () { return e[k]; }
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
n["default"] = e;
|
|
26
|
+
return Object.freeze(n);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
30
|
+
|
|
31
|
+
// - `context` is omitted as it is passed as a root-level option to `useQueries` instead.
|
|
32
|
+
|
|
33
|
+
function useQueries({
|
|
34
|
+
queries,
|
|
35
|
+
context
|
|
36
|
+
}) {
|
|
37
|
+
const queryClient = QueryClientProvider.useQueryClient({
|
|
38
|
+
context
|
|
39
|
+
});
|
|
40
|
+
const isRestoring$1 = isRestoring.useIsRestoring();
|
|
41
|
+
const defaultedQueries = React__namespace.useMemo(() => queries.map(options => {
|
|
42
|
+
const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure the results are already in fetching state before subscribing or updating options
|
|
43
|
+
|
|
44
|
+
defaultedOptions._optimisticResults = isRestoring$1 ? 'isRestoring' : 'optimistic';
|
|
45
|
+
return defaultedOptions;
|
|
46
|
+
}), [queries, queryClient, isRestoring$1]);
|
|
47
|
+
const [observer] = React__namespace.useState(() => new queryCore.QueriesObserver(queryClient, defaultedQueries));
|
|
48
|
+
const result = observer.getOptimisticResult(defaultedQueries);
|
|
49
|
+
index_js.useSyncExternalStore(React__namespace.useCallback(onStoreChange => isRestoring$1 ? () => undefined : observer.subscribe(queryCore.notifyManager.batchCalls(onStoreChange)), [observer, isRestoring$1]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
50
|
+
React__namespace.useEffect(() => {
|
|
51
|
+
// Do not notify on updates because of changes in the options because
|
|
52
|
+
// these changes should already be reflected in the optimistic result.
|
|
53
|
+
observer.setQueries(defaultedQueries, {
|
|
54
|
+
listeners: false
|
|
55
|
+
});
|
|
56
|
+
}, [defaultedQueries, observer]);
|
|
57
|
+
return result;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
exports.useQueries = useQueries;
|
|
61
|
+
//# sourceMappingURL=useQueries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueries.js","sources":["../../src/useQueries.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n QueryKey,\n QueryFunction,\n notifyManager,\n QueriesObserver,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { UseQueryOptions, UseQueryResult } from './types'\nimport { useIsRestoring } from './isRestoring'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// - `context` is omitted as it is passed as a root-level option to `useQueries` instead.\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'context'>\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, unknown, TData, TQueryKey>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> }\n ? UseQueryOptionsForUseQueries<\n TQueryFnData,\n unknown,\n TQueryFnData,\n TQueryKey\n >\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<unknown extends TData ? TQueryFnData : TData, TError>[]\n : // Fallback\n UseQueryResult[]\n\nexport function useQueries<T extends any[]>({\n queries,\n context,\n}: {\n queries: readonly [...QueriesOptions<T>]\n context?: UseQueryOptions['context']\n}): QueriesResults<T> {\n const queryClient = useQueryClient({ context })\n const isRestoring = useIsRestoring()\n\n const defaultedQueries = React.useMemo(\n () =>\n queries.map((options) => {\n const defaultedOptions = queryClient.defaultQueryOptions(options)\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, queryClient, isRestoring],\n )\n\n const [observer] = React.useState(\n () => new QueriesObserver(queryClient, defaultedQueries),\n )\n\n const result = observer.getOptimisticResult(defaultedQueries)\n\n 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(defaultedQueries, { listeners: false })\n }, [defaultedQueries, observer])\n\n return result as QueriesResults<T>\n}\n"],"names":["useQueries","queries","context","queryClient","useQueryClient","isRestoring","useIsRestoring","defaultedQueries","React","useMemo","map","options","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","useState","QueriesObserver","result","getOptimisticResult","useSyncExternalStore","useCallback","onStoreChange","undefined","subscribe","notifyManager","batchCalls","getCurrentResult","useEffect","setQueries","listeners"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA;;AA+HO,SAASA,UAAT,CAAqC;EAC1CC,OAD0C;AAE1CC,EAAAA,OAAAA;AAF0C,CAArC,EAMe;EACpB,MAAMC,WAAW,GAAGC,kCAAc,CAAC;AAAEF,IAAAA,OAAAA;AAAF,GAAD,CAAlC,CAAA;EACA,MAAMG,aAAW,GAAGC,0BAAc,EAAlC,CAAA;AAEA,EAAA,MAAMC,gBAAgB,GAAGC,gBAAK,CAACC,OAAN,CACvB,MACER,OAAO,CAACS,GAAR,CAAaC,OAAD,IAAa;IACvB,MAAMC,gBAAgB,GAAGT,WAAW,CAACU,mBAAZ,CAAgCF,OAAhC,CAAzB,CADuB;;AAIvBC,IAAAA,gBAAgB,CAACE,kBAAjB,GAAsCT,aAAW,GAC7C,aAD6C,GAE7C,YAFJ,CAAA;AAIA,IAAA,OAAOO,gBAAP,CAAA;GARF,CAFqB,EAYvB,CAACX,OAAD,EAAUE,WAAV,EAAuBE,aAAvB,CAZuB,CAAzB,CAAA;AAeA,EAAA,MAAM,CAACU,QAAD,CAAaP,GAAAA,gBAAK,CAACQ,QAAN,CACjB,MAAM,IAAIC,yBAAJ,CAAoBd,WAApB,EAAiCI,gBAAjC,CADW,CAAnB,CAAA;AAIA,EAAA,MAAMW,MAAM,GAAGH,QAAQ,CAACI,mBAAT,CAA6BZ,gBAA7B,CAAf,CAAA;AAEAa,EAAAA,6BAAoB,CAClBZ,gBAAK,CAACa,WAAN,CACGC,aAAD,IACEjB,aAAW,GACP,MAAMkB,SADC,GAEPR,QAAQ,CAACS,SAAT,CAAmBC,uBAAa,CAACC,UAAd,CAAyBJ,aAAzB,CAAnB,CAJR,EAKE,CAACP,QAAD,EAAWV,aAAX,CALF,CADkB,EAQlB,MAAMU,QAAQ,CAACY,gBAAT,EARY,EASlB,MAAMZ,QAAQ,CAACY,gBAAT,EATY,CAApB,CAAA;EAYAnB,gBAAK,CAACoB,SAAN,CAAgB,MAAM;AACpB;AACA;AACAb,IAAAA,QAAQ,CAACc,UAAT,CAAoBtB,gBAApB,EAAsC;AAAEuB,MAAAA,SAAS,EAAE,KAAA;KAAnD,CAAA,CAAA;AACD,GAJD,EAIG,CAACvB,gBAAD,EAAmBQ,QAAnB,CAJH,CAAA,CAAA;AAMA,EAAA,OAAOG,MAAP,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { QueriesObserver, notifyManager } from '@tanstack/query-core';
|
|
3
|
+
import { useQueryClient } from './QueryClientProvider.mjs';
|
|
4
|
+
import { useIsRestoring } from './isRestoring.mjs';
|
|
5
|
+
import { useSyncExternalStore } from 'use-sync-external-store/shim/index.js';
|
|
6
|
+
|
|
7
|
+
// - `context` is omitted as it is passed as a root-level option to `useQueries` instead.
|
|
8
|
+
|
|
9
|
+
function useQueries({
|
|
10
|
+
queries,
|
|
11
|
+
context
|
|
12
|
+
}) {
|
|
13
|
+
const queryClient = useQueryClient({
|
|
14
|
+
context
|
|
15
|
+
});
|
|
16
|
+
const isRestoring = useIsRestoring();
|
|
17
|
+
const defaultedQueries = React.useMemo(() => queries.map(options => {
|
|
18
|
+
const defaultedOptions = queryClient.defaultQueryOptions(options); // Make sure the results are already in fetching state before subscribing or updating options
|
|
19
|
+
|
|
20
|
+
defaultedOptions._optimisticResults = isRestoring ? 'isRestoring' : 'optimistic';
|
|
21
|
+
return defaultedOptions;
|
|
22
|
+
}), [queries, queryClient, isRestoring]);
|
|
23
|
+
const [observer] = React.useState(() => new QueriesObserver(queryClient, defaultedQueries));
|
|
24
|
+
const result = observer.getOptimisticResult(defaultedQueries);
|
|
25
|
+
useSyncExternalStore(React.useCallback(onStoreChange => isRestoring ? () => undefined : observer.subscribe(notifyManager.batchCalls(onStoreChange)), [observer, isRestoring]), () => observer.getCurrentResult(), () => observer.getCurrentResult());
|
|
26
|
+
React.useEffect(() => {
|
|
27
|
+
// Do not notify on updates because of changes in the options because
|
|
28
|
+
// these changes should already be reflected in the optimistic result.
|
|
29
|
+
observer.setQueries(defaultedQueries, {
|
|
30
|
+
listeners: false
|
|
31
|
+
});
|
|
32
|
+
}, [defaultedQueries, observer]);
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export { useQueries };
|
|
37
|
+
//# sourceMappingURL=useQueries.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQueries.mjs","sources":["../../src/useQueries.ts"],"sourcesContent":["import * as React from 'react'\nimport { useSyncExternalStore } from './useSyncExternalStore'\n\nimport {\n QueryKey,\n QueryFunction,\n notifyManager,\n QueriesObserver,\n} from '@tanstack/query-core'\nimport { useQueryClient } from './QueryClientProvider'\nimport { UseQueryOptions, UseQueryResult } from './types'\nimport { useIsRestoring } from './isRestoring'\n\n// This defines the `UseQueryOptions` that are accepted in `QueriesOptions` & `GetOptions`.\n// - `context` is omitted as it is passed as a root-level option to `useQueries` instead.\ntype UseQueryOptionsForUseQueries<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> = Omit<UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>, 'context'>\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, unknown, TData, TQueryKey>\n : T extends { queryFn?: QueryFunction<infer TQueryFnData, infer TQueryKey> }\n ? UseQueryOptionsForUseQueries<\n TQueryFnData,\n unknown,\n TQueryFnData,\n TQueryKey\n >\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<unknown extends TData ? TQueryFnData : TData, TError>[]\n : // Fallback\n UseQueryResult[]\n\nexport function useQueries<T extends any[]>({\n queries,\n context,\n}: {\n queries: readonly [...QueriesOptions<T>]\n context?: UseQueryOptions['context']\n}): QueriesResults<T> {\n const queryClient = useQueryClient({ context })\n const isRestoring = useIsRestoring()\n\n const defaultedQueries = React.useMemo(\n () =>\n queries.map((options) => {\n const defaultedOptions = queryClient.defaultQueryOptions(options)\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, queryClient, isRestoring],\n )\n\n const [observer] = React.useState(\n () => new QueriesObserver(queryClient, defaultedQueries),\n )\n\n const result = observer.getOptimisticResult(defaultedQueries)\n\n 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(defaultedQueries, { listeners: false })\n }, [defaultedQueries, observer])\n\n return result as QueriesResults<T>\n}\n"],"names":["useQueries","queries","context","queryClient","useQueryClient","isRestoring","useIsRestoring","defaultedQueries","React","useMemo","map","options","defaultedOptions","defaultQueryOptions","_optimisticResults","observer","useState","QueriesObserver","result","getOptimisticResult","useSyncExternalStore","useCallback","onStoreChange","undefined","subscribe","notifyManager","batchCalls","getCurrentResult","useEffect","setQueries","listeners"],"mappings":";;;;;;AAcA;;AA+HO,SAASA,UAAT,CAAqC;EAC1CC,OAD0C;AAE1CC,EAAAA,OAAAA;AAF0C,CAArC,EAMe;EACpB,MAAMC,WAAW,GAAGC,cAAc,CAAC;AAAEF,IAAAA,OAAAA;AAAF,GAAD,CAAlC,CAAA;EACA,MAAMG,WAAW,GAAGC,cAAc,EAAlC,CAAA;AAEA,EAAA,MAAMC,gBAAgB,GAAGC,KAAK,CAACC,OAAN,CACvB,MACER,OAAO,CAACS,GAAR,CAAaC,OAAD,IAAa;IACvB,MAAMC,gBAAgB,GAAGT,WAAW,CAACU,mBAAZ,CAAgCF,OAAhC,CAAzB,CADuB;;AAIvBC,IAAAA,gBAAgB,CAACE,kBAAjB,GAAsCT,WAAW,GAC7C,aAD6C,GAE7C,YAFJ,CAAA;AAIA,IAAA,OAAOO,gBAAP,CAAA;GARF,CAFqB,EAYvB,CAACX,OAAD,EAAUE,WAAV,EAAuBE,WAAvB,CAZuB,CAAzB,CAAA;AAeA,EAAA,MAAM,CAACU,QAAD,CAAaP,GAAAA,KAAK,CAACQ,QAAN,CACjB,MAAM,IAAIC,eAAJ,CAAoBd,WAApB,EAAiCI,gBAAjC,CADW,CAAnB,CAAA;AAIA,EAAA,MAAMW,MAAM,GAAGH,QAAQ,CAACI,mBAAT,CAA6BZ,gBAA7B,CAAf,CAAA;AAEAa,EAAAA,oBAAoB,CAClBZ,KAAK,CAACa,WAAN,CACGC,aAAD,IACEjB,WAAW,GACP,MAAMkB,SADC,GAEPR,QAAQ,CAACS,SAAT,CAAmBC,aAAa,CAACC,UAAd,CAAyBJ,aAAzB,CAAnB,CAJR,EAKE,CAACP,QAAD,EAAWV,WAAX,CALF,CADkB,EAQlB,MAAMU,QAAQ,CAACY,gBAAT,EARY,EASlB,MAAMZ,QAAQ,CAACY,gBAAT,EATY,CAApB,CAAA;EAYAnB,KAAK,CAACoB,SAAN,CAAgB,MAAM;AACpB;AACA;AACAb,IAAAA,QAAQ,CAACc,UAAT,CAAoBtB,gBAApB,EAAsC;AAAEuB,MAAAA,SAAS,EAAE,KAAA;KAAnD,CAAA,CAAA;AACD,GAJD,EAIG,CAACvB,gBAAD,EAAmBQ,QAAnB,CAJH,CAAA,CAAA;AAMA,EAAA,OAAOG,MAAP,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var queryCore = require('@tanstack/query-core');
|
|
6
|
+
var useBaseQuery = require('./useBaseQuery.js');
|
|
7
|
+
|
|
8
|
+
function useQuery(arg1, arg2, arg3) {
|
|
9
|
+
const parsedOptions = queryCore.parseQueryArgs(arg1, arg2, arg3);
|
|
10
|
+
return useBaseQuery.useBaseQuery(parsedOptions, queryCore.QueryObserver);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.useQuery = useQuery;
|
|
14
|
+
//# sourceMappingURL=useQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.js","sources":["../../src/useQuery.ts"],"sourcesContent":["import {\n parseQueryArgs,\n QueryFunction,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport { DefinedUseQueryResult, UseQueryOptions, UseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n// HOOK\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn'\n >,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1: TQueryKey | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n arg2?:\n | QueryFunction<TQueryFnData, TQueryKey>\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n arg3?: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UseQueryResult<TData, TError> {\n const parsedOptions = parseQueryArgs(arg1, arg2, arg3)\n return useBaseQuery(parsedOptions, QueryObserver)\n}\n"],"names":["useQuery","arg1","arg2","arg3","parsedOptions","parseQueryArgs","useBaseQuery","QueryObserver"],"mappings":";;;;;;;AA6HO,SAASA,QAAT,CAMLC,IANK,EAOLC,IAPK,EAULC,IAVK,EAW0B;EAC/B,MAAMC,aAAa,GAAGC,wBAAc,CAACJ,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAApC,CAAA;AACA,EAAA,OAAOG,yBAAY,CAACF,aAAD,EAAgBG,uBAAhB,CAAnB,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { parseQueryArgs, QueryObserver } from '@tanstack/query-core';
|
|
2
|
+
import { useBaseQuery } from './useBaseQuery.mjs';
|
|
3
|
+
|
|
4
|
+
function useQuery(arg1, arg2, arg3) {
|
|
5
|
+
const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
|
|
6
|
+
return useBaseQuery(parsedOptions, QueryObserver);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export { useQuery };
|
|
10
|
+
//# sourceMappingURL=useQuery.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useQuery.mjs","sources":["../../src/useQuery.ts"],"sourcesContent":["import {\n parseQueryArgs,\n QueryFunction,\n QueryKey,\n QueryObserver,\n} from '@tanstack/query-core'\nimport { DefinedUseQueryResult, UseQueryOptions, UseQueryResult } from './types'\nimport { useBaseQuery } from './useBaseQuery'\n\n// HOOK\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey'\n >,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData?: () => undefined },\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn' | 'initialData'\n > & { initialData: TQueryFnData | (() => TQueryFnData) },\n): DefinedUseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n queryKey: TQueryKey,\n queryFn: QueryFunction<TQueryFnData, TQueryKey>,\n options?: Omit<\n UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n 'queryKey' | 'queryFn'\n >,\n): UseQueryResult<TData, TError>\n\nexport function useQuery<\n TQueryFnData,\n TError,\n TData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n>(\n arg1: TQueryKey | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n arg2?:\n | QueryFunction<TQueryFnData, TQueryKey>\n | UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n arg3?: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>,\n): UseQueryResult<TData, TError> {\n const parsedOptions = parseQueryArgs(arg1, arg2, arg3)\n return useBaseQuery(parsedOptions, QueryObserver)\n}\n"],"names":["useQuery","arg1","arg2","arg3","parsedOptions","parseQueryArgs","useBaseQuery","QueryObserver"],"mappings":";;;AA6HO,SAASA,QAAT,CAMLC,IANK,EAOLC,IAPK,EAULC,IAVK,EAW0B;EAC/B,MAAMC,aAAa,GAAGC,cAAc,CAACJ,IAAD,EAAOC,IAAP,EAAaC,IAAb,CAApC,CAAA;AACA,EAAA,OAAOG,YAAY,CAACF,aAAD,EAAgBG,aAAhB,CAAnB,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
function shouldThrowError(_useErrorBoundary, params) {
|
|
6
|
+
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
|
7
|
+
if (typeof _useErrorBoundary === 'function') {
|
|
8
|
+
return _useErrorBoundary(...params);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return !!_useErrorBoundary;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.shouldThrowError = shouldThrowError;
|
|
15
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export function shouldThrowError<T extends (...args: any[]) => boolean>(\n _useErrorBoundary: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow useErrorBoundary function to override throwing behavior on a per-error basis\n if (typeof _useErrorBoundary === 'function') {\n return _useErrorBoundary(...params)\n }\n\n return !!_useErrorBoundary\n}\n"],"names":["shouldThrowError","_useErrorBoundary","params"],"mappings":";;;;AAAO,SAASA,gBAAT,CACLC,iBADK,EAELC,MAFK,EAGI;AACT;AACA,EAAA,IAAI,OAAOD,iBAAP,KAA6B,UAAjC,EAA6C;AAC3C,IAAA,OAAOA,iBAAiB,CAAC,GAAGC,MAAJ,CAAxB,CAAA;AACD,GAAA;;EAED,OAAO,CAAC,CAACD,iBAAT,CAAA;AACD;;;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
function shouldThrowError(_useErrorBoundary, params) {
|
|
2
|
+
// Allow useErrorBoundary function to override throwing behavior on a per-error basis
|
|
3
|
+
if (typeof _useErrorBoundary === 'function') {
|
|
4
|
+
return _useErrorBoundary(...params);
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
return !!_useErrorBoundary;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export { shouldThrowError };
|
|
11
|
+
//# sourceMappingURL=utils.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["export function shouldThrowError<T extends (...args: any[]) => boolean>(\n _useErrorBoundary: boolean | T | undefined,\n params: Parameters<T>,\n): boolean {\n // Allow useErrorBoundary function to override throwing behavior on a per-error basis\n if (typeof _useErrorBoundary === 'function') {\n return _useErrorBoundary(...params)\n }\n\n return !!_useErrorBoundary\n}\n"],"names":["shouldThrowError","_useErrorBoundary","params"],"mappings":"AAAO,SAASA,gBAAT,CACLC,iBADK,EAELC,MAFK,EAGI;AACT;AACA,EAAA,IAAI,OAAOD,iBAAP,KAA6B,UAAjC,EAA6C;AAC3C,IAAA,OAAOA,iBAAiB,CAAC,GAAGC,MAAJ,CAAxB,CAAA;AACD,GAAA;;EAED,OAAO,CAAC,CAACD,iBAAT,CAAA;AACD;;;;"}
|
|
@@ -1,13 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* react-query
|
|
3
|
-
*
|
|
4
|
-
* Copyright (c) TanStack
|
|
5
|
-
*
|
|
6
|
-
* This source code is licensed under the MIT license found in the
|
|
7
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
8
|
-
*
|
|
9
|
-
* @license MIT
|
|
10
|
-
*/
|
|
11
1
|
(function (global, factory) {
|
|
12
2
|
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react-dom'), require('react')) :
|
|
13
3
|
typeof define === 'function' && define.amd ? define(['exports', 'react-dom', 'react'], factory) :
|
|
@@ -38,16 +28,6 @@
|
|
|
38
28
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
39
29
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
40
30
|
|
|
41
|
-
/**
|
|
42
|
-
* query-core
|
|
43
|
-
*
|
|
44
|
-
* Copyright (c) TanStack
|
|
45
|
-
*
|
|
46
|
-
* This source code is licensed under the MIT license found in the
|
|
47
|
-
* LICENSE.md file in the root directory of this source tree.
|
|
48
|
-
*
|
|
49
|
-
* @license MIT
|
|
50
|
-
*/
|
|
51
31
|
class Subscribable {
|
|
52
32
|
constructor() {
|
|
53
33
|
this.listeners = [];
|