Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/happy-seals-change.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@powersync/service-core': patch
---

Fix inconsistencies between binary data being requested and actually being sent.
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": -93886621n,
"checksum": -93886621,
"op": "CLEAR",
"op_id": "2",
},
Expand Down Expand Up @@ -74,7 +74,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 1859363232n,
"checksum": 1859363232,
"data": "{"id":"t1","description":"Test 1b"}",
"object_id": "t1",
"object_type": "test",
Expand All @@ -83,7 +83,7 @@ exports[`sync - mongodb > compacting data - invalidate checkpoint 2`] = `
"subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
},
{
"checksum": 3028503153n,
"checksum": 3028503153,
"data": "{"id":"t2","description":"Test 2b"}",
"object_id": "t2",
"object_type": "test",
Expand Down Expand Up @@ -203,6 +203,7 @@ exports[`sync - mongodb > sends checkpoint complete line for empty checkpoint 1`
"next_after": "1",
},
},
null,
{
"checkpoint_complete": {
"last_op_id": "1",
Expand Down Expand Up @@ -274,7 +275,7 @@ exports[`sync - mongodb > sync buckets in order 1`] = `
"bucket": "b1[]",
"data": [
{
"checksum": 2912868539n,
"checksum": 2912868539,
"data": "{"id":"earlier","description":"Test 2"}",
"object_id": "earlier",
"object_type": "test",
Expand All @@ -299,7 +300,7 @@ exports[`sync - mongodb > sync buckets in order 1`] = `
"bucket": "b0[]",
"data": [
{
"checksum": 920318466n,
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
Expand Down Expand Up @@ -354,7 +355,7 @@ exports[`sync - mongodb > sync global data 1`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 920318466n,
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
Expand All @@ -363,7 +364,7 @@ exports[`sync - mongodb > sync global data 1`] = `
"subkey": "e5aa2ddc-1328-58fa-a000-0b5ed31eaf1a",
},
{
"checksum": 3280762209n,
"checksum": 3280762209,
"data": "{"id":"t2","description":"Test 2"}",
"object_id": "t2",
"object_type": "test",
Expand Down Expand Up @@ -702,7 +703,7 @@ exports[`sync - mongodb > sync updates to data query only 2`] = `
"bucket": "by_user["user1"]",
"data": [
{
"checksum": 1418351250n,
"checksum": 1418351250,
"data": "{"id":"list1","user_id":"user1","name":"User 1"}",
"object_id": "list1",
"object_type": "lists",
Expand Down Expand Up @@ -787,7 +788,7 @@ exports[`sync - mongodb > sync updates to global data 2`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 920318466n,
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
Expand Down Expand Up @@ -836,7 +837,7 @@ exports[`sync - mongodb > sync updates to global data 3`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 3280762209n,
"checksum": 3280762209,
"data": "{"id":"t2","description":"Test 2"}",
"object_id": "t2",
"object_type": "test",
Expand Down Expand Up @@ -909,7 +910,7 @@ exports[`sync - mongodb > sync updates to parameter query + data 2`] = `
"bucket": "by_user["user1"]",
"data": [
{
"checksum": 1418351250n,
"checksum": 1418351250,
"data": "{"id":"list1","user_id":"user1","name":"User 1"}",
"object_id": "list1",
"object_type": "lists",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": -93886621n,
"checksum": -93886621,
"op": "CLEAR",
"op_id": "2",
},
Expand Down Expand Up @@ -74,7 +74,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 1859363232n,
"checksum": 1859363232,
"data": "{"id":"t1","description":"Test 1b"}",
"object_id": "t1",
"object_type": "test",
Expand All @@ -83,7 +83,7 @@ exports[`sync - postgres > compacting data - invalidate checkpoint 2`] = `
"subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
},
{
"checksum": 3028503153n,
"checksum": 3028503153,
"data": "{"id":"t2","description":"Test 2b"}",
"object_id": "t2",
"object_type": "test",
Expand Down Expand Up @@ -203,6 +203,7 @@ exports[`sync - postgres > sends checkpoint complete line for empty checkpoint 1
"next_after": "1",
},
},
null,
{
"checkpoint_complete": {
"last_op_id": "1",
Expand Down Expand Up @@ -274,7 +275,7 @@ exports[`sync - postgres > sync buckets in order 1`] = `
"bucket": "b1[]",
"data": [
{
"checksum": 2912868539n,
"checksum": 2912868539,
"data": "{"id":"earlier","description":"Test 2"}",
"object_id": "earlier",
"object_type": "test",
Expand All @@ -299,7 +300,7 @@ exports[`sync - postgres > sync buckets in order 1`] = `
"bucket": "b0[]",
"data": [
{
"checksum": 920318466n,
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
Expand Down Expand Up @@ -354,7 +355,7 @@ exports[`sync - postgres > sync global data 1`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 920318466n,
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
Expand All @@ -363,7 +364,7 @@ exports[`sync - postgres > sync global data 1`] = `
"subkey": "02d285ac-4f96-5124-8fba-c6d1df992dd1",
},
{
"checksum": 3280762209n,
"checksum": 3280762209,
"data": "{"id":"t2","description":"Test 2"}",
"object_id": "t2",
"object_type": "test",
Expand Down Expand Up @@ -702,7 +703,7 @@ exports[`sync - postgres > sync updates to data query only 2`] = `
"bucket": "by_user["user1"]",
"data": [
{
"checksum": 1418351250n,
"checksum": 1418351250,
"data": "{"id":"list1","user_id":"user1","name":"User 1"}",
"object_id": "list1",
"object_type": "lists",
Expand Down Expand Up @@ -787,7 +788,7 @@ exports[`sync - postgres > sync updates to global data 2`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 920318466n,
"checksum": 920318466,
"data": "{"id":"t1","description":"Test 1"}",
"object_id": "t1",
"object_type": "test",
Expand Down Expand Up @@ -836,7 +837,7 @@ exports[`sync - postgres > sync updates to global data 3`] = `
"bucket": "mybucket[]",
"data": [
{
"checksum": 3280762209n,
"checksum": 3280762209,
"data": "{"id":"t2","description":"Test 2"}",
"object_id": "t2",
"object_type": "test",
Expand Down Expand Up @@ -909,7 +910,7 @@ exports[`sync - postgres > sync updates to parameter query + data 2`] = `
"bucket": "by_user["user1"]",
"data": [
{
"checksum": 1418351250n,
"checksum": 1418351250,
"data": "{"id":"list1","user_id":"user1","name":"User 1"}",
"object_id": "list1",
"object_type": "lists",
Expand Down
45 changes: 30 additions & 15 deletions packages/service-core-tests/src/tests/register-sync-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ export function registerSyncTests(factory: storage.TestStorageFactory) {
raw_data: true
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
});

const lines = await consumeCheckpointLines(stream);
Expand Down Expand Up @@ -149,7 +150,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
});

const lines = await consumeCheckpointLines(stream);
Expand Down Expand Up @@ -211,7 +213,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
});

let sentCheckpoints = 0;
Expand Down Expand Up @@ -320,7 +323,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: 'user_one', exp: Date.now() / 1000 + 100000 } as any
token: { sub: 'user_one', exp: Date.now() / 1000 + 100000 } as any,
isEncodingAsBson: false
});

let sentCheckpoints = 0;
Expand Down Expand Up @@ -460,7 +464,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
});

let sentRows = 0;
Expand Down Expand Up @@ -575,7 +580,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 100000 } as any
token: { sub: '', exp: Date.now() / 1000 + 100000 } as any,
isEncodingAsBson: false
});

