apache-iggy 0.5.0-edge.1
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/LICENSE +201 -0
- package/README.md +81 -0
- package/dist/src/bdd/auth.d.ts +20 -0
- package/dist/src/bdd/auth.js +38 -0
- package/dist/src/bdd/message.d.ts +20 -0
- package/dist/src/bdd/message.js +70 -0
- package/dist/src/bdd/stream.d.ts +20 -0
- package/dist/src/bdd/stream.js +39 -0
- package/dist/src/bdd/topic.d.ts +20 -0
- package/dist/src/bdd/topic.js +36 -0
- package/dist/src/bdd/world.d.ts +30 -0
- package/dist/src/bdd/world.js +21 -0
- package/dist/src/client/client.connection.d.ts +40 -0
- package/dist/src/client/client.connection.js +171 -0
- package/dist/src/client/client.d.ts +38 -0
- package/dist/src/client/client.debug.d.ts +21 -0
- package/dist/src/client/client.debug.js +21 -0
- package/dist/src/client/client.js +97 -0
- package/dist/src/client/client.socket.d.ts +48 -0
- package/dist/src/client/client.socket.js +156 -0
- package/dist/src/client/client.type.d.ts +69 -0
- package/dist/src/client/client.type.js +20 -0
- package/dist/src/client/client.utils.d.ts +29 -0
- package/dist/src/client/client.utils.js +54 -0
- package/dist/src/client/index.d.ts +23 -0
- package/dist/src/client/index.js +23 -0
- package/dist/src/client.e2e.d.ts +20 -0
- package/dist/src/client.e2e.js +54 -0
- package/dist/src/debug-send.d.ts +20 -0
- package/dist/src/debug-send.js +117 -0
- package/dist/src/debug.d.ts +20 -0
- package/dist/src/debug.js +107 -0
- package/dist/src/e2e/tcp.client.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.client.e2e.js +45 -0
- package/dist/src/e2e/tcp.consumer-group.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.consumer-group.e2e.js +111 -0
- package/dist/src/e2e/tcp.consumer-stream.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.consumer-stream.e2e.js +92 -0
- package/dist/src/e2e/tcp.parallel.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.parallel.e2e.js +59 -0
- package/dist/src/e2e/tcp.send-message.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.send-message.e2e.js +118 -0
- package/dist/src/e2e/tcp.stream.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.stream.e2e.js +59 -0
- package/dist/src/e2e/tcp.system.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.system.e2e.js +46 -0
- package/dist/src/e2e/tcp.token.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.token.e2e.js +43 -0
- package/dist/src/e2e/tcp.topic.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.topic.e2e.js +83 -0
- package/dist/src/e2e/tcp.user.e2e.d.ts +20 -0
- package/dist/src/e2e/tcp.user.e2e.js +95 -0
- package/dist/src/e2e/test-client.utils.d.ts +21 -0
- package/dist/src/e2e/test-client.utils.js +28 -0
- package/dist/src/index.d.ts +22 -0
- package/dist/src/index.js +22 -0
- package/dist/src/stream/consumer-stream.d.ts +40 -0
- package/dist/src/stream/consumer-stream.js +79 -0
- package/dist/src/stream/index.d.ts +20 -0
- package/dist/src/stream/index.js +20 -0
- package/dist/src/tcp.e2e.d.ts +20 -0
- package/dist/src/tcp.e2e.js +106 -0
- package/dist/src/tcp.sm.utils.d.ts +97 -0
- package/dist/src/tcp.sm.utils.js +66 -0
- package/dist/src/tls.system.e2e.d.ts +20 -0
- package/dist/src/tls.system.e2e.js +49 -0
- package/dist/src/type.utils.d.ts +21 -0
- package/dist/src/type.utils.js +25 -0
- package/dist/src/wire/client/client.utils.d.ts +32 -0
- package/dist/src/wire/client/client.utils.js +48 -0
- package/dist/src/wire/client/get-client.command.d.ts +30 -0
- package/dist/src/wire/client/get-client.command.js +33 -0
- package/dist/src/wire/client/get-clients.command.d.ts +27 -0
- package/dist/src/wire/client/get-clients.command.js +38 -0
- package/dist/src/wire/client/get-me.command.d.ts +27 -0
- package/dist/src/wire/client/get-me.command.js +28 -0
- package/dist/src/wire/client/index.d.ts +22 -0
- package/dist/src/wire/client/index.js +22 -0
- package/dist/src/wire/command-set.d.ts +128 -0
- package/dist/src/wire/command-set.js +157 -0
- package/dist/src/wire/command.code.d.ts +68 -0
- package/dist/src/wire/command.code.js +72 -0
- package/dist/src/wire/command.utils.d.ts +26 -0
- package/dist/src/wire/command.utils.js +29 -0
- package/dist/src/wire/consumer-group/create-group.command.d.ts +34 -0
- package/dist/src/wire/consumer-group/create-group.command.js +44 -0
- package/dist/src/wire/consumer-group/create-group.command.test.d.ts +20 -0
- package/dist/src/wire/consumer-group/create-group.command.test.js +47 -0
- package/dist/src/wire/consumer-group/delete-group.command.d.ts +31 -0
- package/dist/src/wire/consumer-group/delete-group.command.js +31 -0
- package/dist/src/wire/consumer-group/get-group.command.d.ts +33 -0
- package/dist/src/wire/consumer-group/get-group.command.js +32 -0
- package/dist/src/wire/consumer-group/get-groups.command.d.ts +32 -0
- package/dist/src/wire/consumer-group/get-groups.command.js +36 -0
- package/dist/src/wire/consumer-group/group.command.test.d.ts +20 -0
- package/dist/src/wire/consumer-group/group.command.test.js +50 -0
- package/dist/src/wire/consumer-group/group.utils.d.ts +34 -0
- package/dist/src/wire/consumer-group/group.utils.js +53 -0
- package/dist/src/wire/consumer-group/index.d.ts +25 -0
- package/dist/src/wire/consumer-group/index.js +25 -0
- package/dist/src/wire/consumer-group/join-group.command.d.ts +31 -0
- package/dist/src/wire/consumer-group/join-group.command.js +31 -0
- package/dist/src/wire/consumer-group/leave-group.command.d.ts +31 -0
- package/dist/src/wire/consumer-group/leave-group.command.js +31 -0
- package/dist/src/wire/error.code.d.ts +20 -0
- package/dist/src/wire/error.code.js +202 -0
- package/dist/src/wire/error.utils.d.ts +20 -0
- package/dist/src/wire/error.utils.js +23 -0
- package/dist/src/wire/identifier.utils.d.ts +21 -0
- package/dist/src/wire/identifier.utils.js +49 -0
- package/dist/src/wire/identifier.utils.test.d.ts +20 -0
- package/dist/src/wire/identifier.utils.test.js +40 -0
- package/dist/src/wire/index.d.ts +32 -0
- package/dist/src/wire/index.js +31 -0
- package/dist/src/wire/message/flush-unsaved-buffers.command.d.ts +31 -0
- package/dist/src/wire/message/flush-unsaved-buffers.command.js +31 -0
- package/dist/src/wire/message/header.type.d.ts +101 -0
- package/dist/src/wire/message/header.type.js +55 -0
- package/dist/src/wire/message/header.utils.d.ts +67 -0
- package/dist/src/wire/message/header.utils.js +248 -0
- package/dist/src/wire/message/header.utils.test.d.ts +20 -0
- package/dist/src/wire/message/header.utils.test.js +39 -0
- package/dist/src/wire/message/iggy-header.utils.d.ts +32 -0
- package/dist/src/wire/message/iggy-header.utils.js +50 -0
- package/dist/src/wire/message/index.d.ts +25 -0
- package/dist/src/wire/message/index.js +25 -0
- package/dist/src/wire/message/message.utils.d.ts +35 -0
- package/dist/src/wire/message/message.utils.js +112 -0
- package/dist/src/wire/message/partitioning.utils.d.ts +51 -0
- package/dist/src/wire/message/partitioning.utils.js +77 -0
- package/dist/src/wire/message/poll-messages.command.d.ts +43 -0
- package/dist/src/wire/message/poll-messages.command.js +32 -0
- package/dist/src/wire/message/poll.utils.d.ts +93 -0
- package/dist/src/wire/message/poll.utils.js +135 -0
- package/dist/src/wire/message/send-messages.command.d.ts +34 -0
- package/dist/src/wire/message/send-messages.command.js +31 -0
- package/dist/src/wire/message/send-messages.command.test.d.ts +20 -0
- package/dist/src/wire/message/send-messages.command.test.js +88 -0
- package/dist/src/wire/number.utils.d.ts +32 -0
- package/dist/src/wire/number.utils.js +85 -0
- package/dist/src/wire/offset/delete-offset.command.d.ts +28 -0
- package/dist/src/wire/offset/delete-offset.command.js +31 -0
- package/dist/src/wire/offset/get-offset.command.d.ts +34 -0
- package/dist/src/wire/offset/get-offset.command.js +41 -0
- package/dist/src/wire/offset/index.d.ts +22 -0
- package/dist/src/wire/offset/index.js +22 -0
- package/dist/src/wire/offset/offset.utils.d.ts +54 -0
- package/dist/src/wire/offset/offset.utils.js +60 -0
- package/dist/src/wire/offset/store-offset.command.d.ts +34 -0
- package/dist/src/wire/offset/store-offset.command.js +29 -0
- package/dist/src/wire/partition/create-partition.command.d.ts +31 -0
- package/dist/src/wire/partition/create-partition.command.js +31 -0
- package/dist/src/wire/partition/delete-partition.command.d.ts +31 -0
- package/dist/src/wire/partition/delete-partition.command.js +31 -0
- package/dist/src/wire/partition/index.d.ts +21 -0
- package/dist/src/wire/partition/index.js +21 -0
- package/dist/src/wire/partition/partition.utils.d.ts +21 -0
- package/dist/src/wire/partition/partition.utils.js +33 -0
- package/dist/src/wire/partition/partition.utils.test.d.ts +20 -0
- package/dist/src/wire/partition/partition.utils.test.js +33 -0
- package/dist/src/wire/segment/delete-segments.command.d.ts +32 -0
- package/dist/src/wire/segment/delete-segments.command.js +31 -0
- package/dist/src/wire/segment/index.d.ts +20 -0
- package/dist/src/wire/segment/index.js +20 -0
- package/dist/src/wire/segment/segment.utils.d.ts +21 -0
- package/dist/src/wire/segment/segment.utils.js +35 -0
- package/dist/src/wire/serialize.utils.d.ts +22 -0
- package/dist/src/wire/serialize.utils.js +27 -0
- package/dist/src/wire/session/index.d.ts +23 -0
- package/dist/src/wire/session/index.js +22 -0
- package/dist/src/wire/session/login-with-token.command.d.ts +32 -0
- package/dist/src/wire/session/login-with-token.command.js +30 -0
- package/dist/src/wire/session/login-with-token.command.test.d.ts +20 -0
- package/dist/src/wire/session/login-with-token.command.test.js +38 -0
- package/dist/src/wire/session/login.command.d.ts +29 -0
- package/dist/src/wire/session/login.command.js +30 -0
- package/dist/src/wire/session/login.command.test.d.ts +20 -0
- package/dist/src/wire/session/login.command.test.js +52 -0
- package/dist/src/wire/session/login.utils.d.ts +30 -0
- package/dist/src/wire/session/login.utils.js +54 -0
- package/dist/src/wire/session/logout.command.d.ts +25 -0
- package/dist/src/wire/session/logout.command.js +30 -0
- package/dist/src/wire/stream/create-stream.command.d.ts +31 -0
- package/dist/src/wire/stream/create-stream.command.js +41 -0
- package/dist/src/wire/stream/create-stream.command.test.d.ts +20 -0
- package/dist/src/wire/stream/create-stream.command.test.js +45 -0
- package/dist/src/wire/stream/delete-stream.command.d.ts +29 -0
- package/dist/src/wire/stream/delete-stream.command.js +31 -0
- package/dist/src/wire/stream/get-stream.command.d.ts +31 -0
- package/dist/src/wire/stream/get-stream.command.js +33 -0
- package/dist/src/wire/stream/get-streams.command.d.ts +27 -0
- package/dist/src/wire/stream/get-streams.command.js +38 -0
- package/dist/src/wire/stream/index.d.ts +25 -0
- package/dist/src/wire/stream/index.js +25 -0
- package/dist/src/wire/stream/purge-stream.command.d.ts +29 -0
- package/dist/src/wire/stream/purge-stream.command.js +31 -0
- package/dist/src/wire/stream/stream.utils.d.ts +33 -0
- package/dist/src/wire/stream/stream.utils.js +35 -0
- package/dist/src/wire/stream/update-stream.command.d.ts +30 -0
- package/dist/src/wire/stream/update-stream.command.js +40 -0
- package/dist/src/wire/system/get-stats.command.d.ts +50 -0
- package/dist/src/wire/system/get-stats.command.js +83 -0
- package/dist/src/wire/system/index.d.ts +21 -0
- package/dist/src/wire/system/index.js +21 -0
- package/dist/src/wire/system/ping.command.d.ts +25 -0
- package/dist/src/wire/system/ping.command.js +30 -0
- package/dist/src/wire/token/create-token.command.d.ts +31 -0
- package/dist/src/wire/token/create-token.command.js +37 -0
- package/dist/src/wire/token/create-token.command.test.d.ts +20 -0
- package/dist/src/wire/token/create-token.command.test.js +45 -0
- package/dist/src/wire/token/delete-token.command.d.ts +28 -0
- package/dist/src/wire/token/delete-token.command.js +38 -0
- package/dist/src/wire/token/delete-token.command.test.d.ts +20 -0
- package/dist/src/wire/token/delete-token.command.test.js +42 -0
- package/dist/src/wire/token/get-tokens.command.d.ts +27 -0
- package/dist/src/wire/token/get-tokens.command.js +28 -0
- package/dist/src/wire/token/index.d.ts +22 -0
- package/dist/src/wire/token/index.js +22 -0
- package/dist/src/wire/token/token.utils.d.ts +38 -0
- package/dist/src/wire/token/token.utils.js +53 -0
- package/dist/src/wire/topic/create-topic.command.d.ts +38 -0
- package/dist/src/wire/topic/create-topic.command.js +53 -0
- package/dist/src/wire/topic/create-topic.command.test.d.ts +20 -0
- package/dist/src/wire/topic/create-topic.command.test.js +67 -0
- package/dist/src/wire/topic/delete-topic.command.d.ts +32 -0
- package/dist/src/wire/topic/delete-topic.command.js +36 -0
- package/dist/src/wire/topic/get-topic.command.d.ts +33 -0
- package/dist/src/wire/topic/get-topic.command.js +36 -0
- package/dist/src/wire/topic/get-topics.command.d.ts +31 -0
- package/dist/src/wire/topic/get-topics.command.js +33 -0
- package/dist/src/wire/topic/index.d.ts +25 -0
- package/dist/src/wire/topic/index.js +25 -0
- package/dist/src/wire/topic/purge-topic.command.d.ts +30 -0
- package/dist/src/wire/topic/purge-topic.command.js +34 -0
- package/dist/src/wire/topic/topic.utils.d.ts +71 -0
- package/dist/src/wire/topic/topic.utils.js +91 -0
- package/dist/src/wire/topic/update-topic.command.d.ts +36 -0
- package/dist/src/wire/topic/update-topic.command.js +50 -0
- package/dist/src/wire/user/change-password.command.d.ts +30 -0
- package/dist/src/wire/user/change-password.command.js +45 -0
- package/dist/src/wire/user/create-user.command.d.ts +34 -0
- package/dist/src/wire/user/create-user.command.js +48 -0
- package/dist/src/wire/user/create-user.command.test.d.ts +20 -0
- package/dist/src/wire/user/create-user.command.test.js +60 -0
- package/dist/src/wire/user/delete-user.command.d.ts +29 -0
- package/dist/src/wire/user/delete-user.command.js +31 -0
- package/dist/src/wire/user/get-user.command.d.ts +31 -0
- package/dist/src/wire/user/get-user.command.js +31 -0
- package/dist/src/wire/user/get-users.command.d.ts +27 -0
- package/dist/src/wire/user/get-users.command.js +28 -0
- package/dist/src/wire/user/index.d.ts +26 -0
- package/dist/src/wire/user/index.js +26 -0
- package/dist/src/wire/user/permissions.utils.d.ts +77 -0
- package/dist/src/wire/user/permissions.utils.js +161 -0
- package/dist/src/wire/user/permissions.utils.test.d.ts +20 -0
- package/dist/src/wire/user/permissions.utils.test.js +44 -0
- package/dist/src/wire/user/update-permissions.command.d.ts +31 -0
- package/dist/src/wire/user/update-permissions.command.js +39 -0
- package/dist/src/wire/user/update-user.command.d.ts +32 -0
- package/dist/src/wire/user/update-user.command.js +54 -0
- package/dist/src/wire/user/user.utils.d.ts +41 -0
- package/dist/src/wire/user/user.utils.js +74 -0
- package/dist/src/wire/uuid.utils.d.ts +22 -0
- package/dist/src/wire/uuid.utils.js +23 -0
- package/package.json +70 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { uint32ToBuf, uint64ToBuf } from '../number.utils.js';
|
|
20
|
+
export const PartitionKind = {
|
|
21
|
+
Balanced: 1,
|
|
22
|
+
PartitionId: 2,
|
|
23
|
+
MessageKey: 3
|
|
24
|
+
};
|
|
25
|
+
const Balanced = {
|
|
26
|
+
kind: PartitionKind.Balanced,
|
|
27
|
+
value: null
|
|
28
|
+
};
|
|
29
|
+
const PartitionId = (id) => ({
|
|
30
|
+
kind: PartitionKind.PartitionId,
|
|
31
|
+
value: id
|
|
32
|
+
});
|
|
33
|
+
const MessageKey = (key) => ({
|
|
34
|
+
kind: PartitionKind.MessageKey,
|
|
35
|
+
value: key
|
|
36
|
+
});
|
|
37
|
+
// Helper
|
|
38
|
+
export const Partitioning = {
|
|
39
|
+
Balanced,
|
|
40
|
+
PartitionId,
|
|
41
|
+
MessageKey
|
|
42
|
+
};
|
|
43
|
+
export const serializeMessageKey = (v) => {
|
|
44
|
+
if (v instanceof Buffer)
|
|
45
|
+
return v;
|
|
46
|
+
if ('string' === typeof v)
|
|
47
|
+
return Buffer.from(v);
|
|
48
|
+
if ('number' === typeof v)
|
|
49
|
+
return uint32ToBuf(v);
|
|
50
|
+
if ('bigint' === typeof v)
|
|
51
|
+
return uint64ToBuf(v);
|
|
52
|
+
throw new Error(`cannot serialize messageKey ${v}, ${typeof v}`);
|
|
53
|
+
};
|
|
54
|
+
export const serializePartitioningValue = (part) => {
|
|
55
|
+
const { kind, value } = part;
|
|
56
|
+
switch (kind) {
|
|
57
|
+
case PartitionKind.Balanced: return Buffer.alloc(0);
|
|
58
|
+
case PartitionKind.PartitionId: return uint32ToBuf(value);
|
|
59
|
+
case PartitionKind.MessageKey: return serializeMessageKey(value);
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
export const default_partionning = {
|
|
63
|
+
kind: PartitionKind.Balanced,
|
|
64
|
+
value: null
|
|
65
|
+
};
|
|
66
|
+
export const serializePartitioning = (p) => {
|
|
67
|
+
const part = p || default_partionning;
|
|
68
|
+
const b = Buffer.alloc(2);
|
|
69
|
+
const bValue = serializePartitioningValue(part);
|
|
70
|
+
b.writeUint8(part.kind);
|
|
71
|
+
b.writeUint8(bValue.length, 1);
|
|
72
|
+
return Buffer.concat([
|
|
73
|
+
b,
|
|
74
|
+
bValue
|
|
75
|
+
]);
|
|
76
|
+
};
|
|
77
|
+
//# sourceMappingURL=partitioning.utils.js.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import type { Id } from '../identifier.utils.js';
|
|
20
|
+
import type { CommandResponse } from '../../client/client.type.js';
|
|
21
|
+
import type { Consumer } from '../offset/offset.utils.js';
|
|
22
|
+
import { type PollingStrategy, type PollMessagesResponse } from './poll.utils.js';
|
|
23
|
+
export type PollMessages = {
|
|
24
|
+
streamId: Id;
|
|
25
|
+
topicId: Id;
|
|
26
|
+
consumer: Consumer;
|
|
27
|
+
partitionId: number;
|
|
28
|
+
pollingStrategy: PollingStrategy;
|
|
29
|
+
count: number;
|
|
30
|
+
autocommit: boolean;
|
|
31
|
+
};
|
|
32
|
+
export declare const POLL_MESSAGES: {
|
|
33
|
+
code: number;
|
|
34
|
+
serialize: ({ streamId, topicId, consumer, partitionId, pollingStrategy, count, autocommit }: PollMessages) => Buffer<ArrayBuffer>;
|
|
35
|
+
deserialize: (r: CommandResponse) => {
|
|
36
|
+
partitionId: number;
|
|
37
|
+
currentOffset: bigint;
|
|
38
|
+
count: number;
|
|
39
|
+
messages: import("./poll.utils.js").Message[];
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
export declare const pollMessages: (getClient: import("../../client/client.type.js").ClientProvider) => (arg: PollMessages) => Promise<PollMessagesResponse>;
|
|
43
|
+
//# sourceMappingURL=poll-messages.command.d.ts.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { wrapCommand } from '../command.utils.js';
|
|
20
|
+
import { COMMAND_CODE } from '../command.code.js';
|
|
21
|
+
import { serializePollMessages, deserializePollMessages } from './poll.utils.js';
|
|
22
|
+
export const POLL_MESSAGES = {
|
|
23
|
+
code: COMMAND_CODE.PollMessages,
|
|
24
|
+
serialize: ({ streamId, topicId, consumer, partitionId, pollingStrategy, count, autocommit }) => {
|
|
25
|
+
return serializePollMessages(streamId, topicId, consumer, partitionId, pollingStrategy, count, autocommit);
|
|
26
|
+
},
|
|
27
|
+
deserialize: (r) => {
|
|
28
|
+
return deserializePollMessages(r.data);
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
export const pollMessages = wrapCommand(POLL_MESSAGES);
|
|
32
|
+
//# sourceMappingURL=poll-messages.command.js.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
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';
|
|
25
|
+
export declare const PollingStrategyKind: {
|
|
26
|
+
readonly Offset: 1;
|
|
27
|
+
readonly Timestamp: 2;
|
|
28
|
+
readonly First: 3;
|
|
29
|
+
readonly Last: 4;
|
|
30
|
+
readonly Next: 5;
|
|
31
|
+
};
|
|
32
|
+
export type PollingStrategyKind = typeof PollingStrategyKind;
|
|
33
|
+
export type PollingStrategyKindId = keyof PollingStrategyKind;
|
|
34
|
+
export type PollingStrategyKindValue = ValueOf<PollingStrategyKind>;
|
|
35
|
+
export type OffsetPollingStrategy = {
|
|
36
|
+
kind: PollingStrategyKind['Offset'];
|
|
37
|
+
value: bigint;
|
|
38
|
+
};
|
|
39
|
+
export type TimestampPollingStrategy = {
|
|
40
|
+
kind: PollingStrategyKind['Timestamp'];
|
|
41
|
+
value: bigint;
|
|
42
|
+
};
|
|
43
|
+
export type FirstPollingStrategy = {
|
|
44
|
+
kind: PollingStrategyKind['First'];
|
|
45
|
+
value: 0n;
|
|
46
|
+
};
|
|
47
|
+
export type LastPollingStrategy = {
|
|
48
|
+
kind: PollingStrategyKind['Last'];
|
|
49
|
+
value: 0n;
|
|
50
|
+
};
|
|
51
|
+
export type NextPollingStrategy = {
|
|
52
|
+
kind: PollingStrategyKind['Next'];
|
|
53
|
+
value: 0n;
|
|
54
|
+
};
|
|
55
|
+
export type PollingStrategy = OffsetPollingStrategy | TimestampPollingStrategy | FirstPollingStrategy | LastPollingStrategy | NextPollingStrategy;
|
|
56
|
+
export declare const PollingStrategy: {
|
|
57
|
+
Next: NextPollingStrategy;
|
|
58
|
+
First: FirstPollingStrategy;
|
|
59
|
+
Last: LastPollingStrategy;
|
|
60
|
+
Offset: (n: bigint) => OffsetPollingStrategy;
|
|
61
|
+
Timestamp: (n: bigint) => TimestampPollingStrategy;
|
|
62
|
+
};
|
|
63
|
+
export declare const serializePollMessages: (streamId: Id, topicId: Id, consumer: Consumer, partitionId: number, pollingStrategy: PollingStrategy, count?: number, autocommit?: boolean) => Buffer<ArrayBuffer>;
|
|
64
|
+
export declare const MessageState: {
|
|
65
|
+
Available: number;
|
|
66
|
+
Unavailable: number;
|
|
67
|
+
Poisoned: number;
|
|
68
|
+
MarkedForDeletion: number;
|
|
69
|
+
};
|
|
70
|
+
type MessageState = typeof MessageState;
|
|
71
|
+
type MessageStateId = keyof MessageState;
|
|
72
|
+
export declare const mapMessageState: (k: number) => MessageStateId;
|
|
73
|
+
export type Message = {
|
|
74
|
+
headers: IggyMessageHeader;
|
|
75
|
+
payload: Buffer;
|
|
76
|
+
userHeaders: HeadersMap;
|
|
77
|
+
};
|
|
78
|
+
export type PollMessagesResponse = {
|
|
79
|
+
partitionId: number;
|
|
80
|
+
currentOffset: bigint;
|
|
81
|
+
count: number;
|
|
82
|
+
messages: Message[];
|
|
83
|
+
};
|
|
84
|
+
export declare const deserializeMessages: (b: Buffer) => Message[];
|
|
85
|
+
export declare const deserializePollMessages: (r: Buffer, pos?: number) => {
|
|
86
|
+
partitionId: number;
|
|
87
|
+
currentOffset: bigint;
|
|
88
|
+
count: number;
|
|
89
|
+
messages: Message[];
|
|
90
|
+
};
|
|
91
|
+
export declare const deserializePollMessagesTransform: () => Transform;
|
|
92
|
+
export {};
|
|
93
|
+
//# sourceMappingURL=poll.utils.d.ts.map
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
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';
|
|
24
|
+
export const PollingStrategyKind = {
|
|
25
|
+
Offset: 1,
|
|
26
|
+
Timestamp: 2,
|
|
27
|
+
First: 3,
|
|
28
|
+
Last: 4,
|
|
29
|
+
Next: 5
|
|
30
|
+
};
|
|
31
|
+
const Next = {
|
|
32
|
+
kind: PollingStrategyKind.Next,
|
|
33
|
+
value: 0n
|
|
34
|
+
};
|
|
35
|
+
const First = {
|
|
36
|
+
kind: PollingStrategyKind.First,
|
|
37
|
+
value: 0n
|
|
38
|
+
};
|
|
39
|
+
const Last = {
|
|
40
|
+
kind: PollingStrategyKind.Last,
|
|
41
|
+
value: 0n
|
|
42
|
+
};
|
|
43
|
+
const Offset = (n) => ({
|
|
44
|
+
kind: PollingStrategyKind.Offset,
|
|
45
|
+
value: n
|
|
46
|
+
});
|
|
47
|
+
const Timestamp = (n) => ({
|
|
48
|
+
kind: PollingStrategyKind.Timestamp,
|
|
49
|
+
value: n
|
|
50
|
+
});
|
|
51
|
+
// helper
|
|
52
|
+
export const PollingStrategy = {
|
|
53
|
+
Next,
|
|
54
|
+
First,
|
|
55
|
+
Last,
|
|
56
|
+
Offset,
|
|
57
|
+
Timestamp
|
|
58
|
+
};
|
|
59
|
+
export const serializePollMessages = (streamId, topicId, consumer, partitionId, // default to 1
|
|
60
|
+
pollingStrategy, // default to OffsetPollingStrategy
|
|
61
|
+
count = 10, autocommit = false) => {
|
|
62
|
+
const b = Buffer.allocUnsafe(14);
|
|
63
|
+
b.writeUInt8(pollingStrategy.kind, 0);
|
|
64
|
+
b.writeBigUInt64LE(pollingStrategy.value, 1);
|
|
65
|
+
b.writeUInt32LE(count, 9);
|
|
66
|
+
b.writeUInt8(!!autocommit ? 1 : 0, 13);
|
|
67
|
+
return Buffer.concat([
|
|
68
|
+
serializeGetOffset(streamId, topicId, consumer, partitionId),
|
|
69
|
+
b
|
|
70
|
+
]);
|
|
71
|
+
};
|
|
72
|
+
export const MessageState = {
|
|
73
|
+
Available: 1,
|
|
74
|
+
Unavailable: 10,
|
|
75
|
+
Poisoned: 20,
|
|
76
|
+
MarkedForDeletion: 30
|
|
77
|
+
};
|
|
78
|
+
const ReverseMessageState = reverseRecord(MessageState);
|
|
79
|
+
export const mapMessageState = (k) => {
|
|
80
|
+
if (!ReverseMessageState[k])
|
|
81
|
+
throw new Error(`unknow message state: ${k}`);
|
|
82
|
+
return ReverseMessageState[k];
|
|
83
|
+
};
|
|
84
|
+
export const deserializeMessages = (b) => {
|
|
85
|
+
const messages = [];
|
|
86
|
+
let pos = 0;
|
|
87
|
+
const len = b.length;
|
|
88
|
+
while (pos < len) {
|
|
89
|
+
if (pos + IGGY_MESSAGE_HEADER_SIZE > len)
|
|
90
|
+
break;
|
|
91
|
+
const bHead = b.subarray(pos, pos + IGGY_MESSAGE_HEADER_SIZE);
|
|
92
|
+
const headers = deserializeIggyMessageHeaders(bHead);
|
|
93
|
+
pos += IGGY_MESSAGE_HEADER_SIZE;
|
|
94
|
+
const plEnd = pos + headers.payloadLength;
|
|
95
|
+
if (plEnd > len)
|
|
96
|
+
break;
|
|
97
|
+
const payload = b.subarray(pos, plEnd);
|
|
98
|
+
pos += headers.payloadLength;
|
|
99
|
+
let userHeaders = {};
|
|
100
|
+
if (headers.userHeadersLength > 0 && plEnd + headers.userHeadersLength <= len) {
|
|
101
|
+
userHeaders = deserializeHeaders(b.subarray(plEnd, plEnd + headers.userHeadersLength));
|
|
102
|
+
pos += headers.userHeadersLength;
|
|
103
|
+
}
|
|
104
|
+
messages.push({
|
|
105
|
+
headers,
|
|
106
|
+
payload,
|
|
107
|
+
userHeaders
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return messages;
|
|
111
|
+
};
|
|
112
|
+
export const deserializePollMessages = (r, pos = 0) => {
|
|
113
|
+
const partitionId = r.readUInt32LE(pos);
|
|
114
|
+
const currentOffset = r.readBigUInt64LE(pos + 4);
|
|
115
|
+
const count = r.readUInt32LE(pos + 12);
|
|
116
|
+
const messages = deserializeMessages(r.subarray(16));
|
|
117
|
+
return {
|
|
118
|
+
partitionId,
|
|
119
|
+
currentOffset,
|
|
120
|
+
count,
|
|
121
|
+
messages
|
|
122
|
+
};
|
|
123
|
+
};
|
|
124
|
+
export const deserializePollMessagesTransform = () => new Transform({
|
|
125
|
+
objectMode: true,
|
|
126
|
+
transform(chunk, encoding, cb) {
|
|
127
|
+
try {
|
|
128
|
+
return cb(null, deserializePollMessages(chunk));
|
|
129
|
+
}
|
|
130
|
+
catch (err) {
|
|
131
|
+
cb(new Error('deserializePollMessage::transform error', { cause: err }), null);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
//# sourceMappingURL=poll.utils.js.map
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { type Id } from '../identifier.utils.js';
|
|
20
|
+
import { type CreateMessage } from './message.utils.js';
|
|
21
|
+
import type { Partitioning } from './partitioning.utils.js';
|
|
22
|
+
export type SendMessages = {
|
|
23
|
+
streamId: Id;
|
|
24
|
+
topicId: Id;
|
|
25
|
+
messages: CreateMessage[];
|
|
26
|
+
partition?: Partitioning;
|
|
27
|
+
};
|
|
28
|
+
export declare const SEND_MESSAGES: {
|
|
29
|
+
code: number;
|
|
30
|
+
serialize: ({ streamId, topicId, messages, partition }: SendMessages) => Buffer<ArrayBuffer>;
|
|
31
|
+
deserialize: (r: import("../../index.js").CommandResponse) => boolean;
|
|
32
|
+
};
|
|
33
|
+
export declare const sendMessages: (getClient: import("../../index.js").ClientProvider) => (arg: SendMessages) => Promise<boolean>;
|
|
34
|
+
//# sourceMappingURL=send-messages.command.d.ts.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
import { serializeSendMessages } from './message.utils.js';
|
|
20
|
+
import { deserializeVoidResponse } from '../../client/client.utils.js';
|
|
21
|
+
import { wrapCommand } from '../command.utils.js';
|
|
22
|
+
import { COMMAND_CODE } from '../command.code.js';
|
|
23
|
+
export const SEND_MESSAGES = {
|
|
24
|
+
code: COMMAND_CODE.SendMessages,
|
|
25
|
+
serialize: ({ streamId, topicId, messages, partition }) => {
|
|
26
|
+
return serializeSendMessages(streamId, topicId, messages, partition);
|
|
27
|
+
},
|
|
28
|
+
deserialize: deserializeVoidResponse
|
|
29
|
+
};
|
|
30
|
+
export const sendMessages = wrapCommand(SEND_MESSAGES);
|
|
31
|
+
//# sourceMappingURL=send-messages.command.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=send-messages.command.test.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
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', () => {
|
|
26
|
+
const t1 = {
|
|
27
|
+
streamId: 911,
|
|
28
|
+
topicId: 213,
|
|
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' },
|
|
37
|
+
],
|
|
38
|
+
};
|
|
39
|
+
it('serialize SendMessages into a buffer', () => {
|
|
40
|
+
assert.deepEqual(SEND_MESSAGES.serialize(t1).length, 533);
|
|
41
|
+
});
|
|
42
|
+
it('serialize all kinds of messageId', () => {
|
|
43
|
+
assert.doesNotThrow(() => SEND_MESSAGES.serialize(t1));
|
|
44
|
+
});
|
|
45
|
+
it('does not throw on number message id', () => {
|
|
46
|
+
const t = { ...t1, messages: [{ id: 42, payload: 'm' }] };
|
|
47
|
+
assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
|
|
48
|
+
});
|
|
49
|
+
it('does not throw on bigint message id', () => {
|
|
50
|
+
const t = { ...t1, messages: [{ id: 123n, payload: 'm' }] };
|
|
51
|
+
assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
|
|
52
|
+
});
|
|
53
|
+
it('does not throw on uuid message id', () => {
|
|
54
|
+
const t = { ...t1, messages: [{ id: uuidv4(), payload: 'uuid' }] };
|
|
55
|
+
assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
|
|
56
|
+
});
|
|
57
|
+
it('throw on invalid string message id', () => {
|
|
58
|
+
const t = { ...t1, messages: [{ id: 'foo', payload: 'm' }] };
|
|
59
|
+
assert.throws(() => SEND_MESSAGES.serialize(t));
|
|
60
|
+
});
|
|
61
|
+
it('throw on invalid number message id', () => {
|
|
62
|
+
const t = { ...t1, messages: [{ id: -12, payload: 'n' }] };
|
|
63
|
+
assert.throws(() => SEND_MESSAGES.serialize(t));
|
|
64
|
+
});
|
|
65
|
+
it('throw on invalid bigint message id', () => {
|
|
66
|
+
const t = { ...t1, messages: [{ id: -12n, payload: 'bn' }] };
|
|
67
|
+
assert.throws(() => SEND_MESSAGES.serialize(t));
|
|
68
|
+
});
|
|
69
|
+
it('serialize message with headers', () => {
|
|
70
|
+
const t = {
|
|
71
|
+
streamId: 911,
|
|
72
|
+
topicId: 213,
|
|
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
|
+
]
|
|
83
|
+
};
|
|
84
|
+
assert.doesNotThrow(() => SEND_MESSAGES.serialize(t));
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
//# sourceMappingURL=send-messages.command.test.js.map
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
export declare const boolToBuf: (v: boolean) => Buffer<ArrayBuffer>;
|
|
20
|
+
export declare const int8ToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
21
|
+
export declare const int16ToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
22
|
+
export declare const int32ToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
23
|
+
export declare const int64ToBuf: (v: bigint) => Buffer<ArrayBuffer>;
|
|
24
|
+
export declare const uint8ToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
25
|
+
export declare const uint16ToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
26
|
+
export declare const uint32ToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
27
|
+
export declare const uint64ToBuf: (v: bigint) => Buffer<ArrayBuffer>;
|
|
28
|
+
export declare const floatToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
29
|
+
export declare const doubleToBuf: (v: number) => Buffer<ArrayBuffer>;
|
|
30
|
+
export declare function u128ToBuf(num: bigint, width?: number): Buffer;
|
|
31
|
+
export declare function u128LEBufToBigint(b: Buffer): bigint;
|
|
32
|
+
//# sourceMappingURL=number.utils.d.ts.map
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
+
* or more contributor license agreements. See the NOTICE file
|
|
4
|
+
* distributed with this work for additional information
|
|
5
|
+
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
+
* to you under the Apache License, Version 2.0 (the
|
|
7
|
+
* "License"); you may not use this file except in compliance
|
|
8
|
+
* with the License. You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing,
|
|
13
|
+
* software distributed under the License is distributed on an
|
|
14
|
+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
+
* KIND, either express or implied. See the License for the
|
|
16
|
+
* specific language governing permissions and limitations
|
|
17
|
+
* under the License.
|
|
18
|
+
*/
|
|
19
|
+
export const boolToBuf = (v) => {
|
|
20
|
+
const b = Buffer.allocUnsafe(1);
|
|
21
|
+
b.writeUInt8(!v ? 0 : 1);
|
|
22
|
+
return b;
|
|
23
|
+
};
|
|
24
|
+
export const int8ToBuf = (v) => {
|
|
25
|
+
const b = Buffer.allocUnsafe(1);
|
|
26
|
+
b.writeInt8(v);
|
|
27
|
+
return b;
|
|
28
|
+
};
|
|
29
|
+
export const int16ToBuf = (v) => {
|
|
30
|
+
const b = Buffer.allocUnsafe(2);
|
|
31
|
+
b.writeInt16LE(v);
|
|
32
|
+
return b;
|
|
33
|
+
};
|
|
34
|
+
export const int32ToBuf = (v) => {
|
|
35
|
+
const b = Buffer.allocUnsafe(4);
|
|
36
|
+
b.writeInt32LE(v);
|
|
37
|
+
return b;
|
|
38
|
+
};
|
|
39
|
+
export const int64ToBuf = (v) => {
|
|
40
|
+
const b = Buffer.allocUnsafe(8);
|
|
41
|
+
b.writeBigInt64LE(v);
|
|
42
|
+
return b;
|
|
43
|
+
};
|
|
44
|
+
export const uint8ToBuf = (v) => {
|
|
45
|
+
const b = Buffer.allocUnsafe(1);
|
|
46
|
+
b.writeUInt8(v);
|
|
47
|
+
return b;
|
|
48
|
+
};
|
|
49
|
+
export const uint16ToBuf = (v) => {
|
|
50
|
+
const b = Buffer.allocUnsafe(2);
|
|
51
|
+
b.writeUInt16LE(v);
|
|
52
|
+
return b;
|
|
53
|
+
};
|
|
54
|
+
export const uint32ToBuf = (v) => {
|
|
55
|
+
const b = Buffer.allocUnsafe(4);
|
|
56
|
+
b.writeUInt32LE(v);
|
|
57
|
+
return b;
|
|
58
|
+
};
|
|
59
|
+
export const uint64ToBuf = (v) => {
|
|
60
|
+
const b = Buffer.allocUnsafe(8);
|
|
61
|
+
b.writeBigUInt64LE(v);
|
|
62
|
+
return b;
|
|
63
|
+
};
|
|
64
|
+
export const floatToBuf = (v) => {
|
|
65
|
+
const b = Buffer.allocUnsafe(4);
|
|
66
|
+
b.writeFloatLE(v);
|
|
67
|
+
return b;
|
|
68
|
+
};
|
|
69
|
+
export const doubleToBuf = (v) => {
|
|
70
|
+
const b = Buffer.allocUnsafe(8);
|
|
71
|
+
b.writeDoubleLE(v);
|
|
72
|
+
return b;
|
|
73
|
+
};
|
|
74
|
+
// bigint => u128 LE
|
|
75
|
+
export function u128ToBuf(num, width = 16) {
|
|
76
|
+
const hex = num.toString(16);
|
|
77
|
+
const b = Buffer.from(hex.padStart(width * 2, '0').slice(0, width * 2), 'hex');
|
|
78
|
+
return b.reverse();
|
|
79
|
+
}
|
|
80
|
+
// u128 LE => Bigint
|
|
81
|
+
export function u128LEBufToBigint(b) {
|
|
82
|
+
const hex = b.reverse().toString('hex');
|
|
83
|
+
return hex.length === 0 ? BigInt(0) : BigInt(`0x${hex}`);
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=number.utils.js.map
|