@qiaopeng/tanstack-query-plus 0.5.9 → 0.5.10

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 (250) hide show
  1. package/README.md +86 -55
  2. package/dist/{types/base.d.ts → base-CHnwqfyz.d.cts} +12 -14
  3. package/dist/base-CHnwqfyz.d.ts +52 -0
  4. package/dist/chunk-52ZO6Y67.cjs +1121 -0
  5. package/dist/chunk-52ZO6Y67.cjs.map +1 -0
  6. package/dist/chunk-5J6OXSLW.cjs +36 -0
  7. package/dist/chunk-5J6OXSLW.cjs.map +1 -0
  8. package/dist/chunk-6MAYHLTE.cjs +310 -0
  9. package/dist/chunk-6MAYHLTE.cjs.map +1 -0
  10. package/dist/chunk-ADS2QTMP.js +144 -0
  11. package/dist/chunk-ADS2QTMP.js.map +1 -0
  12. package/dist/chunk-APXNNHBD.cjs +374 -0
  13. package/dist/chunk-APXNNHBD.cjs.map +1 -0
  14. package/dist/chunk-AXMWOGNX.js +134 -0
  15. package/dist/chunk-AXMWOGNX.js.map +1 -0
  16. package/dist/chunk-B4KO3K3E.cjs +521 -0
  17. package/dist/chunk-B4KO3K3E.cjs.map +1 -0
  18. package/dist/chunk-BK3OTIBD.cjs +15 -0
  19. package/dist/chunk-BK3OTIBD.cjs.map +1 -0
  20. package/dist/chunk-BYAOQALW.js +13 -0
  21. package/dist/chunk-BYAOQALW.js.map +1 -0
  22. package/dist/chunk-CRTVS7VI.cjs +162 -0
  23. package/dist/chunk-CRTVS7VI.cjs.map +1 -0
  24. package/dist/chunk-EXITP7QO.js +288 -0
  25. package/dist/chunk-EXITP7QO.js.map +1 -0
  26. package/dist/chunk-GMO3PRZZ.js +565 -0
  27. package/dist/chunk-GMO3PRZZ.js.map +1 -0
  28. package/dist/chunk-HRO2DWKZ.js +12 -0
  29. package/dist/chunk-HRO2DWKZ.js.map +1 -0
  30. package/dist/chunk-JHDKUQSB.js +1069 -0
  31. package/dist/chunk-JHDKUQSB.js.map +1 -0
  32. package/dist/chunk-JN2Y6RSY.js +23 -0
  33. package/dist/chunk-JN2Y6RSY.js.map +1 -0
  34. package/dist/chunk-JRJSKRZW.cjs +29 -0
  35. package/dist/chunk-JRJSKRZW.cjs.map +1 -0
  36. package/dist/chunk-KC62H4VJ.js +123 -0
  37. package/dist/chunk-KC62H4VJ.js.map +1 -0
  38. package/dist/chunk-LHEHSLD5.js +31 -0
  39. package/dist/chunk-LHEHSLD5.js.map +1 -0
  40. package/dist/chunk-N4264P7N.cjs +156 -0
  41. package/dist/chunk-N4264P7N.cjs.map +1 -0
  42. package/dist/chunk-NF5QYPYC.cjs +133 -0
  43. package/dist/chunk-NF5QYPYC.cjs.map +1 -0
  44. package/dist/chunk-OFLCHKKE.cjs +28 -0
  45. package/dist/chunk-OFLCHKKE.cjs.map +1 -0
  46. package/dist/chunk-PCNSWVA5.cjs +602 -0
  47. package/dist/chunk-PCNSWVA5.cjs.map +1 -0
  48. package/dist/chunk-STOMAA2X.js +85 -0
  49. package/dist/chunk-STOMAA2X.js.map +1 -0
  50. package/dist/chunk-UVF5S6LX.cjs +15 -0
  51. package/dist/chunk-UVF5S6LX.cjs.map +1 -0
  52. package/dist/chunk-WEIXCDCA.cjs +90 -0
  53. package/dist/chunk-WEIXCDCA.cjs.map +1 -0
  54. package/dist/chunk-X3ZTSLBQ.js +355 -0
  55. package/dist/chunk-X3ZTSLBQ.js.map +1 -0
  56. package/dist/chunk-YEV73J4J.js +504 -0
  57. package/dist/chunk-YEV73J4J.js.map +1 -0
  58. package/dist/chunk-YW5PNTRU.cjs +14 -0
  59. package/dist/chunk-YW5PNTRU.cjs.map +1 -0
  60. package/dist/chunk-ZNXSWUIS.js +12 -0
  61. package/dist/chunk-ZNXSWUIS.js.map +1 -0
  62. package/dist/chunk-ZUEMBY4W.js +21 -0
  63. package/dist/chunk-ZUEMBY4W.js.map +1 -0
  64. package/dist/components/index.cjs +60 -0
  65. package/dist/components/index.cjs.map +1 -0
  66. package/dist/components/index.d.cts +43 -0
  67. package/dist/components/index.d.ts +43 -4
  68. package/dist/components/index.js +3 -4
  69. package/dist/components/index.js.map +1 -0
  70. package/dist/core/devtools.cjs +25 -0
  71. package/dist/core/devtools.cjs.map +1 -0
  72. package/dist/core/devtools.d.cts +17 -0
  73. package/dist/core/devtools.d.ts +9 -7
  74. package/dist/core/devtools.js +4 -16
  75. package/dist/core/devtools.js.map +1 -0
  76. package/dist/core/index.cjs +220 -0
  77. package/dist/core/index.cjs.map +1 -0
  78. package/dist/core/index.d.cts +196 -0
  79. package/dist/core/index.d.ts +196 -9
  80. package/dist/core/index.js +7 -8
  81. package/dist/core/index.js.map +1 -0
  82. package/dist/features/index.cjs +76 -0
  83. package/dist/features/index.cjs.map +1 -0
  84. package/dist/features/index.d.cts +86 -0
  85. package/dist/features/index.d.ts +86 -4
  86. package/dist/features/index.js +7 -3
  87. package/dist/features/index.js.map +1 -0
  88. package/dist/hooks/index.cjs +209 -0
  89. package/dist/hooks/index.cjs.map +1 -0
  90. package/dist/hooks/index.d.cts +377 -0
  91. package/dist/hooks/index.d.ts +377 -10
  92. package/dist/hooks/index.js +8 -9
  93. package/dist/hooks/index.js.map +1 -0
  94. package/dist/hooks/useInViewPrefetch.cjs +33 -0
  95. package/dist/hooks/useInViewPrefetch.cjs.map +1 -0
  96. package/dist/hooks/useInViewPrefetch.d.cts +12 -0
  97. package/dist/hooks/useInViewPrefetch.d.ts +6 -4
  98. package/dist/hooks/useInViewPrefetch.js +30 -20
  99. package/dist/hooks/useInViewPrefetch.js.map +1 -0
  100. package/dist/index.cjs +811 -0
  101. package/dist/index.cjs.map +1 -0
  102. package/dist/index.d.cts +36 -0
  103. package/dist/index.d.ts +36 -8
  104. package/dist/index.js +89 -7
  105. package/dist/index.js.map +1 -0
  106. package/dist/{types/offline.d.ts → offline-DVPtgoAS.d.ts} +15 -13
  107. package/dist/offline-xxeA_-6V.d.cts +99 -0
  108. package/dist/persistence-MRtkmhqq.d.cts +216 -0
  109. package/dist/persistence-tIrEb0pR.d.ts +216 -0
  110. package/dist/react-query/index.cjs +52 -0
  111. package/dist/react-query/index.cjs.map +1 -0
  112. package/dist/react-query/index.d.cts +1 -0
  113. package/dist/react-query/index.d.ts +1 -3
  114. package/dist/react-query/index.js +3 -1
  115. package/dist/react-query/index.js.map +1 -0
  116. package/dist/types/index.cjs +43 -0
  117. package/dist/types/index.cjs.map +1 -0
  118. package/dist/types/index.d.cts +157 -0
  119. package/dist/types/index.d.ts +116 -12
  120. package/dist/types/index.js +6 -8
  121. package/dist/types/index.js.map +1 -0
  122. package/dist/utils/index.cjs +234 -0
  123. package/dist/utils/index.cjs.map +1 -0
  124. package/dist/utils/index.d.cts +272 -0
  125. package/dist/utils/index.d.ts +272 -10
  126. package/dist/utils/index.js +9 -9
  127. package/dist/utils/index.js.map +1 -0
  128. package/package.json +13 -3
  129. package/dist/PersistQueryClientProvider.d.ts +0 -22
  130. package/dist/PersistQueryClientProvider.d.ts.map +0 -1
  131. package/dist/PersistQueryClientProvider.js +0 -57
  132. package/dist/components/LoadingFallback.d.ts +0 -16
  133. package/dist/components/LoadingFallback.d.ts.map +0 -1
  134. package/dist/components/LoadingFallback.js +0 -27
  135. package/dist/components/QueryErrorBoundary.d.ts +0 -12
  136. package/dist/components/QueryErrorBoundary.d.ts.map +0 -1
  137. package/dist/components/QueryErrorBoundary.js +0 -9
  138. package/dist/components/SuspenseWrapper.d.ts +0 -14
  139. package/dist/components/SuspenseWrapper.d.ts.map +0 -1
  140. package/dist/components/SuspenseWrapper.js +0 -9
  141. package/dist/components/index.d.ts.map +0 -1
  142. package/dist/components/internal/ErrorBoundary.d.ts +0 -27
  143. package/dist/components/internal/ErrorBoundary.d.ts.map +0 -1
  144. package/dist/components/internal/ErrorBoundary.js +0 -37
  145. package/dist/core/config.d.ts +0 -80
  146. package/dist/core/config.d.ts.map +0 -1
  147. package/dist/core/config.js +0 -327
  148. package/dist/core/devtools.d.ts.map +0 -1
  149. package/dist/core/env.d.ts +0 -4
  150. package/dist/core/env.d.ts.map +0 -1
  151. package/dist/core/env.js +0 -26
  152. package/dist/core/focusManager.d.ts +0 -33
  153. package/dist/core/focusManager.d.ts.map +0 -1
  154. package/dist/core/focusManager.js +0 -122
  155. package/dist/core/index.d.ts.map +0 -1
  156. package/dist/core/keys.d.ts +0 -59
  157. package/dist/core/keys.d.ts.map +0 -1
  158. package/dist/core/keys.js +0 -107
  159. package/dist/core/queryOptions.d.ts +0 -19
  160. package/dist/core/queryOptions.d.ts.map +0 -1
  161. package/dist/core/queryOptions.js +0 -32
  162. package/dist/features/index.d.ts.map +0 -1
  163. package/dist/features/offline.d.ts +0 -49
  164. package/dist/features/offline.d.ts.map +0 -1
  165. package/dist/features/offline.js +0 -300
  166. package/dist/features/persistence.d.ts +0 -36
  167. package/dist/features/persistence.d.ts.map +0 -1
  168. package/dist/features/persistence.js +0 -187
  169. package/dist/hooks/batchQueries.d.ts +0 -129
  170. package/dist/hooks/batchQueries.d.ts.map +0 -1
  171. package/dist/hooks/batchQueries.js +0 -301
  172. package/dist/hooks/index.d.ts.map +0 -1
  173. package/dist/hooks/useDataGuardMutation.d.ts +0 -39
  174. package/dist/hooks/useDataGuardMutation.d.ts.map +0 -1
  175. package/dist/hooks/useDataGuardMutation.js +0 -137
  176. package/dist/hooks/useDataGuardQuery.d.ts +0 -28
  177. package/dist/hooks/useDataGuardQuery.d.ts.map +0 -1
  178. package/dist/hooks/useDataGuardQuery.js +0 -71
  179. package/dist/hooks/useFocusManager.d.ts +0 -41
  180. package/dist/hooks/useFocusManager.d.ts.map +0 -1
  181. package/dist/hooks/useFocusManager.js +0 -109
  182. package/dist/hooks/useInViewPrefetch.d.ts.map +0 -1
  183. package/dist/hooks/useInfiniteQuery.d.ts +0 -33
  184. package/dist/hooks/useInfiniteQuery.d.ts.map +0 -1
  185. package/dist/hooks/useInfiniteQuery.js +0 -61
  186. package/dist/hooks/useMutation.d.ts +0 -25
  187. package/dist/hooks/useMutation.d.ts.map +0 -1
  188. package/dist/hooks/useMutation.js +0 -180
  189. package/dist/hooks/usePrefetch.d.ts +0 -54
  190. package/dist/hooks/usePrefetch.d.ts.map +0 -1
  191. package/dist/hooks/usePrefetch.js +0 -229
  192. package/dist/hooks/useQuery.d.ts +0 -21
  193. package/dist/hooks/useQuery.d.ts.map +0 -1
  194. package/dist/hooks/useQuery.js +0 -46
  195. package/dist/hooks/useSuspenseQuery.d.ts +0 -11
  196. package/dist/hooks/useSuspenseQuery.d.ts.map +0 -1
  197. package/dist/hooks/useSuspenseQuery.js +0 -19
  198. package/dist/index.d.ts.map +0 -1
  199. package/dist/react-query/index.d.ts.map +0 -1
  200. package/dist/types/base.d.ts.map +0 -1
  201. package/dist/types/base.js +0 -26
  202. package/dist/types/dataGuard.d.ts +0 -69
  203. package/dist/types/dataGuard.d.ts.map +0 -1
  204. package/dist/types/dataGuard.js +0 -10
  205. package/dist/types/index.d.ts.map +0 -1
  206. package/dist/types/infinite.d.ts +0 -39
  207. package/dist/types/infinite.d.ts.map +0 -1
  208. package/dist/types/infinite.js +0 -1
  209. package/dist/types/offline.d.ts.map +0 -1
  210. package/dist/types/offline.js +0 -8
  211. package/dist/types/optimistic.d.ts +0 -126
  212. package/dist/types/optimistic.d.ts.map +0 -1
  213. package/dist/types/optimistic.js +0 -7
  214. package/dist/types/persistence.d.ts +0 -9
  215. package/dist/types/persistence.d.ts.map +0 -1
  216. package/dist/types/persistence.js +0 -1
  217. package/dist/types/selectors.d.ts +0 -11
  218. package/dist/types/selectors.d.ts.map +0 -1
  219. package/dist/types/selectors.js +0 -1
  220. package/dist/types/suspense.d.ts +0 -67
  221. package/dist/types/suspense.d.ts.map +0 -1
  222. package/dist/types/suspense.js +0 -1
  223. package/dist/utils/dataGuard.d.ts +0 -37
  224. package/dist/utils/dataGuard.d.ts.map +0 -1
  225. package/dist/utils/dataGuard.js +0 -251
  226. package/dist/utils/fieldMapper.d.ts +0 -9
  227. package/dist/utils/fieldMapper.d.ts.map +0 -1
  228. package/dist/utils/fieldMapper.js +0 -27
  229. package/dist/utils/index.d.ts.map +0 -1
  230. package/dist/utils/network.d.ts +0 -9
  231. package/dist/utils/network.d.ts.map +0 -1
  232. package/dist/utils/network.js +0 -43
  233. package/dist/utils/optimisticUtils.d.ts +0 -45
  234. package/dist/utils/optimisticUtils.d.ts.map +0 -1
  235. package/dist/utils/optimisticUtils.js +0 -116
  236. package/dist/utils/placeholderData.d.ts +0 -3
  237. package/dist/utils/placeholderData.d.ts.map +0 -1
  238. package/dist/utils/placeholderData.js +0 -28
  239. package/dist/utils/prefetchManager.d.ts +0 -111
  240. package/dist/utils/prefetchManager.d.ts.map +0 -1
  241. package/dist/utils/prefetchManager.js +0 -246
  242. package/dist/utils/queryKey.d.ts +0 -26
  243. package/dist/utils/queryKey.d.ts.map +0 -1
  244. package/dist/utils/queryKey.js +0 -89
  245. package/dist/utils/selectors.d.ts +0 -30
  246. package/dist/utils/selectors.d.ts.map +0 -1
  247. package/dist/utils/selectors.js +0 -18
  248. package/dist/utils/storage.d.ts +0 -7
  249. package/dist/utils/storage.d.ts.map +0 -1
  250. package/dist/utils/storage.js +0 -84
