@tanstack/query-core 4.3.4 → 4.3.7

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 (84) hide show
  1. package/build/lib/focusManager.esm.js +86 -0
  2. package/build/lib/focusManager.esm.js.map +1 -0
  3. package/build/lib/hydration.esm.js +97 -0
  4. package/build/lib/hydration.esm.js.map +1 -0
  5. package/build/lib/index.d.ts +1 -1
  6. package/build/lib/index.esm.js +14 -0
  7. package/build/lib/index.esm.js.map +1 -0
  8. package/build/lib/index.js +1 -0
  9. package/build/lib/index.js.map +1 -1
  10. package/build/lib/index.mjs +1 -1
  11. package/build/lib/infiniteQueryBehavior.esm.js +142 -0
  12. package/build/lib/infiniteQueryBehavior.esm.js.map +1 -0
  13. package/build/lib/infiniteQueryObserver.esm.js +78 -0
  14. package/build/lib/infiniteQueryObserver.esm.js.map +1 -0
  15. package/build/lib/logger.esm.js +4 -0
  16. package/build/lib/logger.esm.js.map +1 -0
  17. package/build/lib/logger.native.esm.js +12 -0
  18. package/build/lib/logger.native.esm.js.map +1 -0
  19. package/build/lib/mutation.esm.js +243 -0
  20. package/build/lib/mutation.esm.js.map +1 -0
  21. package/build/lib/mutationCache.esm.js +85 -0
  22. package/build/lib/mutationCache.esm.js.map +1 -0
  23. package/build/lib/mutationObserver.esm.js +126 -0
  24. package/build/lib/mutationObserver.esm.js.map +1 -0
  25. package/build/lib/notifyManager.esm.js +99 -0
  26. package/build/lib/notifyManager.esm.js.map +1 -0
  27. package/build/lib/onlineManager.esm.js +85 -0
  28. package/build/lib/onlineManager.esm.js.map +1 -0
  29. package/build/lib/queriesObserver.esm.js +156 -0
  30. package/build/lib/queriesObserver.esm.js.map +1 -0
  31. package/build/lib/query.esm.js +460 -0
  32. package/build/lib/query.esm.js.map +1 -0
  33. package/build/lib/queryCache.esm.js +126 -0
  34. package/build/lib/queryCache.esm.js.map +1 -0
  35. package/build/lib/queryClient.esm.js +339 -0
  36. package/build/lib/queryClient.esm.js.map +1 -0
  37. package/build/lib/queryObserver.esm.js +515 -0
  38. package/build/lib/queryObserver.esm.js.map +1 -0
  39. package/build/lib/removable.esm.js +33 -0
  40. package/build/lib/removable.esm.js.map +1 -0
  41. package/build/lib/retryer.esm.js +160 -0
  42. package/build/lib/retryer.esm.js.map +1 -0
  43. package/build/lib/subscribable.esm.js +29 -0
  44. package/build/lib/subscribable.esm.js.map +1 -0
  45. package/build/lib/tests/focusManager.test.d.ts +1 -0
  46. package/build/lib/tests/hydration.test.d.ts +1 -0
  47. package/build/lib/tests/infiniteQueryBehavior.test.d.ts +1 -0
  48. package/build/lib/tests/infiniteQueryObserver.test.d.ts +1 -0
  49. package/build/lib/tests/mutationCache.test.d.ts +1 -0
  50. package/build/lib/tests/mutationObserver.test.d.ts +1 -0
  51. package/build/lib/tests/mutations.test.d.ts +1 -0
  52. package/build/lib/tests/notifyManager.test.d.ts +1 -0
  53. package/build/lib/tests/onlineManager.test.d.ts +1 -0
  54. package/build/lib/tests/queriesObserver.test.d.ts +1 -0
  55. package/build/lib/tests/query.test.d.ts +1 -0
  56. package/build/lib/tests/queryCache.test.d.ts +1 -0
  57. package/build/lib/tests/queryClient.test.d.ts +1 -0
  58. package/build/lib/tests/queryObserver.test.d.ts +1 -0
  59. package/build/lib/tests/utils.d.ts +24 -0
  60. package/build/lib/tests/utils.test.d.ts +1 -0
  61. package/build/lib/utils.esm.js +318 -0
  62. package/build/lib/utils.esm.js.map +1 -0
  63. package/build/umd/index.development.js +1 -0
  64. package/build/umd/index.development.js.map +1 -1
  65. package/build/umd/index.production.js +1 -1
  66. package/build/umd/index.production.js.map +1 -1
  67. package/package.json +2 -1
  68. package/src/index.ts +1 -0
  69. package/src/tests/focusManager.test.tsx +1 -1
  70. package/src/tests/hydration.test.tsx +1 -1
  71. package/src/tests/infiniteQueryBehavior.test.tsx +1 -1
  72. package/src/tests/infiniteQueryObserver.test.tsx +1 -1
  73. package/src/tests/mutationCache.test.tsx +1 -6
  74. package/src/tests/mutationObserver.test.tsx +1 -1
  75. package/src/tests/mutations.test.tsx +1 -6
  76. package/src/tests/notifyManager.test.tsx +1 -1
  77. package/src/tests/onlineManager.test.tsx +1 -1
  78. package/src/tests/queriesObserver.test.tsx +1 -6
  79. package/src/tests/query.test.tsx +1 -1
  80. package/src/tests/queryCache.test.tsx +1 -1
  81. package/src/tests/queryClient.test.tsx +1 -6
  82. package/src/tests/queryObserver.test.tsx +1 -1
  83. package/src/tests/utils.test.tsx +1 -1
  84. package/src/tests/utils.ts +78 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.3.4",
