react-query-kit 1.4.4 → 1.4.6
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 +83 -13
- package/build/lib/createBaseQuery.d.ts +7 -1
- package/build/lib/createBaseQuery.esm.js +18 -28
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +18 -28
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +18 -28
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/lib/createImmutableQuery.d.ts +13 -0
- package/build/lib/createImmutableQuery.esm.js +19 -0
- package/build/lib/createImmutableQuery.esm.js.map +1 -0
- package/build/lib/createImmutableQuery.js +23 -0
- package/build/lib/createImmutableQuery.js.map +1 -0
- package/build/lib/createImmutableQuery.mjs +19 -0
- package/build/lib/createImmutableQuery.mjs.map +1 -0
- package/build/lib/createInfiniteQuery.d.ts +5 -6
- package/build/lib/createInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createInfiniteQuery.js.map +1 -1
- package/build/lib/createInfiniteQuery.mjs.map +1 -1
- package/build/lib/createMutation.d.ts +1 -2
- package/build/lib/createMutation.esm.js.map +1 -1
- package/build/lib/createMutation.js.map +1 -1
- package/build/lib/createMutation.mjs.map +1 -1
- package/build/lib/createQuery.d.ts +2 -3
- package/build/lib/createQuery.esm.js.map +1 -1
- package/build/lib/createQuery.js.map +1 -1
- package/build/lib/createQuery.mjs.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.d.ts +13 -0
- package/build/lib/createSuspenseInfiniteQuery.esm.js +16 -0
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -0
- package/build/lib/createSuspenseInfiniteQuery.js +20 -0
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -0
- package/build/lib/createSuspenseInfiniteQuery.mjs +16 -0
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -0
- package/build/lib/createSuspenseQuery.d.ts +13 -0
- package/build/lib/createSuspenseQuery.esm.js +16 -0
- package/build/lib/createSuspenseQuery.esm.js.map +1 -0
- package/build/lib/createSuspenseQuery.js +20 -0
- package/build/lib/createSuspenseQuery.js.map +1 -0
- package/build/lib/createSuspenseQuery.mjs +16 -0
- package/build/lib/createSuspenseQuery.mjs.map +1 -0
- package/build/lib/index.d.ts +5 -2
- package/build/lib/index.esm.js +4 -1
- package/build/lib/index.esm.js.map +1 -1
- package/build/lib/index.js +8 -2
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +4 -1
- package/build/lib/index.mjs.map +1 -1
- package/build/lib/types.d.ts +58 -26
- package/build/stats-html.html +1 -1
- package/build/stats.json +158 -69
- package/build/umd/index.development.js +61 -35
- 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/package.json +8 -4
- package/src/createBaseQuery.ts +19 -30
- package/src/createImmutableQuery.tsx +82 -0
- package/src/createInfiniteQuery.ts +11 -7
- package/src/createMutation.ts +1 -1
- package/src/createQuery.tsx +3 -3
- package/src/createSuspenseInfiniteQuery.ts +113 -0
- package/src/createSuspenseQuery.ts +64 -0
- package/src/index.ts +15 -1
- package/src/types.ts +315 -48
- package/build/lib/utils.d.ts +0 -1
- package/build/lib/utils.esm.js +0 -6
- package/build/lib/utils.esm.js.map +0 -1
- package/build/lib/utils.js +0 -10
- package/build/lib/utils.js.map +0 -1
- package/build/lib/utils.mjs +0 -6
- package/build/lib/utils.mjs.map +0 -1
- package/src/utils.ts +0 -3
package/README.md
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
<p align="center">
|
|
7
7
|
<a href="https://github.com/liaoliao666/react-query-kit/actions/workflows/tests.yml"><img src="https://github.com/liaoliao666/react-query-kit/actions/workflows/tests.yml/badge.svg?branch=main" alt="Latest build" target="\_parent"></a>
|
|
8
8
|
<a href="https://www.npmjs.com/package/react-query-kit"><img src="https://badgen.net/npm/v/react-query-kit" alt="Latest published version" target="\_parent"></a>
|
|
9
|
-
<a href="https://
|
|
10
|
-
<a href="https://bundlephobia.com/package/react-query-kit@latest"><img src="https://badgen.net/bundlephobia/dependency-count/react-query-kit" alt="Dependency count 0" target="\_parent"></a>
|
|
9
|
+
<a href="https://unpkg.com/browse/react-query-kit@latest/build/umd/index.production.js" rel="nofollow"><img src="https://img.badgesize.io/https:/unpkg.com/react-query-kit@latest/build/umd/index.production.js?label=gzip%20size&compression=gzip" alt="gzip size"></a>
|
|
11
10
|
<a href="https://github.com/liaoliao666/react-query-kit"><img src="https://badgen.net/npm/types/react-query-kit" alt="Types included" target="\_parent"></a>
|
|
12
11
|
<a href="https://www.npmjs.com/package/react-query-kit"><img src="https://badgen.net/npm/license/react-query-kit" alt="License" target="\_parent"></a>
|
|
13
12
|
<a href="https://www.npmjs.com/package/react-query-kit"><img src="https://badgen.net/npm/dt/react-query-kit" alt="Number of downloads" target="\_parent"></a>
|
|
@@ -25,6 +24,8 @@
|
|
|
25
24
|
- Make `queryClient`'s operations clearly associated with custom ReactQuery hooks
|
|
26
25
|
- Set defaultOptions for custom ReactQuery hooks easier and clearer
|
|
27
26
|
|
|
27
|
+

