@@ -4,7 +4,12 @@ import { Buffer } from "node:buffer";
4
4
import { log , Logger } from "../logging" ;
5
5
import { validateColumnName , validateTableName } from "../validation" ;
6
6
import { SenderOptions } from "../options" ;
7
- import { isInteger , timestampToMicros , timestampToNanos , TimestampUnit } from "../utils" ;
7
+ import {
8
+ isInteger ,
9
+ timestampToMicros ,
10
+ timestampToNanos ,
11
+ TimestampUnit ,
12
+ } from "../utils" ;
8
13
9
14
const DEFAULT_MAX_NAME_LENGTH = 127 ;
10
15
@@ -42,15 +47,17 @@ class SenderBuffer {
42
47
this . log = options && typeof options . log === "function" ? options . log : log ;
43
48
SenderOptions . resolveDeprecated ( options , this . log ) ;
44
49
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 ;
48
54
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 ;
52
59
this . resize (
53
- options && isInteger ( options . init_buf_size , 1 )
60
+ options && isInteger ( options . init_buf_size , 1 )
54
61
? options . init_buf_size
55
62
: DEFAULT_BUFFER_SIZE ,
56
63
) ;
@@ -67,7 +74,9 @@ class SenderBuffer {
67
74
*/
68
75
private resize ( bufferSize : number ) {
69
76
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
+ ) ;
71
80
}
72
81
this . bufferSize = bufferSize ;
73
82
// 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 {
158
167
throw new Error ( `Symbol name must be a string, received ${ typeof name } ` ) ;
159
168
}
160
169
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
+ ) ;
162
173
}
163
174
const valueStr = value . toString ( ) ;
164
175
this . checkCapacity ( [ name , valueStr ] , 2 + name . length + valueStr . length ) ;
@@ -262,7 +273,11 @@ class SenderBuffer {
262
273
* @param {string } [unit=us] - Timestamp unit. Supported values: 'ns' - nanoseconds, 'us' - microseconds, 'ms' - milliseconds. Defaults to 'us'.
263
274
* @return {Sender } Returns with a reference to this sender.
264
275
*/
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 {
266
281
if ( typeof value !== "bigint" && ! Number . isInteger ( value ) ) {
267
282
throw new Error ( `Value must be an integer or BigInt, received ${ value } ` ) ;
268
283
}
@@ -284,10 +299,14 @@ class SenderBuffer {
284
299
*/
285
300
at ( timestamp : number | bigint , unit : TimestampUnit = "us" ) {
286
301
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
+ ) ;
288
305
}
289
306
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
+ ) ;
291
310
}
292
311
const timestampNanos = timestampToNanos ( BigInt ( timestamp ) , unit ) ;
293
312
const timestampStr = timestampNanos . toString ( ) ;
@@ -304,7 +323,9 @@ class SenderBuffer {
304
323
*/
305
324
atNow ( ) {
306
325
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
+ ) ;
308
329
}
309
330
this . checkCapacity ( [ ] , 1 ) ;
310
331
this . write ( "\n" ) ;
@@ -334,17 +355,17 @@ class SenderBuffer {
334
355
}
335
356
336
357
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 ,
341
362
) {
342
363
if ( typeof name !== "string" ) {
343
364
throw new Error ( `Column name must be a string, received ${ typeof name } ` ) ;
344
365
}
345
366
if ( valueType && typeof value !== valueType ) {
346
367
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 } ` ,
348
369
) ;
349
370
}
350
371
if ( ! this . hasTable ) {
@@ -364,7 +385,7 @@ class SenderBuffer {
364
385
if ( this . position > this . bufferSize ) {
365
386
// should never happen, if checkCapacity() is correctly used
366
387
throw new Error (
367
- `Buffer overflow [position=${ this . position } , bufferSize=${ this . bufferSize } ]` ,
388
+ `Buffer overflow [position=${ this . position } , bufferSize=${ this . bufferSize } ]` ,
368
389
) ;
369
390
}
370
391
}
0 commit comments