react-query-kit 1.5.2 → 2.0.1
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 +67 -54
- package/build/lib/createBaseQuery.d.ts +3 -2
- package/build/lib/createBaseQuery.esm.js +19 -26
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +16 -23
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +19 -26
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/lib/createInfiniteQuery.d.ts +1 -4
- 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 -5
- 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 +1 -5
- 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 +1 -4
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
- package/build/lib/createSuspenseQuery.d.ts +1 -5
- package/build/lib/createSuspenseQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseQuery.js.map +1 -1
- package/build/lib/createSuspenseQuery.mjs.map +1 -1
- package/build/lib/index.d.ts +2 -2
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/types.d.ts +38 -36
- package/build/lib/utils.d.ts +2 -3
- package/build/lib/utils.esm.js +12 -20
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +12 -21
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +12 -20
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +81 -81
- package/build/umd/index.development.js +30 -45
- 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 +2 -7
- package/src/createBaseQuery.ts +26 -41
- package/src/createInfiniteQuery.ts +1 -22
- package/src/createMutation.ts +1 -11
- package/src/createQuery.tsx +1 -20
- package/src/createSuspenseInfiniteQuery.ts +1 -30
- package/src/createSuspenseQuery.ts +2 -27
- package/src/index.ts +8 -1
- package/src/types.ts +173 -117
- package/src/utils.ts +14 -21
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<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>
|
|
17
17
|
<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>
|
|
18
18
|
<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>
|
|
19
|
-
<a href="https://
|
|
19
|
+
<a href="https://github.com/liaoliao666/react-query-kit/blob/main/LICENSE"><img src="https://badgen.net/npm/license/react-query-kit" alt="License" target="\_parent"></a>
|
|
20
20
|
<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>
|
|
21
21
|
<a href="https://github.com/liaoliao666/react-query-kit"><img src="https://img.shields.io/github/stars/liaoliao666/react-query-kit.svg?style=social&label=Star" alt="GitHub Stars" target="\_parent"></a>
|
|
22
22
|
</p>
|
|
@@ -28,9 +28,9 @@
|
|
|
28
28
|
|
|
29
29
|
- Make `queryKey` strongly related with `queryFn`
|
|
30
30
|
- Manage `queryKey` in a type-safe way
|
|
31
|
-
- Generate a custom ReactQuery hook quickly
|
|
32
31
|
- Make `queryClient`'s operations clearly associated with custom ReactQuery hooks
|
|
33
32
|
- Set defaultOptions for custom ReactQuery hooks easier and clearer
|
|
33
|
+
- Middleware
|
|
34
34
|
|
|
35
35
|