|
|
28
|
+
|
|
28
29
|
English | [简体中文](./README-zh_CN.md)
|
|
29
30
|
|
|
30
31
|
## Table of Contents
|
|
@@ -35,11 +36,15 @@ English | [简体中文](./README-zh_CN.md)
|
|
|
35
36
|
- [Installation](#installation)
|
|
36
37
|
- [Examples](#examples)
|
|
37
38
|
- Usage
|
|
38
|
-
- [createQuery](#
|
|
39
|
-
- [createInfiniteQuery](#
|
|
40
|
-
- [createMutation](#
|
|
41
|
-
- [
|
|
42
|
-
- [
|
|
39
|
+
- [createQuery](#createquery)
|
|
40
|
+
- [createInfiniteQuery](#createinfinitequery)
|
|
41
|
+
- [createMutation](#createmutation)
|
|
42
|
+
- [createImmutableQuery](#createimmutablequery)
|
|
43
|
+
- [createSuspenseQuery](#createsuspensequery)
|
|
44
|
+
- [createSuspenseInfiniteQuery](#createsuspenseinfinitequery)
|
|
45
|
+
- [createMutation](#createmutation)
|
|
46
|
+
- [Type inference](#type-inference)
|
|
47
|
+
- [Caution](#caution)
|
|
43
48
|
- [Issues](#issues)
|
|
44
49
|
- [🐛 Bugs](#-bugs)
|
|
45
50
|
- [💡 Feature Requests](#-feature-requests)
|
|
@@ -118,7 +123,7 @@ export async function getStaticProps() {
|
|
|
118
123
|
const queryClient = new QueryClient()
|
|
119
124
|
|
|
120
125
|
await queryClient.prefetchQuery({
|
|
121
|
-
queryKey: usePost.getKey(variables),
|
|
126
|
+
queryKey: usePost.getKey(variables),
|
|
122
127
|
queryFn: usePost.queryFn
|
|
123
128
|
})
|
|
124
129
|
|
|
@@ -131,7 +136,7 @@ export async function getStaticProps() {
|
|
|
131
136
|
|
|
132
137
|
// usage outside of react component
|
|
133
138
|
const data = await queryClient.fetchQuery({
|
|
134
|
-
queryKey: usePost.getKey(variables),
|
|
139
|
+
queryKey: usePost.getKey(variables),
|
|
135
140
|
queryFn: usePost.queryFn
|
|
136
141
|
})
|
|
137
142
|
|
|
@@ -171,8 +176,10 @@ Expose Methods
|
|
|
171
176
|
|
|
172
177
|
Returns
|
|
173
178
|
|
|
174
|
-
- `queryKey:
|
|
179
|
+
- `queryKey: [primaryKey, TVariables]`
|
|
175
180
|
- The query key of this custom query.
|
|
181
|
+
- `variables: TVariables`
|
|
182
|
+
- The variables of this custom query.
|
|
176
183
|
- `setData: (updater: Updater<TData>, options?: SetDataOptions) => TData | undefined`
|
|
177
184
|
- it's args similar with `queryClient.setQueryData` but without `queryKey`
|
|
178
185
|
|
|
@@ -195,7 +202,7 @@ const useProjects = createInfiniteQuery<Response, Variables, Error>({
|
|
|
195
202
|
).then(res => res.json())
|
|
196
203
|
},
|
|
197
204
|
getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
|
|
198
|
-
defaultPageParam: 1
|
|
205
|
+
defaultPageParam: 1,
|
|
199
206
|
})
|
|
200
207
|
|
|
201
208
|
const variables = { active: true }
|
|
@@ -254,7 +261,6 @@ const data = await queryClient.fetchInfiniteQuery({
|
|
|
254
261
|
queryFn: useProjects.queryFn,
|
|
255
262
|
})
|
|
256
263
|
|
|
257
|
-
|
|
258
264
|
// usage outside of react component
|
|
259
265
|
const data = await queryClient.fetchInfiniteQuery({
|
|
260
266
|
queryKey: useProjects.getKey(variables),
|
|
@@ -286,11 +292,75 @@ Expose Methods
|
|
|
286
292
|
|
|
287
293
|
Returns
|
|
288
294
|
|
|
289
|
-
- `queryKey:
|
|
295
|
+
- `queryKey: [primaryKey, TVariables]`
|
|
290
296
|
- The query key of this custom query.
|
|
297
|
+
- `variables: TVariables`
|
|
298
|
+
- The variables of this custom query.
|
|
291
299
|
- `setData: (updater: Updater<InfiniteData<TFnData>>, options?: SetDataOptions) => TData | undefined`
|
|
292
300
|
- it's args similar with `queryClient.setQueryData` but without `queryKey`
|
|
293
301
|
|
|
302
|
+
## createImmutableQuery
|
|
303
|
+
|
|
304
|
+
If the resource is immutable, no matter how many times we request it again, it will never change. In this case, we can disable all automatic re-requests for it.
|
|
305
|
+
ReactQueryKit provides a helper function `createImmutableQuery` to mark a resource as immutable.
|
|
306
|
+
|
|
307
|
+
```ts
|
|
308
|
+
import { createImmutableQuery } from 'react-query-kit'
|
|
309
|
+
|
|
310
|
+
createImmutableQuery({
|
|
311
|
+
...options,
|
|
312
|
+
})
|
|
313
|
+
|
|
314
|
+
// equals to
|
|
315
|
+
createQuery({
|
|
316
|
+
...options,
|
|
317
|
+
refetchInterval: false,
|
|
318
|
+
refetchOnMount: false,
|
|
319
|
+
refetchOnReconnect: false,
|
|
320
|
+
refetchOnWindowFocus: false,
|
|
321
|
+
staleTime: Infinity,
|
|
322
|
+
gcTime: Infinity,
|
|
323
|
+
})
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
## createSuspenseQuery
|
|
327
|
+
|
|
328
|
+
This has the same effect as setting the `suspense` option to `true` in the query config, but it works better in TypeScript, because `data` is guaranteed to be defined (as errors and loading states are handled by Suspense- and ErrorBoundaries).
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
import { createSuspenseQuery } from 'react-query-kit'
|
|
332
|
+
|
|
333
|
+
createSuspenseQuery({
|
|
334
|
+
...options,
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
// equals to
|
|
338
|
+
createQuery({
|
|
339
|
+
...options,
|
|
340
|
+
enabled: true,
|
|
341
|
+
suspense: true,
|
|
342
|
+
throwOnError: true,
|
|
343
|
+
})
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
## createSuspenseInfiniteQuery
|
|
347
|
+
|
|
348
|
+
```ts
|
|
349
|
+
import { createSuspenseInfiniteQuery } from 'react-query-kit'
|
|
350
|
+
|
|
351
|
+
createSuspenseInfiniteQuery({
|
|
352
|
+
...options,
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
// equals to
|
|
356
|
+
createInfiniteQuery({
|
|
357
|
+
...options,
|
|
358
|
+
enabled: true,
|
|
359
|
+
suspense: true,
|
|
360
|
+
throwOnError: true,
|
|
361
|
+
})
|
|
362
|
+
```
|
|
363
|
+
|
|
294
364
|
## createMutation
|
|
295
365
|
|
|
296
366
|
### Usage
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type { UseBaseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { AdditionalQueryHookOptions } from './types';
|
|
3
|
+
declare type QueryBaseHookOptions = Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'> & AdditionalQueryHookOptions<any, any> & {
|
|
4
|
+
context?: any;
|
|
5
|
+
};
|
|
6
|
+
export declare function createBaseQuery(initialOptions: any, useRQHook: (options: any, queryClient?: any) => any, queryClient?: any, overrideOptions?: QueryBaseHookOptions): any;
|
|
7
|
+
export {};
|
|
@@ -1,53 +1,43 @@
|
|
|
1
1
|
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { isUndefined } from './utils.esm.js';
|
|
3
2
|
|
|
4
|
-
function createBaseQuery(
|
|
3
|
+
function createBaseQuery(initialOptions, useRQHook, queryClient, overrideOptions) {
|
|
5
4
|
const {
|
|
6
5
|
primaryKey,
|
|
7
6
|
queryFn,
|
|
8
7
|
queryKeyHashFn,
|
|
9
8
|
useDefaultOptions,
|
|
10
9
|
...defaultOptions
|
|
11
|
-
} =
|
|
10
|
+
} = initialOptions;
|
|
12
11
|
|
|
13
12
|
const getPrimaryKey = () => primaryKey;
|
|
14
13
|
|
|
15
|
-
const getKey = variables =>
|
|
14
|
+
const getKey = variables => variables === undefined ? [primaryKey] : [primaryKey, variables];
|
|
16
15
|
|
|
17
|
-
const useGeneratedQuery =
|
|
18
|
-
variables: currVariables,
|
|
19
|
-
...currOptions
|
|
20
|
-
} = {}) => {
|
|
21
|
-
const {
|
|
22
|
-
select: _select,
|
|
23
|
-
variables: prevVariables,
|
|
24
|
-
...prevOptions
|
|
25
|
-
} = { ...defaultOptions,
|
|
26
|
-
...(useDefaultOptions == null ? void 0 : useDefaultOptions())
|
|
27
|
-
};
|
|
28
|
-
const variables = isUndefined(currVariables) ? prevVariables : currVariables;
|
|
29
|
-
const queryKey = getKey(variables);
|
|
16
|
+
const useGeneratedQuery = options => {
|
|
30
17
|
const {
|
|
31
18
|
enabled,
|
|
19
|
+
variables,
|
|
32
20
|
...mergedOptions
|
|
33
|
-
} = { ...
|
|
34
|
-
...
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
queryKey
|
|
21
|
+
} = { ...defaultOptions,
|
|
22
|
+
...(useDefaultOptions == null ? void 0 : useDefaultOptions()),
|
|
23
|
+
...options,
|
|
24
|
+
...overrideOptions
|
|
38
25
|
};
|
|
39
|
-
const
|
|
26
|
+
const queryKey = getKey(variables);
|
|
27
|
+
const client = useQueryClient( // compatible with ReactQuery v4
|
|
28
|
+
mergedOptions.context ? {
|
|
40
29
|
context: mergedOptions.context
|
|
41
30
|
} : queryClient);
|
|
42
|
-
|
|
43
|
-
const setData = (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions);
|
|
44
|
-
|
|
45
31
|
const result = useRQHook({ ...mergedOptions,
|
|
46
|
-
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled
|
|
32
|
+
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
33
|
+
queryKeyHashFn,
|
|
34
|
+
queryFn,
|
|
35
|
+
queryKey
|
|
47
36
|
}, client);
|
|
48
37
|
return Object.assign(result, {
|
|
49
38
|
queryKey,
|
|
50
|
-
|
|
39
|
+
variables,
|
|
40
|
+
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
51
41
|
});
|
|
52
42
|
};
|
|
53
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { SetDataOptions, UseBaseQueryOptions } from '@tanstack/react-query'\nimport { useQueryClient } from '@tanstack/react-query'\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n Updater,\n} from './types'\
|
|
1
|
+
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { SetDataOptions, UseBaseQueryOptions } from '@tanstack/react-query'\nimport { useQueryClient } from '@tanstack/react-query'\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n Updater,\n} from './types'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n useDefaultOptions?: () => QueryBaseHookOptions\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any> & { context?: any }\n\nexport function createBaseQuery(\n initialOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n queryClient?: any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n useDefaultOptions,\n ...defaultOptions\n } = initialOptions as CreateQueryOptions\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) =>\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n\n const useGeneratedQuery = (options: QueryBaseHookOptions) => {\n const { enabled, variables, ...mergedOptions } = {\n ...defaultOptions,\n ...useDefaultOptions?.(),\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const client = useQueryClient(\n // compatible with ReactQuery v4\n mergedOptions.context ? { context: mergedOptions.context } : queryClient\n )\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKeyHashFn,\n queryFn,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(useGeneratedQuery, {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n })\n}\n"],"names":["createBaseQuery","initialOptions","useRQHook","queryClient","overrideOptions","primaryKey","queryFn","queryKeyHashFn","useDefaultOptions","defaultOptions","getPrimaryKey","getKey","variables","undefined","useGeneratedQuery","options","enabled","mergedOptions","queryKey","client","useQueryClient","context","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData"],"mappings":";;AAoBO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,WAHK,EAILC,eAJK,EAKA;EACL,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,iBAJI;IAKJ,GAAGC,cAAAA;AALC,GAAA,GAMFR,cANJ,CAAA;;EAQA,MAAMS,aAAa,GAAG,MAAML,UAA5B,CAAA;;AAEA,EAAA,MAAMM,MAAM,GAAIC,SAAD,IACbA,SAAS,KAAKC,SAAd,GAA0B,CAACR,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaO,SAAb,CAD3C,CAAA;;EAGA,MAAME,iBAAiB,GAAIC,OAAD,IAAmC;IAC3D,MAAM;MAAEC,OAAF;MAAWJ,SAAX;MAAsB,GAAGK,aAAAA;KAAkB,GAAA,EAC/C,GAAGR,cAD4C;AAE/C,MAAA,IAAGD,iBAAH,IAAA,IAAA,GAAA,KAAA,CAAA,GAAGA,iBAAiB,EAApB,CAF+C;AAG/C,MAAA,GAAGO,OAH4C;MAI/C,GAAGX,eAAAA;KAJL,CAAA;AAOA,IAAA,MAAMc,QAAQ,GAAGP,MAAM,CAACC,SAAD,CAAvB,CAAA;IAEA,MAAMO,MAAM,GAAGC,cAAc;IAE3BH,aAAa,CAACI,OAAd,GAAwB;MAAEA,OAAO,EAAEJ,aAAa,CAACI,OAAAA;KAAjD,GAA6DlB,WAFlC,CAA7B,CAAA;AAKA,IAAA,MAAMmB,MAAM,GAAGpB,SAAS,CACtB,EACE,GAAGe,aADL;AAEED,MAAAA,OAAO,EACL,OAAOA,OAAP,KAAmB,UAAnB,GACIA,OAAO,CAACG,MAAM,CAACI,YAAP,CAAoBL,QAApB,CAAD,EAAgCN,SAAhC,CADX,GAEII,OALR;MAMET,cANF;MAOED,OAPF;AAQEY,MAAAA,QAAAA;KAToB,EAWtBC,MAXsB,CAAxB,CAAA;AAcA,IAAA,OAAOK,MAAM,CAACC,MAAP,CAAcH,MAAd,EAAsB;MAC3BJ,QAD2B;MAE3BN,SAF2B;AAG3Bc,MAAAA,OAAO,EAAE,CAACC,OAAD,EAA6BC,cAA7B,KACPT,MAAM,CAACU,YAAP,CAAoBX,QAApB,EAA8BS,OAA9B,EAAuCC,cAAvC,CAAA;AAJyB,KAAtB,CAAP,CAAA;GA7BF,CAAA;;AAqCA,EAAA,OAAOJ,MAAM,CAACC,MAAP,CAAcX,iBAAd,EAAiC;IACtCJ,aADsC;IAEtCC,MAFsC;IAGtCL,OAHsC;AAItCC,IAAAA,cAAAA;AAJsC,GAAjC,CAAP,CAAA;AAMD;;;;"}
|
|
@@ -3,55 +3,45 @@
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
5
|
var reactQuery = require('@tanstack/react-query');
|
|
6
|
-
var utils = require('./utils.js');
|
|
7
6
|
|
|
8
|
-
function createBaseQuery(
|
|
7
|
+
function createBaseQuery(initialOptions, useRQHook, queryClient, overrideOptions) {
|
|
9
8
|
const {
|
|
10
9
|
primaryKey,
|
|
11
10
|
queryFn,
|
|
12
11
|
queryKeyHashFn,
|
|
13
12
|
useDefaultOptions,
|
|
14
13
|
...defaultOptions
|
|
15
|
-
} =
|
|
14
|
+
} = initialOptions;
|
|
16
15
|
|
|
17
16
|
const getPrimaryKey = () => primaryKey;
|
|
18
17
|
|
|
19
|
-
const getKey = variables =>
|
|
18
|
+
const getKey = variables => variables === undefined ? [primaryKey] : [primaryKey, variables];
|
|
20
19
|
|
|
21
|
-
const useGeneratedQuery =
|
|
22
|
-
variables: currVariables,
|
|
23
|
-
...currOptions
|
|
24
|
-
} = {}) => {
|
|
25
|
-
const {
|
|
26
|
-
select: _select,
|
|
27
|
-
variables: prevVariables,
|
|
28
|
-
...prevOptions
|
|
29
|
-
} = { ...defaultOptions,
|
|
30
|
-
...(useDefaultOptions == null ? void 0 : useDefaultOptions())
|
|
31
|
-
};
|
|
32
|
-
const variables = utils.isUndefined(currVariables) ? prevVariables : currVariables;
|
|
33
|
-
const queryKey = getKey(variables);
|
|
20
|
+
const useGeneratedQuery = options => {
|
|
34
21
|
const {
|
|
35
22
|
enabled,
|
|
23
|
+
variables,
|
|
36
24
|
...mergedOptions
|
|
37
|
-
} = { ...
|
|
38
|
-
...
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
queryKey
|
|
25
|
+
} = { ...defaultOptions,
|
|
26
|
+
...(useDefaultOptions == null ? void 0 : useDefaultOptions()),
|
|
27
|
+
...options,
|
|
28
|
+
...overrideOptions
|
|
42
29
|
};
|
|
43
|
-
const
|
|
30
|
+
const queryKey = getKey(variables);
|
|
31
|
+
const client = reactQuery.useQueryClient( // compatible with ReactQuery v4
|
|
32
|
+
mergedOptions.context ? {
|
|
44
33
|
context: mergedOptions.context
|
|
45
34
|
} : queryClient);
|
|
46
|
-
|
|
47
|
-
const setData = (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions);
|
|
48
|
-
|
|
49
35
|
const result = useRQHook({ ...mergedOptions,
|
|
50
|
-
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled
|
|
36
|
+
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
37
|
+
queryKeyHashFn,
|
|
38
|
+
queryFn,
|
|
39
|
+
queryKey
|
|
51
40
|
}, client);
|
|
52
41
|
return Object.assign(result, {
|
|
53
42
|
queryKey,
|
|
54
|
-
|
|
43
|
+
variables,
|
|
44
|
+
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
55
45
|
});
|
|
56
46
|
};
|
|
57
47
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { SetDataOptions, UseBaseQueryOptions } from '@tanstack/react-query'\nimport { useQueryClient } from '@tanstack/react-query'\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n Updater,\n} from './types'\
|
|
1
|
+
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { SetDataOptions, UseBaseQueryOptions } from '@tanstack/react-query'\nimport { useQueryClient } from '@tanstack/react-query'\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n Updater,\n} from './types'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n useDefaultOptions?: () => QueryBaseHookOptions\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any> & { context?: any }\n\nexport function createBaseQuery(\n initialOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n queryClient?: any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n useDefaultOptions,\n ...defaultOptions\n } = initialOptions as CreateQueryOptions\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) =>\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n\n const useGeneratedQuery = (options: QueryBaseHookOptions) => {\n const { enabled, variables, ...mergedOptions } = {\n ...defaultOptions,\n ...useDefaultOptions?.(),\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const client = useQueryClient(\n // compatible with ReactQuery v4\n mergedOptions.context ? { context: mergedOptions.context } : queryClient\n )\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKeyHashFn,\n queryFn,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(useGeneratedQuery, {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n })\n}\n"],"names":["createBaseQuery","initialOptions","useRQHook","queryClient","overrideOptions","primaryKey","queryFn","queryKeyHashFn","useDefaultOptions","defaultOptions","getPrimaryKey","getKey","variables","undefined","useGeneratedQuery","options","enabled","mergedOptions","queryKey","client","useQueryClient","context","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData"],"mappings":";;;;;;AAoBO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,WAHK,EAILC,eAJK,EAKA;EACL,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,iBAJI;IAKJ,GAAGC,cAAAA;AALC,GAAA,GAMFR,cANJ,CAAA;;EAQA,MAAMS,aAAa,GAAG,MAAML,UAA5B,CAAA;;AAEA,EAAA,MAAMM,MAAM,GAAIC,SAAD,IACbA,SAAS,KAAKC,SAAd,GAA0B,CAACR,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaO,SAAb,CAD3C,CAAA;;EAGA,MAAME,iBAAiB,GAAIC,OAAD,IAAmC;IAC3D,MAAM;MAAEC,OAAF;MAAWJ,SAAX;MAAsB,GAAGK,aAAAA;KAAkB,GAAA,EAC/C,GAAGR,cAD4C;AAE/C,MAAA,IAAGD,iBAAH,IAAA,IAAA,GAAA,KAAA,CAAA,GAAGA,iBAAiB,EAApB,CAF+C;AAG/C,MAAA,GAAGO,OAH4C;MAI/C,GAAGX,eAAAA;KAJL,CAAA;AAOA,IAAA,MAAMc,QAAQ,GAAGP,MAAM,CAACC,SAAD,CAAvB,CAAA;IAEA,MAAMO,MAAM,GAAGC,yBAAc;IAE3BH,aAAa,CAACI,OAAd,GAAwB;MAAEA,OAAO,EAAEJ,aAAa,CAACI,OAAAA;KAAjD,GAA6DlB,WAFlC,CAA7B,CAAA;AAKA,IAAA,MAAMmB,MAAM,GAAGpB,SAAS,CACtB,EACE,GAAGe,aADL;AAEED,MAAAA,OAAO,EACL,OAAOA,OAAP,KAAmB,UAAnB,GACIA,OAAO,CAACG,MAAM,CAACI,YAAP,CAAoBL,QAApB,CAAD,EAAgCN,SAAhC,CADX,GAEII,OALR;MAMET,cANF;MAOED,OAPF;AAQEY,MAAAA,QAAAA;KAToB,EAWtBC,MAXsB,CAAxB,CAAA;AAcA,IAAA,OAAOK,MAAM,CAACC,MAAP,CAAcH,MAAd,EAAsB;MAC3BJ,QAD2B;MAE3BN,SAF2B;AAG3Bc,MAAAA,OAAO,EAAE,CAACC,OAAD,EAA6BC,cAA7B,KACPT,MAAM,CAACU,YAAP,CAAoBX,QAApB,EAA8BS,OAA9B,EAAuCC,cAAvC,CAAA;AAJyB,KAAtB,CAAP,CAAA;GA7BF,CAAA;;AAqCA,EAAA,OAAOJ,MAAM,CAACC,MAAP,CAAcX,iBAAd,EAAiC;IACtCJ,aADsC;IAEtCC,MAFsC;IAGtCL,OAHsC;AAItCC,IAAAA,cAAAA;AAJsC,GAAjC,CAAP,CAAA;AAMD;;;;"}
|
|
@@ -1,53 +1,43 @@
|
|
|
1
1
|
import { useQueryClient } from '@tanstack/react-query';
|
|
2
|
-
import { isUndefined } from './utils.mjs';
|
|
3
2
|
|
|
4
|
-
function createBaseQuery(
|
|
3
|
+
function createBaseQuery(initialOptions, useRQHook, queryClient, overrideOptions) {
|
|
5
4
|
const {
|
|
6
5
|
primaryKey,
|
|
7
6
|
queryFn,
|
|
8
7
|
queryKeyHashFn,
|
|
9
8
|
useDefaultOptions,
|
|
10
9
|
...defaultOptions
|
|
11
|
-
} =
|
|
10
|
+
} = initialOptions;
|
|
12
11
|
|
|
13
12
|
const getPrimaryKey = () => primaryKey;
|
|
14
13
|
|
|
15
|
-
const getKey = variables =>
|
|
14
|
+
const getKey = variables => variables === undefined ? [primaryKey] : [primaryKey, variables];
|
|
16
15
|
|
|
17
|
-
const useGeneratedQuery =
|
|
18
|
-
variables: currVariables,
|
|
19
|
-
...currOptions
|
|
20
|
-
} = {}) => {
|
|
21
|
-
const {
|
|
22
|
-
select: _select,
|
|
23
|
-
variables: prevVariables,
|
|
24
|
-
...prevOptions
|
|
25
|
-
} = { ...defaultOptions,
|
|
26
|
-
...(useDefaultOptions == null ? void 0 : useDefaultOptions())
|
|
27
|
-
};
|
|
28
|
-
const variables = isUndefined(currVariables) ? prevVariables : currVariables;
|
|
29
|
-
const queryKey = getKey(variables);
|
|
16
|
+
const useGeneratedQuery = options => {
|
|
30
17
|
const {
|
|
31
18
|
enabled,
|
|
19
|
+
variables,
|
|
32
20
|
...mergedOptions
|
|
33
|
-
} = { ...
|
|
34
|
-
...
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
queryKey
|
|
21
|
+
} = { ...defaultOptions,
|
|
22
|
+
...(useDefaultOptions == null ? void 0 : useDefaultOptions()),
|
|
23
|
+
...options,
|
|
24
|
+
...overrideOptions
|
|
38
25
|
};
|
|
39
|
-
const
|
|
26
|
+
const queryKey = getKey(variables);
|
|
27
|
+
const client = useQueryClient( // compatible with ReactQuery v4
|
|
28
|
+
mergedOptions.context ? {
|
|
40
29
|
context: mergedOptions.context
|
|
41
30
|
} : queryClient);
|
|
42
|
-
|
|
43
|
-
const setData = (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions);
|
|
44
|
-
|
|
45
31
|
const result = useRQHook({ ...mergedOptions,
|
|
46
|
-
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled
|
|
32
|
+
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
33
|
+
queryKeyHashFn,
|
|
34
|
+
queryFn,
|
|
35
|
+
queryKey
|
|
47
36
|
}, client);
|
|
48
37
|
return Object.assign(result, {
|
|
49
38
|
queryKey,
|
|
50
|
-
|
|
39
|
+
variables,
|
|
40
|
+
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
51
41
|
});
|
|
52
42
|
};
|
|
53
43
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { SetDataOptions, UseBaseQueryOptions } from '@tanstack/react-query'\nimport { useQueryClient } from '@tanstack/react-query'\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n Updater,\n} from './types'\
|
|
1
|
+
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type { SetDataOptions, UseBaseQueryOptions } from '@tanstack/react-query'\nimport { useQueryClient } from '@tanstack/react-query'\nimport type {\n AdditionalCreateOptions,\n AdditionalQueryHookOptions,\n Updater,\n} from './types'\n\ninterface CreateQueryOptions\n extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,\n AdditionalCreateOptions<any, any> {\n useDefaultOptions?: () => QueryBaseHookOptions\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn' | 'enabled'\n> &\n AdditionalQueryHookOptions<any, any> & { context?: any }\n\nexport function createBaseQuery(\n initialOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n queryClient?: any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n useDefaultOptions,\n ...defaultOptions\n } = initialOptions as CreateQueryOptions\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) =>\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n\n const useGeneratedQuery = (options: QueryBaseHookOptions) => {\n const { enabled, variables, ...mergedOptions } = {\n ...defaultOptions,\n ...useDefaultOptions?.(),\n ...options,\n ...overrideOptions,\n } as QueryBaseHookOptions\n\n const queryKey = getKey(variables)\n\n const client = useQueryClient(\n // compatible with ReactQuery v4\n mergedOptions.context ? { context: mergedOptions.context } : queryClient\n )\n\n const result = useRQHook(\n {\n ...mergedOptions,\n enabled:\n typeof enabled === 'function'\n ? enabled(client.getQueryData(queryKey), variables)\n : enabled,\n queryKeyHashFn,\n queryFn,\n queryKey,\n },\n client\n )\n\n return Object.assign(result, {\n queryKey,\n variables,\n setData: (updater: Updater<any, any>, setDataOptions?: SetDataOptions) =>\n client.setQueryData(queryKey, updater, setDataOptions),\n })\n }\n\n return Object.assign(useGeneratedQuery, {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n })\n}\n"],"names":["createBaseQuery","initialOptions","useRQHook","queryClient","overrideOptions","primaryKey","queryFn","queryKeyHashFn","useDefaultOptions","defaultOptions","getPrimaryKey","getKey","variables","undefined","useGeneratedQuery","options","enabled","mergedOptions","queryKey","client","useQueryClient","context","result","getQueryData","Object","assign","setData","updater","setDataOptions","setQueryData"],"mappings":";;AAoBO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,WAHK,EAILC,eAJK,EAKA;EACL,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,iBAJI;IAKJ,GAAGC,cAAAA;AALC,GAAA,GAMFR,cANJ,CAAA;;EAQA,MAAMS,aAAa,GAAG,MAAML,UAA5B,CAAA;;AAEA,EAAA,MAAMM,MAAM,GAAIC,SAAD,IACbA,SAAS,KAAKC,SAAd,GAA0B,CAACR,UAAD,CAA1B,GAAyC,CAACA,UAAD,EAAaO,SAAb,CAD3C,CAAA;;EAGA,MAAME,iBAAiB,GAAIC,OAAD,IAAmC;IAC3D,MAAM;MAAEC,OAAF;MAAWJ,SAAX;MAAsB,GAAGK,aAAAA;KAAkB,GAAA,EAC/C,GAAGR,cAD4C;AAE/C,MAAA,IAAGD,iBAAH,IAAA,IAAA,GAAA,KAAA,CAAA,GAAGA,iBAAiB,EAApB,CAF+C;AAG/C,MAAA,GAAGO,OAH4C;MAI/C,GAAGX,eAAAA;KAJL,CAAA;AAOA,IAAA,MAAMc,QAAQ,GAAGP,MAAM,CAACC,SAAD,CAAvB,CAAA;IAEA,MAAMO,MAAM,GAAGC,cAAc;IAE3BH,aAAa,CAACI,OAAd,GAAwB;MAAEA,OAAO,EAAEJ,aAAa,CAACI,OAAAA;KAAjD,GAA6DlB,WAFlC,CAA7B,CAAA;AAKA,IAAA,MAAMmB,MAAM,GAAGpB,SAAS,CACtB,EACE,GAAGe,aADL;AAEED,MAAAA,OAAO,EACL,OAAOA,OAAP,KAAmB,UAAnB,GACIA,OAAO,CAACG,MAAM,CAACI,YAAP,CAAoBL,QAApB,CAAD,EAAgCN,SAAhC,CADX,GAEII,OALR;MAMET,cANF;MAOED,OAPF;AAQEY,MAAAA,QAAAA;KAToB,EAWtBC,MAXsB,CAAxB,CAAA;AAcA,IAAA,OAAOK,MAAM,CAACC,MAAP,CAAcH,MAAd,EAAsB;MAC3BJ,QAD2B;MAE3BN,SAF2B;AAG3Bc,MAAAA,OAAO,EAAE,CAACC,OAAD,EAA6BC,cAA7B,KACPT,MAAM,CAACU,YAAP,CAAoBX,QAApB,EAA8BS,OAA9B,EAAuCC,cAAvC,CAAA;AAJyB,KAAtB,CAAP,CAAA;GA7BF,CAAA;;AAqCA,EAAA,OAAOJ,MAAM,CAACC,MAAP,CAAcX,iBAAd,EAAiC;IACtCJ,aADsC;IAEtCC,MAFsC;IAGtCL,OAHsC;AAItCC,IAAAA,cAAAA;AAJsC,GAAjC,CAAP,CAAA;AAMD;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { QueryClient, UseQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
import type { AdditionalCreateOptions, CompatibleWithV4, ImmutableQueryHook, ImmutableQueryHookOptions, inferQueryKey } from './types';
|
|
3
|
+
export interface CreateImmutableQueryOptions<TFnData, TVariables = any, Error = unknown> extends Omit<UseQueryOptions<TFnData, Error, TFnData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'enabled' | 'select' | 'refetchInterval' | 'refetchIntervalInBackground' | 'refetchOnMount' | 'refetchOnReconnect' | 'refetchOnWindowFocus' | 'staleTime' | 'gcTime' | 'cacheTime'>, AdditionalCreateOptions<TFnData, TVariables> {
|
|
4
|
+
}
|
|
5
|
+
export declare function createImmutableQuery<TFnData, TVariables = any, Error = unknown>(options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {
|
|
6
|
+
useDefaultOptions: () => Omit<ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>, 'select'> & {
|
|
7
|
+
variables: TVariables;
|
|
8
|
+
};
|
|
9
|
+
}, queryClient?: CompatibleWithV4<QueryClient, void>): ImmutableQueryHook<TFnData, TVariables, Error, TVariables | void>;
|
|
10
|
+
export declare function createImmutableQuery<TFnData, TVariables = any, Error = unknown>(options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {
|
|
11
|
+
useDefaultOptions: () => Omit<ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>, 'select' | 'variables'>;
|
|
12
|
+
}, queryClient?: CompatibleWithV4<QueryClient, void>): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>;
|
|
13
|
+
export declare function createImmutableQuery<TFnData, TVariables = any, Error = unknown>(options: CreateImmutableQueryOptions<TFnData, TVariables, Error>, queryClient?: CompatibleWithV4<QueryClient, void>): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { createBaseQuery } from './createBaseQuery.esm.js';
|
|
3
|
+
|
|
4
|
+
function createImmutableQuery(options, queryClient) {
|
|
5
|
+
return createBaseQuery(options, useQuery, queryClient, {
|
|
6
|
+
refetchInterval: false,
|
|
7
|
+
refetchOnMount: false,
|
|
8
|
+
refetchOnReconnect: false,
|
|
9
|
+
refetchOnWindowFocus: false,
|
|
10
|
+
staleTime: Infinity,
|
|
11
|
+
gcTime: Infinity,
|
|
12
|
+
// compatible with ReactQuery v4
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
cacheTime: Infinity
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { createImmutableQuery };
|
|
19
|
+
//# sourceMappingURL=createImmutableQuery.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createImmutableQuery.esm.js","sources":["../../src/createImmutableQuery.tsx"],"sourcesContent":["import type { QueryClient, UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleWithV4,\n ImmutableQueryHook,\n ImmutableQueryHookOptions,\n inferQueryKey,\n} from './types'\n\nexport interface CreateImmutableQueryOptions<\n TFnData,\n TVariables = any,\n Error = unknown\n> extends Omit<\n UseQueryOptions<TFnData, Error, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'refetchInterval'\n | 'refetchIntervalInBackground'\n | 'refetchOnMount'\n | 'refetchOnReconnect'\n | 'refetchOnWindowFocus'\n | 'staleTime'\n | 'gcTime'\n | 'cacheTime'\n >,\n AdditionalCreateOptions<TFnData, TVariables> {}\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {\n useDefaultOptions: () => Omit<\n ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>,\n 'select'\n > & { variables: TVariables }\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables | void>\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {\n useDefaultOptions: () => Omit<\n ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>,\n 'select' | 'variables'\n >\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error>,\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>\n\nexport function createImmutableQuery(options: any, queryClient?: any) {\n return createBaseQuery(options, useQuery, queryClient, {\n refetchInterval: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n staleTime: Infinity,\n gcTime: Infinity,\n // compatible with ReactQuery v4\n // @ts-ignore\n cacheTime: Infinity,\n })\n}\n"],"names":["createImmutableQuery","options","queryClient","createBaseQuery","useQuery","refetchInterval","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus","staleTime","Infinity","gcTime","cacheTime"],"mappings":";;;AAqEO,SAASA,oBAAT,CAA8BC,OAA9B,EAA4CC,WAA5C,EAA+D;AACpE,EAAA,OAAOC,eAAe,CAACF,OAAD,EAAUG,QAAV,EAAoBF,WAApB,EAAiC;AACrDG,IAAAA,eAAe,EAAE,KADoC;AAErDC,IAAAA,cAAc,EAAE,KAFqC;AAGrDC,IAAAA,kBAAkB,EAAE,KAHiC;AAIrDC,IAAAA,oBAAoB,EAAE,KAJ+B;AAKrDC,IAAAA,SAAS,EAAEC,QAL0C;AAMrDC,IAAAA,MAAM,EAAED,QAN6C;AAOrD;AACA;AACAE,IAAAA,SAAS,EAAEF,QAAAA;AAT0C,GAAjC,CAAtB,CAAA;AAWD;;;;"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var reactQuery = require('@tanstack/react-query');
|
|
6
|
+
var createBaseQuery = require('./createBaseQuery.js');
|
|
7
|
+
|
|
8
|
+
function createImmutableQuery(options, queryClient) {
|
|
9
|
+
return createBaseQuery.createBaseQuery(options, reactQuery.useQuery, queryClient, {
|
|
10
|
+
refetchInterval: false,
|
|
11
|
+
refetchOnMount: false,
|
|
12
|
+
refetchOnReconnect: false,
|
|
13
|
+
refetchOnWindowFocus: false,
|
|
14
|
+
staleTime: Infinity,
|
|
15
|
+
gcTime: Infinity,
|
|
16
|
+
// compatible with ReactQuery v4
|
|
17
|
+
// @ts-ignore
|
|
18
|
+
cacheTime: Infinity
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
exports.createImmutableQuery = createImmutableQuery;
|
|
23
|
+
//# sourceMappingURL=createImmutableQuery.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createImmutableQuery.js","sources":["../../src/createImmutableQuery.tsx"],"sourcesContent":["import type { QueryClient, UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleWithV4,\n ImmutableQueryHook,\n ImmutableQueryHookOptions,\n inferQueryKey,\n} from './types'\n\nexport interface CreateImmutableQueryOptions<\n TFnData,\n TVariables = any,\n Error = unknown\n> extends Omit<\n UseQueryOptions<TFnData, Error, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'refetchInterval'\n | 'refetchIntervalInBackground'\n | 'refetchOnMount'\n | 'refetchOnReconnect'\n | 'refetchOnWindowFocus'\n | 'staleTime'\n | 'gcTime'\n | 'cacheTime'\n >,\n AdditionalCreateOptions<TFnData, TVariables> {}\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {\n useDefaultOptions: () => Omit<\n ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>,\n 'select'\n > & { variables: TVariables }\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables | void>\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {\n useDefaultOptions: () => Omit<\n ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>,\n 'select' | 'variables'\n >\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error>,\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>\n\nexport function createImmutableQuery(options: any, queryClient?: any) {\n return createBaseQuery(options, useQuery, queryClient, {\n refetchInterval: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n staleTime: Infinity,\n gcTime: Infinity,\n // compatible with ReactQuery v4\n // @ts-ignore\n cacheTime: Infinity,\n })\n}\n"],"names":["createImmutableQuery","options","queryClient","createBaseQuery","useQuery","refetchInterval","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus","staleTime","Infinity","gcTime","cacheTime"],"mappings":";;;;;;;AAqEO,SAASA,oBAAT,CAA8BC,OAA9B,EAA4CC,WAA5C,EAA+D;AACpE,EAAA,OAAOC,+BAAe,CAACF,OAAD,EAAUG,mBAAV,EAAoBF,WAApB,EAAiC;AACrDG,IAAAA,eAAe,EAAE,KADoC;AAErDC,IAAAA,cAAc,EAAE,KAFqC;AAGrDC,IAAAA,kBAAkB,EAAE,KAHiC;AAIrDC,IAAAA,oBAAoB,EAAE,KAJ+B;AAKrDC,IAAAA,SAAS,EAAEC,QAL0C;AAMrDC,IAAAA,MAAM,EAAED,QAN6C;AAOrD;AACA;AACAE,IAAAA,SAAS,EAAEF,QAAAA;AAT0C,GAAjC,CAAtB,CAAA;AAWD;;;;"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { createBaseQuery } from './createBaseQuery.mjs';
|
|
3
|
+
|
|
4
|
+
function createImmutableQuery(options, queryClient) {
|
|
5
|
+
return createBaseQuery(options, useQuery, queryClient, {
|
|
6
|
+
refetchInterval: false,
|
|
7
|
+
refetchOnMount: false,
|
|
8
|
+
refetchOnReconnect: false,
|
|
9
|
+
refetchOnWindowFocus: false,
|
|
10
|
+
staleTime: Infinity,
|
|
11
|
+
gcTime: Infinity,
|
|
12
|
+
// compatible with ReactQuery v4
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
cacheTime: Infinity
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export { createImmutableQuery };
|
|
19
|
+
//# sourceMappingURL=createImmutableQuery.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createImmutableQuery.mjs","sources":["../../src/createImmutableQuery.tsx"],"sourcesContent":["import type { QueryClient, UseQueryOptions } from '@tanstack/react-query'\nimport { useQuery } from '@tanstack/react-query'\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleWithV4,\n ImmutableQueryHook,\n ImmutableQueryHookOptions,\n inferQueryKey,\n} from './types'\n\nexport interface CreateImmutableQueryOptions<\n TFnData,\n TVariables = any,\n Error = unknown\n> extends Omit<\n UseQueryOptions<TFnData, Error, TFnData, inferQueryKey<TVariables>>,\n | 'queryKey'\n | 'queryFn'\n | 'enabled'\n | 'select'\n | 'refetchInterval'\n | 'refetchIntervalInBackground'\n | 'refetchOnMount'\n | 'refetchOnReconnect'\n | 'refetchOnWindowFocus'\n | 'staleTime'\n | 'gcTime'\n | 'cacheTime'\n >,\n AdditionalCreateOptions<TFnData, TVariables> {}\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {\n useDefaultOptions: () => Omit<\n ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>,\n 'select'\n > & { variables: TVariables }\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables | void>\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error> & {\n useDefaultOptions: () => Omit<\n ImmutableQueryHookOptions<TFnData, Error, TFnData, TVariables>,\n 'select' | 'variables'\n >\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>\n\nexport function createImmutableQuery<\n TFnData,\n TVariables = any,\n Error = unknown\n>(\n options: CreateImmutableQueryOptions<TFnData, TVariables, Error>,\n queryClient?: CompatibleWithV4<QueryClient, void>\n): ImmutableQueryHook<TFnData, TVariables, Error, TVariables>\n\nexport function createImmutableQuery(options: any, queryClient?: any) {\n return createBaseQuery(options, useQuery, queryClient, {\n refetchInterval: false,\n refetchOnMount: false,\n refetchOnReconnect: false,\n refetchOnWindowFocus: false,\n staleTime: Infinity,\n gcTime: Infinity,\n // compatible with ReactQuery v4\n // @ts-ignore\n cacheTime: Infinity,\n })\n}\n"],"names":["createImmutableQuery","options","queryClient","createBaseQuery","useQuery","refetchInterval","refetchOnMount","refetchOnReconnect","refetchOnWindowFocus","staleTime","Infinity","gcTime","cacheTime"],"mappings":";;;AAqEO,SAASA,oBAAT,CAA8BC,OAA9B,EAA4CC,WAA5C,EAA+D;AACpE,EAAA,OAAOC,eAAe,CAACF,OAAD,EAAUG,QAAV,EAAoBF,WAApB,EAAiC;AACrDG,IAAAA,eAAe,EAAE,KADoC;AAErDC,IAAAA,cAAc,EAAE,KAFqC;AAGrDC,IAAAA,kBAAkB,EAAE,KAHiC;AAIrDC,IAAAA,oBAAoB,EAAE,KAJ+B;AAKrDC,IAAAA,SAAS,EAAEC,QAL0C;AAMrDC,IAAAA,MAAM,EAAED,QAN6C;AAOrD;AACA;AACAE,IAAAA,SAAS,EAAEF,QAAAA;AAT0C,GAAjC,CAAtB,CAAA;AAWD;;;;"}
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import type { QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import type { AdditionalCreateOptions, CompatibleUseInfiniteQueryOptions, CompatibleWithV4, InfiniteQueryHook, InfiniteQueryHookOptions } from './types';
|
|
3
|
-
interface CreateInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam> extends Omit<CompatibleUseInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam>, 'queryKey' | 'queryFn' | 'enabled' | 'select'>, AdditionalCreateOptions<TFnData, TVariables, TPageParam> {
|
|
3
|
+
export interface CreateInfiniteQueryOptions<TFnData, TVariables = any, Error = unknown, TPageParam = number> extends Omit<CompatibleUseInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam>, 'queryKey' | 'queryFn' | 'enabled' | 'select'>, AdditionalCreateOptions<TFnData, TVariables, TPageParam> {
|
|
4
4
|
}
|
|
5
5
|
export declare function createInfiniteQuery<TFnData, TVariables = any, Error = unknown, TPageParam = number>(options: CreateInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam> & {
|
|
6
6
|
useDefaultOptions: () => Omit<InfiniteQueryHookOptions<TFnData, Error, TVariables, TVariables, TPageParam>, 'select'> & {
|
|
7
7
|
variables: TVariables;
|
|
8
8
|
};
|
|
9
|
-
}, queryClient?: CompatibleWithV4<QueryClient, void>): InfiniteQueryHook<TFnData, TVariables, Error, TVariables | void
|
|
9
|
+
}, queryClient?: CompatibleWithV4<QueryClient, void>): InfiniteQueryHook<TFnData, TVariables, Error, TPageParam, TVariables | void>;
|
|
10
10
|
export declare function createInfiniteQuery<TFnData, TVariables = any, Error = unknown, TPageParam = number>(options: CreateInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam> & {
|
|
11
|
-
useDefaultOptions: () => Omit<InfiniteQueryHookOptions<TFnData, Error, TVariables,
|
|
12
|
-
}, queryClient?: CompatibleWithV4<QueryClient, void>): InfiniteQueryHook<TFnData, TVariables, Error,
|
|
13
|
-
export declare function createInfiniteQuery<TFnData, TVariables = any, Error = unknown, TPageParam = number>(options: CreateInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam>, queryClient?: CompatibleWithV4<QueryClient, void>): InfiniteQueryHook<TFnData, TVariables, Error,
|
|
14
|
-
export {};
|
|
11
|
+
useDefaultOptions: () => Omit<InfiniteQueryHookOptions<TFnData, Error, TVariables, TPageParam, TVariables>, 'select' | 'variables'>;
|
|
12
|
+
}, queryClient?: CompatibleWithV4<QueryClient, void>): InfiniteQueryHook<TFnData, TVariables, Error, TPageParam, TVariables>;
|
|
13
|
+
export declare function createInfiniteQuery<TFnData, TVariables = any, Error = unknown, TPageParam = number>(options: CreateInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam>, queryClient?: CompatibleWithV4<QueryClient, void>): InfiniteQueryHook<TFnData, TVariables, Error, TPageParam, TVariables>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInfiniteQuery.esm.js","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import type { QueryClient } from '@tanstack/react-query'\nimport { useInfiniteQuery } from '@tanstack/react-query'\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n CompatibleWithV4,\n InfiniteQueryHook,\n InfiniteQueryHookOptions,\n} from './types'\n\
|
|
1
|
+
{"version":3,"file":"createInfiniteQuery.esm.js","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import type { QueryClient } from '@tanstack/react-query'\nimport { useInfiniteQuery } from '@tanstack/react-query'\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n AdditionalCreateOptions,\n CompatibleUseInfiniteQueryOptions,\n CompatibleWithV4,\n InfiniteQueryHook,\n InfiniteQueryHookOptions,\n} from './types'\n\nexport interface CreateInfiniteQueryOptions<\n TFnData,\n TVariables = any,\n Error = unknown,\n TPageParam = number\n> extends Omit<\n CompatibleUseInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam>,\n 'queryKey' | 'queryFn' | 'enabled' | 'select'\n >,\n AdditionalCreateOptions<TFnData, TVariables, TPageParam> {}\n\nexport function createInfiniteQuery<\n TFnData,\n TVariables = any,\n Error = unknown,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<\n TFnData,\n TVariables,\n Error,\n TPageParam\n > & {\n useDefaultOptions: () => Omit<\n InfiniteQueryHookOptions<\n TFnData,\n Error,\n TVariables,\n TVariables,\n TPageParam\n >,\n 'select'\n > & { variables: TVariables }\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): InfiniteQueryHook<TFnData, TVariables, Error, TPageParam, TVariables | void>\n\nexport function createInfiniteQuery<\n TFnData,\n TVariables = any,\n Error = unknown,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<\n TFnData,\n TVariables,\n Error,\n TPageParam\n > & {\n useDefaultOptions: () => Omit<\n InfiniteQueryHookOptions<\n TFnData,\n Error,\n TVariables,\n TPageParam,\n TVariables\n >,\n 'select' | 'variables'\n >\n },\n queryClient?: CompatibleWithV4<QueryClient, void>\n): InfiniteQueryHook<TFnData, TVariables, Error, TPageParam, TVariables>\n\nexport function createInfiniteQuery<\n TFnData,\n TVariables = any,\n Error = unknown,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, Error, TPageParam>,\n queryClient?: CompatibleWithV4<QueryClient, void>\n): InfiniteQueryHook<TFnData, TVariables, Error, TPageParam, TVariables>\n\nexport function createInfiniteQuery(options: any, queryClient?: any) {\n return createBaseQuery(options, useInfiniteQuery, queryClient)\n}\n"],"names":["createInfiniteQuery","options","queryClient","createBaseQuery","useInfiniteQuery"],"mappings":";;;AAoFO,SAASA,mBAAT,CAA6BC,OAA7B,EAA2CC,WAA3C,EAA8D;AACnE,EAAA,OAAOC,eAAe,CAACF,OAAD,EAAUG,gBAAV,EAA4BF,WAA5B,CAAtB,CAAA;AACD;;;;"}
|