@tanstack/query-core 5.55.4 → 5.56.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 (88) hide show
  1. package/build/legacy/{hydration-BOOcDeHq.d.cts → hydration-D6canbuP.d.cts} +7 -2
  2. package/build/legacy/{hydration-DTVzC0E7.d.ts → hydration-DgUcX5FN.d.ts} +7 -2
  3. package/build/legacy/hydration.d.cts +1 -1
  4. package/build/legacy/hydration.d.ts +1 -1
  5. package/build/legacy/index.d.cts +1 -1
  6. package/build/legacy/index.d.ts +1 -1
  7. package/build/legacy/infiniteQueryBehavior.cjs +14 -17
  8. package/build/legacy/infiniteQueryBehavior.cjs.map +1 -1
  9. package/build/legacy/infiniteQueryBehavior.d.cts +1 -1
  10. package/build/legacy/infiniteQueryBehavior.d.ts +1 -1
  11. package/build/legacy/infiniteQueryBehavior.js +14 -17
  12. package/build/legacy/infiniteQueryBehavior.js.map +1 -1
  13. package/build/legacy/infiniteQueryObserver.d.cts +1 -1
  14. package/build/legacy/infiniteQueryObserver.d.ts +1 -1
  15. package/build/legacy/mutation.d.cts +1 -1
  16. package/build/legacy/mutation.d.ts +1 -1
  17. package/build/legacy/mutationCache.d.cts +1 -1
  18. package/build/legacy/mutationCache.d.ts +1 -1
  19. package/build/legacy/mutationObserver.d.cts +1 -1
  20. package/build/legacy/mutationObserver.d.ts +1 -1
  21. package/build/legacy/queriesObserver.d.cts +1 -1
  22. package/build/legacy/queriesObserver.d.ts +1 -1
  23. package/build/legacy/query.d.cts +1 -1
  24. package/build/legacy/query.d.ts +1 -1
  25. package/build/legacy/queryCache.d.cts +1 -1
  26. package/build/legacy/queryCache.d.ts +1 -1
  27. package/build/legacy/queryClient.cjs +4 -0
  28. package/build/legacy/queryClient.cjs.map +1 -1
  29. package/build/legacy/queryClient.d.cts +1 -1
  30. package/build/legacy/queryClient.d.ts +1 -1
  31. package/build/legacy/queryClient.js +4 -0
  32. package/build/legacy/queryClient.js.map +1 -1
  33. package/build/legacy/queryObserver.d.cts +1 -1
  34. package/build/legacy/queryObserver.d.ts +1 -1
  35. package/build/legacy/retryer.d.cts +1 -1
  36. package/build/legacy/retryer.d.ts +1 -1
  37. package/build/legacy/types.cjs.map +1 -1
  38. package/build/legacy/types.d.cts +1 -1
  39. package/build/legacy/types.d.ts +1 -1
  40. package/build/legacy/utils.d.cts +1 -1
  41. package/build/legacy/utils.d.ts +1 -1
  42. package/build/modern/{hydration-BOOcDeHq.d.cts → hydration-D6canbuP.d.cts} +7 -2
  43. package/build/modern/{hydration-DTVzC0E7.d.ts → hydration-DgUcX5FN.d.ts} +7 -2
  44. package/build/modern/hydration.d.cts +1 -1
  45. package/build/modern/hydration.d.ts +1 -1
  46. package/build/modern/index.d.cts +1 -1
  47. package/build/modern/index.d.ts +1 -1
  48. package/build/modern/infiniteQueryBehavior.cjs +10 -13
  49. package/build/modern/infiniteQueryBehavior.cjs.map +1 -1
  50. package/build/modern/infiniteQueryBehavior.d.cts +1 -1
  51. package/build/modern/infiniteQueryBehavior.d.ts +1 -1
  52. package/build/modern/infiniteQueryBehavior.js +10 -13
  53. package/build/modern/infiniteQueryBehavior.js.map +1 -1
  54. package/build/modern/infiniteQueryObserver.d.cts +1 -1
  55. package/build/modern/infiniteQueryObserver.d.ts +1 -1
  56. package/build/modern/mutation.d.cts +1 -1
  57. package/build/modern/mutation.d.ts +1 -1
  58. package/build/modern/mutationCache.d.cts +1 -1
  59. package/build/modern/mutationCache.d.ts +1 -1
  60. package/build/modern/mutationObserver.d.cts +1 -1
  61. package/build/modern/mutationObserver.d.ts +1 -1
  62. package/build/modern/queriesObserver.d.cts +1 -1
  63. package/build/modern/queriesObserver.d.ts +1 -1
  64. package/build/modern/query.d.cts +1 -1
  65. package/build/modern/query.d.ts +1 -1
  66. package/build/modern/queryCache.d.cts +1 -1
  67. package/build/modern/queryCache.d.ts +1 -1
  68. package/build/modern/queryClient.cjs +4 -0
  69. package/build/modern/queryClient.cjs.map +1 -1
  70. package/build/modern/queryClient.d.cts +1 -1
  71. package/build/modern/queryClient.d.ts +1 -1
  72. package/build/modern/queryClient.js +4 -0
  73. package/build/modern/queryClient.js.map +1 -1
  74. package/build/modern/queryObserver.d.cts +1 -1
  75. package/build/modern/queryObserver.d.ts +1 -1
  76. package/build/modern/retryer.d.cts +1 -1
  77. package/build/modern/retryer.d.ts +1 -1
  78. package/build/modern/types.cjs.map +1 -1
  79. package/build/modern/types.d.cts +1 -1
  80. package/build/modern/types.d.ts +1 -1
  81. package/build/modern/utils.d.cts +1 -1
  82. package/build/modern/utils.d.ts +1 -1
  83. package/package.json +1 -1
  84. package/src/__tests__/infiniteQueryBehavior.test.tsx +74 -1
  85. package/src/__tests__/queryClient.test.tsx +63 -0
  86. package/src/infiniteQueryBehavior.ts +15 -18
  87. package/src/queryClient.ts +28 -2
  88. package/src/types.ts +26 -6
