@wooksjs/ws-client 0.7.10 → 0.7.12
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.cjs +22 -30
- package/dist/index.mjs +21 -30
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
1
2
|
|
|
2
3
|
//#region packages/ws-client/src/ws-client-error.ts
|
|
3
4
|
/** Error from the WebSocket client (server error reply, timeout, or disconnect). */
|
|
@@ -13,8 +14,10 @@ var WsClientError = class extends Error {
|
|
|
13
14
|
//#region packages/ws-client/src/rpc-tracker.ts
|
|
14
15
|
/** Tracks pending RPC calls by correlation ID. */
|
|
15
16
|
var RpcTracker = class {
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
constructor() {
|
|
18
|
+
this.nextId = 1;
|
|
19
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
20
|
+
}
|
|
18
21
|
/** Generate a new unique message ID. */
|
|
19
22
|
generateId() {
|
|
20
23
|
return this.nextId++;
|
|
@@ -62,10 +65,10 @@ var RpcTracker = class {
|
|
|
62
65
|
//#region packages/ws-client/src/push-dispatcher.ts
|
|
63
66
|
/** Dispatches server push messages to registered client-side listeners. */
|
|
64
67
|
var PushDispatcher = class {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
constructor() {
|
|
69
|
+
this.exact = /* @__PURE__ */ new Map();
|
|
70
|
+
this.wildcards = [];
|
|
71
|
+
}
|
|
69
72
|
/**
|
|
70
73
|
* Register a push listener. Returns an unregister function.
|
|
71
74
|
*
|
|
@@ -75,10 +78,9 @@ var PushDispatcher = class {
|
|
|
75
78
|
on(event, pathPattern, handler) {
|
|
76
79
|
const h = handler;
|
|
77
80
|
if (pathPattern.endsWith("*")) {
|
|
78
|
-
const prefix = pathPattern.slice(0, -1);
|
|
79
81
|
const entry = {
|
|
80
82
|
event,
|
|
81
|
-
prefix,
|
|
83
|
+
prefix: pathPattern.slice(0, -1),
|
|
82
84
|
handler: h
|
|
83
85
|
};
|
|
84
86
|
this.wildcards.push(entry);
|
|
@@ -123,7 +125,9 @@ var PushDispatcher = class {
|
|
|
123
125
|
//#region packages/ws-client/src/message-queue.ts
|
|
124
126
|
/** Queue for outbound messages that accumulate while disconnected. */
|
|
125
127
|
var MessageQueue = class {
|
|
126
|
-
|
|
128
|
+
constructor() {
|
|
129
|
+
this.queue = [];
|
|
130
|
+
}
|
|
127
131
|
/** Enqueue a serialized message. */
|
|
128
132
|
enqueue(serialized) {
|
|
129
133
|
this.queue.push(serialized);
|
|
@@ -173,11 +177,10 @@ function normalizeReconnectConfig(opt) {
|
|
|
173
177
|
}
|
|
174
178
|
/** Manages reconnection state and backoff calculation. */
|
|
175
179
|
var ReconnectController = class {
|
|
176
|
-
attempt = 0;
|
|
177
|
-
timer;
|
|
178
|
-
stopped = false;
|
|
179
180
|
constructor(config) {
|
|
180
181
|
this.config = config;
|
|
182
|
+
this.attempt = 0;
|
|
183
|
+
this.stopped = false;
|
|
181
184
|
}
|
|
182
185
|
/** Whether reconnect is enabled and not manually stopped. */
|
|
183
186
|
get enabled() {
|
|
@@ -229,25 +232,14 @@ function getWebSocketImpl(override) {
|
|
|
229
232
|
}
|
|
230
233
|
/** WebSocket client with RPC, subscriptions, reconnection, and push listeners. */
|
|
231
234
|
var WsClient = class {
|
|
232
|
-
ws = null;
|
|
233
|
-
url;
|
|
234
|
-
protocols;
|
|
235
|
-
rpcTimeout;
|
|
236
|
-
serializer;
|
|
237
|
-
parser;
|
|
238
|
-
WsImpl;
|
|
239
|
-
rpc;
|
|
240
|
-
dispatcher;
|
|
241
|
-
queue;
|
|
242
|
-
reconnector;
|
|
243
|
-
/** Active subscriptions for auto-resubscribe: path → data. */
|
|
244
|
-
subscriptions = /* @__PURE__ */ new Map();
|
|
245
|
-
openHandlers = [];
|
|
246
|
-
closeHandlers = [];
|
|
247
|
-
errorHandlers = [];
|
|
248
|
-
reconnectHandlers = [];
|
|
249
|
-
closed = false;
|
|
250
235
|
constructor(url, options) {
|
|
236
|
+
this.ws = null;
|
|
237
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
238
|
+
this.openHandlers = [];
|
|
239
|
+
this.closeHandlers = [];
|
|
240
|
+
this.errorHandlers = [];
|
|
241
|
+
this.reconnectHandlers = [];
|
|
242
|
+
this.closed = false;
|
|
251
243
|
this.url = url;
|
|
252
244
|
this.protocols = options?.protocols;
|
|
253
245
|
this.rpcTimeout = options?.rpcTimeout ?? DEFAULT_RPC_TIMEOUT;
|
package/dist/index.mjs
CHANGED
|
@@ -12,8 +12,10 @@ var WsClientError = class extends Error {
|
|
|
12
12
|
//#region packages/ws-client/src/rpc-tracker.ts
|
|
13
13
|
/** Tracks pending RPC calls by correlation ID. */
|
|
14
14
|
var RpcTracker = class {
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
constructor() {
|
|
16
|
+
this.nextId = 1;
|
|
17
|
+
this.pending = /* @__PURE__ */ new Map();
|
|
18
|
+
}
|
|
17
19
|
/** Generate a new unique message ID. */
|
|
18
20
|
generateId() {
|
|
19
21
|
return this.nextId++;
|
|
@@ -61,10 +63,10 @@ var RpcTracker = class {
|
|
|
61
63
|
//#region packages/ws-client/src/push-dispatcher.ts
|
|
62
64
|
/** Dispatches server push messages to registered client-side listeners. */
|
|
63
65
|
var PushDispatcher = class {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
constructor() {
|
|
67
|
+
this.exact = /* @__PURE__ */ new Map();
|
|
68
|
+
this.wildcards = [];
|
|
69
|
+
}
|
|
68
70
|
/**
|
|
69
71
|
* Register a push listener. Returns an unregister function.
|
|
70
72
|
*
|
|
@@ -74,10 +76,9 @@ var PushDispatcher = class {
|
|
|
74
76
|
on(event, pathPattern, handler) {
|
|
75
77
|
const h = handler;
|
|
76
78
|
if (pathPattern.endsWith("*")) {
|
|
77
|
-
const prefix = pathPattern.slice(0, -1);
|
|
78
79
|
const entry = {
|
|
79
80
|
event,
|
|
80
|
-
prefix,
|
|
81
|
+
prefix: pathPattern.slice(0, -1),
|
|
81
82
|
handler: h
|
|
82
83
|
};
|
|
83
84
|
this.wildcards.push(entry);
|
|
@@ -122,7 +123,9 @@ var PushDispatcher = class {
|
|
|
122
123
|
//#region packages/ws-client/src/message-queue.ts
|
|
123
124
|
/** Queue for outbound messages that accumulate while disconnected. */
|
|
124
125
|
var MessageQueue = class {
|
|
125
|
-
|
|
126
|
+
constructor() {
|
|
127
|
+
this.queue = [];
|
|
128
|
+
}
|
|
126
129
|
/** Enqueue a serialized message. */
|
|
127
130
|
enqueue(serialized) {
|
|
128
131
|
this.queue.push(serialized);
|
|
@@ -172,11 +175,10 @@ function normalizeReconnectConfig(opt) {
|
|
|
172
175
|
}
|
|
173
176
|
/** Manages reconnection state and backoff calculation. */
|
|
174
177
|
var ReconnectController = class {
|
|
175
|
-
attempt = 0;
|
|
176
|
-
timer;
|
|
177
|
-
stopped = false;
|
|
178
178
|
constructor(config) {
|
|
179
179
|
this.config = config;
|
|
180
|
+
this.attempt = 0;
|
|
181
|
+
this.stopped = false;
|
|
180
182
|
}
|
|
181
183
|
/** Whether reconnect is enabled and not manually stopped. */
|
|
182
184
|
get enabled() {
|
|
@@ -228,25 +230,14 @@ function getWebSocketImpl(override) {
|
|
|
228
230
|
}
|
|
229
231
|
/** WebSocket client with RPC, subscriptions, reconnection, and push listeners. */
|
|
230
232
|
var WsClient = class {
|
|
231
|
-
ws = null;
|
|
232
|
-
url;
|
|
233
|
-
protocols;
|
|
234
|
-
rpcTimeout;
|
|
235
|
-
serializer;
|
|
236
|
-
parser;
|
|
237
|
-
WsImpl;
|
|
238
|
-
rpc;
|
|
239
|
-
dispatcher;
|
|
240
|
-
queue;
|
|
241
|
-
reconnector;
|
|
242
|
-
/** Active subscriptions for auto-resubscribe: path → data. */
|
|
243
|
-
subscriptions = /* @__PURE__ */ new Map();
|
|
244
|
-
openHandlers = [];
|
|
245
|
-
closeHandlers = [];
|
|
246
|
-
errorHandlers = [];
|
|
247
|
-
reconnectHandlers = [];
|
|
248
|
-
closed = false;
|
|
249
233
|
constructor(url, options) {
|
|
234
|
+
this.ws = null;
|
|
235
|
+
this.subscriptions = /* @__PURE__ */ new Map();
|
|
236
|
+
this.openHandlers = [];
|
|
237
|
+
this.closeHandlers = [];
|
|
238
|
+
this.errorHandlers = [];
|
|
239
|
+
this.reconnectHandlers = [];
|
|
240
|
+
this.closed = false;
|
|
250
241
|
this.url = url;
|
|
251
242
|
this.protocols = options?.protocols;
|
|
252
243
|
this.rpcTimeout = options?.rpcTimeout ?? DEFAULT_RPC_TIMEOUT;
|