apache-iggy 0.5.0-edge.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +81 -0
- package/dist/src/bdd/auth.d.ts +20 -0
- package/dist/src/bdd/auth.js +38 -0
- package/dist/src/bdd/message.d.ts +20 -0
- package/dist/src/bdd/message.js +70 -0
- package/dist/src/bdd/stream.d.ts +20 -0
- package/dist/src/bdd/stream.js +39 -0
- package/dist/src/bdd/topic.d.ts +20 -0
- package/dist/src/bdd/topic.js +36 -0
- package/dist/src/bdd/world.d.ts +30 -0
- package/dist/src/bdd/world.js +21 -0
- package/dist/src/client/client.connection.d.ts +40 -0
- package/dist/src/client/client.connection.js +171 -0
- package/dist/src/client/client.d.ts +38 -0
- package/dist/src/client/client.debug.d.ts +21 -0
- package/dist/src/client/client.debug.js +21 -0
- package/dist/src/client/client.js +97 -0
- package/dist/src/client/client.socket.d.ts +48 -0
- package/dist/src/client/client.socket.js +156 -0
- package/dist/src/client/client.type.d.ts +69 -0
- package/dist/src/client/client.type.js +20 -0
- package/dist/src/client/client.utils.d.ts +29 -0
- package/dist/src/client/client.utils.js +54 -0
- package/dist/src/client/index.d.ts +23 -0
- package/dist/src/client/index.js +23 -0
- package/dist/src/client.e2e.d.ts +20 -0
- package/dist/src/client.e2e.js +54 -0
- package/dist/src/debug-send.d.ts +20 -0
- package/dist/src/debug-send.js +117 -0
- package/dist/src/debug.d.ts +20 -0
- package/dist/src/debug.js +107 -0
- package/dist/src/e2e/tcp.client.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.client.e2e.js +45 -0
- package/dist/src/e2e/tcp.consumer-group.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.consumer-group.e2e.js +111 -0
- package/dist/src/e2e/tcp.consumer-stream.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.consumer-stream.e2e.js +92 -0
- package/dist/src/e2e/tcp.parallel.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.parallel.e2e.js +59 -0
- package/dist/src/e2e/tcp.send-message.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.send-message.e2e.js +118 -0
- package/dist/src/e2e/tcp.stream.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.stream.e2e.js +59 -0
- package/dist/src/e2e/tcp.system.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.system.e2e.js +46 -0
- package/dist/src/e2e/tcp.token.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.token.e2e.js +43 -0
- package/dist/src/e2e/tcp.topic.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.topic.e2e.js +83 -0
- package/dist/src/e2e/tcp.user.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.user.e2e.js +95 -0
- package/dist/src/e2e/test-client.utils.d.ts +21 -0
- package/dist/src/e2e/test-client.utils.js +28 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.js +22 -0
- package/dist/src/stream/consumer-stream.d.ts +40 -0
- package/dist/src/stream/consumer-stream.js +79 -0
- package/dist/src/stream/index.d.ts +20 -0
- package/dist/src/stream/index.js +20 -0
- package/dist/src/tcp.e2e.d.ts +20 -0
- package/dist/src/tcp.e2e.js +106 -0
- package/dist/src/tcp.sm.utils.d.ts +97 -0
- package/dist/src/tcp.sm.utils.js +66 -0
- package/dist/src/tls.system.e2e.d.ts +20 -0
- package/dist/src/tls.system.e2e.js +49 -0
- package/dist/src/type.utils.d.ts +21 -0
- package/dist/src/type.utils.js +25 -0
- package/dist/src/wire/client/client.utils.d.ts +32 -0
- package/dist/src/wire/client/client.utils.js +48 -0
- package/dist/src/wire/client/get-client.command.d.ts +30 -0
- package/dist/src/wire/client/get-client.command.js +33 -0
- package/dist/src/wire/client/get-clients.command.d.ts +27 -0
- package/dist/src/wire/client/get-clients.command.js +38 -0
- package/dist/src/wire/client/get-me.command.d.ts +27 -0
- package/dist/src/wire/client/get-me.command.js +28 -0
- package/dist/src/wire/client/index.d.ts +22 -0
- package/dist/src/wire/client/index.js +22 -0
- package/dist/src/wire/command-set.d.ts +128 -0
- package/dist/src/wire/command-set.js +157 -0
- package/dist/src/wire/command.code.d.ts +68 -0
- package/dist/src/wire/command.code.js +72 -0
- package/dist/src/wire/command.utils.d.ts +26 -0
- package/dist/src/wire/command.utils.js +29 -0
- package/dist/src/wire/consumer-group/create-group.command.d.ts +34 -0
- package/dist/src/wire/consumer-group/create-group.command.js +44 -0
- package/dist/src/wire/consumer-group/create-group.command.test.d.ts +20 -0
- package/dist/src/wire/consumer-group/create-group.command.test.js +47 -0
- package/dist/src/wire/consumer-group/delete-group.command.d.ts +31 -0
- package/dist/src/wire/consumer-group/delete-group.command.js +31 -0
- package/dist/src/wire/consumer-group/get-group.command.d.ts +33 -0
- package/dist/src/wire/consumer-group/get-group.command.js +32 -0
- package/dist/src/wire/consumer-group/get-groups.command.d.ts +32 -0
- package/dist/src/wire/consumer-group/get-groups.command.js +36 -0
- package/dist/src/wire/consumer-group/group.command.test.d.ts +20 -0
- package/dist/src/wire/consumer-group/group.command.test.js +50 -0
- package/dist/src/wire/consumer-group/group.utils.d.ts +34 -0
- package/dist/src/wire/consumer-group/group.utils.js +53 -0
- package/dist/src/wire/consumer-group/index.d.ts +25 -0
- package/dist/src/wire/consumer-group/index.js +25 -0
- package/dist/src/wire/consumer-group/join-group.command.d.ts +31 -0
- package/dist/src/wire/consumer-group/join-group.command.js +31 -0
- package/dist/src/wire/consumer-group/leave-group.command.d.ts +31 -0
- package/dist/src/wire/consumer-group/leave-group.command.js +31 -0
- package/dist/src/wire/error.code.d.ts +20 -0
- package/dist/src/wire/error.code.js +202 -0
- package/dist/src/wire/error.utils.d.ts +20 -0
- package/dist/src/wire/error.utils.js +23 -0
- package/dist/src/wire/identifier.utils.d.ts +21 -0
- package/dist/src/wire/identifier.utils.js +49 -0
- package/dist/src/wire/identifier.utils.test.d.ts +20 -0
- package/dist/src/wire/identifier.utils.test.js +40 -0
- package/dist/src/wire/index.d.ts +32 -0
- package/dist/src/wire/index.js +31 -0
- package/dist/src/wire/message/flush-unsaved-buffers.command.d.ts +31 -0
- package/dist/src/wire/message/flush-unsaved-buffers.command.js +31 -0
- package/dist/src/wire/message/header.type.d.ts +101 -0
- package/dist/src/wire/message/header.type.js +55 -0
- package/dist/src/wire/message/header.utils.d.ts +67 -0
- package/dist/src/wire/message/header.utils.js +248 -0
- package/dist/src/wire/message/header.utils.test.d.ts +20 -0
- package/dist/src/wire/message/header.utils.test.js +39 -0
- package/dist/src/wire/message/iggy-header.utils.d.ts +32 -0
- package/dist/src/wire/message/iggy-header.utils.js +50 -0
- package/dist/src/wire/message/index.d.ts +25 -0
- package/dist/src/wire/message/index.js +25 -0
- package/dist/src/wire/message/message.utils.d.ts +35 -0
- package/dist/src/wire/message/message.utils.js +112 -0
- package/dist/src/wire/message/partitioning.utils.d.ts +51 -0
- package/dist/src/wire/message/partitioning.utils.js +77 -0
- package/dist/src/wire/message/poll-messages.command.d.ts +43 -0
- package/dist/src/wire/message/poll-messages.command.js +32 -0
- package/dist/src/wire/message/poll.utils.d.ts +93 -0
- package/dist/src/wire/message/poll.utils.js +135 -0
- package/dist/src/wire/message/send-messages.command.d.ts +34 -0
- package/dist/src/wire/message/send-messages.command.js +31 -0
- package/dist/src/wire/message/send-messages.command.test.d.ts +20 -0
- package/dist/src/wire/message/send-messages.command.test.js +88 -0
- package/dist/src/wire/number.utils.d.ts +32 -0
- package/dist/src/wire/number.utils.js +85 -0
- package/dist/src/wire/offset/delete-offset.command.d.ts +28 -0
- package/dist/src/wire/offset/delete-offset.command.js +31 -0
- package/dist/src/wire/offset/get-offset.command.d.ts +34 -0
- package/dist/src/wire/offset/get-offset.command.js +41 -0
- package/dist/src/wire/offset/index.d.ts +22 -0
- package/dist/src/wire/offset/index.js +22 -0
- package/dist/src/wire/offset/offset.utils.d.ts +54 -0
- package/dist/src/wire/offset/offset.utils.js +60 -0
- package/dist/src/wire/offset/store-offset.command.d.ts +34 -0
- package/dist/src/wire/offset/store-offset.command.js +29 -0
- package/dist/src/wire/partition/create-partition.command.d.ts +31 -0
- package/dist/src/wire/partition/create-partition.command.js +31 -0
- package/dist/src/wire/partition/delete-partition.command.d.ts +31 -0
- package/dist/src/wire/partition/delete-partition.command.js +31 -0
- package/dist/src/wire/partition/index.d.ts +21 -0
- package/dist/src/wire/partition/index.js +21 -0
- package/dist/src/wire/partition/partition.utils.d.ts +21 -0
- package/dist/src/wire/partition/partition.utils.js +33 -0
- package/dist/src/wire/partition/partition.utils.test.d.ts +20 -0
- package/dist/src/wire/partition/partition.utils.test.js +33 -0
- package/dist/src/wire/segment/delete-segments.command.d.ts +32 -0
- package/dist/src/wire/segment/delete-segments.command.js +31 -0
- package/dist/src/wire/segment/index.d.ts +20 -0
- package/dist/src/wire/segment/index.js +20 -0
- package/dist/src/wire/segment/segment.utils.d.ts +21 -0
- package/dist/src/wire/segment/segment.utils.js +35 -0
- package/dist/src/wire/serialize.utils.d.ts +22 -0
- package/dist/src/wire/serialize.utils.js +27 -0
- package/dist/src/wire/session/index.d.ts +23 -0
- package/dist/src/wire/session/index.js +22 -0
- package/dist/src/wire/session/login-with-token.command.d.ts +32 -0
- package/dist/src/wire/session/login-with-token.command.js +30 -0
- package/dist/src/wire/session/login-with-token.command.test.d.ts +20 -0
- package/dist/src/wire/session/login-with-token.command.test.js +38 -0
- package/dist/src/wire/session/login.command.d.ts +29 -0
- package/dist/src/wire/session/login.command.js +30 -0
- package/dist/src/wire/session/login.command.test.d.ts +20 -0
- package/dist/src/wire/session/login.command.test.js +52 -0
- package/dist/src/wire/session/login.utils.d.ts +30 -0
- package/dist/src/wire/session/login.utils.js +54 -0
- package/dist/src/wire/session/logout.command.d.ts +25 -0
- package/dist/src/wire/session/logout.command.js +30 -0
- package/dist/src/wire/stream/create-stream.command.d.ts +31 -0
- package/dist/src/wire/stream/create-stream.command.js +41 -0
- package/dist/src/wire/stream/create-stream.command.test.d.ts +20 -0
- package/dist/src/wire/stream/create-stream.command.test.js +45 -0
- package/dist/src/wire/stream/delete-stream.command.d.ts +29 -0
- package/dist/src/wire/stream/delete-stream.command.js +31 -0
- package/dist/src/wire/stream/get-stream.command.d.ts +31 -0
- package/dist/src/wire/stream/get-stream.command.js +33 -0
- package/dist/src/wire/stream/get-streams.command.d.ts +27 -0
- package/dist/src/wire/stream/get-streams.command.js +38 -0
- package/dist/src/wire/stream/index.d.ts +25 -0
- package/dist/src/wire/stream/index.js +25 -0
- package/dist/src/wire/stream/purge-stream.command.d.ts +29 -0
- package/dist/src/wire/stream/purge-stream.command.js +31 -0
- package/dist/src/wire/stream/stream.utils.d.ts +33 -0
- package/dist/src/wire/stream/stream.utils.js +35 -0
- package/dist/src/wire/stream/update-stream.command.d.ts +30 -0
- package/dist/src/wire/stream/update-stream.command.js +40 -0
- package/dist/src/wire/system/get-stats.command.d.ts +50 -0
- package/dist/src/wire/system/get-stats.command.js +83 -0
- package/dist/src/wire/system/index.d.ts +21 -0
- package/dist/src/wire/system/index.js +21 -0
- package/dist/src/wire/system/ping.command.d.ts +25 -0
- package/dist/src/wire/system/ping.command.js +30 -0
- package/dist/src/wire/token/create-token.command.d.ts +31 -0
- package/dist/src/wire/token/create-token.command.js +37 -0
- package/dist/src/wire/token/create-token.command.test.d.ts +20 -0
- package/dist/src/wire/token/create-token.command.test.js +45 -0
- package/dist/src/wire/token/delete-token.command.d.ts +28 -0
- package/dist/src/wire/token/delete-token.command.js +38 -0
- package/dist/src/wire/token/delete-token.command.test.d.ts +20 -0
- package/dist/src/wire/token/delete-token.command.test.js +42 -0
- package/dist/src/wire/token/get-tokens.command.d.ts +27 -0
- package/dist/src/wire/token/get-tokens.command.js +28 -0
- package/dist/src/wire/token/index.d.ts +22 -0
- package/dist/src/wire/token/index.js +22 -0
- package/dist/src/wire/token/token.utils.d.ts +38 -0
- package/dist/src/wire/token/token.utils.js +53 -0
- package/dist/src/wire/topic/create-topic.command.d.ts +38 -0
- package/dist/src/wire/topic/create-topic.command.js +53 -0
- package/dist/src/wire/topic/create-topic.command.test.d.ts +20 -0
- package/dist/src/wire/topic/create-topic.command.test.js +67 -0
- package/dist/src/wire/topic/delete-topic.command.d.ts +32 -0
- package/dist/src/wire/topic/delete-topic.command.js +36 -0
- package/dist/src/wire/topic/get-topic.command.d.ts +33 -0
- package/dist/src/wire/topic/get-topic.command.js +36 -0
- package/dist/src/wire/topic/get-topics.command.d.ts +31 -0
- package/dist/src/wire/topic/get-topics.command.js +33 -0
- package/dist/src/wire/topic/index.d.ts +25 -0
- package/dist/src/wire/topic/index.js +25 -0
- package/dist/src/wire/topic/purge-topic.command.d.ts +30 -0
- package/dist/src/wire/topic/purge-topic.command.js +34 -0
- package/dist/src/wire/topic/topic.utils.d.ts +71 -0
- package/dist/src/wire/topic/topic.utils.js +91 -0
- package/dist/src/wire/topic/update-topic.command.d.ts +36 -0
- package/dist/src/wire/topic/update-topic.command.js +50 -0
- package/dist/src/wire/user/change-password.command.d.ts +30 -0
- package/dist/src/wire/user/change-password.command.js +45 -0
- package/dist/src/wire/user/create-user.command.d.ts +34 -0
- package/dist/src/wire/user/create-user.command.js +48 -0
- package/dist/src/wire/user/create-user.command.test.d.ts +20 -0
- package/dist/src/wire/user/create-user.command.test.js +60 -0
- package/dist/src/wire/user/delete-user.command.d.ts +29 -0
- package/dist/src/wire/user/delete-user.command.js +31 -0
- package/dist/src/wire/user/get-user.command.d.ts +31 -0
- package/dist/src/wire/user/get-user.command.js +31 -0
- package/dist/src/wire/user/get-users.command.d.ts +27 -0
- package/dist/src/wire/user/get-users.command.js +28 -0
- package/dist/src/wire/user/index.d.ts +26 -0
- package/dist/src/wire/user/index.js +26 -0
- package/dist/src/wire/user/permissions.utils.d.ts +77 -0
- package/dist/src/wire/user/permissions.utils.js +161 -0
- package/dist/src/wire/user/permissions.utils.test.d.ts +20 -0
- package/dist/src/wire/user/permissions.utils.test.js +44 -0
- package/dist/src/wire/user/update-permissions.command.d.ts +31 -0
- package/dist/src/wire/user/update-permissions.command.js +39 -0
- package/dist/src/wire/user/update-user.command.d.ts +32 -0
- package/dist/src/wire/user/update-user.command.js +54 -0
- package/dist/src/wire/user/user.utils.d.ts +41 -0
- package/dist/src/wire/user/user.utils.js +74 -0
- package/dist/src/wire/uuid.utils.d.ts +22 -0
- package/dist/src/wire/uuid.utils.js +23 -0
- package/package.json +70 -0
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { EventEmitter } from 'node:events';
|
|
20
|
+
import { createConnection } from 'node:net';
|
|
21
|
+
import { connect as TLSConnect } from 'node:tls';
|
|
22
|
+
import { serializeCommand } from './client.utils.js';
|
|
23
|
+
import { debug } from './client.debug.js';
|
|
24
|
+
const createTcpSocket = (options) => {
|
|
25
|
+
return createConnection(options);
|
|
26
|
+
};
|
|
27
|
+
const createTlsSocket = ({ port, ...options }) => {
|
|
28
|
+
const socket = TLSConnect(port, options);
|
|
29
|
+
return socket;
|
|
30
|
+
};
|
|
31
|
+
const getTransport = (config) => {
|
|
32
|
+
const { transport, options } = config;
|
|
33
|
+
switch (transport) {
|
|
34
|
+
case 'TLS': return createTlsSocket(options);
|
|
35
|
+
case 'TCP':
|
|
36
|
+
default:
|
|
37
|
+
return createTcpSocket(options);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
const DefaultReconnectOption = {
|
|
41
|
+
enabled: true,
|
|
42
|
+
interval: 5 * 1000,
|
|
43
|
+
maxRetries: 12
|
|
44
|
+
};
|
|
45
|
+
function recreate(option, timer = 1000) {
|
|
46
|
+
return new Promise((resolve) => {
|
|
47
|
+
setTimeout(() => {
|
|
48
|
+
resolve(getTransport(option));
|
|
49
|
+
}, timer);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
export class IggyConnection extends EventEmitter {
|
|
53
|
+
config;
|
|
54
|
+
socket;
|
|
55
|
+
connected;
|
|
56
|
+
connecting;
|
|
57
|
+
ending;
|
|
58
|
+
waitingResponseEnd;
|
|
59
|
+
reconnectOption;
|
|
60
|
+
reconnectCount;
|
|
61
|
+
readBuffers;
|
|
62
|
+
constructor(config) {
|
|
63
|
+
super();
|
|
64
|
+
this.config = config;
|
|
65
|
+
this.socket = getTransport(config);
|
|
66
|
+
this.connected = false;
|
|
67
|
+
this.connecting = false;
|
|
68
|
+
this.ending = false;
|
|
69
|
+
this.waitingResponseEnd = false;
|
|
70
|
+
this.reconnectOption = { ...DefaultReconnectOption, ...config.reconnect };
|
|
71
|
+
this.reconnectCount = 0;
|
|
72
|
+
this.readBuffers = Buffer.allocUnsafe(0);
|
|
73
|
+
}
|
|
74
|
+
connect() {
|
|
75
|
+
this.connecting = true;
|
|
76
|
+
this.socket.on('data', this._onData.bind(this));
|
|
77
|
+
this.socket.on('error', async (err) => {
|
|
78
|
+
debug('socket/error event', err, err.code, this.ending);
|
|
79
|
+
// errors about disconnections should be ignored during disconnect
|
|
80
|
+
if (this.ending && (err?.code === 'ECONNRESET' || err?.code === 'EPIPE'))
|
|
81
|
+
return;
|
|
82
|
+
this.reconnect(err);
|
|
83
|
+
});
|
|
84
|
+
this.socket.once('end', async (hadError) => {
|
|
85
|
+
debug('socket/close#END event', hadError);
|
|
86
|
+
this.connected = false;
|
|
87
|
+
this.emit('disconnected', hadError);
|
|
88
|
+
this.reconnect();
|
|
89
|
+
});
|
|
90
|
+
return new Promise((resolve /**, reject*/) => {
|
|
91
|
+
this.socket.once('connect', () => {
|
|
92
|
+
debug('socket/connect event');
|
|
93
|
+
this.connected = true;
|
|
94
|
+
this.connecting = false;
|
|
95
|
+
this.reconnectCount = 0;
|
|
96
|
+
this.emit('connect');
|
|
97
|
+
resolve(this);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async reconnect(err) {
|
|
102
|
+
const { enabled, interval, maxRetries } = this.reconnectOption;
|
|
103
|
+
debug('reconnect# event/reconnect?', {
|
|
104
|
+
reconnect: { enabled, interval, maxRetries },
|
|
105
|
+
count: this.reconnectCount,
|
|
106
|
+
lastError: err
|
|
107
|
+
});
|
|
108
|
+
if (!enabled || this.reconnectCount > maxRetries) {
|
|
109
|
+
debug(`reconnect reached maxRetries of ${maxRetries}`, err);
|
|
110
|
+
return this.emit('error', new Error(`reconnect maxRetries exceeded (count: ${this.reconnectCount})`, { cause: err }));
|
|
111
|
+
}
|
|
112
|
+
/** recreate socket */
|
|
113
|
+
this.connecting = true;
|
|
114
|
+
this.reconnectCount += 1;
|
|
115
|
+
this.socket = await recreate(this.config, interval);
|
|
116
|
+
this.connect();
|
|
117
|
+
}
|
|
118
|
+
_destroy() {
|
|
119
|
+
this.ending = true;
|
|
120
|
+
this.socket.destroy();
|
|
121
|
+
}
|
|
122
|
+
_endResponseWait() {
|
|
123
|
+
this.readBuffers = Buffer.allocUnsafe(0);
|
|
124
|
+
this.waitingResponseEnd = false;
|
|
125
|
+
}
|
|
126
|
+
_onData(data) {
|
|
127
|
+
debug('ONDATA', typeof data, Buffer.isBuffer(data), data?.length, this.waitingResponseEnd);
|
|
128
|
+
if (this.waitingResponseEnd) {
|
|
129
|
+
data = Buffer.concat([this.readBuffers, data]);
|
|
130
|
+
}
|
|
131
|
+
if (data.length < 8) {
|
|
132
|
+
this.socket.unshift(data);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* data[0:4] hold response status code
|
|
137
|
+
* const status = data.readUInt32LE(0);
|
|
138
|
+
* data[4:8] hold response length
|
|
139
|
+
*/
|
|
140
|
+
const responseSize = data.readUInt32LE(4);
|
|
141
|
+
/** response is just head, no payload */
|
|
142
|
+
if (responseSize === 0 && data.length === 8) {
|
|
143
|
+
this.emit('response', data);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const payloadLength = data.length - 8;
|
|
147
|
+
/** payload is complete */
|
|
148
|
+
if (payloadLength === responseSize) {
|
|
149
|
+
this.emit('response', data);
|
|
150
|
+
this._endResponseWait();
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
/** payload is incomplete, buffering until next data event */
|
|
154
|
+
if (payloadLength < responseSize) {
|
|
155
|
+
this.waitingResponseEnd = true;
|
|
156
|
+
this.readBuffers = data;
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
/** payload is bigger than expected, cut response and unshift extra data */
|
|
160
|
+
if (payloadLength > responseSize) {
|
|
161
|
+
this.emit('response', data.subarray(0, 8 + responseSize));
|
|
162
|
+
this._endResponseWait();
|
|
163
|
+
this.socket.unshift(data.subarray(8 + responseSize));
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
writeCommand(command, payload) {
|
|
167
|
+
const cmd = serializeCommand(command, payload);
|
|
168
|
+
return this.socket.write(cmd);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=client.connection.js.map
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { type Pool } from 'generic-pool';
|
|
20
|
+
import type { RawClient, ClientConfig } from "./client.type.js";
|
|
21
|
+
import { CommandAPI } from '../wire/command-set.js';
|
|
22
|
+
export declare class Client extends CommandAPI {
|
|
23
|
+
_config: ClientConfig;
|
|
24
|
+
_pool: Pool<RawClient>;
|
|
25
|
+
constructor(config: ClientConfig);
|
|
26
|
+
destroy(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export declare class SingleClient extends CommandAPI {
|
|
29
|
+
_config: ClientConfig;
|
|
30
|
+
constructor(config: ClientConfig);
|
|
31
|
+
destroy(): Promise<void>;
|
|
32
|
+
}
|
|
33
|
+
export declare class SimpleClient extends CommandAPI {
|
|
34
|
+
constructor(client: RawClient);
|
|
35
|
+
destroy(): Promise<void>;
|
|
36
|
+
}
|
|
37
|
+
export declare const getClient: (config: ClientConfig) => Promise<SimpleClient>;
|
|
38
|
+
//# sourceMappingURL=client.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import Debug from 'debug';
|
|
20
|
+
export declare const debug: Debug.Debugger;
|
|
21
|
+
//# sourceMappingURL=client.debug.d.ts.map
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import Debug from 'debug';
|
|
20
|
+
export const debug = Debug('iggy:client');
|
|
21
|
+
//# sourceMappingURL=client.debug.js.map
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { createPool } from 'generic-pool';
|
|
20
|
+
import { getRawClient } from '../client/client.socket.js';
|
|
21
|
+
import { CommandAPI } from '../wire/command-set.js';
|
|
22
|
+
import { debug } from './client.debug.js';
|
|
23
|
+
// create & destroy must be async
|
|
24
|
+
const createPoolFactory = (config) => ({
|
|
25
|
+
create: async function () {
|
|
26
|
+
return getRawClient(config);
|
|
27
|
+
},
|
|
28
|
+
destroy: async function (client) {
|
|
29
|
+
return client.destroy();
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const poolClientProvider = (config) => {
|
|
33
|
+
const min = config.poolSize?.min || 1;
|
|
34
|
+
const max = config.poolSize?.max || 4;
|
|
35
|
+
const pool = createPool(createPoolFactory(config), { min, max });
|
|
36
|
+
const poolClientProvider = async () => {
|
|
37
|
+
const c = await pool.acquire();
|
|
38
|
+
debug('client acquired from pool. pool size is', pool.size);
|
|
39
|
+
c.once('finishQueue', () => {
|
|
40
|
+
pool.release(c);
|
|
41
|
+
debug('client released to pool. pool size is', pool.size);
|
|
42
|
+
});
|
|
43
|
+
return c;
|
|
44
|
+
};
|
|
45
|
+
poolClientProvider._pool = pool;
|
|
46
|
+
return poolClientProvider;
|
|
47
|
+
};
|
|
48
|
+
export class Client extends CommandAPI {
|
|
49
|
+
_config;
|
|
50
|
+
_pool;
|
|
51
|
+
constructor(config) {
|
|
52
|
+
const pcp = poolClientProvider(config);
|
|
53
|
+
super(pcp);
|
|
54
|
+
this._config = config;
|
|
55
|
+
this._pool = pcp._pool;
|
|
56
|
+
}
|
|
57
|
+
;
|
|
58
|
+
async destroy() {
|
|
59
|
+
debug('destroying client pool. pool size is', this._pool.size);
|
|
60
|
+
await this._pool.drain();
|
|
61
|
+
await this._pool.clear();
|
|
62
|
+
debug('destroyed client pool. pool size is', this._pool.size);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
const singleClientProvider = (config) => {
|
|
66
|
+
const c = getRawClient(config);
|
|
67
|
+
return async function singleClientProvider() {
|
|
68
|
+
return c;
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
export class SingleClient extends CommandAPI {
|
|
72
|
+
_config;
|
|
73
|
+
constructor(config) {
|
|
74
|
+
super(singleClientProvider(config));
|
|
75
|
+
this._config = config;
|
|
76
|
+
}
|
|
77
|
+
async destroy() {
|
|
78
|
+
const s = await this.clientProvider();
|
|
79
|
+
s.destroy();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
;
|
|
83
|
+
export class SimpleClient extends CommandAPI {
|
|
84
|
+
constructor(client) {
|
|
85
|
+
super(() => Promise.resolve(client));
|
|
86
|
+
}
|
|
87
|
+
async destroy() {
|
|
88
|
+
const s = await this.clientProvider();
|
|
89
|
+
s.destroy();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
;
|
|
93
|
+
export const getClient = async (config) => {
|
|
94
|
+
const cli = getRawClient(config);
|
|
95
|
+
return new SimpleClient(cli);
|
|
96
|
+
};
|
|
97
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { EventEmitter } from 'node:events';
|
|
20
|
+
import type { ClientConfig, ClientCredentials, CommandResponse, PasswordCredentials, RawClient, TokenCredentials } from '../client/client.type.js';
|
|
21
|
+
export declare class CommandResponseStream extends EventEmitter {
|
|
22
|
+
private options;
|
|
23
|
+
private connection;
|
|
24
|
+
private _execQueue;
|
|
25
|
+
busy: boolean;
|
|
26
|
+
isAuthenticated: boolean;
|
|
27
|
+
userId?: number;
|
|
28
|
+
heartbeatIntervalHandler?: NodeJS.Timeout;
|
|
29
|
+
constructor(options: ClientConfig);
|
|
30
|
+
_init(): void;
|
|
31
|
+
sendCommand(command: number, payload: Buffer, handleResponse?: boolean, last?: boolean): Promise<CommandResponse>;
|
|
32
|
+
_processQueue(handleResponse?: boolean): Promise<void>;
|
|
33
|
+
_processNext(command: number, payload: Buffer, handleResp?: boolean): Promise<CommandResponse>;
|
|
34
|
+
_failQueue(err: Error): void;
|
|
35
|
+
authenticate(creds: ClientCredentials): Promise<boolean>;
|
|
36
|
+
_authWithPassword(creds: PasswordCredentials): Promise<{
|
|
37
|
+
userId: number;
|
|
38
|
+
}>;
|
|
39
|
+
_authWithToken(creds: TokenCredentials): Promise<{
|
|
40
|
+
userId: number;
|
|
41
|
+
}>;
|
|
42
|
+
ping(): Promise<boolean>;
|
|
43
|
+
heartbeat(interval?: number): void;
|
|
44
|
+
getReadStream(): import("net").Socket;
|
|
45
|
+
destroy(): void;
|
|
46
|
+
}
|
|
47
|
+
export declare function getRawClient(options: ClientConfig): RawClient;
|
|
48
|
+
//# sourceMappingURL=client.socket.d.ts.map
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { EventEmitter } from 'node:events';
|
|
20
|
+
import { handleResponse } from './client.utils.js';
|
|
21
|
+
import { responseError } from '../wire/error.utils.js';
|
|
22
|
+
import { debug } from './client.debug.js';
|
|
23
|
+
import { IggyConnection } from './client.connection.js';
|
|
24
|
+
import { LOGIN, LOGIN_WITH_TOKEN, PING } from '../wire/index.js';
|
|
25
|
+
const UNLOGGED_COMMAND_CODE = [
|
|
26
|
+
PING.code,
|
|
27
|
+
LOGIN.code,
|
|
28
|
+
LOGIN_WITH_TOKEN.code
|
|
29
|
+
];
|
|
30
|
+
export class CommandResponseStream extends EventEmitter {
|
|
31
|
+
options;
|
|
32
|
+
connection;
|
|
33
|
+
_execQueue;
|
|
34
|
+
busy;
|
|
35
|
+
isAuthenticated;
|
|
36
|
+
userId;
|
|
37
|
+
heartbeatIntervalHandler;
|
|
38
|
+
constructor(options) {
|
|
39
|
+
super();
|
|
40
|
+
this.options = options;
|
|
41
|
+
this.connection = new IggyConnection(options);
|
|
42
|
+
this.busy = false;
|
|
43
|
+
this.isAuthenticated = false;
|
|
44
|
+
this._execQueue = [];
|
|
45
|
+
this._init();
|
|
46
|
+
}
|
|
47
|
+
;
|
|
48
|
+
_init() {
|
|
49
|
+
this.heartbeat(this.options.heartbeatInterval);
|
|
50
|
+
this.connection.on('disconnected', async () => {
|
|
51
|
+
this.isAuthenticated = false;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
async sendCommand(command, payload, handleResponse = true, last = true) {
|
|
55
|
+
if (!this.connection.connected)
|
|
56
|
+
await this.connection.connect();
|
|
57
|
+
if (!this.isAuthenticated && !UNLOGGED_COMMAND_CODE.includes(command))
|
|
58
|
+
await this.authenticate(this.options.credentials);
|
|
59
|
+
return new Promise(async (resolve, reject) => {
|
|
60
|
+
if (last)
|
|
61
|
+
this._execQueue.push({ command, payload, resolve, reject });
|
|
62
|
+
else
|
|
63
|
+
this._execQueue.unshift({ command, payload, resolve, reject });
|
|
64
|
+
this._processQueue(handleResponse);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async _processQueue(handleResponse = true) {
|
|
68
|
+
if (this.busy)
|
|
69
|
+
return;
|
|
70
|
+
this.busy = true;
|
|
71
|
+
while (this._execQueue.length > 0 && this.connection.socket.writable) {
|
|
72
|
+
const next = this._execQueue.shift();
|
|
73
|
+
if (!next)
|
|
74
|
+
break;
|
|
75
|
+
const { command, payload, resolve, reject } = next;
|
|
76
|
+
try {
|
|
77
|
+
resolve(await this._processNext(command, payload, handleResponse));
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
reject(err);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
this.busy = false;
|
|
84
|
+
this.emit('finishQueue');
|
|
85
|
+
}
|
|
86
|
+
_processNext(command, payload, handleResp = true) {
|
|
87
|
+
const lastWrite = this.connection.writeCommand(command, payload);
|
|
88
|
+
debug('==> writeCommand', lastWrite);
|
|
89
|
+
return new Promise((resolve, reject) => {
|
|
90
|
+
if (!lastWrite)
|
|
91
|
+
return reject(new Error('failed to write to socket'));
|
|
92
|
+
const errCb = (err) => reject(err);
|
|
93
|
+
this.connection.once('error', errCb);
|
|
94
|
+
this.connection.once('response', (resp) => {
|
|
95
|
+
this.connection.removeListener('error', errCb);
|
|
96
|
+
if (!handleResp)
|
|
97
|
+
return resolve(resp);
|
|
98
|
+
const r = handleResponse(resp);
|
|
99
|
+
if (r.status !== 0) {
|
|
100
|
+
return reject(responseError(command, r.status));
|
|
101
|
+
}
|
|
102
|
+
return resolve(r);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
_failQueue(err) {
|
|
107
|
+
this._execQueue.forEach(({ reject }) => reject(err));
|
|
108
|
+
this._execQueue = [];
|
|
109
|
+
}
|
|
110
|
+
async authenticate(creds) {
|
|
111
|
+
const r = ('token' in creds) ?
|
|
112
|
+
await this._authWithToken(creds) :
|
|
113
|
+
await this._authWithPassword(creds);
|
|
114
|
+
this.isAuthenticated = true;
|
|
115
|
+
this.userId = r.userId;
|
|
116
|
+
return this.isAuthenticated;
|
|
117
|
+
}
|
|
118
|
+
async _authWithPassword(creds) {
|
|
119
|
+
const pl = LOGIN.serialize(creds);
|
|
120
|
+
const logr = await this.sendCommand(LOGIN.code, pl, true, false);
|
|
121
|
+
return LOGIN.deserialize(logr);
|
|
122
|
+
}
|
|
123
|
+
async _authWithToken(creds) {
|
|
124
|
+
const pl = LOGIN_WITH_TOKEN.serialize(creds);
|
|
125
|
+
const logr = await this.sendCommand(LOGIN_WITH_TOKEN.code, pl, true, false);
|
|
126
|
+
return LOGIN_WITH_TOKEN.deserialize(logr);
|
|
127
|
+
}
|
|
128
|
+
async ping() {
|
|
129
|
+
const pl = PING.serialize();
|
|
130
|
+
const pingR = await this.sendCommand(PING.code, pl, true);
|
|
131
|
+
return PING.deserialize(pingR);
|
|
132
|
+
}
|
|
133
|
+
heartbeat(interval) {
|
|
134
|
+
if (!interval)
|
|
135
|
+
return;
|
|
136
|
+
this.heartbeatIntervalHandler = setInterval(async () => {
|
|
137
|
+
if (this.connection.connected) {
|
|
138
|
+
debug(`sending hearbeat ping (interval: ${interval} ms)`);
|
|
139
|
+
await this.ping();
|
|
140
|
+
}
|
|
141
|
+
}, interval);
|
|
142
|
+
}
|
|
143
|
+
getReadStream() {
|
|
144
|
+
return this.connection.socket;
|
|
145
|
+
}
|
|
146
|
+
destroy() {
|
|
147
|
+
if (this.heartbeatIntervalHandler)
|
|
148
|
+
clearInterval(this.heartbeatIntervalHandler);
|
|
149
|
+
return this.connection._destroy();
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
;
|
|
153
|
+
export function getRawClient(options) {
|
|
154
|
+
return new CommandResponseStream(options);
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=client.socket.js.map
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import type { Readable } from 'stream';
|
|
20
|
+
import { type TcpSocketConnectOpts } from 'node:net';
|
|
21
|
+
import { type ConnectionOptions } from 'node:tls';
|
|
22
|
+
export type TcpOption = TcpSocketConnectOpts;
|
|
23
|
+
export type TlsOption = {
|
|
24
|
+
port: number;
|
|
25
|
+
} & ConnectionOptions;
|
|
26
|
+
export type CommandResponse = {
|
|
27
|
+
status: number;
|
|
28
|
+
length: number;
|
|
29
|
+
data: Buffer;
|
|
30
|
+
};
|
|
31
|
+
export type RawClient = {
|
|
32
|
+
sendCommand: (code: number, payload: Buffer, handleResponse?: boolean) => Promise<CommandResponse>;
|
|
33
|
+
isAuthenticated: boolean;
|
|
34
|
+
authenticate: (c: ClientCredentials) => Promise<boolean>;
|
|
35
|
+
destroy: () => void;
|
|
36
|
+
on: (ev: string, cb: (e?: unknown) => void) => void;
|
|
37
|
+
once: (ev: string, cb: (e?: unknown) => void) => void;
|
|
38
|
+
getReadStream: () => Readable;
|
|
39
|
+
};
|
|
40
|
+
export type ClientProvider = () => Promise<RawClient>;
|
|
41
|
+
export declare const Transports: readonly ["TCP", "TLS"];
|
|
42
|
+
export type TransportType = typeof Transports[number];
|
|
43
|
+
export type ReconnectOption = {
|
|
44
|
+
enabled: boolean;
|
|
45
|
+
interval: number;
|
|
46
|
+
maxRetries: number;
|
|
47
|
+
};
|
|
48
|
+
export type TransportOption = TcpOption | TlsOption;
|
|
49
|
+
export type TokenCredentials = {
|
|
50
|
+
token: string;
|
|
51
|
+
};
|
|
52
|
+
export type PasswordCredentials = {
|
|
53
|
+
username: string;
|
|
54
|
+
password: string;
|
|
55
|
+
};
|
|
56
|
+
export type ClientCredentials = TokenCredentials | PasswordCredentials;
|
|
57
|
+
export type PoolSizeOption = {
|
|
58
|
+
min?: number;
|
|
59
|
+
max?: number;
|
|
60
|
+
};
|
|
61
|
+
export type ClientConfig = {
|
|
62
|
+
transport: TransportType;
|
|
63
|
+
options: TransportOption;
|
|
64
|
+
credentials: ClientCredentials;
|
|
65
|
+
poolSize?: PoolSizeOption;
|
|
66
|
+
reconnect?: ReconnectOption;
|
|
67
|
+
heartbeatInterval?: number;
|
|
68
|
+
};
|
|
69
|
+
//# sourceMappingURL=client.type.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
export const Transports = ['TCP', 'TLS' /**, 'QUIC' */];
|
|
20
|
+
//# sourceMappingURL=client.type.js.map
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { Transform } from 'node:stream';
|
|
20
|
+
import type { CommandResponse } from './client.type.js';
|
|
21
|
+
export declare const handleResponse: (r: Buffer) => {
|
|
22
|
+
status: number;
|
|
23
|
+
length: number;
|
|
24
|
+
data: Buffer<ArrayBufferLike>;
|
|
25
|
+
};
|
|
26
|
+
export declare const handleResponseTransform: () => Transform;
|
|
27
|
+
export declare const deserializeVoidResponse: (r: CommandResponse) => boolean;
|
|
28
|
+
export declare const serializeCommand: (command: number, payload: Buffer) => Buffer<ArrayBuffer>;
|
|
29
|
+
//# sourceMappingURL=client.utils.d.ts.map
|