@pol-studios/powersync 1.0.4 → 1.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (115) hide show
  1. package/dist/CacheSettingsManager-1exbOC6S.d.ts +261 -0
  2. package/dist/attachments/index.d.ts +65 -355
  3. package/dist/attachments/index.js +24 -6
  4. package/dist/{types-Cd7RhNqf.d.ts → background-sync-ChCXW-EV.d.ts} +53 -2
  5. package/dist/chunk-4C3RY5SU.js +204 -0
  6. package/dist/chunk-4C3RY5SU.js.map +1 -0
  7. package/dist/{chunk-3AYXHQ4W.js → chunk-53WH2JJV.js} +111 -47
  8. package/dist/chunk-53WH2JJV.js.map +1 -0
  9. package/dist/chunk-A4IBBWGO.js +377 -0
  10. package/dist/chunk-A4IBBWGO.js.map +1 -0
  11. package/dist/chunk-BREGB4WL.js +1768 -0
  12. package/dist/chunk-BREGB4WL.js.map +1 -0
  13. package/dist/{chunk-EJ23MXPQ.js → chunk-CGL33PL4.js} +3 -1
  14. package/dist/chunk-CGL33PL4.js.map +1 -0
  15. package/dist/chunk-DGUM43GV.js +11 -0
  16. package/dist/chunk-DHYUBVP7.js +131 -0
  17. package/dist/chunk-DHYUBVP7.js.map +1 -0
  18. package/dist/chunk-FV2HXEIY.js +124 -0
  19. package/dist/chunk-FV2HXEIY.js.map +1 -0
  20. package/dist/chunk-GKF7TOMT.js +1 -0
  21. package/dist/{chunk-OTJXIRWX.js → chunk-H772V6XQ.js} +304 -51
  22. package/dist/chunk-H772V6XQ.js.map +1 -0
  23. package/dist/{chunk-C2RSTGDC.js → chunk-HFOFLW5F.js} +525 -87
  24. package/dist/chunk-HFOFLW5F.js.map +1 -0
  25. package/dist/chunk-KGSFAE5B.js +1 -0
  26. package/dist/chunk-LNL64IJZ.js +1 -0
  27. package/dist/chunk-MKD2VCX3.js +32 -0
  28. package/dist/chunk-MKD2VCX3.js.map +1 -0
  29. package/dist/{chunk-7EMDVIZX.js → chunk-N75DEF5J.js} +19 -1
  30. package/dist/chunk-N75DEF5J.js.map +1 -0
  31. package/dist/chunk-P6WOZO7H.js +49 -0
  32. package/dist/chunk-P6WOZO7H.js.map +1 -0
  33. package/dist/chunk-TGBT5XBE.js +1 -0
  34. package/dist/chunk-TGBT5XBE.js.map +1 -0
  35. package/dist/chunk-UEYRTLKE.js +72 -0
  36. package/dist/chunk-UEYRTLKE.js.map +1 -0
  37. package/dist/chunk-WGHNIAF7.js +329 -0
  38. package/dist/chunk-WGHNIAF7.js.map +1 -0
  39. package/dist/chunk-WQ5MPAVC.js +449 -0
  40. package/dist/chunk-WQ5MPAVC.js.map +1 -0
  41. package/dist/{chunk-FPTDATY5.js → chunk-XQAJM2MW.js} +22 -11
  42. package/dist/chunk-XQAJM2MW.js.map +1 -0
  43. package/dist/chunk-YSTEESEG.js +676 -0
  44. package/dist/chunk-YSTEESEG.js.map +1 -0
  45. package/dist/chunk-ZEOKPWUC.js +1165 -0
  46. package/dist/chunk-ZEOKPWUC.js.map +1 -0
  47. package/dist/connector/index.d.ts +182 -2
  48. package/dist/connector/index.js +14 -3
  49. package/dist/core/index.d.ts +5 -3
  50. package/dist/core/index.js +5 -2
  51. package/dist/error/index.d.ts +54 -0
  52. package/dist/error/index.js +8 -0
  53. package/dist/error/index.js.map +1 -0
  54. package/dist/index.d.ts +237 -11
  55. package/dist/index.js +183 -27
  56. package/dist/index.native.d.ts +20 -9
  57. package/dist/index.native.js +183 -28
  58. package/dist/index.web.d.ts +20 -9
  59. package/dist/index.web.js +184 -28
  60. package/dist/maintenance/index.d.ts +118 -0
  61. package/dist/maintenance/index.js +17 -0
  62. package/dist/maintenance/index.js.map +1 -0
  63. package/dist/platform/index.d.ts +16 -1
  64. package/dist/platform/index.js +2 -0
  65. package/dist/platform/index.js.map +1 -1
  66. package/dist/platform/index.native.d.ts +2 -2
  67. package/dist/platform/index.native.js +2 -1
  68. package/dist/platform/index.web.d.ts +1 -1
  69. package/dist/platform/index.web.js +2 -1
  70. package/dist/pol-attachment-queue-C7YNXXhK.d.ts +676 -0
  71. package/dist/provider/index.d.ts +693 -12
  72. package/dist/provider/index.js +57 -12
  73. package/dist/storage/index.d.ts +6 -0
  74. package/dist/storage/index.js +28 -0
  75. package/dist/storage/index.js.map +1 -0
  76. package/dist/storage/index.native.d.ts +6 -0
  77. package/dist/storage/index.native.js +26 -0
  78. package/dist/storage/index.native.js.map +1 -0
  79. package/dist/storage/index.web.d.ts +6 -0
  80. package/dist/storage/index.web.js +26 -0
  81. package/dist/storage/index.web.js.map +1 -0
  82. package/dist/storage/upload/index.d.ts +55 -0
  83. package/dist/storage/upload/index.js +15 -0
  84. package/dist/storage/upload/index.js.map +1 -0
  85. package/dist/storage/upload/index.native.d.ts +57 -0
  86. package/dist/storage/upload/index.native.js +14 -0
  87. package/dist/storage/upload/index.native.js.map +1 -0
  88. package/dist/storage/upload/index.web.d.ts +5 -0
  89. package/dist/storage/upload/index.web.js +14 -0
  90. package/dist/storage/upload/index.web.js.map +1 -0
  91. package/dist/{index-Cb-NI0Ct.d.ts → supabase-connector-qLm-WHkM.d.ts} +146 -10
  92. package/dist/sync/index.d.ts +288 -22
  93. package/dist/sync/index.js +23 -5
  94. package/dist/types-BVacP54t.d.ts +52 -0
  95. package/dist/types-Bgvx7-E8.d.ts +187 -0
  96. package/dist/{types-afHtE1U_.d.ts → types-CDqWh56B.d.ts} +2 -0
  97. package/package.json +72 -2
  98. package/dist/chunk-32OLICZO.js +0 -1
  99. package/dist/chunk-3AYXHQ4W.js.map +0 -1
  100. package/dist/chunk-7EMDVIZX.js.map +0 -1
  101. package/dist/chunk-7JQZBZ5N.js +0 -1
  102. package/dist/chunk-C2RSTGDC.js.map +0 -1
  103. package/dist/chunk-EJ23MXPQ.js.map +0 -1
  104. package/dist/chunk-FPTDATY5.js.map +0 -1
  105. package/dist/chunk-GMFDCVMZ.js +0 -1285
  106. package/dist/chunk-GMFDCVMZ.js.map +0 -1
  107. package/dist/chunk-OLHGI472.js +0 -1
  108. package/dist/chunk-OTJXIRWX.js.map +0 -1
  109. package/dist/chunk-V6LJ6MR2.js +0 -740
  110. package/dist/chunk-V6LJ6MR2.js.map +0 -1
  111. package/dist/chunk-VJCL2SWD.js +0 -1
  112. /package/dist/{chunk-32OLICZO.js.map → chunk-DGUM43GV.js.map} +0 -0
  113. /package/dist/{chunk-7JQZBZ5N.js.map → chunk-GKF7TOMT.js.map} +0 -0
  114. /package/dist/{chunk-OLHGI472.js.map → chunk-KGSFAE5B.js.map} +0 -0
  115. /package/dist/{chunk-VJCL2SWD.js.map → chunk-LNL64IJZ.js.map} +0 -0
