apache-iggy 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (149) hide show
  1. package/dist/client/client.connection.d.ts +49 -0
  2. package/dist/client/client.connection.js +79 -0
  3. package/dist/client/client.d.ts +46 -0
  4. package/dist/client/client.debug.d.ts +4 -0
  5. package/dist/client/client.debug.js +4 -0
  6. package/dist/client/client.js +65 -1
  7. package/dist/client/client.socket.d.ts +91 -0
  8. package/dist/client/client.socket.js +94 -0
  9. package/dist/client/client.type.d.ts +72 -0
  10. package/dist/client/client.type.js +3 -0
  11. package/dist/client/client.utils.d.ts +28 -0
  12. package/dist/client/client.utils.js +29 -0
  13. package/dist/e2e/tcp.cluster.e2e.js +1 -1
  14. package/dist/index.d.ts +3 -3
  15. package/dist/index.js +3 -3
  16. package/dist/tcp.sm.utils.d.ts +31 -42
  17. package/dist/tcp.sm.utils.js +38 -22
  18. package/dist/type.utils.d.ts +14 -0
  19. package/dist/type.utils.js +9 -0
  20. package/dist/wire/command-set.d.ts +2 -9
  21. package/dist/wire/command.utils.d.ts +18 -0
  22. package/dist/wire/command.utils.js +9 -0
  23. package/dist/wire/consumer-group/create-group.command.d.ts +13 -0
  24. package/dist/wire/consumer-group/create-group.command.js +7 -0
  25. package/dist/wire/consumer-group/delete-group.command.d.ts +13 -0
  26. package/dist/wire/consumer-group/delete-group.command.js +7 -0
  27. package/dist/wire/consumer-group/ensure-group.virtual.command.d.ts +15 -1
  28. package/dist/wire/consumer-group/ensure-group.virtual.command.js +14 -0
  29. package/dist/wire/consumer-group/get-group.command.d.ts +13 -0
  30. package/dist/wire/consumer-group/get-group.command.js +7 -0
  31. package/dist/wire/consumer-group/get-groups.command.d.ts +12 -0
  32. package/dist/wire/consumer-group/get-groups.command.js +7 -0
  33. package/dist/wire/consumer-group/group.utils.d.ts +34 -0
  34. package/dist/wire/consumer-group/group.utils.js +22 -0
  35. package/dist/wire/consumer-group/join-group.command.d.ts +13 -0
  36. package/dist/wire/consumer-group/join-group.command.js +7 -0
  37. package/dist/wire/consumer-group/leave-group.command.d.ts +13 -0
  38. package/dist/wire/consumer-group/leave-group.command.js +7 -0
  39. package/dist/wire/identifier.utils.d.ts +11 -0
  40. package/dist/wire/identifier.utils.js +23 -1
  41. package/dist/wire/message/flush-unsaved-buffers.command.d.ts +13 -0
  42. package/dist/wire/message/flush-unsaved-buffers.command.js +7 -0
  43. package/dist/wire/message/header.type.d.ts +57 -15
  44. package/dist/wire/message/header.type.js +31 -18
  45. package/dist/wire/message/header.utils.d.ts +104 -10
  46. package/dist/wire/message/header.utils.js +233 -86
  47. package/dist/wire/message/header.utils.test.js +39 -16
  48. package/dist/wire/message/iggy-header.utils.d.ts +39 -1
  49. package/dist/wire/message/iggy-header.utils.js +30 -3
  50. package/dist/wire/message/index.d.ts +5 -5
  51. package/dist/wire/message/index.js +5 -5
  52. package/dist/wire/message/message.utils.d.ts +60 -0
  53. package/dist/wire/message/message.utils.js +54 -1
  54. package/dist/wire/message/partitioning.utils.d.ts +39 -0
  55. package/dist/wire/message/partitioning.utils.js +43 -1
  56. package/dist/wire/message/poll-messages.command.d.ts +17 -0
  57. package/dist/wire/message/poll-messages.command.js +7 -0
  58. package/dist/wire/message/poll.utils.d.ts +93 -12
  59. package/dist/wire/message/poll.utils.js +92 -21
  60. package/dist/wire/message/send-messages.command.d.ts +14 -0
  61. package/dist/wire/message/send-messages.command.js +7 -0
  62. package/dist/wire/message/send-messages.command.test.js +103 -39
  63. package/dist/wire/number.utils.d.ts +79 -0
  64. package/dist/wire/number.utils.js +79 -2
  65. package/dist/wire/offset/delete-offset.command.d.ts +13 -3
  66. package/dist/wire/offset/delete-offset.command.js +7 -0
  67. package/dist/wire/offset/get-offset.command.d.ts +14 -0
  68. package/dist/wire/offset/get-offset.command.js +7 -0
  69. package/dist/wire/offset/offset.utils.d.ts +48 -0
  70. package/dist/wire/offset/offset.utils.js +33 -0
  71. package/dist/wire/offset/store-offset.command.d.ts +15 -0
  72. package/dist/wire/offset/store-offset.command.js +7 -0
  73. package/dist/wire/partition/create-partition.command.d.ts +13 -0
  74. package/dist/wire/partition/create-partition.command.js +7 -0
  75. package/dist/wire/partition/delete-partition.command.d.ts +13 -0
  76. package/dist/wire/partition/delete-partition.command.js +7 -0
  77. package/dist/wire/partition/partition.utils.d.ts +9 -0
  78. package/dist/wire/partition/partition.utils.js +9 -0
  79. package/dist/wire/serialize.utils.d.ts +20 -0
  80. package/dist/wire/serialize.utils.js +20 -0
  81. package/dist/wire/session/login-with-token.command.d.ts +11 -0
  82. package/dist/wire/session/login-with-token.command.js +7 -0
  83. package/dist/wire/session/login.command.d.ts +7 -0
  84. package/dist/wire/session/login.command.js +7 -0
  85. package/dist/wire/session/login.utils.d.ts +25 -0
  86. package/dist/wire/session/login.utils.js +14 -0
  87. package/dist/wire/session/logout.command.d.ts +7 -0
  88. package/dist/wire/session/logout.command.js +7 -0
  89. package/dist/wire/stream/create-stream.command.d.ts +12 -0
  90. package/dist/wire/stream/create-stream.command.js +7 -0
  91. package/dist/wire/stream/delete-stream.command.d.ts +11 -0
  92. package/dist/wire/stream/delete-stream.command.js +7 -0
  93. package/dist/wire/stream/ensure-stream.virtual.command.d.ts +8 -1
  94. package/dist/wire/stream/ensure-stream.virtual.command.js +7 -0
  95. package/dist/wire/stream/get-stream.command.d.ts +11 -0
  96. package/dist/wire/stream/get-stream.command.js +7 -0
  97. package/dist/wire/stream/get-streams.command.d.ts +7 -0
  98. package/dist/wire/stream/get-streams.command.js +7 -0
  99. package/dist/wire/stream/purge-stream.command.d.ts +11 -0
  100. package/dist/wire/stream/purge-stream.command.js +7 -0
  101. package/dist/wire/stream/stream.utils.d.ts +22 -0
  102. package/dist/wire/stream/stream.utils.js +8 -0
  103. package/dist/wire/stream/update-stream.command.d.ts +12 -0
  104. package/dist/wire/stream/update-stream.command.js +7 -0
  105. package/dist/wire/token/create-token.command.d.ts +12 -0
  106. package/dist/wire/token/create-token.command.js +7 -0
  107. package/dist/wire/token/delete-token.command.d.ts +11 -0
  108. package/dist/wire/token/delete-token.command.js +7 -0
  109. package/dist/wire/token/get-tokens.command.d.ts +7 -0
  110. package/dist/wire/token/get-tokens.command.js +7 -0
  111. package/dist/wire/token/token.utils.d.ts +40 -0
  112. package/dist/wire/token/token.utils.js +21 -0
  113. package/dist/wire/topic/create-topic.command.d.ts +17 -0
  114. package/dist/wire/topic/create-topic.command.js +7 -0
  115. package/dist/wire/topic/delete-topic.command.d.ts +14 -2
  116. package/dist/wire/topic/delete-topic.command.js +7 -0
  117. package/dist/wire/topic/ensure-topic.virtual.command.d.ts +9 -2
  118. package/dist/wire/topic/ensure-topic.virtual.command.js +7 -0
  119. package/dist/wire/topic/get-topic.command.d.ts +13 -2
  120. package/dist/wire/topic/get-topic.command.js +7 -0
  121. package/dist/wire/topic/get-topics.command.d.ts +11 -0
  122. package/dist/wire/topic/get-topics.command.js +7 -0
  123. package/dist/wire/topic/purge-topic.command.d.ts +12 -0
  124. package/dist/wire/topic/purge-topic.command.js +7 -0
  125. package/dist/wire/topic/topic.utils.d.ts +73 -0
  126. package/dist/wire/topic/topic.utils.js +40 -0
  127. package/dist/wire/topic/update-topic.command.d.ts +17 -0
  128. package/dist/wire/topic/update-topic.command.js +7 -0
  129. package/dist/wire/user/change-password.command.d.ts +13 -0
  130. package/dist/wire/user/change-password.command.js +7 -0
  131. package/dist/wire/user/create-user.command.d.ts +14 -0
  132. package/dist/wire/user/create-user.command.js +7 -0
  133. package/dist/wire/user/delete-user.command.d.ts +11 -0
  134. package/dist/wire/user/delete-user.command.js +7 -0
  135. package/dist/wire/user/get-user.command.d.ts +11 -0
  136. package/dist/wire/user/get-user.command.js +7 -0
  137. package/dist/wire/user/get-users.command.d.ts +7 -0
  138. package/dist/wire/user/get-users.command.js +7 -0
  139. package/dist/wire/user/permissions.utils.d.ts +108 -0
  140. package/dist/wire/user/permissions.utils.js +68 -0
  141. package/dist/wire/user/update-permissions.command.d.ts +12 -0
  142. package/dist/wire/user/update-permissions.command.js +7 -0
  143. package/dist/wire/user/update-user.command.d.ts +13 -0
  144. package/dist/wire/user/update-user.command.js +7 -0
  145. package/dist/wire/user/user.utils.d.ts +40 -0
  146. package/dist/wire/user/user.utils.js +33 -0
  147. package/dist/wire/uuid.utils.d.ts +13 -0
  148. package/dist/wire/uuid.utils.js +13 -1
  149. package/package.json +2 -2
