Skip to content

Commit 197a37a

Browse files
authored
Merge pull request #513 from powersync-ja/rename-priority-statuses
Rename `priorityStatuses` -> `priorityStatusEntries`
2 parents 6780fe2 + c170c91 commit 197a37a

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

packages/common/src/client/AbstractPowerSyncDatabase.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
352352
'SELECT priority, last_synced_at FROM ps_sync_state ORDER BY priority DESC'
353353
);
354354
let lastCompleteSync: Date | undefined;
355-
const priorityStatuses: SyncPriorityStatus[] = [];
355+
const priorityStatusEntries: SyncPriorityStatus[] = [];
356356

357357
for (const { priority, last_synced_at } of result) {
358358
const parsedDate = new Date(last_synced_at + 'Z');
@@ -361,15 +361,15 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
361361
// This lowest-possible priority represents a complete sync.
362362
lastCompleteSync = parsedDate;
363363
} else {
364-
priorityStatuses.push({ priority, hasSynced: true, lastSyncedAt: parsedDate });
364+
priorityStatusEntries.push({ priority, hasSynced: true, lastSyncedAt: parsedDate });
365365
}
366366
}
367367

368368
const hasSynced = lastCompleteSync != null;
369369
const updatedStatus = new SyncStatus({
370370
...this.currentStatus.toJSON(),
371371
hasSynced,
372-
priorityStatuses,
372+
priorityStatusEntries,
373373
lastSyncedAt: lastCompleteSync
374374
});
375375

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

+5-5
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ The next upload iteration will be delayed.`);
610610
this.logger.debug('partial checkpoint validation succeeded');
611611

612612
// All states with a higher priority can be deleted since this partial sync includes them.
613-
const priorityStates = this.syncStatus.priorityStatuses.filter((s) => s.priority <= priority);
613+
const priorityStates = this.syncStatus.priorityStatusEntries.filter((s) => s.priority <= priority);
614614
priorityStates.push({
615615
priority,
616616
lastSyncedAt: new Date(),
@@ -619,7 +619,7 @@ The next upload iteration will be delayed.`);
619619

620620
this.updateSyncStatus({
621621
connected: true,
622-
priorityStatuses: priorityStates
622+
priorityStatusEntries: priorityStates
623623
});
624624
}
625625
} else if (isStreamingSyncCheckpointDiff(line)) {
@@ -688,7 +688,7 @@ The next upload iteration will be delayed.`);
688688
this.updateSyncStatus({
689689
connected: true,
690690
lastSyncedAt: new Date(),
691-
priorityStatuses: []
691+
priorityStatusEntries: []
692692
});
693693
} else if (validatedCheckpoint === targetCheckpoint) {
694694
const result = await this.options.adapter.syncLocalDatabase(targetCheckpoint!);
@@ -705,7 +705,7 @@ The next upload iteration will be delayed.`);
705705
this.updateSyncStatus({
706706
connected: true,
707707
lastSyncedAt: new Date(),
708-
priorityStatuses: [],
708+
priorityStatusEntries: [],
709709
dataFlow: {
710710
downloading: false
711711
}
@@ -730,7 +730,7 @@ The next upload iteration will be delayed.`);
730730
...this.syncStatus.dataFlowStatus,
731731
...options.dataFlow
732732
},
733-
priorityStatuses: options.priorityStatuses ?? this.syncStatus.priorityStatuses
733+
priorityStatusEntries: options.priorityStatusEntries ?? this.syncStatus.priorityStatusEntries
734734
});
735735

736736
if (!this.syncStatus.isEqual(updatedStatus)) {

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export type SyncStatusOptions = {
1515
dataFlow?: SyncDataFlowStatus;
1616
lastSyncedAt?: Date;
1717
hasSynced?: boolean;
18-
priorityStatuses?: SyncPriorityStatus[];
18+
priorityStatusEntries?: SyncPriorityStatus[];
1919
};
2020

2121
export class SyncStatus {
@@ -70,8 +70,8 @@ export class SyncStatus {
7070
/**
7171
* Partial sync status for involved bucket priorities.
7272
*/
73-
get priorityStatuses() {
74-
return (this.options.priorityStatuses ?? []).toSorted(SyncStatus.comparePriorities);
73+
get priorityStatusEntries() {
74+
return (this.options.priorityStatusEntries ?? []).toSorted(SyncStatus.comparePriorities);
7575
}
7676

7777
/**
@@ -90,8 +90,8 @@ export class SyncStatus {
9090
* @param priority The bucket priority for which the status should be reported.
9191
*/
9292
statusForPriority(priority: number): SyncPriorityStatus {
93-
// priorityStatuses are sorted by ascending priorities (so higher numbers to lower numbers).
94-
for (const known of this.priorityStatuses) {
93+
// priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
94+
for (const known of this.priorityStatusEntries) {
9595
// We look for the first entry that doesn't have a higher priority.
9696
if (known.priority >= priority) {
9797
return known;
@@ -122,7 +122,7 @@ export class SyncStatus {
122122
dataFlow: this.dataFlowStatus,
123123
lastSyncedAt: this.lastSyncedAt,
124124
hasSynced: this.hasSynced,
125-
priorityStatuses: this.priorityStatuses
125+
priorityStatusEntries: this.priorityStatusEntries
126126
};
127127
}
128128

packages/web/tests/stream.test.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ describe(
249249
});
250250
await another.init();
251251

252-
expect(another.currentStatus.priorityStatuses).toHaveLength(1);
252+
expect(another.currentStatus.priorityStatusEntries).toHaveLength(1);
253253
expect(another.currentStatus.statusForPriority(0).hasSynced).toBeTruthy();
254254
await another.waitForFirstSync({ priority: 0 });
255255
});

0 commit comments

Comments
 (0)