kafka-ts 1.3.1-beta.1 → 1.3.1-beta.2

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 (102) hide show
  1. package/README.md +7 -7
  2. package/dist/api/alter-configs.d.ts +26 -0
  3. package/dist/api/alter-configs.js +33 -0
  4. package/dist/api/api-versions.d.ts +5 -2
  5. package/dist/api/api-versions.js +13 -0
  6. package/dist/api/create-topics.d.ts +14 -12
  7. package/dist/api/create-topics.js +104 -12
  8. package/dist/api/delete-topics.d.ts +10 -8
  9. package/dist/api/delete-topics.js +61 -7
  10. package/dist/api/fetch.d.ts +15 -12
  11. package/dist/api/fetch.js +131 -13
  12. package/dist/api/find-coordinator.d.ts +9 -7
  13. package/dist/api/find-coordinator.js +63 -5
  14. package/dist/api/heartbeat.d.ts +7 -5
  15. package/dist/api/heartbeat.js +42 -4
  16. package/dist/api/index.d.ts +47 -118
  17. package/dist/api/init-producer-id.d.ts +7 -5
  18. package/dist/api/init-producer-id.js +53 -9
  19. package/dist/api/join-group.d.ts +9 -7
  20. package/dist/api/join-group.js +95 -6
  21. package/dist/api/leave-group.d.ts +8 -6
  22. package/dist/api/leave-group.js +49 -6
  23. package/dist/api/list-offsets.d.ts +9 -7
  24. package/dist/api/list-offsets.js +85 -8
  25. package/dist/api/metadata.d.ts +10 -9
  26. package/dist/api/metadata.js +109 -8
  27. package/dist/api/offset-commit.d.ts +10 -8
  28. package/dist/api/offset-commit.js +88 -8
  29. package/dist/api/offset-fetch.d.ts +11 -9
  30. package/dist/api/offset-fetch.js +94 -9
  31. package/dist/api/produce.d.ts +8 -10
  32. package/dist/api/produce.js +132 -38
  33. package/dist/api/sasl-authenticate.d.ts +8 -6
  34. package/dist/api/sasl-authenticate.js +43 -3
  35. package/dist/api/sasl-handshake.d.ts +7 -4
  36. package/dist/api/sasl-handshake.js +10 -0
  37. package/dist/api/sync-group.d.ts +7 -5
  38. package/dist/api/sync-group.js +62 -5
  39. package/dist/broker.js +6 -5
  40. package/dist/cluster.test.js +17 -14
  41. package/dist/connection.d.ts +11 -1
  42. package/dist/connection.js +27 -2
  43. package/dist/consumer/consumer.js +13 -9
  44. package/dist/consumer/metadata.d.ts +24 -0
  45. package/dist/consumer/metadata.js +64 -0
  46. package/dist/distributors/messages-to-topic-partition-leaders.d.ts +17 -0
  47. package/dist/distributors/messages-to-topic-partition-leaders.js +15 -0
  48. package/dist/distributors/messages-to-topic-partition-leaders.test.d.ts +1 -0
  49. package/dist/distributors/messages-to-topic-partition-leaders.test.js +30 -0
  50. package/dist/examples/src/replicator.js +34 -0
  51. package/dist/examples/src/utils/json.js +5 -0
  52. package/dist/request-handler.d.ts +16 -0
  53. package/dist/request-handler.js +67 -0
  54. package/dist/request-handler.test.d.ts +1 -0
  55. package/dist/request-handler.test.js +340 -0
  56. package/dist/src/api/api-versions.js +18 -0
  57. package/dist/src/api/create-topics.js +46 -0
  58. package/dist/src/api/delete-topics.js +26 -0
  59. package/dist/src/api/fetch.js +95 -0
  60. package/dist/src/api/find-coordinator.js +34 -0
  61. package/dist/src/api/heartbeat.js +22 -0
  62. package/dist/src/api/index.js +38 -0
  63. package/dist/src/api/init-producer-id.js +24 -0
  64. package/dist/src/api/join-group.js +48 -0
  65. package/dist/src/api/leave-group.js +30 -0
  66. package/dist/src/api/list-offsets.js +39 -0
  67. package/dist/src/api/metadata.js +47 -0
  68. package/dist/src/api/offset-commit.js +39 -0
  69. package/dist/src/api/offset-fetch.js +44 -0
  70. package/dist/src/api/produce.js +119 -0
  71. package/dist/src/api/sync-group.js +31 -0
  72. package/dist/src/broker.js +35 -0
  73. package/dist/src/connection.js +21 -0
  74. package/dist/src/consumer/consumer-group.js +131 -0
  75. package/dist/src/consumer/consumer.js +103 -0
  76. package/dist/src/consumer/metadata.js +52 -0
  77. package/dist/src/consumer/offset-manager.js +23 -0
  78. package/dist/src/index.js +19 -0
  79. package/dist/src/producer/producer.js +84 -0
  80. package/dist/src/request-handler.js +57 -0
  81. package/dist/src/request-handler.test.js +321 -0
  82. package/dist/src/types.js +2 -0
  83. package/dist/src/utils/api.js +5 -0
  84. package/dist/src/utils/decoder.js +161 -0
  85. package/dist/src/utils/encoder.js +137 -0
  86. package/dist/src/utils/error.js +10 -0
  87. package/dist/utils/api.d.ts +4 -1
  88. package/dist/utils/cached.d.ts +3 -0
  89. package/dist/utils/cached.js +19 -0
  90. package/dist/utils/debug.d.ts +2 -0
  91. package/dist/utils/debug.js +11 -0
  92. package/dist/utils/decoder.d.ts +2 -2
  93. package/dist/utils/decoder.js +14 -1
  94. package/dist/utils/encoder.d.ts +1 -0
  95. package/dist/utils/encoder.js +14 -0
  96. package/dist/utils/lock.d.ts +8 -0
  97. package/dist/utils/lock.js +44 -0
  98. package/dist/utils/memo.d.ts +1 -0
  99. package/dist/utils/memo.js +16 -0
  100. package/dist/utils/mutex.d.ts +3 -0
  101. package/dist/utils/mutex.js +32 -0
  102. package/package.json +1 -1
