@powersync/shared-internals 1.4.0 → 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 +6 -5
- package/lib/client/ConnectionManager.js +22 -14
- 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 +5 -0
- 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 +6 -13
- package/lib/client/sync/stream/AbstractStreamingSyncImplementation.js +135 -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 +2 -0
- 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/index.d.ts +1 -0
- package/lib/index.js +1 -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/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 +25 -19
- package/src/client/InternalConnector.ts +68 -0
- package/src/client/sync/options.ts +6 -0
- package/src/client/sync/stream/AbstractRemote.ts +33 -25
- package/src/client/sync/stream/AbstractStreamingSyncImplementation.ts +163 -105
- package/src/client/sync/stream/WebSocketSupport.ts +32 -1
- package/src/client/sync/stream/core-instruction.ts +1 -0
- package/src/client/watched/DifferentialQueryProcessor.ts +5 -0
- package/src/index.ts +1 -0
- package/src/utils/async.ts +36 -0
- package/src/version.ts +1 -1
package/dist/websockets.node.mjs
CHANGED
|
@@ -5016,6 +5016,9 @@ class WebSocketSupport {
|
|
|
5016
5016
|
// While we're connecting (a process that can't be aborted in RSocket), the WebSocket instance to close if we wanted
|
|
5017
5017
|
// to abort the connection.
|
|
5018
5018
|
let pendingSocket = null;
|
|
5019
|
+
// The transport's connect() only settles on `open` or `error`, but a socket that closes while it's still opening fires
|
|
5020
|
+
// only `close` on React Native iOS and no event at all on Android. So we fail it ourselves.
|
|
5021
|
+
let failPendingConnect = null;
|
|
5019
5022
|
let keepAliveTimeout;
|
|
5020
5023
|
let rsocket = null;
|
|
5021
5024
|
let paused = false;
|
|
@@ -5040,6 +5043,7 @@ class WebSocketSupport {
|
|
|
5040
5043
|
if (pendingSocket) {
|
|
5041
5044
|
pendingSocket.close();
|
|
5042
5045
|
}
|
|
5046
|
+
failPendingConnect?.(new Error('WebSocket connection closed while opening'));
|
|
5043
5047
|
if (rsocket) {
|
|
5044
5048
|
rsocket.close();
|
|
5045
5049
|
}
|
|
@@ -5086,6 +5090,9 @@ class WebSocketSupport {
|
|
|
5086
5090
|
socket.addEventListener('message', () => {
|
|
5087
5091
|
resetTimeout();
|
|
5088
5092
|
});
|
|
5093
|
+
socket.addEventListener('close', () => {
|
|
5094
|
+
failPendingConnect?.(new Error('WebSocket connection closed while opening'));
|
|
5095
|
+
});
|
|
5089
5096
|
return socket;
|
|
5090
5097
|
}
|
|
5091
5098
|
}),
|
|
@@ -5104,9 +5111,21 @@ class WebSocketSupport {
|
|
|
5104
5111
|
}
|
|
5105
5112
|
});
|
|
5106
5113
|
try {
|
|
5107
|
-
rsocket = await
|
|
5114
|
+
rsocket = await new Promise((resolve, reject) => {
|
|
5115
|
+
failPendingConnect = reject;
|
|
5116
|
+
connector.connect().then((socket) => {
|
|
5117
|
+
if (didClose) {
|
|
5118
|
+
// We already gave up on this connection, don't leave it open.
|
|
5119
|
+
socket.close();
|
|
5120
|
+
}
|
|
5121
|
+
else {
|
|
5122
|
+
resolve(socket);
|
|
5123
|
+
}
|
|
5124
|
+
}, reject);
|
|
5125
|
+
});
|
|
5108
5126
|
// The connection is established, we no longer need to monitor the initial timeout
|
|
5109
5127
|
pendingSocket = null;
|
|
5128
|
+
failPendingConnect = null;
|
|
5110
5129
|
}
|
|
5111
5130
|
catch (ex) {
|
|
5112
5131
|
remote.logger.log({ level: this.#platform.LogLevels.error, message: `Failed to connect WebSocket`, error: ex });
|
|
@@ -5117,6 +5136,7 @@ class WebSocketSupport {
|
|
|
5117
5136
|
// Helps to prevent double close scenarios
|
|
5118
5137
|
rsocket.onClose(() => (rsocket = null));
|
|
5119
5138
|
return await new Promise((resolve, reject) => {
|
|
5139
|
+
failPendingConnect = reject;
|
|
5120
5140
|
const queueAsIterator = {
|
|
5121
5141
|
next: async () => {
|
|
5122
5142
|
if (didClose)
|
|
@@ -5153,6 +5173,7 @@ class WebSocketSupport {
|
|
|
5153
5173
|
if (e.message !== 'Closed. ') {
|
|
5154
5174
|
remote.logger.log({ level: this.#platform.LogLevels.error, message: 'RSocket error', error: e });
|
|
5155
5175
|
}
|
|
5176
|
+
failPendingConnect = null; // We'll fail this ourselves
|
|
5156
5177
|
// RSocket will close the RSocket stream automatically
|
|
5157
5178
|
// Close the downstream stream as well - this will close the RSocket connection and WebSocket
|
|
5158
5179
|
abortRequest();
|
|
@@ -5163,6 +5184,7 @@ class WebSocketSupport {
|
|
|
5163
5184
|
},
|
|
5164
5185
|
onNext: (payload) => {
|
|
5165
5186
|
// The connection is active
|
|
5187
|
+
failPendingConnect = null;
|
|
5166
5188
|
if (!connectionEstablished) {
|
|
5167
5189
|
connectionEstablished = true;
|
|
5168
5190
|
resolve(queueAsIterator);
|
|
@@ -5177,7 +5199,13 @@ class WebSocketSupport {
|
|
|
5177
5199
|
requestMore();
|
|
5178
5200
|
},
|
|
5179
5201
|
onComplete: () => {
|
|
5202
|
+
failPendingConnect = null; // We'll fail this ourselves
|
|
5180
5203
|
abortRequest(); // this will also emit a done event
|
|
5204
|
+
if (!connectionEstablished) {
|
|
5205
|
+
// Closed without ever emitting an event? Still emit an empty queue.
|
|
5206
|
+
connectionEstablished = true;
|
|
5207
|
+
resolve(queueAsIterator);
|
|
5208
|
+
}
|
|
5181
5209
|
},
|
|
5182
5210
|
onExtension: () => { }
|
|
5183
5211
|
});
|