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.
- package/dist/client/client.connection.d.ts +49 -0
- package/dist/client/client.connection.js +79 -0
- package/dist/client/client.d.ts +46 -0
- package/dist/client/client.debug.d.ts +4 -0
- package/dist/client/client.debug.js +4 -0
- package/dist/client/client.js +65 -1
- package/dist/client/client.socket.d.ts +91 -0
- package/dist/client/client.socket.js +94 -0
- package/dist/client/client.type.d.ts +72 -0
- package/dist/client/client.type.js +3 -0
- package/dist/client/client.utils.d.ts +28 -0
- package/dist/client/client.utils.js +29 -0
- package/dist/e2e/tcp.cluster.e2e.js +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/dist/tcp.sm.utils.d.ts +31 -42
- package/dist/tcp.sm.utils.js +38 -22
- package/dist/type.utils.d.ts +14 -0
- package/dist/type.utils.js +9 -0
- package/dist/wire/command-set.d.ts +2 -9
- package/dist/wire/command.utils.d.ts +18 -0
- package/dist/wire/command.utils.js +9 -0
- package/dist/wire/consumer-group/create-group.command.d.ts +13 -0
- package/dist/wire/consumer-group/create-group.command.js +7 -0
- package/dist/wire/consumer-group/delete-group.command.d.ts +13 -0
- package/dist/wire/consumer-group/delete-group.command.js +7 -0
- package/dist/wire/consumer-group/ensure-group.virtual.command.d.ts +15 -1
- package/dist/wire/consumer-group/ensure-group.virtual.command.js +14 -0
- package/dist/wire/consumer-group/get-group.command.d.ts +13 -0
- package/dist/wire/consumer-group/get-group.command.js +7 -0
- package/dist/wire/consumer-group/get-groups.command.d.ts +12 -0
- package/dist/wire/consumer-group/get-groups.command.js +7 -0
- package/dist/wire/consumer-group/group.utils.d.ts +34 -0
- package/dist/wire/consumer-group/group.utils.js +22 -0
- package/dist/wire/consumer-group/join-group.command.d.ts +13 -0
- package/dist/wire/consumer-group/join-group.command.js +7 -0
- package/dist/wire/consumer-group/leave-group.command.d.ts +13 -0
- package/dist/wire/consumer-group/leave-group.command.js +7 -0
- package/dist/wire/identifier.utils.d.ts +11 -0
- package/dist/wire/identifier.utils.js +23 -1
- package/dist/wire/message/flush-unsaved-buffers.command.d.ts +13 -0
- package/dist/wire/message/flush-unsaved-buffers.command.js +7 -0
- package/dist/wire/message/header.type.d.ts +57 -15
- package/dist/wire/message/header.type.js +31 -18
- package/dist/wire/message/header.utils.d.ts +104 -10
- package/dist/wire/message/header.utils.js +233 -86
- package/dist/wire/message/header.utils.test.js +39 -16
- package/dist/wire/message/iggy-header.utils.d.ts +39 -1
- package/dist/wire/message/iggy-header.utils.js +30 -3
- package/dist/wire/message/index.d.ts +5 -5
- package/dist/wire/message/index.js +5 -5
- package/dist/wire/message/message.utils.d.ts +60 -0
- package/dist/wire/message/message.utils.js +54 -1
- package/dist/wire/message/partitioning.utils.d.ts +39 -0
- package/dist/wire/message/partitioning.utils.js +43 -1
- package/dist/wire/message/poll-messages.command.d.ts +17 -0
- package/dist/wire/message/poll-messages.command.js +7 -0
- package/dist/wire/message/poll.utils.d.ts +93 -12
- package/dist/wire/message/poll.utils.js +92 -21
- package/dist/wire/message/send-messages.command.d.ts +14 -0
- package/dist/wire/message/send-messages.command.js +7 -0
- package/dist/wire/message/send-messages.command.test.js +103 -39
- package/dist/wire/number.utils.d.ts +79 -0
- package/dist/wire/number.utils.js +79 -2
- package/dist/wire/offset/delete-offset.command.d.ts +13 -3
- package/dist/wire/offset/delete-offset.command.js +7 -0
- package/dist/wire/offset/get-offset.command.d.ts +14 -0
- package/dist/wire/offset/get-offset.command.js +7 -0
- package/dist/wire/offset/offset.utils.d.ts +48 -0
- package/dist/wire/offset/offset.utils.js +33 -0
- package/dist/wire/offset/store-offset.command.d.ts +15 -0
- package/dist/wire/offset/store-offset.command.js +7 -0
- package/dist/wire/partition/create-partition.command.d.ts +13 -0
- package/dist/wire/partition/create-partition.command.js +7 -0
- package/dist/wire/partition/delete-partition.command.d.ts +13 -0
- package/dist/wire/partition/delete-partition.command.js +7 -0
- package/dist/wire/partition/partition.utils.d.ts +9 -0
- package/dist/wire/partition/partition.utils.js +9 -0
- package/dist/wire/serialize.utils.d.ts +20 -0
- package/dist/wire/serialize.utils.js +20 -0
- package/dist/wire/session/login-with-token.command.d.ts +11 -0
- package/dist/wire/session/login-with-token.command.js +7 -0
- package/dist/wire/session/login.command.d.ts +7 -0
- package/dist/wire/session/login.command.js +7 -0
- package/dist/wire/session/login.utils.d.ts +25 -0
- package/dist/wire/session/login.utils.js +14 -0
- package/dist/wire/session/logout.command.d.ts +7 -0
- package/dist/wire/session/logout.command.js +7 -0
- package/dist/wire/stream/create-stream.command.d.ts +12 -0
- package/dist/wire/stream/create-stream.command.js +7 -0
- package/dist/wire/stream/delete-stream.command.d.ts +11 -0
- package/dist/wire/stream/delete-stream.command.js +7 -0
- package/dist/wire/stream/ensure-stream.virtual.command.d.ts +8 -1
- package/dist/wire/stream/ensure-stream.virtual.command.js +7 -0
- package/dist/wire/stream/get-stream.command.d.ts +11 -0
- package/dist/wire/stream/get-stream.command.js +7 -0
- package/dist/wire/stream/get-streams.command.d.ts +7 -0
- package/dist/wire/stream/get-streams.command.js +7 -0
- package/dist/wire/stream/purge-stream.command.d.ts +11 -0
- package/dist/wire/stream/purge-stream.command.js +7 -0
- package/dist/wire/stream/stream.utils.d.ts +22 -0
- package/dist/wire/stream/stream.utils.js +8 -0
- package/dist/wire/stream/update-stream.command.d.ts +12 -0
- package/dist/wire/stream/update-stream.command.js +7 -0
- package/dist/wire/token/create-token.command.d.ts +12 -0
- package/dist/wire/token/create-token.command.js +7 -0
- package/dist/wire/token/delete-token.command.d.ts +11 -0
- package/dist/wire/token/delete-token.command.js +7 -0
- package/dist/wire/token/get-tokens.command.d.ts +7 -0
- package/dist/wire/token/get-tokens.command.js +7 -0
- package/dist/wire/token/token.utils.d.ts +40 -0
- package/dist/wire/token/token.utils.js +21 -0
- package/dist/wire/topic/create-topic.command.d.ts +17 -0
- package/dist/wire/topic/create-topic.command.js +7 -0
- package/dist/wire/topic/delete-topic.command.d.ts +14 -2
- package/dist/wire/topic/delete-topic.command.js +7 -0
- package/dist/wire/topic/ensure-topic.virtual.command.d.ts +9 -2
- package/dist/wire/topic/ensure-topic.virtual.command.js +7 -0
- package/dist/wire/topic/get-topic.command.d.ts +13 -2
- package/dist/wire/topic/get-topic.command.js +7 -0
- package/dist/wire/topic/get-topics.command.d.ts +11 -0
- package/dist/wire/topic/get-topics.command.js +7 -0
- package/dist/wire/topic/purge-topic.command.d.ts +12 -0
- package/dist/wire/topic/purge-topic.command.js +7 -0
- package/dist/wire/topic/topic.utils.d.ts +73 -0
- package/dist/wire/topic/topic.utils.js +40 -0
- package/dist/wire/topic/update-topic.command.d.ts +17 -0
- package/dist/wire/topic/update-topic.command.js +7 -0
- package/dist/wire/user/change-password.command.d.ts +13 -0
- package/dist/wire/user/change-password.command.js +7 -0
- package/dist/wire/user/create-user.command.d.ts +14 -0
- package/dist/wire/user/create-user.command.js +7 -0
- package/dist/wire/user/delete-user.command.d.ts +11 -0
- package/dist/wire/user/delete-user.command.js +7 -0
- package/dist/wire/user/get-user.command.d.ts +11 -0
- package/dist/wire/user/get-user.command.js +7 -0
- package/dist/wire/user/get-users.command.d.ts +7 -0
- package/dist/wire/user/get-users.command.js +7 -0
- package/dist/wire/user/permissions.utils.d.ts +108 -0
- package/dist/wire/user/permissions.utils.js +68 -0
- package/dist/wire/user/update-permissions.command.d.ts +12 -0
- package/dist/wire/user/update-permissions.command.js +7 -0
- package/dist/wire/user/update-user.command.d.ts +13 -0
- package/dist/wire/user/update-user.command.js +7 -0
- package/dist/wire/user/user.utils.d.ts +40 -0
- package/dist/wire/user/user.utils.js +33 -0
- package/dist/wire/uuid.utils.d.ts +13 -0
- package/dist/wire/uuid.utils.js +13 -1
- package/package.json +2 -2
|
@@ -16,176 +16,303 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { boolToBuf, int8ToBuf, int16ToBuf, int32ToBuf, int64ToBuf, uint8ToBuf, uint16ToBuf, uint32ToBuf, uint64ToBuf, floatToBuf, doubleToBuf } from
|
|
20
|
-
import { HeaderKind, ReverseHeaderKind } from
|
|
19
|
+
import { boolToBuf, int8ToBuf, int16ToBuf, int32ToBuf, int64ToBuf, uint8ToBuf, uint16ToBuf, uint32ToBuf, uint64ToBuf, floatToBuf, doubleToBuf, } from "../number.utils.js";
|
|
20
|
+
import { HeaderKind, ReverseHeaderKind, expectedSize, } from "./header.type.js";
|
|
21
|
+
/**
|
|
22
|
+
* Serializes a header value to a Buffer based on its kind.
|
|
23
|
+
*
|
|
24
|
+
* @param header - Header value to serialize
|
|
25
|
+
* @returns Serialized value as Buffer
|
|
26
|
+
*/
|
|
21
27
|
export const serializeHeaderValue = (header) => {
|
|
22
28
|
const { kind, value } = header;
|
|
23
29
|
switch (kind) {
|
|
24
|
-
case HeaderKind.Raw:
|
|
25
|
-
|
|
26
|
-
case HeaderKind.
|
|
27
|
-
|
|
28
|
-
case HeaderKind.
|
|
29
|
-
|
|
30
|
-
case HeaderKind.
|
|
31
|
-
|
|
32
|
-
case HeaderKind.
|
|
33
|
-
|
|
34
|
-
case HeaderKind.
|
|
35
|
-
|
|
36
|
-
case HeaderKind.
|
|
37
|
-
|
|
38
|
-
case HeaderKind.
|
|
30
|
+
case HeaderKind.Raw:
|
|
31
|
+
return value;
|
|
32
|
+
case HeaderKind.String:
|
|
33
|
+
return Buffer.from(value);
|
|
34
|
+
case HeaderKind.Bool:
|
|
35
|
+
return boolToBuf(value);
|
|
36
|
+
case HeaderKind.Int8:
|
|
37
|
+
return int8ToBuf(value);
|
|
38
|
+
case HeaderKind.Int16:
|
|
39
|
+
return int16ToBuf(value);
|
|
40
|
+
case HeaderKind.Int32:
|
|
41
|
+
return int32ToBuf(value);
|
|
42
|
+
case HeaderKind.Int64:
|
|
43
|
+
return int64ToBuf(value);
|
|
44
|
+
case HeaderKind.Int128:
|
|
45
|
+
return value;
|
|
46
|
+
case HeaderKind.Uint8:
|
|
47
|
+
return uint8ToBuf(value);
|
|
48
|
+
case HeaderKind.Uint16:
|
|
49
|
+
return uint16ToBuf(value);
|
|
50
|
+
case HeaderKind.Uint32:
|
|
51
|
+
return uint32ToBuf(value);
|
|
52
|
+
case HeaderKind.Uint64:
|
|
53
|
+
return uint64ToBuf(value);
|
|
54
|
+
case HeaderKind.Uint128:
|
|
55
|
+
return value;
|
|
56
|
+
case HeaderKind.Float:
|
|
57
|
+
return floatToBuf(value);
|
|
58
|
+
case HeaderKind.Double:
|
|
59
|
+
return doubleToBuf(value);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Serializes a header key to a Buffer based on its kind.
|
|
64
|
+
*
|
|
65
|
+
* @param key - Header key to serialize
|
|
66
|
+
* @returns Serialized key as Buffer
|
|
67
|
+
*/
|
|
68
|
+
export const serializeHeaderKey = (key) => {
|
|
69
|
+
const { kind, value } = key;
|
|
70
|
+
switch (kind) {
|
|
71
|
+
case HeaderKind.Raw:
|
|
72
|
+
return value;
|
|
73
|
+
case HeaderKind.String:
|
|
74
|
+
return Buffer.from(value);
|
|
75
|
+
case HeaderKind.Int32:
|
|
76
|
+
return int32ToBuf(value);
|
|
39
77
|
}
|
|
40
78
|
};
|
|
79
|
+
/**
|
|
80
|
+
* Serializes a single header key-value pair to wire format.
|
|
81
|
+
* Format: [key_kind][key_length][key][value_kind][value_length][value]
|
|
82
|
+
*
|
|
83
|
+
* @param key - Header key
|
|
84
|
+
* @param v - Binary header value
|
|
85
|
+
* @returns Serialized header as Buffer
|
|
86
|
+
*/
|
|
41
87
|
export const serializeHeader = (key, v) => {
|
|
42
|
-
const bKey =
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// 'KEY-LEN', b1.length, b1.toString('hex'), '=', b1.readUInt32LE(0), '\n',
|
|
51
|
-
// 'KEY', bKey.length, bKey.toString('hex'), '\n',
|
|
52
|
-
// 'KIND', b2.readUInt8(0), b2.subarray(0, 1).toString('hex'), '\n',
|
|
53
|
-
// 'V-LEN', b2.readUInt32LE(1), b2.subarray(1, 5).toString('hex'), '\n',
|
|
54
|
-
// 'V', v.value.length, v.value.toString('hex')
|
|
55
|
-
// );
|
|
56
|
-
return Buffer.concat([
|
|
57
|
-
b1,
|
|
58
|
-
bKey,
|
|
59
|
-
b2,
|
|
60
|
-
v.value
|
|
61
|
-
]);
|
|
88
|
+
const bKey = serializeHeaderKey(key);
|
|
89
|
+
const keyHeader = Buffer.alloc(5);
|
|
90
|
+
keyHeader.writeUInt8(key.kind);
|
|
91
|
+
keyHeader.writeUInt32LE(bKey.length, 1);
|
|
92
|
+
const valueHeader = Buffer.alloc(5);
|
|
93
|
+
valueHeader.writeUInt8(v.kind);
|
|
94
|
+
valueHeader.writeUInt32LE(v.value.length, 1);
|
|
95
|
+
return Buffer.concat([keyHeader, bKey, valueHeader, v.value]);
|
|
62
96
|
};
|
|
97
|
+
/** Empty headers buffer constant */
|
|
63
98
|
export const EMPTY_HEADERS = Buffer.alloc(0);
|
|
99
|
+
/**
|
|
100
|
+
* Creates a binary header value from a typed header value.
|
|
101
|
+
*
|
|
102
|
+
* @param header - Typed header value
|
|
103
|
+
* @returns Binary header value
|
|
104
|
+
*/
|
|
64
105
|
const createHeaderValue = (header) => ({
|
|
65
106
|
kind: header.kind,
|
|
66
|
-
value: serializeHeaderValue(header)
|
|
107
|
+
value: serializeHeaderValue(header),
|
|
67
108
|
});
|
|
109
|
+
/**
|
|
110
|
+
* Serializes all headers to a single buffer.
|
|
111
|
+
*
|
|
112
|
+
* @param headers - Optional headers array
|
|
113
|
+
* @returns Serialized headers buffer (empty if no headers)
|
|
114
|
+
*/
|
|
68
115
|
export const serializeHeaders = (headers) => {
|
|
69
|
-
if (!headers)
|
|
116
|
+
if (!headers || headers.length === 0)
|
|
70
117
|
return EMPTY_HEADERS;
|
|
71
|
-
return Buffer.concat(
|
|
118
|
+
return Buffer.concat(headers.map((entry) => serializeHeader(entry.key, createHeaderValue(entry.value))));
|
|
72
119
|
};
|
|
120
|
+
/**
|
|
121
|
+
* Maps a numeric header kind to its string identifier.
|
|
122
|
+
*
|
|
123
|
+
* @param k - Numeric header kind value
|
|
124
|
+
* @returns Header kind identifier string
|
|
125
|
+
* @throws Error if the header kind is unknown
|
|
126
|
+
*/
|
|
73
127
|
export const mapHeaderKind = (k) => {
|
|
74
128
|
if (!ReverseHeaderKind[k])
|
|
75
129
|
throw new Error(`unknow header kind: ${k}`);
|
|
76
130
|
return ReverseHeaderKind[k];
|
|
77
131
|
};
|
|
132
|
+
/**
|
|
133
|
+
* Deserializes a header value buffer based on its kind.
|
|
134
|
+
*
|
|
135
|
+
* @param kind - Numeric header kind
|
|
136
|
+
* @param value - Raw value buffer
|
|
137
|
+
* @returns Deserialized value
|
|
138
|
+
* @throws Error if the header kind is invalid
|
|
139
|
+
*/
|
|
78
140
|
export const deserializeHeaderValue = (kind, value) => {
|
|
79
141
|
switch (kind) {
|
|
80
142
|
case HeaderKind.Int128:
|
|
81
143
|
case HeaderKind.Uint128:
|
|
82
|
-
case HeaderKind.Raw:
|
|
83
|
-
|
|
84
|
-
case HeaderKind.
|
|
85
|
-
|
|
86
|
-
case HeaderKind.
|
|
87
|
-
|
|
88
|
-
case HeaderKind.
|
|
89
|
-
|
|
90
|
-
case HeaderKind.
|
|
91
|
-
|
|
92
|
-
case HeaderKind.
|
|
93
|
-
|
|
94
|
-
case HeaderKind.
|
|
95
|
-
|
|
144
|
+
case HeaderKind.Raw:
|
|
145
|
+
return value;
|
|
146
|
+
case HeaderKind.String:
|
|
147
|
+
return value.toString();
|
|
148
|
+
case HeaderKind.Int8:
|
|
149
|
+
return value.readInt8();
|
|
150
|
+
case HeaderKind.Int16:
|
|
151
|
+
return value.readInt16LE();
|
|
152
|
+
case HeaderKind.Int32:
|
|
153
|
+
return value.readInt32LE();
|
|
154
|
+
case HeaderKind.Int64:
|
|
155
|
+
return value.readBigInt64LE();
|
|
156
|
+
case HeaderKind.Uint8:
|
|
157
|
+
return value.readUint8();
|
|
158
|
+
case HeaderKind.Uint16:
|
|
159
|
+
return value.readUint16LE();
|
|
160
|
+
case HeaderKind.Uint32:
|
|
161
|
+
return value.readUInt32LE();
|
|
162
|
+
case HeaderKind.Uint64:
|
|
163
|
+
return value.readBigUInt64LE();
|
|
164
|
+
case HeaderKind.Bool:
|
|
165
|
+
return value.readUInt8() === 1;
|
|
166
|
+
case HeaderKind.Float:
|
|
167
|
+
return value.readFloatLE();
|
|
168
|
+
case HeaderKind.Double:
|
|
169
|
+
return value.readDoubleLE();
|
|
170
|
+
default:
|
|
171
|
+
throw new Error(`deserializeHeaderValue: invalid HeaderKind ${kind}`);
|
|
96
172
|
}
|
|
97
173
|
};
|
|
174
|
+
/**
|
|
175
|
+
* Deserializes a single header from a buffer.
|
|
176
|
+
* Format: [key_kind][key_length][key][value_kind][value_length][value]
|
|
177
|
+
*
|
|
178
|
+
* @param p - Buffer containing serialized headers
|
|
179
|
+
* @param pos - Starting position in the buffer
|
|
180
|
+
* @returns Object with bytes read and deserialized header data
|
|
181
|
+
* @throws Error if header key or value length is invalid (must be 1-255)
|
|
182
|
+
*/
|
|
98
183
|
export const deserializeHeader = (p, pos = 0) => {
|
|
99
|
-
const
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
184
|
+
const keyKind = p.readUInt8(pos);
|
|
185
|
+
const keyLength = p.readUInt32LE(pos + 1);
|
|
186
|
+
if (keyLength < 1 || keyLength > 255) {
|
|
187
|
+
throw new Error(`Invalid header key length: ${keyLength}, must be between 1 and 255`);
|
|
188
|
+
}
|
|
189
|
+
const keyExpected = expectedSize(keyKind);
|
|
190
|
+
if (keyExpected !== -1 && keyLength !== keyExpected) {
|
|
191
|
+
throw new Error(`Invalid header key size for kind ${keyKind}: expected ${keyExpected}, got ${keyLength}`);
|
|
192
|
+
}
|
|
193
|
+
const keyValue = deserializeHeaderValue(keyKind, p.subarray(pos + 5, pos + 5 + keyLength));
|
|
194
|
+
pos += 5 + keyLength;
|
|
195
|
+
const valueKind = p.readUInt8(pos);
|
|
105
196
|
const valueLength = p.readUInt32LE(pos + 1);
|
|
106
|
-
|
|
197
|
+
if (valueLength < 1 || valueLength > 255) {
|
|
198
|
+
throw new Error(`Invalid header value length: ${valueLength}, must be between 1 and 255`);
|
|
199
|
+
}
|
|
200
|
+
const valueExpected = expectedSize(valueKind);
|
|
201
|
+
if (valueExpected !== -1 && valueLength !== valueExpected) {
|
|
202
|
+
throw new Error(`Invalid header value size for kind ${valueKind}: expected ${valueExpected}, got ${valueLength}`);
|
|
203
|
+
}
|
|
204
|
+
const value = deserializeHeaderValue(valueKind, p.subarray(pos + 5, pos + 5 + valueLength));
|
|
107
205
|
return {
|
|
108
|
-
bytesRead:
|
|
206
|
+
bytesRead: 5 + keyLength + 5 + valueLength,
|
|
109
207
|
data: {
|
|
110
|
-
key,
|
|
111
|
-
kind:
|
|
112
|
-
|
|
113
|
-
}
|
|
208
|
+
key: { kind: keyKind, value: keyValue },
|
|
209
|
+
value: { kind: valueKind, value },
|
|
210
|
+
},
|
|
114
211
|
};
|
|
115
212
|
};
|
|
213
|
+
/**
|
|
214
|
+
* Deserializes all headers from a buffer.
|
|
215
|
+
*
|
|
216
|
+
* @param p - Buffer containing serialized headers
|
|
217
|
+
* @param pos - Starting position in the buffer
|
|
218
|
+
* @returns Array of parsed header entries
|
|
219
|
+
*/
|
|
116
220
|
export const deserializeHeaders = (p, pos = 0) => {
|
|
117
|
-
const headers =
|
|
221
|
+
const headers = [];
|
|
118
222
|
const len = p.length;
|
|
119
223
|
while (pos < len) {
|
|
120
|
-
const { bytesRead, data
|
|
121
|
-
headers
|
|
224
|
+
const { bytesRead, data } = deserializeHeader(p, pos);
|
|
225
|
+
headers.push(data);
|
|
122
226
|
pos += bytesRead;
|
|
123
227
|
}
|
|
124
228
|
return headers;
|
|
125
229
|
};
|
|
126
|
-
/**
|
|
230
|
+
/**
|
|
231
|
+
* HeaderValue factory functions and utilities.
|
|
232
|
+
* Provides type-safe constructors for each header value type.
|
|
233
|
+
*/
|
|
234
|
+
/** Creates a raw binary header value */
|
|
127
235
|
const Raw = (value) => ({
|
|
128
236
|
kind: HeaderKind.Raw,
|
|
129
|
-
value
|
|
237
|
+
value,
|
|
130
238
|
});
|
|
239
|
+
/** Creates a string header value */
|
|
131
240
|
const String = (value) => ({
|
|
132
241
|
kind: HeaderKind.String,
|
|
133
|
-
value
|
|
242
|
+
value,
|
|
134
243
|
});
|
|
244
|
+
/** Creates a boolean header value */
|
|
135
245
|
const Bool = (value) => ({
|
|
136
246
|
kind: HeaderKind.Bool,
|
|
137
|
-
value
|
|
247
|
+
value,
|
|
138
248
|
});
|
|
249
|
+
/** Creates an Int8 header value */
|
|
139
250
|
const Int8 = (value) => ({
|
|
140
251
|
kind: HeaderKind.Int8,
|
|
141
|
-
value
|
|
252
|
+
value,
|
|
142
253
|
});
|
|
254
|
+
/** Creates an Int16 header value */
|
|
143
255
|
const Int16 = (value) => ({
|
|
144
256
|
kind: HeaderKind.Int16,
|
|
145
|
-
value
|
|
257
|
+
value,
|
|
146
258
|
});
|
|
259
|
+
/** Creates an Int32 header value */
|
|
147
260
|
const Int32 = (value) => ({
|
|
148
261
|
kind: HeaderKind.Int32,
|
|
149
|
-
value
|
|
262
|
+
value,
|
|
150
263
|
});
|
|
264
|
+
/** Creates an Int64 header value */
|
|
151
265
|
const Int64 = (value) => ({
|
|
152
266
|
kind: HeaderKind.Int64,
|
|
153
|
-
value
|
|
267
|
+
value,
|
|
154
268
|
});
|
|
269
|
+
/** Creates an Int128 header value */
|
|
155
270
|
const Int128 = (value) => ({
|
|
156
271
|
kind: HeaderKind.Int128,
|
|
157
|
-
value
|
|
272
|
+
value,
|
|
158
273
|
});
|
|
274
|
+
/** Creates a Uint8 header value */
|
|
159
275
|
const Uint8 = (value) => ({
|
|
160
276
|
kind: HeaderKind.Uint8,
|
|
161
|
-
value
|
|
277
|
+
value,
|
|
162
278
|
});
|
|
279
|
+
/** Creates a Uint16 header value */
|
|
163
280
|
const Uint16 = (value) => ({
|
|
164
281
|
kind: HeaderKind.Uint16,
|
|
165
|
-
value
|
|
282
|
+
value,
|
|
166
283
|
});
|
|
284
|
+
/** Creates a Uint32 header value */
|
|
167
285
|
const Uint32 = (value) => ({
|
|
168
286
|
kind: HeaderKind.Uint32,
|
|
169
|
-
value
|
|
287
|
+
value,
|
|
170
288
|
});
|
|
289
|
+
/** Creates a Uint64 header value */
|
|
171
290
|
const Uint64 = (value) => ({
|
|
172
291
|
kind: HeaderKind.Uint64,
|
|
173
|
-
value
|
|
292
|
+
value,
|
|
174
293
|
});
|
|
294
|
+
/** Creates a Uint128 header value */
|
|
175
295
|
const Uint128 = (value) => ({
|
|
176
296
|
kind: HeaderKind.Uint128,
|
|
177
|
-
value
|
|
297
|
+
value,
|
|
178
298
|
});
|
|
299
|
+
/** Creates a Float header value */
|
|
179
300
|
const Float = (value) => ({
|
|
180
301
|
kind: HeaderKind.Float,
|
|
181
|
-
value
|
|
302
|
+
value,
|
|
182
303
|
});
|
|
304
|
+
/** Creates a Double header value */
|
|
183
305
|
const Double = (value) => ({
|
|
184
306
|
kind: HeaderKind.Double,
|
|
185
|
-
value
|
|
307
|
+
value,
|
|
186
308
|
});
|
|
309
|
+
/** Gets the kind identifier string of a header value */
|
|
187
310
|
const getKind = (h) => mapHeaderKind(h.kind);
|
|
311
|
+
/** Gets the value from a header value */
|
|
188
312
|
const getValue = (h) => h.value;
|
|
313
|
+
/**
|
|
314
|
+
* HeaderValue factory object with constructors for all header types.
|
|
315
|
+
*/
|
|
189
316
|
export const HeaderValue = {
|
|
190
317
|
Raw,
|
|
191
318
|
String,
|
|
@@ -203,7 +330,27 @@ export const HeaderValue = {
|
|
|
203
330
|
Float,
|
|
204
331
|
Double,
|
|
205
332
|
getKind,
|
|
206
|
-
getValue
|
|
333
|
+
getValue,
|
|
334
|
+
};
|
|
335
|
+
/** Creates a raw binary header key */
|
|
336
|
+
const keyRaw = (value) => ({
|
|
337
|
+
kind: HeaderKind.Raw,
|
|
338
|
+
value,
|
|
339
|
+
});
|
|
340
|
+
/** Creates a string header key */
|
|
341
|
+
const keyString = (value) => ({
|
|
342
|
+
kind: HeaderKind.String,
|
|
343
|
+
value,
|
|
344
|
+
});
|
|
345
|
+
/** Creates an Int32 header key */
|
|
346
|
+
const keyInt32 = (value) => ({
|
|
347
|
+
kind: HeaderKind.Int32,
|
|
348
|
+
value,
|
|
349
|
+
});
|
|
350
|
+
export const HeaderKeyFactory = {
|
|
351
|
+
Raw: keyRaw,
|
|
352
|
+
String: keyString,
|
|
353
|
+
Int32: keyInt32,
|
|
207
354
|
};
|
|
208
355
|
// export type InputHeaderValue = boolean | number | string | bigint | Buffer;
|
|
209
356
|
// export type InputHeaders = Record<string, InputHeaderValue>;
|
|
@@ -16,24 +16,47 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
import { describe, it } from
|
|
20
|
-
import assert from
|
|
21
|
-
import { uuidv7, uuidv4 } from
|
|
22
|
-
import { serializeHeaders, deserializeHeaders, HeaderValue } from
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
19
|
+
import { describe, it } from "node:test";
|
|
20
|
+
import assert from "node:assert/strict";
|
|
21
|
+
import { uuidv7, uuidv4 } from "uuidv7";
|
|
22
|
+
import { serializeHeaders, deserializeHeaders, HeaderValue, HeaderKeyFactory, } from "./header.utils.js";
|
|
23
|
+
import { HeaderKind } from "./header.type.js";
|
|
24
|
+
describe("Headers", () => {
|
|
25
|
+
const headers = [
|
|
26
|
+
{ key: HeaderKeyFactory.String("p"), value: HeaderValue.Bool(true) },
|
|
27
|
+
{ key: HeaderKeyFactory.String("x"), value: HeaderValue.Uint32(123) },
|
|
28
|
+
{ key: HeaderKeyFactory.String("y"), value: HeaderValue.Uint64(42n) },
|
|
29
|
+
{
|
|
30
|
+
key: HeaderKeyFactory.String("z"),
|
|
31
|
+
value: HeaderValue.Float(42.20000076293945),
|
|
32
|
+
},
|
|
33
|
+
{ key: HeaderKeyFactory.String("a"), value: HeaderValue.Double(1 / 3) },
|
|
34
|
+
{ key: HeaderKeyFactory.String("ID"), value: HeaderValue.String(uuidv7()) },
|
|
35
|
+
{
|
|
36
|
+
key: HeaderKeyFactory.String("val"),
|
|
37
|
+
value: HeaderValue.Raw(Buffer.from(uuidv4())),
|
|
38
|
+
},
|
|
39
|
+
];
|
|
40
|
+
it("serialize/deserialize string keys", () => {
|
|
34
41
|
const s = serializeHeaders(headers);
|
|
35
42
|
const d = deserializeHeaders(s);
|
|
36
|
-
assert.
|
|
43
|
+
assert.equal(d.length, headers.length);
|
|
44
|
+
for (let i = 0; i < headers.length; i++) {
|
|
45
|
+
assert.equal(d[i].key.kind, headers[i].key.kind);
|
|
46
|
+
assert.equal(d[i].value.kind, headers[i].value.kind);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
it("serialize/deserialize int32 key", () => {
|
|
50
|
+
const int32Headers = [
|
|
51
|
+
{ key: HeaderKeyFactory.Int32(42), value: HeaderValue.String("test") },
|
|
52
|
+
];
|
|
53
|
+
const s = serializeHeaders(int32Headers);
|
|
54
|
+
const d = deserializeHeaders(s);
|
|
55
|
+
assert.equal(d.length, 1);
|
|
56
|
+
assert.equal(d[0].key.kind, HeaderKind.Int32);
|
|
57
|
+
assert.equal(d[0].key.value, 42);
|
|
58
|
+
assert.equal(d[0].value.kind, HeaderKind.String);
|
|
59
|
+
assert.equal(d[0].value.value, "test");
|
|
37
60
|
});
|
|
38
61
|
});
|
|
39
62
|
//# sourceMappingURL=header.utils.test.js.map
|
|
@@ -16,17 +16,55 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
+
/**
|
|
20
|
+
* Iggy message header containing metadata for each message.
|
|
21
|
+
*/
|
|
19
22
|
export type IggyMessageHeader = {
|
|
23
|
+
/** Message checksum for integrity verification */
|
|
20
24
|
checksum: bigint;
|
|
21
|
-
|
|
25
|
+
/** Unique message identifier (UUID or numeric) */
|
|
26
|
+
id: string | bigint;
|
|
27
|
+
/** Message offset within the partition */
|
|
22
28
|
offset: bigint;
|
|
29
|
+
/** Server-assigned timestamp */
|
|
23
30
|
timestamp: Date;
|
|
31
|
+
/** Client-provided origin timestamp */
|
|
24
32
|
originTimestamp: Date;
|
|
33
|
+
/** Length of user-defined headers in bytes */
|
|
25
34
|
userHeadersLength: number;
|
|
35
|
+
/** Length of message payload in bytes */
|
|
26
36
|
payloadLength: number;
|
|
37
|
+
/** Reserved for future use */
|
|
38
|
+
reserved: bigint;
|
|
27
39
|
};
|
|
40
|
+
/**
|
|
41
|
+
* Size of the Iggy message header in bytes.
|
|
42
|
+
* Layout: u64 (checksum) + u128 (id) + u64 (offset) + u64 (timestamp) + u64 (originTimestamp) + u32 (userHeadersLength) + u32 (payloadLength) + u64 (reserved)
|
|
43
|
+
*/
|
|
28
44
|
export declare const IGGY_MESSAGE_HEADER_SIZE: number;
|
|
45
|
+
/**
|
|
46
|
+
* Serializes an Iggy message header to wire format.
|
|
47
|
+
* Sets checksum, offset, and timestamp to zero (filled by server).
|
|
48
|
+
*
|
|
49
|
+
* @param id - Message ID as 16-byte buffer
|
|
50
|
+
* @param payload - Message payload
|
|
51
|
+
* @param userHeaders - Serialized user headers
|
|
52
|
+
* @returns Serialized header buffer
|
|
53
|
+
*/
|
|
29
54
|
export declare const serializeIggyMessageHeader: (id: Buffer, payload: Buffer, userHeaders: Buffer) => Buffer<ArrayBuffer>;
|
|
55
|
+
/**
|
|
56
|
+
* Deserializes a message ID from a 16-byte buffer to BigInt.
|
|
57
|
+
*
|
|
58
|
+
* @param b - 16-byte buffer containing the message ID
|
|
59
|
+
* @returns Message ID as BigInt
|
|
60
|
+
*/
|
|
30
61
|
export declare const deserialiseMessageId: (b: Buffer) => bigint;
|
|
62
|
+
/**
|
|
63
|
+
* Deserializes Iggy message headers from a buffer.
|
|
64
|
+
*
|
|
65
|
+
* @param b - Buffer containing the serialized header
|
|
66
|
+
* @returns Parsed IggyMessageHeader object
|
|
67
|
+
* @throws Error if buffer length doesn't match expected header size
|
|
68
|
+
*/
|
|
31
69
|
export declare const deserializeIggyMessageHeaders: (b: Buffer) => IggyMessageHeader;
|
|
32
70
|
//# sourceMappingURL=iggy-header.utils.d.ts.map
|
|
@@ -18,8 +18,20 @@
|
|
|
18
18
|
*/
|
|
19
19
|
import { toDate } from "../serialize.utils.js";
|
|
20
20
|
import { u128LEBufToBigint } from "../number.utils.js";
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Size of the Iggy message header in bytes.
|
|
23
|
+
* Layout: u64 (checksum) + u128 (id) + u64 (offset) + u64 (timestamp) + u64 (originTimestamp) + u32 (userHeadersLength) + u32 (payloadLength) + u64 (reserved)
|
|
24
|
+
*/
|
|
25
|
+
export const IGGY_MESSAGE_HEADER_SIZE = 8 + 16 + 8 + 8 + 8 + 4 + 4 + 8;
|
|
26
|
+
/**
|
|
27
|
+
* Serializes an Iggy message header to wire format.
|
|
28
|
+
* Sets checksum, offset, and timestamp to zero (filled by server).
|
|
29
|
+
*
|
|
30
|
+
* @param id - Message ID as 16-byte buffer
|
|
31
|
+
* @param payload - Message payload
|
|
32
|
+
* @param userHeaders - Serialized user headers
|
|
33
|
+
* @returns Serialized header buffer
|
|
34
|
+
*/
|
|
23
35
|
export const serializeIggyMessageHeader = (id, payload, userHeaders) => {
|
|
24
36
|
const b = Buffer.allocUnsafe(IGGY_MESSAGE_HEADER_SIZE);
|
|
25
37
|
b.writeBigUInt64LE(0n, 0); // checksum u64
|
|
@@ -29,9 +41,23 @@ export const serializeIggyMessageHeader = (id, payload, userHeaders) => {
|
|
|
29
41
|
b.writeBigUint64LE(BigInt(new Date().getTime()), 40); // originTimestamp u64
|
|
30
42
|
b.writeUInt32LE(userHeaders.length, 48); // userHeaders len u32
|
|
31
43
|
b.writeUInt32LE(payload.length, 52); // payload len u32
|
|
44
|
+
b.writeBigUInt64LE(0n, 56); // reserved u64
|
|
32
45
|
return b;
|
|
33
46
|
};
|
|
47
|
+
/**
|
|
48
|
+
* Deserializes a message ID from a 16-byte buffer to BigInt.
|
|
49
|
+
*
|
|
50
|
+
* @param b - 16-byte buffer containing the message ID
|
|
51
|
+
* @returns Message ID as BigInt
|
|
52
|
+
*/
|
|
34
53
|
export const deserialiseMessageId = (b) => u128LEBufToBigint(b);
|
|
54
|
+
/**
|
|
55
|
+
* Deserializes Iggy message headers from a buffer.
|
|
56
|
+
*
|
|
57
|
+
* @param b - Buffer containing the serialized header
|
|
58
|
+
* @returns Parsed IggyMessageHeader object
|
|
59
|
+
* @throws Error if buffer length doesn't match expected header size
|
|
60
|
+
*/
|
|
35
61
|
export const deserializeIggyMessageHeaders = (b) => {
|
|
36
62
|
if (b.length !== IGGY_MESSAGE_HEADER_SIZE)
|
|
37
63
|
throw new Error(`deserialize message headers error, length = ${b.length} ` +
|
|
@@ -43,7 +69,8 @@ export const deserializeIggyMessageHeaders = (b) => {
|
|
|
43
69
|
timestamp: toDate(b.readBigUInt64LE(32)),
|
|
44
70
|
originTimestamp: toDate(b.readBigUInt64LE(40)),
|
|
45
71
|
userHeadersLength: b.readUInt32LE(48),
|
|
46
|
-
payloadLength: b.readUInt32LE(52)
|
|
72
|
+
payloadLength: b.readUInt32LE(52),
|
|
73
|
+
reserved: b.readBigUInt64LE(56),
|
|
47
74
|
};
|
|
48
75
|
return headers;
|
|
49
76
|
};
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
19
|
+
export * from "./poll-messages.command.js";
|
|
20
|
+
export * from "./send-messages.command.js";
|
|
21
|
+
export * from "./message.utils.js";
|
|
22
22
|
export * from "./poll.utils.js";
|
|
23
|
-
export { Partitioning } from
|
|
24
|
-
export { HeaderValue } from
|
|
23
|
+
export { Partitioning } from "./partitioning.utils.js";
|
|
24
|
+
export { HeaderValue, HeaderKeyFactory } from "./header.utils.js";
|
|
25
25
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
* specific language governing permissions and limitations
|
|
17
17
|
* under the License.
|
|
18
18
|
*/
|
|
19
|
-
export * from
|
|
20
|
-
export * from
|
|
21
|
-
export * from
|
|
19
|
+
export * from "./poll-messages.command.js";
|
|
20
|
+
export * from "./send-messages.command.js";
|
|
21
|
+
export * from "./message.utils.js";
|
|
22
22
|
export * from "./poll.utils.js";
|
|
23
|
-
export { Partitioning } from
|
|
24
|
-
export { HeaderValue } from
|
|
23
|
+
export { Partitioning } from "./partitioning.utils.js";
|
|
24
|
+
export { HeaderValue, HeaderKeyFactory } from "./header.utils.js";
|
|
25
25
|
//# sourceMappingURL=index.js.map
|