@@ -3,30 +3,73 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LEAVE_GROUP = void 0;
4
4
  const api_1 = require("../utils/api");
5
5
  const error_1 = require("../utils/error");
6
+ /*
7
+ LeaveGroup Request (Version: 0) => group_id member_id
8
+ group_id => STRING
9
+ member_id => STRING
10
+
11
+ LeaveGroup Response (Version: 0) => error_code
12
+ error_code => INT16
13
+ */
14
+ const LEAVE_GROUP_V0 = (0, api_1.createApi)({
15
+ apiKey: 13,
16
+ apiVersion: 0,
17
+ requestHeaderVersion: 1,
18
+ responseHeaderVersion: 0,
19
+ request: (encoder, body) => encoder.writeString(body.groupId).writeString(body.members[0].memberId),
20
+ response: (decoder) => {
21
+ const result = {
22
+ throttleTimeMs: 0,
23
+ errorCode: decoder.readInt16(),
24
+ members: [],
25
+ tags: {},
26
+ };
27
+ if (result.errorCode)
28
+ throw new error_1.KafkaTSApiError(result.errorCode, null, result);
29
+ return result;
30
+ },
31
+ });
32
+ /*
33
+ LeaveGroup Request (Version: 5) => group_id [members] _tagged_fields
34
+ group_id => COMPACT_STRING
35
+ members => member_id group_instance_id reason _tagged_fields
36
+ member_id => COMPACT_STRING
37
+ group_instance_id => COMPACT_NULLABLE_STRING
38
+ reason => COMPACT_NULLABLE_STRING
39
+
40
+ LeaveGroup Response (Version: 5) => throttle_time_ms error_code [members] _tagged_fields
41
+ throttle_time_ms => INT32
42
+ error_code => INT16
43
+ members => member_id group_instance_id error_code _tagged_fields
44
+ member_id => COMPACT_STRING
45
+ group_instance_id => COMPACT_NULLABLE_STRING
46
+ error_code => INT16
47
+ */
6
48
  exports.LEAVE_GROUP = (0, api_1.createApi)({
7
49
  apiKey: 13,
8
50
  apiVersion: 5,
51
+ fallback: LEAVE_GROUP_V0,
52
+ requestHeaderVersion: 2,
53
+ responseHeaderVersion: 1,
9
54
  request: (encoder, body) => encoder
10
- .writeUVarInt(0)
11
55
  .writeCompactString(body.groupId)
12
56
  .writeCompactArray(body.members, (encoder, member) => encoder
13
57
  .writeCompactString(member.memberId)
14
58
  .writeCompactString(member.groupInstanceId)
15
59
  .writeCompactString(member.reason)
16
- .writeUVarInt(0))
17
- .writeUVarInt(0),
60
+ .writeTagBuffer())
61
+ .writeTagBuffer(),
18
62
  response: (decoder) => {
19
63
  const result = {
20
- _tag: decoder.readTagBuffer(),
21
64
  throttleTimeMs: decoder.readInt32(),
22
65
  errorCode: decoder.readInt16(),
23
66
  members: decoder.readCompactArray((decoder) => ({
24
67
  memberId: decoder.readCompactString(),
25
68
  groupInstanceId: decoder.readCompactString(),
26
69
  errorCode: decoder.readInt16(),
27
- _tag: decoder.readTagBuffer(),
70
+ tags: decoder.readTagBuffer(),
28
71
  })),
29
- _tag2: decoder.readTagBuffer(),
72
+ tags: decoder.readTagBuffer(),
30
73
  };
31
74
  if (result.errorCode)
32
75
  throw new error_1.KafkaTSApiError(result.errorCode, null, result);
@@ -1,5 +1,5 @@
1
1
  import { IsolationLevel } from './fetch';
2
- export declare const LIST_OFFSETS: import("../utils/api").Api<{
2
+ type ListOffsetsRequest = {
3
3
  replicaId: number;
4
4
  isolationLevel: IsolationLevel;
5
5
  topics: {
@@ -10,8 +10,8 @@ export declare const LIST_OFFSETS: import("../utils/api").Api<{
10
10
  timestamp: bigint;
11
11
  }[];
12
12
  }[];
13
- }, {
14
- _tag: void;
13
+ };
14
+ type ListOffsetsResponse = {
15
15
  throttleTimeMs: number;
16
16
  topics: {
17
17
  name: string;
@@ -21,9 +21,11 @@ export declare const LIST_OFFSETS: import("../utils/api").Api<{
21
21
  timestamp: bigint;
22
22
  offset: bigint;
23
23
  leaderEpoch: number;
24
- _tag: void;
24
+ tags: Record<number, Buffer>;
25
25
  }[];
26
- _tag: void;
26
+ tags: Record<number, Buffer>;
27
27
  }[];
28
- _tag2: void;
29
- }>;
28
+ tags: Record<number, Buffer>;
29
+ };
30
+ export declare const LIST_OFFSETS: import("../utils/api").Api<ListOffsetsRequest, ListOffsetsResponse>;
31
+ export {};
@@ -3,11 +3,89 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LIST_OFFSETS = void 0;
4
4
  const api_1 = require("../utils/api");
5
5
  const error_1 = require("../utils/error");
6
+ /*
7
+ ListOffsets Request (Version: 1) => replica_id [topics]
8
+ replica_id => INT32
9
+ topics => name [partitions]
10
+ name => STRING
11
+ partitions => partition_index timestamp
12
+ partition_index => INT32
13
+ timestamp => INT64
14
+
15
+ ListOffsets Response (Version: 1) => [topics]
16
+ topics => name [partitions]
17
+ name => STRING
18
+ partitions => partition_index error_code timestamp offset
19
+ partition_index => INT32
20
+ error_code => INT16
21
+ timestamp => INT64
22
+ offset => INT64
23
+ */
24
+ const LIST_OFFSETS_V1 = (0, api_1.createApi)({
25
+ apiKey: 2,
26
+ apiVersion: 1,
27
+ requestHeaderVersion: 1,
28
+ responseHeaderVersion: 0,
29
+ request: (encoder, data) => encoder
30
+ .writeInt32(data.replicaId)
31
+ .writeArray(data.topics, (encoder, topic) => encoder
32
+ .writeString(topic.name)
33
+ .writeArray(topic.partitions, (encoder, partition) => encoder.writeInt32(partition.partitionIndex).writeInt64(partition.timestamp))),
34
+ response: (decoder) => {
35
+ const result = {
36
+ throttleTimeMs: 0,
37
+ topics: decoder.readArray((decoder) => ({
38
+ name: decoder.readString(),
39
+ partitions: decoder.readArray((decoder) => ({
40
+ partitionIndex: decoder.readInt32(),
41
+ errorCode: decoder.readInt16(),
42
+ timestamp: decoder.readInt64(),
43
+ offset: decoder.readInt64(),
44
+ leaderEpoch: -1,
45
+ tags: {},
46
+ })),
47
+ tags: {},
48
+ })),
49
+ tags: {},
50
+ };
51
+ result.topics.forEach((topic) => {
52
+ topic.partitions.forEach((partition) => {
53
+ if (partition.errorCode)
54
+ throw new error_1.KafkaTSApiError(partition.errorCode, null, result);
55
+ });
56
+ });
57
+ return result;
58
+ },
59
+ });
60
+ /*
61
+ ListOffsets Request (Version: 8) => replica_id isolation_level [topics] _tagged_fields
62
+ replica_id => INT32
63
+ isolation_level => INT8
64
+ topics => name [partitions] _tagged_fields
65
+ name => COMPACT_STRING
66
+ partitions => partition_index current_leader_epoch timestamp _tagged_fields
67
+ partition_index => INT32
68
+ current_leader_epoch => INT32
69
+ timestamp => INT64
70
+
71
+ ListOffsets Response (Version: 8) => throttle_time_ms [topics] _tagged_fields
72
+ throttle_time_ms => INT32
73
+ topics => name [partitions] _tagged_fields
74
+ name => COMPACT_STRING
75
+ partitions => partition_index error_code timestamp offset leader_epoch _tagged_fields
76
+ partition_index => INT32
77
+ error_code => INT16
78
+ timestamp => INT64
79
+ offset => INT64
80
+ leader_epoch => INT32
81
+ */
6
82
  exports.LIST_OFFSETS = (0, api_1.createApi)({
7
83
  apiKey: 2,
8
84
  apiVersion: 8,
85
+ fallback: LIST_OFFSETS_V1,
86
+ requestHeaderVersion: 2,
87
+ responseHeaderVersion: 1,
9
88
  request: (encoder, data) => encoder
10
- .writeUVarInt(0)
11
89
  .writeInt32(data.replicaId)
12
90
  .writeInt8(data.isolationLevel)
13
91
  .writeCompactArray(data.topics, (encoder, topic) => encoder
@@ -16,12 +94,11 @@ exports.LIST_OFFSETS = (0, api_1.createApi)({
16
94
  .writeInt32(partition.partitionIndex)
17
95
  .writeInt32(partition.currentLeaderEpoch)
18
96
  .writeInt64(partition.timestamp)
19
- .writeUVarInt(0))
20
- .writeUVarInt(0))
21
- .writeUVarInt(0),
97
+ .writeTagBuffer())
98
+ .writeTagBuffer())
99
+ .writeTagBuffer(),
22
100
  response: (decoder) => {
23
101
  const result = {
24
- _tag: decoder.readTagBuffer(),
25
102
  throttleTimeMs: decoder.readInt32(),
26
103
  topics: decoder.readCompactArray((decoder) => ({
27
104
  name: decoder.readCompactString(),
@@ -31,11 +108,11 @@ exports.LIST_OFFSETS = (0, api_1.createApi)({
31
108
  timestamp: decoder.readInt64(),
32
109
  offset: decoder.readInt64(),
33
110
  leaderEpoch: decoder.readInt32(),
34
- _tag: decoder.readTagBuffer(),
111
+ tags: decoder.readTagBuffer(),
35
112
  })),
36
- _tag: decoder.readTagBuffer(),
113
+ tags: decoder.readTagBuffer(),
37
114
  })),
38
- _tag2: decoder.readTagBuffer(),
115
+ tags: decoder.readTagBuffer(),
39
116
  };
40
117
  result.topics.forEach((topic) => {
41
118
  topic.partitions.forEach((partition) => {
@@ -1,20 +1,18 @@
1
- export type Metadata = Awaited<ReturnType<(typeof METADATA)['response']>>;
2
- export declare const METADATA: import("../utils/api").Api<{
1
+ type MetadataRequest = {
3
2
  topics?: {
4
3
  id: string | null;
5
4
  name: string;
6
5
  }[] | null;
7
6
  allowTopicAutoCreation?: boolean;
8
7
  includeTopicAuthorizedOperations?: boolean;
9
- }, {
10
- _tag: void;
8
+ };
9
+ type MetadataResponse = {
11
10
  throttleTimeMs: number;
12
11
  brokers: {
13
12
  nodeId: number;
14
13
  host: string;
15
14
  port: number;
16
15
  rack: string | null;
17
- _tag: void;
18
16
  }[];
19
17
  clusterId: string | null;
20
18
  controllerId: number;
@@ -31,10 +29,13 @@ export declare const METADATA: import("../utils/api").Api<{
31
29
  replicaNodes: number[];
32
30
  isrNodes: number[];
33
31
  offlineReplicas: number[];
34
- _tag: void;
32
+ tags: Record<number, Buffer>;
35
33
  }[];
36
34
  topicAuthorizedOperations: number;
37
- _tag: void;
35
+ tags: Record<number, Buffer>;
38
36
  }[];
39
- _tag2: void;
40
- }>;
37
+ tags: Record<number, Buffer>;
38
+ };
39
+ export type Metadata = MetadataResponse;
40
+ export declare const METADATA: import("../utils/api").Api<MetadataRequest, MetadataResponse>;
41
+ export {};
@@ -3,25 +3,126 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.METADATA = void 0;
4
4
  const api_1 = require("../utils/api");
5
5
  const error_1 = require("../utils/error");
6
+ /*
7
+ Metadata Request (Version: 0) => [topics]
8
+ topics => name
9
+ name => STRING
10
+
11
+ Metadata Response (Version: 0) => [brokers] [topics]
12
+ brokers => node_id host port
13
+ node_id => INT32
14
+ host => STRING
15
+ port => INT32
16
+ topics => error_code name [partitions]
17
+ error_code => INT16
18
+ name => STRING
19
+ partitions => error_code partition_index leader_id [replica_nodes] [isr_nodes]
20
+ error_code => INT16
21
+ partition_index => INT32
22
+ leader_id => INT32
23
+ replica_nodes => INT32
24
+ isr_nodes => INT32
25
+ */
26
+ const METADATA_V0 = (0, api_1.createApi)({
27
+ apiKey: 3,
28
+ apiVersion: 0,
29
+ requestHeaderVersion: 1,
30
+ responseHeaderVersion: 0,
31
+ request: (encoder, data) => encoder.writeArray(data.topics ?? [], (encoder, topic) => encoder.writeString(topic.name)),
32
+ response: (decoder) => {
33
+ const result = {
34
+ throttleTimeMs: 0,
35
+ brokers: decoder.readArray((decoder) => ({
36
+ nodeId: decoder.readInt32(),
37
+ host: decoder.readString(),
38
+ port: decoder.readInt32(),
39
+ rack: null,
40
+ })),
41
+ clusterId: null,
42
+ controllerId: -1,
43
+ topics: decoder.readArray((decoder) => ({
44
+ errorCode: decoder.readInt16(),
45
+ name: decoder.readString(),
46
+ topicId: '',
47
+ isInternal: false,
48
+ partitions: decoder.readArray((decoder) => ({
49
+ errorCode: decoder.readInt16(),
50
+ partitionIndex: decoder.readInt32(),
51
+ leaderId: decoder.readInt32(),
52
+ leaderEpoch: -1,
53
+ replicaNodes: decoder.readArray(() => decoder.readInt32()),
54
+ isrNodes: decoder.readArray(() => decoder.readInt32()),
55
+ offlineReplicas: [],
56
+ tags: {},
57
+ })),
58
+ topicAuthorizedOperations: -1,
59
+ tags: {},
60
+ })),
61
+ tags: {},
62
+ };
63
+ result.topics.forEach((topic) => {
64
+ if (topic.errorCode)
65
+ throw new error_1.KafkaTSApiError(topic.errorCode, null, result);
66
+ topic.partitions.forEach((partition) => {
67
+ if (partition.errorCode)
68
+ throw new error_1.KafkaTSApiError(partition.errorCode, null, result);
69
+ });
70
+ });
71
+ return result;
72
+ },
73
+ });
74
+ /*
75
+ Metadata Request (Version: 12) => [topics] allow_auto_topic_creation include_topic_authorized_operations _tagged_fields
76
+ topics => topic_id name _tagged_fields
77
+ topic_id => UUID
78
+ name => COMPACT_NULLABLE_STRING
79
+ allow_auto_topic_creation => BOOLEAN
80
+ include_topic_authorized_operations => BOOLEAN
81
+
82
+ Metadata Response (Version: 12) => throttle_time_ms [brokers] cluster_id controller_id [topics] _tagged_fields
83
+ throttle_time_ms => INT32
84
+ brokers => node_id host port rack _tagged_fields
85
+ node_id => INT32
86
+ host => COMPACT_STRING
87
+ port => INT32
88
+ rack => COMPACT_NULLABLE_STRING
89
+ cluster_id => COMPACT_NULLABLE_STRING
90
+ controller_id => INT32
91
+ topics => error_code name topic_id is_internal [partitions] topic_authorized_operations _tagged_fields
92
+ error_code => INT16
93
+ name => COMPACT_NULLABLE_STRING
94
+ topic_id => UUID
95
+ is_internal => BOOLEAN
96
+ partitions => error_code partition_index leader_id leader_epoch [replica_nodes] [isr_nodes] [offline_replicas] _tagged_fields
97
+ error_code => INT16
98
+ partition_index => INT32
99
+ leader_id => INT32
100
+ leader_epoch => INT32
101
+ replica_nodes => INT32
102
+ isr_nodes => INT32
103
+ offline_replicas => INT32
104
+ topic_authorized_operations => INT32
105
+ */
6
106
  exports.METADATA = (0, api_1.createApi)({
7
107
  apiKey: 3,
8
108
  apiVersion: 12,
109
+ fallback: METADATA_V0,
110
+ requestHeaderVersion: 2,
111
+ responseHeaderVersion: 1,
9
112
  request: (encoder, data) => encoder
10
- .writeUVarInt(0)
11
- .writeCompactArray(data.topics ?? null, (encoder, topic) => encoder.writeUUID(topic.id).writeCompactString(topic.name).writeUVarInt(0))
113
+ .writeCompactArray(data.topics ?? null, (encoder, topic) => encoder.writeUUID(topic.id).writeCompactString(topic.name).writeTagBuffer())
12
114
  .writeBoolean(data.allowTopicAutoCreation ?? false)
13
115
  .writeBoolean(data.includeTopicAuthorizedOperations ?? false)
14
- .writeUVarInt(0),
116
+ .writeTagBuffer(),
15
117
  response: (decoder) => {
16
118
  const result = {
17
- _tag: decoder.readTagBuffer(),
18
119
  throttleTimeMs: decoder.readInt32(),
19
120
  brokers: decoder.readCompactArray((broker) => ({
20
121
  nodeId: broker.readInt32(),
21
122
  host: broker.readCompactString(),
22
123
  port: broker.readInt32(),
23
124
  rack: broker.readCompactString(),
24
- _tag: broker.readTagBuffer(),
125
+ tags: broker.readTagBuffer(),
25
126
  })),
26
127
  clusterId: decoder.readCompactString(),
27
128
  controllerId: decoder.readInt32(),
@@ -38,12 +139,12 @@ exports.METADATA = (0, api_1.createApi)({
38
139
  replicaNodes: partition.readCompactArray((node) => node.readInt32()),
39
140
  isrNodes: partition.readCompactArray((node) => node.readInt32()),
40
141
  offlineReplicas: partition.readCompactArray((node) => node.readInt32()),
41
- _tag: partition.readTagBuffer(),
142
+ tags: partition.readTagBuffer(),
42
143
  })),
43
144
  topicAuthorizedOperations: topic.readInt32(),
44
- _tag: topic.readTagBuffer(),
145
+ tags: topic.readTagBuffer(),
45
146
  })),
46
- _tag2: decoder.readTagBuffer(),
147
+ tags: decoder.readTagBuffer(),
47
148
  };
48
149
  result.topics.forEach((topic) => {
49
150
  if (topic.errorCode)
@@ -1,4 +1,4 @@
1
- export declare const OFFSET_COMMIT: import("../utils/api").Api<{
1
+ type OffsetCommitRequest = {
2
2
  groupId: string;
3
3
  generationIdOrMemberEpoch: number;
4
4
  memberId: string;
@@ -12,17 +12,19 @@ export declare const OFFSET_COMMIT: import("../utils/api").Api<{
12
12
  committedMetadata: string | null;
13
13
  }[];
14
14
  }[];
15
- }, {
16
- _tag: void;
15
+ };
16
+ type OffsetCommitResponse = {
17
17
  throttleTimeMs: number;
18
18
  topics: {
19
- name: string | null;
19
+ name: string;
20
20
  partitions: {
21
21
  partitionIndex: number;
22
22
  errorCode: number;
23
- _tag: void;
23
+ tags: Record<number, Buffer>;
24
24
  }[];
25
- _tag: void;
25
+ tags: Record<number, Buffer>;
26
26
  }[];
27
- _tag2: void;
28
- }>;
27
+ tags: Record<number, Buffer>;
28
+ };
29
+ export declare const OFFSET_COMMIT: import("../utils/api").Api<OffsetCommitRequest, OffsetCommitResponse>;
30
+ export {};
@@ -3,11 +3,92 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.OFFSET_COMMIT = void 0;
4
4
  const api_1 = require("../utils/api");
5
5
  const error_1 = require("../utils/error");
6
+ /*
7
+ OffsetCommit Request (Version: 2) => group_id generation_id_or_member_epoch member_id retention_time_ms [topics]
8
+ group_id => STRING
9
+ generation_id_or_member_epoch => INT32
10
+ member_id => STRING
11
+ retention_time_ms => INT64
12
+ topics => name [partitions]
13
+ name => STRING
14
+ partitions => partition_index committed_offset committed_metadata
15
+ partition_index => INT32
16
+ committed_offset => INT64
17
+ committed_metadata => NULLABLE_STRING
18
+
19
+ OffsetCommit Response (Version: 2) => [topics]
20
+ topics => name [partitions]
21
+ name => STRING
22
+ partitions => partition_index error_code
23
+ partition_index => INT32
24
+ error_code => INT16
25
+ */
26
+ const OFFSET_COMMIT_V2 = (0, api_1.createApi)({
27
+ apiKey: 8,
28
+ apiVersion: 2,
29
+ requestHeaderVersion: 1,
30
+ responseHeaderVersion: 0,
31
+ request: (encoder, data) => encoder
32
+ .writeString(data.groupId)
33
+ .writeInt32(data.generationIdOrMemberEpoch)
34
+ .writeString(data.memberId)
35
+ .writeInt64(-1n) // retention_time_ms is deprecated and should be set to -1
36
+ .writeArray(data.topics, (encoder, topic) => encoder.writeString(topic.name).writeArray(topic.partitions, (encoder, partition) => encoder
37
+ .writeInt32(partition.partitionIndex)
38
+ .writeInt64(partition.committedOffset)
39
+ .writeString(partition.committedMetadata))),
40
+ response: (decoder) => {
41
+ const result = {
42
+ throttleTimeMs: 0,
43
+ topics: decoder.readArray((decoder) => ({
44
+ name: decoder.readString(),
45
+ partitions: decoder.readArray((decoder) => ({
46
+ partitionIndex: decoder.readInt32(),
47
+ errorCode: decoder.readInt16(),
48
+ tags: {},
49
+ })),
50
+ tags: {},
51
+ })),
52
+ tags: {},
53
+ };
54
+ result.topics.forEach((topic) => {
55
+ topic.partitions.forEach((partition) => {
56
+ if (partition.errorCode)
57
+ throw new error_1.KafkaTSApiError(partition.errorCode, null, result);
58
+ });
59
+ });
60
+ return result;
61
+ },
62
+ });
63
+ /*
64
+ OffsetCommit Request (Version: 8) => group_id generation_id_or_member_epoch member_id group_instance_id [topics] _tagged_fields
65
+ group_id => COMPACT_STRING
66
+ generation_id_or_member_epoch => INT32
67
+ member_id => COMPACT_STRING
68
+ group_instance_id => COMPACT_NULLABLE_STRING
69
+ topics => name [partitions] _tagged_fields
70
+ name => COMPACT_STRING
71
+ partitions => partition_index committed_offset committed_leader_epoch committed_metadata _tagged_fields
72
+ partition_index => INT32
73
+ committed_offset => INT64
74
+ committed_leader_epoch => INT32
75
+ committed_metadata => COMPACT_NULLABLE_STRING
76
+
77
+ OffsetCommit Response (Version: 8) => throttle_time_ms [topics] _tagged_fields
78
+ throttle_time_ms => INT32
79
+ topics => name [partitions] _tagged_fields
80
+ name => COMPACT_STRING
81
+ partitions => partition_index error_code _tagged_fields
82
+ partition_index => INT32
83
+ error_code => INT16
84
+ */
6
85
  exports.OFFSET_COMMIT = (0, api_1.createApi)({
7
86
  apiKey: 8,
8
87
  apiVersion: 8,
88
+ fallback: OFFSET_COMMIT_V2,
89
+ requestHeaderVersion: 2,
90
+ responseHeaderVersion: 1,
9
91
  request: (encoder, data) => encoder
10
- .writeUVarInt(0)
11
92
  .writeCompactString(data.groupId)
12
93
  .writeInt32(data.generationIdOrMemberEpoch)
13
94
  .writeCompactString(data.memberId)
@@ -19,23 +100,22 @@ exports.OFFSET_COMMIT = (0, api_1.createApi)({
19
100
  .writeInt64(partition.committedOffset)
20
101
  .writeInt32(partition.committedLeaderEpoch)
21
102
  .writeCompactString(partition.committedMetadata)
22
- .writeUVarInt(0))
23
- .writeUVarInt(0))
24
- .writeUVarInt(0),
103
+ .writeTagBuffer())
104
+ .writeTagBuffer())
105
+ .writeTagBuffer(),
25
106
  response: (decoder) => {
26
107
  const result = {
27
- _tag: decoder.readTagBuffer(),
28
108
  throttleTimeMs: decoder.readInt32(),
29
109
  topics: decoder.readCompactArray((decoder) => ({
30
110
  name: decoder.readCompactString(),
31
111
  partitions: decoder.readCompactArray((decoder) => ({
32
112
  partitionIndex: decoder.readInt32(),
33
113
  errorCode: decoder.readInt16(),
34
- _tag: decoder.readTagBuffer(),
114
+ tags: decoder.readTagBuffer(),
35
115
  })),
36
- _tag: decoder.readTagBuffer(),
116
+ tags: decoder.readTagBuffer(),
37
117
  })),
38
- _tag2: decoder.readTagBuffer(),
118
+ tags: decoder.readTagBuffer(),
39
119
  };
40
120
  result.topics.forEach((topic) => {
41
121
  topic.partitions.forEach((partition) => {
@@ -1,4 +1,4 @@
1
- export declare const OFFSET_FETCH: import("../utils/api").Api<{
1
+ type OffsetFetchRequest = {
2
2
  groups: {
3
3
  groupId: string;
4
4
  topics: {
@@ -7,11 +7,11 @@ export declare const OFFSET_FETCH: import("../utils/api").Api<{
7
7
  }[];
8
8
  }[];
9
9
  requireStable: boolean;
10
- }, {
11
- _tag: void;
10
+ };
11
+ type OffsetFetchResponse = {
12
12
  throttleTimeMs: number;
13
13
  groups: {
14
- groupId: string | null;
14
+ groupId: string;
15
15
  topics: {
16
16
  name: string;
17
17
  partitions: {
@@ -20,12 +20,14 @@ export declare const OFFSET_FETCH: import("../utils/api").Api<{
20
20
  committedLeaderEpoch: number;
21
21
  committedMetadata: string | null;
22
22
  errorCode: number;
23
- _tag: void;
23
+ tags: Record<number, Buffer>;
24
24
  }[];
25
- _tag: void;
25
+ tags: Record<number, Buffer>;
26
26
  }[];
27
27
  errorCode: number;
28
- _tag: void;
28
+ tags: Record<number, Buffer>;
29
29
  }[];
30
- _tag2: void;
31
- }>;
30
+ tags: Record<number, Buffer>;
31
+ };
32
+ export declare const OFFSET_FETCH: import("../utils/api").Api<OffsetFetchRequest, OffsetFetchResponse>;
33
+ export {};