bunqueue 1.9.1 → 1.9.2
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/application/operations/queueControl.d.ts.map +1 -1
- package/dist/application/operations/queueControl.js +6 -1
- package/dist/application/operations/queueControl.js.map +1 -1
- package/dist/application/queueManager.d.ts +115 -9
- package/dist/application/queueManager.d.ts.map +1 -1
- package/dist/application/queueManager.js +535 -26
- package/dist/application/queueManager.js.map +1 -1
- package/dist/cli/commands/server.d.ts.map +1 -1
- package/dist/cli/commands/server.js +4 -9
- package/dist/cli/commands/server.js.map +1 -1
- package/dist/client/queue/dlqOps.d.ts +24 -0
- package/dist/client/queue/dlqOps.d.ts.map +1 -0
- package/dist/client/queue/dlqOps.js +73 -0
- package/dist/client/queue/dlqOps.js.map +1 -0
- package/dist/client/queue/helpers.d.ts +20 -0
- package/dist/client/queue/helpers.d.ts.map +1 -0
- package/dist/client/queue/helpers.js +34 -0
- package/dist/client/queue/helpers.js.map +1 -0
- package/dist/client/queue/index.d.ts +8 -0
- package/dist/client/queue/index.d.ts.map +1 -0
- package/dist/client/queue/index.js +8 -0
- package/dist/client/queue/index.js.map +1 -0
- package/dist/client/queue/queue.d.ts +60 -0
- package/dist/client/queue/queue.d.ts.map +1 -0
- package/dist/client/queue/queue.js +322 -0
- package/dist/client/queue/queue.js.map +1 -0
- package/dist/client/queue.d.ts +3 -78
- package/dist/client/queue.d.ts.map +1 -1
- package/dist/client/queue.js +3 -463
- package/dist/client/queue.js.map +1 -1
- package/dist/client/sandboxed/index.d.ts +8 -0
- package/dist/client/sandboxed/index.d.ts.map +1 -0
- package/dist/client/sandboxed/index.js +7 -0
- package/dist/client/sandboxed/index.js.map +1 -0
- package/dist/client/sandboxed/types.d.ts +62 -0
- package/dist/client/sandboxed/types.d.ts.map +1 -0
- package/dist/client/sandboxed/types.js +6 -0
- package/dist/client/sandboxed/types.js.map +1 -0
- package/dist/client/sandboxed/worker.d.ts +38 -0
- package/dist/client/sandboxed/worker.d.ts.map +1 -0
- package/dist/client/sandboxed/worker.js +176 -0
- package/dist/client/sandboxed/worker.js.map +1 -0
- package/dist/client/sandboxed/wrapper.d.ts +13 -0
- package/dist/client/sandboxed/wrapper.d.ts.map +1 -0
- package/dist/client/sandboxed/wrapper.js +65 -0
- package/dist/client/sandboxed/wrapper.js.map +1 -0
- package/dist/client/sandboxedWorker.d.ts +4 -87
- package/dist/client/sandboxedWorker.d.ts.map +1 -1
- package/dist/client/sandboxedWorker.js +3 -296
- package/dist/client/sandboxedWorker.js.map +1 -1
- package/dist/client/tcp/client.d.ts +43 -0
- package/dist/client/tcp/client.d.ts.map +1 -0
- package/dist/client/tcp/client.js +288 -0
- package/dist/client/tcp/client.js.map +1 -0
- package/dist/client/tcp/connection.d.ts +48 -0
- package/dist/client/tcp/connection.d.ts.map +1 -0
- package/dist/client/tcp/connection.js +150 -0
- package/dist/client/tcp/connection.js.map +1 -0
- package/dist/client/tcp/health.d.ts +47 -0
- package/dist/client/tcp/health.d.ts.map +1 -0
- package/dist/client/tcp/health.js +95 -0
- package/dist/client/tcp/health.js.map +1 -0
- package/dist/client/tcp/index.d.ts +13 -0
- package/dist/client/tcp/index.d.ts.map +1 -0
- package/dist/client/tcp/index.js +12 -0
- package/dist/client/tcp/index.js.map +1 -0
- package/dist/client/tcp/lineBuffer.d.ts +17 -0
- package/dist/client/tcp/lineBuffer.d.ts.map +1 -0
- package/dist/client/tcp/lineBuffer.js +32 -0
- package/dist/client/tcp/lineBuffer.js.map +1 -0
- package/dist/client/tcp/reconnect.d.ts +38 -0
- package/dist/client/tcp/reconnect.d.ts.map +1 -0
- package/dist/client/tcp/reconnect.js +70 -0
- package/dist/client/tcp/reconnect.js.map +1 -0
- package/dist/client/tcp/shared.d.ts +11 -0
- package/dist/client/tcp/shared.d.ts.map +1 -0
- package/dist/client/tcp/shared.js +20 -0
- package/dist/client/tcp/shared.js.map +1 -0
- package/dist/client/tcp/types.d.ts +69 -0
- package/dist/client/tcp/types.d.ts.map +1 -0
- package/dist/client/tcp/types.js +19 -0
- package/dist/client/tcp/types.js.map +1 -0
- package/dist/client/tcpClient.d.ts +4 -110
- package/dist/client/tcpClient.d.ts.map +1 -1
- package/dist/client/tcpClient.js +3 -523
- package/dist/client/tcpClient.js.map +1 -1
- package/dist/client/tcpPool.d.ts +3 -0
- package/dist/client/tcpPool.d.ts.map +1 -1
- package/dist/client/tcpPool.js +15 -2
- package/dist/client/tcpPool.js.map +1 -1
- package/dist/client/types.d.ts +7 -0
- package/dist/client/types.d.ts.map +1 -1
- package/dist/client/types.js.map +1 -1
- package/dist/client/worker/ackBatcher.d.ts +40 -0
- package/dist/client/worker/ackBatcher.d.ts.map +1 -0
- package/dist/client/worker/ackBatcher.js +137 -0
- package/dist/client/worker/ackBatcher.js.map +1 -0
- package/dist/client/worker/index.d.ts +11 -0
- package/dist/client/worker/index.d.ts.map +1 -0
- package/dist/client/worker/index.js +10 -0
- package/dist/client/worker/index.js.map +1 -0
- package/dist/client/worker/jobParser.d.ts +10 -0
- package/dist/client/worker/jobParser.d.ts.map +1 -0
- package/dist/client/worker/jobParser.js +43 -0
- package/dist/client/worker/jobParser.js.map +1 -0
- package/dist/client/worker/processor.d.ts +24 -0
- package/dist/client/worker/processor.d.ts.map +1 -0
- package/dist/client/worker/processor.js +86 -0
- package/dist/client/worker/processor.js.map +1 -0
- package/dist/client/worker/types.d.ts +38 -0
- package/dist/client/worker/types.d.ts.map +1 -0
- package/dist/client/worker/types.js +14 -0
- package/dist/client/worker/types.js.map +1 -0
- package/dist/client/worker/worker.d.ts +53 -0
- package/dist/client/worker/worker.d.ts.map +1 -0
- package/dist/client/worker/worker.js +367 -0
- package/dist/client/worker/worker.js.map +1 -0
- package/dist/client/worker.d.ts +3 -69
- package/dist/client/worker.d.ts.map +1 -1
- package/dist/client/worker.js +3 -472
- package/dist/client/worker.js.map +1 -1
- package/dist/domain/queue/shard.d.ts +19 -2
- package/dist/domain/queue/shard.d.ts.map +1 -1
- package/dist/domain/queue/shard.js +36 -4
- package/dist/domain/queue/shard.js.map +1 -1
- package/dist/domain/types/command.d.ts +9 -0
- package/dist/domain/types/command.d.ts.map +1 -1
- package/dist/domain/types/job.d.ts +27 -0
- package/dist/domain/types/job.d.ts.map +1 -1
- package/dist/domain/types/job.js +34 -0
- package/dist/domain/types/job.js.map +1 -1
- package/dist/domain/types/response.d.ts +15 -1
- package/dist/domain/types/response.d.ts.map +1 -1
- package/dist/domain/types/response.js +16 -0
- package/dist/domain/types/response.js.map +1 -1
- package/dist/infrastructure/server/handlers/core.d.ts +1 -1
- package/dist/infrastructure/server/handlers/core.d.ts.map +1 -1
- package/dist/infrastructure/server/handlers/core.js +74 -15
- package/dist/infrastructure/server/handlers/core.js.map +1 -1
- package/dist/infrastructure/server/handlers/monitoring.d.ts.map +1 -1
- package/dist/infrastructure/server/handlers/monitoring.js +6 -4
- package/dist/infrastructure/server/handlers/monitoring.js.map +1 -1
- package/dist/infrastructure/server/http.d.ts.map +1 -1
- package/dist/infrastructure/server/http.js +67 -0
- package/dist/infrastructure/server/http.js.map +1 -1
- package/dist/infrastructure/server/tcp.d.ts.map +1 -1
- package/dist/infrastructure/server/tcp.js +9 -1
- package/dist/infrastructure/server/tcp.js.map +1 -1
- package/dist/infrastructure/server/types.d.ts +2 -0
- package/dist/infrastructure/server/types.d.ts.map +1 -1
- package/dist/main.js +8 -0
- package/dist/main.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Health Tracker
|
|
3
|
+
* Monitors connection health with ping and latency tracking
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Tracks connection health metrics
|
|
7
|
+
*/
|
|
8
|
+
export class HealthTracker {
|
|
9
|
+
config;
|
|
10
|
+
consecutivePingFailures = 0;
|
|
11
|
+
lastSuccessAt = null;
|
|
12
|
+
lastErrorAt = null;
|
|
13
|
+
connectedAt = null;
|
|
14
|
+
totalCommands = 0;
|
|
15
|
+
totalErrors = 0;
|
|
16
|
+
latencyHistory = [];
|
|
17
|
+
pingTimer = null;
|
|
18
|
+
static MAX_LATENCY_HISTORY = 10;
|
|
19
|
+
constructor(config) {
|
|
20
|
+
this.config = config;
|
|
21
|
+
}
|
|
22
|
+
/** Record successful command */
|
|
23
|
+
recordSuccess(latencyMs) {
|
|
24
|
+
this.lastSuccessAt = Date.now();
|
|
25
|
+
this.totalCommands++;
|
|
26
|
+
this.recordLatency(latencyMs);
|
|
27
|
+
}
|
|
28
|
+
/** Record command error */
|
|
29
|
+
recordError() {
|
|
30
|
+
this.lastErrorAt = Date.now();
|
|
31
|
+
this.totalErrors++;
|
|
32
|
+
}
|
|
33
|
+
/** Record command sent (for total count) */
|
|
34
|
+
recordCommandSent() {
|
|
35
|
+
this.totalCommands++;
|
|
36
|
+
}
|
|
37
|
+
/** Record connection established */
|
|
38
|
+
recordConnected() {
|
|
39
|
+
this.connectedAt = Date.now();
|
|
40
|
+
this.consecutivePingFailures = 0;
|
|
41
|
+
}
|
|
42
|
+
/** Record ping success */
|
|
43
|
+
recordPingSuccess(latencyMs) {
|
|
44
|
+
this.consecutivePingFailures = 0;
|
|
45
|
+
this.recordLatency(latencyMs);
|
|
46
|
+
}
|
|
47
|
+
/** Record ping failure, returns true if max failures reached */
|
|
48
|
+
recordPingFailure() {
|
|
49
|
+
this.consecutivePingFailures++;
|
|
50
|
+
this.lastErrorAt = Date.now();
|
|
51
|
+
this.totalErrors++;
|
|
52
|
+
return this.consecutivePingFailures >= this.config.maxPingFailures;
|
|
53
|
+
}
|
|
54
|
+
/** Get current health metrics */
|
|
55
|
+
getHealth(state) {
|
|
56
|
+
const avgLatency = this.latencyHistory.length > 0
|
|
57
|
+
? this.latencyHistory.reduce((a, b) => a + b, 0) / this.latencyHistory.length
|
|
58
|
+
: 0;
|
|
59
|
+
return {
|
|
60
|
+
healthy: state === 'connected' && this.consecutivePingFailures < this.config.maxPingFailures,
|
|
61
|
+
state,
|
|
62
|
+
lastSuccessAt: this.lastSuccessAt,
|
|
63
|
+
lastErrorAt: this.lastErrorAt,
|
|
64
|
+
avgLatencyMs: Math.round(avgLatency * 100) / 100,
|
|
65
|
+
consecutivePingFailures: this.consecutivePingFailures,
|
|
66
|
+
totalCommands: this.totalCommands,
|
|
67
|
+
totalErrors: this.totalErrors,
|
|
68
|
+
uptimeMs: this.connectedAt ? Date.now() - this.connectedAt : 0,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
/** Start ping timer */
|
|
72
|
+
startPing(pingFn) {
|
|
73
|
+
if (this.config.pingInterval <= 0)
|
|
74
|
+
return;
|
|
75
|
+
this.stopPing();
|
|
76
|
+
this.pingTimer = setInterval(() => {
|
|
77
|
+
void pingFn();
|
|
78
|
+
}, this.config.pingInterval);
|
|
79
|
+
}
|
|
80
|
+
/** Stop ping timer */
|
|
81
|
+
stopPing() {
|
|
82
|
+
if (this.pingTimer) {
|
|
83
|
+
clearInterval(this.pingTimer);
|
|
84
|
+
this.pingTimer = null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Record latency for averaging */
|
|
88
|
+
recordLatency(latencyMs) {
|
|
89
|
+
this.latencyHistory.push(latencyMs);
|
|
90
|
+
if (this.latencyHistory.length > HealthTracker.MAX_LATENCY_HISTORY) {
|
|
91
|
+
this.latencyHistory.shift();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=health.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.js","sourceRoot":"","sources":["../../../src/client/tcp/health.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAUH;;GAEG;AACH,MAAM,OAAO,aAAa;IAYK;IAXrB,uBAAuB,GAAG,CAAC,CAAC;IAC5B,aAAa,GAAkB,IAAI,CAAC;IACpC,WAAW,GAAkB,IAAI,CAAC;IAClC,WAAW,GAAkB,IAAI,CAAC;IAClC,aAAa,GAAG,C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,CAAC;IACH,CAAC;IAED,mCAAmC;IAC3B,aAAa,CAAC,SAAiB;QACrC,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACpC,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,GAAG,aAAa,CAAC,mBAAmB,EAAE,CAAC;YACnE,IAAI,CAAC,cAAc,CAAC,KAAK,EAAE,CAAC;QAC9B,CAAC;IACH,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Client Module
|
|
3
|
+
* Re-exports all TCP client components
|
|
4
|
+
*/
|
|
5
|
+
export type { ConnectionOptions, ConnectionHealth, PendingCommand, SocketWrapper } from './types';
|
|
6
|
+
export { DEFAULT_CONNECTION } from './types';
|
|
7
|
+
export { LineBuffer } from './lineBuffer';
|
|
8
|
+
export { HealthTracker, type HealthConfig } from './health';
|
|
9
|
+
export { ReconnectManager, type ReconnectConfig } from './reconnect';
|
|
10
|
+
export { createConnection, CommandQueue } from './connection';
|
|
11
|
+
export { TcpClient } from './client';
|
|
12
|
+
export { getSharedTcpClient, closeSharedTcpClient } from './shared';
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAClG,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,KAAK,eAAe,EAAE,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Client Module
|
|
3
|
+
* Re-exports all TCP client components
|
|
4
|
+
*/
|
|
5
|
+
export { DEFAULT_CONNECTION } from './types';
|
|
6
|
+
export { LineBuffer } from './lineBuffer';
|
|
7
|
+
export { HealthTracker } from './health';
|
|
8
|
+
export { ReconnectManager } from './reconnect';
|
|
9
|
+
export { createConnection, CommandQueue } from './connection';
|
|
10
|
+
export { TcpClient } from './client';
|
|
11
|
+
export { getSharedTcpClient, closeSharedTcpClient } from './shared';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/client/tcp/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAqB,MAAM,UAAU,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAwB,MAAM,aAAa,CAAC;AACrE,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AACrC,OAAO,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line Buffer
|
|
3
|
+
* Efficient parsing of newline-delimited JSON protocol
|
|
4
|
+
*/
|
|
5
|
+
import type { LineBuffer as ILineBuffer } from './types';
|
|
6
|
+
/**
|
|
7
|
+
* Line buffer for efficient parsing of streaming data
|
|
8
|
+
* Handles partial messages across TCP packet boundaries
|
|
9
|
+
*/
|
|
10
|
+
export declare class LineBuffer implements ILineBuffer {
|
|
11
|
+
private partial;
|
|
12
|
+
/** Add data and return complete lines */
|
|
13
|
+
addData(data: string): string[];
|
|
14
|
+
/** Clear buffer */
|
|
15
|
+
clear(): void;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=lineBuffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lineBuffer.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/lineBuffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,UAAU,IAAI,WAAW,EAAE,MAAM,SAAS,CAAC;AAEzD;;;GAGG;AACH,qBAAa,UAAW,YAAW,WAAW;IAC5C,OAAO,CAAC,OAAO,CAAM;IAErB,yCAAyC;IACzC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE;IAkB/B,mBAAmB;IACnB,KAAK,IAAI,IAAI;CAGd"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Line Buffer
|
|
3
|
+
* Efficient parsing of newline-delimited JSON protocol
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Line buffer for efficient parsing of streaming data
|
|
7
|
+
* Handles partial messages across TCP packet boundaries
|
|
8
|
+
*/
|
|
9
|
+
export class LineBuffer {
|
|
10
|
+
partial = '';
|
|
11
|
+
/** Add data and return complete lines */
|
|
12
|
+
addData(data) {
|
|
13
|
+
const combined = this.partial + data;
|
|
14
|
+
const lines = [];
|
|
15
|
+
let start = 0;
|
|
16
|
+
let idx;
|
|
17
|
+
while ((idx = combined.indexOf('\n', start)) !== -1) {
|
|
18
|
+
const line = combined.slice(start, idx);
|
|
19
|
+
if (line.length > 0) {
|
|
20
|
+
lines.push(line);
|
|
21
|
+
}
|
|
22
|
+
start = idx + 1;
|
|
23
|
+
}
|
|
24
|
+
this.partial = start < combined.length ? combined.slice(start) : '';
|
|
25
|
+
return lines;
|
|
26
|
+
}
|
|
27
|
+
/** Clear buffer */
|
|
28
|
+
clear() {
|
|
29
|
+
this.partial = '';
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=lineBuffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lineBuffer.js","sourceRoot":"","sources":["../../../src/client/tcp/lineBuffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;;GAGG;AACH,MAAM,OAAO,UAAU;IACb,OAAO,GAAG,EAAE,CAAC;IAErB,yCAAyC;IACzC,OAAO,CAAC,IAAY;QAClB,MAAM,QAAQ,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC;QACrC,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;QACd,IAAI,GAAW,CAAC;QAEhB,OAAO,CAAC,GAAG,GAAG,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YACpD,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACxC,IAAI,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBACpB,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACnB,CAAC;YACD,KAAK,GAAG,GAAG,GAAG,CAAC,CAAC;QAClB,CAAC;QAED,IAAI,CAAC,OAAO,GAAG,KAAK,GAAG,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACpE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,mBAAmB;IACnB,KAAK;QACH,IAAI,CAAC,OAAO,GAAG,EAAE,CAAC;IACpB,CAAC;CACF"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Reconnection Manager
|
|
3
|
+
* Handles automatic reconnection with exponential backoff
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
/** Reconnection configuration */
|
|
7
|
+
export interface ReconnectConfig {
|
|
8
|
+
maxReconnectAttempts: number;
|
|
9
|
+
reconnectDelay: number;
|
|
10
|
+
maxReconnectDelay: number;
|
|
11
|
+
autoReconnect: boolean;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Manages reconnection attempts with exponential backoff
|
|
15
|
+
*/
|
|
16
|
+
export declare class ReconnectManager extends EventEmitter {
|
|
17
|
+
private readonly config;
|
|
18
|
+
private reconnectAttempts;
|
|
19
|
+
private reconnectTimer;
|
|
20
|
+
private closed;
|
|
21
|
+
constructor(config: ReconnectConfig);
|
|
22
|
+
/** Mark as closed (prevents further reconnects) */
|
|
23
|
+
setClosed(closed: boolean): void;
|
|
24
|
+
/** Check if closed */
|
|
25
|
+
isClosed(): boolean;
|
|
26
|
+
/** Reset reconnect attempts (call on successful connect) */
|
|
27
|
+
reset(): void;
|
|
28
|
+
/** Cancel pending reconnection */
|
|
29
|
+
cancelReconnect(): void;
|
|
30
|
+
/** Check if reconnection is allowed */
|
|
31
|
+
canReconnect(): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Schedule reconnection with exponential backoff
|
|
34
|
+
* Returns false if max attempts reached
|
|
35
|
+
*/
|
|
36
|
+
scheduleReconnect(connectFn: () => Promise<void>): boolean;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=reconnect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reconnect.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/reconnect.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,iCAAiC;AACjC,MAAM,WAAW,eAAe;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,aAAa,EAAE,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,qBAAa,gBAAiB,SAAQ,YAAY;IAKpC,OAAO,CAAC,QAAQ,CAAC,MAAM;IAJnC,OAAO,CAAC,iBAAiB,CAAK;IAC9B,OAAO,CAAC,cAAc,CAA8C;IACpE,OAAO,CAAC,MAAM,CAAS;gBAEM,MAAM,EAAE,eAAe;IAIpD,mDAAmD;IACnD,SAAS,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;IAOhC,sBAAsB;IACtB,QAAQ,IAAI,OAAO;IAInB,4DAA4D;IAC5D,KAAK,IAAI,IAAI;IAIb,kCAAkC;IAClC,eAAe,IAAI,IAAI;IAOvB,uCAAuC;IACvC,YAAY,IAAI,OAAO;IAIvB;;;OAGG;IACH,iBAAiB,CAAC,SAAS,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,GAAG,OAAO;CA6B3D"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Reconnection Manager
|
|
3
|
+
* Handles automatic reconnection with exponential backoff
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
/**
|
|
7
|
+
* Manages reconnection attempts with exponential backoff
|
|
8
|
+
*/
|
|
9
|
+
export class ReconnectManager extends EventEmitter {
|
|
10
|
+
config;
|
|
11
|
+
reconnectAttempts = 0;
|
|
12
|
+
reconnectTimer = null;
|
|
13
|
+
closed = false;
|
|
14
|
+
constructor(config) {
|
|
15
|
+
super();
|
|
16
|
+
this.config = config;
|
|
17
|
+
}
|
|
18
|
+
/** Mark as closed (prevents further reconnects) */
|
|
19
|
+
setClosed(closed) {
|
|
20
|
+
this.closed = closed;
|
|
21
|
+
if (closed) {
|
|
22
|
+
this.cancelReconnect();
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Check if closed */
|
|
26
|
+
isClosed() {
|
|
27
|
+
return this.closed;
|
|
28
|
+
}
|
|
29
|
+
/** Reset reconnect attempts (call on successful connect) */
|
|
30
|
+
reset() {
|
|
31
|
+
this.reconnectAttempts = 0;
|
|
32
|
+
}
|
|
33
|
+
/** Cancel pending reconnection */
|
|
34
|
+
cancelReconnect() {
|
|
35
|
+
if (this.reconnectTimer) {
|
|
36
|
+
clearTimeout(this.reconnectTimer);
|
|
37
|
+
this.reconnectTimer = null;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
/** Check if reconnection is allowed */
|
|
41
|
+
canReconnect() {
|
|
42
|
+
return this.config.autoReconnect && !this.closed;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Schedule reconnection with exponential backoff
|
|
46
|
+
* Returns false if max attempts reached
|
|
47
|
+
*/
|
|
48
|
+
scheduleReconnect(connectFn) {
|
|
49
|
+
if (this.reconnectTimer || this.closed)
|
|
50
|
+
return false;
|
|
51
|
+
this.reconnectAttempts++;
|
|
52
|
+
if (this.reconnectAttempts > this.config.maxReconnectAttempts) {
|
|
53
|
+
this.emit('maxReconnectAttemptsReached');
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
// Exponential backoff with jitter
|
|
57
|
+
const baseDelay = Math.min(this.config.reconnectDelay * Math.pow(2, this.reconnectAttempts - 1), this.config.maxReconnectDelay);
|
|
58
|
+
const jitter = Math.random() * 0.3 * baseDelay;
|
|
59
|
+
const delay = baseDelay + jitter;
|
|
60
|
+
this.emit('reconnecting', { attempt: this.reconnectAttempts, delay });
|
|
61
|
+
this.reconnectTimer = setTimeout(() => {
|
|
62
|
+
this.reconnectTimer = null;
|
|
63
|
+
connectFn().catch(() => {
|
|
64
|
+
// connect() will schedule another reconnect if needed
|
|
65
|
+
});
|
|
66
|
+
}, delay);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=reconnect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iB,GAAG,IAAI,CAAC,MAAM,CAAC,oBAAoB,EAAE,CAAC;YAC9D,IAAI,CAAC,IAAI,CAAC,6BAA6B,CAAC,CAAC;YACzC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,kCAAkC;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,CACxB,IAAI,CAAC,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,EACpE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAC9B,CAAC;QACF,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,GAAG,GAAG,SAAS,CAAC;QAC/C,MAAM,KAAK,GAAG,SAAS,GAAG,MAAM,CAAC;QAEjC,IAAI,CAAC,IAAI,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE,IAAI,CAAC,iBAAiB,EAAE,KAAK,EAAE,CAAC,CAAC;QAEtE,IAAI,CAAC,cAAc,GAAG,UAAU,CAAC,GAAG,EAAE;YACpC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;YAC3B,SAAS,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;gBACrB,sDAAsD;YACxD,CAAC,CAAC,CAAC;QACL,CAAC,EAAE,KAAK,CAAC,CAAC;QAEV,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared TCP Client Instance
|
|
3
|
+
* Singleton pattern for shared client management
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionOptions } from './types';
|
|
6
|
+
import { TcpClient } from './client';
|
|
7
|
+
/** Get shared TCP client */
|
|
8
|
+
export declare function getSharedTcpClient(options?: Partial<ConnectionOptions>): TcpClient;
|
|
9
|
+
/** Close shared client */
|
|
10
|
+
export declare function closeSharedTcpClient(): void;
|
|
11
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/shared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AACjD,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAKrC,4BAA4B;AAC5B,wBAAgB,kBAAkB,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,SAAS,CAGlF;AAED,0BAA0B;AAC1B,wBAAgB,oBAAoB,IAAI,IAAI,CAK3C"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared TCP Client Instance
|
|
3
|
+
* Singleton pattern for shared client management
|
|
4
|
+
*/
|
|
5
|
+
import { TcpClient } from './client';
|
|
6
|
+
/** Shared client instance */
|
|
7
|
+
let sharedClient = null;
|
|
8
|
+
/** Get shared TCP client */
|
|
9
|
+
export function getSharedTcpClient(options) {
|
|
10
|
+
sharedClient ??= new TcpClient(options);
|
|
11
|
+
return sharedClient;
|
|
12
|
+
}
|
|
13
|
+
/** Close shared client */
|
|
14
|
+
export function closeSharedTcpClient() {
|
|
15
|
+
if (sharedClient) {
|
|
16
|
+
sharedClient.close();
|
|
17
|
+
sharedClient = null;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../../src/client/tcp/shared.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC,6BAA6B;AAC7B,IAAI,YAAY,GAAqB,IAAI,CAAC;AAE1C,4BAA4B;AAC5B,MAAM,UAAU,kBAAkB,CAAC,OAAoC;IACrE,YAAY,KAAK,IAAI,SAAS,CAAC,OAAO,CAAC,CAAC;IACxC,OAAO,YAAY,CAAC;AACtB,CAAC;AAED,0BAA0B;AAC1B,MAAM,UAAU,oBAAoB;IAClC,IAAI,YAAY,EAAE,CAAC;QACjB,YAAY,CAAC,KAAK,EAAE,CAAC;QACrB,YAAY,GAAG,IAAI,CAAC;IACtB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Client Types
|
|
3
|
+
* Type definitions for TCP connection management
|
|
4
|
+
*/
|
|
5
|
+
/** Connection options */
|
|
6
|
+
export interface ConnectionOptions {
|
|
7
|
+
host: string;
|
|
8
|
+
port: number;
|
|
9
|
+
token?: string;
|
|
10
|
+
/** Max reconnection attempts (default: Infinity) */
|
|
11
|
+
maxReconnectAttempts?: number;
|
|
12
|
+
/** Initial reconnect delay in ms (default: 100) */
|
|
13
|
+
reconnectDelay?: number;
|
|
14
|
+
/** Max reconnect delay in ms (default: 30000) */
|
|
15
|
+
maxReconnectDelay?: number;
|
|
16
|
+
/** Connection timeout in ms (default: 5000) */
|
|
17
|
+
connectTimeout?: number;
|
|
18
|
+
/** Command timeout in ms (default: 30000) */
|
|
19
|
+
commandTimeout?: number;
|
|
20
|
+
/** Enable auto-reconnect (default: true) */
|
|
21
|
+
autoReconnect?: boolean;
|
|
22
|
+
/** Health check ping interval in ms (default: 30000, 0 to disable) */
|
|
23
|
+
pingInterval?: number;
|
|
24
|
+
/** Max consecutive ping failures before forcing reconnect (default: 3) */
|
|
25
|
+
maxPingFailures?: number;
|
|
26
|
+
}
|
|
27
|
+
/** Connection health metrics */
|
|
28
|
+
export interface ConnectionHealth {
|
|
29
|
+
/** Whether connection is currently healthy */
|
|
30
|
+
healthy: boolean;
|
|
31
|
+
/** Current connection state */
|
|
32
|
+
state: 'connected' | 'connecting' | 'disconnected' | 'closed';
|
|
33
|
+
/** Timestamp of last successful command */
|
|
34
|
+
lastSuccessAt: number | null;
|
|
35
|
+
/** Timestamp of last error */
|
|
36
|
+
lastErrorAt: number | null;
|
|
37
|
+
/** Average latency of last 10 commands in ms */
|
|
38
|
+
avgLatencyMs: number;
|
|
39
|
+
/** Consecutive ping failures */
|
|
40
|
+
consecutivePingFailures: number;
|
|
41
|
+
/** Total commands sent */
|
|
42
|
+
totalCommands: number;
|
|
43
|
+
/** Total errors */
|
|
44
|
+
totalErrors: number;
|
|
45
|
+
/** Uptime since last connect in ms */
|
|
46
|
+
uptimeMs: number;
|
|
47
|
+
}
|
|
48
|
+
/** Default connection options */
|
|
49
|
+
export declare const DEFAULT_CONNECTION: Required<ConnectionOptions>;
|
|
50
|
+
/** Pending command awaiting response */
|
|
51
|
+
export interface PendingCommand {
|
|
52
|
+
id: number;
|
|
53
|
+
command: Record<string, unknown>;
|
|
54
|
+
resolve: (value: Record<string, unknown>) => void;
|
|
55
|
+
reject: (error: Error) => void;
|
|
56
|
+
timeout: ReturnType<typeof setTimeout>;
|
|
57
|
+
}
|
|
58
|
+
/** Socket wrapper interface */
|
|
59
|
+
export interface SocketWrapper {
|
|
60
|
+
write: (data: string) => void;
|
|
61
|
+
end: () => void;
|
|
62
|
+
lineBuffer: LineBuffer;
|
|
63
|
+
}
|
|
64
|
+
/** Line buffer interface for protocol parsing */
|
|
65
|
+
export interface LineBuffer {
|
|
66
|
+
addData(data: string): string[];
|
|
67
|
+
clear(): void;
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,yBAAyB;AACzB,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oDAAoD;IACpD,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,mDAAmD;IACnD,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,iDAAiD;I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C,CAAC;CACxC;AAED,+BAA+B;AAC/B,MAAM,WAAW,aAAa;IAC5B,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9B,GAAG,EAAE,MAAM,IAAI,CAAC;IAChB,UAAU,EAAE,UAAU,CAAC;CACxB;AAED,iDAAiD;AACjD,MAAM,WAAW,UAAU;IACzB,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,KAAK,IAAI,IAAI,CAAC;CACf"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Client Types
|
|
3
|
+
* Type definitions for TCP connection management
|
|
4
|
+
*/
|
|
5
|
+
/** Default connection options */
|
|
6
|
+
export const DEFAULT_CONNECTION = {
|
|
7
|
+
host: 'localhost',
|
|
8
|
+
port: 6789,
|
|
9
|
+
token: '',
|
|
10
|
+
maxReconnectAttempts: Infinity,
|
|
11
|
+
reconnectDelay: 100,
|
|
12
|
+
maxReconnectDelay: 30000,
|
|
13
|
+
connectTimeout: 5000,
|
|
14
|
+
commandTimeout: 30000,
|
|
15
|
+
autoReconnect: true,
|
|
16
|
+
pingInterval: 30000,
|
|
17
|
+
maxPingFailures: 3,
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/client/tcp/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AA+CH,iCAAiC;AACjC,MAAM,CAAC,MAAM,kBAAkB,GAAgC;IAC7D,IAAI,EAAE,WAAW;IACjB,IAAI,EAAE,IAAI;IACV,KAAK,EAAE,EAAE;IACT,oBAAoB,EAAE,QAAQ;IAC9B,cAAc,EAAE,GAAG;IACnB,iBAAiB,EAAE,KAAK;IACxB,cAAc,EAAE,IAAI;IACpB,cAAc,EAAE,KAAK;IACrB,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,KAAK;IACnB,eAAe,EAAE,CAAC;CACnB,CAAC"}
|
|
@@ -1,113 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* TCP Client
|
|
3
|
-
*
|
|
2
|
+
* TCP Client - Re-exports from tcp module
|
|
3
|
+
* @deprecated Import from './tcp' instead
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
export interface ConnectionOptions {
|
|
8
|
-
host: string;
|
|
9
|
-
port: number;
|
|
10
|
-
token?: string;
|
|
11
|
-
/** Max reconnection attempts (default: Infinity) */
|
|
12
|
-
maxReconnectAttempts?: number;
|
|
13
|
-
/** Initial reconnect delay in ms (default: 100) */
|
|
14
|
-
reconnectDelay?: number;
|
|
15
|
-
/** Max reconnect delay in ms (default: 30000) */
|
|
16
|
-
maxReconnectDelay?: number;
|
|
17
|
-
/** Connection timeout in ms (default: 5000) */
|
|
18
|
-
connectTimeout?: number;
|
|
19
|
-
/** Command timeout in ms (default: 30000) */
|
|
20
|
-
commandTimeout?: number;
|
|
21
|
-
/** Enable auto-reconnect (default: true) */
|
|
22
|
-
autoReconnect?: boolean;
|
|
23
|
-
/** Health check ping interval in ms (default: 30000, 0 to disable) */
|
|
24
|
-
pingInterval?: number;
|
|
25
|
-
/** Max consecutive ping failures before forcing reconnect (default: 3) */
|
|
26
|
-
maxPingFailures?: number;
|
|
27
|
-
}
|
|
28
|
-
/** Connection health metrics */
|
|
29
|
-
export interface ConnectionHealth {
|
|
30
|
-
/** Whether connection is currently healthy */
|
|
31
|
-
healthy: boolean;
|
|
32
|
-
/** Current connection state */
|
|
33
|
-
state: 'connected' | 'connecting' | 'disconnected' | 'closed';
|
|
34
|
-
/** Timestamp of last successful command */
|
|
35
|
-
lastSuccessAt: number | null;
|
|
36
|
-
/** Timestamp of last error */
|
|
37
|
-
lastErrorAt: number | null;
|
|
38
|
-
/** Average latency of last 10 commands in ms */
|
|
39
|
-
avgLatencyMs: number;
|
|
40
|
-
/** Consecutive ping failures */
|
|
41
|
-
consecutivePingFailures: number;
|
|
42
|
-
/** Total commands sent */
|
|
43
|
-
totalCommands: number;
|
|
44
|
-
/** Total errors */
|
|
45
|
-
totalErrors: number;
|
|
46
|
-
/** Uptime since last connect in ms */
|
|
47
|
-
uptimeMs: number;
|
|
48
|
-
}
|
|
49
|
-
/** Default connection */
|
|
50
|
-
export declare const DEFAULT_CONNECTION: Required<ConnectionOptions>;
|
|
51
|
-
/**
|
|
52
|
-
* TCP Client - manages connection to bunqueue server
|
|
53
|
-
* Production-ready with auto-reconnection and exponential backoff
|
|
54
|
-
*/
|
|
55
|
-
export declare class TcpClient extends EventEmitter {
|
|
56
|
-
private socket;
|
|
57
|
-
private connected;
|
|
58
|
-
private connecting;
|
|
59
|
-
private closed;
|
|
60
|
-
private reconnectAttempts;
|
|
61
|
-
private reconnectTimer;
|
|
62
|
-
private pingTimer;
|
|
63
|
-
private readonly options;
|
|
64
|
-
private readonly pendingCommands;
|
|
65
|
-
private pendingQueue;
|
|
66
|
-
private currentCommand;
|
|
67
|
-
private commandIdCounter;
|
|
68
|
-
private consecutivePingFailures;
|
|
69
|
-
private lastSuccessAt;
|
|
70
|
-
private lastErrorAt;
|
|
71
|
-
private connectedAt;
|
|
72
|
-
private totalCommands;
|
|
73
|
-
private totalErrors;
|
|
74
|
-
private readonly latencyHistory;
|
|
75
|
-
private static readonly MAX_LATENCY_HISTORY;
|
|
76
|
-
constructor(options?: Partial<ConnectionOptions>);
|
|
77
|
-
/** Connect to server */
|
|
78
|
-
connect(): Promise<void>;
|
|
79
|
-
private doConnect;
|
|
80
|
-
/** Start periodic health check ping */
|
|
81
|
-
private startPing;
|
|
82
|
-
/** Stop health check ping */
|
|
83
|
-
private stopPing;
|
|
84
|
-
/** Send ping to check connection health */
|
|
85
|
-
ping(): Promise<boolean>;
|
|
86
|
-
/** Handle ping failure - force reconnect if too many failures */
|
|
87
|
-
private handlePingFailure;
|
|
88
|
-
/** Force reconnection */
|
|
89
|
-
private forceReconnect;
|
|
90
|
-
/** Record command latency for health metrics */
|
|
91
|
-
private recordLatency;
|
|
92
|
-
/** Get connection health metrics */
|
|
93
|
-
getHealth(): ConnectionHealth;
|
|
94
|
-
/** Schedule reconnection with exponential backoff */
|
|
95
|
-
private scheduleReconnect;
|
|
96
|
-
/** Internal send without auto-connect */
|
|
97
|
-
private sendInternal;
|
|
98
|
-
/** Process next pending command */
|
|
99
|
-
private processNextCommand;
|
|
100
|
-
/** Send command and wait for response */
|
|
101
|
-
send(command: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
102
|
-
/** Close connection */
|
|
103
|
-
close(): void;
|
|
104
|
-
/** Check if connected */
|
|
105
|
-
isConnected(): boolean;
|
|
106
|
-
/** Get connection state */
|
|
107
|
-
getState(): 'connected' | 'connecting' | 'disconnected' | 'closed';
|
|
108
|
-
}
|
|
109
|
-
/** Get shared TCP client */
|
|
110
|
-
export declare function getSharedTcpClient(options?: Partial<ConnectionOptions>): TcpClient;
|
|
111
|
-
/** Close shared client */
|
|
112
|
-
export declare function closeSharedTcpClient(): void;
|
|
5
|
+
export type { ConnectionOptions, ConnectionHealth } from './tcp';
|
|
6
|
+
export { DEFAULT_CONNECTION, TcpClient, getSharedTcpClient, closeSharedTcpClient } from './tcp';
|
|
113
7
|
//# sourceMappingURL=tcpClient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tcpClient.d.ts","sourceRoot":"","sources":["../../src/client/tcpClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,
|
|
1
|
+
{"version":3,"file":"tcpClient.d.ts","sourceRoot":"","sources":["../../src/client/tcpClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,EAAE,kBAAkB,EAAE,SAAS,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC"}
|