react-query-kit 2.0.7 → 2.0.8
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/README.md +5 -4
- package/build/lib/createSuspenseInfiniteQuery.esm.js +2 -2
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs +2 -2
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
- package/build/lib/createSuspenseQuery.esm.js +2 -2
- package/build/lib/createSuspenseQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseQuery.js +1 -1
- package/build/lib/createSuspenseQuery.js.map +1 -1
- package/build/lib/createSuspenseQuery.mjs +2 -2
- package/build/lib/createSuspenseQuery.mjs.map +1 -1
- package/build/lib/types.d.ts +37 -28
- package/build/lib/utils.d.ts +1 -2
- package/build/lib/utils.esm.js +4 -8
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +3 -7
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +4 -8
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +90 -90
- package/build/umd/index.development.js +5 -9
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/build/zip/zip.esm.js +1 -1
- package/package.json +2 -2
- package/src/createSuspenseInfiniteQuery.ts +7 -2
- package/src/createSuspenseQuery.ts +4 -2
- package/src/types.ts +99 -35
- package/src/utils.ts +6 -8
package/README.md
CHANGED
|
@@ -32,8 +32,6 @@
|
|
|
32
32
|
- Set defaultOptions for custom ReactQuery hooks easier and clearer
|
|
33
33
|
- Middleware
|
|
34
34
|
|
|
35
|
-

