@borealise/pipeline 1.0.0-alpha.0 → 1.0.0-alpha.1

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/index.d.mts CHANGED
@@ -207,6 +207,8 @@ interface PipelineClientOptions {
207
207
  }
208
208
 
209
209
  declare class PipelineClient {
210
+ private static readonly WS_CONNECTING;
211
+ private static readonly WS_OPEN;
210
212
  private readonly logger;
211
213
  private readonly options;
212
214
  private ws;
package/dist/index.d.ts CHANGED
@@ -207,6 +207,8 @@ interface PipelineClientOptions {
207
207
  }
208
208
 
209
209
  declare class PipelineClient {
210
+ private static readonly WS_CONNECTING;
211
+ private static readonly WS_OPEN;
210
212
  private readonly logger;
211
213
  private readonly options;
212
214
  private ws;
package/dist/index.js CHANGED
@@ -194,7 +194,7 @@ _Logger.loggers = /* @__PURE__ */ new Map();
194
194
  var Logger = _Logger;
195
195
 
196
196
  // src/PipelineClient.ts
197
- var PipelineClient = class {
197
+ var _PipelineClient = class _PipelineClient {
198
198
  constructor(options) {
199
199
  this.ws = null;
200
200
  this.sessionId = null;
@@ -234,13 +234,18 @@ var PipelineClient = class {
234
234
  this.logger.error("Cannot connect: missing pipeline url");
235
235
  return;
236
236
  }
237
- if (this.ws && (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN)) {
237
+ if (this.ws && (this.ws.readyState === _PipelineClient.WS_CONNECTING || this.ws.readyState === _PipelineClient.WS_OPEN)) {
238
238
  this.logger.warn("Already connected or connecting");
239
239
  return;
240
240
  }
241
241
  this.setState("connecting");
242
242
  try {
243
- const factory = this.options.webSocketFactory || ((url) => new WebSocket(url));
243
+ const factory = this.options.webSocketFactory || (typeof globalThis.WebSocket !== "undefined" ? ((url) => new globalThis.WebSocket(url)) : null);
244
+ if (!factory) {
245
+ this.logger.error("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
246
+ this.setState("disconnected");
247
+ return;
248
+ }
244
249
  this.ws = factory(this.options.url);
245
250
  this.ws.onopen = () => this.handleOpen();
246
251
  this.ws.onmessage = (event) => this.handleMessage(event);
@@ -437,7 +442,7 @@ var PipelineClient = class {
437
442
  if (!this.heartbeatInterval) return;
438
443
  const jitter = this.heartbeatInterval * 0.1 * (Math.random() * 2 - 1);
439
444
  const interval = this.heartbeatInterval + jitter;
440
- this.heartbeatTimer = window.setInterval(() => {
445
+ this.heartbeatTimer = globalThis.setInterval(() => {
441
446
  this.sendHeartbeat();
442
447
  }, interval);
443
448
  this.sendHeartbeat();
@@ -456,14 +461,14 @@ var PipelineClient = class {
456
461
  this.setState("reconnecting");
457
462
  const backoffIndex = Math.min(this.reconnectAttempts, this.reconnectBackoff.length - 1);
458
463
  const delay = this.reconnectBackoff[backoffIndex];
459
- this.reconnectTimer = window.setTimeout(() => {
464
+ this.reconnectTimer = globalThis.setTimeout(() => {
460
465
  this.reconnectAttempts += 1;
461
466
  this.emit("onReconnect", this.reconnectAttempts);
462
467
  this.connect();
463
468
  }, delay);
464
469
  }
465
470
  send(op, data) {
466
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
471
+ if (!this.ws || this.ws.readyState !== _PipelineClient.WS_OPEN) {
467
472
  this.logger.warn("Cannot send: not connected");
468
473
  return;
469
474
  }
@@ -499,6 +504,9 @@ var PipelineClient = class {
499
504
  return fromProvider;
500
505
  }
501
506
  };
507
+ _PipelineClient.WS_CONNECTING = 0;
508
+ _PipelineClient.WS_OPEN = 1;
509
+ var PipelineClient = _PipelineClient;
502
510
  function createPipeline(options) {
503
511
  return new PipelineClient(options);
504
512
  }
package/dist/index.mjs CHANGED
@@ -158,7 +158,7 @@ _Logger.loggers = /* @__PURE__ */ new Map();
158
158
  var Logger = _Logger;
159
159
 
160
160
  // src/PipelineClient.ts
161
- var PipelineClient = class {
161
+ var _PipelineClient = class _PipelineClient {
162
162
  constructor(options) {
163
163
  this.ws = null;
164
164
  this.sessionId = null;
@@ -198,13 +198,18 @@ var PipelineClient = class {
198
198
  this.logger.error("Cannot connect: missing pipeline url");
199
199
  return;
200
200
  }
201
- if (this.ws && (this.ws.readyState === WebSocket.CONNECTING || this.ws.readyState === WebSocket.OPEN)) {
201
+ if (this.ws && (this.ws.readyState === _PipelineClient.WS_CONNECTING || this.ws.readyState === _PipelineClient.WS_OPEN)) {
202
202
  this.logger.warn("Already connected or connecting");
203
203
  return;
204
204
  }
205
205
  this.setState("connecting");
206
206
  try {
207
- const factory = this.options.webSocketFactory || ((url) => new WebSocket(url));
207
+ const factory = this.options.webSocketFactory || (typeof globalThis.WebSocket !== "undefined" ? ((url) => new globalThis.WebSocket(url)) : null);
208
+ if (!factory) {
209
+ this.logger.error("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
210
+ this.setState("disconnected");
211
+ return;
212
+ }
208
213
  this.ws = factory(this.options.url);
209
214
  this.ws.onopen = () => this.handleOpen();
210
215
  this.ws.onmessage = (event) => this.handleMessage(event);
@@ -401,7 +406,7 @@ var PipelineClient = class {
401
406
  if (!this.heartbeatInterval) return;
402
407
  const jitter = this.heartbeatInterval * 0.1 * (Math.random() * 2 - 1);
403
408
  const interval = this.heartbeatInterval + jitter;
404
- this.heartbeatTimer = window.setInterval(() => {
409
+ this.heartbeatTimer = globalThis.setInterval(() => {
405
410
  this.sendHeartbeat();
406
411
  }, interval);
407
412
  this.sendHeartbeat();
@@ -420,14 +425,14 @@ var PipelineClient = class {
420
425
  this.setState("reconnecting");
421
426
  const backoffIndex = Math.min(this.reconnectAttempts, this.reconnectBackoff.length - 1);
422
427
  const delay = this.reconnectBackoff[backoffIndex];
423
- this.reconnectTimer = window.setTimeout(() => {
428
+ this.reconnectTimer = globalThis.setTimeout(() => {
424
429
  this.reconnectAttempts += 1;
425
430
  this.emit("onReconnect", this.reconnectAttempts);
426
431
  this.connect();
427
432
  }, delay);
428
433
  }
429
434
  send(op, data) {
430
- if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
435
+ if (!this.ws || this.ws.readyState !== _PipelineClient.WS_OPEN) {
431
436
  this.logger.warn("Cannot send: not connected");
432
437
  return;
433
438
  }
@@ -463,6 +468,9 @@ var PipelineClient = class {
463
468
  return fromProvider;
464
469
  }
465
470
  };
471
+ _PipelineClient.WS_CONNECTING = 0;
472
+ _PipelineClient.WS_OPEN = 1;
473
+ var PipelineClient = _PipelineClient;
466
474
  function createPipeline(options) {
467
475
  return new PipelineClient(options);
468
476
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@borealise/pipeline",
3
- "version": "1.0.0-alpha.0",
3
+ "version": "1.0.0-alpha.1",
4
4
  "description": "Official realtime pipeline client for Borealise",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",