Skip to content

Commit 6a3e3c2

Browse files
committed
Simplify sync API
1 parent b569cb7 commit 6a3e3c2

File tree

2 files changed

+27
-20
lines changed

2 files changed

+27
-20
lines changed

packages/common/src/db/crud/SyncProgress.ts

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,27 @@ export interface ProgressWithOperations {
2828
* The total amount of operations to download for the current sync iteration
2929
* to complete.
3030
*/
31-
total: number;
31+
totalOperations: number;
3232
/**
3333
* The amount of operations that have already been downloaded.
3434
*/
35-
completed: number;
35+
downloadedOperations: number;
3636

3737
/**
38-
* Relative progress, as {@link completed} of {@link total}. This will be a number
39-
* between `0.0` and `1.0`.
38+
* Relative progress, as {@link downloadedOperations} of {@link totalOperations}.
39+
*
40+
* This will be a number between `0.0` and `1.0`.
4041
*/
41-
fraction: number;
42+
downloadedFraction: number;
4243
}
4344

4445
/**
4546
* Provides realtime progress on how PowerSync is downloading rows.
47+
*
48+
* The progress until the next complete sync is available through the fields on {@link ProgressWithOperations},
49+
* which this class implements.
50+
* Additionally, the {@link SyncProgress.untilPriority} method can be used to otbain progress towards
51+
* a specific priority (instead of the progress for the entire download).
4652
*
4753
* The reported progress always reflects the status towards th end of a sync iteration (after
4854
* which a consistent snapshot of all buckets is available locally).
@@ -56,17 +62,18 @@ export interface ProgressWithOperations {
5662
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
5763
* to be updated one-by-one.
5864
*/
59-
export class SyncProgress {
60-
constructor(protected internal: InternalProgressInformation) {}
65+
export class SyncProgress implements ProgressWithOperations {
6166

62-
/**
63-
* Returns donwload progress towards a complete checkpoint being received.
64-
*
65-
* The returned {@link ProgressWithOperations} tracks the target amount of operations that need
66-
* to be downloaded in total and how many of them have already been received.
67-
*/
68-
get untilCompletion(): ProgressWithOperations {
69-
return this.untilPriority(FULL_SYNC_PRIORITY);
67+
totalOperations: number;
68+
downloadedOperations: number;
69+
downloadedFraction: number;
70+
71+
constructor(protected internal: InternalProgressInformation) {
72+
const untilCompletion = this.untilPriority(FULL_SYNC_PRIORITY);
73+
74+
this.totalOperations = untilCompletion.totalOperations;
75+
this.downloadedOperations = untilCompletion.downloadedOperations;
76+
this.downloadedFraction = untilCompletion.downloadedFraction;
7077
}
7178

7279
/**
@@ -89,9 +96,9 @@ export class SyncProgress {
8996

9097
let progress = total == 0 ? 0.0 : downloaded / total;
9198
return {
92-
total,
93-
completed: downloaded,
94-
fraction: progress
99+
totalOperations: total,
100+
downloadedOperations: downloaded,
101+
downloadedFraction: progress
95102
};
96103
}
97104
}

packages/node/tests/sync.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ async function waitForProgress(
245245
//console.log('checking', progress);
246246

247247
const check = (expected: [number, number], actual: ProgressWithOperations): boolean => {
248-
return actual.completed == expected[0] && actual.total == expected[1];
248+
return actual.downloadedOperations == expected[0] && actual.totalOperations == expected[1];
249249
};
250250

251-
if (!check(total, progress.untilCompletion)) {
251+
if (!check(total, progress)) {
252252
return false;
253253
}
254254

0 commit comments

Comments
 (0)