Skip to content

Commit 189fb8e

Browse files
committed
Remove legacy sync client
1 parent 6fe9d58 commit 189fb8e

31 files changed

Lines changed: 149 additions & 1153 deletions

packages/common/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,18 @@
3030
"types": "./dist/index.d.cts",
3131
"require": "./dist/bundle.cjs"
3232
}
33+
},
34+
"./sync_protocol": {
35+
"types": "./legacy/sync_protocol.d.ts"
3336
}
3437
},
3538
"author": "PowerSync",
3639
"license": "Apache-2.0",
3740
"files": [
3841
"lib",
3942
"dist",
40-
"src"
43+
"src",
44+
"legacy"
4145
],
4246
"repository": {
4347
"type": "git",
@@ -64,7 +68,6 @@
6468
"@rollup/plugin-node-resolve": "catalog:",
6569
"@types/node": "catalog:",
6670
"@types/uuid": "catalog:",
67-
"bson": "catalog:",
6871
"buffer": "^6.0.3",
6972
"cross-fetch": "^4.1.0",
7073
"estree-walker": "^3.0.3",

packages/common/rollup.config.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function defineBuild(isNode) {
3737
}
3838
],
3939
plugins,
40-
external: ['bson', isNode ? 'event-iterator' : undefined]
40+
external: [isNode ? 'event-iterator' : undefined]
4141
};
4242
}
4343

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

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { BSON } from 'bson';
21
import { type fetch } from 'cross-fetch';
32
import Logger, { ILogger } from 'js-logger';
43
import { Requestable, RSocket, RSocketConnector } from 'rsocket-core';
@@ -15,8 +14,6 @@ import {
1514
import { EventIterator } from 'event-iterator';
1615
import type { Queue } from 'event-iterator/lib/event-iterator.js';
1716

18-
export type BSONImplementation = typeof BSON;
19-
2017
export type RemoteConnector = {
2118
fetchCredentials: () => Promise<PowerSyncCredentials | null>;
2219
invalidateCredentials?: () => void;
@@ -264,11 +261,6 @@ export abstract class AbstractRemote {
264261
return res.json();
265262
}
266263

267-
/**
268-
* Provides a BSON implementation. The import nature of this varies depending on the platform
269-
*/
270-
abstract getBSON(): Promise<BSONImplementation>;
271-
272264
/**
273265
* @returns A text decoder decoding UTF-8. This is a method to allow patching it for Hermes which doesn't support the
274266
* builtin, without forcing us to bundle a polyfill with `@powersync/common`.
@@ -285,26 +277,13 @@ export abstract class AbstractRemote {
285277
* Returns a data stream of sync line data, fetched via RSocket-over-WebSocket.
286278
*
287279
* The only mechanism to abort the returned stream is to use the abort signal in {@link SocketSyncStreamOptions}.
288-
*
289-
* @param bson A BSON encoder and decoder. When set, the data stream will be requested with a BSON payload
290-
* (required for compatibility with older sync services).
291280
*/
292-
async socketStreamRaw(
293-
options: SocketSyncStreamOptions,
294-
bson?: typeof BSON
295-
): Promise<SimpleAsyncIterator<Uint8Array>> {
281+
async socketStreamRaw(options: SocketSyncStreamOptions): Promise<SimpleAsyncIterator<Uint8Array>> {
296282
const { path, fetchStrategy = FetchStrategy.Buffered } = options;
297-
const mimeType = bson == null ? 'application/json' : 'application/bson';
283+
const mimeType = 'application/json';
298284

299285
function toBuffer(js: any): Buffer {
300-
let contents: any;
301-
if (bson != null) {
302-
contents = bson.serialize(js);
303-
} else {
304-
contents = JSON.stringify(js);
305-
}
306-
307-
return Buffer.from(contents);
286+
return Buffer.from(JSON.stringify(js));
308287
}
309288

310289
const syncQueueRequestSize = fetchStrategy == FetchStrategy.Buffered ? 10 : 1;

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import { CrudEntry } from '../bucket/CrudEntry.js';
99
import { AbstractRemote, FetchStrategy, SyncStreamOptions } from './AbstractRemote.js';
1010
import { EstablishSyncStream, Instruction, coreStatusToJs } from './core-instruction.js';
1111
import { injectable, InjectableIterator, map, SimpleAsyncIterator } from '../../../utils/stream_transform.js';
12-
import type { BSON } from 'bson';
1312
import { StreamingSyncRequestParameterType } from './JsonValue.js';
1413

1514
export enum LockType {
@@ -639,21 +638,17 @@ The next upload iteration will be delayed.`);
639638
private async receiveSyncLines(data: {
640639
options: SyncStreamOptions;
641640
connection: RequiredPowerSyncConnectionOptions;
642-
bson?: typeof BSON;
643641
}): Promise<SimpleAsyncIterator<Uint8Array | string>> {
644-
const { options, connection, bson } = data;
642+
const { options, connection } = data;
645643
const remote = this.options.remote;
646644

647645
if (connection.connectionMethod == SyncStreamConnectionMethod.HTTP) {
648646
return await remote.fetchStream(options);
649647
} else {
650-
return await this.options.remote.socketStreamRaw(
651-
{
652-
...options,
653-
...{ fetchStrategy: connection.fetchStrategy }
654-
},
655-
bson
656-
);
648+
return await this.options.remote.socketStreamRaw({
649+
...options,
650+
...{ fetchStrategy: connection.fetchStrategy }
651+
});
657652
}
658653
}
659654

packages/node/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
},
6868
"dependencies": {
6969
"@powersync/common": "workspace:*",
70-
"bson": "catalog:",
7170
"comlink": "catalog:",
7271
"undici": "^7.11.0"
7372
},
7473
"devDependencies": {
7574
"@powersync/drizzle-driver": "workspace:*",
7675
"@types/node": "catalog:",
7776
"better-sqlite3": "^12.2.0",
77+
"bson": "catalog:",
7878
"drizzle-orm": "catalog:",
7979
"js-logger": "catalog:",
8080
"rollup": "catalog:",

packages/node/src/sync/stream/NodeRemote.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,12 @@ import {
44
type ILogger,
55
AbstractRemote,
66
AbstractRemoteOptions,
7-
BSONImplementation,
87
DEFAULT_REMOTE_LOGGER,
98
FetchImplementation,
109
FetchImplementationProvider,
1110
RemoteConnector
1211
} from '@powersync/common';
13-
import { BSON } from 'bson';
14-
import {
15-
Dispatcher,
16-
EnvHttpProxyAgent,
17-
ErrorEvent,
18-
getGlobalDispatcher,
19-
ProxyAgent,
20-
WebSocket as UndiciWebSocket
21-
} from 'undici';
12+
import { Dispatcher, EnvHttpProxyAgent, getGlobalDispatcher, ProxyAgent, WebSocket as UndiciWebSocket } from 'undici';
2213

2314
export const STREAMING_POST_TIMEOUT_MS = 30_000;
2415

@@ -98,10 +89,6 @@ export class NodeRemote extends AbstractRemote {
9889
`${os.platform()}/${os.release()}`
9990
].join(' ');
10091
}
101-
102-
async getBSON(): Promise<BSONImplementation> {
103-
return BSON;
104-
}
10592
}
10693

10794
function defaultFetchDispatcher(): Dispatcher {

packages/node/tests/sync.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
TestConnector,
2020
waitForSyncStatus
2121
} from './utils';
22-
import { BucketChecksum, OplogEntryJSON } from './sync_protocol';
22+
import { BucketChecksum, OplogEntryJSON } from '@powersync/common/sync_protocol';
2323

2424
describe('Sync', () => {
2525
describe('json', () => defineSyncTests(false));

packages/node/tests/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import path from 'node:path';
44
import { ReadableStream, TransformStream } from 'node:stream/web';
55

66
import { createLogger } from '@powersync/common';
7+
import { BucketChecksum, StreamingSyncCheckpoint, StreamingSyncLine } from '@powersync/common/sync_protocol';
78
import Logger from 'js-logger';
89
import { onTestFinished, test } from 'vitest';
910
import {
@@ -18,7 +19,6 @@ import {
1819
column
1920
} from '../lib';
2021
import { BSON } from 'bson';
21-
import { BucketChecksum, StreamingSyncCheckpoint, StreamingSyncLine } from './sync_protocol';
2222

2323
export async function createTempDir() {
2424
const ostmpdir = os.tmpdir();

packages/nuxt/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@powersync/kysely-driver": "workspace:*",
8282
"@powersync/vue": "workspace:*",
8383
"@powersync/web": "workspace:*",
84+
"@powersync/common": "workspace:*",
8485
"bson": "catalog:",
8586
"comlink": "catalog:",
8687
"nuxt": "^4.3.1",

0 commit comments

Comments
 (0)