Skip to content

Commit 787b963

Browse files
committed
Format
1 parent 664cba3 commit 787b963

File tree

6 files changed

+78
-67
lines changed

6 files changed

+78
-67
lines changed

packages/common/src/client/SQLOpenFactory.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export interface SQLOpenOptions {
77
dbFilename: string;
88
/**
99
* Directory where the database file is located.
10-
*
10+
*
1111
* When set, the directory must exist when the database is opened, it will
1212
* not be created automatically.
1313
*/

packages/common/src/client/sync/bucket/BucketStorageAdapter.ts

+7-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ export interface SyncLocalDatabaseResult {
3030
checkpointFailures?: string[];
3131
}
3232

33-
export type BucketOperationProgress = Record<string, {
34-
atLast: number;
35-
sinceLast: number;
36-
}>;
33+
export type BucketOperationProgress = Record<
34+
string,
35+
{
36+
atLast: number;
37+
sinceLast: number;
38+
}
39+
>;
3740

3841
export interface BucketChecksum {
3942
bucket: string;

packages/common/src/client/sync/bucket/SqliteBucketStorage.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
9393
}
9494

9595
async getBucketOperationProgress(): Promise<BucketOperationProgress> {
96-
const rows = await this.db.getAll<{name: string, count_at_last: number, count_since_last: number}>("SELECT name, count_at_last, count_since_last FROM ps_buckets");
97-
return Object.fromEntries(rows.map((r) => [r.name, {atLast: r.count_at_last, sinceLast: r.count_since_last}]));
96+
const rows = await this.db.getAll<{ name: string; count_at_last: number; count_since_last: number }>(
97+
'SELECT name, count_at_last, count_since_last FROM ps_buckets'
98+
);
99+
return Object.fromEntries(rows.map((r) => [r.name, { atLast: r.count_at_last, sinceLast: r.count_since_last }]));
98100
}
99101

100102
async saveSyncData(batch: SyncDataBatch) {
@@ -210,7 +212,10 @@ export class SqliteBucketStorage extends BaseObserver<BucketStorageListener> imp
210212
const bucketToCount = Object.fromEntries(checkpoint.buckets.map((b) => [b.bucket, b.count]));
211213
// The two parameters could be replaced with one, but: https://github.com/powersync-ja/better-sqlite3/pull/6
212214
const jsonBucketCount = JSON.stringify(bucketToCount);
213-
await tx.execute('UPDATE ps_buckets SET count_since_last = 0, count_at_last = ?->name WHERE ?->name IS NOT NULL', [jsonBucketCount, jsonBucketCount]);
215+
await tx.execute(
216+
'UPDATE ps_buckets SET count_since_last = 0, count_at_last = ?->name WHERE ?->name IS NOT NULL',
217+
[jsonBucketCount, jsonBucketCount]
218+
);
214219
}
215220

216221
return true;

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ The next upload iteration will be delayed.`);
415415
connecting: false,
416416
dataFlow: {
417417
downloading: false,
418-
downloadProgress: null,
418+
downloadProgress: null
419419
}
420420
});
421421
});
@@ -594,7 +594,7 @@ The next upload iteration will be delayed.`);
594594
lastSyncedAt: new Date(),
595595
dataFlow: {
596596
downloading: false,
597-
downloadProgress: null,
597+
downloadProgress: null
598598
}
599599
});
600600
}
@@ -672,20 +672,20 @@ The next upload iteration will be delayed.`);
672672
const previousProgress = this.syncStatusOptions.dataFlow?.downloadProgress;
673673
let updatedProgress: InternalProgressInformation | null = null;
674674
if (previousProgress) {
675-
updatedProgress = {...previousProgress};
675+
updatedProgress = { ...previousProgress };
676676
const progressForBucket = updatedProgress[data.bucket];
677677
if (progressForBucket) {
678678
updatedProgress[data.bucket] = {
679679
...progressForBucket,
680-
sinceLast: progressForBucket.sinceLast + data.data.length,
680+
sinceLast: progressForBucket.sinceLast + data.data.length
681681
};
682682
}
683683
}
684684

685685
this.updateSyncStatus({
686686
dataFlow: {
687687
downloading: true,
688-
downloadProgress: updatedProgress,
688+
downloadProgress: updatedProgress
689689
}
690690
});
691691
await this.options.adapter.saveSyncData({ buckets: [SyncDataBucket.fromRow(data)] });
@@ -729,7 +729,7 @@ The next upload iteration will be delayed.`);
729729
priorityStatusEntries: [],
730730
dataFlow: {
731731
downloading: false,
732-
downloadProgress: null,
732+
downloadProgress: null
733733
}
734734
});
735735
}
@@ -755,14 +755,14 @@ The next upload iteration will be delayed.`);
755755
priority: bucket.priority ?? 3,
756756
atLast: savedProgress?.atLast ?? 0,
757757
sinceLast: savedProgress?.sinceLast ?? 0,
758-
targetCount: bucket.count ?? 0,
758+
targetCount: bucket.count ?? 0
759759
};
760760
}
761761

762762
this.updateSyncStatus({
763763
dataFlow: {
764764
downloading: true,
765-
downloadProgress: progress,
765+
downloadProgress: progress
766766
}
767767
});
768768
}
+50-47
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
import type { SyncStatus } from "./SyncStatus.js";
1+
import type { SyncStatus } from './SyncStatus.js';
22

33
// (bucket, progress) pairs
44
/** @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+
>;
1114

1215
/**
1316
* @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;
1619

1720
/**
1821
* Information about a progressing download made by the PowerSync SDK.
19-
*
22+
*
2023
* To obtain these values, use {@link SyncProgress}, available through
2124
* {@link SyncStatus#downloadProgress}.
2225
*/
2326
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;
3336

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+
}
4043

4144
/**
4245
* Provides realtime progress on how PowerSync is downloading rows.
43-
*
46+
*
4447
* The reported progress always reflects the status towards th end of a sync iteration (after
4548
* which a consistent snapshot of all buckets is available locally).
46-
*
49+
*
4750
* In rare cases (in particular, when a [compacting](https://docs.powersync.com/usage/lifecycle-maintenance/compacting-buckets)
4851
* operation takes place between syncs), it's possible for the returned numbers to be slightly
4952
* inaccurate. For this reason, {@link SyncProgress} should be seen as an approximation of progress.
5053
* The information returned is good enough to build progress bars, but not exact enough to track
5154
* individual download counts.
52-
*
55+
*
5356
* Also note that data is downloaded in bulk, which means that individual counters are unlikely
5457
* to be updated one-by-one.
5558
*/
5659
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) {}
6261

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+
}
6665

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;
7469

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+
}
8176
}
77+
78+
let progress = total == 0 ? 0.0 : downloaded / total;
79+
return {
80+
total,
81+
completed: downloaded,
82+
fraction: progress
83+
};
84+
}
8285
}

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import { InternalProgressInformation, SyncProgress } from "./SyncProgress.js";
1+
import { InternalProgressInformation, SyncProgress } from './SyncProgress.js';
22

33
export type SyncDataFlowStatus = Partial<{
44
downloading: boolean;
55
uploading: boolean;
66
/**
77
* Internal information about how far we are downloading operations in buckets.
8-
*
8+
*
99
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
1010
*/
11-
downloadProgress: InternalProgressInformation | null,
11+
downloadProgress: InternalProgressInformation | null;
1212
}>;
1313

1414
export interface SyncPriorityStatus {
@@ -85,7 +85,7 @@ export class SyncStatus {
8585
/**
8686
* A realtime progress report on how many operations have been downloaded and
8787
* how many are necessary in total to complete the next sync iteration.
88-
*
88+
*
8989
* This field is only set when {@link SyncDataFlowStatus#downloading} is also true.
9090
*/
9191
get downloadProgress(): SyncProgress | null {

0 commit comments

Comments
 (0)