olova 2.0.55 → 2.0.56

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (84) hide show
  1. package/README.md +28 -288
  2. package/dist/chunk-23UAGQ6N.js +2208 -0
  3. package/dist/chunk-23UAGQ6N.js.map +1 -0
  4. package/dist/chunk-D7SIC5TC.js +367 -0
  5. package/dist/chunk-D7SIC5TC.js.map +1 -0
  6. package/dist/entry-server.cjs +2341 -0
  7. package/dist/entry-server.cjs.map +1 -0
  8. package/dist/entry-server.js +114 -0
  9. package/dist/entry-server.js.map +1 -0
  10. package/dist/entry-worker.cjs +2354 -0
  11. package/dist/entry-worker.cjs.map +1 -0
  12. package/dist/entry-worker.js +126 -0
  13. package/dist/entry-worker.js.map +1 -0
  14. package/dist/main.cjs +18 -0
  15. package/dist/main.cjs.map +1 -0
  16. package/dist/main.js +16 -0
  17. package/dist/main.js.map +1 -0
  18. package/dist/olova.cjs +1684 -0
  19. package/dist/olova.cjs.map +1 -0
  20. package/dist/olova.d.cts +72 -0
  21. package/dist/olova.d.ts +72 -0
  22. package/dist/olova.js +1325 -0
  23. package/dist/olova.js.map +1 -0
  24. package/dist/performance.cjs +386 -0
  25. package/dist/performance.cjs.map +1 -0
  26. package/dist/performance.js +3 -0
  27. package/dist/performance.js.map +1 -0
  28. package/dist/router.cjs +646 -0
  29. package/dist/router.cjs.map +1 -0
  30. package/dist/router.d.cts +113 -0
  31. package/dist/router.d.ts +113 -0
  32. package/dist/router.js +632 -0
  33. package/dist/router.js.map +1 -0
  34. package/main.tsx +76 -0
  35. package/olova.ts +619 -0
  36. package/package.json +42 -61
  37. package/src/entry-server.tsx +165 -0
  38. package/src/entry-worker.tsx +201 -0
  39. package/src/generator/index.ts +409 -0
  40. package/src/hydration/flight.ts +320 -0
  41. package/src/hydration/index.ts +12 -0
  42. package/src/hydration/types.ts +225 -0
  43. package/src/logger.ts +182 -0
  44. package/src/main.tsx +24 -0
  45. package/src/performance.ts +488 -0
  46. package/src/plugin/index.ts +204 -0
  47. package/src/router/ErrorBoundary.tsx +145 -0
  48. package/src/router/Link.tsx +117 -0
  49. package/src/router/OlovaRouter.tsx +354 -0
  50. package/src/router/Outlet.tsx +8 -0
  51. package/src/router/context.ts +117 -0
  52. package/src/router/index.ts +29 -0
  53. package/src/router/matching.ts +63 -0
  54. package/src/router/router.tsx +23 -0
  55. package/src/router/search-params.ts +29 -0
  56. package/src/scanner/index.ts +116 -0
  57. package/src/types/index.ts +191 -0
  58. package/src/utils/export.ts +85 -0
  59. package/src/utils/index.ts +4 -0
  60. package/src/utils/naming.ts +54 -0
  61. package/src/utils/path.ts +45 -0
  62. package/tsup.config.ts +35 -0
  63. package/CHANGELOG.md +0 -31
  64. package/LICENSE +0 -21
  65. package/dist/index.cjs +0 -883
  66. package/dist/index.cjs.map +0 -1
  67. package/dist/index.d.cts +0 -138
  68. package/dist/index.d.ts +0 -138
  69. package/dist/index.js +0 -832
  70. package/dist/index.js.map +0 -1
  71. package/dist/plugin.cjs +0 -927
  72. package/dist/plugin.cjs.map +0 -1
  73. package/dist/plugin.d.cts +0 -18
  74. package/dist/plugin.d.ts +0 -18
  75. package/dist/plugin.js +0 -894
  76. package/dist/plugin.js.map +0 -1
  77. package/dist/ssg.cjs +0 -637
  78. package/dist/ssg.cjs.map +0 -1
  79. package/dist/ssg.d.cts +0 -191
  80. package/dist/ssg.d.ts +0 -191
  81. package/dist/ssg.js +0 -585
  82. package/dist/ssg.js.map +0 -1
  83. package/dist/types-BT6YsBGO.d.cts +0 -143
  84. package/dist/types-BT6YsBGO.d.ts +0 -143
