@powersync/common 1.27.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.
- package/dist/bundle.mjs +1 -1
- package/lib/client/AbstractPowerSyncDatabase.d.ts +77 -5
- package/lib/client/AbstractPowerSyncDatabase.js +78 -6
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +3 -3
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +65 -61
- package/lib/db/crud/SyncStatus.d.ts +55 -14
- package/lib/db/crud/SyncStatus.js +55 -14
- package/lib/utils/{throttle.d.ts → async.d.ts} +1 -0
- package/lib/utils/{throttle.js → async.js} +10 -0
- package/package.json +1 -1
|
@@ -30,22 +30,38 @@ export declare class SyncStatus {
|
|
|
30
30
|
protected options: SyncStatusOptions;
|
|
31
31
|
constructor(options: SyncStatusOptions);
|
|
32
32
|
/**
|
|
33
|
-
*
|
|
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.
|
|
34
36
|
*/
|
|
35
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
|
+
*/
|
|
36
43
|
get connecting(): boolean;
|
|
37
44
|
/**
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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.
|
|
40
49
|
*/
|
|
41
50
|
get lastSyncedAt(): Date | undefined;
|
|
42
51
|
/**
|
|
43
|
-
* Indicates whether there has been at least one full sync
|
|
44
|
-
*
|
|
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.
|
|
45
56
|
*/
|
|
46
57
|
get hasSynced(): boolean | undefined;
|
|
47
58
|
/**
|
|
48
|
-
*
|
|
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.
|
|
49
65
|
*/
|
|
50
66
|
get dataFlowStatus(): Partial<{
|
|
51
67
|
downloading: boolean;
|
|
@@ -63,27 +79,52 @@ export declare class SyncStatus {
|
|
|
63
79
|
uploadError?: Error;
|
|
64
80
|
}>;
|
|
65
81
|
/**
|
|
66
|
-
*
|
|
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.
|
|
67
86
|
*/
|
|
68
87
|
get priorityStatusEntries(): SyncPriorityStatus[];
|
|
69
88
|
/**
|
|
70
|
-
* Reports a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields
|
|
71
|
-
*
|
|
89
|
+
* Reports the sync status (a pair of {@link SyncStatus#hasSynced} and {@link SyncStatus#lastSyncedAt} fields)
|
|
90
|
+
* for a specific bucket priority level.
|
|
72
91
|
*
|
|
73
92
|
* When buckets with different priorities are declared, PowerSync may choose to synchronize higher-priority
|
|
74
93
|
* buckets first. When a consistent view over all buckets for all priorities up until the given priority is
|
|
75
94
|
* reached, PowerSync makes data from those buckets available before lower-priority buckets have finished
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
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
|
|
80
102
|
* with a priority of 1 may return information for priority level 3.
|
|
81
103
|
*
|
|
82
|
-
* @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
|
|
83
106
|
*/
|
|
84
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
|
+
*/
|
|
85
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
|
+
*/
|
|
86
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
|
+
*/
|
|
87
128
|
toJSON(): SyncStatusOptions;
|
|
88
129
|
private static comparePriorities;
|
|
89
130
|
}
|
|
@@ -4,30 +4,46 @@ export class SyncStatus {
|
|
|
4
4
|
this.options = options;
|
|
5
5
|
}
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
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
|
-
*
|
|
17
|
-
*
|
|
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
|
|
24
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
53
|
-
*
|
|
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
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
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
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
|
+
}
|