react-query-kit 1.5.2 → 2.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.
Files changed (56) hide show
  1. package/README.md +26 -42
  2. package/build/lib/createBaseQuery.d.ts +3 -2
  3. package/build/lib/createBaseQuery.esm.js +19 -26
  4. package/build/lib/createBaseQuery.esm.js.map +1 -1
  5. package/build/lib/createBaseQuery.js +16 -23
  6. package/build/lib/createBaseQuery.js.map +1 -1
  7. package/build/lib/createBaseQuery.mjs +19 -26
  8. package/build/lib/createBaseQuery.mjs.map +1 -1
  9. package/build/lib/createInfiniteQuery.d.ts +1 -4
  10. package/build/lib/createInfiniteQuery.esm.js.map +1 -1
  11. package/build/lib/createInfiniteQuery.js.map +1 -1
  12. package/build/lib/createInfiniteQuery.mjs.map +1 -1
  13. package/build/lib/createMutation.d.ts +1 -5
  14. package/build/lib/createMutation.esm.js.map +1 -1
  15. package/build/lib/createMutation.js.map +1 -1
  16. package/build/lib/createMutation.mjs.map +1 -1
  17. package/build/lib/createQuery.d.ts +1 -5
  18. package/build/lib/createQuery.esm.js.map +1 -1
  19. package/build/lib/createQuery.js.map +1 -1
  20. package/build/lib/createQuery.mjs.map +1 -1
  21. package/build/lib/createSuspenseInfiniteQuery.d.ts +1 -4
  22. package/build/lib/createSuspenseInfiniteQuery.esm.js.map +1 -1
  23. package/build/lib/createSuspenseInfiniteQuery.js.map +1 -1
  24. package/build/lib/createSuspenseInfiniteQuery.mjs.map +1 -1
  25. package/build/lib/createSuspenseQuery.d.ts +1 -5
  26. package/build/lib/createSuspenseQuery.esm.js.map +1 -1
  27. package/build/lib/createSuspenseQuery.js.map +1 -1
  28. package/build/lib/createSuspenseQuery.mjs.map +1 -1
  29. package/build/lib/index.d.ts +2 -2
  30. package/build/lib/index.esm.js +1 -1
  31. package/build/lib/index.js +1 -1
  32. package/build/lib/index.mjs +1 -1
  33. package/build/lib/types.d.ts +37 -36
  34. package/build/lib/utils.d.ts +2 -3
  35. package/build/lib/utils.esm.js +12 -20
  36. package/build/lib/utils.esm.js.map +1 -1
  37. package/build/lib/utils.js +12 -21
  38. package/build/lib/utils.js.map +1 -1
  39. package/build/lib/utils.mjs +12 -20
  40. package/build/lib/utils.mjs.map +1 -1
  41. package/build/stats-html.html +1 -1
  42. package/build/stats.json +81 -81
  43. package/build/umd/index.development.js +30 -45
  44. package/build/umd/index.development.js.map +1 -1
  45. package/build/umd/index.production.js +1 -1
  46. package/build/umd/index.production.js.map +1 -1
  47. package/package.json +2 -7
  48. package/src/createBaseQuery.ts +26 -41
  49. package/src/createInfiniteQuery.ts +1 -22
  50. package/src/createMutation.ts +1 -11
  51. package/src/createQuery.tsx +1 -20
  52. package/src/createSuspenseInfiniteQuery.ts +1 -30
  53. package/src/createSuspenseQuery.ts +2 -27
  54. package/src/index.ts +5 -1
  55. package/src/types.ts +161 -117
  56. package/src/utils.ts +14 -21
@@ -1,37 +1,42 @@
1
1
  import type {
2
2
  QueryClient,
3
- SetDataOptions,
4
- Updater,
5
3
  UseBaseQueryOptions,
4
+ UseInfiniteQueryOptions,
6
5
  } from '@tanstack/react-query'
7
6
 
8
7
  import type {
9
8
  AdditionalCreateOptions,
10
- AdditionalQueryHookOptions,
11
9
  CompatibleWithV4,
12
10
  Middleware,
13
11
  } from './types'
14
- import { getQueryKey, useCompatibeQueryClient, withMiddleware } from './utils'
12
+ import { getKey as getQueryKey, withMiddleware } from './utils'
15
13
 
16
- interface CreateQueryOptions
17
- extends Omit<UseBaseQueryOptions, 'queryKey' | 'queryFn' | 'enabled'>,
14
+ interface CreateBaseQueryOptions
15
+ extends Omit<UseInfiniteQueryOptions, 'queryKey' | 'queryFn'>,
18
16
  AdditionalCreateOptions<any, any> {
19
17
  use?: Middleware[]
20
18
  }
21
19
 
22
20
  type QueryBaseHookOptions = Omit<
23
21
  UseBaseQueryOptions,
24
- 'queryKey' | 'queryFn' | 'enabled'
25
- > &
26
- AdditionalQueryHookOptions<any, any>
22
+ 'queryKey' | 'queryFn'
23
+ > & {
24
+ variables?: any
25
+ }
27
26
 