@@ -13,13 +13,13 @@ import { focusManager } from './focusManager'
13
13
  import { onlineManager } from './onlineManager'
14
14
  import { notifyManager } from './notifyManager'
15
15
  import { infiniteQueryBehavior } from './infiniteQueryBehavior'
16
- import type { QueryState } from './query'
17
16
  import type {
18
17
  CancelOptions,
19
18
  DataTag,
20
19
  DefaultError,
21
20
  DefaultOptions,
22
21
  DefaultedQueryObserverOptions,
22
+ EnsureInfiniteQueryDataOptions,
23
23
  EnsureQueryDataOptions,
24
24
  FetchInfiniteQueryOptions,
25
25
  FetchQueryOptions,
@@ -40,6 +40,7 @@ import type {
40
40
  ResetOptions,
41
41
  SetDataOptions,
42
42
  } from './types'
43
+ import type { QueryState } from './query'
43
44
  import type { MutationFilters, QueryFilters, Updater } from './utils'
44
45
 
45
46
  // TYPES
@@ -385,7 +386,7 @@ export class QueryClient {
385
386
  TData,
386
387
  TPageParam
387
388
  >(options.pages)
388
- return this.fetchQuery(options)
389
+ return this.fetchQuery(options as any)
389
390
  }
390
391
 
391
392
  prefetchInfiniteQuery<
@@ -406,6 +407,31 @@ export class QueryClient {
406
407
  return this.fetchInfiniteQuery(options).then(noop).catch(noop)
407
408
  }
408
409
 
410
+ ensureInfiniteQueryData<
411
+ TQueryFnData,
412
+ TError = DefaultError,
413
+ TData = TQueryFnData,
414
+ TQueryKey extends QueryKey = QueryKey,
415
+ TPageParam = unknown,
416
+ >(
417
+ options: EnsureInfiniteQueryDataOptions<
418
+ TQueryFnData,
419
+ TError,
420
+ TData,
421
+ TQueryKey,
422
+ TPageParam
423
+ >,
424
+ ): Promise<InfiniteData<TData, TPageParam>> {
425
+ options.behavior = infiniteQueryBehavior<
426
+ TQueryFnData,
427
+ TError,
428
+ TData,
429
+ TPageParam
430
+ >(options.pages)
431
+
432
+ return this.ensureQueryData(options as any)
433
+ }
434
+
409
435
  resumePausedMutations(): Promise<unknown> {
410
436
  if (onlineManager.isOnline()) {
411
437
  return this.#mutationCache.resumePausedMutations()
package/src/types.ts CHANGED
@@ -448,6 +448,7 @@ export interface FetchQueryOptions<
448
448
  QueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>,
449
449
  'queryKey'
450
450
  > {
451
+ initialPageParam?: never
451
452
  /**
452
453
  * The time in milliseconds after data is considered stale.
453
454
  * If the data is fresh it will be returned from the cache.
@@ -471,6 +472,22 @@ export interface EnsureQueryDataOptions<
471
472
  revalidateIfStale?: boolean
472
473
  }
473
474
 
475
+ export type EnsureInfiniteQueryDataOptions<
476
+ TQueryFnData = unknown,
477
+ TError = DefaultError,
478
+ TData = TQueryFnData,
479
+ TQueryKey extends QueryKey = QueryKey,
480
+ TPageParam = unknown,
481
+ > = FetchInfiniteQueryOptions<
482
+ TQueryFnData,
483
+ TError,
484
+ TData,
485
+ TQueryKey,
486
+ TPageParam
487
+ > & {
488
+ revalidateIfStale?: boolean
489
+ }
490
+
474
491
  type FetchInfiniteQueryPages<TQueryFnData = unknown, TPageParam = unknown> =
475
492
  | { pages?: never }
476
493
  | {
@@ -484,12 +501,15 @@ export type FetchInfiniteQueryOptions<
484
501
  TData = TQueryFnData,
485
502
  TQueryKey extends QueryKey = QueryKey,
486
503
  TPageParam = unknown,
487
- > = FetchQueryOptions<
488
- TQueryFnData,
489
- TError,
490
- InfiniteData<TData, TPageParam>,
491
- TQueryKey,
492
- TPageParam
504
+ > = Omit<
505
+ FetchQueryOptions<
506
+ TQueryFnData,
507
+ TError,
508
+ InfiniteData<TData, TPageParam>,
509
+ TQueryKey,
510
+ TPageParam
511
+ >,
512
+ 'initialPageParam'
493
513
  > &
494
514
  InitialPageParam<TPageParam> &
495
515
  FetchInfiniteQueryPages<TQueryFnData, TPageParam>