@@ -22,19 +22,38 @@ import { responseError } from '../wire/error.utils.js';
22
22
  import { debug } from './client.debug.js';
23
23
  import { IggyConnection } from './client.connection.js';
24
24
  import { LOGIN, LOGIN_WITH_TOKEN, PING } from '../wire/index.js';
25
+ /**
26
+ * Command codes that can be executed without authentication.
27
+ */
25
28
  const UNLOGGED_COMMAND_CODE = [
26
29
  PING.code,
27
30
  LOGIN.code,
28
31
  LOGIN_WITH_TOKEN.code
29
32
  ];
33
+ /**
34
+ * Manages command execution and response handling for the Iggy server.
35
+ * Implements command queuing, authentication, and heartbeat functionality.
36
+ */
30
37
  export class CommandResponseStream extends EventEmitter {
38
+ /** Client configuration */
31
39
  options;
40
+ /** Underlying connection to the server */
32
41
  connection;
42
+ /** Queue of pending command jobs */
33
43
  _execQueue;
44
+ /** Whether the stream is currently processing a command */
34
45
  busy;
46
+ /** Whether the client has been authenticated */
35
47
  isAuthenticated;
48
+ /** Authenticated user ID */
36
49
  userId;
50
+ /** Heartbeat interval timer handle */
37
51
  heartbeatIntervalHandler;
52
+ /**
53
+ * Creates a new CommandResponseStream.
54
+ *
55
+ * @param options - Client configuration
56
+ */
38
57
  constructor(options) {
39
58
  super();
40
59
  this.options = options;
@@ -45,12 +64,25 @@ export class CommandResponseStream extends EventEmitter {
45
64
  this._init();
46
65
  }
47
66
  ;
67
+ /**
68
+ * Initializes the stream by setting up heartbeat and connection event handlers.
69
+ */
48
70
  _init() {
49
71
  this.heartbeat(this.options.heartbeatInterval);
50
72
  this.connection.on('disconnected', async () => {
51
73
  this.isAuthenticated = false;
52
74
  });
53
75
  }
76
+ /**
77
+ * Sends a command to the server.
78
+ * Automatically handles connection and authentication if needed.
79
+ *
80
+ * @param command - Command code to send
81
+ * @param payload - Command payload buffer
82
+ * @param handleResponse - Whether to parse the response (default: true)
83
+ * @param last - Whether to add to end of queue (default: true)
84
+ * @returns Promise resolving to the command response
85
+ */
54
86
  async sendCommand(command, payload, handleResponse = true, last = true) {
55
87
  if (!this.connection.connected)
56
88
  await this.connection.connect();
@@ -64,6 +96,12 @@ export class CommandResponseStream extends EventEmitter {
64
96
  this._processQueue(handleResponse);
65
97
  });
66
98
  }
99
+ /**
100
+ * Processes queued commands sequentially.
101
+ * Emits 'finishQueue' when all commands are processed.
102
+ *
103
+ * @param handleResponse - Whether to parse responses
104
+ */
67
105
  async _processQueue(handleResponse = true) {
68
106
  if (this.busy)
69
107
  return;
@@ -83,6 +121,14 @@ export class CommandResponseStream extends EventEmitter {
83
121
  this.busy = false;
84
122
  this.emit('finishQueue');
85
123
  }
124
+ /**
125
+ * Processes a single command by writing it to the connection and waiting for response.
126
+ *
127
+ * @param command - Command code
128
+ * @param payload - Command payload
129
+ * @param handleResp - Whether to parse the response
130
+ * @returns Promise resolving to the command response
131
+ */
86
132
  _processNext(command, payload, handleResp = true) {
87
133
  const lastWrite = this.connection.writeCommand(command, payload);
88
134
  debug('==> writeCommand', lastWrite);
@@ -103,10 +149,21 @@ export class CommandResponseStream extends EventEmitter {
103
149
  });
104
150
  });
