Skip to content

Commit

Permalink
[Fix] Shared sync (#71)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevensJourney authored Feb 20, 2024
1 parent 9115c4e commit 69592d0
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 18 deletions.
5 changes: 5 additions & 0 deletions .changeset/pink-rings-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@journeyapps/powersync-sdk-web': patch
---

Fixed issue on NextJS 14.1.0 where shared sync web worker would fail to initialize.
5 changes: 5 additions & 0 deletions .changeset/sharp-meals-join.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@journeyapps/powersync-sdk-common': patch
---

Improve `AbstractPowerSyncDatabase.getCrudBatch` should use a `getAll` instead of using `database.execute`.
6 changes: 6 additions & 0 deletions .changeset/small-pianos-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@journeyapps/powersync-sdk-common': patch
---

Removed `object-hash` package as a dependency as this caused issues with NextJs 14.1.0.
Added `equals` method on `CrudEntry` class to better align comparison operations with Javascript.
2 changes: 0 additions & 2 deletions packages/powersync-sdk-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
"event-iterator": "^2.0.0",
"js-logger": "^1.6.1",
"lodash": "^4.17.21",
"object-hash": "^3.0.0",
"uuid": "^3.0.0"
},
"devDependencies": {
"@types/lodash": "^4.14.197",
"@types/node": "^20.5.9",
"@types/object-hash": "^3.0.4",
"@types/uuid": "^3.0.0",
"typescript": "^5.1.3"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver<PowerSyncDB
});
}

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

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

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

/**
* @ignore
* @ignore
*/
private async executeReadOnly(sql: string, params: any[]) {
await this.waitForReady();
Expand Down
18 changes: 16 additions & 2 deletions packages/powersync-sdk-common/src/client/sync/bucket/CrudEntry.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import hash from 'object-hash';
import _ from 'lodash';

/**
* 64-bit unsigned integer stored as a string in base-10.
Expand Down Expand Up @@ -108,10 +108,24 @@ export class CrudEntry {
};
}

equals(entry: CrudEntry) {
return _.isEqual(this.toComparisonArray(), entry.toComparisonArray());
}

/**
* The hash code for this object.
* @deprecated This should not be necessary in the JS SDK.
* Use the @see CrudEntry#equals method instead.
* TODO remove in the next major release.
*/
hashCode() {
return hash([this.transactionId, this.clientId, this.op, this.table, this.id, this.opData]);
return JSON.stringify(this.toComparisonArray());
}

/**
* Generates an array for use in deep comparison operations
*/
toComparisonArray() {
return [this.transactionId, this.clientId, this.op, this.table, this.id, this.opData];
}
}
10 changes: 0 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 69592d0

Please sign in to comment.