@powersync/shared-internals 1.3.1 → 1.5.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/websockets.mjs +29 -1
- package/dist/websockets.mjs.map +1 -1
- package/dist/websockets.node.mjs +29 -1
- package/dist/websockets.node.mjs.map +1 -1
- package/lib/client/BasePowerSyncDatabase.d.ts +12 -6
- package/lib/client/BasePowerSyncDatabase.js +11 -15
- package/lib/client/BasePowerSyncDatabase.js.map +1 -1
- package/lib/client/ConnectionManager.d.ts +7 -5
- package/lib/client/ConnectionManager.js +29 -15
- package/lib/client/ConnectionManager.js.map +1 -1
- package/lib/client/InternalConnector.d.ts +9 -0
- package/lib/client/InternalConnector.js +42 -0
- package/lib/client/InternalConnector.js.map +1 -0
- package/lib/client/sync/options.d.ts +4 -0
- package/lib/client/sync/options.js +7 -1
- package/lib/client/sync/options.js.map +1 -1
- package/lib/client/sync/stream/AbstractRemote.d.ts +7 -9
- package/lib/client/sync/stream/AbstractRemote.js +13 -5
- package/lib/client/sync/stream/AbstractRemote.js.map +1 -1
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.d.ts +12 -14
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +147 -82
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js.map +1 -1
- package/lib/client/sync/stream/WebSocketSupport.js +29 -1
- package/lib/client/sync/stream/WebSocketSupport.js.map +1 -1
- package/lib/client/sync/stream/core-instruction.d.ts +28 -1
- package/lib/client/sync/stream/core-instruction.js.map +1 -1
- package/lib/client/watched/DifferentialQueryProcessor.js +5 -0
- package/lib/client/watched/DifferentialQueryProcessor.js.map +1 -1
- package/lib/db/crud/SyncStatus.d.ts +2 -5
- package/lib/db/crud/SyncStatus.js +5 -18
- package/lib/db/crud/SyncStatus.js.map +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +2 -0
- package/lib/index.js.map +1 -1
- package/lib/utils/async.d.ts +6 -0
- package/lib/utils/async.js +31 -0
- package/lib/utils/async.js.map +1 -1
- package/lib/utils/error-serialization.d.ts +27 -0
- package/lib/utils/error-serialization.js +90 -0
- package/lib/utils/error-serialization.js.map +1 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -3
- package/src/client/BasePowerSyncDatabase.ts +24 -19
- package/src/client/ConnectionManager.ts +32 -19
- package/src/client/InternalConnector.ts +68 -0
- package/src/client/sync/options.ts +8 -1
- package/src/client/sync/stream/AbstractRemote.ts +33 -25
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +177 -106
- package/src/client/sync/stream/WebSocketSupport.ts +32 -1
- package/src/client/sync/stream/core-instruction.ts +25 -2
- package/src/client/watched/DifferentialQueryProcessor.ts +5 -0
- package/src/db/crud/SyncStatus.ts +6 -19
- package/src/index.ts +3 -0
- package/src/utils/async.ts +36 -0
- package/src/utils/error-serialization.ts +116 -0
- package/src/version.ts +1 -1
package/dist/websockets.mjs
CHANGED
|
@@ -7385,6 +7385,9 @@ class WebSocketSupport {
|
|
|
7385
7385
|
// While we're connecting (a process that can't be aborted in RSocket), the WebSocket instance to close if we wanted
|
|
7386
7386
|
// to abort the connection.
|
|
7387
7387
|
let pendingSocket = null;
|
|
7388
|
+
// The transport's connect() only settles on `open` or `error`, but a socket that closes while it's still opening fires
|
|
7389
|
+
// only `close` on React Native iOS and no event at all on Android. So we fail it ourselves.
|
|
7390
|
+
let failPendingConnect = null;
|
|
7388
7391
|
let keepAliveTimeout;
|
|
7389
7392
|
let rsocket = null;
|
|
7390
7393
|
let paused = false;
|
|
@@ -7409,6 +7412,7 @@ class WebSocketSupport {
|
|
|
7409
7412
|
if (pendingSocket) {
|
|
7410
7413
|
pendingSocket.close();
|
|
7411
7414
|
}
|
|
7415
|
+
failPendingConnect?.(new Error('WebSocket connection closed while opening'));
|
|
7412
7416
|
if (rsocket) {
|
|
7413
7417
|
rsocket.close();
|
|
7414
7418
|
}
|
|
@@ -7455,6 +7459,9 @@ class WebSocketSupport {
|
|
|
7455
7459
|
socket.addEventListener('message', () => {
|
|
7456
7460
|
resetTimeout();
|
|
7457
7461
|
});
|
|
7462
|
+
socket.addEventListener('close', () => {
|
|
7463
|
+
failPendingConnect?.(new Error('WebSocket connection closed while opening'));
|
|
7464
|
+
});
|
|
7458
7465
|
return socket;
|
|
7459
7466
|
}
|
|
7460
7467
|
}),
|
|
@@ -7473,9 +7480,21 @@ class WebSocketSupport {
|
|
|
7473
7480
|
}
|
|
7474
7481
|
});
|
|
7475
7482
|
try {
|
|
7476
|
-
rsocket = await
|
|
7483
|
+
rsocket = await new Promise((resolve, reject) => {
|
|
7484
|
+
failPendingConnect = reject;
|
|
7485
|
+
connector.connect().then((socket) => {
|
|
7486
|
+
if (didClose) {
|
|
7487
|
+
// We already gave up on this connection, don't leave it open.
|
|
7488
|
+
socket.close();
|
|
7489
|
+
}
|
|
7490
|
+
else {
|
|
7491
|
+
resolve(socket);
|
|
7492
|
+
}
|
|
7493
|
+
}, reject);
|
|
7494
|
+
});
|
|
7477
7495
|
// The connection is established, we no longer need to monitor the initial timeout
|
|
7478
7496
|
pendingSocket = null;
|
|
7497
|
+
failPendingConnect = null;
|
|
7479
7498
|
}
|
|
7480
7499
|
catch (ex) {
|
|
7481
7500
|
remote.logger.log({ level: this.#platform.LogLevels.error, message: `Failed to connect WebSocket`, error: ex });
|
|
@@ -7486,6 +7505,7 @@ class WebSocketSupport {
|
|
|
7486
7505
|
// Helps to prevent double close scenarios
|
|
7487
7506
|
rsocket.onClose(() => (rsocket = null));
|
|
7488
7507
|
return await new Promise((resolve, reject) => {
|
|
7508
|
+
failPendingConnect = reject;
|
|
7489
7509
|
const queueAsIterator = {
|
|
7490
7510
|
next: async () => {
|
|
7491
7511
|
if (didClose)
|
|
@@ -7522,6 +7542,7 @@ class WebSocketSupport {
|
|
|
7522
7542
|
if (e.message !== 'Closed. ') {
|
|
7523
7543
|
remote.logger.log({ level: this.#platform.LogLevels.error, message: 'RSocket error', error: e });
|
|
7524
7544
|
}
|
|
7545
|
+
failPendingConnect = null; // We'll fail this ourselves
|
|
7525
7546
|
// RSocket will close the RSocket stream automatically
|
|
7526
7547
|
// Close the downstream stream as well - this will close the RSocket connection and WebSocket
|
|
7527
7548
|
abortRequest();
|
|
@@ -7532,6 +7553,7 @@ class WebSocketSupport {
|
|
|
7532
7553
|
},
|
|
7533
7554
|
onNext: (payload) => {
|
|
7534
7555
|
// The connection is active
|
|
7556
|
+
failPendingConnect = null;
|
|
7535
7557
|
if (!connectionEstablished) {
|
|
7536
7558
|
connectionEstablished = true;
|
|
7537
7559
|
resolve(queueAsIterator);
|
|
@@ -7546,7 +7568,13 @@ class WebSocketSupport {
|
|
|
7546
7568
|
requestMore();
|
|
7547
7569
|
},
|
|
7548
7570
|
onComplete: () => {
|
|
7571
|
+
failPendingConnect = null; // We'll fail this ourselves
|
|
7549
7572
|
abortRequest(); // this will also emit a done event
|
|
7573
|
+
if (!connectionEstablished) {
|
|
7574
|
+
// Closed without ever emitting an event? Still emit an empty queue.
|
|
7575
|
+
connectionEstablished = true;
|
|
7576
|
+
resolve(queueAsIterator);
|
|
7577
|
+
}
|
|
7550
7578
|
},
|
|
7551
7579
|
onExtension: () => { }
|
|
7552
7580
|
});
|