105
151
  }
152
+ /**
153
+ * Fails all queued commands with the given error.
154
+ *
155
+ * @param err - Error to reject all queued commands with
156
+ */
106
157
  _failQueue(err) {
107
158
  this._execQueue.forEach(({ reject }) => reject(err));
108
159
  this._execQueue = [];
109
160
  }
161
+ /**
162
+ * Authenticates the client with the server.
163
+ *
164
+ * @param creds - Authentication credentials (token or password)
165
+ * @returns True if authentication succeeded
166
+ */
110
167
  async authenticate(creds) {
111
168
  const r = ('token' in creds) ?
112
169
  await this._authWithToken(creds) :
@@ -115,21 +172,43 @@ export class CommandResponseStream extends EventEmitter {
115
172
  this.userId = r.userId;
116
173
  return this.isAuthenticated;
117
174
  }
175
+ /**
176
+ * Authenticates using username and password.
177
+ *
178
+ * @param creds - Password credentials
179
+ * @returns Login response with user ID
180
+ */
118
181
  async _authWithPassword(creds) {
119
182
  const pl = LOGIN.serialize(creds);
120
183
  const logr = await this.sendCommand(LOGIN.code, pl, true, false);
121
184
  return LOGIN.deserialize(logr);
122
185
  }
186
+ /**
187
+ * Authenticates using a token.
188
+ *
189
+ * @param creds - Token credentials
190
+ * @returns Login response with user ID
191
+ */
123
192
  async _authWithToken(creds) {
124
193
  const pl = LOGIN_WITH_TOKEN.serialize(creds);
125
194
  const logr = await this.sendCommand(LOGIN_WITH_TOKEN.code, pl, true, false);
126
195
  return LOGIN_WITH_TOKEN.deserialize(logr);
127
196
  }
197
+ /**
198
+ * Sends a ping command to the server.
199
+ *
200
+ * @returns Ping response
201
+ */
128
202
  async ping() {
129
203
  const pl = PING.serialize();
130
204
  const pingR = await this.sendCommand(PING.code, pl, true);
131
205
  return PING.deserialize(pingR);
132
206
  }
207
+ /**
208
+ * Starts sending periodic heartbeat pings to keep the connection alive.
209
+ *
210
+ * @param interval - Heartbeat interval in milliseconds
211
+ */
133
212
  heartbeat(interval) {
134
213
  if (!interval)
135
214
  return;
@@ -140,9 +219,18 @@ export class CommandResponseStream extends EventEmitter {
140
219
  }
141
220
  }, interval);