const lines: any[] = [];
Expand Down Expand Up @@ -640,7 +646,8 @@ bucket_definitions:
raw_data: false
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
});

const lines = await consumeCheckpointLines(stream);
Expand Down Expand Up @@ -668,7 +675,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: 0 } as any
token: { sub: '', exp: 0 } as any,
isEncodingAsBson: false
});

const lines = await consumeCheckpointLines(stream);
Expand Down Expand Up @@ -698,7 +706,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
});
const iter = stream[Symbol.asyncIterator]();
context.onTestFinished(() => {
Expand Down Expand Up @@ -771,7 +780,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any,
isEncodingAsBson: false
});
const iter = stream[Symbol.asyncIterator]();
context.onTestFinished(() => {
Expand Down Expand Up @@ -846,7 +856,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any,
isEncodingAsBson: false
});
const iter = stream[Symbol.asyncIterator]();
context.onTestFinished(() => {
Expand Down Expand Up @@ -912,7 +923,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any
token: { sub: 'user1', exp: Date.now() / 1000 + 100 } as any,
isEncodingAsBson: false
});
const iter = stream[Symbol.asyncIterator]();
context.onTestFinished(() => {
Expand Down Expand Up @@ -979,7 +991,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: exp } as any
token: { sub: '', exp: exp } as any,
isEncodingAsBson: false
});
const iter = stream[Symbol.asyncIterator]();
context.onTestFinished(() => {
Expand Down Expand Up @@ -1041,7 +1054,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: '', exp: Date.now() / 1000 + 10 } as any
token: { sub: '', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
});

const iter = stream[Symbol.asyncIterator]();
Expand Down Expand Up @@ -1166,7 +1180,8 @@ bucket_definitions:
raw_data: true
},
tracker,
token: { sub: 'test', exp: Date.now() / 1000 + 10 } as any
token: { sub: 'test', exp: Date.now() / 1000 + 10 } as any,
isEncodingAsBson: false
};
const stream1 = sync.streamResponse(params);
const lines1 = await consumeCheckpointLines(stream1);
Expand Down
6 changes: 3 additions & 3 deletions packages/service-core/src/routes/endpoints/socket-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
bucketStorage: bucketStorage,
syncRules: syncRules,
params: {
...params,
binary_data: true // always true for web sockets
...params
},
token: context!.token_payload!,
tokenStreamOptions: {
Expand All @@ -100,7 +99,8 @@ export const syncStreamReactive: SocketRouteGenerator = (router) =>
},
tracker,
signal,
logger
logger,
isEncodingAsBson: true
})) {
if (signal.aborted) {
break;
Expand Down
Loading