@tanstack/query-core 4.3.4 → 4.3.6

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 (42) hide show
  1. package/build/lib/index.d.ts +1 -1
  2. package/build/lib/index.js +1 -0
  3. package/build/lib/index.js.map +1 -1
  4. package/build/lib/index.mjs +1 -1
  5. package/build/lib/tests/focusManager.test.d.ts +1 -0
  6. package/build/lib/tests/hydration.test.d.ts +1 -0
  7. package/build/lib/tests/infiniteQueryBehavior.test.d.ts +1 -0
  8. package/build/lib/tests/infiniteQueryObserver.test.d.ts +1 -0
  9. package/build/lib/tests/mutationCache.test.d.ts +1 -0
  10. package/build/lib/tests/mutationObserver.test.d.ts +1 -0
  11. package/build/lib/tests/mutations.test.d.ts +1 -0
  12. package/build/lib/tests/notifyManager.test.d.ts +1 -0
  13. package/build/lib/tests/onlineManager.test.d.ts +1 -0
  14. package/build/lib/tests/queriesObserver.test.d.ts +1 -0
  15. package/build/lib/tests/query.test.d.ts +1 -0
  16. package/build/lib/tests/queryCache.test.d.ts +1 -0
  17. package/build/lib/tests/queryClient.test.d.ts +1 -0
  18. package/build/lib/tests/queryObserver.test.d.ts +1 -0
  19. package/build/lib/tests/utils.d.ts +24 -0
  20. package/build/lib/tests/utils.test.d.ts +1 -0
  21. package/build/umd/index.development.js +1 -0
  22. package/build/umd/index.development.js.map +1 -1
  23. package/build/umd/index.production.js +1 -1
  24. package/build/umd/index.production.js.map +1 -1
  25. package/package.json +1 -1
  26. package/src/index.ts +1 -0
  27. package/src/tests/focusManager.test.tsx +1 -1
  28. package/src/tests/hydration.test.tsx +1 -1
  29. package/src/tests/infiniteQueryBehavior.test.tsx +1 -1
  30. package/src/tests/infiniteQueryObserver.test.tsx +1 -1
  31. package/src/tests/mutationCache.test.tsx +1 -6
  32. package/src/tests/mutationObserver.test.tsx +1 -1
  33. package/src/tests/mutations.test.tsx +1 -6
  34. package/src/tests/notifyManager.test.tsx +1 -1
  35. package/src/tests/onlineManager.test.tsx +1 -1
  36. package/src/tests/queriesObserver.test.tsx +1 -6
  37. package/src/tests/query.test.tsx +1 -1
  38. package/src/tests/queryCache.test.tsx +1 -1
  39. package/src/tests/queryClient.test.tsx +1 -6
  40. package/src/tests/queryObserver.test.tsx +1 -1
  41. package/src/tests/utils.test.tsx +1 -1
  42. 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.6",
4
4
  "description": "TODO",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
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
+ }