@pol-studios/powersync 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. package/dist/attachments/index.d.ts +399 -0
  2. package/dist/attachments/index.js +16 -0
  3. package/dist/attachments/index.js.map +1 -0
  4. package/dist/chunk-32OLICZO.js +1 -0
  5. package/dist/chunk-32OLICZO.js.map +1 -0
  6. package/dist/chunk-4FJVBR3X.js +227 -0
  7. package/dist/chunk-4FJVBR3X.js.map +1 -0
  8. package/dist/chunk-7BPTGEVG.js +1 -0
  9. package/dist/chunk-7BPTGEVG.js.map +1 -0
  10. package/dist/chunk-7JQZBZ5N.js +1 -0
  11. package/dist/chunk-7JQZBZ5N.js.map +1 -0
  12. package/dist/chunk-BJ36QDFN.js +290 -0
  13. package/dist/chunk-BJ36QDFN.js.map +1 -0
  14. package/dist/chunk-CFCK2LHI.js +1002 -0
  15. package/dist/chunk-CFCK2LHI.js.map +1 -0
  16. package/dist/chunk-CHRTN5PF.js +322 -0
  17. package/dist/chunk-CHRTN5PF.js.map +1 -0
  18. package/dist/chunk-FLHDT4TS.js +327 -0
  19. package/dist/chunk-FLHDT4TS.js.map +1 -0
  20. package/dist/chunk-GBGATW2S.js +749 -0
  21. package/dist/chunk-GBGATW2S.js.map +1 -0
  22. package/dist/chunk-NPNBGCRC.js +65 -0
  23. package/dist/chunk-NPNBGCRC.js.map +1 -0
  24. package/dist/chunk-Q3LFFMRR.js +925 -0
  25. package/dist/chunk-Q3LFFMRR.js.map +1 -0
  26. package/dist/chunk-T225XEML.js +298 -0
  27. package/dist/chunk-T225XEML.js.map +1 -0
  28. package/dist/chunk-W7HSR35B.js +1 -0
  29. package/dist/chunk-W7HSR35B.js.map +1 -0
  30. package/dist/connector/index.d.ts +5 -0
  31. package/dist/connector/index.js +14 -0
  32. package/dist/connector/index.js.map +1 -0
  33. package/dist/core/index.d.ts +197 -0
  34. package/dist/core/index.js +96 -0
  35. package/dist/core/index.js.map +1 -0
  36. package/dist/index-nae7nzib.d.ts +147 -0
  37. package/dist/index.d.ts +68 -0
  38. package/dist/index.js +191 -0
  39. package/dist/index.js.map +1 -0
  40. package/dist/index.native.d.ts +14 -0
  41. package/dist/index.native.js +195 -0
  42. package/dist/index.native.js.map +1 -0
  43. package/dist/index.web.d.ts +14 -0
  44. package/dist/index.web.js +195 -0
  45. package/dist/index.web.js.map +1 -0
  46. package/dist/platform/index.d.ts +280 -0
  47. package/dist/platform/index.js +14 -0
  48. package/dist/platform/index.js.map +1 -0
  49. package/dist/platform/index.native.d.ts +37 -0
  50. package/dist/platform/index.native.js +7 -0
  51. package/dist/platform/index.native.js.map +1 -0
  52. package/dist/platform/index.web.d.ts +37 -0
  53. package/dist/platform/index.web.js +7 -0
  54. package/dist/platform/index.web.js.map +1 -0
  55. package/dist/provider/index.d.ts +873 -0
  56. package/dist/provider/index.js +63 -0
  57. package/dist/provider/index.js.map +1 -0
  58. package/dist/supabase-connector-D14-kl5v.d.ts +232 -0
  59. package/dist/sync/index.d.ts +421 -0
  60. package/dist/sync/index.js +14 -0
  61. package/dist/sync/index.js.map +1 -0
  62. package/dist/types-Cd7RhNqf.d.ts +224 -0
  63. package/dist/types-afHtE1U_.d.ts +391 -0
  64. package/package.json +101 -0
