Skip to content

Commit 69592d0

Browse files
[Fix] Shared sync (#71)
1 parent 9115c4e commit 69592d0

File tree

7 files changed

+36
-18
lines changed

7 files changed

+36
-18
lines changed

.changeset/pink-rings-retire.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/powersync-sdk-web': patch
3+
---
4+
5+
Fixed issue on NextJS 14.1.0 where shared sync web worker would fail to initialize.

.changeset/sharp-meals-join.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@journeyapps/powersync-sdk-common': patch
3+
---
4+
5+
Improve `AbstractPowerSyncDatabase.getCrudBatch` should use a `getAll` instead of using `database.execute`.

.changeset/small-pianos-clap.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@journeyapps/powersync-sdk-common': patch
3+
---
4+
5+
Removed `object-hash` package as a dependency as this caused issues with NextJs 14.1.0.
6+
Added `equals` method on `CrudEntry` class to better align comparison operations with Javascript.

packages/powersync-sdk-common/package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
"event-iterator": "^2.0.0",
3232
"js-logger": "^1.6.1",
3333
"lodash": "^4.17.21",
34-
"object-hash": "^3.0.0",
3534
"uuid": "^3.0.0"
3635
},
3736
"devDependencies": {
3837
"@types/lodash": "^4.14.197",
3938
"@types/node": "^20.5.9",
40-
"@types/object-hash": "^3.0.4",
4139
"@types/uuid": "^3.0.0",
4240
"typescript": "^5.1.3"
4341
}

packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
299299
});
300300
}
301301

302-
/**
302+
/**
303303
* Close the database, releasing resources.
304304
*
305305
* Also disconnects any active connection.
@@ -352,12 +352,12 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
352352
* and a single transaction may be split over multiple batches.
353353
*/
354354
async getCrudBatch(limit: number): Promise<CrudBatch | null> {
355-
const result = await this.database.execute(
355+
const result = await this.getAll<CrudEntryJSON>(
356356
`SELECT id, tx_id, data FROM ${PSInternalTable.CRUD} ORDER BY id ASC LIMIT ?`,
357357
[limit + 1]
358358
);
359359

360-
const all: CrudEntry[] = result.rows?._array?.map((row) => CrudEntry.fromRow(row)) ?? [];
360+
const all: CrudEntry[] = result.map((row) => CrudEntry.fromRow(row)) ?? [];
361361

362362
let haveMore = false;
363363
if (all.length > limit) {
@@ -623,7 +623,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
623623
}
624624

625625
/**
626-
* @ignore
626+
* @ignore
627627
*/
628628
private async executeReadOnly(sql: string, params: any[]) {
629629
await this.waitForReady();

packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import hash from 'object-hash';
1+
import _ from 'lodash';
22

33
/**
44
* 64-bit unsigned integer stored as a string in base-10.
@@ -108,10 +108,24 @@ export class CrudEntry {
108108
};
109109
}
110110

111+
equals(entry: CrudEntry) {
112+
return _.isEqual(this.toComparisonArray(), entry.toComparisonArray());
113+
}
114+
111115
/**
112116
* The hash code for this object.
117+
* @deprecated This should not be necessary in the JS SDK.
118+
* Use the @see CrudEntry#equals method instead.
119+
* TODO remove in the next major release.
113120
*/
114121
hashCode() {
115-
return hash([this.transactionId, this.clientId, this.op, this.table, this.id, this.opData]);
122+
return JSON.stringify(this.toComparisonArray());
123+
}
124+
125+
/**
126+
* Generates an array for use in deep comparison operations
127+
*/
128+
toComparisonArray() {
129+
return [this.transactionId, this.clientId, this.op, this.table, this.id, this.opData];
116130
}
117131
}

pnpm-lock.yaml

Lines changed: 0 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)