react-query-kit 3.0.0-rc.2 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -39
- package/build/lib/types.d.ts +4 -6
- package/build/lib/utils.esm.js +3 -8
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +3 -8
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +3 -8
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +97 -97
- package/build/umd/index.development.js +3 -8
- 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/types.ts +6 -6
- package/src/utils.ts +3 -7
package/README.md
CHANGED
|
@@ -64,9 +64,9 @@ This module is distributed via [npm][npm] which is bundled with [node][node] and
|
|
|
64
64
|
should be installed as one of your project's `dependencies`:
|
|
65
65
|
|
|
66
66
|
```bash
|
|
67
|
-
$ npm i react-query-
|
|
67
|
+
$ npm i react-query-ki
|
|
68
68
|
# or
|
|
69
|
-
$ yarn add react-query-kit
|
|
69
|
+
$ yarn add react-query-kit
|
|
70
70
|
```
|
|
71
71
|
|
|
72
72
|
If you still on React Query Kit v2? Check out the v2 docs here: https://github.com/liaoliao666/react-query-kit/tree/v2#readme.
|
|
@@ -347,7 +347,7 @@ function App() {
|
|
|
347
347
|
mutation.mutate({ title: 'Do Laundry', content: 'content...' })
|
|
348
348
|
}}
|
|
349
349
|
>
|
|
350
|
-
|
|
350
|
+
create Todo
|
|
351
351
|
</button>
|
|
352
352
|
</>
|
|
353
353
|
)}
|
|
@@ -382,7 +382,7 @@ Returns
|
|
|
382
382
|
```tsx
|
|
383
383
|
import { router } from 'react-query-kit'
|
|
384
384
|
|
|
385
|
-
const
|
|
385
|
+
const post = router(`post`, {
|
|
386
386
|
byId: router.query({
|
|
387
387
|
fetcher: (variables: { id: number }) =>
|
|
388
388
|
fetch(`/posts/${variables.id}`).then(res => res.json()),
|
|
@@ -406,28 +406,29 @@ const posts = router(`posts`, {
|
|
|
406
406
|
})
|
|
407
407
|
|
|
408
408
|
// get root key
|
|
409
|
-
|
|
409
|
+
post.getKey() // ['post']
|
|
410
410
|
|
|
411
411
|
// hooks
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
412
|
+
post.byId.useQuery({ variables: { id: 1 } })
|
|
413
|
+
post.byId.useSuspenseQuery({ variables: { id: 1 } })
|
|
414
|
+
post.list.useInfiniteQuery()
|
|
415
|
+
post.list.useSuspenseInfiniteQuery()
|
|
416
|
+
post.add.useMutation()
|
|
417
417
|
|
|
418
418
|
// expose methods
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
419
|
+
post.byId.getKey({ id: 1 }) // ['post', 'byId', { id: 1 }]
|
|
420
|
+
post.byId.getFetchOptions({ id: 1 })
|
|
421
|
+
post.byId.getOptions({ id: 1 })
|
|
422
|
+
post.byId.fetcher({ id: 1 })
|
|
423
|
+
post.add.getKey() // ['post', 'add']
|
|
424
|
+
post.add.getOptions()
|
|
425
|
+
post.add.mutationFn({ title: 'title', content: 'content' })
|
|
426
426
|
|
|
427
427
|
// infer types
|
|
428
428
|
type Data = inferData<typeof posts.list>
|
|
429
429
|
type FnData = inferFnData<typeof posts.list>
|
|
430
430
|
type Variables = inferVariables<typeof posts.list>
|
|
431
|
+
type Error = inferError<typeof posts.list>
|
|
431
432
|
```
|
|
432
433
|
|
|
433
434
|
## API Reference
|
|
@@ -590,31 +591,11 @@ inferOptions<typeof useProjects> // InfiniteQueryHookOptions<...>
|
|
|
590
591
|
|
|
591
592
|
### What is the difference between `getFetchOptions` and `getOptions`?
|
|
592
593
|
|
|
593
|
-
`getFetchOptions`
|
|
594
|
-
|
|
595
|
-
```ts
|
|
596
|
-
const useTest1 = createQuery({
|
|
597
|
-
staleTime: Infinity,
|
|
598
|
-
})
|
|
599
|
-
|
|
600
|
-
// Only triggers on the first request
|
|
601
|
-
queryClient.prefetchQuery(useTest1.getOptions())
|
|
602
|
-
// Will always trigger a request
|
|
603
|
-
queryClient.prefetchQuery(useTest1.getFetchOptions())
|
|
604
|
-
|
|
605
|
-
const useTest2 = createQuery({
|
|
606
|
-
retry: 3,
|
|
607
|
-
})
|
|
608
|
-
|
|
609
|
-
// Automatically retries 3 times
|
|
610
|
-
queryClient.prefetchQuery(useTest2.getOptions())
|
|
611
|
-
// Does not automatically retry
|
|
612
|
-
queryClient.prefetchQuery(useTest2.getFetchOptions())
|
|
613
|
-
```
|
|
594
|
+
`getFetchOptions` would only return necessary options, while options like `staleTime` and `retry` would be omited
|
|
614
595
|
|
|
615
596
|
### What is the difference between `fetcher` and `queryFn`?
|
|
616
597
|
|
|
617
|
-
ReactQueryKit automatically converts fetcher to queryFn, as shown below:
|
|
598
|
+
ReactQueryKit would automatically converts fetcher to queryFn, as shown below:
|
|
618
599
|
|
|
619
600
|
```ts
|
|
620
601
|
const useTest = createQuery({
|
|
@@ -648,6 +629,7 @@ What you benefit from ReactQueryKit 3
|
|
|
648
629
|
|
|
649
630
|
- Support hierarchical key
|
|
650
631
|
- Support infer the types of fetcher, you can enjoy the preferred types automatically.
|
|
632
|
+
- Support to create a shape of your entire API
|
|
651
633
|
|
|
652
634
|
## Issues
|
|
653
635
|
|
package/build/lib/types.d.ts
CHANGED
|
@@ -123,9 +123,7 @@ export type inferData<T> = T extends {
|
|
|
123
123
|
export type inferFnData<T> = T extends {
|
|
124
124
|
fetcher: ExposeFetcher<infer TFnData, any, any>;
|
|
125
125
|
} ? TFnData : T extends ExposeMutationMethods<infer TFnData, any, any, any> ? TFnData : never;
|
|
126
|
-
export type inferError<T> = T extends
|
|
127
|
-
fetcher: ExposeFetcher<any, infer TError, any>;
|
|
128
|
-
} ? TError : T extends ExposeMutationMethods<any, any, infer TError, any> ? TError : never;
|
|
126
|
+
export type inferError<T> = T extends ExposeMethods<any, any, infer TError> ? TError : T extends ExposeMethods<any, any, infer TError, any> ? TError : T extends ExposeMutationMethods<any, any, infer TError, any> ? TError : never;
|
|
129
127
|
export type inferOptions<T> = T extends QueryHook<infer TFnData, infer TVariables, infer TError> ? QueryHookOptions<TFnData, TError, TFnData, TVariables> : T extends SuspenseQueryHook<infer TFnData, infer TVariables, infer TError> ? SuspenseQueryHookOptions<TFnData, TError, TFnData, TVariables> : T extends InfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? InfiniteQueryHookOptions<TFnData, TError, CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>, TVariables, TPageParam> : T extends SuspenseInfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? SuspenseInfiniteQueryHookOptions<TFnData, TError, CompatibleWithV4<InfiniteData<TFnData, TPageParam>, TFnData>, TVariables, TPageParam> : T extends MutationHook<infer TFnData, infer TVariables, infer TError> ? MutationHookOptions<TFnData, TError, TVariables, unknown> : never;
|
|
130
128
|
export type inferCreateOptions<T> = T extends QueryHook<infer TFnData, infer TVariables, infer TError> ? CreateQueryOptions<TFnData, TVariables, TError> : T extends SuspenseQueryHook<infer TFnData, infer TVariables, infer TError> ? CreateSuspenseQueryOptions<TFnData, TVariables, TError> : T extends InfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam> : T extends SuspenseInfiniteQueryHook<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? CreateSuspenseInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam> : T extends MutationHook<infer TFnData, infer TVariables, infer TError, infer TContext> ? CreateMutationOptions<TFnData, TError, TVariables, TContext> : never;
|
|
131
129
|
export type RouterQuery<TFnData, TVariables = void, TError = CompatibleError> = Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'> & {
|
|
@@ -143,9 +141,9 @@ export type CreateRouter<TConfig extends RouterConfig> = {
|
|
|
143
141
|
[K in keyof TConfig]: TConfig[K] extends RouterMutation<infer TFnData, infer TVariables, infer TError, infer TContext> ? {
|
|
144
142
|
useMutation: MutationHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TContext>;
|
|
145
143
|
} & ExposeMutationMethods<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TContext> : TConfig[K] extends RouterInfiniteQuery<infer TFnData, infer TVariables, infer TError, infer TPageParam> ? {
|
|
146
|
-
useInfiniteQuery: InfiniteQueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TPageParam
|
|
147
|
-
useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TPageParam
|
|
148
|
-
} & ExposeMethods<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, TPageParam
|
|
144
|
+
useInfiniteQuery: InfiniteQueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, DefaultTo<TPageParam, number>>;
|
|
145
|
+
useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, DefaultTo<TPageParam, number>>;
|
|
146
|
+
} & ExposeMethods<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>, DefaultTo<TPageParam, number>> : TConfig[K] extends Omit<RouterQuery<infer TFnData, infer TVariables, infer TError>, 'queryKey'> ? {
|
|
149
147
|
useQuery: QueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>>;
|
|
150
148
|
useSuspenseQuery: SuspenseQueryHook<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>>;
|
|
151
149
|
} & ExposeMethods<TFnData, DefaultTo<TVariables, void>, DefaultTo<TError, CompatibleError>> : never;
|
package/build/lib/utils.esm.js
CHANGED
|
@@ -9,20 +9,15 @@ const suspenseOptions = {
|
|
|
9
9
|
};
|
|
10
10
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
11
11
|
return function useMiddleware(options, queryClient) {
|
|
12
|
-
const [
|
|
12
|
+
const [uses, opts] = [ReactQuery.useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
13
13
|
isV5 ? queryClient : options).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
14
14
|
use: u2 = [],
|
|
15
15
|
...o2
|
|
16
16
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
17
17
|
...o2
|
|
18
18
|
}], [[]]);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (let i = middleware.length; i--;) {
|
|
22
|
-
next = middleware[i](next);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return next(opts, queryClient);
|
|
19
|
+
const composed = uses.reduceRight((next, use) => use(next), hook);
|
|
20
|
+
return composed(opts, queryClient);
|
|
26
21
|
};
|
|
27
22
|
};
|
|
28
23
|
const getKey = (queryKey, variables) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [
|
|
1
|
+
{"version":3,"file":"utils.esm.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composed = uses.reduceRight((next, use) => use(next), hook)\n\n return composed(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","composed","reduceRight","next","getKey","queryKey","variables"],"mappings":";;AAKO,MAAMA,UAAU,GAAGC,mBAAnB;MAEMC,IAAI,GAAG,CAAC,CAACF,UAAU,CAACG,iBAA1B;AAEA,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,IADoB;AAE7BC,EAAAA,QAAQ,EAAE,IAFmB;EAG7BC,gBAAgB,EAAE,CAACC,MAAD,EAAkBC,KAAlB,KAChBA,KAAK,CAACC,KAAN,CAAYC,IAAZ,KAAqBC,SAAAA;AAJM,EAAxB;AAOA,MAAMC,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;IACA,MAAM,CAACC,IAAD,EAAOC,IAAP,IAAoC,CACxCrB,UAAU,CAACsB,cAAX;IAEEpB,IAAI,GAAGiB,WAAH,GAAiBD,OAFvB,EAGEK,iBAHF,EAAA,CAGsBP,IAHtB,CADwC,EAKxCD,cALwC,EAMxCG,OANwC,CAAA,CAOxCM,MAPwC,CAQxC,CAAC,CAACC,EAAD,EAAKC,EAAL,CAAD,EAAW;MAAEC,GAAG,EAAEC,EAAE,GAAG,EAAZ;MAAgB,GAAGC,EAAAA;AAAnB,KAAA,GAA0B,EAArC,KAA4C,CAC1C,CAAC,GAAGJ,EAAJ,EAAQ,GAAGG,EAAX,CAD0C,EAE1C,EAAE,GAAGF,EAAL;MAAS,GAAGG,EAAAA;AAAZ,KAF0C,CARJ,EAYxC,CAAC,EAAD,CAZwC,CAA1C,CAAA;AAcA,IAAA,MAAMC,QAAQ,GAAGV,IAAI,CAACW,WAAL,CAAiB,CAACC,IAAD,EAAOL,GAAP,KAAeA,GAAG,CAACK,IAAD,CAAnC,EAA2ClB,IAA3C,CAAjB,CAAA;AAEA,IAAA,OAAOgB,QAAQ,CAACT,IAAD,EAAOF,WAAP,CAAf,CAAA;GApBF,CAAA;AAsBD,EA3BM;MA6BMc,MAAM,GAAG,CAACC,QAAD,EAAqBC,SAArB,KAAmD;AACvE,EAAA,OAAOA,SAAS,KAAKvB,SAAd,GAA0B,CAAC,GAAGsB,QAAJ,CAA1B,GAA0C,CAAC,GAAGA,QAAJ,EAAcC,SAAd,CAAjD,CAAA;AACD;;;;"}
|
package/build/lib/utils.js
CHANGED
|
@@ -33,20 +33,15 @@ const suspenseOptions = {
|
|
|
33
33
|
};
|
|
34
34
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
35
35
|
return function useMiddleware(options, queryClient) {
|
|
36
|
-
const [
|
|
36
|
+
const [uses, opts] = [ReactQuery.useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
37
37
|
isV5 ? queryClient : options).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
38
38
|
use: u2 = [],
|
|
39
39
|
...o2
|
|
40
40
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
41
41
|
...o2
|
|
42
42
|
}], [[]]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (let i = middleware.length; i--;) {
|
|
46
|
-
next = middleware[i](next);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return next(opts, queryClient);
|
|
43
|
+
const composed = uses.reduceRight((next, use) => use(next), hook);
|
|
44
|
+
return composed(opts, queryClient);
|
|
50
45
|
};
|
|
51
46
|
};
|
|
52
47
|
const getKey = (queryKey, variables) => {
|
package/build/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [
|
|
1
|
+
{"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composed = uses.reduceRight((next, use) => use(next), hook)\n\n return composed(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","composed","reduceRight","next","getKey","queryKey","variables"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAKO,MAAMA,UAAU,GAAGC,8BAAnB;MAEMC,IAAI,GAAG,CAAC,CAACF,UAAU,CAACG,iBAA1B;AAEA,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,IADoB;AAE7BC,EAAAA,QAAQ,EAAE,IAFmB;EAG7BC,gBAAgB,EAAE,CAACC,MAAD,EAAkBC,KAAlB,KAChBA,KAAK,CAACC,KAAN,CAAYC,IAAZ,KAAqBC,SAAAA;AAJM,EAAxB;AAOA,MAAMC,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;IACA,MAAM,CAACC,IAAD,EAAOC,IAAP,IAAoC,CACxCrB,UAAU,CAACsB,cAAX;IAEEpB,IAAI,GAAGiB,WAAH,GAAiBD,OAFvB,EAGEK,iBAHF,EAAA,CAGsBP,IAHtB,CADwC,EAKxCD,cALwC,EAMxCG,OANwC,CAAA,CAOxCM,MAPwC,CAQxC,CAAC,CAACC,EAAD,EAAKC,EAAL,CAAD,EAAW;MAAEC,GAAG,EAAEC,EAAE,GAAG,EAAZ;MAAgB,GAAGC,EAAAA;AAAnB,KAAA,GAA0B,EAArC,KAA4C,CAC1C,CAAC,GAAGJ,EAAJ,EAAQ,GAAGG,EAAX,CAD0C,EAE1C,EAAE,GAAGF,EAAL;MAAS,GAAGG,EAAAA;AAAZ,KAF0C,CARJ,EAYxC,CAAC,EAAD,CAZwC,CAA1C,CAAA;AAcA,IAAA,MAAMC,QAAQ,GAAGV,IAAI,CAACW,WAAL,CAAiB,CAACC,IAAD,EAAOL,GAAP,KAAeA,GAAG,CAACK,IAAD,CAAnC,EAA2ClB,IAA3C,CAAjB,CAAA;AAEA,IAAA,OAAOgB,QAAQ,CAACT,IAAD,EAAOF,WAAP,CAAf,CAAA;GApBF,CAAA;AAsBD,EA3BM;MA6BMc,MAAM,GAAG,CAACC,QAAD,EAAqBC,SAArB,KAAmD;AACvE,EAAA,OAAOA,SAAS,KAAKvB,SAAd,GAA0B,CAAC,GAAGsB,QAAJ,CAA1B,GAA0C,CAAC,GAAGA,QAAJ,EAAcC,SAAd,CAAjD,CAAA;AACD;;;;;;;;"}
|
package/build/lib/utils.mjs
CHANGED
|
@@ -9,20 +9,15 @@ const suspenseOptions = {
|
|
|
9
9
|
};
|
|
10
10
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
11
11
|
return function useMiddleware(options, queryClient) {
|
|
12
|
-
const [
|
|
12
|
+
const [uses, opts] = [ReactQuery.useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
13
13
|
isV5 ? queryClient : options).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
14
14
|
use: u2 = [],
|
|
15
15
|
...o2
|
|
16
16
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
17
17
|
...o2
|
|
18
18
|
}], [[]]);
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
for (let i = middleware.length; i--;) {
|
|
22
|
-
next = middleware[i](next);
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
return next(opts, queryClient);
|
|
19
|
+
const composed = uses.reduceRight((next, use) => use(next), hook);
|
|
20
|
+
return composed(opts, queryClient);
|
|
26
21
|
};
|
|
27
22
|
};
|
|
28
23
|
const getKey = (queryKey, variables) => {
|
package/build/lib/utils.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [
|
|
1
|
+
{"version":3,"file":"utils.mjs","sources":["../../src/utils.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composed = uses.reduceRight((next, use) => use(next), hook)\n\n return composed(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","composed","reduceRight","next","getKey","queryKey","variables"],"mappings":";;AAKO,MAAMA,UAAU,GAAGC,mBAAnB;MAEMC,IAAI,GAAG,CAAC,CAACF,UAAU,CAACG,iBAA1B;AAEA,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,OAAO,EAAE,IADoB;AAE7BC,EAAAA,QAAQ,EAAE,IAFmB;EAG7BC,gBAAgB,EAAE,CAACC,MAAD,EAAkBC,KAAlB,KAChBA,KAAK,CAACC,KAAN,CAAYC,IAAZ,KAAqBC,SAAAA;AAJM,EAAxB;AAOA,MAAMC,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;AACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;IACA,MAAM,CAACC,IAAD,EAAOC,IAAP,IAAoC,CACxCrB,UAAU,CAACsB,cAAX;IAEEpB,IAAI,GAAGiB,WAAH,GAAiBD,OAFvB,EAGEK,iBAHF,EAAA,CAGsBP,IAHtB,CADwC,EAKxCD,cALwC,EAMxCG,OANwC,CAAA,CAOxCM,MAPwC,CAQxC,CAAC,CAACC,EAAD,EAAKC,EAAL,CAAD,EAAW;MAAEC,GAAG,EAAEC,EAAE,GAAG,EAAZ;MAAgB,GAAGC,EAAAA;AAAnB,KAAA,GAA0B,EAArC,KAA4C,CAC1C,CAAC,GAAGJ,EAAJ,EAAQ,GAAGG,EAAX,CAD0C,EAE1C,EAAE,GAAGF,EAAL;MAAS,GAAGG,EAAAA;AAAZ,KAF0C,CARJ,EAYxC,CAAC,EAAD,CAZwC,CAA1C,CAAA;AAcA,IAAA,MAAMC,QAAQ,GAAGV,IAAI,CAACW,WAAL,CAAiB,CAACC,IAAD,EAAOL,GAAP,KAAeA,GAAG,CAACK,IAAD,CAAnC,EAA2ClB,IAA3C,CAAjB,CAAA;AAEA,IAAA,OAAOgB,QAAQ,CAACT,IAAD,EAAOF,WAAP,CAAf,CAAA;GApBF,CAAA;AAsBD,EA3BM;MA6BMc,MAAM,GAAG,CAACC,QAAD,EAAqBC,SAArB,KAAmD;AACvE,EAAA,OAAOA,SAAS,KAAKvB,SAAd,GAA0B,CAAC,GAAGsB,QAAJ,CAA1B,GAA0C,CAAC,GAAGA,QAAJ,EAAcC,SAAd,CAAjD,CAAA;AACD;;;;"}
|
package/build/stats-html.html
CHANGED
|
@@ -4014,7 +4014,7 @@ var drawChart = (function (exports) {
|
|
|
4014
4014
|
</script>
|
|
4015
4015
|
<script>
|
|
4016
4016
|
/*<!--*/
|
|
4017
|
-
const data = {"version":2,"tree":{"name":"root","children":[{"name":"zip.esm.js","children":[{"name":"src","children":[{"uid":"
|
|
4017
|
+
const data = {"version":2,"tree":{"name":"root","children":[{"name":"zip.esm.js","children":[{"name":"src","children":[{"uid":"68f7-1","name":"utils.ts"},{"uid":"68f7-3","name":"createBaseQuery.ts"},{"uid":"68f7-5","name":"createQuery.ts"},{"uid":"68f7-7","name":"createSuspenseQuery.ts"},{"uid":"68f7-9","name":"createInfiniteQuery.ts"},{"uid":"68f7-11","name":"createSuspenseInfiniteQuery.ts"},{"uid":"68f7-13","name":"createMutation.ts"},{"uid":"68f7-15","name":"router.ts"},{"uid":"68f7-17","name":"index.ts"}]}]}],"isRoot":true},"nodeParts":{"68f7-1":{"renderedLength":873,"gzipLength":438,"brotliLength":0,"mainUid":"68f7-0"},"68f7-3":{"renderedLength":1162,"gzipLength":397,"brotliLength":0,"mainUid":"68f7-2"},"68f7-5":{"renderedLength":91,"gzipLength":87,"brotliLength":0,"mainUid":"68f7-4"},"68f7-7":{"renderedLength":179,"gzipLength":118,"brotliLength":0,"mainUid":"68f7-6"},"68f7-9":{"renderedLength":107,"gzipLength":97,"brotliLength":0,"mainUid":"68f7-8"},"68f7-11":{"renderedLength":203,"gzipLength":128,"brotliLength":0,"mainUid":"68f7-10"},"68f7-13":{"renderedLength":271,"gzipLength":168,"brotliLength":0,"mainUid":"68f7-12"},"68f7-15":{"renderedLength":949,"gzipLength":337,"brotliLength":0,"mainUid":"68f7-14"},"68f7-17":{"renderedLength":0,"gzipLength":0,"brotliLength":0,"mainUid":"68f7-16"}},"nodeMetas":{"68f7-0":{"id":"/src/utils.ts","moduleParts":{"zip.esm.js":"68f7-1"},"imported":[{"uid":"68f7-19"}],"importedBy":[{"uid":"68f7-16"},{"uid":"68f7-4"},{"uid":"68f7-6"},{"uid":"68f7-8"},{"uid":"68f7-10"},{"uid":"68f7-12"},{"uid":"68f7-2"}]},"68f7-2":{"id":"/src/createBaseQuery.ts","moduleParts":{"zip.esm.js":"68f7-3"},"imported":[{"uid":"68f7-0"}],"importedBy":[{"uid":"68f7-4"},{"uid":"68f7-6"},{"uid":"68f7-8"},{"uid":"68f7-10"}]},"68f7-4":{"id":"/src/createQuery.ts","moduleParts":{"zip.esm.js":"68f7-5"},"imported":[{"uid":"68f7-2"},{"uid":"68f7-0"}],"importedBy":[{"uid":"68f7-16"},{"uid":"68f7-14"}]},"68f7-6":{"id":"/src/createSuspenseQuery.ts","moduleParts":{"zip.esm.js":"68f7-7"},"imported":[{"uid":"68f7-2"},{"uid":"68f7-0"}],"importedBy":[{"uid":"68f7-16"},{"uid":"68f7-14"}]},"68f7-8":{"id":"/src/createInfiniteQuery.ts","moduleParts":{"zip.esm.js":"68f7-9"},"imported":[{"uid":"68f7-2"},{"uid":"68f7-0"}],"importedBy":[{"uid":"68f7-16"},{"uid":"68f7-14"}]},"68f7-10":{"id":"/src/createSuspenseInfiniteQuery.ts","moduleParts":{"zip.esm.js":"68f7-11"},"imported":[{"uid":"68f7-2"},{"uid":"68f7-0"}],"importedBy":[{"uid":"68f7-16"},{"uid":"68f7-14"}]},"68f7-12":{"id":"/src/createMutation.ts","moduleParts":{"zip.esm.js":"68f7-13"},"imported":[{"uid":"68f7-0"}],"importedBy":[{"uid":"68f7-16"},{"uid":"68f7-14"}]},"68f7-14":{"id":"/src/router.ts","moduleParts":{"zip.esm.js":"68f7-15"},"imported":[{"uid":"68f7-8"},{"uid":"68f7-12"},{"uid":"68f7-4"},{"uid":"68f7-10"},{"uid":"68f7-6"}],"importedBy":[{"uid":"68f7-16"}]},"68f7-16":{"id":"/src/index.ts","moduleParts":{"zip.esm.js":"68f7-17"},"imported":[{"uid":"68f7-4"},{"uid":"68f7-6"},{"uid":"68f7-8"},{"uid":"68f7-10"},{"uid":"68f7-12"},{"uid":"68f7-18"},{"uid":"68f7-14"},{"uid":"68f7-0"}],"importedBy":[],"isEntry":true},"68f7-18":{"id":"/src/types.ts","moduleParts":{},"imported":[],"importedBy":[{"uid":"68f7-16"}]},"68f7-19":{"id":"@tanstack/react-query","moduleParts":{},"imported":[],"importedBy":[{"uid":"68f7-0"}],"isExternal":true}},"env":{"rollup":"2.77.2"},"options":{"gzip":true,"brotli":false,"sourcemap":false}};
|
|
4018
4018
|
|
|
4019
4019
|
const run = () => {
|
|
4020
4020
|
const width = window.innerWidth;
|
package/build/stats.json
CHANGED
|
@@ -10,39 +10,39 @@
|
|
|
10
10
|
"name": "src",
|
|
11
11
|
"children": [
|
|
12
12
|
{
|
|
13
|
-
"uid": "
|
|
13
|
+
"uid": "68f7-21",
|
|
14
14
|
"name": "utils.ts"
|
|
15
15
|
},
|
|
16
16
|
{
|
|
17
|
-
"uid": "
|
|
17
|
+
"uid": "68f7-23",
|
|
18
18
|
"name": "createBaseQuery.ts"
|
|
19
19
|
},
|
|
20
20
|
{
|
|
21
|
-
"uid": "
|
|
21
|
+
"uid": "68f7-25",
|
|
22
22
|
"name": "createQuery.ts"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
|
-
"uid": "
|
|
25
|
+
"uid": "68f7-27",
|
|
26
26
|
"name": "createSuspenseQuery.ts"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
|
-
"uid": "
|
|
29
|
+
"uid": "68f7-29",
|
|
30
30
|
"name": "createInfiniteQuery.ts"
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
|
-
"uid": "
|
|
33
|
+
"uid": "68f7-31",
|
|
34
34
|
"name": "createSuspenseInfiniteQuery.ts"
|
|
35
35
|
},
|
|
36
36
|
{
|
|
37
|
-
"uid": "
|
|
37
|
+
"uid": "68f7-33",
|
|
38
38
|
"name": "createMutation.ts"
|
|
39
39
|
},
|
|
40
40
|
{
|
|
41
|
-
"uid": "
|
|
41
|
+
"uid": "68f7-35",
|
|
42
42
|
"name": "router.ts"
|
|
43
43
|
},
|
|
44
44
|
{
|
|
45
|
-
"uid": "
|
|
45
|
+
"uid": "68f7-37",
|
|
46
46
|
"name": "index.ts"
|
|
47
47
|
}
|
|
48
48
|
]
|
|
@@ -53,307 +53,307 @@
|
|
|
53
53
|
"isRoot": true
|
|
54
54
|
},
|
|
55
55
|
"nodeParts": {
|
|
56
|
-
"
|
|
57
|
-
"renderedLength":
|
|
58
|
-
"gzipLength":
|
|
56
|
+
"68f7-21": {
|
|
57
|
+
"renderedLength": 873,
|
|
58
|
+
"gzipLength": 438,
|
|
59
59
|
"brotliLength": 0,
|
|
60
|
-
"mainUid": "
|
|
60
|
+
"mainUid": "68f7-20"
|
|
61
61
|
},
|
|
62
|
-
"
|
|
62
|
+
"68f7-23": {
|
|
63
63
|
"renderedLength": 1162,
|
|
64
64
|
"gzipLength": 397,
|
|
65
65
|
"brotliLength": 0,
|
|
66
|
-
"mainUid": "
|
|
66
|
+
"mainUid": "68f7-22"
|
|
67
67
|
},
|
|
68
|
-
"
|
|
68
|
+
"68f7-25": {
|
|
69
69
|
"renderedLength": 91,
|
|
70
70
|
"gzipLength": 87,
|
|
71
71
|
"brotliLength": 0,
|
|
72
|
-
"mainUid": "
|
|
72
|
+
"mainUid": "68f7-24"
|
|
73
73
|
},
|
|
74
|
-
"
|
|
74
|
+
"68f7-27": {
|
|
75
75
|
"renderedLength": 179,
|
|
76
76
|
"gzipLength": 118,
|
|
77
77
|
"brotliLength": 0,
|
|
78
|
-
"mainUid": "
|
|
78
|
+
"mainUid": "68f7-26"
|
|
79
79
|
},
|
|
80
|
-
"
|
|
80
|
+
"68f7-29": {
|
|
81
81
|
"renderedLength": 107,
|
|
82
82
|
"gzipLength": 97,
|
|
83
83
|
"brotliLength": 0,
|
|
84
|
-
"mainUid": "
|
|
84
|
+
"mainUid": "68f7-28"
|
|
85
85
|
},
|
|
86
|
-
"
|
|
86
|
+
"68f7-31": {
|
|
87
87
|
"renderedLength": 203,
|
|
88
88
|
"gzipLength": 128,
|
|
89
89
|
"brotliLength": 0,
|
|
90
|
-
"mainUid": "
|
|
90
|
+
"mainUid": "68f7-30"
|
|
91
91
|
},
|
|
92
|
-
"
|
|
92
|
+
"68f7-33": {
|
|
93
93
|
"renderedLength": 271,
|
|
94
94
|
"gzipLength": 168,
|
|
95
95
|
"brotliLength": 0,
|
|
96
|
-
"mainUid": "
|
|
96
|
+
"mainUid": "68f7-32"
|
|
97
97
|
},
|
|
98
|
-
"
|
|
98
|
+
"68f7-35": {
|
|
99
99
|
"renderedLength": 949,
|
|
100
100
|
"gzipLength": 337,
|
|
101
101
|
"brotliLength": 0,
|
|
102
|
-
"mainUid": "
|
|
102
|
+
"mainUid": "68f7-34"
|
|
103
103
|
},
|
|
104
|
-
"
|
|
104
|
+
"68f7-37": {
|
|
105
105
|
"renderedLength": 0,
|
|
106
106
|
"gzipLength": 0,
|
|
107
107
|
"brotliLength": 0,
|
|
108
|
-
"mainUid": "
|
|
108
|
+
"mainUid": "68f7-36"
|
|
109
109
|
}
|
|
110
110
|
},
|
|
111
111
|
"nodeMetas": {
|
|
112
|
-
"
|
|
112
|
+
"68f7-20": {
|
|
113
113
|
"id": "/src/utils.ts",
|
|
114
114
|
"moduleParts": {
|
|
115
|
-
"zip.esm.js": "
|
|
115
|
+
"zip.esm.js": "68f7-21"
|
|
116
116
|
},
|
|
117
117
|
"imported": [
|
|
118
118
|
{
|
|
119
|
-
"uid": "
|
|
119
|
+
"uid": "68f7-39"
|
|
120
120
|
}
|
|
121
121
|
],
|
|
122
122
|
"importedBy": [
|
|
123
123
|
{
|
|
124
|
-
"uid": "
|
|
124
|
+
"uid": "68f7-36"
|
|
125
125
|
},
|
|
126
126
|
{
|
|
127
|
-
"uid": "
|
|
127
|
+
"uid": "68f7-24"
|
|
128
128
|
},
|
|
129
129
|
{
|
|
130
|
-
"uid": "
|
|
130
|
+
"uid": "68f7-26"
|
|
131
131
|
},
|
|
132
132
|
{
|
|
133
|
-
"uid": "
|
|
133
|
+
"uid": "68f7-28"
|
|
134
134
|
},
|
|
135
135
|
{
|
|
136
|
-
"uid": "
|
|
136
|
+
"uid": "68f7-30"
|
|
137
137
|
},
|
|
138
138
|
{
|
|
139
|
-
"uid": "
|
|
139
|
+
"uid": "68f7-32"
|
|
140
140
|
},
|
|
141
141
|
{
|
|
142
|
-
"uid": "
|
|
142
|
+
"uid": "68f7-22"
|
|
143
143
|
}
|
|
144
144
|
]
|
|
145
145
|
},
|
|
146
|
-
"
|
|
146
|
+
"68f7-22": {
|
|
147
147
|
"id": "/src/createBaseQuery.ts",
|
|
148
148
|
"moduleParts": {
|
|
149
|
-
"zip.esm.js": "
|
|
149
|
+
"zip.esm.js": "68f7-23"
|
|
150
150
|
},
|
|
151
151
|
"imported": [
|
|
152
152
|
{
|
|
153
|
-
"uid": "
|
|
153
|
+
"uid": "68f7-20"
|
|
154
154
|
}
|
|
155
155
|
],
|
|
156
156
|
"importedBy": [
|
|
157
157
|
{
|
|
158
|
-
"uid": "
|
|
158
|
+
"uid": "68f7-24"
|
|
159
159
|
},
|
|
160
160
|
{
|
|
161
|
-
"uid": "
|
|
161
|
+
"uid": "68f7-26"
|
|
162
162
|
},
|
|
163
163
|
{
|
|
164
|
-
"uid": "
|
|
164
|
+
"uid": "68f7-28"
|
|
165
165
|
},
|
|
166
166
|
{
|
|
167
|
-
"uid": "
|
|
167
|
+
"uid": "68f7-30"
|
|
168
168
|
}
|
|
169
169
|
]
|
|
170
170
|
},
|
|
171
|
-
"
|
|
171
|
+
"68f7-24": {
|
|
172
172
|
"id": "/src/createQuery.ts",
|
|
173
173
|
"moduleParts": {
|
|
174
|
-
"zip.esm.js": "
|
|
174
|
+
"zip.esm.js": "68f7-25"
|
|
175
175
|
},
|
|
176
176
|
"imported": [
|
|
177
177
|
{
|
|
178
|
-
"uid": "
|
|
178
|
+
"uid": "68f7-22"
|
|
179
179
|
},
|
|
180
180
|
{
|
|
181
|
-
"uid": "
|
|
181
|
+
"uid": "68f7-20"
|
|
182
182
|
}
|
|
183
183
|
],
|
|
184
184
|
"importedBy": [
|
|
185
185
|
{
|
|
186
|
-
"uid": "
|
|
186
|
+
"uid": "68f7-36"
|
|
187
187
|
},
|
|
188
188
|
{
|
|
189
|
-
"uid": "
|
|
189
|
+
"uid": "68f7-34"
|
|
190
190
|
}
|
|
191
191
|
]
|
|
192
192
|
},
|
|
193
|
-
"
|
|
193
|
+
"68f7-26": {
|
|
194
194
|
"id": "/src/createSuspenseQuery.ts",
|
|
195
195
|
"moduleParts": {
|
|
196
|
-
"zip.esm.js": "
|
|
196
|
+
"zip.esm.js": "68f7-27"
|
|
197
197
|
},
|
|
198
198
|
"imported": [
|
|
199
199
|
{
|
|
200
|
-
"uid": "
|
|
200
|
+
"uid": "68f7-22"
|
|
201
201
|
},
|
|
202
202
|
{
|
|
203
|
-
"uid": "
|
|
203
|
+
"uid": "68f7-20"
|
|
204
204
|
}
|
|
205
205
|
],
|
|
206
206
|
"importedBy": [
|
|
207
207
|
{
|
|
208
|
-
"uid": "
|
|
208
|
+
"uid": "68f7-36"
|
|
209
209
|
},
|
|
210
210
|
{
|
|
211
|
-
"uid": "
|
|
211
|
+
"uid": "68f7-34"
|
|
212
212
|
}
|
|
213
213
|
]
|
|
214
214
|
},
|
|
215
|
-
"
|
|
215
|
+
"68f7-28": {
|
|
216
216
|
"id": "/src/createInfiniteQuery.ts",
|
|
217
217
|
"moduleParts": {
|
|
218
|
-
"zip.esm.js": "
|
|
218
|
+
"zip.esm.js": "68f7-29"
|
|
219
219
|
},
|
|
220
220
|
"imported": [
|
|
221
221
|
{
|
|
222
|
-
"uid": "
|
|
222
|
+
"uid": "68f7-22"
|
|
223
223
|
},
|
|
224
224
|
{
|
|
225
|
-
"uid": "
|
|
225
|
+
"uid": "68f7-20"
|
|
226
226
|
}
|
|
227
227
|
],
|
|
228
228
|
"importedBy": [
|
|
229
229
|
{
|
|
230
|
-
"uid": "
|
|
230
|
+
"uid": "68f7-36"
|
|
231
231
|
},
|
|
232
232
|
{
|
|
233
|
-
"uid": "
|
|
233
|
+
"uid": "68f7-34"
|
|
234
234
|
}
|
|
235
235
|
]
|
|
236
236
|
},
|
|
237
|
-
"
|
|
237
|
+
"68f7-30": {
|
|
238
238
|
"id": "/src/createSuspenseInfiniteQuery.ts",
|
|
239
239
|
"moduleParts": {
|
|
240
|
-
"zip.esm.js": "
|
|
240
|
+
"zip.esm.js": "68f7-31"
|
|
241
241
|
},
|
|
242
242
|
"imported": [
|
|
243
243
|
{
|
|
244
|
-
"uid": "
|
|
244
|
+
"uid": "68f7-22"
|
|
245
245
|
},
|
|
246
246
|
{
|
|
247
|
-
"uid": "
|
|
247
|
+
"uid": "68f7-20"
|
|
248
248
|
}
|
|
249
249
|
],
|
|
250
250
|
"importedBy": [
|
|
251
251
|
{
|
|
252
|
-
"uid": "
|
|
252
|
+
"uid": "68f7-36"
|
|
253
253
|
},
|
|
254
254
|
{
|
|
255
|
-
"uid": "
|
|
255
|
+
"uid": "68f7-34"
|
|
256
256
|
}
|
|
257
257
|
]
|
|
258
258
|
},
|
|
259
|
-
"
|
|
259
|
+
"68f7-32": {
|
|
260
260
|
"id": "/src/createMutation.ts",
|
|
261
261
|
"moduleParts": {
|
|
262
|
-
"zip.esm.js": "
|
|
262
|
+
"zip.esm.js": "68f7-33"
|
|
263
263
|
},
|
|
264
264
|
"imported": [
|
|
265
265
|
{
|
|
266
|
-
"uid": "
|
|
266
|
+
"uid": "68f7-20"
|
|
267
267
|
}
|
|
268
268
|
],
|
|
269
269
|
"importedBy": [
|
|
270
270
|
{
|
|
271
|
-
"uid": "
|
|
271
|
+
"uid": "68f7-36"
|
|
272
272
|
},
|
|
273
273
|
{
|
|
274
|
-
"uid": "
|
|
274
|
+
"uid": "68f7-34"
|
|
275
275
|
}
|
|
276
276
|
]
|
|
277
277
|
},
|
|
278
|
-
"
|
|
278
|
+
"68f7-34": {
|
|
279
279
|
"id": "/src/router.ts",
|
|
280
280
|
"moduleParts": {
|
|
281
|
-
"zip.esm.js": "
|
|
281
|
+
"zip.esm.js": "68f7-35"
|
|
282
282
|
},
|
|
283
283
|
"imported": [
|
|
284
284
|
{
|
|
285
|
-
"uid": "
|
|
285
|
+
"uid": "68f7-28"
|
|
286
286
|
},
|
|
287
287
|
{
|
|
288
|
-
"uid": "
|
|
288
|
+
"uid": "68f7-32"
|
|
289
289
|
},
|
|
290
290
|
{
|
|
291
|
-
"uid": "
|
|
291
|
+
"uid": "68f7-24"
|
|
292
292
|
},
|
|
293
293
|
{
|
|
294
|
-
"uid": "
|
|
294
|
+
"uid": "68f7-30"
|
|
295
295
|
},
|
|
296
296
|
{
|
|
297
|
-
"uid": "
|
|
297
|
+
"uid": "68f7-26"
|
|
298
298
|
}
|
|
299
299
|
],
|
|
300
300
|
"importedBy": [
|
|
301
301
|
{
|
|
302
|
-
"uid": "
|
|
302
|
+
"uid": "68f7-36"
|
|
303
303
|
}
|
|
304
304
|
]
|
|
305
305
|
},
|
|
306
|
-
"
|
|
306
|
+
"68f7-36": {
|
|
307
307
|
"id": "/src/index.ts",
|
|
308
308
|
"moduleParts": {
|
|
309
|
-
"zip.esm.js": "
|
|
309
|
+
"zip.esm.js": "68f7-37"
|
|
310
310
|
},
|
|
311
311
|
"imported": [
|
|
312
312
|
{
|
|
313
|
-
"uid": "
|
|
313
|
+
"uid": "68f7-24"
|
|
314
314
|
},
|
|
315
315
|
{
|
|
316
|
-
"uid": "
|
|
316
|
+
"uid": "68f7-26"
|
|
317
317
|
},
|
|
318
318
|
{
|
|
319
|
-
"uid": "
|
|
319
|
+
"uid": "68f7-28"
|
|
320
320
|
},
|
|
321
321
|
{
|
|
322
|
-
"uid": "
|
|
322
|
+
"uid": "68f7-30"
|
|
323
323
|
},
|
|
324
324
|
{
|
|
325
|
-
"uid": "
|
|
325
|
+
"uid": "68f7-32"
|
|
326
326
|
},
|
|
327
327
|
{
|
|
328
|
-
"uid": "
|
|
328
|
+
"uid": "68f7-38"
|
|
329
329
|
},
|
|
330
330
|
{
|
|
331
|
-
"uid": "
|
|
331
|
+
"uid": "68f7-34"
|
|
332
332
|
},
|
|
333
333
|
{
|
|
334
|
-
"uid": "
|
|
334
|
+
"uid": "68f7-20"
|
|
335
335
|
}
|
|
336
336
|
],
|
|
337
337
|
"importedBy": [],
|
|
338
338
|
"isEntry": true
|
|
339
339
|
},
|
|
340
|
-
"
|
|
340
|
+
"68f7-38": {
|
|
341
341
|
"id": "/src/types.ts",
|
|
342
342
|
"moduleParts": {},
|
|
343
343
|
"imported": [],
|
|
344
344
|
"importedBy": [
|
|
345
345
|
{
|
|
346
|
-
"uid": "
|
|
346
|
+
"uid": "68f7-36"
|
|
347
347
|
}
|
|
348
348
|
]
|
|
349
349
|
},
|
|
350
|
-
"
|
|
350
|
+
"68f7-39": {
|
|
351
351
|
"id": "@tanstack/react-query",
|
|
352
352
|
"moduleParts": {},
|
|
353
353
|
"imported": [],
|
|
354
354
|
"importedBy": [
|
|
355
355
|
{
|
|
356
|
-
"uid": "
|
|
356
|
+
"uid": "68f7-20"
|
|
357
357
|
}
|
|
358
358
|
],
|
|
359
359
|
"isExternal": true
|
|
@@ -33,20 +33,15 @@
|
|
|
33
33
|
};
|
|
34
34
|
const withMiddleware = (hook, defaultOptions, type) => {
|
|
35
35
|
return function useMiddleware(options, queryClient) {
|
|
36
|
-
const [
|
|
36
|
+
const [uses, opts] = [ReactQuery.useQueryClient( // @ts-ignore Compatible with ReactQuery v4
|
|
37
37
|
isV5 ? queryClient : options).getDefaultOptions()[type], defaultOptions, options].reduce(([u1, o1], {
|
|
38
38
|
use: u2 = [],
|
|
39
39
|
...o2
|
|
40
40
|
} = {}) => [[...u1, ...u2], { ...o1,
|
|
41
41
|
...o2
|
|
42
42
|
}], [[]]);
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
for (let i = middleware.length; i--;) {
|
|
46
|
-
next = middleware[i](next);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return next(opts, queryClient);
|
|
43
|
+
const composed = uses.reduceRight((next, use) => use(next), hook);
|
|
44
|
+
return composed(opts, queryClient);
|
|
50
45
|
};
|
|
51
46
|
};
|
|
52
47
|
const getKey = (queryKey, variables) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.development.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.ts","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts","../../src/router.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n","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","import { createBaseQuery } from './createBaseQuery'\nimport type { CompatibleError, CreateQueryOptions, QueryHook } from './types'\nimport { ReactQuery } from './utils'\n\nexport const createQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, ReactQuery.useQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseQuery)\n : createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n InfiniteQueryHook,\n} from './types'\nimport { ReactQuery } from './utils'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, ReactQuery.useInfiniteQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)\n : createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)\n}\n","import type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { ReactQuery, 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","import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [scope, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n\n return acc\n },\n {\n getKey: () => [scope],\n } as any\n )\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","middleware","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","getKey","queryKey","variables","createBaseQuery","useRQHook","overrideOptions","useDefaultOptions","console","error","queryFn","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","context","getFullKey","getOptions","getFetchOptions","useBaseHook","Object","assign","createQuery","useQuery","createSuspenseQuery","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","useSuspenseInfiniteQuery","createMutation","useMutation","mutationKey","mutationFn","router","scope","config","entries","acc","key","_type","infiniteQuery","mutation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAKO,MAAMA,UAAU,GAAGC,6BAAnB,CAAA;EAEA,MAAMC,IAAI,GAAG,CAAC,CAACF,UAAU,CAACG,gBAA1B,CAAA;EAEA,MAAMC,eAAe,GAAG;EAC7BC,EAAAA,OAAO,EAAE,IADoB;EAE7BC,EAAAA,QAAQ,EAAE,IAFmB;IAG7BC,gBAAgB,EAAE,CAACC,MAAD,EAAkBC,KAAlB,KAChBA,KAAK,CAACC,KAAN,CAAYC,IAAZ,KAAqBC,SAAAA;EAJM,CAAxB,CAAA;EAOA,MAAMC,cAAc,GAAG,CAC5BC,IAD4B,EAE5BC,cAF4B,EAG5BC,IAH4B,KAIzB;EACH,EAAA,OAAO,SAASC,aAAT,CACLC,OADK,EAELC,WAFK,EAGL;MACA,MAAM,CAACC,UAAD,EAAaC,IAAb,IAAqB,CACzBrB,UAAU,CAACsB,cAAX;MAEEpB,IAAI,GAAGiB,WAAH,GAAiBD,OAFvB,EAGEK,iBAHF,EAAA,CAGsBP,IAHtB,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IAU0C;IAC1D,OAAO,EAAE,GAAGA,OAAL;EAAcwD,IAAAA,KAAK,EAAE,GAAA;KAA5B,CAAA;EACD,CAZD;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"index.development.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.ts","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts","../../src/router.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composed = uses.reduceRight((next, use) => use(next), hook)\n\n return composed(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n","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","import { createBaseQuery } from './createBaseQuery'\nimport type { CompatibleError, CreateQueryOptions, QueryHook } from './types'\nimport { ReactQuery } from './utils'\n\nexport const createQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, ReactQuery.useQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseQuery)\n : createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n InfiniteQueryHook,\n} from './types'\nimport { ReactQuery } from './utils'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, ReactQuery.useInfiniteQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)\n : createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)\n}\n","import type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { ReactQuery, 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","import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [scope, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n\n return acc\n },\n {\n getKey: () => [scope],\n } as any\n )\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["ReactQuery","TanstackReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","state","data","undefined","withMiddleware","hook","defaultOptions","type","useMiddleware","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","composed","reduceRight","next","getKey","queryKey","variables","createBaseQuery","useRQHook","overrideOptions","useDefaultOptions","console","error","queryFn","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","context","getFullKey","getOptions","getFetchOptions","useBaseHook","Object","assign","createQuery","useQuery","createSuspenseQuery","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","useSuspenseInfiniteQuery","createMutation","useMutation","mutationKey","mutationFn","router","scope","config","entries","acc","key","_type","infiniteQuery","mutation"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;EAKO,MAAMA,UAAU,GAAGC,6BAAnB,CAAA;EAEA,MAAMC,IAAI,GAAG,CAAC,CAACF,UAAU,CAACG,gBAA1B,CAAA;EAEA,MAAMC,eAAe,GAAG;EAC7BC,EAAAA,OAAO,EAAE,IADoB;EAE7BC,EAAAA,QAAQ,EAAE,IAFmB;IAG7BC,gBAAgB,EAAE,CAACC,MAAD,EAAkBC,KAAlB,KAChBA,KAAK,CAACC,K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IAEgC;IAC7C,OAAO,EACL,GAAGA,OADE;EAELwD,IAAAA,KAAK,EAAE,GAAA;KAFT,CAAA;EAID,CAPD,CAAA;;EASAN,MAAM,CAACO,aAAP,GAMEzD,OANqB,IAU4C;IACjE,OAAO,EAAE,GAAGA,OAAL;EAAcwD,IAAAA,KAAK,EAAE,KAAA;KAA5B,CAAA;EACD,CAZD,CAAA;;EAcAN,MAAM,CAACQ,QAAP,GAME1D,OANgB,IAU0C;IAC1D,OAAO,EAAE,GAAGA,OAAL;EAAcwD,IAAAA,KAAK,EAAE,GAAA;KAA5B,CAAA;EACD,CAZD;;;;;;;;;;;;;;;;"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryKit={},e.ReactQuery)}(this,(function(e,t){"use strict";function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(u){if("default"!==u){var
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@tanstack/react-query")):"function"==typeof define&&define.amd?define(["exports","@tanstack/react-query"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).ReactQueryKit={},e.ReactQuery)}(this,(function(e,t){"use strict";function u(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(u){if("default"!==u){var r=Object.getOwnPropertyDescriptor(e,u);Object.defineProperty(t,u,r.get?r:{enumerable:!0,get:function(){return e[u]}})}})),t.default=e,Object.freeze(t)}const r=u(t),n=!!r.useSuspenseQuery,i={enabled:!0,suspense:!0,useErrorBoundary:(e,t)=>void 0===t.state.data},s=(e,t,u)=>function(i,s){const[a,y]=[r.useQueryClient(n?s:i).getDefaultOptions()[u],t,i].reduce((([e,t],{use:u=[],...r}={})=>[[...e,...u],{...t,...r}]),[[]]);return a.reduceRight(((e,t)=>t(e)),e)(y,s)},a=(e,t)=>void 0===t?[...e]:[...e,t],y=(e,t,u)=>{const{queryKey:r,fetcher:n,queryKeyHashFn:i,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:c}=e,f=(e,t)=>({queryFn:u=>e(t,u),queryKey:a(r,t)});return Object.assign(s(((e,r)=>t({...e,...u,...f(e.fetcher,e.variables)},r)),e,"queries"),{fetcher:n,getKey:e=>a(r,e),getOptions:t=>({...e,...f(n,t)}),getFetchOptions:e=>({queryKeyHashFn:i,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:c,...f(n,e)})})},o=e=>y(e,r.useQuery),c=e=>n?y(e,r.useSuspenseQuery):y(e,r.useQuery,i),f=e=>y(e,r.useInfiniteQuery),p=e=>n?y(e,r.useSuspenseInfiniteQuery):y(e,r.useInfiniteQuery,i),g=e=>Object.assign(s(r.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,getOptions:()=>e,mutationFn:e.mutationFn}),d=(e,t)=>Object.entries(t).reduce(((t,[u,r])=>{const n={...r,["m"===r._type?"mutationKey":"queryKey"]:[e,u]};return t[u]="m"===r._type?{useMutation:g(n),...g(n)}:"q"===r._type?{useQuery:o(n),useSuspenseQuery:c(n),...o(n)}:{useInfiniteQuery:f(n),useSuspenseInfiniteQuery:p(n),...f(n)},t}),{getKey:()=>[e]});d.query=e=>({...e,_type:"q"}),d.infiniteQuery=e=>({...e,_type:"inf"}),d.mutation=e=>({...e,_type:"m"}),e.createInfiniteQuery=f,e.createMutation=g,e.createQuery=o,e.createSuspenseInfiniteQuery=p,e.createSuspenseQuery=c,e.getKey=a,e.router=d,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
2
2
|
//# sourceMappingURL=index.production.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.ts","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts","../../src/router.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [middleware, opts] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n\n let next = hook\n for (let i = middleware.length; i--; ) {\n next = middleware[i](next)\n }\n\n return next(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n","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","import { createBaseQuery } from './createBaseQuery'\nimport type { CompatibleError, CreateQueryOptions, QueryHook } from './types'\nimport { ReactQuery } from './utils'\n\nexport const createQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, ReactQuery.useQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseQuery)\n : createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n InfiniteQueryHook,\n} from './types'\nimport { ReactQuery } from './utils'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, ReactQuery.useInfiniteQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)\n : createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)\n}\n","import type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { ReactQuery, 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","import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [scope, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n\n return acc\n },\n {\n getKey: () => [scope],\n } as any\n )\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["ReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","undefined","state","data","withMiddleware","hook","defaultOptions","type","options","queryClient","middleware","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","getKey","queryKey","variables","createBaseQuery","useRQHook","overrideOptions","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","queryFn","context","getFullKey","Object","assign","getOptions","getFetchOptions","createQuery","useQuery","createSuspenseQuery","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","useSuspenseInfiniteQuery","createMutation","useMutation","mutationKey","mutationFn","router","scope","config","entries","acc","key","_type","infiniteQuery","mutation"],"mappings":"4lBAKO,MAAMA,OAEAC,IAASD,EAAWE,iBAEpBC,EAAkB,CAC7BC,SAAS,EACTC,UAAU,EACVC,iBAAkB,CAACC,EAAiBC,SACbC,IAArBD,EAAME,MAAMC,MAGHC,EAAiB,CAC5BC,EACAC,EACAC,IAEO,SACLC,EACAC,GAEA,MAAOC,EAAYC,GAAQ,CACzBnB,EAAWoB,eAETnB,EAAOgB,EAAcD,GACrBK,oBAAoBN,GACtBD,EACAE,GACAM,QACA,EAAEC,EAAIC,IAAOC,IAAKC,EAAK,MAAOC,GAAO,CAAA,IAAO,CAC1C,IAAIJ,KAAOG,GACX,IAAKF,KAAOG,KAEd,CAAC,KAGH,IAAIC,EAAOf,EACX,IAAK,IAAIgB,EAAIX,EAAWY,OAAQD,KAC9BD,EAAOV,EAAWW,GAAGD,GAGvB,OAAOA,EAAKT,EAAMF,IAITc,EAAS,CAACC,EAAoBC,SACpBxB,IAAdwB,EAA0B,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D,CAACL,EAAOI,IAqB7D,OAlBAD,EAAIC,GAEE,MADJhD,EAAKiD,MACD,CACET,YAAaD,EAAe1C,MACzB0C,EAAe1C,IAGpB,MADAG,EAAKiD,MACL,CACEhB,SAAUD,EAAYnC,GACtBd,iBAAkBmD,EAAoBrC,MACnCmC,EAAYnC,IAEjB,CACEuC,iBAAkBD,EAAoBtC,GACtCyC,yBAA0BD,EAA4BxC,MACnDsC,EAAoBtC,IAGxBkD,CAAP,GAEF,CACEnC,OAAQ,IAAM,CAACgC,KAKrBD,EAAOtD,MACLQ,IAEO,IACFA,EACHoD,MAAO,MAIXN,EAAOO,cAMLrD,IAKO,IAAKA,EAASoD,MAAO,QAG9BN,EAAOQ,SAMLtD,IAKO,IAAKA,EAASoD,MAAO"}
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createQuery.ts","../../src/createSuspenseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createSuspenseInfiniteQuery.ts","../../src/createMutation.ts","../../src/router.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient, QueryKey } from '@tanstack/react-query'\n\nimport type { Middleware } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\n\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const withMiddleware = (\n hook: any,\n defaultOptions: any,\n type: 'queries' | 'mutations'\n) => {\n return function useMiddleware(\n options?: { client?: QueryClient; use?: Middleware[] },\n queryClient?: QueryClient\n ) {\n const [uses, opts]: [Middleware[], any] = [\n ReactQuery.useQueryClient(\n // @ts-ignore Compatible with ReactQuery v4\n isV5 ? queryClient : options\n ).getDefaultOptions()[type],\n defaultOptions,\n options,\n ].reduce(\n ([u1, o1], { use: u2 = [], ...o2 } = {}) => [\n [...u1, ...u2],\n { ...o1, ...o2 },\n ],\n [[]]\n )\n const composed = uses.reduceRight((next, use) => use(next), hook)\n\n return composed(opts, queryClient)\n }\n}\n\nexport const getKey = (queryKey: QueryKey, variables?: any): QueryKey => {\n return variables === undefined ? [...queryKey] : [...queryKey, variables]\n}\n","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","import { createBaseQuery } from './createBaseQuery'\nimport type { CompatibleError, CreateQueryOptions, QueryHook } from './types'\nimport { ReactQuery } from './utils'\n\nexport const createQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateQueryOptions<TFnData, TVariables, TError>\n): QueryHook<TFnData, TVariables, TError> => {\n return createBaseQuery(options, ReactQuery.useQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseQueryOptions,\n SuspenseQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError\n>(\n options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>\n): SuspenseQueryHook<TFnData, TVariables, TError> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseQuery)\n : createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n InfiniteQueryHook,\n} from './types'\nimport { ReactQuery } from './utils'\n\nexport const createInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>\n): InfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return createBaseQuery(options, ReactQuery.useInfiniteQuery)\n}\n","import { createBaseQuery } from './createBaseQuery'\nimport type {\n CompatibleError,\n CreateSuspenseInfiniteQueryOptions,\n SuspenseInfiniteQueryHook,\n} from './types'\nimport { ReactQuery, isV5, suspenseOptions } from './utils'\n\nexport const createSuspenseInfiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: CreateSuspenseInfiniteQueryOptions<\n TFnData,\n TVariables,\n TError,\n TPageParam\n >\n): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {\n return isV5\n ? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)\n : createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)\n}\n","import type {\n CompatibleError,\n CreateMutationOptions,\n MutationHook,\n} from './types'\nimport { ReactQuery, 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","import { createInfiniteQuery } from './createInfiniteQuery'\nimport { createMutation } from './createMutation'\nimport { createQuery } from './createQuery'\nimport { createSuspenseInfiniteQuery } from './createSuspenseInfiniteQuery'\nimport { createSuspenseQuery } from './createSuspenseQuery'\nimport type {\n CompatibleError,\n CreateInfiniteQueryOptions,\n CreateMutationOptions,\n CreateQueryOptions,\n CreateRouter,\n RouterConfig,\n RouterInfiniteQuery,\n RouterMutation,\n RouterQuery,\n} from './types'\n\nexport const router = <TConfig extends RouterConfig>(\n scope: string,\n config: TConfig\n): CreateRouter<TConfig> => {\n return Object.entries(config).reduce(\n (acc, [key, opts]) => {\n const options: any = {\n ...opts,\n [opts._type === `m` ? `mutationKey` : `queryKey`]: [scope, key],\n }\n\n acc[key] =\n opts._type === `m`\n ? {\n useMutation: createMutation(options),\n ...createMutation(options),\n }\n : opts._type === `q`\n ? {\n useQuery: createQuery(options),\n useSuspenseQuery: createSuspenseQuery(options),\n ...createQuery(options),\n }\n : {\n useInfiniteQuery: createInfiniteQuery(options),\n useSuspenseInfiniteQuery: createSuspenseInfiniteQuery(options),\n ...createInfiniteQuery(options),\n }\n\n return acc\n },\n {\n getKey: () => [scope],\n } as any\n )\n}\n\nrouter.query = <TFnData, TVariables = void, TError = CompatibleError>(\n options: Omit<CreateQueryOptions<TFnData, TVariables, TError>, 'queryKey'>\n): RouterQuery<TFnData, TVariables, TError> => {\n return {\n ...options,\n _type: 'q',\n }\n}\n\nrouter.infiniteQuery = <\n TFnData,\n TVariables = void,\n TError = CompatibleError,\n TPageParam = number\n>(\n options: Omit<\n CreateInfiniteQueryOptions<TFnData, TVariables, TError, TPageParam>,\n 'queryKey'\n >\n): RouterInfiniteQuery<TFnData, TVariables, TError, TPageParam> => {\n return { ...options, _type: 'inf' }\n}\n\nrouter.mutation = <\n TFnData = unknown,\n TVariables = void,\n TError = CompatibleError,\n TContext = unknown\n>(\n options: Omit<\n CreateMutationOptions<TFnData, TVariables, TError, TContext>,\n 'mutationKey'\n >\n): RouterMutation<TFnData, TVariables, TError, TContext> => {\n return { ...options, _type: 'm' }\n}\n"],"names":["ReactQuery","isV5","useSuspenseQuery","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","undefined","state","data","withMiddleware","hook","defaultOptions","type","options","queryClient","uses","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","reduceRight","next","composed","getKey","queryKey","variables","createBaseQuery","useRQHook","overrideOptions","fetcher","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryOptions","fetcherFn","queryFn","context","getFullKey","Object","assign","getOptions","getFetchOptions","createQuery","useQuery","createSuspenseQuery","createInfiniteQuery","useInfiniteQuery","createSuspenseInfiniteQuery","useSuspenseInfiniteQuery","createMutation","useMutation","mutationKey","mutationFn","router","scope","config","entries","acc","key","_type","infiniteQuery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XrC,GAEOf,EACHiC,EAAgBlB,EAAShB,EAAWE,kBACpCgC,EAAgBlB,EAAShB,EAAWoD,SAAUjD,GCTvCmD,EAMXtC,GAEOkB,EAAgBlB,EAAShB,EAAWuD,kBCRhCC,EAMXxC,GAOOf,EACHiC,EAAgBlB,EAAShB,EAAWyD,0BACpCvB,EAAgBlB,EAAShB,EAAWuD,iBAAkBpD,GChB/CuD,EAMX5C,GAEOiC,OAAOC,OACZpC,EAAeZ,EAAW2D,YAAa7C,EAAgB,aACvD,CACEiB,OAAQ,IAAMjB,EAAe8C,YAC7BX,WAAY,IAAMnC,EAClB+C,WAAY/C,EAAe+C,aCHpBC,EAAS,CACpBC,EACAC,IAEOjB,OAAOkB,QAAQD,GAAQ1C,QAC5B,CAAC4C,GAAMC,EAAKhD,MACV,MAAMH,EAAe,IAChBG,EACH,CAAC,MAAAA,EAAKiD,MAAL,cAAA,YAAkD,CAACL,EAAOI,IAqB7D,OAlBAD,EAAIC,GAEE,MADJhD,EAAKiD,MACD,CACET,YAAaD,EAAe1C,MACzB0C,EAAe1C,IAGpB,MADAG,EAAKiD,MACL,CACEhB,SAAUD,EAAYnC,GACtBd,iBAAkBmD,EAAoBrC,MACnCmC,EAAYnC,IAEjB,CACEuC,iBAAkBD,EAAoBtC,GACtCyC,yBAA0BD,EAA4BxC,MACnDsC,EAAoBtC,IAGxBkD,CAAP,GAEF,CACEnC,OAAQ,IAAM,CAACgC,KAKrBD,EAAOtD,MACLQ,IAEO,IACFA,EACHoD,MAAO,MAIXN,EAAOO,cAMLrD,IAKO,IAAKA,EAASoD,MAAO,QAG9BN,EAAOQ,SAMLtD,IAKO,IAAKA,EAASoD,MAAO"}
|
package/build/zip/zip.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"@tanstack/react-query";const t=e,u=!!t.useSuspenseQuery,n={enabled:!0,suspense:!0,useErrorBoundary:(e,t)=>void 0===t.state.data},r=(e,n,r)=>function(s,
|
|
1
|
+
import*as e from"@tanstack/react-query";const t=e,u=!!t.useSuspenseQuery,n={enabled:!0,suspense:!0,useErrorBoundary:(e,t)=>void 0===t.state.data},r=(e,n,r)=>function(s,i){const[a,y]=[t.useQueryClient(u?i:s).getDefaultOptions()[r],n,s].reduce((([e,t],{use:u=[],...n}={})=>[[...e,...u],{...t,...n}]),[[]]);return a.reduceRight(((e,t)=>t(e)),e)(y,i)},s=(e,t)=>void 0===t?[...e]:[...e,t],i=(e,t,u)=>{const{queryKey:n,fetcher:i,queryKeyHashFn:a,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g}=e,p=(e,t)=>({queryFn:u=>e(t,u),queryKey:s(n,t)});return Object.assign(r(((e,n)=>t({...e,...u,...p(e.fetcher,e.variables)},n)),e,"queries"),{fetcher:i,getKey:e=>s(n,e),getOptions:t=>({...e,...p(i,t)}),getFetchOptions:e=>({queryKeyHashFn:a,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g,...p(i,e)})})},a=e=>i(e,t.useQuery),y=e=>u?i(e,t.useSuspenseQuery):i(e,t.useQuery,n),o=e=>i(e,t.useInfiniteQuery),g=e=>u?i(e,t.useSuspenseInfiniteQuery):i(e,t.useInfiniteQuery,n),p=e=>Object.assign(r(t.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,getOptions:()=>e,mutationFn:e.mutationFn}),c=(e,t)=>Object.entries(t).reduce(((t,[u,n])=>{const r={...n,["m"===n._type?"mutationKey":"queryKey"]:[e,u]};return t[u]="m"===n._type?{useMutation:p(r),...p(r)}:"q"===n._type?{useQuery:a(r),useSuspenseQuery:y(r),...a(r)}:{useInfiniteQuery:o(r),useSuspenseInfiniteQuery:g(r),...o(r)},t}),{getKey:()=>[e]});c.query=e=>({...e,_type:"q"}),c.infiniteQuery=e=>({...e,_type:"inf"}),c.mutation=e=>({...e,_type:"m"});export{o as createInfiniteQuery,p as createMutation,a as createQuery,g as createSuspenseInfiniteQuery,y as createSuspenseQuery,s as getKey,c as router};
|
package/package.json
CHANGED
package/src/types.ts
CHANGED
|
@@ -517,9 +517,9 @@ export type inferFnData<T> = T extends {
|
|
|
517
517
|
? TFnData
|
|
518
518
|
: never
|
|
519
519
|
|
|
520
|
-
export type inferError<T> = T extends
|
|
521
|
-
|
|
522
|
-
|
|
520
|
+
export type inferError<T> = T extends ExposeMethods<any, any, infer TError>
|
|
521
|
+
? TError
|
|
522
|
+
: T extends ExposeMethods<any, any, infer TError, any>
|
|
523
523
|
? TError
|
|
524
524
|
: T extends ExposeMutationMethods<any, any, infer TError, any>
|
|
525
525
|
? TError
|
|
@@ -668,19 +668,19 @@ export type CreateRouter<TConfig extends RouterConfig> = {
|
|
|
668
668
|
TFnData,
|
|
669
669
|
DefaultTo<TVariables, void>,
|
|
670
670
|
DefaultTo<TError, CompatibleError>,
|
|
671
|
-
TPageParam
|
|
671
|
+
DefaultTo<TPageParam, number>
|
|
672
672
|
>
|
|
673
673
|
useSuspenseInfiniteQuery: SuspenseInfiniteQueryHook<
|
|
674
674
|
TFnData,
|
|
675
675
|
DefaultTo<TVariables, void>,
|
|
676
676
|
DefaultTo<TError, CompatibleError>,
|
|
677
|
-
TPageParam
|
|
677
|
+
DefaultTo<TPageParam, number>
|
|
678
678
|
>
|
|
679
679
|
} & ExposeMethods<
|
|
680
680
|
TFnData,
|
|
681
681
|
DefaultTo<TVariables, void>,
|
|
682
682
|
DefaultTo<TError, CompatibleError>,
|
|
683
|
-
TPageParam
|
|
683
|
+
DefaultTo<TPageParam, number>
|
|
684
684
|
>
|
|
685
685
|
: TConfig[K] extends Omit<
|
|
686
686
|
RouterQuery<infer TFnData, infer TVariables, infer TError>,
|
package/src/utils.ts
CHANGED
|
@@ -23,7 +23,7 @@ export const withMiddleware = (
|
|
|
23
23
|
options?: { client?: QueryClient; use?: Middleware[] },
|
|
24
24
|
queryClient?: QueryClient
|
|
25
25
|
) {
|
|
26
|
-
const [
|
|
26
|
+
const [uses, opts]: [Middleware[], any] = [
|
|
27
27
|
ReactQuery.useQueryClient(
|
|
28
28
|
// @ts-ignore Compatible with ReactQuery v4
|
|
29
29
|
isV5 ? queryClient : options
|
|
@@ -37,13 +37,9 @@ export const withMiddleware = (
|
|
|
37
37
|
],
|
|
38
38
|
[[]]
|
|
39
39
|
)
|
|
40
|
+
const composed = uses.reduceRight((next, use) => use(next), hook)
|
|
40
41
|
|
|
41
|
-
|
|
42
|
-
for (let i = middleware.length; i--; ) {
|
|
43
|
-
next = middleware[i](next)
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return next(opts, queryClient)
|
|
42
|
+
return composed(opts, queryClient)
|
|
47
43
|
}
|
|
48
44
|
}
|
|
49
45
|
|