@delali/sirannon-db 0.3.5-next.72 → 0.3.5-next.74

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.
@@ -3895,6 +3895,17 @@ function createWSHandler(sirannon, options) {
3895
3895
  }
3896
3896
 
3897
3897
  // src/server/ws-route.ts
3898
+ function endWebSocket(ws, code, reason) {
3899
+ const upgradeState = ws.getUserData().upgradeState;
3900
+ if (upgradeState.upgrading) {
3901
+ upgradeState.endAfterUpgrade ??= () => endWebSocket(ws, code, reason);
3902
+ return;
3903
+ }
3904
+ try {
3905
+ ws.end(code, reason);
3906
+ } catch {
3907
+ }
3908
+ }
3898
3909
  var UNSUPPORTED_SUBPROTOCOL_MESSAGE = `The upgrade offered no subprotocol this server supports. Offer '${SIRANNON_WS_SUBPROTOCOL}' alongside any credential-bearing value, or offer none at all.`;
3899
3910
  var UWS_SEND_BACKPRESSURE = 0;
3900
3911
  var UWS_SEND_DROPPED = 2;
@@ -3935,9 +3946,23 @@ function registerWebSocketRoute(options) {
3935
3946
  }
3936
3947
  const selectedWebSocketProtocol = negotiated.protocol;
3937
3948
  const upgrade = (userData) => {
3938
- endResponse(res, () => {
3939
- res.upgrade(userData, secWebSocketKey, selectedWebSocketProtocol, secWebSocketExtensions, context);
3940
- });
3949
+ const upgradeState = { upgrading: true, endAfterUpgrade: void 0 };
3950
+ try {
3951
+ endResponse(res, () => {
3952
+ res.upgrade(
3953
+ { ...userData, upgradeState },
3954
+ secWebSocketKey,
3955
+ selectedWebSocketProtocol,
3956
+ secWebSocketExtensions,
3957
+ context
3958
+ );
3959
+ });
3960
+ } finally {
3961
+ const endAfterUpgrade = upgradeState.endAfterUpgrade;
3962
+ upgradeState.upgrading = false;
3963
+ upgradeState.endAfterUpgrade = void 0;
3964
+ endAfterUpgrade?.();
3965
+ }
3941
3966
  };
3942
3967
  if (!authenticateHook) {
3943
3968
  if (!abort.claim()) return;
@@ -3973,10 +3998,7 @@ function registerWebSocketRoute(options) {
3973
3998
  const userData = ws.getUserData();
3974
3999
  const refusal = userData.refusal;
3975
4000
  if (refusal) {
3976
- try {
3977
- ws.end(refusal.code, refusal.reason);
3978
- } catch {
3979
- }
4001
+ endWebSocket(ws, refusal.code, refusal.reason);
3980
4002
  return;
3981
4003
  }
3982
4004
  let closing = false;
@@ -4012,10 +4034,7 @@ function registerWebSocketRoute(options) {
4012
4034
  },
4013
4035
  close(code, reason) {
4014
4036
  closing = true;
4015
- try {
4016
- ws.end(code, reason);
4017
- } catch {
4018
- }
4037
+ endWebSocket(ws, code, reason);
4019
4038
  }
4020
4039
  };
4021
4040
  userData.conn = conn;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@delali/sirannon-db",
3
3
  "type": "module",
4
- "version": "0.3.5-next.72",
4
+ "version": "0.3.5-next.74",
5
5
  "description": "A production-grade library that turns SQLite databases into a networked data layer with real-time subscriptions.",
6
6
  "author": "Delali (https://sondelali.com)",
7
7
  "license": "Apache-2.0",
@@ -149,7 +149,7 @@
149
149
  },
150
150
  "peerDependencies": {
151
151
  "@bufbuild/protobuf": ">=2.0.0",
152
- "@delali/sirannon-sqlite": "0.3.5-next.72",
152
+ "@delali/sirannon-sqlite": "0.3.5-next.74",
153
153
  "@grpc/grpc-js": ">=1.10.0",
154
154
  "better-sqlite3": ">=12.0.0",
155
155
  "etcd3": ">=1.1.2",
@@ -193,7 +193,7 @@
193
193
  },
194
194
  "devDependencies": {
195
195
  "@bufbuild/protobuf": "2.11.0",
196
- "@delali/sirannon-sqlite": "0.3.5-next.72",
196
+ "@delali/sirannon-sqlite": "0.3.5-next.74",
197
197
  "@grpc/grpc-js": "1.14.4",
198
198
  "@microsoft/api-extractor": "7.58.12",
199
199
  "@types/better-sqlite3": "7.6.13",
@@ -221,11 +221,11 @@
221
221
  "vitest": "4.0.18"
222
222
  },
223
223
  "optionalDependencies": {
224
- "@delali/sirannon-vfs-darwin-arm64": "0.3.5-next.72",
225
- "@delali/sirannon-vfs-darwin-x64": "0.3.5-next.72",
226
- "@delali/sirannon-vfs-linux-arm64": "0.3.5-next.72",
227
- "@delali/sirannon-vfs-linux-x64": "0.3.5-next.72",
228
- "@delali/sirannon-vfs-win32-arm64": "0.3.5-next.72",
229
- "@delali/sirannon-vfs-win32-x64": "0.3.5-next.72"
224
+ "@delali/sirannon-vfs-darwin-arm64": "0.3.5-next.74",
225
+ "@delali/sirannon-vfs-darwin-x64": "0.3.5-next.74",
226
+ "@delali/sirannon-vfs-linux-arm64": "0.3.5-next.74",
227
+ "@delali/sirannon-vfs-linux-x64": "0.3.5-next.74",
228
+ "@delali/sirannon-vfs-win32-arm64": "0.3.5-next.74",
229
+ "@delali/sirannon-vfs-win32-x64": "0.3.5-next.74"
230
230
  }
231
231
  }