@powersync/web 0.0.0-dev-20251126195153 → 0.0.0-dev-20251127205344
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 +46 -34
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +27 -17
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.d.ts +1 -1
- package/lib/src/db/sync/SharedWebStreamingSyncImplementation.js +15 -13
- package/lib/src/worker/sync/SharedSyncImplementation.js +21 -11
- package/lib/src/worker/sync/WorkerClient.d.ts +1 -1
- package/lib/src/worker/sync/WorkerClient.js +2 -2
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/db/sync/SharedWebStreamingSyncImplementation.ts +18 -16
- package/src/worker/sync/SharedSyncImplementation.ts +23 -13
- package/src/worker/sync/WorkerClient.ts +5 -4
|
@@ -19060,6 +19060,20 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
19060
19060
|
}
|
|
19061
19061
|
});
|
|
19062
19062
|
const shouldReconnect = !!this.connectionManager.syncStreamImplementation && this.ports.length > 0;
|
|
19063
|
+
/**
|
|
19064
|
+
* If the current database adapter is the one that is being closed, we need to disconnect from the backend.
|
|
19065
|
+
* We can disconnect in the portMutex lock. This ensures the disconnect is not affected by potential other
|
|
19066
|
+
* connect operations coming from other tabs.
|
|
19067
|
+
*/
|
|
19068
|
+
if (this.dbAdapter && this.dbAdapter == trackedPort.db) {
|
|
19069
|
+
this.logger.debug(`Disconnecting due to closed database: should reconnect: ${shouldReconnect}`);
|
|
19070
|
+
this.dbAdapter = null;
|
|
19071
|
+
// Unconditionally close the connection because the database it's writing to has just been closed.
|
|
19072
|
+
// The connection has been closed previously, this might throw. We should be able to ignore it.
|
|
19073
|
+
await this.connectionManager
|
|
19074
|
+
.disconnect()
|
|
19075
|
+
.catch((ex) => this.logger.warn('Error while disconnecting. Will attempt to reconnect.', ex));
|
|
19076
|
+
}
|
|
19063
19077
|
return {
|
|
19064
19078
|
shouldReconnect,
|
|
19065
19079
|
trackedPort
|
|
@@ -19072,17 +19086,8 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
19072
19086
|
for (const closeListener of trackedPort.closeListeners) {
|
|
19073
19087
|
await closeListener();
|
|
19074
19088
|
}
|
|
19075
|
-
if (
|
|
19076
|
-
|
|
19077
|
-
// The connection has been closed previously, this might throw. We should be able to ignore it.
|
|
19078
|
-
await this.connectionManager
|
|
19079
|
-
.disconnect()
|
|
19080
|
-
.catch((ex) => this.logger.warn('Error while disconnecting. Will attempt to reconnect.', ex));
|
|
19081
|
-
// Clearing the adapter will result in a new one being opened in connect
|
|
19082
|
-
this.dbAdapter = null;
|
|
19083
|
-
if (shouldReconnect) {
|
|
19084
|
-
await this.connectionManager.connect(CONNECTOR_PLACEHOLDER, this.lastConnectOptions ?? {});
|
|
19085
|
-
}
|
|
19089
|
+
if (shouldReconnect) {
|
|
19090
|
+
await this.connectionManager.connect(CONNECTOR_PLACEHOLDER, this.lastConnectOptions ?? {});
|
|
19086
19091
|
}
|
|
19087
19092
|
// Re-index subscriptions, the subscriptions of the removed port would no longer be considered.
|
|
19088
19093
|
this.collectActiveSubscriptions();
|
|
@@ -19208,6 +19213,11 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
19208
19213
|
});
|
|
19209
19214
|
lastClient.closeListeners.push(async () => {
|
|
19210
19215
|
this.logger.info('Aborting open connection because associated tab closed.');
|
|
19216
|
+
/**
|
|
19217
|
+
* Don't await this close operation. It might never resolve if the tab is closed.
|
|
19218
|
+
* We run the close operation first, before marking the remote as closed. This gives the database some chance
|
|
19219
|
+
* to close the connection.
|
|
19220
|
+
*/
|
|
19211
19221
|
wrapped.close().catch((ex) => this.logger.warn('error closing database connection', ex));
|
|
19212
19222
|
wrapped.markRemoteClosed();
|
|
19213
19223
|
});
|
|
@@ -19254,8 +19264,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
19254
19264
|
/* harmony export */ WorkerClient: () => (/* binding */ WorkerClient)
|
|
19255
19265
|
/* harmony export */ });
|
|
19256
19266
|
/* harmony import */ var comlink__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(/*! comlink */ "../../node_modules/comlink/dist/esm/comlink.mjs");
|
|
19257
|
-
/* harmony import */ var
|
|
19258
|
-
/* harmony import */ var
|
|
19267
|
+
/* harmony import */ var _shared_navigator__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ../../shared/navigator */ "./lib/src/shared/navigator.js");
|
|
19268
|
+
/* harmony import */ var _SharedSyncImplementation__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! ./SharedSyncImplementation */ "./lib/src/worker/sync/SharedSyncImplementation.js");
|
|
19259
19269
|
|
|
19260
19270
|
|
|
19261
19271
|
|
|
@@ -19272,6 +19282,7 @@ class WorkerClient {
|
|
|
19272
19282
|
constructor(sync, port) {
|
|
19273
19283
|
this.sync = sync;
|
|
19274
19284
|
this.port = port;
|
|
19285
|
+
comlink__WEBPACK_IMPORTED_MODULE_2__.expose(this, this.port);
|
|
19275
19286
|
}
|
|
19276
19287
|
async initialize() {
|
|
19277
19288
|
/**
|
|
@@ -19280,12 +19291,11 @@ class WorkerClient {
|
|
|
19280
19291
|
*/
|
|
19281
19292
|
this.port.addEventListener('message', async (event) => {
|
|
19282
19293
|
const payload = event.data;
|
|
19283
|
-
if (payload?.event ==
|
|
19294
|
+
if (payload?.event == _SharedSyncImplementation__WEBPACK_IMPORTED_MODULE_1__.SharedSyncClientEvent.CLOSE_CLIENT) {
|
|
19284
19295
|
await this.removePort();
|
|
19285
19296
|
}
|
|
19286
19297
|
});
|
|
19287
19298
|
this.resolvedPort = await this.sync.addPort(this.port);
|
|
19288
|
-
comlink__WEBPACK_IMPORTED_MODULE_2__.expose(this, this.port);
|
|
19289
19299
|
}
|
|
19290
19300
|
async removePort() {
|
|
19291
19301
|
if (this.resolvedPort) {
|
|
@@ -19294,7 +19304,7 @@ class WorkerClient {
|
|
|
19294
19304
|
const release = await this.sync.removePort(resolved);
|
|
19295
19305
|
this.resolvedPort = null;
|
|
19296
19306
|
this.port.postMessage({
|
|
19297
|
-
event:
|
|
19307
|
+
event: _SharedSyncImplementation__WEBPACK_IMPORTED_MODULE_1__.SharedSyncClientEvent.CLOSE_ACK,
|
|
19298
19308
|
data: {}
|
|
19299
19309
|
});
|
|
19300
19310
|
release?.();
|
|
@@ -19307,7 +19317,7 @@ class WorkerClient {
|
|
|
19307
19317
|
* it can consider the connection to be closed.
|
|
19308
19318
|
*/
|
|
19309
19319
|
addLockBasedCloseSignal(name) {
|
|
19310
|
-
(0,
|
|
19320
|
+
(0,_shared_navigator__WEBPACK_IMPORTED_MODULE_0__.getNavigatorLocks)().request(name, async () => {
|
|
19311
19321
|
await this.removePort();
|
|
19312
19322
|
});
|
|
19313
19323
|
}
|