react-query-kit 2.0.9 → 2.0.10
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/build/lib/createInfiniteQuery.esm.js +1 -1
- package/build/lib/createInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createInfiniteQuery.js +2 -22
- package/build/lib/createInfiniteQuery.js.map +1 -1
- package/build/lib/createInfiniteQuery.mjs +1 -1
- package/build/lib/createInfiniteQuery.mjs.map +1 -1
- package/build/lib/createMutation.d.ts +1 -1
- package/build/lib/createMutation.esm.js +1 -2
- package/build/lib/createMutation.esm.js.map +1 -1
- package/build/lib/createMutation.js +1 -22
- package/build/lib/createMutation.js.map +1 -1
- package/build/lib/createMutation.mjs +1 -2
- package/build/lib/createMutation.mjs.map +1 -1
- package/build/lib/createQuery.esm.js +1 -1
- package/build/lib/createQuery.esm.js.map +1 -1
- package/build/lib/createQuery.js +2 -22
- package/build/lib/createQuery.js.map +1 -1
- package/build/lib/createQuery.mjs +1 -1
- package/build/lib/createQuery.mjs.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.esm.js +2 -3
- package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.js +1 -22
- package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
- package/build/lib/createSuspenseInfiniteQuery.mjs +2 -3
- package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
- package/build/lib/createSuspenseQuery.esm.js +2 -3
- package/build/lib/createSuspenseQuery.esm.js.map +1 -1
- package/build/lib/createSuspenseQuery.js +1 -22
- package/build/lib/createSuspenseQuery.js.map +1 -1
- package/build/lib/createSuspenseQuery.mjs +2 -3
- package/build/lib/createSuspenseQuery.mjs.map +1 -1
- package/build/lib/types.d.ts +5 -3
- package/build/lib/utils.d.ts +7 -5
- package/build/lib/utils.esm.js +5 -4
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +7 -5
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +5 -4
- package/build/lib/utils.mjs.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats.json +88 -106
- package/build/umd/index.development.js +11 -10
- 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/createInfiniteQuery.ts +1 -2
- package/src/createMutation.ts +3 -5
- package/src/createQuery.tsx +1 -2
- package/src/createSuspenseInfiniteQuery.ts +2 -4
- package/src/createSuspenseQuery.ts +2 -4
- package/src/types.ts +6 -3
- package/src/utils.ts +10 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createMutation.ts","../../src/createQuery.tsx","../../src/createSuspenseInfiniteQuery.ts","../../src/createSuspenseQuery.ts"],"sourcesContent":["import * as
|
|
1
|
+
{"version":3,"file":"index.production.js","sources":["../../src/utils.ts","../../src/createBaseQuery.ts","../../src/createInfiniteQuery.ts","../../src/createMutation.ts","../../src/createQuery.tsx","../../src/createSuspenseInfiniteQuery.ts","../../src/createSuspenseQuery.ts"],"sourcesContent":["import * as TanstackReactQuery from '@tanstack/react-query'\nimport type { Query, QueryClient } from '@tanstack/react-query'\n\nimport type { Middleware, inferQueryKey } from './types'\n\nexport const ReactQuery = TanstackReactQuery\n\nexport const isV5 = !!ReactQuery.useSuspenseQuery\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\n// Compatible with ReactQuery v4\nexport const suspenseOptions = {\n enabled: true,\n suspense: true,\n useErrorBoundary: (_error: unknown, query: Query) =>\n query.state.data === undefined,\n}\n\nexport const getKey = <TVariables = void>(\n primaryKey: string,\n variables?: TVariables\n) => {\n return (\n variables === undefined ? [primaryKey] : [primaryKey, variables]\n ) as inferQueryKey<unknown, TVariables>\n}\n","import type {\n QueryClient,\n UseBaseQueryOptions,\n UseInfiniteQueryOptions,\n} from '@tanstack/react-query'\n\nimport type { AdditionalQueryOptions, Middleware } from './types'\nimport { getKey as getQueryKey, withMiddleware } from './utils'\n\ninterface CreateBaseQueryOptions\n extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,\n AdditionalQueryOptions<any, any> {\n use?: Middleware[]\n variables?: any\n}\n\ntype QueryBaseHookOptions = Omit<\n UseBaseQueryOptions,\n 'queryKey' | 'queryFn'\n> & {\n variables?: any\n}\n\nexport const createBaseQuery = (\n defaultOptions: any,\n useRQHook: (options: any, queryClient?: any) => any,\n overrideOptions?: QueryBaseHookOptions\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\n const {\n primaryKey,\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n } = defaultOptions as CreateBaseQueryOptions\n\n const getPrimaryKey = () => primaryKey\n\n const getKey = (variables?: any) => getQueryKey(primaryKey, variables)\n\n const getOptions = (variables: any) => {\n return {\n ...defaultOptions,\n queryKey: getKey(variables),\n }\n }\n\n const getFetchOptions = (variables: any) => {\n return {\n queryKey: getKey(variables),\n queryFn,\n queryKeyHashFn,\n getPreviousPageParam,\n getNextPageParam,\n initialPageParam,\n }\n }\n\n const useBaseHook = (\n options: QueryBaseHookOptions,\n queryClient?: QueryClient\n ) => {\n return useRQHook(\n {\n ...options,\n ...overrideOptions,\n queryKey: getKey(options.variables),\n },\n queryClient\n )\n }\n\n return Object.assign(withMiddleware(useBaseHook, defaultOptions, 'queries'), {\n getPrimaryKey,\n getKey,\n queryFn,\n queryKeyHashFn,\n getOptions,\n getFetchOptions,\n })\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 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 const getKey = () => defaultOptions.mutationKey\n\n return Object.assign(\n withMiddleware(ReactQuery.useMutation, defaultOptions, 'mutations'),\n {\n getKey,\n mutationFn: defaultOptions.mutationFn,\n }\n ) as MutationHook<TData, TVariables, TError, TContext>\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 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 { 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"],"names":["ReactQuery","isV5","useSuspenseQuery","withMiddleware","hook","defaultOptions","type","options","queryClient","middleware","opts","useQueryClient","getDefaultOptions","reduce","u1","o1","use","u2","o2","next","i","length","suspenseOptions","enabled","suspense","useErrorBoundary","_error","query","undefined","state","data","getKey","primaryKey","variables","createBaseQuery","useRQHook","overrideOptions","queryFn","queryKeyHashFn","getPreviousPageParam","getNextPageParam","initialPageParam","getQueryKey","Object","assign","queryKey","getPrimaryKey","getOptions","getFetchOptions","useInfiniteQuery","useMutation","mutationKey","mutationFn","useQuery","useSuspenseInfiniteQuery"],"mappings":"4lBAKO,MAAMA,OAEAC,IAASD,EAAWE,iBAEpBC,EAAiB,CAC5BC,EACAC,EACAC,IAEO,SACLC,EACAC,GAEA,MAAOC,EAAYC,GAAQ,CACzBV,EAAWW,eAETV,EAAOO,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,IAKTc,EAAkB,CAC7BC,SAAS,EACTC,UAAU,EACVC,iBAAkB,CAACC,EAAiBC,SACbC,IAArBD,EAAME,MAAMC,MAGHC,EAAS,CACpBC,EACAC,SAGgBL,IAAdK,EAA0B,CAACD,GAAc,CAACA,EAAYC,GChC7CC,EAAkB,CAC7B7B,EACA8B,EACAC,KAWA,MAAMJ,WACJA,EADIK,QAEJA,EAFIC,eAGJA,EAHIC,qBAIJA,EAJIC,iBAKJA,EALIC,iBAMJA,GACEpC,EAIE0B,EAAUE,GAAoBS,EAAYV,EAAYC,GAkC5D,OAAOU,OAAOC,OAAOzC,GAdD,CAClBI,EACAC,IAEO2B,EACL,IACK5B,KACA6B,EACHS,SAAUd,EAAOxB,EAAQ0B,YAE3BzB,IAI6CH,EAAgB,WAAY,CAC3EyC,cArCoB,IAAMd,SAsC1BD,EACAM,UACAC,iBACAS,WArCkBd,IACX,IACF5B,EACHwC,SAAUd,EAAOE,KAmCnBe,gBA/BuBf,IAChB,CACLY,SAAUd,EAAOE,GACjBI,UACAC,iBACAC,uBACAC,mBACAC,sBAkBJ,wBCpEAlC,GAEO2B,EAAgB3B,EAASP,EAAWiD,mCCH3C5C,GAIOsC,OAAOC,OACZzC,EAAeH,EAAWkD,YAAa7C,EAAgB,aACvD,CACE0B,OALW,IAAM1B,EAAe8C,YAMhCC,WAAY/C,EAAe+C,2BCZ/B7C,GAEO2B,EAAgB3B,EAASP,EAAWqD,wCCG3C9C,GAOON,EACHiC,EAAgB3B,EAASP,EAAWsD,0BACpCpB,EAAgB3B,EAASP,EAAWiD,iBAAkB3B,yBCV1Df,GAEON,EACHiC,EAAgB3B,EAASP,EAAWE,kBACpCgC,EAAgB3B,EAASP,EAAWqD,SAAU/B"}
|
package/build/zip/zip.esm.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import*as e from"@tanstack/react-query";const t=
|
|
1
|
+
import*as e from"@tanstack/react-query";const t=e,u=!!t.useSuspenseQuery,r=(e,r,a)=>function(n,s){const[i,y]=[t.useQueryClient(u?s:n).getDefaultOptions()[a],r,n].reduce((([e,t],{use:u=[],...r}={})=>[[...e,...u],{...t,...r}]),[[]]);let o=e;for(let e=i.length;e--;)o=i[e](o);return o(y,s)},a={enabled:!0,suspense:!0,useErrorBoundary:(e,t)=>void 0===t.state.data},n=(e,t)=>void 0===t?[e]:[e,t],s=(e,t,u)=>{const{primaryKey:a,queryFn:s,queryKeyHashFn:i,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g}=e,P=e=>n(a,e);return Object.assign(r(((e,r)=>t({...e,...u,queryKey:P(e.variables)},r)),e,"queries"),{getPrimaryKey:()=>a,getKey:P,queryFn:s,queryKeyHashFn:i,getOptions:t=>({...e,queryKey:P(t)}),getFetchOptions:e=>({queryKey:P(e),queryFn:s,queryKeyHashFn:i,getPreviousPageParam:y,getNextPageParam:o,initialPageParam:g})})},i=e=>s(e,t.useQuery),y=e=>u?s(e,t.useSuspenseQuery):s(e,t.useQuery,a),o=e=>s(e,t.useInfiniteQuery),g=e=>u?s(e,t.useSuspenseInfiniteQuery):s(e,t.useInfiniteQuery,a),P=e=>Object.assign(r(t.useMutation,e,"mutations"),{getKey:()=>e.mutationKey,mutationFn:e.mutationFn});export{o as createInfiniteQuery,P as createMutation,i as createQuery,g as createSuspenseInfiniteQuery,y as createSuspenseQuery,n as getKey};
|
package/package.json
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import * as ReactQuery from '@tanstack/react-query'
|
|
2
|
-
|
|
3
1
|
import { createBaseQuery } from './createBaseQuery'
|
|
4
2
|
import type {
|
|
5
3
|
CompatibleError,
|
|
6
4
|
CreateInfiniteQueryOptions,
|
|
7
5
|
InfiniteQueryHook,
|
|
8
6
|
} from './types'
|
|
7
|
+
import { ReactQuery } from './utils'
|
|
9
8
|
|
|
10
9
|
export const createInfiniteQuery = <
|
|
11
10
|
TFnData,
|
package/src/createMutation.ts
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
import * as ReactQuery from '@tanstack/react-query'
|
|
2
|
-
|
|
3
1
|
import type {
|
|
4
2
|
CompatibleError,
|
|
5
3
|
CreateMutationOptions,
|
|
6
4
|
MutationHook,
|
|
7
5
|
} from './types'
|
|
8
|
-
import { withMiddleware } from './utils'
|
|
6
|
+
import { ReactQuery, withMiddleware } from './utils'
|
|
9
7
|
|
|
10
8
|
export const createMutation = <
|
|
11
9
|
TData = unknown,
|
|
@@ -14,7 +12,7 @@ export const createMutation = <
|
|
|
14
12
|
TContext = unknown
|
|
15
13
|
>(
|
|
16
14
|
defaultOptions: CreateMutationOptions<TData, TVariables, TError, TContext>
|
|
17
|
-
): MutationHook<TData, TVariables, TError> => {
|
|
15
|
+
): MutationHook<TData, TVariables, TError, TContext> => {
|
|
18
16
|
const getKey = () => defaultOptions.mutationKey
|
|
19
17
|
|
|
20
18
|
return Object.assign(
|
|
@@ -23,5 +21,5 @@ export const createMutation = <
|
|
|
23
21
|
getKey,
|
|
24
22
|
mutationFn: defaultOptions.mutationFn,
|
|
25
23
|
}
|
|
26
|
-
) as MutationHook<TData, TVariables, TError>
|
|
24
|
+
) as MutationHook<TData, TVariables, TError, TContext>
|
|
27
25
|
}
|
package/src/createQuery.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import * as ReactQuery from '@tanstack/react-query'
|
|
2
|
-
|
|
3
1
|
import { createBaseQuery } from './createBaseQuery'
|
|
4
2
|
import type { CompatibleError, CreateQueryOptions, QueryHook } from './types'
|
|
3
|
+
import { ReactQuery } from './utils'
|
|
5
4
|
|
|
6
5
|
export const createQuery = <
|
|
7
6
|
TFnData,
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import * as ReactQuery from '@tanstack/react-query'
|
|
2
|
-
|
|
3
1
|
import { createBaseQuery } from './createBaseQuery'
|
|
4
2
|
import type {
|
|
5
3
|
CompatibleError,
|
|
6
4
|
CreateSuspenseInfiniteQueryOptions,
|
|
7
5
|
SuspenseInfiniteQueryHook,
|
|
8
6
|
} from './types'
|
|
9
|
-
import { isV5, suspenseOptions } from './utils'
|
|
7
|
+
import { ReactQuery, isV5, suspenseOptions } from './utils'
|
|
10
8
|
|
|
11
9
|
export const createSuspenseInfiniteQuery = <
|
|
12
10
|
TFnData,
|
|
@@ -21,7 +19,7 @@ export const createSuspenseInfiniteQuery = <
|
|
|
21
19
|
TPageParam
|
|
22
20
|
>
|
|
23
21
|
): SuspenseInfiniteQueryHook<TFnData, TVariables, TError, TPageParam> => {
|
|
24
|
-
return isV5
|
|
22
|
+
return isV5
|
|
25
23
|
? createBaseQuery(options, ReactQuery.useSuspenseInfiniteQuery)
|
|
26
24
|
: createBaseQuery(options, ReactQuery.useInfiniteQuery, suspenseOptions)
|
|
27
25
|
}
|
|
@@ -1,12 +1,10 @@
|
|
|
1
|
-
import * as ReactQuery from '@tanstack/react-query'
|
|
2
|
-
|
|
3
1
|
import { createBaseQuery } from './createBaseQuery'
|
|
4
2
|
import type {
|
|
5
3
|
CompatibleError,
|
|
6
4
|
CreateSuspenseQueryOptions,
|
|
7
5
|
SuspenseQueryHook,
|
|
8
6
|
} from './types'
|
|
9
|
-
import { isV5, suspenseOptions } from './utils'
|
|
7
|
+
import { ReactQuery, isV5, suspenseOptions } from './utils'
|
|
10
8
|
|
|
11
9
|
export const createSuspenseQuery = <
|
|
12
10
|
TFnData,
|
|
@@ -15,7 +13,7 @@ export const createSuspenseQuery = <
|
|
|
15
13
|
>(
|
|
16
14
|
options: CreateSuspenseQueryOptions<TFnData, TVariables, TError>
|
|
17
15
|
): SuspenseQueryHook<TFnData, TVariables, TError> => {
|
|
18
|
-
return isV5
|
|
16
|
+
return isV5
|
|
19
17
|
? createBaseQuery(options, ReactQuery.useSuspenseQuery)
|
|
20
18
|
: createBaseQuery(options, ReactQuery.useQuery, suspenseOptions)
|
|
21
19
|
}
|
package/src/types.ts
CHANGED
|
@@ -283,6 +283,7 @@ export interface CreateSuspenseQueryOptions<
|
|
|
283
283
|
>,
|
|
284
284
|
AdditionalQueryOptions<TFnData, TVariables> {
|
|
285
285
|
use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]
|
|
286
|
+
variables?: TVariables
|
|
286
287
|
}
|
|
287
288
|
|
|
288
289
|
export interface SuspenseQueryHookOptions<TFnData, TError, TData, TVariables>
|
|
@@ -337,6 +338,7 @@ export interface CreateInfiniteQueryOptions<
|
|
|
337
338
|
>,
|
|
338
339
|
AdditionalQueryOptions<TFnData, TVariables, TPageParam> {
|
|
339
340
|
use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]
|
|
341
|
+
variables?: TVariables
|
|
340
342
|
}
|
|
341
343
|
|
|
342
344
|
export interface InfiniteQueryHookOptions<
|
|
@@ -444,6 +446,7 @@ export interface CreateSuspenseInfiniteQueryOptions<
|
|
|
444
446
|
>,
|
|
445
447
|
AdditionalQueryOptions<TFnData, TVariables, TPageParam> {
|
|
446
448
|
use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]
|
|
449
|
+
variables?: TVariables
|
|
447
450
|
}
|
|
448
451
|
|
|
449
452
|
export interface SuspenseInfiniteQueryHookOptions<
|
|
@@ -517,7 +520,6 @@ export interface MutationHookOptions<TData, TError, TVariables, TContext>
|
|
|
517
520
|
'mutationFn' | 'mutationKey'
|
|
518
521
|
> {
|
|
519
522
|
use?: Middleware<MutationHook<TData, TError, TVariables>>[]
|
|
520
|
-
variables?: TVariables
|
|
521
523
|
}
|
|
522
524
|
|
|
523
525
|
export type MutationHookResult<
|
|
@@ -530,9 +532,10 @@ export type MutationHookResult<
|
|
|
530
532
|
export interface MutationHook<
|
|
531
533
|
TData = unknown,
|
|
532
534
|
TVariables = void,
|
|
533
|
-
TError = unknown
|
|
535
|
+
TError = unknown,
|
|
536
|
+
TDefaultContext = unknown
|
|
534
537
|
> {
|
|
535
|
-
<TContext>(
|
|
538
|
+
<TContext = TDefaultContext>(
|
|
536
539
|
options?: MutationHookOptions<TData, TError, TVariables, TContext>,
|
|
537
540
|
queryClient?: CompatibleWithV4<QueryClient, void>
|
|
538
541
|
): MutationHookResult<TData, TError, TVariables, TContext>
|
package/src/utils.ts
CHANGED
|
@@ -1,20 +1,25 @@
|
|
|
1
|
-
import * as
|
|
1
|
+
import * as TanstackReactQuery from '@tanstack/react-query'
|
|
2
|
+
import type { Query, QueryClient } from '@tanstack/react-query'
|
|
2
3
|
|
|
3
4
|
import type { Middleware, inferQueryKey } from './types'
|
|
4
5
|
|
|
6
|
+
export const ReactQuery = TanstackReactQuery
|
|
7
|
+
|
|
8
|
+
export const isV5 = !!ReactQuery.useSuspenseQuery
|
|
9
|
+
|
|
5
10
|
export const withMiddleware = (
|
|
6
11
|
hook: any,
|
|
7
12
|
defaultOptions: any,
|
|
8
13
|
type: 'queries' | 'mutations'
|
|
9
14
|
) => {
|
|
10
15
|
return function useMiddleware(
|
|
11
|
-
options?: { client?:
|
|
12
|
-
queryClient?:
|
|
16
|
+
options?: { client?: QueryClient; use?: Middleware[] },
|
|
17
|
+
queryClient?: QueryClient
|
|
13
18
|
) {
|
|
14
19
|
const [middleware, opts] = [
|
|
15
20
|
ReactQuery.useQueryClient(
|
|
16
21
|
// @ts-ignore Compatible with ReactQuery v4
|
|
17
|
-
isV5
|
|
22
|
+
isV5 ? queryClient : options
|
|
18
23
|
).getDefaultOptions()[type],
|
|
19
24
|
defaultOptions,
|
|
20
25
|
options,
|
|
@@ -39,12 +44,10 @@ export const withMiddleware = (
|
|
|
39
44
|
export const suspenseOptions = {
|
|
40
45
|
enabled: true,
|
|
41
46
|
suspense: true,
|
|
42
|
-
useErrorBoundary: (_error: unknown, query:
|
|
47
|
+
useErrorBoundary: (_error: unknown, query: Query) =>
|
|
43
48
|
query.state.data === undefined,
|
|
44
49
|
}
|
|
45
50
|
|
|
46
|
-
export const isV5 = () => !!ReactQuery.useSuspenseQuery
|
|
47
|
-
|
|
48
51
|
export const getKey = <TVariables = void>(
|
|
49
52
|
primaryKey: string,
|
|
50
53
|
variables?: TVariables
|