@hz52410/uni-query 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +247 -0
- package/dist/index.cjs.js +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.esm.js +1203 -0
- package/dist/infiniteQueryOptions.d.ts +15 -0
- package/dist/mutationCache.d.ts +8 -0
- package/dist/query-core/index.d.ts +12 -0
- package/dist/query-core/infiniteQueryObserver.d.ts +31 -0
- package/dist/query-core/mutationCache.d.ts +43 -0
- package/dist/query-core/mutationObserver.d.ts +43 -0
- package/dist/query-core/queriesObserver.d.ts +27 -0
- package/dist/query-core/queryCache.d.ts +40 -0
- package/dist/query-core/queryClient.d.ts +133 -0
- package/dist/query-core/queryObserver.d.ts +67 -0
- package/dist/query-core/types.d.ts +236 -0
- package/dist/query-core/utils.d.ts +10 -0
- package/dist/queryCache.d.ts +8 -0
- package/dist/queryClient.d.ts +37 -0
- package/dist/queryOptions.d.ts +9 -0
- package/dist/types.d.ts +33 -0
- package/dist/useBaseQuery.d.ts +15 -0
- package/dist/useInfiniteQuery.d.ts +13 -0
- package/dist/useIsFetching.d.ts +7 -0
- package/dist/useMutation.d.ts +16 -0
- package/dist/useMutationState.d.ts +12 -0
- package/dist/useQueries.d.ts +84 -0
- package/dist/useQuery.d.ts +19 -0
- package/dist/useQueryClient.d.ts +3 -0
- package/dist/utils.d.ts +7 -0
- package/dist/vueQueryPlugin.d.ts +20 -0
- package/package.json +56 -0
|
@@ -0,0 +1,1203 @@
|
|
|
1
|
+
import { isRef as F, unref as M, hasInjectionContext as H, inject as L, nextTick as J, getCurrentScope as C, computed as Q, shallowReactive as I, reactive as U, watch as y, onScopeDispose as v, shallowReadonly as R, readonly as P, toRefs as x, shallowRef as N, ref as $, watchEffect as k } from "vue";
|
|
2
|
+
let T = class {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.queries = /* @__PURE__ */ new Map();
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* 添加查询
|
|
8
|
+
*/
|
|
9
|
+
add(t) {
|
|
10
|
+
this.queries.set(t.queryHash, t);
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* 移除查询
|
|
14
|
+
*/
|
|
15
|
+
remove(t) {
|
|
16
|
+
this.queries.delete(t.queryHash);
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* 查找查询
|
|
20
|
+
*/
|
|
21
|
+
find(t) {
|
|
22
|
+
const e = this.hashQueryKey(t.queryKey);
|
|
23
|
+
return this.queries.get(e);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 查找所有匹配的查询
|
|
27
|
+
*/
|
|
28
|
+
findAll(t = {}) {
|
|
29
|
+
const e = [];
|
|
30
|
+
for (const s of this.queries.values())
|
|
31
|
+
this.matchQuery(s, t) && e.push(s);
|
|
32
|
+
return e;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 清除所有查询
|
|
36
|
+
*/
|
|
37
|
+
clear() {
|
|
38
|
+
this.queries.clear();
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 订阅缓存变化
|
|
42
|
+
*/
|
|
43
|
+
subscribe(t) {
|
|
44
|
+
return () => {
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 生成查询哈希
|
|
49
|
+
*/
|
|
50
|
+
hashQueryKey(t) {
|
|
51
|
+
return JSON.stringify(t);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* 匹配查询
|
|
55
|
+
*/
|
|
56
|
+
matchQuery(t, e) {
|
|
57
|
+
if (e.queryKey) {
|
|
58
|
+
const s = this.hashQueryKey(e.queryKey);
|
|
59
|
+
return e.exact ? t.queryHash === s : t.queryHash.startsWith(s);
|
|
60
|
+
}
|
|
61
|
+
return e.predicate ? e.predicate(t) : !0;
|
|
62
|
+
}
|
|
63
|
+
}, j = class {
|
|
64
|
+
constructor() {
|
|
65
|
+
this.mutations = /* @__PURE__ */ new Map(), this.mutationId = 0;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* 添加 Mutation
|
|
69
|
+
*/
|
|
70
|
+
add(t) {
|
|
71
|
+
this.mutations.set(t.mutationId, t);
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* 移除 Mutation
|
|
75
|
+
*/
|
|
76
|
+
remove(t) {
|
|
77
|
+
this.mutations.delete(t.mutationId);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 查找 Mutation
|
|
81
|
+
*/
|
|
82
|
+
find(t) {
|
|
83
|
+
for (const e of this.mutations.values())
|
|
84
|
+
if (this.matchMutation(e, t))
|
|
85
|
+
return e;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 查找所有匹配的 Mutation
|
|
89
|
+
*/
|
|
90
|
+
findAll(t = {}) {
|
|
91
|
+
const e = [];
|
|
92
|
+
for (const s of this.mutations.values())
|
|
93
|
+
this.matchMutation(s, t) && e.push(s);
|
|
94
|
+
return e;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 清除所有 Mutation
|
|
98
|
+
*/
|
|
99
|
+
clear() {
|
|
100
|
+
this.mutations.clear();
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* 订阅缓存变化
|
|
104
|
+
*/
|
|
105
|
+
subscribe(t) {
|
|
106
|
+
return () => {
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* 生成 Mutation ID
|
|
111
|
+
*/
|
|
112
|
+
generateMutationId() {
|
|
113
|
+
return ++this.mutationId;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* 匹配 Mutation
|
|
117
|
+
*/
|
|
118
|
+
matchMutation(t, e) {
|
|
119
|
+
return !(e.mutationKey && t.options.mutationKey && !this.matchKeys(t.options.mutationKey, e.mutationKey, e.exact) || e.status && t.state.status !== e.status || e.predicate && !e.predicate(t));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* 匹配键
|
|
123
|
+
*/
|
|
124
|
+
matchKeys(t, e, s) {
|
|
125
|
+
return s ? JSON.stringify(t) === JSON.stringify(e) : JSON.stringify(t).startsWith(JSON.stringify(e));
|
|
126
|
+
}
|
|
127
|
+
}, W = class {
|
|
128
|
+
constructor(t = {}) {
|
|
129
|
+
this.queryCache = t.queryCache || new T(), this.mutationCache = t.mutationCache || new j(), this.defaultOptions = t.defaultOptions || {};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* 挂载(uni-app 不需要特殊处理)
|
|
133
|
+
*/
|
|
134
|
+
mount() {
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 卸载
|
|
138
|
+
*/
|
|
139
|
+
unmount() {
|
|
140
|
+
this.queryCache.clear(), this.mutationCache.clear();
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* 获取查询数据
|
|
144
|
+
*/
|
|
145
|
+
getQueryData(t) {
|
|
146
|
+
const e = this.queryCache.find({ queryKey: t, exact: !0 });
|
|
147
|
+
return e == null ? void 0 : e.state.data;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* 设置查询数据
|
|
151
|
+
*/
|
|
152
|
+
setQueryData(t, e, s) {
|
|
153
|
+
const r = this.queryCache.find({ queryKey: t, exact: !0 });
|
|
154
|
+
if (!r)
|
|
155
|
+
return;
|
|
156
|
+
const u = r.state.data, a = typeof e == "function" ? e(u) : e;
|
|
157
|
+
return r.state = {
|
|
158
|
+
...r.state,
|
|
159
|
+
data: a,
|
|
160
|
+
dataUpdatedAt: (s == null ? void 0 : s.updatedAt) || Date.now()
|
|
161
|
+
}, a;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* 设置多个查询数据
|
|
165
|
+
*/
|
|
166
|
+
setQueriesData(t, e, s) {
|
|
167
|
+
return this.queryCache.findAll(t).map((u) => {
|
|
168
|
+
const a = this.setQueryData(u.queryKey, e, s);
|
|
169
|
+
return [u.queryKey, a];
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* 获取查询状态
|
|
174
|
+
*/
|
|
175
|
+
getQueryState(t) {
|
|
176
|
+
const e = this.queryCache.find({ queryKey: t, exact: !0 });
|
|
177
|
+
return e == null ? void 0 : e.state;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* 获取多个查询数据
|
|
181
|
+
*/
|
|
182
|
+
getQueriesData(t) {
|
|
183
|
+
return this.queryCache.findAll(t).map((s) => [s.queryKey, s.state.data]);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* 获取查询
|
|
187
|
+
*/
|
|
188
|
+
getQuery(t) {
|
|
189
|
+
return this.queryCache.find({ queryKey: t, exact: !0 });
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* 获取所有查询
|
|
193
|
+
*/
|
|
194
|
+
getQueries(t = {}) {
|
|
195
|
+
return this.queryCache.findAll(t);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* 获取所有 Mutations
|
|
199
|
+
*/
|
|
200
|
+
getMutations(t = {}) {
|
|
201
|
+
return this.mutationCache.findAll(t);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* 判断是否正在获取
|
|
205
|
+
*/
|
|
206
|
+
isFetching(t = {}) {
|
|
207
|
+
return this.queryCache.findAll(t).filter((s) => s.state.fetchStatus === "fetching").length;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* 判断是否正在执行 Mutation
|
|
211
|
+
*/
|
|
212
|
+
isMutating(t = {}) {
|
|
213
|
+
return this.mutationCache.findAll(t).filter((s) => s.state.status === "loading").length;
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* 获取默认查询选项
|
|
217
|
+
*/
|
|
218
|
+
defaultQueryOptions(t) {
|
|
219
|
+
return {
|
|
220
|
+
...this.defaultOptions.queries || {},
|
|
221
|
+
...t,
|
|
222
|
+
_defaulted: !0
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* 获取默认 Mutation 选项
|
|
227
|
+
*/
|
|
228
|
+
defaultMutationOptions(t) {
|
|
229
|
+
return {
|
|
230
|
+
...this.defaultOptions.mutations || {},
|
|
231
|
+
...t
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* 设置默认选项
|
|
236
|
+
*/
|
|
237
|
+
setDefaultOptions(t) {
|
|
238
|
+
this.defaultOptions = {
|
|
239
|
+
...this.defaultOptions,
|
|
240
|
+
...t
|
|
241
|
+
};
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* 设置查询默认值
|
|
245
|
+
*/
|
|
246
|
+
setQueryDefaults(t, e) {
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* 获取查询默认值
|
|
250
|
+
*/
|
|
251
|
+
getQueryDefaults(t) {
|
|
252
|
+
return {};
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* 设置 Mutation 默认值
|
|
256
|
+
*/
|
|
257
|
+
setMutationDefaults(t, e) {
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* 获取 Mutation 默认值
|
|
261
|
+
*/
|
|
262
|
+
getMutationDefaults(t) {
|
|
263
|
+
return {};
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 获取查询数据(确保存在)
|
|
267
|
+
*/
|
|
268
|
+
async ensureQueryData(t) {
|
|
269
|
+
const e = this.getQuery(t.queryKey);
|
|
270
|
+
return e && e.state.data !== void 0 ? e.state.data : this.fetchQuery(t);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* 获取查询
|
|
274
|
+
*/
|
|
275
|
+
async fetchQuery(t) {
|
|
276
|
+
const e = this.defaultQueryOptions(t), s = await e.queryFn({ queryKey: e.queryKey });
|
|
277
|
+
return e.select ? e.select(s) : s;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* 预取查询
|
|
281
|
+
*/
|
|
282
|
+
async prefetchQuery(t) {
|
|
283
|
+
await this.fetchQuery(t);
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* 获取无限查询
|
|
287
|
+
*/
|
|
288
|
+
async fetchInfiniteQuery(t) {
|
|
289
|
+
return {
|
|
290
|
+
pages: [await t.queryFn({ queryKey: t.queryKey })],
|
|
291
|
+
pageParams: [t.initialPageParam]
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* 预取无限查询
|
|
296
|
+
*/
|
|
297
|
+
async prefetchInfiniteQuery(t) {
|
|
298
|
+
await this.fetchInfiniteQuery(t);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* 移除查询
|
|
302
|
+
*/
|
|
303
|
+
removeQueries(t = {}) {
|
|
304
|
+
this.queryCache.findAll(t).forEach((s) => this.queryCache.remove(s));
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* 重置查询
|
|
308
|
+
*/
|
|
309
|
+
async resetQueries(t = {}, e) {
|
|
310
|
+
this.queryCache.findAll(t).forEach((r) => {
|
|
311
|
+
r.state = {
|
|
312
|
+
...r.state,
|
|
313
|
+
data: void 0,
|
|
314
|
+
error: null,
|
|
315
|
+
status: "pending",
|
|
316
|
+
fetchStatus: "idle"
|
|
317
|
+
};
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* 取消查询
|
|
322
|
+
*/
|
|
323
|
+
async cancelQueries(t = {}, e) {
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* 使查询失效
|
|
327
|
+
*/
|
|
328
|
+
async invalidateQueries(t = {}, e) {
|
|
329
|
+
this.queryCache.findAll(t).forEach((r) => {
|
|
330
|
+
r.state.isInvalidated = !0;
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* 重新获取查询
|
|
335
|
+
*/
|
|
336
|
+
async refetchQueries(t = {}, e) {
|
|
337
|
+
const s = this.queryCache.findAll(t);
|
|
338
|
+
for (const r of s)
|
|
339
|
+
if (r.options.queryFn)
|
|
340
|
+
try {
|
|
341
|
+
const u = await r.options.queryFn({ queryKey: r.queryKey });
|
|
342
|
+
r.state = {
|
|
343
|
+
...r.state,
|
|
344
|
+
data: u,
|
|
345
|
+
status: "success",
|
|
346
|
+
fetchStatus: "idle",
|
|
347
|
+
dataUpdatedAt: Date.now()
|
|
348
|
+
};
|
|
349
|
+
} catch (u) {
|
|
350
|
+
r.state = {
|
|
351
|
+
...r.state,
|
|
352
|
+
error: u,
|
|
353
|
+
status: "error",
|
|
354
|
+
fetchStatus: "idle",
|
|
355
|
+
errorUpdatedAt: Date.now()
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
};
|
|
360
|
+
function Y(n) {
|
|
361
|
+
return JSON.stringify(n);
|
|
362
|
+
}
|
|
363
|
+
function O(n, t) {
|
|
364
|
+
return typeof n == "function" ? n(...t) : n === !0;
|
|
365
|
+
}
|
|
366
|
+
class b {
|
|
367
|
+
constructor(t, e) {
|
|
368
|
+
this.subscribers = /* @__PURE__ */ new Set(), this.client = t, this.options = e, this.query = this.client.getQuery(e.queryKey), this.query || this.createQuery(), this.currentResult = this.createResult(), e.enabled !== !1 && this.shouldFetch() && this.fetch().catch(() => {
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* 创建查询对象
|
|
373
|
+
*/
|
|
374
|
+
createQuery() {
|
|
375
|
+
const t = Y(this.options.queryKey), e = {
|
|
376
|
+
queryKey: this.options.queryKey,
|
|
377
|
+
queryHash: t,
|
|
378
|
+
state: this.createInitialState(),
|
|
379
|
+
options: this.options
|
|
380
|
+
};
|
|
381
|
+
this.client.queryCache.add(e), this.query = e;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* 判断是否应该获取数据
|
|
385
|
+
*/
|
|
386
|
+
shouldFetch() {
|
|
387
|
+
if (!this.query)
|
|
388
|
+
return !0;
|
|
389
|
+
const t = this.query.state;
|
|
390
|
+
if (t.data === void 0)
|
|
391
|
+
return !0;
|
|
392
|
+
if (this.options.staleTime !== void 0 && this.options.staleTime > 0) {
|
|
393
|
+
const e = Date.now(), s = this.options.staleTime;
|
|
394
|
+
if (e - t.dataUpdatedAt > s)
|
|
395
|
+
return !0;
|
|
396
|
+
}
|
|
397
|
+
return !1;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* 订阅结果变化
|
|
401
|
+
*/
|
|
402
|
+
subscribe(t) {
|
|
403
|
+
return this.subscribers.add(t), t(this.currentResult), () => {
|
|
404
|
+
this.subscribers.delete(t);
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* 获取当前结果
|
|
409
|
+
*/
|
|
410
|
+
getCurrentResult() {
|
|
411
|
+
return this.currentResult;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* 获取乐观结果
|
|
415
|
+
*/
|
|
416
|
+
getOptimisticResult(t) {
|
|
417
|
+
return this.createResult();
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* 获取当前查询
|
|
421
|
+
*/
|
|
422
|
+
getCurrentQuery() {
|
|
423
|
+
return this.query;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* 设置选项
|
|
427
|
+
*/
|
|
428
|
+
setOptions(t) {
|
|
429
|
+
this.options = t, this.query = this.client.getQuery(t.queryKey), this.query || this.createQuery(), this.updateResult(), t.enabled !== !1 && this.shouldFetch() && this.fetch().catch(() => {
|
|
430
|
+
});
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* 获取乐观结果(用于 suspense)
|
|
434
|
+
*/
|
|
435
|
+
fetchOptimistic(t) {
|
|
436
|
+
return this.fetch();
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* 获取数据
|
|
440
|
+
*/
|
|
441
|
+
async fetch() {
|
|
442
|
+
if (!this.options.queryFn)
|
|
443
|
+
throw new Error("queryFn is required");
|
|
444
|
+
this.query || this.createQuery(), this.query && (this.query.state = {
|
|
445
|
+
...this.query.state,
|
|
446
|
+
fetchStatus: "fetching"
|
|
447
|
+
}, this.updateResult());
|
|
448
|
+
try {
|
|
449
|
+
const t = await this.options.queryFn({ queryKey: this.options.queryKey }), e = this.options.select ? this.options.select(t) : t;
|
|
450
|
+
return this.query && (this.query.state = {
|
|
451
|
+
...this.query.state,
|
|
452
|
+
data: e,
|
|
453
|
+
status: "success",
|
|
454
|
+
fetchStatus: "idle",
|
|
455
|
+
dataUpdatedAt: Date.now(),
|
|
456
|
+
error: null,
|
|
457
|
+
errorUpdateCount: 0,
|
|
458
|
+
failureCount: 0
|
|
459
|
+
}), this.updateResult(), this.currentResult;
|
|
460
|
+
} catch (t) {
|
|
461
|
+
if (this.query) {
|
|
462
|
+
const e = (this.query.state.errorUpdateCount || 0) + 1;
|
|
463
|
+
this.query.state = {
|
|
464
|
+
...this.query.state,
|
|
465
|
+
error: t,
|
|
466
|
+
status: "error",
|
|
467
|
+
fetchStatus: "idle",
|
|
468
|
+
errorUpdatedAt: Date.now(),
|
|
469
|
+
errorUpdateCount: e,
|
|
470
|
+
failureCount: e,
|
|
471
|
+
failureReason: t
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
throw this.updateResult(), t;
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* 创建结果对象
|
|
479
|
+
*/
|
|
480
|
+
createResult() {
|
|
481
|
+
var r;
|
|
482
|
+
const e = ((r = this.query) == null ? void 0 : r.state) || this.createInitialState();
|
|
483
|
+
return {
|
|
484
|
+
data: this.options.select && e.data ? this.options.select(e.data) : e.data,
|
|
485
|
+
dataUpdatedAt: e.dataUpdatedAt,
|
|
486
|
+
error: e.error,
|
|
487
|
+
errorUpdatedAt: e.errorUpdatedAt,
|
|
488
|
+
errorUpdateCount: e.errorUpdateCount,
|
|
489
|
+
failureCount: e.failureCount,
|
|
490
|
+
failureReason: e.failureReason,
|
|
491
|
+
fetchFailureCount: e.fetchFailureCount,
|
|
492
|
+
fetchFailureReason: e.fetchFailureReason,
|
|
493
|
+
fetchStatus: e.fetchStatus,
|
|
494
|
+
isError: e.status === "error",
|
|
495
|
+
isFetched: e.dataUpdatedAt > 0,
|
|
496
|
+
isFetchedAfterMount: e.dataUpdatedAt > 0 && e.fetchStatus !== "fetching",
|
|
497
|
+
isFetching: e.fetchStatus === "fetching",
|
|
498
|
+
isInitialLoading: e.status === "pending" && e.fetchStatus === "fetching",
|
|
499
|
+
isLoading: e.status === "pending",
|
|
500
|
+
isLoadingError: e.status === "error" && e.fetchStatus !== "fetching",
|
|
501
|
+
isPaused: e.fetchStatus === "paused",
|
|
502
|
+
isPlaceholderData: !1,
|
|
503
|
+
isRefetchError: e.status === "error" && e.fetchStatus === "fetching",
|
|
504
|
+
isRefetching: e.status === "success" && e.fetchStatus === "fetching",
|
|
505
|
+
isStale: this.isStale(e),
|
|
506
|
+
isSuccess: e.status === "success",
|
|
507
|
+
refetch: this.refetch.bind(this),
|
|
508
|
+
status: e.status
|
|
509
|
+
};
|
|
510
|
+
}
|
|
511
|
+
/**
|
|
512
|
+
* 创建初始状态
|
|
513
|
+
*/
|
|
514
|
+
createInitialState() {
|
|
515
|
+
return {
|
|
516
|
+
data: void 0,
|
|
517
|
+
dataUpdatedAt: 0,
|
|
518
|
+
error: null,
|
|
519
|
+
errorUpdatedAt: 0,
|
|
520
|
+
errorUpdateCount: 0,
|
|
521
|
+
failureCount: 0,
|
|
522
|
+
failureReason: null,
|
|
523
|
+
fetchFailureCount: 0,
|
|
524
|
+
fetchFailureReason: null,
|
|
525
|
+
fetchMeta: void 0,
|
|
526
|
+
isInvalidated: !1,
|
|
527
|
+
status: "pending",
|
|
528
|
+
fetchStatus: "idle"
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* 判断是否过期
|
|
533
|
+
*/
|
|
534
|
+
isStale(t) {
|
|
535
|
+
return this.options.staleTime ? Date.now() - t.dataUpdatedAt > this.options.staleTime : !0;
|
|
536
|
+
}
|
|
537
|
+
/**
|
|
538
|
+
* 更新结果并通知订阅者
|
|
539
|
+
*/
|
|
540
|
+
updateResult() {
|
|
541
|
+
this.currentResult = this.createResult(), this.subscribers.forEach((t) => t(this.currentResult));
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 重新获取
|
|
545
|
+
*/
|
|
546
|
+
async refetch(t) {
|
|
547
|
+
return this.fetch();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
class B {
|
|
551
|
+
constructor(t, e) {
|
|
552
|
+
this.subscribers = /* @__PURE__ */ new Set(), this.client = t, this.options = e, this.mutation = this.createMutation(), this.currentResult = this.createResult();
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* 订阅结果变化
|
|
556
|
+
*/
|
|
557
|
+
subscribe(t) {
|
|
558
|
+
return this.subscribers.add(t), t(this.currentResult), () => {
|
|
559
|
+
this.subscribers.delete(t);
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
/**
|
|
563
|
+
* 获取当前结果
|
|
564
|
+
*/
|
|
565
|
+
getCurrentResult() {
|
|
566
|
+
return this.currentResult;
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* 设置选项
|
|
570
|
+
*/
|
|
571
|
+
setOptions(t) {
|
|
572
|
+
this.options = t, this.mutation.options = t, this.updateResult();
|
|
573
|
+
}
|
|
574
|
+
/**
|
|
575
|
+
* 执行 Mutation
|
|
576
|
+
*/
|
|
577
|
+
async mutate(t, e) {
|
|
578
|
+
this.mutation.state = {
|
|
579
|
+
...this.mutation.state,
|
|
580
|
+
status: "loading",
|
|
581
|
+
isLoading: !0,
|
|
582
|
+
variables: t
|
|
583
|
+
}, this.updateResult();
|
|
584
|
+
let s;
|
|
585
|
+
try {
|
|
586
|
+
this.options.onMutate && (s = await this.options.onMutate(t), this.mutation.state.context = s);
|
|
587
|
+
const r = await this.options.mutationFn(t);
|
|
588
|
+
return this.mutation.state = {
|
|
589
|
+
...this.mutation.state,
|
|
590
|
+
data: r,
|
|
591
|
+
status: "success",
|
|
592
|
+
isLoading: !1,
|
|
593
|
+
isSuccess: !0,
|
|
594
|
+
isError: !1
|
|
595
|
+
}, this.updateResult(), this.options.onSuccess && await this.options.onSuccess(r, t, s), r;
|
|
596
|
+
} catch (r) {
|
|
597
|
+
throw this.mutation.state = {
|
|
598
|
+
...this.mutation.state,
|
|
599
|
+
error: r,
|
|
600
|
+
status: "error",
|
|
601
|
+
isLoading: !1,
|
|
602
|
+
isSuccess: !1,
|
|
603
|
+
isError: !0,
|
|
604
|
+
failureCount: (this.mutation.state.failureCount || 0) + 1,
|
|
605
|
+
failureReason: r
|
|
606
|
+
}, this.updateResult(), this.options.onError && await this.options.onError(r, t, s), r;
|
|
607
|
+
} finally {
|
|
608
|
+
this.options.onSettled && await this.options.onSettled(
|
|
609
|
+
this.mutation.state.data,
|
|
610
|
+
this.mutation.state.error,
|
|
611
|
+
t,
|
|
612
|
+
s
|
|
613
|
+
);
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* 创建 Mutation
|
|
618
|
+
*/
|
|
619
|
+
createMutation() {
|
|
620
|
+
return {
|
|
621
|
+
mutationId: this.client.mutationCache.generateMutationId(),
|
|
622
|
+
options: this.options,
|
|
623
|
+
state: this.createInitialResult()
|
|
624
|
+
};
|
|
625
|
+
}
|
|
626
|
+
/**
|
|
627
|
+
* 创建初始结果
|
|
628
|
+
*/
|
|
629
|
+
createInitialResult() {
|
|
630
|
+
return {
|
|
631
|
+
data: void 0,
|
|
632
|
+
error: null,
|
|
633
|
+
failureCount: 0,
|
|
634
|
+
failureReason: null,
|
|
635
|
+
isError: !1,
|
|
636
|
+
isIdle: !0,
|
|
637
|
+
isPaused: !1,
|
|
638
|
+
isLoading: !1,
|
|
639
|
+
isSuccess: !1,
|
|
640
|
+
mutate: () => {
|
|
641
|
+
},
|
|
642
|
+
mutateAsync: async () => {
|
|
643
|
+
throw new Error("Not implemented");
|
|
644
|
+
},
|
|
645
|
+
reset: () => {
|
|
646
|
+
},
|
|
647
|
+
status: "idle",
|
|
648
|
+
variables: void 0,
|
|
649
|
+
context: void 0
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
/**
|
|
653
|
+
* 创建结果对象
|
|
654
|
+
*/
|
|
655
|
+
createResult() {
|
|
656
|
+
return {
|
|
657
|
+
...this.mutation.state,
|
|
658
|
+
mutate: (t, e) => {
|
|
659
|
+
this.mutate(t, e).catch(() => {
|
|
660
|
+
});
|
|
661
|
+
},
|
|
662
|
+
mutateAsync: (t, e) => this.mutate(t, e),
|
|
663
|
+
reset: () => {
|
|
664
|
+
this.mutation.state = this.createInitialResult(), this.updateResult();
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* 更新结果并通知订阅者
|
|
670
|
+
*/
|
|
671
|
+
updateResult() {
|
|
672
|
+
this.currentResult = this.createResult(), this.subscribers.forEach((t) => t(this.currentResult));
|
|
673
|
+
}
|
|
674
|
+
}
|
|
675
|
+
class X extends b {
|
|
676
|
+
constructor(t, e) {
|
|
677
|
+
super(t, e), this.infiniteOptions = e;
|
|
678
|
+
}
|
|
679
|
+
/**
|
|
680
|
+
* 获取下一页
|
|
681
|
+
*/
|
|
682
|
+
async fetchNextPage(t) {
|
|
683
|
+
return this.getCurrentResult();
|
|
684
|
+
}
|
|
685
|
+
/**
|
|
686
|
+
* 获取上一页
|
|
687
|
+
*/
|
|
688
|
+
async fetchPreviousPage(t) {
|
|
689
|
+
return this.getCurrentResult();
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* 获取当前结果(覆盖父类方法)
|
|
693
|
+
*/
|
|
694
|
+
getCurrentResult() {
|
|
695
|
+
const t = super.getCurrentResult(), e = t.data;
|
|
696
|
+
return {
|
|
697
|
+
...t,
|
|
698
|
+
fetchNextPage: this.fetchNextPage.bind(this),
|
|
699
|
+
fetchPreviousPage: this.fetchPreviousPage.bind(this),
|
|
700
|
+
hasNextPage: this.hasNextPage(e),
|
|
701
|
+
hasPreviousPage: this.hasPreviousPage(e),
|
|
702
|
+
isFetchingNextPage: !1,
|
|
703
|
+
isFetchingPreviousPage: !1
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
/**
|
|
707
|
+
* 判断是否有下一页
|
|
708
|
+
*/
|
|
709
|
+
hasNextPage(t) {
|
|
710
|
+
if (!t || !t.pages.length)
|
|
711
|
+
return !1;
|
|
712
|
+
const e = t.pages[t.pages.length - 1], s = this.infiniteOptions.getNextPageParam(e, t.pages);
|
|
713
|
+
return s != null;
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* 判断是否有上一页
|
|
717
|
+
*/
|
|
718
|
+
hasPreviousPage(t) {
|
|
719
|
+
if (!t || !t.pages.length || !this.infiniteOptions.getPreviousPageParam)
|
|
720
|
+
return !1;
|
|
721
|
+
const e = t.pages[0], s = this.infiniteOptions.getPreviousPageParam(
|
|
722
|
+
e,
|
|
723
|
+
t.pages
|
|
724
|
+
);
|
|
725
|
+
return s != null;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
class Z {
|
|
729
|
+
constructor(t, e, s) {
|
|
730
|
+
this.observers = [], this.subscribers = /* @__PURE__ */ new Set(), this.client = t, this.options = s || { queries: e }, this.observers = e.map((r) => {
|
|
731
|
+
const u = t.defaultQueryOptions(r);
|
|
732
|
+
return new b(t, u);
|
|
733
|
+
}), this.currentResult = this.getCombinedResult();
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* 订阅结果变化
|
|
737
|
+
*/
|
|
738
|
+
subscribe(t) {
|
|
739
|
+
this.subscribers.add(t), t(this.currentResult);
|
|
740
|
+
const e = this.observers.map(
|
|
741
|
+
(s) => s.subscribe(() => {
|
|
742
|
+
this.currentResult = this.getCombinedResult(), this.subscribers.forEach((r) => r(this.currentResult));
|
|
743
|
+
})
|
|
744
|
+
);
|
|
745
|
+
return () => {
|
|
746
|
+
this.subscribers.delete(t), e.forEach((s) => s());
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* 获取乐观结果
|
|
751
|
+
*/
|
|
752
|
+
getOptimisticResult(t, e) {
|
|
753
|
+
const s = t.map((u) => {
|
|
754
|
+
const a = this.client.defaultQueryOptions(u);
|
|
755
|
+
return new b(this.client, a).getCurrentResult();
|
|
756
|
+
}), r = e || this.options.combine || ((u) => u);
|
|
757
|
+
return [s, r];
|
|
758
|
+
}
|
|
759
|
+
/**
|
|
760
|
+
* 设置查询
|
|
761
|
+
*/
|
|
762
|
+
setQueries(t, e) {
|
|
763
|
+
this.options = e || { queries: t }, this.observers = t.map((s) => {
|
|
764
|
+
const r = this.client.defaultQueryOptions(s);
|
|
765
|
+
return new b(this.client, r);
|
|
766
|
+
}), this.currentResult = this.getCombinedResult(), this.subscribers.forEach((s) => s(this.currentResult));
|
|
767
|
+
}
|
|
768
|
+
/**
|
|
769
|
+
* 获取组合结果
|
|
770
|
+
*/
|
|
771
|
+
getCombinedResult() {
|
|
772
|
+
const t = this.observers.map((s) => s.getCurrentResult());
|
|
773
|
+
return (this.options.combine || ((s) => s))(t);
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
const z = "VUE_QUERY_CLIENT";
|
|
777
|
+
function _(n) {
|
|
778
|
+
const t = n ? `:${n}` : "";
|
|
779
|
+
return `${z}${t}`;
|
|
780
|
+
}
|
|
781
|
+
function S(n, t) {
|
|
782
|
+
Object.keys(n).forEach((e) => {
|
|
783
|
+
n[e] = t[e];
|
|
784
|
+
});
|
|
785
|
+
}
|
|
786
|
+
function D(n, t, e = "", s = 0) {
|
|
787
|
+
if (t) {
|
|
788
|
+
const r = t(n, e, s);
|
|
789
|
+
if (r === void 0 && F(n) || r !== void 0)
|
|
790
|
+
return r;
|
|
791
|
+
}
|
|
792
|
+
if (Array.isArray(n))
|
|
793
|
+
return n.map(
|
|
794
|
+
(r, u) => D(r, t, String(u), s + 1)
|
|
795
|
+
);
|
|
796
|
+
if (typeof n == "object" && tt(n)) {
|
|
797
|
+
const r = Object.entries(n).map(([u, a]) => [
|
|
798
|
+
u,
|
|
799
|
+
D(a, t, u, s + 1)
|
|
800
|
+
]);
|
|
801
|
+
return Object.fromEntries(r);
|
|
802
|
+
}
|
|
803
|
+
return n;
|
|
804
|
+
}
|
|
805
|
+
function G(n, t) {
|
|
806
|
+
return D(n, t);
|
|
807
|
+
}
|
|
808
|
+
function i(n, t = !1) {
|
|
809
|
+
return G(n, (e, s, r) => {
|
|
810
|
+
if (r === 1 && s === "queryKey")
|
|
811
|
+
return i(e, !0);
|
|
812
|
+
if (t && et(e))
|
|
813
|
+
return i(e(), t);
|
|
814
|
+
if (F(e))
|
|
815
|
+
return i(M(e), t);
|
|
816
|
+
});
|
|
817
|
+
}
|
|
818
|
+
function tt(n) {
|
|
819
|
+
if (Object.prototype.toString.call(n) !== "[object Object]")
|
|
820
|
+
return !1;
|
|
821
|
+
const t = Object.getPrototypeOf(n);
|
|
822
|
+
return t === null || t === Object.prototype;
|
|
823
|
+
}
|
|
824
|
+
function et(n) {
|
|
825
|
+
return typeof n == "function";
|
|
826
|
+
}
|
|
827
|
+
function q(n = "") {
|
|
828
|
+
if (!H())
|
|
829
|
+
throw new Error(
|
|
830
|
+
"vue-query hooks can only be used inside setup() function or functions that support injection context."
|
|
831
|
+
);
|
|
832
|
+
const t = _(n), e = L(t);
|
|
833
|
+
if (!e)
|
|
834
|
+
throw new Error(
|
|
835
|
+
"No 'queryClient' found in Vue context, use 'VueQueryPlugin' to properly initialize the library."
|
|
836
|
+
);
|
|
837
|
+
return e;
|
|
838
|
+
}
|
|
839
|
+
class st extends T {
|
|
840
|
+
find(t) {
|
|
841
|
+
return super.find(i(t));
|
|
842
|
+
}
|
|
843
|
+
findAll(t = {}) {
|
|
844
|
+
return super.findAll(i(t));
|
|
845
|
+
}
|
|
846
|
+
}
|
|
847
|
+
class rt extends j {
|
|
848
|
+
find(t) {
|
|
849
|
+
return super.find(i(t));
|
|
850
|
+
}
|
|
851
|
+
findAll(t = {}) {
|
|
852
|
+
return super.findAll(i(t));
|
|
853
|
+
}
|
|
854
|
+
}
|
|
855
|
+
class nt extends W {
|
|
856
|
+
constructor(t = {}) {
|
|
857
|
+
const e = {
|
|
858
|
+
defaultOptions: t.defaultOptions,
|
|
859
|
+
queryCache: t.queryCache || new st(),
|
|
860
|
+
mutationCache: t.mutationCache || new rt()
|
|
861
|
+
};
|
|
862
|
+
super(e);
|
|
863
|
+
}
|
|
864
|
+
// 移除 SSR isRestoring(uni-app 不需要)
|
|
865
|
+
isFetching(t = {}) {
|
|
866
|
+
return super.isFetching(i(t));
|
|
867
|
+
}
|
|
868
|
+
isMutating(t = {}) {
|
|
869
|
+
return super.isMutating(i(t));
|
|
870
|
+
}
|
|
871
|
+
getQueryData(t) {
|
|
872
|
+
return super.getQueryData(i(t));
|
|
873
|
+
}
|
|
874
|
+
ensureQueryData(t) {
|
|
875
|
+
return super.ensureQueryData(i(t));
|
|
876
|
+
}
|
|
877
|
+
getQueriesData(t) {
|
|
878
|
+
return super.getQueriesData(i(t));
|
|
879
|
+
}
|
|
880
|
+
setQueryData(t, e, s = {}) {
|
|
881
|
+
return super.setQueryData(
|
|
882
|
+
i(t),
|
|
883
|
+
e,
|
|
884
|
+
i(s)
|
|
885
|
+
);
|
|
886
|
+
}
|
|
887
|
+
setQueriesData(t, e, s = {}) {
|
|
888
|
+
return super.setQueriesData(
|
|
889
|
+
i(t),
|
|
890
|
+
e,
|
|
891
|
+
i(s)
|
|
892
|
+
);
|
|
893
|
+
}
|
|
894
|
+
getQueryState(t) {
|
|
895
|
+
return super.getQueryState(i(t));
|
|
896
|
+
}
|
|
897
|
+
removeQueries(t = {}) {
|
|
898
|
+
return super.removeQueries(i(t));
|
|
899
|
+
}
|
|
900
|
+
resetQueries(t = {}, e = {}) {
|
|
901
|
+
return super.resetQueries(i(t), i(e));
|
|
902
|
+
}
|
|
903
|
+
cancelQueries(t = {}, e = {}) {
|
|
904
|
+
return super.cancelQueries(i(t), i(e));
|
|
905
|
+
}
|
|
906
|
+
invalidateQueries(t = {}, e = {}) {
|
|
907
|
+
const s = i(t), r = i(e);
|
|
908
|
+
if (super.invalidateQueries(
|
|
909
|
+
{ ...s, refetchType: "none" },
|
|
910
|
+
r
|
|
911
|
+
), s.refetchType === "none")
|
|
912
|
+
return Promise.resolve();
|
|
913
|
+
const u = {
|
|
914
|
+
...s,
|
|
915
|
+
type: s.refetchType ?? s.type ?? "active"
|
|
916
|
+
};
|
|
917
|
+
return J().then(() => super.refetchQueries(u, r));
|
|
918
|
+
}
|
|
919
|
+
refetchQueries(t = {}, e = {}) {
|
|
920
|
+
return super.refetchQueries(
|
|
921
|
+
i(t),
|
|
922
|
+
i(e)
|
|
923
|
+
);
|
|
924
|
+
}
|
|
925
|
+
fetchQuery(t) {
|
|
926
|
+
return super.fetchQuery(i(t));
|
|
927
|
+
}
|
|
928
|
+
prefetchQuery(t) {
|
|
929
|
+
return super.prefetchQuery(i(t));
|
|
930
|
+
}
|
|
931
|
+
fetchInfiniteQuery(t) {
|
|
932
|
+
return super.fetchInfiniteQuery(i(t));
|
|
933
|
+
}
|
|
934
|
+
prefetchInfiniteQuery(t) {
|
|
935
|
+
return super.prefetchInfiniteQuery(i(t));
|
|
936
|
+
}
|
|
937
|
+
setDefaultOptions(t) {
|
|
938
|
+
super.setDefaultOptions(i(t));
|
|
939
|
+
}
|
|
940
|
+
setQueryDefaults(t, e) {
|
|
941
|
+
const s = i(t), r = i(e);
|
|
942
|
+
super.setQueryDefaults(s, r);
|
|
943
|
+
}
|
|
944
|
+
getQueryDefaults(t) {
|
|
945
|
+
return super.getQueryDefaults(i(t));
|
|
946
|
+
}
|
|
947
|
+
setMutationDefaults(t, e) {
|
|
948
|
+
super.setMutationDefaults(
|
|
949
|
+
i(t),
|
|
950
|
+
i(e)
|
|
951
|
+
);
|
|
952
|
+
}
|
|
953
|
+
getMutationDefaults(t) {
|
|
954
|
+
return super.getMutationDefaults(i(t));
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
const ht = {
|
|
958
|
+
install: (n, t = {}) => {
|
|
959
|
+
var a;
|
|
960
|
+
const e = _(t.queryClientKey);
|
|
961
|
+
let s;
|
|
962
|
+
if ("queryClient" in t && t.queryClient)
|
|
963
|
+
s = t.queryClient;
|
|
964
|
+
else {
|
|
965
|
+
const h = "queryClientConfig" in t ? t.queryClientConfig : void 0;
|
|
966
|
+
s = new nt(h);
|
|
967
|
+
}
|
|
968
|
+
if (t.refetchOnShow !== !1 && typeof uni < "u" && uni.onShow) {
|
|
969
|
+
const h = () => {
|
|
970
|
+
s.refetchQueries({ type: "active" }).catch(() => {
|
|
971
|
+
});
|
|
972
|
+
};
|
|
973
|
+
uni.onShow(h);
|
|
974
|
+
}
|
|
975
|
+
const u = () => {
|
|
976
|
+
};
|
|
977
|
+
(a = n.onUnmount) == null || a.call(n, u), n.provide(e, s);
|
|
978
|
+
}
|
|
979
|
+
};
|
|
980
|
+
function lt(n) {
|
|
981
|
+
return n;
|
|
982
|
+
}
|
|
983
|
+
function ft(n) {
|
|
984
|
+
return n;
|
|
985
|
+
}
|
|
986
|
+
function V(n, t, e) {
|
|
987
|
+
process.env.NODE_ENV === "development" && (C() || console.warn(
|
|
988
|
+
'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
989
|
+
));
|
|
990
|
+
const s = e || q(), r = Q(() => {
|
|
991
|
+
let o = t;
|
|
992
|
+
typeof o == "function" && (o = o());
|
|
993
|
+
const g = i(o);
|
|
994
|
+
typeof g.enabled == "function" && (g.enabled = g.enabled());
|
|
995
|
+
const m = s.defaultQueryOptions(g);
|
|
996
|
+
return m._optimisticResults = "optimistic", m;
|
|
997
|
+
}), u = new n(s, r.value), a = r.value.shallow ? I(u.getCurrentResult()) : U(u.getCurrentResult());
|
|
998
|
+
let h = () => {
|
|
999
|
+
};
|
|
1000
|
+
h = u.subscribe((o) => {
|
|
1001
|
+
S(a, o);
|
|
1002
|
+
});
|
|
1003
|
+
const f = () => {
|
|
1004
|
+
u.setOptions(r.value), S(a, u.getCurrentResult());
|
|
1005
|
+
};
|
|
1006
|
+
y(r, f), v(() => {
|
|
1007
|
+
h();
|
|
1008
|
+
});
|
|
1009
|
+
const p = (...o) => (f(), a.refetch(...o)), d = () => new Promise(
|
|
1010
|
+
(o, g) => {
|
|
1011
|
+
let m = () => {
|
|
1012
|
+
};
|
|
1013
|
+
const E = () => {
|
|
1014
|
+
if (r.value.enabled !== !1) {
|
|
1015
|
+
u.setOptions(r.value);
|
|
1016
|
+
const A = u.getOptimisticResult(
|
|
1017
|
+
r.value
|
|
1018
|
+
);
|
|
1019
|
+
A.isStale ? (m(), u.fetchOptimistic(r.value).then(o, (K) => {
|
|
1020
|
+
O(r.value.throwOnError, [
|
|
1021
|
+
K,
|
|
1022
|
+
u.getCurrentQuery()
|
|
1023
|
+
]) ? g(K) : o(u.getCurrentResult());
|
|
1024
|
+
})) : (m(), o(A));
|
|
1025
|
+
}
|
|
1026
|
+
};
|
|
1027
|
+
E(), m = y(r, E);
|
|
1028
|
+
}
|
|
1029
|
+
);
|
|
1030
|
+
y(
|
|
1031
|
+
() => a.error,
|
|
1032
|
+
(o) => {
|
|
1033
|
+
if (a.isError && !a.isFetching && O(r.value.throwOnError, [
|
|
1034
|
+
o,
|
|
1035
|
+
u.getCurrentQuery()
|
|
1036
|
+
]))
|
|
1037
|
+
throw o;
|
|
1038
|
+
}
|
|
1039
|
+
);
|
|
1040
|
+
const c = r.value.shallow ? R(a) : P(a), l = x(c);
|
|
1041
|
+
for (const o in a)
|
|
1042
|
+
typeof a[o] == "function" && (l[o] = a[o]);
|
|
1043
|
+
return l.suspense = d, l.refetch = p, l;
|
|
1044
|
+
}
|
|
1045
|
+
function dt(n, t) {
|
|
1046
|
+
return V(b, n, t);
|
|
1047
|
+
}
|
|
1048
|
+
function yt({
|
|
1049
|
+
queries: n,
|
|
1050
|
+
...t
|
|
1051
|
+
}, e) {
|
|
1052
|
+
process.env.NODE_ENV === "development" && (C() || console.warn(
|
|
1053
|
+
'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
1054
|
+
));
|
|
1055
|
+
const s = e || q(), r = Q(() => {
|
|
1056
|
+
const f = typeof n == "function" ? n() : n;
|
|
1057
|
+
return M(f).map((d) => {
|
|
1058
|
+
const c = i(d);
|
|
1059
|
+
typeof c.enabled == "function" && (c.enabled = d.enabled());
|
|
1060
|
+
const l = s.defaultQueryOptions(c);
|
|
1061
|
+
return l._optimisticResults = "optimistic", l;
|
|
1062
|
+
});
|
|
1063
|
+
}), u = new Z(
|
|
1064
|
+
s,
|
|
1065
|
+
r.value,
|
|
1066
|
+
t
|
|
1067
|
+
), a = () => {
|
|
1068
|
+
const [f, p] = u.getOptimisticResult(
|
|
1069
|
+
r.value,
|
|
1070
|
+
t.combine
|
|
1071
|
+
);
|
|
1072
|
+
return p(
|
|
1073
|
+
f.map((d, c) => ({
|
|
1074
|
+
...d,
|
|
1075
|
+
refetch: async (...l) => {
|
|
1076
|
+
const [{ [c]: o }] = u.getOptimisticResult(
|
|
1077
|
+
r.value,
|
|
1078
|
+
t.combine
|
|
1079
|
+
);
|
|
1080
|
+
return o.refetch(...l);
|
|
1081
|
+
}
|
|
1082
|
+
}))
|
|
1083
|
+
);
|
|
1084
|
+
}, h = N(a());
|
|
1085
|
+
return y(r, (f) => {
|
|
1086
|
+
u.setQueries(
|
|
1087
|
+
f,
|
|
1088
|
+
t
|
|
1089
|
+
), h.value = a();
|
|
1090
|
+
}), v(() => {
|
|
1091
|
+
}), t.shallow ? R(h) : P(h);
|
|
1092
|
+
}
|
|
1093
|
+
function pt(n, t) {
|
|
1094
|
+
return V(
|
|
1095
|
+
X,
|
|
1096
|
+
n,
|
|
1097
|
+
t
|
|
1098
|
+
);
|
|
1099
|
+
}
|
|
1100
|
+
function gt(n, t) {
|
|
1101
|
+
process.env.NODE_ENV === "development" && (C() || console.warn(
|
|
1102
|
+
'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
1103
|
+
));
|
|
1104
|
+
const e = t || q(), s = Q(() => {
|
|
1105
|
+
const c = typeof n == "function" ? n() : n;
|
|
1106
|
+
return e.defaultMutationOptions(i(c));
|
|
1107
|
+
}), r = new B(e, s.value), u = s.value.shallow ?? !1, a = u ? I(r.getCurrentResult()) : U(r.getCurrentResult()), h = r.subscribe((c) => {
|
|
1108
|
+
S(a, c);
|
|
1109
|
+
}), f = (c, l) => {
|
|
1110
|
+
r.mutate(c, l).catch(() => {
|
|
1111
|
+
});
|
|
1112
|
+
};
|
|
1113
|
+
y(s, () => {
|
|
1114
|
+
r.setOptions(s.value);
|
|
1115
|
+
}), v(() => {
|
|
1116
|
+
h();
|
|
1117
|
+
});
|
|
1118
|
+
const p = u ? R(a) : P(a), d = x(p);
|
|
1119
|
+
return y(
|
|
1120
|
+
() => a.error,
|
|
1121
|
+
(c) => {
|
|
1122
|
+
if (c && O(s.value.throwOnError, [c, void 0]))
|
|
1123
|
+
throw c;
|
|
1124
|
+
}
|
|
1125
|
+
), {
|
|
1126
|
+
...d,
|
|
1127
|
+
mutate: f,
|
|
1128
|
+
mutateAsync: a.mutateAsync,
|
|
1129
|
+
reset: a.reset
|
|
1130
|
+
};
|
|
1131
|
+
}
|
|
1132
|
+
function mt(n = {}, t) {
|
|
1133
|
+
process.env.NODE_ENV === "development" && (C() || console.warn(
|
|
1134
|
+
'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
1135
|
+
));
|
|
1136
|
+
const e = t || q(), s = $(), r = () => {
|
|
1137
|
+
const a = typeof n == "function" ? n() : n;
|
|
1138
|
+
s.value = e.isFetching(i(a));
|
|
1139
|
+
}, u = e.queryCache.subscribe(r);
|
|
1140
|
+
return k(r), v(() => {
|
|
1141
|
+
u();
|
|
1142
|
+
}), s;
|
|
1143
|
+
}
|
|
1144
|
+
function Qt(n = {}, t) {
|
|
1145
|
+
process.env.NODE_ENV === "development" && (C() || console.warn(
|
|
1146
|
+
'vue-query composable like "useQuery()" should only be used inside a "setup()" function or a running effect scope. They might otherwise lead to memory leaks.'
|
|
1147
|
+
));
|
|
1148
|
+
const e = t || q(), s = ut(
|
|
1149
|
+
{
|
|
1150
|
+
filters: Q(() => ({
|
|
1151
|
+
...i(typeof n == "function" ? n() : n),
|
|
1152
|
+
status: "pending"
|
|
1153
|
+
}))
|
|
1154
|
+
},
|
|
1155
|
+
e
|
|
1156
|
+
);
|
|
1157
|
+
return Q(() => s.value.length);
|
|
1158
|
+
}
|
|
1159
|
+
function w(n, t) {
|
|
1160
|
+
return n.findAll(t.filters).map(
|
|
1161
|
+
(e) => t.select ? t.select(e) : e.state
|
|
1162
|
+
);
|
|
1163
|
+
}
|
|
1164
|
+
function ut(n = {}, t) {
|
|
1165
|
+
const e = Q(() => {
|
|
1166
|
+
const a = typeof n == "function" ? n() : n;
|
|
1167
|
+
return {
|
|
1168
|
+
filters: i(a.filters),
|
|
1169
|
+
select: a.select
|
|
1170
|
+
};
|
|
1171
|
+
}), s = (t || q()).mutationCache, r = N(w(s, e.value)), u = s.subscribe(() => {
|
|
1172
|
+
r.value = w(s, e.value);
|
|
1173
|
+
});
|
|
1174
|
+
return y(e, () => {
|
|
1175
|
+
r.value = w(s, e.value);
|
|
1176
|
+
}), v(() => {
|
|
1177
|
+
u();
|
|
1178
|
+
}), R(r);
|
|
1179
|
+
}
|
|
1180
|
+
export {
|
|
1181
|
+
X as InfiniteQueryObserver,
|
|
1182
|
+
rt as MutationCache,
|
|
1183
|
+
B as MutationObserver,
|
|
1184
|
+
Z as QueriesObserver,
|
|
1185
|
+
st as QueryCache,
|
|
1186
|
+
nt as QueryClient,
|
|
1187
|
+
b as QueryObserver,
|
|
1188
|
+
ht as UniQueryPlugin,
|
|
1189
|
+
z as VUE_QUERY_CLIENT,
|
|
1190
|
+
ht as VueQueryPlugin,
|
|
1191
|
+
Y as hashQueryKey,
|
|
1192
|
+
ft as infiniteQueryOptions,
|
|
1193
|
+
lt as queryOptions,
|
|
1194
|
+
O as shouldThrowError,
|
|
1195
|
+
pt as useInfiniteQuery,
|
|
1196
|
+
mt as useIsFetching,
|
|
1197
|
+
Qt as useIsMutating,
|
|
1198
|
+
gt as useMutation,
|
|
1199
|
+
ut as useMutationState,
|
|
1200
|
+
yt as useQueries,
|
|
1201
|
+
dt as useQuery,
|
|
1202
|
+
q as useQueryClient
|
|
1203
|
+
};
|