@powersync/common 1.24.0 → 1.26.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.
@@ -2,12 +2,18 @@ export type SyncDataFlowStatus = Partial<{
2
2
  downloading: boolean;
3
3
  uploading: boolean;
4
4
  }>;
5
+ export interface SyncPriorityStatus {
6
+ priority: number;
7
+ lastSyncedAt?: Date;
8
+ hasSynced?: boolean;
9
+ }
5
10
  export type SyncStatusOptions = {
6
11
  connected?: boolean;
7
12
  connecting?: boolean;
8
13
  dataFlow?: SyncDataFlowStatus;
9
14
  lastSyncedAt?: Date;
10
15
  hasSynced?: boolean;
16
+ priorityStatusEntries?: SyncPriorityStatus[];
11
17
  };
12
18
  export declare class SyncStatus {
13
19
  protected options: SyncStatusOptions;
@@ -34,7 +40,28 @@ export declare class SyncStatus {
34
40
  downloading: boolean;
35
41
  uploading: boolean;
36
42
  }>;
43
+ /**
44
+ * Partial sync status for involved bucket priorities.
45
+ */
46
+ get priorityStatusEntries(): SyncPriorityStatus[];
47
+ /**
48
+ * Reports a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields that apply
49
+ * to a specific bucket priority instead of the entire sync operation.
50
+ *
51
+ * When buckets with different priorities are declared, PowerSync may choose to synchronize higher-priority
52
+ * buckets first. When a consistent view over all buckets for all priorities up until the given priority is
53
+ * reached, PowerSync makes data from those buckets available before lower-priority buckets have finished
54
+ * synchronizing.
55
+ * When PowerSync makes data for a given priority available, all buckets in higher-priorities are guaranteed to
56
+ * be consistent with that checkpoint. For this reason, this method may also return the status for lower priorities.
57
+ * In a state where the PowerSync just finished synchronizing buckets in priority level 3, calling this method
58
+ * with a priority of 1 may return information for priority level 3.
59
+ *
60
+ * @param priority The bucket priority for which the status should be reported.
61
+ */
62
+ statusForPriority(priority: number): SyncPriorityStatus;
37
63
  isEqual(status: SyncStatus): boolean;
38
64
  getMessage(): string;
39
65
  toJSON(): SyncStatusOptions;
66
+ private static comparePriorities;
40
67
  }
@@ -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
  }
@@ -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 (!this.dataQueue.length || this.isClosed || !this.hasDataReader()) {
133
+ if (this.isClosed || !this.hasDataReader()) {
137
134
  Promise.resolve().then(() => (this.processingPromise = null));
138
135
  return;
139
136
  }
140
- const data = this.dataQueue.shift();
141
- await this.iterateAsyncErrored(async (l) => l.data?.(data));
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.24.0",
3
+ "version": "1.26.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": {