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
@@ -16,46 +16,83 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { reverseRecord } from '../../type.utils.js';
20
- import { serializeGetOffset } from '../offset/offset.utils.js';
21
- import { deserializeHeaders } from './header.utils.js';
22
- import { Transform } from 'node:stream';
23
- import { deserializeIggyMessageHeaders, IGGY_MESSAGE_HEADER_SIZE } from './iggy-header.utils.js';
19
+ import { reverseRecord } from "../../type.utils.js";
20
+ import { serializeGetOffset } from "../offset/offset.utils.js";
21
+ import { deserializeHeaders } from "./header.utils.js";
22
+ import { Transform } from "node:stream";
23
+ import { deserializeIggyMessageHeaders, IGGY_MESSAGE_HEADER_SIZE, } from "./iggy-header.utils.js";
24
+ /**
25
+ * Enumeration of message polling strategies.
26
+ */
24
27
  export const PollingStrategyKind = {
28
+ /** Poll from a specific offset */
25
29
  Offset: 1,
30
+ /** Poll from a specific timestamp */
26
31
  Timestamp: 2,
32
+ /** Poll from the first message */
27
33
  First: 3,
34
+ /** Poll from the last message */
28
35
  Last: 4,
29
- Next: 5
36
+ /** Poll the next unconsumed message */
37
+ Next: 5,
30
38
  };
39
+ /** Next polling strategy constant */
31
40
  const Next = {
32
41
  kind: PollingStrategyKind.Next,
33
- value: 0n
42
+ value: 0n,
34
43
  };
44
+ /** First polling strategy constant */
35
45
  const First = {
36
46
  kind: PollingStrategyKind.First,
37
- value: 0n
47
+ value: 0n,
38
48
  };
49
+ /** Last polling strategy constant */
39
50
  const Last = {
40
51
  kind: PollingStrategyKind.Last,
41
- value: 0n
52
+ value: 0n,
42
53
  };
54
+ /**
55
+ * Creates an offset polling strategy.
56
+ *
57
+ * @param n - Offset to start from
58
+ * @returns Offset polling strategy
59
+ */
43
60
  const Offset = (n) => ({
44
61
  kind: PollingStrategyKind.Offset,
45
- value: n
62
+ value: n,
46
63
  });
64
+ /**
65
+ * Creates a timestamp polling strategy.
66
+ *
67
+ * @param n - Timestamp in microseconds
68
+ * @returns Timestamp polling strategy
69
+ */
47
70
  const Timestamp = (n) => ({
48
71
  kind: PollingStrategyKind.Timestamp,
49
- value: n
72
+ value: n,
50
73
  });
51
- // helper
74
+ /**
75
+ * Factory object for creating polling strategies.
76
+ */
52
77
  export const PollingStrategy = {
53
78
  Next,
54
79
  First,
55
80
  Last,
56
81
  Offset,
57
- Timestamp
82
+ Timestamp,
58
83
  };
84
+ /**
85
+ * Serializes a poll messages command payload.
86
+ *
87
+ * @param streamId - Stream identifier
88
+ * @param topicId - Topic identifier
89
+ * @param consumer - Consumer configuration
90
+ * @param partitionId - Partition ID (null for all partitions)
91
+ * @param pollingStrategy - Strategy for selecting messages
92
+ * @param count - Maximum number of messages to poll
93
+ * @param autocommit - Whether to auto-commit offset after polling
94
+ * @returns Serialized command payload
95
+ */
59
96
  export const serializePollMessages = (streamId, topicId, consumer, partitionId, pollingStrategy, // default to OffsetPollingStrategy
60
97
  count = 10, autocommit = false) => {
61
98
  const b = Buffer.allocUnsafe(14);
@@ -65,21 +102,42 @@ count = 10, autocommit = false) => {
65
102
  b.writeUInt8(!!autocommit ? 1 : 0, 13);
66
103
  return Buffer.concat([
67
104
  serializeGetOffset(streamId, topicId, consumer, partitionId),
68
- b
105
+ b,
69
106
  ]);
70
107
  };
