Skip to content

Commit cb58548

Browse files
committed
Format
1 parent cc4a081 commit cb58548

File tree

6 files changed

+76
-65
lines changed

6 files changed

+76
-65
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

+6-6
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,7 @@ The next upload iteration will be delayed.`);
421421
connecting: false,
422422
dataFlow: {
423423
downloading: false,
424-
downloadProgress: null,
424+
downloadProgress: null
425425
}
426426
});
427427
});
@@ -685,20 +685,20 @@ The next upload iteration will be delayed.`);
685685
const previousProgress = this.syncStatusOptions.dataFlow?.downloadProgress;
686686
let updatedProgress: InternalProgressInformation | null = null;
687687
if (previousProgress) {
688-
updatedProgress = {...previousProgress};
688+
updatedProgress = { ...previousProgress };
689689
const progressForBucket = updatedProgress[data.bucket];
690690
if (progressForBucket) {
691691
updatedProgress[data.bucket] = {
692692
...progressForBucket,
693-
sinceLast: progressForBucket.sinceLast + data.data.length,
693+
sinceLast: progressForBucket.sinceLast + data.data.length
694694
};
695695
}
696696
}
697697

698698
this.updateSyncStatus({
699699
dataFlow: {
700700
downloading: true,
701-
downloadProgress: updatedProgress,
701+
downloadProgress: updatedProgress
702702
}
703703
});
704704
await this.options.adapter.saveSyncData({ buckets: [SyncDataBucket.fromRow(data)] });
@@ -772,14 +772,14 @@ The next upload iteration will be delayed.`);
772772
priority: bucket.priority ?? 3,
773773
atLast: savedProgress?.atLast ?? 0,
774774
sinceLast: savedProgress?.sinceLast ?? 0,
775-
targetCount: bucket.count ?? 0,
775+
targetCount: bucket.count ?? 0
776776
};
777777
}
778778

779779
this.updateSyncStatus({
780780
dataFlow: {
781781
downloading: true,
782-
downloadProgress: progress,
782+
downloadProgress: progress
783783
}
784784
});
785785
}
+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,4 +1,4 @@
1-
import { InternalProgressInformation, SyncProgress } from "./SyncProgress.js";
1+
import { InternalProgressInformation, SyncProgress } from './SyncProgress.js';
22

33
export type SyncDataFlowStatus = Partial<{
44
downloading: boolean;
@@ -16,10 +16,10 @@ export type SyncDataFlowStatus = Partial<{
1616
uploadError?: Error;
1717
/**
1818
* Internal information about how far we are downloading operations in buckets.
19-
*
19+
*
2020
* Please use the {@link SyncStatus#downloadProgress} property to track sync progress.
2121
*/
22-
downloadProgress: InternalProgressInformation | null,
22+
downloadProgress: InternalProgressInformation | null;
2323
}>;
2424

2525
export interface SyncPriorityStatus {
@@ -96,7 +96,7 @@ export class SyncStatus {
9696
/**
9797
* A realtime progress report on how many operations have been downloaded and
9898
* how many are necessary in total to complete the next sync iteration.
99-
*
99+
*
100100
* This field is only set when {@link SyncDataFlowStatus#downloading} is also true.
101101
*/
102102
get downloadProgress(): SyncProgress | null {

0 commit comments

Comments
 (0)