|
|
36
36
|
|
|
@@ -93,8 +93,6 @@ const usePost = createQuery<Response, Variables, Error>({
|
|
|
93
93
|
// primaryKey equals to '/posts'
|
|
94
94
|
return fetch(`${primaryKey}/${variables.id}`).then(res => res.json())
|
|
95
95
|
},
|
|
96
|
-
// if u only wanna fetch once
|
|
97
|
-
enabled: (data) => !data,
|
|
98
96
|
suspense: true,
|
|
99
97
|
// u can also pass middleware to cutomize this hook's behavior
|
|
100
98
|
use: [myMiddleware]
|
|
@@ -154,10 +152,6 @@ Options
|
|
|
154
152
|
- `primaryKey: string`
|
|
155
153
|
- Required
|
|
156
154
|
- `primaryKey` will be the first element of the array of `queryKey`
|
|
157
|
-
- `enabled: boolean | ((data: TData, variables: TVariables) => boolean)`
|
|
158
|
-
- Optional
|
|
159
|
-
- Set this to `false` to disable this query from automatically running.
|
|
160
|
-
- If set to a function, the function will be executed with the latest data to compute the boolean
|
|
161
155
|
- `use: Middleware[]`
|
|
162
156
|
- Optional
|
|
163
157
|
- array of middleware functions [(details)](#middleware)
|
|
@@ -170,15 +164,6 @@ Expose Methods
|
|
|
170
164
|
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
171
165
|
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
172
166
|
|
|
173
|
-
Returns
|
|
174
|
-
|
|
175
|
-
- `queryKey: [primaryKey, TVariables]`
|
|
176
|
-
- The query key of this custom query.
|
|
177
|
-
- `variables: TVariables`
|
|
178
|
-
- The variables of this custom query.
|
|
179
|
-
- `setData: (updater: Updater<TData>, options?: SetDataOptions) => TData | undefined`
|
|
180
|
-
- it's args similar with `queryClient.setQueryData` but without `queryKey`
|
|
181
|
-
|
|
182
167
|
## createInfiniteQuery
|
|
183
168
|
|
|
184
169
|
### Usage
|
|
@@ -239,7 +224,9 @@ export default function Page() {
|
|
|
239
224
|
export async function getStaticProps() {
|
|
240
225
|
const queryClient = new QueryClient()
|
|
241
226
|
|
|
242
|
-
await queryClient.prefetchInfiniteQuery(
|
|
227
|
+
await queryClient.prefetchInfiniteQuery(
|
|
228
|
+
useProjects.getFetchOptions(variables)
|
|
229
|
+
)
|
|
243
230
|
|
|
244
231
|
return {
|
|
245
232
|
props: {
|
|
@@ -249,10 +236,9 @@ export async function getStaticProps() {
|
|
|
249
236
|
}
|
|
250
237
|
|
|
251
238
|
// usage outside of react component
|
|
252
|
-
const data = await queryClient.fetchInfiniteQuery(
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const data = await queryClient.fetchInfiniteQuery(useProjects.getFetchOptions(variables))
|
|
239
|
+
const data = await queryClient.fetchInfiniteQuery(
|
|
240
|
+
useProjects.getFetchOptions(variables)
|
|
241
|
+
)
|
|
256
242
|
```
|
|
257
243
|
|
|
258
244
|
### Additional API Reference
|
|
@@ -262,10 +248,6 @@ Options
|
|
|
262
248
|
- `primaryKey: string`
|
|
263
249
|
- Required
|
|
264
250
|
- `primaryKey` will be the first element of the arrary of `queryKey`
|
|
265
|
-
- `enabled: boolean | ((data: TData, variables: TVariables) => boolean)`
|
|
266
|
-
- Optional
|
|
267
|
-
- Set this to `false` to disable this query from automatically running.
|
|
268
|
-
- If set to a function, the function will be executed with the latest data to compute the boolean
|
|
269
251
|
- `use: Middleware[]`
|
|
270
252
|
- Optional
|
|
271
253
|
- array of middleware functions [(details)](#middleware)
|
|
@@ -278,15 +260,6 @@ Expose Methods
|
|
|
278
260
|
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
279
261
|
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
280
262
|
|
|
281
|
-
Returns
|
|
282
|
-
|
|
283
|
-
- `queryKey: [primaryKey, TVariables]`
|
|
284
|
-
- The query key of this custom query.
|
|
285
|
-
- `variables: TVariables`
|
|
286
|
-
- The variables of this custom query.
|
|
287
|
-
- `setData: (updater: Updater<InfiniteData<TFnData>>, options?: SetDataOptions) => TData | undefined`
|
|
288
|
-
- it's args similar with `queryClient.setQueryData` but without `queryKey`
|
|
289
|
-
|
|
290
263
|
## createSuspenseQuery
|
|
291
264
|
|
|
292
265
|
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).
|
|
@@ -405,17 +378,26 @@ Middleware receive the hook and can execute logic before and after running it. I
|
|
|
405
378
|
### Usage
|
|
406
379
|
|
|
407
380
|
```ts
|
|
408
|
-
import {
|
|
381
|
+
import { QueryClient } from '@tanstack/react-query'
|
|
382
|
+
import { Middleware, MutationHook, QueryHook, getKey } from 'react-query-kit'
|
|
409
383
|
|
|
410
384
|
const myMiddleware: Middleware<
|
|
411
385
|
QueryHook<Response, Variables>
|
|
412
386
|
> = useQueryNext => {
|
|
413
|
-
return options => {
|
|
387
|
+
return (options, queryClient) => {
|
|
414
388
|
const { userId } = useAuth()
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
389
|
+
const client = useQueryClient(queryClient)
|
|
390
|
+
const variables = options.variables ?? { id: userId }
|
|
391
|
+
const hasData = () => !!client.getQueryData(useUser.getKey(variables))
|
|
392
|
+
|
|
393
|
+
return useQueryNext(
|
|
394
|
+
{
|
|
395
|
+
...options,
|
|
396
|
+
variables,
|
|
397
|
+
enabled: options.enabled ?? !hasData(),
|
|
398
|
+
},
|
|
399
|
+
queryClient
|
|
400
|
+
)
|
|
419
401
|
}
|
|
420
402
|
}
|
|
421
403
|
|
|
@@ -426,26 +408,56 @@ const useUser = createQuery<Response, Variables>({
|
|
|
426
408
|
|
|
427
409
|
// global middlewares
|
|
428
410
|
const queryMiddleware: Middleware<QueryHook> = useQueryNext => {
|
|
429
|
-
return options => {
|
|
411
|
+
return (options, queryClient) => {
|
|
412
|
+
// u can also get queryKey via function getKey
|
|
413
|
+
const queryKey = getKey(options.primaryKey, options.variables)
|
|
430
414
|
// ...
|
|
431
|
-
return useQueryNext(options)
|
|
415
|
+
return useQueryNext(options, queryClient)
|
|
432
416
|
}
|
|
433
417
|
}
|
|
434
418
|
const mutationMiddleware: Middleware<MutationHook> = useMutationNext => {
|
|
435
|
-
return options => {
|
|
419
|
+
return (options, queryClient) => {
|
|
436
420
|
// ...
|
|
437
|
-
return useMutationNext(options)
|
|
421
|
+
return useMutationNext(options, queryClient)
|
|
438
422
|
}
|
|
439
423
|
}
|
|
440
424
|
|
|
441
|
-
const queryClient =
|
|
442
|
-
|
|
443
|
-
|
|
425
|
+
const queryClient = new QueryClient({
|
|
426
|
+
defaultOptions: {
|
|
427
|
+
queries: {
|
|
428
|
+
use: [queryMiddleware],
|
|
429
|
+
},
|
|
430
|
+
mutations: {
|
|
431
|
+
use: [mutationMiddleware],
|
|
432
|
+
},
|
|
444
433
|
},
|
|
445
|
-
|
|
446
|
-
|
|
434
|
+
})
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
### Extend
|
|
438
|
+
|
|
439
|
+
Middleware will be merged from superior. For example:
|
|
440
|
+
|
|
441
|
+
```jsx
|
|
442
|
+
const queryClient = new QueryClient({
|
|
443
|
+
defaultOptions: {
|
|
444
|
+
queries: {
|
|
445
|
+
use: [a],
|
|
446
|
+
},
|
|
447
447
|
},
|
|
448
448
|
})
|
|
449
|
+
|
|
450
|
+
const useSomething = createQuery({
|
|
451
|
+
use: [b],
|
|
452
|
+
})
|
|
453
|
+
|
|
454
|
+
useSomething({ use: [c] })
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
is equivalent to:
|
|
458
|
+
|
|
459
|
+
```js
|
|
460
|
+
createQuery({ use: [a, b, c] })
|
|
449
461
|
```
|
|
450
462
|
|
|
451
463
|
### Multiple Middleware
|
|
@@ -470,16 +482,17 @@ exit a
|
|
|
470
482
|
|
|
471
483
|
## Type inference
|
|
472
484
|
|
|
473
|
-
You can extract the TypeScript type of any custom hook with `
|
|
485
|
+
You can extract the TypeScript type of any custom hook with `inferData` or `inferVariables`
|
|
474
486
|
|
|
475
487
|
```ts
|
|
476
|
-
import { inferData, inferFnData, inferVariables, inferOptions } from 'react-query-kit'
|
|
488
|
+
import { inferData, inferFnData, inferError, inferVariables, inferOptions } from 'react-query-kit'
|
|
477
489
|
|
|
478
|
-
const useProjects = createInfiniteQuery<Response, Variables>(...)
|
|
490
|
+
const useProjects = createInfiniteQuery<Response, Variables, Error>(...)
|
|
479
491
|
|
|
480
|
-
inferVariables<typeof useProjects> // Variables
|
|
481
492
|
inferData<typeof useProjects> // InfiniteData<Response>
|
|
482
493
|
inferFnData<typeof useProjects> // Response
|
|
494
|
+
inferVariables<typeof useProjects> // Variables
|
|
495
|
+
inferError<typeof useProjects> // Error
|
|
483
496
|
inferOptions<typeof useProjects> // InfiniteQueryHookOptions<...>
|
|
484
497
|
```
|
|
485
498
|
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { UseBaseQueryOptions } from '@tanstack/react-query';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type QueryBaseHookOptions = Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn'> & {
|
|
3
|
+
variables?: any;
|
|
4
|
+
};
|
|
4
5
|
export declare function createBaseQuery(defaultOptions: any, useRQHook: (options: any, queryClient?: any) => any, overrideOptions?: QueryBaseHookOptions): any;
|
|
5
6
|
export {};
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { withMiddleware,
|
|
1
|
+
import { withMiddleware, getKey } from './utils.esm.js';
|
|
2
2
|
|
|
3
3
|
function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
4
4
|
const {
|
|
5
5
|
primaryKey,
|
|
6
6
|
queryFn,
|
|
7
|
-
queryKeyHashFn
|
|
7
|
+
queryKeyHashFn,
|
|
8
|
+
getPreviousPageParam,
|
|
9
|
+
getNextPageParam,
|
|
10
|
+
initialPageParam
|
|
8
11
|
} = defaultOptions;
|
|
9
12
|
|
|
10
13
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -16,42 +19,32 @@ function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
|
16
19
|
|
|
17
20
|
const getPrimaryKey = () => primaryKey;
|
|
18
21
|
|
|
19
|
-
const getKey = variables =>
|
|
22
|
+
const getKey$1 = variables => getKey(primaryKey, variables);
|
|
20
23
|
|
|
21
24
|
const getFetchOptions = variables => {
|
|
22
25
|
return {
|
|
23
|
-
queryKey: getKey(variables),
|
|
26
|
+
queryKey: getKey$1(variables),
|
|
24
27
|
queryFn,
|
|
25
28
|
queryKeyHashFn,
|
|
26
|
-
getPreviousPageParam
|
|
27
|
-
getNextPageParam
|
|
28
|
-
initialPageParam
|
|
29
|
+
getPreviousPageParam,
|
|
30
|
+
getNextPageParam,
|
|
31
|
+
initialPageParam
|
|
29
32
|
};
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
const useBaseHook = (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
...
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
const queryKey = getKey(variables);
|
|
42
|
-
return Object.assign(useRQHook({ ...mergedOptions,
|
|
43
|
-
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
44
|
-
queryKey
|
|
45
|
-
}, client), {
|
|
46
|
-
queryKey: queryKey,
|
|
47
|
-
variables,
|
|
48
|
-
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
49
|
-
});
|
|
35
|
+
const useBaseHook = ({
|
|
36
|
+
variables,
|
|
37
|
+
...rest
|
|
38
|
+
}, queryClient) => {
|
|
39
|
+
return useRQHook({ ...rest,
|
|
40
|
+
...overrideOptions,
|
|
41
|
+
queryKey: getKey$1(variables)
|
|
42
|
+
}, queryClient);
|
|
50
43
|
};
|
|
51
44
|
|
|
52
45
|
return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {
|
|
53
46
|
getPrimaryKey,
|
|
54
|
-
getKey,
|
|
47
|
+
getKey: getKey$1,
|
|
55
48
|
queryFn,
|
|
56
49
|
queryKeyHashFn,
|
|
57
50
|
getFetchOptions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n
|
|
1
|
+
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n }\n }\n\n const useBaseHook = (\n { variables, ...rest }: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n return useRQHook(\n {\n ...rest,\n ...overrideOptions,\n queryKey: getKey(variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n getFetchOptions,\n })\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","process","env","NODE_ENV","useDefaultOptions","Error","getPrimaryKey","getKey","variables","getQueryKey","getFetchOptions","queryKey","useBaseHook","rest","queryClient","Object","assign","withMiddleware"],"mappings":";;AA0BO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,eAHK,EAIA;EACL,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFR,cAPJ,CAAA;;AASA,EAAA,IAAIS,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIX,cAAc,CAACY,iBAAnB,EAAsC;AACpC,MAAA,MAAM,IAAIC,KAAJ,CACJ,oEADI,CAAN,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAMC,aAAa,GAAG,MAAMX,UAA5B,CAAA;;EAEA,MAAMY,QAAM,GAAIC,SAAD,IAAqBC,MAAW,CAACd,UAAD,EAAaa,SAAb,CAA/C,CAAA;;EAEA,MAAME,eAAe,GAAIF,SAAD,IAAoB;IAC1C,OAAO;AACLG,MAAAA,QAAQ,EAAEJ,QAAM,CAACC,SAAD,CADX;MAELZ,OAFK;MAGLC,cAHK;MAILC,oBAJK;MAKLC,gBALK;AAMLC,MAAAA,gBAAAA;KANF,CAAA;GADF,CAAA;;EAWA,MAAMY,WAAW,GAAG,CAClB;IAAEJ,SAAF;IAAa,GAAGK,IAAAA;GADE,EAElBC,WAFkB,KAGf;AACH,IAAA,OAAOrB,SAAS,CACd,EACE,GAAGoB,IADL;AAEE,MAAA,GAAGnB,eAFL;MAGEiB,QAAQ,EAAEJ,QAAM,CAACC,SAAD,CAAA;KAJJ,EAMdM,WANc,CAAhB,CAAA;GAJF,CAAA;;AAcA,EAAA,OAAOC,MAAM,CAACC,MAAP,CAAcC,cAAc,CAACL,WAAD,EAAcpB,cAAd,EAA8B,SAA9B,CAA5B,EAAsE;IAC3Ec,aAD2E;YAE3EC,QAF2E;IAG3EX,OAH2E;IAI3EC,cAJ2E;AAK3Ea,IAAAA,eAAAA;AAL2E,GAAtE,CAAP,CAAA;AAOD;;;;"}
|
|
@@ -8,7 +8,10 @@ function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
|
8
8
|
const {
|
|
9
9
|
primaryKey,
|
|
10
10
|
queryFn,
|
|
11
|
-
queryKeyHashFn
|
|
11
|
+
queryKeyHashFn,
|
|
12
|
+
getPreviousPageParam,
|
|
13
|
+
getNextPageParam,
|
|
14
|
+
initialPageParam
|
|
12
15
|
} = defaultOptions;
|
|
13
16
|
|
|
14
17
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -20,37 +23,27 @@ function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
|
20
23
|
|
|
21
24
|
const getPrimaryKey = () => primaryKey;
|
|
22
25
|
|
|
23
|
-
const getKey = variables => utils.
|
|
26
|
+
const getKey = variables => utils.getKey(primaryKey, variables);
|
|
24
27
|
|
|
25
28
|
const getFetchOptions = variables => {
|
|
26
29
|
return {
|
|
27
30
|
queryKey: getKey(variables),
|
|
28
31
|
queryFn,
|
|
29
32
|
queryKeyHashFn,
|
|
30
|
-
getPreviousPageParam
|
|
31
|
-
getNextPageParam
|
|
32
|
-
initialPageParam
|
|
33
|
+
getPreviousPageParam,
|
|
34
|
+
getNextPageParam,
|
|
35
|
+
initialPageParam
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
38
|
|
|
36
|
-
const useBaseHook = (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
...
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
};
|
|
45
|
-
const queryKey = getKey(variables);
|
|
46
|
-
return Object.assign(useRQHook({ ...mergedOptions,
|
|
47
|
-
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
48
|
-
queryKey
|
|
49
|
-
}, client), {
|
|
50
|
-
queryKey: queryKey,
|
|
51
|
-
variables,
|
|
52
|
-
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
53
|
-
});
|
|
39
|
+
const useBaseHook = ({
|
|
40
|
+
variables,
|
|
41
|
+
...rest
|
|
42
|
+
}, queryClient) => {
|
|
43
|
+
return useRQHook({ ...rest,
|
|
44
|
+
...overrideOptions,
|
|
45
|
+
queryKey: getKey(variables)
|
|
46
|
+
}, queryClient);
|
|
54
47
|
};
|
|
55
48
|
|
|
56
49
|
return Object.assign(utils.withMiddleware(useBaseHook, defaultOptions, 'queries'), {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n
|
|
1
|
+
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n }\n }\n\n const useBaseHook = (\n { variables, ...rest }: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n return useRQHook(\n {\n ...rest,\n ...overrideOptions,\n queryKey: getKey(variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n getFetchOptions,\n })\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","process","env","NODE_ENV","useDefaultOptions","Error","getPrimaryKey","getKey","variables","getQueryKey","getFetchOptions","queryKey","useBaseHook","rest","queryClient","Object","assign","withMiddleware"],"mappings":";;;;;;AA0BO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,eAHK,EAIA;EACL,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFR,cAPJ,CAAA;;AASA,EAAA,IAAIS,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIX,cAAc,CAACY,iBAAnB,EAAsC;AACpC,MAAA,MAAM,IAAIC,KAAJ,CACJ,oEADI,CAAN,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAMC,aAAa,GAAG,MAAMX,UAA5B,CAAA;;EAEA,MAAMY,MAAM,GAAIC,SAAD,IAAqBC,YAAW,CAACd,UAAD,EAAaa,SAAb,CAA/C,CAAA;;EAEA,MAAME,eAAe,GAAIF,SAAD,IAAoB;IAC1C,OAAO;AACLG,MAAAA,QAAQ,EAAEJ,MAAM,CAACC,SAAD,CADX;MAELZ,OAFK;MAGLC,cAHK;MAILC,oBAJK;MAKLC,gBALK;AAMLC,MAAAA,gBAAAA;KANF,CAAA;GADF,CAAA;;EAWA,MAAMY,WAAW,GAAG,CAClB;IAAEJ,SAAF;IAAa,GAAGK,IAAAA;GADE,EAElBC,WAFkB,KAGf;AACH,IAAA,OAAOrB,SAAS,CACd,EACE,GAAGoB,IADL;AAEE,MAAA,GAAGnB,eAFL;MAGEiB,QAAQ,EAAEJ,MAAM,CAACC,SAAD,CAAA;KAJJ,EAMdM,WANc,CAAhB,CAAA;GAJF,CAAA;;AAcA,EAAA,OAAOC,MAAM,CAACC,MAAP,CAAcC,oBAAc,CAACL,WAAD,EAAcpB,cAAd,EAA8B,SAA9B,CAA5B,EAAsE;IAC3Ec,aAD2E;IAE3EC,MAF2E;IAG3EX,OAH2E;IAI3EC,cAJ2E;AAK3Ea,IAAAA,eAAAA;AAL2E,GAAtE,CAAP,CAAA;AAOD;;;;"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { withMiddleware,
|
|
1
|
+
import { withMiddleware, getKey } from './utils.mjs';
|
|
2
2
|
|
|
3
3
|
function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
4
4
|
const {
|
|
5
5
|
primaryKey,
|
|
6
6
|
queryFn,
|
|
7
|
-
queryKeyHashFn
|
|
7
|
+
queryKeyHashFn,
|
|
8
|
+
getPreviousPageParam,
|
|
9
|
+
getNextPageParam,
|
|
10
|
+
initialPageParam
|
|
8
11
|
} = defaultOptions;
|
|
9
12
|
|
|
10
13
|
if (process.env.NODE_ENV !== 'production') {
|
|
@@ -16,42 +19,32 @@ function createBaseQuery(defaultOptions, useRQHook, overrideOptions) {
|
|
|
16
19
|
|
|
17
20
|
const getPrimaryKey = () => primaryKey;
|
|
18
21
|
|
|
19
|
-
const getKey = variables =>
|
|
22
|
+
const getKey$1 = variables => getKey(primaryKey, variables);
|
|
20
23
|
|
|
21
24
|
const getFetchOptions = variables => {
|
|
22
25
|
return {
|
|
23
|
-
queryKey: getKey(variables),
|
|
26
|
+
queryKey: getKey$1(variables),
|
|
24
27
|
queryFn,
|
|
25
28
|
queryKeyHashFn,
|
|
26
|
-
getPreviousPageParam
|
|
27
|
-
getNextPageParam
|
|
28
|
-
initialPageParam
|
|
29
|
+
getPreviousPageParam,
|
|
30
|
+
getNextPageParam,
|
|
31
|
+
initialPageParam
|
|
29
32
|
};
|
|
30
33
|
};
|
|
31
34
|
|
|
32
|
-
const useBaseHook = (
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
...
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
const queryKey = getKey(variables);
|
|
42
|
-
return Object.assign(useRQHook({ ...mergedOptions,
|
|
43
|
-
enabled: typeof enabled === 'function' ? enabled(client.getQueryData(queryKey), variables) : enabled,
|
|
44
|
-
queryKey
|
|
45
|
-
}, client), {
|
|
46
|
-
queryKey: queryKey,
|
|
47
|
-
variables,
|
|
48
|
-
setData: (updater, setDataOptions) => client.setQueryData(queryKey, updater, setDataOptions)
|
|
49
|
-
});
|
|
35
|
+
const useBaseHook = ({
|
|
36
|
+
variables,
|
|
37
|
+
...rest
|
|
38
|
+
}, queryClient) => {
|
|
39
|
+
return useRQHook({ ...rest,
|
|
40
|
+
...overrideOptions,
|
|
41
|
+
queryKey: getKey$1(variables)
|
|
42
|
+
}, queryClient);
|
|
50
43
|
};
|
|
51
44
|
|
|
52
45
|
return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {
|
|
53
46
|
getPrimaryKey,
|
|
54
|
-
getKey,
|
|
47
|
+
getKey: getKey$1,
|
|
55
48
|
queryFn,
|
|
56
49
|
queryKeyHashFn,
|
|
57
50
|
getFetchOptions
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n
|
|
1
|
+
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type {\n AdditionalCreateOptions,\n CompatibleWithV4,\n Middleware,\n} from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalCreateOptions<any, any> {\n use?: Middleware[]\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nexport function createBaseQuery(\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\n): any {\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n throw new Error(\n 'useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n }\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n }\n }\n\n const useBaseHook = (\n { variables, ...rest }: QueryBaseHookOptions,\n queryClient?: CompatibleWithV4<QueryClient, void>\n ) => {\n return useRQHook(\n {\n ...rest,\n ...overrideOptions,\n queryKey: getKey(variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n getFetchOptions,\n })\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","primaryKey","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","process","env","NODE_ENV","useDefaultOptions","Error","getPrimaryKey","getKey","variables","getQueryKey","getFetchOptions","queryKey","useBaseHook","rest","queryClient","Object","assign","withMiddleware"],"mappings":";;AA0BO,SAASA,eAAT,CACLC,cADK,EAELC,SAFK,EAGLC,eAHK,EAIA;EACL,MAAM;IACJC,UADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFR,cAPJ,CAAA;;AASA,EAAA,IAAIS,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIX,cAAc,CAACY,iBAAnB,EAAsC;AACpC,MAAA,MAAM,IAAIC,KAAJ,CACJ,oEADI,CAAN,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAMC,aAAa,GAAG,MAAMX,UAA5B,CAAA;;EAEA,MAAMY,QAAM,GAAIC,SAAD,IAAqBC,MAAW,CAACd,UAAD,EAAaa,SAAb,CAA/C,CAAA;;EAEA,MAAME,eAAe,GAAIF,SAAD,IAAoB;IAC1C,OAAO;AACLG,MAAAA,QAAQ,EAAEJ,QAAM,CAACC,SAAD,CADX;MAELZ,OAFK;MAGLC,cAHK;MAILC,oBAJK;MAKLC,gBALK;AAMLC,MAAAA,gBAAAA;KANF,CAAA;GADF,CAAA;;EAWA,MAAMY,WAAW,GAAG,CAClB;IAAEJ,SAAF;IAAa,GAAGK,IAAAA;GADE,EAElBC,WAFkB,KAGf;AACH,IAAA,OAAOrB,SAAS,CACd,EACE,GAAGoB,IADL;AAEE,MAAA,GAAGnB,eAFL;MAGEiB,QAAQ,EAAEJ,QAAM,CAACC,SAAD,CAAA;KAJJ,EAMdM,WANc,CAAhB,CAAA;GAJF,CAAA;;AAcA,EAAA,OAAOC,MAAM,CAACC,MAAP,CAAcC,cAAc,CAACL,WAAD,EAAcpB,cAAd,EAA8B,SAA9B,CAA5B,EAAsE;IAC3Ec,aAD2E;YAE3EC,QAF2E;IAG3EX,OAH2E;IAI3EC,cAJ2E;AAK3Ea,IAAAA,eAAAA;AAL2E,GAAtE,CAAP,CAAA;AAOD;;;;"}
|
|
@@ -1,5 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export interface CreateInfiniteQueryOptions<TFnData = unknown, TVariables = any, TError = DefaultError, TPageParam = number> extends Omit<CompatibleUseInfiniteQueryOptions<TFnData, TVariables, TFnData, TError, TPageParam>, 'queryKey' | 'queryFn' | 'enabled' | 'select'>, AdditionalCreateOptions<TFnData, TVariables, TPageParam> {
|
|
3
|
-
use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[];
|
|
4
|
-
}
|
|
1
|
+
import type { CreateInfiniteQueryOptions, InfiniteQueryHook } from './types';
|
|
5
2
|
export declare const createInfiniteQuery: <TFnData, TVariables = any, TError = Error, TPageParam = number>(options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>) => InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInfiniteQuery.esm.js","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n
|
|
1
|
+
{"version":3,"file":"createInfiniteQuery.esm.js","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CreateInfiniteQueryOptions,\n DefaultError,\n InfiniteQueryHook,\n} from './types'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, useInfiniteQuery)\n}\n"],"names":["createInfiniteQuery","options","createBaseQuery","useInfiniteQuery"],"mappings":";;;AASaA,MAAAA,mBAAmB,GAM9BC,OANiC,IAO8B;AAC/D,EAAA,OAAOC,eAAe,CAACD,OAAD,EAAUE,gBAAV,CAAtB,CAAA;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInfiniteQuery.js","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n
|
|
1
|
+
{"version":3,"file":"createInfiniteQuery.js","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CreateInfiniteQueryOptions,\n DefaultError,\n InfiniteQueryHook,\n} from './types'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, useInfiniteQuery)\n}\n"],"names":["createInfiniteQuery","options","createBaseQuery","useInfiniteQuery"],"mappings":";;;;;;;AASaA,MAAAA,mBAAmB,GAM9BC,OANiC,IAO8B;AAC/D,EAAA,OAAOC,+BAAe,CAACD,OAAD,EAAUE,2BAAV,CAAtB,CAAA;AACD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInfiniteQuery.mjs","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n
|
|
1
|
+
{"version":3,"file":"createInfiniteQuery.mjs","sources":["../../src/createInfiniteQuery.ts"],"sourcesContent":["import { useInfiniteQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type {\n CreateInfiniteQueryOptions,\n DefaultError,\n InfiniteQueryHook,\n} from './types'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = any,\n TError = DefaultError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, useInfiniteQuery)\n}\n"],"names":["createInfiniteQuery","options","createBaseQuery","useInfiniteQuery"],"mappings":";;;AASaA,MAAAA,mBAAmB,GAM9BC,OANiC,IAO8B;AAC/D,EAAA,OAAOC,eAAe,CAACD,OAAD,EAAUE,gBAAV,CAAtB,CAAA;AACD;;;;"}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DefaultError, Middleware, MutationHook } from './types';
|
|
3
|
-
export interface CreateMutationOptions<TData = unknown, TVariables = void, TError = DefaultError, TContext = unknown> extends UseMutationOptions<TData, TError, TVariables, TContext> {
|
|
4
|
-
use?: Middleware<MutationHook<TData, TError, TVariables>>[];
|
|
5
|
-
}
|
|
1
|
+
import type { CreateMutationOptions, MutationHook } from './types';
|
|
6
2
|
export declare const createMutation: <TData = unknown, TVariables = void, TError = Error, TContext = unknown>(defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>) => MutationHook<TData, TVariables, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMutation.esm.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import { useMutation } from '@tanstack/react-query'\
|
|
1
|
+
{"version":3,"file":"createMutation.esm.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import { useMutation } from '@tanstack/react-query'\n\nimport type { CreateMutationOptions, DefaultError, MutationHook } from './types'\nimport { withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> => {\n const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddleware(useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError>\n}\n"],"names":["createMutation","defaultOptions","getKey","mutationKey","Object","assign","withMiddleware","useMutation","mutationFn"],"mappings":";;;AAKaA,MAAAA,cAAc,GAMzBC,cAN4B,IAOgB;AAC5C,EAAA,MAAMC,MAAM,GAAG,MAAMD,cAAc,CAACE,WAApC,CAAA;;AAEA,EAAA,OAAOC,MAAM,CAACC,MAAP,CACLC,cAAc,CAACC,WAAD,EAAcN,cAAd,EAA8B,WAA9B,CADT,EAEL;IACEC,MADF;IAEEM,UAAU,EAAEP,cAAc,CAACO,UAAAA;AAF7B,GAFK,CAAP,CAAA;AAOD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMutation.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import { useMutation } from '@tanstack/react-query'\
|
|
1
|
+
{"version":3,"file":"createMutation.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import { useMutation } from '@tanstack/react-query'\n\nimport type { CreateMutationOptions, DefaultError, MutationHook } from './types'\nimport { withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> => {\n const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddleware(useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError>\n}\n"],"names":["createMutation","defaultOptions","getKey","mutationKey","Object","assign","withMiddleware","useMutation","mutationFn"],"mappings":";;;;;;;AAKaA,MAAAA,cAAc,GAMzBC,cAN4B,IAOgB;AAC5C,EAAA,MAAMC,MAAM,GAAG,MAAMD,cAAc,CAACE,WAApC,CAAA;;AAEA,EAAA,OAAOC,MAAM,CAACC,MAAP,CACLC,oBAAc,CAACC,sBAAD,EAAcN,cAAd,EAA8B,WAA9B,CADT,EAEL;IACEC,MADF;IAEEM,UAAU,EAAEP,cAAc,CAACO,UAAAA;AAF7B,GAFK,CAAP,CAAA;AAOD;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMutation.mjs","sources":["../../src/createMutation.ts"],"sourcesContent":["import { useMutation } from '@tanstack/react-query'\
|
|
1
|
+
{"version":3,"file":"createMutation.mjs","sources":["../../src/createMutation.ts"],"sourcesContent":["import { useMutation } from '@tanstack/react-query'\n\nimport type { CreateMutationOptions, DefaultError, MutationHook } from './types'\nimport { withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = DefaultError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> => {\n const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddleware(useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError>\n}\n"],"names":["createMutation","defaultOptions","getKey","mutationKey","Object","assign","withMiddleware","useMutation","mutationFn"],"mappings":";;;AAKaA,MAAAA,cAAc,GAMzBC,cAN4B,IAOgB;AAC5C,EAAA,MAAMC,MAAM,GAAG,MAAMD,cAAc,CAACE,WAApC,CAAA;;AAEA,EAAA,OAAOC,MAAM,CAACC,MAAP,CACLC,cAAc,CAACC,WAAD,EAAcN,cAAd,EAA8B,WAA9B,CADT,EAEL;IACEC,MADF;IAEEM,UAAU,EAAEP,cAAc,CAACO,UAAAA;AAF7B,GAFK,CAAP,CAAA;AAOD;;;;"}
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { AdditionalCreateOptions, DefaultError, Middleware, QueryHook, inferQueryKey } from './types';
|
|
3
|
-
export interface CreateQueryOptions<TFnData = unknown, TVariables = any, TError = DefaultError> extends Omit<UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>, 'queryKey' | 'queryFn' | 'enabled' | 'select'>, AdditionalCreateOptions<TFnData, TVariables> {
|
|
4
|
-
use?: Middleware<QueryHook<TFnData, TVariables, TError>>[];
|
|
5
|
-
}
|
|
1
|
+
import type { CreateQueryOptions, QueryHook } from './types';
|
|
6
2
|
export declare const createQuery: <TFnData, TVariables = any, TError = Error>(options: CreateQueryOptions<TFnData, TVariables, TError>) => QueryHook<TFnData, TVariables, TError>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createQuery.esm.js","sources":["../../src/createQuery.tsx"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"createQuery.esm.js","sources":["../../src/createQuery.tsx"],"sourcesContent":["import { useQuery } from '@tanstack/react-query'\n\nimport { createBaseQuery } from './createBaseQuery'\nimport type { CreateQueryOptions, DefaultError, QueryHook } from './types'\n\nexport const createQuery = <TFnData, TVariables = any, TError = DefaultError>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, useQuery)\n}\n"],"names":["createQuery","options","createBaseQuery","useQuery"],"mappings":";;;AAKaA,MAAAA,WAAW,GACtBC,OADyB,IAEkB;AAC3C,EAAA,OAAOC,eAAe,CAACD,OAAD,EAAUE,QAAV,CAAtB,CAAA;AACD;;;;"}
|