108
+ /**
109
+ * Enumeration of message states.
110
+ */
71
111
  export const MessageState = {
112
+ /** Message is available for consumption */
72
113
  Available: 1,
114
+ /** Message is temporarily unavailable */
73
115
  Unavailable: 10,
116
+ /** Message processing failed */
74
117
  Poisoned: 20,
75
- MarkedForDeletion: 30
118
+ /** Message is scheduled for deletion */
119
+ MarkedForDeletion: 30,
76
120
  };
121
+ /** Reverse mapping from numeric value to state name */
77
122
  const ReverseMessageState = reverseRecord(MessageState);
123
+ /**
124
+ * Maps a numeric message state to its string identifier.
125
+ *
126
+ * @param k - Numeric state value
127
+ * @returns State identifier string
128
+ * @throws Error if the state is unknown
129
+ */
78
130
  export const mapMessageState = (k) => {
79
131
  if (!ReverseMessageState[k])
80
132
  throw new Error(`unknow message state: ${k}`);
81
133
  return ReverseMessageState[k];
82
134
  };
135
+ /**
136
+ * Deserializes an array of messages from a buffer.
137
+ *
138
+ * @param b - Buffer containing serialized messages
139
+ * @returns Array of deserialized messages
140
+ */
83
141
  export const deserializeMessages = (b) => {
84
142
  const messages = [];
85
143
  let pos = 0;
@@ -95,19 +153,27 @@ export const deserializeMessages = (b) => {
95
153
  break;
96
154
  const payload = b.subarray(pos, plEnd);
97
155
  pos += headers.payloadLength;
98
- let userHeaders = {};
99
- if (headers.userHeadersLength > 0 && plEnd + headers.userHeadersLength <= len) {
156
+ let userHeaders = [];
157
+ if (headers.userHeadersLength > 0 &&
158
+ plEnd + headers.userHeadersLength <= len) {
100
159
  userHeaders = deserializeHeaders(b.subarray(plEnd, plEnd + headers.userHeadersLength));
101
160
  pos += headers.userHeadersLength;
102
161
  }
103
162
  messages.push({
104
163
  headers,
105
164
  payload,
106
- userHeaders
165
+ userHeaders,
107
166
  });
108
167
  }
109
168
  return messages;
110
169
  };
170
+ /**
171
+ * Deserializes a poll messages response from a buffer.
172
+ *
173
+ * @param r - Response buffer
174
+ * @param pos - Starting position
175
+ * @returns Parsed PollMessagesResponse
176
+ */
111
177
  export const deserializePollMessages = (r, pos = 0) => {
112
178
  const partitionId = r.readUInt32LE(pos);
113
179
  const currentOffset = r.readBigUInt64LE(pos + 4);
@@ -117,9 +183,14 @@ export const deserializePollMessages = (r, pos = 0) => {
117
183
  partitionId,
118
184
  currentOffset,
119
185
  count,
120
- messages
186
+ messages,
121
187
  };
122
188
  };
189
+ /**
190
+ * Creates a Transform stream for deserializing poll messages responses.
191
+ *
192
+ * @returns Transform stream that outputs PollMessagesResponse objects
193
+ */
123
194
  export const deserializePollMessagesTransform = () => new Transform({
124
195
  objectMode: true,
125
196
  transform(chunk, encoding, cb) {
@@ -127,8 +198,8 @@ export const deserializePollMessagesTransform = () => new Transform({
127
198
  return cb(null, deserializePollMessages(chunk));
128
199
  }
129
200
  catch (err) {
130
- cb(new Error('deserializePollMessage::transform error', { cause: err }), null);
201
+ cb(new Error("deserializePollMessage::transform error", { cause: err }), null);
131
202
  }
132
- }
203
+ },
133
204
  });
134
205
  //# sourceMappingURL=poll.utils.js.map
@@ -19,16 +19,30 @@
19
19
  import { type Id } from '../identifier.utils.js';
20
20
  import { type CreateMessage } from './message.utils.js';
21
21
  import type { Partitioning } from './partitioning.utils.js';
22
+ /**
23
+ * Parameters for the send messages command.
24
+ */
22
25
  export type SendMessages = {
26
+ /** Stream identifier */
23
27
  streamId: Id;
28
+ /** Topic identifier */
24
29
  topicId: Id;
30
+ /** Array of messages to send */
25
31
  messages: CreateMessage[];
32
+ /** Optional partitioning strategy */
26
33
  partition?: Partitioning;
27
34
  };
35
+ /**
36
+ * Send messages command definition.
37
+ * Publishes messages to a topic.
38
+ */
28
39
  export declare const SEND_MESSAGES: {
29
40
  code: number;
30
41
  serialize: ({ streamId, topicId, messages, partition }: SendMessages) => Buffer<ArrayBuffer>;
31
42
  deserialize: (r: import("../../index.js").CommandResponse) => boolean;
32
43
  };
44
+ /**
45
+ * Executable send messages command function.
46
+ */
33
47
  export declare const sendMessages: (getClient: import("../../index.js").ClientProvider) => (arg: SendMessages) => Promise<boolean>;
34
48
  //# sourceMappingURL=send-messages.command.d.ts.map
@@ -20,6 +20,10 @@ import { serializeSendMessages } from './message.utils.js';
20
20
  import { deserializeVoidResponse } from '../../client/client.utils.js';
21
21
  import { wrapCommand } from '../command.utils.js';
22
22
  import { COMMAND_CODE } from '../command.code.js';
23
+ /**
24
+ * Send messages command definition.
25
+ * Publishes messages to a topic.
26
+ */
23
27
  export const SEND_MESSAGES = {
24
28
  code: COMMAND_CODE.SendMessages,
25
29
  serialize: ({ streamId, topicId, messages, partition }) => {
@@ -27,5 +31,8 @@ export const SEND_MESSAGES = {
27
31
  },
28
32
  deserialize: deserializeVoidResponse
29
33
  };
34
+ /**
35
+ * Executable send messages command function.
36
+ */
30
37
  export const sendMessages = wrapCommand(SEND_MESSAGES);
31
38
  //# sourceMappingURL=send-messages.command.js.map
@@ -16,70 +16,134 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
- import { describe, it } from 'node:test';
20
- import assert from 'node:assert/strict';
21
- import { uuidv7, uuidv4 } from 'uuidv7';
22
- import { SEND_MESSAGES } from './send-messages.command.js';
23
- import { HeaderValue } from './header.utils.js';
24
- describe('SendMessages', () => {
25
- describe('serialize', () => {
19
+ import { describe, it } from "node:test";
20
+ import assert from "node:assert/strict";
21
+ import { uuidv7, uuidv4 } from "uuidv7";
22
+ import { SEND_MESSAGES } from "./send-messages.command.js";
23
+ import { HeaderValue, HeaderKeyFactory } from "./header.utils.js";
24
+ describe("SendMessages", () => {
25
+ describe("serialize", () => {
26
26
  const t1 = {
27
27
  streamId: 911,
28
28
  topicId: 213,
29
29
  messages: [
30
- { payload: 'a' },
31
- { id: 0, payload: 'b' },
32
- { id: 123, payload: 'X' },
33
- { id: 0n, payload: 'c' },
34
- { id: 1236234534554n, payload: 'X' },
35
- { id: uuidv4(), payload: 'd' },
36
- { id: uuidv7(), payload: 'e' },
30
+ { payload: "a" },
31
+ { id: 0, payload: "b" },
32
+ { id: 123, payload: "X" },
33
+ { id: 0n, payload: "c" },
34
+ { id: 1236234534554n, payload: "X" },
35
+ { id: uuidv4(), payload: "d" },
36
+ { id: uuidv7(), payload: "e" },
37
37
  ],
38
38
  };
39
- it('serialize SendMessages into a buffer', () => {
40
- assert.deepEqual(SEND_MESSAGES.serialize(t1).length, 533);
39
+ it("serialize SendMessages into a buffer", () => {
40
+ assert.deepEqual(SEND_MESSAGES.serialize(t1).length, 589);
41
41
  });
42
- it('serialize all kinds of messageId', () => {
42
+ it("serialize all kinds of messageId", () => {
43
43
  assert.doesNotThrow(() => SEND_MESSAGES.serialize(t1));
44
44
  });
45
- it('does not throw on number message id', () => {
46
- const t = { ...t1, messages: [{ id: 42, payload: 'm' }] };
45
+ it("does not throw on number message id", () => {
46
+ const t = { ...t1, messages: [{ id: 42, payload: "m" }] };
47
47
  assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
48
48
  });
49
- it('does not throw on bigint message id', () => {
50
- const t = { ...t1, messages: [{ id: 123n, payload: 'm' }] };
49
+ it("does not throw on bigint message id", () => {
50
+ const t = { ...t1, messages: [{ id: 123n, payload: "m" }] };
51
51
  assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
52
52
  });
53
- it('does not throw on uuid message id', () => {
54
- const t = { ...t1, messages: [{ id: uuidv4(), payload: 'uuid' }] };
53
+ it("does not throw on uuid message id", () => {
54
+ const t = { ...t1, messages: [{ id: uuidv4(), payload: "uuid" }] };
55
55
  assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
56
56
  });
57
- it('throw on invalid string message id', () => {
58
- const t = { ...t1, messages: [{ id: 'foo', payload: 'm' }] };
57
+ it("throw on invalid string message id", () => {
58
+ const t = { ...t1, messages: [{ id: "foo", payload: "m" }] };
59
59
  assert.throws(() => SEND_MESSAGES.serialize(t));
60
60
  });
61
- it('throw on invalid number message id', () => {
62
- const t = { ...t1, messages: [{ id: -12, payload: 'n' }] };
61
+ it("throw on invalid number message id", () => {
62
+ const t = { ...t1, messages: [{ id: -12, payload: "n" }] };
63
63
  assert.throws(() => SEND_MESSAGES.serialize(t));
64
64
  });
65
- it('throw on invalid bigint message id', () => {
66
- const t = { ...t1, messages: [{ id: -12n, payload: 'bn' }] };
65
+ it("throw on invalid bigint message id", () => {
66
+ const t = { ...t1, messages: [{ id: -12n, payload: "bn" }] };
67
67
  assert.throws(() => SEND_MESSAGES.serialize(t));
68
68
  });
69
- it('serialize message with headers', () => {
69
+ it("serialize message with headers", () => {
70
70
  const t = {
71
71
  streamId: 911,
72
72
  topicId: 213,
73
73
  messages: [
74
- { payload: 'm', headers: { p: HeaderValue.Bool(true) } },
75
- { payload: 'q', headers: { 'v-aze': HeaderValue.Uint8(128) } },
76
- { payload: 'x', headers: { q: HeaderValue.Double(1 / 3) } },
77
- { payload: 's', headers: { x: HeaderValue.Uint32(123) } },
78
- { payload: 'r', headers: { y: HeaderValue.Uint64(42n) } },
79
- { payload: 'g', headers: { y: HeaderValue.Float(42.3) } },
80
- { payload: 'c', headers: { ID: HeaderValue.String(uuidv7()) } },
81
- { payload: 'l', headers: { val: HeaderValue.Raw(Buffer.from(uuidv4())) } }
82
- ]
74
+ {
75
+ payload: "m",
76
+ headers: [
77
+ {
78
+ key: HeaderKeyFactory.String("p"),
79
+ value: HeaderValue.Bool(true),
80
+ },
81
+ ],
82
+ },
83
+ {
84
+ payload: "q",
85
+ headers: [
86
+ {
87
+ key: HeaderKeyFactory.String("v-aze"),
88
+ value: HeaderValue.Uint8(128),
89
+ },
90
+ ],
91
+ },
92
+ {
93
+ payload: "x",
94
+ headers: [
95
+ {
96
+ key: HeaderKeyFactory.String("q"),
97
+ value: HeaderValue.Double(1 / 3),
98
+ },
99
+ ],
100
+ },
101
+ {
102
+ payload: "s",
103
+ headers: [
104
+ {
105
+ key: HeaderKeyFactory.String("x"),
106
+ value: HeaderValue.Uint32(123),
107
+ },
108
+ ],
109
+ },
110
+ {
111
+ payload: "r",
112
+ headers: [
113
+ {
114
+ key: HeaderKeyFactory.String("y"),
115
+ value: HeaderValue.Uint64(42n),
116
+ },
117
+ ],
118
+ },
119
+ {
120
+ payload: "g",
121
+ headers: [
122
+ {
123
+ key: HeaderKeyFactory.String("y"),
124
+ value: HeaderValue.Float(42.3),
125
+ },
126
+ ],
127
+ },
128
+ {
129
+ payload: "c",
130
+ headers: [
131
+ {
132
+ key: HeaderKeyFactory.String("ID"),
133
+ value: HeaderValue.String(uuidv7()),
134
+ },
135
+ ],
136
+ },
137
+ {
138
+ payload: "l",
139
+ headers: [
140
+ {
141
+ key: HeaderKeyFactory.String("val"),
142
+ value: HeaderValue.Raw(Buffer.from(uuidv4())),
143
+ },
144
+ ],
145
+ },
146
+ ],
83
147
  };
84
148
  assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
85
149
  });
@@ -16,17 +16,96 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ /**
20
+ * Converts a boolean value to a 1-byte Buffer.
21
+ *
22
+ * @param v - Boolean value to convert
23
+ * @returns Buffer containing 0x00 (false) or 0x01 (true)
24
+ */
19
25
  export declare const boolToBuf: (v: boolean) => Buffer<ArrayBuffer>;
26
+ /**
27
+ * Converts an 8-bit signed integer to a 1-byte Buffer.
28
+ *
29
+ * @param v - Signed integer value (-128 to 127)
30
+ * @returns Buffer containing the value
31
+ */
20
32
  export declare const int8ToBuf: (v: number) => Buffer<ArrayBuffer>;
33
+ /**
34
+ * Converts a 16-bit signed integer to a 2-byte Buffer in little-endian format.
35
+ *
36
+ * @param v - Signed integer value (-32,768 to 32,767)
37
+ * @returns Buffer containing the value in little-endian byte order
38
+ */
21
39
  export declare const int16ToBuf: (v: number) => Buffer<ArrayBuffer>;
40
+ /**
41
+ * Converts a 32-bit signed integer to a 4-byte Buffer in little-endian format.
42
+ *
43
+ * @param v - Signed integer value (-2,147,483,648 to 2,147,483,647)
44
+ * @returns Buffer containing the value in little-endian byte order
45
+ */
22
46
  export declare const int32ToBuf: (v: number) => Buffer<ArrayBuffer>;
47
+ /**
48
+ * Converts a 64-bit signed BigInt to an 8-byte Buffer in little-endian format.
49
+ *
50
+ * @param v - BigInt value
51
+ * @returns Buffer containing the value in little-endian byte order
52
+ */
23
53
  export declare const int64ToBuf: (v: bigint) => Buffer<ArrayBuffer>;
54
+ /**
55
+ * Converts an 8-bit unsigned integer to a 1-byte Buffer.
56
+ *
57
+ * @param v - Unsigned integer value (0 to 255)
58
+ * @returns Buffer containing the value
59
+ */
24
60
  export declare const uint8ToBuf: (v: number) => Buffer<ArrayBuffer>;
61
+ /**
62
+ * Converts a 16-bit unsigned integer to a 2-byte Buffer in little-endian format.
63
+ *
64
+ * @param v - Unsigned integer value (0 to 65,535)
65
+ * @returns Buffer containing the value in little-endian byte order
66
+ */
25
67
  export declare const uint16ToBuf: (v: number) => Buffer<ArrayBuffer>;
68
+ /**
69
+ * Converts a 32-bit unsigned integer to a 4-byte Buffer in little-endian format.
70
+ *
71
+ * @param v - Unsigned integer value (0 to 4,294,967,295)
72
+ * @returns Buffer containing the value in little-endian byte order
73
+ */
26
74
  export declare const uint32ToBuf: (v: number) => Buffer<ArrayBuffer>;
75
+ /**
76
+ * Converts a 64-bit unsigned BigInt to an 8-byte Buffer in little-endian format.
77
+ *
78
+ * @param v - Unsigned BigInt value
79
+ * @returns Buffer containing the value in little-endian byte order
80
+ */
27
81
  export declare const uint64ToBuf: (v: bigint) => Buffer<ArrayBuffer>;
82
+ /**
83
+ * Converts a 32-bit floating-point number to a 4-byte Buffer in little-endian format.
84
+ *
85
+ * @param v - Float value (IEEE 754 single precision)
86
+ * @returns Buffer containing the value in little-endian byte order
87
+ */
28
88
  export declare const floatToBuf: (v: number) => Buffer<ArrayBuffer>;
89
+ /**
90
+ * Converts a 64-bit floating-point number to an 8-byte Buffer in little-endian format.
91
+ *
92
+ * @param v - Double value (IEEE 754 double precision)
93
+ * @returns Buffer containing the value in little-endian byte order
94
+ */
29
95
  export declare const doubleToBuf: (v: number) => Buffer<ArrayBuffer>;
96
+ /**
97
+ * Converts a BigInt to a 128-bit unsigned integer Buffer in little-endian format.
98
+ *
99
+ * @param num - BigInt value to convert
100
+ * @param width - Width in bytes (default: 16)
101
+ * @returns Buffer containing the value in little-endian byte order
102
+ */
30
103
  export declare function u128ToBuf(num: bigint, width?: number): Buffer;
104
+ /**
105
+ * Converts a 128-bit unsigned integer Buffer in little-endian format to a BigInt.
106
+ *
107
+ * @param b - Buffer containing the value in little-endian byte order
108
+ * @returns BigInt representation of the value
109
+ */
31
110
  export declare function u128LEBufToBigint(b: Buffer): bigint;
32
111
  //# sourceMappingURL=number.utils.d.ts.map
@@ -16,68 +16,145 @@
16
16
  * specific language governing permissions and limitations
17
17
  * under the License.
18
18
  */
19
+ /**
20
+ * Converts a boolean value to a 1-byte Buffer.
21
+ *
22
+ * @param v - Boolean value to convert
23
+ * @returns Buffer containing 0x00 (false) or 0x01 (true)
24
+ */
19
25
  export const boolToBuf = (v) => {
20
26
  const b = Buffer.allocUnsafe(1);
21
27
  b.writeUInt8(!v ? 0 : 1);
22
28
  return b;
23
29
  };
30
+ /**
31
+ * Converts an 8-bit signed integer to a 1-byte Buffer.
32
+ *
33
+ * @param v - Signed integer value (-128 to 127)
34
+ * @returns Buffer containing the value
35
+ */
24
36
  export const int8ToBuf = (v) => {
25
37
  const b = Buffer.allocUnsafe(1);
26
38
  b.writeInt8(v);
27
39
  return b;
28
40
  };
41
+ /**
42
+ * Converts a 16-bit signed integer to a 2-byte Buffer in little-endian format.
43
+ *
44
+ * @param v - Signed integer value (-32,768 to 32,767)
45
+ * @returns Buffer containing the value in little-endian byte order
46
+ */
29
47
  export const int16ToBuf = (v) => {
30
48
  const b = Buffer.allocUnsafe(2);
31
49
  b.writeInt16LE(v);
32
50
  return b;
33
51
  };
52
+ /**
53
+ * Converts a 32-bit signed integer to a 4-byte Buffer in little-endian format.
54
+ *
55
+ * @param v - Signed integer value (-2,147,483,648 to 2,147,483,647)
56
+ * @returns Buffer containing the value in little-endian byte order
57
+ */
34
58
  export const int32ToBuf = (v) => {
35
59
  const b = Buffer.allocUnsafe(4);
36
60
  b.writeInt32LE(v);
37
61
  return b;
38
62
  };
63
+ /**
64
+ * Converts a 64-bit signed BigInt to an 8-byte Buffer in little-endian format.
65
+ *
66
+ * @param v - BigInt value
67
+ * @returns Buffer containing the value in little-endian byte order
68
+ */
39
69
  export const int64ToBuf = (v) => {
40
70
  const b = Buffer.allocUnsafe(8);
41
71
  b.writeBigInt64LE(v);
42
72
  return b;
43
73
  };
74
+ /**
75
+ * Converts an 8-bit unsigned integer to a 1-byte Buffer.
76
+ *
77
+ * @param v - Unsigned integer value (0 to 255)
78
+ * @returns Buffer containing the value
79
+ */
44
80
  export const uint8ToBuf = (v) => {
45
81
  const b = Buffer.allocUnsafe(1);
46
82
  b.writeUInt8(v);
47
83
  return b;
48
84
  };
85
+ /**
86
+ * Converts a 16-bit unsigned integer to a 2-byte Buffer in little-endian format.
87
+ *
88
+ * @param v - Unsigned integer value (0 to 65,535)
89
+ * @returns Buffer containing the value in little-endian byte order
90
+ */
49
91
  export const uint16ToBuf = (v) => {
50
92
  const b = Buffer.allocUnsafe(2);
51
93
  b.writeUInt16LE(v);
52
94
  return b;
53
95
  };
96
+ /**
97
+ * Converts a 32-bit unsigned integer to a 4-byte Buffer in little-endian format.
98
+ *
99
+ * @param v - Unsigned integer value (0 to 4,294,967,295)
100
+ * @returns Buffer containing the value in little-endian byte order
101
+ */
54
102
  export const uint32ToBuf = (v) => {
55
103
  const b = Buffer.allocUnsafe(4);
56
104
  b.writeUInt32LE(v);
57
105
  return b;
58
106
  };
107
+ /**
108
+ * Converts a 64-bit unsigned BigInt to an 8-byte Buffer in little-endian format.
109
+ *
110
+ * @param v - Unsigned BigInt value
111
+ * @returns Buffer containing the value in little-endian byte order
112
+ */
59
113
  export const uint64ToBuf = (v) => {
60
114
  const b = Buffer.allocUnsafe(8);
61
115
  b.writeBigUInt64LE(v);
62
116
  return b;
63
117
  };
118
+ /**
119
+ * Converts a 32-bit floating-point number to a 4-byte Buffer in little-endian format.
120
+ *
121
+ * @param v - Float value (IEEE 754 single precision)
122
+ * @returns Buffer containing the value in little-endian byte order
123
+ */
64
124
  export const floatToBuf = (v) => {
65
125
  const b = Buffer.allocUnsafe(4);
66
126
  b.writeFloatLE(v);
67
127
  return b;
68
128
  };
129
+ /**
130
+ * Converts a 64-bit floating-point number to an 8-byte Buffer in little-endian format.
131
+ *
132
+ * @param v - Double value (IEEE 754 double precision)
133
+ * @returns Buffer containing the value in little-endian byte order
134
+ */
69
135
  export const doubleToBuf = (v) => {
70
136
  const b = Buffer.allocUnsafe(8);
71
137
  b.writeDoubleLE(v);
72
138
  return b;
73
139
  };
74
- // bigint => u128 LE
140
+ /**
141
+ * Converts a BigInt to a 128-bit unsigned integer Buffer in little-endian format.
142
+ *
143
+ * @param num - BigInt value to convert
144
+ * @param width - Width in bytes (default: 16)
145
+ * @returns Buffer containing the value in little-endian byte order
146
+ */
75
147
  export function u128ToBuf(num, width = 16) {
76
148
  const hex = num.toString(16);
77
149
  const b = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
78
150
  return b.reverse();
79
151
  }
80
- // u128 LE => Bigint
152
+ /**
153
+ * Converts a 128-bit unsigned integer Buffer in little-endian format to a BigInt.
154
+ *
155
+ * @param b - Buffer containing the value in little-endian byte order
156
+ * @returns BigInt representation of the value
157
+ */
81
158
  export function u128LEBufToBigint(b) {
82
159
  const hex = b.reverse().toString('hex');
83
160
  return hex.length === 0 ? BigInt(0) : BigInt(`0x${hex}`);