@powersync/web 0.0.0-dev-20250210155038 → 0.0.0-dev-20250220093908
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 +27 -58
- package/dist/index.umd.js.map +1 -1
- package/dist/worker/SharedSyncImplementation.umd.js +85 -115
- package/dist/worker/SharedSyncImplementation.umd.js.map +1 -1
- package/dist/worker/WASQLiteDB.umd.js +58 -57
- package/dist/worker/WASQLiteDB.umd.js.map +1 -1
- package/lib/package.json +8 -4
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.d.ts +0 -2
- package/lib/src/db/adapters/WorkerWrappedAsyncDatabaseConnection.js +0 -31
- package/lib/src/worker/sync/SharedSyncImplementation.js +27 -27
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -5
package/dist/index.umd.js
CHANGED
|
@@ -34086,12 +34086,8 @@ __webpack_require__.r(__webpack_exports__);
|
|
|
34086
34086
|
*/
|
|
34087
34087
|
class WorkerWrappedAsyncDatabaseConnection {
|
|
34088
34088
|
options;
|
|
34089
|
-
releaseSharedConnectionLock;
|
|
34090
|
-
lockAbortController;
|
|
34091
34089
|
constructor(options) {
|
|
34092
34090
|
this.options = options;
|
|
34093
|
-
this.releaseSharedConnectionLock = null;
|
|
34094
|
-
this.lockAbortController = new AbortController();
|
|
34095
34091
|
}
|
|
34096
34092
|
get baseConnection() {
|
|
34097
34093
|
return this.options.baseConnection;
|
|
@@ -34104,30 +34100,6 @@ class WorkerWrappedAsyncDatabaseConnection {
|
|
|
34104
34100
|
*/
|
|
34105
34101
|
async shareConnection() {
|
|
34106
34102
|
const { identifier, remote } = this.options;
|
|
34107
|
-
/**
|
|
34108
|
-
* Hold a navigator lock in order to avoid features such as Chrome's frozen tabs,
|
|
34109
|
-
* or Edge's sleeping tabs from pausing the thread for this connection.
|
|
34110
|
-
* This promise resolves once a lock is obtained.
|
|
34111
|
-
* This lock will be held as long as this connection is open.
|
|
34112
|
-
* The `shareConnection` method should not be called on multiple tabs concurrently.
|
|
34113
|
-
*/
|
|
34114
|
-
await new Promise((lockObtained) => navigator.locks
|
|
34115
|
-
.request(`shared-connection-${this.options.identifier}`, {
|
|
34116
|
-
signal: this.lockAbortController.signal
|
|
34117
|
-
}, async () => {
|
|
34118
|
-
lockObtained();
|
|
34119
|
-
// Free the lock when the connection is already closed.
|
|
34120
|
-
if (this.lockAbortController.signal.aborted) {
|
|
34121
|
-
return;
|
|
34122
|
-
}
|
|
34123
|
-
// Hold the lock while the shared connection is in use.
|
|
34124
|
-
await new Promise((releaseLock) => {
|
|
34125
|
-
// We can use the resolver to free the lock
|
|
34126
|
-
this.releaseSharedConnectionLock = releaseLock;
|
|
34127
|
-
});
|
|
34128
|
-
})
|
|
34129
|
-
// We aren't concerned with errors here
|
|
34130
|
-
.catch(() => { }));
|
|
34131
34103
|
const newPort = await remote[comlink__WEBPACK_IMPORTED_MODULE_0__.createEndpoint]();
|
|
34132
34104
|
return { port: newPort, identifier };
|
|
34133
34105
|
}
|
|
@@ -34139,9 +34111,6 @@ class WorkerWrappedAsyncDatabaseConnection {
|
|
|
34139
34111
|
return this.baseConnection.registerOnTableChange(comlink__WEBPACK_IMPORTED_MODULE_0__.proxy(callback));
|
|
34140
34112
|
}
|
|
34141
34113
|
async close() {
|
|
34142
|
-
// Abort any pending lock requests.
|
|
34143
|
-
this.lockAbortController.abort();
|
|
34144
|
-
this.releaseSharedConnectionLock?.();
|
|
34145
34114
|
await this.baseConnection.close();
|
|
34146
34115
|
this.options.remote[comlink__WEBPACK_IMPORTED_MODULE_0__.releaseProxy]();
|
|
34147
34116
|
this.options.onClose?.();
|
|
@@ -35636,6 +35605,9 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35636
35605
|
await this.waitForReady();
|
|
35637
35606
|
// This effectively queues connect and disconnect calls. Ensuring multiple tabs' requests are synchronized
|
|
35638
35607
|
return (0,_shared_navigator__WEBPACK_IMPORTED_MODULE_8__.getNavigatorLocks)().request('shared-sync-connect', async () => {
|
|
35608
|
+
if (!this.dbAdapter) {
|
|
35609
|
+
await this.openInternalDB();
|
|
35610
|
+
}
|
|
35639
35611
|
this.syncStreamClient = this.generateStreamingImplementation();
|
|
35640
35612
|
this.lastConnectOptions = options;
|
|
35641
35613
|
this.syncStreamClient.registerListener({
|
|
@@ -35659,10 +35631,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35659
35631
|
* Adds a new client tab's message port to the list of connected ports
|
|
35660
35632
|
*/
|
|
35661
35633
|
addPort(port) {
|
|
35662
|
-
const portProvider = {
|
|
35663
|
-
port,
|
|
35664
|
-
clientProvider: comlink__WEBPACK_IMPORTED_MODULE_2__.wrap(port)
|
|
35665
|
-
};
|
|
35634
|
+
const portProvider = { port, clientProvider: comlink__WEBPACK_IMPORTED_MODULE_2__.wrap(port) };
|
|
35666
35635
|
this.ports.push(portProvider);
|
|
35667
35636
|
// Give the newly connected client the latest status
|
|
35668
35637
|
const status = this.syncStreamClient?.syncStatus;
|
|
@@ -35681,11 +35650,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35681
35650
|
return;
|
|
35682
35651
|
}
|
|
35683
35652
|
const trackedPort = this.ports[index];
|
|
35684
|
-
|
|
35685
|
-
trackedPort.db.close();
|
|
35686
|
-
}
|
|
35687
|
-
// Release proxy
|
|
35688
|
-
trackedPort.clientProvider[comlink__WEBPACK_IMPORTED_MODULE_2__.releaseProxy]();
|
|
35653
|
+
// Remove from the list of active ports
|
|
35689
35654
|
this.ports.splice(index, 1);
|
|
35690
35655
|
/**
|
|
35691
35656
|
* The port might currently be in use. Any active functions might
|
|
@@ -35696,12 +35661,22 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35696
35661
|
abortController.controller.abort(new _powersync_common__WEBPACK_IMPORTED_MODULE_0__.AbortOperation('Closing pending requests after client port is removed'));
|
|
35697
35662
|
}
|
|
35698
35663
|
});
|
|
35699
|
-
|
|
35700
|
-
|
|
35701
|
-
|
|
35702
|
-
|
|
35703
|
-
|
|
35664
|
+
const shouldReconnect = !!this.syncStreamClient;
|
|
35665
|
+
if (this.dbAdapter && this.dbAdapter == trackedPort.db) {
|
|
35666
|
+
if (shouldReconnect) {
|
|
35667
|
+
await this.disconnect();
|
|
35668
|
+
}
|
|
35669
|
+
// Clearing the adapter will result in a new one being opened in connect
|
|
35670
|
+
this.dbAdapter = null;
|
|
35671
|
+
if (shouldReconnect) {
|
|
35672
|
+
await this.connect(this.lastConnectOptions);
|
|
35673
|
+
}
|
|
35674
|
+
}
|
|
35675
|
+
if (trackedPort.db) {
|
|
35676
|
+
trackedPort.db.close();
|
|
35704
35677
|
}
|
|
35678
|
+
// Release proxy
|
|
35679
|
+
trackedPort.clientProvider[comlink__WEBPACK_IMPORTED_MODULE_2__.releaseProxy]();
|
|
35705
35680
|
}
|
|
35706
35681
|
triggerCrudUpload() {
|
|
35707
35682
|
this.waitForReady().then(() => this.syncStreamClient?.triggerCrudUpload());
|
|
@@ -35729,10 +35704,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35729
35704
|
const lastPort = this.ports[this.ports.length - 1];
|
|
35730
35705
|
return new Promise(async (resolve, reject) => {
|
|
35731
35706
|
const abortController = new AbortController();
|
|
35732
|
-
this.fetchCredentialsController = {
|
|
35733
|
-
controller: abortController,
|
|
35734
|
-
activePort: lastPort
|
|
35735
|
-
};
|
|
35707
|
+
this.fetchCredentialsController = { controller: abortController, activePort: lastPort };
|
|
35736
35708
|
abortController.signal.onabort = reject;
|
|
35737
35709
|
try {
|
|
35738
35710
|
console.log('calling the last port client provider for credentials');
|
|
@@ -35751,10 +35723,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35751
35723
|
const lastPort = this.ports[this.ports.length - 1];
|
|
35752
35724
|
return new Promise(async (resolve, reject) => {
|
|
35753
35725
|
const abortController = new AbortController();
|
|
35754
|
-
this.uploadDataController = {
|
|
35755
|
-
controller: abortController,
|
|
35756
|
-
activePort: lastPort
|
|
35757
|
-
};
|
|
35726
|
+
this.uploadDataController = { controller: abortController, activePort: lastPort };
|
|
35758
35727
|
// Resolving will make it retry
|
|
35759
35728
|
abortController.signal.onabort = () => resolve();
|
|
35760
35729
|
try {
|
|
@@ -35775,6 +35744,10 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35775
35744
|
}
|
|
35776
35745
|
async openInternalDB() {
|
|
35777
35746
|
const lastClient = this.ports[this.ports.length - 1];
|
|
35747
|
+
if (!lastClient) {
|
|
35748
|
+
// Should not really happen in practice
|
|
35749
|
+
throw new Error(`Could not open DB connection since no client is connected.`);
|
|
35750
|
+
}
|
|
35778
35751
|
const workerPort = await lastClient.clientProvider.getDBWorkerPort();
|
|
35779
35752
|
const remote = comlink__WEBPACK_IMPORTED_MODULE_2__.wrap(workerPort);
|
|
35780
35753
|
const identifier = this.syncParams.dbParams.dbFilename;
|
|
@@ -35782,11 +35755,7 @@ class SharedSyncImplementation extends _powersync_common__WEBPACK_IMPORTED_MODUL
|
|
|
35782
35755
|
const locked = new _db_adapters_LockedAsyncDatabaseAdapter__WEBPACK_IMPORTED_MODULE_6__.LockedAsyncDatabaseAdapter({
|
|
35783
35756
|
name: identifier,
|
|
35784
35757
|
openConnection: async () => {
|
|
35785
|
-
return new _db_adapters_WorkerWrappedAsyncDatabaseConnection__WEBPACK_IMPORTED_MODULE_7__.WorkerWrappedAsyncDatabaseConnection({
|
|
35786
|
-
remote,
|
|
35787
|
-
baseConnection: db,
|
|
35788
|
-
identifier
|
|
35789
|
-
});
|
|
35758
|
+
return new _db_adapters_WorkerWrappedAsyncDatabaseConnection__WEBPACK_IMPORTED_MODULE_7__.WorkerWrappedAsyncDatabaseConnection({ remote, baseConnection: db, identifier });
|
|
35790
35759
|
},
|
|
35791
35760
|
logger: this.logger
|
|
35792
35761
|
});
|