From ca458d3dffee22245edd6fcc6d93017683d1b065 Mon Sep 17 00:00:00 2001 From: Steven Ontong Date: Tue, 24 Oct 2023 13:50:28 +0200 Subject: [PATCH] added changeset. use latest packages --- .changeset/chilled-walls-promise.md | 6 ++++++ .../src/client/AbstractPowerSyncDatabase.ts | 17 +++++++++++++++-- .../powersync-sdk-react-native/package.json | 4 ++-- yarn.lock | 8 ++++---- 4 files changed, 27 insertions(+), 8 deletions(-) create mode 100644 .changeset/chilled-walls-promise.md diff --git a/.changeset/chilled-walls-promise.md b/.changeset/chilled-walls-promise.md new file mode 100644 index 00000000..6af427c0 --- /dev/null +++ b/.changeset/chilled-walls-promise.md @@ -0,0 +1,6 @@ +--- +'@journeyapps/powersync-sdk-react-native': patch +'@journeyapps/powersync-sdk-common': patch +--- + +Updated logic to correspond with React Native Quick SQLite concurrent transactions. Added helper methods on transaction contexts. diff --git a/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts b/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts index c9af43a7..b5b98b56 100644 --- a/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts +++ b/packages/powersync-sdk-common/src/client/AbstractPowerSyncDatabase.ts @@ -46,6 +46,13 @@ export const DEFAULT_POWERSYNC_DB_OPTIONS = { logger: Logger.get('PowerSyncDatabase') }; +/** + * Requesting nested or recursive locks can block the application in some circumstances. + * This default lock timeout will act as a failsafe to throw an error if a lock cannot + * be obtained. + */ +export const DEFAULT_LOCK_TIMEOUT_MS = 120_000; // 2 mins + export abstract class AbstractPowerSyncDatabase extends BaseObserver { /** * Transactions should be queued in the DBAdapter, but we also want to prevent @@ -353,7 +360,10 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver(callback: (tx: Transaction) => Promise, lockTimeout?: number): Promise { + async readTransaction( + callback: (tx: Transaction) => Promise, + lockTimeout: number = DEFAULT_LOCK_TIMEOUT_MS + ): Promise { await this.initialized; return this.database.readTransaction( async (tx) => { @@ -365,7 +375,10 @@ export abstract class AbstractPowerSyncDatabase extends BaseObserver(callback: (tx: Transaction) => Promise, lockTimeout?: number): Promise { + async writeTransaction( + callback: (tx: Transaction) => Promise, + lockTimeout: number = DEFAULT_LOCK_TIMEOUT_MS + ): Promise { await this.initialized; return this.database.writeTransaction( async (tx) => { diff --git a/packages/powersync-sdk-react-native/package.json b/packages/powersync-sdk-react-native/package.json index 61ffe8bf..7f595a68 100644 --- a/packages/powersync-sdk-react-native/package.json +++ b/packages/powersync-sdk-react-native/package.json @@ -24,7 +24,7 @@ }, "homepage": "https://docs.powersync.co/", "peerDependencies": { - "@journeyapps/react-native-quick-sqlite": "0.0.0-dev-20231023173642", + "@journeyapps/react-native-quick-sqlite": "0.0.0-dev-20231024112335", "base-64": "^1.0.0", "react": "*", "react-native-fetch-api": "^3.0.0", @@ -40,7 +40,7 @@ "async-lock": "^1.4.0" }, "devDependencies": { - "@journeyapps/react-native-quick-sqlite": "0.0.0-dev-20231023173642", + "@journeyapps/react-native-quick-sqlite": "0.0.0-dev-20231024112335", "@types/async-lock": "^1.4.0", "react": "18.2.0", "typescript": "^4.1.3" diff --git a/yarn.lock b/yarn.lock index 1ece8051..dfac3108 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2134,10 +2134,10 @@ "@types/yargs" "^17.0.8" chalk "^4.0.0" -"@journeyapps/react-native-quick-sqlite@0.0.0-dev-20231023173642": - version "0.0.0-dev-20231023173642" - resolved "https://registry.npmjs.org/@journeyapps/react-native-quick-sqlite/-/react-native-quick-sqlite-0.0.0-dev-20231023173642.tgz#00cfd6aec9674519ffbbc06245e7ce4ce42a0bcb" - integrity sha512-Na4XDi2u5AUZw+/mflV6LLIHJJvfvJxp5uYMDZtG+4WZ4dw0NDq+sZk+U26T/IU9xgdDWlcmwVKku9dDHLt7eg== +"@journeyapps/react-native-quick-sqlite@0.0.0-dev-20231024112335": + version "0.0.0-dev-20231024112335" + resolved "https://registry.npmjs.org/@journeyapps/react-native-quick-sqlite/-/react-native-quick-sqlite-0.0.0-dev-20231024112335.tgz#a386b718baef17cb1d51eebaa0487cc5cf19a864" + integrity sha512-Jpn+OSQ39xyJ6rnw06XPPHo1YrnCDOrZPaYGvVUEvUgjcMFYfmJ5YH0StM+/KnUcatKxksXYWyPiBqWO/Gg+hA== dependencies: lodash "^4.17.21"