1
- import type { SyncStatus } from " ./SyncStatus.js" ;
1
+ import type { SyncStatus } from ' ./SyncStatus.js' ;
2
2
3
3
// (bucket, progress) pairs
4
4
/** @internal */
5
- export type InternalProgressInformation = Record < string , {
6
- priority : number , // Priority of the associated buckets
7
- atLast : number , // Total ops at last completed sync, or 0
8
- sinceLast : number , // Total ops _since_ the last completed sync.
9
- targetCount : number , // Total opcount for next checkpoint as indicated by service.
10
- } > ;
5
+ export type InternalProgressInformation = Record <
6
+ string ,
7
+ {
8
+ priority : number ; // Priority of the associated buckets
9
+ atLast : number ; // Total ops at last completed sync, or 0
10
+ sinceLast : number ; // Total ops _since_ the last completed sync.
11
+ targetCount : number ; // Total opcount for next checkpoint as indicated by service.
12
+ }
13
+ > ;
11
14
12
15
/**
13
16
* @internal The priority used by the core extension to indicate that a full sync was completed.
@@ -16,67 +19,67 @@ export const FULL_SYNC_PRIORITY = 2147483647;
16
19
17
20
/**
18
21
* Information about a progressing download made by the PowerSync SDK.
19
- *
22
+ *
20
23
* To obtain these values, use {@link SyncProgress}, available through
21
24
* {@link SyncStatus#downloadProgress}.
22
25
*/
23
26
export interface ProgressWithOperations {
24
- /**
25
- * The total amount of operations to download for the current sync iteration
26
- * to complete.
27
- */
28
- total : number ;
29
- /**
30
- * The amount of operations that have already been downloaded.
31
- */
32
- completed : number ;
27
+ /**
28
+ * The total amount of operations to download for the current sync iteration
29
+ * to complete.
30
+ */
31
+ total : number ;
32
+ /**
33
+ * The amount of operations that have already been downloaded.
34
+ */
35
+ completed : number ;
33
36
34
- /**
35
- * Relative progress, as {@link completed} of {@link total}. This will be a number
36
- * between `0.0` and `1.0`.
37
- */
38
- fraction : number ;
39
- } ;
37
+ /**
38
+ * Relative progress, as {@link completed} of {@link total}. This will be a number
39
+ * between `0.0` and `1.0`.
40
+ */
41
+ fraction : number ;
42
+ }
40
43
41
44
/**
42
45
* Provides realtime progress on how PowerSync is downloading rows.
43
- *
46
+ *
44
47
* The reported progress always reflects the status towards th end of a sync iteration (after
45
48
* which a consistent snapshot of all buckets is available locally).
46
- *
49
+ *
47
50
* In rare cases (in particular, when a [compacting](https://docs.powersync.com/usage/lifecycle-maintenance/compacting-buckets)
48
51
* operation takes place between syncs), it's possible for the returned numbers to be slightly
49
52
* inaccurate. For this reason, {@link SyncProgress} should be seen as an approximation of progress.
50
53
* The information returned is good enough to build progress bars, but not exact enough to track
51
54
* individual download counts.
52
- *
55
+ *
53
56
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
54
57
* to be updated one-by-one.
55
58
*/
56
59
export class SyncProgress {
57
- constructor ( protected internal : InternalProgressInformation ) { }
58
-
59
- get untilCompletion ( ) : ProgressWithOperations {
60
- return this . untilPriority ( FULL_SYNC_PRIORITY ) ;
61
- }
60
+ constructor ( protected internal : InternalProgressInformation ) { }
62
61
63
- untilPriority ( priority : number ) : ProgressWithOperations {
64
- let total = 0 ;
65
- let downloaded = 0 ;
62
+ get untilCompletion ( ) : ProgressWithOperations {
63
+ return this . untilPriority ( FULL_SYNC_PRIORITY ) ;
64
+ }
66
65
67
- for ( const progress of Object . values ( this . internal ) ) {
68
- // Include higher-priority buckets, which are represented by lower numbers.
69
- if ( progress . priority <= priority ) {
70
- downloaded += progress . sinceLast ;
71
- total += progress . targetCount - progress . atLast ;
72
- }
73
- }
66
+ untilPriority ( priority : number ) : ProgressWithOperations {
67
+ let total = 0 ;
68
+ let downloaded = 0 ;
74
69
75
- let progress = total == 0 ? 0.0 : downloaded / total ;
76
- return {
77
- total ,
78
- completed : downloaded ,
79
- fraction : progress ,
80
- }
70
+ for ( const progress of Object . values ( this . internal ) ) {
71
+ // Include higher-priority buckets, which are represented by lower numbers.
72
+ if ( progress . priority <= priority ) {
73
+ downloaded += progress . sinceLast ;
74
+ total += progress . targetCount - progress . atLast ;
75
+ }
81
76
}
77
+
78
+ let progress = total == 0 ? 0.0 : downloaded / total ;
79
+ return {
80
+ total,
81
+ completed : downloaded ,
82
+ fraction : progress
83
+ } ;
84
+ }
82
85
}
0 commit comments