Skip to content

Commit f4e5e88

Browse files
committed
chore: add changes
1 parent 6c4db3b commit f4e5e88

File tree

4 files changed

+21
-45
lines changed

4 files changed

+21
-45
lines changed

packages/common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ import {
2727
type AdditionalConnectionOptions,
2828
type PowerSyncConnectionOptions,
2929
StreamingSyncImplementation,
30-
StreamingSyncImplementationListener
30+
StreamingSyncImplementationListener,
31+
DEFAULT_RETRY_DELAY_MS
3132
} from './sync/stream/AbstractStreamingSyncImplementation.js';
3233
import { runOnSchemaChange } from './runOnSchemaChange.js';
3334

@@ -237,7 +238,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
237238

238239
protected abstract generateSyncStreamImplementation(
239240
connector: PowerSyncBackendConnector,
240-
options?: AdditionalConnectionOptions
241+
options: Required<AdditionalConnectionOptions>
241242
): StreamingSyncImplementation;
242243

243244
protected abstract generateBucketStorageAdapter(): BucketStorageAdapter;
@@ -382,9 +383,13 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
382383
throw new Error('Cannot connect using a closed client');
383384
}
384385

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;
389+
385390
this.syncStreamImplementation = this.generateSyncStreamImplementation(connector, {
386-
crudUploadThrottleMs: options?.crudUploadThrottleMs,
387-
retryDelayMs: options?.retryDelayMs
391+
retryDelayMs,
392+
crudUploadThrottleMs,
388393
});
389394
this.syncStatusListenerDisposer = this.syncStreamImplementation.registerListener({
390395
statusChanged: (status) => {

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,9 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
4545
protected generateSyncStreamImplementation(
4646
connector: PowerSyncBackendConnector,
4747
// This is used to pass in options on connection instead of only during database creation
48-
options?: AdditionalConnectionOptions
48+
options: Required<AdditionalConnectionOptions>
4949
): AbstractStreamingSyncImplementation {
5050
const remote = new ReactNativeRemote(connector);
51-
// Use the options passed in during connect, or fallback to the options set during database creation
52-
const retryDelayMs = options?.retryDelayMs ?? this.options.retryDelayMs ?? this.options.retryDelay;
53-
const crudUploadThrottleMs = options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs;
5451

5552
return new ReactNativeStreamingSyncImplementation({
5653
adapter: this.bucketStorageAdapter,
@@ -59,8 +56,8 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
5956
await this.waitForReady();
6057
await connector.uploadData(this);
6158
},
62-
retryDelayMs,
63-
crudUploadThrottleMs,
59+
retryDelayMs: options.retryDelayMs,
60+
crudUploadThrottleMs: options.crudUploadThrottleMs,
6461
identifier: this.database.name
6562
});
6663
}

packages/web/src/db/PowerSyncDatabase.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,13 @@ export class PowerSyncDatabase extends AbstractPowerSyncDatabase {
168168
protected generateSyncStreamImplementation(
169169
connector: PowerSyncBackendConnector,
170170
// This is used to pass in options on connection instead of only during db creation
171-
options?: AdditionalConnectionOptions
171+
options: Required<AdditionalConnectionOptions>
172172
): StreamingSyncImplementation {
173173
const remote = new WebRemote(connector);
174-
// Use the options passed in during connect, or fallback to the options set during database creation
175-
const retryDelayMs = options?.retryDelayMs ?? this.options.retryDelayMs ?? this.options.retryDelay;
176-
const crudUploadThrottleMs = options?.crudUploadThrottleMs ?? this.options.crudUploadThrottleMs;
177-
178174
const syncOptions: WebStreamingSyncImplementationOptions = {
179175
...(this.options as {}),
180-
retryDelayMs,
181-
crudUploadThrottleMs,
176+
retryDelayMs: options.retryDelayMs,
177+
crudUploadThrottleMs: options.crudUploadThrottleMs,
182178
flags: this.resolvedFlags,
183179
adapter: this.bucketStorageAdapter,
184180
remote,

packages/web/tests/src/db/PowersyncDatabase.test.ts

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { PowerSyncDatabase, SharedWebStreamingSyncImplementation, WebStreamingSy
33
import { SSRStreamingSyncImplementation } from '../../../src/db/sync/SSRWebStreamingSyncImplementation'
44
import { testSchema } from '../../utils/testDb'
55

6-
76
vi.mock('../../../src/db/sync/WebStreamingSyncImplementation')
87
vi.mock('../../../src/db/sync/SharedWebStreamingSyncImplementation')
98
vi.mock('../../../src/db/sync/SSRWebStreamingSyncImplementation')
@@ -38,7 +37,7 @@ describe('PowerSyncDatabase - generateSyncStreamImplementation', () => {
3837
crudUploadThrottleMs: 2000
3938
})
4039

41-
db['generateSyncStreamImplementation'](mockConnector)
40+
db['generateSyncStreamImplementation'](mockConnector, { retryDelayMs: 1000, crudUploadThrottleMs: 2000 })
4241
expect(SSRStreamingSyncImplementation).toHaveBeenCalled()
4342

4443
await setTimeout(() => window.removeEventListener('unhandledrejection', handler), 1)
@@ -50,7 +49,7 @@ describe('PowerSyncDatabase - generateSyncStreamImplementation', () => {
5049
database: { dbFilename: 'test.db' },
5150
flags: { enableMultiTabs: true }
5251
})
53-
db['generateSyncStreamImplementation'](mockConnector)
52+
db['generateSyncStreamImplementation'](mockConnector, { retryDelayMs: 1000, crudUploadThrottleMs: 2000 })
5453
expect(SharedWebStreamingSyncImplementation).toHaveBeenCalled()
5554
})
5655

@@ -64,6 +63,7 @@ describe('PowerSyncDatabase - generateSyncStreamImplementation', () => {
6463
ssrMode: false,
6564
enableMultiTabs: false,
6665
},
66+
retryDelayMs: 1000,
6767
crudUploadThrottleMs: 1000
6868
})
6969

@@ -76,30 +76,8 @@ describe('PowerSyncDatabase - generateSyncStreamImplementation', () => {
7676
)
7777
})
7878

79-
it('handles partial option overrides', () => {
80-
const db = new PowerSyncDatabase({
81-
schema: testSchema,
82-
database: {
83-
dbFilename: 'test.db'
84-
},
85-
flags: {
86-
ssrMode: false,
87-
enableMultiTabs: false,
88-
},
89-
retryDelayMs: 1000,
90-
crudUploadThrottleMs: 2000
91-
})
92-
93-
db['generateSyncStreamImplementation'](mockConnector, { retryDelayMs: 50000 })
94-
expect(WebStreamingSyncImplementation).toHaveBeenCalledWith(
95-
expect.objectContaining({
96-
retryDelayMs: 50000,
97-
})
98-
)
99-
})
100-
10179
// This test can be removed once retryDelay is removed and entirely replaced with retryDelayMs
102-
it('works when using deprecated retryDelay instead of retryDelayMs', () => {
80+
it('works when using deprecated retryDelay instead of retryDelayMs', async () => {
10381
const db = new PowerSyncDatabase({
10482
schema: testSchema,
10583
database: {
@@ -112,10 +90,10 @@ describe('PowerSyncDatabase - generateSyncStreamImplementation', () => {
11290
retryDelay: 11100,
11391
})
11492

115-
db['generateSyncStreamImplementation'](mockConnector)
93+
db['generateSyncStreamImplementation'](mockConnector, { crudUploadThrottleMs: 2000, retryDelayMs: 50000 })
11694
expect(WebStreamingSyncImplementation).toHaveBeenCalledWith(
11795
expect.objectContaining({
118-
retryDelayMs: 11100,
96+
retryDelay: 11100,
11997
})
12098
)
12199
})

0 commit comments

Comments
 (0)