28
27
  export function createBaseQuery(
29
28
  defaultOptions: any,
30
29
  useRQHook: (options: any, queryClient?: any) => any,
31
30
  overrideOptions?: QueryBaseHookOptions
32
31
  ): any {
33
- const { primaryKey, queryFn, queryKeyHashFn } =
34
- defaultOptions as CreateQueryOptions
32
+ const {
33
+ primaryKey,
34
+ queryFn,
35
+ queryKeyHashFn,
36
+ getPreviousPageParam,
37
+ getNextPageParam,
38
+ initialPageParam,
39
+ } = defaultOptions as CreateBaseQueryOptions
35
40
 
36
41
  if (process.env.NODE_ENV !== 'production') {
37
42
  // @ts-ignore
@@ -51,43 +56,23 @@ export function createBaseQuery(
51
56
  queryKey: getKey(variables),
52
57
  queryFn,
53
58
  queryKeyHashFn,
54
- getPreviousPageParam: (defaultOptions as any).getPreviousPageParam,
55
- getNextPageParam: (defaultOptions as any).getNextPageParam,
56
- initialPageParam: (defaultOptions as any).initialPageParam,
59
+ getPreviousPageParam,
60
+ getNextPageParam,
61
+ initialPageParam,
57
62
  }
58
63
  }
59
64
 
60
65
  const useBaseHook = (
61
- options: QueryBaseHookOptions,
66
+ { variables, ...rest }: QueryBaseHookOptions,
62
67
  queryClient?: CompatibleWithV4<QueryClient, void>
63
68
  ) => {
64
- const client = useCompatibeQueryClient(options, queryClient)
65
- const { enabled, variables, ...mergedOptions } = {
66
- ...options,
67
- ...overrideOptions,
68
- } as QueryBaseHookOptions
69
- const queryKey = getKey(variables)
70
-
71
- return Object.assign(
72
- useRQHook(
73
- {
74
- ...mergedOptions,
75
- enabled:
76
- typeof enabled === 'function'
77
- ? enabled(client.getQueryData(queryKey), variables)
78
- : enabled,
79
- queryKey,
80
- },
81
- client
82
- ),
69
+ return useRQHook(
83
70
  {
84
- queryKey: queryKey,
85
- variables,
86
- setData: (
87
- updater: Updater<any, any>,
88
- setDataOptions?: SetDataOptions
89
- ) => client.setQueryData(queryKey, updater, setDataOptions),
90
- }
71
+ ...rest,
72
+ ...overrideOptions,
73
+ queryKey: getKey(variables),
74
+ },
75
+ queryClient
91
76
  )
92
77
  }
93
78
 
@@ -2,32 +2,11 @@ import { useInfiniteQuery } from '@tanstack/react-query'
2
2
 
3
3
  import { createBaseQuery } from './createBaseQuery'
4
4
  import type {
5
- AdditionalCreateOptions,
6
- CompatibleUseInfiniteQueryOptions,
5
+ CreateInfiniteQueryOptions,
7
6
  DefaultError,
8
7
  InfiniteQueryHook,
9
- Middleware,
10
8
  } from './types'
11
9
 
12
- export interface CreateInfiniteQueryOptions<
13
- TFnData = unknown,
14
- TVariables = any,
15
- TError = DefaultError,
16
- TPageParam = number
17
- > extends Omit<
18
- CompatibleUseInfiniteQueryOptions<
19
- TFnData,
20
- TVariables,
21
- TFnData,
22
- TError,
23
- TPageParam
24
- >,
25
- 'queryKey' | 'queryFn' | 'enabled' | 'select'
26
- >,
27
- AdditionalCreateOptions<TFnData, TVariables, TPageParam> {
28
- use?: Middleware<InfiniteQueryHook<TFnData, TVariables, TError, TPageParam>>[]
29
- }
30
-
31
10
  export const createInfiniteQuery = <
32
11
  TFnData,
33
12
  TVariables = any,
@@ -1,18 +1,8 @@
1
1
  import { useMutation } from '@tanstack/react-query'
2
- import type { UseMutationOptions } from '@tanstack/react-query'
3
2
 
4
- import type { DefaultError, Middleware, MutationHook } from './types'
3
+ import type { CreateMutationOptions, DefaultError, MutationHook } from './types'
5
4
  import { withMiddleware } from './utils'
6
5
 
7
- export interface CreateMutationOptions<
8
- TData = unknown,
9
- TVariables = void,
10
- TError = DefaultError,
11
- TContext = unknown
12
- > extends UseMutationOptions<TData, TError, TVariables, TContext> {
13
- use?: Middleware<MutationHook<TData, TError, TVariables>>[]
14
- }
15
-
16
6
  export const createMutation = <
17
7
  TData = unknown,
18
8
  TVariables = void,
@@ -1,26 +1,7 @@
1
- import type { UseQueryOptions } from '@tanstack/react-query'
2
1
  import { useQuery } from '@tanstack/react-query'
3
2
 
4
3
  import { createBaseQuery } from './createBaseQuery'
5
- import type {
6
- AdditionalCreateOptions,
7
- DefaultError,
8
- Middleware,
9
- QueryHook,
10
- inferQueryKey,
11
- } from './types'
12
-
13
- export interface CreateQueryOptions<
14
- TFnData = unknown,
15
- TVariables = any,
16
- TError = DefaultError
17
- > extends Omit<
18
- UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
19
- 'queryKey' | 'queryFn' | 'enabled' | 'select'
20
- >,
21
- AdditionalCreateOptions<TFnData, TVariables> {
22
- use?: Middleware<QueryHook<TFnData, TVariables, TError>>[]
23
- }
4
+ import type { CreateQueryOptions, DefaultError, QueryHook } from './types'
24
5
 
25
6
  export const createQuery = <TFnData, TVariables = any, TError = DefaultError>(
26
7
  options: CreateQueryOptions<TFnData, TVariables, TError>
@@ -2,40 +2,11 @@ import { useInfiniteQuery } from '@tanstack/react-query'
2
2
 
3
3
  import { createBaseQuery } from './createBaseQuery'
4
4
  import type {
5
- AdditionalCreateOptions,
6
- CompatibleUseInfiniteQueryOptions,
5
+ CreateSuspenseInfiniteQueryOptions,
7
6
  DefaultError,
8
- Middleware,
9
7
  SuspenseInfiniteQueryHook,
10
8
  } from './types'
11
9
 
12
- export interface CreateSuspenseInfiniteQueryOptions<
13
- TFnData = unknown,
14
- TVariables = any,
15
- TError = DefaultError,
16
- TPageParam = number
17
- > extends Omit<
18
- CompatibleUseInfiniteQueryOptions<
19
- TFnData,
20
- TVariables,
21
- TFnData,
22
- TError,
23
- TPageParam
24
- >,
25
- | 'queryKey'
26
- | 'queryFn'
27
- | 'enabled'
28
- | 'select'
29
- | 'suspense'
30
- | 'throwOnError'
31
- | 'placeholderData'
32
- | 'keepPreviousData'
33
- | 'useErrorBoundary'
34
- >,
35
- Omit<AdditionalCreateOptions<TFnData, TVariables, TPageParam>, 'enabled'> {
36
- use?: Middleware<SuspenseInfiniteQueryHook<TFnData, TVariables, TVariables>>[]
37
- }
38
-
39
10
  export const createSuspenseInfiniteQuery = <
40
11
  TFnData,
41
12
  TVariables = any,
@@ -1,33 +1,8 @@
1
- import type { DefaultError, UseQueryOptions } from '@tanstack/react-query'
1
+ import type { DefaultError } from '@tanstack/react-query'
2
2
  import { useQuery } from '@tanstack/react-query'
3
3
 
4
4
  import { createBaseQuery } from './createBaseQuery'
5
- import type {
6
- AdditionalCreateOptions,
7
- Middleware,
8
- SuspenseQueryHook,
9
- inferQueryKey,
10
- } from './types'
11
-
12
- export interface CreateSuspenseQueryOptions<
13
- TFnData = unknown,
14
- TVariables = any,
15
- TError = DefaultError
16
- > extends Omit<
17
- UseQueryOptions<TFnData, TError, TFnData, inferQueryKey<TVariables>>,
18
- | 'queryKey'
19
- | 'queryFn'
20
- | 'enabled'
21
- | 'select'
22
- | 'suspense'
23
- | 'throwOnError'
24
- | 'placeholderData'
25
- | 'keepPreviousData'
26
- | 'useErrorBoundary'
27
- >,
28
- Omit<AdditionalCreateOptions<TFnData, TVariables>, 'enabled'> {
29
- use?: Middleware<SuspenseQueryHook<TFnData, TVariables, TVariables>>[]
30
- }
5
+ import type { CreateSuspenseQueryOptions, SuspenseQueryHook } from './types'
31
6
 
32
7
  export const createSuspenseQuery = <
33
8
  TFnData,
package/src/index.ts CHANGED
@@ -3,17 +3,21 @@ export * from './createSuspenseQuery'
3
3
  export * from './createInfiniteQuery'
4
4
  export * from './createSuspenseInfiniteQuery'
5
5
  export * from './createMutation'
6
- export { getQueryKey } from './utils'
6
+ export { getKey } from './utils'
7
7
  export type {
8
+ CreateQueryOptions,
8
9
  QueryHookOptions,
9
10
  QueryHook,
10
11
  QueryHookResult,
12
+ CreateInfiniteQueryOptions,
11
13
  InfiniteQueryHookOptions,
12
14
  InfiniteQueryHook,
13
15
  InfiniteQueryHookResult,
16
+ CreateSuspenseQueryOptions,
14
17
  SuspenseQueryHook,
15
18
  SuspenseQueryHookOptions,
16
19
  SuspenseQueryHookResult,
20
+ CreateSuspenseInfiniteQueryOptions,
17
21
  SuspenseInfiniteQueryHook,
18
22
  SuspenseInfiniteQueryHookOptions,
19
23
  SuspenseInfiniteQueryHookResult,