@powersync/common 1.11.0 → 1.12.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.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { ILogger } from 'js-logger';
|
|
2
|
+
import { StreamingSyncRequestParameterType } from './streaming-sync-types';
|
|
2
3
|
import { AbstractRemote } from './AbstractRemote';
|
|
3
4
|
import { BucketStorageAdapter } from '../bucket/BucketStorageAdapter';
|
|
4
5
|
import { SyncStatus, SyncStatusOptions } from '../../../db/crud/SyncStatus';
|
|
@@ -54,6 +55,10 @@ export interface PowerSyncConnectionOptions {
|
|
|
54
55
|
* Defaults to a HTTP streaming connection.
|
|
55
56
|
*/
|
|
56
57
|
connectionMethod?: SyncStreamConnectionMethod;
|
|
58
|
+
/**
|
|
59
|
+
* These parameters are passed to the sync rules, and will be available under the`user_parameters` object.
|
|
60
|
+
*/
|
|
61
|
+
params?: Record<string, StreamingSyncRequestParameterType>;
|
|
57
62
|
}
|
|
58
63
|
export interface StreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener>, Disposable {
|
|
59
64
|
/**
|
|
@@ -22,7 +22,8 @@ export const DEFAULT_STREAMING_SYNC_OPTIONS = {
|
|
|
22
22
|
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
|
|
23
23
|
};
|
|
24
24
|
export const DEFAULT_STREAM_CONNECTION_OPTIONS = {
|
|
25
|
-
connectionMethod: SyncStreamConnectionMethod.HTTP
|
|
25
|
+
connectionMethod: SyncStreamConnectionMethod.HTTP,
|
|
26
|
+
params: {}
|
|
26
27
|
};
|
|
27
28
|
export class AbstractStreamingSyncImplementation extends BaseObserver {
|
|
28
29
|
_lastSyncedAt;
|
|
@@ -116,13 +117,16 @@ export class AbstractStreamingSyncImplementation extends BaseObserver {
|
|
|
116
117
|
}
|
|
117
118
|
catch (ex) {
|
|
118
119
|
this.updateSyncStatus({
|
|
119
|
-
connected: false,
|
|
120
120
|
dataFlow: {
|
|
121
121
|
uploading: false
|
|
122
122
|
}
|
|
123
123
|
});
|
|
124
124
|
await this.delayRetry();
|
|
125
|
-
|
|
125
|
+
if (!this.isConnected) {
|
|
126
|
+
// Exit the upload loop if the sync stream is no longer connected
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
this.logger.debug(`Caught exception when uploading. Upload will retry after a delay. Exception: ${ex.message}`);
|
|
126
130
|
}
|
|
127
131
|
finally {
|
|
128
132
|
this.updateSyncStatus({
|
|
@@ -312,7 +316,8 @@ export class AbstractStreamingSyncImplementation extends BaseObserver {
|
|
|
312
316
|
data: {
|
|
313
317
|
buckets: req,
|
|
314
318
|
include_checksum: true,
|
|
315
|
-
raw_data: true
|
|
319
|
+
raw_data: true,
|
|
320
|
+
parameters: resolvedOptions.params
|
|
316
321
|
}
|
|
317
322
|
};
|
|
318
323
|
const stream = resolvedOptions?.connectionMethod == SyncStreamConnectionMethod.HTTP
|
|
@@ -42,6 +42,12 @@ export interface SyncResponse {
|
|
|
42
42
|
checkpoint_token?: string;
|
|
43
43
|
checkpoint?: Checkpoint;
|
|
44
44
|
}
|
|
45
|
+
type JSONValue = string | number | boolean | null | undefined | JSONObject | JSONArray;
|
|
46
|
+
interface JSONObject {
|
|
47
|
+
[key: string]: JSONValue;
|
|
48
|
+
}
|
|
49
|
+
type JSONArray = JSONValue[];
|
|
50
|
+
export type StreamingSyncRequestParameterType = JSONValue;
|
|
45
51
|
export interface StreamingSyncRequest {
|
|
46
52
|
/**
|
|
47
53
|
* Existing bucket states.
|
|
@@ -59,6 +65,10 @@ export interface StreamingSyncRequest {
|
|
|
59
65
|
* Changes the response to stringified data in each OplogEntry
|
|
60
66
|
*/
|
|
61
67
|
raw_data: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Client parameters to be passed to the sync rules.
|
|
70
|
+
*/
|
|
71
|
+
parameters?: Record<string, StreamingSyncRequestParameterType>;
|
|
62
72
|
}
|
|
63
73
|
export interface StreamingSyncCheckpoint {
|
|
64
74
|
checkpoint: Checkpoint;
|
|
@@ -114,3 +124,4 @@ export interface CrudResponse {
|
|
|
114
124
|
*/
|
|
115
125
|
checkpoint?: OpId;
|
|
116
126
|
}
|
|
127
|
+
export {};
|