Skip to content

Commit 6b38551

Browse files
committed
Fix warning for raw tables with JS client
1 parent 319012e commit 6b38551

File tree

3 files changed

+62
-1
lines changed

3 files changed

+62
-1
lines changed

.changeset/rude-paws-lie.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
'@powersync/common': patch
3+
'@powersync/node': patch
4+
'@powersync/react': patch
5+
'@powersync/react-native': patch
6+
'@powersync/web': patch
7+
---
8+
9+
Fix a warning about raw tables being used when they're not.

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,8 @@ The next upload iteration will be delayed.`);
626626
}
627627

628628
private async legacyStreamingSyncIteration(signal: AbortSignal, resolvedOptions: RequiredPowerSyncConnectionOptions) {
629-
if (resolvedOptions.serializedSchema?.raw_tables != null) {
629+
const rawTables = resolvedOptions.serializedSchema?.raw_tables;
630+
if (rawTables != null && rawTables.length) {
630631
this.logger.warn('Raw tables require the Rust-based sync client. The JS client will ignore them.');
631632
}
632633

packages/node/tests/sync.test.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,57 @@ function defineSyncTests(impl: SyncClientImplementation) {
797797

798798
expect((await query.next()).value.rows._array).toStrictEqual([]);
799799
});
800+
} else {
801+
mockSyncServiceTest('warns about raw tables', async ({ syncService }) => {
802+
const customSchema = new Schema({});
803+
customSchema.withRawTables({
804+
lists: {
805+
put: {
806+
sql: 'INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)',
807+
params: ['Id', { Column: 'name' }]
808+
},
809+
delete: {
810+
sql: 'DELETE FROM lists WHERE id = ?',
811+
params: ['Id']
812+
}
813+
}
814+
});
815+
816+
const logger = createLogger('test', { logLevel: Logger.TRACE });
817+
const logMessages: string[] = [];
818+
(logger as any).invoke = (level, args) => {
819+
console.log(...args);
820+
logMessages.push(util.format(...args));
821+
};
822+
823+
const powersync = await syncService.createDatabase({ schema: customSchema, logger });
824+
powersync.connect(new TestConnector(), options);
825+
826+
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
827+
expect(logMessages).toEqual(
828+
expect.arrayContaining([expect.stringContaining('Raw tables require the Rust-based sync client')])
829+
);
830+
});
831+
832+
mockSyncServiceTest(`does not warn about raw tables if they're not used`, async ({ syncService }) => {
833+
// Regression test for https://github.com/powersync-ja/powersync-js/issues/672
834+
const customSchema = new Schema({});
835+
836+
const logger = createLogger('test', { logLevel: Logger.TRACE });
837+
const logMessages: string[] = [];
838+
(logger as any).invoke = (level, args) => {
839+
console.log(...args);
840+
logMessages.push(util.format(...args));
841+
};
842+
843+
const powersync = await syncService.createDatabase({ schema: customSchema, logger });
844+
powersync.connect(new TestConnector(), options);
845+
846+
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
847+
expect(logMessages).not.toEqual(
848+
expect.arrayContaining([expect.stringContaining('Raw tables require the Rust-based sync client')])
849+
);
850+
});
800851
}
801852
}
802853

0 commit comments

Comments
 (0)