@powersync/web 1.28.2 → 1.29.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/dist/index.umd.js +71 -9
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +8394 -4429
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +12886 -10924
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/lib/package.json +2 -2
- package/lib/src/db/adapters/AsyncDatabaseConnection.d.ts +15 -0
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.d.ts +2 -1
- package/lib/src/db/adapters/LockedAsyncDatabaseAdapter.js +17 -2
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +3 -0
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +11 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.d.ts +22 -0
- package/lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js +32 -0
- package/lib/src/worker/db/SharedWASQLiteConnection.d.ts +42 -0
- package/lib/src/worker/db/SharedWASQLiteConnection.js +90 -0
- package/lib/src/worker/db/WASQLiteDB.worker.js +22 -39
- package/lib/src/worker/db/WorkerWASQLiteConnection.d.ts +9 -0
- package/lib/src/worker/db/WorkerWASQLiteConnection.js +12 -0
- package/lib/src/worker/sync/SharedSyncImplementation.d.ts +2 -2
- package/lib/src/worker/sync/SharedSyncImplementation.js +7 -4
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/db/adapters/AsyncDatabaseConnection.ts +15 -0
- package/src/db/adapters/LockedAsyncDatabaseAdapter.ts +29 -10
- package/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.ts +14 -0
- package/src/db/adapters/wa-sqlite/WASQLiteConnection.ts +45 -0
- package/src/worker/db/SharedWASQLiteConnection.ts +131 -0
- package/src/worker/db/WASQLiteDB.worker.ts +25 -54
- package/src/worker/db/WorkerWASQLiteConnection.ts +14 -0
- package/src/worker/sync/SharedSyncImplementation.ts +15 -12
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3460.index.umd.js +0 -355
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3460.index.umd.js.map +0 -1
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3461.index.umd.js +0 -355
- package/dist/_journeyapps_wa-sqlite-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVFS_js-_journeyapp-81d3461.index.umd.js.map +0 -1
package/dist/index.umd.js
CHANGED
|
@@ -38700,6 +38700,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
38700
38700
|
/* harmony import */ var _powersync_common__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_powersync_common__WEBPACK_IMPORTED_MODULE_0__);
|
|
38701
38701
|
/* harmony import */ var _shared_navigator__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ../..//shared/navigator */ "./lib/src/shared/navigator.js");
|
|
38702
38702
|
/* harmony import */ var _WorkerWrappedAsyncDatabaseConnection__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! ./WorkerWrappedAsyncDatabaseConnection */ "./lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js");
|
|
38703
|
+
/* harmony import */ var _wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(/*! ./wa-sqlite/WASQLiteConnection */ "./lib/src/db/adapters/wa-sqlite/WASQLiteConnection.js");
|
|
38704
|
+
|
|
38703
38705
|
|
|
38704
38706
|
|
|
38705
38707
|
|
|
@@ -38719,6 +38721,7 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
|
|
|
38719
38721
|
_disposeTableChangeListener = null;
|
|
38720
38722
|
_config = null;
|
|
38721
38723
|
pendingAbortControllers;
|
|
38724
|
+
requiresHolds;
|
|
38722
38725
|
closing;
|
|
38723
38726
|
closed;
|
|
38724
38727
|
constructor(options) {
|
|
@@ -38729,6 +38732,7 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
|
|
|
38729
38732
|
this.pendingAbortControllers = new Set();
|
|
38730
38733
|
this.closed = false;
|
|
38731
38734
|
this.closing = false;
|
|
38735
|
+
this.requiresHolds = null;
|
|
38732
38736
|
// Set the name if provided. We can query for the name if not available yet
|
|
38733
38737
|
this.debugMode = options.debugMode ?? false;
|
|
38734
38738
|
if (this.debugMode) {
|
|
@@ -38773,6 +38777,10 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
|
|
|
38773
38777
|
this._config = await this._db.getConfig();
|
|
38774
38778
|
await this.registerOnChangeListener(this._db);
|
|
38775
38779
|
this.iterateListeners((cb) => cb.initialized?.());
|
|
38780
|
+
/**
|
|
38781
|
+
* This is only required for the long-lived shared IndexedDB connections.
|
|
38782
|
+
*/
|
|
38783
|
+
this.requiresHolds = this._config.vfs == _wa_sqlite_WASQLiteConnection__WEBPACK_IMPORTED_MODULE_3__.WASQLiteVFS.IDBBatchAtomicVFS;
|
|
38776
38784
|
}
|
|
38777
38785
|
getConfiguration() {
|
|
38778
38786
|
if (!this._config) {
|
|
@@ -38862,12 +38870,20 @@ class LockedAsyncDatabaseAdapter extends _powersync_common__WEBPACK_IMPORTED_MOD
|
|
|
38862
38870
|
this.pendingAbortControllers.delete(abortController);
|
|
38863
38871
|
}, timeoutMs)
|
|
38864
38872
|
: null;
|
|
38865
|
-
return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, () => {
|
|
38873
|
+
return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_1__.getNavigatorLocks)().request(`db-lock-${this._dbIdentifier}`, { signal: abortController.signal }, async () => {
|
|
38866
38874
|
this.pendingAbortControllers.delete(abortController);
|
|
38867
38875
|
if (timoutId) {
|
|
38868
38876
|
clearTimeout(timoutId);
|
|
38869
38877
|
}
|
|
38870
|
-
|
|
38878
|
+
const holdId = this.requiresHolds ? await this.baseDB.markHold() : null;
|
|
38879
|
+
try {
|
|
38880
|
+
return await callback();
|
|
38881
|
+
}
|
|
38882
|
+
finally {
|
|
38883
|
+
if (holdId) {
|
|
38884
|
+
await this.baseDB.releaseHold(holdId);
|
|
38885
|
+
}
|
|
38886
|
+
}
|
|
38871
38887
|
});
|
|
38872
38888
|
}
|
|
38873
38889
|
async readTransaction(fn, options) {
|
|
@@ -39119,12 +39135,23 @@ class WorkerWrappedAsyncDatabaseConnection {
|
|
|
39119
39135
|
// set.
|
|
39120
39136
|
this.notifyRemoteClosed.abort();
|
|
39121
39137
|
}
|
|
39138
|
+
markHold() {
|
|
39139
|
+
return this.withRemote(() => this.baseConnection.markHold());
|
|
39140
|
+
}
|
|
39141
|
+
releaseHold(holdId) {
|
|
39142
|
+
return this.withRemote(() => this.baseConnection.releaseHold(holdId));
|
|
39143
|
+
}
|
|
39144
|
+
isAutoCommit() {
|
|
39145
|
+
return this.withRemote(() => this.baseConnection.isAutoCommit());
|
|
39146
|
+
}
|
|
39122
39147
|
withRemote(workerPromise) {
|
|
39123
39148
|
const controller = this.notifyRemoteClosed;
|
|
39124
39149
|
if (controller) {
|
|
39125
39150
|
return new Promise((resolve, reject) => {
|
|
39126
39151
|
if (controller.signal.aborted) {
|
|
39127
39152
|
reject(new Error('Called operation on closed remote'));
|
|
39153
|
+
// Don't run the operation if we're going to reject
|
|
39154
|
+
return;
|
|
39128
39155
|
}
|
|
39129
39156
|
function handleAbort() {
|
|
39130
39157
|
reject(new Error('Remote peer closed with request in flight'));
|
|
@@ -39351,6 +39378,8 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
|
|
|
39351
39378
|
* notification loops.
|
|
39352
39379
|
*/
|
|
39353
39380
|
connectionId;
|
|
39381
|
+
_holdCounter;
|
|
39382
|
+
_holdId;
|
|
39354
39383
|
constructor(options) {
|
|
39355
39384
|
super();
|
|
39356
39385
|
this.options = options;
|
|
@@ -39360,6 +39389,15 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
|
|
|
39360
39389
|
this.connectionId = new Date().valueOf() + Math.random();
|
|
39361
39390
|
this.statementMutex = new async_mutex__WEBPACK_IMPORTED_MODULE_2__.Mutex();
|
|
39362
39391
|
this._moduleFactory = DEFAULT_MODULE_FACTORIES[this.options.vfs];
|
|
39392
|
+
this._holdCounter = 0;
|
|
39393
|
+
this._holdId = null;
|
|
39394
|
+
}
|
|
39395
|
+
/**
|
|
39396
|
+
* Gets the id for the current hold.
|
|
39397
|
+
* This can be used to check for invalid states.
|
|
39398
|
+
*/
|
|
39399
|
+
get currentHoldId() {
|
|
39400
|
+
return this._holdId;
|
|
39363
39401
|
}
|
|
39364
39402
|
get sqliteAPI() {
|
|
39365
39403
|
if (!this._sqliteAPI) {
|
|
@@ -39373,6 +39411,27 @@ class WASqliteConnection extends _powersync_common__WEBPACK_IMPORTED_MODULE_1__.
|
|
|
39373
39411
|
}
|
|
39374
39412
|
return this._dbP;
|
|
39375
39413
|
}
|
|
39414
|
+
/**
|
|
39415
|
+
* Checks if the database connection is in autocommit mode.
|
|
39416
|
+
* @returns true if in autocommit mode, false if in a transaction
|
|
39417
|
+
*/
|
|
39418
|
+
async isAutoCommit() {
|
|
39419
|
+
return this.sqliteAPI.get_autocommit(this.dbP) != 0;
|
|
39420
|
+
}
|
|
39421
|
+
async markHold() {
|
|
39422
|
+
const previousHoldId = this._holdId;
|
|
39423
|
+
this._holdId = `${++this._holdCounter}`;
|
|
39424
|
+
if (previousHoldId) {
|
|
39425
|
+
await this.iterateAsyncListeners(async (cb) => cb.holdOverwritten?.(previousHoldId));
|
|
39426
|
+
}
|
|
39427
|
+
return this._holdId;
|
|
39428
|
+
}
|
|
39429
|
+
async releaseHold(holdId) {
|
|
39430
|
+
if (holdId != this._holdId) {
|
|
39431
|
+
throw new Error(`Invalid hold state, expected ${this._holdId} but got ${holdId}`);
|
|
39432
|
+
}
|
|
39433
|
+
this._holdId = null;
|
|
39434
|
+
}
|
|
39376
39435
|
async openDB() {
|
|
39377
39436
|
this._dbP = await this.sqliteAPI.open_v2(this.options.dbFilename);
|
|
39378
39437
|
return this._dbP;
|
|
@@ -40107,7 +40166,7 @@ class SharedWebStreamingSyncImplementation extends _WebStreamingSyncImplementati
|
|
|
40107
40166
|
}
|
|
40108
40167
|
}
|
|
40109
40168
|
else {
|
|
40110
|
-
this.messagePort = new SharedWorker(new URL(/* worker import */ __webpack_require__.p + __webpack_require__.u("
|
|
40169
|
+
this.messagePort = new SharedWorker(new URL(/* worker import */ __webpack_require__.p + __webpack_require__.u("lib_src_worker_sync_SharedSyncImplementation_worker_js-_journeyapps_wa-sqlite-_journeyapps_wa-4748cf"), __webpack_require__.b), {
|
|
40111
40170
|
/* @vite-ignore */
|
|
40112
40171
|
name: `shared-sync-${this.webOptions.identifier}`,
|
|
40113
40172
|
type: undefined
|
|
@@ -40458,12 +40517,12 @@ function openWorkerDatabasePort(workerIdentifier, multipleTabs = true, worker =
|
|
|
40458
40517
|
* (in the case of Android)
|
|
40459
40518
|
*/
|
|
40460
40519
|
return !needsDedicated && multipleTabs
|
|
40461
|
-
? new SharedWorker(new URL(/* worker import */ __webpack_require__.p + __webpack_require__.u("
|
|
40520
|
+
? new SharedWorker(new URL(/* worker import */ __webpack_require__.p + __webpack_require__.u("lib_src_worker_db_WASQLiteDB_worker_js-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVF-1dc7800"), __webpack_require__.b), {
|
|
40462
40521
|
/* @vite-ignore */
|
|
40463
40522
|
name: `shared-DB-worker-${workerIdentifier}`,
|
|
40464
40523
|
type: undefined
|
|
40465
40524
|
}).port
|
|
40466
|
-
: new Worker(new URL(/* worker import */ __webpack_require__.p + __webpack_require__.u("
|
|
40525
|
+
: new Worker(new URL(/* worker import */ __webpack_require__.p + __webpack_require__.u("lib_src_worker_db_WASQLiteDB_worker_js-_journeyapps_wa-sqlite_src_examples_AccessHandlePoolVF-1dc7801"), __webpack_require__.b), {
|
|
40467
40526
|
/* @vite-ignore */
|
|
40468
40527
|
name: `DB-worker-${workerIdentifier}`,
|
|
40469
40528
|
type: undefined
|
|
@@ -40906,11 +40965,14 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
40906
40965
|
return () => { };
|
|
40907
40966
|
}
|
|
40908
40967
|
for (const closeListener of trackedPort.closeListeners) {
|
|
40909
|
-
closeListener();
|
|
40968
|
+
await closeListener();
|
|
40910
40969
|
}
|
|
40911
40970
|
if (this.dbAdapter && this.dbAdapter == trackedPort.db) {
|
|
40912
40971
|
// Unconditionally close the connection because the database it's writing to has just been closed.
|
|
40913
|
-
|
|
40972
|
+
// The connection has been closed previously, this might throw. We should be able to ignore it.
|
|
40973
|
+
await this.connectionManager
|
|
40974
|
+
.disconnect()
|
|
40975
|
+
.catch((ex) => this.logger.warn('Error while disconnecting. Will attempt to reconnect.', ex));
|
|
40914
40976
|
// Clearing the adapter will result in a new one being opened in connect
|
|
40915
40977
|
this.dbAdapter = null;
|
|
40916
40978
|
if (shouldReconnect) {
|
|
@@ -41039,9 +41101,9 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
41039
41101
|
// that and ensure pending requests are aborted when the tab is closed.
|
|
41040
41102
|
remoteCanCloseUnexpectedly: true
|
|
41041
41103
|
});
|
|
41042
|
-
lastClient.closeListeners.push(() => {
|
|
41104
|
+
lastClient.closeListeners.push(async () => {
|
|
41043
41105
|
this.logger.info('Aborting open connection because associated tab closed.');
|
|
41044
|
-
wrapped.close();
|
|
41106
|
+
await wrapped.close().catch((ex) => this.logger.warn('error closing database connection', ex));
|
|
41045
41107
|
wrapped.markRemoteClosed();
|
|
41046
41108
|
});
|
|
41047
41109
|
return wrapped;
|