@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.
- package/dist/CacheSettingsManager-1exbOC6S.d.ts +261 -0
- package/dist/attachments/index.d.ts +65 -355
- package/dist/attachments/index.js +24 -6
- package/dist/{types-Cd7RhNqf.d.ts → background-sync-ChCXW-EV.d.ts} +53 -2
- package/dist/chunk-4C3RY5SU.js +204 -0
- package/dist/chunk-4C3RY5SU.js.map +1 -0
- package/dist/{chunk-3AYXHQ4W.js → chunk-53WH2JJV.js} +111 -47
- package/dist/chunk-53WH2JJV.js.map +1 -0
- package/dist/chunk-A4IBBWGO.js +377 -0
- package/dist/chunk-A4IBBWGO.js.map +1 -0
- package/dist/chunk-BREGB4WL.js +1768 -0
- package/dist/chunk-BREGB4WL.js.map +1 -0
- package/dist/{chunk-EJ23MXPQ.js → chunk-CGL33PL4.js} +3 -1
- package/dist/chunk-CGL33PL4.js.map +1 -0
- package/dist/chunk-DGUM43GV.js +11 -0
- package/dist/chunk-DHYUBVP7.js +131 -0
- package/dist/chunk-DHYUBVP7.js.map +1 -0
- package/dist/chunk-FV2HXEIY.js +124 -0
- package/dist/chunk-FV2HXEIY.js.map +1 -0
- package/dist/chunk-GKF7TOMT.js +1 -0
- package/dist/{chunk-OTJXIRWX.js → chunk-H772V6XQ.js} +304 -51
- package/dist/chunk-H772V6XQ.js.map +1 -0
- package/dist/{chunk-C2RSTGDC.js → chunk-HFOFLW5F.js} +525 -87
- package/dist/chunk-HFOFLW5F.js.map +1 -0
- package/dist/chunk-KGSFAE5B.js +1 -0
- package/dist/chunk-LNL64IJZ.js +1 -0
- package/dist/chunk-MKD2VCX3.js +32 -0
- package/dist/chunk-MKD2VCX3.js.map +1 -0
- package/dist/{chunk-7EMDVIZX.js → chunk-N75DEF5J.js} +19 -1
- package/dist/chunk-N75DEF5J.js.map +1 -0
- package/dist/chunk-P6WOZO7H.js +49 -0
- package/dist/chunk-P6WOZO7H.js.map +1 -0
- package/dist/chunk-TGBT5XBE.js +1 -0
- package/dist/chunk-TGBT5XBE.js.map +1 -0
- package/dist/chunk-UEYRTLKE.js +72 -0
- package/dist/chunk-UEYRTLKE.js.map +1 -0
- package/dist/chunk-WGHNIAF7.js +329 -0
- package/dist/chunk-WGHNIAF7.js.map +1 -0
- package/dist/chunk-WQ5MPAVC.js +449 -0
- package/dist/chunk-WQ5MPAVC.js.map +1 -0
- package/dist/{chunk-FPTDATY5.js → chunk-XQAJM2MW.js} +22 -11
- package/dist/chunk-XQAJM2MW.js.map +1 -0
- package/dist/chunk-YSTEESEG.js +676 -0
- package/dist/chunk-YSTEESEG.js.map +1 -0
- package/dist/chunk-ZEOKPWUC.js +1165 -0
- package/dist/chunk-ZEOKPWUC.js.map +1 -0
- package/dist/connector/index.d.ts +182 -2
- package/dist/connector/index.js +14 -3
- package/dist/core/index.d.ts +5 -3
- package/dist/core/index.js +5 -2
- package/dist/error/index.d.ts +54 -0
- package/dist/error/index.js +8 -0
- package/dist/error/index.js.map +1 -0
- package/dist/index.d.ts +237 -11
- package/dist/index.js +183 -27
- package/dist/index.native.d.ts +20 -9
- package/dist/index.native.js +183 -28
- package/dist/index.web.d.ts +20 -9
- package/dist/index.web.js +184 -28
- package/dist/maintenance/index.d.ts +118 -0
- package/dist/maintenance/index.js +17 -0
- package/dist/maintenance/index.js.map +1 -0
- package/dist/platform/index.d.ts +16 -1
- package/dist/platform/index.js +2 -0
- package/dist/platform/index.js.map +1 -1
- package/dist/platform/index.native.d.ts +2 -2
- package/dist/platform/index.native.js +2 -1
- package/dist/platform/index.web.d.ts +1 -1
- package/dist/platform/index.web.js +2 -1
- package/dist/pol-attachment-queue-C7YNXXhK.d.ts +676 -0
- package/dist/provider/index.d.ts +693 -12
- package/dist/provider/index.js +57 -12
- package/dist/storage/index.d.ts +6 -0
- package/dist/storage/index.js +28 -0
- package/dist/storage/index.js.map +1 -0
- package/dist/storage/index.native.d.ts +6 -0
- package/dist/storage/index.native.js +26 -0
- package/dist/storage/index.native.js.map +1 -0
- package/dist/storage/index.web.d.ts +6 -0
- package/dist/storage/index.web.js +26 -0
- package/dist/storage/index.web.js.map +1 -0
- package/dist/storage/upload/index.d.ts +55 -0
- package/dist/storage/upload/index.js +15 -0
- package/dist/storage/upload/index.js.map +1 -0
- package/dist/storage/upload/index.native.d.ts +57 -0
- package/dist/storage/upload/index.native.js +14 -0
- package/dist/storage/upload/index.native.js.map +1 -0
- package/dist/storage/upload/index.web.d.ts +5 -0
- package/dist/storage/upload/index.web.js +14 -0
- package/dist/storage/upload/index.web.js.map +1 -0
- package/dist/{index-Cb-NI0Ct.d.ts → supabase-connector-qLm-WHkM.d.ts} +146 -10
- package/dist/sync/index.d.ts +288 -22
- package/dist/sync/index.js +23 -5
- package/dist/types-BVacP54t.d.ts +52 -0
- package/dist/types-Bgvx7-E8.d.ts +187 -0
- package/dist/{types-afHtE1U_.d.ts → types-CDqWh56B.d.ts} +2 -0
- package/package.json +72 -2
- package/dist/chunk-32OLICZO.js +0 -1
- package/dist/chunk-3AYXHQ4W.js.map +0 -1
- package/dist/chunk-7EMDVIZX.js.map +0 -1
- package/dist/chunk-7JQZBZ5N.js +0 -1
- package/dist/chunk-C2RSTGDC.js.map +0 -1
- package/dist/chunk-EJ23MXPQ.js.map +0 -1
- package/dist/chunk-FPTDATY5.js.map +0 -1
- package/dist/chunk-GMFDCVMZ.js +0 -1285
- package/dist/chunk-GMFDCVMZ.js.map +0 -1
- package/dist/chunk-OLHGI472.js +0 -1
- package/dist/chunk-OTJXIRWX.js.map +0 -1
- package/dist/chunk-V6LJ6MR2.js +0 -740
- package/dist/chunk-V6LJ6MR2.js.map +0 -1
- package/dist/chunk-VJCL2SWD.js +0 -1
- /package/dist/{chunk-32OLICZO.js.map → chunk-DGUM43GV.js.map} +0 -0
- /package/dist/{chunk-7JQZBZ5N.js.map → chunk-GKF7TOMT.js.map} +0 -0
- /package/dist/{chunk-OLHGI472.js.map → chunk-KGSFAE5B.js.map} +0 -0
- /package/dist/{chunk-VJCL2SWD.js.map → chunk-LNL64IJZ.js.map} +0 -0
package/dist/provider/index.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { SupabaseClient } from '@supabase/supabase-js';
|
|
2
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-
|
|
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-CDqWh56B.js';
|
|
4
4
|
import { PlatformAdapter } from '../platform/index.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { b as ConnectorConfig, S as SupabaseConnector, g as ConflictBus } from '../supabase-connector-qLm-WHkM.js';
|
|
6
|
+
import { j as PolAttachmentQueueConfig, P as PolAttachmentQueue } from '../pol-attachment-queue-C7YNXXhK.js';
|
|
7
7
|
import * as react from 'react';
|
|
8
|
-
import react__default from 'react';
|
|
9
|
-
import {
|
|
8
|
+
import react__default, { ReactNode } from 'react';
|
|
9
|
+
import { Schema } from '@powersync/react-native';
|
|
10
|
+
import { R as RemoteStorageAdapter, A as AttachmentUploadHandler } from '../types-Bgvx7-E8.js';
|
|
11
|
+
import { h as BackgroundSyncSystem, c as SyncControlActions } from '../background-sync-ChCXW-EV.js';
|
|
12
|
+
import '@powersync/attachments';
|
|
13
|
+
import '@powersync/common';
|
|
10
14
|
|
|
11
15
|
/**
|
|
12
16
|
* Provider Types for @pol-studios/powersync
|
|
@@ -70,8 +74,16 @@ interface PowerSyncConfig<TSchema = unknown> {
|
|
|
70
74
|
connector?: ConnectorConfig;
|
|
71
75
|
/**
|
|
72
76
|
* Optional: Attachment queue configuration for offline file caching.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* attachments: {
|
|
81
|
+
* source: { table: 'photos', idColumn: 'storage_path' },
|
|
82
|
+
* remoteStorage: supabaseStorageAdapter,
|
|
83
|
+
* }
|
|
84
|
+
* ```
|
|
73
85
|
*/
|
|
74
|
-
attachments?:
|
|
86
|
+
attachments?: PolAttachmentQueueConfig;
|
|
75
87
|
/**
|
|
76
88
|
* Optional: Sync behavior configuration.
|
|
77
89
|
*/
|
|
@@ -123,7 +135,7 @@ interface PowerSyncContextValue<TSchema = unknown> {
|
|
|
123
135
|
* The attachment queue instance.
|
|
124
136
|
* Will be null if attachments are not configured or not initialized.
|
|
125
137
|
*/
|
|
126
|
-
attachmentQueue:
|
|
138
|
+
attachmentQueue: PolAttachmentQueue | null;
|
|
127
139
|
/**
|
|
128
140
|
* Whether the PowerSync database is ready for use.
|
|
129
141
|
*/
|
|
@@ -132,6 +144,17 @@ interface PowerSyncContextValue<TSchema = unknown> {
|
|
|
132
144
|
* Whether the provider is currently initializing.
|
|
133
145
|
*/
|
|
134
146
|
isInitializing: boolean;
|
|
147
|
+
/**
|
|
148
|
+
* Whether the attachment queue is ready for use.
|
|
149
|
+
* This is separate from isReady because the attachment queue initializes
|
|
150
|
+
* asynchronously after the database is ready.
|
|
151
|
+
*
|
|
152
|
+
* States:
|
|
153
|
+
* - `false`: Attachment queue is still initializing
|
|
154
|
+
* - `true` with `attachmentQueue !== null`: Ready and available
|
|
155
|
+
* - `true` with `attachmentQueue === null`: Either attachments not configured, OR initialization failed
|
|
156
|
+
*/
|
|
157
|
+
attachmentQueueReady: boolean;
|
|
135
158
|
/**
|
|
136
159
|
* Error that occurred during initialization, if any.
|
|
137
160
|
*/
|
|
@@ -191,7 +214,7 @@ interface SyncStatusContextValue {
|
|
|
191
214
|
/**
|
|
192
215
|
* Error that occurred during connection, if any.
|
|
193
216
|
*/
|
|
194
|
-
connectionError
|
|
217
|
+
connectionError: Error | null;
|
|
195
218
|
/**
|
|
196
219
|
* Failed transactions that need attention.
|
|
197
220
|
*/
|
|
@@ -242,6 +265,145 @@ interface SyncStatusContextValue {
|
|
|
242
265
|
* @throws Error if upload is in progress
|
|
243
266
|
*/
|
|
244
267
|
discardAllPendingMutations: () => Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Pause automatic retry of failed uploads.
|
|
270
|
+
* Useful when user is actively resolving conflicts.
|
|
271
|
+
*/
|
|
272
|
+
pauseAutoRetry: () => void;
|
|
273
|
+
/**
|
|
274
|
+
* Resume automatic retry of failed uploads.
|
|
275
|
+
*/
|
|
276
|
+
resumeAutoRetry: () => void;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Connection state - changes rarely (on connect/disconnect).
|
|
280
|
+
* Use this for components that only need to display connection status.
|
|
281
|
+
*/
|
|
282
|
+
interface ConnectionStatusContextValue {
|
|
283
|
+
/** Whether connected to the PowerSync service */
|
|
284
|
+
connected: boolean;
|
|
285
|
+
/** Whether currently attempting to connect */
|
|
286
|
+
connecting: boolean;
|
|
287
|
+
/** Whether initial sync has completed */
|
|
288
|
+
hasSynced: boolean;
|
|
289
|
+
/** Timestamp of last successful sync */
|
|
290
|
+
lastSyncedAt: Date | null;
|
|
291
|
+
/** Error that occurred during connection, if any */
|
|
292
|
+
connectionError: Error | null;
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* Sync activity - changes during active sync.
|
|
296
|
+
* Use this for components that display sync progress.
|
|
297
|
+
*/
|
|
298
|
+
interface SyncActivityContextValue {
|
|
299
|
+
/** Whether data is currently being uploaded to the server */
|
|
300
|
+
uploading: boolean;
|
|
301
|
+
/** Whether data is currently being downloaded from the server */
|
|
302
|
+
downloading: boolean;
|
|
303
|
+
/** Download progress details */
|
|
304
|
+
downloadProgress: DownloadProgress | null;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Pending mutations - changes on local writes.
|
|
308
|
+
* Use this for components that display pending upload count or list.
|
|
309
|
+
*/
|
|
310
|
+
interface PendingMutationsContextValue {
|
|
311
|
+
/** Pending mutations waiting to be uploaded */
|
|
312
|
+
pendingMutations: CrudEntry[];
|
|
313
|
+
/** Number of pending mutations */
|
|
314
|
+
pendingCount: number;
|
|
315
|
+
/** Discard a specific pending mutation by its client ID */
|
|
316
|
+
discardPendingMutation: (clientId: number) => Promise<void>;
|
|
317
|
+
/** Discard all pending mutations */
|
|
318
|
+
discardAllPendingMutations: () => Promise<void>;
|
|
319
|
+
/**
|
|
320
|
+
* Add a pending mutation to the list.
|
|
321
|
+
* Called by mutation hooks (useDbInsert, useDbUpdate, useDbDelete, useDbUpsert)
|
|
322
|
+
* after a successful write. Includes createdAt timestamp for display.
|
|
323
|
+
*/
|
|
324
|
+
addPendingMutation: (entry: CrudEntry) => void;
|
|
325
|
+
/**
|
|
326
|
+
* Remove a pending mutation by its entity ID.
|
|
327
|
+
* Called when a transaction completes sync.
|
|
328
|
+
*/
|
|
329
|
+
removePendingMutation: (id: string) => void;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Failed transactions - changes on failures.
|
|
333
|
+
* Use this for components that display sync errors.
|
|
334
|
+
*/
|
|
335
|
+
interface FailedTransactionsContextValue {
|
|
336
|
+
/** Failed transactions that need attention */
|
|
337
|
+
failedTransactions: FailedTransaction[];
|
|
338
|
+
/** Whether there are any upload errors */
|
|
339
|
+
hasUploadErrors: boolean;
|
|
340
|
+
/** Count of permanent errors that need user action */
|
|
341
|
+
permanentErrorCount: number;
|
|
342
|
+
/** Clear a specific failure by its ID */
|
|
343
|
+
clearFailure: (failureId: string) => void;
|
|
344
|
+
/** Clear all failures */
|
|
345
|
+
clearAllFailures: () => void;
|
|
346
|
+
/** Pause automatic retry of failed uploads */
|
|
347
|
+
pauseAutoRetry: () => void;
|
|
348
|
+
/** Resume automatic retry of failed uploads */
|
|
349
|
+
resumeAutoRetry: () => void;
|
|
350
|
+
/**
|
|
351
|
+
* Retry a specific failed transaction.
|
|
352
|
+
*
|
|
353
|
+
* This removes the failure from tracking and triggers a sync.
|
|
354
|
+
* The actual CRUD entries remain in PowerSync's queue - this just
|
|
355
|
+
* clears our error tracking so the sync can retry them.
|
|
356
|
+
*
|
|
357
|
+
* If the sync fails to start, the failure is re-recorded.
|
|
358
|
+
*/
|
|
359
|
+
retryFailure: (failureId: string) => Promise<void>;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Completed transactions - changes on successful syncs.
|
|
363
|
+
* Use this for components that display sync history.
|
|
364
|
+
*/
|
|
365
|
+
interface CompletedTransactionsContextValue {
|
|
366
|
+
/** Recently completed transactions */
|
|
367
|
+
completedTransactions: CompletedTransaction[];
|
|
368
|
+
/** Clear the completed transaction history */
|
|
369
|
+
clearCompletedHistory: () => void;
|
|
370
|
+
/** Clear a specific completed transaction by ID */
|
|
371
|
+
clearCompletedItem: (completedId: string) => void;
|
|
372
|
+
/**
|
|
373
|
+
* Completed transactions that occurred AFTER the last notification display.
|
|
374
|
+
* Use this for toast/banner notifications to avoid showing stale historical counts.
|
|
375
|
+
*/
|
|
376
|
+
newCompletedTransactions: CompletedTransaction[];
|
|
377
|
+
/**
|
|
378
|
+
* Mark notifications as seen (updates the lastNotificationTime).
|
|
379
|
+
* Call this when a sync notification is displayed or auto-dismissed.
|
|
380
|
+
*/
|
|
381
|
+
markNotificationsAsSeen: () => void;
|
|
382
|
+
}
|
|
383
|
+
/**
|
|
384
|
+
* Sync mode control - changes rarely (user action).
|
|
385
|
+
* Use this for components that display/control sync mode.
|
|
386
|
+
*/
|
|
387
|
+
interface SyncModeContextValue {
|
|
388
|
+
/** Current sync mode */
|
|
389
|
+
syncMode: SyncMode;
|
|
390
|
+
/** Whether sync is currently paused (offline mode) */
|
|
391
|
+
isPaused: boolean;
|
|
392
|
+
/**
|
|
393
|
+
* Whether offline mode was automatically set due to network loss.
|
|
394
|
+
* When true, sync will auto-resume when network returns.
|
|
395
|
+
* When false (user manually chose offline), sync won't auto-resume.
|
|
396
|
+
*/
|
|
397
|
+
isAutoOffline: boolean;
|
|
398
|
+
/**
|
|
399
|
+
* Whether the network is currently reachable.
|
|
400
|
+
* This is used as a gate to block uploads even when syncMode is 'push-pull'.
|
|
401
|
+
*/
|
|
402
|
+
networkReachable: boolean;
|
|
403
|
+
/** Set the sync mode (manual - won't auto-resume) */
|
|
404
|
+
setSyncMode: (mode: SyncMode) => Promise<void>;
|
|
405
|
+
/** Set the force next upload flag */
|
|
406
|
+
setForceNextUpload: (force: boolean) => void;
|
|
245
407
|
}
|
|
246
408
|
/**
|
|
247
409
|
* Value provided by ConnectionHealthContext.
|
|
@@ -335,6 +497,36 @@ declare const PowerSyncContext: react.Context<PowerSyncContextValue<unknown>>;
|
|
|
335
497
|
* ```
|
|
336
498
|
*/
|
|
337
499
|
declare const SyncStatusContext: react.Context<SyncStatusContextValue>;
|
|
500
|
+
/**
|
|
501
|
+
* Context for connection status only.
|
|
502
|
+
* Subscribe to this instead of SyncStatusContext when you only need connection state.
|
|
503
|
+
*/
|
|
504
|
+
declare const ConnectionStatusContext: react.Context<ConnectionStatusContextValue>;
|
|
505
|
+
/**
|
|
506
|
+
* Context for sync activity (uploading/downloading).
|
|
507
|
+
* Subscribe to this instead of SyncStatusContext when you only need sync progress.
|
|
508
|
+
*/
|
|
509
|
+
declare const SyncActivityContext: react.Context<SyncActivityContextValue>;
|
|
510
|
+
/**
|
|
511
|
+
* Context for pending mutations.
|
|
512
|
+
* Subscribe to this instead of SyncStatusContext when you only need pending upload info.
|
|
513
|
+
*/
|
|
514
|
+
declare const PendingMutationsContext: react.Context<PendingMutationsContextValue>;
|
|
515
|
+
/**
|
|
516
|
+
* Context for failed transactions.
|
|
517
|
+
* Subscribe to this instead of SyncStatusContext when you only need error info.
|
|
518
|
+
*/
|
|
519
|
+
declare const FailedTransactionsContext: react.Context<FailedTransactionsContextValue>;
|
|
520
|
+
/**
|
|
521
|
+
* Context for completed transactions.
|
|
522
|
+
* Subscribe to this instead of SyncStatusContext when you only need sync history.
|
|
523
|
+
*/
|
|
524
|
+
declare const CompletedTransactionsContext: react.Context<CompletedTransactionsContextValue>;
|
|
525
|
+
/**
|
|
526
|
+
* Context for sync mode control.
|
|
527
|
+
* Subscribe to this instead of SyncStatusContext when you only need sync mode.
|
|
528
|
+
*/
|
|
529
|
+
declare const SyncModeContext: react.Context<SyncModeContextValue>;
|
|
338
530
|
/**
|
|
339
531
|
* Context for connection health monitoring.
|
|
340
532
|
*
|
|
@@ -386,7 +578,7 @@ declare const SyncMetricsContext: react.Context<SyncMetricsContextValue>;
|
|
|
386
578
|
* }
|
|
387
579
|
* ```
|
|
388
580
|
*/
|
|
389
|
-
declare const AttachmentQueueContext: react.Context<
|
|
581
|
+
declare const AttachmentQueueContext: react.Context<PolAttachmentQueue>;
|
|
390
582
|
|
|
391
583
|
/**
|
|
392
584
|
* PowerSyncProvider Component for @pol-studios/powersync
|
|
@@ -431,6 +623,313 @@ declare const AttachmentQueueContext: react.Context<AttachmentQueue>;
|
|
|
431
623
|
*/
|
|
432
624
|
declare function PowerSyncProvider<TSchema = unknown>({ config, children, onReady, onError, onSyncStatusChange, }: PowerSyncProviderProps<TSchema>): react__default.ReactElement;
|
|
433
625
|
|
|
626
|
+
/**
|
|
627
|
+
* Configuration for @pol-studios/db DataLayerProvider integration.
|
|
628
|
+
* This allows OfflineDataProvider to wrap and configure the DataLayerProvider.
|
|
629
|
+
*/
|
|
630
|
+
interface DataLayerConfig {
|
|
631
|
+
/**
|
|
632
|
+
* Entity schemas that define tables and relationships.
|
|
633
|
+
* This is passed directly to DataLayerProvider.
|
|
634
|
+
*/
|
|
635
|
+
schema: Record<string, unknown>;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Data layer integration configuration.
|
|
639
|
+
*/
|
|
640
|
+
interface DataLayerIntegration {
|
|
641
|
+
/** DataLayer configuration */
|
|
642
|
+
config: DataLayerConfig;
|
|
643
|
+
/** Skip rendering DataLayerProvider (default: false) */
|
|
644
|
+
skip?: boolean;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Callbacks for background sync lifecycle events.
|
|
648
|
+
*/
|
|
649
|
+
interface BackgroundSyncCallbacks {
|
|
650
|
+
/** Called when background sync starts */
|
|
651
|
+
onSyncStart?: () => void;
|
|
652
|
+
/** Called when background sync completes successfully */
|
|
653
|
+
onSyncComplete?: () => void;
|
|
654
|
+
/** Called when background sync fails */
|
|
655
|
+
onSyncError?: (error: Error) => void;
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Background sync configuration.
|
|
659
|
+
*/
|
|
660
|
+
interface BackgroundSyncConfig {
|
|
661
|
+
/** Enable background sync */
|
|
662
|
+
enabled: boolean;
|
|
663
|
+
/** Minimum interval between background syncs in minutes (default: 15) */
|
|
664
|
+
minimumInterval?: number;
|
|
665
|
+
/** Callbacks for sync lifecycle events */
|
|
666
|
+
callbacks?: BackgroundSyncCallbacks;
|
|
667
|
+
}
|
|
668
|
+
/**
|
|
669
|
+
* Status reported by background sync.
|
|
670
|
+
* Compatible with the status callback in BackgroundSyncSystem.
|
|
671
|
+
*/
|
|
672
|
+
interface BackgroundSyncStatus {
|
|
673
|
+
/** Last successful sync timestamp */
|
|
674
|
+
lastSyncedAt?: Date | null;
|
|
675
|
+
/** Whether currently downloading */
|
|
676
|
+
downloading: boolean;
|
|
677
|
+
/** Whether currently uploading */
|
|
678
|
+
uploading: boolean;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* Snapshot of PowerSync sync status for passing to DataLayerProvider.
|
|
682
|
+
*/
|
|
683
|
+
interface PowerSyncSyncStatusSnapshot {
|
|
684
|
+
/** Whether initial sync has completed */
|
|
685
|
+
hasSynced: boolean;
|
|
686
|
+
/** Whether connected to the PowerSync service */
|
|
687
|
+
connected: boolean;
|
|
688
|
+
/** Whether currently attempting to connect */
|
|
689
|
+
connecting: boolean;
|
|
690
|
+
/** Whether the device is online (from platform adapter) */
|
|
691
|
+
isOnline: boolean;
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Attachment configuration for OfflineDataProvider
|
|
695
|
+
*/
|
|
696
|
+
interface OfflineDataAttachmentConfig {
|
|
697
|
+
/** Storage bucket name */
|
|
698
|
+
bucket: string;
|
|
699
|
+
/** Source table for attachments */
|
|
700
|
+
sourceTable: string;
|
|
701
|
+
/** Column containing the storage path/ID */
|
|
702
|
+
idColumn: string;
|
|
703
|
+
/** Optional: Column to order downloads by */
|
|
704
|
+
orderByColumn?: string;
|
|
705
|
+
/** Optional: Filter configuration */
|
|
706
|
+
projectFilter?: {
|
|
707
|
+
foreignKey: string;
|
|
708
|
+
intermediaryTable: string;
|
|
709
|
+
projectForeignKey: string;
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
/**
|
|
713
|
+
* Configuration for OfflineDataProvider
|
|
714
|
+
*/
|
|
715
|
+
interface OfflineDataProviderConfig {
|
|
716
|
+
/** PowerSync schema definition */
|
|
717
|
+
schema: Schema;
|
|
718
|
+
/** Supabase client instance */
|
|
719
|
+
supabaseClient: SupabaseClient;
|
|
720
|
+
/** React Query client */
|
|
721
|
+
queryClient: QueryClient;
|
|
722
|
+
/** PowerSync service URL (if missing, runs in online-only mode) */
|
|
723
|
+
powerSyncUrl?: string;
|
|
724
|
+
/** Database filename (default: 'powersync.db') */
|
|
725
|
+
dbFilename?: string;
|
|
726
|
+
/** Attachment configuration */
|
|
727
|
+
attachments?: OfflineDataAttachmentConfig;
|
|
728
|
+
/** Platform adapter (created automatically if not provided) */
|
|
729
|
+
platform?: PlatformAdapter;
|
|
730
|
+
/** Custom connector configuration for CRUD handling */
|
|
731
|
+
connector?: {
|
|
732
|
+
/** Schema router function for table-specific schema lookups */
|
|
733
|
+
schemaRouter?: (table: string) => unknown;
|
|
734
|
+
/** Enable conflict detection */
|
|
735
|
+
conflictDetection?: {
|
|
736
|
+
enabled: boolean;
|
|
737
|
+
};
|
|
738
|
+
};
|
|
739
|
+
/** Sync behavior configuration */
|
|
740
|
+
sync?: {
|
|
741
|
+
/** Automatically connect when the provider mounts and there's an authenticated session */
|
|
742
|
+
autoConnect?: boolean;
|
|
743
|
+
/** Enable health monitoring */
|
|
744
|
+
enableHealthMonitoring?: boolean;
|
|
745
|
+
/** Enable metrics collection */
|
|
746
|
+
enableMetrics?: boolean;
|
|
747
|
+
};
|
|
748
|
+
}
|
|
749
|
+
/**
|
|
750
|
+
* Props for OfflineDataProvider
|
|
751
|
+
*/
|
|
752
|
+
interface OfflineDataProviderProps {
|
|
753
|
+
/** Provider configuration */
|
|
754
|
+
config: OfflineDataProviderConfig;
|
|
755
|
+
children: ReactNode;
|
|
756
|
+
/**
|
|
757
|
+
* DataLayer configuration for @pol-studios/db integration.
|
|
758
|
+
* When provided, OfflineDataProvider wraps children with DataLayerProvider
|
|
759
|
+
* and automatically bridges PowerSync context to it.
|
|
760
|
+
*/
|
|
761
|
+
dataLayer?: DataLayerIntegration;
|
|
762
|
+
/**
|
|
763
|
+
* Background sync configuration.
|
|
764
|
+
* When enabled, sets up background sync system for iOS/Android.
|
|
765
|
+
*/
|
|
766
|
+
backgroundSync?: BackgroundSyncConfig;
|
|
767
|
+
/** Skip rendering ConflictProvider (default: false) */
|
|
768
|
+
skipConflictProvider?: boolean;
|
|
769
|
+
/** Skip rendering StorageQueueProvider (default: false) */
|
|
770
|
+
skipStorageQueueProvider?: boolean;
|
|
771
|
+
/** Custom storage adapter (overrides built-in Supabase adapter) */
|
|
772
|
+
storageAdapter?: RemoteStorageAdapter;
|
|
773
|
+
/** Custom upload handler */
|
|
774
|
+
uploadHandler?: AttachmentUploadHandler;
|
|
775
|
+
/** Custom error UI for initialization errors */
|
|
776
|
+
renderInitError?: (error: Error, retry: () => void) => ReactNode;
|
|
777
|
+
/**
|
|
778
|
+
* Custom error UI (alias for renderInitError for backward compatibility)
|
|
779
|
+
* @deprecated Use renderInitError instead
|
|
780
|
+
*/
|
|
781
|
+
renderError?: (error: Error, retry: () => void) => ReactNode;
|
|
782
|
+
onReady?: () => void;
|
|
783
|
+
onError?: (error: Error) => void;
|
|
784
|
+
onSyncStatusChange?: (status: PowerSyncSyncStatusSnapshot) => void;
|
|
785
|
+
/**
|
|
786
|
+
* Called when the background sync system is ready.
|
|
787
|
+
* Use this to set up app-level background sync via defineBackgroundSyncTask.
|
|
788
|
+
*/
|
|
789
|
+
onBackgroundSyncSystemReady?: (system: BackgroundSyncSystem) => void;
|
|
790
|
+
}
|
|
791
|
+
/**
|
|
792
|
+
* Props for the internal ProviderBridge component.
|
|
793
|
+
*/
|
|
794
|
+
interface ProviderBridgeProps {
|
|
795
|
+
children: ReactNode;
|
|
796
|
+
/** Skip ConflictProvider */
|
|
797
|
+
skipConflictProvider?: boolean;
|
|
798
|
+
/** Skip StorageQueueProvider */
|
|
799
|
+
skipStorageQueueProvider?: boolean;
|
|
800
|
+
/** Background sync configuration */
|
|
801
|
+
backgroundSync?: BackgroundSyncConfig;
|
|
802
|
+
/** Callback for background sync system setup */
|
|
803
|
+
onBackgroundSyncSystemReady?: (system: BackgroundSyncSystem | null) => void;
|
|
804
|
+
/** Called once when db becomes ready, with the db instance and initial sync status */
|
|
805
|
+
onDbReady: (db: AbstractPowerSyncDatabase | null, syncStatus: PowerSyncSyncStatusSnapshot) => void;
|
|
806
|
+
/** Called whenever sync status changes after initial readiness */
|
|
807
|
+
onSyncStatusChange: (syncStatus: PowerSyncSyncStatusSnapshot) => void;
|
|
808
|
+
/** Called with the addPendingMutation function once available */
|
|
809
|
+
onAddPendingMutationReady: (add: (entry: CrudEntry) => void) => void;
|
|
810
|
+
/** Called with the removePendingMutation function once available */
|
|
811
|
+
onRemovePendingMutationReady: (remove: (id: string) => void) => void;
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* OfflineDataProvider Component for @pol-studios/powersync
|
|
816
|
+
*
|
|
817
|
+
* Batteries-included offline data provider that combines:
|
|
818
|
+
* - PowerSyncProvider for offline-first data sync
|
|
819
|
+
* - DataLayerProvider integration from @pol-studios/db
|
|
820
|
+
* - ConflictProvider for conflict resolution UI
|
|
821
|
+
* - StorageQueueProvider for attachment queue access
|
|
822
|
+
* - Background sync system setup
|
|
823
|
+
* - Error recovery UI with retry capability
|
|
824
|
+
* - Online-only mode fallback (no PowerSync URL)
|
|
825
|
+
*
|
|
826
|
+
* This is the recommended entry point for apps using offline-first data.
|
|
827
|
+
*
|
|
828
|
+
* @example
|
|
829
|
+
* ```tsx
|
|
830
|
+
* <OfflineDataProvider
|
|
831
|
+
* config={{
|
|
832
|
+
* schema: AppSchema,
|
|
833
|
+
* supabaseClient: supabase,
|
|
834
|
+
* queryClient: queryClient,
|
|
835
|
+
* powerSyncUrl: env.powerSyncUrl,
|
|
836
|
+
* attachments: {
|
|
837
|
+
* bucket: 'my-bucket',
|
|
838
|
+
* sourceTable: 'MediaContent',
|
|
839
|
+
* idColumn: 'storagePath',
|
|
840
|
+
* },
|
|
841
|
+
* }}
|
|
842
|
+
* dataLayer={{ config: dataLayerConfig }}
|
|
843
|
+
* renderInitError={(error, retry) => <MyErrorUI error={error} onRetry={retry} />}
|
|
844
|
+
* >
|
|
845
|
+
* <App />
|
|
846
|
+
* </OfflineDataProvider>
|
|
847
|
+
* ```
|
|
848
|
+
*/
|
|
849
|
+
|
|
850
|
+
/**
|
|
851
|
+
* Batteries-included offline data provider.
|
|
852
|
+
*
|
|
853
|
+
* Combines PowerSyncProvider with error boundary, DataLayerProvider integration,
|
|
854
|
+
* and sensible defaults for a complete offline-first data solution.
|
|
855
|
+
*
|
|
856
|
+
* Key features:
|
|
857
|
+
* - Automatic PowerSync setup and initialization
|
|
858
|
+
* - Integration with @pol-studios/db DataLayerProvider
|
|
859
|
+
* - ConflictProvider and StorageQueueProvider wiring
|
|
860
|
+
* - Background sync system support
|
|
861
|
+
* - Error recovery UI with retry capability
|
|
862
|
+
* - Online-only mode fallback when no PowerSync URL is provided
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```tsx
|
|
866
|
+
* // Basic usage
|
|
867
|
+
* <OfflineDataProvider
|
|
868
|
+
* config={{
|
|
869
|
+
* schema: AppSchema,
|
|
870
|
+
* supabaseClient: supabase,
|
|
871
|
+
* queryClient: queryClient,
|
|
872
|
+
* powerSyncUrl: process.env.EXPO_PUBLIC_POWERSYNC_URL,
|
|
873
|
+
* }}
|
|
874
|
+
* >
|
|
875
|
+
* <App />
|
|
876
|
+
* </OfflineDataProvider>
|
|
877
|
+
*
|
|
878
|
+
* // With DataLayer integration
|
|
879
|
+
* <OfflineDataProvider
|
|
880
|
+
* config={{ ... }}
|
|
881
|
+
* dataLayer={{ config: dataLayerConfig }}
|
|
882
|
+
* >
|
|
883
|
+
* <App />
|
|
884
|
+
* </OfflineDataProvider>
|
|
885
|
+
*
|
|
886
|
+
* // With custom error UI
|
|
887
|
+
* <OfflineDataProvider
|
|
888
|
+
* config={{ ... }}
|
|
889
|
+
* renderInitError={(error, retry) => <MyErrorUI error={error} onRetry={retry} />}
|
|
890
|
+
* >
|
|
891
|
+
* <App />
|
|
892
|
+
* </OfflineDataProvider>
|
|
893
|
+
* ```
|
|
894
|
+
*/
|
|
895
|
+
declare function OfflineDataProvider({ config, children, dataLayer, backgroundSync, skipConflictProvider, skipStorageQueueProvider, storageAdapter: customStorageAdapter, uploadHandler: customUploadHandler, renderInitError, renderError, onReady, onError, onSyncStatusChange, onBackgroundSyncSystemReady: onBackgroundSyncSystemReadyProp, }: OfflineDataProviderProps): react__default.ReactElement;
|
|
896
|
+
|
|
897
|
+
/**
|
|
898
|
+
* ProviderBridge Component for @pol-studios/powersync
|
|
899
|
+
*
|
|
900
|
+
* Internal bridge component that connects PowerSync context to external providers:
|
|
901
|
+
* - DataLayerProvider from @pol-studios/db
|
|
902
|
+
* - ConflictProvider from @pol-studios/db
|
|
903
|
+
* - StorageQueueProvider from @pol-studios/db
|
|
904
|
+
*
|
|
905
|
+
* This component is used internally by OfflineDataProvider and should not be
|
|
906
|
+
* exported directly. It handles the complex wiring between packages.
|
|
907
|
+
*/
|
|
908
|
+
|
|
909
|
+
/**
|
|
910
|
+
* ProviderBridge connects the PowerSync package context to external providers
|
|
911
|
+
* like ConflictProvider and StorageQueueProvider from @pol-studios/db.
|
|
912
|
+
*
|
|
913
|
+
* This component:
|
|
914
|
+
* 1. Signals the parent when the db is ready (onDbReady)
|
|
915
|
+
* 2. Reports sync status changes (onSyncStatusChange)
|
|
916
|
+
* 3. Exposes pending mutation functions to parent (for DataLayerProvider)
|
|
917
|
+
* 4. Sets up background sync system when enabled
|
|
918
|
+
* 5. Wraps children with ConflictProvider and StorageQueueProvider
|
|
919
|
+
* 6. Exposes PowerSync db via native PowerSyncContext for SDK hooks
|
|
920
|
+
*
|
|
921
|
+
* IMPORTANT: DataLayerProvider is rendered OUTSIDE this component (in OfflineDataProvider)
|
|
922
|
+
* so it always exists in the React tree even before PowerSync is ready.
|
|
923
|
+
* This prevents "useDataLayer must be used within a DataLayerProvider" errors
|
|
924
|
+
* when routes mount before the db is initialized.
|
|
925
|
+
*
|
|
926
|
+
* CRITICAL: The conflictBus is created internally by PowerSyncProvider and
|
|
927
|
+
* passed to the connector. We MUST use the same bus instance from context
|
|
928
|
+
* for ConflictProvider, otherwise conflicts detected by the connector won't
|
|
929
|
+
* reach the UI components subscribed via ConflictProvider.
|
|
930
|
+
*/
|
|
931
|
+
declare function ProviderBridge({ children, skipConflictProvider, skipStorageQueueProvider, backgroundSync, onBackgroundSyncSystemReady, onDbReady, onSyncStatusChange, onAddPendingMutationReady, onRemovePendingMutationReady, }: ProviderBridgeProps): react__default.ReactElement | null;
|
|
932
|
+
|
|
434
933
|
/**
|
|
435
934
|
* Hook to access the PowerSync database and related services.
|
|
436
935
|
*
|
|
@@ -452,7 +951,17 @@ declare function PowerSyncProvider<TSchema = unknown>({ config, children, onRead
|
|
|
452
951
|
*/
|
|
453
952
|
declare function usePowerSync<TSchema = unknown>(): PowerSyncContextValue<TSchema>;
|
|
454
953
|
/**
|
|
455
|
-
*
|
|
954
|
+
* @deprecated This hook causes re-renders on any status change.
|
|
955
|
+
* Use focused hooks instead:
|
|
956
|
+
*
|
|
957
|
+
* | Old (useSyncStatus) | New hook |
|
|
958
|
+
* |--------------------------------|-----------------------------|
|
|
959
|
+
* | connected, hasSynced | useConnectionStatus() |
|
|
960
|
+
* | uploading, downloading | useSyncActivityContext() |
|
|
961
|
+
* | pendingCount, pendingMutations | usePendingMutationsContext()|
|
|
962
|
+
* | failedTransactions | useFailedTransactions() |
|
|
963
|
+
* | syncMode, setSyncMode | useSyncMode() |
|
|
964
|
+
* | triggerSync, pause, resume | useSyncControl() |
|
|
456
965
|
*
|
|
457
966
|
* @returns Sync status with connection state, pending uploads, and progress
|
|
458
967
|
* @throws Error if used outside of PowerSyncProvider
|
|
@@ -476,6 +985,129 @@ declare function usePowerSync<TSchema = unknown>(): PowerSyncContextValue<TSchem
|
|
|
476
985
|
* ```
|
|
477
986
|
*/
|
|
478
987
|
declare function useSyncStatus(): SyncStatusContextValue;
|
|
988
|
+
/**
|
|
989
|
+
* Hook to access connection status only.
|
|
990
|
+
* Use this instead of useSyncStatus when you only need connection state.
|
|
991
|
+
*
|
|
992
|
+
* @returns Connection status with connected, connecting, hasSynced states
|
|
993
|
+
* @throws Error if used outside of PowerSyncProvider
|
|
994
|
+
*
|
|
995
|
+
* @example
|
|
996
|
+
* ```typescript
|
|
997
|
+
* function ConnectionBadge() {
|
|
998
|
+
* const { connected, connecting } = useConnectionStatus();
|
|
999
|
+
*
|
|
1000
|
+
* if (connecting) return <Badge>Connecting...</Badge>;
|
|
1001
|
+
* return <Badge color={connected ? 'green' : 'red'}>{connected ? 'Online' : 'Offline'}</Badge>;
|
|
1002
|
+
* }
|
|
1003
|
+
* ```
|
|
1004
|
+
*/
|
|
1005
|
+
declare function useConnectionStatus(): ConnectionStatusContextValue;
|
|
1006
|
+
/**
|
|
1007
|
+
* Hook to access sync activity (uploading/downloading).
|
|
1008
|
+
* Use this instead of useSyncStatus when you only need sync progress.
|
|
1009
|
+
*
|
|
1010
|
+
* @returns Sync activity with uploading, downloading, and downloadProgress
|
|
1011
|
+
* @throws Error if used outside of PowerSyncProvider
|
|
1012
|
+
*
|
|
1013
|
+
* @example
|
|
1014
|
+
* ```typescript
|
|
1015
|
+
* function SyncProgressBar() {
|
|
1016
|
+
* const { downloading, downloadProgress } = useSyncActivityContext();
|
|
1017
|
+
*
|
|
1018
|
+
* if (!downloading) return null;
|
|
1019
|
+
* return <ProgressBar value={downloadProgress?.percentage ?? 0} />;
|
|
1020
|
+
* }
|
|
1021
|
+
* ```
|
|
1022
|
+
*/
|
|
1023
|
+
declare function useSyncActivityContext(): SyncActivityContextValue;
|
|
1024
|
+
/**
|
|
1025
|
+
* Hook to access pending mutations.
|
|
1026
|
+
* Use this instead of useSyncStatus when you only need pending upload info.
|
|
1027
|
+
*
|
|
1028
|
+
* @returns Pending mutations with count and discard functions
|
|
1029
|
+
* @throws Error if used outside of PowerSyncProvider
|
|
1030
|
+
*
|
|
1031
|
+
* @example
|
|
1032
|
+
* ```typescript
|
|
1033
|
+
* function PendingChangesIndicator() {
|
|
1034
|
+
* const { pendingCount } = usePendingMutationsContext();
|
|
1035
|
+
*
|
|
1036
|
+
* if (pendingCount === 0) return null;
|
|
1037
|
+
* return <Badge>{pendingCount} pending</Badge>;
|
|
1038
|
+
* }
|
|
1039
|
+
* ```
|
|
1040
|
+
*/
|
|
1041
|
+
declare function usePendingMutationsContext(): PendingMutationsContextValue;
|
|
1042
|
+
/**
|
|
1043
|
+
* Hook to access failed transactions.
|
|
1044
|
+
* Use this instead of useSyncStatus when you only need error info.
|
|
1045
|
+
*
|
|
1046
|
+
* @returns Failed transactions with error counts and clear/retry functions
|
|
1047
|
+
* @throws Error if used outside of PowerSyncProvider
|
|
1048
|
+
*
|
|
1049
|
+
* @example
|
|
1050
|
+
* ```typescript
|
|
1051
|
+
* function SyncErrorBanner() {
|
|
1052
|
+
* const { hasUploadErrors, permanentErrorCount, retryFailure, failedTransactions } = useFailedTransactionsContext();
|
|
1053
|
+
*
|
|
1054
|
+
* if (!hasUploadErrors) return null;
|
|
1055
|
+
* return (
|
|
1056
|
+
* <Banner onRetry={() => failedTransactions.forEach(f => retryFailure(f.id))}>
|
|
1057
|
+
* {permanentErrorCount} changes failed to sync
|
|
1058
|
+
* </Banner>
|
|
1059
|
+
* );
|
|
1060
|
+
* }
|
|
1061
|
+
* ```
|
|
1062
|
+
*/
|
|
1063
|
+
declare function useFailedTransactionsContext(): FailedTransactionsContextValue;
|
|
1064
|
+
/**
|
|
1065
|
+
* Hook to access completed transactions history.
|
|
1066
|
+
* Use this instead of useSyncStatus when you only need sync history.
|
|
1067
|
+
*
|
|
1068
|
+
* @returns Completed transactions with clear function
|
|
1069
|
+
* @throws Error if used outside of PowerSyncProvider
|
|
1070
|
+
*
|
|
1071
|
+
* @example
|
|
1072
|
+
* ```typescript
|
|
1073
|
+
* function RecentSyncs() {
|
|
1074
|
+
* const { completedTransactions, clearCompletedHistory } = useCompletedTransactionsContext();
|
|
1075
|
+
*
|
|
1076
|
+
* return (
|
|
1077
|
+
* <View>
|
|
1078
|
+
* {completedTransactions.map(t => (
|
|
1079
|
+
* <Text key={t.id}>Synced {t.affectedEntityIds.length} items</Text>
|
|
1080
|
+
* ))}
|
|
1081
|
+
* <Button onPress={clearCompletedHistory}>Clear</Button>
|
|
1082
|
+
* </View>
|
|
1083
|
+
* );
|
|
1084
|
+
* }
|
|
1085
|
+
* ```
|
|
1086
|
+
*/
|
|
1087
|
+
declare function useCompletedTransactionsContext(): CompletedTransactionsContextValue;
|
|
1088
|
+
/**
|
|
1089
|
+
* Hook to access sync mode control.
|
|
1090
|
+
* Use this instead of useSyncStatus when you only need sync mode.
|
|
1091
|
+
*
|
|
1092
|
+
* @returns Sync mode with isPaused state and control functions
|
|
1093
|
+
* @throws Error if used outside of PowerSyncProvider
|
|
1094
|
+
*
|
|
1095
|
+
* @example
|
|
1096
|
+
* ```typescript
|
|
1097
|
+
* function SyncModeToggle() {
|
|
1098
|
+
* const { syncMode, isPaused, setSyncMode } = useSyncModeContext();
|
|
1099
|
+
*
|
|
1100
|
+
* return (
|
|
1101
|
+
* <Toggle
|
|
1102
|
+
* value={!isPaused}
|
|
1103
|
+
* onValueChange={(on) => setSyncMode(on ? 'push-pull' : 'offline')}
|
|
1104
|
+
* label={isPaused ? 'Offline' : syncMode}
|
|
1105
|
+
* />
|
|
1106
|
+
* );
|
|
1107
|
+
* }
|
|
1108
|
+
* ```
|
|
1109
|
+
*/
|
|
1110
|
+
declare function useSyncModeContext(): SyncModeContextValue;
|
|
479
1111
|
/**
|
|
480
1112
|
* Hook to control sync operations.
|
|
481
1113
|
*
|
|
@@ -526,6 +1158,7 @@ declare function useSyncMode(): {
|
|
|
526
1158
|
setMode: (mode: SyncMode) => Promise<void>;
|
|
527
1159
|
canUpload: boolean;
|
|
528
1160
|
canDownload: boolean;
|
|
1161
|
+
networkReachable: boolean;
|
|
529
1162
|
};
|
|
530
1163
|
/**
|
|
531
1164
|
* Hook to access connection health status.
|
|
@@ -610,7 +1243,36 @@ declare function useSyncMetrics(): SyncMetrics;
|
|
|
610
1243
|
* }
|
|
611
1244
|
* ```
|
|
612
1245
|
*/
|
|
613
|
-
declare function useAttachmentQueue():
|
|
1246
|
+
declare function useAttachmentQueue(): PolAttachmentQueue | null;
|
|
1247
|
+
/**
|
|
1248
|
+
* Hook to check if the attachment queue has finished initializing.
|
|
1249
|
+
*
|
|
1250
|
+
* This is useful when you need to wait for the attachment queue to be ready
|
|
1251
|
+
* before performing upload operations. The attachment queue initializes
|
|
1252
|
+
* asynchronously after the database is ready, so there's a brief period
|
|
1253
|
+
* where `isReady` is true but `attachmentQueueReady` is false.
|
|
1254
|
+
*
|
|
1255
|
+
* @returns Whether the attachment queue is ready (true if initialized or if attachments not configured)
|
|
1256
|
+
*
|
|
1257
|
+
* @example
|
|
1258
|
+
* ```typescript
|
|
1259
|
+
* function UploadButton() {
|
|
1260
|
+
* const attachmentQueue = useAttachmentQueue();
|
|
1261
|
+
* const attachmentQueueReady = useAttachmentQueueReady();
|
|
1262
|
+
*
|
|
1263
|
+
* if (!attachmentQueueReady) {
|
|
1264
|
+
* return <Button disabled>Initializing...</Button>;
|
|
1265
|
+
* }
|
|
1266
|
+
*
|
|
1267
|
+
* if (!attachmentQueue) {
|
|
1268
|
+
* return <Text>Uploads not configured</Text>;
|
|
1269
|
+
* }
|
|
1270
|
+
*
|
|
1271
|
+
* return <Button onPress={handleUpload}>Upload</Button>;
|
|
1272
|
+
* }
|
|
1273
|
+
* ```
|
|
1274
|
+
*/
|
|
1275
|
+
declare function useAttachmentQueueReady(): boolean;
|
|
614
1276
|
/**
|
|
615
1277
|
* Hook to get the PowerSync database instance.
|
|
616
1278
|
* Throws if not ready.
|
|
@@ -835,20 +1497,29 @@ interface SyncActivityResult {
|
|
|
835
1497
|
failed: FailedTransaction[];
|
|
836
1498
|
/** Recently completed transactions */
|
|
837
1499
|
completed: CompletedTransaction[];
|
|
1500
|
+
/** New completed transactions since last notification display (for toasts/banners) */
|
|
1501
|
+
newCompleted: CompletedTransaction[];
|
|
838
1502
|
/** Counts summary */
|
|
839
1503
|
counts: {
|
|
840
1504
|
pending: number;
|
|
841
1505
|
failed: number;
|
|
842
1506
|
completed: number;
|
|
1507
|
+
newCompleted: number;
|
|
843
1508
|
};
|
|
844
1509
|
/** Whether there is any sync activity to show (pending or failed) */
|
|
845
1510
|
hasActivity: boolean;
|
|
846
1511
|
/** Retry all failed transactions */
|
|
847
1512
|
retryAll: () => Promise<void>;
|
|
1513
|
+
/** Retry a specific failed transaction */
|
|
1514
|
+
retryFailure: (failureId: string) => Promise<void>;
|
|
848
1515
|
/** Dismiss a specific failure */
|
|
849
1516
|
dismissFailure: (failureId: string) => void;
|
|
850
1517
|
/** Clear all completed transactions from the list */
|
|
851
1518
|
clearCompleted: () => void;
|
|
1519
|
+
/** Clear a specific completed transaction from the list */
|
|
1520
|
+
clearCompletedItem: (completedId: string) => void;
|
|
1521
|
+
/** Mark notifications as seen (for auto-dismiss functionality) */
|
|
1522
|
+
markNotificationsAsSeen: () => void;
|
|
852
1523
|
}
|
|
853
1524
|
/**
|
|
854
1525
|
* Hook to get comprehensive sync activity including pending, failed, and completed transactions.
|
|
@@ -874,5 +1545,15 @@ interface SyncActivityResult {
|
|
|
874
1545
|
* ```
|
|
875
1546
|
*/
|
|
876
1547
|
declare function useSyncActivity(): SyncActivityResult;
|
|
1548
|
+
/**
|
|
1549
|
+
* Get failed transactions state and retry/dismiss functions.
|
|
1550
|
+
* Alias for useFailedTransactionsContext.
|
|
1551
|
+
*/
|
|
1552
|
+
declare const useFailedTransactions: typeof useFailedTransactionsContext;
|
|
1553
|
+
/**
|
|
1554
|
+
* Get completed transactions state and clear function.
|
|
1555
|
+
* Alias for useCompletedTransactionsContext.
|
|
1556
|
+
*/
|
|
1557
|
+
declare const useCompletedTransactions: typeof useCompletedTransactionsContext;
|
|
877
1558
|
|
|
878
|
-
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 };
|
|
1559
|
+
export { AttachmentQueueContext, type BackgroundSyncCallbacks, type BackgroundSyncConfig, type BackgroundSyncStatus, CompletedTransactionsContext, type CompletedTransactionsContextValue, ConnectionHealthContext, type ConnectionHealthContextValue, ConnectionStatusContext, type ConnectionStatusContextValue, DEFAULT_CONNECTION_HEALTH, DEFAULT_SYNC_CONFIG, DEFAULT_SYNC_METRICS, DEFAULT_SYNC_STATUS, type DataLayerConfig, type DataLayerIntegration, type EntitySyncStatusResult, FailedTransactionsContext, type FailedTransactionsContextValue, type OfflineDataAttachmentConfig, OfflineDataProvider, type OfflineDataProviderConfig, type OfflineDataProviderProps, PendingMutationsContext, type PendingMutationsContextValue, type PowerSyncConfig, PowerSyncContext, type PowerSyncContextValue, PowerSyncProvider, type PowerSyncProviderProps, type PowerSyncSyncStatusSnapshot, ProviderBridge, type ProviderBridgeProps, SyncActivityContext, type SyncActivityContextValue, type SyncActivityResult, type SyncConfig, SyncMetricsContext, type SyncMetricsContextValue, SyncModeContext, type SyncModeContextValue, SyncStatusContext, type SyncStatusContextValue, type UploadStatusResult, useAttachmentQueue, useAttachmentQueueReady, useCompletedTransactions, useCompletedTransactionsContext, useConnectionHealth, useConnectionStatus, useDatabase, useDownloadProgress, useEntitySyncStatus, useFailedTransactions, useFailedTransactionsContext, useIsSyncing, useOnlineStatus, usePendingMutations, usePendingMutationsContext, usePlatform, usePowerSync, useSyncActivity, useSyncActivityContext, useSyncControl, useSyncMetrics, useSyncMode, useSyncModeContext, useSyncStatus, useUploadStatus };
|