|
|
36
|
-
|
|
37
35
|
English | [简体中文](./README-zh_CN.md)
|
|
38
36
|
|
|
39
37
|
## Table of Contents
|
|
@@ -82,7 +80,7 @@ $ yarn add react-query-kit
|
|
|
82
80
|
|
|
83
81
|
```tsx
|
|
84
82
|
import { QueryClient, dehydrate } from '@tanstack/react-query'
|
|
85
|
-
import { createQuery
|
|
83
|
+
import { createQuery } from 'react-query-kit'
|
|
86
84
|
|
|
87
85
|
type Response = { title: string; content: string }
|
|
88
86
|
type Variables = { id: number }
|
|
@@ -140,8 +138,11 @@ const queries = useQueries({
|
|
|
140
138
|
],
|
|
141
139
|
})
|
|
142
140
|
|
|
141
|
+
// getQueryData
|
|
142
|
+
queryClient.getQueryData(usePost.getKey(variables)) // Response
|
|
143
|
+
|
|
143
144
|
// setQueryData
|
|
144
|
-
queryClient.setQueryData
|
|
145
|
+
queryClient.setQueryData(usePost.getKey(variables), {...})
|
|
145
146
|
```
|
|
146
147
|
|
|
147
148
|
### Additional API Reference
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useSuspenseInfiniteQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { createBaseQuery } from './createBaseQuery.esm.js';
|
|
3
3
|
import { suspenseOptions } from './utils.esm.js';
|
|
4
4
|
|
|
5
5
|
const createSuspenseInfiniteQuery = options => {
|
|
6
|
-
return createBaseQuery(options, useInfiniteQuery, suspenseOptions);
|
|
6
|
+
return useSuspenseInfiniteQuery ? createBaseQuery(options, useSuspenseInfiniteQuery) : createBaseQuery(options, useInfiniteQuery, suspenseOptions);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export { createSuspenseInfiniteQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseInfiniteQuery.esm.js","sources":["../../src/createSuspenseInfiniteQuery.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"createSuspenseInfiniteQuery.esm.js","sources":["../../src/createSuspenseInfiniteQuery.ts"],"sourcesContent":["import {\n useInfiniteQuery,\n useSuspenseInfiniteQuery,\n} from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return useSuspenseInfiniteQuery\n ? createBaseQuery(options, useSuspenseInfiniteQuery)\n : createBaseQuery(options, useInfiniteQuery, suspenseOptions)\n}\n"],"names":["createSuspenseInfiniteQuery","options","useSuspenseInfiniteQuery","createBaseQuery","useInfiniteQuery","suspenseOptions"],"mappings":";;;;AAaaA,MAAAA,2BAA2B,GAMtCC,OANyC,IAY8B;AACvE,EAAA,OAAOC,wBAAwB,GAC3BC,eAAe,CAACF,OAAD,EAAUC,wBAAV,CADY,GAE3BC,eAAe,CAACF,OAAD,EAAUG,gBAAV,EAA4BC,eAA5B,CAFnB,CAAA;AAGD;;;;"}
|
|
@@ -7,7 +7,7 @@ var createBaseQuery = require('./createBaseQuery.js');
|
|
|
7
7
|
var utils = require('./utils.js');
|
|
8
8
|
|
|
9
9
|
const createSuspenseInfiniteQuery = options => {
|
|
10
|
-
return createBaseQuery.createBaseQuery(options, reactQuery.useInfiniteQuery, utils.suspenseOptions);
|
|
10
|
+
return reactQuery.useSuspenseInfiniteQuery ? createBaseQuery.createBaseQuery(options, reactQuery.useSuspenseInfiniteQuery) : createBaseQuery.createBaseQuery(options, reactQuery.useInfiniteQuery, utils.suspenseOptions);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
exports.createSuspenseInfiniteQuery = createSuspenseInfiniteQuery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseInfiniteQuery.js","sources":["../../src/createSuspenseInfiniteQuery.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"createSuspenseInfiniteQuery.js","sources":["../../src/createSuspenseInfiniteQuery.ts"],"sourcesContent":["import {\n useInfiniteQuery,\n useSuspenseInfiniteQuery,\n} from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return useSuspenseInfiniteQuery\n ? createBaseQuery(options, useSuspenseInfiniteQuery)\n : createBaseQuery(options, useInfiniteQuery, suspenseOptions)\n}\n"],"names":["createSuspenseInfiniteQuery","options","useSuspenseInfiniteQuery","createBaseQuery","useInfiniteQuery","suspenseOptions"],"mappings":";;;;;;;;AAaaA,MAAAA,2BAA2B,GAMtCC,OANyC,IAY8B;AACvE,EAAA,OAAOC,mCAAwB,GAC3BC,+BAAe,CAACF,OAAD,EAAUC,mCAAV,CADY,GAE3BC,+BAAe,CAACF,OAAD,EAAUG,2BAAV,EAA4BC,qBAA5B,CAFnB,CAAA;AAGD;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useInfiniteQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useSuspenseInfiniteQuery, useInfiniteQuery } from '@tanstack/react-query';
|
|
2
2
|
import { createBaseQuery } from './createBaseQuery.mjs';
|
|
3
3
|
import { suspenseOptions } from './utils.mjs';
|
|
4
4
|
|
|
5
5
|
const createSuspenseInfiniteQuery = options => {
|
|
6
|
-
return createBaseQuery(options, useInfiniteQuery, suspenseOptions);
|
|
6
|
+
return useSuspenseInfiniteQuery ? createBaseQuery(options, useSuspenseInfiniteQuery) : createBaseQuery(options, useInfiniteQuery, suspenseOptions);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export { createSuspenseInfiniteQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseInfiniteQuery.mjs","sources":["../../src/createSuspenseInfiniteQuery.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"createSuspenseInfiniteQuery.mjs","sources":["../../src/createSuspenseInfiniteQuery.ts"],"sourcesContent":["import {\n useInfiniteQuery,\n useSuspenseInfiniteQuery,\n} from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return useSuspenseInfiniteQuery\n ? createBaseQuery(options, useSuspenseInfiniteQuery)\n : createBaseQuery(options, useInfiniteQuery, suspenseOptions)\n}\n"],"names":["createSuspenseInfiniteQuery","options","useSuspenseInfiniteQuery","createBaseQuery","useInfiniteQuery","suspenseOptions"],"mappings":";;;;AAaaA,MAAAA,2BAA2B,GAMtCC,OANyC,IAY8B;AACvE,EAAA,OAAOC,wBAAwB,GAC3BC,eAAe,CAACF,OAAD,EAAUC,wBAAV,CADY,GAE3BC,eAAe,CAACF,OAAD,EAAUG,gBAAV,EAA4BC,eAA5B,CAFnB,CAAA;AAGD;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useSuspenseQuery, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { createBaseQuery } from './createBaseQuery.esm.js';
|
|
3
3
|
import { suspenseOptions } from './utils.esm.js';
|
|
4
4
|
|
|
5
5
|
const createSuspenseQuery = options => {
|
|
6
|
-
return createBaseQuery(options, useQuery, suspenseOptions);
|
|
6
|
+
return useSuspenseQuery ? createBaseQuery(options, useSuspenseQuery) : createBaseQuery(options, useQuery, suspenseOptions);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export { createSuspenseQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseQuery.esm.js","sources":["../../src/createSuspenseQuery.ts"],"sourcesContent":["import { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, useQuery, suspenseOptions)\n}\n"],"names":["createSuspenseQuery","options","createBaseQuery","useQuery","suspenseOptions"],"mappings":";;;;AAUaA,MAAAA,mBAAmB,GAK9BC,OALiC,IAMkB;AACnD,EAAA,OAAOC,eAAe,
|
|
1
|
+
{"version":3,"file":"createSuspenseQuery.esm.js","sources":["../../src/createSuspenseQuery.ts"],"sourcesContent":["import { useQuery, useSuspenseQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return useSuspenseQuery\n ? createBaseQuery(options, useSuspenseQuery)\n : createBaseQuery(options, useQuery, suspenseOptions)\n}\n"],"names":["createSuspenseQuery","options","useSuspenseQuery","createBaseQuery","useQuery","suspenseOptions"],"mappings":";;;;AAUaA,MAAAA,mBAAmB,GAK9BC,OALiC,IAMkB;AACnD,EAAA,OAAOC,gBAAgB,GACnBC,eAAe,CAACF,OAAD,EAAUC,gBAAV,CADI,GAEnBC,eAAe,CAACF,OAAD,EAAUG,QAAV,EAAoBC,eAApB,CAFnB,CAAA;AAGD;;;;"}
|
|
@@ -7,7 +7,7 @@ var createBaseQuery = require('./createBaseQuery.js');
|
|
|
7
7
|
var utils = require('./utils.js');
|
|
8
8
|
|
|
9
9
|
const createSuspenseQuery = options => {
|
|
10
|
-
return createBaseQuery.createBaseQuery(options, reactQuery.useQuery, utils.suspenseOptions);
|
|
10
|
+
return reactQuery.useSuspenseQuery ? createBaseQuery.createBaseQuery(options, reactQuery.useSuspenseQuery) : createBaseQuery.createBaseQuery(options, reactQuery.useQuery, utils.suspenseOptions);
|
|
11
11
|
};
|
|
12
12
|
|
|
13
13
|
exports.createSuspenseQuery = createSuspenseQuery;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseQuery.js","sources":["../../src/createSuspenseQuery.ts"],"sourcesContent":["import { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, useQuery, suspenseOptions)\n}\n"],"names":["createSuspenseQuery","options","createBaseQuery","useQuery","suspenseOptions"],"mappings":";;;;;;;;AAUaA,MAAAA,mBAAmB,GAK9BC,OALiC,IAMkB;AACnD,EAAA,OAAOC,+BAAe,
|
|
1
|
+
{"version":3,"file":"createSuspenseQuery.js","sources":["../../src/createSuspenseQuery.ts"],"sourcesContent":["import { useQuery, useSuspenseQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return useSuspenseQuery\n ? createBaseQuery(options, useSuspenseQuery)\n : createBaseQuery(options, useQuery, suspenseOptions)\n}\n"],"names":["createSuspenseQuery","options","useSuspenseQuery","createBaseQuery","useQuery","suspenseOptions"],"mappings":";;;;;;;;AAUaA,MAAAA,mBAAmB,GAK9BC,OALiC,IAMkB;AACnD,EAAA,OAAOC,2BAAgB,GACnBC,+BAAe,CAACF,OAAD,EAAUC,2BAAV,CADI,GAEnBC,+BAAe,CAACF,OAAD,EAAUG,mBAAV,EAAoBC,qBAApB,CAFnB,CAAA;AAGD;;;;"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useQuery } from '@tanstack/react-query';
|
|
1
|
+
import { useSuspenseQuery, useQuery } from '@tanstack/react-query';
|
|
2
2
|
import { createBaseQuery } from './createBaseQuery.mjs';
|
|
3
3
|
import { suspenseOptions } from './utils.mjs';
|
|
4
4
|
|
|
5
5
|
const createSuspenseQuery = options => {
|
|
6
|
-
return createBaseQuery(options, useQuery, suspenseOptions);
|
|
6
|
+
return useSuspenseQuery ? createBaseQuery(options, useSuspenseQuery) : createBaseQuery(options, useQuery, suspenseOptions);
|
|
7
7
|
};
|
|
8
8
|
|
|
9
9
|
export { createSuspenseQuery };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSuspenseQuery.mjs","sources":["../../src/createSuspenseQuery.ts"],"sourcesContent":["import { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, useQuery, suspenseOptions)\n}\n"],"names":["createSuspenseQuery","options","createBaseQuery","useQuery","suspenseOptions"],"mappings":";;;;AAUaA,MAAAA,mBAAmB,GAK9BC,OALiC,IAMkB;AACnD,EAAA,OAAOC,eAAe,
|
|
1
|
+
{"version":3,"file":"createSuspenseQuery.mjs","sources":["../../src/createSuspenseQuery.ts"],"sourcesContent":["import { useQuery, useSuspenseQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return useSuspenseQuery\n ? createBaseQuery(options, useSuspenseQuery)\n : createBaseQuery(options, useQuery, suspenseOptions)\n}\n"],"names":["createSuspenseQuery","options","useSuspenseQuery","createBaseQuery","useQuery","suspenseOptions"],"mappings":";;;;AAUaA,MAAAA,mBAAmB,GAK9BC,OALiC,IAMkB;AACnD,EAAA,OAAOC,gBAAgB,GACnBC,eAAe,CAACF,OAAD,EAAUC,gBAAV,CADI,GAEnBC,eAAe,CAACF,OAAD,EAAUG,QAAV,EAAoBC,eAApB,CAFnB,CAAA;AAGD;;;;"}
|
package/build/lib/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { DefaultError, DefinedUseInfiniteQueryResult, DefinedUseQueryResult, GetNextPageParamFunction, GetPreviousPageParamFunction, InfiniteData, InfiniteQueryObserverSuccessResult, MutationFunction, MutationKey, QueryClient, QueryFunction, QueryKey, QueryKeyHashFunction, QueryObserverSuccessResult, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
1
|
+
import type { DataTag, DefaultError, DefinedUseInfiniteQueryResult, DefinedUseQueryResult, GetNextPageParamFunction, GetPreviousPageParamFunction, InfiniteData, InfiniteQueryObserverSuccessResult, MutationFunction, MutationKey, QueryClient, QueryFunction, QueryKey, QueryKeyHashFunction, QueryObserverSuccessResult, UseInfiniteQueryOptions, UseInfiniteQueryResult, UseMutationOptions, UseMutationResult, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
|
|
2
2
|
type CompatibleWithV4<V5, V4> = InfiniteData<unknown> extends UseInfiniteQueryResult<InfiniteData<unknown>>['data'] ? V5 : V4;
|
|
3
3
|
type CompatibleQueryFunction<T = unknown, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown> = CompatibleWithV4<QueryFunction<T, TQueryKey, TPageParam>, QueryFunction<T, TQueryKey>>;
|
|
4
4
|
type CompatibleInfiniteQueryPageParamsOptions<TQueryFnData = unknown, TPageParam = unknown> = CompatibleWithV4<{
|
|
@@ -9,17 +9,20 @@ type CompatibleInfiniteQueryPageParamsOptions<TQueryFnData = unknown, TPageParam
|
|
|
9
9
|
getPreviousPageParam?: GetPreviousPageParamFunction<TQueryFnData>;
|
|
10
10
|
getNextPageParam: GetNextPageParamFunction<TQueryFnData>;
|
|
11
11
|
}>;
|
|
12
|
-
type CompatibleUseInfiniteQueryOptions<TFnData, TVariables, TData, TError, TPageParam> = CompatibleWithV4<UseInfiniteQueryOptions<TFnData, TError, TData, TFnData, inferQueryKey<TVariables>, TPageParam>, UseInfiniteQueryOptions<TFnData, TError, TData, TFnData, inferQueryKey<TVariables>>>;
|
|
12
|
+
type CompatibleUseInfiniteQueryOptions<TFnData, TVariables, TData, TError, TPageParam> = CompatibleWithV4<UseInfiniteQueryOptions<TFnData, TError, TData, TFnData, inferQueryKey<TFnData, TVariables, TPageParam>, TPageParam>, UseInfiniteQueryOptions<TFnData, TError, TData, TFnData, inferQueryKey<TFnData, TVariables, TPageParam>>>;
|
|
13
13
|
type CompatibleInfiniteData<TFnData, TPageParam> = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, InfiniteData<TFnData>>;
|
|
14
14
|
type NonUndefinedGuard<T> = T extends undefined ? never : T;
|
|
15
15
|
type WithRequired<T, K extends keyof T> = T & {
|
|
16
16
|
[_ in K]: {};
|
|
17
17
|
};
|
|
18
18
|
export type CompatibleError = CompatibleWithV4<DefaultError, Error>;
|
|
19
|
-
|
|
19
|
+
type GetQueryKey<TVariables> = TVariables extends void ? [string] : [string, TVariables];
|
|
20
|
+
export type inferQueryKey<TFnData, TVariables, TPageParam = never> = CompatibleWithV4<DataTag<GetQueryKey<TVariables>, [
|
|
21
|
+
TPageParam
|
|
22
|
+
] extends [never] ? TFnData : CompatibleInfiniteData<TFnData, TPageParam>>, GetQueryKey<TVariables>>;
|
|
20
23
|
export type AdditionalQueryOptions<TFnData, TVariables, TPageParam = never> = {
|
|
21
24
|
primaryKey: string;
|
|
22
|
-
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TVariables>, TPageParam>;
|
|
25
|
+
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TFnData, TVariables, TPageParam>, TPageParam>;
|
|
23
26
|
variables?: TVariables;
|
|
24
27
|
};
|
|
25
28
|
type inferMiddlewareHook<T extends (...args: any) => any> = (options: inferCreateOptions<T>, queryClient?: CompatibleWithV4<QueryClient, void>) => ReturnType<T>;
|
|
@@ -27,48 +30,54 @@ export type Middleware<T extends (...args: any) => any = QueryHook<any, any, any
|
|
|
27
30
|
type DeepPartial<T> = T extends object ? {
|
|
28
31
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
29
32
|
} : T;
|
|
30
|
-
export type ExposeMethods<TFnData, TVariables, TPageParam = never> = {
|
|
33
|
+
export type ExposeMethods<TFnData, TVariables, TError, TPageParam = never> = {
|
|
31
34
|
getPrimaryKey: () => string;
|
|
32
|
-
getKey: <V extends DeepPartial<TVariables> | void = void>(variables?: V) => inferQueryKey<V>;
|
|
33
|
-
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TVariables>, TPageParam>;
|
|
34
|
-
queryKeyHashFn: QueryKeyHashFunction<inferQueryKey<TVariables>>;
|
|
35
|
+
getKey: <V extends DeepPartial<TVariables> | void = void>(variables?: V) => inferQueryKey<TFnData, V, TPageParam>;
|
|
36
|
+
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TFnData, TVariables, TPageParam>, TPageParam>;
|
|
37
|
+
queryKeyHashFn: QueryKeyHashFunction<inferQueryKey<TFnData, TVariables, TPageParam>>;
|
|
35
38
|
getFetchOptions: (variables: TVariables extends void ? TVariables | void : TVariables) => [TPageParam] extends [never] ? {
|
|
36
|
-
queryKey: inferQueryKey<TVariables>;
|
|
37
|
-
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TVariables>, TPageParam>;
|
|
38
|
-
queryKeyHashFn?: QueryKeyHashFunction<inferQueryKey<TVariables>>;
|
|
39
|
+
queryKey: inferQueryKey<TFnData, TVariables, TPageParam>;
|
|
40
|
+
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TFnData, TVariables, TPageParam>, TPageParam>;
|
|
41
|
+
queryKeyHashFn?: QueryKeyHashFunction<inferQueryKey<TFnData, TVariables, TPageParam>>;
|
|
39
42
|
} : {
|
|
40
|
-
queryKey: inferQueryKey<TVariables>;
|
|
41
|
-
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TVariables>, TPageParam>;
|
|
42
|
-
queryKeyHashFn?: QueryKeyHashFunction<inferQueryKey<TVariables>>;
|
|
43
|
+
queryKey: inferQueryKey<TFnData, TVariables, TPageParam>;
|
|
44
|
+
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TFnData, TVariables, TPageParam>, TPageParam>;
|
|
45
|
+
queryKeyHashFn?: QueryKeyHashFunction<inferQueryKey<TFnData, TVariables, TPageParam>>;
|
|
43
46
|
} & CompatibleInfiniteQueryPageParamsOptions<TFnData, TPageParam>;
|
|
44
|
-
getOptions:
|
|
47
|
+
getOptions: (variables: TVariables extends void ? TVariables | void : TVariables) => [TPageParam] extends [never] ? CompatibleWithV4<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables, [
|
|
48
|
+
TPageParam
|
|
49
|
+
] extends [never] ? TFnData : CompatibleInfiniteData<TFnData, TPageParam>>>, {
|
|
50
|
+
queryKey: inferQueryKey<TFnData, TVariables, TPageParam>;
|
|
51
|
+
queryFn: CompatibleQueryFunction<TFnData, inferQueryKey<TFnData, TVariables, TPageParam>, TPageParam>;
|
|
52
|
+
queryKeyHashFn?: QueryKeyHashFunction<inferQueryKey<TFnData, TVariables, TPageParam>>;
|
|
53
|
+
}> : CompatibleUseInfiniteQueryOptions<TFnData, TVariables, TFnData, TError, TPageParam>;
|
|
45
54
|
};
|
|
46
|
-
export interface CreateQueryOptions<TFnData = unknown, TVariables = void, TError = CompatibleError> extends Omit<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'select'>, AdditionalQueryOptions<TFnData, TVariables> {
|
|
55
|
+
export interface CreateQueryOptions<TFnData = unknown, TVariables = void, TError = CompatibleError> extends Omit<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TFnData, TVariables>>, 'queryKey' | 'queryFn' | 'select'>, AdditionalQueryOptions<TFnData, TVariables> {
|
|
47
56
|
use?: Middleware<QueryHook<TFnData, TVariables, TError>>[];
|
|
48
57
|
variables?: TVariables;
|
|
49
58
|
}
|
|
50
|
-
export interface QueryHookOptions<TFnData, TError, TData, TVariables> extends Omit<UseQueryOptions<TFnData, TError, TData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'queryKeyHashFn'> {
|
|
59
|
+
export interface QueryHookOptions<TFnData, TError, TData, TVariables> extends Omit<UseQueryOptions<TFnData, TError, TData, inferQueryKey<TFnData, TVariables>>, 'queryKey' | 'queryFn' | 'queryKeyHashFn'> {
|
|
51
60
|
use?: Middleware<QueryHook<TFnData, TVariables, TError>>[];
|
|
52
61
|
variables?: TVariables;
|
|
53
62
|
}
|
|
54
|
-
export
|
|
63
|
+
export interface DefinedQueryHookOptions<TFnData, TError, TData, TVariables> extends Omit<QueryHookOptions<TFnData, TError, TData, TVariables>, 'initialData'> {
|
|
55
64
|
initialData: NonUndefinedGuard<TFnData> | (() => NonUndefinedGuard<TFnData>);
|
|
56
|
-
}
|
|
65
|
+
}
|
|
57
66
|
export type QueryHookResult<TData, TError> = UseQueryResult<TData, TError>;
|
|
58
67
|
export type DefinedQueryHookResult<TData, TError> = DefinedUseQueryResult<TData, TError>;
|
|
59
|
-
export interface QueryHook<TFnData = unknown, TVariables = any, TError = CompatibleError> extends ExposeMethods<TFnData, TVariables> {
|
|
68
|
+
export interface QueryHook<TFnData = unknown, TVariables = any, TError = CompatibleError> extends ExposeMethods<TFnData, TVariables, TError> {
|
|
60
69
|
<TData = TFnData>(options: DefinedQueryHookOptions<TFnData, TError, TData, TVariables>, queryClient?: CompatibleWithV4<QueryClient, void>): DefinedQueryHookResult<TData, TError>;
|
|
61
70
|
<TData = TFnData>(options?: QueryHookOptions<TFnData, TError, TData, TVariables>, queryClient?: CompatibleWithV4<QueryClient, void>): QueryHookResult<TData, TError>;
|
|
62
71
|
}
|
|
63
|
-
export interface CreateSuspenseQueryOptions<TFnData = unknown, TVariables = void, TError = CompatibleError> extends Omit<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'enabled' | 'select' | 'suspense' | 'throwOnError' | 'placeholderData' | 'keepPreviousData' | 'useErrorBoundary'>, AdditionalQueryOptions<TFnData, TVariables> {
|
|
72
|
+
export interface CreateSuspenseQueryOptions<TFnData = unknown, TVariables = void, TError = CompatibleError> extends Omit<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TFnData, TVariables>>, 'queryKey' | 'queryFn' | 'enabled' | 'select' | 'suspense' | 'throwOnError' | 'placeholderData' | 'keepPreviousData' | 'useErrorBoundary'>, AdditionalQueryOptions<TFnData, TVariables> {
|
|
64
73
|
use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[];
|
|
65
74
|
}
|
|
66
|
-
export interface SuspenseQueryHookOptions<TFnData, TError, TData, TVariables> extends Omit<UseQueryOptions<TFnData, TError, TData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'queryKeyHashFn' | 'enabled' | 'suspense' | 'throwOnError' | 'placeholderData' | 'keepPreviousData' | 'useErrorBoundary'> {
|
|
75
|
+
export interface SuspenseQueryHookOptions<TFnData, TError, TData, TVariables> extends Omit<UseQueryOptions<TFnData, TError, TData, inferQueryKey<TFnData, TVariables>>, 'queryKey' | 'queryFn' | 'queryKeyHashFn' | 'enabled' | 'suspense' | 'throwOnError' | 'placeholderData' | 'keepPreviousData' | 'useErrorBoundary'> {
|
|
67
76
|
use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[];
|
|
68
77
|
variables?: TVariables;
|
|
69
78
|
}
|
|
70
79
|
export type SuspenseQueryHookResult<TData, TError> = Omit<QueryObserverSuccessResult<TData, TError>, 'isPlaceholderData' | 'isPreviousData'>;
|
|
71
|
-
export interface SuspenseQueryHook<TFnData = unknown, TVariables = void, TError = CompatibleError> extends ExposeMethods<TFnData, TVariables> {
|
|
80
|
+
export interface SuspenseQueryHook<TFnData = unknown, TVariables = void, TError = CompatibleError> extends ExposeMethods<TFnData, TVariables, TError> {
|
|
72
81
|
<TData = TFnData>(options?: SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>, queryClient?: CompatibleWithV4<QueryClient, void>): SuspenseQueryHookResult<TData, TError>;
|
|
73
82
|
}
|
|
74
83
|
export interface CreateInfiniteQueryOptions<TFnData = unknown, TVariables = void, TError = CompatibleError, TPageParam = number> extends Omit<CompatibleUseInfiniteQueryOptions<TFnData, TVariables, TFnData, TError, TPageParam>, 'queryKey' | 'queryFn' | 'select'>, AdditionalQueryOptions<TFnData, TVariables, TPageParam> {
|
|
@@ -78,12 +87,12 @@ export interface InfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TP
|
|
|
78
87
|
use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[];
|
|
79
88
|
variables?: TVariables;
|
|
80
89
|
}
|
|
81
|
-
export
|
|
82
|
-
initialData: CompatibleInfiniteData<TFnData, TPageParam
|
|
83
|
-
}
|
|
90
|
+
export interface DefinedInfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam = number> extends Omit<InfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam>, 'initialData'> {
|
|
91
|
+
initialData: NonUndefinedGuard<CompatibleInfiniteData<TFnData, TPageParam>> | (() => NonUndefinedGuard<CompatibleInfiniteData<TFnData, TPageParam>>);
|
|
92
|
+
}
|
|
84
93
|
export type InfiniteQueryHookResult<TData, TError> = UseInfiniteQueryResult<TData, TError>;
|
|
85
94
|
export type DefinedInfiniteQueryHookResult<TData, TError> = CompatibleWithV4<DefinedUseInfiniteQueryResult<TData, TError>, WithRequired<UseInfiniteQueryResult<TData, TError>, 'data'>>;
|
|
86
|
-
export interface InfiniteQueryHook<TFnData = unknown, TVariables = void, TError = CompatibleError, TPageParam = number> extends ExposeMethods<TFnData, TVariables, TPageParam> {
|
|
95
|
+
export interface InfiniteQueryHook<TFnData = unknown, TVariables = void, TError = CompatibleError, TPageParam = number> extends ExposeMethods<TFnData, TVariables, TError, TPageParam> {
|
|
87
96
|
<TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(options: DefinedInfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam>, queryClient?: CompatibleWithV4<QueryClient, void>): DefinedInfiniteQueryHookResult<TData, TError>;
|
|
88
97
|
<TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(options?: InfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam>, queryClient?: CompatibleWithV4<QueryClient, void>): InfiniteQueryHookResult<TData, TError>;
|
|
89
98
|
}
|
|
@@ -95,7 +104,7 @@ export interface SuspenseInfiniteQueryHookOptions<TFnData, TError, TData, TVaria
|
|
|
95
104
|
variables?: TVariables;
|
|
96
105
|
}
|
|
97
106
|
export type SuspenseInfiniteQueryHookResult<TData, TError> = Omit<InfiniteQueryObserverSuccessResult<TData, TError>, 'isPlaceholderData' | 'isPreviousData'>;
|
|
98
|
-
export interface SuspenseInfiniteQueryHook<TFnData = unknown, TVariables = void, TError = CompatibleError, TPageParam = number> extends ExposeMethods<TFnData, TVariables, TPageParam> {
|
|
107
|
+
export interface SuspenseInfiniteQueryHook<TFnData = unknown, TVariables = void, TError = CompatibleError, TPageParam = number> extends ExposeMethods<TFnData, TVariables, TError, TPageParam> {
|
|
99
108
|
<TData = CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>>(options?: SuspenseInfiniteQueryHookOptions<TFnData, TError, TData, TVariables, TPageParam>, queryClient?: CompatibleWithV4<QueryClient, void>): SuspenseInfiniteQueryHookResult<TData, TError>;
|
|
100
109
|
}
|
|
101
110
|
export interface CreateMutationOptions<TData = unknown, TVariables = void, TError = CompatibleError, TContext = unknown> extends UseMutationOptions<TData, TError, TVariables, TContext> {
|
package/build/lib/utils.d.ts
CHANGED
|
@@ -7,7 +7,6 @@ export declare const withMiddleware: (hook: any, defaultOptions: any, type: 'que
|
|
|
7
7
|
export declare const suspenseOptions: {
|
|
8
8
|
enabled: boolean;
|
|
9
9
|
suspense: boolean;
|
|
10
|
-
throwOnError: (_error: unknown, query: Query) => boolean;
|
|
11
10
|
useErrorBoundary: (_error: unknown, query: Query) => boolean;
|
|
12
11
|
};
|
|
13
|
-
export declare const getKey: <TVariables = void>(primaryKey: string, variables?: TVariables | undefined) => inferQueryKey<TVariables>;
|
|
12
|
+
export declare const getKey: <TVariables = void>(primaryKey: string, variables?: TVariables | undefined) => inferQueryKey<unknown, TVariables>;
|
package/build/lib/utils.esm.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
1
|
+
import { useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
|
|
2
2
|
|
|
3
3
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
4
4
|
return function useMiddleware(options, queryClient) {
|
|
5
5
|
const [middleware, opts] = [useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
6
|
-
|
|
6
|
+
useSuspenseQuery ? queryClient : options).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
7
7
|
use: u2 = [],
|
|
8
8
|
...o2
|
|
9
9
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
@@ -17,16 +17,12 @@ const withMiddleware = (hook, defaultOptions, type) => {
|
|
|
17
17
|
|
|
18
18
|
return next(opts, queryClient);
|
|
19
19
|
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const defaultThrowOnError = (_error, query) => query.state.data === undefined;
|
|
20
|
+
}; // Compatible with ReactQuery v4
|
|
23
21
|
|
|
24
22
|
const suspenseOptions = {
|
|
25
23
|
enabled: true,
|
|
26
24
|
suspense: true,
|
|
27
|
-
|
|
28
|
-
// Compatible with ReactQuery v4
|
|
29
|
-
useErrorBoundary: defaultThrowOnError
|
|
25
|
+
useErrorBoundary: (_error, query) => query.state.data === undefined
|
|
30
26
|
};
|
|
31
27
|
const getKey = (primaryKey, variables) => {
|
|
32
28
|
return variables === undefined ? [primaryKey] : [primaryKey, variables];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import {\n type Query,\n type QueryClient,\n useQueryClient,\n} from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import {\n type Query,\n type QueryClient,\n useQueryClient,\n useSuspenseQuery,\n} from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n useSuspenseQuery ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\n// Compatible with ReactQuery v4\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const getKey = <TVariables = void>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return (\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n ) as inferQueryKey<unknown, TVariables>\n}\n"],"names":["withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","middleware","opts","useQueryClient","useSuspenseQuery","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","getKey","primaryKey","variables"],"mappings":";;AASO,MAAMA,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAI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EAAaC,SAAb,CAD3C,CAAA;AAGD;;;;"}
|
package/build/lib/utils.js
CHANGED
|
@@ -7,7 +7,7 @@ var reactQuery = require('@tanstack/react-query');
|
|
|
7
7
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
8
8
|
return function useMiddleware(options, queryClient) {
|
|
9
9
|
const [middleware, opts] = [reactQuery.useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
10
|
-
|
|
10
|
+
reactQuery.useSuspenseQuery ? queryClient : options).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
11
11
|
use: u2 = [],
|
|
12
12
|
...o2
|
|
13
13
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
@@ -21,16 +21,12 @@ const withMiddleware = (hook, defaultOptions, type) => {
|
|
|
21
21
|
|
|
22
22
|
return next(opts, queryClient);
|
|
23
23
|
};
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const defaultThrowOnError = (_error, query) => query.state.data === undefined;
|
|
24
|
+
}; // Compatible with ReactQuery v4
|
|
27
25
|
|
|
28
26
|
const suspenseOptions = {
|
|
29
27
|
enabled: true,
|
|
30
28
|
suspense: true,
|
|
31
|
-
|
|
32
|
-
// Compatible with ReactQuery v4
|
|
33
|
-
useErrorBoundary: defaultThrowOnError
|
|
29
|
+
useErrorBoundary: (_error, query) => query.state.data === undefined
|
|
34
30
|
};
|
|
35
31
|
const getKey = (primaryKey, variables) => {
|
|
36
32
|
return variables === undefined ? [primaryKey] : [primaryKey, variables];
|
package/build/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import {\n type Query,\n type QueryClient,\n useQueryClient,\n} from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import {\n type Query,\n type QueryClient,\n useQueryClient,\n useSuspenseQuery,\n} from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n useSuspenseQuery ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\n// Compatible with ReactQuery v4\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const getKey = <TVariables = void>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return (\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n ) as inferQueryKey<unknown, TVariables>\n}\n"],"names":["withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","middleware","opts","useQueryClient","useSuspenseQuery","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","getKey","primaryKey","variables"],"mappings":";;;;;;AASO,MAAMA,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAM,CAACC,UAAD,EAA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|
|
1
|
-
import { useQueryClient } from '@tanstack/react-query';
|
|
1
|
+
import { useQueryClient, useSuspenseQuery } from '@tanstack/react-query';
|
|
2
2
|
|
|
3
3
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
4
4
|
return function useMiddleware(options, queryClient) {
|
|
5
5
|
const [middleware, opts] = [useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
6
|
-
|
|
6
|
+
useSuspenseQuery ? queryClient : options).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
7
7
|
use: u2 = [],
|
|
8
8
|
...o2
|
|
9
9
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
@@ -17,16 +17,12 @@ const withMiddleware = (hook, defaultOptions, type) => {
|
|
|
17
17
|
|
|
18
18
|
return next(opts, queryClient);
|
|
19
19
|
};
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
const defaultThrowOnError = (_error, query) => query.state.data === undefined;
|
|
20
|
+
}; // Compatible with ReactQuery v4
|
|
23
21
|
|
|
24
22
|
const suspenseOptions = {
|
|
25
23
|
enabled: true,
|
|
26
24
|
suspense: true,
|
|
27
|
-
|
|
28
|
-
// Compatible with ReactQuery v4
|
|
29
|
-
useErrorBoundary: defaultThrowOnError
|
|
25
|
+
useErrorBoundary: (_error, query) => query.state.data === undefined
|
|
30
26
|
};
|
|
31
27
|
const getKey = (primaryKey, variables) => {
|
|
32
28
|
return variables === undefined ? [primaryKey] : [primaryKey, variables];
|
package/build/lib/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import {\n type Query,\n type QueryClient,\n useQueryClient,\n} from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import {\n type Query,\n type QueryClient,\n useQueryClient,\n useSuspenseQuery,\n} from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n useSuspenseQuery ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\n// Compatible with ReactQuery v4\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const getKey = <TVariables = void>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return (\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n ) as inferQueryKey<unknown, TVariables>\n}\n"],"names":["withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","middleware","opts","useQueryClient","useSuspenseQuery","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","getKey","primaryKey","variables"],"mappings":";;AASO,MAAMA,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;AACA,IAAA,MAAM,CAACC,UAAD,EAAaC,IAAb,CAAqB,GAAA,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
|
</script>
|
|
4015
4015
|
<script>
|
|
4016
4016
|
/*<!--*/
|
|
4017
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"zip.esm.js","children":[{"name":"src","children":[{"uid":"
|
|
4017
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"zip.esm.js","children":[{"name":"src","children":[{"uid":"3f05-1","name":"utils.ts"},{"uid":"3f05-3","name":"createBaseQuery.ts"},{"uid":"3f05-5","name":"createQuery.tsx"},{"uid":"3f05-7","name":"createSuspenseQuery.ts"},{"uid":"3f05-9","name":"createInfiniteQuery.ts"},{"uid":"3f05-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"3f05-13","name":"createMutation.ts"},{"uid":"3f05-15","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"3f05-1":{"renderedLength":863,"gzipLength":435,"brotliLength":0,"mainUid":"3f05-0"},"3f05-3":{"renderedLength":1047,"gzipLength":368,"brotliLength":0,"mainUid":"3f05-2"},"3f05-5":{"renderedLength":80,"gzipLength":79,"brotliLength":0,"mainUid":"3f05-4"},"3f05-7":{"renderedLength":169,"gzipLength":106,"brotliLength":0,"mainUid":"3f05-6"},"3f05-9":{"renderedLength":96,"gzipLength":89,"brotliLength":0,"mainUid":"3f05-8"},"3f05-11":{"renderedLength":201,"gzipLength":116,"brotliLength":0,"mainUid":"3f05-10"},"3f05-13":{"renderedLength":240,"gzipLength":163,"brotliLength":0,"mainUid":"3f05-12"},"3f05-15":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"3f05-14"}},"nodeMetas":{"3f05-0":{"id":"/src/utils.ts","moduleParts":{"zip.esm.js":"3f05-1"},"imported":[{"uid":"3f05-17"}],"importedBy":[{"uid":"3f05-14"},{"uid":"3f05-6"},{"uid":"3f05-10"},{"uid":"3f05-12"},{"uid":"3f05-2"}]},"3f05-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"zip.esm.js":"3f05-3"},"imported":[{"uid":"3f05-0"}],"importedBy":[{"uid":"3f05-4"},{"uid":"3f05-6"},{"uid":"3f05-8"},{"uid":"3f05-10"}]},"3f05-4":{"id":"/src/createQuery.tsx","moduleParts":{"zip.esm.js":"3f05-5"},"imported":[{"uid":"3f05-17"},{"uid":"3f05-2"}],"importedBy":[{"uid":"3f05-14"}]},"3f05-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"zip.esm.js":"3f05-7"},"imported":[{"uid":"3f05-17"},{"uid":"3f05-2"},{"uid":"3f05-0"}],"importedBy":[{"uid":"3f05-14"}]},"3f05-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"zip.esm.js":"3f05-9"},"imported":[{"uid":"3f05-17"},{"uid":"3f05-2"}],"importedBy":[{"uid":"3f05-14"}]},"3f05-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"zip.esm.js":"3f05-11"},"imported":[{"uid":"3f05-17"},{"uid":"3f05-2"},{"uid":"3f05-0"}],"importedBy":[{"uid":"3f05-14"}]},"3f05-12":{"id":"/src/createMutation.ts","moduleParts":{"zip.esm.js":"3f05-13"},"imported":[{"uid":"3f05-17"},{"uid":"3f05-0"}],"importedBy":[{"uid":"3f05-14"}]},"3f05-14":{"id":"/src/index.ts","moduleParts":{"zip.esm.js":"3f05-15"},"imported":[{"uid":"3f05-4"},{"uid":"3f05-6"},{"uid":"3f05-8"},{"uid":"3f05-10"},{"uid":"3f05-12"},{"uid":"3f05-16"},{"uid":"3f05-0"}],"importedBy":[],"isEntry":true},"3f05-16":{"id":"/src/types.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"3f05-14"}]},"3f05-17":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"3f05-4"},{"uid":"3f05-6"},{"uid":"3f05-8"},{"uid":"3f05-10"},{"uid":"3f05-12"},{"uid":"3f05-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
4018
4018
|
|
|
4019
4019
|
const run = () => {
|
|
4020
4020
|
const width = window.innerWidth;
|