@epoch32/visage 1.1.3 → 1.1.4
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/dist/api/index.js +55 -4085
- package/dist/charts/index.js +48 -2806
- package/dist/devtools/index.js +18 -4771
- package/dist/dom/index.js +32 -1639
- package/dist/form/index.js +13 -1498
- package/dist/index-061jf06a.js +848 -0
- package/dist/index-0madxn60.js +442 -0
- package/dist/index-1xtrtz1t.js +256 -0
- package/dist/index-2zz0g2n2.js +212 -0
- package/dist/index-5s255b3w.js +303 -0
- package/dist/index-6kfe1nr4.js +1179 -0
- package/dist/index-8czhpea8.js +338 -0
- package/dist/index-8x8xz80v.js +727 -0
- package/dist/index-921pn75b.js +0 -0
- package/dist/index-965ryh36.js +537 -0
- package/dist/index-9fvarkrx.js +98 -0
- package/dist/index-a4xns6cc.js +219 -0
- package/dist/index-b5wc752a.js +1696 -0
- package/dist/index-df5e614s.js +334 -0
- package/dist/index-dyvgtp43.js +1094 -0
- package/dist/index-grhdtcb5.js +234 -0
- package/dist/index-h6tjqk6e.js +158 -0
- package/dist/index-js199er4.js +101 -0
- package/dist/index-x2rs3vab.js +124 -0
- package/dist/index-y9bq7h9g.js +1162 -0
- package/dist/index-zr6cvset.js +2092 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +458 -11920
- package/dist/jsx-runtime/index.js +13 -1719
- package/dist/query/index.js +47 -2505
- package/dist/router/index.js +25 -1945
- package/dist/rpc/index.js +39 -3567
- package/dist/server/index.js +11 -1256
- package/dist/signals/index.js +52 -1160
- package/dist/style/index.js +77 -2429
- package/dist/template/index.js +7 -1232
- package/dist/ui/index.d.ts +1 -1
- package/dist/ui/index.js +150 -4249
- package/dist/ui/tabs.d.ts +23 -1
- package/dist/virtual/index.js +12 -2044
- package/dist/vite/index.js +5 -744
- package/package.json +2 -2
- package/src/dom/render.ts +20 -7
- package/src/index.ts +2 -0
- package/src/signals/computed.ts +19 -12
- package/src/signals/effect.ts +7 -7
- package/src/signals/signal.ts +16 -12
- package/src/signals/system.ts +50 -21
- package/src/ui/index.ts +2 -0
- package/src/ui/tabs.tsx +211 -10
- package/src/ui/utils.ts +1 -3
|
@@ -0,0 +1,1162 @@
|
|
|
1
|
+
import {
|
|
2
|
+
SIGNAL_BRAND2,
|
|
3
|
+
COMPUTED_BRAND2,
|
|
4
|
+
untrack2,
|
|
5
|
+
computed2,
|
|
6
|
+
onCleanup2,
|
|
7
|
+
createContext2,
|
|
8
|
+
useContext2,
|
|
9
|
+
effect2,
|
|
10
|
+
signal2
|
|
11
|
+
} from "./index-6kfe1nr4.js";
|
|
12
|
+
import {
|
|
13
|
+
SuspenseContext2
|
|
14
|
+
} from "./index-a4xns6cc.js";
|
|
15
|
+
|
|
16
|
+
// src/query/focus-manager.ts
|
|
17
|
+
class FocusManager2 {
|
|
18
|
+
_focused;
|
|
19
|
+
_listeners = new Set;
|
|
20
|
+
_cleanup;
|
|
21
|
+
constructor() {
|
|
22
|
+
this.setupEventListener();
|
|
23
|
+
}
|
|
24
|
+
setupEventListener() {
|
|
25
|
+
if (typeof window === "undefined" || typeof window.addEventListener === "undefined") {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const listener = () => {
|
|
29
|
+
this.notify(this.isFocused());
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener("visibilitychange", listener, false);
|
|
32
|
+
window.addEventListener("focus", listener, false);
|
|
33
|
+
this._cleanup = () => {
|
|
34
|
+
window.removeEventListener("visibilitychange", listener);
|
|
35
|
+
window.removeEventListener("focus", listener);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
setFocused(focused) {
|
|
39
|
+
this._focused = focused;
|
|
40
|
+
this.notify(this.isFocused());
|
|
41
|
+
}
|
|
42
|
+
isFocused() {
|
|
43
|
+
if (typeof this._focused === "boolean") {
|
|
44
|
+
return this._focused;
|
|
45
|
+
}
|
|
46
|
+
if (typeof document !== "undefined" && typeof document.visibilityState === "string") {
|
|
47
|
+
return document.visibilityState !== "hidden";
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
}
|
|
51
|
+
subscribe(listener) {
|
|
52
|
+
this._listeners.add(listener);
|
|
53
|
+
return () => {
|
|
54
|
+
this._listeners.delete(listener);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
notify(focused) {
|
|
58
|
+
for (const listener of this._listeners) {
|
|
59
|
+
try {
|
|
60
|
+
listener(focused);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
console.error("Error in focus listener:", err);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
cleanup() {
|
|
67
|
+
this._cleanup?.();
|
|
68
|
+
this._listeners.clear();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
var focusManager2 = new FocusManager2;
|
|
72
|
+
|
|
73
|
+
// src/query/mutation-cache.ts
|
|
74
|
+
class Mutation2 {
|
|
75
|
+
options;
|
|
76
|
+
data;
|
|
77
|
+
error;
|
|
78
|
+
status;
|
|
79
|
+
submittedAt;
|
|
80
|
+
variables;
|
|
81
|
+
isIdle;
|
|
82
|
+
isPending;
|
|
83
|
+
isLoading;
|
|
84
|
+
isSuccess;
|
|
85
|
+
isError;
|
|
86
|
+
constructor(options) {
|
|
87
|
+
this.options = options;
|
|
88
|
+
this.data = signal2(undefined);
|
|
89
|
+
this.error = signal2(null);
|
|
90
|
+
this.status = signal2("idle");
|
|
91
|
+
this.submittedAt = signal2(0);
|
|
92
|
+
this.variables = signal2(undefined);
|
|
93
|
+
this.isIdle = computed2(() => this.status() === "idle");
|
|
94
|
+
this.isPending = computed2(() => this.status() === "pending");
|
|
95
|
+
this.isLoading = this.isPending;
|
|
96
|
+
this.isSuccess = computed2(() => this.status() === "success");
|
|
97
|
+
this.isError = computed2(() => this.status() === "error");
|
|
98
|
+
}
|
|
99
|
+
async execute(variables, mutateOptions) {
|
|
100
|
+
this.status.set("pending");
|
|
101
|
+
this.error.set(null);
|
|
102
|
+
this.variables.set(variables);
|
|
103
|
+
this.submittedAt.set(Date.now());
|
|
104
|
+
let context;
|
|
105
|
+
try {
|
|
106
|
+
if (this.options.onMutate) {
|
|
107
|
+
const res = await this.options.onMutate(variables);
|
|
108
|
+
if (res !== undefined) {
|
|
109
|
+
context = res;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
const result = await this.options.mutationFn(variables);
|
|
113
|
+
this.data.set(result);
|
|
114
|
+
this.status.set("success");
|
|
115
|
+
try {
|
|
116
|
+
await this.options.onSuccess?.(result, variables, context);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
console.error("Error in mutation onSuccess:", err);
|
|
119
|
+
}
|
|
120
|
+
try {
|
|
121
|
+
mutateOptions?.onSuccess?.(result, variables, context);
|
|
122
|
+
} catch (err) {
|
|
123
|
+
console.error("Error in mutateOptions onSuccess:", err);
|
|
124
|
+
}
|
|
125
|
+
try {
|
|
126
|
+
await this.options.onSettled?.(result, null, variables, context);
|
|
127
|
+
} catch (err) {
|
|
128
|
+
console.error("Error in mutation onSettled:", err);
|
|
129
|
+
}
|
|
130
|
+
try {
|
|
131
|
+
mutateOptions?.onSettled?.(result, null, variables, context);
|
|
132
|
+
} catch (err) {
|
|
133
|
+
console.error("Error in mutateOptions onSettled:", err);
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
} catch (err) {
|
|
137
|
+
this.error.set(err);
|
|
138
|
+
this.status.set("error");
|
|
139
|
+
try {
|
|
140
|
+
await this.options.onError?.(err, variables, context);
|
|
141
|
+
} catch (e) {
|
|
142
|
+
console.error("Error in mutation onError:", e);
|
|
143
|
+
}
|
|
144
|
+
try {
|
|
145
|
+
mutateOptions?.onError?.(err, variables, context);
|
|
146
|
+
} catch (e) {
|
|
147
|
+
console.error("Error in mutateOptions onError:", e);
|
|
148
|
+
}
|
|
149
|
+
try {
|
|
150
|
+
await this.options.onSettled?.(undefined, err, variables, context);
|
|
151
|
+
} catch (e) {
|
|
152
|
+
console.error("Error in mutation onSettled:", e);
|
|
153
|
+
}
|
|
154
|
+
try {
|
|
155
|
+
mutateOptions?.onSettled?.(undefined, err, variables, context);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
console.error("Error in mutateOptions onSettled:", e);
|
|
158
|
+
}
|
|
159
|
+
throw err;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
reset() {
|
|
163
|
+
this.data.set(undefined);
|
|
164
|
+
this.error.set(null);
|
|
165
|
+
this.status.set("idle");
|
|
166
|
+
this.submittedAt.set(0);
|
|
167
|
+
this.variables.set(undefined);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
class MutationCache2 {
|
|
172
|
+
mutations = new Set;
|
|
173
|
+
build(options) {
|
|
174
|
+
const mutation = new Mutation2(options);
|
|
175
|
+
this.mutations.add(mutation);
|
|
176
|
+
return mutation;
|
|
177
|
+
}
|
|
178
|
+
remove(mutation) {
|
|
179
|
+
this.mutations.delete(mutation);
|
|
180
|
+
}
|
|
181
|
+
clear() {
|
|
182
|
+
this.mutations.clear();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// src/query/online-manager.ts
|
|
187
|
+
class OnlineManager2 {
|
|
188
|
+
_online;
|
|
189
|
+
_listeners = new Set;
|
|
190
|
+
_cleanup;
|
|
191
|
+
constructor() {
|
|
192
|
+
this.setupEventListener();
|
|
193
|
+
}
|
|
194
|
+
setupEventListener() {
|
|
195
|
+
if (typeof window === "undefined" || typeof window.addEventListener === "undefined") {
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
const onlineListener = () => this.notify(true);
|
|
199
|
+
const offlineListener = () => this.notify(false);
|
|
200
|
+
window.addEventListener("online", onlineListener, false);
|
|
201
|
+
window.addEventListener("offline", offlineListener, false);
|
|
202
|
+
this._cleanup = () => {
|
|
203
|
+
window.removeEventListener("online", onlineListener);
|
|
204
|
+
window.removeEventListener("offline", offlineListener);
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
setOnline(online) {
|
|
208
|
+
this._online = online;
|
|
209
|
+
this.notify(this.isOnline());
|
|
210
|
+
}
|
|
211
|
+
isOnline() {
|
|
212
|
+
if (typeof this._online === "boolean") {
|
|
213
|
+
return this._online;
|
|
214
|
+
}
|
|
215
|
+
if (typeof navigator !== "undefined" && typeof navigator.onLine === "boolean") {
|
|
216
|
+
return navigator.onLine;
|
|
217
|
+
}
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
subscribe(listener) {
|
|
221
|
+
this._listeners.add(listener);
|
|
222
|
+
return () => {
|
|
223
|
+
this._listeners.delete(listener);
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
notify(online) {
|
|
227
|
+
for (const listener of this._listeners) {
|
|
228
|
+
try {
|
|
229
|
+
listener(online);
|
|
230
|
+
} catch (err) {
|
|
231
|
+
console.error("Error in online listener:", err);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
cleanup() {
|
|
236
|
+
this._cleanup?.();
|
|
237
|
+
this._listeners.clear();
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
var onlineManager2 = new OnlineManager2;
|
|
241
|
+
|
|
242
|
+
// src/query/utils.ts
|
|
243
|
+
function isPlainObject2(value) {
|
|
244
|
+
if (value === null || typeof value !== "object")
|
|
245
|
+
return false;
|
|
246
|
+
const proto = Object.getPrototypeOf(value);
|
|
247
|
+
return proto === null || proto === Object.prototype;
|
|
248
|
+
}
|
|
249
|
+
function hashKey2(queryKey) {
|
|
250
|
+
return JSON.stringify(queryKey, (_key, val) => {
|
|
251
|
+
if (isPlainObject2(val)) {
|
|
252
|
+
return Object.keys(val).sort().reduce((result, k) => {
|
|
253
|
+
result[k] = val[k];
|
|
254
|
+
return result;
|
|
255
|
+
}, {});
|
|
256
|
+
}
|
|
257
|
+
return val;
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
function deepEqual2(a, b) {
|
|
261
|
+
if (Object.is(a, b))
|
|
262
|
+
return true;
|
|
263
|
+
if (typeof a !== "object" || a === null || typeof b !== "object" || b === null) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
if (Array.isArray(a) !== Array.isArray(b))
|
|
267
|
+
return false;
|
|
268
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
269
|
+
if (a.length !== b.length)
|
|
270
|
+
return false;
|
|
271
|
+
for (let i = 0;i < a.length; i++) {
|
|
272
|
+
if (!deepEqual2(a[i], b[i]))
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
return true;
|
|
276
|
+
}
|
|
277
|
+
const keysA = Object.keys(a);
|
|
278
|
+
const keysB = Object.keys(b);
|
|
279
|
+
if (keysA.length !== keysB.length)
|
|
280
|
+
return false;
|
|
281
|
+
for (const key of keysA) {
|
|
282
|
+
if (!Object.hasOwn(b, key))
|
|
283
|
+
return false;
|
|
284
|
+
if (!deepEqual2(a[key], b[key])) {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
function partialDeepEqual2(a, b) {
|
|
291
|
+
if (Object.is(a, b))
|
|
292
|
+
return true;
|
|
293
|
+
if (a === undefined || a === null || b === undefined || b === null) {
|
|
294
|
+
return a === b;
|
|
295
|
+
}
|
|
296
|
+
if (Array.isArray(a) && Array.isArray(b)) {
|
|
297
|
+
if (a.length > b.length)
|
|
298
|
+
return false;
|
|
299
|
+
for (let i = 0;i < a.length; i++) {
|
|
300
|
+
if (!partialDeepEqual2(a[i], b[i]))
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
return true;
|
|
304
|
+
}
|
|
305
|
+
if (isPlainObject2(a) && isPlainObject2(b)) {
|
|
306
|
+
for (const key of Object.keys(a)) {
|
|
307
|
+
if (!(key in b))
|
|
308
|
+
return false;
|
|
309
|
+
if (!partialDeepEqual2(a[key], b[key]))
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
return true;
|
|
313
|
+
}
|
|
314
|
+
return false;
|
|
315
|
+
}
|
|
316
|
+
function matchQuery2(filters, query) {
|
|
317
|
+
if (!filters)
|
|
318
|
+
return true;
|
|
319
|
+
if (filters.queryKey !== undefined) {
|
|
320
|
+
const filterKey = Array.isArray(filters.queryKey) ? filters.queryKey : [filters.queryKey];
|
|
321
|
+
const queryKey = Array.isArray(query.queryKey) ? query.queryKey : [query.queryKey];
|
|
322
|
+
if (filters.exact) {
|
|
323
|
+
if (filterKey.length !== queryKey.length)
|
|
324
|
+
return false;
|
|
325
|
+
if (!deepEqual2(filterKey, queryKey))
|
|
326
|
+
return false;
|
|
327
|
+
} else {
|
|
328
|
+
if (filterKey.length > queryKey.length)
|
|
329
|
+
return false;
|
|
330
|
+
for (let i = 0;i < filterKey.length; i++) {
|
|
331
|
+
if (!partialDeepEqual2(filterKey[i], queryKey[i])) {
|
|
332
|
+
return false;
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (filters.type === "active" && query.observers.size === 0) {
|
|
338
|
+
return false;
|
|
339
|
+
}
|
|
340
|
+
if (filters.type === "inactive" && query.observers.size > 0) {
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
if (filters.stale !== undefined && query.isStale() !== filters.stale) {
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
if (filters.fetchStatus !== undefined && query.fetchStatus() !== filters.fetchStatus) {
|
|
347
|
+
return false;
|
|
348
|
+
}
|
|
349
|
+
if (filters.predicate && !filters.predicate(query)) {
|
|
350
|
+
return false;
|
|
351
|
+
}
|
|
352
|
+
return true;
|
|
353
|
+
}
|
|
354
|
+
function sleep2(ms) {
|
|
355
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// src/query/query-cache.ts
|
|
359
|
+
function shouldRetry(failureCount, error, retry) {
|
|
360
|
+
if (retry === false)
|
|
361
|
+
return false;
|
|
362
|
+
if (retry === true)
|
|
363
|
+
return true;
|
|
364
|
+
if (typeof retry === "number")
|
|
365
|
+
return failureCount <= retry;
|
|
366
|
+
if (typeof retry === "function")
|
|
367
|
+
return retry(failureCount, error);
|
|
368
|
+
return failureCount < 3;
|
|
369
|
+
}
|
|
370
|
+
function getRetryDelay(attempt, error, retryDelay) {
|
|
371
|
+
if (typeof retryDelay === "function")
|
|
372
|
+
return retryDelay(attempt, error);
|
|
373
|
+
if (typeof retryDelay === "number")
|
|
374
|
+
return retryDelay;
|
|
375
|
+
return Math.min(1000 * 2 ** attempt, 30000);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
class Query2 {
|
|
379
|
+
queryKey;
|
|
380
|
+
queryHash;
|
|
381
|
+
cache;
|
|
382
|
+
data;
|
|
383
|
+
error;
|
|
384
|
+
status;
|
|
385
|
+
fetchStatus;
|
|
386
|
+
dataUpdatedAt;
|
|
387
|
+
errorUpdatedAt;
|
|
388
|
+
failureCount;
|
|
389
|
+
isInvalidated;
|
|
390
|
+
observers = new Set;
|
|
391
|
+
_gcTimeout = null;
|
|
392
|
+
_abortController = null;
|
|
393
|
+
promise = null;
|
|
394
|
+
defaultGcTime = 5 * 60 * 1000;
|
|
395
|
+
constructor(options) {
|
|
396
|
+
this.queryKey = options.queryKey;
|
|
397
|
+
this.queryHash = options.queryHash;
|
|
398
|
+
this.cache = options.cache;
|
|
399
|
+
const initialData = typeof options.initialData === "function" ? options.initialData() : options.initialData;
|
|
400
|
+
const initialUpdatedAt = initialData !== undefined ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt ?? Date.now() : 0;
|
|
401
|
+
this.data = signal2(initialData);
|
|
402
|
+
this.error = signal2(null);
|
|
403
|
+
this.status = signal2(initialData !== undefined ? "success" : "pending");
|
|
404
|
+
this.fetchStatus = signal2("idle");
|
|
405
|
+
this.dataUpdatedAt = signal2(initialUpdatedAt);
|
|
406
|
+
this.errorUpdatedAt = signal2(0);
|
|
407
|
+
this.failureCount = signal2(0);
|
|
408
|
+
this.isInvalidated = signal2(false);
|
|
409
|
+
}
|
|
410
|
+
get state() {
|
|
411
|
+
return {
|
|
412
|
+
data: this.data(),
|
|
413
|
+
error: this.error(),
|
|
414
|
+
status: this.status(),
|
|
415
|
+
fetchStatus: this.fetchStatus(),
|
|
416
|
+
dataUpdatedAt: this.dataUpdatedAt(),
|
|
417
|
+
errorUpdatedAt: this.errorUpdatedAt(),
|
|
418
|
+
failureCount: this.failureCount(),
|
|
419
|
+
isInvalidated: this.isInvalidated()
|
|
420
|
+
};
|
|
421
|
+
}
|
|
422
|
+
isStale(staleTime = 0) {
|
|
423
|
+
if (this.isInvalidated())
|
|
424
|
+
return true;
|
|
425
|
+
if (this.dataUpdatedAt() === 0)
|
|
426
|
+
return true;
|
|
427
|
+
if (staleTime === Number.POSITIVE_INFINITY)
|
|
428
|
+
return false;
|
|
429
|
+
return Date.now() - this.dataUpdatedAt() >= staleTime;
|
|
430
|
+
}
|
|
431
|
+
addObserver(observer) {
|
|
432
|
+
this.observers.add(observer);
|
|
433
|
+
this.clearGcTimeout();
|
|
434
|
+
}
|
|
435
|
+
removeObserver(observer) {
|
|
436
|
+
this.observers.delete(observer);
|
|
437
|
+
if (this.observers.size === 0) {
|
|
438
|
+
this.scheduleGc(observer.options.gcTime);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
scheduleGc(gcTime) {
|
|
442
|
+
this.clearGcTimeout();
|
|
443
|
+
const duration = gcTime !== undefined ? gcTime : this.defaultGcTime;
|
|
444
|
+
if (duration === Number.POSITIVE_INFINITY)
|
|
445
|
+
return;
|
|
446
|
+
if (duration <= 0) {
|
|
447
|
+
this.cache.remove(this);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
this._gcTimeout = setTimeout(() => {
|
|
451
|
+
if (this.observers.size === 0) {
|
|
452
|
+
this.cache.remove(this);
|
|
453
|
+
}
|
|
454
|
+
}, duration);
|
|
455
|
+
}
|
|
456
|
+
clearGcTimeout() {
|
|
457
|
+
if (this._gcTimeout !== null) {
|
|
458
|
+
clearTimeout(this._gcTimeout);
|
|
459
|
+
this._gcTimeout = null;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
setData(updater, options) {
|
|
463
|
+
const prev = this.data();
|
|
464
|
+
const nextData = typeof updater === "function" ? updater(prev) : updater;
|
|
465
|
+
this.data.set(nextData);
|
|
466
|
+
this.error.set(null);
|
|
467
|
+
this.status.set("success");
|
|
468
|
+
this.isInvalidated.set(false);
|
|
469
|
+
this.dataUpdatedAt.set(options?.updatedAt ?? Date.now());
|
|
470
|
+
this.notifyObservers();
|
|
471
|
+
this.cache.notify({ type: "updated", query: this });
|
|
472
|
+
return nextData;
|
|
473
|
+
}
|
|
474
|
+
invalidate() {
|
|
475
|
+
this.isInvalidated.set(true);
|
|
476
|
+
if (this.observers.size > 0) {
|
|
477
|
+
for (const observer of this.observers) {
|
|
478
|
+
observer.onQueryUpdate();
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
cancel() {
|
|
483
|
+
if (this._abortController) {
|
|
484
|
+
this._abortController.abort();
|
|
485
|
+
this._abortController = null;
|
|
486
|
+
}
|
|
487
|
+
this.fetchStatus.set("idle");
|
|
488
|
+
this.promise = null;
|
|
489
|
+
}
|
|
490
|
+
reset() {
|
|
491
|
+
this.cancel();
|
|
492
|
+
this.data.set(undefined);
|
|
493
|
+
this.error.set(null);
|
|
494
|
+
this.status.set("pending");
|
|
495
|
+
this.fetchStatus.set("idle");
|
|
496
|
+
this.dataUpdatedAt.set(0);
|
|
497
|
+
this.errorUpdatedAt.set(0);
|
|
498
|
+
this.failureCount.set(0);
|
|
499
|
+
this.isInvalidated.set(false);
|
|
500
|
+
this.notifyObservers();
|
|
501
|
+
}
|
|
502
|
+
async fetch(options, fetchOptions) {
|
|
503
|
+
if (this.promise && !fetchOptions?.cancelRefetch) {
|
|
504
|
+
return this.promise;
|
|
505
|
+
}
|
|
506
|
+
if (this._abortController && fetchOptions?.cancelRefetch) {
|
|
507
|
+
this.cancel();
|
|
508
|
+
}
|
|
509
|
+
const controller = new AbortController;
|
|
510
|
+
this._abortController = controller;
|
|
511
|
+
this.fetchStatus.set("fetching");
|
|
512
|
+
const queryFn = options?.queryFn;
|
|
513
|
+
if (!queryFn) {
|
|
514
|
+
this.fetchStatus.set("idle");
|
|
515
|
+
throw new Error(`Missing queryFn for queryKey: ${JSON.stringify(this.queryKey)}`);
|
|
516
|
+
}
|
|
517
|
+
const execFetch = async () => {
|
|
518
|
+
let attempt = 0;
|
|
519
|
+
while (true) {
|
|
520
|
+
if (controller.signal.aborted) {
|
|
521
|
+
this.fetchStatus.set("idle");
|
|
522
|
+
this.promise = null;
|
|
523
|
+
throw new Error("Query was cancelled");
|
|
524
|
+
}
|
|
525
|
+
try {
|
|
526
|
+
const result = await queryFn({
|
|
527
|
+
queryKey: this.queryKey,
|
|
528
|
+
signal: controller.signal,
|
|
529
|
+
meta: options?.meta
|
|
530
|
+
});
|
|
531
|
+
if (controller.signal.aborted) {
|
|
532
|
+
throw new Error("Query was cancelled");
|
|
533
|
+
}
|
|
534
|
+
this.setData(result);
|
|
535
|
+
this.failureCount.set(0);
|
|
536
|
+
this.fetchStatus.set("idle");
|
|
537
|
+
this.promise = null;
|
|
538
|
+
return result;
|
|
539
|
+
} catch (err) {
|
|
540
|
+
if (controller.signal.aborted) {
|
|
541
|
+
this.fetchStatus.set("idle");
|
|
542
|
+
this.promise = null;
|
|
543
|
+
throw err;
|
|
544
|
+
}
|
|
545
|
+
attempt++;
|
|
546
|
+
this.failureCount.set(attempt);
|
|
547
|
+
const canRetry = shouldRetry(attempt, err, options?.retry);
|
|
548
|
+
if (canRetry) {
|
|
549
|
+
const delay = getRetryDelay(attempt, err, options?.retryDelay);
|
|
550
|
+
if (delay > 0) {
|
|
551
|
+
await sleep2(delay);
|
|
552
|
+
}
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
555
|
+
this.error.set(err);
|
|
556
|
+
this.errorUpdatedAt.set(Date.now());
|
|
557
|
+
this.status.set("error");
|
|
558
|
+
this.fetchStatus.set("idle");
|
|
559
|
+
this.promise = null;
|
|
560
|
+
this.notifyObservers();
|
|
561
|
+
throw err;
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
};
|
|
565
|
+
this.promise = execFetch();
|
|
566
|
+
return this.promise;
|
|
567
|
+
}
|
|
568
|
+
notifyObservers() {
|
|
569
|
+
for (const observer of this.observers) {
|
|
570
|
+
observer.onQueryUpdate();
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
destroy() {
|
|
574
|
+
this.cancel();
|
|
575
|
+
this.clearGcTimeout();
|
|
576
|
+
this.observers.clear();
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
class QueryCache2 {
|
|
581
|
+
queries = new Map;
|
|
582
|
+
_subscribers = new Set;
|
|
583
|
+
subscribe(listener) {
|
|
584
|
+
this._subscribers.add(listener);
|
|
585
|
+
return () => this._subscribers.delete(listener);
|
|
586
|
+
}
|
|
587
|
+
notify(event) {
|
|
588
|
+
for (const sub of this._subscribers) {
|
|
589
|
+
sub(event);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
getAll() {
|
|
593
|
+
return Array.from(this.queries.values());
|
|
594
|
+
}
|
|
595
|
+
build(_client, options) {
|
|
596
|
+
const queryHash = hashKey2(options.queryKey);
|
|
597
|
+
let query = this.queries.get(queryHash);
|
|
598
|
+
if (!query) {
|
|
599
|
+
query = new Query2({
|
|
600
|
+
queryKey: options.queryKey,
|
|
601
|
+
queryHash,
|
|
602
|
+
cache: this,
|
|
603
|
+
initialData: options.initialData,
|
|
604
|
+
initialDataUpdatedAt: options.initialDataUpdatedAt
|
|
605
|
+
});
|
|
606
|
+
this.add(query);
|
|
607
|
+
}
|
|
608
|
+
return query;
|
|
609
|
+
}
|
|
610
|
+
get(queryHash) {
|
|
611
|
+
return this.queries.get(queryHash);
|
|
612
|
+
}
|
|
613
|
+
add(query) {
|
|
614
|
+
this.queries.set(query.queryHash, query);
|
|
615
|
+
this.notify({ type: "added", query });
|
|
616
|
+
}
|
|
617
|
+
remove(query) {
|
|
618
|
+
const existing = this.queries.get(query.queryHash);
|
|
619
|
+
if (existing) {
|
|
620
|
+
existing.destroy();
|
|
621
|
+
this.queries.delete(query.queryHash);
|
|
622
|
+
this.notify({ type: "removed", query: existing });
|
|
623
|
+
}
|
|
624
|
+
}
|
|
625
|
+
find(filters) {
|
|
626
|
+
return this.findAll(filters)[0];
|
|
627
|
+
}
|
|
628
|
+
findAll(filters) {
|
|
629
|
+
const results = [];
|
|
630
|
+
for (const query of this.queries.values()) {
|
|
631
|
+
if (matchQuery2(filters, query)) {
|
|
632
|
+
results.push(query);
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
return results;
|
|
636
|
+
}
|
|
637
|
+
clear() {
|
|
638
|
+
for (const query of this.queries.values()) {
|
|
639
|
+
query.destroy();
|
|
640
|
+
}
|
|
641
|
+
this.queries.clear();
|
|
642
|
+
this.notify({ type: "cleared" });
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
|
|
646
|
+
// src/query/query-client.ts
|
|
647
|
+
class QueryClient2 {
|
|
648
|
+
queryCache;
|
|
649
|
+
mutationCache;
|
|
650
|
+
defaultOptions;
|
|
651
|
+
_unsubscribeFocus;
|
|
652
|
+
_unsubscribeOnline;
|
|
653
|
+
_isMounted = false;
|
|
654
|
+
constructor(config = {}) {
|
|
655
|
+
this.defaultOptions = config.defaultOptions ?? {};
|
|
656
|
+
this.queryCache = config.queryCache ?? new QueryCache2;
|
|
657
|
+
this.mutationCache = config.mutationCache ?? new MutationCache2;
|
|
658
|
+
this.mount();
|
|
659
|
+
if (typeof window !== "undefined" && window.__VISAGE_DEVTOOLS__) {
|
|
660
|
+
window.__VISAGE_DEVTOOLS__.attachQueryClient(this);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
mount() {
|
|
664
|
+
if (this._isMounted)
|
|
665
|
+
return;
|
|
666
|
+
this._isMounted = true;
|
|
667
|
+
this._unsubscribeFocus = focusManager2.subscribe((focused) => {
|
|
668
|
+
if (focused) {
|
|
669
|
+
this.onWindowFocus();
|
|
670
|
+
}
|
|
671
|
+
});
|
|
672
|
+
this._unsubscribeOnline = onlineManager2.subscribe((online) => {
|
|
673
|
+
if (online) {
|
|
674
|
+
this.onOnline();
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
}
|
|
678
|
+
unmount() {
|
|
679
|
+
this._isMounted = false;
|
|
680
|
+
this._unsubscribeFocus?.();
|
|
681
|
+
this._unsubscribeOnline?.();
|
|
682
|
+
}
|
|
683
|
+
onWindowFocus() {
|
|
684
|
+
const activeQueries = this.queryCache.findAll({ type: "active" });
|
|
685
|
+
for (const query of activeQueries) {
|
|
686
|
+
const observer = Array.from(query.observers)[0];
|
|
687
|
+
const options = observer?.options ?? this.defaultOptions.queries ?? {};
|
|
688
|
+
const refetchOnFocus = options.refetchOnWindowFocus ?? true;
|
|
689
|
+
if (refetchOnFocus === "always" || refetchOnFocus && query.isStale(options.staleTime)) {
|
|
690
|
+
query.fetch(options).catch(() => {});
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
}
|
|
694
|
+
onOnline() {
|
|
695
|
+
const activeQueries = this.queryCache.findAll({ type: "active" });
|
|
696
|
+
for (const query of activeQueries) {
|
|
697
|
+
const observer = Array.from(query.observers)[0];
|
|
698
|
+
const options = observer?.options ?? this.defaultOptions.queries ?? {};
|
|
699
|
+
const refetchOnReconnect = options.refetchOnReconnect ?? true;
|
|
700
|
+
if (refetchOnReconnect === "always" || refetchOnReconnect && query.isStale(options.staleTime)) {
|
|
701
|
+
query.fetch(options).catch(() => {});
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
}
|
|
705
|
+
getDefaultOptions() {
|
|
706
|
+
return this.defaultOptions;
|
|
707
|
+
}
|
|
708
|
+
setDefaultOptions(options) {
|
|
709
|
+
this.defaultOptions = options;
|
|
710
|
+
}
|
|
711
|
+
getQueryCache() {
|
|
712
|
+
return this.queryCache;
|
|
713
|
+
}
|
|
714
|
+
getMutationCache() {
|
|
715
|
+
return this.mutationCache;
|
|
716
|
+
}
|
|
717
|
+
getQueryData(queryKey) {
|
|
718
|
+
const queryHash = hashKey2(queryKey);
|
|
719
|
+
const query = this.queryCache.get(queryHash);
|
|
720
|
+
return query?.data();
|
|
721
|
+
}
|
|
722
|
+
setQueryData(queryKey, updater, options) {
|
|
723
|
+
const query = this.queryCache.build(this, {
|
|
724
|
+
queryKey,
|
|
725
|
+
...this.defaultOptions.queries
|
|
726
|
+
});
|
|
727
|
+
return query.setData(updater, options);
|
|
728
|
+
}
|
|
729
|
+
getQueryState(queryKey) {
|
|
730
|
+
const queryHash = hashKey2(queryKey);
|
|
731
|
+
const query = this.queryCache.get(queryHash);
|
|
732
|
+
return query?.state;
|
|
733
|
+
}
|
|
734
|
+
async fetchQuery(options) {
|
|
735
|
+
const mergedOptions = {
|
|
736
|
+
...this.defaultOptions.queries,
|
|
737
|
+
...options
|
|
738
|
+
};
|
|
739
|
+
const query = this.queryCache.build(this, mergedOptions);
|
|
740
|
+
if (!query.isStale(mergedOptions.staleTime) && query.data() !== undefined) {
|
|
741
|
+
return query.data();
|
|
742
|
+
}
|
|
743
|
+
return query.fetch(mergedOptions);
|
|
744
|
+
}
|
|
745
|
+
async prefetchQuery(options) {
|
|
746
|
+
try {
|
|
747
|
+
await this.fetchQuery(options);
|
|
748
|
+
} catch {}
|
|
749
|
+
}
|
|
750
|
+
async invalidateQueries(filters) {
|
|
751
|
+
const queries = this.queryCache.findAll(filters);
|
|
752
|
+
const promises = [];
|
|
753
|
+
for (const query of queries) {
|
|
754
|
+
query.invalidate();
|
|
755
|
+
if (query.observers.size > 0) {
|
|
756
|
+
const observer = Array.from(query.observers)[0];
|
|
757
|
+
const options = observer?.options ?? this.defaultOptions.queries ?? {};
|
|
758
|
+
promises.push(query.fetch(options).catch(() => {}));
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
await Promise.all(promises);
|
|
762
|
+
}
|
|
763
|
+
async refetchQueries(filters) {
|
|
764
|
+
const queries = this.queryCache.findAll(filters);
|
|
765
|
+
const promises = [];
|
|
766
|
+
for (const query of queries) {
|
|
767
|
+
if (query.observers.size > 0) {
|
|
768
|
+
const observer = Array.from(query.observers)[0];
|
|
769
|
+
const options = observer?.options ?? this.defaultOptions.queries ?? {};
|
|
770
|
+
promises.push(query.fetch(options, { cancelRefetch: true }).catch(() => {}));
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
await Promise.all(promises);
|
|
774
|
+
}
|
|
775
|
+
cancelQueries(filters) {
|
|
776
|
+
const queries = this.queryCache.findAll(filters);
|
|
777
|
+
for (const query of queries) {
|
|
778
|
+
query.cancel();
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
removeQueries(filters) {
|
|
782
|
+
const queries = this.queryCache.findAll(filters);
|
|
783
|
+
for (const query of queries) {
|
|
784
|
+
this.queryCache.remove(query);
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
async resetQueries(filters) {
|
|
788
|
+
const queries = this.queryCache.findAll(filters);
|
|
789
|
+
const promises = [];
|
|
790
|
+
for (const query of queries) {
|
|
791
|
+
query.reset();
|
|
792
|
+
if (query.observers.size > 0) {
|
|
793
|
+
const observer = Array.from(query.observers)[0];
|
|
794
|
+
const options = observer?.options ?? this.defaultOptions.queries ?? {};
|
|
795
|
+
promises.push(query.fetch(options).catch(() => {}));
|
|
796
|
+
}
|
|
797
|
+
}
|
|
798
|
+
await Promise.all(promises);
|
|
799
|
+
}
|
|
800
|
+
clear() {
|
|
801
|
+
this.queryCache.clear();
|
|
802
|
+
this.mutationCache.clear();
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
var QueryClientContext2 = createContext2(null);
|
|
806
|
+
var defaultGlobalClient = null;
|
|
807
|
+
function getDefaultGlobalClient() {
|
|
808
|
+
if (!defaultGlobalClient) {
|
|
809
|
+
defaultGlobalClient = new QueryClient2;
|
|
810
|
+
}
|
|
811
|
+
return defaultGlobalClient;
|
|
812
|
+
}
|
|
813
|
+
function QueryClientProvider2(props) {
|
|
814
|
+
return QueryClientContext2.Provider({
|
|
815
|
+
value: props.client,
|
|
816
|
+
children: props.children
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
function useQueryClient2(client) {
|
|
820
|
+
if (client)
|
|
821
|
+
return client;
|
|
822
|
+
const ctxClient = useContext2(QueryClientContext2);
|
|
823
|
+
return ctxClient ?? getDefaultGlobalClient();
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
// src/query/create-mutation.ts
|
|
827
|
+
function createMutation2(options, client) {
|
|
828
|
+
const queryClient = useQueryClient2(client);
|
|
829
|
+
const resolveOptions = () => typeof options === "function" ? options() : options;
|
|
830
|
+
const defaults = queryClient.getDefaultOptions().mutations ?? {};
|
|
831
|
+
const mergedOpts = { ...defaults, ...resolveOptions() };
|
|
832
|
+
const mutation = queryClient.mutationCache.build(mergedOpts);
|
|
833
|
+
const mutate = (variables, mutateOptions) => {
|
|
834
|
+
mutation.execute(variables, mutateOptions).catch(() => {});
|
|
835
|
+
};
|
|
836
|
+
const mutateAsync = (variables, mutateOptions) => {
|
|
837
|
+
return mutation.execute(variables, mutateOptions);
|
|
838
|
+
};
|
|
839
|
+
const accessor = () => {
|
|
840
|
+
return mutation.data();
|
|
841
|
+
};
|
|
842
|
+
Object.defineProperties(accessor, {
|
|
843
|
+
[SIGNAL_BRAND2]: { value: true },
|
|
844
|
+
[COMPUTED_BRAND2]: { value: true },
|
|
845
|
+
value: { get: () => mutation.data() },
|
|
846
|
+
mutate: { value: mutate },
|
|
847
|
+
mutateAsync: { value: mutateAsync },
|
|
848
|
+
data: { get: () => mutation.data },
|
|
849
|
+
error: { get: () => mutation.error },
|
|
850
|
+
status: { get: () => mutation.status },
|
|
851
|
+
isIdle: { get: () => mutation.isIdle },
|
|
852
|
+
isPending: { get: () => mutation.isPending },
|
|
853
|
+
isLoading: { get: () => mutation.isLoading },
|
|
854
|
+
isSuccess: { get: () => mutation.isSuccess },
|
|
855
|
+
isError: { get: () => mutation.isError },
|
|
856
|
+
reset: { value: () => mutation.reset() },
|
|
857
|
+
variables: { get: () => mutation.variables },
|
|
858
|
+
submittedAt: { get: () => mutation.submittedAt }
|
|
859
|
+
});
|
|
860
|
+
return accessor;
|
|
861
|
+
}
|
|
862
|
+
|
|
863
|
+
// src/query/create-query.ts
|
|
864
|
+
function createQuery2(options, client) {
|
|
865
|
+
const queryClient = useQueryClient2(client);
|
|
866
|
+
const resolveOptions = () => typeof options === "function" ? options() : options;
|
|
867
|
+
const currentQuery = signal2(null);
|
|
868
|
+
const version = signal2(0);
|
|
869
|
+
let activeObserver = null;
|
|
870
|
+
let intervalTimer = null;
|
|
871
|
+
const clearIntervalTimer = () => {
|
|
872
|
+
if (intervalTimer !== null) {
|
|
873
|
+
clearInterval(intervalTimer);
|
|
874
|
+
intervalTimer = null;
|
|
875
|
+
}
|
|
876
|
+
};
|
|
877
|
+
effect2(() => {
|
|
878
|
+
const rawOpts = resolveOptions();
|
|
879
|
+
const defaults = queryClient.getDefaultOptions().queries ?? {};
|
|
880
|
+
const mergedOpts = {
|
|
881
|
+
...defaults,
|
|
882
|
+
...rawOpts
|
|
883
|
+
};
|
|
884
|
+
const isEnabled = typeof mergedOpts.enabled === "function" ? mergedOpts.enabled() : mergedOpts.enabled !== false;
|
|
885
|
+
const targetQuery = queryClient.queryCache.build(queryClient, mergedOpts);
|
|
886
|
+
if (untrack2(currentQuery) !== targetQuery || !activeObserver) {
|
|
887
|
+
const prevQ = untrack2(currentQuery);
|
|
888
|
+
if (prevQ && activeObserver) {
|
|
889
|
+
prevQ.removeObserver(activeObserver);
|
|
890
|
+
}
|
|
891
|
+
const observer = {
|
|
892
|
+
options: mergedOpts,
|
|
893
|
+
onQueryUpdate: () => {
|
|
894
|
+
version.update((v) => v + 1);
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
targetQuery.addObserver(observer);
|
|
898
|
+
activeObserver = observer;
|
|
899
|
+
currentQuery.set(targetQuery);
|
|
900
|
+
} else if (activeObserver) {
|
|
901
|
+
activeObserver.options = mergedOpts;
|
|
902
|
+
}
|
|
903
|
+
clearIntervalTimer();
|
|
904
|
+
const refetchInterval = typeof mergedOpts.refetchInterval === "function" ? mergedOpts.refetchInterval() : mergedOpts.refetchInterval;
|
|
905
|
+
if (refetchInterval && refetchInterval > 0) {
|
|
906
|
+
intervalTimer = setInterval(() => {
|
|
907
|
+
if (focusManager2.isFocused() || mergedOpts.refetchIntervalInBackground) {
|
|
908
|
+
targetQuery.fetch(mergedOpts).catch(() => {});
|
|
909
|
+
}
|
|
910
|
+
}, refetchInterval);
|
|
911
|
+
}
|
|
912
|
+
if (isEnabled) {
|
|
913
|
+
untrack2(() => {
|
|
914
|
+
if (targetQuery.isStale(mergedOpts.staleTime) && targetQuery.fetchStatus() === "idle") {
|
|
915
|
+
const fetchPromise = targetQuery.fetch(mergedOpts);
|
|
916
|
+
fetchPromise.catch(() => {});
|
|
917
|
+
const suspense = useContext2(SuspenseContext2);
|
|
918
|
+
if (suspense) {
|
|
919
|
+
suspense.registerPromise(fetchPromise);
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
});
|
|
923
|
+
}
|
|
924
|
+
});
|
|
925
|
+
onCleanup2(() => {
|
|
926
|
+
clearIntervalTimer();
|
|
927
|
+
if (currentQuery() && activeObserver) {
|
|
928
|
+
currentQuery().removeObserver(activeObserver);
|
|
929
|
+
}
|
|
930
|
+
});
|
|
931
|
+
const data = computed2(() => {
|
|
932
|
+
version();
|
|
933
|
+
const q = currentQuery();
|
|
934
|
+
const rawOpts = resolveOptions();
|
|
935
|
+
const rawData = q?.data();
|
|
936
|
+
if (rawData !== undefined) {
|
|
937
|
+
if (rawOpts.select) {
|
|
938
|
+
return rawOpts.select(rawData);
|
|
939
|
+
}
|
|
940
|
+
return rawData;
|
|
941
|
+
}
|
|
942
|
+
if (rawOpts.placeholderData !== undefined) {
|
|
943
|
+
return typeof rawOpts.placeholderData === "function" ? rawOpts.placeholderData(undefined) : rawOpts.placeholderData;
|
|
944
|
+
}
|
|
945
|
+
return;
|
|
946
|
+
});
|
|
947
|
+
const error = computed2(() => {
|
|
948
|
+
version();
|
|
949
|
+
return currentQuery()?.error() ?? null;
|
|
950
|
+
});
|
|
951
|
+
const status = computed2(() => {
|
|
952
|
+
version();
|
|
953
|
+
return currentQuery()?.status() ?? "pending";
|
|
954
|
+
});
|
|
955
|
+
const fetchStatus = computed2(() => {
|
|
956
|
+
version();
|
|
957
|
+
return currentQuery()?.fetchStatus() ?? "idle";
|
|
958
|
+
});
|
|
959
|
+
const isLoading = computed2(() => {
|
|
960
|
+
return status() === "pending" && fetchStatus() === "fetching";
|
|
961
|
+
});
|
|
962
|
+
const isFetching = computed2(() => {
|
|
963
|
+
return fetchStatus() === "fetching";
|
|
964
|
+
});
|
|
965
|
+
const isSuccess = computed2(() => {
|
|
966
|
+
return status() === "success";
|
|
967
|
+
});
|
|
968
|
+
const isError = computed2(() => {
|
|
969
|
+
return status() === "error";
|
|
970
|
+
});
|
|
971
|
+
const isStale = computed2(() => {
|
|
972
|
+
version();
|
|
973
|
+
const q = currentQuery();
|
|
974
|
+
const rawOpts = resolveOptions();
|
|
975
|
+
return q?.isStale(rawOpts.staleTime) ?? true;
|
|
976
|
+
});
|
|
977
|
+
const dataUpdatedAt = computed2(() => {
|
|
978
|
+
version();
|
|
979
|
+
return currentQuery()?.dataUpdatedAt() ?? 0;
|
|
980
|
+
});
|
|
981
|
+
const errorUpdatedAt = computed2(() => {
|
|
982
|
+
version();
|
|
983
|
+
return currentQuery()?.errorUpdatedAt() ?? 0;
|
|
984
|
+
});
|
|
985
|
+
const refetch = async (refetchOpts) => {
|
|
986
|
+
const q = untrack2(() => currentQuery());
|
|
987
|
+
if (!q)
|
|
988
|
+
return;
|
|
989
|
+
const rawOpts = resolveOptions();
|
|
990
|
+
const defaults = queryClient.getDefaultOptions().queries ?? {};
|
|
991
|
+
const mergedOpts = { ...defaults, ...rawOpts };
|
|
992
|
+
const rawResult = await q.fetch(mergedOpts, { cancelRefetch: refetchOpts?.cancelRefetch });
|
|
993
|
+
if (rawOpts.select) {
|
|
994
|
+
return rawOpts.select(rawResult);
|
|
995
|
+
}
|
|
996
|
+
return rawResult;
|
|
997
|
+
};
|
|
998
|
+
const accessor = () => {
|
|
999
|
+
const q = currentQuery();
|
|
1000
|
+
const rawOpts = resolveOptions();
|
|
1001
|
+
if ((rawOpts.suspense || status() === "pending") && q?.promise) {
|
|
1002
|
+
const suspense = useContext2(SuspenseContext2);
|
|
1003
|
+
if (suspense) {
|
|
1004
|
+
suspense.registerPromise(q.promise);
|
|
1005
|
+
}
|
|
1006
|
+
}
|
|
1007
|
+
return data();
|
|
1008
|
+
};
|
|
1009
|
+
Object.defineProperties(accessor, {
|
|
1010
|
+
[SIGNAL_BRAND2]: { value: true },
|
|
1011
|
+
[COMPUTED_BRAND2]: { value: true },
|
|
1012
|
+
value: { get: () => data() },
|
|
1013
|
+
data: { get: () => data },
|
|
1014
|
+
error: { get: () => error },
|
|
1015
|
+
status: { get: () => status },
|
|
1016
|
+
fetchStatus: { get: () => fetchStatus },
|
|
1017
|
+
isLoading: { get: () => isLoading },
|
|
1018
|
+
isFetching: { get: () => isFetching },
|
|
1019
|
+
isSuccess: { get: () => isSuccess },
|
|
1020
|
+
isError: { get: () => isError },
|
|
1021
|
+
isStale: { get: () => isStale },
|
|
1022
|
+
dataUpdatedAt: { get: () => dataUpdatedAt },
|
|
1023
|
+
errorUpdatedAt: { get: () => errorUpdatedAt },
|
|
1024
|
+
refetch: { value: refetch }
|
|
1025
|
+
});
|
|
1026
|
+
return accessor;
|
|
1027
|
+
}
|
|
1028
|
+
function createInfiniteQuery2(options, client) {
|
|
1029
|
+
const queryClient = useQueryClient2(client);
|
|
1030
|
+
const resolveOptions = () => typeof options === "function" ? options() : options;
|
|
1031
|
+
const isFetchingNextPage = signal2(false);
|
|
1032
|
+
const isFetchingPreviousPage = signal2(false);
|
|
1033
|
+
const baseQuery = createQuery2(() => {
|
|
1034
|
+
const rawOpts = resolveOptions();
|
|
1035
|
+
return {
|
|
1036
|
+
...rawOpts,
|
|
1037
|
+
queryFn: async (ctx) => {
|
|
1038
|
+
const pageParam = ctx.pageParam ?? rawOpts.initialPageParam;
|
|
1039
|
+
const page = await rawOpts.queryFn({
|
|
1040
|
+
...ctx,
|
|
1041
|
+
pageParam
|
|
1042
|
+
});
|
|
1043
|
+
return {
|
|
1044
|
+
pages: [page],
|
|
1045
|
+
pageParams: [pageParam]
|
|
1046
|
+
};
|
|
1047
|
+
},
|
|
1048
|
+
select: undefined
|
|
1049
|
+
};
|
|
1050
|
+
}, queryClient);
|
|
1051
|
+
const hasNextPage = computed2(() => {
|
|
1052
|
+
const current = baseQuery.data();
|
|
1053
|
+
if (!current || current.pages.length === 0)
|
|
1054
|
+
return false;
|
|
1055
|
+
const rawOpts = resolveOptions();
|
|
1056
|
+
const lastPage = current.pages[current.pages.length - 1];
|
|
1057
|
+
const lastParam = current.pageParams[current.pageParams.length - 1];
|
|
1058
|
+
const nextParam = rawOpts.getNextPageParam(lastPage, current.pages, lastParam, current.pageParams);
|
|
1059
|
+
return nextParam !== undefined && nextParam !== null;
|
|
1060
|
+
});
|
|
1061
|
+
const hasPreviousPage = computed2(() => {
|
|
1062
|
+
const current = baseQuery.data();
|
|
1063
|
+
if (!current || current.pages.length === 0)
|
|
1064
|
+
return false;
|
|
1065
|
+
const rawOpts = resolveOptions();
|
|
1066
|
+
if (!rawOpts.getPreviousPageParam)
|
|
1067
|
+
return false;
|
|
1068
|
+
const firstPage = current.pages[0];
|
|
1069
|
+
const firstParam = current.pageParams[0];
|
|
1070
|
+
const prevParam = rawOpts.getPreviousPageParam(firstPage, current.pages, firstParam, current.pageParams);
|
|
1071
|
+
return prevParam !== undefined && prevParam !== null;
|
|
1072
|
+
});
|
|
1073
|
+
const fetchNextPage = async () => {
|
|
1074
|
+
const current = baseQuery.data();
|
|
1075
|
+
if (!current || current.pages.length === 0)
|
|
1076
|
+
return;
|
|
1077
|
+
const rawOpts = resolveOptions();
|
|
1078
|
+
const lastPage = current.pages[current.pages.length - 1];
|
|
1079
|
+
const lastParam = current.pageParams[current.pageParams.length - 1];
|
|
1080
|
+
const nextParam = rawOpts.getNextPageParam(lastPage, current.pages, lastParam, current.pageParams);
|
|
1081
|
+
if (nextParam === undefined || nextParam === null) {
|
|
1082
|
+
return current;
|
|
1083
|
+
}
|
|
1084
|
+
isFetchingNextPage.set(true);
|
|
1085
|
+
try {
|
|
1086
|
+
const newPage = await rawOpts.queryFn({
|
|
1087
|
+
queryKey: rawOpts.queryKey,
|
|
1088
|
+
signal: new AbortController().signal,
|
|
1089
|
+
pageParam: nextParam,
|
|
1090
|
+
meta: rawOpts.meta
|
|
1091
|
+
});
|
|
1092
|
+
const nextData = {
|
|
1093
|
+
pages: [...current.pages, newPage],
|
|
1094
|
+
pageParams: [...current.pageParams, nextParam]
|
|
1095
|
+
};
|
|
1096
|
+
queryClient.setQueryData(rawOpts.queryKey, nextData);
|
|
1097
|
+
return nextData;
|
|
1098
|
+
} finally {
|
|
1099
|
+
isFetchingNextPage.set(false);
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
const fetchPreviousPage = async () => {
|
|
1103
|
+
const current = baseQuery.data();
|
|
1104
|
+
if (!current || current.pages.length === 0)
|
|
1105
|
+
return;
|
|
1106
|
+
const rawOpts = resolveOptions();
|
|
1107
|
+
if (!rawOpts.getPreviousPageParam)
|
|
1108
|
+
return current;
|
|
1109
|
+
const firstPage = current.pages[0];
|
|
1110
|
+
const firstParam = current.pageParams[0];
|
|
1111
|
+
const prevParam = rawOpts.getPreviousPageParam(firstPage, current.pages, firstParam, current.pageParams);
|
|
1112
|
+
if (prevParam === undefined || prevParam === null) {
|
|
1113
|
+
return current;
|
|
1114
|
+
}
|
|
1115
|
+
isFetchingPreviousPage.set(true);
|
|
1116
|
+
try {
|
|
1117
|
+
const newPage = await rawOpts.queryFn({
|
|
1118
|
+
queryKey: rawOpts.queryKey,
|
|
1119
|
+
signal: new AbortController().signal,
|
|
1120
|
+
pageParam: prevParam,
|
|
1121
|
+
meta: rawOpts.meta
|
|
1122
|
+
});
|
|
1123
|
+
const nextData = {
|
|
1124
|
+
pages: [newPage, ...current.pages],
|
|
1125
|
+
pageParams: [prevParam, ...current.pageParams]
|
|
1126
|
+
};
|
|
1127
|
+
queryClient.setQueryData(rawOpts.queryKey, nextData);
|
|
1128
|
+
return nextData;
|
|
1129
|
+
} finally {
|
|
1130
|
+
isFetchingPreviousPage.set(false);
|
|
1131
|
+
}
|
|
1132
|
+
};
|
|
1133
|
+
const accessor = () => {
|
|
1134
|
+
return baseQuery();
|
|
1135
|
+
};
|
|
1136
|
+
Object.defineProperties(accessor, {
|
|
1137
|
+
[SIGNAL_BRAND2]: { value: true },
|
|
1138
|
+
[COMPUTED_BRAND2]: { value: true },
|
|
1139
|
+
value: { get: () => baseQuery.data() },
|
|
1140
|
+
data: { get: () => baseQuery.data },
|
|
1141
|
+
error: { get: () => baseQuery.error },
|
|
1142
|
+
status: { get: () => baseQuery.status },
|
|
1143
|
+
fetchStatus: { get: () => baseQuery.fetchStatus },
|
|
1144
|
+
isLoading: { get: () => baseQuery.isLoading },
|
|
1145
|
+
isFetching: { get: () => baseQuery.isFetching },
|
|
1146
|
+
isSuccess: { get: () => baseQuery.isSuccess },
|
|
1147
|
+
isError: { get: () => baseQuery.isError },
|
|
1148
|
+
isStale: { get: () => baseQuery.isStale },
|
|
1149
|
+
dataUpdatedAt: { get: () => baseQuery.dataUpdatedAt },
|
|
1150
|
+
errorUpdatedAt: { get: () => baseQuery.errorUpdatedAt },
|
|
1151
|
+
refetch: { value: baseQuery.refetch },
|
|
1152
|
+
fetchNextPage: { value: fetchNextPage },
|
|
1153
|
+
fetchPreviousPage: { value: fetchPreviousPage },
|
|
1154
|
+
hasNextPage: { get: () => hasNextPage },
|
|
1155
|
+
hasPreviousPage: { get: () => hasPreviousPage },
|
|
1156
|
+
isFetchingNextPage: { get: () => isFetchingNextPage },
|
|
1157
|
+
isFetchingPreviousPage: { get: () => isFetchingPreviousPage }
|
|
1158
|
+
});
|
|
1159
|
+
return accessor;
|
|
1160
|
+
}
|
|
1161
|
+
|
|
1162
|
+
export { FocusManager2, focusManager2, Mutation2, MutationCache2, OnlineManager2, onlineManager2, isPlainObject2, hashKey2, deepEqual2, partialDeepEqual2, matchQuery2, sleep2, Query2, QueryCache2, QueryClient2, QueryClientContext2, QueryClientProvider2, useQueryClient2, createMutation2, createQuery2, createInfiniteQuery2 };
|