Skip to content

Commit faadfbd

Browse files
committed
Warn for custom request connectors in legacy mode
1 parent 140f350 commit faadfbd

3 files changed

Lines changed: 34 additions & 6 deletions

File tree

packages/node/tests/sync.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, vi } from 'vitest';
22

33
import {
44
CommonPowerSyncDatabase,
5+
LogRecord,
56
PowerSyncLogger,
67
ProgressWithOperations,
78
Schema,
@@ -33,6 +34,28 @@ describe('Sync', () => {
3334
describe('bson', () => defineSyncTests(true));
3435

3536
describe('checkpoint requests', () => {
37+
mockSyncServiceTest('warns for custom connectors without requests being enabled', async ({ syncService }) => {
38+
const records: LogRecord[] = [];
39+
40+
const database = await syncService.createDatabase({ logger: { log: records.push.bind(records) } });
41+
const connector = new (class extends TestConnector {
42+
async postCheckpointRequest(_clientId: string, requestId: string) {
43+
return requestId;
44+
}
45+
})();
46+
47+
await database.connect(connector);
48+
expect(records).toEqual(
49+
expect.arrayContaining([
50+
expect.objectContaining({
51+
message: expect.stringContaining(
52+
'implements postCheckpointRequest, but connect() was called without checkpoint requests'
53+
)
54+
})
55+
])
56+
);
57+
});
58+
3659
mockSyncServiceTest('requests checkpoints for updates', async ({ syncService }) => {
3760
const database = await syncService.createDatabase();
3861
await database.connect(new TestConnector(), { checkpointMode: 'requests' });

packages/shared-internals/src/client/BasePowerSyncDatabase.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ import {
3434
SqliteRecord,
3535
SyncStreamConnectionMethod
3636
} from '@powersync/common';
37-
import {
38-
BucketStorageAdapter,
39-
PSInternalTable,
40-
targetCheckpointRequestId
41-
} from './sync/bucket/BucketStorageAdapter.js';
37+
import { BucketStorageAdapter, PSInternalTable } from './sync/bucket/BucketStorageAdapter.js';
4238
import { SyncStatusSnapshot } from '../db/crud/SyncStatus.js';
4339
import {
4440
ConnectionManager,

packages/shared-internals/src/client/ConnectionManager.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,12 +150,21 @@ export class ConnectionManager extends BaseObserver<ConnectionManagerListener> {
150150
const hadPendingOptions = !!this.pendingConnectionOptions;
151151

152152
// Update pending options to the latest values
153+
const resolvedOptions = resolveSyncOptions(options, this.options.defaultConnectionMethod);
153154
this.pendingConnectionOptions = {
154155
connector,
155-
options: resolveSyncOptions(options, this.options.defaultConnectionMethod),
156+
options: resolvedOptions,
156157
schema: serializedSchema
157158
};
158159

160+
if (connector.postCheckpointRequest && resolvedOptions.checkpointMode == 'legacy') {
161+
this.logger.log({
162+
level: LogLevels.warn,
163+
message:
164+
'The backend connector implements postCheckpointRequest, but connect() was called without checkpoint requests enabled.'
165+
});
166+
}
167+
159168
// Disconnecting here provides aborting in progress connection attempts.
160169
// The connectInternal method will clear pending options once it starts connecting (with the options).
161170
// We only need to trigger a disconnect here if we have already reached the point of connecting.

0 commit comments

Comments
 (0)