@tanstack/query-core 4.0.11-beta.0 → 4.1.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 (96) hide show
  1. package/build/cjs/focusManager.js +101 -0
  2. package/build/cjs/focusManager.js.map +1 -0
  3. package/build/cjs/hydration.js +112 -0
  4. package/build/cjs/hydration.js.map +1 -0
  5. package/build/cjs/index.js +51 -0
  6. package/build/cjs/index.js.map +1 -0
  7. package/build/cjs/infiniteQueryBehavior.js +160 -0
  8. package/build/cjs/infiniteQueryBehavior.js.map +1 -0
  9. package/build/cjs/infiniteQueryObserver.js +92 -0
  10. package/build/cjs/infiniteQueryObserver.js.map +1 -0
  11. package/build/cjs/logger.js +18 -0
  12. package/build/cjs/logger.js.map +1 -0
  13. package/build/cjs/mutation.js +258 -0
  14. package/build/cjs/mutation.js.map +1 -0
  15. package/build/cjs/mutationCache.js +99 -0
  16. package/build/cjs/mutationCache.js.map +1 -0
  17. package/build/cjs/mutationObserver.js +140 -0
  18. package/build/cjs/mutationObserver.js.map +1 -0
  19. package/build/cjs/notifyManager.js +114 -0
  20. package/build/cjs/notifyManager.js.map +1 -0
  21. package/build/cjs/onlineManager.js +100 -0
  22. package/build/cjs/onlineManager.js.map +1 -0
  23. package/build/cjs/queriesObserver.js +170 -0
  24. package/build/cjs/queriesObserver.js.map +1 -0
  25. package/build/cjs/query.js +474 -0
  26. package/build/cjs/query.js.map +1 -0
  27. package/build/cjs/queryCache.js +140 -0
  28. package/build/cjs/queryCache.js.map +1 -0
  29. package/build/cjs/queryClient.js +353 -0
  30. package/build/cjs/queryClient.js.map +1 -0
  31. package/build/cjs/queryObserver.js +529 -0
  32. package/build/cjs/queryObserver.js.map +1 -0
  33. package/build/cjs/removable.js +47 -0
  34. package/build/cjs/removable.js.map +1 -0
  35. package/build/cjs/retryer.js +177 -0
  36. package/build/cjs/retryer.js.map +1 -0
  37. package/build/cjs/subscribable.js +43 -0
  38. package/build/cjs/subscribable.js.map +1 -0
  39. package/build/cjs/utils.js +356 -0
  40. package/build/cjs/utils.js.map +1 -0
  41. package/build/{lib/index.mjs → esm/index.js} +18 -1
  42. package/build/esm/index.js.map +1 -0
  43. package/build/stats-html.html +2689 -0
  44. package/build/stats.json +811 -0
  45. package/build/{lib → types/packages/query-core/src}/focusManager.d.ts +0 -0
  46. package/build/{lib → types/packages/query-core/src}/hydration.d.ts +0 -0
  47. package/build/{lib → types/packages/query-core/src}/index.d.ts +2 -2
  48. package/build/{lib → types/packages/query-core/src}/infiniteQueryBehavior.d.ts +0 -0
  49. package/build/{lib → types/packages/query-core/src}/infiniteQueryObserver.d.ts +0 -0
  50. package/build/{lib → types/packages/query-core/src}/logger.d.ts +0 -0
  51. package/build/{lib → types/packages/query-core/src}/logger.native.d.ts +0 -0
  52. package/build/{lib → types/packages/query-core/src}/mutation.d.ts +0 -0
  53. package/build/{lib → types/packages/query-core/src}/mutationCache.d.ts +6 -1
  54. package/build/{lib → types/packages/query-core/src}/mutationObserver.d.ts +0 -0
  55. package/build/{lib → types/packages/query-core/src}/notifyManager.d.ts +0 -0
  56. package/build/{lib → types/packages/query-core/src}/onlineManager.d.ts +0 -0
  57. package/build/{lib → types/packages/query-core/src}/queriesObserver.d.ts +0 -0
  58. package/build/{lib → types/packages/query-core/src}/query.d.ts +0 -0
  59. package/build/{lib → types/packages/query-core/src}/queryCache.d.ts +6 -1
  60. package/build/{lib → types/packages/query-core/src}/queryClient.d.ts +0 -0
  61. package/build/{lib → types/packages/query-core/src}/queryObserver.d.ts +0 -0
  62. package/build/{lib → types/packages/query-core/src}/removable.d.ts +0 -0
  63. package/build/{lib → types/packages/query-core/src}/retryer.d.ts +0 -0
  64. package/build/{lib → types/packages/query-core/src}/subscribable.d.ts +0 -0
  65. package/build/types/packages/query-core/src/tests/focusManager.test.d.ts +1 -0
  66. package/build/types/packages/query-core/src/tests/hydration.test.d.ts +1 -0
  67. package/build/types/packages/query-core/src/tests/infiniteQueryBehavior.test.d.ts +1 -0
  68. package/build/types/packages/query-core/src/tests/infiniteQueryObserver.test.d.ts +1 -0
  69. package/build/types/packages/query-core/src/tests/mutationCache.test.d.ts +1 -0
  70. package/build/types/packages/query-core/src/tests/mutationObserver.test.d.ts +1 -0
  71. package/build/types/packages/query-core/src/tests/mutations.test.d.ts +1 -0
  72. package/build/types/packages/query-core/src/tests/notifyManager.test.d.ts +1 -0
  73. package/build/types/packages/query-core/src/tests/onlineManager.test.d.ts +1 -0
  74. package/build/types/packages/query-core/src/tests/queriesObserver.test.d.ts +1 -0
  75. package/build/types/packages/query-core/src/tests/query.test.d.ts +1 -0
  76. package/build/types/packages/query-core/src/tests/queryCache.test.d.ts +1 -0
  77. package/build/types/packages/query-core/src/tests/queryClient.test.d.ts +1 -0
  78. package/build/types/packages/query-core/src/tests/queryObserver.test.d.ts +1 -0
  79. package/build/types/packages/query-core/src/tests/utils.test.d.ts +1 -0
  80. package/build/{lib → types/packages/query-core/src}/types.d.ts +0 -0
  81. package/build/{lib → types/packages/query-core/src}/utils.d.ts +0 -0
  82. package/build/types/tests/utils.d.ts +24 -0
  83. package/build/umd/index.development.js +17 -0
  84. package/build/umd/index.development.js.map +1 -1
  85. package/build/umd/index.production.js +1 -1
  86. package/build/umd/index.production.js.map +1 -1
  87. package/package.json +7 -16
  88. package/src/index.ts +2 -2
  89. package/src/mutationCache.ts +7 -0
  90. package/src/mutationObserver.ts +9 -0
  91. package/src/queryCache.ts +7 -0
  92. package/src/queryObserver.ts +8 -0
  93. package/src/tests/queryObserver.test.tsx +19 -0
  94. package/build/lib/index.js +0 -3096
  95. package/build/lib/index.js.map +0 -1
  96. package/build/lib/index.mjs.map +0 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/query-core",
