@tanstack/query-core 4.3.6 → 4.3.7

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 (43) hide show
  1. package/build/lib/focusManager.esm.js +86 -0
  2. package/build/lib/focusManager.esm.js.map +1 -0
  3. package/build/lib/hydration.esm.js +97 -0
  4. package/build/lib/hydration.esm.js.map +1 -0
  5. package/build/lib/index.esm.js +14 -0
  6. package/build/lib/index.esm.js.map +1 -0
  7. package/build/lib/infiniteQueryBehavior.esm.js +142 -0
  8. package/build/lib/infiniteQueryBehavior.esm.js.map +1 -0
  9. package/build/lib/infiniteQueryObserver.esm.js +78 -0
  10. package/build/lib/infiniteQueryObserver.esm.js.map +1 -0
  11. package/build/lib/logger.esm.js +4 -0
  12. package/build/lib/logger.esm.js.map +1 -0
  13. package/build/lib/logger.native.esm.js +12 -0
  14. package/build/lib/logger.native.esm.js.map +1 -0
  15. package/build/lib/mutation.esm.js +243 -0
  16. package/build/lib/mutation.esm.js.map +1 -0
  17. package/build/lib/mutationCache.esm.js +85 -0
  18. package/build/lib/mutationCache.esm.js.map +1 -0
  19. package/build/lib/mutationObserver.esm.js +126 -0
  20. package/build/lib/mutationObserver.esm.js.map +1 -0
  21. package/build/lib/notifyManager.esm.js +99 -0
  22. package/build/lib/notifyManager.esm.js.map +1 -0
  23. package/build/lib/onlineManager.esm.js +85 -0
  24. package/build/lib/onlineManager.esm.js.map +1 -0
  25. package/build/lib/queriesObserver.esm.js +156 -0
  26. package/build/lib/queriesObserver.esm.js.map +1 -0
  27. package/build/lib/query.esm.js +460 -0
  28. package/build/lib/query.esm.js.map +1 -0
  29. package/build/lib/queryCache.esm.js +126 -0
  30. package/build/lib/queryCache.esm.js.map +1 -0
  31. package/build/lib/queryClient.esm.js +339 -0
  32. package/build/lib/queryClient.esm.js.map +1 -0
  33. package/build/lib/queryObserver.esm.js +515 -0
  34. package/build/lib/queryObserver.esm.js.map +1 -0
  35. package/build/lib/removable.esm.js +33 -0
  36. package/build/lib/removable.esm.js.map +1 -0
  37. package/build/lib/retryer.esm.js +160 -0
  38. package/build/lib/retryer.esm.js.map +1 -0
  39. package/build/lib/subscribable.esm.js +29 -0
  40. package/build/lib/subscribable.esm.js.map +1 -0
  41. package/build/lib/utils.esm.js +318 -0
  42. package/build/lib/utils.esm.js.map +1 -0
  43. package/package.json +2 -1
