@@ -12,56 +12,16 @@ import { isBoolean } from "../utils";
12
12
13
13
const DEFAULT_TCP_AUTO_FLUSH_ROWS = 600 ;
14
14
15
- // an arbitrary public key, not used in authentication
16
- // only used to construct a valid JWK token which is accepted by the crypto API
15
+ // Arbitrary public key, used to construct valid JWK tokens.
16
+ // These are not used for actual authentication, only required for crypto API compatibility.
17
17
const PUBLIC_KEY = {
18
18
x : "aultdA0PjhD_cWViqKKyL5chm6H1n-BiZBo_48T-uqc" ,
19
19
y : "__ptaol41JWSpTTL525yVEfzmY8A6Vi_QrW1FjKcHMg" ,
20
20
} ;
21
21
22
- /** @classdesc
23
- * The QuestDB client's API provides methods to connect to the database, ingest data, and close the connection.
24
- * The supported protocols are HTTP and TCP. HTTP is preferred as it provides feedback in the HTTP response. <br>
25
- * Based on benchmarks HTTP also provides higher throughput, if configured to ingest data in bigger batches.
26
- * <p>
27
- * The client supports authentication. <br>
28
- * Authentication details can be passed to the Sender in its configuration options. <br>
29
- * The client supports Basic username/password and Bearer token authentication methods when used with HTTP protocol,
30
- * and JWK token authentication when ingesting data via TCP. <br>
31
- * Please, note that authentication is enabled by default in QuestDB Enterprise only. <br>
32
- * Details on how to configure authentication in the open source version of
33
- * QuestDB: {@link https://questdb.io/docs/reference/api/ilp/authenticate}
34
- * </p>
35
- * <p>
36
- * The client also supports TLS encryption for both, HTTP and TCP transports to provide a secure connection. <br>
37
- * Please, note that the open source version of QuestDB does not support TLS, and requires an external reverse-proxy,
38
- * such as Nginx to enable encryption.
39
- * </p>
40
- * <p>
41
- * The client uses a buffer to store data. It automatically flushes the buffer by sending its content to the server.
42
- * Auto flushing can be disabled via configuration options to gain control over transactions. Initial and maximum
43
- * buffer sizes can also be set.
44
- * </p>
45
- * <p>
46
- * It is recommended that the Sender is created by using one of the static factory methods,
47
- * <i>Sender.fromConfig(configString, extraOptions)</i> or <i>Sender.fromEnv(extraOptions)</i>.
48
- * If the Sender is created via its constructor, at least the SenderOptions configuration object should be
49
- * initialized from a configuration string to make sure that the parameters are validated. <br>
50
- * Detailed description of the Sender's configuration options can be found in
51
- * the <a href="SenderOptions.html">SenderOptions</a> documentation.
52
- * </p>
53
- * <p>
54
- * Extra options can be provided to the Sender in the <i>extraOptions</i> configuration object. <br>
55
- * A custom logging function and a custom HTTP(S) agent can be passed to the Sender in this object. <br>
56
- * The logger implementation provides the option to direct log messages to the same place where the host application's
57
- * log is saved. The default logger writes to the console. <br>
58
- * The custom HTTP(S) agent option becomes handy if there is a need to modify the default options set for the
59
- * HTTP(S) connections. A popular setting would be disabling persistent connections, in this case an agent can be
60
- * passed to the Sender with <i>keepAlive</i> set to <i>false</i>. <br>
61
- * For example: <i>Sender.fromConfig(`http::addr=host:port`, { agent: new undici.Agent({ connect: { keepAlive: false } }) })</i> <br>
62
- * If no custom agent is configured, the Sender will use its own agent which overrides some default values
63
- * of <i>undici.Agent</i>. The Sender's own agent uses persistent connections with 1 minute idle timeout, pipelines requests default to 1.
64
- * </p>
22
+ /**
23
+ * TCP transport implementation. <br>
24
+ * Supports both plain TCP or secure TLS-encrypted connections with configurable JWK token authentication.
65
25
*/
66
26
class TcpTransport implements SenderTransport {
67
27
private readonly secure : boolean ;
@@ -77,10 +37,10 @@ class TcpTransport implements SenderTransport {
77
37
private readonly jwk : Record < string , string > ;
78
38
79
39
/**
80
- * Creates an instance of Sender .
40
+ * Creates a new TcpTransport instance .
81
41
*
82
- * @param { SenderOptions } options - Sender configuration object. <br>
83
- * See SenderOptions documentation for detailed description of configuration options. <br>
42
+ * @param options - Sender configuration object containing connection and authentication details
43
+ * @throws Error if required options are missing or protocol is not 'tcp' or 'tcps'
84
44
*/
85
45
constructor ( options : SenderOptions ) {
86
46
if ( ! options || ! options . protocol ) {
@@ -121,8 +81,8 @@ class TcpTransport implements SenderTransport {
121
81
122
82
/**
123
83
* Creates a TCP connection to the database.
124
- *
125
- * @return { Promise<boolean> } Resolves to true if the client is connected.
84
+ * @returns Promise resolving to true if the connection is established successfully
85
+ * @throws Error if connection fails or authentication is rejected
126
86
*/
127
87
connect ( ) : Promise < boolean > {
128
88
const connOptions : net . NetConnectOpts | tls . ConnectionOptions = {
@@ -193,6 +153,12 @@ class TcpTransport implements SenderTransport {
193
153
} ) ;
194
154
}
195
155
156
+ /**
157
+ * Sends data over the established TCP connection.
158
+ * @param data - Buffer containing the data to send
159
+ * @returns Promise resolving to true if data was sent successfully
160
+ * @throws Error if the data could not be written to the socket
161
+ */
196
162
send ( data : Buffer ) : Promise < boolean > {
197
163
if ( ! this . socket || this . socket . destroyed ) {
198
164
throw new Error ( "TCP transport is not connected" ) ;
0 commit comments