3
+ "version": "4.3.7",
4
4
  "description": "TODO",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "types": "build/lib/index.d.ts",
14
14
  "main": "build/lib/index.js",
15
+ "module": "build/lib/index.esm.js",
15
16
  "exports": {
16
17
  ".": {
17
18
  "types": "./build/lib/index.d.ts",
package/src/index.ts CHANGED
@@ -12,6 +12,7 @@ export { onlineManager } from './onlineManager'
12
12
  export {
13
13
  hashQueryKey,
14
14
  isError,
15
+ isServer,
15
16
  parseQueryArgs,
16
17
  parseFilterArgs,
17
18
  parseMutationFilterArgs,
@@ -1,6 +1,6 @@
1
1
  import { sleep } from '../utils'
2
2
  import { FocusManager } from '../focusManager'
3
- import { setIsServer } from '../../../../tests/utils'
3
+ import { setIsServer } from './utils'
4
4
 
5
5
  describe('focusManager', () => {
6
6
  let focusManager: FocusManager
@@ -3,7 +3,7 @@ import {
3
3
  executeMutation,
4
4
  mockNavigatorOnLine,
5
5
  sleep,
6
- } from '../../../../tests/utils'
6
+ } from './utils'
7
7
  import { QueryCache } from '../queryCache'
8
8
  import { dehydrate, hydrate } from '../hydration'
9
9
 
@@ -4,7 +4,7 @@ import {
4
4
  InfiniteQueryObserver,
5
5
  InfiniteQueryObserverResult,
6
6
  } from '@tanstack/query-core'
7
- import { createQueryClient, queryKey } from '../../../../tests/utils'
7
+ import { createQueryClient, queryKey } from './utils'
8
8
 
9
9
  describe('InfiniteQueryBehavior', () => {
10
10
  let queryClient: QueryClient
@@ -1,4 +1,4 @@
1
- import { createQueryClient, queryKey, sleep } from '../../../../tests/utils'
1
+ import { createQueryClient, queryKey, sleep } from './utils'
2
2
  import { QueryClient, InfiniteQueryObserver } from '..'
3
3
 
4
4
  describe('InfiniteQueryObserver', () => {
@@ -1,10 +1,5 @@
1
1
  import { waitFor } from '@testing-library/react'
2
- import {
3
- queryKey,
4
- sleep,
5
- executeMutation,
6
- createQueryClient,
7
- } from '../../../../tests/utils'
2
+ import { queryKey, sleep, executeMutation, createQueryClient } from './utils'
8
3
  import { MutationCache, MutationObserver } from '..'
9
4
 
10
5
  describe('mutationCache', () => {
@@ -1,5 +1,5 @@
1
1
  import { waitFor } from '@testing-library/react'
2
- import { createQueryClient, sleep } from '../../../../tests/utils'
2
+ import { createQueryClient, sleep } from './utils'
3
3
  import { QueryClient, MutationObserver } from '..'
4
4
 
5
5
  describe('mutationObserver', () => {
@@ -1,10 +1,5 @@
1
1
  import { QueryClient } from '..'
2
- import {
3
- createQueryClient,
4
- executeMutation,
5
- queryKey,
6
- sleep,
7
- } from '../../../../tests/utils'
2
+ import { createQueryClient, executeMutation, queryKey, sleep } from './utils'
8
3
  import { MutationState } from '../mutation'
9
4
  import { MutationObserver } from '../mutationObserver'
10
5
 
@@ -1,5 +1,5 @@
1
1
  import { createNotifyManager } from '../notifyManager'
2
- import { sleep } from '../../../../tests/utils'
2
+ import { sleep } from './utils'
3
3
 
4
4
  describe('notifyManager', () => {
5
5
  it('should use default notifyFn', async () => {
@@ -1,5 +1,5 @@
1
1
  import { OnlineManager } from '../onlineManager'
2
- import { setIsServer, sleep } from '../../../../tests/utils'
2
+ import { setIsServer, sleep } from './utils'
3
3
 
4
4
  describe('onlineManager', () => {
5
5
  let onlineManager: OnlineManager
@@ -1,10 +1,5 @@
1
1
  import { waitFor } from '@testing-library/react'
2
- import {
3
- sleep,
4
- queryKey,
5
- createQueryClient,
6
- mockLogger,
7
- } from '../../../../tests/utils'
2
+ import { sleep, queryKey, createQueryClient, mockLogger } from './utils'
8
3
  import {
9
4
  QueryClient,
10
5
  QueriesObserver,
@@ -4,7 +4,7 @@ import {
4
4
  mockVisibilityState,
5
5
  mockLogger,
6
6
  createQueryClient,
7
- } from '../../../../tests/utils'
7
+ } from './utils'
8
8
  import {
9
9
  QueryCache,
10
10
  QueryClient,
@@ -1,4 +1,4 @@
1
- import { sleep, queryKey, createQueryClient } from '../../../../tests/utils'
1
+ import { sleep, queryKey, createQueryClient } from './utils'
2
2
  import { QueryCache, QueryClient } from '..'
3
3
  import { Query } from '.././query'
4
4
 
@@ -1,12 +1,7 @@
1
1
  import { waitFor } from '@testing-library/react'
2
2
  import '@testing-library/jest-dom'
3
3
 
4
- import {
5
- sleep,
6
- queryKey,
7
- mockLogger,
8
- createQueryClient,
9
- } from '../../../../tests/utils'
4
+ import { sleep, queryKey, mockLogger, createQueryClient } from './utils'
10
5
  import {
11
6
  InfiniteQueryObserver,
12
7
  QueryCache,
@@ -4,7 +4,7 @@ import {
4
4
  expectType,
5
5
  mockLogger,
6
6
  createQueryClient,
7
- } from '../../../../tests/utils'
7
+ } from './utils'
8
8
  import {
9
9
  QueryClient,
10
10
  QueryObserver,
@@ -9,7 +9,7 @@ import {
9
9
  isPlainArray,
10
10
  } from '../utils'
11
11
  import { Mutation } from '../mutation'
12
- import { createQueryClient } from '../../../../tests/utils'
12
+ import { createQueryClient } from './utils'
13
13
 
14
14
  describe('core/utils', () => {
15
15
  describe('isPlainObject', () => {
@@ -0,0 +1,78 @@
1
+ import { act } from '@testing-library/react'
2
+
3
+ import {
4
+ MutationOptions,
5
+ QueryClient,
6
+ QueryClientConfig,
7
+ } from '@tanstack/query-core'
8
+ import * as utils from '../utils'
9
+
10
+ export function createQueryClient(config?: QueryClientConfig): QueryClient {
11
+ jest.spyOn(console, 'error').mockImplementation(() => undefined)
12
+ return new QueryClient({ logger: mockLogger, ...config })
13
+ }
14
+
15
+ export function mockVisibilityState(value: DocumentVisibilityState) {
16
+ return jest.spyOn(document, 'visibilityState', 'get').mockReturnValue(value)
17
+ }
18
+
19
+ export function mockNavigatorOnLine(value: boolean) {
20
+ return jest.spyOn(navigator, 'onLine', 'get').mockReturnValue(value)
21
+ }
22
+
23
+ export const mockLogger = {
24
+ log: jest.fn(),
25
+ warn: jest.fn(),
26
+ error: jest.fn(),
27
+ }
28
+
29
+ let queryKeyCount = 0
30
+ export function queryKey(): Array<string> {
31
+ queryKeyCount++
32
+ return [`query_${queryKeyCount}`]
33
+ }
34
+
35
+ export function sleep(timeout: number): Promise<void> {
36
+ return new Promise((resolve, _reject) => {
37
+ setTimeout(resolve, timeout)
38
+ })
39
+ }
40
+
41
+ export function setActTimeout(fn: () => void, ms?: number) {
42
+ return setTimeout(() => {
43
+ act(() => {
44
+ fn()
45
+ })
46
+ }, ms)
47
+ }
48
+
49
+ /**
50
+ * Assert the parameter is of a specific type.
51
+ */
52
+ export const expectType = <T>(_: T): void => undefined
53
+
54
+ /**
55
+ * Assert the parameter is not typed as `any`
56
+ */
57
+ export const expectTypeNotAny = <T>(_: 0 extends 1 & T ? never : T): void =>
58
+ undefined
59
+
60
+ export const executeMutation = (
61
+ queryClient: QueryClient,
62
+ options: MutationOptions<any, any, any, any>,
63
+ ): Promise<unknown> => {
64
+ return queryClient.getMutationCache().build(queryClient, options).execute()
65
+ }
66
+
67
+ // This monkey-patches the isServer-value from utils,
68
+ // so that we can pretend to be in a server environment
69
+ export function setIsServer(isServer: boolean) {
70
+ const original = utils.isServer
71
+ // @ts-ignore
72
+ utils.isServer = isServer
73
+
74
+ return () => {
75
+ // @ts-ignore
76
+ utils.isServer = original
77
+ }
78
+ }