3
- "version": "4.0.11-beta.0",
3
+ "version": "4.1.0",
4
4
  "description": "TODO",
5
5
  "author": "tannerlinsley",
6
6
  "license": "MIT",
@@ -10,25 +10,16 @@
10
10
  "type": "github",
11
11
  "url": "https://github.com/sponsors/tannerlinsley"
12
12
  },
13
- "module": "build/lib/index.mjs",
14
- "main": "build/lib/index.js",
13
+ "module": "build/esm/index.js",
14
+ "main": "build/cjs/index.js",
15
15
  "browser": "build/umd/index.production.js",
16
- "types": "build/lib/index.d.ts",
17
- "exports": {
18
- ".": {
19
- "types": "./build/lib/index.d.ts",
20
- "import": "./build/lib/index.mjs",
21
- "default": "./build/lib/index.js"
22
- },
23
- "./package.json": "./package.json"
24
- },
16
+ "types": "build/types/packages/query-core/src/index.d.ts",
25
17
  "files": [
26
- "build/lib/*",
27
- "build/umd/*",
18
+ "build/*",
28
19
  "src"
29
20
  ],
30
21
  "scripts": {
31
- "clean": "rm -rf ./build",
32
- "test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src"
22
+ "test:eslint": "../../node_modules/.bin/eslint --ext .ts,.tsx ./src",
23
+ "compile": "../../node_modules/.bin/tsc -p tsconfig.json --noEmit --emitDeclarationOnly false"
33
24
  }
34
25
  }
package/src/index.ts CHANGED
@@ -17,13 +17,13 @@ export {
17
17
  parseMutationFilterArgs,
18
18
  parseMutationArgs,
19
19
  } from './utils'
20
- export type { MutationFilters, QueryFilters, Updater } from './utils'
20
+ export type { MutationFilters, QueryFilters } from './utils'
21
21
  export { isCancelledError } from './retryer'
22
22
  export { dehydrate, hydrate } from './hydration'
23
23
 
24
24
  // Types
25
25
  export * from './types'