@@ -0,0 +1,515 @@
1
+ import { shallowEqualObjects, noop, isServer, isValidTimeout, timeUntilStale, replaceData } from './utils.esm.js';
2
+ import { notifyManager } from './notifyManager.esm.js';
3
+ import { focusManager } from './focusManager.esm.js';
4
+ import { Subscribable } from './subscribable.esm.js';
5
+ import { canFetch, isCancelledError } from './retryer.esm.js';
6
+
7
+ class QueryObserver extends Subscribable {
8
+ constructor(client, options) {
9
+ super();
10
+ this.client = client;
11
+ this.options = options;
12
+ this.trackedProps = new Set();
13
+ this.selectError = null;
14
+ this.bindMethods();
15
+ this.setOptions(options);
16
+ }
17
+
18
+ bindMethods() {
19
+ this.remove = this.remove.bind(this);
20
+ this.refetch = this.refetch.bind(this);
21
+ }
22
+
23
+ onSubscribe() {
24
+ if (this.listeners.length === 1) {
25
+ this.currentQuery.addObserver(this);
26
+
27
+ if (shouldFetchOnMount(this.currentQuery, this.options)) {
28
+ this.executeFetch();
29
+ }
30
+
31
+ this.updateTimers();
32
+ }
33
+ }
34
+
35
+ onUnsubscribe() {
36
+ if (!this.listeners.length) {
37
+ this.destroy();
38
+ }
39
+ }
40
+
41
+ shouldFetchOnReconnect() {
42
+ return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnReconnect);
43
+ }
44
+
45
+ shouldFetchOnWindowFocus() {
46
+ return shouldFetchOn(this.currentQuery, this.options, this.options.refetchOnWindowFocus);
47
+ }
48
+
49
+ destroy() {
50
+ this.listeners = [];
51
+ this.clearStaleTimeout();
52
+ this.clearRefetchInterval();
53
+ this.currentQuery.removeObserver(this);
54
+ }
55
+
56
+ setOptions(options, notifyOptions) {
57
+ const prevOptions = this.options;
58
+ const prevQuery = this.currentQuery;
59
+ this.options = this.client.defaultQueryOptions(options);
60
+
61
+ if (!shallowEqualObjects(prevOptions, this.options)) {
62
+ this.client.getQueryCache().notify({
63
+ type: 'observerOptionsUpdated',
64
+ query: this.currentQuery,
65
+ observer: this
66
+ });
67
+ }
68
+
69
+ if (typeof this.options.enabled !== 'undefined' && typeof this.options.enabled !== 'boolean') {
70
+ throw new Error('Expected enabled to be a boolean');
71
+ } // Keep previous query key if the user does not supply one
72
+
73
+
74
+ if (!this.options.queryKey) {
75
+ this.options.queryKey = prevOptions.queryKey;
76
+ }
77
+
78
+ this.updateQuery();
79
+ const mounted = this.hasListeners(); // Fetch if there are subscribers
80
+
81
+ if (mounted && shouldFetchOptionally(this.currentQuery, prevQuery, this.options, prevOptions)) {
82
+ this.executeFetch();
83
+ } // Update result
84
+
85
+
86
+ this.updateResult(notifyOptions); // Update stale interval if needed
87
+
88
+ if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || this.options.staleTime !== prevOptions.staleTime)) {
89
+ this.updateStaleTimeout();
90
+ }
91
+
92
+ const nextRefetchInterval = this.computeRefetchInterval(); // Update refetch interval if needed
93
+
94
+ if (mounted && (this.currentQuery !== prevQuery || this.options.enabled !== prevOptions.enabled || nextRefetchInterval !== this.currentRefetchInterval)) {
95
+ this.updateRefetchInterval(nextRefetchInterval);
96
+ }
97
+ }
98
+
99
+ getOptimisticResult(options) {
100
+ const query = this.client.getQueryCache().build(this.client, options);
101
+ return this.createResult(query, options);
102
+ }
103
+
104
+ getCurrentResult() {
105
+ return this.currentResult;
106
+ }
107
+
108
+ trackResult(result) {
109
+ const trackedResult = {};
110
+ Object.keys(result).forEach(key => {
111
+ Object.defineProperty(trackedResult, key, {
112
+ configurable: false,
113
+ enumerable: true,
114
+ get: () => {
115
+ this.trackedProps.add(key);
116
+ return result[key];
117
+ }
118
+ });
119
+ });
120
+ return trackedResult;
121
+ }
122
+
123
+ getCurrentQuery() {
124
+ return this.currentQuery;
125
+ }
126
+
127
+ remove() {
128
+ this.client.getQueryCache().remove(this.currentQuery);
129
+ }
130
+
131
+ refetch({
132
+ refetchPage,
133
+ ...options
134
+ } = {}) {
135
+ return this.fetch({ ...options,
136
+ meta: {
137
+ refetchPage
138
+ }
139
+ });
140
+ }
141
+
142
+ fetchOptimistic(options) {
143
+ const defaultedOptions = this.client.defaultQueryOptions(options);
144
+ const query = this.client.getQueryCache().build(this.client, defaultedOptions);
145
+ query.isFetchingOptimistic = true;
146
+ return query.fetch().then(() => this.createResult(query, defaultedOptions));
147
+ }
148
+
149
+ fetch(fetchOptions) {
150
+ var _fetchOptions$cancelR;
151
+
152
+ return this.executeFetch({ ...fetchOptions,
153
+ cancelRefetch: (_fetchOptions$cancelR = fetchOptions.cancelRefetch) != null ? _fetchOptions$cancelR : true
154
+ }).then(() => {
155
+ this.updateResult();
156
+ return this.currentResult;
157
+ });
158
+ }
159
+
160
+ executeFetch(fetchOptions) {
161
+ // Make sure we reference the latest query as the current one might have been removed
162
+ this.updateQuery(); // Fetch
163
+
164
+ let promise = this.currentQuery.fetch(this.options, fetchOptions);
165
+
166
+ if (!(fetchOptions != null && fetchOptions.throwOnError)) {
167
+ promise = promise.catch(noop);
168
+ }
169
+
170
+ return promise;
171
+ }
172
+
173
+ updateStaleTimeout() {
174
+ this.clearStaleTimeout();
175
+
176
+ if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
177
+ return;
178
+ }
179
+
180
+ const time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime); // The timeout is sometimes triggered 1 ms before the stale time expiration.
181
+ // To mitigate this issue we always add 1 ms to the timeout.
182
+
183
+ const timeout = time + 1;
184
+ this.staleTimeoutId = setTimeout(() => {
185
+ if (!this.currentResult.isStale) {
186
+ this.updateResult();
187
+ }
188
+ }, timeout);
189
+ }
190
+
191
+ computeRefetchInterval() {
192
+ var _this$options$refetch;
193
+
194
+ return typeof this.options.refetchInterval === 'function' ? this.options.refetchInterval(this.currentResult.data, this.currentQuery) : (_this$options$refetch = this.options.refetchInterval) != null ? _this$options$refetch : false;
195
+ }
196
+
197
+ updateRefetchInterval(nextInterval) {
198
+ this.clearRefetchInterval();
199
+ this.currentRefetchInterval = nextInterval;
200
+
201
+ if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
202
+ return;
203
+ }
204
+
205
+ this.refetchIntervalId = setInterval(() => {
206
+ if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
207
+ this.executeFetch();
208
+ }
209
+ }, this.currentRefetchInterval);
210
+ }
211
+
212
+ updateTimers() {
213
+ this.updateStaleTimeout();
214
+ this.updateRefetchInterval(this.computeRefetchInterval());
215
+ }
216
+
217
+ clearStaleTimeout() {
218
+ if (this.staleTimeoutId) {
219
+ clearTimeout(this.staleTimeoutId);
220
+ this.staleTimeoutId = undefined;
221
+ }
222
+ }
223
+
224
+ clearRefetchInterval() {
225
+ if (this.refetchIntervalId) {
226
+ clearInterval(this.refetchIntervalId);
227
+ this.refetchIntervalId = undefined;
228
+ }
229
+ }
230
+
231
+ createResult(query, options) {
232
+ const prevQuery = this.currentQuery;
233
+ const prevOptions = this.options;
234
+ const prevResult = this.currentResult;
235
+ const prevResultState = this.currentResultState;
236
+ const prevResultOptions = this.currentResultOptions;
237
+ const queryChange = query !== prevQuery;
238
+ const queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
239
+ const prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
240
+ const {
241
+ state
242
+ } = query;
243
+ let {
244
+ dataUpdatedAt,
245
+ error,
246
+ errorUpdatedAt,
247
+ fetchStatus,
248
+ status
249
+ } = state;
250
+ let isPreviousData = false;
251
+ let isPlaceholderData = false;
252
+ let data; // Optimistically set result in fetching state if needed
253
+
254
+ if (options._optimisticResults) {
255
+ const mounted = this.hasListeners();
256
+ const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
257
+ const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
258
+
259
+ if (fetchOnMount || fetchOptionally) {
260
+ fetchStatus = canFetch(query.options.networkMode) ? 'fetching' : 'paused';
261
+
262
+ if (!dataUpdatedAt) {
263
+ status = 'loading';
264
+ }
265
+ }
266
+
267
+ if (options._optimisticResults === 'isRestoring') {
268
+ fetchStatus = 'idle';
269
+ }
270
+ } // Keep previous data if needed
271
+
272
+
273
+ if (options.keepPreviousData && !state.dataUpdateCount && prevQueryResult != null && prevQueryResult.isSuccess && status !== 'error') {
274
+ data = prevQueryResult.data;
275
+ dataUpdatedAt = prevQueryResult.dataUpdatedAt;
276
+ status = prevQueryResult.status;
277
+ isPreviousData = true;
278
+ } // Select data if needed
279
+ else if (options.select && typeof state.data !== 'undefined') {
280
+ // Memoize select result
281
+ if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === this.selectFn) {
282
+ data = this.selectResult;
283
+ } else {
284
+ try {
285
+ this.selectFn = options.select;
286
+ data = options.select(state.data);
287
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, data, options);
288
+ this.selectResult = data;
289
+ this.selectError = null;
290
+ } catch (selectError) {
291
+ if (process.env.NODE_ENV !== 'production') {
292
+ this.client.getLogger().error(selectError);
293
+ }
294
+
295
+ this.selectError = selectError;
296
+ }
297
+ }
298
+ } // Use query data
299
+ else {
300
+ data = state.data;
301
+ } // Show placeholder data if needed
302
+
303
+
304
+ if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && status === 'loading') {
305
+ let placeholderData; // Memoize placeholder data
306
+
307
+ if (prevResult != null && prevResult.isPlaceholderData && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
308
+ placeholderData = prevResult.data;
309
+ } else {
310
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData() : options.placeholderData;
311
+
312
+ if (options.select && typeof placeholderData !== 'undefined') {
313
+ try {
314
+ placeholderData = options.select(placeholderData);
315
+ placeholderData = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
316
+ this.selectError = null;
317
+ } catch (selectError) {
318
+ if (process.env.NODE_ENV !== 'production') {
319
+ this.client.getLogger().error(selectError);
320
+ }
321
+
322
+ this.selectError = selectError;
323
+ }
324
+ }
325
+ }
326
+
327
+ if (typeof placeholderData !== 'undefined') {
328
+ status = 'success';
329
+ data = placeholderData;
330
+ isPlaceholderData = true;
331
+ }
332
+ }
333
+
334
+ if (this.selectError) {
335
+ error = this.selectError;
336
+ data = this.selectResult;
337
+ errorUpdatedAt = Date.now();
338
+ status = 'error';
339
+ }
340
+
341
+ const isFetching = fetchStatus === 'fetching';
342
+ const result = {
343
+ status,
344
+ fetchStatus,
345
+ isLoading: status === 'loading',
346
+ isSuccess: status === 'success',
347
+ isError: status === 'error',
348
+ data,
349
+ dataUpdatedAt,
350
+ error,
351
+ errorUpdatedAt,
352
+ failureCount: state.fetchFailureCount,
353
+ errorUpdateCount: state.errorUpdateCount,
354
+ isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
355
+ isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
356
+ isFetching: isFetching,
357
+ isRefetching: isFetching && status !== 'loading',
358
+ isLoadingError: status === 'error' && state.dataUpdatedAt === 0,
359
+ isPaused: fetchStatus === 'paused',
360
+ isPlaceholderData,
361
+ isPreviousData,
362
+ isRefetchError: status === 'error' && state.dataUpdatedAt !== 0,
363
+ isStale: isStale(query, options),
364
+ refetch: this.refetch,
365
+ remove: this.remove
366
+ };
367
+ return result;
368
+ }
369
+
370
+ updateResult(notifyOptions) {
371
+ const prevResult = this.currentResult;
372
+ const nextResult = this.createResult(this.currentQuery, this.options);
373
+ this.currentResultState = this.currentQuery.state;
374
+ this.currentResultOptions = this.options; // Only notify and update result if something has changed
375
+
376
+ if (shallowEqualObjects(nextResult, prevResult)) {
377
+ return;
378
+ }
379
+
380
+ this.currentResult = nextResult; // Determine which callbacks to trigger
381
+
382
+ const defaultNotifyOptions = {
383
+ cache: true
384
+ };
385
+
386
+ const shouldNotifyListeners = () => {
387
+ if (!prevResult) {
388
+ return true;
389
+ }
390
+
391
+ const {
392
+ notifyOnChangeProps
393
+ } = this.options;
394
+
395
+ if (notifyOnChangeProps === 'all' || !notifyOnChangeProps && !this.trackedProps.size) {
396
+ return true;
397
+ }
398
+
399
+ const includedProps = new Set(notifyOnChangeProps != null ? notifyOnChangeProps : this.trackedProps);
400
+
401
+ if (this.options.useErrorBoundary) {
402
+ includedProps.add('error');
403
+ }
404
+
405
+ return Object.keys(this.currentResult).some(key => {
406
+ const typedKey = key;
407
+ const changed = this.currentResult[typedKey] !== prevResult[typedKey];
408
+ return changed && includedProps.has(typedKey);
409
+ });
410
+ };
411
+
412
+ if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
413
+ defaultNotifyOptions.listeners = true;
414
+ }
415
+
416
+ this.notify({ ...defaultNotifyOptions,
417
+ ...notifyOptions
418
+ });
419
+ }
420
+
421
+ updateQuery() {
422
+ const query = this.client.getQueryCache().build(this.client, this.options);
423
+
424
+ if (query === this.currentQuery) {
425
+ return;
426
+ }
427
+
428
+ const prevQuery = this.currentQuery;
429
+ this.currentQuery = query;
430
+ this.currentQueryInitialState = query.state;
431
+ this.previousQueryResult = this.currentResult;
432
+
433
+ if (this.hasListeners()) {
434
+ prevQuery == null ? void 0 : prevQuery.removeObserver(this);
435
+ query.addObserver(this);
436
+ }
437
+ }
438
+
439
+ onQueryUpdate(action) {
440
+ const notifyOptions = {};
441
+
442
+ if (action.type === 'success') {
443
+ notifyOptions.onSuccess = !action.manual;
444
+ } else if (action.type === 'error' && !isCancelledError(action.error)) {
445
+ notifyOptions.onError = true;
446
+ }
447
+
448
+ this.updateResult(notifyOptions);
449
+
450
+ if (this.hasListeners()) {
451
+ this.updateTimers();
452
+ }
453
+ }
454
+
455
+ notify(notifyOptions) {
456
+ notifyManager.batch(() => {
457
+ // First trigger the configuration callbacks
458
+ if (notifyOptions.onSuccess) {
459
+ var _this$options$onSucce, _this$options, _this$options$onSettl, _this$options2;
460
+
461
+ (_this$options$onSucce = (_this$options = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options, this.currentResult.data);
462
+ (_this$options$onSettl = (_this$options2 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options2, this.currentResult.data, null);
463
+ } else if (notifyOptions.onError) {
464
+ var _this$options$onError, _this$options3, _this$options$onSettl2, _this$options4;
465
+
466
+ (_this$options$onError = (_this$options3 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options3, this.currentResult.error);
467
+ (_this$options$onSettl2 = (_this$options4 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options4, undefined, this.currentResult.error);
468
+ } // Then trigger the listeners
469
+
470
+
471
+ if (notifyOptions.listeners) {
472
+ this.listeners.forEach(listener => {
473
+ listener(this.currentResult);
474
+ });
475
+ } // Then the cache listeners
476
+
477
+
478
+ if (notifyOptions.cache) {
479
+ this.client.getQueryCache().notify({
480
+ query: this.currentQuery,
481
+ type: 'observerResultsUpdated'
482
+ });
483
+ }
484
+ });
485
+ }
486
+
487
+ }
488
+
489
+ function shouldLoadOnMount(query, options) {
490
+ return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
491
+ }
492
+
493
+ function shouldFetchOnMount(query, options) {
494
+ return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
495
+ }
496
+
497
+ function shouldFetchOn(query, options, field) {
498
+ if (options.enabled !== false) {
499
+ const value = typeof field === 'function' ? field(query) : field;
500
+ return value === 'always' || value !== false && isStale(query, options);
501
+ }
502
+
503
+ return false;
504
+ }
505
+
506
+ function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
507
+ return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== 'error') && isStale(query, options);
508
+ }
509
+
510
+ function isStale(query, options) {
511
+ return query.isStaleByTime(options.staleTime);
512
+ }
513
+
514
+ export { QueryObserver };
515
+ //# sourceMappingURL=queryObserver.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queryObserver.esm.js","sources":["../../src/queryObserver.ts"],"sourcesContent":["import { DefaultedQueryObserverOptions, RefetchPageFilters } from './types'\nimport {\n isServer,\n isValidTimeout,\n noop,\n replaceData,\n shallowEqualObjects,\n timeUntilStale,\n} from './utils'\nimport { notifyManager } from './notifyManager'\nimport type {\n PlaceholderDataFunction,\n QueryKey,\n QueryObserverBaseResult,\n QueryObserverOptions,\n QueryObserverResult,\n QueryOptions,\n RefetchOptions,\n} from './types'\nimport type { Query, QueryState, Action, FetchOptions } from './query'\nimport type { QueryClient } from './queryClient'\nimport { focusManager } from './focusManager'\nimport { Subscribable } from './subscribable'\nimport { canFetch, isCancelledError } from './retryer'\n\ntype QueryObserverListener<TData, TError> = (\n result: QueryObserverResult<TData, TError>,\n) => void\n\nexport interface NotifyOptions {\n cache?: boolean\n listeners?: boolean\n onError?: boolean\n onSuccess?: boolean\n}\n\nexport interface ObserverFetchOptions extends FetchOptions {\n throwOnError?: boolean\n}\n\nexport class QueryObserver<\n TQueryFnData = unknown,\n TError = unknown,\n TData = TQueryFnData,\n TQueryData = TQueryFnData,\n TQueryKey extends QueryKey = QueryKey,\n> extends Subscribable<QueryObserverListener<TData, TError>> {\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n\n private client: QueryClient\n private currentQuery!: Query<TQueryFnData, TError, TQueryData, TQueryKey>\n private currentQueryInitialState!: QueryState<TQueryData, TError>\n private currentResult!: QueryObserverResult<TData, TError>\n private currentResultState?: QueryState<TQueryData, TError>\n private currentResultOptions?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >\n private previousQueryResult?: QueryObserverResult<TData, TError>\n private selectError: TError | null\n private selectFn?: (data: TQueryData) => TData\n private selectResult?: TData\n private staleTimeoutId?: ReturnType<typeof setTimeout>\n private refetchIntervalId?: ReturnType<typeof setInterval>\n private currentRefetchInterval?: number | false\n private trackedProps!: Set<keyof QueryObserverResult>\n\n constructor(\n client: QueryClient,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ) {\n super()\n\n this.client = client\n this.options = options\n this.trackedProps = new Set()\n this.selectError = null\n this.bindMethods()\n this.setOptions(options)\n }\n\n protected bindMethods(): void {\n this.remove = this.remove.bind(this)\n this.refetch = this.refetch.bind(this)\n }\n\n protected onSubscribe(): void {\n if (this.listeners.length === 1) {\n this.currentQuery.addObserver(this)\n\n if (shouldFetchOnMount(this.currentQuery, this.options)) {\n this.executeFetch()\n }\n\n this.updateTimers()\n }\n }\n\n protected onUnsubscribe(): void {\n if (!this.listeners.length) {\n this.destroy()\n }\n }\n\n shouldFetchOnReconnect(): boolean {\n return shouldFetchOn(\n this.currentQuery,\n this.options,\n this.options.refetchOnReconnect,\n )\n }\n\n shouldFetchOnWindowFocus(): boolean {\n return shouldFetchOn(\n this.currentQuery,\n this.options,\n this.options.refetchOnWindowFocus,\n )\n }\n\n destroy(): void {\n this.listeners = []\n this.clearStaleTimeout()\n this.clearRefetchInterval()\n this.currentQuery.removeObserver(this)\n }\n\n setOptions(\n options?: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n notifyOptions?: NotifyOptions,\n ): void {\n const prevOptions = this.options\n const prevQuery = this.currentQuery\n\n this.options = this.client.defaultQueryOptions(options)\n\n if (!shallowEqualObjects(prevOptions, this.options)) {\n this.client.getQueryCache().notify({\n type: 'observerOptionsUpdated',\n query: this.currentQuery,\n observer: this,\n })\n }\n\n if (\n typeof this.options.enabled !== 'undefined' &&\n typeof this.options.enabled !== 'boolean'\n ) {\n throw new Error('Expected enabled to be a boolean')\n }\n\n // Keep previous query key if the user does not supply one\n if (!this.options.queryKey) {\n this.options.queryKey = prevOptions.queryKey\n }\n\n this.updateQuery()\n\n const mounted = this.hasListeners()\n\n // Fetch if there are subscribers\n if (\n mounted &&\n shouldFetchOptionally(\n this.currentQuery,\n prevQuery,\n this.options,\n prevOptions,\n )\n ) {\n this.executeFetch()\n }\n\n // Update result\n this.updateResult(notifyOptions)\n\n // Update stale interval if needed\n if (\n mounted &&\n (this.currentQuery !== prevQuery ||\n this.options.enabled !== prevOptions.enabled ||\n this.options.staleTime !== prevOptions.staleTime)\n ) {\n this.updateStaleTimeout()\n }\n\n const nextRefetchInterval = this.computeRefetchInterval()\n\n // Update refetch interval if needed\n if (\n mounted &&\n (this.currentQuery !== prevQuery ||\n this.options.enabled !== prevOptions.enabled ||\n nextRefetchInterval !== this.currentRefetchInterval)\n ) {\n this.updateRefetchInterval(nextRefetchInterval)\n }\n }\n\n getOptimisticResult(\n options: DefaultedQueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const query = this.client.getQueryCache().build(this.client, options)\n\n return this.createResult(query, options)\n }\n\n getCurrentResult(): QueryObserverResult<TData, TError> {\n return this.currentResult\n }\n\n trackResult(\n result: QueryObserverResult<TData, TError>,\n ): QueryObserverResult<TData, TError> {\n const trackedResult = {} as QueryObserverResult<TData, TError>\n\n Object.keys(result).forEach((key) => {\n Object.defineProperty(trackedResult, key, {\n configurable: false,\n enumerable: true,\n get: () => {\n this.trackedProps.add(key as keyof QueryObserverResult)\n return result[key as keyof QueryObserverResult]\n },\n })\n })\n\n return trackedResult\n }\n\n getCurrentQuery(): Query<TQueryFnData, TError, TQueryData, TQueryKey> {\n return this.currentQuery\n }\n\n remove(): void {\n this.client.getQueryCache().remove(this.currentQuery)\n }\n\n refetch<TPageData>({\n refetchPage,\n ...options\n }: RefetchOptions & RefetchPageFilters<TPageData> = {}): Promise<\n QueryObserverResult<TData, TError>\n > {\n return this.fetch({\n ...options,\n meta: { refetchPage },\n })\n }\n\n fetchOptimistic(\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): Promise<QueryObserverResult<TData, TError>> {\n const defaultedOptions = this.client.defaultQueryOptions(options)\n\n const query = this.client\n .getQueryCache()\n .build(this.client, defaultedOptions)\n query.isFetchingOptimistic = true\n\n return query.fetch().then(() => this.createResult(query, defaultedOptions))\n }\n\n protected fetch(\n fetchOptions: ObserverFetchOptions,\n ): Promise<QueryObserverResult<TData, TError>> {\n return this.executeFetch({\n ...fetchOptions,\n cancelRefetch: fetchOptions.cancelRefetch ?? true,\n }).then(() => {\n this.updateResult()\n return this.currentResult\n })\n }\n\n private executeFetch(\n fetchOptions?: ObserverFetchOptions,\n ): Promise<TQueryData | undefined> {\n // Make sure we reference the latest query as the current one might have been removed\n this.updateQuery()\n\n // Fetch\n let promise: Promise<TQueryData | undefined> = this.currentQuery.fetch(\n this.options as QueryOptions<TQueryFnData, TError, TQueryData, TQueryKey>,\n fetchOptions,\n )\n\n if (!fetchOptions?.throwOnError) {\n promise = promise.catch(noop)\n }\n\n return promise\n }\n\n private updateStaleTimeout(): void {\n this.clearStaleTimeout()\n\n if (\n isServer ||\n this.currentResult.isStale ||\n !isValidTimeout(this.options.staleTime)\n ) {\n return\n }\n\n const time = timeUntilStale(\n this.currentResult.dataUpdatedAt,\n this.options.staleTime,\n )\n\n // The timeout is sometimes triggered 1 ms before the stale time expiration.\n // To mitigate this issue we always add 1 ms to the timeout.\n const timeout = time + 1\n\n this.staleTimeoutId = setTimeout(() => {\n if (!this.currentResult.isStale) {\n this.updateResult()\n }\n }, timeout)\n }\n\n private computeRefetchInterval() {\n return typeof this.options.refetchInterval === 'function'\n ? this.options.refetchInterval(this.currentResult.data, this.currentQuery)\n : this.options.refetchInterval ?? false\n }\n\n private updateRefetchInterval(nextInterval: number | false): void {\n this.clearRefetchInterval()\n\n this.currentRefetchInterval = nextInterval\n\n if (\n isServer ||\n this.options.enabled === false ||\n !isValidTimeout(this.currentRefetchInterval) ||\n this.currentRefetchInterval === 0\n ) {\n return\n }\n\n this.refetchIntervalId = setInterval(() => {\n if (\n this.options.refetchIntervalInBackground ||\n focusManager.isFocused()\n ) {\n this.executeFetch()\n }\n }, this.currentRefetchInterval)\n }\n\n private updateTimers(): void {\n this.updateStaleTimeout()\n this.updateRefetchInterval(this.computeRefetchInterval())\n }\n\n private clearStaleTimeout(): void {\n if (this.staleTimeoutId) {\n clearTimeout(this.staleTimeoutId)\n this.staleTimeoutId = undefined\n }\n }\n\n private clearRefetchInterval(): void {\n if (this.refetchIntervalId) {\n clearInterval(this.refetchIntervalId)\n this.refetchIntervalId = undefined\n }\n }\n\n protected createResult(\n query: Query<TQueryFnData, TError, TQueryData, TQueryKey>,\n options: QueryObserverOptions<\n TQueryFnData,\n TError,\n TData,\n TQueryData,\n TQueryKey\n >,\n ): QueryObserverResult<TData, TError> {\n const prevQuery = this.currentQuery\n const prevOptions = this.options\n const prevResult = this.currentResult as\n | QueryObserverResult<TData, TError>\n | undefined\n const prevResultState = this.currentResultState\n const prevResultOptions = this.currentResultOptions\n const queryChange = query !== prevQuery\n const queryInitialState = queryChange\n ? query.state\n : this.currentQueryInitialState\n const prevQueryResult = queryChange\n ? this.currentResult\n : this.previousQueryResult\n\n const { state } = query\n let { dataUpdatedAt, error, errorUpdatedAt, fetchStatus, status } = state\n let isPreviousData = false\n let isPlaceholderData = false\n let data: TData | undefined\n\n // Optimistically set result in fetching state if needed\n if (options._optimisticResults) {\n const mounted = this.hasListeners()\n\n const fetchOnMount = !mounted && shouldFetchOnMount(query, options)\n\n const fetchOptionally =\n mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions)\n\n if (fetchOnMount || fetchOptionally) {\n fetchStatus = canFetch(query.options.networkMode)\n ? 'fetching'\n : 'paused'\n if (!dataUpdatedAt) {\n status = 'loading'\n }\n }\n if (options._optimisticResults === 'isRestoring') {\n fetchStatus = 'idle'\n }\n }\n\n // Keep previous data if needed\n if (\n options.keepPreviousData &&\n !state.dataUpdateCount &&\n prevQueryResult?.isSuccess &&\n status !== 'error'\n ) {\n data = prevQueryResult.data\n dataUpdatedAt = prevQueryResult.dataUpdatedAt\n status = prevQueryResult.status\n isPreviousData = true\n }\n // Select data if needed\n else if (options.select && typeof state.data !== 'undefined') {\n // Memoize select result\n if (\n prevResult &&\n state.data === prevResultState?.data &&\n options.select === this.selectFn\n ) {\n data = this.selectResult\n } else {\n try {\n this.selectFn = options.select\n data = options.select(state.data)\n data = replaceData(prevResult?.data, data, options)\n this.selectResult = data\n this.selectError = null\n } catch (selectError) {\n if (process.env.NODE_ENV !== 'production') {\n this.client.getLogger().error(selectError)\n }\n this.selectError = selectError as TError\n }\n }\n }\n // Use query data\n else {\n data = state.data as unknown as TData\n }\n\n // Show placeholder data if needed\n if (\n typeof options.placeholderData !== 'undefined' &&\n typeof data === 'undefined' &&\n status === 'loading'\n ) {\n let placeholderData\n\n // Memoize placeholder data\n if (\n prevResult?.isPlaceholderData &&\n options.placeholderData === prevResultOptions?.placeholderData\n ) {\n placeholderData = prevResult.data\n } else {\n placeholderData =\n typeof options.placeholderData === 'function'\n ? (options.placeholderData as PlaceholderDataFunction<TQueryData>)()\n : options.placeholderData\n if (options.select && typeof placeholderData !== 'undefined') {\n try {\n placeholderData = options.select(placeholderData)\n placeholderData = replaceData(\n prevResult?.data,\n placeholderData,\n options,\n )\n this.selectError = null\n } catch (selectError) {\n if (process.env.NODE_ENV !== 'production') {\n this.client.getLogger().error(selectError)\n }\n this.selectError = selectError as TError\n }\n }\n }\n\n if (typeof placeholderData !== 'undefined') {\n status = 'success'\n data = placeholderData as TData\n isPlaceholderData = true\n }\n }\n\n if (this.selectError) {\n error = this.selectError as any\n data = this.selectResult\n errorUpdatedAt = Date.now()\n status = 'error'\n }\n\n const isFetching = fetchStatus === 'fetching'\n\n const result: QueryObserverBaseResult<TData, TError> = {\n status,\n fetchStatus,\n isLoading: status === 'loading',\n isSuccess: status === 'success',\n isError: status === 'error',\n data,\n dataUpdatedAt,\n error,\n errorUpdatedAt,\n failureCount: state.fetchFailureCount,\n errorUpdateCount: state.errorUpdateCount,\n isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,\n isFetchedAfterMount:\n state.dataUpdateCount > queryInitialState.dataUpdateCount ||\n state.errorUpdateCount > queryInitialState.errorUpdateCount,\n isFetching: isFetching,\n isRefetching: isFetching && status !== 'loading',\n isLoadingError: status === 'error' && state.dataUpdatedAt === 0,\n isPaused: fetchStatus === 'paused',\n isPlaceholderData,\n isPreviousData,\n isRefetchError: status === 'error' && state.dataUpdatedAt !== 0,\n isStale: isStale(query, options),\n refetch: this.refetch,\n remove: this.remove,\n }\n\n return result as QueryObserverResult<TData, TError>\n }\n\n updateResult(notifyOptions?: NotifyOptions): void {\n const prevResult = this.currentResult as\n | QueryObserverResult<TData, TError>\n | undefined\n\n const nextResult = this.createResult(this.currentQuery, this.options)\n this.currentResultState = this.currentQuery.state\n this.currentResultOptions = this.options\n\n // Only notify and update result if something has changed\n if (shallowEqualObjects(nextResult, prevResult)) {\n return\n }\n\n this.currentResult = nextResult\n\n // Determine which callbacks to trigger\n const defaultNotifyOptions: NotifyOptions = { cache: true }\n\n const shouldNotifyListeners = (): boolean => {\n if (!prevResult) {\n return true\n }\n\n const { notifyOnChangeProps } = this.options\n\n if (\n notifyOnChangeProps === 'all' ||\n (!notifyOnChangeProps && !this.trackedProps.size)\n ) {\n return true\n }\n\n const includedProps = new Set(notifyOnChangeProps ?? this.trackedProps)\n\n if (this.options.useErrorBoundary) {\n includedProps.add('error')\n }\n\n return Object.keys(this.currentResult).some((key) => {\n const typedKey = key as keyof QueryObserverResult\n const changed = this.currentResult[typedKey] !== prevResult[typedKey]\n return changed && includedProps.has(typedKey)\n })\n }\n\n if (notifyOptions?.listeners !== false && shouldNotifyListeners()) {\n defaultNotifyOptions.listeners = true\n }\n\n this.notify({ ...defaultNotifyOptions, ...notifyOptions })\n }\n\n private updateQuery(): void {\n const query = this.client.getQueryCache().build(this.client, this.options)\n\n if (query === this.currentQuery) {\n return\n }\n\n const prevQuery = this.currentQuery as\n | Query<TQueryFnData, TError, TQueryData, TQueryKey>\n | undefined\n this.currentQuery = query\n this.currentQueryInitialState = query.state\n this.previousQueryResult = this.currentResult\n\n if (this.hasListeners()) {\n prevQuery?.removeObserver(this)\n query.addObserver(this)\n }\n }\n\n onQueryUpdate(action: Action<TData, TError>): void {\n const notifyOptions: NotifyOptions = {}\n\n if (action.type === 'success') {\n notifyOptions.onSuccess = !action.manual\n } else if (action.type === 'error' && !isCancelledError(action.error)) {\n notifyOptions.onError = true\n }\n\n this.updateResult(notifyOptions)\n\n if (this.hasListeners()) {\n this.updateTimers()\n }\n }\n\n private notify(notifyOptions: NotifyOptions): void {\n notifyManager.batch(() => {\n // First trigger the configuration callbacks\n if (notifyOptions.onSuccess) {\n this.options.onSuccess?.(this.currentResult.data!)\n this.options.onSettled?.(this.currentResult.data!, null)\n } else if (notifyOptions.onError) {\n this.options.onError?.(this.currentResult.error!)\n this.options.onSettled?.(undefined, this.currentResult.error!)\n }\n\n // Then trigger the listeners\n if (notifyOptions.listeners) {\n this.listeners.forEach((listener) => {\n listener(this.currentResult)\n })\n }\n\n // Then the cache listeners\n if (notifyOptions.cache) {\n this.client.getQueryCache().notify({\n query: this.currentQuery,\n type: 'observerResultsUpdated',\n })\n }\n })\n }\n}\n\nfunction shouldLoadOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any>,\n): boolean {\n return (\n options.enabled !== false &&\n !query.state.dataUpdatedAt &&\n !(query.state.status === 'error' && options.retryOnMount === false)\n )\n}\n\nfunction shouldFetchOnMount(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n shouldLoadOnMount(query, options) ||\n (query.state.dataUpdatedAt > 0 &&\n shouldFetchOn(query, options, options.refetchOnMount))\n )\n}\n\nfunction shouldFetchOn(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n field: typeof options['refetchOnMount'] &\n typeof options['refetchOnWindowFocus'] &\n typeof options['refetchOnReconnect'],\n) {\n if (options.enabled !== false) {\n const value = typeof field === 'function' ? field(query) : field\n\n return value === 'always' || (value !== false && isStale(query, options))\n }\n return false\n}\n\nfunction shouldFetchOptionally(\n query: Query<any, any, any, any>,\n prevQuery: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n prevOptions: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return (\n options.enabled !== false &&\n (query !== prevQuery || prevOptions.enabled === false) &&\n (!options.suspense || query.state.status !== 'error') &&\n isStale(query, options)\n )\n}\n\nfunction isStale(\n query: Query<any, any, any, any>,\n options: QueryObserverOptions<any, any, any, any, any>,\n): boolean {\n return query.isStaleByTime(options.staleTime)\n}\n"],"names":["QueryObserver","Subscribable","constructor","client","options","trackedProps","Set","selectError","bindMethods","setOptions","remove","bind","refetch","onSubscribe","listeners","length","currentQuery","addObserver","shouldFetchOnMount","executeFetch","updateTimers","onUnsubscribe","destroy","shouldFetchOnReconnect","shouldFetchOn","refetchOnReconnect","shouldFetchOnWindowFocus","refetchOnWindowFocus","clearStaleTimeout","clearRefetchInterval","removeObserver","notifyOptions","prevOptions","prevQuery","defaultQueryOptions","shallowEqualObjects","getQueryCache","notify","type","query","observer","enabled","Error","queryKey","updateQuery","mounted","hasListeners","shouldFetchOptionally","updateResult","staleTime","updateStaleTimeout","nextRefetchInterval","computeRefetchInterval","currentRefetchInterval","updateRefetchInterval","getOptimisticResult","build","createResult","getCurrentResult","currentResult","trackResult","result","trackedResult","Object","keys","forEach","key","defineProperty","configurable","enumerable","get","add","getCurrentQuery","refetchPage","fetch","meta","fetchOptimistic","defaultedOptions","isFetchingOptimistic","then","fetchOptions","cancelRefetch","promise","throwOnError","catch","noop","isServer","isStale","isValidTimeout","time","timeUntilStale","dataUpdatedAt","timeout","staleTimeoutId","setTimeout","refetchInterval","data","nextInterval","refetchIntervalId","setInterval","refetchIntervalInBackground","focusManager","isFocused","clearTimeout","undefined","clearInterval","prevResult","prevResultState","currentResultState","prevResultOptions","currentResultOptions","queryChange","queryInitialState","state","currentQueryInitialState","prevQueryResult","previousQueryResult","error","errorUpdatedAt","fetchStatus","status","isPreviousData","isPlaceholderData","_optimisticResults","fetchOnMount","fetchOptionally","canFetch","networkMode","keepPreviousData","dataUpdateCount","isSuccess","select","selectFn","selectResult","replaceData","process","env","NODE_ENV","getLogger","placeholderData","Date","now","isFetching","isLoading","isError","failureCount","fetchFailureCount","errorUpdateCount","isFetched","isFetchedAfterMount","isRefetching","isLoadingError","isPaused","isRefetchError","nextResult","defaultNotifyOptions","cache","shouldNotifyListeners","notifyOnChangeProps","size","includedProps","useErrorBoundary","some","typedKey","changed","has","onQueryUpdate","action","onSuccess","manual","isCancelledError","onError","notifyManager","batch","onSettled","listener","shouldLoadOnMount","retryOnMount","refetchOnMount","field","value","suspense","isStaleByTime"],"mappings":";;;;;;AAwCO,MAAMA,aAAN,SAMGC,YANH,CAMsD;AA8B3DC,EAAAA,WAAW,CACTC,MADS,EAETC,OAFS,EAST;AACA,IAAA,KAAA,EAAA,CAAA;IAEA,IAAKD,CAAAA,MAAL,GAAcA,MAAd,CAAA;IACA,IAAKC,CAAAA,OAAL,GAAeA,OAAf,CAAA;AACA,IAAA,IAAA,CAAKC,YAAL,GAAoB,IAAIC,GAAJ,EAApB,CAAA;IACA,IAAKC,CAAAA,WAAL,GAAmB,IAAnB,CAAA;AACA,IAAA,IAAA,CAAKC,WAAL,EAAA,CAAA;IACA,IAAKC,CAAAA,UAAL,CAAgBL,OAAhB,CAAA,CAAA;AACD,GAAA;;AAESI,EAAAA,WAAW,GAAS;IAC5B,IAAKE,CAAAA,MAAL,GAAc,IAAKA,CAAAA,MAAL,CAAYC,IAAZ,CAAiB,IAAjB,CAAd,CAAA;IACA,IAAKC,CAAAA,OAAL,GAAe,IAAKA,CAAAA,OAAL,CAAa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AAYO,MAAZ,KAAuB,OAF7C,KAGAjC,OAAO,CAAChD,KAAD,EAAQnC,OAAR,CAJT,CAAA;AAMD,CAAA;;AAED,SAASmF,OAAT,CACEhD,KADF,EAEEnC,OAFF,EAGW;AACT,EAAA,OAAOmC,KAAK,CAAC+I,aAAN,CAAoBlL,OAAO,CAAC6C,SAA5B,CAAP,CAAA;AACD;;;;"}
@@ -0,0 +1,33 @@
1
+ import { isValidTimeout, isServer } from './utils.esm.js';
2
+
3
+ class Removable {
4
+ destroy() {
5
+ this.clearGcTimeout();
6
+ }
7
+
8
+ scheduleGc() {
9
+ this.clearGcTimeout();
10
+
11
+ if (isValidTimeout(this.cacheTime)) {
12
+ this.gcTimeout = setTimeout(() => {
13
+ this.optionalRemove();
14
+ }, this.cacheTime);
15
+ }
16
+ }
17
+
18
+ updateCacheTime(newCacheTime) {
19
+ // Default to 5 minutes (Infinity for server-side) if no cache time is set
20
+ this.cacheTime = Math.max(this.cacheTime || 0, newCacheTime != null ? newCacheTime : isServer ? Infinity : 5 * 60 * 1000);
21
+ }
22
+
23
+ clearGcTimeout() {
24
+ if (this.gcTimeout) {
25
+ clearTimeout(this.gcTimeout);
26
+ this.gcTimeout = undefined;
27
+ }
28
+ }
29
+
30
+ }
31
+
32
+ export { Removable };
33
+ //# sourceMappingURL=removable.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removable.esm.js","sources":["../../src/removable.ts"],"sourcesContent":["import { isServer, isValidTimeout } from './utils'\n\nexport abstract class Removable {\n cacheTime!: number\n private gcTimeout?: ReturnType<typeof setTimeout>\n\n destroy(): void {\n this.clearGcTimeout()\n }\n\n protected scheduleGc(): void {\n this.clearGcTimeout()\n\n if (isValidTimeout(this.cacheTime)) {\n this.gcTimeout = setTimeout(() => {\n this.optionalRemove()\n }, this.cacheTime)\n }\n }\n\n protected updateCacheTime(newCacheTime: number | undefined): void {\n // Default to 5 minutes (Infinity for server-side) if no cache time is set\n this.cacheTime = Math.max(\n this.cacheTime || 0,\n newCacheTime ?? (isServer ? Infinity : 5 * 60 * 1000),\n )\n }\n\n protected clearGcTimeout() {\n if (this.gcTimeout) {\n clearTimeout(this.gcTimeout)\n this.gcTimeout = undefined\n }\n }\n\n protected abstract optionalRemove(): void\n}\n"],"names":["Removable","destroy","clearGcTimeout","scheduleGc","isValidTimeout","cacheTime","gcTimeout","setTimeout","optionalRemove","updateCacheTime","newCacheTime","Math","max","isServer","Infinity","clearTimeout","undefined"],"mappings":";;AAEO,MAAeA,SAAf,CAAyB;AAI9BC,EAAAA,OAAO,GAAS;AACd,IAAA,IAAA,CAAKC,cAAL,EAAA,CAAA;AACD,GAAA;;AAESC,EAAAA,UAAU,GAAS;AAC3B,IAAA,IAAA,CAAKD,cAAL,EAAA,CAAA;;AAEA,IAAA,IAAIE,cAAc,CAAC,IAAKC,CAAAA,SAAN,CAAlB,EAAoC;AAClC,MAAA,IAAA,CAAKC,SAAL,GAAiBC,UAAU,CAAC,MAAM;AAChC,QAAA,IAAA,CAAKC,cAAL,EAAA,CAAA;OADyB,EAExB,IAAKH,CAAAA,SAFmB,CAA3B,CAAA;AAGD,KAAA;AACF,GAAA;;EAESI,eAAe,CAACC,YAAD,EAAyC;AAChE;IACA,IAAKL,CAAAA,SAAL,GAAiBM,IAAI,CAACC,GAAL,CACf,IAAA,CAAKP,SAAL,IAAkB,CADH,EAEfK,YAFe,IAEfA,IAAAA,GAAAA,YAFe,GAEEG,QAAQ,GAAGC,QAAH,GAAc,CAAI,GAAA,EAAJ,GAAS,IAFjC,CAAjB,CAAA;AAID,GAAA;;AAESZ,EAAAA,cAAc,GAAG;IACzB,IAAI,IAAA,CAAKI,SAAT,EAAoB;MAClBS,YAAY,CAAC,IAAKT,CAAAA,SAAN,CAAZ,CAAA;MACA,IAAKA,CAAAA,SAAL,GAAiBU,SAAjB,CAAA;AACD,KAAA;AACF,GAAA;;AA/B6B;;;;"}