@@ -0,0 +1,873 @@
1
+ import { SupabaseClient } from '@supabase/supabase-js';
2
+ import { QueryClient } from '@tanstack/react-query';
3
+ import { A as AbstractPowerSyncDatabase, a as SyncStatus, C as CrudEntry, S as SyncMode, F as FailedTransaction, h as CompletedTransaction, b as ConnectionHealth, e as SyncMetrics, D as DownloadProgress, E as EntitySyncState, f as SyncError } from '../types-afHtE1U_.js';
4
+ import { PlatformAdapter } from '../platform/index.js';
5
+ import { C as ConnectorConfig, S as SupabaseConnector } from '../supabase-connector-D14-kl5v.js';
6
+ import { AttachmentQueueConfig, AttachmentQueue } from '../attachments/index.js';
7
+ import * as react from 'react';
8
+ import react__default from 'react';
9
+ import { c as SyncControlActions } from '../types-Cd7RhNqf.js';
10
+
11
+ /**
12
+ * Provider Types for @pol-studios/powersync
13
+ *
14
+ * Defines configuration and context interfaces for the PowerSyncProvider.
15
+ */
16
+
17
+ /**
18
+ * Main configuration for PowerSyncProvider.
19
+ *
20
+ * @template TSchema - The PowerSync schema type
21
+ *
22
+ * @example
23
+ * ```typescript
24
+ * const config: PowerSyncConfig<AppSchema> = {
25
+ * platform: createNativePlatformAdapter(logger),
26
+ * schema: AppSchema,
27
+ * powerSyncUrl: 'https://your-powersync-instance.com',
28
+ * supabaseClient: supabase,
29
+ * dbFilename: 'myapp.db',
30
+ * sync: {
31
+ * autoConnect: true,
32
+ * },
33
+ * };
34
+ * ```
35
+ */
36
+ interface PowerSyncConfig<TSchema = unknown> {
37
+ /**
38
+ * Platform adapter for platform-specific operations.
39
+ * Use createNativePlatformAdapter() for React Native or createWebPlatformAdapter() for Web.
40
+ */
41
+ platform: PlatformAdapter;
42
+ /**
43
+ * PowerSync schema definition.
44
+ * This defines the tables and their structure for the local database.
45
+ */
46
+ schema: TSchema;
47
+ /**
48
+ * PowerSync service URL.
49
+ * @example "https://your-instance.powersync.journeyapps.com"
50
+ */
51
+ powerSyncUrl: string;
52
+ /**
53
+ * Supabase client instance.
54
+ * Used for authentication and as the backend for CRUD uploads.
55
+ */
56
+ supabaseClient: SupabaseClient;
57
+ /**
58
+ * Optional: TanStack Query client for cache invalidation.
59
+ * If provided, will invalidate queries when sync completes.
60
+ */
61
+ queryClient?: QueryClient;
62
+ /**
63
+ * Optional: Database filename.
64
+ * @default "powersync.db"
65
+ */
66
+ dbFilename?: string;
67
+ /**
68
+ * Optional: Connector configuration for custom CRUD handling.
69
+ */
70
+ connector?: ConnectorConfig;
71
+ /**
72
+ * Optional: Attachment queue configuration for offline file caching.
73
+ */
74
+ attachments?: AttachmentQueueConfig;
75
+ /**
76
+ * Optional: Sync behavior configuration.
77
+ */
78
+ sync?: SyncConfig;
79
+ }
80
+ /**
81
+ * Sync behavior configuration.
82
+ */
83
+ interface SyncConfig {
84
+ /**
85
+ * Automatically connect when the provider mounts and there's an authenticated session.
86
+ * @default true
87
+ */
88
+ autoConnect?: boolean;
89
+ /**
90
+ * Sync interval for periodic sync checks (in milliseconds).
91
+ * Set to 0 to disable periodic sync.
92
+ * @default 0 (disabled)
93
+ */
94
+ syncInterval?: number;
95
+ /**
96
+ * Enable health monitoring.
97
+ * @default true
98
+ */
99
+ enableHealthMonitoring?: boolean;
100
+ /**
101
+ * Enable metrics collection.
102
+ * @default true
103
+ */
104
+ enableMetrics?: boolean;
105
+ }
106
+ /**
107
+ * Value provided by the main PowerSyncContext.
108
+ *
109
+ * @template TSchema - The PowerSync schema type
110
+ */
111
+ interface PowerSyncContextValue<TSchema = unknown> {
112
+ /**
113
+ * The PowerSync database instance.
114
+ * Will be null if not initialized or if initialization failed.
115
+ */
116
+ db: AbstractPowerSyncDatabase | null;
117
+ /**
118
+ * The Supabase connector instance.
119
+ * Will be null if not initialized.
120
+ */
121
+ connector: SupabaseConnector | null;
122
+ /**
123
+ * The attachment queue instance.
124
+ * Will be null if attachments are not configured or not initialized.
125
+ */
126
+ attachmentQueue: AttachmentQueue | null;
127
+ /**
128
+ * Whether the PowerSync database is ready for use.
129
+ */
130
+ isReady: boolean;
131
+ /**
132
+ * Whether the provider is currently initializing.
133
+ */
134
+ isInitializing: boolean;
135
+ /**
136
+ * Error that occurred during initialization, if any.
137
+ */
138
+ error: Error | null;
139
+ /**
140
+ * The schema used for this database.
141
+ */
142
+ schema: TSchema;
143
+ /**
144
+ * The platform adapter instance.
145
+ */
146
+ platform: PlatformAdapter;
147
+ }
148
+ /**
149
+ * Value provided by SyncStatusContext.
150
+ */
151
+ interface SyncStatusContextValue {
152
+ /**
153
+ * Current sync status.
154
+ */
155
+ status: SyncStatus;
156
+ /**
157
+ * Pending mutations waiting to be uploaded.
158
+ */
159
+ pendingMutations: CrudEntry[];
160
+ /**
161
+ * Number of pending mutations.
162
+ */
163
+ pendingCount: number;
164
+ /**
165
+ * Whether data is currently being uploaded to the server.
166
+ * This is the authoritative source for upload activity.
167
+ */
168
+ isUploading: boolean;
169
+ /**
170
+ * Whether data is currently being downloaded from the server.
171
+ * This is the authoritative source for download activity.
172
+ */
173
+ isDownloading: boolean;
174
+ /**
175
+ * Whether sync is currently paused (offline mode).
176
+ */
177
+ isPaused: boolean;
178
+ /**
179
+ * Current sync mode: 'push-pull' (full sync), 'pull-only' (download only), or 'offline' (no sync).
180
+ */
181
+ syncMode: SyncMode;
182
+ /**
183
+ * Timestamp of the last successful sync.
184
+ */
185
+ lastSyncedAt: Date | null;
186
+ /**
187
+ * Error that occurred during connection, if any.
188
+ */
189
+ connectionError?: Error | null;
190
+ /**
191
+ * Failed transactions that need attention.
192
+ */
193
+ failedTransactions: FailedTransaction[];
194
+ /**
195
+ * Whether there are any upload errors.
196
+ */
197
+ hasUploadErrors: boolean;
198
+ /**
199
+ * Count of permanent errors that need user action.
200
+ */
201
+ permanentErrorCount: number;
202
+ /**
203
+ * Clear a specific failure by its ID.
204
+ */
205
+ clearFailure: (failureId: string) => void;
206
+ /**
207
+ * Clear all failures.
208
+ */
209
+ clearAllFailures: () => void;
210
+ /**
211
+ * Completed transactions history.
212
+ */
213
+ completedTransactions: CompletedTransaction[];
214
+ /**
215
+ * Clear the completed transaction history.
216
+ */
217
+ clearCompletedHistory: () => void;
218
+ /**
219
+ * Set the sync mode.
220
+ * @param mode - The sync mode to set
221
+ */
222
+ setSyncMode: (mode: SyncMode) => Promise<void>;
223
+ /**
224
+ * Set the force next upload flag.
225
+ * When true, the next sync cycle will upload regardless of sync mode.
226
+ */
227
+ setForceNextUpload: (force: boolean) => void;
228
+ /**
229
+ * Discard a specific pending mutation by its client ID.
230
+ * Uses safe disconnect/reconnect pattern to avoid transaction conflicts.
231
+ * @throws Error if upload is in progress
232
+ */
233
+ discardPendingMutation: (clientId: number) => Promise<void>;
234
+ /**
235
+ * Discard all pending mutations.
236
+ * Uses safe disconnect/reconnect pattern to avoid transaction conflicts.
237
+ * @throws Error if upload is in progress
238
+ */
239
+ discardAllPendingMutations: () => Promise<void>;
240
+ }
241
+ /**
242
+ * Value provided by ConnectionHealthContext.
243
+ */
244
+ interface ConnectionHealthContextValue {
245
+ /**
246
+ * Current connection health status.
247
+ */
248
+ health: ConnectionHealth;
249
+ }
250
+ /**
251
+ * Value provided by SyncMetricsContext.
252
+ */
253
+ interface SyncMetricsContextValue {
254
+ /**
255
+ * Current sync metrics.
256
+ */
257
+ metrics: SyncMetrics;
258
+ }
259
+ /**
260
+ * Props for the PowerSyncProvider component.
261
+ *
262
+ * @template TSchema - The PowerSync schema type
263
+ */
264
+ interface PowerSyncProviderProps<TSchema = unknown> {
265
+ /**
266
+ * PowerSync configuration.
267
+ */
268
+ config: PowerSyncConfig<TSchema>;
269
+ /**
270
+ * Child components to render.
271
+ */
272
+ children: React.ReactNode;
273
+ /**
274
+ * Called when the database is initialized and ready.
275
+ */
276
+ onReady?: () => void;
277
+ /**
278
+ * Called when an error occurs during initialization.
279
+ */
280
+ onError?: (error: Error) => void;
281
+ /**
282
+ * Called when sync status changes.
283
+ */
284
+ onSyncStatusChange?: (status: SyncStatus) => void;
285
+ }
286
+ /**
287
+ * Default sync status.
288
+ */
289
+ declare const DEFAULT_SYNC_STATUS: SyncStatus;
290
+ /**
291
+ * Default connection health.
292
+ */
293
+ declare const DEFAULT_CONNECTION_HEALTH: ConnectionHealth;
294
+ /**
295
+ * Default sync metrics.
296
+ */
297
+ declare const DEFAULT_SYNC_METRICS: SyncMetrics;
298
+ /**
299
+ * Default sync configuration.
300
+ */
301
+ declare const DEFAULT_SYNC_CONFIG: Required<SyncConfig>;
302
+
303
+ /**
304
+ * Main context for PowerSync database instance and related state.
305
+ *
306
+ * Provides access to:
307
+ * - PowerSync database instance
308
+ * - SupabaseConnector instance
309
+ * - AttachmentQueue instance (if configured)
310
+ * - Initialization state
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * const { db, isReady, error } = useContext(PowerSyncContext);
315
+ * ```
316
+ */
317
+ declare const PowerSyncContext: react.Context<PowerSyncContextValue<unknown>>;
318
+ /**
319
+ * Context for sync status updates.
320
+ *
321
+ * Provides access to:
322
+ * - Current sync status (connected, syncing, etc.)
323
+ * - Pending mutations count
324
+ * - Paused state
325
+ * - Last synced timestamp
326
+ *
327
+ * @example
328
+ * ```typescript
329
+ * const { status, pendingCount, isPaused } = useContext(SyncStatusContext);
330
+ * ```
331
+ */
332
+ declare const SyncStatusContext: react.Context<SyncStatusContextValue>;
333
+ /**
334
+ * Context for connection health monitoring.
335
+ *
336
+ * Provides access to:
337
+ * - Health status (healthy, degraded, disconnected)
338
+ * - Latency measurements
339
+ * - Health check timestamps
340
+ * - Failure counts
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * const { health } = useContext(ConnectionHealthContext);
345
+ * if (health.status === 'degraded') {
346
+ * showWarning('Connection is slow');
347
+ * }
348
+ * ```
349
+ */
350
+ declare const ConnectionHealthContext: react.Context<ConnectionHealthContextValue>;
351
+ /**
352
+ * Context for sync metrics and statistics.
353
+ *
354
+ * Provides access to:
355
+ * - Sync operation counts
356
+ * - Sync durations
357
+ * - Data transfer amounts
358
+ * - Error tracking
359
+ *
360
+ * @example
361
+ * ```typescript
362
+ * const { metrics } = useContext(SyncMetricsContext);
363
+ * console.log(`Total syncs: ${metrics.totalSyncs}`);
364
+ * ```
365
+ */
366
+ declare const SyncMetricsContext: react.Context<SyncMetricsContextValue>;
367
+ /**
368
+ * Context for the attachment queue (if configured).
369
+ *
370
+ * Provides direct access to the AttachmentQueue instance for:
371
+ * - Checking attachment sync stats
372
+ * - Pausing/resuming downloads
373
+ * - Getting local URIs for attachments
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * const attachmentQueue = useContext(AttachmentQueueContext);
378
+ * if (attachmentQueue) {
379
+ * const stats = await attachmentQueue.getStats();
380
+ * console.log(`Downloaded: ${stats.syncedCount}/${stats.totalExpected}`);
381
+ * }
382
+ * ```
383
+ */
384
+ declare const AttachmentQueueContext: react.Context<AttachmentQueue>;
385
+
386
+ /**
387
+ * PowerSyncProvider Component for @pol-studios/powersync
388
+ *
389
+ * Main provider component that initializes and manages the PowerSync database,
390
+ * connector, attachment queue, and all monitoring services.
391
+ */
392
+
393
+ /**
394
+ * PowerSyncProvider initializes and manages the PowerSync database and related services.
395
+ *
396
+ * Features:
397
+ * - Initializes PowerSync database using platform adapter
398
+ * - Creates and manages SupabaseConnector
399
+ * - Connects/disconnects based on auth state
400
+ * - Tracks sync status and connection health
401
+ * - Optionally initializes AttachmentQueue
402
+ * - Provides all contexts to children
403
+ * - Handles cleanup on unmount
404
+ *
405
+ * @example
406
+ * ```tsx
407
+ * import { PowerSyncProvider, usePowerSync, useSyncStatus } from '@pol-studios/powersync';
408
+ *
409
+ * function App() {
410
+ * return (
411
+ * <PowerSyncProvider
412
+ * config={{
413
+ * platform: createNativePlatformAdapter(logger),
414
+ * schema: AppSchema,
415
+ * powerSyncUrl: 'https://your-powersync.com',
416
+ * supabaseClient: supabase,
417
+ * }}
418
+ * onReady={() => console.log('PowerSync ready!')}
419
+ * onError={(err) => console.error('PowerSync error:', err)}
420
+ * >
421
+ * <MainApp />
422
+ * </PowerSyncProvider>
423
+ * );
424
+ * }
425
+ * ```
426
+ */
427
+ declare function PowerSyncProvider<TSchema = unknown>({ config, children, onReady, onError, onSyncStatusChange, }: PowerSyncProviderProps<TSchema>): react__default.ReactElement;
428
+
429
+ /**
430
+ * Hook to access the PowerSync database and related services.
431
+ *
432
+ * @returns PowerSync context value with database, connector, and state
433
+ * @throws Error if used outside of PowerSyncProvider
434
+ *
435
+ * @example
436
+ * ```typescript
437
+ * function MyComponent() {
438
+ * const { db, isReady, error } = usePowerSync();
439
+ *
440
+ * if (!isReady) return <LoadingSpinner />;
441
+ * if (error) return <Error message={error.message} />;
442
+ *
443
+ * // Use db for queries
444
+ * const users = await db.getAll('SELECT * FROM users');
445
+ * }
446
+ * ```
447
+ */
448
+ declare function usePowerSync<TSchema = unknown>(): PowerSyncContextValue<TSchema>;
449
+ /**
450
+ * Hook to access the current sync status.
451
+ *
452
+ * @returns Sync status with connection state, pending uploads, and progress
453
+ * @throws Error if used outside of PowerSyncProvider
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * function SyncIndicator() {
458
+ * const { status, pendingCount, isPaused } = useSyncStatus();
459
+ *
460
+ * if (status.downloading) {
461
+ * const { current, target, percentage } = status.downloadProgress ?? {};
462
+ * return <Progress value={percentage} label={`${current}/${target}`} />;
463
+ * }
464
+ *
465
+ * if (pendingCount > 0) {
466
+ * return <Badge>{pendingCount} pending uploads</Badge>;
467
+ * }
468
+ *
469
+ * return <Text>Synced</Text>;
470
+ * }
471
+ * ```
472
+ */
473
+ declare function useSyncStatus(): SyncStatusContextValue;
474
+ /**
475
+ * Hook to control sync operations.
476
+ *
477
+ * @returns Actions for triggering, pausing, and resuming sync
478
+ *
479
+ * @example
480
+ * ```typescript
481
+ * function SyncControls() {
482
+ * const { triggerSync, syncNow, pause, resume, disconnect, setSyncMode } = useSyncControl();
483
+ * const { isPaused, syncMode } = useSyncStatus();
484
+ *
485
+ * return (
486
+ * <View>
487
+ * <Button onPress={syncNow}>Sync Now</Button>
488
+ * {isPaused ? (
489
+ * <Button onPress={resume}>Resume</Button>
490
+ * ) : (
491
+ * <Button onPress={pause}>Pause</Button>
492
+ * )}
493
+ * </View>
494
+ * );
495
+ * }
496
+ * ```
497
+ */
498
+ declare function useSyncControl(): SyncControlActions;
499
+ /**
500
+ * Hook to get and set the current sync mode.
501
+ *
502
+ * @returns Object with current mode, setter, and capability flags
503
+ *
504
+ * @example
505
+ * ```typescript
506
+ * function SyncModeSelector() {
507
+ * const { mode, setMode, canUpload, canDownload } = useSyncMode();
508
+ *
509
+ * return (
510
+ * <View>
511
+ * <Text>Current mode: {mode}</Text>
512
+ * <Text>Can upload: {canUpload ? 'Yes' : 'No'}</Text>
513
+ * <Button onPress={() => setMode('pull-only')}>Download Only</Button>
514
+ * </View>
515
+ * );
516
+ * }
517
+ * ```
518
+ */
519
+ declare function useSyncMode(): {
520
+ mode: SyncMode;
521
+ setMode: (mode: SyncMode) => Promise<void>;
522
+ canUpload: boolean;
523
+ canDownload: boolean;
524
+ };
525
+ /**
526
+ * Hook to access connection health status.
527
+ *
528
+ * @returns Current connection health with latency and failure tracking
529
+ * @throws Error if used outside of PowerSyncProvider
530
+ *
531
+ * @example
532
+ * ```typescript
533
+ * function ConnectionIndicator() {
534
+ * const health = useConnectionHealth();
535
+ *
536
+ * const statusColor = {
537
+ * healthy: 'green',
538
+ * degraded: 'yellow',
539
+ * disconnected: 'red',
540
+ * }[health.status];
541
+ *
542
+ * return (
543
+ * <View>
544
+ * <StatusDot color={statusColor} />
545
+ * {health.latency && <Text>{health.latency}ms</Text>}
546
+ * </View>
547
+ * );
548
+ * }
549
+ * ```
550
+ */
551
+ declare function useConnectionHealth(): ConnectionHealth;
552
+ /**
553
+ * Hook to access sync metrics.
554
+ *
555
+ * @returns Sync metrics including success rates, timing, and data transfer
556
+ * @throws Error if used outside of PowerSyncProvider
557
+ *
558
+ * @example
559
+ * ```typescript
560
+ * function SyncStats() {
561
+ * const metrics = useSyncMetrics();
562
+ *
563
+ * const successRate = metrics.totalSyncs > 0
564
+ * ? (metrics.successfulSyncs / metrics.totalSyncs * 100).toFixed(1)
565
+ * : 100;
566
+ *
567
+ * return (
568
+ * <View>
569
+ * <Text>Total syncs: {metrics.totalSyncs}</Text>
570
+ * <Text>Success rate: {successRate}%</Text>
571
+ * <Text>Avg duration: {metrics.averageSyncDuration ?? 'N/A'}ms</Text>
572
+ * </View>
573
+ * );
574
+ * }
575
+ * ```
576
+ */
577
+ declare function useSyncMetrics(): SyncMetrics;
578
+ /**
579
+ * Hook to access the attachment queue (if configured).
580
+ *
581
+ * @returns AttachmentQueue instance or null if not configured
582
+ *
583
+ * @example
584
+ * ```typescript
585
+ * function PhotoStats() {
586
+ * const attachmentQueue = useAttachmentQueue();
587
+ * const [stats, setStats] = useState(null);
588
+ *
589
+ * useEffect(() => {
590
+ * if (!attachmentQueue) return;
591
+ *
592
+ * return attachmentQueue.onProgress((newStats) => {
593
+ * setStats(newStats);
594
+ * });
595
+ * }, [attachmentQueue]);
596
+ *
597
+ * if (!stats) return null;
598
+ *
599
+ * return (
600
+ * <View>
601
+ * <Text>Photos: {stats.syncedCount}/{stats.totalExpected}</Text>
602
+ * <Text>Cache used: {formatBytes(stats.syncedSize)}</Text>
603
+ * </View>
604
+ * );
605
+ * }
606
+ * ```
607
+ */
608
+ declare function useAttachmentQueue(): AttachmentQueue | null;
609
+ /**
610
+ * Hook to get the PowerSync database instance.
611
+ * Throws if not ready.
612
+ *
613
+ * @returns The PowerSync database instance
614
+ * @throws Error if not initialized or used outside of PowerSyncProvider
615
+ *
616
+ * @example
617
+ * ```typescript
618
+ * function UserList() {
619
+ * const db = useDatabase();
620
+ * const [users, setUsers] = useState([]);
621
+ *
622
+ * useEffect(() => {
623
+ * db.getAll('SELECT * FROM users').then(setUsers);
624
+ * }, [db]);
625
+ *
626
+ * return <FlatList data={users} />;
627
+ * }
628
+ * ```
629
+ */
630
+ declare function useDatabase(): AbstractPowerSyncDatabase;
631
+ /**
632
+ * Hook to access the platform adapter.
633
+ *
634
+ * @returns The platform adapter instance
635
+ *
636
+ * @example
637
+ * ```typescript
638
+ * function FileViewer({ filePath }) {
639
+ * const { platform } = usePowerSync();
640
+ *
641
+ * const handleOpen = async () => {
642
+ * const content = await platform.fileSystem.readFile(filePath);
643
+ * // Process content...
644
+ * };
645
+ *
646
+ * return <Button onPress={handleOpen}>Open File</Button>;
647
+ * }
648
+ * ```
649
+ */
650
+ declare function usePlatform(): PlatformAdapter;
651
+ /**
652
+ * Hook to track online/offline status using the platform's network adapter.
653
+ *
654
+ * @returns Whether the device is currently connected to the internet
655
+ *
656
+ * @example
657
+ * ```typescript
658
+ * function OfflineBanner() {
659
+ * const isOnline = useOnlineStatus();
660
+ *
661
+ * if (isOnline) return null;
662
+ *
663
+ * return <Banner type="warning">You are offline</Banner>;
664
+ * }
665
+ * ```
666
+ */
667
+ declare function useOnlineStatus(): boolean;
668
+ /**
669
+ * Hook to get pending mutations that need to be uploaded.
670
+ *
671
+ * @returns Array of pending CRUD entries and count
672
+ *
673
+ * @example
674
+ * ```typescript
675
+ * function PendingChanges() {
676
+ * const { mutations, count } = usePendingMutations();
677
+ *
678
+ * if (count === 0) return null;
679
+ *
680
+ * return (
681
+ * <View>
682
+ * <Text>{count} changes pending upload</Text>
683
+ * <FlatList
684
+ * data={mutations}
685
+ * renderItem={({ item }) => (
686
+ * <Text>{item.op} on {item.table}</Text>
687
+ * )}
688
+ * />
689
+ * </View>
690
+ * );
691
+ * }
692
+ * ```
693
+ */
694
+ declare function usePendingMutations(): {
695
+ mutations: CrudEntry[];
696
+ count: number;
697
+ };
698
+ /**
699
+ * Hook to check if sync is currently active.
700
+ *
701
+ * @returns Whether sync is currently in progress (uploading or downloading)
702
+ *
703
+ * @example
704
+ * ```typescript
705
+ * function SyncButton() {
706
+ * const isSyncing = useIsSyncing();
707
+ * const { triggerSync } = useSyncControl();
708
+ *
709
+ * return (
710
+ * <Button
711
+ * onPress={triggerSync}
712
+ * disabled={isSyncing}
713
+ * >
714
+ * {isSyncing ? 'Syncing...' : 'Sync Now'}
715
+ * </Button>
716
+ * );
717
+ * }
718
+ * ```
719
+ */
720
+ declare function useIsSyncing(): boolean;
721
+ /**
722
+ * Hook to get download progress during sync.
723
+ *
724
+ * @returns Download progress or null if not downloading
725
+ *
726
+ * @example
727
+ * ```typescript
728
+ * function DownloadProgress() {
729
+ * const progress = useDownloadProgress();
730
+ *
731
+ * if (!progress) return null;
732
+ *
733
+ * return (
734
+ * <ProgressBar
735
+ * value={progress.percentage}
736
+ * label={`${progress.current}/${progress.target} operations`}
737
+ * />
738
+ * );
739
+ * }
740
+ * ```
741
+ */
742
+ declare function useDownloadProgress(): DownloadProgress;
743
+ /**
744
+ * Return type for useEntitySyncStatus hook.
745
+ */
746
+ interface EntitySyncStatusResult {
747
+ /** Current sync state for this entity */
748
+ state: EntitySyncState;
749
+ /** Error details if state is 'error' */
750
+ error: SyncError | null;
751
+ /** Number of pending operations for this entity */
752
+ pendingOperations: number;
753
+ /** The failed transaction if any */
754
+ failedTransaction: FailedTransaction | null;
755
+ /** Dismiss the failure (remove from tracking) */
756
+ dismiss: () => void;
757
+ }
758
+ /**
759
+ * Hook to get sync status for a specific entity.
760
+ *
761
+ * Combines local mutation state (from pending mutations) with
762
+ * failure state to provide a unified status for UI.
763
+ *
764
+ * @param entityId - The entity ID to check status for
765
+ * @returns Unified sync state and actions
766
+ *
767
+ * @example
768
+ * ```typescript
769
+ * function EquipmentHeader({ unitId }) {
770
+ * const { state, error, dismiss } = useEntitySyncStatus(unitId);
771
+ *
772
+ * const borderColor = {
773
+ * idle: 'transparent',
774
+ * saving: 'orange',
775
+ * syncing: 'amber',
776
+ * synced: 'green',
777
+ * error: 'red',
778
+ * }[state];
779
+ * }
780
+ * ```
781
+ */
782
+ declare function useEntitySyncStatus(entityId: string | undefined): EntitySyncStatusResult;
783
+ /**
784
+ * Return type for useUploadStatus hook.
785
+ */
786
+ interface UploadStatusResult {
787
+ /** Number of operations waiting to upload */
788
+ pendingCount: number;
789
+ /** Number of failed transactions */
790
+ failedCount: number;
791
+ /** Number of permanent failures needing user action */
792
+ permanentFailureCount: number;
793
+ /** Whether there are any errors */
794
+ hasErrors: boolean;
795
+ /** Whether there are permanent errors needing attention */
796
+ hasPermanentErrors: boolean;
797
+ /** All failed transactions */
798
+ failedTransactions: FailedTransaction[];
799
+ /** Trigger sync retry (reconnect) */
800
+ retryAll: () => Promise<void>;
801
+ /** Dismiss all failures */
802
+ dismissAll: () => void;
803
+ }
804
+ /**
805
+ * Hook to get overall upload status across all entities.
806
+ *
807
+ * @returns Upload status with counts and actions
808
+ *
809
+ * @example
810
+ * ```typescript
811
+ * function SyncStatusBar() {
812
+ * const { pendingCount, failedCount, hasPermanentErrors, retryAll } = useUploadStatus();
813
+ *
814
+ * if (hasPermanentErrors) {
815
+ * return <Banner onRetry={retryAll}>
816
+ * {failedCount} changes failed to sync
817
+ * </Banner>;
818
+ * }
819
+ * }
820
+ * ```
821
+ */
822
+ declare function useUploadStatus(): UploadStatusResult;
823
+ /**
824
+ * Return type for useSyncActivity hook.
825
+ */
826
+ interface SyncActivityResult {
827
+ /** Pending CRUD entries waiting to be synced */
828
+ pending: CrudEntry[];
829
+ /** Failed transactions that need attention */
830
+ failed: FailedTransaction[];
831
+ /** Recently completed transactions */
832
+ completed: CompletedTransaction[];
833
+ /** Counts summary */
834
+ counts: {
835
+ pending: number;
836
+ failed: number;
837
+ completed: number;
838
+ };
839
+ /** Whether there is any sync activity to show (pending or failed) */
840
+ hasActivity: boolean;
841
+ /** Retry all failed transactions */
842
+ retryAll: () => Promise<void>;
843
+ /** Dismiss a specific failure */
844
+ dismissFailure: (failureId: string) => void;
845
+ /** Clear all completed transactions from the list */
846
+ clearCompleted: () => void;
847
+ }
848
+ /**
849
+ * Hook to get comprehensive sync activity including pending, failed, and completed transactions.
850
+ *
851
+ * Uses the provider's completed transaction tracking via the status tracker.
852
+ *
853
+ * @returns Sync activity with all transaction states and actions
854
+ *
855
+ * @example
856
+ * ```typescript
857
+ * function SyncActivityBanner() {
858
+ * const { pending, failed, completed, counts, hasActivity, retryAll, clearCompleted } = useSyncActivity();
859
+ *
860
+ * if (!hasActivity && completed.length === 0) return null;
861
+ *
862
+ * return (
863
+ * <View>
864
+ * <Text>{counts.pending} syncing, {counts.failed} failed</Text>
865
+ * {failed.length > 0 && <Button onPress={retryAll}>Retry All</Button>}
866
+ * </View>
867
+ * );
868
+ * }
869
+ * ```
870
+ */
871
+ declare function useSyncActivity(): SyncActivityResult;
872
+
873
+ export { AttachmentQueueContext, ConnectionHealthContext, type ConnectionHealthContextValue, DEFAULT_CONNECTION_HEALTH, DEFAULT_SYNC_CONFIG, DEFAULT_SYNC_METRICS, DEFAULT_SYNC_STATUS, type EntitySyncStatusResult, type PowerSyncConfig, PowerSyncContext, type PowerSyncContextValue, PowerSyncProvider, type PowerSyncProviderProps, type SyncActivityResult, type SyncConfig, SyncMetricsContext, type SyncMetricsContextValue, SyncStatusContext, type SyncStatusContextValue, type UploadStatusResult, useAttachmentQueue, useConnectionHealth, useDatabase, useDownloadProgress, useEntitySyncStatus, useIsSyncing, useOnlineStatus, usePendingMutations, usePlatform, usePowerSync, useSyncActivity, useSyncControl, useSyncMetrics, useSyncMode, useSyncStatus, useUploadStatus };