@powersync/op-sqlite 0.5.5 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/lib/commonjs/db/OPSqliteAdapter.js +21 -7
- package/lib/commonjs/db/OPSqliteAdapter.js.map +1 -1
- package/lib/module/db/OPSqliteAdapter.js +21 -7
- package/lib/module/db/OPSqliteAdapter.js.map +1 -1
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts +2 -1
- package/lib/typescript/commonjs/src/db/OPSqliteAdapter.d.ts.map +1 -1
- package/lib/typescript/commonjs/tsconfig.build.tsbuildinfo +1 -1
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts +2 -1
- package/lib/typescript/module/src/db/OPSqliteAdapter.d.ts.map +1 -1
- package/lib/typescript/module/tsconfig.build.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/OPSqliteAdapter.ts +25 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powersync/op-sqlite",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "PowerSync - sync Postgres or MongoDB with SQLite in your React Native app for offline-first and real-time data",
|
|
5
5
|
"source": "./src/index.ts",
|
|
6
6
|
"main": "./lib/commonjs/index.js",
|
|
@@ -59,13 +59,13 @@
|
|
|
59
59
|
},
|
|
60
60
|
"peerDependencies": {
|
|
61
61
|
"@op-engineering/op-sqlite": "^11.2.13",
|
|
62
|
-
"@powersync/common": "^1.
|
|
62
|
+
"@powersync/common": "^1.31.0",
|
|
63
63
|
"react": "*",
|
|
64
64
|
"react-native": "*"
|
|
65
65
|
},
|
|
66
66
|
"dependencies": {
|
|
67
67
|
"async-lock": "^1.4.0",
|
|
68
|
-
"@powersync/common": "1.
|
|
68
|
+
"@powersync/common": "1.31.0"
|
|
69
69
|
},
|
|
70
70
|
"devDependencies": {
|
|
71
71
|
"@op-engineering/op-sqlite": "^11.2.13",
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
|
|
2
1
|
import { ANDROID_DATABASE_PATH, getDylibPath, IOS_LIBRARY_PATH, open, type DB } from '@op-engineering/op-sqlite';
|
|
2
|
+
import { BaseObserver, DBAdapter, DBAdapterListener, DBLockOptions, QueryResult, Transaction } from '@powersync/common';
|
|
3
3
|
import Lock from 'async-lock';
|
|
4
|
-
import { OPSQLiteConnection } from './OPSQLiteConnection';
|
|
5
4
|
import { Platform } from 'react-native';
|
|
5
|
+
import { OPSQLiteConnection } from './OPSQLiteConnection';
|
|
6
6
|
import { SqliteOptions } from './SqliteOptions';
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -32,6 +32,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
32
32
|
protected writeConnection: OPSQLiteConnection | null;
|
|
33
33
|
|
|
34
34
|
private readQueue: Array<() => void> = [];
|
|
35
|
+
private abortController: AbortController;
|
|
35
36
|
|
|
36
37
|
constructor(protected options: OPSQLiteAdapterOptions) {
|
|
37
38
|
super();
|
|
@@ -40,6 +41,7 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
40
41
|
this.locks = new Lock();
|
|
41
42
|
this.readConnections = null;
|
|
42
43
|
this.writeConnection = null;
|
|
44
|
+
this.abortController = new AbortController();
|
|
43
45
|
this.initialized = this.init();
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -153,11 +155,14 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
153
155
|
}
|
|
154
156
|
}
|
|
155
157
|
|
|
156
|
-
close() {
|
|
157
|
-
this.initialized
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
158
|
+
async close() {
|
|
159
|
+
await this.initialized;
|
|
160
|
+
// Abort any pending operations
|
|
161
|
+
this.abortController.abort();
|
|
162
|
+
this.readQueue = [];
|
|
163
|
+
|
|
164
|
+
this.writeConnection!.close();
|
|
165
|
+
this.readConnections!.forEach((c) => c.connection.close());
|
|
161
166
|
}
|
|
162
167
|
|
|
163
168
|
async readLock<T>(fn: (tx: OPSQLiteConnection) => Promise<T>, options?: DBLockOptions): Promise<T> {
|
|
@@ -203,10 +208,20 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
203
208
|
|
|
204
209
|
return new Promise(async (resolve, reject) => {
|
|
205
210
|
try {
|
|
211
|
+
// Set up abort signal listener
|
|
212
|
+
const abortListener = () => {
|
|
213
|
+
reject(new Error('Database connection was closed'));
|
|
214
|
+
};
|
|
215
|
+
this.abortController.signal.addEventListener('abort', abortListener);
|
|
216
|
+
|
|
206
217
|
await this.locks
|
|
207
218
|
.acquire(
|
|
208
219
|
LockType.WRITE,
|
|
209
220
|
async () => {
|
|
221
|
+
// Check if operation was aborted before executing
|
|
222
|
+
if (this.abortController.signal.aborted) {
|
|
223
|
+
reject(new Error('Database connection was closed'));
|
|
224
|
+
}
|
|
210
225
|
resolve(await fn(this.writeConnection!));
|
|
211
226
|
},
|
|
212
227
|
{ timeout: options?.timeoutMs }
|
|
@@ -214,6 +229,9 @@ export class OPSQLiteDBAdapter extends BaseObserver<DBAdapterListener> implement
|
|
|
214
229
|
.then(() => {
|
|
215
230
|
// flush updates once a write lock has been released
|
|
216
231
|
this.writeConnection!.flushUpdates();
|
|
232
|
+
})
|
|
233
|
+
.finally(() => {
|
|
234
|
+
this.abortController.signal.removeEventListener('abort', abortListener);
|
|
217
235
|
});
|
|
218
236
|
} catch (ex) {
|
|
219
237
|
reject(ex);
|