@@ -0,0 +1,602 @@
1
+ 'use strict';
2
+
3
+ var chunkAPXNNHBD_cjs = require('./chunk-APXNNHBD.cjs');
4
+ var chunk6MAYHLTE_cjs = require('./chunk-6MAYHLTE.cjs');
5
+ var reactQuery = require('@tanstack/react-query');
6
+
7
+ // src/utils/fieldMapper.ts
8
+ function createFieldEnricher(queryKey, mappings) {
9
+ return (data, queryClient) => {
10
+ const config = queryClient.getQueryData(queryKey);
11
+ if (!config) return data;
12
+ const result = { ...data };
13
+ Object.entries(mappings).forEach(([idField, { nameField, configKey }]) => {
14
+ const idValue = data[idField];
15
+ if (idValue == null) return;
16
+ const options = config[configKey];
17
+ if (!options?.length) return;
18
+ const optionMap = new Map(options.map((item) => [String(item.value), item.label]));
19
+ const label = optionMap.get(String(idValue));
20
+ if (label) {
21
+ result[nameField] = label;
22
+ }
23
+ });
24
+ return result;
25
+ };
26
+ }
27
+ function createTempId(prefix = "temp") {
28
+ return `${prefix}-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`;
29
+ }
30
+ function createOptimisticBase(customFields) {
31
+ const now = (/* @__PURE__ */ new Date()).toISOString();
32
+ return { createTime: now, updateTime: now, createUser: "", updateUser: "", deleteStatus: 0, ...customFields };
33
+ }
34
+
35
+ // src/utils/optimisticUtils.ts
36
+ function idsAreEqual(a, b) {
37
+ if (a === b) return true;
38
+ if (a === void 0 || a === null || b === void 0 || b === null) return false;
39
+ return String(a) === String(b);
40
+ }
41
+ var listUpdater = {
42
+ add: (items, newItem) => {
43
+ const currentItems = items || [];
44
+ const existingIndex = currentItems.findIndex((item) => idsAreEqual(item.id, newItem.id));
45
+ if (existingIndex >= 0) {
46
+ const updatedItems = [...currentItems];
47
+ updatedItems[existingIndex] = newItem;
48
+ return updatedItems;
49
+ }
50
+ return [newItem, ...currentItems];
51
+ },
52
+ update: (items, updatedItem) => {
53
+ const currentItems = items || [];
54
+ return currentItems.map((item) => idsAreEqual(item.id, updatedItem.id) ? { ...item, ...updatedItem } : item);
55
+ },
56
+ remove: (items, itemId) => {
57
+ const currentItems = items || [];
58
+ return currentItems.filter((item) => !idsAreEqual(item.id, itemId));
59
+ }
60
+ };
61
+ function createAddItemConfig(queryKey, options) {
62
+ return { queryKey, updater: (oldData, newItem) => {
63
+ const currentItems = oldData || [];
64
+ if (options?.addToTop !== false) {
65
+ return [newItem, ...currentItems];
66
+ }
67
+ return [...currentItems, newItem];
68
+ }, rollback: options?.onRollback ? (_previousData, error) => {
69
+ options.onRollback(error);
70
+ } : void 0, enabled: true };
71
+ }
72
+ function createUpdateItemConfig(queryKey, options) {
73
+ return { queryKey, updater: (oldData, updatedItem) => {
74
+ return listUpdater.update(oldData, updatedItem);
75
+ }, rollback: options?.onRollback ? (_previousData, error) => {
76
+ options.onRollback(error);
77
+ } : void 0, enabled: true };
78
+ }
79
+ function createRemoveItemConfig(queryKey, options) {
80
+ return { queryKey, updater: (oldData, itemId) => {
81
+ return listUpdater.remove(oldData, itemId);
82
+ }, rollback: options?.onRollback ? (_previousData, error) => {
83
+ options.onRollback(error);
84
+ } : void 0, enabled: true };
85
+ }
86
+ function createListOperationConfig(config) {
87
+ return {
88
+ queryKey: config.queryKey,
89
+ updater: (oldData, variables) => {
90
+ switch (config.operation) {
91
+ case "add" /* ADD */:
92
+ return listUpdater.add(oldData, variables);
93
+ case "update" /* UPDATE */:
94
+ return listUpdater.update(oldData, variables);
95
+ case "remove" /* REMOVE */:
96
+ return listUpdater.remove(oldData, variables);
97
+ default:
98
+ return oldData || [];
99
+ }
100
+ },
101
+ rollback: config.onRollback ? (previousData, error) => {
102
+ const opType = config.operation === "add" /* ADD */ ? "create" : config.operation === "remove" /* REMOVE */ ? "delete" : "update";
103
+ config.onRollback(error, { previousData, timestamp: Date.now(), operationType: opType });
104
+ } : void 0,
105
+ enabled: true
106
+ };
107
+ }
108
+ function batchUpdateItems(items, updates) {
109
+ let currentItems = items || [];
110
+ updates.forEach((update) => {
111
+ currentItems = listUpdater.update(currentItems, update);
112
+ });
113
+ return currentItems;
114
+ }
115
+ function batchRemoveItems(items, itemIds) {
116
+ let currentItems = items || [];
117
+ itemIds.forEach((itemId) => {
118
+ currentItems = listUpdater.remove(currentItems, itemId);
119
+ });
120
+ return currentItems;
121
+ }
122
+ function reorderItems(items, fromIndex, toIndex) {
123
+ const currentItems = [...items || []];
124
+ if (fromIndex < 0 || fromIndex >= currentItems.length || toIndex < 0 || toIndex >= currentItems.length) {
125
+ return currentItems;
126
+ }
127
+ const [movedItem] = currentItems.splice(fromIndex, 1);
128
+ currentItems.splice(toIndex, 0, movedItem);
129
+ return currentItems;
130
+ }
131
+ function conditionalUpdateItems(items, predicate, updater) {
132
+ const currentItems = items || [];
133
+ return currentItems.map((item) => {
134
+ if (predicate(item)) {
135
+ return { ...item, ...updater(item) };
136
+ }
137
+ return item;
138
+ });
139
+ }
140
+ function stableListPlaceholder(previousData) {
141
+ if (previousData === void 0 || previousData === null) return previousData;
142
+ if (Array.isArray(previousData)) {
143
+ return [];
144
+ }
145
+ if (typeof previousData === "object") {
146
+ const obj = { ...previousData };
147
+ if (Array.isArray(obj.Rows)) {
148
+ obj.Rows = [];
149
+ if (typeof obj.Total === "number") obj.Total = obj.Total;
150
+ return obj;
151
+ }
152
+ if (Array.isArray(obj.items)) {
153
+ obj.items = [];
154
+ if (typeof obj.total === "number") obj.total = obj.total;
155
+ return obj;
156
+ }
157
+ if (Array.isArray(obj.data)) {
158
+ obj.data = [];
159
+ return obj;
160
+ }
161
+ }
162
+ return previousData;
163
+ }
164
+
165
+ // src/utils/prefetchManager.ts
166
+ var SmartPrefetchManager = class {
167
+ constructor(queryClient) {
168
+ this.prefetchQueue = /* @__PURE__ */ new Map();
169
+ this.prefetchHistory = /* @__PURE__ */ new Set();
170
+ this.networkSpeed = "fast";
171
+ this.isProcessing = false;
172
+ this.maxQueueSize = 10;
173
+ this.maxHistorySize = 100;
174
+ this.totalPrefetches = 0;
175
+ this.successfulPrefetches = 0;
176
+ this.failedPrefetches = 0;
177
+ this.skippedPrefetches = 0;
178
+ this.prefetchTimes = [];
179
+ this.maxPrefetchTimesSize = 50;
180
+ this.interactionHistory = [];
181
+ this.maxInteractionHistorySize = 100;
182
+ this.queryAccessCounts = /* @__PURE__ */ new Map();
183
+ this.querySequences = [];
184
+ this.maxSequenceSize = 50;
185
+ this.queryClient = queryClient;
186
+ this.initNetworkMonitoring();
187
+ }
188
+ initNetworkMonitoring() {
189
+ const networkInfo = chunkAPXNNHBD_cjs.getNetworkInfo();
190
+ if (!networkInfo) {
191
+ return;
192
+ }
193
+ this.updateNetworkSpeed();
194
+ if (typeof navigator !== "undefined" && "connection" in navigator) {
195
+ const navWithConnection = navigator;
196
+ const connection = navWithConnection.connection || navWithConnection.mozConnection || navWithConnection.webkitConnection;
197
+ const handleNetworkChange = () => {
198
+ this.updateNetworkSpeed();
199
+ };
200
+ connection?.addEventListener?.("change", handleNetworkChange);
201
+ this.networkCleanup = () => {
202
+ connection?.removeEventListener("change", handleNetworkChange);
203
+ };
204
+ }
205
+ }
206
+ updateNetworkSpeed() {
207
+ this.networkSpeed = chunkAPXNNHBD_cjs.getNetworkSpeed();
208
+ }
209
+ getNetworkSpeed() {
210
+ return this.networkSpeed;
211
+ }
212
+ isSlowNetwork() {
213
+ return this.networkSpeed === "slow" || this.networkSpeed === "unknown";
214
+ }
215
+ shouldPrefetch(queryKey, config = {}) {
216
+ const key = this.getQueryKeyString(queryKey);
217
+ if (this.prefetchQueue.has(key)) return false;
218
+ if (this.prefetchHistory.has(key)) return false;
219
+ const cachedData = this.queryClient.getQueryData(queryKey);
220
+ if (cachedData) return false;
221
+ if (this.isSlowNetwork() && !config.allowSlowNetwork) return false;
222
+ if (this.prefetchQueue.size >= this.maxQueueSize) return false;
223
+ return true;
224
+ }
225
+ addPrefetchTask(queryKey, queryFn, config = {}) {
226
+ if (!this.shouldPrefetch(queryKey, config)) {
227
+ this.skippedPrefetches++;
228
+ return false;
229
+ }
230
+ const key = this.getQueryKeyString(queryKey);
231
+ const task = { id: `${key}-${Date.now()}`, queryKey, queryFn, config: { priority: "medium", delay: 0, staleTime: chunk6MAYHLTE_cjs.DEFAULT_STALE_TIME, allowSlowNetwork: false, ...config }, timestamp: Date.now() };
232
+ this.prefetchQueue.set(key, task);
233
+ this.processQueue();
234
+ return true;
235
+ }
236
+ async processQueue() {
237
+ if (this.isProcessing || this.prefetchQueue.size === 0) {
238
+ return;
239
+ }
240
+ this.isProcessing = true;
241
+ try {
242
+ const sortedTasks = this.getSortedTasks();
243
+ for (const task of sortedTasks) {
244
+ const key = this.getQueryKeyString(task.queryKey);
245
+ const startTime = Date.now();
246
+ if (task.config.delay && task.config.delay > 0) {
247
+ await this.delay(task.config.delay);
248
+ }
249
+ try {
250
+ this.totalPrefetches++;
251
+ await this.queryClient.prefetchQuery({ queryKey: task.queryKey, queryFn: task.queryFn, staleTime: task.config.staleTime });
252
+ this.successfulPrefetches++;
253
+ const duration = Date.now() - startTime;
254
+ this.recordPrefetchTime(duration);
255
+ this.addToHistory(key);
256
+ } catch {
257
+ this.failedPrefetches++;
258
+ }
259
+ this.prefetchQueue.delete(key);
260
+ }
261
+ } finally {
262
+ this.isProcessing = false;
263
+ }
264
+ }
265
+ getSortedTasks() {
266
+ const tasks = Array.from(this.prefetchQueue.values());
267
+ const priorityOrder = { high: 0, medium: 1, low: 2 };
268
+ return tasks.sort((a, b) => {
269
+ const priorityA = priorityOrder[a.config.priority || "medium"];
270
+ const priorityB = priorityOrder[b.config.priority || "medium"];
271
+ if (priorityA !== priorityB) return priorityA - priorityB;
272
+ if (a.predictionScore !== void 0 && b.predictionScore !== void 0) {
273
+ if (a.predictionScore !== b.predictionScore) {
274
+ return b.predictionScore - a.predictionScore;
275
+ }
276
+ }
277
+ return a.timestamp - b.timestamp;
278
+ });
279
+ }
280
+ async prefetchNow(queryKey, queryFn, config = {}) {
281
+ const key = this.getQueryKeyString(queryKey);
282
+ const startTime = Date.now();
283
+ try {
284
+ this.totalPrefetches++;
285
+ await this.queryClient.prefetchQuery({ queryKey, queryFn, staleTime: config.staleTime || chunk6MAYHLTE_cjs.DEFAULT_STALE_TIME });
286
+ this.successfulPrefetches++;
287
+ const duration = Date.now() - startTime;
288
+ this.recordPrefetchTime(duration);
289
+ this.addToHistory(key);
290
+ } catch (error) {
291
+ this.failedPrefetches++;
292
+ throw error;
293
+ }
294
+ }
295
+ addToHistory(key) {
296
+ this.prefetchHistory.add(key);
297
+ if (this.prefetchHistory.size > this.maxHistorySize) {
298
+ const firstKey = this.prefetchHistory.values().next().value;
299
+ if (firstKey) {
300
+ this.prefetchHistory.delete(firstKey);
301
+ }
302
+ }
303
+ }
304
+ clearHistory() {
305
+ this.prefetchHistory.clear();
306
+ }
307
+ clearQueue() {
308
+ this.prefetchQueue.clear();
309
+ }
310
+ reset() {
311
+ this.clearQueue();
312
+ this.clearHistory();
313
+ this.clearInteractionHistory();
314
+ this.resetStats();
315
+ }
316
+ destroy() {
317
+ if (this.networkCleanup) {
318
+ this.networkCleanup();
319
+ this.networkCleanup = void 0;
320
+ }
321
+ this.reset();
322
+ }
323
+ recordInteraction(queryKey, type = "view") {
324
+ const interaction = { queryKey, timestamp: Date.now(), type };
325
+ this.interactionHistory.push(interaction);
326
+ if (this.interactionHistory.length > this.maxInteractionHistorySize) {
327
+ this.interactionHistory.shift();
328
+ }
329
+ const key = this.getQueryKeyString(queryKey);
330
+ this.queryAccessCounts.set(key, (this.queryAccessCounts.get(key) || 0) + 1);
331
+ if (this.interactionHistory.length >= 2) {
332
+ const prevInteraction = this.interactionHistory[this.interactionHistory.length - 2];
333
+ const prevKey = this.getQueryKeyString(prevInteraction.queryKey);
334
+ const existingSequence = this.querySequences.find((s) => s.from === prevKey && s.to === key);
335
+ if (existingSequence) {
336
+ existingSequence.count++;
337
+ } else {
338
+ this.querySequences.push({ from: prevKey, to: key, count: 1 });
339
+ if (this.querySequences.length > this.maxSequenceSize) {
340
+ this.querySequences.shift();
341
+ }
342
+ }
343
+ }
344
+ }
345
+ getPredictions(currentQueryKey, limit = 5) {
346
+ const predictions = [];
347
+ if (currentQueryKey) {
348
+ const currentKey = this.getQueryKeyString(currentQueryKey);
349
+ const sequences = this.querySequences.filter((s) => s.from === currentKey).sort((a, b) => b.count - a.count).slice(0, limit);
350
+ sequences.forEach((seq) => {
351
+ try {
352
+ const queryKey = JSON.parse(seq.to);
353
+ predictions.push({ queryKey, score: Math.min(seq.count / 10, 1), reason: `Frequently accessed after current query (${seq.count} times)` });
354
+ } catch {
355
+ }
356
+ });
357
+ }
358
+ const frequentQueries = Array.from(this.queryAccessCounts.entries()).sort((a, b) => b[1] - a[1]).slice(0, limit);
359
+ frequentQueries.forEach(([key, count]) => {
360
+ try {
361
+ const queryKey = JSON.parse(key);
362
+ if (!predictions.some((p) => this.getQueryKeyString(p.queryKey) === key)) {
363
+ predictions.push({ queryKey, score: Math.min(count / 20, 1), reason: `Frequently accessed (${count} times)` });
364
+ }
365
+ } catch {
366
+ }
367
+ });
368
+ const recentInteractions = this.interactionHistory.slice(-10).reverse();
369
+ recentInteractions.forEach((interaction, index) => {
370
+ const key = this.getQueryKeyString(interaction.queryKey);
371
+ if (!predictions.some((p) => this.getQueryKeyString(p.queryKey) === key)) {
372
+ predictions.push({ queryKey: interaction.queryKey, score: Math.max(0.3 - index * 0.03, 0.1), reason: `Recently accessed (${index + 1} queries ago)` });
373
+ }
374
+ });
375
+ return predictions.sort((a, b) => b.score - a.score).slice(0, limit);
376
+ }
377
+ async prefetchPredicted(currentQueryKey, queryFnMap, config = {}) {
378
+ const predictions = this.getPredictions(currentQueryKey);
379
+ for (const prediction of predictions) {
380
+ const key = this.getQueryKeyString(prediction.queryKey);
381
+ const queryFn = queryFnMap.get(key);
382
+ if (queryFn) {
383
+ const taskConfig = { ...config, priority: prediction.score > 0.7 ? "high" : prediction.score > 0.4 ? "medium" : "low" };
384
+ const added = this.addPrefetchTask(prediction.queryKey, queryFn, taskConfig);
385
+ if (added) {
386
+ const task = this.prefetchQueue.get(key);
387
+ if (task) {
388
+ task.predictionScore = prediction.score;
389
+ }
390
+ }
391
+ }
392
+ }
393
+ }
394
+ clearInteractionHistory() {
395
+ this.interactionHistory = [];
396
+ this.queryAccessCounts.clear();
397
+ this.querySequences = [];
398
+ }
399
+ recordPrefetchTime(duration) {
400
+ this.prefetchTimes.push(duration);
401
+ if (this.prefetchTimes.length > this.maxPrefetchTimesSize) {
402
+ this.prefetchTimes.shift();
403
+ }
404
+ }
405
+ getAveragePrefetchTime() {
406
+ if (this.prefetchTimes.length === 0) {
407
+ return 0;
408
+ }
409
+ const sum = this.prefetchTimes.reduce((acc, time) => acc + time, 0);
410
+ return Math.round(sum / this.prefetchTimes.length);
411
+ }
412
+ getStats() {
413
+ return { queueSize: this.prefetchQueue.size, historySize: this.prefetchHistory.size, networkSpeed: this.networkSpeed, isProcessing: this.isProcessing, totalPrefetches: this.totalPrefetches, successfulPrefetches: this.successfulPrefetches, failedPrefetches: this.failedPrefetches, averagePrefetchTime: this.getAveragePrefetchTime(), skippedPrefetches: this.skippedPrefetches };
414
+ }
415
+ getPerformanceReport() {
416
+ const stats = this.getStats();
417
+ const successRate = stats.totalPrefetches > 0 ? Math.round(stats.successfulPrefetches / stats.totalPrefetches * 100) : 0;
418
+ const queueTasks = Array.from(this.prefetchQueue.values());
419
+ const byPriority = { high: queueTasks.filter((t) => t.config.priority === "high").length, medium: queueTasks.filter((t) => t.config.priority === "medium").length, low: queueTasks.filter((t) => t.config.priority === "low").length };
420
+ return { stats, successRate, predictions: { totalInteractions: this.interactionHistory.length, uniqueQueries: this.queryAccessCounts.size, sequencePatterns: this.querySequences.length }, queue: { size: this.prefetchQueue.size, byPriority } };
421
+ }
422
+ resetStats() {
423
+ this.totalPrefetches = 0;
424
+ this.successfulPrefetches = 0;
425
+ this.failedPrefetches = 0;
426
+ this.skippedPrefetches = 0;
427
+ this.prefetchTimes = [];
428
+ }
429
+ getQueryKeyString(queryKey) {
430
+ return JSON.stringify(queryKey);
431
+ }
432
+ delay(ms) {
433
+ return new Promise((resolve) => setTimeout(resolve, ms));
434
+ }
435
+ setMaxQueueSize(size) {
436
+ this.maxQueueSize = size;
437
+ }
438
+ setMaxHistorySize(size) {
439
+ this.maxHistorySize = size;
440
+ }
441
+ getQueuedTasks() {
442
+ return Array.from(this.prefetchQueue.values());
443
+ }
444
+ removeTask(queryKey) {
445
+ const key = this.getQueryKeyString(queryKey);
446
+ return this.prefetchQueue.delete(key);
447
+ }
448
+ hasTask(queryKey) {
449
+ const key = this.getQueryKeyString(queryKey);
450
+ return this.prefetchQueue.has(key);
451
+ }
452
+ updateTaskPriority(queryKey, priority) {
453
+ const key = this.getQueryKeyString(queryKey);
454
+ const task = this.prefetchQueue.get(key);
455
+ if (task) {
456
+ task.config.priority = priority;
457
+ return true;
458
+ }
459
+ return false;
460
+ }
461
+ pauseQueue() {
462
+ this.isProcessing = true;
463
+ }
464
+ resumeQueue() {
465
+ this.isProcessing = false;
466
+ this.processQueue();
467
+ }
468
+ };
469
+ var prefetchManagerInstance = null;
470
+ function getPrefetchManager(queryClient) {
471
+ if (!prefetchManagerInstance) {
472
+ prefetchManagerInstance = new SmartPrefetchManager(queryClient);
473
+ }
474
+ return prefetchManagerInstance;
475
+ }
476
+ function resetPrefetchManager() {
477
+ prefetchManagerInstance = null;
478
+ }
479
+
480
+ // src/utils/selectors.ts
481
+ function selectById(id) {
482
+ return (data) => {
483
+ return data?.find((item) => item.id === id);
484
+ };
485
+ }
486
+ function selectByIds(ids) {
487
+ return (data) => {
488
+ if (!data) return [];
489
+ return data.filter((item) => ids.includes(item.id));
490
+ };
491
+ }
492
+ function selectFirst(data) {
493
+ return data?.[0];
494
+ }
495
+ function selectLast(data) {
496
+ if (!data || data.length === 0) return void 0;
497
+ return data[data.length - 1];
498
+ }
499
+ function selectCount(data) {
500
+ return data?.length ?? 0;
501
+ }
502
+ function selectTotal(data) {
503
+ return data?.total ?? 0;
504
+ }
505
+ function selectItems(data) {
506
+ return data?.items ?? [];
507
+ }
508
+ function selectWhere(predicate) {
509
+ return (data) => {
510
+ if (!data) return [];
511
+ return data.filter(predicate);
512
+ };
513
+ }
514
+ function selectMap(mapper) {
515
+ return (data) => {
516
+ if (!data) return [];
517
+ return data.map(mapper);
518
+ };
519
+ }
520
+ function selectField(field) {
521
+ return (data) => {
522
+ return data?.[field];
523
+ };
524
+ }
525
+ function selectFields(fields) {
526
+ return (data) => {
527
+ if (!data) return void 0;
528
+ const result = {};
529
+ fields.forEach((field) => {
530
+ result[field] = data[field];
531
+ });
532
+ return result;
533
+ };
534
+ }
535
+ function compose(selector1, selector2) {
536
+ return (data) => {
537
+ return selector2(selector1(data));
538
+ };
539
+ }
540
+ var selectors = { byId: selectById, byIds: selectByIds, first: selectFirst, last: selectLast, count: selectCount, total: selectTotal, items: selectItems, where: selectWhere, map: selectMap, field: selectField, fields: selectFields, compose };
541
+
542
+ // src/utils/queryClientUtils.ts
543
+ function invalidateQueriesBatch(queryClient, tasks) {
544
+ tasks.forEach((task) => {
545
+ if (Array.isArray(task) || typeof task === "string") {
546
+ queryClient.invalidateQueries({ queryKey: task });
547
+ } else {
548
+ queryClient.invalidateQueries(task);
549
+ }
550
+ });
551
+ }
552
+ function cancelQueriesBatch(queryClient, tasks) {
553
+ tasks.forEach((task) => {
554
+ if (Array.isArray(task) || typeof task === "string") {
555
+ queryClient.cancelQueries({ queryKey: task });
556
+ } else {
557
+ queryClient.cancelQueries(task);
558
+ }
559
+ });
560
+ }
561
+ function setQueryDataBatch(queryClient, tasks) {
562
+ tasks.forEach((task) => queryClient.setQueryData(task.queryKey, task.data));
563
+ }
564
+
565
+ Object.defineProperty(exports, "keepPreviousData", {
566
+ enumerable: true,
567
+ get: function () { return reactQuery.keepPreviousData; }
568
+ });
569
+ exports.SmartPrefetchManager = SmartPrefetchManager;
570
+ exports.batchRemoveItems = batchRemoveItems;
571
+ exports.batchUpdateItems = batchUpdateItems;
572
+ exports.cancelQueriesBatch = cancelQueriesBatch;
573
+ exports.compose = compose;
574
+ exports.conditionalUpdateItems = conditionalUpdateItems;
575
+ exports.createAddItemConfig = createAddItemConfig;
576
+ exports.createFieldEnricher = createFieldEnricher;
577
+ exports.createListOperationConfig = createListOperationConfig;
578
+ exports.createOptimisticBase = createOptimisticBase;
579
+ exports.createRemoveItemConfig = createRemoveItemConfig;
580
+ exports.createTempId = createTempId;
581
+ exports.createUpdateItemConfig = createUpdateItemConfig;
582
+ exports.getPrefetchManager = getPrefetchManager;
583
+ exports.invalidateQueriesBatch = invalidateQueriesBatch;
584
+ exports.listUpdater = listUpdater;
585
+ exports.reorderItems = reorderItems;
586
+ exports.resetPrefetchManager = resetPrefetchManager;
587
+ exports.selectById = selectById;
588
+ exports.selectByIds = selectByIds;
589
+ exports.selectCount = selectCount;
590
+ exports.selectField = selectField;
591
+ exports.selectFields = selectFields;
592
+ exports.selectFirst = selectFirst;
593
+ exports.selectItems = selectItems;
594
+ exports.selectLast = selectLast;
595
+ exports.selectMap = selectMap;
596
+ exports.selectTotal = selectTotal;
597
+ exports.selectWhere = selectWhere;
598
+ exports.selectors = selectors;
599
+ exports.setQueryDataBatch = setQueryDataBatch;
600
+ exports.stableListPlaceholder = stableListPlaceholder;
601
+ //# sourceMappingURL=chunk-PCNSWVA5.cjs.map
602
+ //# sourceMappingURL=chunk-PCNSWVA5.cjs.map