@tanstack/query-core 4.24.10 → 5.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (184) hide show
  1. package/build/lib/focusManager.d.ts +1 -3
  2. package/build/lib/focusManager.esm.js +19 -36
  3. package/build/lib/focusManager.esm.js.map +1 -1
  4. package/build/lib/focusManager.js +19 -38
  5. package/build/lib/focusManager.js.map +1 -1
  6. package/build/lib/focusManager.mjs +19 -36
  7. package/build/lib/focusManager.mjs.map +1 -1
  8. package/build/lib/hydration.esm.js +21 -23
  9. package/build/lib/hydration.esm.js.map +1 -1
  10. package/build/lib/hydration.js +21 -25
  11. package/build/lib/hydration.js.map +1 -1
  12. package/build/lib/hydration.mjs +21 -23
  13. package/build/lib/hydration.mjs.map +1 -1
  14. package/build/lib/index.d.ts +1 -2
  15. package/build/lib/index.esm.js +1 -1
  16. package/build/lib/index.js +2 -8
  17. package/build/lib/index.js.map +1 -1
  18. package/build/lib/index.mjs +1 -1
  19. package/build/lib/infiniteQueryBehavior.d.ts +3 -7
  20. package/build/lib/infiniteQueryBehavior.esm.js +52 -75
  21. package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
  22. package/build/lib/infiniteQueryBehavior.js +50 -77
  23. package/build/lib/infiniteQueryBehavior.js.map +1 -1
  24. package/build/lib/infiniteQueryBehavior.mjs +52 -75
  25. package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
  26. package/build/lib/infiniteQueryObserver.d.ts +4 -4
  27. package/build/lib/infiniteQueryObserver.esm.js +18 -26
  28. package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
  29. package/build/lib/infiniteQueryObserver.js +18 -28
  30. package/build/lib/infiniteQueryObserver.js.map +1 -1
  31. package/build/lib/infiniteQueryObserver.mjs +18 -26
  32. package/build/lib/infiniteQueryObserver.mjs.map +1 -1
  33. package/build/lib/mutation.d.ts +11 -22
  34. package/build/lib/mutation.esm.js +73 -105
  35. package/build/lib/mutation.esm.js.map +1 -1
  36. package/build/lib/mutation.js +73 -107
  37. package/build/lib/mutation.js.map +1 -1
  38. package/build/lib/mutation.mjs +73 -105
  39. package/build/lib/mutation.mjs.map +1 -1
  40. package/build/lib/mutationCache.d.ts +4 -6
  41. package/build/lib/mutationCache.esm.js +23 -32
  42. package/build/lib/mutationCache.esm.js.map +1 -1
  43. package/build/lib/mutationCache.js +23 -34
  44. package/build/lib/mutationCache.js.map +1 -1
  45. package/build/lib/mutationCache.mjs +23 -32
  46. package/build/lib/mutationCache.mjs.map +1 -1
  47. package/build/lib/mutationObserver.d.ts +4 -9
  48. package/build/lib/mutationObserver.esm.js +42 -73
  49. package/build/lib/mutationObserver.esm.js.map +1 -1
  50. package/build/lib/mutationObserver.js +42 -75
  51. package/build/lib/mutationObserver.js.map +1 -1
  52. package/build/lib/mutationObserver.mjs +42 -73
  53. package/build/lib/mutationObserver.mjs.map +1 -1
  54. package/build/lib/notifyManager.esm.js +7 -17
  55. package/build/lib/notifyManager.esm.js.map +1 -1
  56. package/build/lib/notifyManager.js +7 -19
  57. package/build/lib/notifyManager.js.map +1 -1
  58. package/build/lib/notifyManager.mjs +7 -17
  59. package/build/lib/notifyManager.mjs.map +1 -1
  60. package/build/lib/onlineManager.d.ts +1 -3
  61. package/build/lib/onlineManager.esm.js +16 -30
  62. package/build/lib/onlineManager.esm.js.map +1 -1
  63. package/build/lib/onlineManager.js +16 -32
  64. package/build/lib/onlineManager.js.map +1 -1
  65. package/build/lib/onlineManager.mjs +16 -30
  66. package/build/lib/onlineManager.mjs.map +1 -1
  67. package/build/lib/queriesObserver.d.ts +3 -10
  68. package/build/lib/queriesObserver.esm.js +47 -71
  69. package/build/lib/queriesObserver.esm.js.map +1 -1
  70. package/build/lib/queriesObserver.js +49 -75
  71. package/build/lib/queriesObserver.js.map +1 -1
  72. package/build/lib/queriesObserver.mjs +47 -71
  73. package/build/lib/queriesObserver.mjs.map +1 -1
  74. package/build/lib/query.d.ts +14 -21
  75. package/build/lib/query.esm.js +140 -194
  76. package/build/lib/query.esm.js.map +1 -1
  77. package/build/lib/query.js +139 -195
  78. package/build/lib/query.js.map +1 -1
  79. package/build/lib/query.mjs +140 -194
  80. package/build/lib/query.mjs.map +1 -1
  81. package/build/lib/queryCache.d.ts +12 -7
  82. package/build/lib/queryCache.esm.js +21 -45
  83. package/build/lib/queryCache.esm.js.map +1 -1
  84. package/build/lib/queryCache.js +20 -46
  85. package/build/lib/queryCache.js.map +1 -1
  86. package/build/lib/queryCache.mjs +21 -45
  87. package/build/lib/queryCache.mjs.map +1 -1
  88. package/build/lib/queryClient.d.ts +18 -46
  89. package/build/lib/queryClient.esm.js +137 -216
  90. package/build/lib/queryClient.esm.js.map +1 -1
  91. package/build/lib/queryClient.js +136 -217
  92. package/build/lib/queryClient.js.map +1 -1
  93. package/build/lib/queryClient.mjs +137 -216
  94. package/build/lib/queryClient.mjs.map +1 -1
  95. package/build/lib/queryObserver.d.ts +4 -29
  96. package/build/lib/queryObserver.esm.js +176 -258
  97. package/build/lib/queryObserver.esm.js.map +1 -1
  98. package/build/lib/queryObserver.js +176 -260
  99. package/build/lib/queryObserver.js.map +1 -1
  100. package/build/lib/queryObserver.mjs +176 -258
  101. package/build/lib/queryObserver.mjs.map +1 -1
  102. package/build/lib/removable.d.ts +3 -3
  103. package/build/lib/removable.esm.js +10 -14
  104. package/build/lib/removable.esm.js.map +1 -1
  105. package/build/lib/removable.js +10 -16
  106. package/build/lib/removable.js.map +1 -1
  107. package/build/lib/removable.mjs +10 -14
  108. package/build/lib/removable.mjs.map +1 -1
  109. package/build/lib/retryer.d.ts +5 -5
  110. package/build/lib/retryer.esm.js +27 -44
  111. package/build/lib/retryer.esm.js.map +1 -1
  112. package/build/lib/retryer.js +27 -46
  113. package/build/lib/retryer.js.map +1 -1
  114. package/build/lib/retryer.mjs +27 -44
  115. package/build/lib/retryer.mjs.map +1 -1
  116. package/build/lib/subscribable.esm.js +4 -7
  117. package/build/lib/subscribable.esm.js.map +1 -1
  118. package/build/lib/subscribable.js +4 -9
  119. package/build/lib/subscribable.js.map +1 -1
  120. package/build/lib/subscribable.mjs +4 -7
  121. package/build/lib/subscribable.mjs.map +1 -1
  122. package/build/lib/tests/utils.d.ts +3 -12
  123. package/build/lib/types.d.ts +111 -99
  124. package/build/lib/utils.d.ts +8 -18
  125. package/build/lib/utils.esm.js +39 -132
  126. package/build/lib/utils.esm.js.map +1 -1
  127. package/build/lib/utils.js +42 -144
  128. package/build/lib/utils.js.map +1 -1
  129. package/build/lib/utils.mjs +39 -132
  130. package/build/lib/utils.mjs.map +1 -1
  131. package/build/umd/index.development.js +867 -1399
  132. package/build/umd/index.development.js.map +1 -1
  133. package/build/umd/index.production.js +1 -1
  134. package/build/umd/index.production.js.map +1 -1
  135. package/package.json +1 -1
  136. package/src/focusManager.ts +17 -24
  137. package/src/index.ts +1 -11
  138. package/src/infiniteQueryBehavior.ts +54 -94
  139. package/src/infiniteQueryObserver.ts +10 -12
  140. package/src/mutation.ts +68 -92
  141. package/src/mutationCache.ts +27 -27
  142. package/src/mutationObserver.ts +58 -97
  143. package/src/onlineManager.ts +14 -14
  144. package/src/queriesObserver.ts +50 -54
  145. package/src/query.ts +107 -111
  146. package/src/queryCache.ts +42 -41
  147. package/src/queryClient.ts +155 -434
  148. package/src/queryObserver.ts +155 -192
  149. package/src/removable.ts +13 -13
  150. package/src/retryer.ts +5 -5
  151. package/src/subscribable.ts +1 -1
  152. package/src/tests/focusManager.test.tsx +25 -25
  153. package/src/tests/hydration.test.tsx +167 -81
  154. package/src/tests/infiniteQueryBehavior.test.tsx +209 -17
  155. package/src/tests/infiniteQueryObserver.test.tsx +6 -2
  156. package/src/tests/mutationCache.test.tsx +127 -127
  157. package/src/tests/mutationObserver.test.tsx +1 -31
  158. package/src/tests/mutations.test.tsx +62 -43
  159. package/src/tests/onlineManager.test.tsx +12 -4
  160. package/src/tests/queriesObserver.test.tsx +41 -77
  161. package/src/tests/query.test.tsx +175 -243
  162. package/src/tests/queryCache.test.tsx +170 -93
  163. package/src/tests/queryClient.test.tsx +229 -378
  164. package/src/tests/queryObserver.test.tsx +23 -147
  165. package/src/tests/utils.test.tsx +84 -29
  166. package/src/tests/utils.ts +9 -18
  167. package/src/types.ts +187 -140
  168. package/src/utils.ts +31 -124
  169. package/build/lib/logger.d.ts +0 -8
  170. package/build/lib/logger.esm.js +0 -4
  171. package/build/lib/logger.esm.js.map +0 -1
  172. package/build/lib/logger.js +0 -8
  173. package/build/lib/logger.js.map +0 -1
  174. package/build/lib/logger.mjs +0 -4
  175. package/build/lib/logger.mjs.map +0 -1
  176. package/build/lib/logger.native.d.ts +0 -6
  177. package/build/lib/logger.native.esm.js +0 -12
  178. package/build/lib/logger.native.esm.js.map +0 -1
  179. package/build/lib/logger.native.js +0 -16
  180. package/build/lib/logger.native.js.map +0 -1
  181. package/build/lib/logger.native.mjs +0 -12
  182. package/build/lib/logger.native.mjs.map +0 -1
  183. package/src/logger.native.ts +0 -11
  184. package/src/logger.ts +0 -9
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.24.10",
3
+ "version": "5.0.0-alpha.1",
4
4
  "description": "The framework agnostic core that powers TanStack Query",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -6,26 +6,24 @@ type SetupFn = (
6
6
  ) => (() => void) | undefined
