diff --git a/packages/common/src/client/AbstractPowerSyncDatabase.ts b/packages/common/src/client/AbstractPowerSyncDatabase.ts index 8dc50477a..08ee000ee 100644 --- a/packages/common/src/client/AbstractPowerSyncDatabase.ts +++ b/packages/common/src/client/AbstractPowerSyncDatabase.ts @@ -243,7 +243,11 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver { this.currentStatus = new SyncStatus({ diff --git a/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts b/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts index 40553d459..ed99a7427 100644 --- a/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +++ b/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts @@ -79,6 +79,17 @@ export interface PowerSyncConnectionOptions { * These parameters are passed to the sync rules, and will be available under the`user_parameters` object. */ params?: Record; + /** + * Delay for retrying sync streaming operations + * from the PowerSync backend after an error occurs. + */ + retryDelayMs?: number; + /** + * Backend Connector CRUD operations are throttled + * to occur at most every `crudUploadThrottleMs` + * milliseconds. + */ + crudUploadThrottleMs?: number; } export interface StreamingSyncImplementation extends BaseObserver, Disposable { @@ -102,14 +113,15 @@ export interface StreamingSyncImplementation extends BaseObserver = { +export const DEFAULT_STREAM_CONNECTION_OPTIONS: Required> = { connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET, params: {} }; @@ -427,7 +439,7 @@ The next upload iteration will be delayed.`); type: LockType.SYNC, signal, callback: async () => { - const resolvedOptions: Required = { + const resolvedOptions: Required> = { ...DEFAULT_STREAM_CONNECTION_OPTIONS, ...(options ?? {}) }; diff --git a/packages/react-native/src/db/PowerSyncDatabase.ts b/packages/react-native/src/db/PowerSyncDatabase.ts index 7f7db0c74..9cd19ca77 100644 --- a/packages/react-native/src/db/PowerSyncDatabase.ts +++ b/packages/react-native/src/db/PowerSyncDatabase.ts @@ -42,7 +42,12 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase { } protected generateSyncStreamImplementation( - connector: PowerSyncBackendConnector + connector: PowerSyncBackendConnector, + // This is used to pass in options on connection instead of only during db creation + options?: { + retryDelayMs: number; + crudUploadThrottleMs: number; + } ): AbstractStreamingSyncImplementation { const remote = new ReactNativeRemote(connector); @@ -53,8 +58,8 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase { await this.waitForReady(); await connector.uploadData(this); }, - retryDelayMs: this.options.retryDelay, - crudUploadThrottleMs: this.options.crudUploadThrottleMs, + retryDelayMs: options?.retryDelayMs || this.options.retryDelay, + crudUploadThrottleMs: options?.crudUploadThrottleMs || this.options.crudUploadThrottleMs, identifier: this.database.name }); }