@borealise/pipeline 1.0.0-alpha.4 → 1.0.0-alpha.6
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 +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +40 -45
- package/dist/index.mjs +43 -74
- package/package.json +2 -2
package/dist/index.d.mts
CHANGED
|
@@ -124,7 +124,7 @@ type DispatchHandler = (action: string, payload?: unknown) => void;
|
|
|
124
124
|
interface PipelineClientOptions {
|
|
125
125
|
url: string;
|
|
126
126
|
tokenProvider?: () => string | null | undefined;
|
|
127
|
-
|
|
127
|
+
loggerEnabled?: boolean;
|
|
128
128
|
webSocketFactory?: (url: string) => WebSocket;
|
|
129
129
|
}
|
|
130
130
|
|
package/dist/index.d.ts
CHANGED
|
@@ -124,7 +124,7 @@ type DispatchHandler = (action: string, payload?: unknown) => void;
|
|
|
124
124
|
interface PipelineClientOptions {
|
|
125
125
|
url: string;
|
|
126
126
|
tokenProvider?: () => string | null | undefined;
|
|
127
|
-
|
|
127
|
+
loggerEnabled?: boolean;
|
|
128
128
|
webSocketFactory?: (url: string) => WebSocket;
|
|
129
129
|
}
|
|
130
130
|
|
package/dist/index.js
CHANGED
|
@@ -22,19 +22,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
22
22
|
var index_exports = {};
|
|
23
23
|
__export(index_exports, {
|
|
24
24
|
PipelineClient: () => PipelineClient,
|
|
25
|
-
PipelineErrors: () =>
|
|
25
|
+
PipelineErrors: () => import_shared.PipelineErrors,
|
|
26
26
|
createPipeline: () => createPipeline,
|
|
27
|
-
getPipelineErrorName: () =>
|
|
27
|
+
getPipelineErrorName: () => import_shared.getPipelineErrorName
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(index_exports);
|
|
30
30
|
|
|
31
|
-
// src/constants/opcodes.ts
|
|
32
|
-
var opcodes_exports = {};
|
|
33
|
-
__reExport(opcodes_exports, require("@borealise/shared"));
|
|
34
|
-
|
|
35
|
-
// src/index.ts
|
|
36
|
-
__reExport(index_exports, opcodes_exports, module.exports);
|
|
37
|
-
|
|
38
31
|
// src/logger.ts
|
|
39
32
|
var _Logger = class _Logger {
|
|
40
33
|
constructor(name, options = {}) {
|
|
@@ -70,6 +63,7 @@ _Logger.loggers = /* @__PURE__ */ new Map();
|
|
|
70
63
|
var Logger = _Logger;
|
|
71
64
|
|
|
72
65
|
// src/PipelineClient.ts
|
|
66
|
+
var import_shared = require("@borealise/shared");
|
|
73
67
|
var _PipelineClient = class _PipelineClient {
|
|
74
68
|
constructor(options) {
|
|
75
69
|
this.ws = null;
|
|
@@ -88,7 +82,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
88
82
|
this.maxReconnectAttempts = 10;
|
|
89
83
|
this.reconnectBackoff = [1e3, 2e3, 5e3, 1e4, 3e4];
|
|
90
84
|
this.options = { ...options };
|
|
91
|
-
this.logger = Logger.create(
|
|
85
|
+
this.logger = options.loggerEnabled ? Logger.create("Pipeline") : void 0;
|
|
92
86
|
}
|
|
93
87
|
get state() {
|
|
94
88
|
return this._state;
|
|
@@ -107,20 +101,19 @@ var _PipelineClient = class _PipelineClient {
|
|
|
107
101
|
}
|
|
108
102
|
connect() {
|
|
109
103
|
if (!this.options.url) {
|
|
110
|
-
this.logger
|
|
104
|
+
this.logger?.error("Cannot connect: missing pipeline url");
|
|
111
105
|
return;
|
|
112
106
|
}
|
|
113
107
|
if (this.ws && (this.ws.readyState === _PipelineClient.WS_CONNECTING || this.ws.readyState === _PipelineClient.WS_OPEN)) {
|
|
114
|
-
this.logger
|
|
108
|
+
this.logger?.warn("Already connected or connecting");
|
|
115
109
|
return;
|
|
116
110
|
}
|
|
117
111
|
this.setState("connecting");
|
|
118
112
|
try {
|
|
119
113
|
const factory = this.options.webSocketFactory || (typeof globalThis.WebSocket !== "undefined" ? ((url) => new globalThis.WebSocket(url)) : null);
|
|
120
114
|
if (!factory) {
|
|
121
|
-
this.logger.error("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
|
|
122
115
|
this.setState("disconnected");
|
|
123
|
-
|
|
116
|
+
throw new ReferenceError("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
|
|
124
117
|
}
|
|
125
118
|
this.ws = factory(this.options.url);
|
|
126
119
|
this.ws.onopen = () => this.handleOpen();
|
|
@@ -128,7 +121,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
128
121
|
this.ws.onclose = (event) => this.handleClose(event);
|
|
129
122
|
this.ws.onerror = (event) => this.handleError(event);
|
|
130
123
|
} catch (error) {
|
|
131
|
-
this.logger
|
|
124
|
+
this.logger?.error("Connection failed", error);
|
|
132
125
|
this.scheduleReconnect();
|
|
133
126
|
}
|
|
134
127
|
}
|
|
@@ -136,7 +129,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
136
129
|
this.clearTimers();
|
|
137
130
|
this.reconnectAttempts = 0;
|
|
138
131
|
if (this.ws) {
|
|
139
|
-
this.ws.close(
|
|
132
|
+
this.ws.close(import_shared.CloseCodes.NORMAL, "client disconnect");
|
|
140
133
|
this.ws = null;
|
|
141
134
|
}
|
|
142
135
|
this.sessionId = null;
|
|
@@ -144,17 +137,17 @@ var _PipelineClient = class _PipelineClient {
|
|
|
144
137
|
this.setState("disconnected");
|
|
145
138
|
}
|
|
146
139
|
identify(token) {
|
|
147
|
-
this.send(
|
|
140
|
+
this.send(import_shared.Opcodes.IDENTIFY, { token });
|
|
148
141
|
}
|
|
149
142
|
updatePresence(status, activity) {
|
|
150
|
-
this.send(
|
|
143
|
+
this.send(import_shared.Opcodes.PRESENCE_UPDATE, { status, activity });
|
|
151
144
|
}
|
|
152
145
|
subscribe(events) {
|
|
153
146
|
for (const event of events) {
|
|
154
147
|
this.subscriptions.add(event);
|
|
155
148
|
}
|
|
156
149
|
if (this.isIdentified) {
|
|
157
|
-
this.send(
|
|
150
|
+
this.send(import_shared.Opcodes.SUBSCRIBE, { events });
|
|
158
151
|
}
|
|
159
152
|
}
|
|
160
153
|
unsubscribe(events) {
|
|
@@ -162,15 +155,14 @@ var _PipelineClient = class _PipelineClient {
|
|
|
162
155
|
this.subscriptions.delete(event);
|
|
163
156
|
}
|
|
164
157
|
if (this.isIdentified) {
|
|
165
|
-
this.send(
|
|
158
|
+
this.send(import_shared.Opcodes.UNSUBSCRIBE, { events });
|
|
166
159
|
}
|
|
167
160
|
}
|
|
168
161
|
sendChatMessage(roomSlug, content) {
|
|
169
162
|
if (!this.isIdentified) {
|
|
170
|
-
this.logger.warn("Cannot send chat: not identified");
|
|
171
163
|
return false;
|
|
172
164
|
}
|
|
173
|
-
this.send(
|
|
165
|
+
this.send(import_shared.Opcodes.CHAT_SEND, {
|
|
174
166
|
room_slug: roomSlug,
|
|
175
167
|
content
|
|
176
168
|
});
|
|
@@ -213,7 +205,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
213
205
|
}
|
|
214
206
|
}
|
|
215
207
|
handleOpen() {
|
|
216
|
-
this.logger
|
|
208
|
+
this.logger?.info("Connected");
|
|
217
209
|
this.setState("connected");
|
|
218
210
|
this.reconnectAttempts = 0;
|
|
219
211
|
this.emit("onConnect");
|
|
@@ -222,42 +214,42 @@ var _PipelineClient = class _PipelineClient {
|
|
|
222
214
|
try {
|
|
223
215
|
const message = JSON.parse(String(event.data));
|
|
224
216
|
switch (message.op) {
|
|
225
|
-
case
|
|
217
|
+
case import_shared.Opcodes.HELLO:
|
|
226
218
|
this.handleHello(message.d);
|
|
227
219
|
break;
|
|
228
|
-
case
|
|
220
|
+
case import_shared.Opcodes.HEARTBEAT_ACK:
|
|
229
221
|
break;
|
|
230
|
-
case
|
|
222
|
+
case import_shared.Opcodes.READY:
|
|
231
223
|
this.handleReady(message.d);
|
|
232
224
|
break;
|
|
233
|
-
case
|
|
225
|
+
case import_shared.Opcodes.INVALID_SESSION:
|
|
234
226
|
this.handleInvalidSession(message.d);
|
|
235
227
|
break;
|
|
236
|
-
case
|
|
228
|
+
case import_shared.Opcodes.RECONNECT:
|
|
237
229
|
this.handleReconnect();
|
|
238
230
|
break;
|
|
239
|
-
case
|
|
231
|
+
case import_shared.Opcodes.DISPATCH:
|
|
240
232
|
this.handleDispatch(message.t, message.d, message.s);
|
|
241
233
|
break;
|
|
242
|
-
case
|
|
234
|
+
case import_shared.Opcodes.ERROR:
|
|
243
235
|
this.handleServerError(message.d);
|
|
244
236
|
break;
|
|
245
237
|
default:
|
|
246
|
-
this.logger
|
|
238
|
+
this.logger?.warn(`Unknown opcode: ${message.op}`);
|
|
247
239
|
}
|
|
248
240
|
} catch (error) {
|
|
249
|
-
this.logger
|
|
241
|
+
this.logger?.error("Failed to parse message", error);
|
|
250
242
|
}
|
|
251
243
|
}
|
|
252
244
|
handleClose(event) {
|
|
253
|
-
this.logger
|
|
245
|
+
this.logger?.info(`Disconnected: ${event.code} - ${event.reason}`);
|
|
254
246
|
this.clearTimers();
|
|
255
247
|
this.ws = null;
|
|
256
248
|
this.emit("onDisconnect", event.code, event.reason);
|
|
257
249
|
const noReconnectCodes = [
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
250
|
+
import_shared.CloseCodes.AUTHENTICATION_FAILED,
|
|
251
|
+
import_shared.CloseCodes.NOT_AUTHENTICATED,
|
|
252
|
+
import_shared.CloseCodes.NORMAL
|
|
261
253
|
];
|
|
262
254
|
if (!noReconnectCodes.includes(event.code)) {
|
|
263
255
|
this.scheduleReconnect();
|
|
@@ -266,7 +258,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
266
258
|
this.setState("disconnected");
|
|
267
259
|
}
|
|
268
260
|
handleError(_event) {
|
|
269
|
-
this.logger
|
|
261
|
+
this.logger?.error("WebSocket error");
|
|
270
262
|
}
|
|
271
263
|
handleHello(payload) {
|
|
272
264
|
this.sessionId = payload.session_id;
|
|
@@ -294,7 +286,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
294
286
|
}
|
|
295
287
|
}
|
|
296
288
|
handleReconnect() {
|
|
297
|
-
this.logger
|
|
289
|
+
this.logger?.info("Server requested reconnect");
|
|
298
290
|
this.disconnect();
|
|
299
291
|
this.connect();
|
|
300
292
|
}
|
|
@@ -307,7 +299,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
307
299
|
this.dispatchHandler?.("pipeline/handleDispatch", { event, data });
|
|
308
300
|
}
|
|
309
301
|
handleServerError(payload) {
|
|
310
|
-
this.logger
|
|
302
|
+
this.logger?.error(`Server error: ${payload.code} - ${payload.message || "unknown"}`);
|
|
311
303
|
this.emit("onError", payload);
|
|
312
304
|
this.dispatchHandler?.("pipeline/handleServerError", payload);
|
|
313
305
|
}
|
|
@@ -324,13 +316,13 @@ var _PipelineClient = class _PipelineClient {
|
|
|
324
316
|
this.sendHeartbeat();
|
|
325
317
|
}
|
|
326
318
|
sendHeartbeat() {
|
|
327
|
-
this.send(
|
|
319
|
+
this.send(import_shared.Opcodes.HEARTBEAT, {
|
|
328
320
|
seq: this.lastSequence || null
|
|
329
321
|
});
|
|
330
322
|
}
|
|
331
323
|
scheduleReconnect() {
|
|
332
324
|
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
333
|
-
this.logger
|
|
325
|
+
this.logger?.error("Max reconnect attempts reached");
|
|
334
326
|
this.setState("disconnected");
|
|
335
327
|
return;
|
|
336
328
|
}
|
|
@@ -345,7 +337,6 @@ var _PipelineClient = class _PipelineClient {
|
|
|
345
337
|
}
|
|
346
338
|
send(op, data) {
|
|
347
339
|
if (!this.ws || this.ws.readyState !== _PipelineClient.WS_OPEN) {
|
|
348
|
-
this.logger.warn("Cannot send: not connected");
|
|
349
340
|
return;
|
|
350
341
|
}
|
|
351
342
|
const message = { op, d: data };
|
|
@@ -358,7 +349,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
358
349
|
try {
|
|
359
350
|
listener(data);
|
|
360
351
|
} catch (error) {
|
|
361
|
-
this.logger
|
|
352
|
+
this.logger?.error(`Event listener error for ${event}`, error);
|
|
362
353
|
}
|
|
363
354
|
}
|
|
364
355
|
}
|
|
@@ -370,7 +361,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
370
361
|
;
|
|
371
362
|
listener(...args);
|
|
372
363
|
} catch (error) {
|
|
373
|
-
this.logger
|
|
364
|
+
this.logger?.error(`Connection listener error for ${event}`, error);
|
|
374
365
|
}
|
|
375
366
|
}
|
|
376
367
|
}
|
|
@@ -386,10 +377,14 @@ var PipelineClient = _PipelineClient;
|
|
|
386
377
|
function createPipeline(options) {
|
|
387
378
|
return new PipelineClient(options);
|
|
388
379
|
}
|
|
380
|
+
|
|
381
|
+
// src/index.ts
|
|
382
|
+
__reExport(index_exports, require("@borealise/shared"), module.exports);
|
|
389
383
|
// Annotate the CommonJS export names for ESM import in node:
|
|
390
384
|
0 && (module.exports = {
|
|
391
385
|
PipelineClient,
|
|
392
386
|
PipelineErrors,
|
|
393
387
|
createPipeline,
|
|
394
|
-
getPipelineErrorName
|
|
388
|
+
getPipelineErrorName,
|
|
389
|
+
...require("@borealise/shared")
|
|
395
390
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,38 +1,3 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
-
var __export = (target, all) => {
|
|
6
|
-
for (var name in all)
|
|
7
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
-
};
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
-
for (let key of __getOwnPropNames(from))
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
-
}
|
|
15
|
-
return to;
|
|
16
|
-
};
|
|
17
|
-
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
18
|
-
|
|
19
|
-
// src/index.ts
|
|
20
|
-
var index_exports = {};
|
|
21
|
-
__export(index_exports, {
|
|
22
|
-
PipelineClient: () => PipelineClient,
|
|
23
|
-
PipelineErrors: () => opcodes_exports.PipelineErrors,
|
|
24
|
-
createPipeline: () => createPipeline,
|
|
25
|
-
getPipelineErrorName: () => opcodes_exports.getPipelineErrorName
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
// src/constants/opcodes.ts
|
|
29
|
-
var opcodes_exports = {};
|
|
30
|
-
__reExport(opcodes_exports, shared_star);
|
|
31
|
-
import * as shared_star from "@borealise/shared";
|
|
32
|
-
|
|
33
|
-
// src/index.ts
|
|
34
|
-
__reExport(index_exports, opcodes_exports);
|
|
35
|
-
|
|
36
1
|
// src/logger.ts
|
|
37
2
|
var _Logger = class _Logger {
|
|
38
3
|
constructor(name, options = {}) {
|
|
@@ -68,6 +33,12 @@ _Logger.loggers = /* @__PURE__ */ new Map();
|
|
|
68
33
|
var Logger = _Logger;
|
|
69
34
|
|
|
70
35
|
// src/PipelineClient.ts
|
|
36
|
+
import {
|
|
37
|
+
CloseCodes,
|
|
38
|
+
Opcodes,
|
|
39
|
+
PipelineErrors,
|
|
40
|
+
getPipelineErrorName
|
|
41
|
+
} from "@borealise/shared";
|
|
71
42
|
var _PipelineClient = class _PipelineClient {
|
|
72
43
|
constructor(options) {
|
|
73
44
|
this.ws = null;
|
|
@@ -86,7 +57,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
86
57
|
this.maxReconnectAttempts = 10;
|
|
87
58
|
this.reconnectBackoff = [1e3, 2e3, 5e3, 1e4, 3e4];
|
|
88
59
|
this.options = { ...options };
|
|
89
|
-
this.logger = Logger.create(
|
|
60
|
+
this.logger = options.loggerEnabled ? Logger.create("Pipeline") : void 0;
|
|
90
61
|
}
|
|
91
62
|
get state() {
|
|
92
63
|
return this._state;
|
|
@@ -105,20 +76,19 @@ var _PipelineClient = class _PipelineClient {
|
|
|
105
76
|
}
|
|
106
77
|
connect() {
|
|
107
78
|
if (!this.options.url) {
|
|
108
|
-
this.logger
|
|
79
|
+
this.logger?.error("Cannot connect: missing pipeline url");
|
|
109
80
|
return;
|
|
110
81
|
}
|
|
111
82
|
if (this.ws && (this.ws.readyState === _PipelineClient.WS_CONNECTING || this.ws.readyState === _PipelineClient.WS_OPEN)) {
|
|
112
|
-
this.logger
|
|
83
|
+
this.logger?.warn("Already connected or connecting");
|
|
113
84
|
return;
|
|
114
85
|
}
|
|
115
86
|
this.setState("connecting");
|
|
116
87
|
try {
|
|
117
88
|
const factory = this.options.webSocketFactory || (typeof globalThis.WebSocket !== "undefined" ? ((url) => new globalThis.WebSocket(url)) : null);
|
|
118
89
|
if (!factory) {
|
|
119
|
-
this.logger.error("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
|
|
120
90
|
this.setState("disconnected");
|
|
121
|
-
|
|
91
|
+
throw new ReferenceError("No WebSocket runtime found. In Node.js, provide webSocketFactory (for example using ws).");
|
|
122
92
|
}
|
|
123
93
|
this.ws = factory(this.options.url);
|
|
124
94
|
this.ws.onopen = () => this.handleOpen();
|
|
@@ -126,7 +96,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
126
96
|
this.ws.onclose = (event) => this.handleClose(event);
|
|
127
97
|
this.ws.onerror = (event) => this.handleError(event);
|
|
128
98
|
} catch (error) {
|
|
129
|
-
this.logger
|
|
99
|
+
this.logger?.error("Connection failed", error);
|
|
130
100
|
this.scheduleReconnect();
|
|
131
101
|
}
|
|
132
102
|
}
|
|
@@ -134,7 +104,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
134
104
|
this.clearTimers();
|
|
135
105
|
this.reconnectAttempts = 0;
|
|
136
106
|
if (this.ws) {
|
|
137
|
-
this.ws.close(
|
|
107
|
+
this.ws.close(CloseCodes.NORMAL, "client disconnect");
|
|
138
108
|
this.ws = null;
|
|
139
109
|
}
|
|
140
110
|
this.sessionId = null;
|
|
@@ -142,17 +112,17 @@ var _PipelineClient = class _PipelineClient {
|
|
|
142
112
|
this.setState("disconnected");
|
|
143
113
|
}
|
|
144
114
|
identify(token) {
|
|
145
|
-
this.send(
|
|
115
|
+
this.send(Opcodes.IDENTIFY, { token });
|
|
146
116
|
}
|
|
147
117
|
updatePresence(status, activity) {
|
|
148
|
-
this.send(
|
|
118
|
+
this.send(Opcodes.PRESENCE_UPDATE, { status, activity });
|
|
149
119
|
}
|
|
150
120
|
subscribe(events) {
|
|
151
121
|
for (const event of events) {
|
|
152
122
|
this.subscriptions.add(event);
|
|
153
123
|
}
|
|
154
124
|
if (this.isIdentified) {
|
|
155
|
-
this.send(
|
|
125
|
+
this.send(Opcodes.SUBSCRIBE, { events });
|
|
156
126
|
}
|
|
157
127
|
}
|
|
158
128
|
unsubscribe(events) {
|
|
@@ -160,15 +130,14 @@ var _PipelineClient = class _PipelineClient {
|
|
|
160
130
|
this.subscriptions.delete(event);
|
|
161
131
|
}
|
|
162
132
|
if (this.isIdentified) {
|
|
163
|
-
this.send(
|
|
133
|
+
this.send(Opcodes.UNSUBSCRIBE, { events });
|
|
164
134
|
}
|
|
165
135
|
}
|
|
166
136
|
sendChatMessage(roomSlug, content) {
|
|
167
137
|
if (!this.isIdentified) {
|
|
168
|
-
this.logger.warn("Cannot send chat: not identified");
|
|
169
138
|
return false;
|
|
170
139
|
}
|
|
171
|
-
this.send(
|
|
140
|
+
this.send(Opcodes.CHAT_SEND, {
|
|
172
141
|
room_slug: roomSlug,
|
|
173
142
|
content
|
|
174
143
|
});
|
|
@@ -211,7 +180,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
211
180
|
}
|
|
212
181
|
}
|
|
213
182
|
handleOpen() {
|
|
214
|
-
this.logger
|
|
183
|
+
this.logger?.info("Connected");
|
|
215
184
|
this.setState("connected");
|
|
216
185
|
this.reconnectAttempts = 0;
|
|
217
186
|
this.emit("onConnect");
|
|
@@ -220,42 +189,42 @@ var _PipelineClient = class _PipelineClient {
|
|
|
220
189
|
try {
|
|
221
190
|
const message = JSON.parse(String(event.data));
|
|
222
191
|
switch (message.op) {
|
|
223
|
-
case
|
|
192
|
+
case Opcodes.HELLO:
|
|
224
193
|
this.handleHello(message.d);
|
|
225
194
|
break;
|
|
226
|
-
case
|
|
195
|
+
case Opcodes.HEARTBEAT_ACK:
|
|
227
196
|
break;
|
|
228
|
-
case
|
|
197
|
+
case Opcodes.READY:
|
|
229
198
|
this.handleReady(message.d);
|
|
230
199
|
break;
|
|
231
|
-
case
|
|
200
|
+
case Opcodes.INVALID_SESSION:
|
|
232
201
|
this.handleInvalidSession(message.d);
|
|
233
202
|
break;
|
|
234
|
-
case
|
|
203
|
+
case Opcodes.RECONNECT:
|
|
235
204
|
this.handleReconnect();
|
|
236
205
|
break;
|
|
237
|
-
case
|
|
206
|
+
case Opcodes.DISPATCH:
|
|
238
207
|
this.handleDispatch(message.t, message.d, message.s);
|
|
239
208
|
break;
|
|
240
|
-
case
|
|
209
|
+
case Opcodes.ERROR:
|
|
241
210
|
this.handleServerError(message.d);
|
|
242
211
|
break;
|
|
243
212
|
default:
|
|
244
|
-
this.logger
|
|
213
|
+
this.logger?.warn(`Unknown opcode: ${message.op}`);
|
|
245
214
|
}
|
|
246
215
|
} catch (error) {
|
|
247
|
-
this.logger
|
|
216
|
+
this.logger?.error("Failed to parse message", error);
|
|
248
217
|
}
|
|
249
218
|
}
|
|
250
219
|
handleClose(event) {
|
|
251
|
-
this.logger
|
|
220
|
+
this.logger?.info(`Disconnected: ${event.code} - ${event.reason}`);
|
|
252
221
|
this.clearTimers();
|
|
253
222
|
this.ws = null;
|
|
254
223
|
this.emit("onDisconnect", event.code, event.reason);
|
|
255
224
|
const noReconnectCodes = [
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
225
|
+
CloseCodes.AUTHENTICATION_FAILED,
|
|
226
|
+
CloseCodes.NOT_AUTHENTICATED,
|
|
227
|
+
CloseCodes.NORMAL
|
|
259
228
|
];
|
|
260
229
|
if (!noReconnectCodes.includes(event.code)) {
|
|
261
230
|
this.scheduleReconnect();
|
|
@@ -264,7 +233,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
264
233
|
this.setState("disconnected");
|
|
265
234
|
}
|
|
266
235
|
handleError(_event) {
|
|
267
|
-
this.logger
|
|
236
|
+
this.logger?.error("WebSocket error");
|
|
268
237
|
}
|
|
269
238
|
handleHello(payload) {
|
|
270
239
|
this.sessionId = payload.session_id;
|
|
@@ -292,7 +261,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
292
261
|
}
|
|
293
262
|
}
|
|
294
263
|
handleReconnect() {
|
|
295
|
-
this.logger
|
|
264
|
+
this.logger?.info("Server requested reconnect");
|
|
296
265
|
this.disconnect();
|
|
297
266
|
this.connect();
|
|
298
267
|
}
|
|
@@ -305,7 +274,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
305
274
|
this.dispatchHandler?.("pipeline/handleDispatch", { event, data });
|
|
306
275
|
}
|
|
307
276
|
handleServerError(payload) {
|
|
308
|
-
this.logger
|
|
277
|
+
this.logger?.error(`Server error: ${payload.code} - ${payload.message || "unknown"}`);
|
|
309
278
|
this.emit("onError", payload);
|
|
310
279
|
this.dispatchHandler?.("pipeline/handleServerError", payload);
|
|
311
280
|
}
|
|
@@ -322,13 +291,13 @@ var _PipelineClient = class _PipelineClient {
|
|
|
322
291
|
this.sendHeartbeat();
|
|
323
292
|
}
|
|
324
293
|
sendHeartbeat() {
|
|
325
|
-
this.send(
|
|
294
|
+
this.send(Opcodes.HEARTBEAT, {
|
|
326
295
|
seq: this.lastSequence || null
|
|
327
296
|
});
|
|
328
297
|
}
|
|
329
298
|
scheduleReconnect() {
|
|
330
299
|
if (this.reconnectAttempts >= this.maxReconnectAttempts) {
|
|
331
|
-
this.logger
|
|
300
|
+
this.logger?.error("Max reconnect attempts reached");
|
|
332
301
|
this.setState("disconnected");
|
|
333
302
|
return;
|
|
334
303
|
}
|
|
@@ -343,7 +312,6 @@ var _PipelineClient = class _PipelineClient {
|
|
|
343
312
|
}
|
|
344
313
|
send(op, data) {
|
|
345
314
|
if (!this.ws || this.ws.readyState !== _PipelineClient.WS_OPEN) {
|
|
346
|
-
this.logger.warn("Cannot send: not connected");
|
|
347
315
|
return;
|
|
348
316
|
}
|
|
349
317
|
const message = { op, d: data };
|
|
@@ -356,7 +324,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
356
324
|
try {
|
|
357
325
|
listener(data);
|
|
358
326
|
} catch (error) {
|
|
359
|
-
this.logger
|
|
327
|
+
this.logger?.error(`Event listener error for ${event}`, error);
|
|
360
328
|
}
|
|
361
329
|
}
|
|
362
330
|
}
|
|
@@ -368,7 +336,7 @@ var _PipelineClient = class _PipelineClient {
|
|
|
368
336
|
;
|
|
369
337
|
listener(...args);
|
|
370
338
|
} catch (error) {
|
|
371
|
-
this.logger
|
|
339
|
+
this.logger?.error(`Connection listener error for ${event}`, error);
|
|
372
340
|
}
|
|
373
341
|
}
|
|
374
342
|
}
|
|
@@ -384,11 +352,12 @@ var PipelineClient = _PipelineClient;
|
|
|
384
352
|
function createPipeline(options) {
|
|
385
353
|
return new PipelineClient(options);
|
|
386
354
|
}
|
|
387
|
-
|
|
388
|
-
|
|
355
|
+
|
|
356
|
+
// src/index.ts
|
|
357
|
+
export * from "@borealise/shared";
|
|
389
358
|
export {
|
|
390
359
|
PipelineClient,
|
|
391
|
-
|
|
360
|
+
PipelineErrors,
|
|
392
361
|
createPipeline,
|
|
393
|
-
|
|
362
|
+
getPipelineErrorName
|
|
394
363
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@borealise/pipeline",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.6",
|
|
4
4
|
"description": "Official realtime pipeline client for Borealise",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -44,6 +44,6 @@
|
|
|
44
44
|
"typescript": "^5.9.2"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@borealise/shared": "^1.0.
|
|
47
|
+
"@borealise/shared": "^1.0.5"
|
|
48
48
|
}
|
|
49
49
|
}
|