26
- export type { Query, QueryState } from './query'
26
+ export type { Query } from './query'
27
27
  export type { Mutation } from './mutation'
28
28
  export type { Logger } from './logger'
29
29
  export type {
@@ -48,6 +48,12 @@ interface NotifyEventMutationObserverRemoved {
48
48
  observer: MutationObserver<any, any, any>
49
49
  }
50
50
 
51
+ interface NotifyEventMutationObserverOptionsUpdated {
52
+ type: 'observerOptionsUpdated'
53
+ mutation?: Mutation<any, any, any, any>
54
+ observer: MutationObserver<any, any, any, any>
55
+ }
56
+
51
57
  interface NotifyEventMutationUpdated {
52
58
  type: 'updated'
53
59
  mutation: Mutation<any, any, any, any>
@@ -59,6 +65,7 @@ type MutationCacheNotifyEvent =
59
65
  | NotifyEventMutationRemoved
60
66
  | NotifyEventMutationObserverAdded
61
67
  | NotifyEventMutationObserverRemoved
68
+ | NotifyEventMutationObserverOptionsUpdated
62
69
  | NotifyEventMutationUpdated
63
70
 
64
71
  type MutationCacheListener = (event: MutationCacheNotifyEvent) => void
@@ -8,6 +8,7 @@ import type {
8
8
  MutationObserverResult,
9
9
  MutationObserverOptions,
10
10
  } from './types'
11
+ import { shallowEqualObjects } from './utils'
11
12
 
12
13
  // TYPES
13
14
 
@@ -63,7 +64,15 @@ export class MutationObserver<
63
64
  setOptions(
64
65
  options?: MutationObserverOptions<TData, TError, TVariables, TContext>,
65
66
  ) {
67
+ const prevOptions = this.options
66
68
  this.options = this.client.defaultMutationOptions(options)
69
+ if (!shallowEqualObjects(prevOptions, this.options)) {
70
+ this.client.getMutationCache().notify({
71
+ type: 'observerOptionsUpdated',
72
+ mutation: this.currentMutation,
73
+ observer: this,
74
+ })
75
+ }
67
76
  }
68
77
 
69
78
  protected onUnsubscribe(): void {
package/src/queryCache.ts CHANGED
@@ -55,6 +55,12 @@ interface NotifyEventQueryObserverResultsUpdated {
55
55
  query: Query<any, any, any, any>
56
56
  }
57
57
 
58
+ interface NotifyEventQueryObserverOptionsUpdated {
59
+ type: 'observerOptionsUpdated'
60
+ query: Query<any, any, any, any>
61
+ observer: QueryObserver<any, any, any, any, any>
62
+ }
63
+
58
64
  type QueryCacheNotifyEvent =
59
65
  | NotifyEventQueryAdded
60
66
  | NotifyEventQueryRemoved
@@ -62,6 +68,7 @@ type QueryCacheNotifyEvent =
62
68
  | NotifyEventQueryObserverAdded
63
69
  | NotifyEventQueryObserverRemoved
64
70
  | NotifyEventQueryObserverResultsUpdated
71
+ | NotifyEventQueryObserverOptionsUpdated
65
72
 
66
73
  type QueryCacheListener = (event: QueryCacheNotifyEvent) => void
67
74
 
@@ -155,6 +155,14 @@ export class QueryObserver<
155
155
 
156
156
  this.options = this.client.defaultQueryOptions(options)
157
157
 
158
+ if (!shallowEqualObjects(prevOptions, this.options)) {
159
+ this.client.getQueryCache().notify({
160
+ type: 'observerOptionsUpdated',
161
+ query: this.currentQuery,
162
+ observer: this,
163
+ })
164
+ }
165
+
158
166
  if (
159
167
  typeof this.options.enabled !== 'undefined' &&
160
168
  typeof this.options.enabled !== 'boolean'
@@ -799,4 +799,23 @@ describe('queryObserver', () => {
799
799
 
800
800
  unsubscribe()
801
801
  })
802
+
803
+ test('setOptions should notify cache listeners', async () => {
804
+ const key = queryKey()
805
+
806
+ const observer = new QueryObserver(queryClient, {
807
+ queryKey: key,
808
+ })
809
+
810
+ const spy = jest.fn()
811
+ const unsubscribe = queryClient.getQueryCache().subscribe(spy)
812
+ observer.setOptions({ enabled: false })
813
+
814
+ expect(spy).toHaveBeenCalledTimes(1)
815
+ expect(spy).toHaveBeenCalledWith(
816
+ expect.objectContaining({ type: 'observerOptionsUpdated' }),
817
+ )
818
+
819
+ unsubscribe()
820
+ })
802
821
  })