Skip to content

Commit 0ad1eca

Browse files
committed
js doc for buffer
1 parent 3021396 commit 0ad1eca

6 files changed

Lines changed: 72 additions & 45 deletions

File tree

src/buffer/base.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@ import {
1616
TimestampUnit,
1717
} from "../utils";
1818

19+
// Default maximum length for table and column names.
1920
const DEFAULT_MAX_NAME_LENGTH = 127;
2021

21-
/** @classdesc
22-
* The QuestDB client's API provides methods to connect to the database, ingest data, and close the connection.
23-
* If no custom agent is configured, the Sender will use its own agent which overrides some default values
24-
* of <i>undici.Agent</i>. The Sender's own agent uses persistent connections with 1 minute idle timeout, pipelines requests default to 1.
25-
* </p>
22+
/**
23+
* Abstract base class for SenderBuffer implementations. <br>
24+
* Provides common functionality for writing data into the buffer.
2625
*/
2726
abstract class SenderBufferBase implements SenderBuffer {
2827
private bufferSize: number;
@@ -40,7 +39,7 @@ abstract class SenderBufferBase implements SenderBuffer {
4039
protected readonly log: Logger;
4140

4241
/**
43-
* Creates an instance of Sender.
42+
* Creates an instance of SenderBufferBase.
4443
*
4544
* @param {SenderOptions} options - Sender configuration object. <br>
4645
* See SenderOptions documentation for detailed description of configuration options. <br>
@@ -68,7 +67,7 @@ abstract class SenderBufferBase implements SenderBuffer {
6867
}
6968

7069
/**
71-
* Extends the size of the sender's buffer. <br>
70+
* Extends the size of the buffer. <br>
7271
* Can be used to increase the size of buffer if overflown.
7372
* The buffer's content is copied into the new buffer.
7473
*
@@ -112,22 +111,20 @@ abstract class SenderBufferBase implements SenderBuffer {
112111
}
113112

114113
/**
115-
* @ignore
116-
* @return {Buffer} Returns a cropped buffer, or null if there is nothing to send.
117-
* The returned buffer is backed by the sender's buffer.
118-
* Used only in tests.
114+
* @return {Buffer} Returns a cropped buffer, or null if there is nothing to send. <br>
115+
* The returned buffer is backed by this buffer instance, meaning the view can change as the buffer is mutated.
116+
* Used only in tests to assert the buffer's content.
119117
*/
120118
toBufferView(pos = this.endOfLastRow): Buffer {
121119
return pos > 0 ? this.buffer.subarray(0, pos) : null;
122120
}
123121

124122
/**
125-
* @ignore
126-
* @return {Buffer|null} Returns a cropped buffer ready to send to the server, or null if there is nothing to send.
127-
* The returned buffer is a copy of the sender's buffer.
128-
* It also compacts the Sender's buffer.
123+
* @return {Buffer} Returns a cropped buffer ready to send to the server, or null if there is nothing to send. <br>
124+
* The returned buffer is a copy of this buffer.
125+
* It also compacts the buffer.
129126
*/
130-
toBufferNew(pos = this.endOfLastRow): Buffer | null {
127+
toBufferNew(pos = this.endOfLastRow): Buffer {
131128
if (pos > 0) {
132129
const data = Buffer.allocUnsafe(pos);
133130
this.buffer.copy(data, 0, 0, pos);
@@ -138,7 +135,7 @@ abstract class SenderBufferBase implements SenderBuffer {
138135
}
139136

140137
/**
141-
* Write the table name into the buffer of the sender.
138+
* Write the table name into the buffer.
142139
*
143140
* @param {string} table - Table name.
144141
* @return {Sender} Returns with a reference to this sender.
@@ -158,7 +155,7 @@ abstract class SenderBufferBase implements SenderBuffer {
158155
}
159156

160157
/**
161-
* Write a symbol name and value into the buffer of the sender.
158+
* Write a symbol name and value into the buffer.
162159
*
163160
* @param {string} name - Symbol name.
164161
* @param {unknown} value - Symbol value, toString() is called to extract the actual symbol value from the parameter.
@@ -185,7 +182,7 @@ abstract class SenderBufferBase implements SenderBuffer {
185182
}
186183

187184
/**
188-
* Write a string column with its value into the buffer of the sender.
185+
* Write a string column with its value into the buffer.
189186
*
190187
* @param {string} name - Column name.
191188
* @param {string} value - Column value, accepts only string values.
@@ -207,7 +204,7 @@ abstract class SenderBufferBase implements SenderBuffer {
207204
}
208205

209206
/**
210-
* Write a boolean column with its value into the buffer of the sender.
207+
* Write a boolean column with its value into the buffer.
211208
*
212209
* @param {string} name - Column name.
213210
* @param {boolean} value - Column value, accepts only boolean values.
@@ -227,7 +224,7 @@ abstract class SenderBufferBase implements SenderBuffer {
227224
}
228225

229226
/**
230-
* Write a float column with its value into the buffer of the sender.
227+
* Write a float column with its value into the buffer.
231228
*
232229
* @param {string} name - Column name.
233230
* @param {number} value - Column value, accepts only number values.
@@ -236,11 +233,12 @@ abstract class SenderBufferBase implements SenderBuffer {
236233
abstract floatColumn(name: string, value: number): SenderBuffer;
237234

238235
/**
239-
* Write an integer column with its value into the buffer of the sender.
236+
* Write an integer column with its value into the buffer.
240237
*
241238
* @param {string} name - Column name.
242239
* @param {number} value - Column value, accepts only number values.
243240
* @return {Sender} Returns with a reference to this sender.
241+
* @throws Error if the value is not an integer
244242
*/
245243
intColumn(name: string, value: number): SenderBuffer {
246244
if (!Number.isInteger(value)) {
@@ -256,7 +254,7 @@ abstract class SenderBufferBase implements SenderBuffer {
256254
}
257255

258256
/**
259-
* Write a timestamp column with its value into the buffer of the sender.
257+
* Write a timestamp column with its value into the buffer.
260258
*
261259
* @param {string} name - Column name.
262260
* @param {number | bigint} value - Epoch timestamp, accepts numbers or BigInts.
@@ -282,7 +280,7 @@ abstract class SenderBufferBase implements SenderBuffer {
282280
}
283281

284282
/**
285-
* Closing the row after writing the designated timestamp into the buffer of the sender.
283+
* Closing the row after writing the designated timestamp into the buffer.
286284
*
287285
* @param {number | bigint} timestamp - Designated epoch timestamp, accepts numbers or BigInts.
288286
* @param {string} [unit=us] - Timestamp unit. Supported values: 'ns' - nanoseconds, 'us' - microseconds, 'ms' - milliseconds. Defaults to 'us'.
@@ -308,7 +306,7 @@ abstract class SenderBufferBase implements SenderBuffer {
308306
}
309307

310308
/**
311-
* Closing the row without writing designated timestamp into the buffer of the sender. <br>
309+
* Closing the row without writing designated timestamp into the buffer. <br>
312310
* Designated timestamp will be populated by the server on this record.
313311
*/
314312
atNow() {
@@ -323,7 +321,7 @@ abstract class SenderBufferBase implements SenderBuffer {
323321
}
324322

325323
/**
326-
* Returns the current position of the buffer.
324+
* Returns the current position of the buffer. <br>
327325
* New data will be written into the buffer starting from this position.
328326
*/
329327
currentPosition(): number {

src/buffer/bufferv1.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,22 @@ import { SenderOptions } from "../options";
33
import { SenderBuffer } from "./index";
44
import { SenderBufferBase } from "./base";
55

6+
/**
7+
* Buffer implementation for protocol version 1.
8+
* Sends floating point numbers in their text form.
9+
*/
610
class SenderBufferV1 extends SenderBufferBase {
711
constructor(options: SenderOptions) {
812
super(options);
913
}
1014

15+
/**
16+
* Write a float column with its value into the buffer using v1 serialization (text format).
17+
*
18+
* @param {string} name - Column name.
19+
* @param {number} value - Column value, accepts only number values.
20+
* @return {Sender} Returns with a reference to this sender.
21+
*/
1122
floatColumn(name: string, value: number): SenderBuffer {
1223
this.writeColumn(
1324
name,

src/buffer/bufferv2.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@ import { SenderBufferBase } from "./base";
66
const ENTITY_TYPE_DOUBLE: number = 16;
77
const EQUALS_SIGN: number = "=".charCodeAt(0);
88

9+
/**
10+
* Buffer implementation for protocol version 2.
11+
* Sends floating point numbers in binary form.
12+
*/
913
class SenderBufferV2 extends SenderBufferBase {
1014
constructor(options: SenderOptions) {
1115
super(options);
1216
}
1317

18+
/**
19+
* Write a float column with its value into the buffer using v2 serialization (binary format).
20+
*
21+
* @param {string} name - Column name.
22+
* @param {number} value - Column value, accepts only number values.
23+
* @return {Sender} Returns with a reference to this sender.
24+
*/
1425
floatColumn(name: string, value: number): SenderBuffer {
1526
this.writeColumn(
1627
name,

src/buffer/index.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ function createBuffer(options: SenderOptions): SenderBuffer {
3838
* Buffer used by the Sender.
3939
*/
4040
interface SenderBuffer {
41+
4142
/**
4243
* Resets the buffer, data added to the buffer will be lost. <br>
4344
* In other words it clears the buffer and sets the writing position to the beginning of the buffer.
@@ -47,31 +48,29 @@ interface SenderBuffer {
4748
reset(): SenderBuffer;
4849

4950
/**
50-
* @ignore
51-
* @return {Buffer} Returns a cropped buffer, or null if there is nothing to send.
52-
* The returned buffer is backed by the sender's buffer.
53-
* Used only in tests.
51+
* @return {Buffer} Returns a cropped buffer, or null if there is nothing to send. <br>
52+
* The returned buffer is backed by this buffer instance, meaning the view can change as the buffer is mutated.
53+
* Used only in tests to assert the buffer's content.
5454
*/
5555
toBufferView(pos?: number): Buffer;
5656

5757
/**
58-
* @ignore
59-
* @return {Buffer|null} Returns a cropped buffer ready to send to the server, or null if there is nothing to send.
60-
* The returned buffer is a copy of the sender's buffer.
61-
* It also compacts the Sender's buffer.
58+
* @return {Buffer} Returns a cropped buffer ready to send to the server, or null if there is nothing to send. <br>
59+
* The returned buffer is a copy of this buffer.
60+
* It also compacts the buffer.
6261
*/
6362
toBufferNew(pos?: number): Buffer | null;
6463

6564
/**
66-
* Write the table name into the buffer of the sender.
65+
* Write the table name into the buffer.
6766
*
6867
* @param {string} table - Table name.
6968
* @return {Sender} Returns with a reference to this sender.
7069
*/
7170
table(table: string): SenderBuffer;
7271

7372
/**
74-
* Write a symbol name and value into the buffer of the sender.
73+
* Write a symbol name and value into the buffer.
7574
*
7675
* @param {string} name - Symbol name.
7776
* @param {unknown} value - Symbol value, toString() is called to extract the actual symbol value from the parameter.
@@ -80,7 +79,7 @@ interface SenderBuffer {
8079
symbol(name: string, value: unknown): SenderBuffer;
8180

8281
/**
83-
* Write a string column with its value into the buffer of the sender.
82+
* Write a string column with its value into the buffer.
8483
*
8584
* @param {string} name - Column name.
8685
* @param {string} value - Column value, accepts only string values.
@@ -89,7 +88,7 @@ interface SenderBuffer {
8988
stringColumn(name: string, value: string): SenderBuffer;
9089

9190
/**
92-
* Write a boolean column with its value into the buffer of the sender.
91+
* Write a boolean column with its value into the buffer.
9392
*
9493
* @param {string} name - Column name.
9594
* @param {boolean} value - Column value, accepts only boolean values.
@@ -98,7 +97,7 @@ interface SenderBuffer {
9897
booleanColumn(name: string, value: boolean): SenderBuffer;
9998

10099
/**
101-
* Write a float column with its value into the buffer of the sender.
100+
* Write a float column with its value into the buffer.
102101
*
103102
* @param {string} name - Column name.
104103
* @param {number} value - Column value, accepts only number values.
@@ -107,16 +106,17 @@ interface SenderBuffer {
107106
floatColumn(name: string, value: number): SenderBuffer;
108107

109108
/**
110-
* Write an integer column with its value into the buffer of the sender.
109+
* Write an integer column with its value into the buffer.
111110
*
112111
* @param {string} name - Column name.
113112
* @param {number} value - Column value, accepts only number values.
114113
* @return {Sender} Returns with a reference to this sender.
114+
* @throws Error if the value is not an integer
115115
*/
116116
intColumn(name: string, value: number): SenderBuffer;
117117

118118
/**
119-
* Write a timestamp column with its value into the buffer of the sender.
119+
* Write a timestamp column with its value into the buffer.
120120
*
121121
* @param {string} name - Column name.
122122
* @param {number | bigint} value - Epoch timestamp, accepts numbers or BigInts.
@@ -130,21 +130,21 @@ interface SenderBuffer {
130130
): SenderBuffer;
131131

132132
/**
133-
* Closing the row after writing the designated timestamp into the buffer of the sender.
133+
* Closing the row after writing the designated timestamp into the buffer.
134134
*
135135
* @param {number | bigint} timestamp - Designated epoch timestamp, accepts numbers or BigInts.
136136
* @param {string} [unit=us] - Timestamp unit. Supported values: 'ns' - nanoseconds, 'us' - microseconds, 'ms' - milliseconds. Defaults to 'us'.
137137
*/
138138
at(timestamp: number | bigint, unit: TimestampUnit): void;
139139

140140
/**
141-
* Closing the row without writing designated timestamp into the buffer of the sender. <br>
141+
* Closing the row without writing designated timestamp into the buffer. <br>
142142
* Designated timestamp will be populated by the server on this record.
143143
*/
144144
atNow(): void;
145145

146146
/**
147-
* Returns the current position of the buffer.
147+
* Returns the current position of the buffer. <br>
148148
* New data will be written into the buffer starting from this position.
149149
*/
150150
currentPosition(): number;

src/transport/tcp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ class TcpTransport implements SenderTransport {
175175
}
176176

177177
/**
178-
* Closes the TCP connection to the database.
178+
* Closes the TCP connection to the database. <br>
179179
*/
180180
async close(): Promise<void> {
181181
if (this.socket) {

src/utils.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ function timestampToNanos(timestamp: bigint, unit: TimestampUnit) {
3636
}
3737
}
3838

39+
/**
40+
* Fetches JSON data from a URL.
41+
* @template T - The expected type of the JSON response
42+
* @param url - The URL to fetch from
43+
* @returns Promise resolving to the parsed JSON data
44+
* @throws Error if the request fails or returns a non-OK status
45+
*/
3946
async function fetchJson<T>(url: string): Promise<T> {
4047
let response: globalThis.Response;
4148
try {

0 commit comments

Comments
 (0)