Skip to content

Commit c332fdd

Browse files
committed
chore: pr feedback
1 parent a366e3d commit c332fdd

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ import {
2828
type PowerSyncConnectionOptions,
2929
StreamingSyncImplementation,
3030
StreamingSyncImplementationListener,
31-
DEFAULT_RETRY_DELAY_MS
31+
DEFAULT_RETRY_DELAY_MS,
32+
type RequiredAdditionalConnectionOptions
3233
} from './sync/stream/AbstractStreamingSyncImplementation.js';
3334
import { runOnSchemaChange } from './runOnSchemaChange.js';
3435

@@ -238,7 +239,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
238239

239240
protected abstract generateSyncStreamImplementation(
240241
connector: PowerSyncBackendConnector,
241-
options: Required<AdditionalConnectionOptions>
242+
options: RequiredAdditionalConnectionOptions
242243
): StreamingSyncImplementation;
243244

244245
protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
@@ -371,6 +372,15 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
371372
return this.waitForReady();
372373
}
373374

375+
// Use the options passed in during connect, or fallback to the options set during database creation or fallback to the default options
376+
resolvedConnectionOptions(options?: PowerSyncConnectionOptions): RequiredAdditionalConnectionOptions {
377+
return {
378+
retryDelayMs: options?.retryDelayMs ?? this.options.retryDelayMs ?? this.options.retryDelay ?? DEFAULT_RETRY_DELAY_MS,
379+
crudUploadThrottleMs:
380+
options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs ?? DEFAULT_CRUD_UPLOAD_THROTTLE_MS
381+
};
382+
}
383+
374384
/**
375385
* Connects to stream of events from the PowerSync instance.
376386
*/
@@ -383,9 +393,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
383393
throw new Error('Cannot connect using a closed client');
384394
}
385395

386-
// Use the options passed in during connect, or fallback to the options set during database creation or fallback to the default options
387-
const retryDelayMs = options?.retryDelayMs ?? this.options.retryDelayMs ?? this.options.retryDelay ?? DEFAULT_RETRY_DELAY_MS;
388-
const crudUploadThrottleMs = options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs ?? DEFAULT_CRUD_UPLOAD_THROTTLE_MS;
396+
const { retryDelayMs, crudUploadThrottleMs } = this.resolvedConnectionOptions(options);
389397

390398
this.syncStreamImplementation = this.generateSyncStreamImplementation(connector, {
391399
retryDelayMs,

packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ export interface StreamingSyncImplementationListener extends BaseListener {
6565
* Configurable options to be used when connecting to the PowerSync
6666
* backend instance.
6767
*/
68-
export interface PowerSyncConnectionOptions extends DefaultConnectionOptions, AdditionalConnectionOptions {}
68+
export interface PowerSyncConnectionOptions extends BaseConnectionOptions, AdditionalConnectionOptions {}
6969

7070
/** @internal */
71-
export interface DefaultConnectionOptions {
71+
export interface BaseConnectionOptions {
7272
/**
7373
* The connection method to use when streaming updates from
7474
* the PowerSync backend instance.
@@ -97,6 +97,10 @@ export interface AdditionalConnectionOptions {
9797
crudUploadThrottleMs?: number;
9898
}
9999

100+
101+
/** @internal */
102+
export type RequiredAdditionalConnectionOptions = Required<AdditionalConnectionOptions>
103+
100104
export interface StreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener>, Disposable {
101105
/**
102106
* Connects to the sync service
@@ -126,7 +130,7 @@ export const DEFAULT_STREAMING_SYNC_OPTIONS = {
126130
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
127131
};
128132

129-
export type RequiredPowerSyncConnectionOptions = Required<DefaultConnectionOptions>;
133+
export type RequiredPowerSyncConnectionOptions = Required<BaseConnectionOptions>;
130134

131135
export const DEFAULT_STREAM_CONNECTION_OPTIONS: RequiredPowerSyncConnectionOptions = {
132136
connectionMethod: SyncStreamConnectionMethod.WEB_SOCKET,

packages/react-native/src/db/PowerSyncDatabase.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import {
22
AbstractPowerSyncDatabase,
33
AbstractStreamingSyncImplementation,
4-
AdditionalConnectionOptions,
54
BucketStorageAdapter,
65
DBAdapter,
76
PowerSyncBackendConnector,
87
PowerSyncDatabaseOptionsWithSettings,
8+
type RequiredAdditionalConnectionOptions,
99
SqliteBucketStorage
1010
} from '@powersync/common';
1111
import { ReactNativeRemote } from '../sync/stream/ReactNativeRemote';
@@ -44,7 +44,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
4444

4545
protected generateSyncStreamImplementation(
4646
connector: PowerSyncBackendConnector,
47-
options: Required<AdditionalConnectionOptions>
47+
options: RequiredAdditionalConnectionOptions
4848
): AbstractStreamingSyncImplementation {
4949
const remote = new ReactNativeRemote(connector);
5050

packages/web/src/db/PowerSyncDatabase.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {
33
type PowerSyncBackendConnector,
44
type PowerSyncCloseOptions,
55
type PowerSyncConnectionOptions,
6-
type AdditionalConnectionOptions,
6+
type RequiredAdditionalConnectionOptions,
77
AbstractPowerSyncDatabase,
88
DBAdapter,
99
DEFAULT_POWERSYNC_CLOSE_OPTIONS,
@@ -12,7 +12,7 @@ import {
1212
PowerSyncDatabaseOptionsWithOpenFactory,
1313
PowerSyncDatabaseOptionsWithSettings,
1414
SqliteBucketStorage,
15-
StreamingSyncImplementation
15+
StreamingSyncImplementation,
1616
} from '@powersync/common';
1717
import { Mutex } from 'async-mutex';
1818
import { WASQLiteOpenFactory } from './adapters/wa-sqlite/WASQLiteOpenFactory';
@@ -167,7 +167,7 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
167167

168168
protected generateSyncStreamImplementation(
169169
connector: PowerSyncBackendConnector,
170-
options: Required<AdditionalConnectionOptions>
170+
options: RequiredAdditionalConnectionOptions
171171
): StreamingSyncImplementation {
172172
const remote = new WebRemote(connector);
173173
const syncOptions: WebStreamingSyncImplementationOptions = {

0 commit comments

Comments
 (0)