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
@@ -19,17 +19,77 @@
19
19
  import { type Headers } from './header.utils.js';
20
20
  import { type Id } from '../identifier.utils.js';
21
21
  import { type Partitioning } from './partitioning.utils.js';
22
+ /** Valid types for message ID: numeric, bigint, or UUID string */
22
23
  export type MessageIdKind = number | bigint | string;
24
+ /**
25
+ * Message creation parameters.
26
+ */
23
27
  export type CreateMessage = {
28
+ /** Optional message ID (auto-generated if not provided) */
24
29
  id?: MessageIdKind;
30
+ /** Optional user-defined headers */
25
31
  headers?: Headers;
32
+ /** Message payload as string or Buffer */
26
33
  payload: string | Buffer;
27
34
  };
35
+ /**
36
+ * Type guard to check if a value is a valid message ID.
37
+ *
38
+ * @param x - Value to check
39
+ * @returns True if the value is a valid MessageIdKind
40
+ */
28
41
  export declare const isValidMessageId: (x?: unknown) => x is MessageIdKind;
42
+ /**
43
+ * Serializes a message ID to a 16-byte buffer.
44
+ * Supports undefined (zero), numeric, bigint, and UUID string formats.
45
+ *
46
+ * @param id - Message ID to serialize
47
+ * @returns 16-byte buffer containing the serialized ID
48
+ * @throws Error if the ID format is invalid
49
+ */
29
50
  export declare const serializeMessageId: (id?: unknown) => Buffer<ArrayBufferLike>;
51
+ /**
52
+ * Serializes a single message to wire format.
53
+ * Format: [iggy_header][payload][user_headers]
54
+ *
55
+ * @param msg - Message to serialize
56
+ * @returns Serialized message buffer
57
+ */
30
58
  export declare const serializeMessage: (msg: CreateMessage) => Buffer<ArrayBuffer>;
59
+ /**
60
+ * Serializes multiple messages to an array of buffers.
61
+ *
62
+ * @param messages - Array of messages to serialize
63
+ * @returns Array of serialized message buffers
64
+ */
31
65
  export declare const serializeMessages: (messages: CreateMessage[]) => Buffer<ArrayBuffer>[];
66
+ /**
67
+ * Creates an index buffer for a batch of messages.
68
+ * Each index entry is 16 bytes tracking message positions.
69
+ *
70
+ * @param messages - Array of serialized message buffers
71
+ * @returns Index buffer
72
+ */
32
73
  export declare const createMessagesIndex: (messages: Buffer[]) => Buffer<ArrayBuffer>;
74
+ /**
75
+ * Serializes a send messages command payload.
76
+ * Includes stream/topic identifiers, partitioning, and all messages with index.
77
+ *
78
+ * @param streamId - Stream identifier
79
+ * @param topicId - Topic identifier
80
+ * @param messages - Array of messages to send
81
+ * @param partitioning - Optional partitioning strategy
82
+ * @returns Serialized command payload
83
+ */
33
84
  export declare const serializeSendMessages: (streamId: Id, topicId: Id, messages: CreateMessage[], partitioning?: Partitioning) => Buffer<ArrayBuffer>;
85
+ /**
86
+ * Serializes a flush unsaved buffers command payload.
87
+ *
88
+ * @param streamId - Stream identifier
89
+ * @param topicId - Topic identifier
90
+ * @param partitionId - Partition ID to flush
91
+ * @param fsync - Whether to force sync to disk
92
+ * @returns Serialized command payload
93
+ */
34
94
  export declare const serializeFlushUnsavedBuffers: (streamId: Id, topicId: Id, partitionId: number, fsync?: boolean) => Buffer<ArrayBuffer>;
35
95
  //# sourceMappingURL=message.utils.d.ts.map
@@ -24,12 +24,26 @@ import { serializePartitioning } from './partitioning.utils.js';
24
24
  import { parse as parseUUID } from '../uuid.utils.js';
25
25
  import { serializeIggyMessageHeader } from './iggy-header.utils.js';
26
26
  const debug = Debug('iggy:client');
27
- /** index size per messages in bit */
27
+ /** Size of the message index entry in bytes (16 bytes per message) */
28
28
  const INDEX_SIZE = 16;
