@@ -4,7 +4,12 @@ import { Buffer } from "node:buffer";
44import { log , Logger } from "../logging" ;
55import { validateColumnName , validateTableName } from "../validation" ;
66import { SenderOptions } from "../options" ;
7- import { isInteger , timestampToMicros , timestampToNanos , TimestampUnit } from "../utils" ;
7+ import {
8+ isInteger ,
9+ timestampToMicros ,
10+ timestampToNanos ,
11+ TimestampUnit ,
12+ } from "../utils" ;
813
914const DEFAULT_MAX_NAME_LENGTH = 127 ;
1015
@@ -42,15 +47,17 @@ class SenderBuffer {
4247 this . log = options && typeof options . log === "function" ? options . log : log ;
4348 SenderOptions . resolveDeprecated ( options , this . log ) ;
4449
45- this . maxNameLength = options && isInteger ( options . max_name_len , 1 )
46- ? options . max_name_len
47- : DEFAULT_MAX_NAME_LENGTH ;
50+ this . maxNameLength =
51+ options && isInteger ( options . max_name_len , 1 )
52+ ? options . max_name_len
53+ : DEFAULT_MAX_NAME_LENGTH ;
4854
49- this . maxBufferSize = options && isInteger ( options . max_buf_size , 1 )
50- ? options . max_buf_size
51- : DEFAULT_MAX_BUFFER_SIZE ;
55+ this . maxBufferSize =
56+ options && isInteger ( options . max_buf_size , 1 )
57+ ? options . max_buf_size
58+ : DEFAULT_MAX_BUFFER_SIZE ;
5259 this . resize (
53- options && isInteger ( options . init_buf_size , 1 )
60+ options && isInteger ( options . init_buf_size , 1 )
5461 ? options . init_buf_size
5562 : DEFAULT_BUFFER_SIZE ,
5663 ) ;
@@ -67,7 +74,9 @@ class SenderBuffer {
6774 */
6875 private resize ( bufferSize : number ) {
6976 if ( bufferSize > this . maxBufferSize ) {
70- throw new Error ( `Max buffer size is ${ this . maxBufferSize } bytes, requested buffer size: ${ bufferSize } ` ) ;
77+ throw new Error (
78+ `Max buffer size is ${ this . maxBufferSize } bytes, requested buffer size: ${ bufferSize } ` ,
79+ ) ;
7180 }
7281 this . bufferSize = bufferSize ;
7382 // Allocating an extra byte because Buffer.write() does not fail if the length of the data to be written is
@@ -158,7 +167,9 @@ class SenderBuffer {
158167 throw new Error ( `Symbol name must be a string, received ${ typeof name } ` ) ;
159168 }
160169 if ( ! this . hasTable || this . hasColumns ) {
161- throw new Error ( "Symbol can be added only after table name is set and before any column added" ) ;
170+ throw new Error (
171+ "Symbol can be added only after table name is set and before any column added" ,
172+ ) ;
162173 }
163174 const valueStr = value . toString ( ) ;
164175 this . checkCapacity ( [ name , valueStr ] , 2 + name . length + valueStr . length ) ;
@@ -262,7 +273,11 @@ class SenderBuffer {
262273 * @param {string } [unit=us] - Timestamp unit. Supported values: 'ns' - nanoseconds, 'us' - microseconds, 'ms' - milliseconds. Defaults to 'us'.
263274 * @return {Sender } Returns with a reference to this sender.
264275 */
265- timestampColumn ( name : string , value : number | bigint , unit : TimestampUnit = "us" ) : SenderBuffer {
276+ timestampColumn (
277+ name : string ,
278+ value : number | bigint ,
279+ unit : TimestampUnit = "us" ,
280+ ) : SenderBuffer {
266281 if ( typeof value !== "bigint" && ! Number . isInteger ( value ) ) {
267282 throw new Error ( `Value must be an integer or BigInt, received ${ value } ` ) ;
268283 }
@@ -284,10 +299,14 @@ class SenderBuffer {
284299 */
285300 at ( timestamp : number | bigint , unit : TimestampUnit = "us" ) {
286301 if ( ! this . hasSymbols && ! this . hasColumns ) {
287- throw new Error ( "The row must have a symbol or column set before it is closed" ) ;
302+ throw new Error (
303+ "The row must have a symbol or column set before it is closed" ,
304+ ) ;
288305 }
289306 if ( typeof timestamp !== "bigint" && ! Number . isInteger ( timestamp ) ) {
290- throw new Error ( `Designated timestamp must be an integer or BigInt, received ${ timestamp } ` ) ;
307+ throw new Error (
308+ `Designated timestamp must be an integer or BigInt, received ${ timestamp } ` ,
309+ ) ;
291310 }
292311 const timestampNanos = timestampToNanos ( BigInt ( timestamp ) , unit ) ;
293312 const timestampStr = timestampNanos . toString ( ) ;
@@ -304,7 +323,9 @@ class SenderBuffer {
304323 */
305324 atNow ( ) {
306325 if ( ! this . hasSymbols && ! this . hasColumns ) {
307- throw new Error ( "The row must have a symbol or column set before it is closed" ) ;
326+ throw new Error (
327+ "The row must have a symbol or column set before it is closed" ,
328+ ) ;
308329 }
309330 this . checkCapacity ( [ ] , 1 ) ;
310331 this . write ( "\n" ) ;
@@ -334,17 +355,17 @@ class SenderBuffer {
334355 }
335356
336357 private writeColumn (
337- name : string ,
338- value : unknown ,
339- writeValue : ( ) => void ,
340- valueType ?: string
358+ name : string ,
359+ value : unknown ,
360+ writeValue : ( ) => void ,
361+ valueType ?: string ,
341362 ) {
342363 if ( typeof name !== "string" ) {
343364 throw new Error ( `Column name must be a string, received ${ typeof name } ` ) ;
344365 }
345366 if ( valueType && typeof value !== valueType ) {
346367 throw new Error (
347- `Column value must be of type ${ valueType } , received ${ typeof value } ` ,
368+ `Column value must be of type ${ valueType } , received ${ typeof value } ` ,
348369 ) ;
349370 }
350371 if ( ! this . hasTable ) {
@@ -364,7 +385,7 @@ class SenderBuffer {
364385 if ( this . position > this . bufferSize ) {
365386 // should never happen, if checkCapacity() is correctly used
366387 throw new Error (
367- `Buffer overflow [position=${ this . position } , bufferSize=${ this . bufferSize } ]` ,
388+ `Buffer overflow [position=${ this . position } , bufferSize=${ this . bufferSize } ]` ,
368389 ) ;
369390 }
370391 }
0 commit comments