@powersync/common 1.26.0 → 1.27.1

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.
@@ -1,6 +1,17 @@
1
1
  export type SyncDataFlowStatus = Partial<{
2
2
  downloading: boolean;
3
3
  uploading: boolean;
4
+ /**
5
+ * Error during downloading (including connecting).
6
+ *
7
+ * Cleared on the next successful data download.
8
+ */
9
+ downloadError?: Error;
10
+ /**
11
+ * Error during uploading.
12
+ * Cleared on the next successful upload.
13
+ */
14
+ uploadError?: Error;
4
15
  }>;
5
16
  export interface SyncPriorityStatus {
6
17
  priority: number;
@@ -19,49 +30,101 @@ export declare class SyncStatus {
19
30
  protected options: SyncStatusOptions;
20
31
  constructor(options: SyncStatusOptions);
21
32
  /**
22
- * true if currently connected.
33
+ * Indicates if the client is currently connected to the PowerSync service.
34
+ *
35
+ * @returns {boolean} True if connected, false otherwise. Defaults to false if not specified.
23
36
  */
24
37
  get connected(): boolean;
38
+ /**
39
+ * Indicates if the client is in the process of establishing a connection to the PowerSync service.
40
+ *
41
+ * @returns {boolean} True if connecting, false otherwise. Defaults to false if not specified.
42
+ */
25
43
  get connecting(): boolean;
26
44
  /**
27
- * Time that a last sync has fully completed, if any.
28
- * Currently this is reset to null after a restart.
45
+ * Time that a last sync has fully completed, if any.
46
+ * This timestamp is reset to null after a restart of the PowerSync service.
47
+ *
48
+ * @returns {Date | undefined} The timestamp of the last successful sync, or undefined if no sync has completed.
29
49
  */
30
50
  get lastSyncedAt(): Date | undefined;
31
51
  /**
32
- * Indicates whether there has been at least one full sync, if any.
33
- * Is undefined when unknown, for example when state is still being loaded from the database.
52
+ * Indicates whether there has been at least one full sync completed since initialization.
53
+ *
54
+ * @returns {boolean | undefined} True if at least one sync has completed, false if no sync has completed,
55
+ * or undefined when the state is still being loaded from the database.
34
56
  */
35
57
  get hasSynced(): boolean | undefined;
36
58
  /**
37
- * Upload/download status
59
+ * Provides the current data flow status regarding uploads and downloads.
60
+ *
61
+ * @returns {SyncDataFlowStatus} An object containing:
62
+ * - downloading: True if actively downloading changes (only when connected is also true)
63
+ * - uploading: True if actively uploading changes
64
+ * Defaults to {downloading: false, uploading: false} if not specified.
38
65
  */
39
66
  get dataFlowStatus(): Partial<{
40
67
  downloading: boolean;
41
68
  uploading: boolean;
69
+ /**
70
+ * Error during downloading (including connecting).
71
+ *
72
+ * Cleared on the next successful data download.
73
+ */
74
+ downloadError?: Error;
75
+ /**
76
+ * Error during uploading.
77
+ * Cleared on the next successful upload.
78
+ */
79
+ uploadError?: Error;
42
80
  }>;
43
81
  /**
44
- * Partial sync status for involved bucket priorities.
82
+ * Provides sync status information for all bucket priorities, sorted by priority (highest first).
83
+ *
84
+ * @returns {SyncPriorityStatus[]} An array of status entries for different sync priority levels,
85
+ * sorted with highest priorities (lower numbers) first.
45
86
  */
46
87
  get priorityStatusEntries(): SyncPriorityStatus[];
47
88
  /**
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.
89
+ * Reports the sync status (a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields)
90
+ * for a specific bucket priority level.
50
91
  *
51
92
  * When buckets with different priorities are declared, PowerSync may choose to synchronize higher-priority
52
93
  * buckets first. When a consistent view over all buckets for all priorities up until the given priority is
53
94
  * 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
95
+ * syncing.
96
+ *
97
+ * This method returns the status for the requested priority or the next higher priority level that has
98
+ * status information available. This is because when PowerSync makes data for a given priority available,
99
+ * all buckets in higher-priorities are guaranteed to be consistent with that checkpoint.
100
+ *
101
+ * For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
58
102
  * with a priority of 1 may return information for priority level 3.
59
103
  *
60
- * @param priority The bucket priority for which the status should be reported.
104
+ * @param {number} priority The bucket priority for which the status should be reported
105
+ * @returns {SyncPriorityStatus} Status information for the requested priority level or the next higher level with available status
61
106
  */
62
107
  statusForPriority(priority: number): SyncPriorityStatus;
108
+ /**
109
+ * Compares this SyncStatus instance with another to determine if they are equal.
110
+ * Equality is determined by comparing the serialized JSON representation of both instances.
111
+ *
112
+ * @param {SyncStatus} status The SyncStatus instance to compare against
113
+ * @returns {boolean} True if the instances are considered equal, false otherwise
114
+ */
63
115
  isEqual(status: SyncStatus): boolean;
116
+ /**
117
+ * Creates a human-readable string representation of the current sync status.
118
+ * Includes information about connection state, sync completion, and data flow.
119
+ *
120
+ * @returns {string} A string representation of the sync status
121
+ */
64
122
  getMessage(): string;
123
+ /**
124
+ * Serializes the SyncStatus instance to a plain object.
125
+ *
126
+ * @returns {SyncStatusOptions} A plain object representation of the sync status
127
+ */
65
128
  toJSON(): SyncStatusOptions;
66
129
  private static comparePriorities;
67
130
  }
@@ -4,30 +4,46 @@ export class SyncStatus {
4
4
  this.options = options;
5
5
  }
6
6
  /**
7
- * true if currently connected.
7
+ * Indicates if the client is currently connected to the PowerSync service.
8
+ *
9
+ * @returns {boolean} True if connected, false otherwise. Defaults to false if not specified.
8
10
  */
9
11
  get connected() {
10
12
  return this.options.connected ?? false;
11
13
  }
14
+ /**
15
+ * Indicates if the client is in the process of establishing a connection to the PowerSync service.
16
+ *
17
+ * @returns {boolean} True if connecting, false otherwise. Defaults to false if not specified.
18
+ */
12
19
  get connecting() {
13
20
  return this.options.connecting ?? false;
14
21
  }
15
22
  /**
16
- * Time that a last sync has fully completed, if any.
17
- * Currently this is reset to null after a restart.
23
+ * Time that a last sync has fully completed, if any.
24
+ * This timestamp is reset to null after a restart of the PowerSync service.
25
+ *
26
+ * @returns {Date | undefined} The timestamp of the last successful sync, or undefined if no sync has completed.
18
27
  */
19
28
  get lastSyncedAt() {
20
29
  return this.options.lastSyncedAt;
21
30
  }
22
31
  /**
23
- * Indicates whether there has been at least one full sync, if any.
24
- * Is undefined when unknown, for example when state is still being loaded from the database.
32
+ * Indicates whether there has been at least one full sync completed since initialization.
33
+ *
34
+ * @returns {boolean | undefined} True if at least one sync has completed, false if no sync has completed,
35
+ * or undefined when the state is still being loaded from the database.
25
36
  */
26
37
  get hasSynced() {
27
38
  return this.options.hasSynced;
28
39
  }
29
40
  /**
30
- * Upload/download status
41
+ * Provides the current data flow status regarding uploads and downloads.
42
+ *
43
+ * @returns {SyncDataFlowStatus} An object containing:
44
+ * - downloading: True if actively downloading changes (only when connected is also true)
45
+ * - uploading: True if actively uploading changes
46
+ * Defaults to {downloading: false, uploading: false} if not specified.
31
47
  */
32
48
  get dataFlowStatus() {
33
49
  return (this.options.dataFlow ?? {
@@ -43,25 +59,32 @@ export class SyncStatus {
43
59
  });
44
60
  }
45
61
  /**
46
- * Partial sync status for involved bucket priorities.
62
+ * Provides sync status information for all bucket priorities, sorted by priority (highest first).
63
+ *
64
+ * @returns {SyncPriorityStatus[]} An array of status entries for different sync priority levels,
65
+ * sorted with highest priorities (lower numbers) first.
47
66
  */
48
67
  get priorityStatusEntries() {
49
68
  return (this.options.priorityStatusEntries ?? []).slice().sort(SyncStatus.comparePriorities);
50
69
  }
51
70
  /**
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.
71
+ * Reports the sync status (a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields)
72
+ * for a specific bucket priority level.
54
73
  *
55
74
  * When buckets with different priorities are declared, PowerSync may choose to synchronize higher-priority
56
75
  * buckets first. When a consistent view over all buckets for all priorities up until the given priority is
57
76
  * 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
77
+ * syncing.
78
+ *
79
+ * This method returns the status for the requested priority or the next higher priority level that has
80
+ * status information available. This is because when PowerSync makes data for a given priority available,
81
+ * all buckets in higher-priorities are guaranteed to be consistent with that checkpoint.
82
+ *
83
+ * For example, if PowerSync just finished synchronizing buckets in priority level 3, calling this method
62
84
  * with a priority of 1 may return information for priority level 3.
63
85
  *
64
- * @param priority The bucket priority for which the status should be reported.
86
+ * @param {number} priority The bucket priority for which the status should be reported
87
+ * @returns {SyncPriorityStatus} Status information for the requested priority level or the next higher level with available status
65
88
  */
66
89
  statusForPriority(priority) {
67
90
  // priorityStatusEntries are sorted by ascending priorities (so higher numbers to lower numbers).
@@ -78,13 +101,31 @@ export class SyncStatus {
78
101
  hasSynced: this.hasSynced
79
102
  };
80
103
  }
104
+ /**
105
+ * Compares this SyncStatus instance with another to determine if they are equal.
106
+ * Equality is determined by comparing the serialized JSON representation of both instances.
107
+ *
108
+ * @param {SyncStatus} status The SyncStatus instance to compare against
109
+ * @returns {boolean} True if the instances are considered equal, false otherwise
110
+ */
81
111
  isEqual(status) {
82
112
  return JSON.stringify(this.options) == JSON.stringify(status.options);
83
113
  }
114
+ /**
115
+ * Creates a human-readable string representation of the current sync status.
116
+ * Includes information about connection state, sync completion, and data flow.
117
+ *
118
+ * @returns {string} A string representation of the sync status
119
+ */
84
120
  getMessage() {
85
121
  const dataFlow = this.dataFlowStatus;
86
- return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}`;
122
+ return `SyncStatus<connected: ${this.connected} connecting: ${this.connecting} lastSyncedAt: ${this.lastSyncedAt} hasSynced: ${this.hasSynced}. Downloading: ${dataFlow.downloading}. Uploading: ${dataFlow.uploading}. UploadError: ${dataFlow.uploadError}, DownloadError?: ${dataFlow.downloadError}>`;
87
123
  }
124
+ /**
125
+ * Serializes the SyncStatus instance to a plain object.
126
+ *
127
+ * @returns {SyncStatusOptions} A plain object representation of the sync status
128
+ */
88
129
  toJSON() {
89
130
  return {
90
131
  connected: this.connected,
@@ -12,3 +12,4 @@ export declare function throttleTrailing(func: () => void, wait: number): () =>
12
12
  * Roughly equivalent to lodash/throttle with {leading: true, trailing: true}
13
13
  */
14
14
  export declare function throttleLeadingTrailing(func: () => void, wait: number): () => void;
15
+ export declare function onAbortPromise(signal: AbortSignal): Promise<void>;
@@ -43,3 +43,13 @@ export function throttleLeadingTrailing(func, wait) {
43
43
  }
44
44
  };
45
45
  }
46
+ export function onAbortPromise(signal) {
47
+ return new Promise((resolve) => {
48
+ if (signal.aborted) {
49
+ resolve();
50
+ }
51
+ else {
52
+ signal.onabort = () => resolve();
53
+ }
54
+ });
55
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@powersync/common",
3
- "version": "1.26.0",
3
+ "version": "1.27.1",
4
4
  "publishConfig": {
5
5
  "registry": "https://registry.npmjs.org/",
6
6
  "access": "public"