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