@qiaopeng/tanstack-query-plus 0.5.8 → 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 +155 -95
  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 -47
  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 -321
  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 -44
  162. package/dist/features/index.d.ts.map +0 -1
  163. package/dist/features/offline.d.ts +0 -48
  164. package/dist/features/offline.d.ts.map +0 -1
  165. package/dist/features/offline.js +0 -269
  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 -186
  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 -151
  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 -257
  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 -24
  243. package/dist/utils/queryKey.d.ts.map +0 -1
  244. package/dist/utils/queryKey.js +0 -77
  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
@@ -1,111 +0,0 @@
1
- import type { QueryClient, QueryFunction, QueryKey } from "@tanstack/react-query";
2
- export interface PrefetchConfig {
3
- priority?: "high" | "medium" | "low";
4
- delay?: number;
5
- staleTime?: number;
6
- allowSlowNetwork?: boolean;
7
- }
8
- export interface PrefetchTask {
9
- queryKey: QueryKey;
10
- queryFn: QueryFunction<any>;
11
- config: PrefetchConfig;
12
- timestamp: number;
13
- id: string;
14
- predictionScore?: number;
15
- }
16
- export type NetworkSpeed = "slow" | "medium" | "fast" | "unknown";
17
- export interface PrefetchStats {
18
- queueSize: number;
19
- historySize: number;
20
- networkSpeed: NetworkSpeed;
21
- isProcessing: boolean;
22
- totalPrefetches: number;
23
- successfulPrefetches: number;
24
- failedPrefetches: number;
25
- averagePrefetchTime: number;
26
- skippedPrefetches: number;
27
- }
28
- export interface InteractionRecord {
29
- queryKey: QueryKey;
30
- timestamp: number;
31
- type: "view" | "hover" | "click" | "focus";
32
- }
33
- export interface PredictionResult {
34
- queryKey: QueryKey;
35
- score: number;
36
- reason: string;
37
- }
38
- export declare class SmartPrefetchManager {
39
- private queryClient;
40
- private prefetchQueue;
41
- private prefetchHistory;
42
- private networkSpeed;
43
- private isProcessing;
44
- private maxQueueSize;
45
- private maxHistorySize;
46
- private totalPrefetches;
47
- private successfulPrefetches;
48
- private failedPrefetches;
49
- private skippedPrefetches;
50
- private prefetchTimes;
51
- private maxPrefetchTimesSize;
52
- private interactionHistory;
53
- private maxInteractionHistorySize;
54
- private queryAccessCounts;
55
- private querySequences;
56
- private maxSequenceSize;
57
- private networkCleanup?;
58
- constructor(queryClient: QueryClient);
59
- private initNetworkMonitoring;
60
- private updateNetworkSpeed;
61
- getNetworkSpeed(): NetworkSpeed;
62
- isSlowNetwork(): boolean;
63
- shouldPrefetch(queryKey: QueryKey, config?: PrefetchConfig): boolean;
64
- addPrefetchTask(queryKey: QueryKey, queryFn: QueryFunction<any>, config?: PrefetchConfig): boolean;
65
- private processQueue;
66
- private getSortedTasks;
67
- prefetchNow<TData = unknown>(queryKey: QueryKey, queryFn: QueryFunction<TData>, config?: PrefetchConfig): Promise<void>;
68
- private addToHistory;
69
- clearHistory(): void;
70
- clearQueue(): void;
71
- reset(): void;
72
- destroy(): void;
73
- recordInteraction(queryKey: QueryKey, type?: "view" | "hover" | "click" | "focus"): void;
74
- getPredictions(currentQueryKey?: QueryKey, limit?: number): PredictionResult[];
75
- prefetchPredicted(currentQueryKey: QueryKey | undefined, queryFnMap: Map<string, QueryFunction<any>>, config?: PrefetchConfig): Promise<void>;
76
- clearInteractionHistory(): void;
77
- private recordPrefetchTime;
78
- private getAveragePrefetchTime;
79
- getStats(): PrefetchStats;
80
- getPerformanceReport(): {
81
- stats: PrefetchStats;
82
- successRate: number;
83
- predictions: {
84
- totalInteractions: number;
85
- uniqueQueries: number;
86
- sequencePatterns: number;
87
- };
88
- queue: {
89
- size: number;
90
- byPriority: {
91
- high: number;
92
- medium: number;
93
- low: number;
94
- };
95
- };
96
- };
97
- resetStats(): void;
98
- private getQueryKeyString;
99
- private delay;
100
- setMaxQueueSize(size: number): void;
101
- setMaxHistorySize(size: number): void;
102
- getQueuedTasks(): PrefetchTask[];
103
- removeTask(queryKey: QueryKey): boolean;
104
- hasTask(queryKey: QueryKey): boolean;
105
- updateTaskPriority(queryKey: QueryKey, priority: "high" | "medium" | "low"): boolean;
106
- pauseQueue(): void;
107
- resumeQueue(): void;
108
- }
109
- export declare function getPrefetchManager(queryClient: QueryClient): SmartPrefetchManager;
110
- export declare function resetPrefetchManager(): void;
111
- //# sourceMappingURL=prefetchManager.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"prefetchManager.d.ts","sourceRoot":"","sources":["../../src/utils/prefetchManager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAMlF,MAAM,WAAW,cAAc;IAAG,QAAQ,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,gBAAgB,CAAC,EAAE,OAAO,CAAA;CAAE;AACxI,MAAM,WAAW,YAAY;IAAG,QAAQ,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC;IAAC,MAAM,EAAE,cAAc,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,EAAE,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,MAAM,CAAA;CAAE;AAClK,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,QAAQ,GAAG,MAAM,GAAG,SAAS,CAAC;AAClE,MAAM,WAAW,aAAa;IAAG,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;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C,KAAK,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,UAAU,EAAE;gBAAE,IAAI,EAAE,MAAM,CAAC;gBAAC,MAAM,EAAE,MAAM,CAAC;gBAAC,GAAG,EAAE,MAAM,CAAA;aAAE,CAAA;SAAE,CAAA;KAAE;IAOtP,UAAU,IAAI,IAAI;IACzB,OAAO,CAAC,iBAAiB;IACzB,OAAO,CAAC,KAAK;IACN,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACnC,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI;IACrC,cAAc,IAAI,YAAY,EAAE;IAChC,UAAU,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IACvC,OAAO,CAAC,QAAQ,EAAE,QAAQ,GAAG,OAAO;IACpC,kBAAkB,CAAC,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,OAAO;IACpF,UAAU,IAAI,IAAI;IAClB,WAAW,IAAI,IAAI;CAC3B;AAED,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,oBAAoB,CAAuI;AACzN,wBAAgB,oBAAoB,SAAsC"}
@@ -1,246 +0,0 @@
1
- import { DEFAULT_STALE_TIME } from "../core/config.js";
2
- import { getNetworkInfo, getNetworkSpeed } from "./network.js";
3
- export class SmartPrefetchManager {
4
- constructor(queryClient) {
5
- this.prefetchQueue = new Map();
6
- this.prefetchHistory = new Set();
7
- this.networkSpeed = "fast";
8
- this.isProcessing = false;
9
- this.maxQueueSize = 10;
10
- this.maxHistorySize = 100;
11
- this.totalPrefetches = 0;
12
- this.successfulPrefetches = 0;
13
- this.failedPrefetches = 0;
14
- this.skippedPrefetches = 0;
15
- this.prefetchTimes = [];
16
- this.maxPrefetchTimesSize = 50;
17
- this.interactionHistory = [];
18
- this.maxInteractionHistorySize = 100;
19
- this.queryAccessCounts = new Map();
20
- this.querySequences = [];
21
- this.maxSequenceSize = 50;
22
- this.queryClient = queryClient;
23
- this.initNetworkMonitoring();
24
- }
25
- initNetworkMonitoring() {
26
- const networkInfo = getNetworkInfo();
27
- if (!networkInfo) {
28
- return;
29
- }
30
- this.updateNetworkSpeed();
31
- if (typeof navigator !== "undefined" && "connection" in navigator) {
32
- const navWithConnection = navigator;
33
- const connection = navWithConnection.connection || navWithConnection.mozConnection || navWithConnection.webkitConnection;
34
- const handleNetworkChange = () => { this.updateNetworkSpeed(); };
35
- connection?.addEventListener?.("change", handleNetworkChange);
36
- this.networkCleanup = () => { connection?.removeEventListener("change", handleNetworkChange); };
37
- }
38
- }
39
- updateNetworkSpeed() { this.networkSpeed = getNetworkSpeed(); }
40
- getNetworkSpeed() { return this.networkSpeed; }
41
- isSlowNetwork() { return this.networkSpeed === "slow" || this.networkSpeed === "unknown"; }
42
- shouldPrefetch(queryKey, config = {}) {
43
- const key = this.getQueryKeyString(queryKey);
44
- if (this.prefetchQueue.has(key))
45
- return false;
46
- if (this.prefetchHistory.has(key))
47
- return false;
48
- const cachedData = this.queryClient.getQueryData(queryKey);
49
- if (cachedData)
50
- return false;
51
- if (this.isSlowNetwork() && !config.allowSlowNetwork)
52
- return false;
53
- if (this.prefetchQueue.size >= this.maxQueueSize)
54
- return false;
55
- return true;
56
- }
57
- addPrefetchTask(queryKey, queryFn, config = {}) {
58
- if (!this.shouldPrefetch(queryKey, config)) {
59
- this.skippedPrefetches++;
60
- return false;
61
- }
62
- const key = this.getQueryKeyString(queryKey);
63
- const task = { id: `${key}-${Date.now()}`, queryKey, queryFn, config: { priority: "medium", delay: 0, staleTime: DEFAULT_STALE_TIME, allowSlowNetwork: false, ...config }, timestamp: Date.now() };
64
- this.prefetchQueue.set(key, task);
65
- this.processQueue();
66
- return true;
67
- }
68
- async processQueue() {
69
- if (this.isProcessing || this.prefetchQueue.size === 0) {
70
- return;
71
- }
72
- this.isProcessing = true;
73
- try {
74
- const sortedTasks = this.getSortedTasks();
75
- for (const task of sortedTasks) {
76
- const key = this.getQueryKeyString(task.queryKey);
77
- const startTime = Date.now();
78
- if (task.config.delay && task.config.delay > 0) {
79
- await this.delay(task.config.delay);
80
- }
81
- try {
82
- this.totalPrefetches++;
83
- await this.queryClient.prefetchQuery({ queryKey: task.queryKey, queryFn: task.queryFn, staleTime: task.config.staleTime });
84
- this.successfulPrefetches++;
85
- const duration = Date.now() - startTime;
86
- this.recordPrefetchTime(duration);
87
- this.addToHistory(key);
88
- }
89
- catch {
90
- this.failedPrefetches++;
91
- }
92
- this.prefetchQueue.delete(key);
93
- }
94
- }
95
- finally {
96
- this.isProcessing = false;
97
- }
98
- }
99
- getSortedTasks() {
100
- const tasks = Array.from(this.prefetchQueue.values());
101
- const priorityOrder = { high: 0, medium: 1, low: 2 };
102
- return tasks.sort((a, b) => {
103
- const priorityA = priorityOrder[a.config.priority || "medium"];
104
- const priorityB = priorityOrder[b.config.priority || "medium"];
105
- if (priorityA !== priorityB)
106
- return priorityA - priorityB;
107
- if (a.predictionScore !== undefined && b.predictionScore !== undefined) {
108
- if (a.predictionScore !== b.predictionScore) {
109
- return b.predictionScore - a.predictionScore;
110
- }
111
- }
112
- return a.timestamp - b.timestamp;
113
- });
114
- }
115
- async prefetchNow(queryKey, queryFn, config = {}) {
116
- const key = this.getQueryKeyString(queryKey);
117
- const startTime = Date.now();
118
- try {
119
- this.totalPrefetches++;
120
- await this.queryClient.prefetchQuery({ queryKey, queryFn, staleTime: config.staleTime || DEFAULT_STALE_TIME });
121
- this.successfulPrefetches++;
122
- const duration = Date.now() - startTime;
123
- this.recordPrefetchTime(duration);
124
- this.addToHistory(key);
125
- }
126
- catch (error) {
127
- this.failedPrefetches++;
128
- throw error;
129
- }
130
- }
131
- addToHistory(key) { this.prefetchHistory.add(key); if (this.prefetchHistory.size > this.maxHistorySize) {
132
- const firstKey = this.prefetchHistory.values().next().value;
133
- if (firstKey) {
134
- this.prefetchHistory.delete(firstKey);
135
- }
136
- } }
137
- clearHistory() { this.prefetchHistory.clear(); }
138
- clearQueue() { this.prefetchQueue.clear(); }
139
- reset() { this.clearQueue(); this.clearHistory(); this.clearInteractionHistory(); this.resetStats(); }
140
- destroy() { if (this.networkCleanup) {
141
- this.networkCleanup();
142
- this.networkCleanup = undefined;
143
- } this.reset(); }
144
- recordInteraction(queryKey, type = "view") {
145
- const interaction = { queryKey, timestamp: Date.now(), type };
146
- this.interactionHistory.push(interaction);
147
- if (this.interactionHistory.length > this.maxInteractionHistorySize) {
148
- this.interactionHistory.shift();
149
- }
150
- const key = this.getQueryKeyString(queryKey);
151
- this.queryAccessCounts.set(key, (this.queryAccessCounts.get(key) || 0) + 1);
152
- if (this.interactionHistory.length >= 2) {
153
- const prevInteraction = this.interactionHistory[this.interactionHistory.length - 2];
154
- const prevKey = this.getQueryKeyString(prevInteraction.queryKey);
155
- const existingSequence = this.querySequences.find((s) => s.from === prevKey && s.to === key);
156
- if (existingSequence) {
157
- existingSequence.count++;
158
- }
159
- else {
160
- this.querySequences.push({ from: prevKey, to: key, count: 1 });
161
- if (this.querySequences.length > this.maxSequenceSize) {
162
- this.querySequences.shift();
163
- }
164
- }
165
- }
166
- }
167
- getPredictions(currentQueryKey, limit = 5) {
168
- const predictions = [];
169
- if (currentQueryKey) {
170
- const currentKey = this.getQueryKeyString(currentQueryKey);
171
- const sequences = this.querySequences.filter((s) => s.from === currentKey).sort((a, b) => b.count - a.count).slice(0, limit);
172
- sequences.forEach((seq) => { try {
173
- const queryKey = JSON.parse(seq.to);
174
- predictions.push({ queryKey, score: Math.min(seq.count / 10, 1), reason: `Frequently accessed after current query (${seq.count} times)` });
175
- }
176
- catch { } });
177
- }
178
- const frequentQueries = Array.from(this.queryAccessCounts.entries()).sort((a, b) => b[1] - a[1]).slice(0, limit);
179
- frequentQueries.forEach(([key, count]) => { try {
180
- const queryKey = JSON.parse(key);
181
- if (!predictions.some((p) => this.getQueryKeyString(p.queryKey) === key)) {
182
- predictions.push({ queryKey, score: Math.min(count / 20, 1), reason: `Frequently accessed (${count} times)` });
183
- }
184
- }
185
- catch { } });
186
- const recentInteractions = this.interactionHistory.slice(-10).reverse();
187
- recentInteractions.forEach((interaction, index) => {
188
- const key = this.getQueryKeyString(interaction.queryKey);
189
- if (!predictions.some((p) => this.getQueryKeyString(p.queryKey) === key)) {
190
- predictions.push({ queryKey: interaction.queryKey, score: Math.max(0.3 - index * 0.03, 0.1), reason: `Recently accessed (${index + 1} queries ago)` });
191
- }
192
- });
193
- return predictions.sort((a, b) => b.score - a.score).slice(0, limit);
194
- }
195
- async prefetchPredicted(currentQueryKey, queryFnMap, config = {}) {
196
- const predictions = this.getPredictions(currentQueryKey);
197
- for (const prediction of predictions) {
198
- const key = this.getQueryKeyString(prediction.queryKey);
199
- const queryFn = queryFnMap.get(key);
200
- if (queryFn) {
201
- const taskConfig = { ...config, priority: prediction.score > 0.7 ? "high" : prediction.score > 0.4 ? "medium" : "low" };
202
- const added = this.addPrefetchTask(prediction.queryKey, queryFn, taskConfig);
203
- if (added) {
204
- const task = this.prefetchQueue.get(key);
205
- if (task) {
206
- task.predictionScore = prediction.score;
207
- }
208
- }
209
- }
210
- }
211
- }
212
- clearInteractionHistory() { this.interactionHistory = []; this.queryAccessCounts.clear(); this.querySequences = []; }
213
- recordPrefetchTime(duration) { this.prefetchTimes.push(duration); if (this.prefetchTimes.length > this.maxPrefetchTimesSize) {
214
- this.prefetchTimes.shift();
215
- } }
216
- getAveragePrefetchTime() { if (this.prefetchTimes.length === 0) {
217
- return 0;
218
- } const sum = this.prefetchTimes.reduce((acc, time) => acc + time, 0); return Math.round(sum / this.prefetchTimes.length); }
219
- getStats() { 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 }; }
220
- getPerformanceReport() {
221
- const stats = this.getStats();
222
- const successRate = stats.totalPrefetches > 0 ? Math.round((stats.successfulPrefetches / stats.totalPrefetches) * 100) : 0;
223
- const queueTasks = Array.from(this.prefetchQueue.values());
224
- 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 };
225
- return { stats, successRate, predictions: { totalInteractions: this.interactionHistory.length, uniqueQueries: this.queryAccessCounts.size, sequencePatterns: this.querySequences.length }, queue: { size: this.prefetchQueue.size, byPriority } };
226
- }
227
- resetStats() { this.totalPrefetches = 0; this.successfulPrefetches = 0; this.failedPrefetches = 0; this.skippedPrefetches = 0; this.prefetchTimes = []; }
228
- getQueryKeyString(queryKey) { return JSON.stringify(queryKey); }
229
- delay(ms) { return new Promise((resolve) => setTimeout(resolve, ms)); }
230
- setMaxQueueSize(size) { this.maxQueueSize = size; }
231
- setMaxHistorySize(size) { this.maxHistorySize = size; }
232
- getQueuedTasks() { return Array.from(this.prefetchQueue.values()); }
233
- removeTask(queryKey) { const key = this.getQueryKeyString(queryKey); return this.prefetchQueue.delete(key); }
234
- hasTask(queryKey) { const key = this.getQueryKeyString(queryKey); return this.prefetchQueue.has(key); }
235
- updateTaskPriority(queryKey, priority) { const key = this.getQueryKeyString(queryKey); const task = this.prefetchQueue.get(key); if (task) {
236
- task.config.priority = priority;
237
- return true;
238
- } return false; }
239
- pauseQueue() { this.isProcessing = true; }
240
- resumeQueue() { this.isProcessing = false; this.processQueue(); }
241
- }
242
- let prefetchManagerInstance = null;
243
- export function getPrefetchManager(queryClient) { if (!prefetchManagerInstance) {
244
- prefetchManagerInstance = new SmartPrefetchManager(queryClient);
245
- } return prefetchManagerInstance; }
246
- export function resetPrefetchManager() { prefetchManagerInstance = null; }
@@ -1,24 +0,0 @@
1
- export interface NormalizeConfig<T = any> {
2
- required?: (keyof T)[];
3
- defaults?: Partial<T>;
4
- sortKeys?: boolean;
5
- removeEmpty?: boolean;
6
- }
7
- export declare function normalizeQueryParams<T extends Record<string, any>>(params: T | undefined, config?: NormalizeConfig<T>): Record<string, any>;
8
- export interface QueryKeyFactoryConfig<TParams = any> {
9
- namespace: string;
10
- normalizeConfig?: NormalizeConfig<TParams>;
11
- }
12
- export interface QueryKeyFactory<TParams = any> {
13
- all: () => readonly [string];
14
- lists: () => readonly [string, string];
15
- list: (params?: TParams) => readonly [string, string, Record<string, any>];
16
- details: () => readonly [string, string];
17
- detail: (id: string) => readonly [string, string, string];
18
- custom: (queryName: string, params?: any) => readonly [string, string, string, any?];
19
- }
20
- export declare function createQueryKeyFactory<TParams = any>(config: QueryKeyFactoryConfig<TParams>): QueryKeyFactory<TParams>;
21
- export declare function createSimpleQueryKeyFactory(namespace: string): QueryKeyFactory;
22
- export declare function isQueryKeyEqual(key1: readonly any[], key2: readonly any[]): boolean;
23
- export declare function extractParamsFromKey(queryKey: readonly any[]): Record<string, any> | undefined;
24
- //# sourceMappingURL=queryKey.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"queryKey.d.ts","sourceRoot":"","sources":["../../src/utils/queryKey.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,GAAG;IAAI,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE;AACtI,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,SAAS,EAAE,MAAM,GAAE,eAAe,CAAC,CAAC,CAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAuB/I;AACD,MAAM,WAAW,qBAAqB,CAAC,OAAO,GAAG,GAAG;IAAI,SAAS,EAAE,MAAM,CAAC;IAAC,eAAe,CAAC,EAAE,eAAe,CAAC,OAAO,CAAC,CAAA;CAAE;AACvH,MAAM,WAAW,eAAe,CAAC,OAAO,GAAG,GAAG;IAAI,GAAG,EAAE,MAAM,SAAS,CAAC,MAAM,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,IAAI,EAAE,CAAC,MAAM,CAAC,EAAE,OAAO,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;IAAC,OAAO,EAAE,MAAM,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAAC,MAAM,EAAE,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,KAAK,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;CAAE;AAC/X,wBAAgB,qBAAqB,CAAC,OAAO,GAAG,GAAG,EAAE,MAAM,EAAE,qBAAqB,CAAC,OAAO,CAAC,GAAG,eAAe,CAAC,OAAO,CAAC,CAUrH;AACD,wBAAgB,2BAA2B,CAAC,SAAS,EAAE,MAAM,GAAG,eAAe,CAAiD;AAChI,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,GAAG,EAAE,EAAE,IAAI,EAAE,SAAS,GAAG,EAAE,GAAG,OAAO,CAUnF;AACD,wBAAgB,oBAAoB,CAAC,QAAQ,EAAE,SAAS,GAAG,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAI9F"}
@@ -1,77 +0,0 @@
1
- export function normalizeQueryParams(params, config = {}) {
2
- const { required = [], defaults = {}, sortKeys = true, removeEmpty = true } = config;
3
- if (!params) {
4
- return { ...defaults };
5
- }
6
- const normalized = {};
7
- required.forEach((key) => {
8
- const value = params[key] ?? defaults[key];
9
- if (value !== undefined) {
10
- if (typeof value === "number" || (typeof value === "string" && !Number.isNaN(Number(value)))) {
11
- normalized[String(key)] = Number(value);
12
- }
13
- else {
14
- normalized[String(key)] = value;
15
- }
16
- }
17
- });
18
- const optionalKeys = Object.keys(params).filter((key) => !required.includes(key));
19
- if (sortKeys) {
20
- optionalKeys.sort();
21
- }
22
- optionalKeys.forEach((key) => {
23
- const value = params[key];
24
- if (removeEmpty && (value === undefined || value === null || value === "")) {
25
- return;
26
- }
27
- if (typeof value === "string") {
28
- const trimmed = value.trim();
29
- if (trimmed || !removeEmpty) {
30
- normalized[key] = trimmed;
31
- }
32
- }
33
- else if (value !== undefined && value !== null) {
34
- normalized[key] = value;
35
- }
36
- });
37
- return normalized;
38
- }
39
- export function createQueryKeyFactory(config) {
40
- const { namespace, normalizeConfig } = config;
41
- return {
42
- all: () => [namespace],
43
- lists: () => [namespace, "list"],
44
- list: (params) => { const normalized = normalizeQueryParams(params, normalizeConfig); return [namespace, "list", normalized]; },
45
- details: () => [namespace, "detail"],
46
- detail: (id) => [namespace, "detail", id],
47
- custom: (queryName, params) => { if (params !== undefined) {
48
- return [namespace, "custom", queryName, params];
49
- } return [namespace, "custom", queryName]; }
50
- };
51
- }
52
- export function createSimpleQueryKeyFactory(namespace) { return createQueryKeyFactory({ namespace }); }
53
- export function isQueryKeyEqual(key1, key2) {
54
- if (key1.length !== key2.length)
55
- return false;
56
- return key1.every((value, index) => {
57
- const other = key2[index];
58
- if (typeof value !== "object" || value === null) {
59
- return value === other;
60
- }
61
- if (typeof other !== "object" || other === null) {
62
- return false;
63
- }
64
- const keys1 = Object.keys(value);
65
- const keys2 = Object.keys(other);
66
- if (keys1.length !== keys2.length)
67
- return false;
68
- return keys1.every((key) => value[key] === other[key]);
69
- });
70
- }
71
- export function extractParamsFromKey(queryKey) {
72
- const lastItem = queryKey[queryKey.length - 1];
73
- if (typeof lastItem === "object" && lastItem !== null && !Array.isArray(lastItem)) {
74
- return lastItem;
75
- }
76
- return undefined;
77
- }
@@ -1,30 +0,0 @@
1
- import type { EntityWithId, PaginatedData } from "../types/selectors";
2
- export declare function selectById<T extends EntityWithId>(id: T["id"]): (data: T[] | undefined) => T | undefined;
3
- export declare function selectByIds<T extends EntityWithId>(ids: T["id"][]): (data: T[] | undefined) => T[];
4
- export declare function selectFirst<T>(data: T[] | undefined): T | undefined;
5
- export declare function selectLast<T>(data: T[] | undefined): T | undefined;
6
- export declare function selectCount<T>(data: T[] | undefined): number;
7
- export declare function selectTotal<T extends {
8
- total?: number;
9
- }>(data: T | undefined): number;
10
- export declare function selectItems<TItem, T extends PaginatedData<TItem>>(data: T | undefined): TItem[];
11
- export declare function selectWhere<T>(predicate: (item: T) => boolean): (data: T[] | undefined) => T[];
12
- export declare function selectMap<T, R>(mapper: (item: T) => R): (data: T[] | undefined) => R[];
13
- export declare function selectField<T, K extends keyof T>(field: K): (data: T | undefined) => T[K] | undefined;
14
- export declare function selectFields<T, K extends keyof T>(fields: K[]): (data: T | undefined) => Pick<T, K> | undefined;
15
- export declare function compose<T, R1, R2>(selector1: (data: T) => R1, selector2: (data: R1) => R2): (data: T) => R2;
16
- export declare const selectors: {
17
- byId: typeof selectById;
18
- byIds: typeof selectByIds;
19
- first: typeof selectFirst;
20
- last: typeof selectLast;
21
- count: typeof selectCount;
22
- total: typeof selectTotal;
23
- items: typeof selectItems;
24
- where: typeof selectWhere;
25
- map: typeof selectMap;
26
- field: typeof selectField;
27
- fields: typeof selectFields;
28
- compose: typeof compose;
29
- };
30
- //# sourceMappingURL=selectors.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selectors.d.ts","sourceRoot":"","sources":["../../src/utils/selectors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACtE,wBAAgB,UAAU,CAAC,CAAC,SAAS,YAAY,EAAE,EAAE,E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AY,MAAM,CAAC,GAAG,SAAS,KAAG,CAAC,CAAC,CAAC,CAAC,GAAG,SAAS,CAAgC;AAC5I,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,SAAS,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,IAAY,MAAM,CAAC,GAAG,SAAS,KAAG,IAAI,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAoJ;AAC1Q,wBAAgB,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,CAAC,IAAI,EAAE,EAAE,KAAK,EAAE,IAAY,MAAM,CAAC,KAAG,EAAE,CAA6C;AAC/J,eAAO,MAAM,SAAS;;;;;;;;;;;;;CAAoO,CAAC"}
@@ -1,18 +0,0 @@
1
- export function selectById(id) { return (data) => { return data?.find((item) => item.id === id); }; }
2
- export function selectByIds(ids) { return (data) => { if (!data)
3
- return []; return data.filter((item) => ids.includes(item.id)); }; }
4
- export function selectFirst(data) { return data?.[0]; }
5
- export function selectLast(data) { if (!data || data.length === 0)
6
- return undefined; return data[data.length - 1]; }
7
- export function selectCount(data) { return data?.length ?? 0; }
8
- export function selectTotal(data) { return data?.total ?? 0; }
9
- export function selectItems(data) { return data?.items ?? []; }
10
- export function selectWhere(predicate) { return (data) => { if (!data)
11
- return []; return data.filter(predicate); }; }
12
- export function selectMap(mapper) { return (data) => { if (!data)
13
- return []; return data.map(mapper); }; }
14
- export function selectField(field) { return (data) => { return data?.[field]; }; }
15
- export function selectFields(fields) { return (data) => { if (!data)
16
- return undefined; const result = {}; fields.forEach((field) => { result[field] = data[field]; }); return result; }; }
17
- export function compose(selector1, selector2) { return (data) => { return selector2(selector1(data)); }; }
18
- export const selectors = { byId: selectById, byIds: selectByIds, first: selectFirst, last: selectLast, count: selectCount, total: selectTotal, items: selectItems, where: selectWhere, map: selectMap, field: selectField, fields: selectFields, compose };
@@ -1,7 +0,0 @@
1
- import type { StorageInfo } from "../types/persistence";
2
- import { StorageType } from "../types/base.js";
3
- export declare function isStorageAvailable(storageType: StorageType): boolean;
4
- export declare function getStorageUsage(storageType: StorageType): StorageInfo;
5
- export declare function formatBytes(bytes: number): string;
6
- export declare function deepClone<T>(obj: T): T;
7
- //# sourceMappingURL=storage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../../src/utils/storage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAa/C,wBAAgB,kBAAkB,CAAC,WAAW,EAAE,WAAW,GAAG,OAAO,CASpE;AACD,wBAAgB,eAAe,CAAC,WAAW,EAAE,WAAW,GAAG,WAAW,CAiBrE;AACD,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAIjD;AACD,wBAAgB,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAMtC"}
@@ -1,84 +0,0 @@
1
- import { StorageType } from "../types/base.js";
2
- function getStorageByType(storageType) {
3
- try {
4
- switch (storageType) {
5
- case StorageType.LOCAL:
6
- return typeof window !== "undefined" ? window.localStorage : null;
7
- case StorageType.SESSION:
8
- return typeof window !== "undefined" ? window.sessionStorage : null;
9
- default:
10
- return null;
11
- }
12
- }
13
- catch {
14
- return null;
15
- }
16
- }
17
- export function isStorageAvailable(storageType) {
18
- try {
19
- const storage = getStorageByType(storageType);
20
- if (!storage) {
21
- return false;
22
- }
23
- const testKey = "__storage_test__";
24
- storage.setItem(testKey, "test");
25
- storage.removeItem(testKey);
26
- return true;
27
- }
28
- catch {
29
- return false;
30
- }
31
- }
32
- export function getStorageUsage(storageType) {
33
- try {
34
- const storage = getStorageByType(storageType);
35
- if (!storage) {
36
- return { type: storageType, used: 0, total: 0, usage: 0, available: false, error: "Storage not available" };
37
- }
38
- let used = 0;
39
- for (let i = 0; i < storage.length; i++) {
40
- const key = storage.key(i);
41
- if (key) {
42
- const value = storage.getItem(key);
43
- if (value) {
44
- used += key.length + value.length;
45
- }
46
- }
47
- }
48
- const total = storageType === StorageType.LOCAL ? 5 * 1024 * 1024 : 5 * 1024 * 1024;
49
- return { type: storageType, used, total, usage: used / total, available: true };
50
- }
51
- catch (error) {
52
- return { type: storageType, used: 0, total: 0, usage: 0, available: false, error: error instanceof Error ? error.message : "Unknown error" };
53
- }
54
- }
55
- export function formatBytes(bytes) {
56
- if (bytes === 0) {
57
- return "0 Bytes";
58
- }
59
- const k = 1024;
60
- const sizes = ["Bytes", "KB", "MB", "GB"];
61
- const i = Math.floor(Math.log(bytes) / Math.log(k));
62
- return `${Number.parseFloat((bytes / k ** i).toFixed(2))} ${sizes[i]}`;
63
- }
64
- export function deepClone(obj) {
65
- if (obj === null || typeof obj !== "object") {
66
- return obj;
67
- }
68
- if (obj instanceof Date) {
69
- return new Date(obj.getTime());
70
- }
71
- if (Array.isArray(obj)) {
72
- return obj.map((item) => deepClone(item));
73
- }
74
- if (typeof obj === "object") {
75
- const cloned = {};
76
- for (const key in obj) {
77
- if (Object.prototype.hasOwnProperty.call(obj, key)) {
78
- cloned[key] = deepClone(obj[key]);
79
- }
80
- }
81
- return cloned;
82
- }
83
- return obj;
84
- }