@powersync/common 2.0.0 → 2.2.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/lib/attachments/AttachmentQueue.d.ts +79 -41
- package/lib/attachments/AttachmentQueue.js +47 -11
- package/lib/attachments/AttachmentQueue.js.map +1 -1
- package/lib/attachments/AttachmentTransportAdapter.d.ts +47 -0
- package/lib/attachments/AttachmentTransportAdapter.js +2 -0
- package/lib/attachments/AttachmentTransportAdapter.js.map +1 -0
- package/lib/attachments/BufferedAttachmentTransport.d.ts +24 -0
- package/lib/attachments/BufferedAttachmentTransport.js +32 -0
- package/lib/attachments/BufferedAttachmentTransport.js.map +1 -0
- package/lib/attachments/LocalStorageAdapter.d.ts +19 -0
- package/lib/attachments/SyncingService.d.ts +7 -4
- package/lib/attachments/SyncingService.js +10 -9
- package/lib/attachments/SyncingService.js.map +1 -1
- package/lib/client/CommonPowerSyncDatabase.d.ts +14 -1
- package/lib/client/connection/PowerSyncBackendConnector.d.ts +11 -0
- package/lib/client/sync/CheckpointRequest.d.ts +32 -0
- package/lib/client/sync/CheckpointRequest.js +2 -0
- package/lib/client/sync/CheckpointRequest.js.map +1 -0
- package/lib/client/sync/options.d.ts +34 -0
- package/lib/client/sync/options.js.map +1 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/package.json +4 -3
- package/src/attachments/AttachmentQueue.ts +114 -56
- package/src/attachments/AttachmentTransportAdapter.ts +49 -0
- package/src/attachments/BufferedAttachmentTransport.ts +37 -0
- package/src/attachments/LocalStorageAdapter.ts +20 -0
- package/src/attachments/SyncingService.ts +11 -11
- package/src/client/CommonPowerSyncDatabase.ts +15 -1
- package/src/client/connection/PowerSyncBackendConnector.ts +12 -0
- package/src/client/sync/CheckpointRequest.ts +31 -0
- package/src/client/sync/options.ts +35 -0
- package/src/index.ts +9 -1
|
@@ -25,4 +25,16 @@ export interface PowerSyncBackendConnector {
|
|
|
25
25
|
* Any thrown errors will result in a retry after the configured wait period (default: 5 seconds).
|
|
26
26
|
*/
|
|
27
27
|
uploadData: (database: CommonPowerSyncDatabase) => Promise<void>;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Posts a client-generated checkpoint request to the backend and returns the effective checkpoint request state.
|
|
31
|
+
*
|
|
32
|
+
* This method is optional. It only needs to be implemented when the selected {@link CheckpointMode} is `requests`
|
|
33
|
+
* and [asynchronous backend uploads](https://docs.powersync.com/client-sdks/advanced/checkpoint-requests#asynchronous-upload-backends)
|
|
34
|
+
* are used. In any other case, this method should not be present on backend connectors.
|
|
35
|
+
*
|
|
36
|
+
* @param requestId - The client-generated checkpoint request ID (a positive 64-bit integer encoded as a string).
|
|
37
|
+
* @param clientId - The PowerSync client ID for the current device.
|
|
38
|
+
*/
|
|
39
|
+
postCheckpointRequest?(clientId: string, requestId: string): Promise<string>;
|
|
28
40
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A checkpoint request created by {@link CommonPowerSyncDatabase#requestCheckpoint}.
|
|
3
|
+
*
|
|
4
|
+
* Use this value to wait until the local database has applied server-side changes up to the requested checkpoint. This
|
|
5
|
+
* is useful for explicit refresh flows where the caller wants confirmation that the local view has caught up to the
|
|
6
|
+
* service.
|
|
7
|
+
*
|
|
8
|
+
* Checkpoint requests are backed by request ids tracked in the local database, so they are reusable across disconnect
|
|
9
|
+
* and reconnect cycles. A wait interrupted by a disconnect throws an error, but the same request can be awaited again
|
|
10
|
+
* once a new connection is established.
|
|
11
|
+
*
|
|
12
|
+
* Requests do not survive {@link CommonPowerSyncDatabase#disconnectAndClear}, instances created before a clear should
|
|
13
|
+
* be discarded and requested again.
|
|
14
|
+
*
|
|
15
|
+
* @alpha
|
|
16
|
+
*/
|
|
17
|
+
export interface CheckpointRequest {
|
|
18
|
+
/**
|
|
19
|
+
* Whether this checkpoint request has synced before.
|
|
20
|
+
*/
|
|
21
|
+
readonly hasSynced: boolean;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Waits until this checkpoint has been synced locally.
|
|
25
|
+
*
|
|
26
|
+
* This method fails on sync errors: If a download or upload error occurs before this checkpoint request has synced,
|
|
27
|
+
* that error is rethrown here. This makes it easier to observe sync errors when relying on checkpoints. Once sync has
|
|
28
|
+
* recovered, it is valid to call this method again to await the checkpoint.
|
|
29
|
+
*/
|
|
30
|
+
waitForSync(options?: { signal?: AbortSignal }): Promise<void>;
|
|
31
|
+
}
|
|
@@ -49,6 +49,11 @@ export interface SyncOptions {
|
|
|
49
49
|
* milliseconds.
|
|
50
50
|
*/
|
|
51
51
|
crudUploadThrottleMs?: number;
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* The mode used to request checkpoints from the service (used after uploading local data).
|
|
55
|
+
*/
|
|
56
|
+
checkpointMode?: CheckpointMode;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
/**
|
|
@@ -75,3 +80,33 @@ export enum FetchStrategy {
|
|
|
75
80
|
*/
|
|
76
81
|
Sequential = 'sequential'
|
|
77
82
|
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The mechanism to request checkpoints from the PowerSync service.
|
|
86
|
+
*
|
|
87
|
+
* Checkpoint requests are used after a client uploads local mutations. The PowerSync service later references them in
|
|
88
|
+
* downloaded data, allowing the SDK to assume that uploaded data has been synced down again.
|
|
89
|
+
*
|
|
90
|
+
* There are two ways to send checkpoint requests: A legacy (but default and stable) format supported by all PowerSync
|
|
91
|
+
* service versions, and a newer (`requests`) method which is only available from PowerSync service version 1.24.0 or
|
|
92
|
+
* later.
|
|
93
|
+
*
|
|
94
|
+
* Note that the requests checkpoint mode is an alpha API.
|
|
95
|
+
*
|
|
96
|
+
* @public
|
|
97
|
+
*/
|
|
98
|
+
export type CheckpointMode = 'legacy' | 'requests' | { requests: CheckpointRequestsOptions };
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Options associated with a {@link CheckpointMode} when the requests-based checkpoint option is used.
|
|
102
|
+
*
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export interface CheckpointRequestsOptions {
|
|
106
|
+
/**
|
|
107
|
+
* The delay, in milliseconds, to wait before re-sending a checkpoint request when it hasn't been applied in time.
|
|
108
|
+
*
|
|
109
|
+
* The minimum value for this is 10 seconds, lower values will be ignored.
|
|
110
|
+
*/
|
|
111
|
+
retryDelay: number;
|
|
112
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export * from './attachments/AttachmentContext.js';
|
|
2
2
|
export * from './attachments/AttachmentErrorHandler.js';
|
|
3
3
|
export * from './attachments/AttachmentQueue.js';
|
|
4
|
+
export * from './attachments/AttachmentTransportAdapter.js';
|
|
4
5
|
export * from './attachments/LocalStorageAdapter.js';
|
|
5
6
|
export * from './attachments/RemoteStorageAdapter.js';
|
|
6
7
|
export * from './attachments/Schema.js';
|
|
@@ -14,9 +15,16 @@ export * from './client/SQLOpenFactory.js';
|
|
|
14
15
|
export * from './client/sync/bucket/CrudBatch.js';
|
|
15
16
|
export { CrudEntry, OpId, UpdateType } from './client/sync/bucket/CrudEntry.js';
|
|
16
17
|
export * from './client/sync/bucket/CrudTransaction.js';
|
|
18
|
+
export * from './client/sync/CheckpointRequest.js';
|
|
17
19
|
export * from './client/sync/stream/JsonValue.js';
|
|
18
20
|
export * from './client/sync/sync-streams.js';
|
|
19
|
-
export {
|
|
21
|
+
export {
|
|
22
|
+
SyncOptions,
|
|
23
|
+
SyncStreamConnectionMethod,
|
|
24
|
+
FetchStrategy,
|
|
25
|
+
CheckpointMode,
|
|
26
|
+
CheckpointRequestsOptions
|
|
27
|
+
} from './client/sync/options.js';
|
|
20
28
|
|
|
21
29
|
export { ProgressWithOperations, SyncProgress } from './db/crud/SyncProgress.js';
|
|
22
30
|
export * from './db/crud/SyncStatus.js';
|