@@ -17,13 +17,12 @@ import {
17
17
TimestampUnit ,
18
18
} from "../utils" ;
19
19
20
+ // Default maximum length for table and column names.
20
21
const DEFAULT_MAX_NAME_LENGTH = 127 ;
21
22
22
- /** @classdesc
23
- * The QuestDB client's API provides methods to connect to the database, ingest data, and close the connection.
24
- * If no custom agent is configured, the Sender will use its own agent which overrides some default values
25
- * of <i>undici.Agent</i>. The Sender's own agent uses persistent connections with 1 minute idle timeout, pipelines requests default to 1.
26
- * </p>
23
+ /**
24
+ * Abstract base class for SenderBuffer implementations. <br>
25
+ * Provides common functionality for writing data into the buffer.
27
26
*/
28
27
abstract class SenderBufferBase implements SenderBuffer {
29
28
private bufferSize : number ;
@@ -41,7 +40,7 @@ abstract class SenderBufferBase implements SenderBuffer {
41
40
protected readonly log : Logger ;
42
41
43
42
/**
44
- * Creates an instance of Sender .
43
+ * Creates an instance of SenderBufferBase .
45
44
*
46
45
* @param {SenderOptions } options - Sender configuration object. <br>
47
46
* See SenderOptions documentation for detailed description of configuration options. <br>
@@ -69,7 +68,7 @@ abstract class SenderBufferBase implements SenderBuffer {
69
68
}
70
69
71
70
/**
72
- * Extends the size of the sender's buffer. <br>
71
+ * Extends the size of the buffer. <br>
73
72
* Can be used to increase the size of buffer if overflown.
74
73
* The buffer's content is copied into the new buffer.
75
74
*
@@ -113,22 +112,20 @@ abstract class SenderBufferBase implements SenderBuffer {
113
112
}
114
113
115
114
/**
116
- * @ignore
117
- * @return {Buffer } Returns a cropped buffer, or null if there is nothing to send.
118
- * The returned buffer is backed by the sender's buffer.
119
- * Used only in tests.
115
+ * @return {Buffer } Returns a cropped buffer, or null if there is nothing to send. <br>
116
+ * The returned buffer is backed by this buffer instance, meaning the view can change as the buffer is mutated.
117
+ * Used only in tests to assert the buffer's content.
120
118
*/
121
119
toBufferView ( pos = this . endOfLastRow ) : Buffer {
122
120
return pos > 0 ? this . buffer . subarray ( 0 , pos ) : null ;
123
121
}
124
122
125
123
/**
126
- * @ignore
127
- * @return {Buffer|null } Returns a cropped buffer ready to send to the server, or null if there is nothing to send.
128
- * The returned buffer is a copy of the sender's buffer.
129
- * It also compacts the Sender's buffer.
124
+ * @return {Buffer } Returns a cropped buffer ready to send to the server, or null if there is nothing to send. <br>
125
+ * The returned buffer is a copy of this buffer.
126
+ * It also compacts the buffer.
130
127
*/
131
- toBufferNew ( pos = this . endOfLastRow ) : Buffer | null {
128
+ toBufferNew ( pos = this . endOfLastRow ) : Buffer {
132
129
if ( pos > 0 ) {
133
130
const data = Buffer . allocUnsafe ( pos ) ;
134
131
this . buffer . copy ( data , 0 , 0 , pos ) ;
@@ -139,7 +136,7 @@ abstract class SenderBufferBase implements SenderBuffer {
139
136
}
140
137
141
138
/**
142
- * Write the table name into the buffer of the sender .
139
+ * Write the table name into the buffer.
143
140
*
144
141
* @param {string } table - Table name.
145
142
* @return {Sender } Returns with a reference to this sender.
@@ -159,7 +156,7 @@ abstract class SenderBufferBase implements SenderBuffer {
159
156
}
160
157
161
158
/**
162
- * Write a symbol name and value into the buffer of the sender .
159
+ * Write a symbol name and value into the buffer.
163
160
*
164
161
* @param {string } name - Symbol name.
165
162
* @param {unknown } value - Symbol value, toString() is called to extract the actual symbol value from the parameter.
@@ -186,7 +183,7 @@ abstract class SenderBufferBase implements SenderBuffer {
186
183
}
187
184
188
185
/**
189
- * Write a string column with its value into the buffer of the sender .
186
+ * Write a string column with its value into the buffer.
190
187
*
191
188
* @param {string } name - Column name.
192
189
* @param {string } value - Column value, accepts only string values.
@@ -208,7 +205,7 @@ abstract class SenderBufferBase implements SenderBuffer {
208
205
}
209
206
210
207
/**
211
- * Write a boolean column with its value into the buffer of the sender .
208
+ * Write a boolean column with its value into the buffer.
212
209
*
213
210
* @param {string } name - Column name.
214
211
* @param {boolean } value - Column value, accepts only boolean values.
@@ -228,7 +225,7 @@ abstract class SenderBufferBase implements SenderBuffer {
228
225
}
229
226
230
227
/**
231
- * Write a float column with its value into the buffer of the sender .
228
+ * Write a float column with its value into the buffer.
232
229
*
233
230
* @param {string } name - Column name.
234
231
* @param {number } value - Column value, accepts only number values.
@@ -239,11 +236,12 @@ abstract class SenderBufferBase implements SenderBuffer {
239
236
abstract arrayColumn ( name : string , value : unknown [ ] ) : SenderBuffer ;
240
237
241
238
/**
242
- * Write an integer column with its value into the buffer of the sender .
239
+ * Write an integer column with its value into the buffer.
243
240
*
244
241
* @param {string } name - Column name.
245
242
* @param {number } value - Column value, accepts only number values.
246
243
* @return {Sender } Returns with a reference to this sender.
244
+ * @throws Error if the value is not an integer
247
245
*/
248
246
intColumn ( name : string , value : number ) : SenderBuffer {
249
247
if ( ! Number . isInteger ( value ) ) {
@@ -259,7 +257,7 @@ abstract class SenderBufferBase implements SenderBuffer {
259
257
}
260
258
261
259
/**
262
- * Write a timestamp column with its value into the buffer of the sender .
260
+ * Write a timestamp column with its value into the buffer.
263
261
*
264
262
* @param {string } name - Column name.
265
263
* @param {number | bigint } value - Epoch timestamp, accepts numbers or BigInts.
@@ -285,7 +283,7 @@ abstract class SenderBufferBase implements SenderBuffer {
285
283
}
286
284
287
285
/**
288
- * Closing the row after writing the designated timestamp into the buffer of the sender .
286
+ * Closing the row after writing the designated timestamp into the buffer.
289
287
*
290
288
* @param {number | bigint } timestamp - Designated epoch timestamp, accepts numbers or BigInts.
291
289
* @param {string } [unit=us] - Timestamp unit. Supported values: 'ns' - nanoseconds, 'us' - microseconds, 'ms' - milliseconds. Defaults to 'us'.
@@ -311,7 +309,7 @@ abstract class SenderBufferBase implements SenderBuffer {
311
309
}
312
310
313
311
/**
314
- * Closing the row without writing designated timestamp into the buffer of the sender . <br>
312
+ * Closing the row without writing designated timestamp into the buffer. <br>
315
313
* Designated timestamp will be populated by the server on this record.
316
314
*/
317
315
atNow ( ) {
@@ -325,6 +323,14 @@ abstract class SenderBufferBase implements SenderBuffer {
325
323
this . startNewRow ( ) ;
326
324
}
327
325
326
+ /**
327
+ * Returns the current position of the buffer. <br>
328
+ * New data will be written into the buffer starting from this position.
329
+ */
330
+ currentPosition ( ) : number {
331
+ return this . position ;
332
+ }
333
+
328
334
protected checkCapacity ( data : string [ ] , base = 0 ) {
329
335
let length = base ;
330
336
for ( const str of data ) {
0 commit comments