Skip to content

Commit 1731621

Browse files
committed
Port old sync test
1 parent 413e675 commit 1731621

3 files changed

Lines changed: 21 additions & 115 deletions

File tree

packages/node/tests/sync.test.ts

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,26 @@ describe('Sync', () => {
2525
describe('json', () => defineSyncTests(false));
2626
describe('bson', () => defineSyncTests(true));
2727

28-
mockSyncServiceTest.skip('can migrate between sync implementations', async ({ syncService }) => {
28+
mockSyncServiceTest('can migrate between sync implementations', async ({ syncService }) => {
29+
let database = await syncService.createDatabase();
30+
// Create a bucket with a broken oplog key format.
31+
const { id: bucketId } = await database.writeLock(async (adapter) => {
32+
return await adapter.get<{ id: number }>('INSERT INTO ps_buckets(name) VALUES (?) RETURNING id', ['a']);
33+
});
34+
await database.execute(
35+
'INSERT INTO ps_oplog(bucket, op_id, key, row_type, row_id, data, hash) VALUES (?, ?, ?, ?, ?, ?, ?)',
36+
[
37+
bucketId,
38+
'1',
39+
// The JavaScript client used to subkeys to JSON when it shouldn't...
40+
'lists/1/"subkey_1"',
41+
'lists',
42+
'1',
43+
'{}',
44+
0
45+
]
46+
);
47+
2948
function addData(id: string) {
3049
syncService.pushLine({
3150
data: {
@@ -51,27 +70,8 @@ describe('Sync', () => {
5170
}
5271
};
5372

54-
let database = await syncService.createDatabase();
73+
// Connecting with the new client should fix the format.
5574
database.connect(new TestConnector(), {
56-
clientImplementation: SyncClientImplementation.JAVASCRIPT,
57-
connectionMethod: SyncStreamConnectionMethod.HTTP
58-
});
59-
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
60-
syncService.pushLine(checkpoint);
61-
addData('1');
62-
63-
await vi.waitFor(async () => {
64-
expect(await database.getAll('SELECT * FROM ps_oplog')).toHaveLength(1);
65-
});
66-
await database.disconnect();
67-
// The JavaScript client encodes subkeys to JSON when it shouldn't...
68-
expect(await database.getAll('SELECT * FROM ps_oplog')).toEqual([
69-
expect.objectContaining({ key: 'lists/1/"subkey_1"' })
70-
]);
71-
72-
// Connecting again with the new client should fix the format
73-
database.connect(new TestConnector(), {
74-
clientImplementation: SyncClientImplementation.RUST,
7575
connectionMethod: SyncStreamConnectionMethod.HTTP
7676
});
7777
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
@@ -86,25 +86,6 @@ describe('Sync', () => {
8686
expect.objectContaining({ key: 'lists/1/subkey_1' }),
8787
expect.objectContaining({ key: 'lists/2/subkey_2' })
8888
]);
89-
90-
// Finally, connecting with JS again should keep the fixed subkey format.
91-
database.connect(new TestConnector(), {
92-
clientImplementation: SyncClientImplementation.RUST,
93-
connectionMethod: SyncStreamConnectionMethod.HTTP
94-
});
95-
await vi.waitFor(() => expect(syncService.connectedListeners).toHaveLength(1));
96-
syncService.pushLine(checkpoint);
97-
addData('3');
98-
await vi.waitFor(async () => {
99-
expect(await database.getAll('SELECT * FROM ps_oplog')).toHaveLength(3);
100-
});
101-
await database.disconnect();
102-
expect(await database.getAll('SELECT * FROM ps_oplog')).toEqual([
103-
// Existing entry should be fixed too!
104-
expect.objectContaining({ key: 'lists/1/subkey_1' }),
105-
expect.objectContaining({ key: 'lists/2/subkey_2' }),
106-
expect.objectContaining({ key: 'lists/3/subkey_3' })
107-
]);
10889
});
10990

11091
mockSyncServiceTest('reconnects immediately after changed connection', async ({ syncService }) => {

packages/nuxt/src/runtime/composables/usePowerSyncInspector.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { DiagnosticsAppSchema } from '../utils/AppSchema';
2-
import { RecordingStorageAdapter } from '../utils/RecordingStorageAdapter';
32
import { DynamicSchemaManager } from '../utils/DynamicSchemaManager';
43

54
// Global variable to store schema manager during construction
@@ -21,7 +20,6 @@ function getCurrentSchemaManager() {
2120
*
2221
* @returns An object containing:
2322
* - `diagnosticsSchema` - The schema for diagnostics data collection. Use this to extend your app schema with diagnostic tables.
24-
* - `RecordingStorageAdapter` - Used internally. Storage adapter class that records operations for diagnostic purposes.
2523
* - `getCurrentSchemaManager()` - Used internally. Gets the current schema manager instance for dynamic schema operations.
2624
*
2725
* @example
@@ -40,7 +38,6 @@ export function usePowerSyncInspector() {
4038

4139
return {
4240
diagnosticsSchema,
43-
RecordingStorageAdapter,
4441
getCurrentSchemaManager
4542
};
4643
}

tools/diagnostics-app/src/library/powersync/RecordingStorageAdapter.ts

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)