Skip to content

Commit

Permalink
Start with status API
Browse files Browse the repository at this point in the history
  • Loading branch information
simolus3 committed Feb 3, 2025
1 parent 1bd7447 commit f423ffd
Showing 1 changed file with 38 additions and 11 deletions.
49 changes: 38 additions & 11 deletions packages/powersync_core/lib/src/sync_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ class SyncStatus {
/// Time that a last sync has fully completed, if any.
///
/// This is null while loading the database.
final DateTime? lastSyncedAt;
DateTime? get lastSyncedAt => statusInPriority.lastOrNull?.lastSyncedAt;

/// Indicates whether there has been at least one full sync, if any.
/// Is null when unknown, for example when state is still being loaded from the database.
final bool? hasSynced;
bool? get hasSynced => statusInPriority.lastOrNull?.hasSynced;

/// Error during uploading.
///
Expand All @@ -38,15 +38,19 @@ class SyncStatus {
/// Cleared on the next successful data download.
final Object? downloadError;

const SyncStatus(
{this.connected = false,
this.connecting = false,
this.lastSyncedAt,
this.hasSynced,
this.downloading = false,
this.uploading = false,
this.downloadError,
this.uploadError});
final List<SyncPriorityStatus> statusInPriority;

const SyncStatus({
this.connected = false,
this.connecting = false,
this.lastSyncedAt,
this.hasSynced,
this.downloading = false,
this.uploading = false,
this.downloadError,
this.uploadError,
this.statusInPriority = const [],
});

@override
bool operator ==(Object other) {
Expand Down Expand Up @@ -100,6 +104,29 @@ class SyncStatus {
}
}

/// The priority of a PowerSync bucket.
extension type const BucketPriority._(int priorityNumber) {
static const _highest = 0;
static const _lowests = 3;

factory BucketPriority(int i) {
assert(i >= _highest && i <= _lowests);
return BucketPriority._(i);
}

/// A [Comparator] instance suitable for comparing [BucketPriority] values.
static Comparator<BucketPriority> comparator =
(a, b) => -a.priorityNumber.compareTo(b.priorityNumber);
}

/// Partial information about the synchronization status for buckets within a
/// priority.
typedef SyncPriorityStatus = ({
BucketPriority priority,
DateTime lastSyncedAt,
bool hasSynced,
});

/// Stats of the local upload queue.
class UploadQueueStats {
/// Number of records in the upload queue.
Expand Down

0 comments on commit f423ffd

Please sign in to comment.