@superblocksteam/shared 0.9148.0 → 0.9151.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.
@@ -1,3 +1,7 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- export declare function connectWebSocket(wsUrl: string, protocol?: string | string[]): Promise<WebSocket>;
2
+ /**
3
+ * If the connection is not established within the timeout, the promise will be rejected.
4
+ * This can happen with bad network conditions, but is very rare.
5
+ */
6
+ export declare function connectWebSocket(wsUrl: string, protocol?: string | string[], timeout?: number): Promise<WebSocket>;
3
7
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAchG"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAoBlH"}
@@ -5,14 +5,23 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.connectWebSocket = void 0;
7
7
  const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
8
- function connectWebSocket(wsUrl, protocol) {
8
+ /**
9
+ * If the connection is not established within the timeout, the promise will be rejected.
10
+ * This can happen with bad network conditions, but is very rare.
11
+ */
12
+ function connectWebSocket(wsUrl, protocol, timeout = 30000) {
9
13
  return new Promise((resolve, reject) => {
10
14
  const ws = new isomorphic_ws_1.default(wsUrl, protocol);
15
+ const timeoutId = setTimeout(() => {
16
+ reject(new Error('Connection timeout'));
17
+ }, timeout);
11
18
  ws.addEventListener('open', () => {
19
+ clearTimeout(timeoutId);
12
20
  // Resolve the promise with the WebSocket instance when the connection is open
13
21
  resolve(ws);
14
22
  });
15
23
  ws.addEventListener('error', (error) => {
24
+ clearTimeout(timeoutId);
16
25
  // Reject the promise if there's an error
17
26
  reject(error);
18
27
  });
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAsC;AAEtC,SAAgB,gBAAgB,CAAC,KAAa,EAAE,QAA4B;IAC1E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,EAAE,GAAG,IAAI,uBAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE1C,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YAC/B,8EAA8E;YAC9E,OAAO,CAAC,EAAE,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACrC,yCAAyC;YACzC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AAdD,4CAcC"}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAsC;AAEtC;;;GAGG;AACH,SAAgB,gBAAgB,CAAC,KAAa,EAAE,QAA4B,EAAE,OAAO,GAAG,KAAM;IAC5F,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,EAAE,GAAG,IAAI,uBAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE1C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAChC,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAC1C,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YAC/B,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,8EAA8E;YAC9E,OAAO,CAAC,EAAE,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACrC,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,yCAAyC;YACzC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC;AApBD,4CAoBC"}
@@ -1,3 +1,7 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- export declare function connectWebSocket(wsUrl: string, protocol?: string | string[]): Promise<WebSocket>;
2
+ /**
3
+ * If the connection is not established within the timeout, the promise will be rejected.
4
+ * This can happen with bad network conditions, but is very rare.
5
+ */
6
+ export declare function connectWebSocket(wsUrl: string, protocol?: string | string[], timeout?: number): Promise<WebSocket>;
3
7
  //# sourceMappingURL=util.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAchG"}
1
+ {"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,EAAE,OAAO,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,CAoBlH"}
@@ -1,12 +1,21 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
- export function connectWebSocket(wsUrl, protocol) {
2
+ /**
3
+ * If the connection is not established within the timeout, the promise will be rejected.
4
+ * This can happen with bad network conditions, but is very rare.
5
+ */
6
+ export function connectWebSocket(wsUrl, protocol, timeout = 30000) {
3
7
  return new Promise((resolve, reject) => {
4
8
  const ws = new WebSocket(wsUrl, protocol);
9
+ const timeoutId = setTimeout(() => {
10
+ reject(new Error('Connection timeout'));
11
+ }, timeout);
5
12
  ws.addEventListener('open', () => {
13
+ clearTimeout(timeoutId);
6
14
  // Resolve the promise with the WebSocket instance when the connection is open
7
15
  resolve(ws);
8
16
  });
9
17
  ws.addEventListener('error', (error) => {
18
+ clearTimeout(timeoutId);
10
19
  // Reject the promise if there's an error
11
20
  reject(error);
12
21
  });
@@ -1 +1 @@
1
- {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,QAA4B;IAC1E,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE1C,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YAC/B,8EAA8E;YAC9E,OAAO,CAAC,EAAE,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACrC,yCAAyC;YACzC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
1
+ {"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/socket/util.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,eAAe,CAAC;AAEtC;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,QAA4B,EAAE,OAAO,GAAG,KAAM;IAC5F,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACrC,MAAM,EAAE,GAAG,IAAI,SAAS,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAE1C,MAAM,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAChC,MAAM,CAAC,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC,CAAC;QAC1C,CAAC,EAAE,OAAO,CAAC,CAAC;QAEZ,EAAE,CAAC,gBAAgB,CAAC,MAAM,EAAE,GAAG,EAAE;YAC/B,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,8EAA8E;YAC9E,OAAO,CAAC,EAAE,CAAC,CAAC;QACd,CAAC,CAAC,CAAC;QAEH,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,EAAE;YACrC,YAAY,CAAC,SAAS,CAAC,CAAC;YACxB,yCAAyC;YACzC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;AACL,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superblocksteam/shared",
3
- "version": "0.9148.0",
3
+ "version": "0.9151.0",
4
4
  "description": "Superblocks Shared Resources",
5
5
  "repository": "https://github.com/superblocksteam/shared.git",
6
6
  "license": "Superblocks Community Software License",
@@ -25,7 +25,7 @@
25
25
  "@opentelemetry/api": "^1.9.0",
26
26
  "@opentelemetry/semantic-conventions": "^1.28.0",
27
27
  "@rockset/client": "0.8.32",
28
- "@superblocksteam/types": "0.1859.0",
28
+ "@superblocksteam/types": "0.1860.0",
29
29
  "@types/esprima": "4.0.3",
30
30
  "@types/estree": "^1.0.5",
31
31
  "google-protobuf": "3.21.2",
@@ -1,15 +1,25 @@
1
1
  import WebSocket from 'isomorphic-ws';
2
2
 
3
- export function connectWebSocket(wsUrl: string, protocol?: string | string[]): Promise<WebSocket> {
3
+ /**
4
+ * If the connection is not established within the timeout, the promise will be rejected.
5
+ * This can happen with bad network conditions, but is very rare.
6
+ */
7
+ export function connectWebSocket(wsUrl: string, protocol?: string | string[], timeout = 30_000): Promise<WebSocket> {
4
8
  return new Promise((resolve, reject) => {
5
9
  const ws = new WebSocket(wsUrl, protocol);
6
10
 
11
+ const timeoutId = setTimeout(() => {
12
+ reject(new Error('Connection timeout'));
13
+ }, timeout);
14
+
7
15
  ws.addEventListener('open', () => {
16
+ clearTimeout(timeoutId);
8
17
  // Resolve the promise with the WebSocket instance when the connection is open
9
18
  resolve(ws);
10
19
  });
11
20
 
12
21
  ws.addEventListener('error', (error) => {
22
+ clearTimeout(timeoutId);
13
23
  // Reject the promise if there's an error
14
24
  reject(error);
15
25
  });