@@ -0,0 +1,2208 @@
1
+ import * as React2 from 'react';
2
+ import { jsx } from 'react/jsx-runtime';
3
+
4
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/timeoutManager.js
5
+ var defaultTimeoutProvider = {
6
+ // We need the wrapper function syntax below instead of direct references to
7
+ // global setTimeout etc.
8
+ //
9
+ // BAD: `setTimeout: setTimeout`
10
+ // GOOD: `setTimeout: (cb, delay) => setTimeout(cb, delay)`
11
+ //
12
+ // If we use direct references here, then anything that wants to spy on or
13
+ // replace the global setTimeout (like tests) won't work since we'll already
14
+ // have a hard reference to the original implementation at the time when this
15
+ // file was imported.
16
+ setTimeout: (callback, delay) => setTimeout(callback, delay),
17
+ clearTimeout: (timeoutId) => clearTimeout(timeoutId),
18
+ setInterval: (callback, delay) => setInterval(callback, delay),
19
+ clearInterval: (intervalId) => clearInterval(intervalId)
20
+ };
21
+ var TimeoutManager = class {
22
+ // We cannot have TimeoutManager<T> as we must instantiate it with a concrete
23
+ // type at app boot; and if we leave that type, then any new timer provider
24
+ // would need to support ReturnType<typeof setTimeout>, which is infeasible.
25
+ //
26
+ // We settle for type safety for the TimeoutProvider type, and accept that
27
+ // this class is unsafe internally to allow for extension.
28
+ #provider = defaultTimeoutProvider;
29
+ #providerCalled = false;
30
+ setTimeoutProvider(provider) {
31
+ if (process.env.NODE_ENV !== "production") {
32
+ if (this.#providerCalled && provider !== this.#provider) {
33
+ console.error(
34
+ `[timeoutManager]: Switching provider after calls to previous provider might result in unexpected behavior.`,
35
+ { previous: this.#provider, provider }
36
+ );
37
+ }
38
+ }
39
+ this.#provider = provider;
40
+ if (process.env.NODE_ENV !== "production") {
41
+ this.#providerCalled = false;
42
+ }
43
+ }
44
+ setTimeout(callback, delay) {
45
+ if (process.env.NODE_ENV !== "production") {
46
+ this.#providerCalled = true;
47
+ }
48
+ return this.#provider.setTimeout(callback, delay);
49
+ }
50
+ clearTimeout(timeoutId) {
51
+ this.#provider.clearTimeout(timeoutId);
52
+ }
53
+ setInterval(callback, delay) {
54
+ if (process.env.NODE_ENV !== "production") {
55
+ this.#providerCalled = true;
56
+ }
57
+ return this.#provider.setInterval(callback, delay);
58
+ }
59
+ clearInterval(intervalId) {
60
+ this.#provider.clearInterval(intervalId);
61
+ }
62
+ };
63
+ var timeoutManager = new TimeoutManager();
64
+ function systemSetTimeoutZero(callback) {
65
+ setTimeout(callback, 0);
66
+ }
67
+
68
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/utils.js
69
+ var isServer = typeof window === "undefined" || "Deno" in globalThis;
70
+ function noop() {
71
+ }
72
+ function functionalUpdate(updater, input) {
73
+ return typeof updater === "function" ? updater(input) : updater;
74
+ }
75
+ function isValidTimeout(value) {
76
+ return typeof value === "number" && value >= 0 && value !== Infinity;
77
+ }
78
+ function timeUntilStale(updatedAt, staleTime) {
79
+ return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
80
+ }
81
+ function resolveStaleTime(staleTime, query) {
82
+ return typeof staleTime === "function" ? staleTime(query) : staleTime;
83
+ }
84
+ function resolveEnabled(enabled, query) {
85
+ return typeof enabled === "function" ? enabled(query) : enabled;
86
+ }
87
+ function matchQuery(filters, query) {
88
+ const {
89
+ type = "all",
90
+ exact,
91
+ fetchStatus,
92
+ predicate,
93
+ queryKey,
94
+ stale
95
+ } = filters;
96
+ if (queryKey) {
97
+ if (exact) {
98
+ if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) {
99
+ return false;
100
+ }
101
+ } else if (!partialMatchKey(query.queryKey, queryKey)) {
102
+ return false;
103
+ }
104
+ }
105
+ if (type !== "all") {
106
+ const isActive = query.isActive();
107
+ if (type === "active" && !isActive) {
108
+ return false;
109
+ }
110
+ if (type === "inactive" && isActive) {
111
+ return false;
112
+ }
113
+ }
114
+ if (typeof stale === "boolean" && query.isStale() !== stale) {
115
+ return false;
116
+ }
117
+ if (fetchStatus && fetchStatus !== query.state.fetchStatus) {
118
+ return false;
119
+ }
120
+ if (predicate && !predicate(query)) {
121
+ return false;
122
+ }
123
+ return true;
124
+ }
125
+ function matchMutation(filters, mutation) {
126
+ const { exact, status, predicate, mutationKey } = filters;
127
+ if (mutationKey) {
128
+ if (!mutation.options.mutationKey) {
129
+ return false;
130
+ }
131
+ if (exact) {
132
+ if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) {
133
+ return false;
134
+ }
135
+ } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) {
136
+ return false;
137
+ }
138
+ }
139
+ if (status && mutation.state.status !== status) {
140
+ return false;
141
+ }
142
+ if (predicate && !predicate(mutation)) {
143
+ return false;
144
+ }
145
+ return true;
146
+ }
147
+ function hashQueryKeyByOptions(queryKey, options) {
148
+ const hashFn = options?.queryKeyHashFn || hashKey;
149
+ return hashFn(queryKey);
150
+ }
151
+ function hashKey(queryKey) {
152
+ return JSON.stringify(
153
+ queryKey,
154
+ (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
155
+ result[key] = val[key];
156
+ return result;
157
+ }, {}) : val
158
+ );
159
+ }
160
+ function partialMatchKey(a, b) {
161
+ if (a === b) {
162
+ return true;
163
+ }
164
+ if (typeof a !== typeof b) {
165
+ return false;
166
+ }
167
+ if (a && b && typeof a === "object" && typeof b === "object") {
168
+ return Object.keys(b).every((key) => partialMatchKey(a[key], b[key]));
169
+ }
170
+ return false;
171
+ }
172
+ var hasOwn = Object.prototype.hasOwnProperty;
173
+ function replaceEqualDeep(a, b, depth = 0) {
174
+ if (a === b) {
175
+ return a;
176
+ }
177
+ if (depth > 500) return b;
178
+ const array = isPlainArray(a) && isPlainArray(b);
179
+ if (!array && !(isPlainObject(a) && isPlainObject(b))) return b;
180
+ const aItems = array ? a : Object.keys(a);
181
+ const aSize = aItems.length;
182
+ const bItems = array ? b : Object.keys(b);
183
+ const bSize = bItems.length;
184
+ const copy = array ? new Array(bSize) : {};
185
+ let equalItems = 0;
186
+ for (let i = 0; i < bSize; i++) {
187
+ const key = array ? i : bItems[i];
188
+ const aItem = a[key];
189
+ const bItem = b[key];
190
+ if (aItem === bItem) {
191
+ copy[key] = aItem;
192
+ if (array ? i < aSize : hasOwn.call(a, key)) equalItems++;
193
+ continue;
194
+ }
195
+ if (aItem === null || bItem === null || typeof aItem !== "object" || typeof bItem !== "object") {
196
+ copy[key] = bItem;
197
+ continue;
198
+ }
199
+ const v = replaceEqualDeep(aItem, bItem, depth + 1);
200
+ copy[key] = v;
201
+ if (v === aItem) equalItems++;
202
+ }
203
+ return aSize === bSize && equalItems === aSize ? a : copy;
204
+ }
205
+ function isPlainArray(value) {
206
+ return Array.isArray(value) && value.length === Object.keys(value).length;
207
+ }
208
+ function isPlainObject(o) {
209
+ if (!hasObjectPrototype(o)) {
210
+ return false;
211
+ }
212
+ const ctor = o.constructor;
213
+ if (ctor === void 0) {
214
+ return true;
215
+ }
216
+ const prot = ctor.prototype;
217
+ if (!hasObjectPrototype(prot)) {
218
+ return false;
219
+ }
220
+ if (!prot.hasOwnProperty("isPrototypeOf")) {
221
+ return false;
222
+ }
223
+ if (Object.getPrototypeOf(o) !== Object.prototype) {
224
+ return false;
225
+ }
226
+ return true;
227
+ }
228
+ function hasObjectPrototype(o) {
229
+ return Object.prototype.toString.call(o) === "[object Object]";
230
+ }
231
+ function sleep(timeout) {
232
+ return new Promise((resolve) => {
233
+ timeoutManager.setTimeout(resolve, timeout);
234
+ });
235
+ }
236
+ function replaceData(prevData, data, options) {
237
+ if (typeof options.structuralSharing === "function") {
238
+ return options.structuralSharing(prevData, data);
239
+ } else if (options.structuralSharing !== false) {
240
+ if (process.env.NODE_ENV !== "production") {
241
+ try {
242
+ return replaceEqualDeep(prevData, data);
243
+ } catch (error) {
244
+ console.error(
245
+ `Structural sharing requires data to be JSON serializable. To fix this, turn off structuralSharing or return JSON-serializable data from your queryFn. [${options.queryHash}]: ${error}`
246
+ );
247
+ throw error;
248
+ }
249
+ }
250
+ return replaceEqualDeep(prevData, data);
251
+ }
252
+ return data;
253
+ }
254
+ function addToEnd(items, item, max = 0) {
255
+ const newItems = [...items, item];
256
+ return max && newItems.length > max ? newItems.slice(1) : newItems;
257
+ }
258
+ function addToStart(items, item, max = 0) {
259
+ const newItems = [item, ...items];
260
+ return max && newItems.length > max ? newItems.slice(0, -1) : newItems;
261
+ }
262
+ var skipToken = /* @__PURE__ */ Symbol();
263
+ function ensureQueryFn(options, fetchOptions) {
264
+ if (process.env.NODE_ENV !== "production") {
265
+ if (options.queryFn === skipToken) {
266
+ console.error(
267
+ `Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${options.queryHash}'`
268
+ );
269
+ }
270
+ }
271
+ if (!options.queryFn && fetchOptions?.initialPromise) {
272
+ return () => fetchOptions.initialPromise;
273
+ }
274
+ if (!options.queryFn || options.queryFn === skipToken) {
275
+ return () => Promise.reject(new Error(`Missing queryFn: '${options.queryHash}'`));
276
+ }
277
+ return options.queryFn;
278
+ }
279
+ function addConsumeAwareSignal(object, getSignal, onCancelled) {
280
+ let consumed = false;
281
+ let signal;
282
+ Object.defineProperty(object, "signal", {
283
+ enumerable: true,
284
+ get: () => {
285
+ signal ??= getSignal();
286
+ if (consumed) {
287
+ return signal;
288
+ }
289
+ consumed = true;
290
+ if (signal.aborted) {
291
+ onCancelled();
292
+ } else {
293
+ signal.addEventListener("abort", onCancelled, { once: true });
294
+ }
295
+ return signal;
296
+ }
297
+ });
298
+ return object;
299
+ }
300
+
301
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/thenable.js
302
+ function pendingThenable() {
303
+ let resolve;
304
+ let reject;
305
+ const thenable = new Promise((_resolve, _reject) => {
306
+ resolve = _resolve;
307
+ reject = _reject;
308
+ });
309
+ thenable.status = "pending";
310
+ thenable.catch(() => {
311
+ });
312
+ function finalize(data) {
313
+ Object.assign(thenable, data);
314
+ delete thenable.resolve;
315
+ delete thenable.reject;
316
+ }
317
+ thenable.resolve = (value) => {
318
+ finalize({
319
+ status: "fulfilled",
320
+ value
321
+ });
322
+ resolve(value);
323
+ };
324
+ thenable.reject = (reason) => {
325
+ finalize({
326
+ status: "rejected",
327
+ reason
328
+ });
329
+ reject(reason);
330
+ };
331
+ return thenable;
332
+ }
333
+ function tryResolveSync(promise) {
334
+ let data;
335
+ promise.then((result) => {
336
+ data = result;
337
+ return result;
338
+ }, noop)?.catch(noop);
339
+ if (data !== void 0) {
340
+ return { data };
341
+ }
342
+ return void 0;
343
+ }
344
+
345
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/hydration.js
346
+ function defaultTransformerFn(data) {
347
+ return data;
348
+ }
349
+ function dehydrateMutation(mutation) {
350
+ return {
351
+ mutationKey: mutation.options.mutationKey,
352
+ state: mutation.state,
353
+ ...mutation.options.scope && { scope: mutation.options.scope },
354
+ ...mutation.meta && { meta: mutation.meta }
355
+ };
356
+ }
357
+ function dehydrateQuery(query, serializeData, shouldRedactErrors) {
358
+ const dehydratePromise = () => {
359
+ const promise = query.promise?.then(serializeData).catch((error) => {
360
+ if (!shouldRedactErrors(error)) {
361
+ return Promise.reject(error);
362
+ }
363
+ if (process.env.NODE_ENV !== "production") {
364
+ console.error(
365
+ `A query that was dehydrated as pending ended up rejecting. [${query.queryHash}]: ${error}; The error will be redacted in production builds`
366
+ );
367
+ }
368
+ return Promise.reject(new Error("redacted"));
369
+ });
370
+ promise?.catch(noop);
371
+ return promise;
372
+ };
373
+ return {
374
+ dehydratedAt: Date.now(),
375
+ state: {
376
+ ...query.state,
377
+ ...query.state.data !== void 0 && {
378
+ data: serializeData(query.state.data)
379
+ }
380
+ },
381
+ queryKey: query.queryKey,
382
+ queryHash: query.queryHash,
383
+ ...query.state.status === "pending" && {
384
+ promise: dehydratePromise()
385
+ },
386
+ ...query.meta && { meta: query.meta }
387
+ };
388
+ }
389
+ function defaultShouldDehydrateMutation(mutation) {
390
+ return mutation.state.isPaused;
391
+ }
392
+ function defaultShouldDehydrateQuery(query) {
393
+ return query.state.status === "success";
394
+ }
395
+ function defaultShouldRedactErrors(_) {
396
+ return true;
397
+ }
398
+ function dehydrate(client, options = {}) {
399
+ const filterMutation = options.shouldDehydrateMutation ?? client.getDefaultOptions().dehydrate?.shouldDehydrateMutation ?? defaultShouldDehydrateMutation;
400
+ const mutations = client.getMutationCache().getAll().flatMap(
401
+ (mutation) => filterMutation(mutation) ? [dehydrateMutation(mutation)] : []
402
+ );
403
+ const filterQuery = options.shouldDehydrateQuery ?? client.getDefaultOptions().dehydrate?.shouldDehydrateQuery ?? defaultShouldDehydrateQuery;
404
+ const shouldRedactErrors = options.shouldRedactErrors ?? client.getDefaultOptions().dehydrate?.shouldRedactErrors ?? defaultShouldRedactErrors;
405
+ const serializeData = options.serializeData ?? client.getDefaultOptions().dehydrate?.serializeData ?? defaultTransformerFn;
406
+ const queries = client.getQueryCache().getAll().flatMap(
407
+ (query) => filterQuery(query) ? [dehydrateQuery(query, serializeData, shouldRedactErrors)] : []
408
+ );
409
+ return { mutations, queries };
410
+ }
411
+ function hydrate(client, dehydratedState, options) {
412
+ if (typeof dehydratedState !== "object" || dehydratedState === null) {
413
+ return;
414
+ }
415
+ const mutationCache = client.getMutationCache();
416
+ const queryCache = client.getQueryCache();
417
+ const deserializeData = options?.defaultOptions?.deserializeData ?? client.getDefaultOptions().hydrate?.deserializeData ?? defaultTransformerFn;
418
+ const mutations = dehydratedState.mutations || [];
419
+ const queries = dehydratedState.queries || [];
420
+ mutations.forEach(({ state, ...mutationOptions }) => {
421
+ mutationCache.build(
422
+ client,
423
+ {
424
+ ...client.getDefaultOptions().hydrate?.mutations,
425
+ ...options?.defaultOptions?.mutations,
426
+ ...mutationOptions
427
+ },
428
+ state
429
+ );
430
+ });
431
+ queries.forEach(
432
+ ({ queryKey, state, queryHash, meta, promise, dehydratedAt }) => {
433
+ const syncData = promise ? tryResolveSync(promise) : void 0;
434
+ const rawData = state.data === void 0 ? syncData?.data : state.data;
435
+ const data = rawData === void 0 ? rawData : deserializeData(rawData);
436
+ let query = queryCache.get(queryHash);
437
+ const existingQueryIsPending = query?.state.status === "pending";
438
+ const existingQueryIsFetching = query?.state.fetchStatus === "fetching";
439
+ if (query) {
440
+ const hasNewerSyncData = syncData && // We only need this undefined check to handle older dehydration
441
+ // payloads that might not have dehydratedAt
442
+ dehydratedAt !== void 0 && dehydratedAt > query.state.dataUpdatedAt;
443
+ if (state.dataUpdatedAt > query.state.dataUpdatedAt || hasNewerSyncData) {
444
+ const { fetchStatus: _ignored, ...serializedState } = state;
445
+ query.setState({
446
+ ...serializedState,
447
+ data
448
+ });
449
+ }
450
+ } else {
451
+ query = queryCache.build(
452
+ client,
453
+ {
454
+ ...client.getDefaultOptions().hydrate?.queries,
455
+ ...options?.defaultOptions?.queries,
456
+ queryKey,
457
+ queryHash,
458
+ meta
459
+ },
460
+ // Reset fetch status to idle to avoid
461
+ // query being stuck in fetching state upon hydration
462
+ {
463
+ ...state,
464
+ data,
465
+ fetchStatus: "idle",
466
+ status: data !== void 0 ? "success" : state.status
467
+ }
468
+ );
469
+ }
470
+ if (promise && !existingQueryIsPending && !existingQueryIsFetching && // Only hydrate if dehydration is newer than any existing data,
471
+ // this is always true for new queries
472
+ (dehydratedAt === void 0 || dehydratedAt > query.state.dataUpdatedAt)) {
473
+ query.fetch(void 0, {
474
+ // RSC transformed promises are not thenable
475
+ initialPromise: Promise.resolve(promise).then(deserializeData)
476
+ }).catch(noop);
477
+ }
478
+ }
479
+ );
480
+ }
481
+
482
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/notifyManager.js
483
+ var defaultScheduler = systemSetTimeoutZero;
484
+ function createNotifyManager() {
485
+ let queue = [];
486
+ let transactions = 0;
487
+ let notifyFn = (callback) => {
488
+ callback();
489
+ };
490
+ let batchNotifyFn = (callback) => {
491
+ callback();
492
+ };
493
+ let scheduleFn = defaultScheduler;
494
+ const schedule = (callback) => {
495
+ if (transactions) {
496
+ queue.push(callback);
497
+ } else {
498
+ scheduleFn(() => {
499
+ notifyFn(callback);
500
+ });
501
+ }
502
+ };
503
+ const flush = () => {
504
+ const originalQueue = queue;
505
+ queue = [];
506
+ if (originalQueue.length) {
507
+ scheduleFn(() => {
508
+ batchNotifyFn(() => {
509
+ originalQueue.forEach((callback) => {
510
+ notifyFn(callback);
511
+ });
512
+ });
513
+ });
514
+ }
515
+ };
516
+ return {
517
+ batch: (callback) => {
518
+ let result;
519
+ transactions++;
520
+ try {
521
+ result = callback();
522
+ } finally {
523
+ transactions--;
524
+ if (!transactions) {
525
+ flush();
526
+ }
527
+ }
528
+ return result;
529
+ },
530
+ /**
531
+ * All calls to the wrapped function will be batched.
532
+ */
533
+ batchCalls: (callback) => {
534
+ return (...args) => {
535
+ schedule(() => {
536
+ callback(...args);
537
+ });
538
+ };
539
+ },
540
+ schedule,
541
+ /**
542
+ * Use this method to set a custom notify function.
543
+ * This can be used to for example wrap notifications with `React.act` while running tests.
544
+ */
545
+ setNotifyFunction: (fn) => {
546
+ notifyFn = fn;
547
+ },
548
+ /**
549
+ * Use this method to set a custom function to batch notifications together into a single tick.
550
+ * By default React Query will use the batch function provided by ReactDOM or React Native.
551
+ */
552
+ setBatchNotifyFunction: (fn) => {
553
+ batchNotifyFn = fn;
554
+ },
555
+ setScheduler: (fn) => {
556
+ scheduleFn = fn;
557
+ }
558
+ };
559
+ }
560
+ var notifyManager = createNotifyManager();
561
+
562
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/subscribable.js
563
+ var Subscribable = class {
564
+ constructor() {
565
+ this.listeners = /* @__PURE__ */ new Set();
566
+ this.subscribe = this.subscribe.bind(this);
567
+ }
568
+ subscribe(listener) {
569
+ this.listeners.add(listener);
570
+ this.onSubscribe();
571
+ return () => {
572
+ this.listeners.delete(listener);
573
+ this.onUnsubscribe();
574
+ };
575
+ }
576
+ hasListeners() {
577
+ return this.listeners.size > 0;
578
+ }
579
+ onSubscribe() {
580
+ }
581
+ onUnsubscribe() {
582
+ }
583
+ };
584
+
585
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/focusManager.js
586
+ var FocusManager = class extends Subscribable {
587
+ #focused;
588
+ #cleanup;
589
+ #setup;
590
+ constructor() {
591
+ super();
592
+ this.#setup = (onFocus) => {
593
+ if (!isServer && window.addEventListener) {
594
+ const listener = () => onFocus();
595
+ window.addEventListener("visibilitychange", listener, false);
596
+ return () => {
597
+ window.removeEventListener("visibilitychange", listener);
598
+ };
599
+ }
600
+ return;
601
+ };
602
+ }
603
+ onSubscribe() {
604
+ if (!this.#cleanup) {
605
+ this.setEventListener(this.#setup);
606
+ }
607
+ }
608
+ onUnsubscribe() {
609
+ if (!this.hasListeners()) {
610
+ this.#cleanup?.();
611
+ this.#cleanup = void 0;
612
+ }
613
+ }
614
+ setEventListener(setup) {
615
+ this.#setup = setup;
616
+ this.#cleanup?.();
617
+ this.#cleanup = setup((focused) => {
618
+ if (typeof focused === "boolean") {
619
+ this.setFocused(focused);
620
+ } else {
621
+ this.onFocus();
622
+ }
623
+ });
624
+ }
625
+ setFocused(focused) {
626
+ const changed = this.#focused !== focused;
627
+ if (changed) {
628
+ this.#focused = focused;
629
+ this.onFocus();
630
+ }
631
+ }
632
+ onFocus() {
633
+ const isFocused = this.isFocused();
634
+ this.listeners.forEach((listener) => {
635
+ listener(isFocused);
636
+ });
637
+ }
638
+ isFocused() {
639
+ if (typeof this.#focused === "boolean") {
640
+ return this.#focused;
641
+ }
642
+ return globalThis.document?.visibilityState !== "hidden";
643
+ }
644
+ };
645
+ var focusManager = new FocusManager();
646
+
647
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/onlineManager.js
648
+ var OnlineManager = class extends Subscribable {
649
+ #online = true;
650
+ #cleanup;
651
+ #setup;
652
+ constructor() {
653
+ super();
654
+ this.#setup = (onOnline) => {
655
+ if (!isServer && window.addEventListener) {
656
+ const onlineListener = () => onOnline(true);
657
+ const offlineListener = () => onOnline(false);
658
+ window.addEventListener("online", onlineListener, false);
659
+ window.addEventListener("offline", offlineListener, false);
660
+ return () => {
661
+ window.removeEventListener("online", onlineListener);
662
+ window.removeEventListener("offline", offlineListener);
663
+ };
664
+ }
665
+ return;
666
+ };
667
+ }
668
+ onSubscribe() {
669
+ if (!this.#cleanup) {
670
+ this.setEventListener(this.#setup);
671
+ }
672
+ }
673
+ onUnsubscribe() {
674
+ if (!this.hasListeners()) {
675
+ this.#cleanup?.();
676
+ this.#cleanup = void 0;
677
+ }
678
+ }
679
+ setEventListener(setup) {
680
+ this.#setup = setup;
681
+ this.#cleanup?.();
682
+ this.#cleanup = setup(this.setOnline.bind(this));
683
+ }
684
+ setOnline(online) {
685
+ const changed = this.#online !== online;
686
+ if (changed) {
687
+ this.#online = online;
688
+ this.listeners.forEach((listener) => {
689
+ listener(online);
690
+ });
691
+ }
692
+ }
693
+ isOnline() {
694
+ return this.#online;
695
+ }
696
+ };
697
+ var onlineManager = new OnlineManager();
698
+
699
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/retryer.js
700
+ function defaultRetryDelay(failureCount) {
701
+ return Math.min(1e3 * 2 ** failureCount, 3e4);
702
+ }
703
+ function canFetch(networkMode) {
704
+ return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
705
+ }
706
+ var CancelledError = class extends Error {
707
+ constructor(options) {
708
+ super("CancelledError");
709
+ this.revert = options?.revert;
710
+ this.silent = options?.silent;
711
+ }
712
+ };
713
+ function createRetryer(config) {
714
+ let isRetryCancelled = false;
715
+ let failureCount = 0;
716
+ let continueFn;
717
+ const thenable = pendingThenable();
718
+ const isResolved = () => thenable.status !== "pending";
719
+ const cancel = (cancelOptions) => {
720
+ if (!isResolved()) {
721
+ const error = new CancelledError(cancelOptions);
722
+ reject(error);
723
+ config.onCancel?.(error);
724
+ }
725
+ };
726
+ const cancelRetry = () => {
727
+ isRetryCancelled = true;
728
+ };
729
+ const continueRetry = () => {
730
+ isRetryCancelled = false;
731
+ };
732
+ const canContinue = () => focusManager.isFocused() && (config.networkMode === "always" || onlineManager.isOnline()) && config.canRun();
733
+ const canStart = () => canFetch(config.networkMode) && config.canRun();
734
+ const resolve = (value) => {
735
+ if (!isResolved()) {
736
+ continueFn?.();
737
+ thenable.resolve(value);
738
+ }
739
+ };
740
+ const reject = (value) => {
741
+ if (!isResolved()) {
742
+ continueFn?.();
743
+ thenable.reject(value);
744
+ }
745
+ };
746
+ const pause = () => {
747
+ return new Promise((continueResolve) => {
748
+ continueFn = (value) => {
749
+ if (isResolved() || canContinue()) {
750
+ continueResolve(value);
751
+ }
752
+ };
753
+ config.onPause?.();
754
+ }).then(() => {
755
+ continueFn = void 0;
756
+ if (!isResolved()) {
757
+ config.onContinue?.();
758
+ }
759
+ });
760
+ };
761
+ const run = () => {
762
+ if (isResolved()) {
763
+ return;
764
+ }
765
+ let promiseOrValue;
766
+ const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
767
+ try {
768
+ promiseOrValue = initialPromise ?? config.fn();
769
+ } catch (error) {
770
+ promiseOrValue = Promise.reject(error);
771
+ }
772
+ Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
773
+ if (isResolved()) {
774
+ return;
775
+ }
776
+ const retry = config.retry ?? (isServer ? 0 : 3);
777
+ const retryDelay = config.retryDelay ?? defaultRetryDelay;
778
+ const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
779
+ const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
780
+ if (isRetryCancelled || !shouldRetry) {
781
+ reject(error);
782
+ return;
783
+ }
784
+ failureCount++;
785
+ config.onFail?.(failureCount, error);
786
+ sleep(delay).then(() => {
787
+ return canContinue() ? void 0 : pause();
788
+ }).then(() => {
789
+ if (isRetryCancelled) {
790
+ reject(error);
791
+ } else {
792
+ run();
793
+ }
794
+ });
795
+ });
796
+ };
797
+ return {
798
+ promise: thenable,
799
+ status: () => thenable.status,
800
+ cancel,
801
+ continue: () => {
802
+ continueFn?.();
803
+ return thenable;
804
+ },
805
+ cancelRetry,
806
+ continueRetry,
807
+ canStart,
808
+ start: () => {
809
+ if (canStart()) {
810
+ run();
811
+ } else {
812
+ pause().then(run);
813
+ }
814
+ return thenable;
815
+ }
816
+ };
817
+ }
818
+
819
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/removable.js
820
+ var Removable = class {
821
+ #gcTimeout;
822
+ destroy() {
823
+ this.clearGcTimeout();
824
+ }
825
+ scheduleGc() {
826
+ this.clearGcTimeout();
827
+ if (isValidTimeout(this.gcTime)) {
828
+ this.#gcTimeout = timeoutManager.setTimeout(() => {
829
+ this.optionalRemove();
830
+ }, this.gcTime);
831
+ }
832
+ }
833
+ updateGcTime(newGcTime) {
834
+ this.gcTime = Math.max(
835
+ this.gcTime || 0,
836
+ newGcTime ?? (isServer ? Infinity : 5 * 60 * 1e3)
837
+ );
838
+ }
839
+ clearGcTimeout() {
840
+ if (this.#gcTimeout) {
841
+ timeoutManager.clearTimeout(this.#gcTimeout);
842
+ this.#gcTimeout = void 0;
843
+ }
844
+ }
845
+ };
846
+
847
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/query.js
848
+ var Query = class extends Removable {
849
+ #initialState;
850
+ #revertState;
851
+ #cache;
852
+ #client;
853
+ #retryer;
854
+ #defaultOptions;
855
+ #abortSignalConsumed;
856
+ constructor(config) {
857
+ super();
858
+ this.#abortSignalConsumed = false;
859
+ this.#defaultOptions = config.defaultOptions;
860
+ this.setOptions(config.options);
861
+ this.observers = [];
862
+ this.#client = config.client;
863
+ this.#cache = this.#client.getQueryCache();
864
+ this.queryKey = config.queryKey;
865
+ this.queryHash = config.queryHash;
866
+ this.#initialState = getDefaultState(this.options);
867
+ this.state = config.state ?? this.#initialState;
868
+ this.scheduleGc();
869
+ }
870
+ get meta() {
871
+ return this.options.meta;
872
+ }
873
+ get promise() {
874
+ return this.#retryer?.promise;
875
+ }
876
+ setOptions(options) {
877
+ this.options = { ...this.#defaultOptions, ...options };
878
+ this.updateGcTime(this.options.gcTime);
879
+ if (this.state && this.state.data === void 0) {
880
+ const defaultState = getDefaultState(this.options);
881
+ if (defaultState.data !== void 0) {
882
+ this.setState(
883
+ successState(defaultState.data, defaultState.dataUpdatedAt)
884
+ );
885
+ this.#initialState = defaultState;
886
+ }
887
+ }
888
+ }
889
+ optionalRemove() {
890
+ if (!this.observers.length && this.state.fetchStatus === "idle") {
891
+ this.#cache.remove(this);
892
+ }
893
+ }
894
+ setData(newData, options) {
895
+ const data = replaceData(this.state.data, newData, this.options);
896
+ this.#dispatch({
897
+ data,
898
+ type: "success",
899
+ dataUpdatedAt: options?.updatedAt,
900
+ manual: options?.manual
901
+ });
902
+ return data;
903
+ }
904
+ setState(state, setStateOptions) {
905
+ this.#dispatch({ type: "setState", state, setStateOptions });
906
+ }
907
+ cancel(options) {
908
+ const promise = this.#retryer?.promise;
909
+ this.#retryer?.cancel(options);
910
+ return promise ? promise.then(noop).catch(noop) : Promise.resolve();
911
+ }
912
+ destroy() {
913
+ super.destroy();
914
+ this.cancel({ silent: true });
915
+ }
916
+ reset() {
917
+ this.destroy();
918
+ this.setState(this.#initialState);
919
+ }
920
+ isActive() {
921
+ return this.observers.some(
922
+ (observer) => resolveEnabled(observer.options.enabled, this) !== false
923
+ );
924
+ }
925
+ isDisabled() {
926
+ if (this.getObserversCount() > 0) {
927
+ return !this.isActive();
928
+ }
929
+ return this.options.queryFn === skipToken || this.state.dataUpdateCount + this.state.errorUpdateCount === 0;
930
+ }
931
+ isStatic() {
932
+ if (this.getObserversCount() > 0) {
933
+ return this.observers.some(
934
+ (observer) => resolveStaleTime(observer.options.staleTime, this) === "static"
935
+ );
936
+ }
937
+ return false;
938
+ }
939
+ isStale() {
940
+ if (this.getObserversCount() > 0) {
941
+ return this.observers.some(
942
+ (observer) => observer.getCurrentResult().isStale
943
+ );
944
+ }
945
+ return this.state.data === void 0 || this.state.isInvalidated;
946
+ }
947
+ isStaleByTime(staleTime = 0) {
948
+ if (this.state.data === void 0) {
949
+ return true;
950
+ }
951
+ if (staleTime === "static") {
952
+ return false;
953
+ }
954
+ if (this.state.isInvalidated) {
955
+ return true;
956
+ }
957
+ return !timeUntilStale(this.state.dataUpdatedAt, staleTime);
958
+ }
959
+ onFocus() {
960
+ const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
961
+ observer?.refetch({ cancelRefetch: false });
962
+ this.#retryer?.continue();
963
+ }
964
+ onOnline() {
965
+ const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
966
+ observer?.refetch({ cancelRefetch: false });
967
+ this.#retryer?.continue();
968
+ }
969
+ addObserver(observer) {
970
+ if (!this.observers.includes(observer)) {
971
+ this.observers.push(observer);
972
+ this.clearGcTimeout();
973
+ this.#cache.notify({ type: "observerAdded", query: this, observer });
974
+ }
975
+ }
976
+ removeObserver(observer) {
977
+ if (this.observers.includes(observer)) {
978
+ this.observers = this.observers.filter((x) => x !== observer);
979
+ if (!this.observers.length) {
980
+ if (this.#retryer) {
981
+ if (this.#abortSignalConsumed) {
982
+ this.#retryer.cancel({ revert: true });
983
+ } else {
984
+ this.#retryer.cancelRetry();
985
+ }
986
+ }
987
+ this.scheduleGc();
988
+ }
989
+ this.#cache.notify({ type: "observerRemoved", query: this, observer });
990
+ }
991
+ }
992
+ getObserversCount() {
993
+ return this.observers.length;
994
+ }
995
+ invalidate() {
996
+ if (!this.state.isInvalidated) {
997
+ this.#dispatch({ type: "invalidate" });
998
+ }
999
+ }
1000
+ async fetch(options, fetchOptions) {
1001
+ if (this.state.fetchStatus !== "idle" && // If the promise in the retryer is already rejected, we have to definitely
1002
+ // re-start the fetch; there is a chance that the query is still in a
1003
+ // pending state when that happens
1004
+ this.#retryer?.status() !== "rejected") {
1005
+ if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) {
1006
+ this.cancel({ silent: true });
1007
+ } else if (this.#retryer) {
1008
+ this.#retryer.continueRetry();
1009
+ return this.#retryer.promise;
1010
+ }
1011
+ }
1012
+ if (options) {
1013
+ this.setOptions(options);
1014
+ }
1015
+ if (!this.options.queryFn) {
1016
+ const observer = this.observers.find((x) => x.options.queryFn);
1017
+ if (observer) {
1018
+ this.setOptions(observer.options);
1019
+ }
1020
+ }
1021
+ if (process.env.NODE_ENV !== "production") {
1022
+ if (!Array.isArray(this.options.queryKey)) {
1023
+ console.error(
1024
+ `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']`
1025
+ );
1026
+ }
1027
+ }
1028
+ const abortController = new AbortController();
1029
+ const addSignalProperty = (object) => {
1030
+ Object.defineProperty(object, "signal", {
1031
+ enumerable: true,
1032
+ get: () => {
1033
+ this.#abortSignalConsumed = true;
1034
+ return abortController.signal;
1035
+ }
1036
+ });
1037
+ };
1038
+ const fetchFn = () => {
1039
+ const queryFn = ensureQueryFn(this.options, fetchOptions);
1040
+ const createQueryFnContext = () => {
1041
+ const queryFnContext2 = {
1042
+ client: this.#client,
1043
+ queryKey: this.queryKey,
1044
+ meta: this.meta
1045
+ };
1046
+ addSignalProperty(queryFnContext2);
1047
+ return queryFnContext2;
1048
+ };
1049
+ const queryFnContext = createQueryFnContext();
1050
+ this.#abortSignalConsumed = false;
1051
+ if (this.options.persister) {
1052
+ return this.options.persister(
1053
+ queryFn,
1054
+ queryFnContext,
1055
+ this
1056
+ );
1057
+ }
1058
+ return queryFn(queryFnContext);
1059
+ };
1060
+ const createFetchContext = () => {
1061
+ const context2 = {
1062
+ fetchOptions,
1063
+ options: this.options,
1064
+ queryKey: this.queryKey,
1065
+ client: this.#client,
1066
+ state: this.state,
1067
+ fetchFn
1068
+ };
1069
+ addSignalProperty(context2);
1070
+ return context2;
1071
+ };
1072
+ const context = createFetchContext();
1073
+ this.options.behavior?.onFetch(context, this);
1074
+ this.#revertState = this.state;
1075
+ if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) {
1076
+ this.#dispatch({ type: "fetch", meta: context.fetchOptions?.meta });
1077
+ }
1078
+ this.#retryer = createRetryer({
1079
+ initialPromise: fetchOptions?.initialPromise,
1080
+ fn: context.fetchFn,
1081
+ onCancel: (error) => {
1082
+ if (error instanceof CancelledError && error.revert) {
1083
+ this.setState({
1084
+ ...this.#revertState,
1085
+ fetchStatus: "idle"
1086
+ });
1087
+ }
1088
+ abortController.abort();
1089
+ },
1090
+ onFail: (failureCount, error) => {
1091
+ this.#dispatch({ type: "failed", failureCount, error });
1092
+ },
1093
+ onPause: () => {
1094
+ this.#dispatch({ type: "pause" });
1095
+ },
1096
+ onContinue: () => {
1097
+ this.#dispatch({ type: "continue" });
1098
+ },
1099
+ retry: context.options.retry,
1100
+ retryDelay: context.options.retryDelay,
1101
+ networkMode: context.options.networkMode,
1102
+ canRun: () => true
1103
+ });
1104
+ try {
1105
+ const data = await this.#retryer.start();
1106
+ if (data === void 0) {
1107
+ if (process.env.NODE_ENV !== "production") {
1108
+ console.error(
1109
+ `Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`
1110
+ );
1111
+ }
1112
+ throw new Error(`${this.queryHash} data is undefined`);
1113
+ }
1114
+ this.setData(data);
1115
+ this.#cache.config.onSuccess?.(data, this);
1116
+ this.#cache.config.onSettled?.(
1117
+ data,
1118
+ this.state.error,
1119
+ this
1120
+ );
1121
+ return data;
1122
+ } catch (error) {
1123
+ if (error instanceof CancelledError) {
1124
+ if (error.silent) {
1125
+ return this.#retryer.promise;
1126
+ } else if (error.revert) {
1127
+ if (this.state.data === void 0) {
1128
+ throw error;
1129
+ }
1130
+ return this.state.data;
1131
+ }
1132
+ }
1133
+ this.#dispatch({
1134
+ type: "error",
1135
+ error
1136
+ });
1137
+ this.#cache.config.onError?.(
1138
+ error,
1139
+ this
1140
+ );
1141
+ this.#cache.config.onSettled?.(
1142
+ this.state.data,
1143
+ error,
1144
+ this
1145
+ );
1146
+ throw error;
1147
+ } finally {
1148
+ this.scheduleGc();
1149
+ }
1150
+ }
1151
+ #dispatch(action) {
1152
+ const reducer = (state) => {
1153
+ switch (action.type) {
1154
+ case "failed":
1155
+ return {
1156
+ ...state,
1157
+ fetchFailureCount: action.failureCount,
1158
+ fetchFailureReason: action.error
1159
+ };
1160
+ case "pause":
1161
+ return {
1162
+ ...state,
1163
+ fetchStatus: "paused"
1164
+ };
1165
+ case "continue":
1166
+ return {
1167
+ ...state,
1168
+ fetchStatus: "fetching"
1169
+ };
1170
+ case "fetch":
1171
+ return {
1172
+ ...state,
1173
+ ...fetchState(state.data, this.options),
1174
+ fetchMeta: action.meta ?? null
1175
+ };
1176
+ case "success":
1177
+ const newState = {
1178
+ ...state,
1179
+ ...successState(action.data, action.dataUpdatedAt),
1180
+ dataUpdateCount: state.dataUpdateCount + 1,
1181
+ ...!action.manual && {
1182
+ fetchStatus: "idle",
1183
+ fetchFailureCount: 0,
1184
+ fetchFailureReason: null
1185
+ }
1186
+ };
1187
+ this.#revertState = action.manual ? newState : void 0;
1188
+ return newState;
1189
+ case "error":
1190
+ const error = action.error;
1191
+ return {
1192
+ ...state,
1193
+ error,
1194
+ errorUpdateCount: state.errorUpdateCount + 1,
1195
+ errorUpdatedAt: Date.now(),
1196
+ fetchFailureCount: state.fetchFailureCount + 1,
1197
+ fetchFailureReason: error,
1198
+ fetchStatus: "idle",
1199
+ status: "error",
1200
+ // flag existing data as invalidated if we get a background error
1201
+ // note that "no data" always means stale so we can set unconditionally here
1202
+ isInvalidated: true
1203
+ };
1204
+ case "invalidate":
1205
+ return {
1206
+ ...state,
1207
+ isInvalidated: true
1208
+ };
1209
+ case "setState":
1210
+ return {
1211
+ ...state,
1212
+ ...action.state
1213
+ };
1214
+ }
1215
+ };
1216
+ this.state = reducer(this.state);
1217
+ notifyManager.batch(() => {
1218
+ this.observers.forEach((observer) => {
1219
+ observer.onQueryUpdate();
1220
+ });
1221
+ this.#cache.notify({ query: this, type: "updated", action });
1222
+ });
1223
+ }
1224
+ };
1225
+ function fetchState(data, options) {
1226
+ return {
1227
+ fetchFailureCount: 0,
1228
+ fetchFailureReason: null,
1229
+ fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
1230
+ ...data === void 0 && {
1231
+ error: null,
1232
+ status: "pending"
1233
+ }
1234
+ };
1235
+ }
1236
+ function successState(data, dataUpdatedAt) {
1237
+ return {
1238
+ data,
1239
+ dataUpdatedAt: dataUpdatedAt ?? Date.now(),
1240
+ error: null,
1241
+ isInvalidated: false,
1242
+ status: "success"
1243
+ };
1244
+ }
1245
+ function getDefaultState(options) {
1246
+ const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
1247
+ const hasData = data !== void 0;
1248
+ const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
1249
+ return {
1250
+ data,
1251
+ dataUpdateCount: 0,
1252
+ dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
1253
+ error: null,
1254
+ errorUpdateCount: 0,
1255
+ errorUpdatedAt: 0,
1256
+ fetchFailureCount: 0,
1257
+ fetchFailureReason: null,
1258
+ fetchMeta: null,
1259
+ isInvalidated: false,
1260
+ status: hasData ? "success" : "pending",
1261
+ fetchStatus: "idle"
1262
+ };
1263
+ }
1264
+
1265
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/queryCache.js
1266
+ var QueryCache = class extends Subscribable {
1267
+ constructor(config = {}) {
1268
+ super();
1269
+ this.config = config;
1270
+ this.#queries = /* @__PURE__ */ new Map();
1271
+ }
1272
+ #queries;
1273
+ build(client, options, state) {
1274
+ const queryKey = options.queryKey;
1275
+ const queryHash = options.queryHash ?? hashQueryKeyByOptions(queryKey, options);
1276
+ let query = this.get(queryHash);
1277
+ if (!query) {
1278
+ query = new Query({
1279
+ client,
1280
+ queryKey,
1281
+ queryHash,
1282
+ options: client.defaultQueryOptions(options),
1283
+ state,
1284
+ defaultOptions: client.getQueryDefaults(queryKey)
1285
+ });
1286
+ this.add(query);
1287
+ }
1288
+ return query;
1289
+ }
1290
+ add(query) {
1291
+ if (!this.#queries.has(query.queryHash)) {
1292
+ this.#queries.set(query.queryHash, query);
1293
+ this.notify({
1294
+ type: "added",
1295
+ query
1296
+ });
1297
+ }
1298
+ }
1299
+ remove(query) {
1300
+ const queryInMap = this.#queries.get(query.queryHash);
1301
+ if (queryInMap) {
1302
+ query.destroy();
1303
+ if (queryInMap === query) {
1304
+ this.#queries.delete(query.queryHash);
1305
+ }
1306
+ this.notify({ type: "removed", query });
1307
+ }
1308
+ }
1309
+ clear() {
1310
+ notifyManager.batch(() => {
1311
+ this.getAll().forEach((query) => {
1312
+ this.remove(query);
1313
+ });
1314
+ });
1315
+ }
1316
+ get(queryHash) {
1317
+ return this.#queries.get(queryHash);
1318
+ }
1319
+ getAll() {
1320
+ return [...this.#queries.values()];
1321
+ }
1322
+ find(filters) {
1323
+ const defaultedFilters = { exact: true, ...filters };
1324
+ return this.getAll().find(
1325
+ (query) => matchQuery(defaultedFilters, query)
1326
+ );
1327
+ }
1328
+ findAll(filters = {}) {
1329
+ const queries = this.getAll();
1330
+ return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries;
1331
+ }
1332
+ notify(event) {
1333
+ notifyManager.batch(() => {
1334
+ this.listeners.forEach((listener) => {
1335
+ listener(event);
1336
+ });
1337
+ });
1338
+ }
1339
+ onFocus() {
1340
+ notifyManager.batch(() => {
1341
+ this.getAll().forEach((query) => {
1342
+ query.onFocus();
1343
+ });
1344
+ });
1345
+ }
1346
+ onOnline() {
1347
+ notifyManager.batch(() => {
1348
+ this.getAll().forEach((query) => {
1349
+ query.onOnline();
1350
+ });
1351
+ });
1352
+ }
1353
+ };
1354
+
1355
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/mutation.js
1356
+ var Mutation = class extends Removable {
1357
+ #client;
1358
+ #observers;
1359
+ #mutationCache;
1360
+ #retryer;
1361
+ constructor(config) {
1362
+ super();
1363
+ this.#client = config.client;
1364
+ this.mutationId = config.mutationId;
1365
+ this.#mutationCache = config.mutationCache;
1366
+ this.#observers = [];
1367
+ this.state = config.state || getDefaultState2();
1368
+ this.setOptions(config.options);
1369
+ this.scheduleGc();
1370
+ }
1371
+ setOptions(options) {
1372
+ this.options = options;
1373
+ this.updateGcTime(this.options.gcTime);
1374
+ }
1375
+ get meta() {
1376
+ return this.options.meta;
1377
+ }
1378
+ addObserver(observer) {
1379
+ if (!this.#observers.includes(observer)) {
1380
+ this.#observers.push(observer);
1381
+ this.clearGcTimeout();
1382
+ this.#mutationCache.notify({
1383
+ type: "observerAdded",
1384
+ mutation: this,
1385
+ observer
1386
+ });
1387
+ }
1388
+ }
1389
+ removeObserver(observer) {
1390
+ this.#observers = this.#observers.filter((x) => x !== observer);
1391
+ this.scheduleGc();
1392
+ this.#mutationCache.notify({
1393
+ type: "observerRemoved",
1394
+ mutation: this,
1395
+ observer
1396
+ });
1397
+ }
1398
+ optionalRemove() {
1399
+ if (!this.#observers.length) {
1400
+ if (this.state.status === "pending") {
1401
+ this.scheduleGc();
1402
+ } else {
1403
+ this.#mutationCache.remove(this);
1404
+ }
1405
+ }
1406
+ }
1407
+ continue() {
1408
+ return this.#retryer?.continue() ?? // continuing a mutation assumes that variables are set, mutation must have been dehydrated before
1409
+ this.execute(this.state.variables);
1410
+ }
1411
+ async execute(variables) {
1412
+ const onContinue = () => {
1413
+ this.#dispatch({ type: "continue" });
1414
+ };
1415
+ const mutationFnContext = {
1416
+ client: this.#client,
1417
+ meta: this.options.meta,
1418
+ mutationKey: this.options.mutationKey
1419
+ };
1420
+ this.#retryer = createRetryer({
1421
+ fn: () => {
1422
+ if (!this.options.mutationFn) {
1423
+ return Promise.reject(new Error("No mutationFn found"));
1424
+ }
1425
+ return this.options.mutationFn(variables, mutationFnContext);
1426
+ },
1427
+ onFail: (failureCount, error) => {
1428
+ this.#dispatch({ type: "failed", failureCount, error });
1429
+ },
1430
+ onPause: () => {
1431
+ this.#dispatch({ type: "pause" });
1432
+ },
1433
+ onContinue,
1434
+ retry: this.options.retry ?? 0,
1435
+ retryDelay: this.options.retryDelay,
1436
+ networkMode: this.options.networkMode,
1437
+ canRun: () => this.#mutationCache.canRun(this)
1438
+ });
1439
+ const restored = this.state.status === "pending";
1440
+ const isPaused = !this.#retryer.canStart();
1441
+ try {
1442
+ if (restored) {
1443
+ onContinue();
1444
+ } else {
1445
+ this.#dispatch({ type: "pending", variables, isPaused });
1446
+ if (this.#mutationCache.config.onMutate) {
1447
+ await this.#mutationCache.config.onMutate(
1448
+ variables,
1449
+ this,
1450
+ mutationFnContext
1451
+ );
1452
+ }
1453
+ const context = await this.options.onMutate?.(
1454
+ variables,
1455
+ mutationFnContext
1456
+ );
1457
+ if (context !== this.state.context) {
1458
+ this.#dispatch({
1459
+ type: "pending",
1460
+ context,
1461
+ variables,
1462
+ isPaused
1463
+ });
1464
+ }
1465
+ }
1466
+ const data = await this.#retryer.start();
1467
+ await this.#mutationCache.config.onSuccess?.(
1468
+ data,
1469
+ variables,
1470
+ this.state.context,
1471
+ this,
1472
+ mutationFnContext
1473
+ );
1474
+ await this.options.onSuccess?.(
1475
+ data,
1476
+ variables,
1477
+ this.state.context,
1478
+ mutationFnContext
1479
+ );
1480
+ await this.#mutationCache.config.onSettled?.(
1481
+ data,
1482
+ null,
1483
+ this.state.variables,
1484
+ this.state.context,
1485
+ this,
1486
+ mutationFnContext
1487
+ );
1488
+ await this.options.onSettled?.(
1489
+ data,
1490
+ null,
1491
+ variables,
1492
+ this.state.context,
1493
+ mutationFnContext
1494
+ );
1495
+ this.#dispatch({ type: "success", data });
1496
+ return data;
1497
+ } catch (error) {
1498
+ try {
1499
+ await this.#mutationCache.config.onError?.(
1500
+ error,
1501
+ variables,
1502
+ this.state.context,
1503
+ this,
1504
+ mutationFnContext
1505
+ );
1506
+ } catch (e) {
1507
+ void Promise.reject(e);
1508
+ }
1509
+ try {
1510
+ await this.options.onError?.(
1511
+ error,
1512
+ variables,
1513
+ this.state.context,
1514
+ mutationFnContext
1515
+ );
1516
+ } catch (e) {
1517
+ void Promise.reject(e);
1518
+ }
1519
+ try {
1520
+ await this.#mutationCache.config.onSettled?.(
1521
+ void 0,
1522
+ error,
1523
+ this.state.variables,
1524
+ this.state.context,
1525
+ this,
1526
+ mutationFnContext
1527
+ );
1528
+ } catch (e) {
1529
+ void Promise.reject(e);
1530
+ }
1531
+ try {
1532
+ await this.options.onSettled?.(
1533
+ void 0,
1534
+ error,
1535
+ variables,
1536
+ this.state.context,
1537
+ mutationFnContext
1538
+ );
1539
+ } catch (e) {
1540
+ void Promise.reject(e);
1541
+ }
1542
+ this.#dispatch({ type: "error", error });
1543
+ throw error;
1544
+ } finally {
1545
+ this.#mutationCache.runNext(this);
1546
+ }
1547
+ }
1548
+ #dispatch(action) {
1549
+ const reducer = (state) => {
1550
+ switch (action.type) {
1551
+ case "failed":
1552
+ return {
1553
+ ...state,
1554
+ failureCount: action.failureCount,
1555
+ failureReason: action.error
1556
+ };
1557
+ case "pause":
1558
+ return {
1559
+ ...state,
1560
+ isPaused: true
1561
+ };
1562
+ case "continue":
1563
+ return {
1564
+ ...state,
1565
+ isPaused: false
1566
+ };
1567
+ case "pending":
1568
+ return {
1569
+ ...state,
1570
+ context: action.context,
1571
+ data: void 0,
1572
+ failureCount: 0,
1573
+ failureReason: null,
1574
+ error: null,
1575
+ isPaused: action.isPaused,
1576
+ status: "pending",
1577
+ variables: action.variables,
1578
+ submittedAt: Date.now()
1579
+ };
1580
+ case "success":
1581
+ return {
1582
+ ...state,
1583
+ data: action.data,
1584
+ failureCount: 0,
1585
+ failureReason: null,
1586
+ error: null,
1587
+ status: "success",
1588
+ isPaused: false
1589
+ };
1590
+ case "error":
1591
+ return {
1592
+ ...state,
1593
+ data: void 0,
1594
+ error: action.error,
1595
+ failureCount: state.failureCount + 1,
1596
+ failureReason: action.error,
1597
+ isPaused: false,
1598
+ status: "error"
1599
+ };
1600
+ }
1601
+ };
1602
+ this.state = reducer(this.state);
1603
+ notifyManager.batch(() => {
1604
+ this.#observers.forEach((observer) => {
1605
+ observer.onMutationUpdate(action);
1606
+ });
1607
+ this.#mutationCache.notify({
1608
+ mutation: this,
1609
+ type: "updated",
1610
+ action
1611
+ });
1612
+ });
1613
+ }
1614
+ };
1615
+ function getDefaultState2() {
1616
+ return {
1617
+ context: void 0,
1618
+ data: void 0,
1619
+ error: null,
1620
+ failureCount: 0,
1621
+ failureReason: null,
1622
+ isPaused: false,
1623
+ status: "idle",
1624
+ variables: void 0,
1625
+ submittedAt: 0
1626
+ };
1627
+ }
1628
+
1629
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/mutationCache.js
1630
+ var MutationCache = class extends Subscribable {
1631
+ constructor(config = {}) {
1632
+ super();
1633
+ this.config = config;
1634
+ this.#mutations = /* @__PURE__ */ new Set();
1635
+ this.#scopes = /* @__PURE__ */ new Map();
1636
+ this.#mutationId = 0;
1637
+ }
1638
+ #mutations;
1639
+ #scopes;
1640
+ #mutationId;
1641
+ build(client, options, state) {
1642
+ const mutation = new Mutation({
1643
+ client,
1644
+ mutationCache: this,
1645
+ mutationId: ++this.#mutationId,
1646
+ options: client.defaultMutationOptions(options),
1647
+ state
1648
+ });
1649
+ this.add(mutation);
1650
+ return mutation;
1651
+ }
1652
+ add(mutation) {
1653
+ this.#mutations.add(mutation);
1654
+ const scope = scopeFor(mutation);
1655
+ if (typeof scope === "string") {
1656
+ const scopedMutations = this.#scopes.get(scope);
1657
+ if (scopedMutations) {
1658
+ scopedMutations.push(mutation);
1659
+ } else {
1660
+ this.#scopes.set(scope, [mutation]);
1661
+ }
1662
+ }
1663
+ this.notify({ type: "added", mutation });
1664
+ }
1665
+ remove(mutation) {
1666
+ if (this.#mutations.delete(mutation)) {
1667
+ const scope = scopeFor(mutation);
1668
+ if (typeof scope === "string") {
1669
+ const scopedMutations = this.#scopes.get(scope);
1670
+ if (scopedMutations) {
1671
+ if (scopedMutations.length > 1) {
1672
+ const index = scopedMutations.indexOf(mutation);
1673
+ if (index !== -1) {
1674
+ scopedMutations.splice(index, 1);
1675
+ }
1676
+ } else if (scopedMutations[0] === mutation) {
1677
+ this.#scopes.delete(scope);
1678
+ }
1679
+ }
1680
+ }
1681
+ }
1682
+ this.notify({ type: "removed", mutation });
1683
+ }
1684
+ canRun(mutation) {
1685
+ const scope = scopeFor(mutation);
1686
+ if (typeof scope === "string") {
1687
+ const mutationsWithSameScope = this.#scopes.get(scope);
1688
+ const firstPendingMutation = mutationsWithSameScope?.find(
1689
+ (m) => m.state.status === "pending"
1690
+ );
1691
+ return !firstPendingMutation || firstPendingMutation === mutation;
1692
+ } else {
1693
+ return true;
1694
+ }
1695
+ }
1696
+ runNext(mutation) {
1697
+ const scope = scopeFor(mutation);
1698
+ if (typeof scope === "string") {
1699
+ const foundMutation = this.#scopes.get(scope)?.find((m) => m !== mutation && m.state.isPaused);
1700
+ return foundMutation?.continue() ?? Promise.resolve();
1701
+ } else {
1702
+ return Promise.resolve();
1703
+ }
1704
+ }
1705
+ clear() {
1706
+ notifyManager.batch(() => {
1707
+ this.#mutations.forEach((mutation) => {
1708
+ this.notify({ type: "removed", mutation });
1709
+ });
1710
+ this.#mutations.clear();
1711
+ this.#scopes.clear();
1712
+ });
1713
+ }
1714
+ getAll() {
1715
+ return Array.from(this.#mutations);
1716
+ }
1717
+ find(filters) {
1718
+ const defaultedFilters = { exact: true, ...filters };
1719
+ return this.getAll().find(
1720
+ (mutation) => matchMutation(defaultedFilters, mutation)
1721
+ );
1722
+ }
1723
+ findAll(filters = {}) {
1724
+ return this.getAll().filter((mutation) => matchMutation(filters, mutation));
1725
+ }
1726
+ notify(event) {
1727
+ notifyManager.batch(() => {
1728
+ this.listeners.forEach((listener) => {
1729
+ listener(event);
1730
+ });
1731
+ });
1732
+ }
1733
+ resumePausedMutations() {
1734
+ const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
1735
+ return notifyManager.batch(
1736
+ () => Promise.all(
1737
+ pausedMutations.map((mutation) => mutation.continue().catch(noop))
1738
+ )
1739
+ );
1740
+ }
1741
+ };
1742
+ function scopeFor(mutation) {
1743
+ return mutation.options.scope?.id;
1744
+ }
1745
+
1746
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
1747
+ function infiniteQueryBehavior(pages) {
1748
+ return {
1749
+ onFetch: (context, query) => {
1750
+ const options = context.options;
1751
+ const direction = context.fetchOptions?.meta?.fetchMore?.direction;
1752
+ const oldPages = context.state.data?.pages || [];
1753
+ const oldPageParams = context.state.data?.pageParams || [];
1754
+ let result = { pages: [], pageParams: [] };
1755
+ let currentPage = 0;
1756
+ const fetchFn = async () => {
1757
+ let cancelled = false;
1758
+ const addSignalProperty = (object) => {
1759
+ addConsumeAwareSignal(
1760
+ object,
1761
+ () => context.signal,
1762
+ () => cancelled = true
1763
+ );
1764
+ };
1765
+ const queryFn = ensureQueryFn(context.options, context.fetchOptions);
1766
+ const fetchPage = async (data, param, previous) => {
1767
+ if (cancelled) {
1768
+ return Promise.reject();
1769
+ }
1770
+ if (param == null && data.pages.length) {
1771
+ return Promise.resolve(data);
1772
+ }
1773
+ const createQueryFnContext = () => {
1774
+ const queryFnContext2 = {
1775
+ client: context.client,
1776
+ queryKey: context.queryKey,
1777
+ pageParam: param,
1778
+ direction: previous ? "backward" : "forward",
1779
+ meta: context.options.meta
1780
+ };
1781
+ addSignalProperty(queryFnContext2);
1782
+ return queryFnContext2;
1783
+ };
1784
+ const queryFnContext = createQueryFnContext();
1785
+ const page = await queryFn(queryFnContext);
1786
+ const { maxPages } = context.options;
1787
+ const addTo = previous ? addToStart : addToEnd;
1788
+ return {
1789
+ pages: addTo(data.pages, page, maxPages),
1790
+ pageParams: addTo(data.pageParams, param, maxPages)
1791
+ };
1792
+ };
1793
+ if (direction && oldPages.length) {
1794
+ const previous = direction === "backward";
1795
+ const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
1796
+ const oldData = {
1797
+ pages: oldPages,
1798
+ pageParams: oldPageParams
1799
+ };
1800
+ const param = pageParamFn(options, oldData);
1801
+ result = await fetchPage(oldData, param, previous);
1802
+ } else {
1803
+ const remainingPages = pages ?? oldPages.length;
1804
+ do {
1805
+ const param = currentPage === 0 ? oldPageParams[0] ?? options.initialPageParam : getNextPageParam(options, result);
1806
+ if (currentPage > 0 && param == null) {
1807
+ break;
1808
+ }
1809
+ result = await fetchPage(result, param);
1810
+ currentPage++;
1811
+ } while (currentPage < remainingPages);
1812
+ }
1813
+ return result;
1814
+ };
1815
+ if (context.options.persister) {
1816
+ context.fetchFn = () => {
1817
+ return context.options.persister?.(
1818
+ fetchFn,
1819
+ {
1820
+ client: context.client,
1821
+ queryKey: context.queryKey,
1822
+ meta: context.options.meta,
1823
+ signal: context.signal
1824
+ },
1825
+ query
1826
+ );
1827
+ };
1828
+ } else {
1829
+ context.fetchFn = fetchFn;
1830
+ }
1831
+ }
1832
+ };
1833
+ }
1834
+ function getNextPageParam(options, { pages, pageParams }) {
1835
+ const lastIndex = pages.length - 1;
1836
+ return pages.length > 0 ? options.getNextPageParam(
1837
+ pages[lastIndex],
1838
+ pages,
1839
+ pageParams[lastIndex],
1840
+ pageParams
1841
+ ) : void 0;
1842
+ }
1843
+ function getPreviousPageParam(options, { pages, pageParams }) {
1844
+ return pages.length > 0 ? options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams) : void 0;
1845
+ }
1846
+
1847
+ // ../node_modules/.pnpm/@tanstack+query-core@5.90.20/node_modules/@tanstack/query-core/build/modern/queryClient.js
1848
+ var QueryClient = class {
1849
+ #queryCache;
1850
+ #mutationCache;
1851
+ #defaultOptions;
1852
+ #queryDefaults;
1853
+ #mutationDefaults;
1854
+ #mountCount;
1855
+ #unsubscribeFocus;
1856
+ #unsubscribeOnline;
1857
+ constructor(config = {}) {
1858
+ this.#queryCache = config.queryCache || new QueryCache();
1859
+ this.#mutationCache = config.mutationCache || new MutationCache();
1860
+ this.#defaultOptions = config.defaultOptions || {};
1861
+ this.#queryDefaults = /* @__PURE__ */ new Map();
1862
+ this.#mutationDefaults = /* @__PURE__ */ new Map();
1863
+ this.#mountCount = 0;
1864
+ }
1865
+ mount() {
1866
+ this.#mountCount++;
1867
+ if (this.#mountCount !== 1) return;
1868
+ this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {
1869
+ if (focused) {
1870
+ await this.resumePausedMutations();
1871
+ this.#queryCache.onFocus();
1872
+ }
1873
+ });
1874
+ this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {
1875
+ if (online) {
1876
+ await this.resumePausedMutations();
1877
+ this.#queryCache.onOnline();
1878
+ }
1879
+ });
1880
+ }
1881
+ unmount() {
1882
+ this.#mountCount--;
1883
+ if (this.#mountCount !== 0) return;
1884
+ this.#unsubscribeFocus?.();
1885
+ this.#unsubscribeFocus = void 0;
1886
+ this.#unsubscribeOnline?.();
1887
+ this.#unsubscribeOnline = void 0;
1888
+ }
1889
+ isFetching(filters) {
1890
+ return this.#queryCache.findAll({ ...filters, fetchStatus: "fetching" }).length;
1891
+ }
1892
+ isMutating(filters) {
1893
+ return this.#mutationCache.findAll({ ...filters, status: "pending" }).length;
1894
+ }
1895
+ /**
1896
+ * Imperative (non-reactive) way to retrieve data for a QueryKey.
1897
+ * Should only be used in callbacks or functions where reading the latest data is necessary, e.g. for optimistic updates.
1898
+ *
1899
+ * Hint: Do not use this function inside a component, because it won't receive updates.
1900
+ * Use `useQuery` to create a `QueryObserver` that subscribes to changes.
1901
+ */
1902
+ getQueryData(queryKey) {
1903
+ const options = this.defaultQueryOptions({ queryKey });
1904
+ return this.#queryCache.get(options.queryHash)?.state.data;
1905
+ }
1906
+ ensureQueryData(options) {
1907
+ const defaultedOptions = this.defaultQueryOptions(options);
1908
+ const query = this.#queryCache.build(this, defaultedOptions);
1909
+ const cachedData = query.state.data;
1910
+ if (cachedData === void 0) {
1911
+ return this.fetchQuery(options);
1912
+ }
1913
+ if (options.revalidateIfStale && query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query))) {
1914
+ void this.prefetchQuery(defaultedOptions);
1915
+ }
1916
+ return Promise.resolve(cachedData);
1917
+ }
1918
+ getQueriesData(filters) {
1919
+ return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {
1920
+ const data = state.data;
1921
+ return [queryKey, data];
1922
+ });
1923
+ }
1924
+ setQueryData(queryKey, updater, options) {
1925
+ const defaultedOptions = this.defaultQueryOptions({ queryKey });
1926
+ const query = this.#queryCache.get(
1927
+ defaultedOptions.queryHash
1928
+ );
1929
+ const prevData = query?.state.data;
1930
+ const data = functionalUpdate(updater, prevData);
1931
+ if (data === void 0) {
1932
+ return void 0;
1933
+ }
1934
+ return this.#queryCache.build(this, defaultedOptions).setData(data, { ...options, manual: true });
1935
+ }
1936
+ setQueriesData(filters, updater, options) {
1937
+ return notifyManager.batch(
1938
+ () => this.#queryCache.findAll(filters).map(({ queryKey }) => [
1939
+ queryKey,
1940
+ this.setQueryData(queryKey, updater, options)
1941
+ ])
1942
+ );
1943
+ }
1944
+ getQueryState(queryKey) {
1945
+ const options = this.defaultQueryOptions({ queryKey });
1946
+ return this.#queryCache.get(
1947
+ options.queryHash
1948
+ )?.state;
1949
+ }
1950
+ removeQueries(filters) {
1951
+ const queryCache = this.#queryCache;
1952
+ notifyManager.batch(() => {
1953
+ queryCache.findAll(filters).forEach((query) => {
1954
+ queryCache.remove(query);
1955
+ });
1956
+ });
1957
+ }
1958
+ resetQueries(filters, options) {
1959
+ const queryCache = this.#queryCache;
1960
+ return notifyManager.batch(() => {
1961
+ queryCache.findAll(filters).forEach((query) => {
1962
+ query.reset();
1963
+ });
1964
+ return this.refetchQueries(
1965
+ {
1966
+ type: "active",
1967
+ ...filters
1968
+ },
1969
+ options
1970
+ );
1971
+ });
1972
+ }
1973
+ cancelQueries(filters, cancelOptions = {}) {
1974
+ const defaultedCancelOptions = { revert: true, ...cancelOptions };
1975
+ const promises = notifyManager.batch(
1976
+ () => this.#queryCache.findAll(filters).map((query) => query.cancel(defaultedCancelOptions))
1977
+ );
1978
+ return Promise.all(promises).then(noop).catch(noop);
1979
+ }
1980
+ invalidateQueries(filters, options = {}) {
1981
+ return notifyManager.batch(() => {
1982
+ this.#queryCache.findAll(filters).forEach((query) => {
1983
+ query.invalidate();
1984
+ });
1985
+ if (filters?.refetchType === "none") {
1986
+ return Promise.resolve();
1987
+ }
1988
+ return this.refetchQueries(
1989
+ {
1990
+ ...filters,
1991
+ type: filters?.refetchType ?? filters?.type ?? "active"
1992
+ },
1993
+ options
1994
+ );
1995
+ });
1996
+ }
1997
+ refetchQueries(filters, options = {}) {
1998
+ const fetchOptions = {
1999
+ ...options,
2000
+ cancelRefetch: options.cancelRefetch ?? true
2001
+ };
2002
+ const promises = notifyManager.batch(
2003
+ () => this.#queryCache.findAll(filters).filter((query) => !query.isDisabled() && !query.isStatic()).map((query) => {
2004
+ let promise = query.fetch(void 0, fetchOptions);
2005
+ if (!fetchOptions.throwOnError) {
2006
+ promise = promise.catch(noop);
2007
+ }
2008
+ return query.state.fetchStatus === "paused" ? Promise.resolve() : promise;
2009
+ })
2010
+ );
2011
+ return Promise.all(promises).then(noop);
2012
+ }
2013
+ fetchQuery(options) {
2014
+ const defaultedOptions = this.defaultQueryOptions(options);
2015
+ if (defaultedOptions.retry === void 0) {
2016
+ defaultedOptions.retry = false;
2017
+ }
2018
+ const query = this.#queryCache.build(this, defaultedOptions);
2019
+ return query.isStaleByTime(
2020
+ resolveStaleTime(defaultedOptions.staleTime, query)
2021
+ ) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
2022
+ }
2023
+ prefetchQuery(options) {
2024
+ return this.fetchQuery(options).then(noop).catch(noop);
2025
+ }
2026
+ fetchInfiniteQuery(options) {
2027
+ options.behavior = infiniteQueryBehavior(options.pages);
2028
+ return this.fetchQuery(options);
2029
+ }
2030
+ prefetchInfiniteQuery(options) {
2031
+ return this.fetchInfiniteQuery(options).then(noop).catch(noop);
2032
+ }
2033
+ ensureInfiniteQueryData(options) {
2034
+ options.behavior = infiniteQueryBehavior(options.pages);
2035
+ return this.ensureQueryData(options);
2036
+ }
2037
+ resumePausedMutations() {
2038
+ if (onlineManager.isOnline()) {
2039
+ return this.#mutationCache.resumePausedMutations();
2040
+ }
2041
+ return Promise.resolve();
2042
+ }
2043
+ getQueryCache() {
2044
+ return this.#queryCache;
2045
+ }
2046
+ getMutationCache() {
2047
+ return this.#mutationCache;
2048
+ }
2049
+ getDefaultOptions() {
2050
+ return this.#defaultOptions;
2051
+ }
2052
+ setDefaultOptions(options) {
2053
+ this.#defaultOptions = options;
2054
+ }
2055
+ setQueryDefaults(queryKey, options) {
2056
+ this.#queryDefaults.set(hashKey(queryKey), {
2057
+ queryKey,
2058
+ defaultOptions: options
2059
+ });
2060
+ }
2061
+ getQueryDefaults(queryKey) {
2062
+ const defaults = [...this.#queryDefaults.values()];
2063
+ const result = {};
2064
+ defaults.forEach((queryDefault) => {
2065
+ if (partialMatchKey(queryKey, queryDefault.queryKey)) {
2066
+ Object.assign(result, queryDefault.defaultOptions);
2067
+ }
2068
+ });
2069
+ return result;
2070
+ }
2071
+ setMutationDefaults(mutationKey, options) {
2072
+ this.#mutationDefaults.set(hashKey(mutationKey), {
2073
+ mutationKey,
2074
+ defaultOptions: options
2075
+ });
2076
+ }
2077
+ getMutationDefaults(mutationKey) {
2078
+ const defaults = [...this.#mutationDefaults.values()];
2079
+ const result = {};
2080
+ defaults.forEach((queryDefault) => {
2081
+ if (partialMatchKey(mutationKey, queryDefault.mutationKey)) {
2082
+ Object.assign(result, queryDefault.defaultOptions);
2083
+ }
2084
+ });
2085
+ return result;
2086
+ }
2087
+ defaultQueryOptions(options) {
2088
+ if (options._defaulted) {
2089
+ return options;
2090
+ }
2091
+ const defaultedOptions = {
2092
+ ...this.#defaultOptions.queries,
2093
+ ...this.getQueryDefaults(options.queryKey),
2094
+ ...options,
2095
+ _defaulted: true
2096
+ };
2097
+ if (!defaultedOptions.queryHash) {
2098
+ defaultedOptions.queryHash = hashQueryKeyByOptions(
2099
+ defaultedOptions.queryKey,
2100
+ defaultedOptions
2101
+ );
2102
+ }
2103
+ if (defaultedOptions.refetchOnReconnect === void 0) {
2104
+ defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== "always";
2105
+ }
2106
+ if (defaultedOptions.throwOnError === void 0) {
2107
+ defaultedOptions.throwOnError = !!defaultedOptions.suspense;
2108
+ }
2109
+ if (!defaultedOptions.networkMode && defaultedOptions.persister) {
2110
+ defaultedOptions.networkMode = "offlineFirst";
2111
+ }
2112
+ if (defaultedOptions.queryFn === skipToken) {
2113
+ defaultedOptions.enabled = false;
2114
+ }
2115
+ return defaultedOptions;
2116
+ }
2117
+ defaultMutationOptions(options) {
2118
+ if (options?._defaulted) {
2119
+ return options;
2120
+ }
2121
+ return {
2122
+ ...this.#defaultOptions.mutations,
2123
+ ...options?.mutationKey && this.getMutationDefaults(options.mutationKey),
2124
+ ...options,
2125
+ _defaulted: true
2126
+ };
2127
+ }
2128
+ clear() {
2129
+ this.#queryCache.clear();
2130
+ this.#mutationCache.clear();
2131
+ }
2132
+ };
2133
+ var QueryClientContext = React2.createContext(
2134
+ void 0
2135
+ );
2136
+ var useQueryClient = (queryClient) => {
2137
+ const client = React2.useContext(QueryClientContext);
2138
+ if (queryClient) {
2139
+ return queryClient;
2140
+ }
2141
+ if (!client) {
2142
+ throw new Error("No QueryClient set, use QueryClientProvider to set one");
2143
+ }
2144
+ return client;
2145
+ };
2146
+ var QueryClientProvider = ({
2147
+ client,
2148
+ children
2149
+ }) => {
2150
+ React2.useEffect(() => {
2151
+ client.mount();
2152
+ return () => {
2153
+ client.unmount();
2154
+ };
2155
+ }, [client]);
2156
+ return /* @__PURE__ */ jsx(QueryClientContext.Provider, { value: client, children });
2157
+ };
2158
+ var HydrationBoundary = ({
2159
+ children,
2160
+ options = {},
2161
+ state,
2162
+ queryClient
2163
+ }) => {
2164
+ const client = useQueryClient(queryClient);
2165
+ const optionsRef = React2.useRef(options);
2166
+ React2.useEffect(() => {
2167
+ optionsRef.current = options;
2168
+ });
2169
+ const hydrationQueue = React2.useMemo(() => {
2170
+ if (state) {
2171
+ if (typeof state !== "object") {
2172
+ return;
2173
+ }
2174
+ const queryCache = client.getQueryCache();
2175
+ const queries = state.queries || [];
2176
+ const newQueries = [];
2177
+ const existingQueries = [];
2178
+ for (const dehydratedQuery of queries) {
2179
+ const existingQuery = queryCache.get(dehydratedQuery.queryHash);
2180
+ if (!existingQuery) {
2181
+ newQueries.push(dehydratedQuery);
2182
+ } else {
2183
+ const hydrationIsNewer = dehydratedQuery.state.dataUpdatedAt > existingQuery.state.dataUpdatedAt || dehydratedQuery.promise && existingQuery.state.status !== "pending" && existingQuery.state.fetchStatus !== "fetching" && dehydratedQuery.dehydratedAt !== void 0 && dehydratedQuery.dehydratedAt > existingQuery.state.dataUpdatedAt;
2184
+ if (hydrationIsNewer) {
2185
+ existingQueries.push(dehydratedQuery);
2186
+ }
2187
+ }
2188
+ }
2189
+ if (newQueries.length > 0) {
2190
+ hydrate(client, { queries: newQueries }, optionsRef.current);
2191
+ }
2192
+ if (existingQueries.length > 0) {
2193
+ return existingQueries;
2194
+ }
2195
+ }
2196
+ return void 0;
2197
+ }, [client, state]);
2198
+ React2.useEffect(() => {
2199
+ if (hydrationQueue) {
2200
+ hydrate(client, { queries: hydrationQueue }, optionsRef.current);
2201
+ }
2202
+ }, [client, hydrationQueue]);
2203
+ return children;
2204
+ };
2205
+
2206
+ export { HydrationBoundary, QueryClient, QueryClientProvider, dehydrate };
2207
+ //# sourceMappingURL=chunk-23UAGQ6N.js.map
2208
+ //# sourceMappingURL=chunk-23UAGQ6N.js.map