@@ -17,13 +17,12 @@ import {
1717 TimestampUnit ,
1818} from "../utils" ;
1919
20+ // Default maximum length for table and column names.
2021const DEFAULT_MAX_NAME_LENGTH = 127 ;
2122
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.
2726 */
2827abstract class SenderBufferBase implements SenderBuffer {
2928 private bufferSize : number ;
@@ -41,7 +40,7 @@ abstract class SenderBufferBase implements SenderBuffer {
4140 protected readonly log : Logger ;
4241
4342 /**
44- * Creates an instance of Sender .
43+ * Creates an instance of SenderBufferBase .
4544 *
4645 * @param {SenderOptions } options - Sender configuration object. <br>
4746 * See SenderOptions documentation for detailed description of configuration options. <br>
@@ -69,7 +68,7 @@ abstract class SenderBufferBase implements SenderBuffer {
6968 }
7069
7170 /**
72- * Extends the size of the sender's buffer. <br>
71+ * Extends the size of the buffer. <br>
7372 * Can be used to increase the size of buffer if overflown.
7473 * The buffer's content is copied into the new buffer.
7574 *
@@ -113,22 +112,20 @@ abstract class SenderBufferBase implements SenderBuffer {
113112 }
114113
115114 /**
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.
120118 */
121119 toBufferView ( pos = this . endOfLastRow ) : Buffer {
122120 return pos > 0 ? this . buffer . subarray ( 0 , pos ) : null ;
123121 }
124122
125123 /**
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.
130127 */
131- toBufferNew ( pos = this . endOfLastRow ) : Buffer | null {
128+ toBufferNew ( pos = this . endOfLastRow ) : Buffer {
132129 if ( pos > 0 ) {
133130 const data = Buffer . allocUnsafe ( pos ) ;
134131 this . buffer . copy ( data , 0 , 0 , pos ) ;
@@ -139,7 +136,7 @@ abstract class SenderBufferBase implements SenderBuffer {
139136 }
140137
141138 /**
142- * Write the table name into the buffer of the sender .
139+ * Write the table name into the buffer.
143140 *
144141 * @param {string } table - Table name.
145142 * @return {Sender } Returns with a reference to this sender.
@@ -159,7 +156,7 @@ abstract class SenderBufferBase implements SenderBuffer {
159156 }
160157
161158 /**
162- * Write a symbol name and value into the buffer of the sender .
159+ * Write a symbol name and value into the buffer.
163160 *
164161 * @param {string } name - Symbol name.
165162 * @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 {
186183 }
187184
188185 /**
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.
190187 *
191188 * @param {string } name - Column name.
192189 * @param {string } value - Column value, accepts only string values.
@@ -208,7 +205,7 @@ abstract class SenderBufferBase implements SenderBuffer {
208205 }
209206
210207 /**
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.
212209 *
213210 * @param {string } name - Column name.
214211 * @param {boolean } value - Column value, accepts only boolean values.
@@ -228,7 +225,7 @@ abstract class SenderBufferBase implements SenderBuffer {
228225 }
229226
230227 /**
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.
232229 *
233230 * @param {string } name - Column name.
234231 * @param {number } value - Column value, accepts only number values.
@@ -239,11 +236,12 @@ abstract class SenderBufferBase implements SenderBuffer {
239236 abstract arrayColumn ( name : string , value : unknown [ ] ) : SenderBuffer ;
240237
241238 /**
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.
243240 *
244241 * @param {string } name - Column name.
245242 * @param {number } value - Column value, accepts only number values.
246243 * @return {Sender } Returns with a reference to this sender.
244+ * @throws Error if the value is not an integer
247245 */
248246 intColumn ( name : string , value : number ) : SenderBuffer {
249247 if ( ! Number . isInteger ( value ) ) {
@@ -259,7 +257,7 @@ abstract class SenderBufferBase implements SenderBuffer {
259257 }
260258
261259 /**
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.
263261 *
264262 * @param {string } name - Column name.
265263 * @param {number | bigint } value - Epoch timestamp, accepts numbers or BigInts.
@@ -285,7 +283,7 @@ abstract class SenderBufferBase implements SenderBuffer {
285283 }
286284
287285 /**
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.
289287 *
290288 * @param {number | bigint } timestamp - Designated epoch timestamp, accepts numbers or BigInts.
291289 * @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 {
311309 }
312310
313311 /**
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>
315313 * Designated timestamp will be populated by the server on this record.
316314 */
317315 atNow ( ) {
@@ -325,6 +323,14 @@ abstract class SenderBufferBase implements SenderBuffer {
325323 this . startNewRow ( ) ;
326324 }
327325
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+
328334 protected checkCapacity ( data : string [ ] , base = 0 ) {
329335 let length = base ;
330336 for ( const str of data ) {
0 commit comments