@tanstack/query-core 4.3.8 → 4.5.0

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 (71) hide show
  1. package/build/lib/infiniteQueryObserver.d.ts +3 -2
  2. package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
  3. package/build/lib/infiniteQueryObserver.js.map +1 -1
  4. package/build/lib/infiniteQueryObserver.mjs.map +1 -1
  5. package/build/lib/mutation.d.ts +1 -1
  6. package/build/lib/mutation.esm.js.map +1 -1
  7. package/build/lib/mutation.js.map +1 -1
  8. package/build/lib/mutation.mjs.map +1 -1
  9. package/build/lib/mutationCache.d.ts +4 -3
  10. package/build/lib/mutationCache.esm.js.map +1 -1
  11. package/build/lib/mutationCache.js.map +1 -1
  12. package/build/lib/mutationCache.mjs.map +1 -1
  13. package/build/lib/mutationObserver.d.ts +1 -1
  14. package/build/lib/mutationObserver.esm.js.map +1 -1
  15. package/build/lib/mutationObserver.js.map +1 -1
  16. package/build/lib/mutationObserver.mjs.map +1 -1
  17. package/build/lib/queriesObserver.d.ts +1 -1
  18. package/build/lib/queriesObserver.esm.js.map +1 -1
  19. package/build/lib/queriesObserver.js.map +1 -1
  20. package/build/lib/queriesObserver.mjs.map +1 -1
  21. package/build/lib/query.d.ts +1 -1
  22. package/build/lib/query.esm.js +1 -1
  23. package/build/lib/query.esm.js.map +1 -1
  24. package/build/lib/query.js +1 -1
  25. package/build/lib/query.js.map +1 -1
  26. package/build/lib/query.mjs +1 -1
  27. package/build/lib/query.mjs.map +1 -1
  28. package/build/lib/queryCache.d.ts +4 -3
  29. package/build/lib/queryCache.esm.js.map +1 -1
  30. package/build/lib/queryCache.js.map +1 -1
  31. package/build/lib/queryCache.mjs.map +1 -1
  32. package/build/lib/queryClient.d.ts +3 -3
  33. package/build/lib/queryClient.esm.js.map +1 -1
  34. package/build/lib/queryClient.js.map +1 -1
  35. package/build/lib/queryClient.mjs.map +1 -1
  36. package/build/lib/queryObserver.d.ts +1 -1
  37. package/build/lib/queryObserver.esm.js.map +1 -1
  38. package/build/lib/queryObserver.js.map +1 -1
  39. package/build/lib/queryObserver.mjs.map +1 -1
  40. package/build/lib/retryer.d.ts +1 -1
  41. package/build/lib/retryer.esm.js.map +1 -1
  42. package/build/lib/retryer.js.map +1 -1
  43. package/build/lib/retryer.mjs.map +1 -1
  44. package/build/lib/tests/utils.d.ts +2 -1
  45. package/build/lib/types.d.ts +1 -1
  46. package/build/umd/index.development.js +1 -1
  47. package/build/umd/index.development.js.map +1 -1
  48. package/build/umd/index.production.js +1 -1
  49. package/build/umd/index.production.js.map +1 -1
  50. package/package.json +1 -1
  51. package/src/infiniteQueryObserver.ts +3 -6
  52. package/src/mutation.ts +4 -2
  53. package/src/mutationCache.ts +5 -3
  54. package/src/mutationObserver.ts +2 -1
  55. package/src/queriesObserver.ts +2 -1
  56. package/src/query.ts +9 -3
  57. package/src/queryCache.ts +5 -8
  58. package/src/queryClient.ts +4 -5
  59. package/src/queryObserver.ts +1 -1
  60. package/src/retryer.ts +1 -1
  61. package/src/tests/infiniteQueryBehavior.test.tsx +2 -2
  62. package/src/tests/infiniteQueryObserver.test.tsx +2 -1
  63. package/src/tests/mutationObserver.test.tsx +2 -1
  64. package/src/tests/mutations.test.tsx +2 -2
  65. package/src/tests/queriesObserver.test.tsx +3 -7
  66. package/src/tests/query.test.tsx +7 -6
  67. package/src/tests/queryCache.test.tsx +3 -2
  68. package/src/tests/queryClient.test.tsx +2 -3
  69. package/src/tests/queryObserver.test.tsx +2 -6
  70. package/src/tests/utils.ts +2 -5
  71. package/src/types.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.3.8",
