@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
@@ -1,10 +1,4 @@
1
- import {
2
- sleep,
3
- queryKey,
4
- expectType,
5
- mockLogger,
6
- createQueryClient,
7
- } from './utils'
1
+ import { sleep, queryKey, expectType, createQueryClient } from './utils'
8
2
  import type { QueryClient, QueryObserverResult } from '..'
9
3
  import { QueryObserver, focusManager } from '..'
10
4
 
@@ -46,9 +40,9 @@ describe('queryObserver', () => {
46
40
  await sleep(1)
47
41
  unsubscribe()
48
42
  expect(results.length).toBe(4)
49
- expect(results[0]).toMatchObject({ data: undefined, status: 'loading' })
43
+ expect(results[0]).toMatchObject({ data: undefined, status: 'pending' })
50
44
  expect(results[1]).toMatchObject({ data: 1, status: 'success' })
51
- expect(results[2]).toMatchObject({ data: undefined, status: 'loading' })
45
+ expect(results[2]).toMatchObject({ data: undefined, status: 'pending' })
52
46
  expect(results[3]).toMatchObject({ data: 2, status: 'success' })
53
47
  })
54
48
 
@@ -148,7 +142,7 @@ describe('queryObserver', () => {
148
142
  expect(count).toBe(2)
149
143
  expect(results.length).toBe(5)
150
144
  expect(results[0]).toMatchObject({
151
- status: 'loading',
145
+ status: 'pending',
152
146
  isFetching: true,
153
147
  data: undefined,
154
148
  })
@@ -203,7 +197,7 @@ describe('queryObserver', () => {
203
197
  expect(count).toBe(1)
204
198
  expect(results.length).toBe(4)
205
199
  expect(results[0]).toMatchObject({
206
- status: 'loading',
200
+ status: 'pending',
207
201
  isFetching: true,
208
202
  data: undefined,
209
203
  })
@@ -263,7 +257,7 @@ describe('queryObserver', () => {
263
257
  await observer.refetch()
264
258
  unsubscribe()
265
259
  expect(results[0]).toMatchObject({
266
- status: 'loading',
260
+ status: 'pending',
267
261
  isFetching: true,
268
262
  data: undefined,
269
263
  })
@@ -313,7 +307,7 @@ describe('queryObserver', () => {
313
307
  unsubscribe()
314
308
 
315
309
  expect(results[0]).toMatchObject({
316
- status: 'loading',
310
+ status: 'pending',
317
311
  isFetching: true,
318
312
  data: undefined,
319
313
  error: null,
@@ -383,7 +377,7 @@ describe('queryObserver', () => {
383
377
  enabled: false,
384
378
  })
385
379
  const unsubscribe = observer.subscribe(callback)
386
- await queryClient.fetchQuery(key, queryFn)
380
+ await queryClient.fetchQuery({ queryKey: key, queryFn })
387
381
  unsubscribe()
388
382
  expect(queryFn).toHaveBeenCalledTimes(1)
389
383
  expect(callback).toHaveBeenCalledTimes(2)
@@ -401,7 +395,7 @@ describe('queryObserver', () => {
401
395
  results.push(x)
402
396
  })
403
397
  observer.setOptions({ enabled: false, staleTime: 10 })
404
- await queryClient.fetchQuery(key, queryFn)
398
+ await queryClient.fetchQuery({ queryKey: key, queryFn })
405
399
  await sleep(100)
406
400
  unsubscribe()
407
401
  expect(queryFn).toHaveBeenCalledTimes(1)
@@ -426,7 +420,7 @@ describe('queryObserver', () => {
426
420
  const unsubscribe2 = observer.subscribe((x) => {
427
421
  results2.push(x)
428
422
  })
429
- await queryClient.fetchQuery(key, queryFn)
423
+ await queryClient.fetchQuery({ queryKey: key, queryFn })
430
424
  await sleep(50)
431
425
  unsubscribe1()
432
426
  unsubscribe2()
@@ -460,25 +454,29 @@ describe('queryObserver', () => {
460
454
 
461
455
  test('should clear interval when unsubscribing to a refetchInterval query', async () => {
462
456
  const key = queryKey()
457
+ let count = 0
463
458
 
464
- const fetchData = () => Promise.resolve('data')
459
+ const fetchData = () => {
460
+ count++
461
+ return Promise.resolve('data')
462
+ }
465
463
  const observer = new QueryObserver(queryClient, {
466
464
  queryKey: key,
467
465
  queryFn: fetchData,
468
- cacheTime: 0,
469
- refetchInterval: 1,
466
+ gcTime: 0,
467
+ refetchInterval: 10,
470
468
  })
471
469
  const unsubscribe = observer.subscribe(() => undefined)
472
- // @ts-expect-error
473
- expect(observer.refetchIntervalId).not.toBeUndefined()
470
+ expect(count).toBe(1)
471
+ await sleep(15)
472
+ expect(count).toBe(2)
474
473
  unsubscribe()
475
- // @ts-expect-error
476
- expect(observer.refetchIntervalId).toBeUndefined()
477
474
  await sleep(10)
478
- expect(queryClient.getQueryCache().find(key)).toBeUndefined()
475
+ expect(queryClient.getQueryCache().find({ queryKey: key })).toBeUndefined()
476
+ expect(count).toBe(2)
479
477
  })
480
478
 
481
- test('uses placeholderData as non-cache data when loading a query with no data', async () => {
479
+ test('uses placeholderData as non-cache data when pending a query with no data', async () => {
482
480
  const key = queryKey()
483
481
  const observer = new QueryObserver(queryClient, {
484
482
  queryKey: key,
@@ -523,36 +521,6 @@ describe('queryObserver', () => {
523
521
  expect(firstData).toBe(secondData)
524
522
  })
525
523
 
526
- test('the retrier should not throw an error when reject if the retrier is already resolved', async () => {
527
- const key = queryKey()
528
- let count = 0
529
-
530
- const observer = new QueryObserver(queryClient, {
531
- queryKey: key,
532
- queryFn: () => {
533
- count++
534
- return Promise.reject<unknown>(`reject ${count}`)
535
- },
536
- retry: 1,
537
- retryDelay: 20,
538
- })
539
-
540
- const unsubscribe = observer.subscribe(() => undefined)
541
-
542
- // Simulate a race condition when an unsubscribe and a retry occur.
543
- await sleep(20)
544
- unsubscribe()
545
-
546
- // A second reject is triggered for the retry
547
- // but the retryer has already set isResolved to true
548
- // so it does nothing and no error is thrown
549
-
550
- // Should not log an error
551
- queryClient.clear()
552
- await sleep(40)
553
- expect(mockLogger.error).not.toHaveBeenNthCalledWith(1, 'reject 1')
554
- })
555
-
556
524
  test('should throw an error if enabled option type is not valid', async () => {
557
525
  const key = queryKey()
558
526
 
@@ -649,50 +617,6 @@ describe('queryObserver', () => {
649
617
  unsubscribe()
650
618
  })
651
619
 
652
- test('should prefer isDataEqual to structuralSharing', async () => {
653
- const key = queryKey()
654
-
655
- const data = { value: 'data' }
656
- const newData = { value: 'data' }
657
-
658
- const observer = new QueryObserver(queryClient, {
659
- queryKey: key,
660
- queryFn: () => data,
661
- })
662
-
663
- const unsubscribe = observer.subscribe(() => undefined)
664
-
665
- await sleep(10)
666
- expect(observer.getCurrentResult().data).toBe(data)
667
-
668
- observer.setOptions({
669
- queryKey: key,
670
- queryFn: () => newData,
671
- isDataEqual: () => true,
672
- structuralSharing: false,
673
- })
674
-
675
- await observer.refetch()
676
- expect(observer.getCurrentResult().data).toBe(data)
677
-
678
- unsubscribe()
679
- })
680
-
681
- test('select function error using placeholderdata should log an error', () => {
682
- const key = queryKey()
683
-
684
- new QueryObserver(queryClient, {
685
- queryKey: key,
686
- queryFn: () => 'data',
687
- placeholderData: 'placeholderdata',
688
- select: () => {
689
- throw new Error('error')
690
- },
691
- })
692
-
693
- expect(mockLogger.error).toHaveBeenNthCalledWith(2, new Error('error'))
694
- })
695
-
696
620
  test('should not use replaceEqualDeep for select value when structuralSharing option is true and placeholderdata is defined', () => {
697
621
  const key = queryKey()
698
622
 
@@ -766,54 +690,6 @@ describe('queryObserver', () => {
766
690
  expect(observer.getCurrentResult().isPlaceholderData).toBe(false)
767
691
  })
768
692
 
769
- test('updateResult should not notify cache listeners if cache option is false', async () => {
770
- const key = queryKey()
771
-
772
- const data1 = { value: 'data 1' }
773
- const data2 = { value: 'data 2' }
774
-
775
- await queryClient.prefetchQuery(key, () => data1)
776
- const observer = new QueryObserver(queryClient, {
777
- queryKey: key,
778
- })
779
- await queryClient.prefetchQuery(key, () => data2)
780
-
781
- const spy = jest.fn()
782
- const unsubscribe = queryClient.getQueryCache().subscribe(spy)
783
- observer.updateResult({ cache: false })
784
-
785
- expect(spy).toHaveBeenCalledTimes(0)
786
-
787
- unsubscribe()
788
- })
789
-
790
- test('should not notify observer when the stale timeout expires and the current result is stale', async () => {
791
- const key = queryKey()
792
- const queryFn = () => 'data'
793
-
794
- await queryClient.prefetchQuery(key, queryFn)
795
- const observer = new QueryObserver(queryClient, {
796
- queryKey: key,
797
- queryFn,
798
- staleTime: 20,
799
- })
800
-
801
- const spy = jest.fn()
802
- const unsubscribe = observer.subscribe(spy)
803
- await queryClient.refetchQueries(key)
804
- await sleep(10)
805
-
806
- // Force isStale to true
807
- // because no use case has been found to reproduce this condition
808
- // @ts-ignore
809
- observer['currentResult'].isStale = true
810
- spy.mockReset()
811
- await sleep(30)
812
- expect(spy).not.toHaveBeenCalled()
813
-
814
- unsubscribe()
815
- })
816
-
817
693
  test('setOptions should notify cache listeners', async () => {
818
694
  const key = queryKey()
819
695
 
@@ -1,12 +1,13 @@
1
1
  import {
2
2
  replaceEqualDeep,
3
- partialDeepEqual,
3
+ partialMatchKey,
4
4
  isPlainObject,
5
- parseMutationArgs,
6
5
  matchMutation,
7
6
  scheduleMicrotask,
8
7
  sleep,
9
8
  isPlainArray,
9
+ addToEnd,
10
+ addToStart,
10
11
  } from '../utils'
11
12
  import { Mutation } from '../mutation'
12
13
  import { createQueryClient } from './utils'
@@ -67,47 +68,47 @@ describe('core/utils', () => {
67
68
  })
68
69
  })
69
70
 
70
- describe('partialDeepEqual', () => {
71
+ describe('partialMatchKey', () => {
71
72
  it('should return `true` if a includes b', () => {
72
- const a = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
73
- const b = { a: { b: 'b' }, c: 'c', d: [] }
74
- expect(partialDeepEqual(a, b)).toEqual(true)
73
+ const a = [{ a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }]
74
+ const b = [{ a: { b: 'b' }, c: 'c', d: [] }]
75
+ expect(partialMatchKey(a, b)).toEqual(true)
75
76
  })
76
77
 
77
78
  it('should return `false` if a does not include b', () => {
78
- const a = { a: { b: 'b' }, c: 'c', d: [] }
79
- const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
80
- expect(partialDeepEqual(a, b)).toEqual(false)
79
+ const a = [{ a: { b: 'b' }, c: 'c', d: [] }]
80
+ const b = [{ a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }]
81
+ expect(partialMatchKey(a, b)).toEqual(false)
81
82
  })
82
83
 
83
84
  it('should return `true` if array a includes array b', () => {
84
85
  const a = [1, 2, 3]
85
86
  const b = [1, 2]
86
- expect(partialDeepEqual(a, b)).toEqual(true)
87
+ expect(partialMatchKey(a, b)).toEqual(true)
87
88
  })
88
89
 
89
90
  it('should return `false` if a is null and b is not', () => {
90
- const a = null
91
- const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
92
- expect(partialDeepEqual(a, b)).toEqual(false)
91
+ const a = [null]
92
+ const b = [{ a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }]
93
+ expect(partialMatchKey(a, b)).toEqual(false)
93
94
  })
94
95
 
95
96
  it('should return `false` if a contains null and b is not', () => {
96
- const a = { a: null, c: 'c', d: [] }
97
- const b = { a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }
98
- expect(partialDeepEqual(a, b)).toEqual(false)
97
+ const a = [{ a: null, c: 'c', d: [] }]
98
+ const b = [{ a: { b: 'b' }, c: 'c', d: [{ d: 'd ' }] }]
99
+ expect(partialMatchKey(a, b)).toEqual(false)
99
100
  })
100
101
 
101
102
  it('should return `false` if b is null and a is not', () => {
102
- const a = { a: { b: 'b' }, c: 'c', d: [] }
103
- const b = null
104
- expect(partialDeepEqual(a, b)).toEqual(false)
103
+ const a = [{ a: { b: 'b' }, c: 'c', d: [] }]
104
+ const b = [null]
105
+ expect(partialMatchKey(a, b)).toEqual(false)
105
106
  })
106
107
 
107
108
  it('should return `false` if b contains null and a is not', () => {
108
- const a = { a: { b: 'b' }, c: 'c', d: [] }
109
- const b = { a: null, c: 'c', d: [{ d: 'd ' }] }
110
- expect(partialDeepEqual(a, b)).toEqual(false)
109
+ const a = [{ a: { b: 'b' }, c: 'c', d: [] }]
110
+ const b = [{ a: null, c: 'c', d: [{ d: 'd ' }] }]
111
+ expect(partialMatchKey(a, b)).toEqual(false)
111
112
  })
112
113
  })
113
114
 
@@ -327,13 +328,6 @@ describe('core/utils', () => {
327
328
  })
328
329
  })
329
330
 
330
- describe('parseMutationArgs', () => {
331
- it('should return mutation options', () => {
332
- const options = { mutationKey: ['key'] }
333
- expect(parseMutationArgs(options)).toMatchObject(options)
334
- })
335
- })
336
-
337
331
  describe('matchMutation', () => {
338
332
  it('should return false if mutationKey options is undefined', () => {
339
333
  const filters = { mutationKey: ['key1'] }
@@ -357,4 +351,65 @@ describe('core/utils', () => {
357
351
  expect(callback).toHaveBeenCalledTimes(1)
358
352
  })
359
353
  })
354
+
355
+ describe('addToEnd', () => {
356
+ it('should add item to the end of the array', () => {
357
+ const items = [1, 2, 3]
358
+ const newItems = addToEnd(items, 4)
359
+ expect(newItems).toEqual([1, 2, 3, 4])
360
+ })
361
+
362
+ it('should not exceed max if provided', () => {
363
+ const items = [1, 2, 3]
364
+ const newItems = addToEnd(items, 4, 3)
365
+ expect(newItems).toEqual([2, 3, 4])
366
+ })
367
+
368
+ it('should add item to the end of the array when max = 0', () => {
369
+ const items = [1, 2, 3]
370
+ const item = 4
371
+ const max = 0
372
+ expect(addToEnd(items, item, max)).toEqual([1, 2, 3, 4])
373
+ })
374
+
375
+ it('should add item to the end of the array when max is undefined', () => {
376
+ const items = [1, 2, 3]
377
+ const item = 4
378
+ const max = undefined
379
+ expect(addToEnd(items, item, max)).toEqual([1, 2, 3, 4])
380
+ })
381
+ })
382
+
383
+ describe('addToStart', () => {
384
+ it('should add an item to the start of the array', () => {
385
+ const items = [1, 2, 3]
386
+ const item = 4
387
+ const newItems = addToStart(items, item)
388
+ expect(newItems).toEqual([4, 1, 2, 3])
389
+ })
390
+
391
+ it('should respect the max argument', () => {
392
+ const items = [1, 2, 3]
393
+ const item = 4
394
+ const max = 2
395
+ const newItems = addToStart(items, item, max)
396
+ expect(newItems).toEqual([4, 1, 2])
397
+ })
398
+
399
+ it('should not remove any items if max = 0', () => {
400
+ const items = [1, 2, 3]
401
+ const item = 4
402
+ const max = 0
403
+ const newItems = addToStart(items, item, max)
404
+ expect(newItems).toEqual([4, 1, 2, 3])
405
+ })
406
+
407
+ it('should not remove any items if max is undefined', () => {
408
+ const items = [1, 2, 3]
409
+ const item = 4
410
+ const max = 0
411
+ const newItems = addToStart(items, item, max)
412
+ expect(newItems).toEqual([4, 1, 2, 3])
413
+ })
414
+ })
360
415
  })
@@ -5,8 +5,7 @@ import { QueryClient } from '@tanstack/query-core'
5
5
  import * as utils from '../utils'
6
6
 
7
7
  export function createQueryClient(config?: QueryClientConfig): QueryClient {
8
- jest.spyOn(console, 'error').mockImplementation(() => undefined)
9
- return new QueryClient({ logger: mockLogger, ...config })
8
+ return new QueryClient(config)
10
9
  }
11
10
 
12
11
  export function mockVisibilityState(value: DocumentVisibilityState) {
@@ -17,12 +16,6 @@ export function mockNavigatorOnLine(value: boolean) {
17
16
  return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
18
17
  }
19
18
 
20
- export const mockLogger = {
21
- log: jest.fn(),
22
- warn: jest.fn(),
23
- error: jest.fn(),
24
- }
25
-
26
19
  let queryKeyCount = 0
27
20
  export function queryKey(): Array<string> {
28
21
  queryKeyCount++
@@ -48,17 +41,15 @@ export function setActTimeout(fn: () => void, ms?: number) {
48
41
  */
49
42
  export const expectType = <T>(_: T): void => undefined
50
43
 
51
- /**
52
- * Assert the parameter is not typed as `any`
53
- */
54
- export const expectTypeNotAny = <T>(_: 0 extends 1 & T ? never : T): void =>
55
- undefined
56
-
57
- export const executeMutation = (
44
+ export const executeMutation = <TVariables>(
58
45
  queryClient: QueryClient,
59
- options: MutationOptions<any, any, any, any>,
60
- ): Promise<unknown> => {
61
- return queryClient.getMutationCache().build(queryClient, options).execute()
46
+ options: MutationOptions<any, any, TVariables, any>,
47
+ variables: TVariables,
48
+ ) => {
49
+ return queryClient
50
+ .getMutationCache()
51
+ .build(queryClient, options)
52
+ .execute(variables)
62
53
  }
63
54
 
64
55
  // This monkey-patches the isServer-value from utils,