142
221
  }
222
+ /**
223
+ * Returns the underlying socket as a readable stream.
224
+ *
225
+ * @returns The connection socket
226
+ */
143
227
  getReadStream() {
144
228
  return this.connection.socket;
145
229
  }
230
+ /**
231
+ * Destroys the stream and cleans up resources.
232
+ * Stops heartbeat and destroys the connection.
233
+ */
146
234
  destroy() {
147
235
  if (this.heartbeatIntervalHandler)
148
236
  clearInterval(this.heartbeatIntervalHandler);
@@ -150,6 +238,12 @@ export class CommandResponseStream extends EventEmitter {
150
238
  }
151
239
  }
152
240
  ;
241
+ /**
242
+ * Creates a new RawClient instance.
243
+ *
244
+ * @param options - Client configuration
245
+ * @returns RawClient instance
246
+ */
153
247
  export function getRawClient(options) {
154
248
  return new CommandResponseStream(options);
155
249
  }
@@ -19,51 +19,123 @@
19
19
  import type { Readable } from 'stream';
20
20
  import { type TcpSocketConnectOpts } from 'node:net';
21
21
  import { type ConnectionOptions } from 'node:tls';
22
+ /**
23
+ * TCP socket connection options.
24
+ * Alias for Node.js TcpSocketConnectOpts.
25
+ */
22
26
  export type TcpOption = TcpSocketConnectOpts;
27
+ /**
28
+ * TLS socket connection options.
29
+ * Combines port number with Node.js TLS ConnectionOptions.
30
+ */
23
31
  export type TlsOption = {
24
32
  port: number;
25
33
  } & ConnectionOptions;
34
+ /**
35
+ * Response from a command sent to the Iggy server.
36
+ */
26
37
  export type CommandResponse = {
38
+ /** Response status code (0 indicates success) */
27
39
  status: number;
40
+ /** Length of the response data in bytes */
28
41
  length: number;
42
+ /** Response payload data */
29
43
  data: Buffer;
30
44
  };
