diff --git a/.changeset/rude-paws-lie.md b/.changeset/rude-paws-lie.md new file mode 100644 index 000000000..36eef0221 --- /dev/null +++ b/.changeset/rude-paws-lie.md @@ -0,0 +1,9 @@ +--- +'@powersync/common': patch +'@powersync/node': patch +'@powersync/react': patch +'@powersync/react-native': patch +'@powersync/web': patch +--- + +Fix a warning about raw tables being used when they're not. diff --git a/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts b/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts index e3fea79b6..31aed88bc 100644 --- a/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +++ b/packages/common/src/client/sync/stream/AbstractStreamingSyncImplementation.ts @@ -626,7 +626,8 @@ The next upload iteration will be delayed.`); } private async legacyStreamingSyncIteration(signal: AbortSignal, resolvedOptions: RequiredPowerSyncConnectionOptions) { - if (resolvedOptions.serializedSchema?.raw_tables != null) { + const rawTables = resolvedOptions.serializedSchema?.raw_tables; + if (rawTables != null && rawTables.length) { this.logger.warn('Raw tables require the Rust-based sync client. The JS client will ignore them.'); } diff --git a/packages/node/tests/sync.test.ts b/packages/node/tests/sync.test.ts index 5d2f7199d..561b81cf8 100644 --- a/packages/node/tests/sync.test.ts +++ b/packages/node/tests/sync.test.ts @@ -797,6 +797,57 @@ function defineSyncTests(impl: SyncClientImplementation) { expect((await query.next()).value.rows._array).toStrictEqual([]); }); + } else { + mockSyncServiceTest('warns about raw tables', async ({ syncService }) => { + const customSchema = new Schema({}); + customSchema.withRawTables({ + lists: { + put: { + sql: 'INSERT OR REPLACE INTO lists (id, name) VALUES (?, ?)', + params: ['Id', { Column: 'name' }] + }, + delete: { + sql: 'DELETE FROM lists WHERE id = ?', + params: ['Id'] + } + } + }); + + const logger = createLogger('test', { logLevel: Logger.TRACE }); + const logMessages: string[] = []; + (logger as any).invoke = (level, args) => { + console.log(...args); + logMessages.push(util.format(...args)); + }; + + const powersync = await syncService.createDatabase({ schema: customSchema, logger }); + powersync.connect(new TestConnector(), options); + + await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1)); + expect(logMessages).toEqual( + expect.arrayContaining([expect.stringContaining('Raw tables require the Rust-based sync client')]) + ); + }); + + mockSyncServiceTest(`does not warn about raw tables if they're not used`, async ({ syncService }) => { + // Regression test for https://github.com/powersync-ja/powersync-js/issues/672 + const customSchema = new Schema({}); + + const logger = createLogger('test', { logLevel: Logger.TRACE }); + const logMessages: string[] = []; + (logger as any).invoke = (level, args) => { + console.log(...args); + logMessages.push(util.format(...args)); + }; + + const powersync = await syncService.createDatabase({ schema: customSchema, logger }); + powersync.connect(new TestConnector(), options); + + await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1)); + expect(logMessages).not.toEqual( + expect.arrayContaining([expect.stringContaining('Raw tables require the Rust-based sync client')]) + ); + }); } }