@bkbdev/plugin-react-query 0.0.0-stage → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Bobby Echo Prasetyo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,16 @@
1
- # Temporary Holding Version
1
+ # @bkbdev/plugin-react-query
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ React Query for the BKB desktop: the query cache as it is now (status, observers, last update), a
4
+ timeline of fetches, invalidations, mutations, window focus and network returns, and Refetch and
5
+ Invalidate for one query. Install it next to `@bkbdev/core`, then list it in the Babel plugin options
6
+ and restart Metro with `--reset-cache`:
7
+
8
+ ```js
9
+ // babel.config.js
10
+ plugins: [['@bkbdev/core/babel', { bkbPlugins: ['@bkbdev/plugin-react-query'] }]],
11
+ ```
12
+
13
+ The Babel plugin wraps your `new QueryClient(...)` calls in development builds, so nothing in
14
+ your app changes. Release builds never load this package. Works with `react-query` 3 and
15
+ `@tanstack/react-query` 4 and 5. Query data and mutation variables pass through BKB's redaction:
16
+ keys that look like credentials are never shown.
package/dist/index.cjs ADDED
@@ -0,0 +1,539 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // packages/plugins/react-query/src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ default: () => src_default,
24
+ droppedCacheEvents: () => droppedCacheEvents,
25
+ onCacheEvent: () => onCacheEvent,
26
+ trackQueryClient: () => trackQueryClient,
27
+ trackedClients: () => trackedClients
28
+ });
29
+ module.exports = __toCommonJS(src_exports);
30
+
31
+ // packages/plugins/react-query/src/hub.ts
32
+ var import_plugin = require("@bkbdev/core/plugin");
33
+ var REGISTRY_KEY = "__BKB_QUERY_CLIENTS_V1__";
34
+ var events = (0, import_plugin.createEventHub)("__BKB_QUERY_CACHE_EVENTS_V1__");
35
+ function registry() {
36
+ const existing = global[REGISTRY_KEY];
37
+ if (existing) return existing;
38
+ const created = { clients: /* @__PURE__ */ new Map(), labelCounts: /* @__PURE__ */ new Map() };
39
+ global[REGISTRY_KEY] = created;
40
+ return created;
41
+ }
42
+ function clientLabel(variable, file, line) {
43
+ const base = variable != null ? variable : file !== null && line !== null ? file.slice(-120) + ":" + line : "client";
44
+ return base.slice(0, 128);
45
+ }
46
+ function reserveClientId(label) {
47
+ var _a;
48
+ const state = registry();
49
+ const count = ((_a = state.labelCounts.get(label)) != null ? _a : 0) + 1;
50
+ state.labelCounts.set(label, count);
51
+ return count === 1 ? label : label + "#" + count;
52
+ }
53
+ function rememberClient(tracked2) {
54
+ registry().clients.set(tracked2.clientId, tracked2);
55
+ }
56
+ function trackedClients() {
57
+ return [...registry().clients.values()];
58
+ }
59
+ var publishCacheEvent = events.publish;
60
+ var onCacheEvent = events.subscribe;
61
+ var droppedCacheEvents = events.droppedCount;
62
+
63
+ // packages/plugins/react-query/src/actions.ts
64
+ var import_plugin2 = require("@bkbdev/core/plugin");
65
+
66
+ // packages/plugins/react-query/src/key.ts
67
+ var MAX_DEPTH = 4;
68
+ var MAX_ITEMS = 8;
69
+ var MAX_CHARACTERS = 200;
70
+ function quote(text) {
71
+ const clipped = text.length > 60 ? text.slice(0, 60) + "\u2026" : text;
72
+ return "'" + clipped.replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/\n/g, "\\n") + "'";
73
+ }
74
+ function propertyName(name) {
75
+ return /^[A-Za-z_$][\w$]*$/.test(name) ? name : quote(name);
76
+ }
77
+ function isRecord(value) {
78
+ return typeof value === "object" && value !== null && !Array.isArray(value);
79
+ }
80
+ function scalar(value) {
81
+ if (typeof value === "string") return quote(value);
82
+ if (value === null || typeof value === "number" || typeof value === "boolean")
83
+ return String(value);
84
+ if (value === void 0) return "undefined";
85
+ if (typeof value === "bigint") return String(value) + "n";
86
+ if (typeof value === "function") return "[Function]";
87
+ return "[" + typeof value + "]";
88
+ }
89
+ function list(items, total, open, close) {
90
+ const more = total > items.length ? ["\u2026"] : [];
91
+ if (!items.length && !more.length) return open + close;
92
+ const body = [...items, ...more].join(", ");
93
+ return open === "{" ? "{ " + body + " }" : open + body + close;
94
+ }
95
+ function render(value, depth, seen) {
96
+ if (typeof value !== "object" || value === null) return scalar(value);
97
+ if (seen.has(value)) return "[Circular]";
98
+ if (depth >= MAX_DEPTH) return Array.isArray(value) ? "[\u2026]" : "{\u2026}";
99
+ seen.add(value);
100
+ try {
101
+ if (Array.isArray(value))
102
+ return list(
103
+ value.slice(0, MAX_ITEMS).map((item) => render(item, depth + 1, seen)),
104
+ value.length,
105
+ "[",
106
+ "]"
107
+ );
108
+ if (!isRecord(value)) return "[object]";
109
+ const names = Object.keys(value);
110
+ return list(
111
+ names.slice(0, MAX_ITEMS).map((name) => propertyName(name) + ": " + render(value[name], depth + 1, seen)),
112
+ names.length,
113
+ "{",
114
+ "}"
115
+ );
116
+ } finally {
117
+ seen.delete(value);
118
+ }
119
+ }
120
+ function formatQueryKey(key) {
121
+ let text;
122
+ try {
123
+ text = render(key, 0, /* @__PURE__ */ new Set());
124
+ } catch (e) {
125
+ return "[unreadable key]";
126
+ }
127
+ return text.length > MAX_CHARACTERS ? text.slice(0, MAX_CHARACTERS - 1) + "\u2026" : text;
128
+ }
129
+
130
+ // packages/plugins/react-query/src/snapshot.ts
131
+ function isFetching(query) {
132
+ const state = query.state;
133
+ return state.fetchStatus === void 0 ? state.isFetching === true : state.fetchStatus === "fetching";
134
+ }
135
+ function isPaused(query) {
136
+ return query.state.fetchStatus === "paused";
137
+ }
138
+ function hasActiveObserver(query) {
139
+ var _a;
140
+ if (typeof query.isActive === "function") return query.isActive();
141
+ const observers = (_a = query.observers) != null ? _a : [];
142
+ return observers.some((observer) => {
143
+ var _a2;
144
+ return ((_a2 = observer.options) == null ? void 0 : _a2.enabled) !== false;
145
+ });
146
+ }
147
+ function hasQueryFunction(client, query) {
148
+ var _a, _b;
149
+ if (typeof ((_a = query.options) == null ? void 0 : _a.queryFn) === "function") return true;
150
+ const defaults = client.getDefaultOptions ? client.getDefaultOptions() : void 0;
151
+ return typeof ((_b = defaults == null ? void 0 : defaults.queries) == null ? void 0 : _b.queryFn) === "function";
152
+ }
153
+ function isRefetchable(client, query) {
154
+ var _a;
155
+ if (!hasQueryFunction(client, query)) return false;
156
+ const observers = (_a = query.observers) != null ? _a : [];
157
+ return observers.length === 0 || hasActiveObserver(query);
158
+ }
159
+ function queryStatus(query) {
160
+ var _a;
161
+ if (isFetching(query)) return "fetching";
162
+ if (isPaused(query)) return "paused";
163
+ if (query.state.status === "error") return "error";
164
+ if (!((_a = query.observers) != null ? _a : []).length) return "inactive";
165
+ if (query.state.dataUpdatedAt === 0) return "idle";
166
+ return typeof query.isStale === "function" && !query.isStale() ? "fresh" : "stale";
167
+ }
168
+ function queryRow(client, clientId, query, fetchCount, source) {
169
+ var _a;
170
+ return {
171
+ clientId,
172
+ queryId: query.queryHash,
173
+ key: formatQueryKey(query.queryKey),
174
+ status: queryStatus(query),
175
+ observers: ((_a = query.observers) != null ? _a : []).length,
176
+ fetchCount,
177
+ updatedAt: query.state.dataUpdatedAt > 0 ? query.state.dataUpdatedAt : null,
178
+ refetchable: isRefetchable(client, query),
179
+ source
180
+ };
181
+ }
182
+
183
+ // packages/plugins/react-query/src/actions.ts
184
+ function refused(reason) {
185
+ return { outcome: "refused", reason };
186
+ }
187
+ function refetchBlocker(client, query) {
188
+ if (isFetching(query)) return "The query is already fetching.";
189
+ if (!isRefetchable(client, query))
190
+ return "The query has no query function, or every component using it has it disabled.";
191
+ return void 0;
192
+ }
193
+ function find(client, queryId) {
194
+ return client.getQueryCache().getAll().find((query) => query.queryHash === queryId);
195
+ }
196
+ function runQueryAction(client, clientId, action, queryId, emit, now = Date.now) {
197
+ const query = find(client, queryId);
198
+ if (!query) return refused("The query no longer exists.");
199
+ if (action === "refetch") {
200
+ const blocker = refetchBlocker(client, query);
201
+ if (blocker) return refused(blocker);
202
+ }
203
+ emit({
204
+ kind: "request",
205
+ clientId,
206
+ action,
207
+ queryId,
208
+ key: formatQueryKey(query.queryKey),
209
+ timestamp: now()
210
+ });
211
+ const filters = { queryKey: query.queryKey, exact: true };
212
+ const pending = action === "refetch" ? client.refetchQueries(filters, { cancelRefetch: false }) : client.invalidateQueries(filters);
213
+ pending.catch(() => void 0);
214
+ return { outcome: "done", fetchStarted: isFetching(query) };
215
+ }
216
+ function readQueryData(client, queryId) {
217
+ const query = find(client, queryId);
218
+ if (!query) return refused("The query no longer exists.");
219
+ if (query.state.dataUpdatedAt === 0 && query.state.data === void 0)
220
+ return refused("The query has no data yet.");
221
+ const { data, truncated } = (0, import_plugin2.snapshotValue)(query.state.data);
222
+ return { outcome: "data", data, truncated };
223
+ }
224
+
225
+ // packages/plugins/react-query/src/commands.ts
226
+ function field(value, key) {
227
+ if (typeof value !== "object" || value === null) return void 0;
228
+ try {
229
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
230
+ return descriptor && "value" in descriptor ? descriptor.value : void 0;
231
+ } catch (e) {
232
+ return void 0;
233
+ }
234
+ }
235
+ function parseCommand(command) {
236
+ const operation = field(command, "operation");
237
+ const clientId = field(command, "clientId");
238
+ const queryId = field(command, "queryId");
239
+ if (operation === "resync" && typeof clientId === "string" && clientId && clientId.length <= 256)
240
+ return { operation, clientId };
241
+ if (operation !== "refetch" && operation !== "invalidate" && operation !== "read-data")
242
+ return void 0;
243
+ if (typeof clientId !== "string" || !clientId || clientId.length > 256) return void 0;
244
+ if (typeof queryId !== "string" || !queryId || queryId.length > 512) return void 0;
245
+ return { operation, clientId, queryId };
246
+ }
247
+ function handleQueryCommand(command) {
248
+ const parsed = parseCommand(command);
249
+ if (!parsed) return { outcome: "refused", reason: "The request was not understood." };
250
+ const tracked2 = trackedClients().find((candidate) => candidate.clientId === parsed.clientId);
251
+ if (!tracked2) return { outcome: "refused", reason: "That query client is not tracked." };
252
+ if (parsed.operation === "resync") {
253
+ tracked2.watcher.resend();
254
+ return { outcome: "done", fetchStarted: false };
255
+ }
256
+ if (parsed.operation === "read-data") return readQueryData(tracked2.client, parsed.queryId);
257
+ return runQueryAction(
258
+ tracked2.client,
259
+ tracked2.clientId,
260
+ parsed.operation,
261
+ parsed.queryId,
262
+ publishCacheEvent
263
+ );
264
+ }
265
+
266
+ // packages/plugins/react-query/src/provider.ts
267
+ function queryCacheProvider() {
268
+ return {
269
+ capability: "queryCache",
270
+ instanceId: "react-query-" + Date.now().toString(36) + Math.random().toString(36).slice(2, 8),
271
+ subscribe: (listener) => onCacheEvent((event) => listener(event)),
272
+ handleCommand: handleQueryCommand,
273
+ droppedCount: droppedCacheEvents
274
+ };
275
+ }
276
+
277
+ // packages/plugins/react-query/src/track.ts
278
+ var import_plugin4 = require("@bkbdev/core/plugin");
279
+
280
+ // packages/plugins/react-query/src/mutations.ts
281
+ var import_plugin3 = require("@bkbdev/core/plugin");
282
+
283
+ // packages/plugins/react-query/src/errors.ts
284
+ function describeError(error) {
285
+ if (error === null || error === void 0) return null;
286
+ if (error instanceof Error) return error.message.slice(0, 200);
287
+ if (typeof error === "string") return error.slice(0, 200);
288
+ return "Unknown error";
289
+ }
290
+
291
+ // packages/plugins/react-query/src/mutations.ts
292
+ function isRunning(status) {
293
+ return status === "loading" || status === "pending";
294
+ }
295
+ function isMutation(value) {
296
+ return typeof value === "object" && value !== null && typeof value.mutationId === "number";
297
+ }
298
+ function mutationOf(event) {
299
+ if (isMutation(event)) return event;
300
+ const inner = event == null ? void 0 : event.mutation;
301
+ return isMutation(inner) ? inner : void 0;
302
+ }
303
+ function nameOf(mutation) {
304
+ var _a;
305
+ const key = (_a = mutation.options) == null ? void 0 : _a.mutationKey;
306
+ return key === void 0 ? "mutation" : formatQueryKey(key);
307
+ }
308
+ var MutationWatcher = class {
309
+ constructor(cache, clientId, emit, now = Date.now) {
310
+ this.cache = cache;
311
+ this.clientId = clientId;
312
+ this.emit = emit;
313
+ this.now = now;
314
+ this.seen = /* @__PURE__ */ new Map();
315
+ }
316
+ start() {
317
+ for (const mutation of this.cache.getAll())
318
+ this.seen.set(mutation.mutationId, { status: mutation.state.status, startedAt: null });
319
+ this.stopSubscription = this.cache.subscribe((event) => {
320
+ const mutation = mutationOf(event);
321
+ if (mutation) this.observe(mutation);
322
+ });
323
+ }
324
+ stop() {
325
+ var _a;
326
+ (_a = this.stopSubscription) == null ? void 0 : _a.call(this);
327
+ this.stopSubscription = void 0;
328
+ }
329
+ observe(mutation) {
330
+ var _a;
331
+ const id = mutation.mutationId;
332
+ const entry = (_a = this.seen.get(id)) != null ? _a : { status: "idle", startedAt: null };
333
+ this.seen.set(id, entry);
334
+ const status = mutation.state.status;
335
+ const wasRunning = isRunning(entry.status);
336
+ if (isRunning(status) && !wasRunning) {
337
+ entry.startedAt = this.now();
338
+ this.send(mutation, "started", null, null);
339
+ } else if (wasRunning && (status === "success" || status === "error")) {
340
+ const durationMs = entry.startedAt === null ? 0 : this.now() - entry.startedAt;
341
+ const error = status === "error" ? describeError(mutation.state.error) : null;
342
+ this.send(mutation, status === "error" ? "failed" : "succeeded", durationMs, error);
343
+ }
344
+ entry.status = status;
345
+ }
346
+ send(mutation, phase, durationMs, error) {
347
+ this.emit({
348
+ kind: "mutation",
349
+ clientId: this.clientId,
350
+ mutationId: mutation.mutationId,
351
+ name: nameOf(mutation),
352
+ phase,
353
+ variables: phase === "started" ? (0, import_plugin3.previewValue)(mutation.state.variables) : null,
354
+ durationMs,
355
+ error,
356
+ timestamp: this.now()
357
+ });
358
+ }
359
+ };
360
+
361
+ // packages/plugins/react-query/src/watcher.ts
362
+ function isQuery(value) {
363
+ return typeof value === "object" && value !== null && typeof value.queryHash === "string";
364
+ }
365
+ function queryOf(event) {
366
+ if (isQuery(event)) return event;
367
+ const inner = event == null ? void 0 : event.query;
368
+ return isQuery(inner) ? inner : void 0;
369
+ }
370
+ var QueryWatcher = class {
371
+ constructor(client, clientId, emit, now = Date.now, source = null) {
372
+ this.client = client;
373
+ this.clientId = clientId;
374
+ this.emit = emit;
375
+ this.now = now;
376
+ this.source = source;
377
+ this.seen = /* @__PURE__ */ new Map();
378
+ }
379
+ // Records the queries that already exist without reporting them, then follows the cache.
380
+ start() {
381
+ const cache = this.client.getQueryCache();
382
+ for (const query of cache.getAll()) this.sendRow(query, this.remember(query));
383
+ this.stopSubscription = cache.subscribe((event) => {
384
+ const query = queryOf(event);
385
+ if (query) this.observe(query);
386
+ this.reconcile(cache);
387
+ });
388
+ }
389
+ stop() {
390
+ var _a;
391
+ (_a = this.stopSubscription) == null ? void 0 : _a.call(this);
392
+ this.stopSubscription = void 0;
393
+ }
394
+ // Sends the state of every query again, even if it did not change since the last time.
395
+ resend() {
396
+ var _a;
397
+ for (const query of this.client.getQueryCache().getAll()) {
398
+ const entry = (_a = this.seen.get(query.queryHash)) != null ? _a : this.remember(query);
399
+ entry.rowSignature = "";
400
+ this.sendRow(query, entry);
401
+ }
402
+ }
403
+ fetchCount(queryId) {
404
+ var _a, _b;
405
+ return (_b = (_a = this.seen.get(queryId)) == null ? void 0 : _a.fetchCount) != null ? _b : 0;
406
+ }
407
+ rows() {
408
+ return this.client.getQueryCache().getAll().map(
409
+ (query) => queryRow(this.client, this.clientId, query, this.fetchCount(query.queryHash), this.source)
410
+ );
411
+ }
412
+ remember(query) {
413
+ const seen = {
414
+ key: formatQueryKey(query.queryKey),
415
+ fetching: isFetching(query),
416
+ invalidated: query.state.isInvalidated,
417
+ dataUpdatedAt: query.state.dataUpdatedAt,
418
+ errorUpdatedAt: query.state.errorUpdatedAt,
419
+ startedAt: null,
420
+ fetchCount: 0,
421
+ rowSignature: ""
422
+ };
423
+ this.seen.set(query.queryHash, seen);
424
+ return seen;
425
+ }
426
+ event(query, key, phase, extra = {}) {
427
+ var _a, _b;
428
+ this.emit({
429
+ kind: "query",
430
+ clientId: this.clientId,
431
+ queryId: query,
432
+ key,
433
+ phase,
434
+ durationMs: (_a = extra.durationMs) != null ? _a : null,
435
+ error: (_b = extra.error) != null ? _b : null,
436
+ timestamp: this.now()
437
+ });
438
+ }
439
+ observe(query) {
440
+ const id = query.queryHash;
441
+ const state = query.state;
442
+ const fetching = isFetching(query);
443
+ let entry = this.seen.get(id);
444
+ if (!entry) {
445
+ entry = this.remember(query);
446
+ entry.fetching = false;
447
+ entry.invalidated = false;
448
+ }
449
+ const key = entry.key;
450
+ let failed = false;
451
+ if (fetching && !entry.fetching) {
452
+ entry.startedAt = this.now();
453
+ entry.fetchCount += 1;
454
+ this.event(id, key, "fetch-started");
455
+ } else if (!fetching && entry.fetching) failed = this.settle(id, entry, query);
456
+ if (state.isInvalidated && !entry.invalidated && !failed) this.event(id, key, "invalidated");
457
+ entry.fetching = fetching;
458
+ entry.invalidated = state.isInvalidated;
459
+ entry.dataUpdatedAt = state.dataUpdatedAt;
460
+ entry.errorUpdatedAt = state.errorUpdatedAt;
461
+ this.sendRow(query, entry);
462
+ }
463
+ // Reports the query's state, but only when it differs from the one reported last.
464
+ sendRow(query, entry) {
465
+ const row = queryRow(this.client, this.clientId, query, entry.fetchCount, this.source);
466
+ const signature = JSON.stringify(row);
467
+ if (signature === entry.rowSignature) return;
468
+ entry.rowSignature = signature;
469
+ this.emit({ kind: "row", clientId: this.clientId, row, timestamp: this.now() });
470
+ }
471
+ // A fetch ended: failed, succeeded, or was cancelled (reported as neither). True when failed.
472
+ settle(id, entry, query) {
473
+ const state = query.state;
474
+ const durationMs = entry.startedAt === null ? 0 : this.now() - entry.startedAt;
475
+ entry.startedAt = null;
476
+ if (state.errorUpdatedAt > entry.errorUpdatedAt) {
477
+ this.event(id, entry.key, "failed", { durationMs, error: describeError(state.error) });
478
+ return true;
479
+ }
480
+ if (state.dataUpdatedAt > entry.dataUpdatedAt)
481
+ this.event(id, entry.key, "succeeded", { durationMs });
482
+ return false;
483
+ }
484
+ reconcile(cache) {
485
+ const live = cache.getAll();
486
+ if (live.length === this.seen.size) return;
487
+ const present = new Set(live.map((query) => query.queryHash));
488
+ for (const [id, entry] of [...this.seen]) {
489
+ if (present.has(id)) continue;
490
+ this.seen.delete(id);
491
+ this.event(id, entry.key, "removed");
492
+ }
493
+ }
494
+ };
495
+
496
+ // packages/plugins/react-query/src/track.ts
497
+ var tracked = /* @__PURE__ */ new WeakSet();
498
+ function reportWakeups(cache, clientId) {
499
+ for (const [method, kind] of [
500
+ ["onFocus", "focus"],
501
+ ["onOnline", "online"]
502
+ ]) {
503
+ const original = cache[method];
504
+ if (typeof original !== "function") continue;
505
+ cache[method] = () => {
506
+ publishCacheEvent({ kind, clientId, timestamp: Date.now() });
507
+ original.call(cache);
508
+ };
509
+ }
510
+ }
511
+ function trackQueryClient(client, meta) {
512
+ var _a, _b, _c;
513
+ if (typeof __DEV__ !== "undefined" && !__DEV__) return client;
514
+ if (tracked.has(client)) return client;
515
+ tracked.add(client);
516
+ const clientId = reserveClientId(
517
+ clientLabel((_a = meta == null ? void 0 : meta.variable) != null ? _a : null, (_b = meta == null ? void 0 : meta.file) != null ? _b : null, (_c = meta == null ? void 0 : meta.line) != null ? _c : null)
518
+ );
519
+ const watcher = new QueryWatcher(
520
+ client,
521
+ clientId,
522
+ publishCacheEvent,
523
+ Date.now,
524
+ (0, import_plugin4.trackSource)(meta)
525
+ );
526
+ watcher.start();
527
+ new MutationWatcher(client.getMutationCache(), clientId, publishCacheEvent).start();
528
+ reportWakeups(client.getQueryCache(), clientId);
529
+ rememberClient({ clientId, client, watcher });
530
+ return client;
531
+ }
532
+
533
+ // packages/plugins/react-query/src/index.ts
534
+ var plugin = {
535
+ name: "react-query",
536
+ extend: () => ({ pluginProviders: [queryCacheProvider()] })
537
+ };
538
+ var src_default = plugin;
539
+ //# sourceMappingURL=index.cjs.map