@elice/material-shared-utils 1.251120.1 → 1.260128.0-rc.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.
Files changed (102) hide show
  1. package/cjs/_virtual/_rollupPluginBabelHelpers.js +177 -376
  2. package/cjs/_virtual/index.js +5 -0
  3. package/cjs/_virtual/use-sync-external-store-shim.production.js +5 -0
  4. package/cjs/hooks/useHelpyLogo.js +3 -7
  5. package/cjs/index.js +4 -4
  6. package/cjs/material-config/MaterialConfigContext.d.ts +0 -1
  7. package/cjs/material-config/MaterialConfigContext.js +2 -2
  8. package/cjs/material-fetch/useMaterialFetch.d.ts +2 -47
  9. package/cjs/material-fetch/useMaterialFetch.js +1 -4
  10. package/cjs/material-fetch/useMaterialFetchRaw.d.ts +1 -1
  11. package/cjs/material-fetch/useMaterialFetchRaw.js +12 -19
  12. package/cjs/material-hoc/withMaterial.d.ts +1 -1
  13. package/cjs/material-hoc/withMaterial.js +0 -1
  14. package/cjs/node_modules/@tanstack/query-core/build/lib/focusManager.js +93 -0
  15. package/cjs/node_modules/@tanstack/query-core/build/lib/notifyManager.js +101 -0
  16. package/cjs/node_modules/@tanstack/query-core/build/lib/onlineManager.js +95 -0
  17. package/cjs/node_modules/@tanstack/query-core/build/lib/queryObserver.js +571 -0
  18. package/cjs/node_modules/@tanstack/query-core/build/lib/retryer.js +21 -0
  19. package/cjs/node_modules/@tanstack/query-core/build/lib/subscribable.js +33 -0
  20. package/cjs/node_modules/@tanstack/query-core/build/lib/utils.js +154 -0
  21. package/cjs/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js +65 -0
  22. package/cjs/node_modules/@tanstack/react-query/build/lib/QueryErrorResetBoundary.js +46 -0
  23. package/cjs/node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.js +52 -0
  24. package/cjs/node_modules/@tanstack/react-query/build/lib/isRestoring.js +31 -0
  25. package/cjs/node_modules/@tanstack/react-query/build/lib/suspense.js +39 -0
  26. package/cjs/node_modules/@tanstack/react-query/build/lib/useBaseQuery.js +94 -0
  27. package/cjs/node_modules/@tanstack/react-query/build/lib/useQuery.js +14 -0
  28. package/cjs/node_modules/@tanstack/react-query/build/lib/useSyncExternalStore.js +9 -0
  29. package/cjs/node_modules/@tanstack/react-query/build/lib/utils.js +12 -0
  30. package/cjs/node_modules/rxjs/dist/esm5/internal/BehaviorSubject.js +39 -0
  31. package/cjs/node_modules/rxjs/dist/esm5/internal/Observable.js +105 -0
  32. package/cjs/node_modules/rxjs/dist/esm5/internal/Subject.js +165 -0
  33. package/cjs/node_modules/rxjs/dist/esm5/internal/Subscriber.js +157 -0
  34. package/cjs/node_modules/rxjs/dist/esm5/internal/Subscription.js +148 -0
  35. package/cjs/node_modules/rxjs/dist/esm5/internal/config.js +6 -0
  36. package/cjs/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +19 -0
  37. package/cjs/node_modules/rxjs/dist/esm5/internal/symbol/observable.js +5 -0
  38. package/cjs/node_modules/rxjs/dist/esm5/internal/util/ObjectUnsubscribedError.js +13 -0
  39. package/cjs/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js +16 -0
  40. package/cjs/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js +10 -0
  41. package/cjs/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js +14 -0
  42. package/cjs/node_modules/rxjs/dist/esm5/internal/util/errorContext.js +9 -0
  43. package/cjs/node_modules/rxjs/dist/esm5/internal/util/identity.js +7 -0
  44. package/cjs/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +7 -0
  45. package/cjs/node_modules/rxjs/dist/esm5/internal/util/noop.js +5 -0
  46. package/cjs/node_modules/rxjs/dist/esm5/internal/util/pipe.js +17 -0
  47. package/cjs/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js +13 -0
  48. package/cjs/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +77 -0
  49. package/cjs/node_modules/use-sync-external-store/shim/index.js +13 -0
  50. package/es/_virtual/_rollupPluginBabelHelpers.js +176 -376
  51. package/es/_virtual/index.js +3 -0
  52. package/es/_virtual/use-sync-external-store-shim.production.js +3 -0
  53. package/es/hooks/useCallbackProp.js +3 -3
  54. package/es/hooks/useDeepClonedCompareEffect.js +2 -2
  55. package/es/hooks/useHelpyLogo.js +2 -6
  56. package/es/index.js +2 -2
  57. package/es/material-config/MaterialConfigContext.d.ts +0 -1
  58. package/es/material-config/MaterialConfigContext.js +1 -1
  59. package/es/material-config/MaterialConfigProvider.js +5 -5
  60. package/es/material-fetch/useMaterialFetch.d.ts +2 -47
  61. package/es/material-fetch/useMaterialFetch.js +1 -4
  62. package/es/material-fetch/useMaterialFetchRaw.d.ts +1 -1
  63. package/es/material-fetch/useMaterialFetchRaw.js +13 -20
  64. package/es/material-hoc/withMaterial.d.ts +1 -1
  65. package/es/material-hoc/withMaterial.js +0 -1
  66. package/es/node_modules/@tanstack/query-core/build/lib/focusManager.js +90 -0
  67. package/es/node_modules/@tanstack/query-core/build/lib/notifyManager.js +98 -0
  68. package/es/node_modules/@tanstack/query-core/build/lib/onlineManager.js +92 -0
  69. package/es/node_modules/@tanstack/query-core/build/lib/queryObserver.js +569 -0
  70. package/es/node_modules/@tanstack/query-core/build/lib/retryer.js +17 -0
  71. package/es/node_modules/@tanstack/query-core/build/lib/subscribable.js +31 -0
  72. package/es/node_modules/@tanstack/query-core/build/lib/utils.js +140 -0
  73. package/es/node_modules/@tanstack/react-query/build/lib/QueryClientProvider.js +42 -0
  74. package/es/node_modules/@tanstack/react-query/build/lib/QueryErrorResetBoundary.js +24 -0
  75. package/es/node_modules/@tanstack/react-query/build/lib/errorBoundaryUtils.js +28 -0
  76. package/es/node_modules/@tanstack/react-query/build/lib/isRestoring.js +9 -0
  77. package/es/node_modules/@tanstack/react-query/build/lib/suspense.js +34 -0
  78. package/es/node_modules/@tanstack/react-query/build/lib/useBaseQuery.js +72 -0
  79. package/es/node_modules/@tanstack/react-query/build/lib/useQuery.js +12 -0
  80. package/es/node_modules/@tanstack/react-query/build/lib/useSyncExternalStore.js +7 -0
  81. package/es/node_modules/@tanstack/react-query/build/lib/utils.js +10 -0
  82. package/es/node_modules/rxjs/dist/esm5/internal/BehaviorSubject.js +37 -0
  83. package/es/node_modules/rxjs/dist/esm5/internal/Observable.js +103 -0
  84. package/es/node_modules/rxjs/dist/esm5/internal/Subject.js +162 -0
  85. package/es/node_modules/rxjs/dist/esm5/internal/Subscriber.js +153 -0
  86. package/es/node_modules/rxjs/dist/esm5/internal/Subscription.js +144 -0
  87. package/es/node_modules/rxjs/dist/esm5/internal/config.js +4 -0
  88. package/es/node_modules/rxjs/dist/esm5/internal/scheduler/timeoutProvider.js +17 -0
  89. package/es/node_modules/rxjs/dist/esm5/internal/symbol/observable.js +3 -0
  90. package/es/node_modules/rxjs/dist/esm5/internal/util/ObjectUnsubscribedError.js +11 -0
  91. package/es/node_modules/rxjs/dist/esm5/internal/util/UnsubscriptionError.js +14 -0
  92. package/es/node_modules/rxjs/dist/esm5/internal/util/arrRemove.js +8 -0
  93. package/es/node_modules/rxjs/dist/esm5/internal/util/createErrorClass.js +12 -0
  94. package/es/node_modules/rxjs/dist/esm5/internal/util/errorContext.js +7 -0
  95. package/es/node_modules/rxjs/dist/esm5/internal/util/identity.js +5 -0
  96. package/es/node_modules/rxjs/dist/esm5/internal/util/isFunction.js +5 -0
  97. package/es/node_modules/rxjs/dist/esm5/internal/util/noop.js +3 -0
  98. package/es/node_modules/rxjs/dist/esm5/internal/util/pipe.js +15 -0
  99. package/es/node_modules/rxjs/dist/esm5/internal/util/reportUnhandledError.js +11 -0
  100. package/es/node_modules/use-sync-external-store/cjs/use-sync-external-store-shim.production.js +69 -0
  101. package/es/node_modules/use-sync-external-store/shim/index.js +11 -0
  102. package/package.json +6 -4