7
7
 
8
8
  export class FocusManager extends Subscribable {
9
- private focused?: boolean
10
- private cleanup?: () => void
9
+ #focused?: boolean
10
+ #cleanup?: () => void
11
11
 
12
- private setup: SetupFn
12
+ #setup: SetupFn
13
13
 
14
14
  constructor() {
15
15
  super()
16
- this.setup = (onFocus) => {
16
+ this.#setup = (onFocus) => {
17
17
  // addEventListener does not exist in React Native, but window does
18
18
  // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
19
19
  if (!isServer && window.addEventListener) {
20
20
  const listener = () => onFocus()
21
- // Listen to visibillitychange and focus
21
+ // Listen to visibilitychange
22
22
  window.addEventListener('visibilitychange', listener, false)
23
- window.addEventListener('focus', listener, false)
24
23
 
25
24
  return () => {
26
25
  // Be sure to unsubscribe if a new handler is set
27
26
  window.removeEventListener('visibilitychange', listener)
28
- window.removeEventListener('focus', listener)
29
27
  }
30
28
  }
31
29
  return
@@ -33,22 +31,22 @@ export class FocusManager extends Subscribable {
33
31
  }
34
32
 
35
33
  protected onSubscribe(): void {
36
- if (!this.cleanup) {
37
- this.setEventListener(this.setup)
34
+ if (!this.#cleanup) {
35
+ this.setEventListener(this.#setup)
38
36
  }
39
37
  }
40
38
 
41
39
  protected onUnsubscribe() {
42
40
  if (!this.hasListeners()) {
43
- this.cleanup?.()
44
- this.cleanup = undefined
41
+ this.#cleanup?.()
42
+ this.#cleanup = undefined
45
43
  }
46
44
  }
47
45
 
48
46
  setEventListener(setup: SetupFn): void {
49
- this.setup = setup
50
- this.cleanup?.()
51
- this.cleanup = setup((focused) => {
47
+ this.#setup = setup
48
+ this.#cleanup?.()
49
+ this.#cleanup = setup((focused) => {
52
50
  if (typeof focused === 'boolean') {
53
51
  this.setFocused(focused)
54
52
  } else {
@@ -58,7 +56,7 @@ export class FocusManager extends Subscribable {
58
56
  }
59
57
 
60
58
  setFocused(focused?: boolean): void {
61
- this.focused = focused
59
+ this.#focused = focused
62
60
 
63
61
  if (focused) {
64
62
  this.onFocus()
@@ -72,18 +70,13 @@ export class FocusManager extends Subscribable {
72
70
  }
73
71
 
74
72
  isFocused(): boolean {
75
- if (typeof this.focused === 'boolean') {
76
- return this.focused
73
+ if (typeof this.#focused === 'boolean') {
74
+ return this.#focused
77
75
  }
78
76
 
79
77
  // document global can be unavailable in react native
80
- if (typeof document === 'undefined') {
81
- return true
82
- }
83
-
84
- return [undefined, 'visible', 'prerender'].includes(
85
- document.visibilityState,
86
- )
78
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
79
+ return globalThis.document?.visibilityState !== 'hidden'
87
80
  }
88
81
  }
89
82
 
package/src/index.ts CHANGED
@@ -11,16 +11,7 @@ export { MutationObserver } from './mutationObserver'
11
11
  export { notifyManager } from './notifyManager'
12
12
  export { focusManager } from './focusManager'
13
13
  export { onlineManager } from './onlineManager'
14
- export {
15
- hashQueryKey,
16
- replaceEqualDeep,
17
- isError,
18
- isServer,
19
- parseQueryArgs,
20
- parseFilterArgs,
21
- parseMutationFilterArgs,
22
- parseMutationArgs,
23
- } from './utils'
14
+ export { hashKey, replaceEqualDeep, isServer, keepPreviousData } from './utils'
24
15
  export type { MutationFilters, QueryFilters, Updater } from './utils'
25
16
  export { isCancelledError } from './retryer'
26
17
  export {
@@ -34,7 +25,6 @@ export {
34
25
  export * from './types'
35
26
  export type { Query, QueryState } from './query'
36
27
  export type { Mutation } from './mutation'
37
- export type { Logger } from './logger'
38
28
  export type {
39
29
  DehydrateOptions,
40
30
  DehydratedState,
@@ -1,10 +1,10 @@
1
1
  import type { QueryBehavior } from './query'
2
-
2
+ import { addToEnd, addToStart } from './utils'
3
3
  import type {
4
4
  InfiniteData,
5
+ InfiniteQueryPageParamsOptions,
5
6
  QueryFunctionContext,
6
- QueryOptions,
7
- RefetchQueryFilters,
7
+ QueryKey,
8
8
  } from './types'
9
9
 
10
10
  export function infiniteQueryBehavior<
@@ -15,12 +15,8 @@ export function infiniteQueryBehavior<
15
15
  return {
16
16
  onFetch: (context) => {
17
17
  context.fetchFn = () => {
18
- const refetchPage: RefetchQueryFilters['refetchPage'] | undefined =
19
- context.fetchOptions?.meta?.refetchPage
20
- const fetchMore = context.fetchOptions?.meta?.fetchMore
21
- const pageParam = fetchMore?.pageParam
22
- const isFetchingNextPage = fetchMore?.direction === 'forward'
23
- const isFetchingPreviousPage = fetchMore?.direction === 'backward'
18
+ const options = context.options as InfiniteQueryPageParamsOptions<TData>
19
+ const direction = context.fetchOptions?.meta?.fetchMore?.direction
24
20
  const oldPages = context.state.data?.pages || []
25
21
  const oldPageParams = context.state.data?.pageParams || []
26
22
  let newPageParams = oldPageParams
@@ -30,10 +26,10 @@ export function infiniteQueryBehavior<
30
26
  Object.defineProperty(object, 'signal', {
31
27
  enumerable: true,
32
28
  get: () => {
33
- if (context.signal?.aborted) {
29
+ if (context.signal.aborted) {
34
30
  cancelled = true
35
31
  } else {
36
- context.signal?.addEventListener('abort', () => {
32
+ context.signal.addEventListener('abort', () => {
37
33
  cancelled = true
38
34
  })
39
35
  }
@@ -44,7 +40,8 @@ export function infiniteQueryBehavior<
44
40
 
45
41
  // Get query function
46
42
  const queryFn =
47
- context.options.queryFn || (() => Promise.reject('Missing queryFn'))
43
+ context.options.queryFn ||
44
+ (() => Promise.reject(new Error('Missing queryFn')))
48
45
 
49
46
  const buildNewPages = (
50
47
  pages: unknown[],
@@ -52,28 +49,35 @@ export function infiniteQueryBehavior<
52
49
  page: unknown,
53
50
  previous?: boolean,
54
51
  ) => {
55
- newPageParams = previous
56
- ? [param, ...newPageParams]
57
- : [...newPageParams, param]
58
- return previous ? [page, ...pages] : [...pages, page]
52
+ const { maxPages } = context.options
53
+
54
+ if (previous) {
55
+ newPageParams = addToStart(newPageParams, param, maxPages)
56
+ return addToStart(pages, page, maxPages)
57
+ }
58
+
59
+ newPageParams = addToEnd(newPageParams, param, maxPages)
60
+ return addToEnd(pages, page, maxPages)
59
61
  }
60
62
 
61
63
  // Create function to fetch a page
62
64
  const fetchPage = (
63
65
  pages: unknown[],
64
- manual?: boolean,
65
- param?: unknown,
66
+ param: unknown,
66
67
  previous?: boolean,
67
68
  ): Promise<unknown[]> => {
68
69
  if (cancelled) {
69
- return Promise.reject('Cancelled')
70
+ return Promise.reject()
70
71
  }
71
72
 
72
- if (typeof param === 'undefined' && !manual && pages.length) {
73
+ if (typeof param === 'undefined' && pages.length) {
73
74
  return Promise.resolve(pages)
74
75
  }
75
76
 
76
- const queryFnContext: QueryFunctionContext = {
77
+ const queryFnContext: Omit<
78
+ QueryFunctionContext<QueryKey, unknown>,
79
+ 'signal'
80
+ > = {
77
81
  queryKey: context.queryKey,
78
82
  pageParam: param,
79
83
  meta: context.options.meta,
@@ -81,7 +85,9 @@ export function infiniteQueryBehavior<
81
85
 
82
86
  addSignalProperty(queryFnContext)
83
87
 
84
- const queryFnResult = queryFn(queryFnContext)
88
+ const queryFnResult = queryFn(
89
+ queryFnContext as QueryFunctionContext<QueryKey, unknown>,
90
+ )
85
91
 
86
92
  const promise = Promise.resolve(queryFnResult).then((page) =>
87
93
  buildNewPages(pages, param, page, previous),
@@ -94,60 +100,30 @@ export function infiniteQueryBehavior<
94
100
 
95
101
  // Fetch first page?
96
102
  if (!oldPages.length) {
97
- promise = fetchPage([])
103
+ promise = fetchPage([], options.defaultPageParam)
98
104
  }
99
105
 
100
- // Fetch next page?
101
- else if (isFetchingNextPage) {
102
- const manual = typeof pageParam !== 'undefined'
103
- const param = manual
104
- ? pageParam
105
- : getNextPageParam(context.options, oldPages)
106
- promise = fetchPage(oldPages, manual, param)
107
- }
108
-
109
- // Fetch previous page?
110
- else if (isFetchingPreviousPage) {
111
- const manual = typeof pageParam !== 'undefined'
112
- const param = manual
113
- ? pageParam
114
- : getPreviousPageParam(context.options, oldPages)
115
- promise = fetchPage(oldPages, manual, param, true)
106
+ // fetch next / previous page?
107
+ else if (direction) {
108
+ const previous = direction === 'backward'
109
+ const param = previous
110
+ ? getPreviousPageParam(options, oldPages)
111
+ : getNextPageParam(options, oldPages)
112
+ promise = fetchPage(oldPages, param, previous)
116
113
  }
117
114
 
118
115
  // Refetch pages
119
116
  else {
120
117
  newPageParams = []
121
118
 
122
- const manual = typeof context.options.getNextPageParam === 'undefined'
123
-
124
- const shouldFetchFirstPage =
125
- refetchPage && oldPages[0]
126
- ? refetchPage(oldPages[0], 0, oldPages)
127
- : true
128
-
129
119
  // Fetch first page
130
- promise = shouldFetchFirstPage
131
- ? fetchPage([], manual, oldPageParams[0])
132
- : Promise.resolve(buildNewPages([], oldPageParams[0], oldPages[0]))
120
+ promise = fetchPage([], oldPageParams[0])
133
121
 
134
122
  // Fetch remaining pages
135
123
  for (let i = 1; i < oldPages.length; i++) {
136
124
  promise = promise.then((pages) => {
137
- const shouldFetchNextPage =
138
- refetchPage && oldPages[i]
139
- ? refetchPage(oldPages[i], i, oldPages)
140
- : true
141
-
142
- if (shouldFetchNextPage) {
143
- const param = manual
144
- ? oldPageParams[i]
145
- : getNextPageParam(context.options, pages)
146
- return fetchPage(pages, manual, param)
147
- }
148
- return Promise.resolve(
149
- buildNewPages(pages, oldPageParams[i], oldPages[i]),
150
- )
125
+ const param = getNextPageParam(options, pages)
126
+ return fetchPage(pages, param)
151
127
  })
152
128
  }
153
129
  }
@@ -163,15 +139,15 @@ export function infiniteQueryBehavior<
163
139
  }
164
140
  }
165
141
 
166
- export function getNextPageParam(
167
- options: QueryOptions<any, any>,
142
+ function getNextPageParam(
143
+ options: InfiniteQueryPageParamsOptions<any>,
168
144
  pages: unknown[],
169
145
  ): unknown | undefined {
170
- return options.getNextPageParam?.(pages[pages.length - 1], pages)
146
+ return options.getNextPageParam(pages[pages.length - 1], pages)
171
147
  }
172
148
 
173
- export function getPreviousPageParam(
174
- options: QueryOptions<any, any>,
149
+ function getPreviousPageParam(
150
+ options: InfiniteQueryPageParamsOptions<any>,
175
151
  pages: unknown[],
176
152
  ): unknown | undefined {
177
153
  return options.getPreviousPageParam?.(pages[0], pages)
@@ -179,38 +155,22 @@ export function getPreviousPageParam(
179
155
 
180
156
  /**
181
157
  * Checks if there is a next page.
182
- * Returns `undefined` if it cannot be determined.
183
158
  */
184
159
  export function hasNextPage(
185
- options: QueryOptions<any, any, any, any>,
186
- pages?: unknown,
187
- ): boolean | undefined {
188
- if (options.getNextPageParam && Array.isArray(pages)) {
189
- const nextPageParam = getNextPageParam(options, pages)
190
- return (
191
- typeof nextPageParam !== 'undefined' &&
192
- nextPageParam !== null &&
193
- nextPageParam !== false
194
- )
195
- }
196
- return
160
+ options: InfiniteQueryPageParamsOptions<any>,
161
+ pages?: unknown[],
162
+ ): boolean {
163
+ if (!pages) return false
164
+ return typeof getNextPageParam(options, pages) !== 'undefined'
197
165
  }
198
166
 
199
167
  /**
200
168
  * Checks if there is a previous page.
201
- * Returns `undefined` if it cannot be determined.
202
169
  */
203
170
  export function hasPreviousPage(
204
- options: QueryOptions<any, any, any, any>,
205
- pages?: unknown,
206
- ): boolean | undefined {
207
- if (options.getPreviousPageParam && Array.isArray(pages)) {
208
- const previousPageParam = getPreviousPageParam(options, pages)
209
- return (
210
- typeof previousPageParam !== 'undefined' &&
211
- previousPageParam !== null &&
212
- previousPageParam !== false
213
- )
214
- }
215
- return
171
+ options: InfiniteQueryPageParamsOptions<any>,
172
+ pages?: unknown[],
173
+ ): boolean {
174
+ if (!pages || !options.getPreviousPageParam) return false
175
+ return typeof getPreviousPageParam(options, pages) !== 'undefined'
216
176
  }
@@ -6,6 +6,7 @@ import type {
6
6
  InfiniteQueryObserverOptions,
7
7
  InfiniteQueryObserverResult,
8
8
  QueryKey,
9
+ RegisteredError,
9
10
  } from './types'
10
11
  import type { QueryClient } from './queryClient'
11
12
  import type { NotifyOptions, ObserverFetchOptions } from './queryObserver'
@@ -23,14 +24,14 @@ type InfiniteQueryObserverListener<TData, TError> = (
23
24
 
24
25
  export class InfiniteQueryObserver<
25
26
  TQueryFnData = unknown,
26
- TError = unknown,
27
- TData = TQueryFnData,
27
+ TError = RegisteredError,
28
+ TData = InfiniteData<TQueryFnData>,
28
29
  TQueryData = TQueryFnData,
29
30
  TQueryKey extends QueryKey = QueryKey,
30
31
  > extends QueryObserver<
31
32
  TQueryFnData,
32
33
  TError,
33
- InfiniteData<TData>,
34
+ TData,
34
35
  InfiniteData<TQueryData>,
35
36
  TQueryKey
36
37
  > {
@@ -102,27 +103,24 @@ export class InfiniteQueryObserver<
102
103
  >
103
104
  }
104
105
 
105
- fetchNextPage({ pageParam, ...options }: FetchNextPageOptions = {}): Promise<
106
- InfiniteQueryObserverResult<TData, TError>
107
- > {
106
+ fetchNextPage(
107
+ options: FetchNextPageOptions = {},
108
+ ): Promise<InfiniteQueryObserverResult<TData, TError>> {
108
109
  return this.fetch({
109
110
  ...options,
110
111
  meta: {
111
- fetchMore: { direction: 'forward', pageParam },
112
+ fetchMore: { direction: 'forward' },
112
113
  },
113
114
  })
114
115
  }
115
116
 
116
- fetchPreviousPage({
117
- pageParam,
118
- ...options
119
- }: FetchPreviousPageOptions = {}): Promise<
117
+ fetchPreviousPage({ ...options }: FetchPreviousPageOptions = {}): Promise<
120
118
  InfiniteQueryObserverResult<TData, TError>
121
119
  > {
122
120
  return this.fetch({
123
121
  ...options,
124
122
  meta: {
125
- fetchMore: { direction: 'backward', pageParam },
123
+ fetchMore: { direction: 'backward' },
126
124
  },
127
125
  })
128
126
  }