45
+ /**
46
+ * Low-level client interface for communicating with the Iggy server.
47
+ * Provides direct access to command sending and event handling.
48
+ */
31
49
  export type RawClient = {
50
+ /** Sends a command to the server and returns the response */
32
51
  sendCommand: (code: number, payload: Buffer, handleResponse?: boolean) => Promise<CommandResponse>;
52
+ /** Whether the client has been authenticated */
33
53
  isAuthenticated: boolean;
54
+ /** Authenticates the client with the server */
34
55
  authenticate: (c: ClientCredentials) => Promise<boolean>;
56
+ /** Destroys the client connection */
35
57
  destroy: () => void;
58
+ /** Registers an event listener */
36
59
  on: (ev: string, cb: (e?: unknown) => void) => void;
60
+ /** Registers a one-time event listener */
37
61
  once: (ev: string, cb: (e?: unknown) => void) => void;
62
+ /** Returns the underlying readable stream */
38
63
  getReadStream: () => Readable;
39
64
  };
65
+ /**
66
+ * Function type that provides a RawClient instance.
67
+ * Used for dependency injection and connection pooling.
68
+ */
40
69
  export type ClientProvider = () => Promise<RawClient>;
70
+ /**
71
+ * Available transport protocols for connecting to the Iggy server.
72
+ */
41
73
  export declare const Transports: readonly ["TCP", "TLS"];
74
+ /**
75
+ * Transport protocol type.
76
+ * Currently supports 'TCP' and 'TLS'.
77
+ */
42
78
  export type TransportType = typeof Transports[number];
79
+ /**
80
+ * Configuration options for automatic reconnection.
81
+ */
43
82
  export type ReconnectOption = {
83
+ /** Whether automatic reconnection is enabled */
44
84
  enabled: boolean;
85
+ /** Interval between reconnection attempts in milliseconds */
45
86
  interval: number;
87
+ /** Maximum number of reconnection attempts */
46
88
  maxRetries: number;
47
89
  };
90
+ /**
91
+ * Union type for transport-specific connection options.
92
+ */
48
93
  export type TransportOption = TcpOption | TlsOption;
94
+ /**
95
+ * Token-based authentication credentials.
96
+ */
49
97
  export type TokenCredentials = {
98
+ /** Authentication token */
50
99
  token: string;
51
100
  };
101
+ /**
102
+ * Username/password authentication credentials.
103
+ */
52
104
  export type PasswordCredentials = {
105
+ /** Username for authentication */
53
106
  username: string;
107
+ /** Password for authentication */
54
108
  password: string;
55
109
  };
110
+ /**
111
+ * Union type for client authentication credentials.
112
+ * Supports either token-based or password-based authentication.
113
+ */
56
114
  export type ClientCredentials = TokenCredentials | PasswordCredentials;
115
+ /**
116
+ * Connection pool size configuration.
117
+ */
57
118
  export type PoolSizeOption = {
119
+ /** Minimum number of connections in the pool */
58
120
  min?: number;
121
+ /** Maximum number of connections in the pool */
59
122
  max?: number;
60
123
  };
124
+ /**
125
+ * Complete client configuration for connecting to the Iggy server.
126
+ */
61
127
  export type ClientConfig = {
128
+ /** Transport protocol to use (TCP or TLS) */
62
129
  transport: TransportType;
130
+ /** Transport-specific connection options */
63
131
  options: TransportOption;
132
+ /** Authentication credentials */
64
133
  credentials: ClientCredentials;
134
+ /** Connection pool size configuration */
65
135
  poolSize?: PoolSizeOption;
136
+ /** Automatic reconnection configuration */
66
137
  reconnect?: ReconnectOption;
138
+ /** Interval for sending heartbeat pings in milliseconds */
67
139
  heartbeatInterval?: number;
68
140
  };
69
141
  //# sourceMappingURL=client.type.d.ts.map
@@ -16,5 +16,8 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ /**
20
+ * Available transport protocols for connecting to the Iggy server.
21
+ */
19
22
  export const Transports = ['TCP', 'TLS' /**, 'QUIC' */];
20
23
  //# sourceMappingURL=client.type.js.map
@@ -18,12 +18,40 @@
18
18
  */
19
19
  import { Transform } from 'node:stream';
20
20
  import type { CommandResponse } from './client.type.js';
21
+ /**
22
+ * Parses a raw response buffer into a structured CommandResponse.
23
+ * Extracts status code, length, and payload data from the buffer.
24
+ *
25
+ * @param r - Raw response buffer from the server
26
+ * @returns Parsed command response with status, length, and data
27
+ */
21
28
  export declare const handleResponse: (r: Buffer) => {
22
29
  status: number;
23
30
  length: number;
24
31
  data: Buffer<ArrayBufferLike>;
25
32
  };
33
+ /**
34
+ * Creates a Transform stream that parses response buffers.
35
+ * Transforms raw server responses into just the data payload.
36
+ *
37
+ * @returns Transform stream for processing server responses
38
+ */
26
39
  export declare const handleResponseTransform: () => Transform;
