@panoptic-eng/sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1650 @@
1
+ import * as React from "react";
2
+ import { useEffect } from "react";
3
+ import { WagmiProvider, useConnect } from "wagmi";
4
+ import { exec, execSync, spawn } from "node:child_process";
5
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
+
7
+ //#region src/test/test-utils.ts
8
+ /**
9
+ * Converts an object of options to an array of command line arguments.
10
+ *
11
+ * @param options The options object.
12
+ * @returns The command line arguments.
13
+ */
14
+ function toArgs(obj, options = { casing: "kebab" }) {
15
+ const { casing } = options;
16
+ return Object.entries(obj).flatMap(([key, value]) => {
17
+ if (value === void 0) return [];
18
+ if (Array.isArray(value)) return [toFlagCase(key), value.join(",")];
19
+ if (typeof value === "object" && value !== null) return Object.entries(value).flatMap(([subKey, subValue]) => {
20
+ if (subValue === void 0) return [];
21
+ const flag$1 = toFlagCase(`${key}.${subKey}`, casing === "kebab" ? "-" : "_");
22
+ return [flag$1, Array.isArray(subValue) ? subValue.join(",") : subValue];
23
+ });
24
+ const flag = toFlagCase(key, casing === "kebab" ? "-" : "_");
25
+ if (value === false) return [flag, "false"];
26
+ if (value === true) return [flag];
27
+ const stringified = value.toString();
28
+ if (stringified === "") return [flag];
29
+ return [flag, stringified];
30
+ });
31
+ }
32
+ /** Converts to a --flag-case string. */
33
+ function toFlagCase(str, separator = "-") {
34
+ const keys = [];
35
+ for (let i = 0; i < str.split(".").length; i++) {
36
+ const key = str.split(".")[i];
37
+ if (!key) continue;
38
+ keys.push(key.replace(/\s+/g, separator).replace(/([a-z])([A-Z])/g, `$1${separator}$2`).toLowerCase());
39
+ }
40
+ return `--${keys.join(".")}`;
41
+ }
42
+ const spawnAnvil = (args) => {
43
+ return new Promise((resolve, reject) => {
44
+ const subprocess = spawn(
45
+ "anvil",
46
+ toArgs({ ...args })
47
+ // [
48
+ // `--fork-url`,
49
+ // `https://eth-mainnet.g.alchemy.com/v2/${process.env.ALCHEMY_API_KEY}`,
50
+ // `--chain-id`,
51
+ // `31337`,
52
+ // `-vvvvv`,
53
+ // `--no-cors`,
54
+ // `--fork-block-number`,
55
+ // `23146780`,
56
+ // ]
57
+ );
58
+ subprocess.stdout.on("data", (data) => {
59
+ process.stdout.write(data);
60
+ if (data.toString().includes("Listening on")) {
61
+ process.stdout.write(data);
62
+ console.log(data.toString());
63
+ resolve();
64
+ }
65
+ });
66
+ subprocess.stderr.on("data", (data) => {
67
+ process.stderr.write(data);
68
+ });
69
+ subprocess.on("exit", (code) => {
70
+ if (code !== 0) {
71
+ console.error(`Child process exited with code ${code}`);
72
+ reject(new Error(`Anvil process exited with code ${code}`));
73
+ }
74
+ });
75
+ subprocess.on("error", (err) => {
76
+ console.error("Failed to start child process:", err);
77
+ reject(err);
78
+ });
79
+ });
80
+ };
81
+ const killAnvilProcess = async (port) => {
82
+ try {
83
+ const data = execSync(`lsof -iTCP:${port} -sTCP:LISTEN -t`);
84
+ const pids = data.toString().split("\n").slice(0, -1);
85
+ console.debug(`Clearing ports: ${pids.join(", ")}`);
86
+ for (const pid of pids) exec(`kill -9 ${pid}`, (error) => {
87
+ if (error) console.error(`Error while killing ${pid}: ${error}`);
88
+ });
89
+ } catch (e) {
90
+ console.error("Cleanup error: ", e.toString());
91
+ }
92
+ };
93
+ const killAllAnvilProcesses = async () => {
94
+ try {
95
+ const data = execSync("lsof -c anvil -t");
96
+ const pids = data.toString().split("\n").slice(0, -1);
97
+ console.debug(`Clearing ports: ${pids.join(", ")}`);
98
+ for (const pid of pids) exec(`kill -9 ${pid}`, (error) => {
99
+ if (error) console.error(`Error while killing ${pid}: ${error}`);
100
+ });
101
+ } catch (e) {
102
+ console.error("Cleanup error: ", e.toString());
103
+ }
104
+ };
105
+
106
+ //#endregion
107
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/subscribable.js
108
+ var Subscribable = class {
109
+ constructor() {
110
+ this.listeners = /* @__PURE__ */ new Set();
111
+ this.subscribe = this.subscribe.bind(this);
112
+ }
113
+ subscribe(listener) {
114
+ this.listeners.add(listener);
115
+ this.onSubscribe();
116
+ return () => {
117
+ this.listeners.delete(listener);
118
+ this.onUnsubscribe();
119
+ };
120
+ }
121
+ hasListeners() {
122
+ return this.listeners.size > 0;
123
+ }
124
+ onSubscribe() {}
125
+ onUnsubscribe() {}
126
+ };
127
+
128
+ //#endregion
129
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/utils.js
130
+ var isServer = typeof window === "undefined" || "Deno" in globalThis;
131
+ function noop() {
132
+ return void 0;
133
+ }
134
+ function functionalUpdate(updater, input) {
135
+ return typeof updater === "function" ? updater(input) : updater;
136
+ }
137
+ function isValidTimeout(value) {
138
+ return typeof value === "number" && value >= 0 && value !== Infinity;
139
+ }
140
+ function timeUntilStale(updatedAt, staleTime) {
141
+ return Math.max(updatedAt + (staleTime || 0) - Date.now(), 0);
142
+ }
143
+ function resolveStaleTime(staleTime, query) {
144
+ return typeof staleTime === "function" ? staleTime(query) : staleTime;
145
+ }
146
+ function matchQuery(filters, query) {
147
+ const { type = "all", exact, fetchStatus, predicate, queryKey, stale } = filters;
148
+ if (queryKey) {
149
+ if (exact) {
150
+ if (query.queryHash !== hashQueryKeyByOptions(queryKey, query.options)) return false;
151
+ } else if (!partialMatchKey(query.queryKey, queryKey)) return false;
152
+ }
153
+ if (type !== "all") {
154
+ const isActive = query.isActive();
155
+ if (type === "active" && !isActive) return false;
156
+ if (type === "inactive" && isActive) return false;
157
+ }
158
+ if (typeof stale === "boolean" && query.isStale() !== stale) return false;
159
+ if (fetchStatus && fetchStatus !== query.state.fetchStatus) return false;
160
+ if (predicate && !predicate(query)) return false;
161
+ return true;
162
+ }
163
+ function matchMutation(filters, mutation) {
164
+ const { exact, status, predicate, mutationKey } = filters;
165
+ if (mutationKey) {
166
+ if (!mutation.options.mutationKey) return false;
167
+ if (exact) {
168
+ if (hashKey(mutation.options.mutationKey) !== hashKey(mutationKey)) return false;
169
+ } else if (!partialMatchKey(mutation.options.mutationKey, mutationKey)) return false;
170
+ }
171
+ if (status && mutation.state.status !== status) return false;
172
+ if (predicate && !predicate(mutation)) return false;
173
+ return true;
174
+ }
175
+ function hashQueryKeyByOptions(queryKey, options) {
176
+ const hashFn = options?.queryKeyHashFn || hashKey;
177
+ return hashFn(queryKey);
178
+ }
179
+ function hashKey(queryKey) {
180
+ return JSON.stringify(queryKey, (_, val) => isPlainObject(val) ? Object.keys(val).sort().reduce((result, key) => {
181
+ result[key] = val[key];
182
+ return result;
183
+ }, {}) : val);
184
+ }
185
+ function partialMatchKey(a, b) {
186
+ if (a === b) return true;
187
+ if (typeof a !== typeof b) return false;
188
+ if (a && b && typeof a === "object" && typeof b === "object") return !Object.keys(b).some((key) => !partialMatchKey(a[key], b[key]));
189
+ return false;
190
+ }
191
+ function replaceEqualDeep(a, b) {
192
+ if (a === b) return a;
193
+ const array = isPlainArray(a) && isPlainArray(b);
194
+ if (array || isPlainObject(a) && isPlainObject(b)) {
195
+ const aItems = array ? a : Object.keys(a);
196
+ const aSize = aItems.length;
197
+ const bItems = array ? b : Object.keys(b);
198
+ const bSize = bItems.length;
199
+ const copy = array ? [] : {};
200
+ let equalItems = 0;
201
+ for (let i = 0; i < bSize; i++) {
202
+ const key = array ? i : bItems[i];
203
+ if ((!array && aItems.includes(key) || array) && a[key] === void 0 && b[key] === void 0) {
204
+ copy[key] = void 0;
205
+ equalItems++;
206
+ } else {
207
+ copy[key] = replaceEqualDeep(a[key], b[key]);
208
+ if (copy[key] === a[key] && a[key] !== void 0) equalItems++;
209
+ }
210
+ }
211
+ return aSize === bSize && equalItems === aSize ? a : copy;
212
+ }
213
+ return b;
214
+ }
215
+ function isPlainArray(value) {
216
+ return Array.isArray(value) && value.length === Object.keys(value).length;
217
+ }
218
+ function isPlainObject(o) {
219
+ if (!hasObjectPrototype(o)) return false;
220
+ const ctor = o.constructor;
221
+ if (ctor === void 0) return true;
222
+ const prot = ctor.prototype;
223
+ if (!hasObjectPrototype(prot)) return false;
224
+ if (!prot.hasOwnProperty("isPrototypeOf")) return false;
225
+ if (Object.getPrototypeOf(o) !== Object.prototype) return false;
226
+ return true;
227
+ }
228
+ function hasObjectPrototype(o) {
229
+ return Object.prototype.toString.call(o) === "[object Object]";
230
+ }
231
+ function sleep(ms) {
232
+ return new Promise((resolve) => {
233
+ setTimeout(resolve, ms);
234
+ });
235
+ }
236
+ function replaceData(prevData, data, options) {
237
+ if (typeof options.structuralSharing === "function") return options.structuralSharing(prevData, data);
238
+ else if (options.structuralSharing !== false) return replaceEqualDeep(prevData, data);
239
+ return data;
240
+ }
241
+ function addToEnd(items, item, max = 0) {
242
+ const newItems = [...items, item];
243
+ return max && newItems.length > max ? newItems.slice(1) : newItems;
244
+ }
245
+ function addToStart(items, item, max = 0) {
246
+ const newItems = [item, ...items];
247
+ return max && newItems.length > max ? newItems.slice(0, -1) : newItems;
248
+ }
249
+ var skipToken = Symbol();
250
+ var ensureQueryFn = (options, fetchOptions) => {
251
+ if (process.env.NODE_ENV !== "production") {
252
+ if (options.queryFn === skipToken) console.error(`Attempted to invoke queryFn when set to skipToken. This is likely a configuration error. Query hash: '${options.queryHash}'`);
253
+ }
254
+ if (!options.queryFn && fetchOptions?.initialPromise) return () => fetchOptions.initialPromise;
255
+ if (!options.queryFn || options.queryFn === skipToken) return () => Promise.reject(new Error(`Missing queryFn: '${options.queryHash}'`));
256
+ return options.queryFn;
257
+ };
258
+
259
+ //#endregion
260
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/focusManager.js
261
+ var FocusManager = class extends Subscribable {
262
+ #focused;
263
+ #cleanup;
264
+ #setup;
265
+ constructor() {
266
+ super();
267
+ this.#setup = (onFocus) => {
268
+ if (!isServer && window.addEventListener) {
269
+ const listener = () => onFocus();
270
+ window.addEventListener("visibilitychange", listener, false);
271
+ return () => {
272
+ window.removeEventListener("visibilitychange", listener);
273
+ };
274
+ }
275
+ return;
276
+ };
277
+ }
278
+ onSubscribe() {
279
+ if (!this.#cleanup) this.setEventListener(this.#setup);
280
+ }
281
+ onUnsubscribe() {
282
+ if (!this.hasListeners()) {
283
+ this.#cleanup?.();
284
+ this.#cleanup = void 0;
285
+ }
286
+ }
287
+ setEventListener(setup) {
288
+ this.#setup = setup;
289
+ this.#cleanup?.();
290
+ this.#cleanup = setup((focused) => {
291
+ if (typeof focused === "boolean") this.setFocused(focused);
292
+ else this.onFocus();
293
+ });
294
+ }
295
+ setFocused(focused) {
296
+ const changed = this.#focused !== focused;
297
+ if (changed) {
298
+ this.#focused = focused;
299
+ this.onFocus();
300
+ }
301
+ }
302
+ onFocus() {
303
+ const isFocused = this.isFocused();
304
+ this.listeners.forEach((listener) => {
305
+ listener(isFocused);
306
+ });
307
+ }
308
+ isFocused() {
309
+ if (typeof this.#focused === "boolean") return this.#focused;
310
+ return globalThis.document?.visibilityState !== "hidden";
311
+ }
312
+ };
313
+ var focusManager = new FocusManager();
314
+
315
+ //#endregion
316
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/onlineManager.js
317
+ var OnlineManager = class extends Subscribable {
318
+ #online = true;
319
+ #cleanup;
320
+ #setup;
321
+ constructor() {
322
+ super();
323
+ this.#setup = (onOnline) => {
324
+ if (!isServer && window.addEventListener) {
325
+ const onlineListener = () => onOnline(true);
326
+ const offlineListener = () => onOnline(false);
327
+ window.addEventListener("online", onlineListener, false);
328
+ window.addEventListener("offline", offlineListener, false);
329
+ return () => {
330
+ window.removeEventListener("online", onlineListener);
331
+ window.removeEventListener("offline", offlineListener);
332
+ };
333
+ }
334
+ return;
335
+ };
336
+ }
337
+ onSubscribe() {
338
+ if (!this.#cleanup) this.setEventListener(this.#setup);
339
+ }
340
+ onUnsubscribe() {
341
+ if (!this.hasListeners()) {
342
+ this.#cleanup?.();
343
+ this.#cleanup = void 0;
344
+ }
345
+ }
346
+ setEventListener(setup) {
347
+ this.#setup = setup;
348
+ this.#cleanup?.();
349
+ this.#cleanup = setup(this.setOnline.bind(this));
350
+ }
351
+ setOnline(online) {
352
+ const changed = this.#online !== online;
353
+ if (changed) {
354
+ this.#online = online;
355
+ this.listeners.forEach((listener) => {
356
+ listener(online);
357
+ });
358
+ }
359
+ }
360
+ isOnline() {
361
+ return this.#online;
362
+ }
363
+ };
364
+ var onlineManager = new OnlineManager();
365
+
366
+ //#endregion
367
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/retryer.js
368
+ function defaultRetryDelay(failureCount) {
369
+ return Math.min(1e3 * 2 ** failureCount, 3e4);
370
+ }
371
+ function canFetch(networkMode) {
372
+ return (networkMode ?? "online") === "online" ? onlineManager.isOnline() : true;
373
+ }
374
+ var CancelledError = class {
375
+ constructor(options) {
376
+ this.revert = options?.revert;
377
+ this.silent = options?.silent;
378
+ }
379
+ };
380
+ function isCancelledError(value) {
381
+ return value instanceof CancelledError;
382
+ }
383
+ function createRetryer(config) {
384
+ let isRetryCancelled = false;
385
+ let failureCount = 0;
386
+ let isResolved = false;
387
+ let continueFn;
388
+ let promiseResolve;
389
+ let promiseReject;
390
+ const promise = new Promise((outerResolve, outerReject) => {
391
+ promiseResolve = outerResolve;
392
+ promiseReject = outerReject;
393
+ });
394
+ const cancel = (cancelOptions) => {
395
+ if (!isResolved) {
396
+ reject(new CancelledError(cancelOptions));
397
+ config.abort?.();
398
+ }
399
+ };
400
+ const cancelRetry = () => {
401
+ isRetryCancelled = true;
402
+ };
403
+ const continueRetry = () => {
404
+ isRetryCancelled = false;
405
+ };
406
+ const canContinue = () => focusManager.isFocused() && (config.networkMode === "always" || onlineManager.isOnline()) && config.canRun();
407
+ const canStart = () => canFetch(config.networkMode) && config.canRun();
408
+ const resolve = (value) => {
409
+ if (!isResolved) {
410
+ isResolved = true;
411
+ config.onSuccess?.(value);
412
+ continueFn?.();
413
+ promiseResolve(value);
414
+ }
415
+ };
416
+ const reject = (value) => {
417
+ if (!isResolved) {
418
+ isResolved = true;
419
+ config.onError?.(value);
420
+ continueFn?.();
421
+ promiseReject(value);
422
+ }
423
+ };
424
+ const pause = () => {
425
+ return new Promise((continueResolve) => {
426
+ continueFn = (value) => {
427
+ if (isResolved || canContinue()) continueResolve(value);
428
+ };
429
+ config.onPause?.();
430
+ }).then(() => {
431
+ continueFn = void 0;
432
+ if (!isResolved) config.onContinue?.();
433
+ });
434
+ };
435
+ const run = () => {
436
+ if (isResolved) return;
437
+ let promiseOrValue;
438
+ const initialPromise = failureCount === 0 ? config.initialPromise : void 0;
439
+ try {
440
+ promiseOrValue = initialPromise ?? config.fn();
441
+ } catch (error) {
442
+ promiseOrValue = Promise.reject(error);
443
+ }
444
+ Promise.resolve(promiseOrValue).then(resolve).catch((error) => {
445
+ if (isResolved) return;
446
+ const retry = config.retry ?? (isServer ? 0 : 3);
447
+ const retryDelay = config.retryDelay ?? defaultRetryDelay;
448
+ const delay = typeof retryDelay === "function" ? retryDelay(failureCount, error) : retryDelay;
449
+ const shouldRetry = retry === true || typeof retry === "number" && failureCount < retry || typeof retry === "function" && retry(failureCount, error);
450
+ if (isRetryCancelled || !shouldRetry) {
451
+ reject(error);
452
+ return;
453
+ }
454
+ failureCount++;
455
+ config.onFail?.(failureCount, error);
456
+ sleep(delay).then(() => {
457
+ return canContinue() ? void 0 : pause();
458
+ }).then(() => {
459
+ if (isRetryCancelled) reject(error);
460
+ else run();
461
+ });
462
+ });
463
+ };
464
+ return {
465
+ promise,
466
+ cancel,
467
+ continue: () => {
468
+ continueFn?.();
469
+ return promise;
470
+ },
471
+ cancelRetry,
472
+ continueRetry,
473
+ canStart,
474
+ start: () => {
475
+ if (canStart()) run();
476
+ else pause().then(run);
477
+ return promise;
478
+ }
479
+ };
480
+ }
481
+
482
+ //#endregion
483
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/notifyManager.js
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 = (cb) => setTimeout(cb, 0);
494
+ const setScheduler = (fn) => {
495
+ scheduleFn = fn;
496
+ };
497
+ const batch = (callback) => {
498
+ let result;
499
+ transactions++;
500
+ try {
501
+ result = callback();
502
+ } finally {
503
+ transactions--;
504
+ if (!transactions) flush();
505
+ }
506
+ return result;
507
+ };
508
+ const schedule = (callback) => {
509
+ if (transactions) queue.push(callback);
510
+ else scheduleFn(() => {
511
+ notifyFn(callback);
512
+ });
513
+ };
514
+ const batchCalls = (callback) => {
515
+ return (...args) => {
516
+ schedule(() => {
517
+ callback(...args);
518
+ });
519
+ };
520
+ };
521
+ const flush = () => {
522
+ const originalQueue = queue;
523
+ queue = [];
524
+ if (originalQueue.length) scheduleFn(() => {
525
+ batchNotifyFn(() => {
526
+ originalQueue.forEach((callback) => {
527
+ notifyFn(callback);
528
+ });
529
+ });
530
+ });
531
+ };
532
+ const setNotifyFunction = (fn) => {
533
+ notifyFn = fn;
534
+ };
535
+ const setBatchNotifyFunction = (fn) => {
536
+ batchNotifyFn = fn;
537
+ };
538
+ return {
539
+ batch,
540
+ batchCalls,
541
+ schedule,
542
+ setNotifyFunction,
543
+ setBatchNotifyFunction,
544
+ setScheduler
545
+ };
546
+ }
547
+ var notifyManager = createNotifyManager();
548
+
549
+ //#endregion
550
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/removable.js
551
+ var Removable = class {
552
+ #gcTimeout;
553
+ destroy() {
554
+ this.clearGcTimeout();
555
+ }
556
+ scheduleGc() {
557
+ this.clearGcTimeout();
558
+ if (isValidTimeout(this.gcTime)) this.#gcTimeout = setTimeout(() => {
559
+ this.optionalRemove();
560
+ }, this.gcTime);
561
+ }
562
+ updateGcTime(newGcTime) {
563
+ this.gcTime = Math.max(this.gcTime || 0, newGcTime ?? (isServer ? Infinity : 5 * 60 * 1e3));
564
+ }
565
+ clearGcTimeout() {
566
+ if (this.#gcTimeout) {
567
+ clearTimeout(this.#gcTimeout);
568
+ this.#gcTimeout = void 0;
569
+ }
570
+ }
571
+ };
572
+
573
+ //#endregion
574
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/query.js
575
+ var Query = class extends Removable {
576
+ #initialState;
577
+ #revertState;
578
+ #cache;
579
+ #retryer;
580
+ #defaultOptions;
581
+ #abortSignalConsumed;
582
+ constructor(config) {
583
+ super();
584
+ this.#abortSignalConsumed = false;
585
+ this.#defaultOptions = config.defaultOptions;
586
+ this.setOptions(config.options);
587
+ this.observers = [];
588
+ this.#cache = config.cache;
589
+ this.queryKey = config.queryKey;
590
+ this.queryHash = config.queryHash;
591
+ this.#initialState = config.state || getDefaultState$1(this.options);
592
+ this.state = this.#initialState;
593
+ this.scheduleGc();
594
+ }
595
+ get meta() {
596
+ return this.options.meta;
597
+ }
598
+ get promise() {
599
+ return this.#retryer?.promise;
600
+ }
601
+ setOptions(options) {
602
+ this.options = {
603
+ ...this.#defaultOptions,
604
+ ...options
605
+ };
606
+ this.updateGcTime(this.options.gcTime);
607
+ }
608
+ optionalRemove() {
609
+ if (!this.observers.length && this.state.fetchStatus === "idle") this.#cache.remove(this);
610
+ }
611
+ setData(newData, options) {
612
+ const data = replaceData(this.state.data, newData, this.options);
613
+ this.#dispatch({
614
+ data,
615
+ type: "success",
616
+ dataUpdatedAt: options?.updatedAt,
617
+ manual: options?.manual
618
+ });
619
+ return data;
620
+ }
621
+ setState(state, setStateOptions) {
622
+ this.#dispatch({
623
+ type: "setState",
624
+ state,
625
+ setStateOptions
626
+ });
627
+ }
628
+ cancel(options) {
629
+ const promise = this.#retryer?.promise;
630
+ this.#retryer?.cancel(options);
631
+ return promise ? promise.then(noop).catch(noop) : Promise.resolve();
632
+ }
633
+ destroy() {
634
+ super.destroy();
635
+ this.cancel({ silent: true });
636
+ }
637
+ reset() {
638
+ this.destroy();
639
+ this.setState(this.#initialState);
640
+ }
641
+ isActive() {
642
+ return this.observers.some((observer) => observer.options.enabled !== false);
643
+ }
644
+ isDisabled() {
645
+ return this.getObserversCount() > 0 && !this.isActive();
646
+ }
647
+ isStale() {
648
+ if (this.state.isInvalidated) return true;
649
+ if (this.getObserversCount() > 0) return this.observers.some((observer) => observer.getCurrentResult().isStale);
650
+ return this.state.data === void 0;
651
+ }
652
+ isStaleByTime(staleTime = 0) {
653
+ return this.state.isInvalidated || this.state.data === void 0 || !timeUntilStale(this.state.dataUpdatedAt, staleTime);
654
+ }
655
+ onFocus() {
656
+ const observer = this.observers.find((x) => x.shouldFetchOnWindowFocus());
657
+ observer?.refetch({ cancelRefetch: false });
658
+ this.#retryer?.continue();
659
+ }
660
+ onOnline() {
661
+ const observer = this.observers.find((x) => x.shouldFetchOnReconnect());
662
+ observer?.refetch({ cancelRefetch: false });
663
+ this.#retryer?.continue();
664
+ }
665
+ addObserver(observer) {
666
+ if (!this.observers.includes(observer)) {
667
+ this.observers.push(observer);
668
+ this.clearGcTimeout();
669
+ this.#cache.notify({
670
+ type: "observerAdded",
671
+ query: this,
672
+ observer
673
+ });
674
+ }
675
+ }
676
+ removeObserver(observer) {
677
+ if (this.observers.includes(observer)) {
678
+ this.observers = this.observers.filter((x) => x !== observer);
679
+ if (!this.observers.length) {
680
+ if (this.#retryer) if (this.#abortSignalConsumed) this.#retryer.cancel({ revert: true });
681
+ else this.#retryer.cancelRetry();
682
+ this.scheduleGc();
683
+ }
684
+ this.#cache.notify({
685
+ type: "observerRemoved",
686
+ query: this,
687
+ observer
688
+ });
689
+ }
690
+ }
691
+ getObserversCount() {
692
+ return this.observers.length;
693
+ }
694
+ invalidate() {
695
+ if (!this.state.isInvalidated) this.#dispatch({ type: "invalidate" });
696
+ }
697
+ fetch(options, fetchOptions) {
698
+ if (this.state.fetchStatus !== "idle") {
699
+ if (this.state.data !== void 0 && fetchOptions?.cancelRefetch) this.cancel({ silent: true });
700
+ else if (this.#retryer) {
701
+ this.#retryer.continueRetry();
702
+ return this.#retryer.promise;
703
+ }
704
+ }
705
+ if (options) this.setOptions(options);
706
+ if (!this.options.queryFn) {
707
+ const observer = this.observers.find((x) => x.options.queryFn);
708
+ if (observer) this.setOptions(observer.options);
709
+ }
710
+ if (process.env.NODE_ENV !== "production") {
711
+ if (!Array.isArray(this.options.queryKey)) console.error(`As of v4, queryKey needs to be an Array. If you are using a string like 'repoData', please change it to an Array, e.g. ['repoData']`);
712
+ }
713
+ const abortController = new AbortController();
714
+ const addSignalProperty = (object) => {
715
+ Object.defineProperty(object, "signal", {
716
+ enumerable: true,
717
+ get: () => {
718
+ this.#abortSignalConsumed = true;
719
+ return abortController.signal;
720
+ }
721
+ });
722
+ };
723
+ const fetchFn = () => {
724
+ const queryFn = ensureQueryFn(this.options, fetchOptions);
725
+ const queryFnContext = {
726
+ queryKey: this.queryKey,
727
+ meta: this.meta
728
+ };
729
+ addSignalProperty(queryFnContext);
730
+ this.#abortSignalConsumed = false;
731
+ if (this.options.persister) return this.options.persister(queryFn, queryFnContext, this);
732
+ return queryFn(queryFnContext);
733
+ };
734
+ const context = {
735
+ fetchOptions,
736
+ options: this.options,
737
+ queryKey: this.queryKey,
738
+ state: this.state,
739
+ fetchFn
740
+ };
741
+ addSignalProperty(context);
742
+ this.options.behavior?.onFetch(context, this);
743
+ this.#revertState = this.state;
744
+ if (this.state.fetchStatus === "idle" || this.state.fetchMeta !== context.fetchOptions?.meta) this.#dispatch({
745
+ type: "fetch",
746
+ meta: context.fetchOptions?.meta
747
+ });
748
+ const onError = (error) => {
749
+ if (!(isCancelledError(error) && error.silent)) this.#dispatch({
750
+ type: "error",
751
+ error
752
+ });
753
+ if (!isCancelledError(error)) {
754
+ this.#cache.config.onError?.(error, this);
755
+ this.#cache.config.onSettled?.(this.state.data, error, this);
756
+ }
757
+ if (!this.isFetchingOptimistic) this.scheduleGc();
758
+ this.isFetchingOptimistic = false;
759
+ };
760
+ this.#retryer = createRetryer({
761
+ initialPromise: fetchOptions?.initialPromise,
762
+ fn: context.fetchFn,
763
+ abort: abortController.abort.bind(abortController),
764
+ onSuccess: (data) => {
765
+ if (data === void 0) {
766
+ if (process.env.NODE_ENV !== "production") console.error(`Query data cannot be undefined. Please make sure to return a value other than undefined from your query function. Affected query key: ${this.queryHash}`);
767
+ onError(new Error(`${this.queryHash} data is undefined`));
768
+ return;
769
+ }
770
+ this.setData(data);
771
+ this.#cache.config.onSuccess?.(data, this);
772
+ this.#cache.config.onSettled?.(data, this.state.error, this);
773
+ if (!this.isFetchingOptimistic) this.scheduleGc();
774
+ this.isFetchingOptimistic = false;
775
+ },
776
+ onError,
777
+ onFail: (failureCount, error) => {
778
+ this.#dispatch({
779
+ type: "failed",
780
+ failureCount,
781
+ error
782
+ });
783
+ },
784
+ onPause: () => {
785
+ this.#dispatch({ type: "pause" });
786
+ },
787
+ onContinue: () => {
788
+ this.#dispatch({ type: "continue" });
789
+ },
790
+ retry: context.options.retry,
791
+ retryDelay: context.options.retryDelay,
792
+ networkMode: context.options.networkMode,
793
+ canRun: () => true
794
+ });
795
+ return this.#retryer.start();
796
+ }
797
+ #dispatch(action) {
798
+ const reducer = (state) => {
799
+ switch (action.type) {
800
+ case "failed": return {
801
+ ...state,
802
+ fetchFailureCount: action.failureCount,
803
+ fetchFailureReason: action.error
804
+ };
805
+ case "pause": return {
806
+ ...state,
807
+ fetchStatus: "paused"
808
+ };
809
+ case "continue": return {
810
+ ...state,
811
+ fetchStatus: "fetching"
812
+ };
813
+ case "fetch": return {
814
+ ...state,
815
+ ...fetchState(state.data, this.options),
816
+ fetchMeta: action.meta ?? null
817
+ };
818
+ case "success": return {
819
+ ...state,
820
+ data: action.data,
821
+ dataUpdateCount: state.dataUpdateCount + 1,
822
+ dataUpdatedAt: action.dataUpdatedAt ?? Date.now(),
823
+ error: null,
824
+ isInvalidated: false,
825
+ status: "success",
826
+ ...!action.manual && {
827
+ fetchStatus: "idle",
828
+ fetchFailureCount: 0,
829
+ fetchFailureReason: null
830
+ }
831
+ };
832
+ case "error":
833
+ const error = action.error;
834
+ if (isCancelledError(error) && error.revert && this.#revertState) return {
835
+ ...this.#revertState,
836
+ fetchStatus: "idle"
837
+ };
838
+ return {
839
+ ...state,
840
+ error,
841
+ errorUpdateCount: state.errorUpdateCount + 1,
842
+ errorUpdatedAt: Date.now(),
843
+ fetchFailureCount: state.fetchFailureCount + 1,
844
+ fetchFailureReason: error,
845
+ fetchStatus: "idle",
846
+ status: "error"
847
+ };
848
+ case "invalidate": return {
849
+ ...state,
850
+ isInvalidated: true
851
+ };
852
+ case "setState": return {
853
+ ...state,
854
+ ...action.state
855
+ };
856
+ }
857
+ };
858
+ this.state = reducer(this.state);
859
+ notifyManager.batch(() => {
860
+ this.observers.forEach((observer) => {
861
+ observer.onQueryUpdate();
862
+ });
863
+ this.#cache.notify({
864
+ query: this,
865
+ type: "updated",
866
+ action
867
+ });
868
+ });
869
+ }
870
+ };
871
+ function fetchState(data, options) {
872
+ return {
873
+ fetchFailureCount: 0,
874
+ fetchFailureReason: null,
875
+ fetchStatus: canFetch(options.networkMode) ? "fetching" : "paused",
876
+ ...data === void 0 && {
877
+ error: null,
878
+ status: "pending"
879
+ }
880
+ };
881
+ }
882
+ function getDefaultState$1(options) {
883
+ const data = typeof options.initialData === "function" ? options.initialData() : options.initialData;
884
+ const hasData = data !== void 0;
885
+ const initialDataUpdatedAt = hasData ? typeof options.initialDataUpdatedAt === "function" ? options.initialDataUpdatedAt() : options.initialDataUpdatedAt : 0;
886
+ return {
887
+ data,
888
+ dataUpdateCount: 0,
889
+ dataUpdatedAt: hasData ? initialDataUpdatedAt ?? Date.now() : 0,
890
+ error: null,
891
+ errorUpdateCount: 0,
892
+ errorUpdatedAt: 0,
893
+ fetchFailureCount: 0,
894
+ fetchFailureReason: null,
895
+ fetchMeta: null,
896
+ isInvalidated: false,
897
+ status: hasData ? "success" : "pending",
898
+ fetchStatus: "idle"
899
+ };
900
+ }
901
+
902
+ //#endregion
903
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/queryCache.js
904
+ var QueryCache = class extends Subscribable {
905
+ constructor(config = {}) {
906
+ super();
907
+ this.config = config;
908
+ this.#queries = /* @__PURE__ */ new Map();
909
+ }
910
+ #queries;
911
+ build(client, options, state) {
912
+ const queryKey = options.queryKey;
913
+ const queryHash = options.queryHash ?? hashQueryKeyByOptions(queryKey, options);
914
+ let query = this.get(queryHash);
915
+ if (!query) {
916
+ query = new Query({
917
+ cache: this,
918
+ queryKey,
919
+ queryHash,
920
+ options: client.defaultQueryOptions(options),
921
+ state,
922
+ defaultOptions: client.getQueryDefaults(queryKey)
923
+ });
924
+ this.add(query);
925
+ }
926
+ return query;
927
+ }
928
+ add(query) {
929
+ if (!this.#queries.has(query.queryHash)) {
930
+ this.#queries.set(query.queryHash, query);
931
+ this.notify({
932
+ type: "added",
933
+ query
934
+ });
935
+ }
936
+ }
937
+ remove(query) {
938
+ const queryInMap = this.#queries.get(query.queryHash);
939
+ if (queryInMap) {
940
+ query.destroy();
941
+ if (queryInMap === query) this.#queries.delete(query.queryHash);
942
+ this.notify({
943
+ type: "removed",
944
+ query
945
+ });
946
+ }
947
+ }
948
+ clear() {
949
+ notifyManager.batch(() => {
950
+ this.getAll().forEach((query) => {
951
+ this.remove(query);
952
+ });
953
+ });
954
+ }
955
+ get(queryHash) {
956
+ return this.#queries.get(queryHash);
957
+ }
958
+ getAll() {
959
+ return [...this.#queries.values()];
960
+ }
961
+ find(filters) {
962
+ const defaultedFilters = {
963
+ exact: true,
964
+ ...filters
965
+ };
966
+ return this.getAll().find((query) => matchQuery(defaultedFilters, query));
967
+ }
968
+ findAll(filters = {}) {
969
+ const queries = this.getAll();
970
+ return Object.keys(filters).length > 0 ? queries.filter((query) => matchQuery(filters, query)) : queries;
971
+ }
972
+ notify(event) {
973
+ notifyManager.batch(() => {
974
+ this.listeners.forEach((listener) => {
975
+ listener(event);
976
+ });
977
+ });
978
+ }
979
+ onFocus() {
980
+ notifyManager.batch(() => {
981
+ this.getAll().forEach((query) => {
982
+ query.onFocus();
983
+ });
984
+ });
985
+ }
986
+ onOnline() {
987
+ notifyManager.batch(() => {
988
+ this.getAll().forEach((query) => {
989
+ query.onOnline();
990
+ });
991
+ });
992
+ }
993
+ };
994
+
995
+ //#endregion
996
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/mutation.js
997
+ var Mutation = class extends Removable {
998
+ #observers;
999
+ #mutationCache;
1000
+ #retryer;
1001
+ constructor(config) {
1002
+ super();
1003
+ this.mutationId = config.mutationId;
1004
+ this.#mutationCache = config.mutationCache;
1005
+ this.#observers = [];
1006
+ this.state = config.state || getDefaultState();
1007
+ this.setOptions(config.options);
1008
+ this.scheduleGc();
1009
+ }
1010
+ setOptions(options) {
1011
+ this.options = options;
1012
+ this.updateGcTime(this.options.gcTime);
1013
+ }
1014
+ get meta() {
1015
+ return this.options.meta;
1016
+ }
1017
+ addObserver(observer) {
1018
+ if (!this.#observers.includes(observer)) {
1019
+ this.#observers.push(observer);
1020
+ this.clearGcTimeout();
1021
+ this.#mutationCache.notify({
1022
+ type: "observerAdded",
1023
+ mutation: this,
1024
+ observer
1025
+ });
1026
+ }
1027
+ }
1028
+ removeObserver(observer) {
1029
+ this.#observers = this.#observers.filter((x) => x !== observer);
1030
+ this.scheduleGc();
1031
+ this.#mutationCache.notify({
1032
+ type: "observerRemoved",
1033
+ mutation: this,
1034
+ observer
1035
+ });
1036
+ }
1037
+ optionalRemove() {
1038
+ if (!this.#observers.length) if (this.state.status === "pending") this.scheduleGc();
1039
+ else this.#mutationCache.remove(this);
1040
+ }
1041
+ continue() {
1042
+ return this.#retryer?.continue() ?? this.execute(this.state.variables);
1043
+ }
1044
+ async execute(variables) {
1045
+ this.#retryer = createRetryer({
1046
+ fn: () => {
1047
+ if (!this.options.mutationFn) return Promise.reject(new Error("No mutationFn found"));
1048
+ return this.options.mutationFn(variables);
1049
+ },
1050
+ onFail: (failureCount, error) => {
1051
+ this.#dispatch({
1052
+ type: "failed",
1053
+ failureCount,
1054
+ error
1055
+ });
1056
+ },
1057
+ onPause: () => {
1058
+ this.#dispatch({ type: "pause" });
1059
+ },
1060
+ onContinue: () => {
1061
+ this.#dispatch({ type: "continue" });
1062
+ },
1063
+ retry: this.options.retry ?? 0,
1064
+ retryDelay: this.options.retryDelay,
1065
+ networkMode: this.options.networkMode,
1066
+ canRun: () => this.#mutationCache.canRun(this)
1067
+ });
1068
+ const restored = this.state.status === "pending";
1069
+ const isPaused = !this.#retryer.canStart();
1070
+ try {
1071
+ if (!restored) {
1072
+ this.#dispatch({
1073
+ type: "pending",
1074
+ variables,
1075
+ isPaused
1076
+ });
1077
+ await this.#mutationCache.config.onMutate?.(variables, this);
1078
+ const context = await this.options.onMutate?.(variables);
1079
+ if (context !== this.state.context) this.#dispatch({
1080
+ type: "pending",
1081
+ context,
1082
+ variables,
1083
+ isPaused
1084
+ });
1085
+ }
1086
+ const data = await this.#retryer.start();
1087
+ await this.#mutationCache.config.onSuccess?.(data, variables, this.state.context, this);
1088
+ await this.options.onSuccess?.(data, variables, this.state.context);
1089
+ await this.#mutationCache.config.onSettled?.(data, null, this.state.variables, this.state.context, this);
1090
+ await this.options.onSettled?.(data, null, variables, this.state.context);
1091
+ this.#dispatch({
1092
+ type: "success",
1093
+ data
1094
+ });
1095
+ return data;
1096
+ } catch (error) {
1097
+ try {
1098
+ await this.#mutationCache.config.onError?.(error, variables, this.state.context, this);
1099
+ await this.options.onError?.(error, variables, this.state.context);
1100
+ await this.#mutationCache.config.onSettled?.(void 0, error, this.state.variables, this.state.context, this);
1101
+ await this.options.onSettled?.(void 0, error, variables, this.state.context);
1102
+ throw error;
1103
+ } finally {
1104
+ this.#dispatch({
1105
+ type: "error",
1106
+ error
1107
+ });
1108
+ }
1109
+ } finally {
1110
+ this.#mutationCache.runNext(this);
1111
+ }
1112
+ }
1113
+ #dispatch(action) {
1114
+ const reducer = (state) => {
1115
+ switch (action.type) {
1116
+ case "failed": return {
1117
+ ...state,
1118
+ failureCount: action.failureCount,
1119
+ failureReason: action.error
1120
+ };
1121
+ case "pause": return {
1122
+ ...state,
1123
+ isPaused: true
1124
+ };
1125
+ case "continue": return {
1126
+ ...state,
1127
+ isPaused: false
1128
+ };
1129
+ case "pending": return {
1130
+ ...state,
1131
+ context: action.context,
1132
+ data: void 0,
1133
+ failureCount: 0,
1134
+ failureReason: null,
1135
+ error: null,
1136
+ isPaused: action.isPaused,
1137
+ status: "pending",
1138
+ variables: action.variables,
1139
+ submittedAt: Date.now()
1140
+ };
1141
+ case "success": return {
1142
+ ...state,
1143
+ data: action.data,
1144
+ failureCount: 0,
1145
+ failureReason: null,
1146
+ error: null,
1147
+ status: "success",
1148
+ isPaused: false
1149
+ };
1150
+ case "error": return {
1151
+ ...state,
1152
+ data: void 0,
1153
+ error: action.error,
1154
+ failureCount: state.failureCount + 1,
1155
+ failureReason: action.error,
1156
+ isPaused: false,
1157
+ status: "error"
1158
+ };
1159
+ }
1160
+ };
1161
+ this.state = reducer(this.state);
1162
+ notifyManager.batch(() => {
1163
+ this.#observers.forEach((observer) => {
1164
+ observer.onMutationUpdate(action);
1165
+ });
1166
+ this.#mutationCache.notify({
1167
+ mutation: this,
1168
+ type: "updated",
1169
+ action
1170
+ });
1171
+ });
1172
+ }
1173
+ };
1174
+ function getDefaultState() {
1175
+ return {
1176
+ context: void 0,
1177
+ data: void 0,
1178
+ error: null,
1179
+ failureCount: 0,
1180
+ failureReason: null,
1181
+ isPaused: false,
1182
+ status: "idle",
1183
+ variables: void 0,
1184
+ submittedAt: 0
1185
+ };
1186
+ }
1187
+
1188
+ //#endregion
1189
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/mutationCache.js
1190
+ var MutationCache = class extends Subscribable {
1191
+ constructor(config = {}) {
1192
+ super();
1193
+ this.config = config;
1194
+ this.#mutations = /* @__PURE__ */ new Map();
1195
+ this.#mutationId = Date.now();
1196
+ }
1197
+ #mutations;
1198
+ #mutationId;
1199
+ build(client, options, state) {
1200
+ const mutation = new Mutation({
1201
+ mutationCache: this,
1202
+ mutationId: ++this.#mutationId,
1203
+ options: client.defaultMutationOptions(options),
1204
+ state
1205
+ });
1206
+ this.add(mutation);
1207
+ return mutation;
1208
+ }
1209
+ add(mutation) {
1210
+ const scope = scopeFor(mutation);
1211
+ const mutations = this.#mutations.get(scope) ?? [];
1212
+ mutations.push(mutation);
1213
+ this.#mutations.set(scope, mutations);
1214
+ this.notify({
1215
+ type: "added",
1216
+ mutation
1217
+ });
1218
+ }
1219
+ remove(mutation) {
1220
+ const scope = scopeFor(mutation);
1221
+ if (this.#mutations.has(scope)) {
1222
+ const mutations = this.#mutations.get(scope)?.filter((x) => x !== mutation);
1223
+ if (mutations) if (mutations.length === 0) this.#mutations.delete(scope);
1224
+ else this.#mutations.set(scope, mutations);
1225
+ }
1226
+ this.notify({
1227
+ type: "removed",
1228
+ mutation
1229
+ });
1230
+ }
1231
+ canRun(mutation) {
1232
+ const firstPendingMutation = this.#mutations.get(scopeFor(mutation))?.find((m) => m.state.status === "pending");
1233
+ return !firstPendingMutation || firstPendingMutation === mutation;
1234
+ }
1235
+ runNext(mutation) {
1236
+ const foundMutation = this.#mutations.get(scopeFor(mutation))?.find((m) => m !== mutation && m.state.isPaused);
1237
+ return foundMutation?.continue() ?? Promise.resolve();
1238
+ }
1239
+ clear() {
1240
+ notifyManager.batch(() => {
1241
+ this.getAll().forEach((mutation) => {
1242
+ this.remove(mutation);
1243
+ });
1244
+ });
1245
+ }
1246
+ getAll() {
1247
+ return [...this.#mutations.values()].flat();
1248
+ }
1249
+ find(filters) {
1250
+ const defaultedFilters = {
1251
+ exact: true,
1252
+ ...filters
1253
+ };
1254
+ return this.getAll().find((mutation) => matchMutation(defaultedFilters, mutation));
1255
+ }
1256
+ findAll(filters = {}) {
1257
+ return this.getAll().filter((mutation) => matchMutation(filters, mutation));
1258
+ }
1259
+ notify(event) {
1260
+ notifyManager.batch(() => {
1261
+ this.listeners.forEach((listener) => {
1262
+ listener(event);
1263
+ });
1264
+ });
1265
+ }
1266
+ resumePausedMutations() {
1267
+ const pausedMutations = this.getAll().filter((x) => x.state.isPaused);
1268
+ return notifyManager.batch(() => Promise.all(pausedMutations.map((mutation) => mutation.continue().catch(noop))));
1269
+ }
1270
+ };
1271
+ function scopeFor(mutation) {
1272
+ return mutation.options.scope?.id ?? String(mutation.mutationId);
1273
+ }
1274
+
1275
+ //#endregion
1276
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/infiniteQueryBehavior.js
1277
+ function infiniteQueryBehavior(pages) {
1278
+ return { onFetch: (context, query) => {
1279
+ const fetchFn = async () => {
1280
+ const options = context.options;
1281
+ const direction = context.fetchOptions?.meta?.fetchMore?.direction;
1282
+ const oldPages = context.state.data?.pages || [];
1283
+ const oldPageParams = context.state.data?.pageParams || [];
1284
+ const empty = {
1285
+ pages: [],
1286
+ pageParams: []
1287
+ };
1288
+ let cancelled = false;
1289
+ const addSignalProperty = (object) => {
1290
+ Object.defineProperty(object, "signal", {
1291
+ enumerable: true,
1292
+ get: () => {
1293
+ if (context.signal.aborted) cancelled = true;
1294
+ else context.signal.addEventListener("abort", () => {
1295
+ cancelled = true;
1296
+ });
1297
+ return context.signal;
1298
+ }
1299
+ });
1300
+ };
1301
+ const queryFn = ensureQueryFn(context.options, context.fetchOptions);
1302
+ const fetchPage = async (data, param, previous) => {
1303
+ if (cancelled) return Promise.reject();
1304
+ if (param == null && data.pages.length) return Promise.resolve(data);
1305
+ const queryFnContext = {
1306
+ queryKey: context.queryKey,
1307
+ pageParam: param,
1308
+ direction: previous ? "backward" : "forward",
1309
+ meta: context.options.meta
1310
+ };
1311
+ addSignalProperty(queryFnContext);
1312
+ const page = await queryFn(queryFnContext);
1313
+ const { maxPages } = context.options;
1314
+ const addTo = previous ? addToStart : addToEnd;
1315
+ return {
1316
+ pages: addTo(data.pages, page, maxPages),
1317
+ pageParams: addTo(data.pageParams, param, maxPages)
1318
+ };
1319
+ };
1320
+ let result;
1321
+ if (direction && oldPages.length) {
1322
+ const previous = direction === "backward";
1323
+ const pageParamFn = previous ? getPreviousPageParam : getNextPageParam;
1324
+ const oldData = {
1325
+ pages: oldPages,
1326
+ pageParams: oldPageParams
1327
+ };
1328
+ const param = pageParamFn(options, oldData);
1329
+ result = await fetchPage(oldData, param, previous);
1330
+ } else {
1331
+ result = await fetchPage(empty, oldPageParams[0] ?? options.initialPageParam);
1332
+ const remainingPages = pages ?? oldPages.length;
1333
+ for (let i = 1; i < remainingPages; i++) {
1334
+ const param = getNextPageParam(options, result);
1335
+ result = await fetchPage(result, param);
1336
+ }
1337
+ }
1338
+ return result;
1339
+ };
1340
+ if (context.options.persister) context.fetchFn = () => {
1341
+ return context.options.persister?.(fetchFn, {
1342
+ queryKey: context.queryKey,
1343
+ meta: context.options.meta,
1344
+ signal: context.signal
1345
+ }, query);
1346
+ };
1347
+ else context.fetchFn = fetchFn;
1348
+ } };
1349
+ }
1350
+ function getNextPageParam(options, { pages, pageParams }) {
1351
+ const lastIndex = pages.length - 1;
1352
+ return options.getNextPageParam(pages[lastIndex], pages, pageParams[lastIndex], pageParams);
1353
+ }
1354
+ function getPreviousPageParam(options, { pages, pageParams }) {
1355
+ return options.getPreviousPageParam?.(pages[0], pages, pageParams[0], pageParams);
1356
+ }
1357
+
1358
+ //#endregion
1359
+ //#region ../../node_modules/.pnpm/@tanstack+query-core@5.45.0/node_modules/@tanstack/query-core/build/modern/queryClient.js
1360
+ var QueryClient = class {
1361
+ #queryCache;
1362
+ #mutationCache;
1363
+ #defaultOptions;
1364
+ #queryDefaults;
1365
+ #mutationDefaults;
1366
+ #mountCount;
1367
+ #unsubscribeFocus;
1368
+ #unsubscribeOnline;
1369
+ constructor(config = {}) {
1370
+ this.#queryCache = config.queryCache || new QueryCache();
1371
+ this.#mutationCache = config.mutationCache || new MutationCache();
1372
+ this.#defaultOptions = config.defaultOptions || {};
1373
+ this.#queryDefaults = /* @__PURE__ */ new Map();
1374
+ this.#mutationDefaults = /* @__PURE__ */ new Map();
1375
+ this.#mountCount = 0;
1376
+ }
1377
+ mount() {
1378
+ this.#mountCount++;
1379
+ if (this.#mountCount !== 1) return;
1380
+ this.#unsubscribeFocus = focusManager.subscribe(async (focused) => {
1381
+ if (focused) {
1382
+ await this.resumePausedMutations();
1383
+ this.#queryCache.onFocus();
1384
+ }
1385
+ });
1386
+ this.#unsubscribeOnline = onlineManager.subscribe(async (online) => {
1387
+ if (online) {
1388
+ await this.resumePausedMutations();
1389
+ this.#queryCache.onOnline();
1390
+ }
1391
+ });
1392
+ }
1393
+ unmount() {
1394
+ this.#mountCount--;
1395
+ if (this.#mountCount !== 0) return;
1396
+ this.#unsubscribeFocus?.();
1397
+ this.#unsubscribeFocus = void 0;
1398
+ this.#unsubscribeOnline?.();
1399
+ this.#unsubscribeOnline = void 0;
1400
+ }
1401
+ isFetching(filters) {
1402
+ return this.#queryCache.findAll({
1403
+ ...filters,
1404
+ fetchStatus: "fetching"
1405
+ }).length;
1406
+ }
1407
+ isMutating(filters) {
1408
+ return this.#mutationCache.findAll({
1409
+ ...filters,
1410
+ status: "pending"
1411
+ }).length;
1412
+ }
1413
+ getQueryData(queryKey) {
1414
+ const options = this.defaultQueryOptions({ queryKey });
1415
+ return this.#queryCache.get(options.queryHash)?.state.data;
1416
+ }
1417
+ ensureQueryData(options) {
1418
+ const cachedData = this.getQueryData(options.queryKey);
1419
+ if (cachedData === void 0) return this.fetchQuery(options);
1420
+ else {
1421
+ const defaultedOptions = this.defaultQueryOptions(options);
1422
+ const query = this.#queryCache.build(this, defaultedOptions);
1423
+ if (options.revalidateIfStale && query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query))) this.prefetchQuery(defaultedOptions);
1424
+ return Promise.resolve(cachedData);
1425
+ }
1426
+ }
1427
+ getQueriesData(filters) {
1428
+ return this.#queryCache.findAll(filters).map(({ queryKey, state }) => {
1429
+ const data = state.data;
1430
+ return [queryKey, data];
1431
+ });
1432
+ }
1433
+ setQueryData(queryKey, updater, options) {
1434
+ const defaultedOptions = this.defaultQueryOptions({ queryKey });
1435
+ const query = this.#queryCache.get(defaultedOptions.queryHash);
1436
+ const prevData = query?.state.data;
1437
+ const data = functionalUpdate(updater, prevData);
1438
+ if (data === void 0) return void 0;
1439
+ return this.#queryCache.build(this, defaultedOptions).setData(data, {
1440
+ ...options,
1441
+ manual: true
1442
+ });
1443
+ }
1444
+ setQueriesData(filters, updater, options) {
1445
+ return notifyManager.batch(() => this.#queryCache.findAll(filters).map(({ queryKey }) => [queryKey, this.setQueryData(queryKey, updater, options)]));
1446
+ }
1447
+ getQueryState(queryKey) {
1448
+ const options = this.defaultQueryOptions({ queryKey });
1449
+ return this.#queryCache.get(options.queryHash)?.state;
1450
+ }
1451
+ removeQueries(filters) {
1452
+ const queryCache = this.#queryCache;
1453
+ notifyManager.batch(() => {
1454
+ queryCache.findAll(filters).forEach((query) => {
1455
+ queryCache.remove(query);
1456
+ });
1457
+ });
1458
+ }
1459
+ resetQueries(filters, options) {
1460
+ const queryCache = this.#queryCache;
1461
+ const refetchFilters = {
1462
+ type: "active",
1463
+ ...filters
1464
+ };
1465
+ return notifyManager.batch(() => {
1466
+ queryCache.findAll(filters).forEach((query) => {
1467
+ query.reset();
1468
+ });
1469
+ return this.refetchQueries(refetchFilters, options);
1470
+ });
1471
+ }
1472
+ cancelQueries(filters = {}, cancelOptions = {}) {
1473
+ const defaultedCancelOptions = {
1474
+ revert: true,
1475
+ ...cancelOptions
1476
+ };
1477
+ const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).map((query) => query.cancel(defaultedCancelOptions)));
1478
+ return Promise.all(promises).then(noop).catch(noop);
1479
+ }
1480
+ invalidateQueries(filters = {}, options = {}) {
1481
+ return notifyManager.batch(() => {
1482
+ this.#queryCache.findAll(filters).forEach((query) => {
1483
+ query.invalidate();
1484
+ });
1485
+ if (filters.refetchType === "none") return Promise.resolve();
1486
+ const refetchFilters = {
1487
+ ...filters,
1488
+ type: filters.refetchType ?? filters.type ?? "active"
1489
+ };
1490
+ return this.refetchQueries(refetchFilters, options);
1491
+ });
1492
+ }
1493
+ refetchQueries(filters = {}, options) {
1494
+ const fetchOptions = {
1495
+ ...options,
1496
+ cancelRefetch: options?.cancelRefetch ?? true
1497
+ };
1498
+ const promises = notifyManager.batch(() => this.#queryCache.findAll(filters).filter((query) => !query.isDisabled()).map((query) => {
1499
+ let promise = query.fetch(void 0, fetchOptions);
1500
+ if (!fetchOptions.throwOnError) promise = promise.catch(noop);
1501
+ return query.state.fetchStatus === "paused" ? Promise.resolve() : promise;
1502
+ }));
1503
+ return Promise.all(promises).then(noop);
1504
+ }
1505
+ fetchQuery(options) {
1506
+ const defaultedOptions = this.defaultQueryOptions(options);
1507
+ if (defaultedOptions.retry === void 0) defaultedOptions.retry = false;
1508
+ const query = this.#queryCache.build(this, defaultedOptions);
1509
+ return query.isStaleByTime(resolveStaleTime(defaultedOptions.staleTime, query)) ? query.fetch(defaultedOptions) : Promise.resolve(query.state.data);
1510
+ }
1511
+ prefetchQuery(options) {
1512
+ return this.fetchQuery(options).then(noop).catch(noop);
1513
+ }
1514
+ fetchInfiniteQuery(options) {
1515
+ options.behavior = infiniteQueryBehavior(options.pages);
1516
+ return this.fetchQuery(options);
1517
+ }
1518
+ prefetchInfiniteQuery(options) {
1519
+ return this.fetchInfiniteQuery(options).then(noop).catch(noop);
1520
+ }
1521
+ resumePausedMutations() {
1522
+ if (onlineManager.isOnline()) return this.#mutationCache.resumePausedMutations();
1523
+ return Promise.resolve();
1524
+ }
1525
+ getQueryCache() {
1526
+ return this.#queryCache;
1527
+ }
1528
+ getMutationCache() {
1529
+ return this.#mutationCache;
1530
+ }
1531
+ getDefaultOptions() {
1532
+ return this.#defaultOptions;
1533
+ }
1534
+ setDefaultOptions(options) {
1535
+ this.#defaultOptions = options;
1536
+ }
1537
+ setQueryDefaults(queryKey, options) {
1538
+ this.#queryDefaults.set(hashKey(queryKey), {
1539
+ queryKey,
1540
+ defaultOptions: options
1541
+ });
1542
+ }
1543
+ getQueryDefaults(queryKey) {
1544
+ const defaults = [...this.#queryDefaults.values()];
1545
+ let result = {};
1546
+ defaults.forEach((queryDefault) => {
1547
+ if (partialMatchKey(queryKey, queryDefault.queryKey)) result = {
1548
+ ...result,
1549
+ ...queryDefault.defaultOptions
1550
+ };
1551
+ });
1552
+ return result;
1553
+ }
1554
+ setMutationDefaults(mutationKey, options) {
1555
+ this.#mutationDefaults.set(hashKey(mutationKey), {
1556
+ mutationKey,
1557
+ defaultOptions: options
1558
+ });
1559
+ }
1560
+ getMutationDefaults(mutationKey) {
1561
+ const defaults = [...this.#mutationDefaults.values()];
1562
+ let result = {};
1563
+ defaults.forEach((queryDefault) => {
1564
+ if (partialMatchKey(mutationKey, queryDefault.mutationKey)) result = {
1565
+ ...result,
1566
+ ...queryDefault.defaultOptions
1567
+ };
1568
+ });
1569
+ return result;
1570
+ }
1571
+ defaultQueryOptions(options) {
1572
+ if (options._defaulted) return options;
1573
+ const defaultedOptions = {
1574
+ ...this.#defaultOptions.queries,
1575
+ ...this.getQueryDefaults(options.queryKey),
1576
+ ...options,
1577
+ _defaulted: true
1578
+ };
1579
+ if (!defaultedOptions.queryHash) defaultedOptions.queryHash = hashQueryKeyByOptions(defaultedOptions.queryKey, defaultedOptions);
1580
+ if (defaultedOptions.refetchOnReconnect === void 0) defaultedOptions.refetchOnReconnect = defaultedOptions.networkMode !== "always";
1581
+ if (defaultedOptions.throwOnError === void 0) defaultedOptions.throwOnError = !!defaultedOptions.suspense;
1582
+ if (!defaultedOptions.networkMode && defaultedOptions.persister) defaultedOptions.networkMode = "offlineFirst";
1583
+ if (defaultedOptions.enabled !== true && defaultedOptions.queryFn === skipToken) defaultedOptions.enabled = false;
1584
+ return defaultedOptions;
1585
+ }
1586
+ defaultMutationOptions(options) {
1587
+ if (options?._defaulted) return options;
1588
+ return {
1589
+ ...this.#defaultOptions.mutations,
1590
+ ...options?.mutationKey && this.getMutationDefaults(options.mutationKey),
1591
+ ...options,
1592
+ _defaulted: true
1593
+ };
1594
+ }
1595
+ clear() {
1596
+ this.#queryCache.clear();
1597
+ this.#mutationCache.clear();
1598
+ }
1599
+ };
1600
+
1601
+ //#endregion
1602
+ //#region ../../node_modules/.pnpm/@tanstack+react-query@5.45.1_react@18.3.0-canary-c3048aab4-20240326/node_modules/@tanstack/react-query/build/modern/QueryClientProvider.js
1603
+ "use client";
1604
+ var QueryClientContext = React.createContext(void 0);
1605
+ var QueryClientProvider = ({ client, children }) => {
1606
+ React.useEffect(() => {
1607
+ client.mount();
1608
+ return () => {
1609
+ client.unmount();
1610
+ };
1611
+ }, [client]);
1612
+ return /* @__PURE__ */ jsx(QueryClientContext.Provider, {
1613
+ value: client,
1614
+ children
1615
+ });
1616
+ };
1617
+
1618
+ //#endregion
1619
+ //#region src/test/react-test-utils.tsx
1620
+ const Connect = () => {
1621
+ const { connectors, connect } = useConnect();
1622
+ useEffect(() => {
1623
+ if (connectors[0] === void 0) return void 0;
1624
+ connect({ connector: connectors[0] });
1625
+ }, [connect, connectors]);
1626
+ return /* @__PURE__ */ jsx(Fragment, {});
1627
+ };
1628
+ const ReactTestWrapper = ({ children, wagmiConfig }) => {
1629
+ const testQueryClient = new QueryClient({ defaultOptions: {
1630
+ queries: { retry: false },
1631
+ mutations: { retry: false }
1632
+ } });
1633
+ return /* @__PURE__ */ jsx(WagmiProvider, {
1634
+ config: wagmiConfig,
1635
+ children: /* @__PURE__ */ jsx(QueryClientProvider, {
1636
+ client: testQueryClient,
1637
+ children: /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(Connect, {}), children] })
1638
+ })
1639
+ });
1640
+ };
1641
+
1642
+ //#endregion
1643
+ //#region src/test/test-accounts.ts
1644
+ const alice = "0x0000000000000000000000000000000000001234";
1645
+ const bob = "0x0000000000000000000000000000000000002345";
1646
+ const charlie = "0x0000000000000000000000000000000000003456";
1647
+
1648
+ //#endregion
1649
+ export { ReactTestWrapper, alice, bob, charlie, killAllAnvilProcesses, killAnvilProcess, spawnAnvil };
1650
+ //# sourceMappingURL=index.js.map