3
+ "version": "4.5.0",
4
4
  "description": "TODO",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -8,17 +8,14 @@ import type {
8
8
  QueryKey,
9
9
  } from './types'
10
10
  import type { QueryClient } from './queryClient'
11
- import {
12
- NotifyOptions,
13
- ObserverFetchOptions,
14
- QueryObserver,
15
- } from './queryObserver'
11
+ import type { NotifyOptions, ObserverFetchOptions } from './queryObserver'
12
+ import { QueryObserver } from './queryObserver'
16
13
  import {
17
14
  hasNextPage,
18
15
  hasPreviousPage,
19
16
  infiniteQueryBehavior,
20
17
  } from './infiniteQueryBehavior'
21
- import { Query } from './query'
18
+ import type { Query } from './query'
22
19
 
23
20
  type InfiniteQueryObserverListener<TData, TError> = (
24
21
  result: InfiniteQueryObserverResult<TData, TError>,
package/src/mutation.ts CHANGED
@@ -1,10 +1,12 @@
1
1
  import type { MutationOptions, MutationStatus, MutationMeta } from './types'
2
2
  import type { MutationCache } from './mutationCache'
3
3
  import type { MutationObserver } from './mutationObserver'
4
- import { defaultLogger, Logger } from './logger'
4
+ import type { Logger } from './logger'
5
+ import { defaultLogger } from './logger'
5
6
  import { notifyManager } from './notifyManager'
6
7
  import { Removable } from './removable'
7
- import { canFetch, Retryer, createRetryer } from './retryer'
8
+ import type { Retryer } from './retryer'
9
+ import { canFetch, createRetryer } from './retryer'
8
10
 
9
11
  // TYPES
10
12
 
@@ -1,9 +1,11 @@
1
- import { MutationObserver } from './mutationObserver'
1
+ import type { MutationObserver } from './mutationObserver'
2
2
  import type { MutationOptions } from './types'
3
3
  import type { QueryClient } from './queryClient'
4
4
  import { notifyManager } from './notifyManager'
5
- import { Action, Mutation, MutationState } from './mutation'
6
- import { matchMutation, MutationFilters, noop } from './utils'
5
+ import type { Action, MutationState } from './mutation'
6
+ import { Mutation } from './mutation'
7
+ import type { MutationFilters } from './utils'
8
+ import { matchMutation, noop } from './utils'
7
9
  import { Subscribable } from './subscribable'
8
10
 
9
11
  // TYPES
@@ -1,4 +1,5 @@
1
- import { Action, getDefaultState, Mutation } from './mutation'
1
+ import type { Action, Mutation } from './mutation'
2
+ import { getDefaultState } from './mutation'
2
3
  import { notifyManager } from './notifyManager'
3
4
  import type { QueryClient } from './queryClient'
4
5
  import { Subscribable } from './subscribable'
@@ -6,7 +6,8 @@ import type {
6
6
  DefaultedQueryObserverOptions,
7
7
  } from './types'
8
8
  import type { QueryClient } from './queryClient'
9
- import { NotifyOptions, QueryObserver } from './queryObserver'
9
+ import type { NotifyOptions } from './queryObserver'
10
+ import { QueryObserver } from './queryObserver'
10
11
  import { Subscribable } from './subscribable'
11
12
 
12
13
  type QueriesObserverListener = (result: QueryObserverResult[]) => void
package/src/query.ts CHANGED
@@ -12,9 +12,11 @@ import type {
12
12
  } from './types'
13
13
  import type { QueryCache } from './queryCache'
14
14
  import type { QueryObserver } from './queryObserver'
15
- import { defaultLogger, Logger } from './logger'
15
+ import type { Logger } from './logger'
16
+ import { defaultLogger } from './logger'
16
17
  import { notifyManager } from './notifyManager'
17
- import { Retryer, isCancelledError, canFetch, createRetryer } from './retryer'
18
+ import type { Retryer } from './retryer'
19
+ import { isCancelledError, canFetch, createRetryer } from './retryer'
18
20
  import { Removable } from './removable'
19
21
 
20
22
  // TYPES
@@ -450,7 +452,11 @@ export class Query<
450
452
  abort: abortController?.abort.bind(abortController),
451
453
  onSuccess: (data) => {
452
454
  if (typeof data === 'undefined') {
453
- onError(new Error('Query data cannot be undefined') as any)
455
+ onError(
456
+ new Error(
457
+ `Query data cannot be undefined - affected query key: ${this.queryHash}`,
458
+ ) as any,
459
+ )
454
460
  return
455
461
  }
456
462
 
package/src/queryCache.ts CHANGED
@@ -1,15 +1,12 @@
1
- import {
2
- QueryFilters,
3
- hashQueryKeyByOptions,
4
- matchQuery,
5
- parseFilterArgs,
6
- } from './utils'
7
- import { Action, Query, QueryState } from './query'
1
+ import type { QueryFilters } from './utils'
2
+ import { hashQueryKeyByOptions, matchQuery, parseFilterArgs } from './utils'
3
+ import type { Action, QueryState } from './query'
4
+ import { Query } from './query'
8
5
  import type { QueryKey, QueryOptions } from './types'
9
6
  import { notifyManager } from './notifyManager'
10
7
  import type { QueryClient } from './queryClient'
11
8
  import { Subscribable } from './subscribable'
12
- import { QueryObserver } from './queryObserver'
9
+ import type { QueryObserver } from './queryObserver'
13
10
 
14
11
  // TYPES
15
12
 
@@ -1,13 +1,11 @@
1
+ import type { QueryFilters, Updater, MutationFilters } from './utils'
1
2
  import {
2
- QueryFilters,
3
- Updater,
4
3
  hashQueryKey,
5
4
  noop,
6
5
  parseFilterArgs,
7
6
  parseQueryArgs,
8
7
  partialMatchKey,
9
8
  hashQueryKeyByOptions,
10
- MutationFilters,
11
9
  functionalUpdate,
12
10
  } from './utils'
13
11
  import type {
@@ -38,8 +36,9 @@ import { focusManager } from './focusManager'
38
36
  import { onlineManager } from './onlineManager'
39
37
  import { notifyManager } from './notifyManager'
40
38
  import { infiniteQueryBehavior } from './infiniteQueryBehavior'
41
- import { CancelOptions, DefaultedQueryObserverOptions } from './types'
42
- import { defaultLogger, Logger } from './logger'
39
+ import type { CancelOptions, DefaultedQueryObserverOptions } from './types'
40
+ import type { Logger } from './logger'
41
+ import { defaultLogger } from './logger'
43
42
 
44
43
  // TYPES
45
44
 
@@ -1,4 +1,4 @@
1
- import { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'
1
+ import type { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'
2
2
  import {
3
3
  isServer,
4
4
  isValidTimeout,
package/src/retryer.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { focusManager } from './focusManager'
2
2
  import { onlineManager } from './onlineManager'
3
3
  import { sleep } from './utils'
4
- import { CancelOptions, NetworkMode } from './types'
4
+ import type { CancelOptions, NetworkMode } from './types'
5
5
 
6
6
  // TYPES
7
7
 
@@ -1,9 +1,9 @@
1
1
  import { waitFor } from '@testing-library/react'
2
- import {
2
+ import type {
3
3
  QueryClient,
4
- InfiniteQueryObserver,
5
4
  InfiniteQueryObserverResult,
6
5
  } from '@tanstack/query-core'
6
+ import { InfiniteQueryObserver } from '@tanstack/query-core'
7
7
  import { createQueryClient, queryKey } from './utils'
8
8
 
9
9
  describe('InfiniteQueryBehavior', () => {
@@ -1,5 +1,6 @@
1
1
  import { createQueryClient, queryKey, sleep } from './utils'
2
- import { QueryClient, InfiniteQueryObserver } from '..'
2
+ import type { QueryClient } from '..'
3
+ import { InfiniteQueryObserver } from '..'
3
4
 
4
5
  describe('InfiniteQueryObserver', () => {
5
6
  let queryClient: QueryClient
@@ -1,6 +1,7 @@
1
1
  import { waitFor } from '@testing-library/react'
2
2
  import { createQueryClient, sleep } from './utils'
3
- import { QueryClient, MutationObserver } from '..'
3
+ import type { QueryClient } from '..'
4
+ import { MutationObserver } from '..'
4
5
 
5
6
  describe('mutationObserver', () => {
6
7
  let queryClient: QueryClient
@@ -1,6 +1,6 @@
1
- import { QueryClient } from '..'
1
+ import type { QueryClient } from '..'
2
2
  import { createQueryClient, executeMutation, queryKey, sleep } from './utils'
3
- import { MutationState } from '../mutation'
3
+ import type { MutationState } from '../mutation'
4
4
  import { MutationObserver } from '../mutationObserver'
5
5
 
6
6
  describe('mutations', () => {
@@ -1,12 +1,8 @@
1
1
  import { waitFor } from '@testing-library/react'
2
2
  import { sleep, queryKey, createQueryClient, mockLogger } from './utils'
3
- import {
4
- QueryClient,
5
- QueriesObserver,
6
- QueryObserverResult,
7
- QueryObserver,
8
- } from '..'
9
- import { QueryKey } from '..'
3
+ import type { QueryClient, QueryObserverResult } from '..'
4
+ import { QueriesObserver, QueryObserver } from '..'
5
+ import type { QueryKey } from '..'
10
6
 
11
7
  describe('queriesObserver', () => {
12
8
  let queryClient: QueryClient
@@ -5,16 +5,13 @@ import {
5
5
  mockLogger,
6
6
  createQueryClient,
7
7
  } from './utils'
8
- import {
8
+ import type {
9
9
  QueryCache,
10
10
  QueryClient,
11
- QueryObserver,
12
- isCancelledError,
13
- isError,
14
- onlineManager,
15
11
  QueryFunctionContext,
16
12
  QueryObserverResult,
17
13
  } from '..'
14
+ import { QueryObserver, isCancelledError, isError, onlineManager } from '..'
18
15
  import { waitFor } from '@testing-library/react'
19
16
 
20
17
  describe('query', () => {
@@ -819,7 +816,11 @@ describe('query', () => {
819
816
 
820
817
  await sleep(10)
821
818
 
822
- const error = new Error('Query data cannot be undefined')
819
+ const error = new Error(
820
+ `Query data cannot be undefined - affected query key: ${
821
+ observer.getCurrentQuery().queryHash
822
+ }`,
823
+ )
823
824
 
824
825
  expect(observerResult).toMatchObject({
825
826
  isError: true,
@@ -1,6 +1,7 @@
1
1
  import { sleep, queryKey, createQueryClient } from './utils'
2
- import { QueryCache, QueryClient } from '..'
3
- import { Query } from '.././query'
2
+ import type { QueryClient } from '..'
3
+ import { QueryCache } from '..'
4
+ import type { Query } from '.././query'
4
5
 
5
6
  describe('queryCache', () => {
6
7
  let queryClient: QueryClient
@@ -2,14 +2,13 @@ import { waitFor } from '@testing-library/react'
2
2
  import '@testing-library/jest-dom'
3
3
 
4
4
  import { sleep, queryKey, mockLogger, createQueryClient } from './utils'
5
- import {
6
- InfiniteQueryObserver,
5
+ import type {
7
6
  QueryCache,
8
7
  QueryClient,
9
8
  QueryFunction,
10
- QueryObserver,
11
9
  QueryObserverOptions,
12
10
  } from '..'
11
+ import { InfiniteQueryObserver, QueryObserver } from '..'
13
12
  import { focusManager, onlineManager } from '..'
14
13
 
15
14
  describe('queryClient', () => {
@@ -5,12 +5,8 @@ import {
5
5
  mockLogger,
6
6
  createQueryClient,
7
7
  } from './utils'
8
- import {
9
- QueryClient,
10
- QueryObserver,
11
- QueryObserverResult,
12
- focusManager,
13
- } from '..'
8
+ import type { QueryClient, QueryObserverResult } from '..'
9
+ import { QueryObserver, focusManager } from '..'
14
10
 
15
11
  describe('queryObserver', () => {
16
12
  let queryClient: QueryClient
@@ -1,10 +1,7 @@
1
1
  import { act } from '@testing-library/react'
2
2
 
3
- import {
4
- MutationOptions,
5
- QueryClient,
6
- QueryClientConfig,
7
- } from '@tanstack/query-core'
3
+ import type { MutationOptions, QueryClientConfig } from '@tanstack/query-core'
4
+ import { QueryClient } from '@tanstack/query-core'
8
5
  import * as utils from '../utils'
9
6
 
10
7
  export function createQueryClient(config?: QueryClientConfig): QueryClient {
package/src/types.ts CHANGED
@@ -4,7 +4,7 @@ import type { RetryValue, RetryDelayValue } from './retryer'
4
4
  import type { QueryFilters, QueryTypeFilter } from './utils'
5
5
  import type { QueryCache } from './queryCache'
6
6
  import type { MutationCache } from './mutationCache'
7
- import { Logger } from './logger'
7
+ import type { Logger } from './logger'
8
8
 
9
9
  export type QueryKey = readonly unknown[]
10
10