@tanstack/vue-query 4.9.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.
- package/LICENSE +21 -0
- package/README.md +83 -0
- package/build/lib/__mocks__/useBaseQuery.d.ts +2 -0
- package/build/lib/__mocks__/useQueryClient.d.ts +3 -0
- package/build/lib/__tests__/mutationCache.test.d.ts +1 -0
- package/build/lib/__tests__/queryCache.test.d.ts +1 -0
- package/build/lib/__tests__/queryClient.test.d.ts +1 -0
- package/build/lib/__tests__/test-utils.d.ts +9 -0
- package/build/lib/__tests__/useInfiniteQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useIsFetching.test.d.ts +1 -0
- package/build/lib/__tests__/useIsMutating.test.d.ts +1 -0
- package/build/lib/__tests__/useMutation.test.d.ts +1 -0
- package/build/lib/__tests__/useQueries.test.d.ts +1 -0
- package/build/lib/__tests__/useQuery.test.d.ts +1 -0
- package/build/lib/__tests__/useQueryClient.test.d.ts +1 -0
- package/build/lib/__tests__/utils.test.d.ts +1 -0
- package/build/lib/__tests__/vueQueryPlugin.test.d.ts +1 -0
- package/build/lib/devtools/devtools.d.ts +2 -0
- package/build/lib/devtools/devtools.esm.js +163 -0
- package/build/lib/devtools/devtools.esm.js.map +1 -0
- package/build/lib/devtools/devtools.js +167 -0
- package/build/lib/devtools/devtools.js.map +1 -0
- package/build/lib/devtools/devtools.mjs +163 -0
- package/build/lib/devtools/devtools.mjs.map +1 -0
- package/build/lib/devtools/utils.d.ts +15 -0
- package/build/lib/devtools/utils.esm.js +103 -0
- package/build/lib/devtools/utils.esm.js.map +1 -0
- package/build/lib/devtools/utils.js +111 -0
- package/build/lib/devtools/utils.js.map +1 -0
- package/build/lib/devtools/utils.mjs +103 -0
- package/build/lib/devtools/utils.mjs.map +1 -0
- package/build/lib/index.d.ts +21 -0
- package/build/lib/index.esm.js +14 -0
- package/build/lib/index.esm.js.map +1 -0
- package/build/lib/index.js +39 -0
- package/build/lib/index.js.map +1 -0
- package/build/lib/index.mjs +14 -0
- package/build/lib/index.mjs.map +1 -0
- package/build/lib/mutationCache.d.ts +7 -0
- package/build/lib/mutationCache.esm.js +16 -0
- package/build/lib/mutationCache.esm.js.map +1 -0
- package/build/lib/mutationCache.js +20 -0
- package/build/lib/mutationCache.js.map +1 -0
- package/build/lib/mutationCache.mjs +16 -0
- package/build/lib/mutationCache.mjs.map +1 -0
- package/build/lib/queryCache.d.ts +9 -0
- package/build/lib/queryCache.esm.js +25 -0
- package/build/lib/queryCache.esm.js.map +1 -0
- package/build/lib/queryCache.js +29 -0
- package/build/lib/queryCache.js.map +1 -0
- package/build/lib/queryCache.mjs +25 -0
- package/build/lib/queryCache.mjs.map +1 -0
- package/build/lib/queryClient.d.ts +43 -0
- package/build/lib/queryClient.esm.js +173 -0
- package/build/lib/queryClient.esm.js.map +1 -0
- package/build/lib/queryClient.js +177 -0
- package/build/lib/queryClient.js.map +1 -0
- package/build/lib/queryClient.mjs +173 -0
- package/build/lib/queryClient.mjs.map +1 -0
- package/build/lib/types.d.ts +17 -0
- package/build/lib/useBaseQuery.d.ts +10 -0
- package/build/lib/useBaseQuery.esm.js +80 -0
- package/build/lib/useBaseQuery.esm.js.map +1 -0
- package/build/lib/useBaseQuery.js +84 -0
- package/build/lib/useBaseQuery.js.map +1 -0
- package/build/lib/useBaseQuery.mjs +80 -0
- package/build/lib/useBaseQuery.mjs.map +1 -0
- package/build/lib/useInfiniteQuery.d.ts +16 -0
- package/build/lib/useInfiniteQuery.esm.js +15 -0
- package/build/lib/useInfiniteQuery.esm.js.map +1 -0
- package/build/lib/useInfiniteQuery.js +19 -0
- package/build/lib/useInfiniteQuery.js.map +1 -0
- package/build/lib/useInfiniteQuery.mjs +15 -0
- package/build/lib/useInfiniteQuery.mjs.map +1 -0
- package/build/lib/useIsFetching.d.ts +7 -0
- package/build/lib/useIsFetching.esm.js +40 -0
- package/build/lib/useIsFetching.esm.js.map +1 -0
- package/build/lib/useIsFetching.js +45 -0
- package/build/lib/useIsFetching.js.map +1 -0
- package/build/lib/useIsFetching.mjs +40 -0
- package/build/lib/useIsFetching.mjs.map +1 -0
- package/build/lib/useIsMutating.d.ts +7 -0
- package/build/lib/useIsMutating.esm.js +40 -0
- package/build/lib/useIsMutating.esm.js.map +1 -0
- package/build/lib/useIsMutating.js +45 -0
- package/build/lib/useIsMutating.js.map +1 -0
- package/build/lib/useIsMutating.mjs +40 -0
- package/build/lib/useIsMutating.mjs.map +1 -0
- package/build/lib/useMutation.d.ts +17 -0
- package/build/lib/useMutation.esm.js +64 -0
- package/build/lib/useMutation.esm.js.map +1 -0
- package/build/lib/useMutation.js +69 -0
- package/build/lib/useMutation.js.map +1 -0
- package/build/lib/useMutation.mjs +64 -0
- package/build/lib/useMutation.mjs.map +1 -0
- package/build/lib/useQueries.d.ts +49 -0
- package/build/lib/useQueries.esm.js +38 -0
- package/build/lib/useQueries.esm.js.map +1 -0
- package/build/lib/useQueries.js +42 -0
- package/build/lib/useQueries.js.map +1 -0
- package/build/lib/useQueries.mjs +38 -0
- package/build/lib/useQueries.mjs.map +1 -0
- package/build/lib/useQuery.d.ts +36 -0
- package/build/lib/useQuery.esm.js +13 -0
- package/build/lib/useQuery.esm.js.map +1 -0
- package/build/lib/useQuery.js +17 -0
- package/build/lib/useQuery.js.map +1 -0
- package/build/lib/useQuery.mjs +13 -0
- package/build/lib/useQuery.mjs.map +1 -0
- package/build/lib/useQueryClient.d.ts +2 -0
- package/build/lib/useQueryClient.esm.js +24 -0
- package/build/lib/useQueryClient.esm.js.map +1 -0
- package/build/lib/useQueryClient.js +28 -0
- package/build/lib/useQueryClient.js.map +1 -0
- package/build/lib/useQueryClient.mjs +24 -0
- package/build/lib/useQueryClient.mjs.map +1 -0
- package/build/lib/utils.d.ts +8 -0
- package/build/lib/utils.esm.js +55 -0
- package/build/lib/utils.esm.js.map +1 -0
- package/build/lib/utils.js +64 -0
- package/build/lib/utils.js.map +1 -0
- package/build/lib/utils.mjs +55 -0
- package/build/lib/utils.mjs.map +1 -0
- package/build/lib/vueQueryPlugin.d.ts +27 -0
- package/build/lib/vueQueryPlugin.esm.js +80 -0
- package/build/lib/vueQueryPlugin.esm.js.map +1 -0
- package/build/lib/vueQueryPlugin.js +84 -0
- package/build/lib/vueQueryPlugin.js.map +1 -0
- package/build/lib/vueQueryPlugin.mjs +80 -0
- package/build/lib/vueQueryPlugin.mjs.map +1 -0
- package/build/umd/index.development.js +5024 -0
- package/build/umd/index.development.js.map +1 -0
- package/build/umd/index.production.js +2 -0
- package/build/umd/index.production.js.map +1 -0
- package/package.json +55 -0
|
@@ -0,0 +1,5024 @@
|
|
|
1
|
+
(function (global, factory) {
|
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('vue-demi')) :
|
|
3
|
+
typeof define === 'function' && define.amd ? define(['exports', 'vue-demi'], factory) :
|
|
4
|
+
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.VueQuery = {}, global.Vue));
|
|
5
|
+
})(this, (function (exports, vueDemi) { 'use strict';
|
|
6
|
+
|
|
7
|
+
class Subscribable {
|
|
8
|
+
constructor() {
|
|
9
|
+
this.listeners = [];
|
|
10
|
+
this.subscribe = this.subscribe.bind(this);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
subscribe(listener) {
|
|
14
|
+
this.listeners.push(listener);
|
|
15
|
+
this.onSubscribe();
|
|
16
|
+
return () => {
|
|
17
|
+
this.listeners = this.listeners.filter(x => x !== listener);
|
|
18
|
+
this.onUnsubscribe();
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
hasListeners() {
|
|
23
|
+
return this.listeners.length > 0;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
onSubscribe() {// Do nothing
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
onUnsubscribe() {// Do nothing
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// TYPES
|
|
35
|
+
// UTILS
|
|
36
|
+
const isServer = typeof window === 'undefined';
|
|
37
|
+
function noop() {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
function functionalUpdate(updater, input) {
|
|
41
|
+
return typeof updater === 'function' ? updater(input) : updater;
|
|
42
|
+
}
|
|
43
|
+
function isValidTimeout(value) {
|
|
44
|
+
return typeof value === 'number' && value >= 0 && value !== Infinity;
|
|
45
|
+
}
|
|
46
|
+
function difference(array1, array2) {
|
|
47
|
+
return array1.filter(x => array2.indexOf(x) === -1);
|
|
48
|
+
}
|
|
49
|
+
function replaceAt(array, index, value) {
|
|
50
|
+
const copy = array.slice(0);
|
|
51
|
+
copy[index] = value;
|
|
52
|
+
return copy;
|
|
53
|
+
}
|
|
54
|
+
function timeUntilStale(updatedAt, staleTime) {
|
|
55
|
+
return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
|
|
56
|
+
}
|
|
57
|
+
function parseQueryArgs(arg1, arg2, arg3) {
|
|
58
|
+
if (!isQueryKey$1(arg1)) {
|
|
59
|
+
return arg1;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (typeof arg2 === 'function') {
|
|
63
|
+
return { ...arg3,
|
|
64
|
+
queryKey: arg1,
|
|
65
|
+
queryFn: arg2
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return { ...arg2,
|
|
70
|
+
queryKey: arg1
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function parseMutationArgs$1(arg1, arg2, arg3) {
|
|
74
|
+
if (isQueryKey$1(arg1)) {
|
|
75
|
+
if (typeof arg2 === 'function') {
|
|
76
|
+
return { ...arg3,
|
|
77
|
+
mutationKey: arg1,
|
|
78
|
+
mutationFn: arg2
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return { ...arg2,
|
|
83
|
+
mutationKey: arg1
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
if (typeof arg1 === 'function') {
|
|
88
|
+
return { ...arg2,
|
|
89
|
+
mutationFn: arg1
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { ...arg1
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
function parseFilterArgs$1(arg1, arg2, arg3) {
|
|
97
|
+
return isQueryKey$1(arg1) ? [{ ...arg2,
|
|
98
|
+
queryKey: arg1
|
|
99
|
+
}, arg3] : [arg1 || {}, arg2];
|
|
100
|
+
}
|
|
101
|
+
function parseMutationFilterArgs$1(arg1, arg2, arg3) {
|
|
102
|
+
return isQueryKey$1(arg1) ? [{ ...arg2,
|
|
103
|
+
mutationKey: arg1
|
|
104
|
+
}, arg3] : [arg1 || {}, arg2];
|
|
105
|
+
}
|
|
106
|
+
function matchQuery(filters, query) {
|
|
107
|
+
const {
|
|
108
|
+
type = 'all',
|
|
109
|
+
exact,
|
|
110
|
+
fetchStatus,
|
|
111
|
+
predicate,
|
|
112
|
+
queryKey,
|
|
113
|
+
stale
|
|
114
|
+
} = filters;
|
|
115
|
+
|
|
116
|
+
if (isQueryKey$1(queryKey)) {
|
|
117
|
+
if (exact) {
|
|
118
|
+
if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
121
|
+
} else if (!partialMatchKey(query.queryKey, queryKey)) {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (type !== 'all') {
|
|
127
|
+
const isActive = query.isActive();
|
|
128
|
+
|
|
129
|
+
if (type === 'active' && !isActive) {
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (type === 'inactive' && isActive) {
|
|
134
|
+
return false;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (typeof stale === 'boolean' && query.isStale() !== stale) {
|
|
139
|
+
return false;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
if (typeof fetchStatus !== 'undefined' && fetchStatus !== query.state.fetchStatus) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (predicate && !predicate(query)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return true;
|
|
151
|
+
}
|
|
152
|
+
function matchMutation(filters, mutation) {
|
|
153
|
+
const {
|
|
154
|
+
exact,
|
|
155
|
+
fetching,
|
|
156
|
+
predicate,
|
|
157
|
+
mutationKey
|
|
158
|
+
} = filters;
|
|
159
|
+
|
|
160
|
+
if (isQueryKey$1(mutationKey)) {
|
|
161
|
+
if (!mutation.options.mutationKey) {
|
|
162
|
+
return false;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (exact) {
|
|
166
|
+
if (hashQueryKey(mutation.options.mutationKey) !== hashQueryKey(mutationKey)) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
} else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (typeof fetching === 'boolean' && mutation.state.status === 'loading' !== fetching) {
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (predicate && !predicate(mutation)) {
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return true;
|
|
183
|
+
}
|
|
184
|
+
function hashQueryKeyByOptions(queryKey, options) {
|
|
185
|
+
const hashFn = (options == null ? void 0 : options.queryKeyHashFn) || hashQueryKey;
|
|
186
|
+
return hashFn(queryKey);
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Default query keys hash function.
|
|
190
|
+
* Hashes the value into a stable hash.
|
|
191
|
+
*/
|
|
192
|
+
|
|
193
|
+
function hashQueryKey(queryKey) {
|
|
194
|
+
return JSON.stringify(queryKey, (_, val) => isPlainObject$1(val) ? Object.keys(val).sort().reduce((result, key) => {
|
|
195
|
+
result[key] = val[key];
|
|
196
|
+
return result;
|
|
197
|
+
}, {}) : val);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Checks if key `b` partially matches with key `a`.
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
function partialMatchKey(a, b) {
|
|
204
|
+
return partialDeepEqual(a, b);
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Checks if `b` partially matches with `a`.
|
|
208
|
+
*/
|
|
209
|
+
|
|
210
|
+
function partialDeepEqual(a, b) {
|
|
211
|
+
if (a === b) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (typeof a !== typeof b) {
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
if (a && b && typeof a === 'object' && typeof b === 'object') {
|
|
220
|
+
return !Object.keys(b).some(key => !partialDeepEqual(a[key], b[key]));
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
return false;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* This function returns `a` if `b` is deeply equal.
|
|
227
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
228
|
+
* This can be used for structural sharing between JSON values for example.
|
|
229
|
+
*/
|
|
230
|
+
|
|
231
|
+
function replaceEqualDeep(a, b) {
|
|
232
|
+
if (a === b) {
|
|
233
|
+
return a;
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const array = isPlainArray(a) && isPlainArray(b);
|
|
237
|
+
|
|
238
|
+
if (array || isPlainObject$1(a) && isPlainObject$1(b)) {
|
|
239
|
+
const aSize = array ? a.length : Object.keys(a).length;
|
|
240
|
+
const bItems = array ? b : Object.keys(b);
|
|
241
|
+
const bSize = bItems.length;
|
|
242
|
+
const copy = array ? [] : {};
|
|
243
|
+
let equalItems = 0;
|
|
244
|
+
|
|
245
|
+
for (let i = 0; i < bSize; i++) {
|
|
246
|
+
const key = array ? i : bItems[i];
|
|
247
|
+
copy[key] = replaceEqualDeep(a[key], b[key]);
|
|
248
|
+
|
|
249
|
+
if (copy[key] === a[key]) {
|
|
250
|
+
equalItems++;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return aSize === bSize && equalItems === aSize ? a : copy;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
return b;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Shallow compare objects. Only works with objects that always have the same properties.
|
|
261
|
+
*/
|
|
262
|
+
|
|
263
|
+
function shallowEqualObjects(a, b) {
|
|
264
|
+
if (a && !b || b && !a) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
for (const key in a) {
|
|
269
|
+
if (a[key] !== b[key]) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
return true;
|
|
275
|
+
}
|
|
276
|
+
function isPlainArray(value) {
|
|
277
|
+
return Array.isArray(value) && value.length === Object.keys(value).length;
|
|
278
|
+
} // Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
279
|
+
|
|
280
|
+
function isPlainObject$1(o) {
|
|
281
|
+
if (!hasObjectPrototype(o)) {
|
|
282
|
+
return false;
|
|
283
|
+
} // If has modified constructor
|
|
284
|
+
|
|
285
|
+
|
|
286
|
+
const ctor = o.constructor;
|
|
287
|
+
|
|
288
|
+
if (typeof ctor === 'undefined') {
|
|
289
|
+
return true;
|
|
290
|
+
} // If has modified prototype
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
const prot = ctor.prototype;
|
|
294
|
+
|
|
295
|
+
if (!hasObjectPrototype(prot)) {
|
|
296
|
+
return false;
|
|
297
|
+
} // If constructor does not have an Object-specific method
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
301
|
+
return false;
|
|
302
|
+
} // Most likely a plain Object
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
return true;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function hasObjectPrototype(o) {
|
|
309
|
+
return Object.prototype.toString.call(o) === '[object Object]';
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function isQueryKey$1(value) {
|
|
313
|
+
return Array.isArray(value);
|
|
314
|
+
}
|
|
315
|
+
function isError(value) {
|
|
316
|
+
return value instanceof Error;
|
|
317
|
+
}
|
|
318
|
+
function sleep(timeout) {
|
|
319
|
+
return new Promise(resolve => {
|
|
320
|
+
setTimeout(resolve, timeout);
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Schedules a microtask.
|
|
325
|
+
* This can be useful to schedule state updates after rendering.
|
|
326
|
+
*/
|
|
327
|
+
|
|
328
|
+
function scheduleMicrotask(callback) {
|
|
329
|
+
sleep(0).then(callback);
|
|
330
|
+
}
|
|
331
|
+
function getAbortController() {
|
|
332
|
+
if (typeof AbortController === 'function') {
|
|
333
|
+
return new AbortController();
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
function replaceData(prevData, data, options) {
|
|
337
|
+
// Use prev data if an isDataEqual function is defined and returns `true`
|
|
338
|
+
if (options.isDataEqual != null && options.isDataEqual(prevData, data)) {
|
|
339
|
+
return prevData;
|
|
340
|
+
} else if (typeof options.structuralSharing === 'function') {
|
|
341
|
+
return options.structuralSharing(prevData, data);
|
|
342
|
+
} else if (options.structuralSharing !== false) {
|
|
343
|
+
// Structurally share data between prev and new data if needed
|
|
344
|
+
return replaceEqualDeep(prevData, data);
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
return data;
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
class FocusManager extends Subscribable {
|
|
351
|
+
constructor() {
|
|
352
|
+
super();
|
|
353
|
+
|
|
354
|
+
this.setup = onFocus => {
|
|
355
|
+
// addEventListener does not exist in React Native, but window does
|
|
356
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
357
|
+
if (!isServer && window.addEventListener) {
|
|
358
|
+
const listener = () => onFocus(); // Listen to visibillitychange and focus
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
window.addEventListener('visibilitychange', listener, false);
|
|
362
|
+
window.addEventListener('focus', listener, false);
|
|
363
|
+
return () => {
|
|
364
|
+
// Be sure to unsubscribe if a new handler is set
|
|
365
|
+
window.removeEventListener('visibilitychange', listener);
|
|
366
|
+
window.removeEventListener('focus', listener);
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
onSubscribe() {
|
|
373
|
+
if (!this.cleanup) {
|
|
374
|
+
this.setEventListener(this.setup);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
onUnsubscribe() {
|
|
379
|
+
if (!this.hasListeners()) {
|
|
380
|
+
var _this$cleanup;
|
|
381
|
+
|
|
382
|
+
(_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
|
|
383
|
+
this.cleanup = undefined;
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
setEventListener(setup) {
|
|
388
|
+
var _this$cleanup2;
|
|
389
|
+
|
|
390
|
+
this.setup = setup;
|
|
391
|
+
(_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
|
|
392
|
+
this.cleanup = setup(focused => {
|
|
393
|
+
if (typeof focused === 'boolean') {
|
|
394
|
+
this.setFocused(focused);
|
|
395
|
+
} else {
|
|
396
|
+
this.onFocus();
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
setFocused(focused) {
|
|
402
|
+
this.focused = focused;
|
|
403
|
+
|
|
404
|
+
if (focused) {
|
|
405
|
+
this.onFocus();
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
onFocus() {
|
|
410
|
+
this.listeners.forEach(listener => {
|
|
411
|
+
listener();
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
isFocused() {
|
|
416
|
+
if (typeof this.focused === 'boolean') {
|
|
417
|
+
return this.focused;
|
|
418
|
+
} // document global can be unavailable in react native
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
if (typeof document === 'undefined') {
|
|
422
|
+
return true;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
return [undefined, 'visible', 'prerender'].includes(document.visibilityState);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
}
|
|
429
|
+
const focusManager = new FocusManager();
|
|
430
|
+
|
|
431
|
+
class OnlineManager extends Subscribable {
|
|
432
|
+
constructor() {
|
|
433
|
+
super();
|
|
434
|
+
|
|
435
|
+
this.setup = onOnline => {
|
|
436
|
+
// addEventListener does not exist in React Native, but window does
|
|
437
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
438
|
+
if (!isServer && window.addEventListener) {
|
|
439
|
+
const listener = () => onOnline(); // Listen to online
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
window.addEventListener('online', listener, false);
|
|
443
|
+
window.addEventListener('offline', listener, false);
|
|
444
|
+
return () => {
|
|
445
|
+
// Be sure to unsubscribe if a new handler is set
|
|
446
|
+
window.removeEventListener('online', listener);
|
|
447
|
+
window.removeEventListener('offline', listener);
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
};
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
onSubscribe() {
|
|
454
|
+
if (!this.cleanup) {
|
|
455
|
+
this.setEventListener(this.setup);
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
onUnsubscribe() {
|
|
460
|
+
if (!this.hasListeners()) {
|
|
461
|
+
var _this$cleanup;
|
|
462
|
+
|
|
463
|
+
(_this$cleanup = this.cleanup) == null ? void 0 : _this$cleanup.call(this);
|
|
464
|
+
this.cleanup = undefined;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
setEventListener(setup) {
|
|
469
|
+
var _this$cleanup2;
|
|
470
|
+
|
|
471
|
+
this.setup = setup;
|
|
472
|
+
(_this$cleanup2 = this.cleanup) == null ? void 0 : _this$cleanup2.call(this);
|
|
473
|
+
this.cleanup = setup(online => {
|
|
474
|
+
if (typeof online === 'boolean') {
|
|
475
|
+
this.setOnline(online);
|
|
476
|
+
} else {
|
|
477
|
+
this.onOnline();
|
|
478
|
+
}
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
setOnline(online) {
|
|
483
|
+
this.online = online;
|
|
484
|
+
|
|
485
|
+
if (online) {
|
|
486
|
+
this.onOnline();
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
onOnline() {
|
|
491
|
+
this.listeners.forEach(listener => {
|
|
492
|
+
listener();
|
|
493
|
+
});
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
isOnline() {
|
|
497
|
+
if (typeof this.online === 'boolean') {
|
|
498
|
+
return this.online;
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
if (typeof navigator === 'undefined' || typeof navigator.onLine === 'undefined') {
|
|
502
|
+
return true;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
return navigator.onLine;
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
}
|
|
509
|
+
const onlineManager = new OnlineManager();
|
|
510
|
+
|
|
511
|
+
function defaultRetryDelay(failureCount) {
|
|
512
|
+
return Math.min(1000 * 2 ** failureCount, 30000);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
function canFetch(networkMode) {
|
|
516
|
+
return (networkMode != null ? networkMode : 'online') === 'online' ? onlineManager.isOnline() : true;
|
|
517
|
+
}
|
|
518
|
+
class CancelledError {
|
|
519
|
+
constructor(options) {
|
|
520
|
+
this.revert = options == null ? void 0 : options.revert;
|
|
521
|
+
this.silent = options == null ? void 0 : options.silent;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
}
|
|
525
|
+
function isCancelledError(value) {
|
|
526
|
+
return value instanceof CancelledError;
|
|
527
|
+
}
|
|
528
|
+
function createRetryer(config) {
|
|
529
|
+
let isRetryCancelled = false;
|
|
530
|
+
let failureCount = 0;
|
|
531
|
+
let isResolved = false;
|
|
532
|
+
let continueFn;
|
|
533
|
+
let promiseResolve;
|
|
534
|
+
let promiseReject;
|
|
535
|
+
const promise = new Promise((outerResolve, outerReject) => {
|
|
536
|
+
promiseResolve = outerResolve;
|
|
537
|
+
promiseReject = outerReject;
|
|
538
|
+
});
|
|
539
|
+
|
|
540
|
+
const cancel = cancelOptions => {
|
|
541
|
+
if (!isResolved) {
|
|
542
|
+
reject(new CancelledError(cancelOptions));
|
|
543
|
+
config.abort == null ? void 0 : config.abort();
|
|
544
|
+
}
|
|
545
|
+
};
|
|
546
|
+
|
|
547
|
+
const cancelRetry = () => {
|
|
548
|
+
isRetryCancelled = true;
|
|
549
|
+
};
|
|
550
|
+
|
|
551
|
+
const continueRetry = () => {
|
|
552
|
+
isRetryCancelled = false;
|
|
553
|
+
};
|
|
554
|
+
|
|
555
|
+
const shouldPause = () => !focusManager.isFocused() || config.networkMode !== 'always' && !onlineManager.isOnline();
|
|
556
|
+
|
|
557
|
+
const resolve = value => {
|
|
558
|
+
if (!isResolved) {
|
|
559
|
+
isResolved = true;
|
|
560
|
+
config.onSuccess == null ? void 0 : config.onSuccess(value);
|
|
561
|
+
continueFn == null ? void 0 : continueFn();
|
|
562
|
+
promiseResolve(value);
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
const reject = value => {
|
|
567
|
+
if (!isResolved) {
|
|
568
|
+
isResolved = true;
|
|
569
|
+
config.onError == null ? void 0 : config.onError(value);
|
|
570
|
+
continueFn == null ? void 0 : continueFn();
|
|
571
|
+
promiseReject(value);
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
const pause = () => {
|
|
576
|
+
return new Promise(continueResolve => {
|
|
577
|
+
continueFn = value => {
|
|
578
|
+
if (isResolved || !shouldPause()) {
|
|
579
|
+
return continueResolve(value);
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
config.onPause == null ? void 0 : config.onPause();
|
|
584
|
+
}).then(() => {
|
|
585
|
+
continueFn = undefined;
|
|
586
|
+
|
|
587
|
+
if (!isResolved) {
|
|
588
|
+
config.onContinue == null ? void 0 : config.onContinue();
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}; // Create loop function
|
|
592
|
+
|
|
593
|
+
|
|
594
|
+
const run = () => {
|
|
595
|
+
// Do nothing if already resolved
|
|
596
|
+
if (isResolved) {
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
let promiseOrValue; // Execute query
|
|
601
|
+
|
|
602
|
+
try {
|
|
603
|
+
promiseOrValue = config.fn();
|
|
604
|
+
} catch (error) {
|
|
605
|
+
promiseOrValue = Promise.reject(error);
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
Promise.resolve(promiseOrValue).then(resolve).catch(error => {
|
|
609
|
+
var _config$retry, _config$retryDelay;
|
|
610
|
+
|
|
611
|
+
// Stop if the fetch is already resolved
|
|
612
|
+
if (isResolved) {
|
|
613
|
+
return;
|
|
614
|
+
} // Do we need to retry the request?
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
const retry = (_config$retry = config.retry) != null ? _config$retry : 3;
|
|
618
|
+
const retryDelay = (_config$retryDelay = config.retryDelay) != null ? _config$retryDelay : defaultRetryDelay;
|
|
619
|
+
const delay = typeof retryDelay === 'function' ? retryDelay(failureCount, error) : retryDelay;
|
|
620
|
+
const shouldRetry = retry === true || typeof retry === 'number' && failureCount < retry || typeof retry === 'function' && retry(failureCount, error);
|
|
621
|
+
|
|
622
|
+
if (isRetryCancelled || !shouldRetry) {
|
|
623
|
+
// We are done if the query does not need to be retried
|
|
624
|
+
reject(error);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
failureCount++; // Notify on fail
|
|
629
|
+
|
|
630
|
+
config.onFail == null ? void 0 : config.onFail(failureCount, error); // Delay
|
|
631
|
+
|
|
632
|
+
sleep(delay) // Pause if the document is not visible or when the device is offline
|
|
633
|
+
.then(() => {
|
|
634
|
+
if (shouldPause()) {
|
|
635
|
+
return pause();
|
|
636
|
+
}
|
|
637
|
+
}).then(() => {
|
|
638
|
+
if (isRetryCancelled) {
|
|
639
|
+
reject(error);
|
|
640
|
+
} else {
|
|
641
|
+
run();
|
|
642
|
+
}
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
}; // Start loop
|
|
646
|
+
|
|
647
|
+
|
|
648
|
+
if (canFetch(config.networkMode)) {
|
|
649
|
+
run();
|
|
650
|
+
} else {
|
|
651
|
+
pause().then(run);
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
return {
|
|
655
|
+
promise,
|
|
656
|
+
cancel,
|
|
657
|
+
continue: () => {
|
|
658
|
+
continueFn == null ? void 0 : continueFn();
|
|
659
|
+
},
|
|
660
|
+
cancelRetry,
|
|
661
|
+
continueRetry
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
const defaultLogger = console;
|
|
666
|
+
|
|
667
|
+
function createNotifyManager() {
|
|
668
|
+
let queue = [];
|
|
669
|
+
let transactions = 0;
|
|
670
|
+
|
|
671
|
+
let notifyFn = callback => {
|
|
672
|
+
callback();
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
let batchNotifyFn = callback => {
|
|
676
|
+
callback();
|
|
677
|
+
};
|
|
678
|
+
|
|
679
|
+
const batch = callback => {
|
|
680
|
+
let result;
|
|
681
|
+
transactions++;
|
|
682
|
+
|
|
683
|
+
try {
|
|
684
|
+
result = callback();
|
|
685
|
+
} finally {
|
|
686
|
+
transactions--;
|
|
687
|
+
|
|
688
|
+
if (!transactions) {
|
|
689
|
+
flush();
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
return result;
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const schedule = callback => {
|
|
697
|
+
if (transactions) {
|
|
698
|
+
queue.push(callback);
|
|
699
|
+
} else {
|
|
700
|
+
scheduleMicrotask(() => {
|
|
701
|
+
notifyFn(callback);
|
|
702
|
+
});
|
|
703
|
+
}
|
|
704
|
+
};
|
|
705
|
+
/**
|
|
706
|
+
* All calls to the wrapped function will be batched.
|
|
707
|
+
*/
|
|
708
|
+
|
|
709
|
+
|
|
710
|
+
const batchCalls = callback => {
|
|
711
|
+
return (...args) => {
|
|
712
|
+
schedule(() => {
|
|
713
|
+
callback(...args);
|
|
714
|
+
});
|
|
715
|
+
};
|
|
716
|
+
};
|
|
717
|
+
|
|
718
|
+
const flush = () => {
|
|
719
|
+
const originalQueue = queue;
|
|
720
|
+
queue = [];
|
|
721
|
+
|
|
722
|
+
if (originalQueue.length) {
|
|
723
|
+
scheduleMicrotask(() => {
|
|
724
|
+
batchNotifyFn(() => {
|
|
725
|
+
originalQueue.forEach(callback => {
|
|
726
|
+
notifyFn(callback);
|
|
727
|
+
});
|
|
728
|
+
});
|
|
729
|
+
});
|
|
730
|
+
}
|
|
731
|
+
};
|
|
732
|
+
/**
|
|
733
|
+
* Use this method to set a custom notify function.
|
|
734
|
+
* This can be used to for example wrap notifications with `React.act` while running tests.
|
|
735
|
+
*/
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
const setNotifyFunction = fn => {
|
|
739
|
+
notifyFn = fn;
|
|
740
|
+
};
|
|
741
|
+
/**
|
|
742
|
+
* Use this method to set a custom function to batch notifications together into a single tick.
|
|
743
|
+
* By default React Query will use the batch function provided by ReactDOM or React Native.
|
|
744
|
+
*/
|
|
745
|
+
|
|
746
|
+
|
|
747
|
+
const setBatchNotifyFunction = fn => {
|
|
748
|
+
batchNotifyFn = fn;
|
|
749
|
+
};
|
|
750
|
+
|
|
751
|
+
return {
|
|
752
|
+
batch,
|
|
753
|
+
batchCalls,
|
|
754
|
+
schedule,
|
|
755
|
+
setNotifyFunction,
|
|
756
|
+
setBatchNotifyFunction
|
|
757
|
+
};
|
|
758
|
+
} // SINGLETON
|
|
759
|
+
|
|
760
|
+
const notifyManager = createNotifyManager();
|
|
761
|
+
|
|
762
|
+
class Removable {
|
|
763
|
+
destroy() {
|
|
764
|
+
this.clearGcTimeout();
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
scheduleGc() {
|
|
768
|
+
this.clearGcTimeout();
|
|
769
|
+
|
|
770
|
+
if (isValidTimeout(this.cacheTime)) {
|
|
771
|
+
this.gcTimeout = setTimeout(() => {
|
|
772
|
+
this.optionalRemove();
|
|
773
|
+
}, this.cacheTime);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
updateCacheTime(newCacheTime) {
|
|
778
|
+
// Default to 5 minutes (Infinity for server-side) if no cache time is set
|
|
779
|
+
this.cacheTime = Math.max(this.cacheTime || 0, newCacheTime != null ? newCacheTime : isServer ? Infinity : 5 * 60 * 1000);
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
clearGcTimeout() {
|
|
783
|
+
if (this.gcTimeout) {
|
|
784
|
+
clearTimeout(this.gcTimeout);
|
|
785
|
+
this.gcTimeout = undefined;
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// CLASS
|
|
792
|
+
class Query extends Removable {
|
|
793
|
+
constructor(config) {
|
|
794
|
+
super();
|
|
795
|
+
this.abortSignalConsumed = false;
|
|
796
|
+
this.defaultOptions = config.defaultOptions;
|
|
797
|
+
this.setOptions(config.options);
|
|
798
|
+
this.observers = [];
|
|
799
|
+
this.cache = config.cache;
|
|
800
|
+
this.logger = config.logger || defaultLogger;
|
|
801
|
+
this.queryKey = config.queryKey;
|
|
802
|
+
this.queryHash = config.queryHash;
|
|
803
|
+
this.initialState = config.state || getDefaultState$1(this.options);
|
|
804
|
+
this.state = this.initialState;
|
|
805
|
+
this.meta = config.meta;
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
setOptions(options) {
|
|
809
|
+
this.options = { ...this.defaultOptions,
|
|
810
|
+
...options
|
|
811
|
+
};
|
|
812
|
+
this.meta = options == null ? void 0 : options.meta;
|
|
813
|
+
this.updateCacheTime(this.options.cacheTime);
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
optionalRemove() {
|
|
817
|
+
if (!this.observers.length && this.state.fetchStatus === 'idle') {
|
|
818
|
+
this.cache.remove(this);
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
|
|
822
|
+
setData(newData, options) {
|
|
823
|
+
const data = replaceData(this.state.data, newData, this.options); // Set data and mark it as cached
|
|
824
|
+
|
|
825
|
+
this.dispatch({
|
|
826
|
+
data,
|
|
827
|
+
type: 'success',
|
|
828
|
+
dataUpdatedAt: options == null ? void 0 : options.updatedAt,
|
|
829
|
+
manual: options == null ? void 0 : options.manual
|
|
830
|
+
});
|
|
831
|
+
return data;
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
setState(state, setStateOptions) {
|
|
835
|
+
this.dispatch({
|
|
836
|
+
type: 'setState',
|
|
837
|
+
state,
|
|
838
|
+
setStateOptions
|
|
839
|
+
});
|
|
840
|
+
}
|
|
841
|
+
|
|
842
|
+
cancel(options) {
|
|
843
|
+
var _this$retryer;
|
|
844
|
+
|
|
845
|
+
const promise = this.promise;
|
|
846
|
+
(_this$retryer = this.retryer) == null ? void 0 : _this$retryer.cancel(options);
|
|
847
|
+
return promise ? promise.then(noop).catch(noop) : Promise.resolve();
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
destroy() {
|
|
851
|
+
super.destroy();
|
|
852
|
+
this.cancel({
|
|
853
|
+
silent: true
|
|
854
|
+
});
|
|
855
|
+
}
|
|
856
|
+
|
|
857
|
+
reset() {
|
|
858
|
+
this.destroy();
|
|
859
|
+
this.setState(this.initialState);
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
isActive() {
|
|
863
|
+
return this.observers.some(observer => observer.options.enabled !== false);
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
isDisabled() {
|
|
867
|
+
return this.getObserversCount() > 0 && !this.isActive();
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
isStale() {
|
|
871
|
+
return this.state.isInvalidated || !this.state.dataUpdatedAt || this.observers.some(observer => observer.getCurrentResult().isStale);
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
isStaleByTime(staleTime = 0) {
|
|
875
|
+
return this.state.isInvalidated || !this.state.dataUpdatedAt || !timeUntilStale(this.state.dataUpdatedAt, staleTime);
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
onFocus() {
|
|
879
|
+
var _this$retryer2;
|
|
880
|
+
|
|
881
|
+
const observer = this.observers.find(x => x.shouldFetchOnWindowFocus());
|
|
882
|
+
|
|
883
|
+
if (observer) {
|
|
884
|
+
observer.refetch({
|
|
885
|
+
cancelRefetch: false
|
|
886
|
+
});
|
|
887
|
+
} // Continue fetch if currently paused
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
(_this$retryer2 = this.retryer) == null ? void 0 : _this$retryer2.continue();
|
|
891
|
+
}
|
|
892
|
+
|
|
893
|
+
onOnline() {
|
|
894
|
+
var _this$retryer3;
|
|
895
|
+
|
|
896
|
+
const observer = this.observers.find(x => x.shouldFetchOnReconnect());
|
|
897
|
+
|
|
898
|
+
if (observer) {
|
|
899
|
+
observer.refetch({
|
|
900
|
+
cancelRefetch: false
|
|
901
|
+
});
|
|
902
|
+
} // Continue fetch if currently paused
|
|
903
|
+
|
|
904
|
+
|
|
905
|
+
(_this$retryer3 = this.retryer) == null ? void 0 : _this$retryer3.continue();
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
addObserver(observer) {
|
|
909
|
+
if (this.observers.indexOf(observer) === -1) {
|
|
910
|
+
this.observers.push(observer); // Stop the query from being garbage collected
|
|
911
|
+
|
|
912
|
+
this.clearGcTimeout();
|
|
913
|
+
this.cache.notify({
|
|
914
|
+
type: 'observerAdded',
|
|
915
|
+
query: this,
|
|
916
|
+
observer
|
|
917
|
+
});
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
removeObserver(observer) {
|
|
922
|
+
if (this.observers.indexOf(observer) !== -1) {
|
|
923
|
+
this.observers = this.observers.filter(x => x !== observer);
|
|
924
|
+
|
|
925
|
+
if (!this.observers.length) {
|
|
926
|
+
// If the transport layer does not support cancellation
|
|
927
|
+
// we'll let the query continue so the result can be cached
|
|
928
|
+
if (this.retryer) {
|
|
929
|
+
if (this.abortSignalConsumed) {
|
|
930
|
+
this.retryer.cancel({
|
|
931
|
+
revert: true
|
|
932
|
+
});
|
|
933
|
+
} else {
|
|
934
|
+
this.retryer.cancelRetry();
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
|
|
938
|
+
this.scheduleGc();
|
|
939
|
+
}
|
|
940
|
+
|
|
941
|
+
this.cache.notify({
|
|
942
|
+
type: 'observerRemoved',
|
|
943
|
+
query: this,
|
|
944
|
+
observer
|
|
945
|
+
});
|
|
946
|
+
}
|
|
947
|
+
}
|
|
948
|
+
|
|
949
|
+
getObserversCount() {
|
|
950
|
+
return this.observers.length;
|
|
951
|
+
}
|
|
952
|
+
|
|
953
|
+
invalidate() {
|
|
954
|
+
if (!this.state.isInvalidated) {
|
|
955
|
+
this.dispatch({
|
|
956
|
+
type: 'invalidate'
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
fetch(options, fetchOptions) {
|
|
962
|
+
var _this$options$behavio, _context$fetchOptions;
|
|
963
|
+
|
|
964
|
+
if (this.state.fetchStatus !== 'idle') {
|
|
965
|
+
if (this.state.dataUpdatedAt && fetchOptions != null && fetchOptions.cancelRefetch) {
|
|
966
|
+
// Silently cancel current fetch if the user wants to cancel refetches
|
|
967
|
+
this.cancel({
|
|
968
|
+
silent: true
|
|
969
|
+
});
|
|
970
|
+
} else if (this.promise) {
|
|
971
|
+
var _this$retryer4;
|
|
972
|
+
|
|
973
|
+
// make sure that retries that were potentially cancelled due to unmounts can continue
|
|
974
|
+
(_this$retryer4 = this.retryer) == null ? void 0 : _this$retryer4.continueRetry(); // Return current promise if we are already fetching
|
|
975
|
+
|
|
976
|
+
return this.promise;
|
|
977
|
+
}
|
|
978
|
+
} // Update config if passed, otherwise the config from the last execution is used
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
if (options) {
|
|
982
|
+
this.setOptions(options);
|
|
983
|
+
} // Use the options from the first observer with a query function if no function is found.
|
|
984
|
+
// This can happen when the query is hydrated or created with setQueryData.
|
|
985
|
+
|
|
986
|
+
|
|
987
|
+
if (!this.options.queryFn) {
|
|
988
|
+
const observer = this.observers.find(x => x.options.queryFn);
|
|
989
|
+
|
|
990
|
+
if (observer) {
|
|
991
|
+
this.setOptions(observer.options);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
if (!Array.isArray(this.options.queryKey)) {
|
|
996
|
+
{
|
|
997
|
+
this.logger.error("As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']");
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
|
|
1001
|
+
const abortController = getAbortController(); // Create query function context
|
|
1002
|
+
|
|
1003
|
+
const queryFnContext = {
|
|
1004
|
+
queryKey: this.queryKey,
|
|
1005
|
+
pageParam: undefined,
|
|
1006
|
+
meta: this.meta
|
|
1007
|
+
}; // Adds an enumerable signal property to the object that
|
|
1008
|
+
// which sets abortSignalConsumed to true when the signal
|
|
1009
|
+
// is read.
|
|
1010
|
+
|
|
1011
|
+
const addSignalProperty = object => {
|
|
1012
|
+
Object.defineProperty(object, 'signal', {
|
|
1013
|
+
enumerable: true,
|
|
1014
|
+
get: () => {
|
|
1015
|
+
if (abortController) {
|
|
1016
|
+
this.abortSignalConsumed = true;
|
|
1017
|
+
return abortController.signal;
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
return undefined;
|
|
1021
|
+
}
|
|
1022
|
+
});
|
|
1023
|
+
};
|
|
1024
|
+
|
|
1025
|
+
addSignalProperty(queryFnContext); // Create fetch function
|
|
1026
|
+
|
|
1027
|
+
const fetchFn = () => {
|
|
1028
|
+
if (!this.options.queryFn) {
|
|
1029
|
+
return Promise.reject('Missing queryFn');
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
this.abortSignalConsumed = false;
|
|
1033
|
+
return this.options.queryFn(queryFnContext);
|
|
1034
|
+
}; // Trigger behavior hook
|
|
1035
|
+
|
|
1036
|
+
|
|
1037
|
+
const context = {
|
|
1038
|
+
fetchOptions,
|
|
1039
|
+
options: this.options,
|
|
1040
|
+
queryKey: this.queryKey,
|
|
1041
|
+
state: this.state,
|
|
1042
|
+
fetchFn,
|
|
1043
|
+
meta: this.meta
|
|
1044
|
+
};
|
|
1045
|
+
addSignalProperty(context);
|
|
1046
|
+
(_this$options$behavio = this.options.behavior) == null ? void 0 : _this$options$behavio.onFetch(context); // Store state in case the current fetch needs to be reverted
|
|
1047
|
+
|
|
1048
|
+
this.revertState = this.state; // Set to fetching state if not already in it
|
|
1049
|
+
|
|
1050
|
+
if (this.state.fetchStatus === 'idle' || this.state.fetchMeta !== ((_context$fetchOptions = context.fetchOptions) == null ? void 0 : _context$fetchOptions.meta)) {
|
|
1051
|
+
var _context$fetchOptions2;
|
|
1052
|
+
|
|
1053
|
+
this.dispatch({
|
|
1054
|
+
type: 'fetch',
|
|
1055
|
+
meta: (_context$fetchOptions2 = context.fetchOptions) == null ? void 0 : _context$fetchOptions2.meta
|
|
1056
|
+
});
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1059
|
+
const onError = error => {
|
|
1060
|
+
// Optimistically update state if needed
|
|
1061
|
+
if (!(isCancelledError(error) && error.silent)) {
|
|
1062
|
+
this.dispatch({
|
|
1063
|
+
type: 'error',
|
|
1064
|
+
error: error
|
|
1065
|
+
});
|
|
1066
|
+
}
|
|
1067
|
+
|
|
1068
|
+
if (!isCancelledError(error)) {
|
|
1069
|
+
var _this$cache$config$on, _this$cache$config;
|
|
1070
|
+
|
|
1071
|
+
// Notify cache callback
|
|
1072
|
+
(_this$cache$config$on = (_this$cache$config = this.cache.config).onError) == null ? void 0 : _this$cache$config$on.call(_this$cache$config, error, this);
|
|
1073
|
+
|
|
1074
|
+
{
|
|
1075
|
+
this.logger.error(error);
|
|
1076
|
+
}
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
if (!this.isFetchingOptimistic) {
|
|
1080
|
+
// Schedule query gc after fetching
|
|
1081
|
+
this.scheduleGc();
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
this.isFetchingOptimistic = false;
|
|
1085
|
+
}; // Try to fetch the data
|
|
1086
|
+
|
|
1087
|
+
|
|
1088
|
+
this.retryer = createRetryer({
|
|
1089
|
+
fn: context.fetchFn,
|
|
1090
|
+
abort: abortController == null ? void 0 : abortController.abort.bind(abortController),
|
|
1091
|
+
onSuccess: data => {
|
|
1092
|
+
var _this$cache$config$on2, _this$cache$config2;
|
|
1093
|
+
|
|
1094
|
+
if (typeof data === 'undefined') {
|
|
1095
|
+
{
|
|
1096
|
+
this.logger.error("Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: " + this.queryHash);
|
|
1097
|
+
}
|
|
1098
|
+
|
|
1099
|
+
onError(new Error('undefined'));
|
|
1100
|
+
return;
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
this.setData(data); // Notify cache callback
|
|
1104
|
+
|
|
1105
|
+
(_this$cache$config$on2 = (_this$cache$config2 = this.cache.config).onSuccess) == null ? void 0 : _this$cache$config$on2.call(_this$cache$config2, data, this);
|
|
1106
|
+
|
|
1107
|
+
if (!this.isFetchingOptimistic) {
|
|
1108
|
+
// Schedule query gc after fetching
|
|
1109
|
+
this.scheduleGc();
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
this.isFetchingOptimistic = false;
|
|
1113
|
+
},
|
|
1114
|
+
onError,
|
|
1115
|
+
onFail: () => {
|
|
1116
|
+
this.dispatch({
|
|
1117
|
+
type: 'failed'
|
|
1118
|
+
});
|
|
1119
|
+
},
|
|
1120
|
+
onPause: () => {
|
|
1121
|
+
this.dispatch({
|
|
1122
|
+
type: 'pause'
|
|
1123
|
+
});
|
|
1124
|
+
},
|
|
1125
|
+
onContinue: () => {
|
|
1126
|
+
this.dispatch({
|
|
1127
|
+
type: 'continue'
|
|
1128
|
+
});
|
|
1129
|
+
},
|
|
1130
|
+
retry: context.options.retry,
|
|
1131
|
+
retryDelay: context.options.retryDelay,
|
|
1132
|
+
networkMode: context.options.networkMode
|
|
1133
|
+
});
|
|
1134
|
+
this.promise = this.retryer.promise;
|
|
1135
|
+
return this.promise;
|
|
1136
|
+
}
|
|
1137
|
+
|
|
1138
|
+
dispatch(action) {
|
|
1139
|
+
const reducer = state => {
|
|
1140
|
+
var _action$meta, _action$dataUpdatedAt;
|
|
1141
|
+
|
|
1142
|
+
switch (action.type) {
|
|
1143
|
+
case 'failed':
|
|
1144
|
+
return { ...state,
|
|
1145
|
+
fetchFailureCount: state.fetchFailureCount + 1
|
|
1146
|
+
};
|
|
1147
|
+
|
|
1148
|
+
case 'pause':
|
|
1149
|
+
return { ...state,
|
|
1150
|
+
fetchStatus: 'paused'
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
case 'continue':
|
|
1154
|
+
return { ...state,
|
|
1155
|
+
fetchStatus: 'fetching'
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
case 'fetch':
|
|
1159
|
+
return { ...state,
|
|
1160
|
+
fetchFailureCount: 0,
|
|
1161
|
+
fetchMeta: (_action$meta = action.meta) != null ? _action$meta : null,
|
|
1162
|
+
fetchStatus: canFetch(this.options.networkMode) ? 'fetching' : 'paused',
|
|
1163
|
+
...(!state.dataUpdatedAt && {
|
|
1164
|
+
error: null,
|
|
1165
|
+
status: 'loading'
|
|
1166
|
+
})
|
|
1167
|
+
};
|
|
1168
|
+
|
|
1169
|
+
case 'success':
|
|
1170
|
+
return { ...state,
|
|
1171
|
+
data: action.data,
|
|
1172
|
+
dataUpdateCount: state.dataUpdateCount + 1,
|
|
1173
|
+
dataUpdatedAt: (_action$dataUpdatedAt = action.dataUpdatedAt) != null ? _action$dataUpdatedAt : Date.now(),
|
|
1174
|
+
error: null,
|
|
1175
|
+
isInvalidated: false,
|
|
1176
|
+
status: 'success',
|
|
1177
|
+
...(!action.manual && {
|
|
1178
|
+
fetchStatus: 'idle',
|
|
1179
|
+
fetchFailureCount: 0
|
|
1180
|
+
})
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
case 'error':
|
|
1184
|
+
const error = action.error;
|
|
1185
|
+
|
|
1186
|
+
if (isCancelledError(error) && error.revert && this.revertState) {
|
|
1187
|
+
return { ...this.revertState
|
|
1188
|
+
};
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
return { ...state,
|
|
1192
|
+
error: error,
|
|
1193
|
+
errorUpdateCount: state.errorUpdateCount + 1,
|
|
1194
|
+
errorUpdatedAt: Date.now(),
|
|
1195
|
+
fetchFailureCount: state.fetchFailureCount + 1,
|
|
1196
|
+
fetchStatus: 'idle',
|
|
1197
|
+
status: 'error'
|
|
1198
|
+
};
|
|
1199
|
+
|
|
1200
|
+
case 'invalidate':
|
|
1201
|
+
return { ...state,
|
|
1202
|
+
isInvalidated: true
|
|
1203
|
+
};
|
|
1204
|
+
|
|
1205
|
+
case 'setState':
|
|
1206
|
+
return { ...state,
|
|
1207
|
+
...action.state
|
|
1208
|
+
};
|
|
1209
|
+
}
|
|
1210
|
+
};
|
|
1211
|
+
|
|
1212
|
+
this.state = reducer(this.state);
|
|
1213
|
+
notifyManager.batch(() => {
|
|
1214
|
+
this.observers.forEach(observer => {
|
|
1215
|
+
observer.onQueryUpdate(action);
|
|
1216
|
+
});
|
|
1217
|
+
this.cache.notify({
|
|
1218
|
+
query: this,
|
|
1219
|
+
type: 'updated',
|
|
1220
|
+
action
|
|
1221
|
+
});
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
function getDefaultState$1(options) {
|
|
1228
|
+
const data = typeof options.initialData === 'function' ? options.initialData() : options.initialData;
|
|
1229
|
+
const hasInitialData = typeof options.initialData !== 'undefined';
|
|
1230
|
+
const initialDataUpdatedAt = hasInitialData ? typeof options.initialDataUpdatedAt === 'function' ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
|
|
1231
|
+
const hasData = typeof data !== 'undefined';
|
|
1232
|
+
return {
|
|
1233
|
+
data,
|
|
1234
|
+
dataUpdateCount: 0,
|
|
1235
|
+
dataUpdatedAt: hasData ? initialDataUpdatedAt != null ? initialDataUpdatedAt : Date.now() : 0,
|
|
1236
|
+
error: null,
|
|
1237
|
+
errorUpdateCount: 0,
|
|
1238
|
+
errorUpdatedAt: 0,
|
|
1239
|
+
fetchFailureCount: 0,
|
|
1240
|
+
fetchMeta: null,
|
|
1241
|
+
isInvalidated: false,
|
|
1242
|
+
status: hasData ? 'success' : 'loading',
|
|
1243
|
+
fetchStatus: 'idle'
|
|
1244
|
+
};
|
|
1245
|
+
}
|
|
1246
|
+
|
|
1247
|
+
// CLASS
|
|
1248
|
+
class QueryCache$1 extends Subscribable {
|
|
1249
|
+
constructor(config) {
|
|
1250
|
+
super();
|
|
1251
|
+
this.config = config || {};
|
|
1252
|
+
this.queries = [];
|
|
1253
|
+
this.queriesMap = {};
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
build(client, options, state) {
|
|
1257
|
+
var _options$queryHash;
|
|
1258
|
+
|
|
1259
|
+
const queryKey = options.queryKey;
|
|
1260
|
+
const queryHash = (_options$queryHash = options.queryHash) != null ? _options$queryHash : hashQueryKeyByOptions(queryKey, options);
|
|
1261
|
+
let query = this.get(queryHash);
|
|
1262
|
+
|
|
1263
|
+
if (!query) {
|
|
1264
|
+
query = new Query({
|
|
1265
|
+
cache: this,
|
|
1266
|
+
logger: client.getLogger(),
|
|
1267
|
+
queryKey,
|
|
1268
|
+
queryHash,
|
|
1269
|
+
options: client.defaultQueryOptions(options),
|
|
1270
|
+
state,
|
|
1271
|
+
defaultOptions: client.getQueryDefaults(queryKey),
|
|
1272
|
+
meta: options.meta
|
|
1273
|
+
});
|
|
1274
|
+
this.add(query);
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
return query;
|
|
1278
|
+
}
|
|
1279
|
+
|
|
1280
|
+
add(query) {
|
|
1281
|
+
if (!this.queriesMap[query.queryHash]) {
|
|
1282
|
+
this.queriesMap[query.queryHash] = query;
|
|
1283
|
+
this.queries.push(query);
|
|
1284
|
+
this.notify({
|
|
1285
|
+
type: 'added',
|
|
1286
|
+
query
|
|
1287
|
+
});
|
|
1288
|
+
}
|
|
1289
|
+
}
|
|
1290
|
+
|
|
1291
|
+
remove(query) {
|
|
1292
|
+
const queryInMap = this.queriesMap[query.queryHash];
|
|
1293
|
+
|
|
1294
|
+
if (queryInMap) {
|
|
1295
|
+
query.destroy();
|
|
1296
|
+
this.queries = this.queries.filter(x => x !== query);
|
|
1297
|
+
|
|
1298
|
+
if (queryInMap === query) {
|
|
1299
|
+
delete this.queriesMap[query.queryHash];
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
this.notify({
|
|
1303
|
+
type: 'removed',
|
|
1304
|
+
query
|
|
1305
|
+
});
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
clear() {
|
|
1310
|
+
notifyManager.batch(() => {
|
|
1311
|
+
this.queries.forEach(query => {
|
|
1312
|
+
this.remove(query);
|
|
1313
|
+
});
|
|
1314
|
+
});
|
|
1315
|
+
}
|
|
1316
|
+
|
|
1317
|
+
get(queryHash) {
|
|
1318
|
+
return this.queriesMap[queryHash];
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
getAll() {
|
|
1322
|
+
return this.queries;
|
|
1323
|
+
}
|
|
1324
|
+
|
|
1325
|
+
find(arg1, arg2) {
|
|
1326
|
+
const [filters] = parseFilterArgs$1(arg1, arg2);
|
|
1327
|
+
|
|
1328
|
+
if (typeof filters.exact === 'undefined') {
|
|
1329
|
+
filters.exact = true;
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
return this.queries.find(query => matchQuery(filters, query));
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
findAll(arg1, arg2) {
|
|
1336
|
+
const [filters] = parseFilterArgs$1(arg1, arg2);
|
|
1337
|
+
return Object.keys(filters).length > 0 ? this.queries.filter(query => matchQuery(filters, query)) : this.queries;
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1340
|
+
notify(event) {
|
|
1341
|
+
notifyManager.batch(() => {
|
|
1342
|
+
this.listeners.forEach(listener => {
|
|
1343
|
+
listener(event);
|
|
1344
|
+
});
|
|
1345
|
+
});
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1348
|
+
onFocus() {
|
|
1349
|
+
notifyManager.batch(() => {
|
|
1350
|
+
this.queries.forEach(query => {
|
|
1351
|
+
query.onFocus();
|
|
1352
|
+
});
|
|
1353
|
+
});
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
onOnline() {
|
|
1357
|
+
notifyManager.batch(() => {
|
|
1358
|
+
this.queries.forEach(query => {
|
|
1359
|
+
query.onOnline();
|
|
1360
|
+
});
|
|
1361
|
+
});
|
|
1362
|
+
}
|
|
1363
|
+
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// CLASS
|
|
1367
|
+
class Mutation extends Removable {
|
|
1368
|
+
constructor(config) {
|
|
1369
|
+
super();
|
|
1370
|
+
this.options = { ...config.defaultOptions,
|
|
1371
|
+
...config.options
|
|
1372
|
+
};
|
|
1373
|
+
this.mutationId = config.mutationId;
|
|
1374
|
+
this.mutationCache = config.mutationCache;
|
|
1375
|
+
this.logger = config.logger || defaultLogger;
|
|
1376
|
+
this.observers = [];
|
|
1377
|
+
this.state = config.state || getDefaultState();
|
|
1378
|
+
this.meta = config.meta;
|
|
1379
|
+
this.updateCacheTime(this.options.cacheTime);
|
|
1380
|
+
this.scheduleGc();
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
setState(state) {
|
|
1384
|
+
this.dispatch({
|
|
1385
|
+
type: 'setState',
|
|
1386
|
+
state
|
|
1387
|
+
});
|
|
1388
|
+
}
|
|
1389
|
+
|
|
1390
|
+
addObserver(observer) {
|
|
1391
|
+
if (this.observers.indexOf(observer) === -1) {
|
|
1392
|
+
this.observers.push(observer); // Stop the mutation from being garbage collected
|
|
1393
|
+
|
|
1394
|
+
this.clearGcTimeout();
|
|
1395
|
+
this.mutationCache.notify({
|
|
1396
|
+
type: 'observerAdded',
|
|
1397
|
+
mutation: this,
|
|
1398
|
+
observer
|
|
1399
|
+
});
|
|
1400
|
+
}
|
|
1401
|
+
}
|
|
1402
|
+
|
|
1403
|
+
removeObserver(observer) {
|
|
1404
|
+
this.observers = this.observers.filter(x => x !== observer);
|
|
1405
|
+
this.scheduleGc();
|
|
1406
|
+
this.mutationCache.notify({
|
|
1407
|
+
type: 'observerRemoved',
|
|
1408
|
+
mutation: this,
|
|
1409
|
+
observer
|
|
1410
|
+
});
|
|
1411
|
+
}
|
|
1412
|
+
|
|
1413
|
+
optionalRemove() {
|
|
1414
|
+
if (!this.observers.length) {
|
|
1415
|
+
if (this.state.status === 'loading') {
|
|
1416
|
+
this.scheduleGc();
|
|
1417
|
+
} else {
|
|
1418
|
+
this.mutationCache.remove(this);
|
|
1419
|
+
}
|
|
1420
|
+
}
|
|
1421
|
+
}
|
|
1422
|
+
|
|
1423
|
+
continue() {
|
|
1424
|
+
if (this.retryer) {
|
|
1425
|
+
this.retryer.continue();
|
|
1426
|
+
return this.retryer.promise;
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
return this.execute();
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
async execute() {
|
|
1433
|
+
const executeMutation = () => {
|
|
1434
|
+
var _this$options$retry;
|
|
1435
|
+
|
|
1436
|
+
this.retryer = createRetryer({
|
|
1437
|
+
fn: () => {
|
|
1438
|
+
if (!this.options.mutationFn) {
|
|
1439
|
+
return Promise.reject('No mutationFn found');
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
return this.options.mutationFn(this.state.variables);
|
|
1443
|
+
},
|
|
1444
|
+
onFail: () => {
|
|
1445
|
+
this.dispatch({
|
|
1446
|
+
type: 'failed'
|
|
1447
|
+
});
|
|
1448
|
+
},
|
|
1449
|
+
onPause: () => {
|
|
1450
|
+
this.dispatch({
|
|
1451
|
+
type: 'pause'
|
|
1452
|
+
});
|
|
1453
|
+
},
|
|
1454
|
+
onContinue: () => {
|
|
1455
|
+
this.dispatch({
|
|
1456
|
+
type: 'continue'
|
|
1457
|
+
});
|
|
1458
|
+
},
|
|
1459
|
+
retry: (_this$options$retry = this.options.retry) != null ? _this$options$retry : 0,
|
|
1460
|
+
retryDelay: this.options.retryDelay,
|
|
1461
|
+
networkMode: this.options.networkMode
|
|
1462
|
+
});
|
|
1463
|
+
return this.retryer.promise;
|
|
1464
|
+
};
|
|
1465
|
+
|
|
1466
|
+
const restored = this.state.status === 'loading';
|
|
1467
|
+
|
|
1468
|
+
try {
|
|
1469
|
+
var _this$mutationCache$c3, _this$mutationCache$c4, _this$options$onSucce, _this$options2, _this$options$onSettl, _this$options3;
|
|
1470
|
+
|
|
1471
|
+
if (!restored) {
|
|
1472
|
+
var _this$mutationCache$c, _this$mutationCache$c2, _this$options$onMutat, _this$options;
|
|
1473
|
+
|
|
1474
|
+
this.dispatch({
|
|
1475
|
+
type: 'loading',
|
|
1476
|
+
variables: this.options.variables
|
|
1477
|
+
}); // Notify cache callback
|
|
1478
|
+
|
|
1479
|
+
(_this$mutationCache$c = (_this$mutationCache$c2 = this.mutationCache.config).onMutate) == null ? void 0 : _this$mutationCache$c.call(_this$mutationCache$c2, this.state.variables, this);
|
|
1480
|
+
const context = await ((_this$options$onMutat = (_this$options = this.options).onMutate) == null ? void 0 : _this$options$onMutat.call(_this$options, this.state.variables));
|
|
1481
|
+
|
|
1482
|
+
if (context !== this.state.context) {
|
|
1483
|
+
this.dispatch({
|
|
1484
|
+
type: 'loading',
|
|
1485
|
+
context,
|
|
1486
|
+
variables: this.state.variables
|
|
1487
|
+
});
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1490
|
+
|
|
1491
|
+
const data = await executeMutation(); // Notify cache callback
|
|
1492
|
+
|
|
1493
|
+
(_this$mutationCache$c3 = (_this$mutationCache$c4 = this.mutationCache.config).onSuccess) == null ? void 0 : _this$mutationCache$c3.call(_this$mutationCache$c4, data, this.state.variables, this.state.context, this);
|
|
1494
|
+
await ((_this$options$onSucce = (_this$options2 = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options2, data, this.state.variables, this.state.context));
|
|
1495
|
+
await ((_this$options$onSettl = (_this$options3 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options3, data, null, this.state.variables, this.state.context));
|
|
1496
|
+
this.dispatch({
|
|
1497
|
+
type: 'success',
|
|
1498
|
+
data
|
|
1499
|
+
});
|
|
1500
|
+
return data;
|
|
1501
|
+
} catch (error) {
|
|
1502
|
+
try {
|
|
1503
|
+
var _this$mutationCache$c5, _this$mutationCache$c6, _this$options$onError, _this$options4, _this$options$onSettl2, _this$options5;
|
|
1504
|
+
|
|
1505
|
+
// Notify cache callback
|
|
1506
|
+
(_this$mutationCache$c5 = (_this$mutationCache$c6 = this.mutationCache.config).onError) == null ? void 0 : _this$mutationCache$c5.call(_this$mutationCache$c6, error, this.state.variables, this.state.context, this);
|
|
1507
|
+
|
|
1508
|
+
if ("development" !== 'production') {
|
|
1509
|
+
this.logger.error(error);
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
await ((_this$options$onError = (_this$options4 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options4, error, this.state.variables, this.state.context));
|
|
1513
|
+
await ((_this$options$onSettl2 = (_this$options5 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options5, undefined, error, this.state.variables, this.state.context));
|
|
1514
|
+
throw error;
|
|
1515
|
+
} finally {
|
|
1516
|
+
this.dispatch({
|
|
1517
|
+
type: 'error',
|
|
1518
|
+
error: error
|
|
1519
|
+
});
|
|
1520
|
+
}
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
dispatch(action) {
|
|
1525
|
+
const reducer = state => {
|
|
1526
|
+
switch (action.type) {
|
|
1527
|
+
case 'failed':
|
|
1528
|
+
return { ...state,
|
|
1529
|
+
failureCount: state.failureCount + 1
|
|
1530
|
+
};
|
|
1531
|
+
|
|
1532
|
+
case 'pause':
|
|
1533
|
+
return { ...state,
|
|
1534
|
+
isPaused: true
|
|
1535
|
+
};
|
|
1536
|
+
|
|
1537
|
+
case 'continue':
|
|
1538
|
+
return { ...state,
|
|
1539
|
+
isPaused: false
|
|
1540
|
+
};
|
|
1541
|
+
|
|
1542
|
+
case 'loading':
|
|
1543
|
+
return { ...state,
|
|
1544
|
+
context: action.context,
|
|
1545
|
+
data: undefined,
|
|
1546
|
+
error: null,
|
|
1547
|
+
isPaused: !canFetch(this.options.networkMode),
|
|
1548
|
+
status: 'loading',
|
|
1549
|
+
variables: action.variables
|
|
1550
|
+
};
|
|
1551
|
+
|
|
1552
|
+
case 'success':
|
|
1553
|
+
return { ...state,
|
|
1554
|
+
data: action.data,
|
|
1555
|
+
error: null,
|
|
1556
|
+
status: 'success',
|
|
1557
|
+
isPaused: false
|
|
1558
|
+
};
|
|
1559
|
+
|
|
1560
|
+
case 'error':
|
|
1561
|
+
return { ...state,
|
|
1562
|
+
data: undefined,
|
|
1563
|
+
error: action.error,
|
|
1564
|
+
failureCount: state.failureCount + 1,
|
|
1565
|
+
isPaused: false,
|
|
1566
|
+
status: 'error'
|
|
1567
|
+
};
|
|
1568
|
+
|
|
1569
|
+
case 'setState':
|
|
1570
|
+
return { ...state,
|
|
1571
|
+
...action.state
|
|
1572
|
+
};
|
|
1573
|
+
}
|
|
1574
|
+
};
|
|
1575
|
+
|
|
1576
|
+
this.state = reducer(this.state);
|
|
1577
|
+
notifyManager.batch(() => {
|
|
1578
|
+
this.observers.forEach(observer => {
|
|
1579
|
+
observer.onMutationUpdate(action);
|
|
1580
|
+
});
|
|
1581
|
+
this.mutationCache.notify({
|
|
1582
|
+
mutation: this,
|
|
1583
|
+
type: 'updated',
|
|
1584
|
+
action
|
|
1585
|
+
});
|
|
1586
|
+
});
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
}
|
|
1590
|
+
function getDefaultState() {
|
|
1591
|
+
return {
|
|
1592
|
+
context: undefined,
|
|
1593
|
+
data: undefined,
|
|
1594
|
+
error: null,
|
|
1595
|
+
failureCount: 0,
|
|
1596
|
+
isPaused: false,
|
|
1597
|
+
status: 'idle',
|
|
1598
|
+
variables: undefined
|
|
1599
|
+
};
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
// CLASS
|
|
1603
|
+
class MutationCache$1 extends Subscribable {
|
|
1604
|
+
constructor(config) {
|
|
1605
|
+
super();
|
|
1606
|
+
this.config = config || {};
|
|
1607
|
+
this.mutations = [];
|
|
1608
|
+
this.mutationId = 0;
|
|
1609
|
+
}
|
|
1610
|
+
|
|
1611
|
+
build(client, options, state) {
|
|
1612
|
+
const mutation = new Mutation({
|
|
1613
|
+
mutationCache: this,
|
|
1614
|
+
logger: client.getLogger(),
|
|
1615
|
+
mutationId: ++this.mutationId,
|
|
1616
|
+
options: client.defaultMutationOptions(options),
|
|
1617
|
+
state,
|
|
1618
|
+
defaultOptions: options.mutationKey ? client.getMutationDefaults(options.mutationKey) : undefined,
|
|
1619
|
+
meta: options.meta
|
|
1620
|
+
});
|
|
1621
|
+
this.add(mutation);
|
|
1622
|
+
return mutation;
|
|
1623
|
+
}
|
|
1624
|
+
|
|
1625
|
+
add(mutation) {
|
|
1626
|
+
this.mutations.push(mutation);
|
|
1627
|
+
this.notify({
|
|
1628
|
+
type: 'added',
|
|
1629
|
+
mutation
|
|
1630
|
+
});
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
remove(mutation) {
|
|
1634
|
+
this.mutations = this.mutations.filter(x => x !== mutation);
|
|
1635
|
+
this.notify({
|
|
1636
|
+
type: 'removed',
|
|
1637
|
+
mutation
|
|
1638
|
+
});
|
|
1639
|
+
}
|
|
1640
|
+
|
|
1641
|
+
clear() {
|
|
1642
|
+
notifyManager.batch(() => {
|
|
1643
|
+
this.mutations.forEach(mutation => {
|
|
1644
|
+
this.remove(mutation);
|
|
1645
|
+
});
|
|
1646
|
+
});
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
getAll() {
|
|
1650
|
+
return this.mutations;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
find(filters) {
|
|
1654
|
+
if (typeof filters.exact === 'undefined') {
|
|
1655
|
+
filters.exact = true;
|
|
1656
|
+
}
|
|
1657
|
+
|
|
1658
|
+
return this.mutations.find(mutation => matchMutation(filters, mutation));
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
findAll(filters) {
|
|
1662
|
+
return this.mutations.filter(mutation => matchMutation(filters, mutation));
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1665
|
+
notify(event) {
|
|
1666
|
+
notifyManager.batch(() => {
|
|
1667
|
+
this.listeners.forEach(listener => {
|
|
1668
|
+
listener(event);
|
|
1669
|
+
});
|
|
1670
|
+
});
|
|
1671
|
+
}
|
|
1672
|
+
|
|
1673
|
+
resumePausedMutations() {
|
|
1674
|
+
const pausedMutations = this.mutations.filter(x => x.state.isPaused);
|
|
1675
|
+
return notifyManager.batch(() => pausedMutations.reduce((promise, mutation) => promise.then(() => mutation.continue().catch(noop)), Promise.resolve()));
|
|
1676
|
+
}
|
|
1677
|
+
|
|
1678
|
+
}
|
|
1679
|
+
|
|
1680
|
+
function infiniteQueryBehavior() {
|
|
1681
|
+
return {
|
|
1682
|
+
onFetch: context => {
|
|
1683
|
+
context.fetchFn = () => {
|
|
1684
|
+
var _context$fetchOptions, _context$fetchOptions2, _context$fetchOptions3, _context$fetchOptions4, _context$state$data, _context$state$data2;
|
|
1685
|
+
|
|
1686
|
+
const refetchPage = (_context$fetchOptions = context.fetchOptions) == null ? void 0 : (_context$fetchOptions2 = _context$fetchOptions.meta) == null ? void 0 : _context$fetchOptions2.refetchPage;
|
|
1687
|
+
const fetchMore = (_context$fetchOptions3 = context.fetchOptions) == null ? void 0 : (_context$fetchOptions4 = _context$fetchOptions3.meta) == null ? void 0 : _context$fetchOptions4.fetchMore;
|
|
1688
|
+
const pageParam = fetchMore == null ? void 0 : fetchMore.pageParam;
|
|
1689
|
+
const isFetchingNextPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'forward';
|
|
1690
|
+
const isFetchingPreviousPage = (fetchMore == null ? void 0 : fetchMore.direction) === 'backward';
|
|
1691
|
+
const oldPages = ((_context$state$data = context.state.data) == null ? void 0 : _context$state$data.pages) || [];
|
|
1692
|
+
const oldPageParams = ((_context$state$data2 = context.state.data) == null ? void 0 : _context$state$data2.pageParams) || [];
|
|
1693
|
+
let newPageParams = oldPageParams;
|
|
1694
|
+
let cancelled = false;
|
|
1695
|
+
|
|
1696
|
+
const addSignalProperty = object => {
|
|
1697
|
+
Object.defineProperty(object, 'signal', {
|
|
1698
|
+
enumerable: true,
|
|
1699
|
+
get: () => {
|
|
1700
|
+
var _context$signal;
|
|
1701
|
+
|
|
1702
|
+
if ((_context$signal = context.signal) != null && _context$signal.aborted) {
|
|
1703
|
+
cancelled = true;
|
|
1704
|
+
} else {
|
|
1705
|
+
var _context$signal2;
|
|
1706
|
+
|
|
1707
|
+
(_context$signal2 = context.signal) == null ? void 0 : _context$signal2.addEventListener('abort', () => {
|
|
1708
|
+
cancelled = true;
|
|
1709
|
+
});
|
|
1710
|
+
}
|
|
1711
|
+
|
|
1712
|
+
return context.signal;
|
|
1713
|
+
}
|
|
1714
|
+
});
|
|
1715
|
+
}; // Get query function
|
|
1716
|
+
|
|
1717
|
+
|
|
1718
|
+
const queryFn = context.options.queryFn || (() => Promise.reject('Missing queryFn'));
|
|
1719
|
+
|
|
1720
|
+
const buildNewPages = (pages, param, page, previous) => {
|
|
1721
|
+
newPageParams = previous ? [param, ...newPageParams] : [...newPageParams, param];
|
|
1722
|
+
return previous ? [page, ...pages] : [...pages, page];
|
|
1723
|
+
}; // Create function to fetch a page
|
|
1724
|
+
|
|
1725
|
+
|
|
1726
|
+
const fetchPage = (pages, manual, param, previous) => {
|
|
1727
|
+
if (cancelled) {
|
|
1728
|
+
return Promise.reject('Cancelled');
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
if (typeof param === 'undefined' && !manual && pages.length) {
|
|
1732
|
+
return Promise.resolve(pages);
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
const queryFnContext = {
|
|
1736
|
+
queryKey: context.queryKey,
|
|
1737
|
+
pageParam: param,
|
|
1738
|
+
meta: context.meta
|
|
1739
|
+
};
|
|
1740
|
+
addSignalProperty(queryFnContext);
|
|
1741
|
+
const queryFnResult = queryFn(queryFnContext);
|
|
1742
|
+
const promise = Promise.resolve(queryFnResult).then(page => buildNewPages(pages, param, page, previous));
|
|
1743
|
+
return promise;
|
|
1744
|
+
};
|
|
1745
|
+
|
|
1746
|
+
let promise; // Fetch first page?
|
|
1747
|
+
|
|
1748
|
+
if (!oldPages.length) {
|
|
1749
|
+
promise = fetchPage([]);
|
|
1750
|
+
} // Fetch next page?
|
|
1751
|
+
else if (isFetchingNextPage) {
|
|
1752
|
+
const manual = typeof pageParam !== 'undefined';
|
|
1753
|
+
const param = manual ? pageParam : getNextPageParam(context.options, oldPages);
|
|
1754
|
+
promise = fetchPage(oldPages, manual, param);
|
|
1755
|
+
} // Fetch previous page?
|
|
1756
|
+
else if (isFetchingPreviousPage) {
|
|
1757
|
+
const manual = typeof pageParam !== 'undefined';
|
|
1758
|
+
const param = manual ? pageParam : getPreviousPageParam(context.options, oldPages);
|
|
1759
|
+
promise = fetchPage(oldPages, manual, param, true);
|
|
1760
|
+
} // Refetch pages
|
|
1761
|
+
else {
|
|
1762
|
+
newPageParams = [];
|
|
1763
|
+
const manual = typeof context.options.getNextPageParam === 'undefined';
|
|
1764
|
+
const shouldFetchFirstPage = refetchPage && oldPages[0] ? refetchPage(oldPages[0], 0, oldPages) : true; // Fetch first page
|
|
1765
|
+
|
|
1766
|
+
promise = shouldFetchFirstPage ? fetchPage([], manual, oldPageParams[0]) : Promise.resolve(buildNewPages([], oldPageParams[0], oldPages[0])); // Fetch remaining pages
|
|
1767
|
+
|
|
1768
|
+
for (let i = 1; i < oldPages.length; i++) {
|
|
1769
|
+
promise = promise.then(pages => {
|
|
1770
|
+
const shouldFetchNextPage = refetchPage && oldPages[i] ? refetchPage(oldPages[i], i, oldPages) : true;
|
|
1771
|
+
|
|
1772
|
+
if (shouldFetchNextPage) {
|
|
1773
|
+
const param = manual ? oldPageParams[i] : getNextPageParam(context.options, pages);
|
|
1774
|
+
return fetchPage(pages, manual, param);
|
|
1775
|
+
}
|
|
1776
|
+
|
|
1777
|
+
return Promise.resolve(buildNewPages(pages, oldPageParams[i], oldPages[i]));
|
|
1778
|
+
});
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
|
|
1782
|
+
const finalPromise = promise.then(pages => ({
|
|
1783
|
+
pages,
|
|
1784
|
+
pageParams: newPageParams
|
|
1785
|
+
}));
|
|
1786
|
+
return finalPromise;
|
|
1787
|
+
};
|
|
1788
|
+
}
|
|
1789
|
+
};
|
|
1790
|
+
}
|
|
1791
|
+
function getNextPageParam(options, pages) {
|
|
1792
|
+
return options.getNextPageParam == null ? void 0 : options.getNextPageParam(pages[pages.length - 1], pages);
|
|
1793
|
+
}
|
|
1794
|
+
function getPreviousPageParam(options, pages) {
|
|
1795
|
+
return options.getPreviousPageParam == null ? void 0 : options.getPreviousPageParam(pages[0], pages);
|
|
1796
|
+
}
|
|
1797
|
+
/**
|
|
1798
|
+
* Checks if there is a next page.
|
|
1799
|
+
* Returns `undefined` if it cannot be determined.
|
|
1800
|
+
*/
|
|
1801
|
+
|
|
1802
|
+
function hasNextPage(options, pages) {
|
|
1803
|
+
if (options.getNextPageParam && Array.isArray(pages)) {
|
|
1804
|
+
const nextPageParam = getNextPageParam(options, pages);
|
|
1805
|
+
return typeof nextPageParam !== 'undefined' && nextPageParam !== null && nextPageParam !== false;
|
|
1806
|
+
}
|
|
1807
|
+
}
|
|
1808
|
+
/**
|
|
1809
|
+
* Checks if there is a previous page.
|
|
1810
|
+
* Returns `undefined` if it cannot be determined.
|
|
1811
|
+
*/
|
|
1812
|
+
|
|
1813
|
+
function hasPreviousPage(options, pages) {
|
|
1814
|
+
if (options.getPreviousPageParam && Array.isArray(pages)) {
|
|
1815
|
+
const previousPageParam = getPreviousPageParam(options, pages);
|
|
1816
|
+
return typeof previousPageParam !== 'undefined' && previousPageParam !== null && previousPageParam !== false;
|
|
1817
|
+
}
|
|
1818
|
+
}
|
|
1819
|
+
|
|
1820
|
+
// CLASS
|
|
1821
|
+
class QueryClient$1 {
|
|
1822
|
+
constructor(config = {}) {
|
|
1823
|
+
this.queryCache = config.queryCache || new QueryCache$1();
|
|
1824
|
+
this.mutationCache = config.mutationCache || new MutationCache$1();
|
|
1825
|
+
this.logger = config.logger || defaultLogger;
|
|
1826
|
+
this.defaultOptions = config.defaultOptions || {};
|
|
1827
|
+
this.queryDefaults = [];
|
|
1828
|
+
this.mutationDefaults = [];
|
|
1829
|
+
}
|
|
1830
|
+
|
|
1831
|
+
mount() {
|
|
1832
|
+
this.unsubscribeFocus = focusManager.subscribe(() => {
|
|
1833
|
+
if (focusManager.isFocused()) {
|
|
1834
|
+
this.resumePausedMutations();
|
|
1835
|
+
this.queryCache.onFocus();
|
|
1836
|
+
}
|
|
1837
|
+
});
|
|
1838
|
+
this.unsubscribeOnline = onlineManager.subscribe(() => {
|
|
1839
|
+
if (onlineManager.isOnline()) {
|
|
1840
|
+
this.resumePausedMutations();
|
|
1841
|
+
this.queryCache.onOnline();
|
|
1842
|
+
}
|
|
1843
|
+
});
|
|
1844
|
+
}
|
|
1845
|
+
|
|
1846
|
+
unmount() {
|
|
1847
|
+
var _this$unsubscribeFocu, _this$unsubscribeOnli;
|
|
1848
|
+
|
|
1849
|
+
(_this$unsubscribeFocu = this.unsubscribeFocus) == null ? void 0 : _this$unsubscribeFocu.call(this);
|
|
1850
|
+
(_this$unsubscribeOnli = this.unsubscribeOnline) == null ? void 0 : _this$unsubscribeOnli.call(this);
|
|
1851
|
+
}
|
|
1852
|
+
|
|
1853
|
+
isFetching(arg1, arg2) {
|
|
1854
|
+
const [filters] = parseFilterArgs$1(arg1, arg2);
|
|
1855
|
+
filters.fetchStatus = 'fetching';
|
|
1856
|
+
return this.queryCache.findAll(filters).length;
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
isMutating(filters) {
|
|
1860
|
+
return this.mutationCache.findAll({ ...filters,
|
|
1861
|
+
fetching: true
|
|
1862
|
+
}).length;
|
|
1863
|
+
}
|
|
1864
|
+
|
|
1865
|
+
getQueryData(queryKey, filters) {
|
|
1866
|
+
var _this$queryCache$find;
|
|
1867
|
+
|
|
1868
|
+
return (_this$queryCache$find = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find.state.data;
|
|
1869
|
+
}
|
|
1870
|
+
|
|
1871
|
+
getQueriesData(queryKeyOrFilters) {
|
|
1872
|
+
return this.getQueryCache().findAll(queryKeyOrFilters).map(({
|
|
1873
|
+
queryKey,
|
|
1874
|
+
state
|
|
1875
|
+
}) => {
|
|
1876
|
+
const data = state.data;
|
|
1877
|
+
return [queryKey, data];
|
|
1878
|
+
});
|
|
1879
|
+
}
|
|
1880
|
+
|
|
1881
|
+
setQueryData(queryKey, updater, options) {
|
|
1882
|
+
const query = this.queryCache.find(queryKey);
|
|
1883
|
+
const prevData = query == null ? void 0 : query.state.data;
|
|
1884
|
+
const data = functionalUpdate(updater, prevData);
|
|
1885
|
+
|
|
1886
|
+
if (typeof data === 'undefined') {
|
|
1887
|
+
return undefined;
|
|
1888
|
+
}
|
|
1889
|
+
|
|
1890
|
+
const parsedOptions = parseQueryArgs(queryKey);
|
|
1891
|
+
const defaultedOptions = this.defaultQueryOptions(parsedOptions);
|
|
1892
|
+
return this.queryCache.build(this, defaultedOptions).setData(data, { ...options,
|
|
1893
|
+
manual: true
|
|
1894
|
+
});
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
setQueriesData(queryKeyOrFilters, updater, options) {
|
|
1898
|
+
return notifyManager.batch(() => this.getQueryCache().findAll(queryKeyOrFilters).map(({
|
|
1899
|
+
queryKey
|
|
1900
|
+
}) => [queryKey, this.setQueryData(queryKey, updater, options)]));
|
|
1901
|
+
}
|
|
1902
|
+
|
|
1903
|
+
getQueryState(queryKey, filters) {
|
|
1904
|
+
var _this$queryCache$find2;
|
|
1905
|
+
|
|
1906
|
+
return (_this$queryCache$find2 = this.queryCache.find(queryKey, filters)) == null ? void 0 : _this$queryCache$find2.state;
|
|
1907
|
+
}
|
|
1908
|
+
|
|
1909
|
+
removeQueries(arg1, arg2) {
|
|
1910
|
+
const [filters] = parseFilterArgs$1(arg1, arg2);
|
|
1911
|
+
const queryCache = this.queryCache;
|
|
1912
|
+
notifyManager.batch(() => {
|
|
1913
|
+
queryCache.findAll(filters).forEach(query => {
|
|
1914
|
+
queryCache.remove(query);
|
|
1915
|
+
});
|
|
1916
|
+
});
|
|
1917
|
+
}
|
|
1918
|
+
|
|
1919
|
+
resetQueries(arg1, arg2, arg3) {
|
|
1920
|
+
const [filters, options] = parseFilterArgs$1(arg1, arg2, arg3);
|
|
1921
|
+
const queryCache = this.queryCache;
|
|
1922
|
+
const refetchFilters = {
|
|
1923
|
+
type: 'active',
|
|
1924
|
+
...filters
|
|
1925
|
+
};
|
|
1926
|
+
return notifyManager.batch(() => {
|
|
1927
|
+
queryCache.findAll(filters).forEach(query => {
|
|
1928
|
+
query.reset();
|
|
1929
|
+
});
|
|
1930
|
+
return this.refetchQueries(refetchFilters, options);
|
|
1931
|
+
});
|
|
1932
|
+
}
|
|
1933
|
+
|
|
1934
|
+
cancelQueries(arg1, arg2, arg3) {
|
|
1935
|
+
const [filters, cancelOptions = {}] = parseFilterArgs$1(arg1, arg2, arg3);
|
|
1936
|
+
|
|
1937
|
+
if (typeof cancelOptions.revert === 'undefined') {
|
|
1938
|
+
cancelOptions.revert = true;
|
|
1939
|
+
}
|
|
1940
|
+
|
|
1941
|
+
const promises = notifyManager.batch(() => this.queryCache.findAll(filters).map(query => query.cancel(cancelOptions)));
|
|
1942
|
+
return Promise.all(promises).then(noop).catch(noop);
|
|
1943
|
+
}
|
|
1944
|
+
|
|
1945
|
+
invalidateQueries(arg1, arg2, arg3) {
|
|
1946
|
+
const [filters, options] = parseFilterArgs$1(arg1, arg2, arg3);
|
|
1947
|
+
return notifyManager.batch(() => {
|
|
1948
|
+
var _ref, _filters$refetchType;
|
|
1949
|
+
|
|
1950
|
+
this.queryCache.findAll(filters).forEach(query => {
|
|
1951
|
+
query.invalidate();
|
|
1952
|
+
});
|
|
1953
|
+
|
|
1954
|
+
if (filters.refetchType === 'none') {
|
|
1955
|
+
return Promise.resolve();
|
|
1956
|
+
}
|
|
1957
|
+
|
|
1958
|
+
const refetchFilters = { ...filters,
|
|
1959
|
+
type: (_ref = (_filters$refetchType = filters.refetchType) != null ? _filters$refetchType : filters.type) != null ? _ref : 'active'
|
|
1960
|
+
};
|
|
1961
|
+
return this.refetchQueries(refetchFilters, options);
|
|
1962
|
+
});
|
|
1963
|
+
}
|
|
1964
|
+
|
|
1965
|
+
refetchQueries(arg1, arg2, arg3) {
|
|
1966
|
+
const [filters, options] = parseFilterArgs$1(arg1, arg2, arg3);
|
|
1967
|
+
const promises = notifyManager.batch(() => this.queryCache.findAll(filters).filter(query => !query.isDisabled()).map(query => {
|
|
1968
|
+
var _options$cancelRefetc;
|
|
1969
|
+
|
|
1970
|
+
return query.fetch(undefined, { ...options,
|
|
1971
|
+
cancelRefetch: (_options$cancelRefetc = options == null ? void 0 : options.cancelRefetch) != null ? _options$cancelRefetc : true,
|
|
1972
|
+
meta: {
|
|
1973
|
+
refetchPage: filters.refetchPage
|
|
1974
|
+
}
|
|
1975
|
+
});
|
|
1976
|
+
}));
|
|
1977
|
+
let promise = Promise.all(promises).then(noop);
|
|
1978
|
+
|
|
1979
|
+
if (!(options != null && options.throwOnError)) {
|
|
1980
|
+
promise = promise.catch(noop);
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
return promise;
|
|
1984
|
+
}
|
|
1985
|
+
|
|
1986
|
+
fetchQuery(arg1, arg2, arg3) {
|
|
1987
|
+
const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
|
|
1988
|
+
const defaultedOptions = this.defaultQueryOptions(parsedOptions); // https://github.com/tannerlinsley/react-query/issues/652
|
|
1989
|
+
|
|
1990
|
+
if (typeof defaultedOptions.retry === 'undefined') {
|
|
1991
|
+
defaultedOptions.retry = false;
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
const query = this.queryCache.build(this, defaultedOptions);
|
|
1995
|
+
return query.isStaleByTime(defaultedOptions.staleTime) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
|
|
1996
|
+
}
|
|
1997
|
+
|
|
1998
|
+
prefetchQuery(arg1, arg2, arg3) {
|
|
1999
|
+
return this.fetchQuery(arg1, arg2, arg3).then(noop).catch(noop);
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
fetchInfiniteQuery(arg1, arg2, arg3) {
|
|
2003
|
+
const parsedOptions = parseQueryArgs(arg1, arg2, arg3);
|
|
2004
|
+
parsedOptions.behavior = infiniteQueryBehavior();
|
|
2005
|
+
return this.fetchQuery(parsedOptions);
|
|
2006
|
+
}
|
|
2007
|
+
|
|
2008
|
+
prefetchInfiniteQuery(arg1, arg2, arg3) {
|
|
2009
|
+
return this.fetchInfiniteQuery(arg1, arg2, arg3).then(noop).catch(noop);
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
resumePausedMutations() {
|
|
2013
|
+
return this.mutationCache.resumePausedMutations();
|
|
2014
|
+
}
|
|
2015
|
+
|
|
2016
|
+
getQueryCache() {
|
|
2017
|
+
return this.queryCache;
|
|
2018
|
+
}
|
|
2019
|
+
|
|
2020
|
+
getMutationCache() {
|
|
2021
|
+
return this.mutationCache;
|
|
2022
|
+
}
|
|
2023
|
+
|
|
2024
|
+
getLogger() {
|
|
2025
|
+
return this.logger;
|
|
2026
|
+
}
|
|
2027
|
+
|
|
2028
|
+
getDefaultOptions() {
|
|
2029
|
+
return this.defaultOptions;
|
|
2030
|
+
}
|
|
2031
|
+
|
|
2032
|
+
setDefaultOptions(options) {
|
|
2033
|
+
this.defaultOptions = options;
|
|
2034
|
+
}
|
|
2035
|
+
|
|
2036
|
+
setQueryDefaults(queryKey, options) {
|
|
2037
|
+
const result = this.queryDefaults.find(x => hashQueryKey(queryKey) === hashQueryKey(x.queryKey));
|
|
2038
|
+
|
|
2039
|
+
if (result) {
|
|
2040
|
+
result.defaultOptions = options;
|
|
2041
|
+
} else {
|
|
2042
|
+
this.queryDefaults.push({
|
|
2043
|
+
queryKey,
|
|
2044
|
+
defaultOptions: options
|
|
2045
|
+
});
|
|
2046
|
+
}
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
getQueryDefaults(queryKey) {
|
|
2050
|
+
if (!queryKey) {
|
|
2051
|
+
return undefined;
|
|
2052
|
+
} // Get the first matching defaults
|
|
2053
|
+
|
|
2054
|
+
|
|
2055
|
+
const firstMatchingDefaults = this.queryDefaults.find(x => partialMatchKey(queryKey, x.queryKey)); // Additional checks and error in dev mode
|
|
2056
|
+
|
|
2057
|
+
{
|
|
2058
|
+
// Retrieve all matching defaults for the given key
|
|
2059
|
+
const matchingDefaults = this.queryDefaults.filter(x => partialMatchKey(queryKey, x.queryKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
|
|
2060
|
+
|
|
2061
|
+
if (matchingDefaults.length > 1) {
|
|
2062
|
+
this.logger.error("[QueryClient] Several query defaults match with key '" + JSON.stringify(queryKey) + "'. The first matching query defaults are used. Please check how query defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetquerydefaults.");
|
|
2063
|
+
}
|
|
2064
|
+
}
|
|
2065
|
+
|
|
2066
|
+
return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
|
|
2067
|
+
}
|
|
2068
|
+
|
|
2069
|
+
setMutationDefaults(mutationKey, options) {
|
|
2070
|
+
const result = this.mutationDefaults.find(x => hashQueryKey(mutationKey) === hashQueryKey(x.mutationKey));
|
|
2071
|
+
|
|
2072
|
+
if (result) {
|
|
2073
|
+
result.defaultOptions = options;
|
|
2074
|
+
} else {
|
|
2075
|
+
this.mutationDefaults.push({
|
|
2076
|
+
mutationKey,
|
|
2077
|
+
defaultOptions: options
|
|
2078
|
+
});
|
|
2079
|
+
}
|
|
2080
|
+
}
|
|
2081
|
+
|
|
2082
|
+
getMutationDefaults(mutationKey) {
|
|
2083
|
+
if (!mutationKey) {
|
|
2084
|
+
return undefined;
|
|
2085
|
+
} // Get the first matching defaults
|
|
2086
|
+
|
|
2087
|
+
|
|
2088
|
+
const firstMatchingDefaults = this.mutationDefaults.find(x => partialMatchKey(mutationKey, x.mutationKey)); // Additional checks and error in dev mode
|
|
2089
|
+
|
|
2090
|
+
{
|
|
2091
|
+
// Retrieve all matching defaults for the given key
|
|
2092
|
+
const matchingDefaults = this.mutationDefaults.filter(x => partialMatchKey(mutationKey, x.mutationKey)); // It is ok not having defaults, but it is error prone to have more than 1 default for a given key
|
|
2093
|
+
|
|
2094
|
+
if (matchingDefaults.length > 1) {
|
|
2095
|
+
this.logger.error("[QueryClient] Several mutation defaults match with key '" + JSON.stringify(mutationKey) + "'. The first matching mutation defaults are used. Please check how mutation defaults are registered. Order does matter here. cf. https://react-query.tanstack.com/reference/QueryClient#queryclientsetmutationdefaults.");
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
|
|
2099
|
+
return firstMatchingDefaults == null ? void 0 : firstMatchingDefaults.defaultOptions;
|
|
2100
|
+
}
|
|
2101
|
+
|
|
2102
|
+
defaultQueryOptions(options) {
|
|
2103
|
+
if (options != null && options._defaulted) {
|
|
2104
|
+
return options;
|
|
2105
|
+
}
|
|
2106
|
+
|
|
2107
|
+
const defaultedOptions = { ...this.defaultOptions.queries,
|
|
2108
|
+
...this.getQueryDefaults(options == null ? void 0 : options.queryKey),
|
|
2109
|
+
...options,
|
|
2110
|
+
_defaulted: true
|
|
2111
|
+
};
|
|
2112
|
+
|
|
2113
|
+
if (!defaultedOptions.queryHash && defaultedOptions.queryKey) {
|
|
2114
|
+
defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
|
|
2115
|
+
} // dependent default values
|
|
2116
|
+
|
|
2117
|
+
|
|
2118
|
+
if (typeof defaultedOptions.refetchOnReconnect === 'undefined') {
|
|
2119
|
+
defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== 'always';
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
if (typeof defaultedOptions.useErrorBoundary === 'undefined') {
|
|
2123
|
+
defaultedOptions.useErrorBoundary = !!defaultedOptions.suspense;
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
return defaultedOptions;
|
|
2127
|
+
}
|
|
2128
|
+
|
|
2129
|
+
defaultMutationOptions(options) {
|
|
2130
|
+
if (options != null && options._defaulted) {
|
|
2131
|
+
return options;
|
|
2132
|
+
}
|
|
2133
|
+
|
|
2134
|
+
return { ...this.defaultOptions.mutations,
|
|
2135
|
+
...this.getMutationDefaults(options == null ? void 0 : options.mutationKey),
|
|
2136
|
+
...options,
|
|
2137
|
+
_defaulted: true
|
|
2138
|
+
};
|
|
2139
|
+
}
|
|
2140
|
+
|
|
2141
|
+
clear() {
|
|
2142
|
+
this.queryCache.clear();
|
|
2143
|
+
this.mutationCache.clear();
|
|
2144
|
+
}
|
|
2145
|
+
|
|
2146
|
+
}
|
|
2147
|
+
|
|
2148
|
+
class QueryObserver extends Subscribable {
|
|
2149
|
+
constructor(client, options) {
|
|
2150
|
+
super();
|
|
2151
|
+
this.client = client;
|
|
2152
|
+
this.options = options;
|
|
2153
|
+
this.trackedProps = new Set();
|
|
2154
|
+
this.selectError = null;
|
|
2155
|
+
this.bindMethods();
|
|
2156
|
+
this.setOptions(options);
|
|
2157
|
+
}
|
|
2158
|
+
|
|
2159
|
+
bindMethods() {
|
|
2160
|
+
this.remove = this.remove.bind(this);
|
|
2161
|
+
this.refetch = this.refetch.bind(this);
|
|
2162
|
+
}
|
|
2163
|
+
|
|
2164
|
+
onSubscribe() {
|
|
2165
|
+
if (this.listeners.length === 1) {
|
|
2166
|
+
this.currentQuery.addObserver(this);
|
|
2167
|
+
|
|
2168
|
+
if (shouldFetchOnMount(this.currentQuery, this.options)) {
|
|
2169
|
+
this.executeFetch();
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
this.updateTimers();
|
|
2173
|
+
}
|
|
2174
|
+
}
|
|
2175
|
+
|
|
2176
|
+
onUnsubscribe() {
|
|
2177
|
+
if (!this.listeners.length) {
|
|
2178
|
+
this.destroy();
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
|
|
2182
|
+
shouldFetchOnReconnect() {
|
|
2183
|
+
return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnReconnect);
|
|
2184
|
+
}
|
|
2185
|
+
|
|
2186
|
+
shouldFetchOnWindowFocus() {
|
|
2187
|
+
return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnWindowFocus);
|
|
2188
|
+
}
|
|
2189
|
+
|
|
2190
|
+
destroy() {
|
|
2191
|
+
this.listeners = [];
|
|
2192
|
+
this.clearStaleTimeout();
|
|
2193
|
+
this.clearRefetchInterval();
|
|
2194
|
+
this.currentQuery.removeObserver(this);
|
|
2195
|
+
}
|
|
2196
|
+
|
|
2197
|
+
setOptions(options, notifyOptions) {
|
|
2198
|
+
const prevOptions = this.options;
|
|
2199
|
+
const prevQuery = this.currentQuery;
|
|
2200
|
+
this.options = this.client.defaultQueryOptions(options);
|
|
2201
|
+
|
|
2202
|
+
if (!shallowEqualObjects(prevOptions, this.options)) {
|
|
2203
|
+
this.client.getQueryCache().notify({
|
|
2204
|
+
type: 'observerOptionsUpdated',
|
|
2205
|
+
query: this.currentQuery,
|
|
2206
|
+
observer: this
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
|
|
2211
|
+
throw new Error('Expected enabled to be a boolean');
|
|
2212
|
+
} // Keep previous query key if the user does not supply one
|
|
2213
|
+
|
|
2214
|
+
|
|
2215
|
+
if (!this.options.queryKey) {
|
|
2216
|
+
this.options.queryKey = prevOptions.queryKey;
|
|
2217
|
+
}
|
|
2218
|
+
|
|
2219
|
+
this.updateQuery();
|
|
2220
|
+
const mounted = this.hasListeners(); // Fetch if there are subscribers
|
|
2221
|
+
|
|
2222
|
+
if (mounted && shouldFetchOptionally(this.currentQuery, prevQuery, this.options, prevOptions)) {
|
|
2223
|
+
this.executeFetch();
|
|
2224
|
+
} // Update result
|
|
2225
|
+
|
|
2226
|
+
|
|
2227
|
+
this.updateResult(notifyOptions); // Update stale interval if needed
|
|
2228
|
+
|
|
2229
|
+
if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
|
|
2230
|
+
this.updateStaleTimeout();
|
|
2231
|
+
}
|
|
2232
|
+
|
|
2233
|
+
const nextRefetchInterval = this.computeRefetchInterval(); // Update refetch interval if needed
|
|
2234
|
+
|
|
2235
|
+
if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.currentRefetchInterval)) {
|
|
2236
|
+
this.updateRefetchInterval(nextRefetchInterval);
|
|
2237
|
+
}
|
|
2238
|
+
}
|
|
2239
|
+
|
|
2240
|
+
getOptimisticResult(options) {
|
|
2241
|
+
const query = this.client.getQueryCache().build(this.client, options);
|
|
2242
|
+
return this.createResult(query, options);
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2245
|
+
getCurrentResult() {
|
|
2246
|
+
return this.currentResult;
|
|
2247
|
+
}
|
|
2248
|
+
|
|
2249
|
+
trackResult(result) {
|
|
2250
|
+
const trackedResult = {};
|
|
2251
|
+
Object.keys(result).forEach(key => {
|
|
2252
|
+
Object.defineProperty(trackedResult, key, {
|
|
2253
|
+
configurable: false,
|
|
2254
|
+
enumerable: true,
|
|
2255
|
+
get: () => {
|
|
2256
|
+
this.trackedProps.add(key);
|
|
2257
|
+
return result[key];
|
|
2258
|
+
}
|
|
2259
|
+
});
|
|
2260
|
+
});
|
|
2261
|
+
return trackedResult;
|
|
2262
|
+
}
|
|
2263
|
+
|
|
2264
|
+
getCurrentQuery() {
|
|
2265
|
+
return this.currentQuery;
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
remove() {
|
|
2269
|
+
this.client.getQueryCache().remove(this.currentQuery);
|
|
2270
|
+
}
|
|
2271
|
+
|
|
2272
|
+
refetch({
|
|
2273
|
+
refetchPage,
|
|
2274
|
+
...options
|
|
2275
|
+
} = {}) {
|
|
2276
|
+
return this.fetch({ ...options,
|
|
2277
|
+
meta: {
|
|
2278
|
+
refetchPage
|
|
2279
|
+
}
|
|
2280
|
+
});
|
|
2281
|
+
}
|
|
2282
|
+
|
|
2283
|
+
fetchOptimistic(options) {
|
|
2284
|
+
const defaultedOptions = this.client.defaultQueryOptions(options);
|
|
2285
|
+
const query = this.client.getQueryCache().build(this.client, defaultedOptions);
|
|
2286
|
+
query.isFetchingOptimistic = true;
|
|
2287
|
+
return query.fetch().then(() => this.createResult(query, defaultedOptions));
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
fetch(fetchOptions) {
|
|
2291
|
+
var _fetchOptions$cancelR;
|
|
2292
|
+
|
|
2293
|
+
return this.executeFetch({ ...fetchOptions,
|
|
2294
|
+
cancelRefetch: (_fetchOptions$cancelR = fetchOptions.cancelRefetch) != null ? _fetchOptions$cancelR : true
|
|
2295
|
+
}).then(() => {
|
|
2296
|
+
this.updateResult();
|
|
2297
|
+
return this.currentResult;
|
|
2298
|
+
});
|
|
2299
|
+
}
|
|
2300
|
+
|
|
2301
|
+
executeFetch(fetchOptions) {
|
|
2302
|
+
// Make sure we reference the latest query as the current one might have been removed
|
|
2303
|
+
this.updateQuery(); // Fetch
|
|
2304
|
+
|
|
2305
|
+
let promise = this.currentQuery.fetch(this.options, fetchOptions);
|
|
2306
|
+
|
|
2307
|
+
if (!(fetchOptions != null && fetchOptions.throwOnError)) {
|
|
2308
|
+
promise = promise.catch(noop);
|
|
2309
|
+
}
|
|
2310
|
+
|
|
2311
|
+
return promise;
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
updateStaleTimeout() {
|
|
2315
|
+
this.clearStaleTimeout();
|
|
2316
|
+
|
|
2317
|
+
if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
const time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime); // The timeout is sometimes triggered 1 ms before the stale time expiration.
|
|
2322
|
+
// To mitigate this issue we always add 1 ms to the timeout.
|
|
2323
|
+
|
|
2324
|
+
const timeout = time + 1;
|
|
2325
|
+
this.staleTimeoutId = setTimeout(() => {
|
|
2326
|
+
if (!this.currentResult.isStale) {
|
|
2327
|
+
this.updateResult();
|
|
2328
|
+
}
|
|
2329
|
+
}, timeout);
|
|
2330
|
+
}
|
|
2331
|
+
|
|
2332
|
+
computeRefetchInterval() {
|
|
2333
|
+
var _this$options$refetch;
|
|
2334
|
+
|
|
2335
|
+
return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.currentResult.data, this.currentQuery) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
updateRefetchInterval(nextInterval) {
|
|
2339
|
+
this.clearRefetchInterval();
|
|
2340
|
+
this.currentRefetchInterval = nextInterval;
|
|
2341
|
+
|
|
2342
|
+
if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
|
|
2343
|
+
return;
|
|
2344
|
+
}
|
|
2345
|
+
|
|
2346
|
+
this.refetchIntervalId = setInterval(() => {
|
|
2347
|
+
if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
|
|
2348
|
+
this.executeFetch();
|
|
2349
|
+
}
|
|
2350
|
+
}, this.currentRefetchInterval);
|
|
2351
|
+
}
|
|
2352
|
+
|
|
2353
|
+
updateTimers() {
|
|
2354
|
+
this.updateStaleTimeout();
|
|
2355
|
+
this.updateRefetchInterval(this.computeRefetchInterval());
|
|
2356
|
+
}
|
|
2357
|
+
|
|
2358
|
+
clearStaleTimeout() {
|
|
2359
|
+
if (this.staleTimeoutId) {
|
|
2360
|
+
clearTimeout(this.staleTimeoutId);
|
|
2361
|
+
this.staleTimeoutId = undefined;
|
|
2362
|
+
}
|
|
2363
|
+
}
|
|
2364
|
+
|
|
2365
|
+
clearRefetchInterval() {
|
|
2366
|
+
if (this.refetchIntervalId) {
|
|
2367
|
+
clearInterval(this.refetchIntervalId);
|
|
2368
|
+
this.refetchIntervalId = undefined;
|
|
2369
|
+
}
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
createResult(query, options) {
|
|
2373
|
+
const prevQuery = this.currentQuery;
|
|
2374
|
+
const prevOptions = this.options;
|
|
2375
|
+
const prevResult = this.currentResult;
|
|
2376
|
+
const prevResultState = this.currentResultState;
|
|
2377
|
+
const prevResultOptions = this.currentResultOptions;
|
|
2378
|
+
const queryChange = query !== prevQuery;
|
|
2379
|
+
const queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
|
|
2380
|
+
const prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
|
|
2381
|
+
const {
|
|
2382
|
+
state
|
|
2383
|
+
} = query;
|
|
2384
|
+
let {
|
|
2385
|
+
dataUpdatedAt,
|
|
2386
|
+
error,
|
|
2387
|
+
errorUpdatedAt,
|
|
2388
|
+
fetchStatus,
|
|
2389
|
+
status
|
|
2390
|
+
} = state;
|
|
2391
|
+
let isPreviousData = false;
|
|
2392
|
+
let isPlaceholderData = false;
|
|
2393
|
+
let data; // Optimistically set result in fetching state if needed
|
|
2394
|
+
|
|
2395
|
+
if (options._optimisticResults) {
|
|
2396
|
+
const mounted = this.hasListeners();
|
|
2397
|
+
const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
|
|
2398
|
+
const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
|
|
2399
|
+
|
|
2400
|
+
if (fetchOnMount || fetchOptionally) {
|
|
2401
|
+
fetchStatus = canFetch(query.options.networkMode) ? 'fetching' : 'paused';
|
|
2402
|
+
|
|
2403
|
+
if (!dataUpdatedAt) {
|
|
2404
|
+
status = 'loading';
|
|
2405
|
+
}
|
|
2406
|
+
}
|
|
2407
|
+
|
|
2408
|
+
if (options._optimisticResults === 'isRestoring') {
|
|
2409
|
+
fetchStatus = 'idle';
|
|
2410
|
+
}
|
|
2411
|
+
} // Keep previous data if needed
|
|
2412
|
+
|
|
2413
|
+
|
|
2414
|
+
if (options.keepPreviousData && !state.dataUpdateCount && prevQueryResult != null && prevQueryResult.isSuccess && status !== 'error') {
|
|
2415
|
+
data = prevQueryResult.data;
|
|
2416
|
+
dataUpdatedAt = prevQueryResult.dataUpdatedAt;
|
|
2417
|
+
status = prevQueryResult.status;
|
|
2418
|
+
isPreviousData = true;
|
|
2419
|
+
} // Select data if needed
|
|
2420
|
+
else if (options.select && typeof state.data !== 'undefined') {
|
|
2421
|
+
// Memoize select result
|
|
2422
|
+
if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === this.selectFn) {
|
|
2423
|
+
data = this.selectResult;
|
|
2424
|
+
} else {
|
|
2425
|
+
try {
|
|
2426
|
+
this.selectFn = options.select;
|
|
2427
|
+
data = options.select(state.data);
|
|
2428
|
+
data = replaceData(prevResult == null ? void 0 : prevResult.data, data, options);
|
|
2429
|
+
this.selectResult = data;
|
|
2430
|
+
this.selectError = null;
|
|
2431
|
+
} catch (selectError) {
|
|
2432
|
+
{
|
|
2433
|
+
this.client.getLogger().error(selectError);
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
this.selectError = selectError;
|
|
2437
|
+
}
|
|
2438
|
+
}
|
|
2439
|
+
} // Use query data
|
|
2440
|
+
else {
|
|
2441
|
+
data = state.data;
|
|
2442
|
+
} // Show placeholder data if needed
|
|
2443
|
+
|
|
2444
|
+
|
|
2445
|
+
if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && status === 'loading') {
|
|
2446
|
+
let placeholderData; // Memoize placeholder data
|
|
2447
|
+
|
|
2448
|
+
if (prevResult != null && prevResult.isPlaceholderData && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
|
|
2449
|
+
placeholderData = prevResult.data;
|
|
2450
|
+
} else {
|
|
2451
|
+
placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData() : options.placeholderData;
|
|
2452
|
+
|
|
2453
|
+
if (options.select && typeof placeholderData !== 'undefined') {
|
|
2454
|
+
try {
|
|
2455
|
+
placeholderData = options.select(placeholderData);
|
|
2456
|
+
placeholderData = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
|
|
2457
|
+
this.selectError = null;
|
|
2458
|
+
} catch (selectError) {
|
|
2459
|
+
{
|
|
2460
|
+
this.client.getLogger().error(selectError);
|
|
2461
|
+
}
|
|
2462
|
+
|
|
2463
|
+
this.selectError = selectError;
|
|
2464
|
+
}
|
|
2465
|
+
}
|
|
2466
|
+
}
|
|
2467
|
+
|
|
2468
|
+
if (typeof placeholderData !== 'undefined') {
|
|
2469
|
+
status = 'success';
|
|
2470
|
+
data = placeholderData;
|
|
2471
|
+
isPlaceholderData = true;
|
|
2472
|
+
}
|
|
2473
|
+
}
|
|
2474
|
+
|
|
2475
|
+
if (this.selectError) {
|
|
2476
|
+
error = this.selectError;
|
|
2477
|
+
data = this.selectResult;
|
|
2478
|
+
errorUpdatedAt = Date.now();
|
|
2479
|
+
status = 'error';
|
|
2480
|
+
}
|
|
2481
|
+
|
|
2482
|
+
const isFetching = fetchStatus === 'fetching';
|
|
2483
|
+
const isLoading = status === 'loading';
|
|
2484
|
+
const isError = status === 'error';
|
|
2485
|
+
const result = {
|
|
2486
|
+
status,
|
|
2487
|
+
fetchStatus,
|
|
2488
|
+
isLoading,
|
|
2489
|
+
isSuccess: status === 'success',
|
|
2490
|
+
isError,
|
|
2491
|
+
isInitialLoading: isLoading && isFetching,
|
|
2492
|
+
data,
|
|
2493
|
+
dataUpdatedAt,
|
|
2494
|
+
error,
|
|
2495
|
+
errorUpdatedAt,
|
|
2496
|
+
failureCount: state.fetchFailureCount,
|
|
2497
|
+
errorUpdateCount: state.errorUpdateCount,
|
|
2498
|
+
isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
|
|
2499
|
+
isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
|
|
2500
|
+
isFetching,
|
|
2501
|
+
isRefetching: isFetching && !isLoading,
|
|
2502
|
+
isLoadingError: isError && state.dataUpdatedAt === 0,
|
|
2503
|
+
isPaused: fetchStatus === 'paused',
|
|
2504
|
+
isPlaceholderData,
|
|
2505
|
+
isPreviousData,
|
|
2506
|
+
isRefetchError: isError && state.dataUpdatedAt !== 0,
|
|
2507
|
+
isStale: isStale(query, options),
|
|
2508
|
+
refetch: this.refetch,
|
|
2509
|
+
remove: this.remove
|
|
2510
|
+
};
|
|
2511
|
+
return result;
|
|
2512
|
+
}
|
|
2513
|
+
|
|
2514
|
+
updateResult(notifyOptions) {
|
|
2515
|
+
const prevResult = this.currentResult;
|
|
2516
|
+
const nextResult = this.createResult(this.currentQuery, this.options);
|
|
2517
|
+
this.currentResultState = this.currentQuery.state;
|
|
2518
|
+
this.currentResultOptions = this.options; // Only notify and update result if something has changed
|
|
2519
|
+
|
|
2520
|
+
if (shallowEqualObjects(nextResult, prevResult)) {
|
|
2521
|
+
return;
|
|
2522
|
+
}
|
|
2523
|
+
|
|
2524
|
+
this.currentResult = nextResult; // Determine which callbacks to trigger
|
|
2525
|
+
|
|
2526
|
+
const defaultNotifyOptions = {
|
|
2527
|
+
cache: true
|
|
2528
|
+
};
|
|
2529
|
+
|
|
2530
|
+
const shouldNotifyListeners = () => {
|
|
2531
|
+
if (!prevResult) {
|
|
2532
|
+
return true;
|
|
2533
|
+
}
|
|
2534
|
+
|
|
2535
|
+
const {
|
|
2536
|
+
notifyOnChangeProps
|
|
2537
|
+
} = this.options;
|
|
2538
|
+
|
|
2539
|
+
if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !this.trackedProps.size) {
|
|
2540
|
+
return true;
|
|
2541
|
+
}
|
|
2542
|
+
|
|
2543
|
+
const includedProps = new Set(notifyOnChangeProps != null ? notifyOnChangeProps : this.trackedProps);
|
|
2544
|
+
|
|
2545
|
+
if (this.options.useErrorBoundary) {
|
|
2546
|
+
includedProps.add('error');
|
|
2547
|
+
}
|
|
2548
|
+
|
|
2549
|
+
return Object.keys(this.currentResult).some(key => {
|
|
2550
|
+
const typedKey = key;
|
|
2551
|
+
const changed = this.currentResult[typedKey] !== prevResult[typedKey];
|
|
2552
|
+
return changed && includedProps.has(typedKey);
|
|
2553
|
+
});
|
|
2554
|
+
};
|
|
2555
|
+
|
|
2556
|
+
if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
|
|
2557
|
+
defaultNotifyOptions.listeners = true;
|
|
2558
|
+
}
|
|
2559
|
+
|
|
2560
|
+
this.notify({ ...defaultNotifyOptions,
|
|
2561
|
+
...notifyOptions
|
|
2562
|
+
});
|
|
2563
|
+
}
|
|
2564
|
+
|
|
2565
|
+
updateQuery() {
|
|
2566
|
+
const query = this.client.getQueryCache().build(this.client, this.options);
|
|
2567
|
+
|
|
2568
|
+
if (query === this.currentQuery) {
|
|
2569
|
+
return;
|
|
2570
|
+
}
|
|
2571
|
+
|
|
2572
|
+
const prevQuery = this.currentQuery;
|
|
2573
|
+
this.currentQuery = query;
|
|
2574
|
+
this.currentQueryInitialState = query.state;
|
|
2575
|
+
this.previousQueryResult = this.currentResult;
|
|
2576
|
+
|
|
2577
|
+
if (this.hasListeners()) {
|
|
2578
|
+
prevQuery == null ? void 0 : prevQuery.removeObserver(this);
|
|
2579
|
+
query.addObserver(this);
|
|
2580
|
+
}
|
|
2581
|
+
}
|
|
2582
|
+
|
|
2583
|
+
onQueryUpdate(action) {
|
|
2584
|
+
const notifyOptions = {};
|
|
2585
|
+
|
|
2586
|
+
if (action.type === 'success') {
|
|
2587
|
+
notifyOptions.onSuccess = !action.manual;
|
|
2588
|
+
} else if (action.type === 'error' && !isCancelledError(action.error)) {
|
|
2589
|
+
notifyOptions.onError = true;
|
|
2590
|
+
}
|
|
2591
|
+
|
|
2592
|
+
this.updateResult(notifyOptions);
|
|
2593
|
+
|
|
2594
|
+
if (this.hasListeners()) {
|
|
2595
|
+
this.updateTimers();
|
|
2596
|
+
}
|
|
2597
|
+
}
|
|
2598
|
+
|
|
2599
|
+
notify(notifyOptions) {
|
|
2600
|
+
notifyManager.batch(() => {
|
|
2601
|
+
// First trigger the configuration callbacks
|
|
2602
|
+
if (notifyOptions.onSuccess) {
|
|
2603
|
+
var _this$options$onSucce, _this$options, _this$options$onSettl, _this$options2;
|
|
2604
|
+
|
|
2605
|
+
(_this$options$onSucce = (_this$options = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options, this.currentResult.data);
|
|
2606
|
+
(_this$options$onSettl = (_this$options2 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options2, this.currentResult.data, null);
|
|
2607
|
+
} else if (notifyOptions.onError) {
|
|
2608
|
+
var _this$options$onError, _this$options3, _this$options$onSettl2, _this$options4;
|
|
2609
|
+
|
|
2610
|
+
(_this$options$onError = (_this$options3 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options3, this.currentResult.error);
|
|
2611
|
+
(_this$options$onSettl2 = (_this$options4 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options4, undefined, this.currentResult.error);
|
|
2612
|
+
} // Then trigger the listeners
|
|
2613
|
+
|
|
2614
|
+
|
|
2615
|
+
if (notifyOptions.listeners) {
|
|
2616
|
+
this.listeners.forEach(listener => {
|
|
2617
|
+
listener(this.currentResult);
|
|
2618
|
+
});
|
|
2619
|
+
} // Then the cache listeners
|
|
2620
|
+
|
|
2621
|
+
|
|
2622
|
+
if (notifyOptions.cache) {
|
|
2623
|
+
this.client.getQueryCache().notify({
|
|
2624
|
+
query: this.currentQuery,
|
|
2625
|
+
type: 'observerResultsUpdated'
|
|
2626
|
+
});
|
|
2627
|
+
}
|
|
2628
|
+
});
|
|
2629
|
+
}
|
|
2630
|
+
|
|
2631
|
+
}
|
|
2632
|
+
|
|
2633
|
+
function shouldLoadOnMount(query, options) {
|
|
2634
|
+
return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
|
|
2635
|
+
}
|
|
2636
|
+
|
|
2637
|
+
function shouldFetchOnMount(query, options) {
|
|
2638
|
+
return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
|
|
2639
|
+
}
|
|
2640
|
+
|
|
2641
|
+
function shouldFetchOn(query, options, field) {
|
|
2642
|
+
if (options.enabled !== false) {
|
|
2643
|
+
const value = typeof field === 'function' ? field(query) : field;
|
|
2644
|
+
return value === 'always' || value !== false && isStale(query, options);
|
|
2645
|
+
}
|
|
2646
|
+
|
|
2647
|
+
return false;
|
|
2648
|
+
}
|
|
2649
|
+
|
|
2650
|
+
function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
|
|
2651
|
+
return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== 'error') && isStale(query, options);
|
|
2652
|
+
}
|
|
2653
|
+
|
|
2654
|
+
function isStale(query, options) {
|
|
2655
|
+
return query.isStaleByTime(options.staleTime);
|
|
2656
|
+
}
|
|
2657
|
+
|
|
2658
|
+
class QueriesObserver extends Subscribable {
|
|
2659
|
+
constructor(client, queries) {
|
|
2660
|
+
super();
|
|
2661
|
+
this.client = client;
|
|
2662
|
+
this.queries = [];
|
|
2663
|
+
this.result = [];
|
|
2664
|
+
this.observers = [];
|
|
2665
|
+
this.observersMap = {};
|
|
2666
|
+
|
|
2667
|
+
if (queries) {
|
|
2668
|
+
this.setQueries(queries);
|
|
2669
|
+
}
|
|
2670
|
+
}
|
|
2671
|
+
|
|
2672
|
+
onSubscribe() {
|
|
2673
|
+
if (this.listeners.length === 1) {
|
|
2674
|
+
this.observers.forEach(observer => {
|
|
2675
|
+
observer.subscribe(result => {
|
|
2676
|
+
this.onUpdate(observer, result);
|
|
2677
|
+
});
|
|
2678
|
+
});
|
|
2679
|
+
}
|
|
2680
|
+
}
|
|
2681
|
+
|
|
2682
|
+
onUnsubscribe() {
|
|
2683
|
+
if (!this.listeners.length) {
|
|
2684
|
+
this.destroy();
|
|
2685
|
+
}
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
destroy() {
|
|
2689
|
+
this.listeners = [];
|
|
2690
|
+
this.observers.forEach(observer => {
|
|
2691
|
+
observer.destroy();
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
setQueries(queries, notifyOptions) {
|
|
2696
|
+
this.queries = queries;
|
|
2697
|
+
notifyManager.batch(() => {
|
|
2698
|
+
const prevObservers = this.observers;
|
|
2699
|
+
const newObserverMatches = this.findMatchingObservers(this.queries); // set options for the new observers to notify of changes
|
|
2700
|
+
|
|
2701
|
+
newObserverMatches.forEach(match => match.observer.setOptions(match.defaultedQueryOptions, notifyOptions));
|
|
2702
|
+
const newObservers = newObserverMatches.map(match => match.observer);
|
|
2703
|
+
const newObserversMap = Object.fromEntries(newObservers.map(observer => [observer.options.queryHash, observer]));
|
|
2704
|
+
const newResult = newObservers.map(observer => observer.getCurrentResult());
|
|
2705
|
+
const hasIndexChange = newObservers.some((observer, index) => observer !== prevObservers[index]);
|
|
2706
|
+
|
|
2707
|
+
if (prevObservers.length === newObservers.length && !hasIndexChange) {
|
|
2708
|
+
return;
|
|
2709
|
+
}
|
|
2710
|
+
|
|
2711
|
+
this.observers = newObservers;
|
|
2712
|
+
this.observersMap = newObserversMap;
|
|
2713
|
+
this.result = newResult;
|
|
2714
|
+
|
|
2715
|
+
if (!this.hasListeners()) {
|
|
2716
|
+
return;
|
|
2717
|
+
}
|
|
2718
|
+
|
|
2719
|
+
difference(prevObservers, newObservers).forEach(observer => {
|
|
2720
|
+
observer.destroy();
|
|
2721
|
+
});
|
|
2722
|
+
difference(newObservers, prevObservers).forEach(observer => {
|
|
2723
|
+
observer.subscribe(result => {
|
|
2724
|
+
this.onUpdate(observer, result);
|
|
2725
|
+
});
|
|
2726
|
+
});
|
|
2727
|
+
this.notify();
|
|
2728
|
+
});
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2731
|
+
getCurrentResult() {
|
|
2732
|
+
return this.result;
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
getQueries() {
|
|
2736
|
+
return this.observers.map(observer => observer.getCurrentQuery());
|
|
2737
|
+
}
|
|
2738
|
+
|
|
2739
|
+
getOptimisticResult(queries) {
|
|
2740
|
+
return this.findMatchingObservers(queries).map(match => match.observer.getOptimisticResult(match.defaultedQueryOptions));
|
|
2741
|
+
}
|
|
2742
|
+
|
|
2743
|
+
findMatchingObservers(queries) {
|
|
2744
|
+
const prevObservers = this.observers;
|
|
2745
|
+
const defaultedQueryOptions = queries.map(options => this.client.defaultQueryOptions(options));
|
|
2746
|
+
const matchingObservers = defaultedQueryOptions.flatMap(defaultedOptions => {
|
|
2747
|
+
const match = prevObservers.find(observer => observer.options.queryHash === defaultedOptions.queryHash);
|
|
2748
|
+
|
|
2749
|
+
if (match != null) {
|
|
2750
|
+
return [{
|
|
2751
|
+
defaultedQueryOptions: defaultedOptions,
|
|
2752
|
+
observer: match
|
|
2753
|
+
}];
|
|
2754
|
+
}
|
|
2755
|
+
|
|
2756
|
+
return [];
|
|
2757
|
+
});
|
|
2758
|
+
const matchedQueryHashes = matchingObservers.map(match => match.defaultedQueryOptions.queryHash);
|
|
2759
|
+
const unmatchedQueries = defaultedQueryOptions.filter(defaultedOptions => !matchedQueryHashes.includes(defaultedOptions.queryHash));
|
|
2760
|
+
const unmatchedObservers = prevObservers.filter(prevObserver => !matchingObservers.some(match => match.observer === prevObserver));
|
|
2761
|
+
|
|
2762
|
+
const getObserver = options => {
|
|
2763
|
+
const defaultedOptions = this.client.defaultQueryOptions(options);
|
|
2764
|
+
const currentObserver = this.observersMap[defaultedOptions.queryHash];
|
|
2765
|
+
return currentObserver != null ? currentObserver : new QueryObserver(this.client, defaultedOptions);
|
|
2766
|
+
};
|
|
2767
|
+
|
|
2768
|
+
const newOrReusedObservers = unmatchedQueries.map((options, index) => {
|
|
2769
|
+
if (options.keepPreviousData) {
|
|
2770
|
+
// return previous data from one of the observers that no longer match
|
|
2771
|
+
const previouslyUsedObserver = unmatchedObservers[index];
|
|
2772
|
+
|
|
2773
|
+
if (previouslyUsedObserver !== undefined) {
|
|
2774
|
+
return {
|
|
2775
|
+
defaultedQueryOptions: options,
|
|
2776
|
+
observer: previouslyUsedObserver
|
|
2777
|
+
};
|
|
2778
|
+
}
|
|
2779
|
+
}
|
|
2780
|
+
|
|
2781
|
+
return {
|
|
2782
|
+
defaultedQueryOptions: options,
|
|
2783
|
+
observer: getObserver(options)
|
|
2784
|
+
};
|
|
2785
|
+
});
|
|
2786
|
+
|
|
2787
|
+
const sortMatchesByOrderOfQueries = (a, b) => defaultedQueryOptions.indexOf(a.defaultedQueryOptions) - defaultedQueryOptions.indexOf(b.defaultedQueryOptions);
|
|
2788
|
+
|
|
2789
|
+
return matchingObservers.concat(newOrReusedObservers).sort(sortMatchesByOrderOfQueries);
|
|
2790
|
+
}
|
|
2791
|
+
|
|
2792
|
+
onUpdate(observer, result) {
|
|
2793
|
+
const index = this.observers.indexOf(observer);
|
|
2794
|
+
|
|
2795
|
+
if (index !== -1) {
|
|
2796
|
+
this.result = replaceAt(this.result, index, result);
|
|
2797
|
+
this.notify();
|
|
2798
|
+
}
|
|
2799
|
+
}
|
|
2800
|
+
|
|
2801
|
+
notify() {
|
|
2802
|
+
notifyManager.batch(() => {
|
|
2803
|
+
this.listeners.forEach(listener => {
|
|
2804
|
+
listener(this.result);
|
|
2805
|
+
});
|
|
2806
|
+
});
|
|
2807
|
+
}
|
|
2808
|
+
|
|
2809
|
+
}
|
|
2810
|
+
|
|
2811
|
+
class InfiniteQueryObserver extends QueryObserver {
|
|
2812
|
+
// Type override
|
|
2813
|
+
// Type override
|
|
2814
|
+
// Type override
|
|
2815
|
+
// eslint-disable-next-line @typescript-eslint/no-useless-constructor
|
|
2816
|
+
constructor(client, options) {
|
|
2817
|
+
super(client, options);
|
|
2818
|
+
}
|
|
2819
|
+
|
|
2820
|
+
bindMethods() {
|
|
2821
|
+
super.bindMethods();
|
|
2822
|
+
this.fetchNextPage = this.fetchNextPage.bind(this);
|
|
2823
|
+
this.fetchPreviousPage = this.fetchPreviousPage.bind(this);
|
|
2824
|
+
}
|
|
2825
|
+
|
|
2826
|
+
setOptions(options, notifyOptions) {
|
|
2827
|
+
super.setOptions({ ...options,
|
|
2828
|
+
behavior: infiniteQueryBehavior()
|
|
2829
|
+
}, notifyOptions);
|
|
2830
|
+
}
|
|
2831
|
+
|
|
2832
|
+
getOptimisticResult(options) {
|
|
2833
|
+
options.behavior = infiniteQueryBehavior();
|
|
2834
|
+
return super.getOptimisticResult(options);
|
|
2835
|
+
}
|
|
2836
|
+
|
|
2837
|
+
fetchNextPage({
|
|
2838
|
+
pageParam,
|
|
2839
|
+
...options
|
|
2840
|
+
} = {}) {
|
|
2841
|
+
return this.fetch({ ...options,
|
|
2842
|
+
meta: {
|
|
2843
|
+
fetchMore: {
|
|
2844
|
+
direction: 'forward',
|
|
2845
|
+
pageParam
|
|
2846
|
+
}
|
|
2847
|
+
}
|
|
2848
|
+
});
|
|
2849
|
+
}
|
|
2850
|
+
|
|
2851
|
+
fetchPreviousPage({
|
|
2852
|
+
pageParam,
|
|
2853
|
+
...options
|
|
2854
|
+
} = {}) {
|
|
2855
|
+
return this.fetch({ ...options,
|
|
2856
|
+
meta: {
|
|
2857
|
+
fetchMore: {
|
|
2858
|
+
direction: 'backward',
|
|
2859
|
+
pageParam
|
|
2860
|
+
}
|
|
2861
|
+
}
|
|
2862
|
+
});
|
|
2863
|
+
}
|
|
2864
|
+
|
|
2865
|
+
createResult(query, options) {
|
|
2866
|
+
var _state$data, _state$data2, _state$fetchMeta, _state$fetchMeta$fetc, _state$fetchMeta2, _state$fetchMeta2$fet;
|
|
2867
|
+
|
|
2868
|
+
const {
|
|
2869
|
+
state
|
|
2870
|
+
} = query;
|
|
2871
|
+
const result = super.createResult(query, options);
|
|
2872
|
+
return { ...result,
|
|
2873
|
+
fetchNextPage: this.fetchNextPage,
|
|
2874
|
+
fetchPreviousPage: this.fetchPreviousPage,
|
|
2875
|
+
hasNextPage: hasNextPage(options, (_state$data = state.data) == null ? void 0 : _state$data.pages),
|
|
2876
|
+
hasPreviousPage: hasPreviousPage(options, (_state$data2 = state.data) == null ? void 0 : _state$data2.pages),
|
|
2877
|
+
isFetchingNextPage: state.fetchStatus === 'fetching' && ((_state$fetchMeta = state.fetchMeta) == null ? void 0 : (_state$fetchMeta$fetc = _state$fetchMeta.fetchMore) == null ? void 0 : _state$fetchMeta$fetc.direction) === 'forward',
|
|
2878
|
+
isFetchingPreviousPage: state.fetchStatus === 'fetching' && ((_state$fetchMeta2 = state.fetchMeta) == null ? void 0 : (_state$fetchMeta2$fet = _state$fetchMeta2.fetchMore) == null ? void 0 : _state$fetchMeta2$fet.direction) === 'backward'
|
|
2879
|
+
};
|
|
2880
|
+
}
|
|
2881
|
+
|
|
2882
|
+
}
|
|
2883
|
+
|
|
2884
|
+
// CLASS
|
|
2885
|
+
class MutationObserver extends Subscribable {
|
|
2886
|
+
constructor(client, options) {
|
|
2887
|
+
super();
|
|
2888
|
+
this.client = client;
|
|
2889
|
+
this.setOptions(options);
|
|
2890
|
+
this.bindMethods();
|
|
2891
|
+
this.updateResult();
|
|
2892
|
+
}
|
|
2893
|
+
|
|
2894
|
+
bindMethods() {
|
|
2895
|
+
this.mutate = this.mutate.bind(this);
|
|
2896
|
+
this.reset = this.reset.bind(this);
|
|
2897
|
+
}
|
|
2898
|
+
|
|
2899
|
+
setOptions(options) {
|
|
2900
|
+
const prevOptions = this.options;
|
|
2901
|
+
this.options = this.client.defaultMutationOptions(options);
|
|
2902
|
+
|
|
2903
|
+
if (!shallowEqualObjects(prevOptions, this.options)) {
|
|
2904
|
+
this.client.getMutationCache().notify({
|
|
2905
|
+
type: 'observerOptionsUpdated',
|
|
2906
|
+
mutation: this.currentMutation,
|
|
2907
|
+
observer: this
|
|
2908
|
+
});
|
|
2909
|
+
}
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2912
|
+
onUnsubscribe() {
|
|
2913
|
+
if (!this.listeners.length) {
|
|
2914
|
+
var _this$currentMutation;
|
|
2915
|
+
|
|
2916
|
+
(_this$currentMutation = this.currentMutation) == null ? void 0 : _this$currentMutation.removeObserver(this);
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
|
|
2920
|
+
onMutationUpdate(action) {
|
|
2921
|
+
this.updateResult(); // Determine which callbacks to trigger
|
|
2922
|
+
|
|
2923
|
+
const notifyOptions = {
|
|
2924
|
+
listeners: true
|
|
2925
|
+
};
|
|
2926
|
+
|
|
2927
|
+
if (action.type === 'success') {
|
|
2928
|
+
notifyOptions.onSuccess = true;
|
|
2929
|
+
} else if (action.type === 'error') {
|
|
2930
|
+
notifyOptions.onError = true;
|
|
2931
|
+
}
|
|
2932
|
+
|
|
2933
|
+
this.notify(notifyOptions);
|
|
2934
|
+
}
|
|
2935
|
+
|
|
2936
|
+
getCurrentResult() {
|
|
2937
|
+
return this.currentResult;
|
|
2938
|
+
}
|
|
2939
|
+
|
|
2940
|
+
reset() {
|
|
2941
|
+
this.currentMutation = undefined;
|
|
2942
|
+
this.updateResult();
|
|
2943
|
+
this.notify({
|
|
2944
|
+
listeners: true
|
|
2945
|
+
});
|
|
2946
|
+
}
|
|
2947
|
+
|
|
2948
|
+
mutate(variables, options) {
|
|
2949
|
+
this.mutateOptions = options;
|
|
2950
|
+
|
|
2951
|
+
if (this.currentMutation) {
|
|
2952
|
+
this.currentMutation.removeObserver(this);
|
|
2953
|
+
}
|
|
2954
|
+
|
|
2955
|
+
this.currentMutation = this.client.getMutationCache().build(this.client, { ...this.options,
|
|
2956
|
+
variables: typeof variables !== 'undefined' ? variables : this.options.variables
|
|
2957
|
+
});
|
|
2958
|
+
this.currentMutation.addObserver(this);
|
|
2959
|
+
return this.currentMutation.execute();
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
updateResult() {
|
|
2963
|
+
const state = this.currentMutation ? this.currentMutation.state : getDefaultState();
|
|
2964
|
+
const result = { ...state,
|
|
2965
|
+
isLoading: state.status === 'loading',
|
|
2966
|
+
isSuccess: state.status === 'success',
|
|
2967
|
+
isError: state.status === 'error',
|
|
2968
|
+
isIdle: state.status === 'idle',
|
|
2969
|
+
mutate: this.mutate,
|
|
2970
|
+
reset: this.reset
|
|
2971
|
+
};
|
|
2972
|
+
this.currentResult = result;
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
notify(options) {
|
|
2976
|
+
notifyManager.batch(() => {
|
|
2977
|
+
// First trigger the mutate callbacks
|
|
2978
|
+
if (this.mutateOptions) {
|
|
2979
|
+
if (options.onSuccess) {
|
|
2980
|
+
var _this$mutateOptions$o, _this$mutateOptions, _this$mutateOptions$o2, _this$mutateOptions2;
|
|
2981
|
+
|
|
2982
|
+
(_this$mutateOptions$o = (_this$mutateOptions = this.mutateOptions).onSuccess) == null ? void 0 : _this$mutateOptions$o.call(_this$mutateOptions, this.currentResult.data, this.currentResult.variables, this.currentResult.context);
|
|
2983
|
+
(_this$mutateOptions$o2 = (_this$mutateOptions2 = this.mutateOptions).onSettled) == null ? void 0 : _this$mutateOptions$o2.call(_this$mutateOptions2, this.currentResult.data, null, this.currentResult.variables, this.currentResult.context);
|
|
2984
|
+
} else if (options.onError) {
|
|
2985
|
+
var _this$mutateOptions$o3, _this$mutateOptions3, _this$mutateOptions$o4, _this$mutateOptions4;
|
|
2986
|
+
|
|
2987
|
+
(_this$mutateOptions$o3 = (_this$mutateOptions3 = this.mutateOptions).onError) == null ? void 0 : _this$mutateOptions$o3.call(_this$mutateOptions3, this.currentResult.error, this.currentResult.variables, this.currentResult.context);
|
|
2988
|
+
(_this$mutateOptions$o4 = (_this$mutateOptions4 = this.mutateOptions).onSettled) == null ? void 0 : _this$mutateOptions$o4.call(_this$mutateOptions4, undefined, this.currentResult.error, this.currentResult.variables, this.currentResult.context);
|
|
2989
|
+
}
|
|
2990
|
+
} // Then trigger the listeners
|
|
2991
|
+
|
|
2992
|
+
|
|
2993
|
+
if (options.listeners) {
|
|
2994
|
+
this.listeners.forEach(listener => {
|
|
2995
|
+
listener(this.currentResult);
|
|
2996
|
+
});
|
|
2997
|
+
}
|
|
2998
|
+
});
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
}
|
|
3002
|
+
|
|
3003
|
+
// TYPES
|
|
3004
|
+
// FUNCTIONS
|
|
3005
|
+
function dehydrateMutation(mutation) {
|
|
3006
|
+
return {
|
|
3007
|
+
mutationKey: mutation.options.mutationKey,
|
|
3008
|
+
state: mutation.state
|
|
3009
|
+
};
|
|
3010
|
+
} // Most config is not dehydrated but instead meant to configure again when
|
|
3011
|
+
// consuming the de/rehydrated data, typically with useQuery on the client.
|
|
3012
|
+
// Sometimes it might make sense to prefetch data on the server and include
|
|
3013
|
+
// in the html-payload, but not consume it on the initial render.
|
|
3014
|
+
|
|
3015
|
+
|
|
3016
|
+
function dehydrateQuery(query) {
|
|
3017
|
+
return {
|
|
3018
|
+
state: query.state,
|
|
3019
|
+
queryKey: query.queryKey,
|
|
3020
|
+
queryHash: query.queryHash
|
|
3021
|
+
};
|
|
3022
|
+
}
|
|
3023
|
+
|
|
3024
|
+
function defaultShouldDehydrateMutation(mutation) {
|
|
3025
|
+
return mutation.state.isPaused;
|
|
3026
|
+
}
|
|
3027
|
+
|
|
3028
|
+
function defaultShouldDehydrateQuery(query) {
|
|
3029
|
+
return query.state.status === 'success';
|
|
3030
|
+
}
|
|
3031
|
+
|
|
3032
|
+
function dehydrate(client, options = {}) {
|
|
3033
|
+
const mutations = [];
|
|
3034
|
+
const queries = [];
|
|
3035
|
+
|
|
3036
|
+
if (options.dehydrateMutations !== false) {
|
|
3037
|
+
const shouldDehydrateMutation = options.shouldDehydrateMutation || defaultShouldDehydrateMutation;
|
|
3038
|
+
client.getMutationCache().getAll().forEach(mutation => {
|
|
3039
|
+
if (shouldDehydrateMutation(mutation)) {
|
|
3040
|
+
mutations.push(dehydrateMutation(mutation));
|
|
3041
|
+
}
|
|
3042
|
+
});
|
|
3043
|
+
}
|
|
3044
|
+
|
|
3045
|
+
if (options.dehydrateQueries !== false) {
|
|
3046
|
+
const shouldDehydrateQuery = options.shouldDehydrateQuery || defaultShouldDehydrateQuery;
|
|
3047
|
+
client.getQueryCache().getAll().forEach(query => {
|
|
3048
|
+
if (shouldDehydrateQuery(query)) {
|
|
3049
|
+
queries.push(dehydrateQuery(query));
|
|
3050
|
+
}
|
|
3051
|
+
});
|
|
3052
|
+
}
|
|
3053
|
+
|
|
3054
|
+
return {
|
|
3055
|
+
mutations,
|
|
3056
|
+
queries
|
|
3057
|
+
};
|
|
3058
|
+
}
|
|
3059
|
+
function hydrate(client, dehydratedState, options) {
|
|
3060
|
+
if (typeof dehydratedState !== 'object' || dehydratedState === null) {
|
|
3061
|
+
return;
|
|
3062
|
+
}
|
|
3063
|
+
|
|
3064
|
+
const mutationCache = client.getMutationCache();
|
|
3065
|
+
const queryCache = client.getQueryCache(); // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
3066
|
+
|
|
3067
|
+
const mutations = dehydratedState.mutations || []; // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
3068
|
+
|
|
3069
|
+
const queries = dehydratedState.queries || [];
|
|
3070
|
+
mutations.forEach(dehydratedMutation => {
|
|
3071
|
+
var _options$defaultOptio;
|
|
3072
|
+
|
|
3073
|
+
mutationCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio = options.defaultOptions) == null ? void 0 : _options$defaultOptio.mutations),
|
|
3074
|
+
mutationKey: dehydratedMutation.mutationKey
|
|
3075
|
+
}, dehydratedMutation.state);
|
|
3076
|
+
});
|
|
3077
|
+
queries.forEach(dehydratedQuery => {
|
|
3078
|
+
var _options$defaultOptio2;
|
|
3079
|
+
|
|
3080
|
+
const query = queryCache.get(dehydratedQuery.queryHash); // Do not hydrate if an existing query exists with newer data
|
|
3081
|
+
|
|
3082
|
+
if (query) {
|
|
3083
|
+
if (query.state.dataUpdatedAt < dehydratedQuery.state.dataUpdatedAt) {
|
|
3084
|
+
query.setState(dehydratedQuery.state);
|
|
3085
|
+
}
|
|
3086
|
+
|
|
3087
|
+
return;
|
|
3088
|
+
} // Restore query
|
|
3089
|
+
|
|
3090
|
+
|
|
3091
|
+
queryCache.build(client, { ...(options == null ? void 0 : (_options$defaultOptio2 = options.defaultOptions) == null ? void 0 : _options$defaultOptio2.queries),
|
|
3092
|
+
queryKey: dehydratedQuery.queryKey,
|
|
3093
|
+
queryHash: dehydratedQuery.queryHash
|
|
3094
|
+
}, dehydratedQuery.state);
|
|
3095
|
+
});
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
3099
|
+
const VUE_QUERY_CLIENT = 'VUE_QUERY_CLIENT';
|
|
3100
|
+
function getClientKey(key) {
|
|
3101
|
+
const suffix = key ? ":" + key : '';
|
|
3102
|
+
return "" + VUE_QUERY_CLIENT + suffix;
|
|
3103
|
+
}
|
|
3104
|
+
function isQueryKey(value) {
|
|
3105
|
+
return Array.isArray(value);
|
|
3106
|
+
}
|
|
3107
|
+
function updateState(state, update) {
|
|
3108
|
+
Object.keys(state).forEach(key => {
|
|
3109
|
+
state[key] = update[key];
|
|
3110
|
+
});
|
|
3111
|
+
}
|
|
3112
|
+
function cloneDeep(value, customizer) {
|
|
3113
|
+
if (customizer) {
|
|
3114
|
+
const result = customizer(value);
|
|
3115
|
+
|
|
3116
|
+
if (result !== undefined || vueDemi.isRef(value)) {
|
|
3117
|
+
return result;
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
|
|
3121
|
+
if (Array.isArray(value)) {
|
|
3122
|
+
return value.map(val => cloneDeep(val, customizer));
|
|
3123
|
+
}
|
|
3124
|
+
|
|
3125
|
+
if (typeof value === 'object' && isPlainObject(value)) {
|
|
3126
|
+
const entries = Object.entries(value).map(([key, val]) => [key, cloneDeep(val, customizer)]);
|
|
3127
|
+
return Object.fromEntries(entries);
|
|
3128
|
+
}
|
|
3129
|
+
|
|
3130
|
+
return value;
|
|
3131
|
+
}
|
|
3132
|
+
function cloneDeepUnref(obj) {
|
|
3133
|
+
return cloneDeep(obj, val => {
|
|
3134
|
+
if (vueDemi.isRef(val)) {
|
|
3135
|
+
return cloneDeepUnref(vueDemi.unref(val));
|
|
3136
|
+
}
|
|
3137
|
+
});
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
function isPlainObject(value) {
|
|
3141
|
+
if (Object.prototype.toString.call(value) !== '[object Object]') {
|
|
3142
|
+
return false;
|
|
3143
|
+
}
|
|
3144
|
+
|
|
3145
|
+
const prototype = Object.getPrototypeOf(value);
|
|
3146
|
+
return prototype === null || prototype === Object.prototype;
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
function useQueryClient(id = '') {
|
|
3150
|
+
var _getCurrentInstance;
|
|
3151
|
+
|
|
3152
|
+
const vm = (_getCurrentInstance = vueDemi.getCurrentInstance()) == null ? void 0 : _getCurrentInstance.proxy;
|
|
3153
|
+
|
|
3154
|
+
if (!vm) {
|
|
3155
|
+
throw new Error('vue-query hooks can only be used inside setup() function.');
|
|
3156
|
+
}
|
|
3157
|
+
|
|
3158
|
+
const key = getClientKey(id);
|
|
3159
|
+
const queryClient = vueDemi.inject(key);
|
|
3160
|
+
|
|
3161
|
+
if (!queryClient) {
|
|
3162
|
+
throw new Error("No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library.");
|
|
3163
|
+
}
|
|
3164
|
+
|
|
3165
|
+
return queryClient;
|
|
3166
|
+
}
|
|
3167
|
+
|
|
3168
|
+
class QueryCache extends QueryCache$1 {
|
|
3169
|
+
find(arg1, arg2) {
|
|
3170
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3171
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3172
|
+
return super.find(arg1Unreffed, arg2Unreffed);
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
findAll(arg1, arg2) {
|
|
3176
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3177
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3178
|
+
|
|
3179
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3180
|
+
return super.findAll(arg1Unreffed, arg2Unreffed);
|
|
3181
|
+
}
|
|
3182
|
+
|
|
3183
|
+
return super.findAll(arg1Unreffed);
|
|
3184
|
+
}
|
|
3185
|
+
|
|
3186
|
+
}
|
|
3187
|
+
|
|
3188
|
+
class MutationCache extends MutationCache$1 {
|
|
3189
|
+
find(filters) {
|
|
3190
|
+
return super.find(cloneDeepUnref(filters));
|
|
3191
|
+
}
|
|
3192
|
+
|
|
3193
|
+
findAll(filters) {
|
|
3194
|
+
return super.findAll(cloneDeepUnref(filters));
|
|
3195
|
+
}
|
|
3196
|
+
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
class QueryClient extends QueryClient$1 {
|
|
3200
|
+
constructor(config = {}) {
|
|
3201
|
+
const unreffedConfig = cloneDeepUnref(config);
|
|
3202
|
+
const vueQueryConfig = {
|
|
3203
|
+
logger: cloneDeepUnref(unreffedConfig.logger),
|
|
3204
|
+
defaultOptions: cloneDeepUnref(unreffedConfig.defaultOptions),
|
|
3205
|
+
queryCache: unreffedConfig.queryCache || new QueryCache(),
|
|
3206
|
+
mutationCache: unreffedConfig.mutationCache || new MutationCache()
|
|
3207
|
+
};
|
|
3208
|
+
super(vueQueryConfig);
|
|
3209
|
+
}
|
|
3210
|
+
|
|
3211
|
+
isFetching(arg1, arg2) {
|
|
3212
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3213
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3214
|
+
|
|
3215
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3216
|
+
return super.isFetching(arg1Unreffed, arg2Unreffed);
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
return super.isFetching(arg1Unreffed);
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
isMutating(filters) {
|
|
3223
|
+
return super.isMutating(cloneDeepUnref(filters));
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
getQueryData(queryKey, filters) {
|
|
3227
|
+
return super.getQueryData(cloneDeepUnref(queryKey), cloneDeepUnref(filters));
|
|
3228
|
+
}
|
|
3229
|
+
|
|
3230
|
+
getQueriesData(queryKeyOrFilters) {
|
|
3231
|
+
const unreffed = cloneDeepUnref(queryKeyOrFilters);
|
|
3232
|
+
|
|
3233
|
+
if (isQueryKey(unreffed)) {
|
|
3234
|
+
return super.getQueriesData(unreffed);
|
|
3235
|
+
}
|
|
3236
|
+
|
|
3237
|
+
return super.getQueriesData(unreffed);
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
setQueryData(queryKey, updater, options) {
|
|
3241
|
+
return super.setQueryData(cloneDeepUnref(queryKey), updater, cloneDeepUnref(options));
|
|
3242
|
+
}
|
|
3243
|
+
|
|
3244
|
+
setQueriesData(queryKeyOrFilters, updater, options) {
|
|
3245
|
+
const arg1Unreffed = cloneDeepUnref(queryKeyOrFilters);
|
|
3246
|
+
const arg3Unreffed = cloneDeepUnref(options);
|
|
3247
|
+
|
|
3248
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3249
|
+
return super.setQueriesData(arg1Unreffed, updater, arg3Unreffed);
|
|
3250
|
+
}
|
|
3251
|
+
|
|
3252
|
+
return super.setQueriesData(arg1Unreffed, updater, arg3Unreffed);
|
|
3253
|
+
}
|
|
3254
|
+
|
|
3255
|
+
getQueryState(queryKey, filters) {
|
|
3256
|
+
return super.getQueryState(cloneDeepUnref(queryKey), cloneDeepUnref(filters));
|
|
3257
|
+
}
|
|
3258
|
+
|
|
3259
|
+
removeQueries(arg1, arg2) {
|
|
3260
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3261
|
+
|
|
3262
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3263
|
+
return super.removeQueries(arg1Unreffed, cloneDeepUnref(arg2));
|
|
3264
|
+
}
|
|
3265
|
+
|
|
3266
|
+
return super.removeQueries(arg1Unreffed);
|
|
3267
|
+
}
|
|
3268
|
+
|
|
3269
|
+
resetQueries(arg1, arg2, arg3) {
|
|
3270
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3271
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3272
|
+
|
|
3273
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3274
|
+
return super.resetQueries(arg1Unreffed, arg2Unreffed, cloneDeepUnref(arg3));
|
|
3275
|
+
}
|
|
3276
|
+
|
|
3277
|
+
return super.resetQueries(arg1Unreffed, arg2Unreffed);
|
|
3278
|
+
}
|
|
3279
|
+
|
|
3280
|
+
cancelQueries(arg1, arg2, arg3) {
|
|
3281
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3282
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3283
|
+
|
|
3284
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3285
|
+
return super.cancelQueries(arg1Unreffed, arg2Unreffed, cloneDeepUnref(arg3));
|
|
3286
|
+
}
|
|
3287
|
+
|
|
3288
|
+
return super.cancelQueries(arg1Unreffed, arg2Unreffed);
|
|
3289
|
+
}
|
|
3290
|
+
|
|
3291
|
+
invalidateQueries(arg1, arg2, arg3) {
|
|
3292
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3293
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3294
|
+
|
|
3295
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3296
|
+
return super.invalidateQueries(arg1Unreffed, arg2Unreffed, cloneDeepUnref(arg3));
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
return super.invalidateQueries(arg1Unreffed, arg2Unreffed);
|
|
3300
|
+
}
|
|
3301
|
+
|
|
3302
|
+
refetchQueries(arg1, arg2, arg3) {
|
|
3303
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3304
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3305
|
+
|
|
3306
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3307
|
+
return super.refetchQueries(arg1Unreffed, arg2Unreffed, cloneDeepUnref(arg3));
|
|
3308
|
+
}
|
|
3309
|
+
|
|
3310
|
+
return super.refetchQueries(arg1Unreffed, arg2Unreffed);
|
|
3311
|
+
}
|
|
3312
|
+
|
|
3313
|
+
fetchQuery(arg1, arg2, arg3) {
|
|
3314
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3315
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3316
|
+
|
|
3317
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3318
|
+
return super.fetchQuery(arg1Unreffed, arg2Unreffed, cloneDeepUnref(arg3));
|
|
3319
|
+
}
|
|
3320
|
+
|
|
3321
|
+
return super.fetchQuery(arg1Unreffed);
|
|
3322
|
+
}
|
|
3323
|
+
|
|
3324
|
+
prefetchQuery(arg1, arg2, arg3) {
|
|
3325
|
+
return super.prefetchQuery(cloneDeepUnref(arg1), cloneDeepUnref(arg2), cloneDeepUnref(arg3));
|
|
3326
|
+
}
|
|
3327
|
+
|
|
3328
|
+
fetchInfiniteQuery(arg1, arg2, arg3) {
|
|
3329
|
+
const arg1Unreffed = cloneDeepUnref(arg1);
|
|
3330
|
+
const arg2Unreffed = cloneDeepUnref(arg2);
|
|
3331
|
+
|
|
3332
|
+
if (isQueryKey(arg1Unreffed)) {
|
|
3333
|
+
return super.fetchInfiniteQuery(arg1Unreffed, arg2Unreffed, cloneDeepUnref(arg3));
|
|
3334
|
+
}
|
|
3335
|
+
|
|
3336
|
+
return super.fetchInfiniteQuery(arg1Unreffed);
|
|
3337
|
+
}
|
|
3338
|
+
|
|
3339
|
+
prefetchInfiniteQuery(arg1, arg2, arg3) {
|
|
3340
|
+
return super.prefetchInfiniteQuery(cloneDeepUnref(arg1), cloneDeepUnref(arg2), cloneDeepUnref(arg3));
|
|
3341
|
+
}
|
|
3342
|
+
|
|
3343
|
+
setDefaultOptions(options) {
|
|
3344
|
+
super.setDefaultOptions(cloneDeepUnref(options));
|
|
3345
|
+
}
|
|
3346
|
+
|
|
3347
|
+
setQueryDefaults(queryKey, options) {
|
|
3348
|
+
super.setQueryDefaults(cloneDeepUnref(queryKey), cloneDeepUnref(options));
|
|
3349
|
+
}
|
|
3350
|
+
|
|
3351
|
+
getQueryDefaults(queryKey) {
|
|
3352
|
+
return super.getQueryDefaults(cloneDeepUnref(queryKey));
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
setMutationDefaults(mutationKey, options) {
|
|
3356
|
+
super.setMutationDefaults(cloneDeepUnref(mutationKey), cloneDeepUnref(options));
|
|
3357
|
+
}
|
|
3358
|
+
|
|
3359
|
+
getMutationDefaults(mutationKey) {
|
|
3360
|
+
return super.getMutationDefaults(cloneDeepUnref(mutationKey));
|
|
3361
|
+
}
|
|
3362
|
+
|
|
3363
|
+
}
|
|
3364
|
+
|
|
3365
|
+
function getDevtoolsGlobalHook() {
|
|
3366
|
+
return getTarget().__VUE_DEVTOOLS_GLOBAL_HOOK__;
|
|
3367
|
+
}
|
|
3368
|
+
function getTarget() {
|
|
3369
|
+
// @ts-ignore
|
|
3370
|
+
return (typeof navigator !== 'undefined' && typeof window !== 'undefined')
|
|
3371
|
+
? window
|
|
3372
|
+
: typeof global !== 'undefined'
|
|
3373
|
+
? global
|
|
3374
|
+
: {};
|
|
3375
|
+
}
|
|
3376
|
+
const isProxyAvailable = typeof Proxy === 'function';
|
|
3377
|
+
|
|
3378
|
+
const HOOK_SETUP = 'devtools-plugin:setup';
|
|
3379
|
+
const HOOK_PLUGIN_SETTINGS_SET = 'plugin:settings:set';
|
|
3380
|
+
|
|
3381
|
+
let supported;
|
|
3382
|
+
let perf;
|
|
3383
|
+
function isPerformanceSupported() {
|
|
3384
|
+
var _a;
|
|
3385
|
+
if (supported !== undefined) {
|
|
3386
|
+
return supported;
|
|
3387
|
+
}
|
|
3388
|
+
if (typeof window !== 'undefined' && window.performance) {
|
|
3389
|
+
supported = true;
|
|
3390
|
+
perf = window.performance;
|
|
3391
|
+
}
|
|
3392
|
+
else if (typeof global !== 'undefined' && ((_a = global.perf_hooks) === null || _a === void 0 ? void 0 : _a.performance)) {
|
|
3393
|
+
supported = true;
|
|
3394
|
+
perf = global.perf_hooks.performance;
|
|
3395
|
+
}
|
|
3396
|
+
else {
|
|
3397
|
+
supported = false;
|
|
3398
|
+
}
|
|
3399
|
+
return supported;
|
|
3400
|
+
}
|
|
3401
|
+
function now() {
|
|
3402
|
+
return isPerformanceSupported() ? perf.now() : Date.now();
|
|
3403
|
+
}
|
|
3404
|
+
|
|
3405
|
+
class ApiProxy {
|
|
3406
|
+
constructor(plugin, hook) {
|
|
3407
|
+
this.target = null;
|
|
3408
|
+
this.targetQueue = [];
|
|
3409
|
+
this.onQueue = [];
|
|
3410
|
+
this.plugin = plugin;
|
|
3411
|
+
this.hook = hook;
|
|
3412
|
+
const defaultSettings = {};
|
|
3413
|
+
if (plugin.settings) {
|
|
3414
|
+
for (const id in plugin.settings) {
|
|
3415
|
+
const item = plugin.settings[id];
|
|
3416
|
+
defaultSettings[id] = item.defaultValue;
|
|
3417
|
+
}
|
|
3418
|
+
}
|
|
3419
|
+
const localSettingsSaveId = `__vue-devtools-plugin-settings__${plugin.id}`;
|
|
3420
|
+
let currentSettings = Object.assign({}, defaultSettings);
|
|
3421
|
+
try {
|
|
3422
|
+
const raw = localStorage.getItem(localSettingsSaveId);
|
|
3423
|
+
const data = JSON.parse(raw);
|
|
3424
|
+
Object.assign(currentSettings, data);
|
|
3425
|
+
}
|
|
3426
|
+
catch (e) {
|
|
3427
|
+
// noop
|
|
3428
|
+
}
|
|
3429
|
+
this.fallbacks = {
|
|
3430
|
+
getSettings() {
|
|
3431
|
+
return currentSettings;
|
|
3432
|
+
},
|
|
3433
|
+
setSettings(value) {
|
|
3434
|
+
try {
|
|
3435
|
+
localStorage.setItem(localSettingsSaveId, JSON.stringify(value));
|
|
3436
|
+
}
|
|
3437
|
+
catch (e) {
|
|
3438
|
+
// noop
|
|
3439
|
+
}
|
|
3440
|
+
currentSettings = value;
|
|
3441
|
+
},
|
|
3442
|
+
now() {
|
|
3443
|
+
return now();
|
|
3444
|
+
},
|
|
3445
|
+
};
|
|
3446
|
+
if (hook) {
|
|
3447
|
+
hook.on(HOOK_PLUGIN_SETTINGS_SET, (pluginId, value) => {
|
|
3448
|
+
if (pluginId === this.plugin.id) {
|
|
3449
|
+
this.fallbacks.setSettings(value);
|
|
3450
|
+
}
|
|
3451
|
+
});
|
|
3452
|
+
}
|
|
3453
|
+
this.proxiedOn = new Proxy({}, {
|
|
3454
|
+
get: (_target, prop) => {
|
|
3455
|
+
if (this.target) {
|
|
3456
|
+
return this.target.on[prop];
|
|
3457
|
+
}
|
|
3458
|
+
else {
|
|
3459
|
+
return (...args) => {
|
|
3460
|
+
this.onQueue.push({
|
|
3461
|
+
method: prop,
|
|
3462
|
+
args,
|
|
3463
|
+
});
|
|
3464
|
+
};
|
|
3465
|
+
}
|
|
3466
|
+
},
|
|
3467
|
+
});
|
|
3468
|
+
this.proxiedTarget = new Proxy({}, {
|
|
3469
|
+
get: (_target, prop) => {
|
|
3470
|
+
if (this.target) {
|
|
3471
|
+
return this.target[prop];
|
|
3472
|
+
}
|
|
3473
|
+
else if (prop === 'on') {
|
|
3474
|
+
return this.proxiedOn;
|
|
3475
|
+
}
|
|
3476
|
+
else if (Object.keys(this.fallbacks).includes(prop)) {
|
|
3477
|
+
return (...args) => {
|
|
3478
|
+
this.targetQueue.push({
|
|
3479
|
+
method: prop,
|
|
3480
|
+
args,
|
|
3481
|
+
resolve: () => { },
|
|
3482
|
+
});
|
|
3483
|
+
return this.fallbacks[prop](...args);
|
|
3484
|
+
};
|
|
3485
|
+
}
|
|
3486
|
+
else {
|
|
3487
|
+
return (...args) => {
|
|
3488
|
+
return new Promise(resolve => {
|
|
3489
|
+
this.targetQueue.push({
|
|
3490
|
+
method: prop,
|
|
3491
|
+
args,
|
|
3492
|
+
resolve,
|
|
3493
|
+
});
|
|
3494
|
+
});
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
},
|
|
3498
|
+
});
|
|
3499
|
+
}
|
|
3500
|
+
async setRealTarget(target) {
|
|
3501
|
+
this.target = target;
|
|
3502
|
+
for (const item of this.onQueue) {
|
|
3503
|
+
this.target.on[item.method](...item.args);
|
|
3504
|
+
}
|
|
3505
|
+
for (const item of this.targetQueue) {
|
|
3506
|
+
item.resolve(await this.target[item.method](...item.args));
|
|
3507
|
+
}
|
|
3508
|
+
}
|
|
3509
|
+
}
|
|
3510
|
+
|
|
3511
|
+
function setupDevtoolsPlugin(pluginDescriptor, setupFn) {
|
|
3512
|
+
const descriptor = pluginDescriptor;
|
|
3513
|
+
const target = getTarget();
|
|
3514
|
+
const hook = getDevtoolsGlobalHook();
|
|
3515
|
+
const enableProxy = isProxyAvailable && descriptor.enableEarlyProxy;
|
|
3516
|
+
if (hook && (target.__VUE_DEVTOOLS_PLUGIN_API_AVAILABLE__ || !enableProxy)) {
|
|
3517
|
+
hook.emit(HOOK_SETUP, pluginDescriptor, setupFn);
|
|
3518
|
+
}
|
|
3519
|
+
else {
|
|
3520
|
+
const proxy = enableProxy ? new ApiProxy(descriptor, hook) : null;
|
|
3521
|
+
const list = target.__VUE_DEVTOOLS_PLUGINS__ = target.__VUE_DEVTOOLS_PLUGINS__ || [];
|
|
3522
|
+
list.push({
|
|
3523
|
+
pluginDescriptor: descriptor,
|
|
3524
|
+
setupFn,
|
|
3525
|
+
proxy,
|
|
3526
|
+
});
|
|
3527
|
+
if (proxy)
|
|
3528
|
+
setupFn(proxy.proxiedTarget);
|
|
3529
|
+
}
|
|
3530
|
+
}
|
|
3531
|
+
|
|
3532
|
+
function _extends() {
|
|
3533
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
3534
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
3535
|
+
var source = arguments[i];
|
|
3536
|
+
|
|
3537
|
+
for (var key in source) {
|
|
3538
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
3539
|
+
target[key] = source[key];
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
}
|
|
3543
|
+
|
|
3544
|
+
return target;
|
|
3545
|
+
};
|
|
3546
|
+
return _extends.apply(this, arguments);
|
|
3547
|
+
}
|
|
3548
|
+
|
|
3549
|
+
var removeAccents$1 = {exports: {}};
|
|
3550
|
+
|
|
3551
|
+
var characterMap = {
|
|
3552
|
+
"À": "A",
|
|
3553
|
+
"Á": "A",
|
|
3554
|
+
"Â": "A",
|
|
3555
|
+
"Ã": "A",
|
|
3556
|
+
"Ä": "A",
|
|
3557
|
+
"Å": "A",
|
|
3558
|
+
"Ấ": "A",
|
|
3559
|
+
"Ắ": "A",
|
|
3560
|
+
"Ẳ": "A",
|
|
3561
|
+
"Ẵ": "A",
|
|
3562
|
+
"Ặ": "A",
|
|
3563
|
+
"Æ": "AE",
|
|
3564
|
+
"Ầ": "A",
|
|
3565
|
+
"Ằ": "A",
|
|
3566
|
+
"Ȃ": "A",
|
|
3567
|
+
"Ç": "C",
|
|
3568
|
+
"Ḉ": "C",
|
|
3569
|
+
"È": "E",
|
|
3570
|
+
"É": "E",
|
|
3571
|
+
"Ê": "E",
|
|
3572
|
+
"Ë": "E",
|
|
3573
|
+
"Ế": "E",
|
|
3574
|
+
"Ḗ": "E",
|
|
3575
|
+
"Ề": "E",
|
|
3576
|
+
"Ḕ": "E",
|
|
3577
|
+
"Ḝ": "E",
|
|
3578
|
+
"Ȇ": "E",
|
|
3579
|
+
"Ì": "I",
|
|
3580
|
+
"Í": "I",
|
|
3581
|
+
"Î": "I",
|
|
3582
|
+
"Ï": "I",
|
|
3583
|
+
"Ḯ": "I",
|
|
3584
|
+
"Ȋ": "I",
|
|
3585
|
+
"Ð": "D",
|
|
3586
|
+
"Ñ": "N",
|
|
3587
|
+
"Ò": "O",
|
|
3588
|
+
"Ó": "O",
|
|
3589
|
+
"Ô": "O",
|
|
3590
|
+
"Õ": "O",
|
|
3591
|
+
"Ö": "O",
|
|
3592
|
+
"Ø": "O",
|
|
3593
|
+
"Ố": "O",
|
|
3594
|
+
"Ṍ": "O",
|
|
3595
|
+
"Ṓ": "O",
|
|
3596
|
+
"Ȏ": "O",
|
|
3597
|
+
"Ù": "U",
|
|
3598
|
+
"Ú": "U",
|
|
3599
|
+
"Û": "U",
|
|
3600
|
+
"Ü": "U",
|
|
3601
|
+
"Ý": "Y",
|
|
3602
|
+
"à": "a",
|
|
3603
|
+
"á": "a",
|
|
3604
|
+
"â": "a",
|
|
3605
|
+
"ã": "a",
|
|
3606
|
+
"ä": "a",
|
|
3607
|
+
"å": "a",
|
|
3608
|
+
"ấ": "a",
|
|
3609
|
+
"ắ": "a",
|
|
3610
|
+
"ẳ": "a",
|
|
3611
|
+
"ẵ": "a",
|
|
3612
|
+
"ặ": "a",
|
|
3613
|
+
"æ": "ae",
|
|
3614
|
+
"ầ": "a",
|
|
3615
|
+
"ằ": "a",
|
|
3616
|
+
"ȃ": "a",
|
|
3617
|
+
"ç": "c",
|
|
3618
|
+
"ḉ": "c",
|
|
3619
|
+
"è": "e",
|
|
3620
|
+
"é": "e",
|
|
3621
|
+
"ê": "e",
|
|
3622
|
+
"ë": "e",
|
|
3623
|
+
"ế": "e",
|
|
3624
|
+
"ḗ": "e",
|
|
3625
|
+
"ề": "e",
|
|
3626
|
+
"ḕ": "e",
|
|
3627
|
+
"ḝ": "e",
|
|
3628
|
+
"ȇ": "e",
|
|
3629
|
+
"ì": "i",
|
|
3630
|
+
"í": "i",
|
|
3631
|
+
"î": "i",
|
|
3632
|
+
"ï": "i",
|
|
3633
|
+
"ḯ": "i",
|
|
3634
|
+
"ȋ": "i",
|
|
3635
|
+
"ð": "d",
|
|
3636
|
+
"ñ": "n",
|
|
3637
|
+
"ò": "o",
|
|
3638
|
+
"ó": "o",
|
|
3639
|
+
"ô": "o",
|
|
3640
|
+
"õ": "o",
|
|
3641
|
+
"ö": "o",
|
|
3642
|
+
"ø": "o",
|
|
3643
|
+
"ố": "o",
|
|
3644
|
+
"ṍ": "o",
|
|
3645
|
+
"ṓ": "o",
|
|
3646
|
+
"ȏ": "o",
|
|
3647
|
+
"ù": "u",
|
|
3648
|
+
"ú": "u",
|
|
3649
|
+
"û": "u",
|
|
3650
|
+
"ü": "u",
|
|
3651
|
+
"ý": "y",
|
|
3652
|
+
"ÿ": "y",
|
|
3653
|
+
"Ā": "A",
|
|
3654
|
+
"ā": "a",
|
|
3655
|
+
"Ă": "A",
|
|
3656
|
+
"ă": "a",
|
|
3657
|
+
"Ą": "A",
|
|
3658
|
+
"ą": "a",
|
|
3659
|
+
"Ć": "C",
|
|
3660
|
+
"ć": "c",
|
|
3661
|
+
"Ĉ": "C",
|
|
3662
|
+
"ĉ": "c",
|
|
3663
|
+
"Ċ": "C",
|
|
3664
|
+
"ċ": "c",
|
|
3665
|
+
"Č": "C",
|
|
3666
|
+
"č": "c",
|
|
3667
|
+
"C̆": "C",
|
|
3668
|
+
"c̆": "c",
|
|
3669
|
+
"Ď": "D",
|
|
3670
|
+
"ď": "d",
|
|
3671
|
+
"Đ": "D",
|
|
3672
|
+
"đ": "d",
|
|
3673
|
+
"Ē": "E",
|
|
3674
|
+
"ē": "e",
|
|
3675
|
+
"Ĕ": "E",
|
|
3676
|
+
"ĕ": "e",
|
|
3677
|
+
"Ė": "E",
|
|
3678
|
+
"ė": "e",
|
|
3679
|
+
"Ę": "E",
|
|
3680
|
+
"ę": "e",
|
|
3681
|
+
"Ě": "E",
|
|
3682
|
+
"ě": "e",
|
|
3683
|
+
"Ĝ": "G",
|
|
3684
|
+
"Ǵ": "G",
|
|
3685
|
+
"ĝ": "g",
|
|
3686
|
+
"ǵ": "g",
|
|
3687
|
+
"Ğ": "G",
|
|
3688
|
+
"ğ": "g",
|
|
3689
|
+
"Ġ": "G",
|
|
3690
|
+
"ġ": "g",
|
|
3691
|
+
"Ģ": "G",
|
|
3692
|
+
"ģ": "g",
|
|
3693
|
+
"Ĥ": "H",
|
|
3694
|
+
"ĥ": "h",
|
|
3695
|
+
"Ħ": "H",
|
|
3696
|
+
"ħ": "h",
|
|
3697
|
+
"Ḫ": "H",
|
|
3698
|
+
"ḫ": "h",
|
|
3699
|
+
"Ĩ": "I",
|
|
3700
|
+
"ĩ": "i",
|
|
3701
|
+
"Ī": "I",
|
|
3702
|
+
"ī": "i",
|
|
3703
|
+
"Ĭ": "I",
|
|
3704
|
+
"ĭ": "i",
|
|
3705
|
+
"Į": "I",
|
|
3706
|
+
"į": "i",
|
|
3707
|
+
"İ": "I",
|
|
3708
|
+
"ı": "i",
|
|
3709
|
+
"IJ": "IJ",
|
|
3710
|
+
"ij": "ij",
|
|
3711
|
+
"Ĵ": "J",
|
|
3712
|
+
"ĵ": "j",
|
|
3713
|
+
"Ķ": "K",
|
|
3714
|
+
"ķ": "k",
|
|
3715
|
+
"Ḱ": "K",
|
|
3716
|
+
"ḱ": "k",
|
|
3717
|
+
"K̆": "K",
|
|
3718
|
+
"k̆": "k",
|
|
3719
|
+
"Ĺ": "L",
|
|
3720
|
+
"ĺ": "l",
|
|
3721
|
+
"Ļ": "L",
|
|
3722
|
+
"ļ": "l",
|
|
3723
|
+
"Ľ": "L",
|
|
3724
|
+
"ľ": "l",
|
|
3725
|
+
"Ŀ": "L",
|
|
3726
|
+
"ŀ": "l",
|
|
3727
|
+
"Ł": "l",
|
|
3728
|
+
"ł": "l",
|
|
3729
|
+
"Ḿ": "M",
|
|
3730
|
+
"ḿ": "m",
|
|
3731
|
+
"M̆": "M",
|
|
3732
|
+
"m̆": "m",
|
|
3733
|
+
"Ń": "N",
|
|
3734
|
+
"ń": "n",
|
|
3735
|
+
"Ņ": "N",
|
|
3736
|
+
"ņ": "n",
|
|
3737
|
+
"Ň": "N",
|
|
3738
|
+
"ň": "n",
|
|
3739
|
+
"ʼn": "n",
|
|
3740
|
+
"N̆": "N",
|
|
3741
|
+
"n̆": "n",
|
|
3742
|
+
"Ō": "O",
|
|
3743
|
+
"ō": "o",
|
|
3744
|
+
"Ŏ": "O",
|
|
3745
|
+
"ŏ": "o",
|
|
3746
|
+
"Ő": "O",
|
|
3747
|
+
"ő": "o",
|
|
3748
|
+
"Œ": "OE",
|
|
3749
|
+
"œ": "oe",
|
|
3750
|
+
"P̆": "P",
|
|
3751
|
+
"p̆": "p",
|
|
3752
|
+
"Ŕ": "R",
|
|
3753
|
+
"ŕ": "r",
|
|
3754
|
+
"Ŗ": "R",
|
|
3755
|
+
"ŗ": "r",
|
|
3756
|
+
"Ř": "R",
|
|
3757
|
+
"ř": "r",
|
|
3758
|
+
"R̆": "R",
|
|
3759
|
+
"r̆": "r",
|
|
3760
|
+
"Ȓ": "R",
|
|
3761
|
+
"ȓ": "r",
|
|
3762
|
+
"Ś": "S",
|
|
3763
|
+
"ś": "s",
|
|
3764
|
+
"Ŝ": "S",
|
|
3765
|
+
"ŝ": "s",
|
|
3766
|
+
"Ş": "S",
|
|
3767
|
+
"Ș": "S",
|
|
3768
|
+
"ș": "s",
|
|
3769
|
+
"ş": "s",
|
|
3770
|
+
"Š": "S",
|
|
3771
|
+
"š": "s",
|
|
3772
|
+
"Ţ": "T",
|
|
3773
|
+
"ţ": "t",
|
|
3774
|
+
"ț": "t",
|
|
3775
|
+
"Ț": "T",
|
|
3776
|
+
"Ť": "T",
|
|
3777
|
+
"ť": "t",
|
|
3778
|
+
"Ŧ": "T",
|
|
3779
|
+
"ŧ": "t",
|
|
3780
|
+
"T̆": "T",
|
|
3781
|
+
"t̆": "t",
|
|
3782
|
+
"Ũ": "U",
|
|
3783
|
+
"ũ": "u",
|
|
3784
|
+
"Ū": "U",
|
|
3785
|
+
"ū": "u",
|
|
3786
|
+
"Ŭ": "U",
|
|
3787
|
+
"ŭ": "u",
|
|
3788
|
+
"Ů": "U",
|
|
3789
|
+
"ů": "u",
|
|
3790
|
+
"Ű": "U",
|
|
3791
|
+
"ű": "u",
|
|
3792
|
+
"Ų": "U",
|
|
3793
|
+
"ų": "u",
|
|
3794
|
+
"Ȗ": "U",
|
|
3795
|
+
"ȗ": "u",
|
|
3796
|
+
"V̆": "V",
|
|
3797
|
+
"v̆": "v",
|
|
3798
|
+
"Ŵ": "W",
|
|
3799
|
+
"ŵ": "w",
|
|
3800
|
+
"Ẃ": "W",
|
|
3801
|
+
"ẃ": "w",
|
|
3802
|
+
"X̆": "X",
|
|
3803
|
+
"x̆": "x",
|
|
3804
|
+
"Ŷ": "Y",
|
|
3805
|
+
"ŷ": "y",
|
|
3806
|
+
"Ÿ": "Y",
|
|
3807
|
+
"Y̆": "Y",
|
|
3808
|
+
"y̆": "y",
|
|
3809
|
+
"Ź": "Z",
|
|
3810
|
+
"ź": "z",
|
|
3811
|
+
"Ż": "Z",
|
|
3812
|
+
"ż": "z",
|
|
3813
|
+
"Ž": "Z",
|
|
3814
|
+
"ž": "z",
|
|
3815
|
+
"ſ": "s",
|
|
3816
|
+
"ƒ": "f",
|
|
3817
|
+
"Ơ": "O",
|
|
3818
|
+
"ơ": "o",
|
|
3819
|
+
"Ư": "U",
|
|
3820
|
+
"ư": "u",
|
|
3821
|
+
"Ǎ": "A",
|
|
3822
|
+
"ǎ": "a",
|
|
3823
|
+
"Ǐ": "I",
|
|
3824
|
+
"ǐ": "i",
|
|
3825
|
+
"Ǒ": "O",
|
|
3826
|
+
"ǒ": "o",
|
|
3827
|
+
"Ǔ": "U",
|
|
3828
|
+
"ǔ": "u",
|
|
3829
|
+
"Ǖ": "U",
|
|
3830
|
+
"ǖ": "u",
|
|
3831
|
+
"Ǘ": "U",
|
|
3832
|
+
"ǘ": "u",
|
|
3833
|
+
"Ǚ": "U",
|
|
3834
|
+
"ǚ": "u",
|
|
3835
|
+
"Ǜ": "U",
|
|
3836
|
+
"ǜ": "u",
|
|
3837
|
+
"Ứ": "U",
|
|
3838
|
+
"ứ": "u",
|
|
3839
|
+
"Ṹ": "U",
|
|
3840
|
+
"ṹ": "u",
|
|
3841
|
+
"Ǻ": "A",
|
|
3842
|
+
"ǻ": "a",
|
|
3843
|
+
"Ǽ": "AE",
|
|
3844
|
+
"ǽ": "ae",
|
|
3845
|
+
"Ǿ": "O",
|
|
3846
|
+
"ǿ": "o",
|
|
3847
|
+
"Þ": "TH",
|
|
3848
|
+
"þ": "th",
|
|
3849
|
+
"Ṕ": "P",
|
|
3850
|
+
"ṕ": "p",
|
|
3851
|
+
"Ṥ": "S",
|
|
3852
|
+
"ṥ": "s",
|
|
3853
|
+
"X́": "X",
|
|
3854
|
+
"x́": "x",
|
|
3855
|
+
"Ѓ": "Г",
|
|
3856
|
+
"ѓ": "г",
|
|
3857
|
+
"Ќ": "К",
|
|
3858
|
+
"ќ": "к",
|
|
3859
|
+
"A̋": "A",
|
|
3860
|
+
"a̋": "a",
|
|
3861
|
+
"E̋": "E",
|
|
3862
|
+
"e̋": "e",
|
|
3863
|
+
"I̋": "I",
|
|
3864
|
+
"i̋": "i",
|
|
3865
|
+
"Ǹ": "N",
|
|
3866
|
+
"ǹ": "n",
|
|
3867
|
+
"Ồ": "O",
|
|
3868
|
+
"ồ": "o",
|
|
3869
|
+
"Ṑ": "O",
|
|
3870
|
+
"ṑ": "o",
|
|
3871
|
+
"Ừ": "U",
|
|
3872
|
+
"ừ": "u",
|
|
3873
|
+
"Ẁ": "W",
|
|
3874
|
+
"ẁ": "w",
|
|
3875
|
+
"Ỳ": "Y",
|
|
3876
|
+
"ỳ": "y",
|
|
3877
|
+
"Ȁ": "A",
|
|
3878
|
+
"ȁ": "a",
|
|
3879
|
+
"Ȅ": "E",
|
|
3880
|
+
"ȅ": "e",
|
|
3881
|
+
"Ȉ": "I",
|
|
3882
|
+
"ȉ": "i",
|
|
3883
|
+
"Ȍ": "O",
|
|
3884
|
+
"ȍ": "o",
|
|
3885
|
+
"Ȑ": "R",
|
|
3886
|
+
"ȑ": "r",
|
|
3887
|
+
"Ȕ": "U",
|
|
3888
|
+
"ȕ": "u",
|
|
3889
|
+
"B̌": "B",
|
|
3890
|
+
"b̌": "b",
|
|
3891
|
+
"Č̣": "C",
|
|
3892
|
+
"č̣": "c",
|
|
3893
|
+
"Ê̌": "E",
|
|
3894
|
+
"ê̌": "e",
|
|
3895
|
+
"F̌": "F",
|
|
3896
|
+
"f̌": "f",
|
|
3897
|
+
"Ǧ": "G",
|
|
3898
|
+
"ǧ": "g",
|
|
3899
|
+
"Ȟ": "H",
|
|
3900
|
+
"ȟ": "h",
|
|
3901
|
+
"J̌": "J",
|
|
3902
|
+
"ǰ": "j",
|
|
3903
|
+
"Ǩ": "K",
|
|
3904
|
+
"ǩ": "k",
|
|
3905
|
+
"M̌": "M",
|
|
3906
|
+
"m̌": "m",
|
|
3907
|
+
"P̌": "P",
|
|
3908
|
+
"p̌": "p",
|
|
3909
|
+
"Q̌": "Q",
|
|
3910
|
+
"q̌": "q",
|
|
3911
|
+
"Ř̩": "R",
|
|
3912
|
+
"ř̩": "r",
|
|
3913
|
+
"Ṧ": "S",
|
|
3914
|
+
"ṧ": "s",
|
|
3915
|
+
"V̌": "V",
|
|
3916
|
+
"v̌": "v",
|
|
3917
|
+
"W̌": "W",
|
|
3918
|
+
"w̌": "w",
|
|
3919
|
+
"X̌": "X",
|
|
3920
|
+
"x̌": "x",
|
|
3921
|
+
"Y̌": "Y",
|
|
3922
|
+
"y̌": "y",
|
|
3923
|
+
"A̧": "A",
|
|
3924
|
+
"a̧": "a",
|
|
3925
|
+
"B̧": "B",
|
|
3926
|
+
"b̧": "b",
|
|
3927
|
+
"Ḑ": "D",
|
|
3928
|
+
"ḑ": "d",
|
|
3929
|
+
"Ȩ": "E",
|
|
3930
|
+
"ȩ": "e",
|
|
3931
|
+
"Ɛ̧": "E",
|
|
3932
|
+
"ɛ̧": "e",
|
|
3933
|
+
"Ḩ": "H",
|
|
3934
|
+
"ḩ": "h",
|
|
3935
|
+
"I̧": "I",
|
|
3936
|
+
"i̧": "i",
|
|
3937
|
+
"Ɨ̧": "I",
|
|
3938
|
+
"ɨ̧": "i",
|
|
3939
|
+
"M̧": "M",
|
|
3940
|
+
"m̧": "m",
|
|
3941
|
+
"O̧": "O",
|
|
3942
|
+
"o̧": "o",
|
|
3943
|
+
"Q̧": "Q",
|
|
3944
|
+
"q̧": "q",
|
|
3945
|
+
"U̧": "U",
|
|
3946
|
+
"u̧": "u",
|
|
3947
|
+
"X̧": "X",
|
|
3948
|
+
"x̧": "x",
|
|
3949
|
+
"Z̧": "Z",
|
|
3950
|
+
"z̧": "z",
|
|
3951
|
+
};
|
|
3952
|
+
|
|
3953
|
+
var chars = Object.keys(characterMap).join('|');
|
|
3954
|
+
var allAccents = new RegExp(chars, 'g');
|
|
3955
|
+
var firstAccent = new RegExp(chars, '');
|
|
3956
|
+
|
|
3957
|
+
var removeAccents = function(string) {
|
|
3958
|
+
return string.replace(allAccents, function(match) {
|
|
3959
|
+
return characterMap[match];
|
|
3960
|
+
});
|
|
3961
|
+
};
|
|
3962
|
+
|
|
3963
|
+
var hasAccents = function(string) {
|
|
3964
|
+
return !!string.match(firstAccent);
|
|
3965
|
+
};
|
|
3966
|
+
|
|
3967
|
+
removeAccents$1.exports = removeAccents;
|
|
3968
|
+
removeAccents$1.exports.has = hasAccents;
|
|
3969
|
+
removeAccents$1.exports.remove = removeAccents;
|
|
3970
|
+
|
|
3971
|
+
var rankings = {
|
|
3972
|
+
CASE_SENSITIVE_EQUAL: 7,
|
|
3973
|
+
EQUAL: 6,
|
|
3974
|
+
STARTS_WITH: 5,
|
|
3975
|
+
WORD_STARTS_WITH: 4,
|
|
3976
|
+
CONTAINS: 3,
|
|
3977
|
+
ACRONYM: 2,
|
|
3978
|
+
MATCHES: 1,
|
|
3979
|
+
NO_MATCH: 0
|
|
3980
|
+
};
|
|
3981
|
+
matchSorter.rankings = rankings;
|
|
3982
|
+
|
|
3983
|
+
var defaultBaseSortFn = function defaultBaseSortFn(a, b) {
|
|
3984
|
+
return String(a.rankedValue).localeCompare(String(b.rankedValue));
|
|
3985
|
+
};
|
|
3986
|
+
/**
|
|
3987
|
+
* Takes an array of items and a value and returns a new array with the items that match the given value
|
|
3988
|
+
* @param {Array} items - the items to sort
|
|
3989
|
+
* @param {String} value - the value to use for ranking
|
|
3990
|
+
* @param {Object} options - Some options to configure the sorter
|
|
3991
|
+
* @return {Array} - the new sorted array
|
|
3992
|
+
*/
|
|
3993
|
+
|
|
3994
|
+
|
|
3995
|
+
function matchSorter(items, value, options) {
|
|
3996
|
+
if (options === void 0) {
|
|
3997
|
+
options = {};
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
var _options = options,
|
|
4001
|
+
keys = _options.keys,
|
|
4002
|
+
_options$threshold = _options.threshold,
|
|
4003
|
+
threshold = _options$threshold === void 0 ? rankings.MATCHES : _options$threshold,
|
|
4004
|
+
_options$baseSort = _options.baseSort,
|
|
4005
|
+
baseSort = _options$baseSort === void 0 ? defaultBaseSortFn : _options$baseSort,
|
|
4006
|
+
_options$sorter = _options.sorter,
|
|
4007
|
+
sorter = _options$sorter === void 0 ? function (matchedItems) {
|
|
4008
|
+
return matchedItems.sort(function (a, b) {
|
|
4009
|
+
return sortRankedValues(a, b, baseSort);
|
|
4010
|
+
});
|
|
4011
|
+
} : _options$sorter;
|
|
4012
|
+
var matchedItems = items.reduce(reduceItemsToRanked, []);
|
|
4013
|
+
return sorter(matchedItems).map(function (_ref) {
|
|
4014
|
+
var item = _ref.item;
|
|
4015
|
+
return item;
|
|
4016
|
+
});
|
|
4017
|
+
|
|
4018
|
+
function reduceItemsToRanked(matches, item, index) {
|
|
4019
|
+
var rankingInfo = getHighestRanking(item, keys, value, options);
|
|
4020
|
+
var rank = rankingInfo.rank,
|
|
4021
|
+
_rankingInfo$keyThres = rankingInfo.keyThreshold,
|
|
4022
|
+
keyThreshold = _rankingInfo$keyThres === void 0 ? threshold : _rankingInfo$keyThres;
|
|
4023
|
+
|
|
4024
|
+
if (rank >= keyThreshold) {
|
|
4025
|
+
matches.push(_extends({}, rankingInfo, {
|
|
4026
|
+
item: item,
|
|
4027
|
+
index: index
|
|
4028
|
+
}));
|
|
4029
|
+
}
|
|
4030
|
+
|
|
4031
|
+
return matches;
|
|
4032
|
+
}
|
|
4033
|
+
}
|
|
4034
|
+
/**
|
|
4035
|
+
* Gets the highest ranking for value for the given item based on its values for the given keys
|
|
4036
|
+
* @param {*} item - the item to rank
|
|
4037
|
+
* @param {Array} keys - the keys to get values from the item for the ranking
|
|
4038
|
+
* @param {String} value - the value to rank against
|
|
4039
|
+
* @param {Object} options - options to control the ranking
|
|
4040
|
+
* @return {{rank: Number, keyIndex: Number, keyThreshold: Number}} - the highest ranking
|
|
4041
|
+
*/
|
|
4042
|
+
|
|
4043
|
+
|
|
4044
|
+
function getHighestRanking(item, keys, value, options) {
|
|
4045
|
+
if (!keys) {
|
|
4046
|
+
// if keys is not specified, then we assume the item given is ready to be matched
|
|
4047
|
+
var stringItem = item;
|
|
4048
|
+
return {
|
|
4049
|
+
// ends up being duplicate of 'item' in matches but consistent
|
|
4050
|
+
rankedValue: stringItem,
|
|
4051
|
+
rank: getMatchRanking(stringItem, value, options),
|
|
4052
|
+
keyIndex: -1,
|
|
4053
|
+
keyThreshold: options.threshold
|
|
4054
|
+
};
|
|
4055
|
+
}
|
|
4056
|
+
|
|
4057
|
+
var valuesToRank = getAllValuesToRank(item, keys);
|
|
4058
|
+
return valuesToRank.reduce(function (_ref2, _ref3, i) {
|
|
4059
|
+
var rank = _ref2.rank,
|
|
4060
|
+
rankedValue = _ref2.rankedValue,
|
|
4061
|
+
keyIndex = _ref2.keyIndex,
|
|
4062
|
+
keyThreshold = _ref2.keyThreshold;
|
|
4063
|
+
var itemValue = _ref3.itemValue,
|
|
4064
|
+
attributes = _ref3.attributes;
|
|
4065
|
+
var newRank = getMatchRanking(itemValue, value, options);
|
|
4066
|
+
var newRankedValue = rankedValue;
|
|
4067
|
+
var minRanking = attributes.minRanking,
|
|
4068
|
+
maxRanking = attributes.maxRanking,
|
|
4069
|
+
threshold = attributes.threshold;
|
|
4070
|
+
|
|
4071
|
+
if (newRank < minRanking && newRank >= rankings.MATCHES) {
|
|
4072
|
+
newRank = minRanking;
|
|
4073
|
+
} else if (newRank > maxRanking) {
|
|
4074
|
+
newRank = maxRanking;
|
|
4075
|
+
}
|
|
4076
|
+
|
|
4077
|
+
if (newRank > rank) {
|
|
4078
|
+
rank = newRank;
|
|
4079
|
+
keyIndex = i;
|
|
4080
|
+
keyThreshold = threshold;
|
|
4081
|
+
newRankedValue = itemValue;
|
|
4082
|
+
}
|
|
4083
|
+
|
|
4084
|
+
return {
|
|
4085
|
+
rankedValue: newRankedValue,
|
|
4086
|
+
rank: rank,
|
|
4087
|
+
keyIndex: keyIndex,
|
|
4088
|
+
keyThreshold: keyThreshold
|
|
4089
|
+
};
|
|
4090
|
+
}, {
|
|
4091
|
+
rankedValue: item,
|
|
4092
|
+
rank: rankings.NO_MATCH,
|
|
4093
|
+
keyIndex: -1,
|
|
4094
|
+
keyThreshold: options.threshold
|
|
4095
|
+
});
|
|
4096
|
+
}
|
|
4097
|
+
/**
|
|
4098
|
+
* Gives a rankings score based on how well the two strings match.
|
|
4099
|
+
* @param {String} testString - the string to test against
|
|
4100
|
+
* @param {String} stringToRank - the string to rank
|
|
4101
|
+
* @param {Object} options - options for the match (like keepDiacritics for comparison)
|
|
4102
|
+
* @returns {Number} the ranking for how well stringToRank matches testString
|
|
4103
|
+
*/
|
|
4104
|
+
|
|
4105
|
+
|
|
4106
|
+
function getMatchRanking(testString, stringToRank, options) {
|
|
4107
|
+
testString = prepareValueForComparison(testString, options);
|
|
4108
|
+
stringToRank = prepareValueForComparison(stringToRank, options); // too long
|
|
4109
|
+
|
|
4110
|
+
if (stringToRank.length > testString.length) {
|
|
4111
|
+
return rankings.NO_MATCH;
|
|
4112
|
+
} // case sensitive equals
|
|
4113
|
+
|
|
4114
|
+
|
|
4115
|
+
if (testString === stringToRank) {
|
|
4116
|
+
return rankings.CASE_SENSITIVE_EQUAL;
|
|
4117
|
+
} // Lower casing before further comparison
|
|
4118
|
+
|
|
4119
|
+
|
|
4120
|
+
testString = testString.toLowerCase();
|
|
4121
|
+
stringToRank = stringToRank.toLowerCase(); // case insensitive equals
|
|
4122
|
+
|
|
4123
|
+
if (testString === stringToRank) {
|
|
4124
|
+
return rankings.EQUAL;
|
|
4125
|
+
} // starts with
|
|
4126
|
+
|
|
4127
|
+
|
|
4128
|
+
if (testString.startsWith(stringToRank)) {
|
|
4129
|
+
return rankings.STARTS_WITH;
|
|
4130
|
+
} // word starts with
|
|
4131
|
+
|
|
4132
|
+
|
|
4133
|
+
if (testString.includes(" " + stringToRank)) {
|
|
4134
|
+
return rankings.WORD_STARTS_WITH;
|
|
4135
|
+
} // contains
|
|
4136
|
+
|
|
4137
|
+
|
|
4138
|
+
if (testString.includes(stringToRank)) {
|
|
4139
|
+
return rankings.CONTAINS;
|
|
4140
|
+
} else if (stringToRank.length === 1) {
|
|
4141
|
+
// If the only character in the given stringToRank
|
|
4142
|
+
// isn't even contained in the testString, then
|
|
4143
|
+
// it's definitely not a match.
|
|
4144
|
+
return rankings.NO_MATCH;
|
|
4145
|
+
} // acronym
|
|
4146
|
+
|
|
4147
|
+
|
|
4148
|
+
if (getAcronym(testString).includes(stringToRank)) {
|
|
4149
|
+
return rankings.ACRONYM;
|
|
4150
|
+
} // will return a number between rankings.MATCHES and
|
|
4151
|
+
// rankings.MATCHES + 1 depending on how close of a match it is.
|
|
4152
|
+
|
|
4153
|
+
|
|
4154
|
+
return getClosenessRanking(testString, stringToRank);
|
|
4155
|
+
}
|
|
4156
|
+
/**
|
|
4157
|
+
* Generates an acronym for a string.
|
|
4158
|
+
*
|
|
4159
|
+
* @param {String} string the string for which to produce the acronym
|
|
4160
|
+
* @returns {String} the acronym
|
|
4161
|
+
*/
|
|
4162
|
+
|
|
4163
|
+
|
|
4164
|
+
function getAcronym(string) {
|
|
4165
|
+
var acronym = '';
|
|
4166
|
+
var wordsInString = string.split(' ');
|
|
4167
|
+
wordsInString.forEach(function (wordInString) {
|
|
4168
|
+
var splitByHyphenWords = wordInString.split('-');
|
|
4169
|
+
splitByHyphenWords.forEach(function (splitByHyphenWord) {
|
|
4170
|
+
acronym += splitByHyphenWord.substr(0, 1);
|
|
4171
|
+
});
|
|
4172
|
+
});
|
|
4173
|
+
return acronym;
|
|
4174
|
+
}
|
|
4175
|
+
/**
|
|
4176
|
+
* Returns a score based on how spread apart the
|
|
4177
|
+
* characters from the stringToRank are within the testString.
|
|
4178
|
+
* A number close to rankings.MATCHES represents a loose match. A number close
|
|
4179
|
+
* to rankings.MATCHES + 1 represents a tighter match.
|
|
4180
|
+
* @param {String} testString - the string to test against
|
|
4181
|
+
* @param {String} stringToRank - the string to rank
|
|
4182
|
+
* @returns {Number} the number between rankings.MATCHES and
|
|
4183
|
+
* rankings.MATCHES + 1 for how well stringToRank matches testString
|
|
4184
|
+
*/
|
|
4185
|
+
|
|
4186
|
+
|
|
4187
|
+
function getClosenessRanking(testString, stringToRank) {
|
|
4188
|
+
var matchingInOrderCharCount = 0;
|
|
4189
|
+
var charNumber = 0;
|
|
4190
|
+
|
|
4191
|
+
function findMatchingCharacter(matchChar, string, index) {
|
|
4192
|
+
for (var j = index, J = string.length; j < J; j++) {
|
|
4193
|
+
var stringChar = string[j];
|
|
4194
|
+
|
|
4195
|
+
if (stringChar === matchChar) {
|
|
4196
|
+
matchingInOrderCharCount += 1;
|
|
4197
|
+
return j + 1;
|
|
4198
|
+
}
|
|
4199
|
+
}
|
|
4200
|
+
|
|
4201
|
+
return -1;
|
|
4202
|
+
}
|
|
4203
|
+
|
|
4204
|
+
function getRanking(spread) {
|
|
4205
|
+
var spreadPercentage = 1 / spread;
|
|
4206
|
+
var inOrderPercentage = matchingInOrderCharCount / stringToRank.length;
|
|
4207
|
+
var ranking = rankings.MATCHES + inOrderPercentage * spreadPercentage;
|
|
4208
|
+
return ranking;
|
|
4209
|
+
}
|
|
4210
|
+
|
|
4211
|
+
var firstIndex = findMatchingCharacter(stringToRank[0], testString, 0);
|
|
4212
|
+
|
|
4213
|
+
if (firstIndex < 0) {
|
|
4214
|
+
return rankings.NO_MATCH;
|
|
4215
|
+
}
|
|
4216
|
+
|
|
4217
|
+
charNumber = firstIndex;
|
|
4218
|
+
|
|
4219
|
+
for (var i = 1, I = stringToRank.length; i < I; i++) {
|
|
4220
|
+
var matchChar = stringToRank[i];
|
|
4221
|
+
charNumber = findMatchingCharacter(matchChar, testString, charNumber);
|
|
4222
|
+
var found = charNumber > -1;
|
|
4223
|
+
|
|
4224
|
+
if (!found) {
|
|
4225
|
+
return rankings.NO_MATCH;
|
|
4226
|
+
}
|
|
4227
|
+
}
|
|
4228
|
+
|
|
4229
|
+
var spread = charNumber - firstIndex;
|
|
4230
|
+
return getRanking(spread);
|
|
4231
|
+
}
|
|
4232
|
+
/**
|
|
4233
|
+
* Sorts items that have a rank, index, and keyIndex
|
|
4234
|
+
* @param {Object} a - the first item to sort
|
|
4235
|
+
* @param {Object} b - the second item to sort
|
|
4236
|
+
* @return {Number} -1 if a should come first, 1 if b should come first, 0 if equal
|
|
4237
|
+
*/
|
|
4238
|
+
|
|
4239
|
+
|
|
4240
|
+
function sortRankedValues(a, b, baseSort) {
|
|
4241
|
+
var aFirst = -1;
|
|
4242
|
+
var bFirst = 1;
|
|
4243
|
+
var aRank = a.rank,
|
|
4244
|
+
aKeyIndex = a.keyIndex;
|
|
4245
|
+
var bRank = b.rank,
|
|
4246
|
+
bKeyIndex = b.keyIndex;
|
|
4247
|
+
var same = aRank === bRank;
|
|
4248
|
+
|
|
4249
|
+
if (same) {
|
|
4250
|
+
if (aKeyIndex === bKeyIndex) {
|
|
4251
|
+
// use the base sort function as a tie-breaker
|
|
4252
|
+
return baseSort(a, b);
|
|
4253
|
+
} else {
|
|
4254
|
+
return aKeyIndex < bKeyIndex ? aFirst : bFirst;
|
|
4255
|
+
}
|
|
4256
|
+
} else {
|
|
4257
|
+
return aRank > bRank ? aFirst : bFirst;
|
|
4258
|
+
}
|
|
4259
|
+
}
|
|
4260
|
+
/**
|
|
4261
|
+
* Prepares value for comparison by stringifying it, removing diacritics (if specified)
|
|
4262
|
+
* @param {String} value - the value to clean
|
|
4263
|
+
* @param {Object} options - {keepDiacritics: whether to remove diacritics}
|
|
4264
|
+
* @return {String} the prepared value
|
|
4265
|
+
*/
|
|
4266
|
+
|
|
4267
|
+
|
|
4268
|
+
function prepareValueForComparison(value, _ref4) {
|
|
4269
|
+
var keepDiacritics = _ref4.keepDiacritics;
|
|
4270
|
+
// value might not actually be a string at this point (we don't get to choose)
|
|
4271
|
+
// so part of preparing the value for comparison is ensure that it is a string
|
|
4272
|
+
value = "" + value; // toString
|
|
4273
|
+
|
|
4274
|
+
if (!keepDiacritics) {
|
|
4275
|
+
value = removeAccents$1.exports(value);
|
|
4276
|
+
}
|
|
4277
|
+
|
|
4278
|
+
return value;
|
|
4279
|
+
}
|
|
4280
|
+
/**
|
|
4281
|
+
* Gets value for key in item at arbitrarily nested keypath
|
|
4282
|
+
* @param {Object} item - the item
|
|
4283
|
+
* @param {Object|Function} key - the potentially nested keypath or property callback
|
|
4284
|
+
* @return {Array} - an array containing the value(s) at the nested keypath
|
|
4285
|
+
*/
|
|
4286
|
+
|
|
4287
|
+
|
|
4288
|
+
function getItemValues(item, key) {
|
|
4289
|
+
if (typeof key === 'object') {
|
|
4290
|
+
key = key.key;
|
|
4291
|
+
}
|
|
4292
|
+
|
|
4293
|
+
var value;
|
|
4294
|
+
|
|
4295
|
+
if (typeof key === 'function') {
|
|
4296
|
+
value = key(item);
|
|
4297
|
+
} else if (item == null) {
|
|
4298
|
+
value = null;
|
|
4299
|
+
} else if (Object.hasOwnProperty.call(item, key)) {
|
|
4300
|
+
value = item[key];
|
|
4301
|
+
} else if (key.includes('.')) {
|
|
4302
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
4303
|
+
return getNestedValues(key, item);
|
|
4304
|
+
} else {
|
|
4305
|
+
value = null;
|
|
4306
|
+
} // because `value` can also be undefined
|
|
4307
|
+
|
|
4308
|
+
|
|
4309
|
+
if (value == null) {
|
|
4310
|
+
return [];
|
|
4311
|
+
}
|
|
4312
|
+
|
|
4313
|
+
if (Array.isArray(value)) {
|
|
4314
|
+
return value;
|
|
4315
|
+
}
|
|
4316
|
+
|
|
4317
|
+
return [String(value)];
|
|
4318
|
+
}
|
|
4319
|
+
/**
|
|
4320
|
+
* Given path: "foo.bar.baz"
|
|
4321
|
+
* And item: {foo: {bar: {baz: 'buzz'}}}
|
|
4322
|
+
* -> 'buzz'
|
|
4323
|
+
* @param path a dot-separated set of keys
|
|
4324
|
+
* @param item the item to get the value from
|
|
4325
|
+
*/
|
|
4326
|
+
|
|
4327
|
+
|
|
4328
|
+
function getNestedValues(path, item) {
|
|
4329
|
+
var keys = path.split('.');
|
|
4330
|
+
var values = [item];
|
|
4331
|
+
|
|
4332
|
+
for (var i = 0, I = keys.length; i < I; i++) {
|
|
4333
|
+
var nestedKey = keys[i];
|
|
4334
|
+
var nestedValues = [];
|
|
4335
|
+
|
|
4336
|
+
for (var j = 0, J = values.length; j < J; j++) {
|
|
4337
|
+
var nestedItem = values[j];
|
|
4338
|
+
if (nestedItem == null) continue;
|
|
4339
|
+
|
|
4340
|
+
if (Object.hasOwnProperty.call(nestedItem, nestedKey)) {
|
|
4341
|
+
var nestedValue = nestedItem[nestedKey];
|
|
4342
|
+
|
|
4343
|
+
if (nestedValue != null) {
|
|
4344
|
+
nestedValues.push(nestedValue);
|
|
4345
|
+
}
|
|
4346
|
+
} else if (nestedKey === '*') {
|
|
4347
|
+
// ensure that values is an array
|
|
4348
|
+
nestedValues = nestedValues.concat(nestedItem);
|
|
4349
|
+
}
|
|
4350
|
+
}
|
|
4351
|
+
|
|
4352
|
+
values = nestedValues;
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4355
|
+
if (Array.isArray(values[0])) {
|
|
4356
|
+
// keep allowing the implicit wildcard for an array of strings at the end of
|
|
4357
|
+
// the path; don't use `.flat()` because that's not available in node.js v10
|
|
4358
|
+
var result = [];
|
|
4359
|
+
return result.concat.apply(result, values);
|
|
4360
|
+
} // Based on our logic it should be an array of strings by now...
|
|
4361
|
+
// assuming the user's path terminated in strings
|
|
4362
|
+
|
|
4363
|
+
|
|
4364
|
+
return values;
|
|
4365
|
+
}
|
|
4366
|
+
/**
|
|
4367
|
+
* Gets all the values for the given keys in the given item and returns an array of those values
|
|
4368
|
+
* @param item - the item from which the values will be retrieved
|
|
4369
|
+
* @param keys - the keys to use to retrieve the values
|
|
4370
|
+
* @return objects with {itemValue, attributes}
|
|
4371
|
+
*/
|
|
4372
|
+
|
|
4373
|
+
|
|
4374
|
+
function getAllValuesToRank(item, keys) {
|
|
4375
|
+
var allValues = [];
|
|
4376
|
+
|
|
4377
|
+
for (var j = 0, J = keys.length; j < J; j++) {
|
|
4378
|
+
var key = keys[j];
|
|
4379
|
+
var attributes = getKeyAttributes(key);
|
|
4380
|
+
var itemValues = getItemValues(item, key);
|
|
4381
|
+
|
|
4382
|
+
for (var i = 0, I = itemValues.length; i < I; i++) {
|
|
4383
|
+
allValues.push({
|
|
4384
|
+
itemValue: itemValues[i],
|
|
4385
|
+
attributes: attributes
|
|
4386
|
+
});
|
|
4387
|
+
}
|
|
4388
|
+
}
|
|
4389
|
+
|
|
4390
|
+
return allValues;
|
|
4391
|
+
}
|
|
4392
|
+
|
|
4393
|
+
var defaultKeyAttributes = {
|
|
4394
|
+
maxRanking: Infinity,
|
|
4395
|
+
minRanking: -Infinity
|
|
4396
|
+
};
|
|
4397
|
+
/**
|
|
4398
|
+
* Gets all the attributes for the given key
|
|
4399
|
+
* @param key - the key from which the attributes will be retrieved
|
|
4400
|
+
* @return object containing the key's attributes
|
|
4401
|
+
*/
|
|
4402
|
+
|
|
4403
|
+
function getKeyAttributes(key) {
|
|
4404
|
+
if (typeof key === 'string') {
|
|
4405
|
+
return defaultKeyAttributes;
|
|
4406
|
+
}
|
|
4407
|
+
|
|
4408
|
+
return _extends({}, defaultKeyAttributes, key);
|
|
4409
|
+
}
|
|
4410
|
+
|
|
4411
|
+
/* istanbul ignore file */
|
|
4412
|
+
// eslint-disable-next-line no-shadow
|
|
4413
|
+
var QueryState;
|
|
4414
|
+
|
|
4415
|
+
(function (QueryState) {
|
|
4416
|
+
QueryState[QueryState["Fetching"] = 0] = "Fetching";
|
|
4417
|
+
QueryState[QueryState["Fresh"] = 1] = "Fresh";
|
|
4418
|
+
QueryState[QueryState["Stale"] = 2] = "Stale";
|
|
4419
|
+
QueryState[QueryState["Inactive"] = 3] = "Inactive";
|
|
4420
|
+
QueryState[QueryState["Paused"] = 4] = "Paused";
|
|
4421
|
+
})(QueryState || (QueryState = {}));
|
|
4422
|
+
|
|
4423
|
+
function getQueryState(query) {
|
|
4424
|
+
if (query.state.fetchStatus === 'fetching') {
|
|
4425
|
+
return QueryState.Fetching;
|
|
4426
|
+
}
|
|
4427
|
+
|
|
4428
|
+
if (query.state.fetchStatus === 'paused') {
|
|
4429
|
+
return QueryState.Paused;
|
|
4430
|
+
}
|
|
4431
|
+
|
|
4432
|
+
if (!query.getObserversCount()) {
|
|
4433
|
+
return QueryState.Inactive;
|
|
4434
|
+
}
|
|
4435
|
+
|
|
4436
|
+
if (query.isStale()) {
|
|
4437
|
+
return QueryState.Stale;
|
|
4438
|
+
}
|
|
4439
|
+
|
|
4440
|
+
return QueryState.Fresh;
|
|
4441
|
+
}
|
|
4442
|
+
function getQueryStateLabel(query) {
|
|
4443
|
+
const queryState = getQueryState(query);
|
|
4444
|
+
|
|
4445
|
+
if (queryState === QueryState.Fetching) {
|
|
4446
|
+
return 'fetching';
|
|
4447
|
+
}
|
|
4448
|
+
|
|
4449
|
+
if (queryState === QueryState.Paused) {
|
|
4450
|
+
return 'paused';
|
|
4451
|
+
}
|
|
4452
|
+
|
|
4453
|
+
if (queryState === QueryState.Stale) {
|
|
4454
|
+
return 'stale';
|
|
4455
|
+
}
|
|
4456
|
+
|
|
4457
|
+
if (queryState === QueryState.Inactive) {
|
|
4458
|
+
return 'inactive';
|
|
4459
|
+
}
|
|
4460
|
+
|
|
4461
|
+
return 'fresh';
|
|
4462
|
+
}
|
|
4463
|
+
function getQueryStatusFg(query) {
|
|
4464
|
+
const queryState = getQueryState(query);
|
|
4465
|
+
|
|
4466
|
+
if (queryState === QueryState.Stale) {
|
|
4467
|
+
return 0x000000;
|
|
4468
|
+
}
|
|
4469
|
+
|
|
4470
|
+
return 0xffffff;
|
|
4471
|
+
}
|
|
4472
|
+
function getQueryStatusBg(query) {
|
|
4473
|
+
const queryState = getQueryState(query);
|
|
4474
|
+
|
|
4475
|
+
if (queryState === QueryState.Fetching) {
|
|
4476
|
+
return 0x006bff;
|
|
4477
|
+
}
|
|
4478
|
+
|
|
4479
|
+
if (queryState === QueryState.Paused) {
|
|
4480
|
+
return 0x8c49eb;
|
|
4481
|
+
}
|
|
4482
|
+
|
|
4483
|
+
if (queryState === QueryState.Stale) {
|
|
4484
|
+
return 0xffb200;
|
|
4485
|
+
}
|
|
4486
|
+
|
|
4487
|
+
if (queryState === QueryState.Inactive) {
|
|
4488
|
+
return 0x3f4e60;
|
|
4489
|
+
}
|
|
4490
|
+
|
|
4491
|
+
return 0x008327;
|
|
4492
|
+
}
|
|
4493
|
+
|
|
4494
|
+
const queryHashSort = (a, b) => String(a.queryHash).localeCompare(b.queryHash);
|
|
4495
|
+
|
|
4496
|
+
const dateSort = (a, b) => a.state.dataUpdatedAt < b.state.dataUpdatedAt ? 1 : -1;
|
|
4497
|
+
|
|
4498
|
+
const statusAndDateSort = (a, b) => {
|
|
4499
|
+
if (getQueryState(a) === getQueryState(b)) {
|
|
4500
|
+
return dateSort(a, b);
|
|
4501
|
+
}
|
|
4502
|
+
|
|
4503
|
+
return getQueryState(a) > getQueryState(b) ? 1 : -1;
|
|
4504
|
+
};
|
|
4505
|
+
|
|
4506
|
+
const sortFns = {
|
|
4507
|
+
'Status > Last Updated': statusAndDateSort,
|
|
4508
|
+
'Query Hash': queryHashSort,
|
|
4509
|
+
'Last Updated': dateSort
|
|
4510
|
+
};
|
|
4511
|
+
|
|
4512
|
+
/* istanbul ignore file */
|
|
4513
|
+
const pluginId = 'vue-query';
|
|
4514
|
+
const pluginName = 'Vue Query';
|
|
4515
|
+
function setupDevtools(app, queryClient) {
|
|
4516
|
+
setupDevtoolsPlugin({
|
|
4517
|
+
id: pluginId,
|
|
4518
|
+
label: pluginName,
|
|
4519
|
+
packageName: 'vue-query',
|
|
4520
|
+
homepage: 'https://github.com/DamianOsipiuk/vue-query',
|
|
4521
|
+
logo: 'https://vue-query.vercel.app/vue-query.svg',
|
|
4522
|
+
app,
|
|
4523
|
+
settings: {
|
|
4524
|
+
baseSort: {
|
|
4525
|
+
type: 'choice',
|
|
4526
|
+
component: 'button-group',
|
|
4527
|
+
label: 'Sort Cache Entries',
|
|
4528
|
+
options: [{
|
|
4529
|
+
label: 'ASC',
|
|
4530
|
+
value: 1
|
|
4531
|
+
}, {
|
|
4532
|
+
label: 'DESC',
|
|
4533
|
+
value: -1
|
|
4534
|
+
}],
|
|
4535
|
+
defaultValue: 1
|
|
4536
|
+
},
|
|
4537
|
+
sortFn: {
|
|
4538
|
+
type: 'choice',
|
|
4539
|
+
label: 'Sort Function',
|
|
4540
|
+
options: Object.keys(sortFns).map(key => ({
|
|
4541
|
+
label: key,
|
|
4542
|
+
value: key
|
|
4543
|
+
})),
|
|
4544
|
+
defaultValue: Object.keys(sortFns)[0]
|
|
4545
|
+
}
|
|
4546
|
+
}
|
|
4547
|
+
}, api => {
|
|
4548
|
+
const queryCache = queryClient.getQueryCache();
|
|
4549
|
+
api.addInspector({
|
|
4550
|
+
id: pluginId,
|
|
4551
|
+
label: pluginName,
|
|
4552
|
+
icon: 'api',
|
|
4553
|
+
nodeActions: [{
|
|
4554
|
+
icon: 'cloud_download',
|
|
4555
|
+
tooltip: 'Refetch',
|
|
4556
|
+
action: queryHash => {
|
|
4557
|
+
var _queryCache$get;
|
|
4558
|
+
|
|
4559
|
+
(_queryCache$get = queryCache.get(queryHash)) == null ? void 0 : _queryCache$get.fetch();
|
|
4560
|
+
}
|
|
4561
|
+
}, {
|
|
4562
|
+
icon: 'alarm',
|
|
4563
|
+
tooltip: 'Invalidate',
|
|
4564
|
+
action: queryHash => {
|
|
4565
|
+
const query = queryCache.get(queryHash);
|
|
4566
|
+
queryClient.invalidateQueries(query.queryKey);
|
|
4567
|
+
}
|
|
4568
|
+
}, {
|
|
4569
|
+
icon: 'settings_backup_restore',
|
|
4570
|
+
tooltip: 'Reset',
|
|
4571
|
+
action: queryHash => {
|
|
4572
|
+
var _queryCache$get2;
|
|
4573
|
+
|
|
4574
|
+
(_queryCache$get2 = queryCache.get(queryHash)) == null ? void 0 : _queryCache$get2.reset();
|
|
4575
|
+
}
|
|
4576
|
+
}, {
|
|
4577
|
+
icon: 'delete',
|
|
4578
|
+
tooltip: 'Remove',
|
|
4579
|
+
action: queryHash => {
|
|
4580
|
+
const query = queryCache.get(queryHash);
|
|
4581
|
+
queryCache.remove(query);
|
|
4582
|
+
}
|
|
4583
|
+
}]
|
|
4584
|
+
});
|
|
4585
|
+
api.addTimelineLayer({
|
|
4586
|
+
id: pluginId,
|
|
4587
|
+
label: pluginName,
|
|
4588
|
+
color: 0xffd94c
|
|
4589
|
+
});
|
|
4590
|
+
queryCache.subscribe(event => {
|
|
4591
|
+
api.sendInspectorTree(pluginId);
|
|
4592
|
+
api.sendInspectorState(pluginId);
|
|
4593
|
+
|
|
4594
|
+
if ( // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
4595
|
+
event && ['queryAdded', 'queryRemoved', 'queryUpdated'].includes(event.type)) {
|
|
4596
|
+
api.addTimelineEvent({
|
|
4597
|
+
layerId: pluginId,
|
|
4598
|
+
event: {
|
|
4599
|
+
title: event.type,
|
|
4600
|
+
subtitle: event.query.queryHash,
|
|
4601
|
+
time: api.now(),
|
|
4602
|
+
data: {
|
|
4603
|
+
queryHash: event.query.queryHash,
|
|
4604
|
+
...event
|
|
4605
|
+
}
|
|
4606
|
+
}
|
|
4607
|
+
});
|
|
4608
|
+
}
|
|
4609
|
+
});
|
|
4610
|
+
api.on.getInspectorTree(payload => {
|
|
4611
|
+
if (payload.inspectorId === pluginId) {
|
|
4612
|
+
const queries = queryCache.getAll();
|
|
4613
|
+
const settings = api.getSettings();
|
|
4614
|
+
const filtered = matchSorter(queries, payload.filter, {
|
|
4615
|
+
keys: ['queryHash'],
|
|
4616
|
+
baseSort: (a, b) => sortFns[settings.sortFn](a.item, b.item) * settings.baseSort
|
|
4617
|
+
});
|
|
4618
|
+
const nodes = filtered.map(query => {
|
|
4619
|
+
const stateLabel = getQueryStateLabel(query);
|
|
4620
|
+
return {
|
|
4621
|
+
id: query.queryHash,
|
|
4622
|
+
label: query.queryHash,
|
|
4623
|
+
tags: [{
|
|
4624
|
+
label: stateLabel + " [" + query.getObserversCount() + "]",
|
|
4625
|
+
textColor: getQueryStatusFg(query),
|
|
4626
|
+
backgroundColor: getQueryStatusBg(query)
|
|
4627
|
+
}]
|
|
4628
|
+
};
|
|
4629
|
+
});
|
|
4630
|
+
payload.rootNodes = nodes;
|
|
4631
|
+
}
|
|
4632
|
+
});
|
|
4633
|
+
api.on.getInspectorState(payload => {
|
|
4634
|
+
if (payload.inspectorId === pluginId) {
|
|
4635
|
+
const query = queryCache.get(payload.nodeId);
|
|
4636
|
+
|
|
4637
|
+
if (!query) {
|
|
4638
|
+
return;
|
|
4639
|
+
}
|
|
4640
|
+
|
|
4641
|
+
payload.state = {
|
|
4642
|
+
' Query Details': [{
|
|
4643
|
+
key: 'Query key',
|
|
4644
|
+
value: query.queryHash
|
|
4645
|
+
}, {
|
|
4646
|
+
key: 'Query status',
|
|
4647
|
+
value: getQueryStateLabel(query)
|
|
4648
|
+
}, {
|
|
4649
|
+
key: 'Observers',
|
|
4650
|
+
value: query.getObserversCount()
|
|
4651
|
+
}, {
|
|
4652
|
+
key: 'Last Updated',
|
|
4653
|
+
value: new Date(query.state.dataUpdatedAt).toLocaleTimeString()
|
|
4654
|
+
}],
|
|
4655
|
+
'Data Explorer': [{
|
|
4656
|
+
key: 'Data',
|
|
4657
|
+
value: query.state.data
|
|
4658
|
+
}],
|
|
4659
|
+
'Query Explorer': [{
|
|
4660
|
+
key: 'Query',
|
|
4661
|
+
value: query
|
|
4662
|
+
}]
|
|
4663
|
+
};
|
|
4664
|
+
}
|
|
4665
|
+
});
|
|
4666
|
+
});
|
|
4667
|
+
}
|
|
4668
|
+
|
|
4669
|
+
const VueQueryPlugin = {
|
|
4670
|
+
install: (app, options = {}) => {
|
|
4671
|
+
const clientKey = getClientKey(options.queryClientKey);
|
|
4672
|
+
let client;
|
|
4673
|
+
|
|
4674
|
+
if ('queryClient' in options && options.queryClient) {
|
|
4675
|
+
client = options.queryClient;
|
|
4676
|
+
} else {
|
|
4677
|
+
if (options.contextSharing && typeof window !== 'undefined') {
|
|
4678
|
+
if (!window.__VUE_QUERY_CONTEXT__) {
|
|
4679
|
+
const clientConfig = 'queryClientConfig' in options ? options.queryClientConfig : undefined;
|
|
4680
|
+
client = new QueryClient(clientConfig);
|
|
4681
|
+
window.__VUE_QUERY_CONTEXT__ = client;
|
|
4682
|
+
} else {
|
|
4683
|
+
client = window.__VUE_QUERY_CONTEXT__;
|
|
4684
|
+
}
|
|
4685
|
+
} else {
|
|
4686
|
+
const clientConfig = 'queryClientConfig' in options ? options.queryClientConfig : undefined;
|
|
4687
|
+
client = new QueryClient(clientConfig);
|
|
4688
|
+
}
|
|
4689
|
+
}
|
|
4690
|
+
|
|
4691
|
+
client.mount();
|
|
4692
|
+
|
|
4693
|
+
const cleanup = () => {
|
|
4694
|
+
client.unmount();
|
|
4695
|
+
};
|
|
4696
|
+
|
|
4697
|
+
if (app.onUnmount) {
|
|
4698
|
+
app.onUnmount(cleanup);
|
|
4699
|
+
} else {
|
|
4700
|
+
const originalUnmount = app.unmount;
|
|
4701
|
+
|
|
4702
|
+
app.unmount = function vueQueryUnmount() {
|
|
4703
|
+
cleanup();
|
|
4704
|
+
originalUnmount();
|
|
4705
|
+
};
|
|
4706
|
+
}
|
|
4707
|
+
/* istanbul ignore next */
|
|
4708
|
+
|
|
4709
|
+
|
|
4710
|
+
if (vueDemi.isVue2) {
|
|
4711
|
+
app.mixin({
|
|
4712
|
+
beforeCreate() {
|
|
4713
|
+
// HACK: taken from provide(): https://github.com/vuejs/composition-api/blob/master/src/apis/inject.ts#L30
|
|
4714
|
+
if (!this._provided) {
|
|
4715
|
+
const provideCache = {};
|
|
4716
|
+
Object.defineProperty(this, '_provided', {
|
|
4717
|
+
get: () => provideCache,
|
|
4718
|
+
set: v => Object.assign(provideCache, v)
|
|
4719
|
+
});
|
|
4720
|
+
}
|
|
4721
|
+
|
|
4722
|
+
this._provided[clientKey] = client;
|
|
4723
|
+
|
|
4724
|
+
{
|
|
4725
|
+
if (this === this.$root) {
|
|
4726
|
+
setupDevtools(this, client);
|
|
4727
|
+
}
|
|
4728
|
+
}
|
|
4729
|
+
}
|
|
4730
|
+
|
|
4731
|
+
});
|
|
4732
|
+
} else {
|
|
4733
|
+
app.provide(clientKey, client);
|
|
4734
|
+
|
|
4735
|
+
{
|
|
4736
|
+
setupDevtools(app, client);
|
|
4737
|
+
}
|
|
4738
|
+
}
|
|
4739
|
+
}
|
|
4740
|
+
};
|
|
4741
|
+
|
|
4742
|
+
function useBaseQuery(Observer, arg1, arg2 = {}, arg3 = {}) {
|
|
4743
|
+
var _options$queryClient;
|
|
4744
|
+
|
|
4745
|
+
const options = getQueryUnreffedOptions();
|
|
4746
|
+
const queryClient = (_options$queryClient = options.queryClient) != null ? _options$queryClient : useQueryClient(options.queryClientKey);
|
|
4747
|
+
const defaultedOptions = queryClient.defaultQueryOptions(options);
|
|
4748
|
+
const observer = new Observer(queryClient, defaultedOptions);
|
|
4749
|
+
const state = vueDemi.reactive(observer.getCurrentResult());
|
|
4750
|
+
const unsubscribe = observer.subscribe(result => {
|
|
4751
|
+
updateState(state, result);
|
|
4752
|
+
});
|
|
4753
|
+
vueDemi.watch([() => arg1, () => arg2, () => arg3], () => {
|
|
4754
|
+
observer.setOptions(queryClient.defaultQueryOptions(getQueryUnreffedOptions()));
|
|
4755
|
+
}, {
|
|
4756
|
+
deep: true
|
|
4757
|
+
});
|
|
4758
|
+
vueDemi.onScopeDispose(() => {
|
|
4759
|
+
unsubscribe();
|
|
4760
|
+
});
|
|
4761
|
+
|
|
4762
|
+
const suspense = () => {
|
|
4763
|
+
return new Promise(resolve => {
|
|
4764
|
+
const run = () => {
|
|
4765
|
+
const newOptions = queryClient.defaultQueryOptions(getQueryUnreffedOptions());
|
|
4766
|
+
|
|
4767
|
+
if (newOptions.enabled !== false) {
|
|
4768
|
+
const optimisticResult = observer.getOptimisticResult(newOptions);
|
|
4769
|
+
|
|
4770
|
+
if (optimisticResult.isStale) {
|
|
4771
|
+
resolve(observer.fetchOptimistic(defaultedOptions));
|
|
4772
|
+
} else {
|
|
4773
|
+
resolve(optimisticResult);
|
|
4774
|
+
}
|
|
4775
|
+
}
|
|
4776
|
+
};
|
|
4777
|
+
|
|
4778
|
+
run();
|
|
4779
|
+
vueDemi.watch([() => arg1, () => arg2, () => arg3], run, {
|
|
4780
|
+
deep: true
|
|
4781
|
+
});
|
|
4782
|
+
});
|
|
4783
|
+
};
|
|
4784
|
+
|
|
4785
|
+
return { ...vueDemi.toRefs(vueDemi.readonly(state)),
|
|
4786
|
+
suspense
|
|
4787
|
+
};
|
|
4788
|
+
/**
|
|
4789
|
+
* Get Query Options object
|
|
4790
|
+
* All inner refs unwrapped. No Reactivity
|
|
4791
|
+
*/
|
|
4792
|
+
|
|
4793
|
+
function getQueryUnreffedOptions() {
|
|
4794
|
+
let mergedOptions;
|
|
4795
|
+
|
|
4796
|
+
if (!isQueryKey(arg1)) {
|
|
4797
|
+
// `useQuery(optionsObj)`
|
|
4798
|
+
mergedOptions = arg1;
|
|
4799
|
+
} else if (typeof arg2 === 'function') {
|
|
4800
|
+
// `useQuery(queryKey, queryFn, optionsObj?)`
|
|
4801
|
+
mergedOptions = { ...arg3,
|
|
4802
|
+
queryKey: arg1,
|
|
4803
|
+
queryFn: arg2
|
|
4804
|
+
};
|
|
4805
|
+
} else {
|
|
4806
|
+
// `useQuery(queryKey, optionsObj?)`
|
|
4807
|
+
mergedOptions = { ...arg2,
|
|
4808
|
+
queryKey: arg1
|
|
4809
|
+
};
|
|
4810
|
+
}
|
|
4811
|
+
|
|
4812
|
+
return cloneDeepUnref(mergedOptions);
|
|
4813
|
+
}
|
|
4814
|
+
}
|
|
4815
|
+
|
|
4816
|
+
function useQuery(arg1, arg2, arg3) {
|
|
4817
|
+
const result = useBaseQuery(QueryObserver, arg1, arg2, arg3);
|
|
4818
|
+
return { ...result,
|
|
4819
|
+
refetch: result.refetch.value,
|
|
4820
|
+
remove: result.remove.value
|
|
4821
|
+
};
|
|
4822
|
+
}
|
|
4823
|
+
|
|
4824
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
4825
|
+
|
|
4826
|
+
function useQueries({
|
|
4827
|
+
queries
|
|
4828
|
+
}) {
|
|
4829
|
+
const unreffedQueries = cloneDeepUnref(queries);
|
|
4830
|
+
const queryClientKey = unreffedQueries[0].queryClientKey;
|
|
4831
|
+
const optionsQueryClient = unreffedQueries[0].queryClient;
|
|
4832
|
+
const queryClient = optionsQueryClient != null ? optionsQueryClient : useQueryClient(queryClientKey);
|
|
4833
|
+
const defaultedQueries = unreffedQueries.map(options => {
|
|
4834
|
+
return queryClient.defaultQueryOptions(options);
|
|
4835
|
+
});
|
|
4836
|
+
const observer = new QueriesObserver(queryClient, defaultedQueries);
|
|
4837
|
+
const state = vueDemi.reactive(observer.getCurrentResult());
|
|
4838
|
+
const unsubscribe = observer.subscribe(result => {
|
|
4839
|
+
state.splice(0, state.length, ...result);
|
|
4840
|
+
});
|
|
4841
|
+
vueDemi.watch(() => queries, () => {
|
|
4842
|
+
const defaulted = cloneDeepUnref(queries).map(options => {
|
|
4843
|
+
return queryClient.defaultQueryOptions(options);
|
|
4844
|
+
});
|
|
4845
|
+
observer.setQueries(defaulted);
|
|
4846
|
+
}, {
|
|
4847
|
+
deep: true
|
|
4848
|
+
});
|
|
4849
|
+
vueDemi.onScopeDispose(() => {
|
|
4850
|
+
unsubscribe();
|
|
4851
|
+
});
|
|
4852
|
+
return vueDemi.readonly(state);
|
|
4853
|
+
}
|
|
4854
|
+
|
|
4855
|
+
function useInfiniteQuery(arg1, arg2, arg3) {
|
|
4856
|
+
const result = useBaseQuery(InfiniteQueryObserver, arg1, arg2, arg3);
|
|
4857
|
+
return { ...result,
|
|
4858
|
+
fetchNextPage: result.fetchNextPage.value,
|
|
4859
|
+
fetchPreviousPage: result.fetchPreviousPage.value,
|
|
4860
|
+
refetch: result.refetch.value,
|
|
4861
|
+
remove: result.remove.value
|
|
4862
|
+
};
|
|
4863
|
+
}
|
|
4864
|
+
|
|
4865
|
+
function useMutation(arg1, arg2, arg3) {
|
|
4866
|
+
var _options$queryClient;
|
|
4867
|
+
|
|
4868
|
+
const options = parseMutationArgs(arg1, arg2, arg3);
|
|
4869
|
+
const queryClient = (_options$queryClient = options.queryClient) != null ? _options$queryClient : useQueryClient(options.queryClientKey);
|
|
4870
|
+
const defaultedOptions = queryClient.defaultMutationOptions(options);
|
|
4871
|
+
const observer = new MutationObserver(queryClient, defaultedOptions);
|
|
4872
|
+
const state = vueDemi.reactive(observer.getCurrentResult());
|
|
4873
|
+
const unsubscribe = observer.subscribe(result => {
|
|
4874
|
+
updateState(state, result);
|
|
4875
|
+
});
|
|
4876
|
+
|
|
4877
|
+
const mutate = (variables, mutateOptions) => {
|
|
4878
|
+
observer.mutate(variables, mutateOptions).catch(() => {// This is intentional
|
|
4879
|
+
});
|
|
4880
|
+
};
|
|
4881
|
+
|
|
4882
|
+
vueDemi.watch([() => arg1, () => arg2, () => arg3], () => {
|
|
4883
|
+
observer.setOptions(queryClient.defaultMutationOptions(parseMutationArgs(arg1, arg2, arg3)));
|
|
4884
|
+
}, {
|
|
4885
|
+
deep: true
|
|
4886
|
+
});
|
|
4887
|
+
vueDemi.onScopeDispose(() => {
|
|
4888
|
+
unsubscribe();
|
|
4889
|
+
});
|
|
4890
|
+
const resultRefs = vueDemi.toRefs(vueDemi.readonly(state));
|
|
4891
|
+
return { ...resultRefs,
|
|
4892
|
+
mutate,
|
|
4893
|
+
mutateAsync: state.mutate,
|
|
4894
|
+
reset: state.reset
|
|
4895
|
+
};
|
|
4896
|
+
}
|
|
4897
|
+
function parseMutationArgs(arg1, arg2, arg3) {
|
|
4898
|
+
let options = arg1;
|
|
4899
|
+
|
|
4900
|
+
if (isQueryKey(arg1)) {
|
|
4901
|
+
if (typeof arg2 === 'function') {
|
|
4902
|
+
options = { ...arg3,
|
|
4903
|
+
mutationKey: arg1,
|
|
4904
|
+
mutationFn: arg2
|
|
4905
|
+
};
|
|
4906
|
+
} else {
|
|
4907
|
+
options = { ...arg2,
|
|
4908
|
+
mutationKey: arg1
|
|
4909
|
+
};
|
|
4910
|
+
}
|
|
4911
|
+
}
|
|
4912
|
+
|
|
4913
|
+
if (typeof arg1 === 'function') {
|
|
4914
|
+
options = { ...arg2,
|
|
4915
|
+
mutationFn: arg1
|
|
4916
|
+
};
|
|
4917
|
+
}
|
|
4918
|
+
|
|
4919
|
+
return cloneDeepUnref(options);
|
|
4920
|
+
}
|
|
4921
|
+
|
|
4922
|
+
function useIsFetching(arg1, arg2) {
|
|
4923
|
+
var _filters$value$queryC;
|
|
4924
|
+
|
|
4925
|
+
const filters = vueDemi.ref(parseFilterArgs(arg1, arg2));
|
|
4926
|
+
const queryClient = (_filters$value$queryC = filters.value.queryClient) != null ? _filters$value$queryC : useQueryClient(filters.value.queryClientKey);
|
|
4927
|
+
const isFetching = vueDemi.ref(queryClient.isFetching(filters));
|
|
4928
|
+
const unsubscribe = queryClient.getQueryCache().subscribe(() => {
|
|
4929
|
+
isFetching.value = queryClient.isFetching(filters);
|
|
4930
|
+
});
|
|
4931
|
+
vueDemi.watch([() => arg1, () => arg2], () => {
|
|
4932
|
+
filters.value = parseFilterArgs(arg1, arg2);
|
|
4933
|
+
isFetching.value = queryClient.isFetching(filters);
|
|
4934
|
+
}, {
|
|
4935
|
+
deep: true
|
|
4936
|
+
});
|
|
4937
|
+
vueDemi.onScopeDispose(() => {
|
|
4938
|
+
unsubscribe();
|
|
4939
|
+
});
|
|
4940
|
+
return isFetching;
|
|
4941
|
+
}
|
|
4942
|
+
function parseFilterArgs(arg1, arg2 = {}) {
|
|
4943
|
+
let options;
|
|
4944
|
+
|
|
4945
|
+
if (isQueryKey(arg1)) {
|
|
4946
|
+
options = { ...arg2,
|
|
4947
|
+
queryKey: arg1
|
|
4948
|
+
};
|
|
4949
|
+
} else {
|
|
4950
|
+
options = arg1 || {};
|
|
4951
|
+
}
|
|
4952
|
+
|
|
4953
|
+
return cloneDeepUnref(options);
|
|
4954
|
+
}
|
|
4955
|
+
|
|
4956
|
+
function useIsMutating(arg1, arg2) {
|
|
4957
|
+
var _filters$value$queryC;
|
|
4958
|
+
|
|
4959
|
+
const filters = vueDemi.ref(parseMutationFilterArgs(arg1, arg2));
|
|
4960
|
+
const queryClient = (_filters$value$queryC = filters.value.queryClient) != null ? _filters$value$queryC : useQueryClient(filters.value.queryClientKey);
|
|
4961
|
+
const isMutating = vueDemi.ref(queryClient.isMutating(filters));
|
|
4962
|
+
const unsubscribe = queryClient.getMutationCache().subscribe(() => {
|
|
4963
|
+
isMutating.value = queryClient.isMutating(filters);
|
|
4964
|
+
});
|
|
4965
|
+
vueDemi.watch([() => arg1, () => arg2], () => {
|
|
4966
|
+
filters.value = parseMutationFilterArgs(arg1, arg2);
|
|
4967
|
+
isMutating.value = queryClient.isMutating(filters);
|
|
4968
|
+
}, {
|
|
4969
|
+
deep: true
|
|
4970
|
+
});
|
|
4971
|
+
vueDemi.onScopeDispose(() => {
|
|
4972
|
+
unsubscribe();
|
|
4973
|
+
});
|
|
4974
|
+
return isMutating;
|
|
4975
|
+
}
|
|
4976
|
+
function parseMutationFilterArgs(arg1, arg2 = {}) {
|
|
4977
|
+
let options;
|
|
4978
|
+
|
|
4979
|
+
if (isQueryKey(arg1)) {
|
|
4980
|
+
options = { ...arg2,
|
|
4981
|
+
mutationKey: arg1
|
|
4982
|
+
};
|
|
4983
|
+
} else {
|
|
4984
|
+
options = arg1 || {};
|
|
4985
|
+
}
|
|
4986
|
+
|
|
4987
|
+
return cloneDeepUnref(options);
|
|
4988
|
+
}
|
|
4989
|
+
|
|
4990
|
+
exports.CancelledError = CancelledError;
|
|
4991
|
+
exports.InfiniteQueryObserver = InfiniteQueryObserver;
|
|
4992
|
+
exports.MutationCache = MutationCache;
|
|
4993
|
+
exports.MutationObserver = MutationObserver;
|
|
4994
|
+
exports.QueriesObserver = QueriesObserver;
|
|
4995
|
+
exports.QueryCache = QueryCache;
|
|
4996
|
+
exports.QueryClient = QueryClient;
|
|
4997
|
+
exports.QueryObserver = QueryObserver;
|
|
4998
|
+
exports.VUE_QUERY_CLIENT = VUE_QUERY_CLIENT;
|
|
4999
|
+
exports.VueQueryPlugin = VueQueryPlugin;
|
|
5000
|
+
exports.dehydrate = dehydrate;
|
|
5001
|
+
exports.focusManager = focusManager;
|
|
5002
|
+
exports.hashQueryKey = hashQueryKey;
|
|
5003
|
+
exports.hydrate = hydrate;
|
|
5004
|
+
exports.isCancelledError = isCancelledError;
|
|
5005
|
+
exports.isError = isError;
|
|
5006
|
+
exports.isServer = isServer;
|
|
5007
|
+
exports.notifyManager = notifyManager;
|
|
5008
|
+
exports.onlineManager = onlineManager;
|
|
5009
|
+
exports.parseFilterArgs = parseFilterArgs$1;
|
|
5010
|
+
exports.parseMutationArgs = parseMutationArgs$1;
|
|
5011
|
+
exports.parseMutationFilterArgs = parseMutationFilterArgs$1;
|
|
5012
|
+
exports.parseQueryArgs = parseQueryArgs;
|
|
5013
|
+
exports.useInfiniteQuery = useInfiniteQuery;
|
|
5014
|
+
exports.useIsFetching = useIsFetching;
|
|
5015
|
+
exports.useIsMutating = useIsMutating;
|
|
5016
|
+
exports.useMutation = useMutation;
|
|
5017
|
+
exports.useQueries = useQueries;
|
|
5018
|
+
exports.useQuery = useQuery;
|
|
5019
|
+
exports.useQueryClient = useQueryClient;
|
|
5020
|
+
|
|
5021
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5022
|
+
|
|
5023
|
+
}));
|
|
5024
|
+
//# sourceMappingURL=index.development.js.map
|