40
+ /**
41
+ * Deserializes a void response from the server.
42
+ * Returns true if the command succeeded with no data.
43
+ *
44
+ * @param r - Command response to check
45
+ * @returns True if the response indicates success with no data
46
+ */
27
47
  export declare const deserializeVoidResponse: (r: CommandResponse) => boolean;
48
+ /**
49
+ * Serializes a command and its payload into a buffer for sending to the server.
50
+ * Creates the wire format: [payload_size (4 bytes)][command (4 bytes)][payload]
51
+ *
52
+ * @param command - Command code to send
53
+ * @param payload - Command payload buffer
54
+ * @returns Buffer ready to be sent to the server
55
+ */
28
56
  export declare const serializeCommand: (command: number, payload: Buffer) => Buffer<ArrayBuffer>;
29
57
  //# sourceMappingURL=client.utils.d.ts.map
@@ -19,6 +19,13 @@
19
19
  import { Transform } from 'node:stream';
20
20
  import { translateCommandCode } from '../wire/command.code.js';
21
21
  import { debug } from './client.debug.js';
22
+ /**
23
+ * Parses a raw response buffer into a structured CommandResponse.
24
+ * Extracts status code, length, and payload data from the buffer.
25
+ *
26
+ * @param r - Raw response buffer from the server
27
+ * @returns Parsed command response with status, length, and data
28
+ */
22
29
  export const handleResponse = (r) => {
23
30
  const status = r.readUint32LE(0);
24
31
  const length = r.readUint32LE(4);
@@ -27,6 +34,12 @@ export const handleResponse = (r) => {
27
34
  status, length, data: r.subarray(8)
28
35
  };
29
36
  };