29
+ /**
30
+ * Type guard to check if a value is a valid message ID.
31
+ *
32
+ * @param x - Value to check
33
+ * @returns True if the value is a valid MessageIdKind
34
+ */
29
35
  export const isValidMessageId = (x) => x === undefined ||
30
36
  'string' === typeof x ||
31
37
  'bigint' === typeof x ||
32
38
  'number' === typeof x;
39
+ /**
40
+ * Serializes a message ID to a 16-byte buffer.
41
+ * Supports undefined (zero), numeric, bigint, and UUID string formats.
42
+ *
43
+ * @param id - Message ID to serialize
44
+ * @returns 16-byte buffer containing the serialized ID
45
+ * @throws Error if the ID format is invalid
46
+ */
33
47
  export const serializeMessageId = (id) => {
34
48
  if (!isValidMessageId(id))
35
49
  throw new Error(`invalid message id: '${id}' (use uuid string | number | bigint >= 0)`);
@@ -49,6 +63,13 @@ export const serializeMessageId = (id) => {
49
63
  throw new Error(`invalid message id: '${id}' (use uuid string | number | bigint >= 0)`, { cause: err });
50
64
  }
51
65
  };
66
+ /**
67
+ * Serializes a single message to wire format.
68
+ * Format: [iggy_header][payload][user_headers]
69
+ *
70
+ * @param msg - Message to serialize
71
+ * @returns Serialized message buffer
72
+ */
52
73
  export const serializeMessage = (msg) => {
53
74
  const { id, headers, payload } = msg;
54
75
  const bId = serializeMessageId(id);
@@ -64,7 +85,20 @@ export const serializeMessage = (msg) => {
64
85
  );
65
86
  return r;
66
87
  };
88
+ /**
89
+ * Serializes multiple messages to an array of buffers.
90
+ *
91
+ * @param messages - Array of messages to serialize
92
+ * @returns Array of serialized message buffers
93
+ */
67
94
  export const serializeMessages = (messages) => messages.map(c => serializeMessage(c));
95
+ /**
96
+ * Creates an index buffer for a batch of messages.
97
+ * Each index entry is 16 bytes tracking message positions.
98
+ *
99
+ * @param messages - Array of serialized message buffers
100
+ * @returns Index buffer
101
+ */
68
102
  export const createMessagesIndex = (messages) => {
69
103
  const bIndex = Buffer.allocUnsafe(messages.length * INDEX_SIZE);
70
104
  let currentIndex = 0;
@@ -78,6 +112,16 @@ export const createMessagesIndex = (messages) => {
78
112
  });
79
113
  return bIndex;
80
114
  };
115
+ /**
116
+ * Serializes a send messages command payload.
117
+ * Includes stream/topic identifiers, partitioning, and all messages with index.
118
+ *
119
+ * @param streamId - Stream identifier
120
+ * @param topicId - Topic identifier
121
+ * @param messages - Array of messages to send
122
+ * @param partitioning - Optional partitioning strategy
123
+ * @returns Serialized command payload
124
+ */
81
125
  export const serializeSendMessages = (streamId, topicId, messages, partitioning) => {
82
126
  const streamIdentifier = serializeIdentifier(streamId);
83
127
  const topicIdentifier = serializeIdentifier(topicId);
@@ -97,6 +141,15 @@ export const serializeSendMessages = (streamId, topicId, messages, partitioning)
97
141
  ...bMessagesArray
98
142
  ]);
99
143
  };