@@ -0,0 +1,676 @@
1
+ // src/provider/context.ts
2
+ import { createContext } from "react";
3
+ var PowerSyncContext = createContext(null);
4
+ PowerSyncContext.displayName = "PowerSyncContext";
5
+ var SyncStatusContext = createContext(null);
6
+ SyncStatusContext.displayName = "SyncStatusContext";
7
+ var ConnectionStatusContext = createContext(null);
8
+ ConnectionStatusContext.displayName = "ConnectionStatusContext";
9
+ var SyncActivityContext = createContext(null);
10
+ SyncActivityContext.displayName = "SyncActivityContext";
11
+ var PendingMutationsContext = createContext(null);
12
+ PendingMutationsContext.displayName = "PendingMutationsContext";
13
+ var FailedTransactionsContext = createContext(null);
14
+ FailedTransactionsContext.displayName = "FailedTransactionsContext";
15
+ var CompletedTransactionsContext = createContext(null);
16
+ CompletedTransactionsContext.displayName = "CompletedTransactionsContext";
17
+ var SyncModeContext = createContext(null);
18
+ SyncModeContext.displayName = "SyncModeContext";
19
+ var ConnectionHealthContext = createContext(null);
20
+ ConnectionHealthContext.displayName = "ConnectionHealthContext";
21
+ var SyncMetricsContext = createContext(null);
22
+ SyncMetricsContext.displayName = "SyncMetricsContext";
23
+ var AttachmentQueueContext = createContext(null);
24
+ AttachmentQueueContext.displayName = "AttachmentQueueContext";
25
+
26
+ // src/provider/hooks.ts
27
+ import { c as _c } from "react/compiler-runtime";
28
+ import { useContext, useCallback, useMemo, useRef, useState, useEffect } from "react";
29
+ var warnedSyncStatusCallSites = __DEV__ ? /* @__PURE__ */ new Set() : null;
30
+ var SYNCED_DISPLAY_DURATION_MS = 3e3;
31
+ function usePowerSync() {
32
+ const context = useContext(PowerSyncContext);
33
+ if (!context) {
34
+ throw new Error("usePowerSync must be used within a PowerSyncProvider");
35
+ }
36
+ return context;
37
+ }
38
+ function useSyncStatus() {
39
+ if (__DEV__ && warnedSyncStatusCallSites) {
40
+ const stack = new Error().stack?.split("\n")[2] ?? "unknown";
41
+ if (!warnedSyncStatusCallSites.has(stack)) {
42
+ warnedSyncStatusCallSites.add(stack);
43
+ console.warn("[useSyncStatus] Deprecated: This hook causes re-renders on any status change. Use focused hooks: useConnectionStatus, useSyncActivityContext, usePendingMutationsContext, etc. See migration guide in JSDoc.");
44
+ }
45
+ }
46
+ const context = useContext(SyncStatusContext);
47
+ if (!context) {
48
+ throw new Error("useSyncStatus must be used within a PowerSyncProvider");
49
+ }
50
+ return context;
51
+ }
52
+ function useConnectionStatus() {
53
+ const context = useContext(ConnectionStatusContext);
54
+ if (!context) {
55
+ throw new Error("useConnectionStatus must be used within a PowerSyncProvider");
56
+ }
57
+ return context;
58
+ }
59
+ function useSyncActivityContext() {
60
+ const context = useContext(SyncActivityContext);
61
+ if (!context) {
62
+ throw new Error("useSyncActivityContext must be used within a PowerSyncProvider");
63
+ }
64
+ return context;
65
+ }
66
+ function usePendingMutationsContext() {
67
+ const context = useContext(PendingMutationsContext);
68
+ if (!context) {
69
+ throw new Error("usePendingMutationsContext must be used within a PowerSyncProvider");
70
+ }
71
+ return context;
72
+ }
73
+ function useFailedTransactionsContext() {
74
+ const context = useContext(FailedTransactionsContext);
75
+ if (!context) {
76
+ throw new Error("useFailedTransactionsContext must be used within a PowerSyncProvider");
77
+ }
78
+ return context;
79
+ }
80
+ function useCompletedTransactionsContext() {
81
+ const context = useContext(CompletedTransactionsContext);
82
+ if (!context) {
83
+ throw new Error("useCompletedTransactionsContext must be used within a PowerSyncProvider");
84
+ }
85
+ return context;
86
+ }
87
+ function useSyncModeContext() {
88
+ const context = useContext(SyncModeContext);
89
+ if (!context) {
90
+ throw new Error("useSyncModeContext must be used within a PowerSyncProvider");
91
+ }
92
+ return context;
93
+ }
94
+ function useSyncControl() {
95
+ const $ = _c(35);
96
+ const {
97
+ db,
98
+ connector,
99
+ platform
100
+ } = usePowerSync();
101
+ const {
102
+ setSyncMode: setContextSyncMode,
103
+ setForceNextUpload
104
+ } = useSyncModeContext();
105
+ const scopeRef = useRef(null);
106
+ let t0;
107
+ if ($[0] !== connector || $[1] !== db || $[2] !== platform || $[3] !== setContextSyncMode) {
108
+ t0 = async (mode) => {
109
+ await setContextSyncMode(mode);
110
+ if (mode === "offline") {
111
+ if (db?.connected) {
112
+ platform.logger.info("[useSyncControl] Mode changed to offline - disconnecting");
113
+ await db.disconnect();
114
+ }
115
+ } else {
116
+ if (db && connector && !db.connected) {
117
+ platform.logger.info("[useSyncControl] Mode changed to", mode, "- reconnecting");
118
+ await db.connect(connector);
119
+ }
120
+ }
121
+ };
122
+ $[0] = connector;
123
+ $[1] = db;
124
+ $[2] = platform;
125
+ $[3] = setContextSyncMode;
126
+ $[4] = t0;
127
+ } else {
128
+ t0 = $[4];
129
+ }
130
+ const setSyncMode = t0;
131
+ let t1;
132
+ if ($[5] !== connector || $[6] !== db || $[7] !== platform || $[8] !== setForceNextUpload) {
133
+ t1 = async () => {
134
+ if (!db || !connector) {
135
+ platform.logger.warn("[useSyncControl] Cannot sync - database not initialized");
136
+ return;
137
+ }
138
+ setForceNextUpload(true);
139
+ platform.logger.info("[useSyncControl] Sync Now triggered - forcing full sync");
140
+ if (db.connected) {
141
+ await db.disconnect();
142
+ }
143
+ await db.connect(connector);
144
+ platform.logger.info("[useSyncControl] Connected, sync should start automatically");
145
+ };
146
+ $[5] = connector;
147
+ $[6] = db;
148
+ $[7] = platform;
149
+ $[8] = setForceNextUpload;
150
+ $[9] = t1;
151
+ } else {
152
+ t1 = $[9];
153
+ }
154
+ const syncNow = t1;
155
+ let t2;
156
+ if ($[10] !== connector || $[11] !== db || $[12] !== platform || $[13] !== setContextSyncMode) {
157
+ t2 = async () => {
158
+ if (!db || !connector) {
159
+ platform.logger.warn("[useSyncControl] Cannot trigger sync - not initialized");
160
+ return;
161
+ }
162
+ await setContextSyncMode("push-pull");
163
+ if (db.connected) {
164
+ platform.logger.info("[useSyncControl] Disconnecting to force fresh sync...");
165
+ await db.disconnect();
166
+ }
167
+ platform.logger.info("[useSyncControl] Connecting...");
168
+ await db.connect(connector);
169
+ platform.logger.info("[useSyncControl] Connected, sync should start automatically");
170
+ };
171
+ $[10] = connector;
172
+ $[11] = db;
173
+ $[12] = platform;
174
+ $[13] = setContextSyncMode;
175
+ $[14] = t2;
176
+ } else {
177
+ t2 = $[14];
178
+ }
179
+ const triggerSync = t2;
180
+ let t3;
181
+ if ($[15] !== platform || $[16] !== setSyncMode) {
182
+ t3 = async () => {
183
+ await setSyncMode("offline");
184
+ platform.logger.info("[useSyncControl] Sync paused");
185
+ };
186
+ $[15] = platform;
187
+ $[16] = setSyncMode;
188
+ $[17] = t3;
189
+ } else {
190
+ t3 = $[17];
191
+ }
192
+ const pause = t3;
193
+ let t4;
194
+ if ($[18] !== platform || $[19] !== setSyncMode) {
195
+ t4 = async () => {
196
+ await setSyncMode("push-pull");
197
+ platform.logger.info("[useSyncControl] Sync resumed");
198
+ };
199
+ $[18] = platform;
200
+ $[19] = setSyncMode;
201
+ $[20] = t4;
202
+ } else {
203
+ t4 = $[20];
204
+ }
205
+ const resume = t4;
206
+ let t5;
207
+ if ($[21] !== db || $[22] !== platform) {
208
+ t5 = async () => {
209
+ if (!db) {
210
+ platform.logger.warn("[useSyncControl] Cannot disconnect - not initialized");
211
+ return;
212
+ }
213
+ platform.logger.info("[useSyncControl] Disconnecting...");
214
+ await db.disconnect();
215
+ platform.logger.info("[useSyncControl] Disconnected");
216
+ };
217
+ $[21] = db;
218
+ $[22] = platform;
219
+ $[23] = t5;
220
+ } else {
221
+ t5 = $[23];
222
+ }
223
+ const disconnect = t5;
224
+ let t6;
225
+ if ($[24] !== connector || $[25] !== platform) {
226
+ t6 = (scope) => {
227
+ scopeRef.current = scope;
228
+ if (connector && scope) {
229
+ connector.setActiveProjectIds(scope.ids);
230
+ platform.logger.info("[useSyncControl] Scope set:", scope);
231
+ }
232
+ };
233
+ $[24] = connector;
234
+ $[25] = platform;
235
+ $[26] = t6;
236
+ } else {
237
+ t6 = $[26];
238
+ }
239
+ const setScope = t6;
240
+ let t7;
241
+ if ($[27] !== disconnect || $[28] !== pause || $[29] !== resume || $[30] !== setScope || $[31] !== setSyncMode || $[32] !== syncNow || $[33] !== triggerSync) {
242
+ t7 = {
243
+ triggerSync,
244
+ syncNow,
245
+ pause,
246
+ resume,
247
+ disconnect,
248
+ setScope,
249
+ setSyncMode
250
+ };
251
+ $[27] = disconnect;
252
+ $[28] = pause;
253
+ $[29] = resume;
254
+ $[30] = setScope;
255
+ $[31] = setSyncMode;
256
+ $[32] = syncNow;
257
+ $[33] = triggerSync;
258
+ $[34] = t7;
259
+ } else {
260
+ t7 = $[34];
261
+ }
262
+ return t7;
263
+ }
264
+ function useSyncMode() {
265
+ const $ = _c(6);
266
+ const {
267
+ syncMode,
268
+ setSyncMode,
269
+ networkReachable
270
+ } = useSyncModeContext();
271
+ const t0 = networkReachable && syncMode === "push-pull";
272
+ const t1 = syncMode !== "offline";
273
+ let t2;
274
+ if ($[0] !== networkReachable || $[1] !== setSyncMode || $[2] !== syncMode || $[3] !== t0 || $[4] !== t1) {
275
+ t2 = {
276
+ mode: syncMode,
277
+ setMode: setSyncMode,
278
+ canUpload: t0,
279
+ canDownload: t1,
280
+ networkReachable
281
+ };
282
+ $[0] = networkReachable;
283
+ $[1] = setSyncMode;
284
+ $[2] = syncMode;
285
+ $[3] = t0;
286
+ $[4] = t1;
287
+ $[5] = t2;
288
+ } else {
289
+ t2 = $[5];
290
+ }
291
+ return t2;
292
+ }
293
+ function useConnectionHealth() {
294
+ const context = useContext(ConnectionHealthContext);
295
+ if (!context) {
296
+ throw new Error("useConnectionHealth must be used within a PowerSyncProvider");
297
+ }
298
+ return context.health;
299
+ }
300
+ function useSyncMetrics() {
301
+ const context = useContext(SyncMetricsContext);
302
+ if (!context) {
303
+ throw new Error("useSyncMetrics must be used within a PowerSyncProvider");
304
+ }
305
+ return context.metrics;
306
+ }
307
+ function useAttachmentQueue() {
308
+ return useContext(AttachmentQueueContext);
309
+ }
310
+ function useAttachmentQueueReady() {
311
+ const {
312
+ attachmentQueueReady
313
+ } = usePowerSync();
314
+ return attachmentQueueReady;
315
+ }
316
+ function useDatabase() {
317
+ const {
318
+ db,
319
+ isReady,
320
+ error
321
+ } = usePowerSync();
322
+ if (error) {
323
+ throw error;
324
+ }
325
+ if (!isReady || !db) {
326
+ throw new Error("PowerSync database is not ready");
327
+ }
328
+ return db;
329
+ }
330
+ function usePlatform() {
331
+ const {
332
+ platform
333
+ } = usePowerSync();
334
+ return platform;
335
+ }
336
+ function useOnlineStatus() {
337
+ const $ = _c(4);
338
+ const {
339
+ platform
340
+ } = usePowerSync();
341
+ const [isOnline, setIsOnline] = useState(true);
342
+ let t0;
343
+ if ($[0] !== platform.network) {
344
+ t0 = () => {
345
+ platform.network.isConnected().then(setIsOnline);
346
+ const unsubscribe = platform.network.addConnectionListener(setIsOnline);
347
+ return unsubscribe;
348
+ };
349
+ $[0] = platform.network;
350
+ $[1] = t0;
351
+ } else {
352
+ t0 = $[1];
353
+ }
354
+ let t1;
355
+ if ($[2] !== platform) {
356
+ t1 = [platform];
357
+ $[2] = platform;
358
+ $[3] = t1;
359
+ } else {
360
+ t1 = $[3];
361
+ }
362
+ useEffect(t0, t1);
363
+ return isOnline;
364
+ }
365
+ function usePendingMutations() {
366
+ const $ = _c(3);
367
+ const {
368
+ pendingMutations,
369
+ pendingCount
370
+ } = usePendingMutationsContext();
371
+ let t0;
372
+ if ($[0] !== pendingCount || $[1] !== pendingMutations) {
373
+ t0 = {
374
+ mutations: pendingMutations,
375
+ count: pendingCount
376
+ };
377
+ $[0] = pendingCount;
378
+ $[1] = pendingMutations;
379
+ $[2] = t0;
380
+ } else {
381
+ t0 = $[2];
382
+ }
383
+ return t0;
384
+ }
385
+ function useIsSyncing() {
386
+ const {
387
+ uploading,
388
+ downloading
389
+ } = useSyncActivityContext();
390
+ return uploading || downloading;
391
+ }
392
+ function useDownloadProgress() {
393
+ const {
394
+ downloadProgress
395
+ } = useSyncActivityContext();
396
+ return downloadProgress;
397
+ }
398
+ function useEntitySyncStatus(entityId) {
399
+ const {
400
+ pendingMutations
401
+ } = usePendingMutationsContext();
402
+ const {
403
+ failedTransactions,
404
+ clearFailure
405
+ } = useFailedTransactionsContext();
406
+ const [, forceUpdate] = useState(0);
407
+ const recentlySyncedRef = useRef(/* @__PURE__ */ new Map());
408
+ const entityPendingMutations = useMemo(() => {
409
+ if (!entityId) return [];
410
+ return pendingMutations.filter((entry) => entry.id === entityId || String(entry.opData?.id) === entityId);
411
+ }, [entityId, pendingMutations]);
412
+ const failedTransaction = useMemo(() => {
413
+ if (!entityId) return null;
414
+ return failedTransactions.find((ft) => ft.affectedEntityIds.includes(entityId)) ?? null;
415
+ }, [entityId, failedTransactions]);
416
+ const wasSyncingRef = useRef(false);
417
+ const isCurrentlySyncing = entityPendingMutations.length > 0;
418
+ useEffect(() => {
419
+ if (!entityId) return;
420
+ if (wasSyncingRef.current && !isCurrentlySyncing && !failedTransaction) {
421
+ recentlySyncedRef.current.set(entityId, Date.now());
422
+ const timer = setTimeout(() => {
423
+ const syncedAt = recentlySyncedRef.current.get(entityId);
424
+ if (syncedAt && Date.now() - syncedAt >= SYNCED_DISPLAY_DURATION_MS) {
425
+ recentlySyncedRef.current.delete(entityId);
426
+ forceUpdate((n) => n + 1);
427
+ }
428
+ }, SYNCED_DISPLAY_DURATION_MS);
429
+ return () => {
430
+ clearTimeout(timer);
431
+ recentlySyncedRef.current.delete(entityId);
432
+ };
433
+ }
434
+ wasSyncingRef.current = isCurrentlySyncing;
435
+ }, [entityId, isCurrentlySyncing, failedTransaction]);
436
+ const state = useMemo(() => {
437
+ if (!entityId) return "idle";
438
+ if (failedTransaction) {
439
+ return "error";
440
+ }
441
+ if (entityPendingMutations.length > 0) {
442
+ return "syncing";
443
+ }
444
+ const syncedAt_0 = recentlySyncedRef.current.get(entityId);
445
+ if (syncedAt_0 && Date.now() - syncedAt_0 < SYNCED_DISPLAY_DURATION_MS) {
446
+ return "synced";
447
+ }
448
+ return "idle";
449
+ }, [entityId, failedTransaction, entityPendingMutations.length]);
450
+ const error = failedTransaction?.error ?? null;
451
+ const dismiss = useCallback(() => {
452
+ if (failedTransaction) {
453
+ clearFailure(failedTransaction.id);
454
+ }
455
+ }, [failedTransaction, clearFailure]);
456
+ return {
457
+ state,
458
+ error,
459
+ pendingOperations: entityPendingMutations.length,
460
+ failedTransaction,
461
+ dismiss
462
+ };
463
+ }
464
+ function useUploadStatus() {
465
+ const $ = _c(12);
466
+ const {
467
+ pendingCount
468
+ } = usePendingMutationsContext();
469
+ const {
470
+ failedTransactions,
471
+ hasUploadErrors,
472
+ permanentErrorCount,
473
+ clearAllFailures
474
+ } = useFailedTransactionsContext();
475
+ const {
476
+ triggerSync
477
+ } = useSyncControl();
478
+ let t0;
479
+ if ($[0] !== triggerSync) {
480
+ t0 = async () => {
481
+ await triggerSync();
482
+ };
483
+ $[0] = triggerSync;
484
+ $[1] = t0;
485
+ } else {
486
+ t0 = $[1];
487
+ }
488
+ const retryAll = t0;
489
+ let t1;
490
+ if ($[2] !== clearAllFailures) {
491
+ t1 = () => {
492
+ clearAllFailures();
493
+ };
494
+ $[2] = clearAllFailures;
495
+ $[3] = t1;
496
+ } else {
497
+ t1 = $[3];
498
+ }
499
+ const dismissAll = t1;
500
+ const t2 = permanentErrorCount > 0;
501
+ let t3;
502
+ if ($[4] !== dismissAll || $[5] !== failedTransactions || $[6] !== hasUploadErrors || $[7] !== pendingCount || $[8] !== permanentErrorCount || $[9] !== retryAll || $[10] !== t2) {
503
+ t3 = {
504
+ pendingCount,
505
+ failedCount: failedTransactions.length,
506
+ permanentFailureCount: permanentErrorCount,
507
+ hasErrors: hasUploadErrors,
508
+ hasPermanentErrors: t2,
509
+ failedTransactions,
510
+ retryAll,
511
+ dismissAll
512
+ };
513
+ $[4] = dismissAll;
514
+ $[5] = failedTransactions;
515
+ $[6] = hasUploadErrors;
516
+ $[7] = pendingCount;
517
+ $[8] = permanentErrorCount;
518
+ $[9] = retryAll;
519
+ $[10] = t2;
520
+ $[11] = t3;
521
+ } else {
522
+ t3 = $[11];
523
+ }
524
+ return t3;
525
+ }
526
+ function useSyncActivity() {
527
+ const $ = _c(24);
528
+ const {
529
+ pendingMutations
530
+ } = usePendingMutationsContext();
531
+ const {
532
+ failedTransactions,
533
+ clearFailure,
534
+ retryFailure
535
+ } = useFailedTransactionsContext();
536
+ const {
537
+ completedTransactions,
538
+ clearCompletedHistory,
539
+ clearCompletedItem,
540
+ newCompletedTransactions,
541
+ markNotificationsAsSeen
542
+ } = useCompletedTransactionsContext();
543
+ const {
544
+ uploading: isUploading,
545
+ downloading: isDownloading
546
+ } = useSyncActivityContext();
547
+ const {
548
+ triggerSync
549
+ } = useSyncControl();
550
+ let t0;
551
+ if ($[0] !== triggerSync) {
552
+ t0 = async () => {
553
+ await triggerSync();
554
+ };
555
+ $[0] = triggerSync;
556
+ $[1] = t0;
557
+ } else {
558
+ t0 = $[1];
559
+ }
560
+ const retryAll = t0;
561
+ let t1;
562
+ if ($[2] !== clearFailure) {
563
+ t1 = (failureId) => {
564
+ clearFailure(failureId);
565
+ };
566
+ $[2] = clearFailure;
567
+ $[3] = t1;
568
+ } else {
569
+ t1 = $[3];
570
+ }
571
+ const dismissFailure = t1;
572
+ let t2;
573
+ if ($[4] !== clearCompletedHistory) {
574
+ t2 = () => {
575
+ clearCompletedHistory();
576
+ };
577
+ $[4] = clearCompletedHistory;
578
+ $[5] = t2;
579
+ } else {
580
+ t2 = $[5];
581
+ }
582
+ const clearCompleted = t2;
583
+ let t3;
584
+ if ($[6] !== completedTransactions.length || $[7] !== failedTransactions.length || $[8] !== newCompletedTransactions.length || $[9] !== pendingMutations.length) {
585
+ t3 = {
586
+ pending: pendingMutations.length,
587
+ failed: failedTransactions.length,
588
+ completed: completedTransactions.length,
589
+ newCompleted: newCompletedTransactions.length
590
+ };
591
+ $[6] = completedTransactions.length;
592
+ $[7] = failedTransactions.length;
593
+ $[8] = newCompletedTransactions.length;
594
+ $[9] = pendingMutations.length;
595
+ $[10] = t3;
596
+ } else {
597
+ t3 = $[10];
598
+ }
599
+ const counts = t3;
600
+ const hasActivity = isUploading || isDownloading || failedTransactions.length > 0;
601
+ let t4;
602
+ if ($[11] !== clearCompleted || $[12] !== clearCompletedItem || $[13] !== completedTransactions || $[14] !== counts || $[15] !== dismissFailure || $[16] !== failedTransactions || $[17] !== hasActivity || $[18] !== markNotificationsAsSeen || $[19] !== newCompletedTransactions || $[20] !== pendingMutations || $[21] !== retryAll || $[22] !== retryFailure) {
603
+ t4 = {
604
+ pending: pendingMutations,
605
+ failed: failedTransactions,
606
+ completed: completedTransactions,
607
+ newCompleted: newCompletedTransactions,
608
+ counts,
609
+ hasActivity,
610
+ retryAll,
611
+ retryFailure,
612
+ dismissFailure,
613
+ clearCompleted,
614
+ clearCompletedItem,
615
+ markNotificationsAsSeen
616
+ };
617
+ $[11] = clearCompleted;
618
+ $[12] = clearCompletedItem;
619
+ $[13] = completedTransactions;
620
+ $[14] = counts;
621
+ $[15] = dismissFailure;
622
+ $[16] = failedTransactions;
623
+ $[17] = hasActivity;
624
+ $[18] = markNotificationsAsSeen;
625
+ $[19] = newCompletedTransactions;
626
+ $[20] = pendingMutations;
627
+ $[21] = retryAll;
628
+ $[22] = retryFailure;
629
+ $[23] = t4;
630
+ } else {
631
+ t4 = $[23];
632
+ }
633
+ return t4;
634
+ }
635
+ var useFailedTransactions = useFailedTransactionsContext;
636
+ var useCompletedTransactions = useCompletedTransactionsContext;
637
+
638
+ export {
639
+ PowerSyncContext,
640
+ SyncStatusContext,
641
+ ConnectionStatusContext,
642
+ SyncActivityContext,
643
+ PendingMutationsContext,
644
+ FailedTransactionsContext,
645
+ CompletedTransactionsContext,
646
+ SyncModeContext,
647
+ ConnectionHealthContext,
648
+ SyncMetricsContext,
649
+ AttachmentQueueContext,
650
+ usePowerSync,
651
+ useSyncStatus,
652
+ useConnectionStatus,
653
+ useSyncActivityContext,
654
+ usePendingMutationsContext,
655
+ useFailedTransactionsContext,
656
+ useCompletedTransactionsContext,
657
+ useSyncModeContext,
658
+ useSyncControl,
659
+ useSyncMode,
660
+ useConnectionHealth,
661
+ useSyncMetrics,
662
+ useAttachmentQueue,
663
+ useAttachmentQueueReady,
664
+ useDatabase,
665
+ usePlatform,
666
+ useOnlineStatus,
667
+ usePendingMutations,
668
+ useIsSyncing,
669
+ useDownloadProgress,
670
+ useEntitySyncStatus,
671
+ useUploadStatus,
672
+ useSyncActivity,
673
+ useFailedTransactions,
674
+ useCompletedTransactions
675
+ };
676
+ //# sourceMappingURL=chunk-YSTEESEG.js.map