37
+ /**
38
+ * Creates a Transform stream that parses response buffers.
39
+ * Transforms raw server responses into just the data payload.
40
+ *
41
+ * @returns Transform stream for processing server responses
42
+ */
30
43
  export const handleResponseTransform = () => new Transform({
31
44
  transform(chunk, encoding, cb) {
32
45
  try {
@@ -39,8 +52,24 @@ export const handleResponseTransform = () => new Transform({
39
52
  }
40
53
  }
41
54
  });
55
+ /**
56
+ * Deserializes a void response from the server.
57
+ * Returns true if the command succeeded with no data.
58
+ *
59
+ * @param r - Command response to check
60
+ * @returns True if the response indicates success with no data
61
+ */
42
62
  export const deserializeVoidResponse = (r) => r.status === 0 && r.data.length === 0;
63
+ /** Length of the command code in bytes */
43
64
  const COMMAND_LENGTH = 4;
65
+ /**
66
+ * Serializes a command and its payload into a buffer for sending to the server.
67
+ * Creates the wire format: [payload_size (4 bytes)][command (4 bytes)][payload]
68
+ *
69
+ * @param command - Command code to send
70
+ * @param payload - Command payload buffer
71
+ * @returns Buffer ready to be sent to the server
72
+ */
44
73
  export const serializeCommand = (command, payload) => {
45
74
  const payloadSize = payload.length + COMMAND_LENGTH;
46
75
  const data = Buffer.allocUnsafe(8 + payload.length);
@@ -20,7 +20,7 @@ import { after, describe, it } from "node:test";
20
20
  import assert from "node:assert/strict";
21
21
  import { getTestClient } from "./test-client.utils.js";
22
22
  // cluster mode still in dev atm
23
- // response is mocked from /core/configs/server.toml
23
+ // response is mocked from /core/server/config.toml
24
24
  const expectedMeta = {
25
25
  name: "iggy-cluster",
26
26
  nodes: [
package/dist/index.d.ts CHANGED
@@ -16,7 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export { type Id, PollingStrategy, Consumer, Partitioning, HeaderValue, } from './wire/index.js';
20
- export * from './client/index.js';
21
- export * from './stream/index.js';
19
+ export { type Id, PollingStrategy, Consumer, Partitioning, HeaderValue, HeaderKeyFactory, } from "./wire/index.js";
20
+ export * from "./client/index.js";
21
+ export * from "./stream/index.js";
22
22
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -16,7 +16,7 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- export { PollingStrategy, Consumer, Partitioning, HeaderValue, } from './wire/index.js';
20
- export * from './client/index.js';
21
- export * from './stream/index.js';
19
+ export { PollingStrategy, Consumer, Partitioning, HeaderValue, HeaderKeyFactory, } from "./wire/index.js";
20
+ export * from "./client/index.js";
21
+ export * from "./stream/index.js";
22
22
  //# sourceMappingURL=index.js.map
@@ -16,79 +16,68 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { type Partitioning, type Message } from './wire/index.js';
20
- import type { ClientProvider } from './client/client.type.js';
21
- import type { Id } from './wire/identifier.utils.js';
19
+ import { type Partitioning, type Message } from "./wire/index.js";
20
+ import type { ClientProvider } from "./client/client.type.js";
21
+ import type { Id } from "./wire/identifier.utils.js";
22
22
  export declare const someMessageContent: () => {
23
23
  payload: string;
24
- headers: {
25
- foo: import("./wire/message/header.type.js").HeaderValueInt32;
26
- bar: import("./wire/message/header.type.js").HeaderValueUint8;
27
- };
28
- Headers?: undefined;
24
+ headers: ({
25
+ key: import("./wire/message/header.type.js").HeaderKeyString;
26
+ value: import("./wire/message/header.type.js").HeaderValueInt32;
27
+ } | {
28
+ key: import("./wire/message/header.type.js").HeaderKeyString;
29
+ value: import("./wire/message/header.type.js").HeaderValueUint8;
30
+ })[];
29
31
  } | {
30
32
  payload: string;
31
33
  headers?: undefined;
32
- Headers?: undefined;
33
34
  } | {
34
35
  payload: string;
35
36
  headers: {
36
- 'x-header-string-1': import("./wire/message/header.type.js").HeaderValueString;
37
- };
38
- Headers?: undefined;
37
+ key: import("./wire/message/header.type.js").HeaderKeyString;
38
+ value: import("./wire/message/header.type.js").HeaderValueString;
39
+ }[];
39
40
  } | {
40
41
  payload: string;
41
42
  headers: {
42
- 'x-header-bool': import("./wire/message/header.type.js").HeaderValueBool;
43
- };
44
- Headers?: undefined;
45
- } | {
46
- payload: string;
47
- Headers: {
48
- 'x-header-bool': import("./wire/message/header.type.js").HeaderValueBool;
49
- };
50
- headers?: undefined;
43
+ key: import("./wire/message/header.type.js").HeaderKeyString;
44
+ value: import("./wire/message/header.type.js").HeaderValueBool;
45
+ }[];
51
46
  };
52
47
  export declare const generateMessages: (count?: number) => ({
53
48
  payload: string;
54
- headers: {
55
- foo: import("./wire/message/header.type.js").HeaderValueInt32;
56
- bar: import("./wire/message/header.type.js").HeaderValueUint8;
57
- };
58
- Headers?: undefined;
49
+ headers: ({
50
+ key: import("./wire/message/header.type.js").HeaderKeyString;
51
+ value: import("./wire/message/header.type.js").HeaderValueInt32;
52
+ } | {
53
+ key: import("./wire/message/header.type.js").HeaderKeyString;
54
+ value: import("./wire/message/header.type.js").HeaderValueUint8;
55
+ })[];
59
56
  id: string;
60
57
  } | {
61
58
  payload: string;
62
59
  headers?: undefined;
63
- Headers?: undefined;
64
60
  id: string;
65
61
  } | {
66
62
  payload: string;
67
63
  headers: {
68
- 'x-header-string-1': import("./wire/message/header.type.js").HeaderValueString;
69
- };
70
- Headers?: undefined;
64
+ key: import("./wire/message/header.type.js").HeaderKeyString;
65
+ value: import("./wire/message/header.type.js").HeaderValueString;
66
+ }[];
71
67
  id: string;
72
68
  } | {
73
69
  payload: string;
74
70
  headers: {
75
- 'x-header-bool': import("./wire/message/header.type.js").HeaderValueBool;
76
- };
77
- Headers?: undefined;
78
- id: string;
79
- } | {
80
- payload: string;
81
- Headers: {
82
- 'x-header-bool': import("./wire/message/header.type.js").HeaderValueBool;
83
- };
84
- headers?: undefined;
71
+ key: import("./wire/message/header.type.js").HeaderKeyString;
72
+ value: import("./wire/message/header.type.js").HeaderValueBool;
73
+ }[];
85
74
  id: string;
86
75
  })[];
87
76
  export declare const sendSomeMessages: (s: ClientProvider) => (streamId: Id, topicId: Id, partition: Partitioning) => Promise<true>;
88
77
  export declare const formatPolledMessages: (msgs: Message[]) => {
89
- id: string | BigInt;
78
+ id: string | bigint;
90
79
  offset: bigint;
91
- headers: import("./wire/message/header.utils.js").HeadersMap;
80
+ headers: import("./wire/message/header.utils.js").ParsedHeaderEntry[];
92
81
  payload: string;
93
82
  timestamp: Date;
94
83
  checksum: bigint;
@@ -16,23 +16,36 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import assert from 'node:assert/strict';
20
- import { v7 } from './wire/uuid.utils.js';
21
- import { sendMessages, HeaderValue } from './wire/index.js';
22
- const h0 = { 'foo': HeaderValue.Int32(42), 'bar': HeaderValue.Uint8(123) };
23
- const h1 = { 'x-header-string-1': HeaderValue.String('incredible') };
24
- const h2 = { 'x-header-bool': HeaderValue.Bool(false) };
19
+ import assert from "node:assert/strict";
20
+ import { v7 } from "./wire/uuid.utils.js";
21
+ import { sendMessages, HeaderValue, HeaderKeyFactory, } from "./wire/index.js";
22
+ const h0 = [
23
+ { key: HeaderKeyFactory.String("foo"), value: HeaderValue.Int32(42) },
24
+ { key: HeaderKeyFactory.String("bar"), value: HeaderValue.Uint8(123) },
25
+ ];
26
+ const h1 = [
27
+ {
28
+ key: HeaderKeyFactory.String("x-header-string-1"),
29
+ value: HeaderValue.String("incredible"),
30
+ },
31
+ ];
32
+ const h2 = [
33
+ {
34
+ key: HeaderKeyFactory.String("x-header-bool"),
35
+ value: HeaderValue.Bool(false),
36
+ },
37
+ ];
25
38
  const messages = [
26
- { payload: 'content with header', headers: h0 },
27
- { payload: 'content solo' },
28
- { payload: 'yolo msg' },
29
- { payload: 'yolo msg 2' },
30
- { payload: 'this is fuu', headers: h1 },
31
- { payload: 'this is bar', headers: h2 },
32
- { payload: 'yolo msg 3' },
33
- { payload: 'fuu again', headers: h1 },
34
- { payload: 'damnit', headers: h0 },
35
- { payload: 'yolo msg 4', Headers: h2 },
39
+ { payload: "content with header", headers: h0 },
40
+ { payload: "content solo" },
41
+ { payload: "yolo msg" },
42
+ { payload: "yolo msg 2" },
43
+ { payload: "this is fuu", headers: h1 },
44
+ { payload: "this is bar", headers: h2 },
45
+ { payload: "yolo msg 3" },
46
+ { payload: "fuu again", headers: h1 },
47
+ { payload: "damnit", headers: h0 },
48
+ { payload: "yolo msg 4", headers: h2 },
36
49
  ];
37
50
  export const someMessageContent = () => messages[Math.floor(Math.random() * messages.length)];
38
51
  export const generateMessages = (count = 1) => {
@@ -40,25 +53,28 @@ export const generateMessages = (count = 1) => {
40
53
  };
41
54
  export const sendSomeMessages = (s) => async (streamId, topicId, partition) => {
42
55
  const rSend = await sendMessages(s)({
43
- topicId, streamId, messages: generateMessages(100), partition
56
+ topicId,
57
+ streamId,
58
+ messages: generateMessages(100),
59
+ partition,
44
60
  });
45
61
  assert.ok(rSend);
46
62
  return rSend;
47
63
  };
48
- export const formatPolledMessages = (msgs) => msgs.map(m => {
49
- const { headers: { id, offset, timestamp, checksum }, payload, userHeaders } = m;
64
+ export const formatPolledMessages = (msgs) => msgs.map((m) => {
65
+ const { headers: { id, offset, timestamp, checksum }, payload, userHeaders, } = m;
50
66
  return {
51
67
  id,
52
68
  offset,
53
69
  headers: userHeaders,
54
70
  payload: payload.toString(),
55
71
  timestamp,
56
- checksum
72
+ checksum,
57
73
  };
58
74
  });
59
- export const getIggyAddress = (host = '127.0.0.1', port = 8090) => {
75
+ export const getIggyAddress = (host = "127.0.0.1", port = 8090) => {
60
76
  if (process.env.IGGY_TCP_ADDRESS) {
61
- const s = (process.env.IGGY_TCP_ADDRESS || '').split(':');
77
+ const s = (process.env.IGGY_TCP_ADDRESS || "").split(":");
62
78
  [host, port] = [s[0], s[1] ? parseInt(s[1].toString(), 10) : port];
63
79
  }
64
80
  return [host, port];
@@ -16,6 +16,20 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ /**
20
+ * Reverses the keys and values of a record object.
21
+ * Creates a new record where the original values become keys and vice versa.
22
+ *
23
+ * @typeParam T - Type of the original keys
24
+ * @typeParam U - Type of the original values (becomes keys in result)
25
+ * @param input - Record object to reverse
26
+ * @returns New record with swapped keys and values
27
+ */
19
28
  export declare function reverseRecord<T extends PropertyKey, U extends PropertyKey>(input: Record<T, U>): Record<U, T>;
29
+ /**
30
+ * Extracts the value types from an object type.
31
+ *
32
+ * @typeParam T - Object type to extract values from
33
+ */
20
34
  export type ValueOf<T> = T[keyof T];
21
35
  //# sourceMappingURL=type.utils.d.ts.map