@powersync/common 1.24.0 → 1.25.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.mjs +3 -3
- package/lib/client/AbstractPowerSyncDatabase.d.ts +11 -2
- package/lib/client/AbstractPowerSyncDatabase.js +50 -15
- package/lib/client/sync/bucket/BucketStorageAdapter.d.ts +6 -1
- package/lib/client/sync/bucket/SqliteBucketStorage.d.ts +2 -2
- package/lib/client/sync/bucket/SqliteBucketStorage.js +34 -10
- package/lib/client/sync/stream/AbstractRemote.js +2 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +3 -0
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +88 -32
- package/lib/client/sync/stream/streaming-sync-types.d.ts +8 -1
- package/lib/client/sync/stream/streaming-sync-types.js +3 -0
- package/lib/db/DBAdapter.d.ts +1 -1
- package/lib/db/crud/SyncStatus.d.ts +27 -0
- package/lib/db/crud/SyncStatus.js +41 -1
- package/lib/utils/DataStream.js +5 -6
- package/package.json +1 -3
|
@@ -42,6 +42,42 @@ export class SyncStatus {
|
|
|
42
42
|
uploading: false
|
|
43
43
|
});
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Partial sync status for involved bucket priorities.
|
|
47
|
+
*/
|
|
48
|
+
get priorityStatusEntries() {
|
|
49
|
+
return (this.options.priorityStatusEntries ?? []).slice().sort(SyncStatus.comparePriorities);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Reports a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields that apply
|
|
53
|
+
* to a specific bucket priority instead of the entire sync operation.
|
|
54
|
+
*
|
|
55
|
+
* When buckets with different priorities are declared, PowerSync may choose to synchronize higher-priority
|
|
56
|
+
* buckets first. When a consistent view over all buckets for all priorities up until the given priority is
|
|
57
|
+
* reached, PowerSync makes data from those buckets available before lower-priority buckets have finished
|
|
58
|
+
* synchronizing.
|
|
59
|
+
* When PowerSync makes data for a given priority available, all buckets in higher-priorities are guaranteed to
|
|
60
|
+
* be consistent with that checkpoint. For this reason, this method may also return the status for lower priorities.
|
|
61
|
+
* In a state where the PowerSync just finished synchronizing buckets in priority level 3, calling this method
|
|
62
|
+
* with a priority of 1 may return information for priority level 3.
|
|
63
|
+
*
|
|
64
|
+
* @param priority The bucket priority for which the status should be reported.
|
|
65
|
+
*/
|
|
66
|
+
statusForPriority(priority) {
|
|
67
|
+
// priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
|
|
68
|
+
for (const known of this.priorityStatusEntries) {
|
|
69
|
+
// We look for the first entry that doesn't have a higher priority.
|
|
70
|
+
if (known.priority >= priority) {
|
|
71
|
+
return known;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
// If we have a complete sync, that necessarily includes all priorities.
|
|
75
|
+
return {
|
|
76
|
+
priority,
|
|
77
|
+
lastSyncedAt: this.lastSyncedAt,
|
|
78
|
+
hasSynced: this.hasSynced
|
|
79
|
+
};
|
|
80
|
+
}
|
|
45
81
|
isEqual(status) {
|
|
46
82
|
return JSON.stringify(this.options) == JSON.stringify(status.options);
|
|
47
83
|
}
|
|
@@ -55,7 +91,11 @@ export class SyncStatus {
|
|
|
55
91
|
connecting: this.connecting,
|
|
56
92
|
dataFlow: this.dataFlowStatus,
|
|
57
93
|
lastSyncedAt: this.lastSyncedAt,
|
|
58
|
-
hasSynced: this.hasSynced
|
|
94
|
+
hasSynced: this.hasSynced,
|
|
95
|
+
priorityStatusEntries: this.priorityStatusEntries
|
|
59
96
|
};
|
|
60
97
|
}
|
|
98
|
+
static comparePriorities(a, b) {
|
|
99
|
+
return b.priority - a.priority; // Reverse because higher priorities have lower numbers
|
|
100
|
+
}
|
|
61
101
|
}
|
package/lib/utils/DataStream.js
CHANGED
|
@@ -63,9 +63,6 @@ export class DataStream extends BaseObserver {
|
|
|
63
63
|
* @returns a Data payload or Null if the stream closed.
|
|
64
64
|
*/
|
|
65
65
|
async read() {
|
|
66
|
-
if (this.dataQueue.length <= this.lowWatermark) {
|
|
67
|
-
await this.iterateAsyncErrored(async (l) => l.lowWater?.());
|
|
68
|
-
}
|
|
69
66
|
if (this.closed) {
|
|
70
67
|
return null;
|
|
71
68
|
}
|
|
@@ -133,12 +130,14 @@ export class DataStream extends BaseObserver {
|
|
|
133
130
|
return Array.from(this.listeners.values()).some((l) => !!l.data);
|
|
134
131
|
}
|
|
135
132
|
async _processQueue() {
|
|
136
|
-
if (
|
|
133
|
+
if (this.isClosed || !this.hasDataReader()) {
|
|
137
134
|
Promise.resolve().then(() => (this.processingPromise = null));
|
|
138
135
|
return;
|
|
139
136
|
}
|
|
140
|
-
|
|
141
|
-
|
|
137
|
+
if (this.dataQueue.length) {
|
|
138
|
+
const data = this.dataQueue.shift();
|
|
139
|
+
await this.iterateAsyncErrored(async (l) => l.data?.(data));
|
|
140
|
+
}
|
|
142
141
|
if (this.dataQueue.length <= this.lowWatermark) {
|
|
143
142
|
await this.iterateAsyncErrored(async (l) => l.lowWater?.());
|
|
144
143
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/common",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"registry": "https://registry.npmjs.org/",
|
|
6
6
|
"access": "public"
|
|
@@ -52,8 +52,6 @@
|
|
|
52
52
|
"rsocket-core": "1.0.0-alpha.3",
|
|
53
53
|
"rsocket-websocket-client": "1.0.0-alpha.3",
|
|
54
54
|
"text-encoding": "^0.7.0",
|
|
55
|
-
"typescript": "^5.5.3",
|
|
56
|
-
"vitest": "^2.0.5",
|
|
57
55
|
"web-streams-polyfill": "3.2.1"
|
|
58
56
|
},
|
|
59
57
|
"scripts": {
|