144
+ /**
145
+ * Serializes a flush unsaved buffers command payload.
146
+ *
147
+ * @param streamId - Stream identifier
148
+ * @param topicId - Topic identifier
149
+ * @param partitionId - Partition ID to flush
150
+ * @param fsync - Whether to force sync to disk
151
+ * @returns Serialized command payload
152
+ */
100
153
  export const serializeFlushUnsavedBuffers = (streamId, topicId, partitionId, fsync = false) => {
101
154
  const streamIdentifier = serializeIdentifier(streamId);
102
155
  const topicIdentifier = serializeIdentifier(topicId);
@@ -17,35 +17,74 @@
17
17
  * under the License.
18
18
  */
19
19
  import type { ValueOf } from '../../type.utils.js';
20
+ /**
21
+ * Enumeration of partition selection strategies.
22
+ */
20
23
  export declare const PartitionKind: {
24
+ /** Server selects partition using round-robin */
21
25
  readonly Balanced: 1;
26
+ /** Client specifies exact partition ID */
22
27
  readonly PartitionId: 2;
28
+ /** Client provides a key for consistent hashing */
23
29
  readonly MessageKey: 3;
24
30
  };
31
+ /** Type alias for the PartitionKind object */
25
32
  export type PartitionKind = typeof PartitionKind;
33
+ /** String literal type of partition kind names */
26
34
  export type PartitionKindId = keyof PartitionKind;
35
+ /** Numeric values of partition kinds */
27
36
  export type PartitionKindValue = ValueOf<PartitionKind>;
37
+ /** Balanced partitioning (server selects partition) */
28
38
  export type Balanced = {
29
39
  kind: PartitionKind['Balanced'];
30
40
  value: null;
31
41
  };
42
+ /** Explicit partition ID selection */
32
43
  export type PartitionId = {
33
44
  kind: PartitionKind['PartitionId'];
45
+ /** Partition ID (uint32) */
34
46
  value: number;
35
47
  };
48
+ /** Possible types for message key values */
36
49
  export type MessageKeyValue = string | number | bigint | Buffer;
50
+ /** Message key-based partitioning for consistent hashing */
37
51
  export type MessageKey = {
38
52
  kind: PartitionKind['MessageKey'];
39
53
  value: MessageKeyValue;
40
54
  };
55
+ /** Union of all partitioning strategies */
41
56
  export type Partitioning = Balanced | PartitionId | MessageKey;
57
+ /**
58
+ * Factory object for creating partitioning strategies.
59
+ */
42
60
  export declare const Partitioning: {
43
61
  Balanced: Balanced;
44
62
  PartitionId: (id: number) => PartitionId;
45
63
  MessageKey: (key: MessageKeyValue) => MessageKey;
46
64
  };
65
+ /**
66
+ * Serializes a message key value to a buffer.
67
+ *
68
+ * @param v - Message key value
69
+ * @returns Serialized buffer
70
+ * @throws Error if the value type is not supported
71
+ */
47
72
  export declare const serializeMessageKey: (v: MessageKeyValue) => Buffer<ArrayBufferLike>;
73
+ /**
74
+ * Serializes the value portion of a partitioning strategy.
75
+ *
76
+ * @param part - Partitioning strategy
77
+ * @returns Serialized value buffer
78
+ */
48
79
  export declare const serializePartitioningValue: (part: Partitioning) => Buffer;
80
+ /** Default partitioning strategy (balanced) */
49
81
  export declare const default_partionning: Balanced;
82
+ /**
83
+ * Serializes a partitioning strategy to wire format.
84
+ * Format: [kind (1 byte)][value_length (1 byte)][value]
85
+ *
86
+ * @param p - Optional partitioning strategy (defaults to balanced)
87
+ * @returns Serialized partitioning buffer
88
+ */
50
89
  export declare const serializePartitioning: (p?: Partitioning) => Buffer<ArrayBuffer>;
51
90
  //# sourceMappingURL=partitioning.utils.d.ts.map
@@ -17,29 +17,57 @@
17
17
  * under the License.
18
18
  */
19
19
  import { uint32ToBuf, uint64ToBuf } from '../number.utils.js';
20
+ /**
21
+ * Enumeration of partition selection strategies.
22
+ */
20
23
  export const PartitionKind = {
24
+ /** Server selects partition using round-robin */
21
25
  Balanced: 1,
26
+ /** Client specifies exact partition ID */
22
27
  PartitionId: 2,
28
+ /** Client provides a key for consistent hashing */
23
29
  MessageKey: 3
24
30
  };
31
+ /** Balanced partitioning constant */
25
32
  const Balanced = {
26
33
  kind: PartitionKind.Balanced,
27
34
  value: null
28
35
  };
36
+ /**
37
+ * Creates a partition ID partitioning strategy.
38
+ *
39
+ * @param id - Partition ID to target
40
+ * @returns PartitionId partitioning object
41
+ */
29
42
  const PartitionId = (id) => ({
30
43
  kind: PartitionKind.PartitionId,
31
44
  value: id
32
45
  });
46
+ /**
47
+ * Creates a message key partitioning strategy.
48
+ *
49
+ * @param key - Key for consistent hashing
50
+ * @returns MessageKey partitioning object
51
+ */
33
52
  const MessageKey = (key) => ({
34
53
  kind: PartitionKind.MessageKey,
35
54
  value: key
36
55
  });
37
- // Helper
56
+ /**
57
+ * Factory object for creating partitioning strategies.
58
+ */
38
59
  export const Partitioning = {
39
60
  Balanced,
40
61
  PartitionId,
41
62
  MessageKey
42
63
  };
64
+ /**
65
+ * Serializes a message key value to a buffer.
66
+ *
67
+ * @param v - Message key value
68
+ * @returns Serialized buffer
69
+ * @throws Error if the value type is not supported
70
+ */
43
71
  export const serializeMessageKey = (v) => {
44
72
  if (v instanceof Buffer)
45
73
  return v;
@@ -51,6 +79,12 @@ export const serializeMessageKey = (v) => {
51
79
  return uint64ToBuf(v);
52
80
  throw new Error(`cannot serialize messageKey ${v}, ${typeof v}`);
53
81
  };
82
+ /**
83
+ * Serializes the value portion of a partitioning strategy.
84
+ *
85
+ * @param part - Partitioning strategy
86
+ * @returns Serialized value buffer
87
+ */
54
88
  export const serializePartitioningValue = (part) => {
55
89
  const { kind, value } = part;
56
90
  switch (kind) {
@@ -59,10 +93,18 @@ export const serializePartitioningValue = (part) => {
59
93
  case PartitionKind.MessageKey: return serializeMessageKey(value);
60
94
  }
61
95
  };
96
+ /** Default partitioning strategy (balanced) */
62
97
  export const default_partionning = {
63
98
  kind: PartitionKind.Balanced,
64
99
  value: null
65
100
  };
101
+ /**
102
+ * Serializes a partitioning strategy to wire format.
103
+ * Format: [kind (1 byte)][value_length (1 byte)][value]
104
+ *
105
+ * @param p - Optional partitioning strategy (defaults to balanced)
106
+ * @returns Serialized partitioning buffer
107
+ */
66
108
  export const serializePartitioning = (p) => {
67
109
  const part = p || default_partionning;
68
110
  const b = Buffer.alloc(2);
@@ -20,15 +20,29 @@ import type { Id } from '../identifier.utils.js';
20
20
  import type { CommandResponse } from '../../client/client.type.js';
21
21
  import type { Consumer } from '../offset/offset.utils.js';
22
22
  import { type PollingStrategy, type PollMessagesResponse } from './poll.utils.js';
23
+ /**
24
+ * Parameters for the poll messages command.
25
+ */
23
26
  export type PollMessages = {
27
+ /** Stream identifier */
24
28
  streamId: Id;
29
+ /** Topic identifier */
25
30
  topicId: Id;
31
+ /** Consumer configuration */
26
32
  consumer: Consumer;
33
+ /** Partition ID (null for all partitions) */
27
34
  partitionId: number | null;
35
+ /** Strategy for selecting messages */
28
36
  pollingStrategy: PollingStrategy;
37
+ /** Maximum number of messages to poll */
29
38
  count: number;
39
+ /** Whether to auto-commit offset after polling */
30
40
  autocommit: boolean;
31
41
  };
42
+ /**
43
+ * Poll messages command definition.
44
+ * Retrieves messages from a topic partition.
45
+ */
32
46
  export declare const POLL_MESSAGES: {
33
47
  code: number;
34
48
  serialize: ({ streamId, topicId, consumer, partitionId, pollingStrategy, count, autocommit }: PollMessages) => Buffer<ArrayBuffer>;
@@ -39,5 +53,8 @@ export declare const POLL_MESSAGES: {
39
53
  messages: import("./poll.utils.js").Message[];
40
54
  };
41
55
  };
56
+ /**
57
+ * Executable poll messages command function.
58
+ */
42
59
  export declare const pollMessages: (getClient: import("../../client/client.type.js").ClientProvider) => (arg: PollMessages) => Promise<PollMessagesResponse>;
43
60
  //# sourceMappingURL=poll-messages.command.d.ts.map
@@ -19,6 +19,10 @@
19
19
  import { wrapCommand } from '../command.utils.js';
20
20
  import { COMMAND_CODE } from '../command.code.js';
21
21
  import { serializePollMessages, deserializePollMessages } from './poll.utils.js';
22
+ /**
23
+ * Poll messages command definition.
24
+ * Retrieves messages from a topic partition.
25
+ */
22
26
  export const POLL_MESSAGES = {
23
27
  code: COMMAND_CODE.PollMessages,
24
28
  serialize: ({ streamId, topicId, consumer, partitionId, pollingStrategy, count, autocommit }) => {
@@ -28,5 +32,8 @@ export const POLL_MESSAGES = {
28
32
  return deserializePollMessages(r.data);
29
33
  }
30
34
  };
35
+ /**
36
+ * Executable poll messages command function.
37
+ */
31
38
  export const pollMessages = wrapCommand(POLL_MESSAGES);
32
39
  //# sourceMappingURL=poll-messages.command.js.map
@@ -16,43 +16,65 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { type Id } from '../identifier.utils.js';
20
- import { type ValueOf } from '../../type.utils.js';
21
- import { type Consumer } from '../offset/offset.utils.js';
22
- import { type HeadersMap } from './header.utils.js';
23
- import { Transform } from 'node:stream';
24
- import { IggyMessageHeader } from './iggy-header.utils.js';
19
+ import { type Id } from "../identifier.utils.js";
20
+ import { type ValueOf } from "../../type.utils.js";
21
+ import { type Consumer } from "../offset/offset.utils.js";
22
+ import { type ParsedHeaderEntry } from "./header.utils.js";
23
+ import { Transform } from "node:stream";
24
+ import { type IggyMessageHeader } from "./iggy-header.utils.js";
25
+ /**
26
+ * Enumeration of message polling strategies.
27
+ */
25
28
  export declare const PollingStrategyKind: {
29
+ /** Poll from a specific offset */
26
30
  readonly Offset: 1;
31
+ /** Poll from a specific timestamp */
27
32
  readonly Timestamp: 2;
33
+ /** Poll from the first message */
28
34
  readonly First: 3;
35
+ /** Poll from the last message */
29
36
  readonly Last: 4;
37
+ /** Poll the next unconsumed message */
30
38
  readonly Next: 5;
31
39
  };
40
+ /** Type alias for the PollingStrategyKind object */
32
41
  export type PollingStrategyKind = typeof PollingStrategyKind;
42
+ /** String literal type of polling strategy names */
33
43
  export type PollingStrategyKindId = keyof PollingStrategyKind;
44
+ /** Numeric values of polling strategies */
34
45
  export type PollingStrategyKindValue = ValueOf<PollingStrategyKind>;
46
+ /** Polling from a specific offset */
35
47
  export type OffsetPollingStrategy = {
36
- kind: PollingStrategyKind['Offset'];
48
+ kind: PollingStrategyKind["Offset"];
49
+ /** Offset to start polling from */
37
50
  value: bigint;
38
51
  };
52
+ /** Polling from a specific timestamp */
39
53
  export type TimestampPollingStrategy = {
40
- kind: PollingStrategyKind['Timestamp'];
54
+ kind: PollingStrategyKind["Timestamp"];
55
+ /** Timestamp in microseconds */
41
56
  value: bigint;
42
57
  };
58
+ /** Polling from the first message */
43
59
  export type FirstPollingStrategy = {
44
- kind: PollingStrategyKind['First'];
60
+ kind: PollingStrategyKind["First"];
45
61
  value: 0n;
46
62
  };
63
+ /** Polling from the last message */
47
64
  export type LastPollingStrategy = {
48
- kind: PollingStrategyKind['Last'];
65
+ kind: PollingStrategyKind["Last"];
49
66
  value: 0n;
50
67
  };
68
+ /** Polling the next unconsumed message */
51
69
  export type NextPollingStrategy = {
52
- kind: PollingStrategyKind['Next'];
70
+ kind: PollingStrategyKind["Next"];
53
71
  value: 0n;
54
72
  };
73
+ /** Union of all polling strategy types */
55
74
  export type PollingStrategy = OffsetPollingStrategy | TimestampPollingStrategy | FirstPollingStrategy | LastPollingStrategy | NextPollingStrategy;
75
+ /**
76
+ * Factory object for creating polling strategies.
77
+ */
56
78
  export declare const PollingStrategy: {
57
79
  Next: NextPollingStrategy;
58
80
  First: FirstPollingStrategy;
@@ -60,35 +82,94 @@ export declare const PollingStrategy: {
60
82
  Offset: (n: bigint) => OffsetPollingStrategy;
61
83
  Timestamp: (n: bigint) => TimestampPollingStrategy;
62
84
  };
85
+ /**
86
+ * Serializes a poll messages command payload.
87
+ *
88
+ * @param streamId - Stream identifier
89
+ * @param topicId - Topic identifier
90
+ * @param consumer - Consumer configuration
91
+ * @param partitionId - Partition ID (null for all partitions)
92
+ * @param pollingStrategy - Strategy for selecting messages
93
+ * @param count - Maximum number of messages to poll
94
+ * @param autocommit - Whether to auto-commit offset after polling
95
+ * @returns Serialized command payload
96
+ */
63
97
  export declare const serializePollMessages: (streamId: Id, topicId: Id, consumer: Consumer, partitionId: number | null, pollingStrategy: PollingStrategy, // default to OffsetPollingStrategy
64
98
  count?: number, autocommit?: boolean) => Buffer<ArrayBuffer>;
99
+ /**
100
+ * Enumeration of message states.
101
+ */
65
102
  export declare const MessageState: {
103
+ /** Message is available for consumption */
66
104
  Available: number;
105
+ /** Message is temporarily unavailable */
67
106
  Unavailable: number;
107
+ /** Message processing failed */
68
108
  Poisoned: number;
109
+ /** Message is scheduled for deletion */
69
110
  MarkedForDeletion: number;
70
111
  };
112
+ /** Type alias for the MessageState object */
71
113
  type MessageState = typeof MessageState;
114
+ /** String literal type of message state names */
72
115
  type MessageStateId = keyof MessageState;
116
+ /**
117
+ * Maps a numeric message state to its string identifier.
118
+ *
119
+ * @param k - Numeric state value
120
+ * @returns State identifier string
121
+ * @throws Error if the state is unknown
122
+ */
73
123
  export declare const mapMessageState: (k: number) => MessageStateId;
124
+ /**
125
+ * A polled message with headers, payload, and user headers.
126
+ */
74
127
  export type Message = {
128
+ /** Iggy message header metadata */
75
129
  headers: IggyMessageHeader;
130
+ /** Message payload data */
76
131
  payload: Buffer;
77
- userHeaders: HeadersMap;
132
+ /** User-defined headers */
133
+ userHeaders: ParsedHeaderEntry[];
78
134
  };
135
+ /**
136
+ * Response from a poll messages command.
137
+ */
79
138
  export type PollMessagesResponse = {
139
+ /** Partition the messages came from */
80
140
  partitionId: number;
141
+ /** Current offset in the partition */
81
142
  currentOffset: bigint;
143
+ /** Number of messages returned */
82
144
  count: number;
145
+ /** Array of polled messages */
83
146
  messages: Message[];
84
147
  };
148
+ /**
149
+ * Deserializes an array of messages from a buffer.
150
+ *
151
+ * @param b - Buffer containing serialized messages
152
+ * @returns Array of deserialized messages
153
+ */
85
154
  export declare const deserializeMessages: (b: Buffer) => Message[];
155
+ /**
156
+ * Deserializes a poll messages response from a buffer.
157
+ *
158
+ * @param r - Response buffer
159
+ * @param pos - Starting position
160
+ * @returns Parsed PollMessagesResponse
161
+ */
86
162
  export declare const deserializePollMessages: (r: Buffer, pos?: number) => {
87
163
  partitionId: number;
88
164
  currentOffset: bigint;
89
165
  count: number;
90
166
  messages: Message[];
91
167
  };
168
+ /**
169
+ * Creates a Transform stream for deserializing poll messages responses.
170
+ *
171
+ * @returns Transform stream that outputs PollMessagesResponse objects
172
+ */
92
173
  export declare const deserializePollMessagesTransform: () => Transform;
93
174
  export {};
94
175
  //# sourceMappingURL=poll.utils.d.ts.map