@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.
- package/build/lib/focusManager.d.ts +1 -3
- package/build/lib/focusManager.esm.js +19 -36
- package/build/lib/focusManager.esm.js.map +1 -1
- package/build/lib/focusManager.js +19 -38
- package/build/lib/focusManager.js.map +1 -1
- package/build/lib/focusManager.mjs +19 -36
- package/build/lib/focusManager.mjs.map +1 -1
- package/build/lib/hydration.esm.js +21 -23
- package/build/lib/hydration.esm.js.map +1 -1
- package/build/lib/hydration.js +21 -25
- package/build/lib/hydration.js.map +1 -1
- package/build/lib/hydration.mjs +21 -23
- package/build/lib/hydration.mjs.map +1 -1
- package/build/lib/index.d.ts +1 -2
- package/build/lib/index.esm.js +1 -1
- package/build/lib/index.js +2 -8
- package/build/lib/index.js.map +1 -1
- package/build/lib/index.mjs +1 -1
- package/build/lib/infiniteQueryBehavior.d.ts +3 -7
- package/build/lib/infiniteQueryBehavior.esm.js +52 -75
- package/build/lib/infiniteQueryBehavior.esm.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.js +50 -77
- package/build/lib/infiniteQueryBehavior.js.map +1 -1
- package/build/lib/infiniteQueryBehavior.mjs +52 -75
- package/build/lib/infiniteQueryBehavior.mjs.map +1 -1
- package/build/lib/infiniteQueryObserver.d.ts +4 -4
- package/build/lib/infiniteQueryObserver.esm.js +18 -26
- package/build/lib/infiniteQueryObserver.esm.js.map +1 -1
- package/build/lib/infiniteQueryObserver.js +18 -28
- package/build/lib/infiniteQueryObserver.js.map +1 -1
- package/build/lib/infiniteQueryObserver.mjs +18 -26
- package/build/lib/infiniteQueryObserver.mjs.map +1 -1
- package/build/lib/mutation.d.ts +11 -22
- package/build/lib/mutation.esm.js +73 -105
- package/build/lib/mutation.esm.js.map +1 -1
- package/build/lib/mutation.js +73 -107
- package/build/lib/mutation.js.map +1 -1
- package/build/lib/mutation.mjs +73 -105
- package/build/lib/mutation.mjs.map +1 -1
- package/build/lib/mutationCache.d.ts +4 -6
- package/build/lib/mutationCache.esm.js +23 -32
- package/build/lib/mutationCache.esm.js.map +1 -1
- package/build/lib/mutationCache.js +23 -34
- package/build/lib/mutationCache.js.map +1 -1
- package/build/lib/mutationCache.mjs +23 -32
- package/build/lib/mutationCache.mjs.map +1 -1
- package/build/lib/mutationObserver.d.ts +4 -9
- package/build/lib/mutationObserver.esm.js +42 -73
- package/build/lib/mutationObserver.esm.js.map +1 -1
- package/build/lib/mutationObserver.js +42 -75
- package/build/lib/mutationObserver.js.map +1 -1
- package/build/lib/mutationObserver.mjs +42 -73
- package/build/lib/mutationObserver.mjs.map +1 -1
- package/build/lib/notifyManager.esm.js +7 -17
- package/build/lib/notifyManager.esm.js.map +1 -1
- package/build/lib/notifyManager.js +7 -19
- package/build/lib/notifyManager.js.map +1 -1
- package/build/lib/notifyManager.mjs +7 -17
- package/build/lib/notifyManager.mjs.map +1 -1
- package/build/lib/onlineManager.d.ts +1 -3
- package/build/lib/onlineManager.esm.js +16 -30
- package/build/lib/onlineManager.esm.js.map +1 -1
- package/build/lib/onlineManager.js +16 -32
- package/build/lib/onlineManager.js.map +1 -1
- package/build/lib/onlineManager.mjs +16 -30
- package/build/lib/onlineManager.mjs.map +1 -1
- package/build/lib/queriesObserver.d.ts +3 -10
- package/build/lib/queriesObserver.esm.js +47 -71
- package/build/lib/queriesObserver.esm.js.map +1 -1
- package/build/lib/queriesObserver.js +49 -75
- package/build/lib/queriesObserver.js.map +1 -1
- package/build/lib/queriesObserver.mjs +47 -71
- package/build/lib/queriesObserver.mjs.map +1 -1
- package/build/lib/query.d.ts +14 -21
- package/build/lib/query.esm.js +140 -194
- package/build/lib/query.esm.js.map +1 -1
- package/build/lib/query.js +139 -195
- package/build/lib/query.js.map +1 -1
- package/build/lib/query.mjs +140 -194
- package/build/lib/query.mjs.map +1 -1
- package/build/lib/queryCache.d.ts +12 -7
- package/build/lib/queryCache.esm.js +21 -45
- package/build/lib/queryCache.esm.js.map +1 -1
- package/build/lib/queryCache.js +20 -46
- package/build/lib/queryCache.js.map +1 -1
- package/build/lib/queryCache.mjs +21 -45
- package/build/lib/queryCache.mjs.map +1 -1
- package/build/lib/queryClient.d.ts +18 -46
- package/build/lib/queryClient.esm.js +137 -216
- package/build/lib/queryClient.esm.js.map +1 -1
- package/build/lib/queryClient.js +136 -217
- package/build/lib/queryClient.js.map +1 -1
- package/build/lib/queryClient.mjs +137 -216
- package/build/lib/queryClient.mjs.map +1 -1
- package/build/lib/queryObserver.d.ts +4 -29
- package/build/lib/queryObserver.esm.js +176 -258
- package/build/lib/queryObserver.esm.js.map +1 -1
- package/build/lib/queryObserver.js +176 -260
- package/build/lib/queryObserver.js.map +1 -1
- package/build/lib/queryObserver.mjs +176 -258
- package/build/lib/queryObserver.mjs.map +1 -1
- package/build/lib/removable.d.ts +3 -3
- package/build/lib/removable.esm.js +10 -14
- package/build/lib/removable.esm.js.map +1 -1
- package/build/lib/removable.js +10 -16
- package/build/lib/removable.js.map +1 -1
- package/build/lib/removable.mjs +10 -14
- package/build/lib/removable.mjs.map +1 -1
- package/build/lib/retryer.d.ts +5 -5
- package/build/lib/retryer.esm.js +27 -44
- package/build/lib/retryer.esm.js.map +1 -1
- package/build/lib/retryer.js +27 -46
- package/build/lib/retryer.js.map +1 -1
- package/build/lib/retryer.mjs +27 -44
- package/build/lib/retryer.mjs.map +1 -1
- package/build/lib/subscribable.esm.js +4 -7
- package/build/lib/subscribable.esm.js.map +1 -1
- package/build/lib/subscribable.js +4 -9
- package/build/lib/subscribable.js.map +1 -1
- package/build/lib/subscribable.mjs +4 -7
- package/build/lib/subscribable.mjs.map +1 -1
- package/build/lib/tests/utils.d.ts +3 -12
- package/build/lib/types.d.ts +111 -99
- package/build/lib/utils.d.ts +8 -18
- package/build/lib/utils.esm.js +39 -132
- package/build/lib/utils.esm.js.map +1 -1
- package/build/lib/utils.js +42 -144
- package/build/lib/utils.js.map +1 -1
- package/build/lib/utils.mjs +39 -132
- package/build/lib/utils.mjs.map +1 -1
- package/build/umd/index.development.js +867 -1399
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/focusManager.ts +17 -24
- package/src/index.ts +1 -11
- package/src/infiniteQueryBehavior.ts +54 -94
- package/src/infiniteQueryObserver.ts +10 -12
- package/src/mutation.ts +68 -92
- package/src/mutationCache.ts +27 -27
- package/src/mutationObserver.ts +58 -97
- package/src/onlineManager.ts +14 -14
- package/src/queriesObserver.ts +50 -54
- package/src/query.ts +107 -111
- package/src/queryCache.ts +42 -41
- package/src/queryClient.ts +155 -434
- package/src/queryObserver.ts +155 -192
- package/src/removable.ts +13 -13
- package/src/retryer.ts +5 -5
- package/src/subscribable.ts +1 -1
- package/src/tests/focusManager.test.tsx +25 -25
- package/src/tests/hydration.test.tsx +167 -81
- package/src/tests/infiniteQueryBehavior.test.tsx +209 -17
- package/src/tests/infiniteQueryObserver.test.tsx +6 -2
- package/src/tests/mutationCache.test.tsx +127 -127
- package/src/tests/mutationObserver.test.tsx +1 -31
- package/src/tests/mutations.test.tsx +62 -43
- package/src/tests/onlineManager.test.tsx +12 -4
- package/src/tests/queriesObserver.test.tsx +41 -77
- package/src/tests/query.test.tsx +175 -243
- package/src/tests/queryCache.test.tsx +170 -93
- package/src/tests/queryClient.test.tsx +229 -378
- package/src/tests/queryObserver.test.tsx +23 -147
- package/src/tests/utils.test.tsx +84 -29
- package/src/tests/utils.ts +9 -18
- package/src/types.ts +187 -140
- package/src/utils.ts +31 -124
- package/build/lib/logger.d.ts +0 -8
- package/build/lib/logger.esm.js +0 -4
- package/build/lib/logger.esm.js.map +0 -1
- package/build/lib/logger.js +0 -8
- package/build/lib/logger.js.map +0 -1
- package/build/lib/logger.mjs +0 -4
- package/build/lib/logger.mjs.map +0 -1
- package/build/lib/logger.native.d.ts +0 -6
- package/build/lib/logger.native.esm.js +0 -12
- package/build/lib/logger.native.esm.js.map +0 -1
- package/build/lib/logger.native.js +0 -16
- package/build/lib/logger.native.js.map +0 -1
- package/build/lib/logger.native.mjs +0 -12
- package/build/lib/logger.native.mjs.map +0 -1
- package/src/logger.native.ts +0 -11
- package/src/logger.ts +0 -9
package/src/queryCache.ts
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { QueryFilters } from './utils'
|
|
2
|
-
import { hashQueryKeyByOptions, matchQuery
|
|
2
|
+
import { hashQueryKeyByOptions, matchQuery } from './utils'
|
|
3
3
|
import type { Action, QueryState } from './query'
|
|
4
4
|
import { Query } from './query'
|
|
5
|
-
import type {
|
|
5
|
+
import type {
|
|
6
|
+
NotifyEvent,
|
|
7
|
+
QueryKey,
|
|
8
|
+
QueryOptions,
|
|
9
|
+
RegisteredError,
|
|
10
|
+
WithRequired,
|
|
11
|
+
} from './types'
|
|
6
12
|
import { notifyManager } from './notifyManager'
|
|
7
13
|
import type { QueryClient } from './queryClient'
|
|
8
14
|
import { Subscribable } from './subscribable'
|
|
@@ -13,10 +19,7 @@ import type { QueryObserver } from './queryObserver'
|
|
|
13
19
|
interface QueryCacheConfig {
|
|
14
20
|
onError?: (error: unknown, query: Query<unknown, unknown, unknown>) => void
|
|
15
21
|
onSuccess?: (data: unknown, query: Query<unknown, unknown, unknown>) => void
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
interface QueryHashMap {
|
|
19
|
-
[hash: string]: Query<any, any, any, any>
|
|
22
|
+
createStore?: () => QueryStore
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
interface NotifyEventQueryAdded extends NotifyEvent {
|
|
@@ -69,19 +72,22 @@ type QueryCacheNotifyEvent =
|
|
|
69
72
|
|
|
70
73
|
type QueryCacheListener = (event: QueryCacheNotifyEvent) => void
|
|
71
74
|
|
|
75
|
+
export interface QueryStore {
|
|
76
|
+
has: (queryKey: string) => boolean
|
|
77
|
+
set: (queryKey: string, query: Query) => void
|
|
78
|
+
get: (queryKey: string) => Query | undefined
|
|
79
|
+
delete: (queryKey: string) => void
|
|
80
|
+
values: () => IterableIterator<Query>
|
|
81
|
+
}
|
|
82
|
+
|
|
72
83
|
// CLASS
|
|
73
84
|
|
|
74
85
|
export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
75
|
-
|
|
86
|
+
#queries: QueryStore
|
|
76
87
|
|
|
77
|
-
|
|
78
|
-
private queriesMap: QueryHashMap
|
|
79
|
-
|
|
80
|
-
constructor(config?: QueryCacheConfig) {
|
|
88
|
+
constructor(public config: QueryCacheConfig = {}) {
|
|
81
89
|
super()
|
|
82
|
-
this
|
|
83
|
-
this.queries = []
|
|
84
|
-
this.queriesMap = {}
|
|
90
|
+
this.#queries = config.createStore?.() ?? new Map<string, Query>()
|
|
85
91
|
}
|
|
86
92
|
|
|
87
93
|
build<TQueryFnData, TError, TData, TQueryKey extends QueryKey>(
|
|
@@ -97,7 +103,6 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
|
97
103
|
if (!query) {
|
|
98
104
|
query = new Query({
|
|
99
105
|
cache: this,
|
|
100
|
-
logger: client.getLogger(),
|
|
101
106
|
queryKey,
|
|
102
107
|
queryHash,
|
|
103
108
|
options: client.defaultQueryOptions(options),
|
|
@@ -111,9 +116,9 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
|
111
116
|
}
|
|
112
117
|
|
|
113
118
|
add(query: Query<any, any, any, any>): void {
|
|
114
|
-
if (!this.
|
|
115
|
-
this.
|
|
116
|
-
|
|
119
|
+
if (!this.#queries.has(query.queryHash)) {
|
|
120
|
+
this.#queries.set(query.queryHash, query)
|
|
121
|
+
|
|
117
122
|
this.notify({
|
|
118
123
|
type: 'added',
|
|
119
124
|
query,
|
|
@@ -122,15 +127,13 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
|
122
127
|
}
|
|
123
128
|
|
|
124
129
|
remove(query: Query<any, any, any, any>): void {
|
|
125
|
-
const queryInMap = this.
|
|
130
|
+
const queryInMap = this.#queries.get(query.queryHash)
|
|
126
131
|
|
|
127
132
|
if (queryInMap) {
|
|
128
133
|
query.destroy()
|
|
129
134
|
|
|
130
|
-
this.queries = this.queries.filter((x) => x !== query)
|
|
131
|
-
|
|
132
135
|
if (queryInMap === query) {
|
|
133
|
-
|
|
136
|
+
this.#queries.delete(query.queryHash)
|
|
134
137
|
}
|
|
135
138
|
|
|
136
139
|
this.notify({ type: 'removed', query })
|
|
@@ -139,7 +142,7 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
|
139
142
|
|
|
140
143
|
clear(): void {
|
|
141
144
|
notifyManager.batch(() => {
|
|
142
|
-
this.
|
|
145
|
+
this.getAll().forEach((query) => {
|
|
143
146
|
this.remove(query)
|
|
144
147
|
})
|
|
145
148
|
})
|
|
@@ -147,40 +150,38 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
|
147
150
|
|
|
148
151
|
get<
|
|
149
152
|
TQueryFnData = unknown,
|
|
150
|
-
TError =
|
|
153
|
+
TError = RegisteredError,
|
|
151
154
|
TData = TQueryFnData,
|
|
152
155
|
TQueryKey extends QueryKey = QueryKey,
|
|
153
156
|
>(
|
|
154
157
|
queryHash: string,
|
|
155
158
|
): Query<TQueryFnData, TError, TData, TQueryKey> | undefined {
|
|
156
|
-
return this.
|
|
159
|
+
return this.#queries.get(queryHash) as
|
|
160
|
+
| Query<TQueryFnData, TError, TData, TQueryKey>
|
|
161
|
+
| undefined
|
|
157
162
|
}
|
|
158
163
|
|
|
159
164
|
getAll(): Query[] {
|
|
160
|
-
return this.
|
|
165
|
+
return [...this.#queries.values()]
|
|
161
166
|
}
|
|
162
167
|
|
|
163
|
-
find<TQueryFnData = unknown, TError =
|
|
164
|
-
|
|
165
|
-
arg2?: QueryFilters,
|
|
168
|
+
find<TQueryFnData = unknown, TError = RegisteredError, TData = TQueryFnData>(
|
|
169
|
+
filters: WithRequired<QueryFilters, 'queryKey'>,
|
|
166
170
|
): Query<TQueryFnData, TError, TData> | undefined {
|
|
167
|
-
const [filters] = parseFilterArgs(arg1, arg2)
|
|
168
|
-
|
|
169
171
|
if (typeof filters.exact === 'undefined') {
|
|
170
172
|
filters.exact = true
|
|
171
173
|
}
|
|
172
174
|
|
|
173
|
-
return this.
|
|
175
|
+
return this.getAll().find((query) => matchQuery(filters, query)) as
|
|
176
|
+
| Query<TQueryFnData, TError, TData>
|
|
177
|
+
| undefined
|
|
174
178
|
}
|
|
175
179
|
|
|
176
|
-
findAll(
|
|
177
|
-
|
|
178
|
-
findAll(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): Query[]
|
|
179
|
-
findAll(arg1?: QueryKey | QueryFilters, arg2?: QueryFilters): Query[] {
|
|
180
|
-
const [filters] = parseFilterArgs(arg1, arg2)
|
|
180
|
+
findAll(filters: QueryFilters = {}): Query[] {
|
|
181
|
+
const queries = this.getAll()
|
|
181
182
|
return Object.keys(filters).length > 0
|
|
182
|
-
?
|
|
183
|
-
:
|
|
183
|
+
? queries.filter((query) => matchQuery(filters, query))
|
|
184
|
+
: queries
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
notify(event: QueryCacheNotifyEvent) {
|
|
@@ -193,7 +194,7 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
|
193
194
|
|
|
194
195
|
onFocus(): void {
|
|
195
196
|
notifyManager.batch(() => {
|
|
196
|
-
this.
|
|
197
|
+
this.getAll().forEach((query) => {
|
|
197
198
|
query.onFocus()
|
|
198
199
|
})
|
|
199
200
|
})
|
|
@@ -201,7 +202,7 @@ export class QueryCache extends Subscribable<QueryCacheListener> {
|
|
|
201
202
|
|
|
202
203
|
onOnline(): void {
|
|
203
204
|
notifyManager.batch(() => {
|
|
204
|
-
this.
|
|
205
|
+
this.getAll().forEach((query) => {
|
|
205
206
|
query.onOnline()
|
|
206
207
|
})
|
|
207
208
|
})
|