starknet 10.6.6 → 10.6.7
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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.global.js +58 -25
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +58 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +58 -25
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -7394,6 +7394,8 @@ var WebSocketChannel = class {
|
|
|
7394
7394
|
// resetting the reconnection attempt counter.
|
|
7395
7395
|
reconnectStabilityTimeoutId = null;
|
|
7396
7396
|
requestQueue = [];
|
|
7397
|
+
/** Abort handles for the requests currently on the wire, one per pending `sendReceive`. */
|
|
7398
|
+
inFlight = /* @__PURE__ */ new Set();
|
|
7397
7399
|
events = new EventEmitter();
|
|
7398
7400
|
openListener = (ev) => {
|
|
7399
7401
|
this.scheduleReconnectAttemptsReset();
|
|
@@ -7477,12 +7479,19 @@ var WebSocketChannel = class {
|
|
|
7477
7479
|
});
|
|
7478
7480
|
}
|
|
7479
7481
|
const sendId = this.send(method, params);
|
|
7482
|
+
const socket = this.websocket;
|
|
7480
7483
|
return new Promise((resolve, reject) => {
|
|
7481
|
-
|
|
7482
|
-
if (!this.websocket || this.websocket.readyState !== ws_default.OPEN) {
|
|
7484
|
+
if (socket.readyState !== ws_default.OPEN) {
|
|
7483
7485
|
reject(new WebSocketNotConnectedError("WebSocket not available or not connected."));
|
|
7484
7486
|
return;
|
|
7485
7487
|
}
|
|
7488
|
+
let timeoutId;
|
|
7489
|
+
const settle = () => {
|
|
7490
|
+
clearTimeout(timeoutId);
|
|
7491
|
+
socket.removeEventListener("message", messageHandler);
|
|
7492
|
+
socket.removeEventListener("error", errorHandler);
|
|
7493
|
+
this.inFlight.delete(abort);
|
|
7494
|
+
};
|
|
7486
7495
|
const messageHandler = (event) => {
|
|
7487
7496
|
if (!isString(event.data)) {
|
|
7488
7497
|
logger.warn("WebSocket received non-string message data:", event.data);
|
|
@@ -7497,34 +7506,35 @@ var WebSocketChannel = class {
|
|
|
7497
7506
|
);
|
|
7498
7507
|
return;
|
|
7499
7508
|
}
|
|
7500
|
-
if (message.id
|
|
7501
|
-
|
|
7502
|
-
|
|
7503
|
-
|
|
7504
|
-
|
|
7505
|
-
|
|
7506
|
-
} else {
|
|
7507
|
-
reject(
|
|
7508
|
-
new Error(`Error on ${method} (id: ${sendId}): ${JSON.stringify(message.error)}`)
|
|
7509
|
-
);
|
|
7510
|
-
}
|
|
7509
|
+
if (message.id !== sendId) return;
|
|
7510
|
+
settle();
|
|
7511
|
+
if ("result" in message) {
|
|
7512
|
+
resolve(message.result);
|
|
7513
|
+
} else {
|
|
7514
|
+
reject(new Error(`Error on ${method} (id: ${sendId}): ${JSON.stringify(message.error)}`));
|
|
7511
7515
|
}
|
|
7512
7516
|
};
|
|
7513
7517
|
const errorHandler = (event) => {
|
|
7514
|
-
|
|
7515
|
-
this.websocket.removeEventListener("message", messageHandler);
|
|
7516
|
-
this.websocket.removeEventListener("error", errorHandler);
|
|
7518
|
+
settle();
|
|
7517
7519
|
reject(
|
|
7518
7520
|
new Error(
|
|
7519
7521
|
`WebSocket error during ${method} (id: ${sendId}): ${event.type || "Unknown error"}`
|
|
7520
7522
|
)
|
|
7521
7523
|
);
|
|
7522
7524
|
};
|
|
7523
|
-
|
|
7524
|
-
|
|
7525
|
+
const abort = (reason) => {
|
|
7526
|
+
settle();
|
|
7527
|
+
reject(
|
|
7528
|
+
new WebSocketNotConnectedError(
|
|
7529
|
+
`Request ${method} (id: ${sendId}) went unanswered: ${reason}`
|
|
7530
|
+
)
|
|
7531
|
+
);
|
|
7532
|
+
};
|
|
7533
|
+
socket.addEventListener("message", messageHandler);
|
|
7534
|
+
socket.addEventListener("error", errorHandler);
|
|
7535
|
+
this.inFlight.add(abort);
|
|
7525
7536
|
timeoutId = setTimeout(() => {
|
|
7526
|
-
|
|
7527
|
-
this.websocket.removeEventListener("error", errorHandler);
|
|
7537
|
+
settle();
|
|
7528
7538
|
reject(
|
|
7529
7539
|
new TimeoutError(
|
|
7530
7540
|
`Request ${method} (id: ${sendId}) timed out after ${this.requestTimeout}ms`
|
|
@@ -7581,6 +7591,7 @@ var WebSocketChannel = class {
|
|
|
7581
7591
|
this.userInitiatedClose = true;
|
|
7582
7592
|
this.isReconnecting = false;
|
|
7583
7593
|
this._rejectRequestQueue("the connection was closed by the user");
|
|
7594
|
+
this._rejectInFlight("the connection was closed by the user");
|
|
7584
7595
|
this.websocket.close(code, reason);
|
|
7585
7596
|
}
|
|
7586
7597
|
/**
|
|
@@ -7672,6 +7683,21 @@ var WebSocketChannel = class {
|
|
|
7672
7683
|
reject(new WebSocketNotConnectedError(`Request ${method} was never sent: ${reason}`));
|
|
7673
7684
|
});
|
|
7674
7685
|
}
|
|
7686
|
+
/**
|
|
7687
|
+
* Settle every request already on the wire.
|
|
7688
|
+
*
|
|
7689
|
+
* The counterpart of `_rejectRequestQueue`, for requests past the queue. Their only other
|
|
7690
|
+
* exit is the `requestTimeout` timer, so without this the caller waits the whole timeout —
|
|
7691
|
+
* 60s by default — for a reply that can no longer arrive, and that pending timer keeps the
|
|
7692
|
+
* Node event loop alive for just as long.
|
|
7693
|
+
*/
|
|
7694
|
+
_rejectInFlight(reason) {
|
|
7695
|
+
if (this.inFlight.size === 0) return;
|
|
7696
|
+
const pending = Array.from(this.inFlight);
|
|
7697
|
+
this.inFlight.clear();
|
|
7698
|
+
logger.info(`WebSocket: Rejecting ${pending.length} in-flight request(s). Reason: ${reason}.`);
|
|
7699
|
+
pending.forEach((abort) => abort(reason));
|
|
7700
|
+
}
|
|
7675
7701
|
async _restoreSubscriptions() {
|
|
7676
7702
|
const oldSubscriptions = Array.from(this.activeSubscriptions.values());
|
|
7677
7703
|
this.activeSubscriptions.clear();
|
|
@@ -7725,18 +7751,24 @@ var WebSocketChannel = class {
|
|
|
7725
7751
|
`WebSocket: Connection lost. Attempting to reconnect... (${this.reconnectAttempts}/${this.reconnectOptions.retries})`
|
|
7726
7752
|
);
|
|
7727
7753
|
this.reconnect();
|
|
7754
|
+
let attemptSettled = false;
|
|
7755
|
+
const scheduleRetry = () => {
|
|
7756
|
+
if (attemptSettled || !this.isReconnecting) return;
|
|
7757
|
+
attemptSettled = true;
|
|
7758
|
+
const delay = this.reconnectOptions.exponential ? this.reconnectOptions.delay * 2 ** (this.reconnectAttempts - 1) : this.reconnectOptions.delay;
|
|
7759
|
+
logger.info(`WebSocket: Reconnect attempt failed. Retrying in ${delay}ms.`);
|
|
7760
|
+
this.reconnectTimeoutId = setTimeout(tryReconnect, delay);
|
|
7761
|
+
};
|
|
7728
7762
|
this.websocket.onopen = async () => {
|
|
7729
7763
|
logger.info("WebSocket: Reconnection successful.");
|
|
7764
|
+
attemptSettled = true;
|
|
7730
7765
|
this.isReconnecting = false;
|
|
7731
7766
|
await this._restoreSubscriptions();
|
|
7732
7767
|
this._processRequestQueue();
|
|
7733
7768
|
this.events.emit("open", new Event("open"));
|
|
7734
7769
|
};
|
|
7735
|
-
this.websocket.onerror =
|
|
7736
|
-
|
|
7737
|
-
logger.info(`WebSocket: Reconnect attempt failed. Retrying in ${delay}ms.`);
|
|
7738
|
-
this.reconnectTimeoutId = setTimeout(tryReconnect, delay);
|
|
7739
|
-
};
|
|
7770
|
+
this.websocket.onerror = scheduleRetry;
|
|
7771
|
+
this.websocket.addEventListener("close", scheduleRetry);
|
|
7740
7772
|
};
|
|
7741
7773
|
tryReconnect();
|
|
7742
7774
|
}
|
|
@@ -7745,6 +7777,7 @@ var WebSocketChannel = class {
|
|
|
7745
7777
|
this.websocket.removeEventListener("close", this.closeListener);
|
|
7746
7778
|
this.websocket.removeEventListener("message", this.messageListener);
|
|
7747
7779
|
this.websocket.removeEventListener("error", this.errorListener);
|
|
7780
|
+
this._rejectInFlight("the connection was closed");
|
|
7748
7781
|
this.events.emit("close", ev);
|
|
7749
7782
|
if (!this.userInitiatedClose) {
|
|
7750
7783
|
this._startReconnect();
|