@@ -0,0 +1,569 @@
1
+ import { shallowEqualObjects, noop, isServer, isValidTimeout, timeUntilStale, replaceData } from './utils.js';
2
+ import { notifyManager } from './notifyManager.js';
3
+ import { focusManager } from './focusManager.js';
4
+ import { Subscribable } from './subscribable.js';
5
+ import { canFetch, isCancelledError } from './retryer.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.size === 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.hasListeners()) {
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 = new Set();
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
+ const result = this.createResult(query, options);
102
+
103
+ if (shouldAssignObserverCurrentProperties(this, result, options)) {
104
+ // this assigns the optimistic result to the current Observer
105
+ // because if the query function changes, useQuery will be performing
106
+ // an effect where it would fetch again.
107
+ // When the fetch finishes, we perform a deep data cloning in order
108
+ // to reuse objects references. This deep data clone is performed against
109
+ // the `observer.currentResult.data` property
110
+ // When QueryKey changes, we refresh the query and get new `optimistic`
111
+ // result, while we leave the `observer.currentResult`, so when new data
112
+ // arrives, it finds the old `observer.currentResult` which is related
113
+ // to the old QueryKey. Which means that currentResult and selectData are
114
+ // out of sync already.
115
+ // To solve this, we move the cursor of the currentResult everytime
116
+ // an observer reads an optimistic value.
117
+ // When keeping the previous data, the result doesn't change until new
118
+ // data arrives.
119
+ this.currentResult = result;
120
+ this.currentResultOptions = this.options;
121
+ this.currentResultState = this.currentQuery.state;
122
+ }
123
+
124
+ return result;
125
+ }
126
+
127
+ getCurrentResult() {
128
+ return this.currentResult;
129
+ }
130
+
131
+ trackResult(result) {
132
+ const trackedResult = {};
133
+ Object.keys(result).forEach(key => {
134
+ Object.defineProperty(trackedResult, key, {
135
+ configurable: false,
136
+ enumerable: true,
137
+ get: () => {
138
+ this.trackedProps.add(key);
139
+ return result[key];
140
+ }
141
+ });
142
+ });
143
+ return trackedResult;
144
+ }
145
+
146
+ getCurrentQuery() {
147
+ return this.currentQuery;
148
+ }
149
+
150
+ remove() {
151
+ this.client.getQueryCache().remove(this.currentQuery);
152
+ }
153
+
154
+ refetch({
155
+ refetchPage,
156
+ ...options
157
+ } = {}) {
158
+ return this.fetch({ ...options,
159
+ meta: {
160
+ refetchPage
161
+ }
162
+ });
163
+ }
164
+
165
+ fetchOptimistic(options) {
166
+ const defaultedOptions = this.client.defaultQueryOptions(options);
167
+ const query = this.client.getQueryCache().build(this.client, defaultedOptions);
168
+ query.isFetchingOptimistic = true;
169
+ return query.fetch().then(() => this.createResult(query, defaultedOptions));
170
+ }
171
+
172
+ fetch(fetchOptions) {
173
+ var _fetchOptions$cancelR;
174
+
175
+ return this.executeFetch({ ...fetchOptions,
176
+ cancelRefetch: (_fetchOptions$cancelR = fetchOptions.cancelRefetch) != null ? _fetchOptions$cancelR : true
177
+ }).then(() => {
178
+ this.updateResult();
179
+ return this.currentResult;
180
+ });
181
+ }
182
+
183
+ executeFetch(fetchOptions) {
184
+ // Make sure we reference the latest query as the current one might have been removed
185
+ this.updateQuery(); // Fetch
186
+
187
+ let promise = this.currentQuery.fetch(this.options, fetchOptions);
188
+
189
+ if (!(fetchOptions != null && fetchOptions.throwOnError)) {
190
+ promise = promise.catch(noop);
191
+ }
192
+
193
+ return promise;
194
+ }
195
+
196
+ updateStaleTimeout() {
197
+ this.clearStaleTimeout();
198
+
199
+ if (isServer || this.currentResult.isStale || !isValidTimeout(this.options.staleTime)) {
200
+ return;
201
+ }
202
+
203
+ const time = timeUntilStale(this.currentResult.dataUpdatedAt, this.options.staleTime); // The timeout is sometimes triggered 1 ms before the stale time expiration.
204
+ // To mitigate this issue we always add 1 ms to the timeout.
205
+
206
+ const timeout = time + 1;
207
+ this.staleTimeoutId = setTimeout(() => {
208
+ if (!this.currentResult.isStale) {
209
+ this.updateResult();
210
+ }
211
+ }, timeout);
212
+ }
213
+
214
+ computeRefetchInterval() {
215
+ var _this$options$refetch;
216
+
217
+ 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;
218
+ }
219
+
220
+ updateRefetchInterval(nextInterval) {
221
+ this.clearRefetchInterval();
222
+ this.currentRefetchInterval = nextInterval;
223
+
224
+ if (isServer || this.options.enabled === false || !isValidTimeout(this.currentRefetchInterval) || this.currentRefetchInterval === 0) {
225
+ return;
226
+ }
227
+
228
+ this.refetchIntervalId = setInterval(() => {
229
+ if (this.options.refetchIntervalInBackground || focusManager.isFocused()) {
230
+ this.executeFetch();
231
+ }
232
+ }, this.currentRefetchInterval);
233
+ }
234
+
235
+ updateTimers() {
236
+ this.updateStaleTimeout();
237
+ this.updateRefetchInterval(this.computeRefetchInterval());
238
+ }
239
+
240
+ clearStaleTimeout() {
241
+ if (this.staleTimeoutId) {
242
+ clearTimeout(this.staleTimeoutId);
243
+ this.staleTimeoutId = undefined;
244
+ }
245
+ }
246
+
247
+ clearRefetchInterval() {
248
+ if (this.refetchIntervalId) {
249
+ clearInterval(this.refetchIntervalId);
250
+ this.refetchIntervalId = undefined;
251
+ }
252
+ }
253
+
254
+ createResult(query, options) {
255
+ const prevQuery = this.currentQuery;
256
+ const prevOptions = this.options;
257
+ const prevResult = this.currentResult;
258
+ const prevResultState = this.currentResultState;
259
+ const prevResultOptions = this.currentResultOptions;
260
+ const queryChange = query !== prevQuery;
261
+ const queryInitialState = queryChange ? query.state : this.currentQueryInitialState;
262
+ const prevQueryResult = queryChange ? this.currentResult : this.previousQueryResult;
263
+ const {
264
+ state
265
+ } = query;
266
+ let {
267
+ dataUpdatedAt,
268
+ error,
269
+ errorUpdatedAt,
270
+ fetchStatus,
271
+ status
272
+ } = state;
273
+ let isPreviousData = false;
274
+ let isPlaceholderData = false;
275
+ let data; // Optimistically set result in fetching state if needed
276
+
277
+ if (options._optimisticResults) {
278
+ const mounted = this.hasListeners();
279
+ const fetchOnMount = !mounted && shouldFetchOnMount(query, options);
280
+ const fetchOptionally = mounted && shouldFetchOptionally(query, prevQuery, options, prevOptions);
281
+
282
+ if (fetchOnMount || fetchOptionally) {
283
+ fetchStatus = canFetch(query.options.networkMode) ? 'fetching' : 'paused';
284
+
285
+ if (!dataUpdatedAt) {
286
+ status = 'loading';
287
+ }
288
+ }
289
+
290
+ if (options._optimisticResults === 'isRestoring') {
291
+ fetchStatus = 'idle';
292
+ }
293
+ } // Keep previous data if needed
294
+
295
+
296
+ if (options.keepPreviousData && !state.dataUpdatedAt && prevQueryResult != null && prevQueryResult.isSuccess && status !== 'error') {
297
+ data = prevQueryResult.data;
298
+ dataUpdatedAt = prevQueryResult.dataUpdatedAt;
299
+ status = prevQueryResult.status;
300
+ isPreviousData = true;
301
+ } // Select data if needed
302
+ else if (options.select && typeof state.data !== 'undefined') {
303
+ // Memoize select result
304
+ if (prevResult && state.data === (prevResultState == null ? void 0 : prevResultState.data) && options.select === this.selectFn) {
305
+ data = this.selectResult;
306
+ } else {
307
+ try {
308
+ this.selectFn = options.select;
309
+ data = options.select(state.data);
310
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, data, options);
311
+ this.selectResult = data;
312
+ this.selectError = null;
313
+ } catch (selectError) {
314
+
315
+ this.selectError = selectError;
316
+ }
317
+ }
318
+ } // Use query data
319
+ else {
320
+ data = state.data;
321
+ } // Show placeholder data if needed
322
+
323
+
324
+ if (typeof options.placeholderData !== 'undefined' && typeof data === 'undefined' && status === 'loading') {
325
+ let placeholderData; // Memoize placeholder data
326
+
327
+ if (prevResult != null && prevResult.isPlaceholderData && options.placeholderData === (prevResultOptions == null ? void 0 : prevResultOptions.placeholderData)) {
328
+ placeholderData = prevResult.data;
329
+ } else {
330
+ placeholderData = typeof options.placeholderData === 'function' ? options.placeholderData() : options.placeholderData;
331
+
332
+ if (options.select && typeof placeholderData !== 'undefined') {
333
+ try {
334
+ placeholderData = options.select(placeholderData);
335
+ this.selectError = null;
336
+ } catch (selectError) {
337
+
338
+ this.selectError = selectError;
339
+ }
340
+ }
341
+ }
342
+
343
+ if (typeof placeholderData !== 'undefined') {
344
+ status = 'success';
345
+ data = replaceData(prevResult == null ? void 0 : prevResult.data, placeholderData, options);
346
+ isPlaceholderData = true;
347
+ }
348
+ }
349
+
350
+ if (this.selectError) {
351
+ error = this.selectError;
352
+ data = this.selectResult;
353
+ errorUpdatedAt = Date.now();
354
+ status = 'error';
355
+ }
356
+
357
+ const isFetching = fetchStatus === 'fetching';
358
+ const isLoading = status === 'loading';
359
+ const isError = status === 'error';
360
+ const result = {
361
+ status,
362
+ fetchStatus,
363
+ isLoading,
364
+ isSuccess: status === 'success',
365
+ isError,
366
+ isInitialLoading: isLoading && isFetching,
367
+ data,
368
+ dataUpdatedAt,
369
+ error,
370
+ errorUpdatedAt,
371
+ failureCount: state.fetchFailureCount,
372
+ failureReason: state.fetchFailureReason,
373
+ errorUpdateCount: state.errorUpdateCount,
374
+ isFetched: state.dataUpdateCount > 0 || state.errorUpdateCount > 0,
375
+ isFetchedAfterMount: state.dataUpdateCount > queryInitialState.dataUpdateCount || state.errorUpdateCount > queryInitialState.errorUpdateCount,
376
+ isFetching,
377
+ isRefetching: isFetching && !isLoading,
378
+ isLoadingError: isError && state.dataUpdatedAt === 0,
379
+ isPaused: fetchStatus === 'paused',
380
+ isPlaceholderData,
381
+ isPreviousData,
382
+ isRefetchError: isError && state.dataUpdatedAt !== 0,
383
+ isStale: isStale(query, options),
384
+ refetch: this.refetch,
385
+ remove: this.remove
386
+ };
387
+ return result;
388
+ }
389
+
390
+ updateResult(notifyOptions) {
391
+ const prevResult = this.currentResult;
392
+ const nextResult = this.createResult(this.currentQuery, this.options);
393
+ this.currentResultState = this.currentQuery.state;
394
+ this.currentResultOptions = this.options; // Only notify and update result if something has changed
395
+
396
+ if (shallowEqualObjects(nextResult, prevResult)) {
397
+ return;
398
+ }
399
+
400
+ this.currentResult = nextResult; // Determine which callbacks to trigger
401
+
402
+ const defaultNotifyOptions = {
403
+ cache: true
404
+ };
405
+
406
+ const shouldNotifyListeners = () => {
407
+ if (!prevResult) {
408
+ return true;
409
+ }
410
+
411
+ const {
412
+ notifyOnChangeProps
413
+ } = this.options;
414
+ const notifyOnChangePropsValue = typeof notifyOnChangeProps === 'function' ? notifyOnChangeProps() : notifyOnChangeProps;
415
+
416
+ if (notifyOnChangePropsValue === 'all' || !notifyOnChangePropsValue && !this.trackedProps.size) {
417
+ return true;
418
+ }
419
+
420
+ const includedProps = new Set(notifyOnChangePropsValue != null ? notifyOnChangePropsValue : this.trackedProps);
421
+
422
+ if (this.options.useErrorBoundary) {
423
+ includedProps.add('error');
424
+ }
425
+
426
+ return Object.keys(this.currentResult).some(key => {
427
+ const typedKey = key;
428
+ const changed = this.currentResult[typedKey] !== prevResult[typedKey];
429
+ return changed && includedProps.has(typedKey);
430
+ });
431
+ };
432
+
433
+ if ((notifyOptions == null ? void 0 : notifyOptions.listeners) !== false && shouldNotifyListeners()) {
434
+ defaultNotifyOptions.listeners = true;
435
+ }
436
+
437
+ this.notify({ ...defaultNotifyOptions,
438
+ ...notifyOptions
439
+ });
440
+ }
441
+
442
+ updateQuery() {
443
+ const query = this.client.getQueryCache().build(this.client, this.options);
444
+
445
+ if (query === this.currentQuery) {
446
+ return;
447
+ }
448
+
449
+ const prevQuery = this.currentQuery;
450
+ this.currentQuery = query;
451
+ this.currentQueryInitialState = query.state;
452
+ this.previousQueryResult = this.currentResult;
453
+
454
+ if (this.hasListeners()) {
455
+ prevQuery == null ? void 0 : prevQuery.removeObserver(this);
456
+ query.addObserver(this);
457
+ }
458
+ }
459
+
460
+ onQueryUpdate(action) {
461
+ const notifyOptions = {};
462
+
463
+ if (action.type === 'success') {
464
+ notifyOptions.onSuccess = !action.manual;
465
+ } else if (action.type === 'error' && !isCancelledError(action.error)) {
466
+ notifyOptions.onError = true;
467
+ }
468
+
469
+ this.updateResult(notifyOptions);
470
+
471
+ if (this.hasListeners()) {
472
+ this.updateTimers();
473
+ }
474
+ }
475
+
476
+ notify(notifyOptions) {
477
+ notifyManager.batch(() => {
478
+ // First trigger the configuration callbacks
479
+ if (notifyOptions.onSuccess) {
480
+ var _this$options$onSucce, _this$options, _this$options$onSettl, _this$options2;
481
+
482
+ (_this$options$onSucce = (_this$options = this.options).onSuccess) == null ? void 0 : _this$options$onSucce.call(_this$options, this.currentResult.data);
483
+ (_this$options$onSettl = (_this$options2 = this.options).onSettled) == null ? void 0 : _this$options$onSettl.call(_this$options2, this.currentResult.data, null);
484
+ } else if (notifyOptions.onError) {
485
+ var _this$options$onError, _this$options3, _this$options$onSettl2, _this$options4;
486
+
487
+ (_this$options$onError = (_this$options3 = this.options).onError) == null ? void 0 : _this$options$onError.call(_this$options3, this.currentResult.error);
488
+ (_this$options$onSettl2 = (_this$options4 = this.options).onSettled) == null ? void 0 : _this$options$onSettl2.call(_this$options4, undefined, this.currentResult.error);
489
+ } // Then trigger the listeners
490
+
491
+
492
+ if (notifyOptions.listeners) {
493
+ this.listeners.forEach(({
494
+ listener
495
+ }) => {
496
+ listener(this.currentResult);
497
+ });
498
+ } // Then the cache listeners
499
+
500
+
501
+ if (notifyOptions.cache) {
502
+ this.client.getQueryCache().notify({
503
+ query: this.currentQuery,
504
+ type: 'observerResultsUpdated'
505
+ });
506
+ }
507
+ });
508
+ }
509
+
510
+ }
511
+
512
+ function shouldLoadOnMount(query, options) {
513
+ return options.enabled !== false && !query.state.dataUpdatedAt && !(query.state.status === 'error' && options.retryOnMount === false);
514
+ }
515
+
516
+ function shouldFetchOnMount(query, options) {
517
+ return shouldLoadOnMount(query, options) || query.state.dataUpdatedAt > 0 && shouldFetchOn(query, options, options.refetchOnMount);
518
+ }
519
+
520
+ function shouldFetchOn(query, options, field) {
521
+ if (options.enabled !== false) {
522
+ const value = typeof field === 'function' ? field(query) : field;
523
+ return value === 'always' || value !== false && isStale(query, options);
524
+ }
525
+
526
+ return false;
527
+ }
528
+
529
+ function shouldFetchOptionally(query, prevQuery, options, prevOptions) {
530
+ return options.enabled !== false && (query !== prevQuery || prevOptions.enabled === false) && (!options.suspense || query.state.status !== 'error') && isStale(query, options);
531
+ }
532
+
533
+ function isStale(query, options) {
534
+ return query.isStaleByTime(options.staleTime);
535
+ } // this function would decide if we will update the observer's 'current'
536
+ // properties after an optimistic reading via getOptimisticResult
537
+
538
+
539
+ function shouldAssignObserverCurrentProperties(observer, optimisticResult, options) {
540
+ // it is important to keep this condition like this for three reasons:
541
+ // 1. It will get removed in the v5
542
+ // 2. it reads: don't update the properties if we want to keep the previous
543
+ // data.
544
+ // 3. The opposite condition (!options.keepPreviousData) would fallthrough
545
+ // and will result in a bad decision
546
+ if (options.keepPreviousData) {
547
+ return false;
548
+ } // this means we want to put some placeholder data when pending and queryKey
549
+ // changed.
550
+
551
+
552
+ if (options.placeholderData !== undefined) {
553
+ // re-assign properties only if current data is placeholder data
554
+ // which means that data did not arrive yet, so, if there is some cached data
555
+ // we need to "prepare" to receive it
556
+ return optimisticResult.isPlaceholderData;
557
+ } // if the newly created result isn't what the observer is holding as current,
558
+ // then we'll need to update the properties as well
559
+
560
+
561
+ if (!shallowEqualObjects(observer.getCurrentResult(), optimisticResult)) {
562
+ return true;
563
+ } // basically, just keep previous properties if nothing changed
564
+
565
+
566
+ return false;
567
+ }
568
+
569
+ export { QueryObserver };
@@ -0,0 +1,17 @@
1
+ import { onlineManager } from './onlineManager.js';
2
+
3
+ function canFetch(networkMode) {
4
+ return (networkMode != null ? networkMode : 'online') === 'online' ? onlineManager.isOnline() : true;
5
+ }
6
+ class CancelledError {
7
+ constructor(options) {
8
+ this.revert = options == null ? void 0 : options.revert;
9
+ this.silent = options == null ? void 0 : options.silent;
10
+ }
11
+
12
+ }
13
+ function isCancelledError(value) {
14
+ return value instanceof CancelledError;
15
+ }
16
+
17
+ export { CancelledError, canFetch, isCancelledError };
@@ -0,0 +1,31 @@
1
+ class Subscribable {
2
+ constructor() {
3
+ this.listeners = new Set();
4
+ this.subscribe = this.subscribe.bind(this);
5
+ }
6
+
7
+ subscribe(listener) {
8
+ const identity = {
9
+ listener
10
+ };
11
+ this.listeners.add(identity);
12
+ this.onSubscribe();
13
+ return () => {
14
+ this.listeners.delete(identity);
15
+ this.onUnsubscribe();
16
+ };
17
+ }
18
+
19
+ hasListeners() {
20
+ return this.listeners.size > 0;
21
+ }
22
+
23
+ onSubscribe() {// Do nothing
24
+ }
25
+
26
+ onUnsubscribe() {// Do nothing
27
+ }
28
+
29
+ }
30
+
31
+ export { Subscribable };