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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sandboxedWorker.js","sourceRoot":"","sources":["../../src/client/sandboxedWorker.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"sandboxedWorker.js","sourceRoot":"","sources":["../../src/client/sandboxedWorker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Client
|
|
3
|
+
* Production-ready TCP client with auto-reconnection
|
|
4
|
+
*/
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import type { ConnectionOptions, ConnectionHealth } from './types';
|
|
7
|
+
/**
|
|
8
|
+
* TCP Client - manages connection to bunqueue server
|
|
9
|
+
*/
|
|
10
|
+
export declare class TcpClient extends EventEmitter {
|
|
11
|
+
private socket;
|
|
12
|
+
private connected;
|
|
13
|
+
private connecting;
|
|
14
|
+
private readonly options;
|
|
15
|
+
private readonly health;
|
|
16
|
+
private readonly reconnect;
|
|
17
|
+
private readonly commands;
|
|
18
|
+
constructor(options?: Partial<ConnectionOptions>);
|
|
19
|
+
/** Connect to server */
|
|
20
|
+
connect(): Promise<void>;
|
|
21
|
+
private waitForConnection;
|
|
22
|
+
private doConnect;
|
|
23
|
+
private authenticate;
|
|
24
|
+
private handleData;
|
|
25
|
+
private handleClose;
|
|
26
|
+
/** Send ping to check connection health */
|
|
27
|
+
ping(): Promise<boolean>;
|
|
28
|
+
private handlePingFailure;
|
|
29
|
+
private forceReconnect;
|
|
30
|
+
/** Get connection health metrics */
|
|
31
|
+
getHealth(): ConnectionHealth;
|
|
32
|
+
private sendInternal;
|
|
33
|
+
private processNextCommand;
|
|
34
|
+
/** Send command and wait for response */
|
|
35
|
+
send(command: Record<string, unknown>): Promise<Record<string, unknown>>;
|
|
36
|
+
/** Close connection */
|
|
37
|
+
close(): void;
|
|
38
|
+
/** Check if connected */
|
|
39
|
+
isConnected(): boolean;
|
|
40
|
+
/** Get connection state */
|
|
41
|
+
getState(): 'connected' | 'connecting' | 'disconnected' | 'closed';
|
|
42
|
+
}
|
|
43
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAA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
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { DEFAULT_CONNECTION } from './types';
|
|
7
|
+
import { HealthTracker } from './health';
|
|
8
|
+
import { ReconnectManager } from './reconnect';
|
|
9
|
+
import { createConnection, CommandQueue } from './connection';
|
|
10
|
+
/**
|
|
11
|
+
* TCP Client - manages connection to bunqueue server
|
|
12
|
+
*/
|
|
13
|
+
export class TcpClient extends EventEmitter {
|
|
14
|
+
socket = null;
|
|
15
|
+
connected = false;
|
|
16
|
+
connecting = false;
|
|
17
|
+
options;
|
|
18
|
+
health;
|
|
19
|
+
reconnect;
|
|
20
|
+
commands;
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
super();
|
|
23
|
+
this.options = { ...DEFAULT_CONNECTION, ...options };
|
|
24
|
+
this.commands = new CommandQueue();
|
|
25
|
+
this.health = new HealthTracker({
|
|
26
|
+
pingInterval: this.options.pingInterval,
|
|
27
|
+
maxPingFailures: this.options.maxPingFailures,
|
|
28
|
+
});
|
|
29
|
+
this.reconnect = new ReconnectManager({
|
|
30
|
+
maxReconnectAttempts: this.options.maxReconnectAttempts,
|
|
31
|
+
reconnectDelay: this.options.reconnectDelay,
|
|
32
|
+
maxReconnectDelay: this.options.maxReconnectDelay,
|
|
33
|
+
autoReconnect: this.options.autoReconnect,
|
|
34
|
+
});
|
|
35
|
+
this.reconnect.on('reconnecting', (data) => this.emit('reconnecting', data));
|
|
36
|
+
this.reconnect.on('maxReconnectAttemptsReached', () => {
|
|
37
|
+
this.emit('maxReconnectAttemptsReached');
|
|
38
|
+
this.commands.rejectAll(new Error('Max reconnection attempts reached'));
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
/** Connect to server */
|
|
42
|
+
async connect() {
|
|
43
|
+
if (this.connected)
|
|
44
|
+
return;
|
|
45
|
+
if (this.connecting) {
|
|
46
|
+
return this.waitForConnection();
|
|
47
|
+
}
|
|
48
|
+
this.connecting = true;
|
|
49
|
+
this.reconnect.setClosed(false);
|
|
50
|
+
try {
|
|
51
|
+
await this.doConnect();
|
|
52
|
+
this.reconnect.reset();
|
|
53
|
+
this.emit('connected');
|
|
54
|
+
this.health.startPing(async () => {
|
|
55
|
+
await this.ping();
|
|
56
|
+
});
|
|
57
|
+
this.processNextCommand();
|
|
58
|
+
}
|
|
59
|
+
catch (err) {
|
|
60
|
+
this.connecting = false;
|
|
61
|
+
if (this.reconnect.canReconnect()) {
|
|
62
|
+
this.reconnect.scheduleReconnect(() => this.connect());
|
|
63
|
+
}
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
waitForConnection() {
|
|
68
|
+
return new Promise((resolve, reject) => {
|
|
69
|
+
const onConnect = () => {
|
|
70
|
+
this.off('error', onError);
|
|
71
|
+
resolve();
|
|
72
|
+
};
|
|
73
|
+
const onError = (err) => {
|
|
74
|
+
this.off('connected', onConnect);
|
|
75
|
+
reject(err);
|
|
76
|
+
};
|
|
77
|
+
this.once('connected', onConnect);
|
|
78
|
+
this.once('error', onError);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async doConnect() {
|
|
82
|
+
const { socket } = await createConnection(this.options.host, this.options.port, this.options.connectTimeout, {
|
|
83
|
+
onData: (line) => {
|
|
84
|
+
this.handleData(line);
|
|
85
|
+
},
|
|
86
|
+
onClose: () => {
|
|
87
|
+
this.handleClose();
|
|
88
|
+
},
|
|
89
|
+
onError: (error) => this.emit('error', error),
|
|
90
|
+
});
|
|
91
|
+
this.socket = socket;
|
|
92
|
+
this.connected = true;
|
|
93
|
+
this.connecting = false;
|
|
94
|
+
this.health.recordConnected();
|
|
95
|
+
if (this.options.token) {
|
|
96
|
+
await this.authenticate();
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async authenticate() {
|
|
100
|
+
const response = await this.sendInternal({ cmd: 'Auth', token: this.options.token });
|
|
101
|
+
if (!response.ok) {
|
|
102
|
+
throw new Error('Authentication failed');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
handleData(line) {
|
|
106
|
+
const current = this.commands.getCurrentCommand();
|
|
107
|
+
if (!current)
|
|
108
|
+
return;
|
|
109
|
+
try {
|
|
110
|
+
const response = JSON.parse(line);
|
|
111
|
+
clearTimeout(current.timeout);
|
|
112
|
+
current.resolve(response);
|
|
113
|
+
this.commands.setCurrentCommand(null);
|
|
114
|
+
this.processNextCommand();
|
|
115
|
+
}
|
|
116
|
+
catch {
|
|
117
|
+
clearTimeout(current.timeout);
|
|
118
|
+
current.reject(new Error('Invalid response from server'));
|
|
119
|
+
this.commands.setCurrentCommand(null);
|
|
120
|
+
this.processNextCommand();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
handleClose() {
|
|
124
|
+
const wasConnected = this.connected;
|
|
125
|
+
this.connected = false;
|
|
126
|
+
this.connecting = false;
|
|
127
|
+
this.socket = null;
|
|
128
|
+
this.health.stopPing();
|
|
129
|
+
// Reject current in-flight command so it doesn't hang forever
|
|
130
|
+
this.commands.clearCurrent(new Error('Connection lost'));
|
|
131
|
+
if (wasConnected) {
|
|
132
|
+
this.emit('disconnected');
|
|
133
|
+
if (this.reconnect.canReconnect()) {
|
|
134
|
+
this.reconnect.scheduleReconnect(() => this.connect());
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
/** Send ping to check connection health */
|
|
139
|
+
async ping() {
|
|
140
|
+
if (!this.connected)
|
|
141
|
+
return false;
|
|
142
|
+
try {
|
|
143
|
+
const start = Date.now();
|
|
144
|
+
const response = await this.send({ cmd: 'Ping' });
|
|
145
|
+
const success = response.pong === true;
|
|
146
|
+
if (success) {
|
|
147
|
+
this.health.recordPingSuccess(Date.now() - start);
|
|
148
|
+
this.emit('health', { type: 'ping_success', latency: Date.now() - start });
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
this.handlePingFailure();
|
|
152
|
+
}
|
|
153
|
+
return success;
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
this.handlePingFailure();
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
handlePingFailure() {
|
|
161
|
+
if (this.health.recordPingFailure()) {
|
|
162
|
+
this.emit('health', { type: 'unhealthy', reason: 'max_ping_failures' });
|
|
163
|
+
this.forceReconnect();
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
this.emit('health', { type: 'ping_failed' });
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
forceReconnect() {
|
|
170
|
+
if (this.reconnect.isClosed())
|
|
171
|
+
return;
|
|
172
|
+
if (this.socket) {
|
|
173
|
+
this.socket.end();
|
|
174
|
+
this.socket = null;
|
|
175
|
+
}
|
|
176
|
+
this.connected = false;
|
|
177
|
+
this.health.stopPing();
|
|
178
|
+
if (this.reconnect.canReconnect())
|
|
179
|
+
this.reconnect.scheduleReconnect(() => this.connect());
|
|
180
|
+
}
|
|
181
|
+
/** Get connection health metrics */
|
|
182
|
+
getHealth() {
|
|
183
|
+
return this.health.getHealth(this.getState());
|
|
184
|
+
}
|
|
185
|
+
async sendInternal(command) {
|
|
186
|
+
if (!this.socket)
|
|
187
|
+
throw new Error('Not connected');
|
|
188
|
+
const startTime = Date.now();
|
|
189
|
+
this.health.recordCommandSent();
|
|
190
|
+
return new Promise((resolve, reject) => {
|
|
191
|
+
const timeout = setTimeout(() => {
|
|
192
|
+
const current = this.commands.getCurrentCommand();
|
|
193
|
+
if (current?.command === command) {
|
|
194
|
+
this.commands.setCurrentCommand(null);
|
|
195
|
+
this.health.recordError();
|
|
196
|
+
reject(new Error('Command timeout'));
|
|
197
|
+
this.processNextCommand();
|
|
198
|
+
}
|
|
199
|
+
}, this.options.commandTimeout);
|
|
200
|
+
this.commands.setCurrentCommand({
|
|
201
|
+
id: 0,
|
|
202
|
+
command,
|
|
203
|
+
resolve: (result) => {
|
|
204
|
+
this.health.recordSuccess(Date.now() - startTime);
|
|
205
|
+
resolve(result);
|
|
206
|
+
},
|
|
207
|
+
reject: (err) => {
|
|
208
|
+
this.health.recordError();
|
|
209
|
+
reject(err);
|
|
210
|
+
},
|
|
211
|
+
timeout,
|
|
212
|
+
});
|
|
213
|
+
this.socket?.write(JSON.stringify(command) + '\n');
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
processNextCommand() {
|
|
217
|
+
if (this.commands.getCurrentCommand() || !this.connected)
|
|
218
|
+
return;
|
|
219
|
+
const next = this.commands.dequeue();
|
|
220
|
+
if (!next || !this.socket)
|
|
221
|
+
return;
|
|
222
|
+
this.commands.setCurrentCommand(next);
|
|
223
|
+
this.socket.write(JSON.stringify(next.command) + '\n');
|
|
224
|
+
}
|
|
225
|
+
/** Send command and wait for response */
|
|
226
|
+
async send(command) {
|
|
227
|
+
if (this.connected && !this.commands.hasPending() && !this.commands.getCurrentCommand()) {
|
|
228
|
+
return this.sendInternal(command);
|
|
229
|
+
}
|
|
230
|
+
const startTime = Date.now();
|
|
231
|
+
this.health.recordCommandSent();
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
const id = this.commands.nextId();
|
|
234
|
+
const timeout = setTimeout(() => {
|
|
235
|
+
if (this.commands.remove(id)) {
|
|
236
|
+
this.health.recordError();
|
|
237
|
+
reject(new Error('Command timeout'));
|
|
238
|
+
}
|
|
239
|
+
}, this.options.commandTimeout);
|
|
240
|
+
this.commands.enqueue({
|
|
241
|
+
id,
|
|
242
|
+
command,
|
|
243
|
+
resolve: (result) => {
|
|
244
|
+
this.health.recordSuccess(Date.now() - startTime);
|
|
245
|
+
resolve(result);
|
|
246
|
+
},
|
|
247
|
+
reject: (err) => {
|
|
248
|
+
this.health.recordError();
|
|
249
|
+
reject(err);
|
|
250
|
+
},
|
|
251
|
+
timeout,
|
|
252
|
+
});
|
|
253
|
+
if (!this.connected && !this.connecting) {
|
|
254
|
+
this.connect().catch(() => { });
|
|
255
|
+
}
|
|
256
|
+
else if (this.connected) {
|
|
257
|
+
this.processNextCommand();
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
/** Close connection */
|
|
262
|
+
close() {
|
|
263
|
+
this.reconnect.setClosed(true);
|
|
264
|
+
this.health.stopPing();
|
|
265
|
+
this.reconnect.cancelReconnect();
|
|
266
|
+
this.commands.rejectAll(new Error('Client closed'));
|
|
267
|
+
if (this.socket) {
|
|
268
|
+
this.socket.end();
|
|
269
|
+
this.socket = null;
|
|
270
|
+
this.connected = false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
/** Check if connected */
|
|
274
|
+
isConnected() {
|
|
275
|
+
return this.connected;
|
|
276
|
+
}
|
|
277
|
+
/** Get connection state */
|
|
278
|
+
getState() {
|
|
279
|
+
if (this.reconnect.isClosed())
|
|
280
|
+
return 'closed';
|
|
281
|
+
if (this.connected)
|
|
282
|
+
return 'connected';
|
|
283
|
+
if (this.connecting)
|
|
284
|
+
return 'connecting';
|
|
285
|
+
return 'disconnected';
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/client/tcp/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE9D;;GAEG;AACH,MAAM,OAAO,SAAU,SAAQ,YAAY;IACjC,MAAM,GAAyB,IAAI,CAAC;IACpC,SAAS,GAAG,KAAK,CAAC;IAClB,UAAU,GAAG,KAAK,CAAC;IACV,OAAO,CAA8B;IACrC,MAAM,CAAgB;IACtB,SAAS,CAAmB;IAC5B,QAAQ,CAAe;IAEx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AC;YAC5B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,uBAAuB;IACvB,KAAK;QACH,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;QACvB,IAAI,CAAC,SAAS,CAAC,eAAe,EAAE,CAAC;QACjC,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,eAAe,CAAC,CAAC,CAAC;QACpD,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAChB,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;YAClB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;YACnB,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC;QACzB,CAAC;IACH,CAAC;IAED,yBAAyB;IACzB,WAAW;QACT,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,2BAA2B;IAC3B,QAAQ;QACN,IAAI,IAAI,CAAC,SAAS,CAAC,QAAQ,EAAE;YAAE,OAAO,QAAQ,CAAC;QAC/C,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO,WAAW,CAAC;QACvC,IAAI,IAAI,CAAC,UAAU;YAAE,OAAO,YAAY,CAAC;QACzC,OAAO,cAAc,CAAC;IACxB,CAAC;CACF"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Connection Handler
|
|
3
|
+
* Manages low-level socket connection and data handling
|
|
4
|
+
*/
|
|
5
|
+
import type { SocketWrapper, PendingCommand } from './types';
|
|
6
|
+
/** Connection events */
|
|
7
|
+
export interface ConnectionEvents {
|
|
8
|
+
onData: (line: string) => void;
|
|
9
|
+
onClose: () => void;
|
|
10
|
+
onError: (error: Error) => void;
|
|
11
|
+
}
|
|
12
|
+
/** Connection result */
|
|
13
|
+
export interface ConnectionResult {
|
|
14
|
+
socket: SocketWrapper;
|
|
15
|
+
cleanup: () => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Establish TCP connection to server
|
|
19
|
+
*/
|
|
20
|
+
export declare function createConnection(host: string, port: number, connectTimeout: number, events: ConnectionEvents): Promise<ConnectionResult>;
|
|
21
|
+
/**
|
|
22
|
+
* Command queue for managing pending commands
|
|
23
|
+
*/
|
|
24
|
+
export declare class CommandQueue {
|
|
25
|
+
private readonly pendingCommands;
|
|
26
|
+
private pendingQueue;
|
|
27
|
+
private currentCommand;
|
|
28
|
+
private commandIdCounter;
|
|
29
|
+
/** Get current command being processed */
|
|
30
|
+
getCurrentCommand(): PendingCommand | null;
|
|
31
|
+
/** Set current command */
|
|
32
|
+
setCurrentCommand(cmd: PendingCommand | null): void;
|
|
33
|
+
/** Check if has pending commands */
|
|
34
|
+
hasPending(): boolean;
|
|
35
|
+
/** Add command to queue */
|
|
36
|
+
enqueue(command: PendingCommand): void;
|
|
37
|
+
/** Get next command ID */
|
|
38
|
+
nextId(): number;
|
|
39
|
+
/** Dequeue next command */
|
|
40
|
+
dequeue(): PendingCommand | null;
|
|
41
|
+
/** Remove command by ID */
|
|
42
|
+
remove(id: number): boolean;
|
|
43
|
+
/** Reject all pending commands */
|
|
44
|
+
rejectAll(error: Error): void;
|
|
45
|
+
/** Clear current command with optional rejection */
|
|
46
|
+
clearCurrent(error?: Error): void;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=connection.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/connection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AAG7D,wBAAwB;AACxB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/B,OAAO,EAAE,MAAM,IAAI,CAAC;IACpB,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CACjC;AAED,wBAAwB;AACxB,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,aAAa,CAAC;IACtB,OAAO,EAAE,MAAM,IAAI,CAAC;CACrB;AAED;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,gBAAgB,GACvB,OAAO,CAAC,gBAAgB,CAAC,CAoE3B;AAED;;GAEG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAA0C;IAC1E,OAAO,CAAC,YAAY,CAAgB;IACpC,OAAO,CAAC,cAAc,CAA+B;IACrD,OAAO,CAAC,gBAAgB,CAAK;IAE7B,0CAA0C;IAC1C,iBAAiB,IAAI,cAAc,GAAG,IAAI;IAI1C,0BAA0B;IAC1B,iBAAiB,CAAC,GAAG,EAAE,cAAc,GAAG,IAAI,GAAG,IAAI;IAInD,oCAAoC;IACpC,UAAU,IAAI,OAAO;IAIrB,2BAA2B;IAC3B,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI;IAKtC,0BAA0B;IAC1B,MAAM,IAAI,MAAM;IAIhB,2BAA2B;IAC3B,OAAO,IAAI,cAAc,GAAG,IAAI;IAWhC,2BAA2B;IAC3B,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAW3B,kCAAkC;IAClC,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI;IAe7B,oDAAoD;IACpD,YAAY,CAAC,KAAK,CAAC,EAAE,KAAK,GAAG,IAAI;CASlC"}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Connection Handler
|
|
3
|
+
* Manages low-level socket connection and data handling
|
|
4
|
+
*/
|
|
5
|
+
import { LineBuffer } from './lineBuffer';
|
|
6
|
+
/**
|
|
7
|
+
* Establish TCP connection to server
|
|
8
|
+
*/
|
|
9
|
+
export async function createConnection(host, port, connectTimeout, events) {
|
|
10
|
+
return new Promise((resolve, reject) => {
|
|
11
|
+
const socketData = {
|
|
12
|
+
write: () => { },
|
|
13
|
+
end: () => { },
|
|
14
|
+
lineBuffer: new LineBuffer(),
|
|
15
|
+
};
|
|
16
|
+
let connectionResolved = false;
|
|
17
|
+
let timeoutId = null;
|
|
18
|
+
const cleanup = () => {
|
|
19
|
+
if (timeoutId) {
|
|
20
|
+
clearTimeout(timeoutId);
|
|
21
|
+
timeoutId = null;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
void Bun.connect({
|
|
25
|
+
hostname: host,
|
|
26
|
+
port: port,
|
|
27
|
+
socket: {
|
|
28
|
+
data: (_sock, data) => {
|
|
29
|
+
const lines = socketData.lineBuffer.addData(data.toString());
|
|
30
|
+
for (const line of lines) {
|
|
31
|
+
events.onData(line);
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
open: (sock) => {
|
|
35
|
+
cleanup();
|
|
36
|
+
socketData.write = (d) => sock.write(d);
|
|
37
|
+
socketData.end = () => sock.end();
|
|
38
|
+
connectionResolved = true;
|
|
39
|
+
resolve({ socket: socketData, cleanup });
|
|
40
|
+
},
|
|
41
|
+
close: () => {
|
|
42
|
+
if (!connectionResolved) {
|
|
43
|
+
connectionResolved = true;
|
|
44
|
+
cleanup();
|
|
45
|
+
reject(new Error('Connection closed'));
|
|
46
|
+
}
|
|
47
|
+
events.onClose();
|
|
48
|
+
},
|
|
49
|
+
error: (_sock, error) => {
|
|
50
|
+
if (!connectionResolved) {
|
|
51
|
+
connectionResolved = true;
|
|
52
|
+
cleanup();
|
|
53
|
+
reject(new Error(`Connection error: ${error.message}`));
|
|
54
|
+
}
|
|
55
|
+
events.onError(error);
|
|
56
|
+
},
|
|
57
|
+
connectError: (_sock, error) => {
|
|
58
|
+
if (!connectionResolved) {
|
|
59
|
+
connectionResolved = true;
|
|
60
|
+
cleanup();
|
|
61
|
+
reject(new Error(`Failed to connect to ${host}:${port}: ${error.message}`));
|
|
62
|
+
}
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
timeoutId = setTimeout(() => {
|
|
67
|
+
if (!connectionResolved) {
|
|
68
|
+
connectionResolved = true;
|
|
69
|
+
reject(new Error(`Connection timeout to ${host}:${port}`));
|
|
70
|
+
}
|
|
71
|
+
}, connectTimeout);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Command queue for managing pending commands
|
|
76
|
+
*/
|
|
77
|
+
export class CommandQueue {
|
|
78
|
+
pendingCommands = new Map();
|
|
79
|
+
pendingQueue = [];
|
|
80
|
+
currentCommand = null;
|
|
81
|
+
commandIdCounter = 0;
|
|
82
|
+
/** Get current command being processed */
|
|
83
|
+
getCurrentCommand() {
|
|
84
|
+
return this.currentCommand;
|
|
85
|
+
}
|
|
86
|
+
/** Set current command */
|
|
87
|
+
setCurrentCommand(cmd) {
|
|
88
|
+
this.currentCommand = cmd;
|
|
89
|
+
}
|
|
90
|
+
/** Check if has pending commands */
|
|
91
|
+
hasPending() {
|
|
92
|
+
return this.pendingCommands.size > 0;
|
|
93
|
+
}
|
|
94
|
+
/** Add command to queue */
|
|
95
|
+
enqueue(command) {
|
|
96
|
+
this.pendingCommands.set(command.id, command);
|
|
97
|
+
this.pendingQueue.push(command.id);
|
|
98
|
+
}
|
|
99
|
+
/** Get next command ID */
|
|
100
|
+
nextId() {
|
|
101
|
+
return ++this.commandIdCounter;
|
|
102
|
+
}
|
|
103
|
+
/** Dequeue next command */
|
|
104
|
+
dequeue() {
|
|
105
|
+
const nextId = this.pendingQueue.shift();
|
|
106
|
+
if (nextId === undefined)
|
|
107
|
+
return null;
|
|
108
|
+
const next = this.pendingCommands.get(nextId);
|
|
109
|
+
if (!next)
|
|
110
|
+
return null;
|
|
111
|
+
this.pendingCommands.delete(nextId);
|
|
112
|
+
return next;
|
|
113
|
+
}
|
|
114
|
+
/** Remove command by ID */
|
|
115
|
+
remove(id) {
|
|
116
|
+
if (!this.pendingCommands.has(id))
|
|
117
|
+
return false;
|
|
118
|
+
this.pendingCommands.delete(id);
|
|
119
|
+
const queueIdx = this.pendingQueue.indexOf(id);
|
|
120
|
+
if (queueIdx !== -1) {
|
|
121
|
+
this.pendingQueue.splice(queueIdx, 1);
|
|
122
|
+
}
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
/** Reject all pending commands */
|
|
126
|
+
rejectAll(error) {
|
|
127
|
+
for (const cmd of this.pendingCommands.values()) {
|
|
128
|
+
clearTimeout(cmd.timeout);
|
|
129
|
+
cmd.reject(error);
|
|
130
|
+
}
|
|
131
|
+
this.pendingCommands.clear();
|
|
132
|
+
this.pendingQueue = [];
|
|
133
|
+
if (this.currentCommand) {
|
|
134
|
+
clearTimeout(this.currentCommand.timeout);
|
|
135
|
+
this.currentCommand.reject(error);
|
|
136
|
+
this.currentCommand = null;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/** Clear current command with optional rejection */
|
|
140
|
+
clearCurrent(error) {
|
|
141
|
+
if (this.currentCommand) {
|
|
142
|
+
clearTimeout(this.currentCommand.timeout);
|
|
143
|
+
if (error) {
|
|
144
|
+
this.currentCommand.reject(error);
|
|
145
|
+
}
|
|
146
|
+
this.currentCommand = null;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
//# sourceMappingURL=connection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../../src/client/tcp/connection.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAe1C;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAAY,EACZ,IAAY,EACZ,cAAsB,EACtB,MAAwB;IAExB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,M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EAAE,CAAC,CAAC;QAC/C,IAAI,QAAQ,KAAK,CAAC,CAAC,EAAE,CAAC;YACpB,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;QACxC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,kCAAkC;IAClC,SAAS,CAAC,KAAY;QACpB,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,eAAe,CAAC,MAAM,EAAE,EAAE,CAAC;YAChD,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC1B,GAAG,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;QACD,IAAI,CAAC,eAAe,CAAC,KAAK,EAAE,CAAC;QAC7B,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;QAEvB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YAClC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;IACH,CAAC;IAED,oDAAoD;IACpD,YAAY,CAAC,KAAa;QACxB,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,YAAY,CAAC,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC;YAC1C,IAAI,KAAK,EAAE,CAAC;gBACV,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;YACpC,CAAC;YACD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC;QAC7B,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TCP Health Tracker
|
|
3
|
+
* Monitors connection health with ping and latency tracking
|
|
4
|
+
*/
|
|
5
|
+
import type { ConnectionHealth } from './types';
|
|
6
|
+
/** Health tracker configuration */
|
|
7
|
+
export interface HealthConfig {
|
|
8
|
+
pingInterval: number;
|
|
9
|
+
maxPingFailures: number;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Tracks connection health metrics
|
|
13
|
+
*/
|
|
14
|
+
export declare class HealthTracker {
|
|
15
|
+
private readonly config;
|
|
16
|
+
private consecutivePingFailures;
|
|
17
|
+
private lastSuccessAt;
|
|
18
|
+
private lastErrorAt;
|
|
19
|
+
private connectedAt;
|
|
20
|
+
private totalCommands;
|
|
21
|
+
private totalErrors;
|
|
22
|
+
private readonly latencyHistory;
|
|
23
|
+
private pingTimer;
|
|
24
|
+
private static readonly MAX_LATENCY_HISTORY;
|
|
25
|
+
constructor(config: HealthConfig);
|
|
26
|
+
/** Record successful command */
|
|
27
|
+
recordSuccess(latencyMs: number): void;
|
|
28
|
+
/** Record command error */
|
|
29
|
+
recordError(): void;
|
|
30
|
+
/** Record command sent (for total count) */
|
|
31
|
+
recordCommandSent(): void;
|
|
32
|
+
/** Record connection established */
|
|
33
|
+
recordConnected(): void;
|
|
34
|
+
/** Record ping success */
|
|
35
|
+
recordPingSuccess(latencyMs: number): void;
|
|
36
|
+
/** Record ping failure, returns true if max failures reached */
|
|
37
|
+
recordPingFailure(): boolean;
|
|
38
|
+
/** Get current health metrics */
|
|
39
|
+
getHealth(state: 'connected' | 'connecting' | 'disconnected' | 'closed'): ConnectionHealth;
|
|
40
|
+
/** Start ping timer */
|
|
41
|
+
startPing(pingFn: () => Promise<void>): void;
|
|
42
|
+
/** Stop ping timer */
|
|
43
|
+
stopPing(): void;
|
|
44
|
+
/** Record latency for averaging */
|
|
45
|
+
private recordLatency;
|
|
46
|
+
}
|
|
47
|
+
//# sourceMappingURL=health.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"health.d.ts","sourceRoot":"","sources":["../../../src/client/tcp/health.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,S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