react-query-kit 2.0.9 → 3.0.0-beta.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 +105 -48
- package/build/lib/createBaseQuery.d.ts +2 -6
- package/build/lib/createBaseQuery.esm.js +19 -12
- package/build/lib/createBaseQuery.esm.js.map +1 -1
- package/build/lib/createBaseQuery.js +19 -12
- package/build/lib/createBaseQuery.js.map +1 -1
- package/build/lib/createBaseQuery.mjs +19 -12
- package/build/lib/createBaseQuery.mjs.map +1 -1
- package/build/lib/createMutation.d.ts +1 -1
- package/build/lib/createMutation.esm.js +2 -3
- package/build/lib/createMutation.esm.js.map +1 -1
- package/build/lib/createMutation.js +2 -3
- package/build/lib/createMutation.js.map +1 -1
- package/build/lib/createMutation.mjs +2 -3
- package/build/lib/createMutation.mjs.map +1 -1
- 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.esm.js +1 -1
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
- package/build/lib/createSuspenseQuery.esm.js +1 -1
- package/build/lib/createSuspenseQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseQuery.js +1 -1
- package/build/lib/createSuspenseQuery.js.map +1 -1
- package/build/lib/createSuspenseQuery.mjs +1 -1
- package/build/lib/createSuspenseQuery.mjs.map +1 -1
- package/build/lib/types.d.ts +42 -50
- package/build/lib/utils.d.ts +9 -8
- package/build/lib/utils.esm.js +10 -10
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +10 -10
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +10 -10
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +96 -96
- package/build/umd/index.development.js +33 -27
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/build/zip/zip.esm.js +1 -1
- package/package.json +1 -1
- package/src/createBaseQuery.ts +25 -14
- package/src/createMutation.ts +4 -5
- package/src/createSuspenseInfiniteQuery.ts +1 -1
- package/src/createSuspenseQuery.ts +1 -1
- package/src/types.ts +101 -164
- package/src/utils.ts +17 -21
- /package/src/{createQuery.tsx → createQuery.ts} +0 -0
package/README.md
CHANGED
|
@@ -26,10 +26,9 @@
|
|
|
26
26
|
|
|
27
27
|
## What could you benefit from it
|
|
28
28
|
|
|
29
|
-
- Make `queryKey` strongly related with `queryFn`
|
|
30
29
|
- Manage `queryKey` in a type-safe way
|
|
31
30
|
- Make `queryClient`'s operations clearly associated with custom ReactQuery hooks
|
|
32
|
-
-
|
|
31
|
+
- You can extract the TypeScript type of any custom ReactQuery hooks
|
|
33
32
|
- Middleware
|
|
34
33
|
|
|
35
34
|
English | [简体中文](./README-zh_CN.md)
|
|
@@ -49,6 +48,8 @@ English | [简体中文](./README-zh_CN.md)
|
|
|
49
48
|
- [createMutation](#createmutation)
|
|
50
49
|
- [Middleware](#middleware)
|
|
51
50
|
- [Type inference](#type-inference)
|
|
51
|
+
- [FAQ](#faq)
|
|
52
|
+
- [Migration](#migration)
|
|
52
53
|
- [Issues](#issues)
|
|
53
54
|
- [🐛 Bugs](#-bugs)
|
|
54
55
|
- [💡 Feature Requests](#-feature-requests)
|
|
@@ -62,11 +63,13 @@ This module is distributed via [npm][npm] which is bundled with [node][node] and
|
|
|
62
63
|
should be installed as one of your project's `dependencies`:
|
|
63
64
|
|
|
64
65
|
```bash
|
|
65
|
-
$ npm i react-query-kit
|
|
66
|
+
$ npm i react-query-kit@beta
|
|
66
67
|
# or
|
|
67
|
-
$ yarn add react-query-kit
|
|
68
|
+
$ yarn add react-query-kit@beta
|
|
68
69
|
```
|
|
69
70
|
|
|
71
|
+
If you still on React Query Kit v2? Check out the v2 docs here: https://github.com/liaoliao666/react-query-kit/tree/v2#readme.
|
|
72
|
+
|
|
70
73
|
# Examples
|
|
71
74
|
|
|
72
75
|
- [Basic](https://codesandbox.io/s/example-react-query-kit-basic-1ny2j8)
|
|
@@ -85,11 +88,10 @@ import { createQuery } from 'react-query-kit'
|
|
|
85
88
|
type Response = { title: string; content: string }
|
|
86
89
|
type Variables = { id: number }
|
|
87
90
|
|
|
88
|
-
const usePost = createQuery
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return fetch(`${primaryKey}/${variables.id}`).then(res => res.json())
|
|
91
|
+
const usePost = createQuery({
|
|
92
|
+
queryKey: ['posts'],
|
|
93
|
+
fetcher: (variables: Variables): Promise<Response> => {
|
|
94
|
+
return fetch(`/posts/${variables.id}`).then(res => res.json())
|
|
93
95
|
},
|
|
94
96
|
// u can also pass middleware to cutomize this hook's behavior
|
|
95
97
|
use: [myMiddleware]
|
|
@@ -100,7 +102,7 @@ const variables = { id: 1 }
|
|
|
100
102
|
|
|
101
103
|
// example
|
|
102
104
|
export default function Page() {
|
|
103
|
-
// queryKey
|
|
105
|
+
// queryKey will be `['posts', { id: 1 }]` if u passed variables
|
|
104
106
|
const { data } = usePost({ variables })
|
|
105
107
|
|
|
106
108
|
return (
|
|
@@ -111,8 +113,8 @@ export default function Page() {
|
|
|
111
113
|
)
|
|
112
114
|
}
|
|
113
115
|
|
|
114
|
-
console.log(usePost.getKey()) // ['
|
|
115
|
-
console.log(usePost.getKey(variables)) // ['
|
|
116
|
+
console.log(usePost.getKey()) // ['posts']
|
|
117
|
+
console.log(usePost.getKey(variables)) // ['posts', { id: 1 }]
|
|
116
118
|
|
|
117
119
|
// nextjs example
|
|
118
120
|
export async function getStaticProps() {
|
|
@@ -149,19 +151,20 @@ queryClient.setQueryData(usePost.getKey(variables), {...})
|
|
|
149
151
|
|
|
150
152
|
Options
|
|
151
153
|
|
|
152
|
-
- `
|
|
154
|
+
- `fetcher: (variables: TVariables, context: QueryFunctionContext<QueryKey, TPageParam>) => TFnData | Promise<TFnData>`
|
|
153
155
|
- Required
|
|
154
|
-
-
|
|
156
|
+
- The function that the query will use to request data. And The second param is the `QueryFunctionContext` of `queryFn`.
|
|
157
|
+
- `variables?: TVariables`
|
|
158
|
+
- Optional
|
|
159
|
+
- `variables` will be the frist param of fetcher and the last element of the `queryKey` array
|
|
155
160
|
- `use: Middleware[]`
|
|
156
161
|
- Optional
|
|
157
162
|
- array of middleware functions [(details)](#middleware)
|
|
158
163
|
|
|
159
164
|
Expose Methods
|
|
160
165
|
|
|
161
|
-
- `
|
|
162
|
-
- `getKey: (variables: TVariables) =>
|
|
163
|
-
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
164
|
-
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
166
|
+
- `fetcher: (variables: TVariables, context: QueryFunctionContext<QueryKey, TPageParam>) => TFnData | Promise<TFnData>`
|
|
167
|
+
- `getKey: (variables: TVariables) => QueryKey`
|
|
165
168
|
- `getOptions: (variables: TVariables) => UseQueryOptions`
|
|
166
169
|
- `getFetchOptions: (variables: TVariables) => ({ queryKey, queryFn, queryKeyHashFn })`
|
|
167
170
|
|
|
@@ -176,15 +179,15 @@ import { createInfiniteQuery } from 'react-query-kit'
|
|
|
176
179
|
type Response = { projects: { id: string; name: string }[]; nextCursor: number }
|
|
177
180
|
type Variables = { active: boolean }
|
|
178
181
|
|
|
179
|
-
const useProjects = createInfiniteQuery
|
|
180
|
-
|
|
181
|
-
|
|
182
|
+
const useProjects = createInfiniteQuery({
|
|
183
|
+
queryKey: ['projects'],
|
|
184
|
+
fetcher: (variables: Variables, { pageParam }): Promise<Response> => {
|
|
182
185
|
return fetch(
|
|
183
186
|
`/projects?cursor=${pageParam}?active=${variables.active}`
|
|
184
187
|
).then(res => res.json())
|
|
185
188
|
},
|
|
186
189
|
getNextPageParam: (lastPage, pages) => lastPage.nextCursor,
|
|
187
|
-
initialPageParam:
|
|
190
|
+
initialPageParam: 0,
|
|
188
191
|
})
|
|
189
192
|
|
|
190
193
|
const variables = { active: true }
|
|
@@ -246,19 +249,20 @@ const data = await queryClient.fetchInfiniteQuery(
|
|
|
246
249
|
|
|
247
250
|
Options
|
|
248
251
|
|
|
249
|
-
- `
|
|
252
|
+
- `fetcher: (variables: TVariables, context: QueryFunctionContext<QueryKey, TPageParam>) => TFnData | Promise<TFnData>`
|
|
250
253
|
- Required
|
|
251
|
-
-
|
|
254
|
+
- The function that the query will use to request data. And The second param is the `QueryFunctionContext` of `queryFn`.
|
|
255
|
+
- `variables?: TVariables`
|
|
256
|
+
- Optional
|
|
257
|
+
- `variables` will be the frist param of fetcher and the last element of the `queryKey` array
|
|
252
258
|
- `use: Middleware[]`
|
|
253
259
|
- Optional
|
|
254
260
|
- array of middleware functions [(details)](#middleware)
|
|
255
261
|
|
|
256
262
|
Expose Methods
|
|
257
263
|
|
|
258
|
-
- `
|
|
259
|
-
- `getKey: (variables: TVariables) =>
|
|
260
|
-
- `queryFn: QueryFunction<TFnData, [primaryKey, TVariables]>`
|
|
261
|
-
- `queryKeyHashFn: (queryKey: [primaryKey, TVariables]) => string`
|
|
264
|
+
- `fetcher: (variables: TVariables, context: QueryFunctionContext<QueryKey, TPageParam>) => TFnData | Promise<TFnData>`
|
|
265
|
+
- `getKey: (variables: TVariables) => QueryKey`
|
|
262
266
|
- `getOptions: (variables: TVariables) => UseInfiniteQueryOptions`
|
|
263
267
|
- `getFetchOptions: (variables: TVariables) => ({ queryKey, queryFn, queryKeyHashFn, getNextPageParam, getPreviousPageParam, initialPageParam })`
|
|
264
268
|
|
|
@@ -369,6 +373,7 @@ Options
|
|
|
369
373
|
Returns
|
|
370
374
|
|
|
371
375
|
- `getKey: () => MutationKey`
|
|
376
|
+
- `getOptions: () => UseMutationOptions`
|
|
372
377
|
- `mutationFn: MutationFunction<TData, TVariables>`
|
|
373
378
|
|
|
374
379
|
## Middleware
|
|
@@ -383,42 +388,31 @@ Middleware receive the hook and can execute logic before and after running it. I
|
|
|
383
388
|
import { QueryClient } from '@tanstack/react-query'
|
|
384
389
|
import { Middleware, MutationHook, QueryHook, getKey } from 'react-query-kit'
|
|
385
390
|
|
|
386
|
-
const
|
|
387
|
-
QueryHook<Response, Variables>
|
|
388
|
-
> = useQueryNext => {
|
|
391
|
+
const logger: Middleware<QueryHook<Response, Variables>> = useQueryNext => {
|
|
389
392
|
return options => {
|
|
390
|
-
const
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
393
|
+
const logger = useLogger()
|
|
394
|
+
const fetcher = (variables, context) => {
|
|
395
|
+
logger.log(context.queryKey, variables)
|
|
396
|
+
return options.fetcher(variables, context)
|
|
397
|
+
}
|
|
394
398
|
|
|
395
399
|
return useQueryNext({
|
|
396
400
|
...options,
|
|
397
|
-
|
|
398
|
-
enabled: options.enabled ?? !hasData(),
|
|
401
|
+
fetcher,
|
|
399
402
|
})
|
|
400
403
|
}
|
|
401
404
|
}
|
|
402
405
|
|
|
403
406
|
const useUser = createQuery<Response, Variables>({
|
|
404
407
|
// ...
|
|
405
|
-
use: [
|
|
406
|
-
myMiddleware,
|
|
407
|
-
// or just defined inside of `use`
|
|
408
|
-
function myMiddleware2(useQueryNext) {
|
|
409
|
-
return options => {
|
|
410
|
-
// ...
|
|
411
|
-
return useQueryNext(options)
|
|
412
|
-
}
|
|
413
|
-
},
|
|
414
|
-
],
|
|
408
|
+
use: [logger],
|
|
415
409
|
})
|
|
416
410
|
|
|
417
411
|
// global middlewares
|
|
418
412
|
const queryMiddleware: Middleware<QueryHook> = useQueryNext => {
|
|
419
413
|
return options => {
|
|
420
414
|
// u can also get queryKey via function getKey
|
|
421
|
-
const
|
|
415
|
+
const fullKey = getKey(options.queryKey, options.variables)
|
|
422
416
|
// ...
|
|
423
417
|
return useQueryNext(options)
|
|
424
418
|
}
|
|
@@ -526,6 +520,69 @@ inferError<typeof useProjects> // Error
|
|
|
526
520
|
inferOptions<typeof useProjects> // InfiniteQueryHookOptions<...>
|
|
527
521
|
```
|
|
528
522
|
|
|
523
|
+
## FAQ
|
|
524
|
+
|
|
525
|
+
### What is the difference between `getFetchOptions` and `getOptions`?
|
|
526
|
+
|
|
527
|
+
`getFetchOptions` will only return necessary options, while options like `staleTime` and `retry` will be ignored
|
|
528
|
+
|
|
529
|
+
```ts
|
|
530
|
+
const useTest1 = createQuery({
|
|
531
|
+
staleTime: Infinity,
|
|
532
|
+
})
|
|
533
|
+
|
|
534
|
+
// Only triggers on the first request
|
|
535
|
+
queryClient.prefetchQuery(useTest1.getOptions())
|
|
536
|
+
// Will always trigger a request
|
|
537
|
+
queryClient.prefetchQuery(useTest1.getFetchOptions())
|
|
538
|
+
|
|
539
|
+
const useTest2 = createQuery({
|
|
540
|
+
retry: 3,
|
|
541
|
+
})
|
|
542
|
+
|
|
543
|
+
// Automatically retries 3 times
|
|
544
|
+
queryClient.prefetchQuery(useTest2.getOptions())
|
|
545
|
+
// Does not automatically retry
|
|
546
|
+
queryClient.prefetchQuery(useTest2.getFetchOptions())
|
|
547
|
+
```
|
|
548
|
+
|
|
549
|
+
### What is the difference between `fetcher` and `queryFn`?
|
|
550
|
+
|
|
551
|
+
ReactQueryKit automatically converts fetcher to queryFn, as shown below:
|
|
552
|
+
|
|
553
|
+
```ts
|
|
554
|
+
const useTest = createQuery({
|
|
555
|
+
queryKey: ['test'],
|
|
556
|
+
fetcher: (variables, context) => {
|
|
557
|
+
// ...
|
|
558
|
+
},
|
|
559
|
+
})
|
|
560
|
+
|
|
561
|
+
// => useTest.getOptions(variables):
|
|
562
|
+
// {
|
|
563
|
+
// queryKey: ['test', variables],
|
|
564
|
+
// queryFn: (context) => fetcher(variables, context)
|
|
565
|
+
// }
|
|
566
|
+
```
|
|
567
|
+
|
|
568
|
+
## Migration
|
|
569
|
+
|
|
570
|
+
Upgrading from ReactQueryKit 2 → ReactQueryKit 3
|
|
571
|
+
|
|
572
|
+
```diff
|
|
573
|
+
createQuery({
|
|
574
|
+
- primaryKey: 'posts',
|
|
575
|
+
- queryFn: ({ queryKey: [_primaryKey, variables] }) => {},
|
|
576
|
+
+ queryKey: ['posts'],
|
|
577
|
+
+ fetcher: variables => {},
|
|
578
|
+
})
|
|
579
|
+
```
|
|
580
|
+
|
|
581
|
+
What you benefit from ReactQueryKit 3
|
|
582
|
+
|
|
583
|
+
- Support hierarchical key
|
|
584
|
+
- Support infer the types of fetcher, you can enjoy the preferred types automatically.
|
|
585
|
+
|
|
529
586
|
## Issues
|
|
530
587
|
|
|
531
588
|
_Looking to contribute? Look for the [Good First Issue][good-first-issue]
|
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
variables?: any;
|
|
4
|
-
};
|
|
5
|
-
export declare const createBaseQuery: (defaultOptions: any, useRQHook: (options: any, queryClient?: any) => any, overrideOptions?: QueryBaseHookOptions) => any;
|
|
6
|
-
export {};
|
|
1
|
+
import type { UseInfiniteQueryOptions } from '@tanstack/react-query';
|
|
2
|
+
export declare const createBaseQuery: (defaultOptions: any, useRQHook: (options: any, queryClient?: any) => any, overrideOptions?: Partial<UseInfiniteQueryOptions>) => any;
|
|
@@ -5,51 +5,58 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
if (defaultOptions.useDefaultOptions) {
|
|
7
7
|
console.error('[Bug] useDefaultOptions is not supported, please use middleware instead.');
|
|
8
|
+
} // @ts-ignore
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if (defaultOptions.queryFn) {
|
|
12
|
+
console.error('[Bug] queryFn is not supported, please use fetcher instead.');
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
queryKey,
|
|
18
|
+
fetcher,
|
|
14
19
|
queryKeyHashFn,
|
|
15
20
|
getPreviousPageParam,
|
|
16
21
|
getNextPageParam,
|
|
17
22
|
initialPageParam
|
|
18
23
|
} = defaultOptions;
|
|
19
24
|
|
|
20
|
-
const
|
|
25
|
+
const getQueryOptions = (fetcherFn, variables) => {
|
|
26
|
+
return {
|
|
27
|
+
queryFn: context => fetcherFn(variables, context),
|
|
28
|
+
queryKey: getKey(queryKey, variables)
|
|
29
|
+
};
|
|
30
|
+
};
|
|
21
31
|
|
|
22
|
-
const getKey$1 = variables => getKey(
|
|
32
|
+
const getKey$1 = variables => getKey(queryKey, variables);
|
|
23
33
|
|
|
24
34
|
const getOptions = variables => {
|
|
25
35
|
return { ...defaultOptions,
|
|
26
|
-
|
|
36
|
+
...getQueryOptions(fetcher, variables)
|
|
27
37
|
};
|
|
28
38
|
};
|
|
29
39
|
|
|
30
40
|
const getFetchOptions = variables => {
|
|
31
41
|
return {
|
|
32
|
-
queryKey: getKey$1(variables),
|
|
33
|
-
queryFn,
|
|
34
42
|
queryKeyHashFn,
|
|
35
43
|
getPreviousPageParam,
|
|
36
44
|
getNextPageParam,
|
|
37
|
-
initialPageParam
|
|
45
|
+
initialPageParam,
|
|
46
|
+
...getQueryOptions(fetcher, variables)
|
|
38
47
|
};
|
|
39
48
|
};
|
|
40
49
|
|
|
41
50
|
const useBaseHook = (options, queryClient) => {
|
|
42
51
|
return useRQHook({ ...options,
|
|
43
52
|
...overrideOptions,
|
|
44
|
-
|
|
53
|
+
...getQueryOptions(options.fetcher, options.variables)
|
|
45
54
|
}, queryClient);
|
|
46
55
|
};
|
|
47
56
|
|
|
48
57
|
return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {
|
|
49
|
-
|
|
58
|
+
fetcher,
|
|
50
59
|
getKey: getKey$1,
|
|
51
|
-
queryFn,
|
|
52
|
-
queryKeyHashFn,
|
|
53
60
|
getOptions,
|
|
54
61
|
getFetchOptions
|
|
55
62
|
});
|
|
@@ -1 +1 @@
|
|
|
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 { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as
|
|
1
|
+
{"version":3,"file":"createBaseQuery.esm.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n QueryFunctionContext,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getFullKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n fetcher?: any\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: Partial<UseInfiniteQueryOptions>\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n\n // @ts-ignore\n if (defaultOptions.queryFn) {\n console.error(\n '[Bug] queryFn is not supported, please use fetcher instead.'\n )\n }\n }\n\n const {\n queryKey,\n fetcher,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n const getQueryOptions = (fetcherFn: any, variables: any) => {\n return {\n queryFn: (context: QueryFunctionContext) => fetcherFn(variables, context),\n queryKey: getFullKey(queryKey, variables),\n }\n }\n\n const getKey = (variables?: any) => getFullKey(queryKey, variables)\n\n const getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n ...getQueryOptions(options.fetcher, options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n fetcher,\n getKey,\n getOptions,\n getFetchOptions,\n })\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","process","env","NODE_ENV","useDefaultOptions","console","error","queryFn","queryKey","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","variables","context","getFullKey","getKey","getOptions","getFetchOptions","useBaseHook","options","queryClient","Object","assign","withMiddleware"],"mappings":";;AAyBO,MAAMA,eAAe,GAAG,CAC7BC,cAD6B,EAE7BC,SAF6B,EAG7BC,eAH6B,KAIrB;AACR,EAAA,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIL,cAAc,CAACM,iBAAnB,EAAsC;MACpCC,OAAO,CAACC,KAAR,CACE,0EADF,CAAA,CAAA;AAGD,KANwC;;;IASzC,IAAIR,cAAc,CAACS,OAAnB,EAA4B;MAC1BF,OAAO,CAACC,KAAR,CACE,6DADF,CAAA,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAM;IACJE,QADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFf,cAPJ,CAAA;;AASA,EAAA,MAAMgB,eAAe,GAAG,CAACC,SAAD,EAAiBC,SAAjB,KAAoC;IAC1D,OAAO;MACLT,OAAO,EAAGU,OAAD,IAAmCF,SAAS,CAACC,SAAD,EAAYC,OAAZ,CADhD;AAELT,MAAAA,QAAQ,EAAEU,MAAU,CAACV,QAAD,EAAWQ,SAAX,CAAA;KAFtB,CAAA;GADF,CAAA;;EAOA,MAAMG,QAAM,GAAIH,SAAD,IAAqBE,MAAU,CAACV,QAAD,EAAWQ,SAAX,CAA9C,CAAA;;EAEA,MAAMI,UAAU,GAAIJ,SAAD,IAAoB;IACrC,OAAO,EACL,GAAGlB,cADE;AAEL,MAAA,GAAGgB,eAAe,CAACL,OAAD,EAAUO,SAAV,CAAA;KAFpB,CAAA;GADF,CAAA;;EAOA,MAAMK,eAAe,GAAIL,SAAD,IAAoB;IAC1C,OAAO;MACLN,cADK;MAELC,oBAFK;MAGLC,gBAHK;MAILC,gBAJK;AAKL,MAAA,GAAGC,eAAe,CAACL,OAAD,EAAUO,SAAV,CAAA;KALpB,CAAA;GADF,CAAA;;AAUA,EAAA,MAAMM,WAAW,GAAG,CAClBC,OADkB,EAElBC,WAFkB,KAGf;AACH,IAAA,OAAOzB,SAAS,CACd,EACE,GAAGwB,OADL;AAEE,MAAA,GAAGvB,eAFL;MAGE,GAAGc,eAAe,CAACS,OAAO,CAACd,OAAT,EAAkBc,OAAO,CAACP,SAA1B,CAAA;KAJN,EAMdQ,WANc,CAAhB,CAAA;GAJF,CAAA;;AAcA,EAAA,OAAOC,MAAM,CAACC,MAAP,CAAcC,cAAc,CAACL,WAAD,EAAcxB,cAAd,EAA8B,SAA9B,CAA5B,EAAsE;IAC3EW,OAD2E;YAE3EU,QAF2E;IAG3EC,UAH2E;AAI3EC,IAAAA,eAAAA;AAJ2E,GAAtE,CAAP,CAAA;AAMD;;;;"}
|
|
@@ -9,51 +9,58 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
9
9
|
// @ts-ignore
|
|
10
10
|
if (defaultOptions.useDefaultOptions) {
|
|
11
11
|
console.error('[Bug] useDefaultOptions is not supported, please use middleware instead.');
|
|
12
|
+
} // @ts-ignore
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
if (defaultOptions.queryFn) {
|
|
16
|
+
console.error('[Bug] queryFn is not supported, please use fetcher instead.');
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
const {
|
|
16
|
-
|
|
17
|
-
|
|
21
|
+
queryKey,
|
|
22
|
+
fetcher,
|
|
18
23
|
queryKeyHashFn,
|
|
19
24
|
getPreviousPageParam,
|
|
20
25
|
getNextPageParam,
|
|
21
26
|
initialPageParam
|
|
22
27
|
} = defaultOptions;
|
|
23
28
|
|
|
24
|
-
const
|
|
29
|
+
const getQueryOptions = (fetcherFn, variables) => {
|
|
30
|
+
return {
|
|
31
|
+
queryFn: context => fetcherFn(variables, context),
|
|
32
|
+
queryKey: utils.getKey(queryKey, variables)
|
|
33
|
+
};
|
|
34
|
+
};
|
|
25
35
|
|
|
26
|
-
const getKey = variables => utils.getKey(
|
|
36
|
+
const getKey = variables => utils.getKey(queryKey, variables);
|
|
27
37
|
|
|
28
38
|
const getOptions = variables => {
|
|
29
39
|
return { ...defaultOptions,
|
|
30
|
-
|
|
40
|
+
...getQueryOptions(fetcher, variables)
|
|
31
41
|
};
|
|
32
42
|
};
|
|
33
43
|
|
|
34
44
|
const getFetchOptions = variables => {
|
|
35
45
|
return {
|
|
36
|
-
queryKey: getKey(variables),
|
|
37
|
-
queryFn,
|
|
38
46
|
queryKeyHashFn,
|
|
39
47
|
getPreviousPageParam,
|
|
40
48
|
getNextPageParam,
|
|
41
|
-
initialPageParam
|
|
49
|
+
initialPageParam,
|
|
50
|
+
...getQueryOptions(fetcher, variables)
|
|
42
51
|
};
|
|
43
52
|
};
|
|
44
53
|
|
|
45
54
|
const useBaseHook = (options, queryClient) => {
|
|
46
55
|
return useRQHook({ ...options,
|
|
47
56
|
...overrideOptions,
|
|
48
|
-
|
|
57
|
+
...getQueryOptions(options.fetcher, options.variables)
|
|
49
58
|
}, queryClient);
|
|
50
59
|
};
|
|
51
60
|
|
|
52
61
|
return Object.assign(utils.withMiddleware(useBaseHook, defaultOptions, 'queries'), {
|
|
53
|
-
|
|
62
|
+
fetcher,
|
|
54
63
|
getKey,
|
|
55
|
-
queryFn,
|
|
56
|
-
queryKeyHashFn,
|
|
57
64
|
getOptions,
|
|
58
65
|
getFetchOptions
|
|
59
66
|
});
|
|
@@ -1 +1 @@
|
|
|
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 { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as
|
|
1
|
+
{"version":3,"file":"createBaseQuery.js","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n QueryFunctionContext,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getFullKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n fetcher?: any\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: Partial<UseInfiniteQueryOptions>\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n\n // @ts-ignore\n if (defaultOptions.queryFn) {\n console.error(\n '[Bug] queryFn is not supported, please use fetcher instead.'\n )\n }\n }\n\n const {\n queryKey,\n fetcher,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n const getQueryOptions = (fetcherFn: any, variables: any) => {\n return {\n queryFn: (context: QueryFunctionContext) => fetcherFn(variables, context),\n queryKey: getFullKey(queryKey, variables),\n }\n }\n\n const getKey = (variables?: any) => getFullKey(queryKey, variables)\n\n const getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n ...getQueryOptions(options.fetcher, options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n fetcher,\n getKey,\n getOptions,\n getFetchOptions,\n })\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","process","env","NODE_ENV","useDefaultOptions","console","error","queryFn","queryKey","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","variables","context","getFullKey","getKey","getOptions","getFetchOptions","useBaseHook","options","queryClient","Object","assign","withMiddleware"],"mappings":";;;;;;AAyBO,MAAMA,eAAe,GAAG,CAC7BC,cAD6B,EAE7BC,SAF6B,EAG7BC,eAH6B,KAIrB;AACR,EAAA,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIL,cAAc,CAACM,iBAAnB,EAAsC;MACpCC,OAAO,CAACC,KAAR,CACE,0EADF,CAAA,CAAA;AAGD,KANwC;;;IASzC,IAAIR,cAAc,CAACS,OAAnB,EAA4B;MAC1BF,OAAO,CAACC,KAAR,CACE,6DADF,CAAA,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAM;IACJE,QADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFf,cAPJ,CAAA;;AASA,EAAA,MAAMgB,eAAe,GAAG,CAACC,SAAD,EAAiBC,SAAjB,KAAoC;IAC1D,OAAO;MACLT,OAAO,EAAGU,OAAD,IAAmCF,SAAS,CAACC,SAAD,EAAYC,OAAZ,CADhD;AAELT,MAAAA,QAAQ,EAAEU,YAAU,CAACV,QAAD,EAAWQ,SAAX,CAAA;KAFtB,CAAA;GADF,CAAA;;EAOA,MAAMG,MAAM,GAAIH,SAAD,IAAqBE,YAAU,CAACV,QAAD,EAAWQ,SAAX,CAA9C,CAAA;;EAEA,MAAMI,UAAU,GAAIJ,SAAD,IAAoB;IACrC,OAAO,EACL,GAAGlB,cADE;AAEL,MAAA,GAAGgB,eAAe,CAACL,OAAD,EAAUO,SAAV,CAAA;KAFpB,CAAA;GADF,CAAA;;EAOA,MAAMK,eAAe,GAAIL,SAAD,IAAoB;IAC1C,OAAO;MACLN,cADK;MAELC,oBAFK;MAGLC,gBAHK;MAILC,gBAJK;AAKL,MAAA,GAAGC,eAAe,CAACL,OAAD,EAAUO,SAAV,CAAA;KALpB,CAAA;GADF,CAAA;;AAUA,EAAA,MAAMM,WAAW,GAAG,CAClBC,OADkB,EAElBC,WAFkB,KAGf;AACH,IAAA,OAAOzB,SAAS,CACd,EACE,GAAGwB,OADL;AAEE,MAAA,GAAGvB,eAFL;MAGE,GAAGc,eAAe,CAACS,OAAO,CAACd,OAAT,EAAkBc,OAAO,CAACP,SAA1B,CAAA;KAJN,EAMdQ,WANc,CAAhB,CAAA;GAJF,CAAA;;AAcA,EAAA,OAAOC,MAAM,CAACC,MAAP,CAAcC,oBAAc,CAACL,WAAD,EAAcxB,cAAd,EAA8B,SAA9B,CAA5B,EAAsE;IAC3EW,OAD2E;IAE3EU,MAF2E;IAG3EC,UAH2E;AAI3EC,IAAAA,eAAAA;AAJ2E,GAAtE,CAAP,CAAA;AAMD;;;;"}
|
|
@@ -5,51 +5,58 @@ const createBaseQuery = (defaultOptions, useRQHook, overrideOptions) => {
|
|
|
5
5
|
// @ts-ignore
|
|
6
6
|
if (defaultOptions.useDefaultOptions) {
|
|
7
7
|
console.error('[Bug] useDefaultOptions is not supported, please use middleware instead.');
|
|
8
|
+
} // @ts-ignore
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
if (defaultOptions.queryFn) {
|
|
12
|
+
console.error('[Bug] queryFn is not supported, please use fetcher instead.');
|
|
8
13
|
}
|
|
9
14
|
}
|
|
10
15
|
|
|
11
16
|
const {
|
|
12
|
-
|
|
13
|
-
|
|
17
|
+
queryKey,
|
|
18
|
+
fetcher,
|
|
14
19
|
queryKeyHashFn,
|
|
15
20
|
getPreviousPageParam,
|
|
16
21
|
getNextPageParam,
|
|
17
22
|
initialPageParam
|
|
18
23
|
} = defaultOptions;
|
|
19
24
|
|
|
20
|
-
const
|
|
25
|
+
const getQueryOptions = (fetcherFn, variables) => {
|
|
26
|
+
return {
|
|
27
|
+
queryFn: context => fetcherFn(variables, context),
|
|
28
|
+
queryKey: getKey(queryKey, variables)
|
|
29
|
+
};
|
|
30
|
+
};
|
|
21
31
|
|
|
22
|
-
const getKey$1 = variables => getKey(
|
|
32
|
+
const getKey$1 = variables => getKey(queryKey, variables);
|
|
23
33
|
|
|
24
34
|
const getOptions = variables => {
|
|
25
35
|
return { ...defaultOptions,
|
|
26
|
-
|
|
36
|
+
...getQueryOptions(fetcher, variables)
|
|
27
37
|
};
|
|
28
38
|
};
|
|
29
39
|
|
|
30
40
|
const getFetchOptions = variables => {
|
|
31
41
|
return {
|
|
32
|
-
queryKey: getKey$1(variables),
|
|
33
|
-
queryFn,
|
|
34
42
|
queryKeyHashFn,
|
|
35
43
|
getPreviousPageParam,
|
|
36
44
|
getNextPageParam,
|
|
37
|
-
initialPageParam
|
|
45
|
+
initialPageParam,
|
|
46
|
+
...getQueryOptions(fetcher, variables)
|
|
38
47
|
};
|
|
39
48
|
};
|
|
40
49
|
|
|
41
50
|
const useBaseHook = (options, queryClient) => {
|
|
42
51
|
return useRQHook({ ...options,
|
|
43
52
|
...overrideOptions,
|
|
44
|
-
|
|
53
|
+
...getQueryOptions(options.fetcher, options.variables)
|
|
45
54
|
}, queryClient);
|
|
46
55
|
};
|
|
47
56
|
|
|
48
57
|
return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {
|
|
49
|
-
|
|
58
|
+
fetcher,
|
|
50
59
|
getKey: getKey$1,
|
|
51
|
-
queryFn,
|
|
52
|
-
queryKeyHashFn,
|
|
53
60
|
getOptions,
|
|
54
61
|
getFetchOptions
|
|
55
62
|
});
|
|
@@ -1 +1 @@
|
|
|
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 { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as
|
|
1
|
+
{"version":3,"file":"createBaseQuery.mjs","sources":["../../src/createBaseQuery.ts"],"sourcesContent":["import type {\n QueryClient,\n QueryFunctionContext,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getFullKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n fetcher?: any\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: Partial<UseInfiniteQueryOptions>\n): any => {\n if (process.env.NODE_ENV !== 'production') {\n // @ts-ignore\n if (defaultOptions.useDefaultOptions) {\n console.error(\n '[Bug] useDefaultOptions is not supported, please use middleware instead.'\n )\n }\n\n // @ts-ignore\n if (defaultOptions.queryFn) {\n console.error(\n '[Bug] queryFn is not supported, please use fetcher instead.'\n )\n }\n }\n\n const {\n queryKey,\n fetcher,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n const getQueryOptions = (fetcherFn: any, variables: any) => {\n return {\n queryFn: (context: QueryFunctionContext) => fetcherFn(variables, context),\n queryKey: getFullKey(queryKey, variables),\n }\n }\n\n const getKey = (variables?: any) => getFullKey(queryKey, variables)\n\n const getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n ...getQueryOptions(fetcher, variables),\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n ...getQueryOptions(options.fetcher, options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n fetcher,\n getKey,\n getOptions,\n getFetchOptions,\n })\n}\n"],"names":["createBaseQuery","defaultOptions","useRQHook","overrideOptions","process","env","NODE_ENV","useDefaultOptions","console","error","queryFn","queryKey","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","variables","context","getFullKey","getKey","getOptions","getFetchOptions","useBaseHook","options","queryClient","Object","assign","withMiddleware"],"mappings":";;AAyBO,MAAMA,eAAe,GAAG,CAC7BC,cAD6B,EAE7BC,SAF6B,EAG7BC,eAH6B,KAIrB;AACR,EAAA,IAAIC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAAyB,YAA7B,EAA2C;AACzC;IACA,IAAIL,cAAc,CAACM,iBAAnB,EAAsC;MACpCC,OAAO,CAACC,KAAR,CACE,0EADF,CAAA,CAAA;AAGD,KANwC;;;IASzC,IAAIR,cAAc,CAACS,OAAnB,EAA4B;MAC1BF,OAAO,CAACC,KAAR,CACE,6DADF,CAAA,CAAA;AAGD,KAAA;AACF,GAAA;;EAED,MAAM;IACJE,QADI;IAEJC,OAFI;IAGJC,cAHI;IAIJC,oBAJI;IAKJC,gBALI;AAMJC,IAAAA,gBAAAA;AANI,GAAA,GAOFf,cAPJ,CAAA;;AASA,EAAA,MAAMgB,eAAe,GAAG,CAACC,SAAD,EAAiBC,SAAjB,KAAoC;IAC1D,OAAO;MACLT,OAAO,EAAGU,OAAD,IAAmCF,SAAS,CAACC,SAAD,EAAYC,OAAZ,CADhD;AAELT,MAAAA,QAAQ,EAAEU,MAAU,CAACV,QAAD,EAAWQ,SAAX,CAAA;KAFtB,CAAA;GADF,CAAA;;EAOA,MAAMG,QAAM,GAAIH,SAAD,IAAqBE,MAAU,CAACV,QAAD,EAAWQ,SAAX,CAA9C,CAAA;;EAEA,MAAMI,UAAU,GAAIJ,SAAD,IAAoB;IACrC,OAAO,EACL,GAAGlB,cADE;AAEL,MAAA,GAAGgB,eAAe,CAACL,OAAD,EAAUO,SAAV,CAAA;KAFpB,CAAA;GADF,CAAA;;EAOA,MAAMK,eAAe,GAAIL,SAAD,IAAoB;IAC1C,OAAO;MACLN,cADK;MAELC,oBAFK;MAGLC,gBAHK;MAILC,gBAJK;AAKL,MAAA,GAAGC,eAAe,CAACL,OAAD,EAAUO,SAAV,CAAA;KALpB,CAAA;GADF,CAAA;;AAUA,EAAA,MAAMM,WAAW,GAAG,CAClBC,OADkB,EAElBC,WAFkB,KAGf;AACH,IAAA,OAAOzB,SAAS,CACd,EACE,GAAGwB,OADL;AAEE,MAAA,GAAGvB,eAFL;MAGE,GAAGc,eAAe,CAACS,OAAO,CAACd,OAAT,EAAkBc,OAAO,CAACP,SAA1B,CAAA;KAJN,EAMdQ,WANc,CAAhB,CAAA;GAJF,CAAA;;AAcA,EAAA,OAAOC,MAAM,CAACC,MAAP,CAAcC,cAAc,CAACL,WAAD,EAAcxB,cAAd,EAA8B,SAA9B,CAA5B,EAAsE;IAC3EW,OAD2E;YAE3EU,QAF2E;IAG3EC,UAH2E;AAI3EC,IAAAA,eAAAA;AAJ2E,GAAtE,CAAP,CAAA;AAMD;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { CreateMutationOptions, MutationHook } from './types';
|
|
2
|
-
export declare const createMutation: <TData = unknown, TVariables = void, TError = Error, TContext = unknown>(defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>) => MutationHook<TData, TVariables, TError>;
|
|
2
|
+
export declare const createMutation: <TData = unknown, TVariables = void, TError = Error, TContext = unknown>(defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>) => MutationHook<TData, TVariables, TError, TContext>;
|
|
@@ -2,10 +2,9 @@ import * as ReactQuery from '@tanstack/react-query';
|
|
|
2
2
|
import { withMiddleware } from './utils.esm.js';
|
|
3
3
|
|
|
4
4
|
const createMutation = defaultOptions => {
|
|
5
|
-
const getKey = () => defaultOptions.mutationKey;
|
|
6
|
-
|
|
7
5
|
return Object.assign(withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'), {
|
|
8
|
-
getKey,
|
|
6
|
+
getKey: () => defaultOptions.mutationKey,
|
|
7
|
+
getOptions: () => defaultOptions,
|
|
9
8
|
mutationFn: defaultOptions.mutationFn
|
|
10
9
|
});
|
|
11
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMutation.esm.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import * as ReactQuery from '@tanstack/react-query'\n\nimport type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> => {\n
|
|
1
|
+
{"version":3,"file":"createMutation.esm.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import * as ReactQuery from '@tanstack/react-query'\n\nimport type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError, TContext> => {\n return Object.assign(\n withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'),\n {\n getKey: () => defaultOptions.mutationKey,\n getOptions: () => defaultOptions,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError, TContext>\n}\n"],"names":["createMutation","defaultOptions","Object","assign","withMiddleware","ReactQuery","useMutation","getKey","mutationKey","getOptions","mutationFn"],"mappings":";;;AASaA,MAAAA,cAAc,GAMzBC,cAN4B,IAO0B;AACtD,EAAA,OAAOC,MAAM,CAACC,MAAP,CACLC,cAAc,CAACC,UAAU,CAACC,WAAZ,EAAyBL,cAAzB,EAAyC,WAAzC,CADT,EAEL;AACEM,IAAAA,MAAM,EAAE,MAAMN,cAAc,CAACO,WAD/B;IAEEC,UAAU,EAAE,MAAMR,cAFpB;IAGES,UAAU,EAAET,cAAc,CAACS,UAAAA;AAH7B,GAFK,CAAP,CAAA;AAQD;;;;"}
|
|
@@ -26,10 +26,9 @@ function _interopNamespace(e) {
|
|
|
26
26
|
var ReactQuery__namespace = /*#__PURE__*/_interopNamespace(ReactQuery);
|
|
27
27
|
|
|
28
28
|
const createMutation = defaultOptions => {
|
|
29
|
-
const getKey = () => defaultOptions.mutationKey;
|
|
30
|
-
|
|
31
29
|
return Object.assign(utils.withMiddleware(ReactQuery__namespace.useMutation, defaultOptions, 'mutations'), {
|
|
32
|
-
getKey,
|
|
30
|
+
getKey: () => defaultOptions.mutationKey,
|
|
31
|
+
getOptions: () => defaultOptions,
|
|
33
32
|
mutationFn: defaultOptions.mutationFn
|
|
34
33
|
});
|
|
35
34
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createMutation.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import * as ReactQuery from '@tanstack/react-query'\n\nimport type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError> => {\n
|
|
1
|
+
{"version":3,"file":"createMutation.js","sources":["../../src/createMutation.ts"],"sourcesContent":["import * as ReactQuery from '@tanstack/react-query'\n\nimport type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { withMiddleware } from './utils'\n\nexport const createMutation = <\n TData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>\n): MutationHook<TData, TVariables, TError, TContext> => {\n return Object.assign(\n withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'),\n {\n getKey: () => defaultOptions.mutationKey,\n getOptions: () => defaultOptions,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError, TContext>\n}\n"],"names":["createMutation","defaultOptions","Object","assign","withMiddleware","ReactQuery","useMutation","getKey","mutationKey","getOptions","mutationFn"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AASaA,MAAAA,cAAc,GAMzBC,cAN4B,IAO0B;AACtD,EAAA,OAAOC,MAAM,CAACC,MAAP,CACLC,oBAAc,CAACC,qBAAU,CAACC,WAAZ,EAAyBL,cAAzB,EAAyC,WAAzC,CADT,EAEL;AACEM,IAAAA,MAAM,EAAE,MAAMN,cAAc,CAACO,WAD/B;IAEEC,UAAU,EAAE,MAAMR,cAFpB;IAGES,UAAU,EAAET,cAAc,CAACS,UAAAA;AAH7B,GAFK,CAAP,CAAA;AAQD;;;;"}
|
|
@@ -2,10 +2,9 @@ import * as ReactQuery from '@tanstack/react-query';
|
|
|
2
2
|
import { withMiddleware } from './utils.mjs';
|
|
3
3
|
|
|
4
4
|
const createMutation = defaultOptions => {
|
|
5
|
-
const getKey = () => defaultOptions.mutationKey;
|
|
6
|
-
|
|
7
5
|
return Object.assign(withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'), {
|
|
8
|
-
getKey,
|
|
6
|
+
getKey: () => defaultOptions.mutationKey,
|
|
7
|
+
getOptions: () => defaultOptions,
|
|
9
8
|
mutationFn: defaultOptions.mutationFn
|
|
10
9
|
});
|
|
11
10
|
};
|