Skip to content

Commit

Permalink
chore: pr feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
DominicGBauer committed Jan 27, 2025
1 parent 823970f commit 961c961
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 39 deletions.
24 changes: 5 additions & 19 deletions packages/common/src/client/AbstractPowerSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import { CrudEntry, CrudEntryJSON } from './sync/bucket/CrudEntry.js';
import { CrudTransaction } from './sync/bucket/CrudTransaction.js';
import {
DEFAULT_CRUD_UPLOAD_THROTTLE_MS,
PowerSyncConnectionOptions,
type PowerSyncConnectionOptionalOptions,
type PowerSyncConnectionOptions,
StreamingSyncImplementation,
StreamingSyncImplementationListener
} from './sync/stream/AbstractStreamingSyncImplementation.js';
Expand All @@ -35,21 +36,9 @@ export interface DisconnectAndClearOptions {
clearLocal?: boolean;
}

export interface BasePowerSyncDatabaseOptions {
export interface BasePowerSyncDatabaseOptions extends PowerSyncConnectionOptionalOptions {
/** Schema used for the local database. */
schema: Schema;

/**
* Delay for retrying sync streaming operations
* from the PowerSync backend after an error occurs.
*/
retryDelay?: number;
/**
* Backend Connector CRUD operations are throttled
* to occur at most every `crudUploadThrottleMs`
* milliseconds.
*/
crudUploadThrottleMs?: number;
logger?: ILogger;
}

Expand Down Expand Up @@ -129,7 +118,7 @@ export const DEFAULT_POWERSYNC_CLOSE_OPTIONS: PowerSyncCloseOptions = {
export const DEFAULT_WATCH_THROTTLE_MS = 30;

export const DEFAULT_POWERSYNC_DB_OPTIONS = {
retryDelay: 5000,
retryDelayMs: 5000,
logger: Logger.get('PowerSyncDatabase'),
crudUploadThrottleMs: DEFAULT_CRUD_UPLOAD_THROTTLE_MS
};
Expand Down Expand Up @@ -244,10 +233,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB

protected abstract generateSyncStreamImplementation(
connector: PowerSyncBackendConnector,
options?: {
retryDelayMs?: number;
crudUploadThrottleMs?: number;
}
options?: PowerSyncConnectionOptionalOptions
): StreamingSyncImplementation;

protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ export interface StreamingSyncImplementationListener extends BaseListener {
* Configurable options to be used when connecting to the PowerSync
* backend instance.
*/
export interface PowerSyncConnectionOptions {
export interface PowerSyncConnectionOptions extends PowerSyncConnectionOptionalOptions, PowerSyncConnectionRequiredOptions {}

export interface PowerSyncConnectionRequiredOptions {
/**
* The connection method to use when streaming updates from
* the PowerSync backend instance.
Expand All @@ -79,19 +81,21 @@ export interface PowerSyncConnectionOptions {
* These parameters are passed to the sync rules, and will be available under the`user_parameters` object.
*/
params?: Record<string, StreamingSyncRequestParameterType>;
/**
}

export interface PowerSyncConnectionOptionalOptions {
/**
* 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;
retryDelayMs?: number;
/**
* Backend Connector CRUD operations are throttled
* to occur at most every `crudUploadThrottleMs`
* milliseconds.
*/
crudUploadThrottleMs?: number;
}
export type PowerSyncConnectionRequiredOptions = Required<Omit<PowerSyncConnectionOptions, 'retryDelayMs' | 'crudUploadThrottleMs'>>;

export interface StreamingSyncImplementation extends BaseObserver<StreamingSyncImplementationListener>, Disposable {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/react-native/src/db/PowerSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
): AbstractStreamingSyncImplementation {
const remote = new ReactNativeRemote(connector);
// Use the options passed in during connect, or fallback to the options set during database creation
const retryDelayMs = options?.retryDelayMs || this.options.retryDelay;
const crudUploadThrottleMs = options?.crudUploadThrottleMs || this.options.crudUploadThrottleMs;
const retryDelayMs = options?.retryDelayMs ?? this.options.retryDelayMs;
const crudUploadThrottleMs = options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs;

return new ReactNativeStreamingSyncImplementation({
adapter: this.bucketStorageAdapter,
Expand Down
10 changes: 4 additions & 6 deletions packages/web/src/db/PowerSyncDatabase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
type PowerSyncBackendConnector,
type PowerSyncCloseOptions,
type PowerSyncConnectionOptions,
type PowerSyncConnectionOptionalOptions,
AbstractPowerSyncDatabase,
DBAdapter,
DEFAULT_POWERSYNC_CLOSE_OPTIONS,
Expand Down Expand Up @@ -167,15 +168,12 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
protected generateSyncStreamImplementation(
connector: PowerSyncBackendConnector,
// This is used to pass in options on connection instead of only during db creation
options?: {
retryDelayMs?: number;
crudUploadThrottleMs?: number;
}
options?: PowerSyncConnectionOptionalOptions
): StreamingSyncImplementation {
const remote = new WebRemote(connector);
// Use the options passed in during connect, or fallback to the options set during database creation
const retryDelayMs = options?.retryDelayMs || this.options.retryDelay;
const crudUploadThrottleMs = options?.crudUploadThrottleMs || this.options.crudUploadThrottleMs;
const retryDelayMs = options?.retryDelayMs ?? this.options.retryDelayMs;
const crudUploadThrottleMs = options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs;

const syncOptions: WebStreamingSyncImplementationOptions = {
...(this.options as {}),
Expand Down
4 changes: 2 additions & 2 deletions packages/web/tests/src/db/PowersyncDatabase.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('PowerSyncDatabase - generateSyncStreamImplementation', () => {
flags: {
ssrMode: true,
},
retryDelay: 1000,
retryDelayMs: 1000,
crudUploadThrottleMs: 2000
})

Expand Down Expand Up @@ -86,7 +86,7 @@ describe('PowerSyncDatabase - generateSyncStreamImplementation', () => {
ssrMode: false,
enableMultiTabs: false,
},
retryDelay: 1000,
retryDelayMs: 1000,
crudUploadThrottleMs: 2000
})

Expand Down

0 comments on commit 961c961

Please sign in to comment.