kafka-ts 0.0.1-beta → 0.0.3-beta

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 (188) hide show
  1. package/.github/workflows/release.yml +17 -0
  2. package/.prettierrc +3 -2
  3. package/LICENSE +1 -1
  4. package/README.md +48 -35
  5. package/docker-compose.yml +102 -102
  6. package/examples/package-lock.json +28 -27
  7. package/examples/package.json +12 -12
  8. package/examples/src/client.ts +6 -6
  9. package/examples/src/consumer.ts +9 -8
  10. package/examples/src/create-topic.ts +23 -16
  11. package/examples/src/producer.ts +7 -7
  12. package/examples/src/replicator.ts +4 -4
  13. package/examples/src/utils/delay.ts +1 -0
  14. package/examples/src/utils/json.ts +1 -1
  15. package/examples/tsconfig.json +2 -2
  16. package/package.json +21 -15
  17. package/src/__snapshots__/request-handler.test.ts.snap +9 -718
  18. package/src/api/api-versions.ts +2 -2
  19. package/src/api/create-topics.ts +2 -2
  20. package/src/api/delete-topics.ts +2 -2
  21. package/src/api/fetch.ts +3 -3
  22. package/src/api/find-coordinator.ts +2 -2
  23. package/src/api/heartbeat.ts +2 -2
  24. package/src/api/index.ts +18 -18
  25. package/src/api/init-producer-id.ts +2 -2
  26. package/src/api/join-group.ts +3 -3
  27. package/src/api/leave-group.ts +2 -2
  28. package/src/api/list-offsets.ts +3 -3
  29. package/src/api/metadata.ts +3 -3
  30. package/src/api/offset-commit.ts +2 -2
  31. package/src/api/offset-fetch.ts +2 -2
  32. package/src/api/produce.ts +3 -3
  33. package/src/api/sasl-authenticate.ts +2 -2
  34. package/src/api/sasl-handshake.ts +2 -2
  35. package/src/api/sync-group.ts +2 -2
  36. package/src/broker.ts +9 -9
  37. package/src/client.ts +6 -6
  38. package/src/{request-handler.test.ts → cluster.test.ts} +72 -69
  39. package/src/cluster.ts +7 -7
  40. package/src/connection.ts +17 -15
  41. package/src/consumer/consumer-group.ts +14 -14
  42. package/src/consumer/consumer-metadata.ts +2 -2
  43. package/src/consumer/consumer.ts +84 -82
  44. package/src/consumer/fetch-manager.ts +179 -0
  45. package/src/consumer/fetcher.ts +57 -0
  46. package/src/consumer/offset-manager.ts +6 -6
  47. package/src/consumer/processor.ts +47 -0
  48. package/src/distributors/assignments-to-replicas.test.ts +7 -7
  49. package/src/distributors/assignments-to-replicas.ts +1 -1
  50. package/src/distributors/messages-to-topic-partition-leaders.test.ts +6 -6
  51. package/src/index.ts +4 -3
  52. package/src/metadata.ts +4 -4
  53. package/src/producer/producer.ts +8 -8
  54. package/src/types.ts +2 -0
  55. package/src/utils/api.ts +4 -4
  56. package/src/utils/debug.ts +2 -2
  57. package/src/utils/decoder.ts +4 -4
  58. package/src/utils/encoder.ts +6 -6
  59. package/src/utils/error.ts +3 -3
  60. package/src/utils/retrier.ts +1 -1
  61. package/src/utils/tracer.ts +7 -4
  62. package/tsconfig.json +16 -16
  63. package/dist/api/api-versions.d.ts +0 -9
  64. package/dist/api/api-versions.js +0 -24
  65. package/dist/api/create-topics.d.ts +0 -38
  66. package/dist/api/create-topics.js +0 -53
  67. package/dist/api/delete-topics.d.ts +0 -18
  68. package/dist/api/delete-topics.js +0 -33
  69. package/dist/api/fetch.d.ts +0 -77
  70. package/dist/api/fetch.js +0 -106
  71. package/dist/api/find-coordinator.d.ts +0 -21
  72. package/dist/api/find-coordinator.js +0 -39
  73. package/dist/api/heartbeat.d.ts +0 -11
  74. package/dist/api/heartbeat.js +0 -27
  75. package/dist/api/index.d.ts +0 -573
  76. package/dist/api/index.js +0 -164
  77. package/dist/api/init-producer-id.d.ts +0 -13
  78. package/dist/api/init-producer-id.js +0 -29
  79. package/dist/api/join-group.d.ts +0 -34
  80. package/dist/api/join-group.js +0 -51
  81. package/dist/api/leave-group.d.ts +0 -19
  82. package/dist/api/leave-group.js +0 -39
  83. package/dist/api/list-offsets.d.ts +0 -29
  84. package/dist/api/list-offsets.js +0 -48
  85. package/dist/api/metadata.d.ts +0 -40
  86. package/dist/api/metadata.js +0 -58
  87. package/dist/api/offset-commit.d.ts +0 -28
  88. package/dist/api/offset-commit.js +0 -48
  89. package/dist/api/offset-fetch.d.ts +0 -33
  90. package/dist/api/offset-fetch.js +0 -57
  91. package/dist/api/produce.d.ts +0 -53
  92. package/dist/api/produce.js +0 -129
  93. package/dist/api/sasl-authenticate.d.ts +0 -11
  94. package/dist/api/sasl-authenticate.js +0 -23
  95. package/dist/api/sasl-handshake.d.ts +0 -6
  96. package/dist/api/sasl-handshake.js +0 -19
  97. package/dist/api/sync-group.d.ts +0 -24
  98. package/dist/api/sync-group.js +0 -36
  99. package/dist/broker.d.ts +0 -29
  100. package/dist/broker.js +0 -60
  101. package/dist/client.d.ts +0 -23
  102. package/dist/client.js +0 -36
  103. package/dist/cluster.d.ts +0 -24
  104. package/dist/cluster.js +0 -72
  105. package/dist/connection.d.ts +0 -25
  106. package/dist/connection.js +0 -155
  107. package/dist/consumer/consumer-group.d.ts +0 -36
  108. package/dist/consumer/consumer-group.js +0 -182
  109. package/dist/consumer/consumer-metadata.d.ts +0 -7
  110. package/dist/consumer/consumer-metadata.js +0 -14
  111. package/dist/consumer/consumer.d.ts +0 -37
  112. package/dist/consumer/consumer.js +0 -178
  113. package/dist/consumer/metadata.d.ts +0 -24
  114. package/dist/consumer/metadata.js +0 -64
  115. package/dist/consumer/offset-manager.d.ts +0 -22
  116. package/dist/consumer/offset-manager.js +0 -56
  117. package/dist/distributors/assignments-to-replicas.d.ts +0 -17
  118. package/dist/distributors/assignments-to-replicas.js +0 -60
  119. package/dist/distributors/assignments-to-replicas.test.d.ts +0 -1
  120. package/dist/distributors/assignments-to-replicas.test.js +0 -40
  121. package/dist/distributors/messages-to-topic-partition-leaders.d.ts +0 -17
  122. package/dist/distributors/messages-to-topic-partition-leaders.js +0 -15
  123. package/dist/distributors/messages-to-topic-partition-leaders.test.d.ts +0 -1
  124. package/dist/distributors/messages-to-topic-partition-leaders.test.js +0 -30
  125. package/dist/examples/src/replicator.js +0 -34
  126. package/dist/examples/src/utils/json.js +0 -5
  127. package/dist/index.d.ts +0 -3
  128. package/dist/index.js +0 -19
  129. package/dist/metadata.d.ts +0 -24
  130. package/dist/metadata.js +0 -89
  131. package/dist/producer/producer.d.ts +0 -19
  132. package/dist/producer/producer.js +0 -111
  133. package/dist/request-handler.d.ts +0 -16
  134. package/dist/request-handler.js +0 -67
  135. package/dist/request-handler.test.d.ts +0 -1
  136. package/dist/request-handler.test.js +0 -340
  137. package/dist/src/api/api-versions.js +0 -18
  138. package/dist/src/api/create-topics.js +0 -46
  139. package/dist/src/api/delete-topics.js +0 -26
  140. package/dist/src/api/fetch.js +0 -95
  141. package/dist/src/api/find-coordinator.js +0 -34
  142. package/dist/src/api/heartbeat.js +0 -22
  143. package/dist/src/api/index.js +0 -38
  144. package/dist/src/api/init-producer-id.js +0 -24
  145. package/dist/src/api/join-group.js +0 -48
  146. package/dist/src/api/leave-group.js +0 -30
  147. package/dist/src/api/list-offsets.js +0 -39
  148. package/dist/src/api/metadata.js +0 -47
  149. package/dist/src/api/offset-commit.js +0 -39
  150. package/dist/src/api/offset-fetch.js +0 -44
  151. package/dist/src/api/produce.js +0 -119
  152. package/dist/src/api/sync-group.js +0 -31
  153. package/dist/src/broker.js +0 -35
  154. package/dist/src/connection.js +0 -21
  155. package/dist/src/consumer/consumer-group.js +0 -131
  156. package/dist/src/consumer/consumer.js +0 -103
  157. package/dist/src/consumer/metadata.js +0 -52
  158. package/dist/src/consumer/offset-manager.js +0 -23
  159. package/dist/src/index.js +0 -19
  160. package/dist/src/producer/producer.js +0 -84
  161. package/dist/src/request-handler.js +0 -57
  162. package/dist/src/request-handler.test.js +0 -321
  163. package/dist/src/types.js +0 -2
  164. package/dist/src/utils/api.js +0 -5
  165. package/dist/src/utils/decoder.js +0 -161
  166. package/dist/src/utils/encoder.js +0 -137
  167. package/dist/src/utils/error.js +0 -10
  168. package/dist/types.d.ts +0 -9
  169. package/dist/types.js +0 -2
  170. package/dist/utils/api.d.ts +0 -9
  171. package/dist/utils/api.js +0 -5
  172. package/dist/utils/debug.d.ts +0 -2
  173. package/dist/utils/debug.js +0 -11
  174. package/dist/utils/decoder.d.ts +0 -29
  175. package/dist/utils/decoder.js +0 -147
  176. package/dist/utils/delay.d.ts +0 -1
  177. package/dist/utils/delay.js +0 -5
  178. package/dist/utils/encoder.d.ts +0 -28
  179. package/dist/utils/encoder.js +0 -122
  180. package/dist/utils/error.d.ts +0 -11
  181. package/dist/utils/error.js +0 -27
  182. package/dist/utils/memo.d.ts +0 -1
  183. package/dist/utils/memo.js +0 -16
  184. package/dist/utils/retrier.d.ts +0 -10
  185. package/dist/utils/retrier.js +0 -22
  186. package/dist/utils/tracer.d.ts +0 -1
  187. package/dist/utils/tracer.js +0 -26
  188. package/examples/node_modules/.package-lock.json +0 -22
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api.js";
2
- import { KafkaTSApiError } from "../utils/error.js";
1
+ import { createApi } from '../utils/api.js';
2
+ import { KafkaTSApiError } from '../utils/error.js';
3
3
 
4
4
  export const API_VERSIONS = createApi({
5
5
  apiKey: 18,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const CREATE_TOPICS = createApi({
5
5
  apiKey: 19,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const DELETE_TOPICS = createApi({
5
5
  apiKey: 20,
package/src/api/fetch.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { createApi } from "../utils/api";
2
- import { Decoder } from "../utils/decoder";
3
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { Decoder } from '../utils/decoder';
3
+ import { KafkaTSApiError } from '../utils/error';
4
4
 
5
5
  export const enum IsolationLevel {
6
6
  READ_UNCOMMITTED = 0,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const KEY_TYPE = {
5
5
  GROUP: 0,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const HEARTBEAT = createApi({
5
5
  apiKey: 12,
package/src/api/index.ts CHANGED
@@ -1,21 +1,21 @@
1
- import { Api } from "../utils/api";
2
- import { API_VERSIONS } from "./api-versions";
3
- import { CREATE_TOPICS } from "./create-topics";
4
- import { DELETE_TOPICS } from "./delete-topics";
5
- import { FETCH } from "./fetch";
6
- import { FIND_COORDINATOR } from "./find-coordinator";
7
- import { HEARTBEAT } from "./heartbeat";
8
- import { INIT_PRODUCER_ID } from "./init-producer-id";
9
- import { JOIN_GROUP } from "./join-group";
10
- import { LEAVE_GROUP } from "./leave-group";
11
- import { LIST_OFFSETS } from "./list-offsets";
12
- import { METADATA } from "./metadata";
13
- import { OFFSET_COMMIT } from "./offset-commit";
14
- import { OFFSET_FETCH } from "./offset-fetch";
15
- import { PRODUCE } from "./produce";
16
- import { SASL_AUTHENTICATE } from "./sasl-authenticate";
17
- import { SASL_HANDSHAKE } from "./sasl-handshake";
18
- import { SYNC_GROUP } from "./sync-group";
1
+ import { Api } from '../utils/api';
2
+ import { API_VERSIONS } from './api-versions';
3
+ import { CREATE_TOPICS } from './create-topics';
4
+ import { DELETE_TOPICS } from './delete-topics';
5
+ import { FETCH } from './fetch';
6
+ import { FIND_COORDINATOR } from './find-coordinator';
7
+ import { HEARTBEAT } from './heartbeat';
8
+ import { INIT_PRODUCER_ID } from './init-producer-id';
9
+ import { JOIN_GROUP } from './join-group';
10
+ import { LEAVE_GROUP } from './leave-group';
11
+ import { LIST_OFFSETS } from './list-offsets';
12
+ import { METADATA } from './metadata';
13
+ import { OFFSET_COMMIT } from './offset-commit';
14
+ import { OFFSET_FETCH } from './offset-fetch';
15
+ import { PRODUCE } from './produce';
16
+ import { SASL_AUTHENTICATE } from './sasl-authenticate';
17
+ import { SASL_HANDSHAKE } from './sasl-handshake';
18
+ import { SYNC_GROUP } from './sync-group';
19
19
 
20
20
  export const API = {
21
21
  API_VERSIONS,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const INIT_PRODUCER_ID = createApi({
5
5
  apiKey: 22,
@@ -1,6 +1,6 @@
1
- import { createApi } from "../utils/api";
2
- import { Encoder } from "../utils/encoder";
3
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { Encoder } from '../utils/encoder';
3
+ import { KafkaTSApiError } from '../utils/error';
4
4
 
5
5
  export const JOIN_GROUP = createApi({
6
6
  apiKey: 11,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const LEAVE_GROUP = createApi({
5
5
  apiKey: 13,
@@ -1,6 +1,6 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
3
- import { IsolationLevel } from "./fetch";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
+ import { IsolationLevel } from './fetch';
4
4
 
5
5
  export const LIST_OFFSETS = createApi({
6
6
  apiKey: 2,
@@ -1,7 +1,7 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
- export type Metadata = ReturnType<(typeof METADATA)["response"]>;
4
+ export type Metadata = ReturnType<(typeof METADATA)['response']>;
5
5
 
6
6
  export const METADATA = createApi({
7
7
  apiKey: 3,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const OFFSET_COMMIT = createApi({
5
5
  apiKey: 8,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const OFFSET_FETCH = createApi({
5
5
  apiKey: 9,
@@ -1,6 +1,6 @@
1
- import { createApi } from "../utils/api.js";
2
- import { Encoder } from "../utils/encoder.js";
3
- import { KafkaTSApiError } from "../utils/error.js";
1
+ import { createApi } from '../utils/api.js';
2
+ import { Encoder } from '../utils/encoder.js';
3
+ import { KafkaTSApiError } from '../utils/error.js';
4
4
 
5
5
  export const PRODUCE = createApi({
6
6
  apiKey: 0,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const SASL_AUTHENTICATE = createApi({
5
5
  apiKey: 36,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export const SASL_HANDSHAKE = createApi({
5
5
  apiKey: 17,
@@ -1,5 +1,5 @@
1
- import { createApi } from "../utils/api";
2
- import { KafkaTSApiError } from "../utils/error";
1
+ import { createApi } from '../utils/api';
2
+ import { KafkaTSApiError } from '../utils/error';
3
3
 
4
4
  export type Assignment = { [topic: string]: number[] };
5
5
 
package/src/broker.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { TcpSocketConnectOpts } from "net";
2
- import { TLSSocketOptions } from "tls";
3
- import { API } from "./api";
4
- import { Connection, SendRequest } from "./connection";
5
- import { KafkaTSError } from "./utils/error";
6
- import { memo } from "./utils/memo";
1
+ import { TcpSocketConnectOpts } from 'net';
2
+ import { TLSSocketOptions } from 'tls';
3
+ import { API } from './api';
4
+ import { Connection, SendRequest } from './connection';
5
+ import { KafkaTSError } from './utils/error';
6
+ import { memo } from './utils/memo';
7
7
 
8
- export type SASLOptions = { mechanism: "PLAIN"; username: string; password: string };
8
+ export type SASLOptions = { mechanism: 'PLAIN'; username: string; password: string };
9
9
 
10
10
  type BrokerOptions = {
11
11
  clientId: string | null;
@@ -64,11 +64,11 @@ export class Broker {
64
64
  }
65
65
 
66
66
  private async saslAuthenticate() {
67
- if (this.options.sasl?.mechanism !== "PLAIN") {
67
+ if (this.options.sasl?.mechanism !== 'PLAIN') {
68
68
  return;
69
69
  }
70
70
  const { username, password } = this.options.sasl;
71
- const authBytes = [null, username, password].join("\u0000");
71
+ const authBytes = [null, username, password].join('\u0000');
72
72
  await this.sendRequest(API.SASL_AUTHENTICATE, { authBytes: Buffer.from(authBytes) });
73
73
  }
74
74
  }
package/src/client.ts CHANGED
@@ -1,9 +1,9 @@
1
- import { TcpSocketConnectOpts } from "net";
2
- import { TLSSocketOptions } from "tls";
3
- import { SASLOptions } from "./broker";
4
- import { Cluster } from "./cluster";
5
- import { Consumer, ConsumerOptions } from "./consumer/consumer";
6
- import { Producer, ProducerOptions } from "./producer/producer";
1
+ import { TcpSocketConnectOpts } from 'net';
2
+ import { TLSSocketOptions } from 'tls';
3
+ import { SASLOptions } from './broker';
4
+ import { Cluster } from './cluster';
5
+ import { Consumer, ConsumerOptions } from './consumer/consumer';
6
+ import { Producer, ProducerOptions } from './producer/producer';
7
7
 
8
8
  type ClientOptions = {
9
9
  clientId?: string | null;
@@ -1,21 +1,21 @@
1
- import { randomBytes } from "crypto";
2
- import { readFileSync } from "fs";
3
- import { afterAll, beforeAll, describe, expect, it } from "vitest";
4
- import { API } from "./api";
5
- import { KEY_TYPE } from "./api/find-coordinator";
6
- import { createKafkaClient } from "./client";
7
- import { Cluster } from "./cluster";
8
- import { KafkaTSApiError } from "./utils/error";
1
+ import { randomBytes } from 'crypto';
2
+ import { readFileSync } from 'fs';
3
+ import { afterAll, beforeAll, describe, expect, it } from 'vitest';
4
+ import { API } from './api';
5
+ import { KEY_TYPE } from './api/find-coordinator';
6
+ import { createKafkaClient } from './client';
7
+ import { Cluster } from './cluster';
8
+ import { KafkaTSApiError } from './utils/error';
9
9
 
10
10
  export const kafka = createKafkaClient({
11
- clientId: "kafkats",
12
- bootstrapServers: [{ host: "localhost", port: 9092 }],
13
- sasl: { mechanism: "PLAIN", username: "admin", password: "admin" },
14
- ssl: { ca: readFileSync("./certs/ca.crt").toString() },
11
+ clientId: 'kafka-ts',
12
+ bootstrapServers: [{ host: 'localhost', port: 9092 }],
13
+ sasl: { mechanism: 'PLAIN', username: 'admin', password: 'admin' },
14
+ ssl: { ca: readFileSync('./certs/ca.crt').toString() },
15
15
  });
16
16
 
17
- describe.sequential("Request handler", () => {
18
- const groupId = randomBytes(16).toString("hex");
17
+ describe.sequential('Request handler', () => {
18
+ const groupId = randomBytes(16).toString('hex');
19
19
 
20
20
  let cluster: Cluster;
21
21
 
@@ -27,9 +27,9 @@ describe.sequential("Request handler", () => {
27
27
  allowTopicAutoCreation: false,
28
28
  includeTopicAuthorizedOperations: false,
29
29
  });
30
- if (metadataResult.topics.some((topic) => topic.name === "kafkats-test-topic")) {
30
+ if (metadataResult.topics.some((topic) => topic.name === 'kafka-ts-test-topic')) {
31
31
  await cluster.sendRequest(API.DELETE_TOPICS, {
32
- topics: [{ name: "kafkats-test-topic", topicId: null }],
32
+ topics: [{ name: 'kafka-ts-test-topic', topicId: null }],
33
33
  timeoutMs: 10000,
34
34
  });
35
35
  }
@@ -39,18 +39,18 @@ describe.sequential("Request handler", () => {
39
39
  await cluster.disconnect();
40
40
  });
41
41
 
42
- it("should request api versions", async () => {
42
+ it('should request api versions', async () => {
43
43
  const result = await cluster.sendRequest(API.API_VERSIONS, {});
44
44
  expect(result).toMatchSnapshot();
45
45
  });
46
46
 
47
- let topicId: string = "d6718d178e1b47c886441ad2d19faea5";
47
+ let topicId: string = 'd6718d178e1b47c886441ad2d19faea5';
48
48
 
49
- it("should create topics", async () => {
49
+ it('should create topics', async () => {
50
50
  const result = await cluster.sendRequest(API.CREATE_TOPICS, {
51
51
  topics: [
52
52
  {
53
- name: "kafkats-test-topic",
53
+ name: 'kafka-ts-test-topic',
54
54
  numPartitions: 1,
55
55
  replicationFactor: 1,
56
56
  assignments: [],
@@ -62,22 +62,23 @@ describe.sequential("Request handler", () => {
62
62
  });
63
63
  topicId = result.topics[0].topicId;
64
64
  result.topics.forEach((topic) => {
65
- topic.topicId = "Any<UUID>";
65
+ topic.topicId = 'Any<UUID>';
66
66
  });
67
67
  expect(result).toMatchSnapshot();
68
68
 
69
69
  await new Promise((resolve) => setTimeout(resolve, 1000));
70
70
  });
71
71
 
72
- it("should request metadata for all topics", async () => {
72
+ it('should request metadata for all topics', async () => {
73
73
  const result = await cluster.sendRequest(API.METADATA, {
74
74
  topics: null,
75
75
  allowTopicAutoCreation: false,
76
76
  includeTopicAuthorizedOperations: false,
77
77
  });
78
78
  result.controllerId = 0;
79
+ result.topics = result.topics.filter((topic) => topic.name !== '__consumer_offsets');
79
80
  result.topics.forEach((topic) => {
80
- topic.topicId = "Any<UUID>";
81
+ topic.topicId = 'Any<UUID>';
81
82
  topic.partitions.forEach((partition) => {
82
83
  partition.leaderId = 0;
83
84
  partition.isrNodes = [0];
@@ -89,16 +90,16 @@ describe.sequential("Request handler", () => {
89
90
 
90
91
  let leaderId = 0;
91
92
 
92
- it("should request metadata for a topic", async () => {
93
+ it('should request metadata for a topic', async () => {
93
94
  const result = await cluster.sendRequest(API.METADATA, {
94
- topics: [{ id: topicId, name: "kafkats-test-topic" }],
95
+ topics: [{ id: topicId, name: 'kafka-ts-test-topic' }],
95
96
  allowTopicAutoCreation: false,
96
97
  includeTopicAuthorizedOperations: false,
97
98
  });
98
99
  leaderId = result.topics[0].partitions[0].leaderId;
99
100
  result.controllerId = 0;
100
101
  result.topics.forEach((topic) => {
101
- topic.topicId = "Any<UUID>";
102
+ topic.topicId = 'Any<UUID>';
102
103
  topic.partitions.forEach((partition) => {
103
104
  partition.leaderId = 0;
104
105
  partition.isrNodes = [0];
@@ -108,18 +109,20 @@ describe.sequential("Request handler", () => {
108
109
  expect(result).toMatchSnapshot();
109
110
  });
110
111
 
111
- it("should init producer id", async () => {
112
+ let producerId = 9n;
113
+
114
+ it('should init producer id', async () => {
112
115
  const result = await cluster.sendRequest(API.INIT_PRODUCER_ID, {
113
116
  transactionalId: null,
114
117
  transactionTimeoutMs: 0,
115
- producerId: 0n,
118
+ producerId,
116
119
  producerEpoch: 0,
117
120
  });
118
121
  result.producerId = 0n;
119
122
  expect(result).toMatchSnapshot();
120
123
  });
121
124
 
122
- it("should produce messages", async () => {
125
+ it('should produce messages', async () => {
123
126
  const now = Date.now();
124
127
  const result = await cluster.sendRequestToNode(leaderId)(API.PRODUCE, {
125
128
  transactionalId: null,
@@ -127,7 +130,7 @@ describe.sequential("Request handler", () => {
127
130
  acks: 1,
128
131
  topicData: [
129
132
  {
130
- name: "kafkats-test-topic",
133
+ name: 'kafka-ts-test-topic',
131
134
  partitionData: [
132
135
  {
133
136
  index: 0,
@@ -139,18 +142,18 @@ describe.sequential("Request handler", () => {
139
142
  lastOffsetDelta: 0,
140
143
  maxTimestamp: BigInt(now),
141
144
  producerEpoch: 0,
142
- producerId: 9n,
145
+ producerId,
143
146
  records: [
144
147
  {
145
148
  attributes: 0,
146
149
  offsetDelta: 0,
147
150
  timestampDelta: 0n,
148
- key: "key",
149
- value: "value",
151
+ key: 'key',
152
+ value: 'value',
150
153
  headers: [
151
154
  {
152
- key: "header-key",
153
- value: "header-value",
155
+ key: 'header-key',
156
+ value: 'header-value',
154
157
  },
155
158
  ],
156
159
  },
@@ -163,7 +166,7 @@ describe.sequential("Request handler", () => {
163
166
  expect(result).toMatchSnapshot();
164
167
  });
165
168
 
166
- it("should fetch messages", async () => {
169
+ it('should fetch messages', async () => {
167
170
  const result = await cluster.sendRequestToNode(leaderId)(API.FETCH, {
168
171
  maxWaitMs: 100,
169
172
  minBytes: 1,
@@ -187,10 +190,10 @@ describe.sequential("Request handler", () => {
187
190
  },
188
191
  ],
189
192
  forgottenTopicsData: [],
190
- rackId: "",
193
+ rackId: '',
191
194
  });
192
195
  result.responses.forEach((response) => {
193
- response.topicId = "Any<UUID>";
196
+ response.topicId = 'Any<UUID>';
194
197
  response.partitions.forEach((partition) => {
195
198
  partition.records.forEach((record) => {
196
199
  expect(record.baseTimestamp).toBeGreaterThan(1721926744730n);
@@ -208,10 +211,10 @@ describe.sequential("Request handler", () => {
208
211
 
209
212
  let coordinatorId = -1;
210
213
 
211
- it("should find coordinator", async () => {
214
+ it('should find coordinator', async () => {
212
215
  const result = await cluster.sendRequest(API.FIND_COORDINATOR, { keyType: KEY_TYPE.GROUP, keys: [groupId] });
213
216
  result.coordinators.forEach((coordinator) => {
214
- coordinator.key = "Any<String>";
217
+ coordinator.key = 'Any<String>';
215
218
  });
216
219
  coordinatorId = result.coordinators[0].nodeId;
217
220
  result.coordinators.forEach((coordinator) => {
@@ -221,9 +224,9 @@ describe.sequential("Request handler", () => {
221
224
  expect(result).toMatchSnapshot();
222
225
  });
223
226
 
224
- let memberId = "";
227
+ let memberId = '';
225
228
 
226
- it("should fail join group request with new memberId", async () => {
229
+ it('should fail join group request with new memberId', async () => {
227
230
  try {
228
231
  const result = await cluster.sendRequestToNode(coordinatorId)(API.JOIN_GROUP, {
229
232
  groupId,
@@ -231,67 +234,67 @@ describe.sequential("Request handler", () => {
231
234
  rebalanceTimeoutMs: 60000,
232
235
  memberId,
233
236
  groupInstanceId: null,
234
- protocolType: "consumer",
237
+ protocolType: 'consumer',
235
238
  protocols: [
236
239
  {
237
- name: "RoundRobinAssigner",
238
- metadata: { version: 0, topics: ["kafkats-test-topic"] },
240
+ name: 'RoundRobinAssigner',
241
+ metadata: { version: 0, topics: ['kafka-ts-test-topic'] },
239
242
  },
240
243
  ],
241
244
  reason: null,
242
245
  });
243
- expect(false, "Should throw an error").toBe(true);
246
+ expect(false, 'Should throw an error').toBe(true);
244
247
  } catch (error) {
245
248
  const { response } = error as KafkaTSApiError;
246
249
  memberId = response.memberId;
247
- response.memberId = "Any<UUID>";
250
+ response.memberId = 'Any<UUID>';
248
251
  expect(response).toMatchSnapshot();
249
252
  }
250
253
  });
251
254
 
252
- it("should join group", async () => {
255
+ it('should join group', async () => {
253
256
  const result = await cluster.sendRequestToNode(coordinatorId)(API.JOIN_GROUP, {
254
257
  groupId,
255
258
  sessionTimeoutMs: 30000,
256
259
  rebalanceTimeoutMs: 60000,
257
260
  memberId,
258
261
  groupInstanceId: null,
259
- protocolType: "consumer",
262
+ protocolType: 'consumer',
260
263
  protocols: [
261
264
  {
262
- name: "RoundRobinAssigner",
263
- metadata: { version: 0, topics: ["kafkats-test-topic"] },
265
+ name: 'RoundRobinAssigner',
266
+ metadata: { version: 0, topics: ['kafka-ts-test-topic'] },
264
267
  },
265
268
  ],
266
269
  reason: null,
267
270
  });
268
- result.memberId = "Any<UUID>";
269
- result.leader = "Any<UUID>";
271
+ result.memberId = 'Any<UUID>';
272
+ result.leader = 'Any<UUID>';
270
273
  result.members.forEach((member) => {
271
- member.memberId = "Any<UUID>";
274
+ member.memberId = 'Any<UUID>';
272
275
  });
273
276
  expect(result).toMatchSnapshot();
274
277
  });
275
278
 
276
- it("should sync group", async () => {
279
+ it('should sync group', async () => {
277
280
  const result = await cluster.sendRequestToNode(coordinatorId)(API.SYNC_GROUP, {
278
281
  groupId,
279
282
  generationId: 1,
280
283
  memberId,
281
284
  groupInstanceId: null,
282
- protocolType: "consumer",
283
- protocolName: "RoundRobinAssigner",
285
+ protocolType: 'consumer',
286
+ protocolName: 'RoundRobinAssigner',
284
287
  assignments: [
285
288
  {
286
289
  memberId,
287
- assignment: { "kafka-test-topic": [0] },
290
+ assignment: { 'kafka-test-topic': [0] },
288
291
  },
289
292
  ],
290
293
  });
291
294
  expect(result).toMatchSnapshot();
292
295
  });
293
296
 
294
- it("should commit offsets", async () => {
297
+ it('should commit offsets', async () => {
295
298
  const result = await cluster.sendRequestToNode(coordinatorId)(API.OFFSET_COMMIT, {
296
299
  groupId,
297
300
  generationIdOrMemberEpoch: 1,
@@ -299,7 +302,7 @@ describe.sequential("Request handler", () => {
299
302
  groupInstanceId: null,
300
303
  topics: [
301
304
  {
302
- name: "kafkats-test-topic",
305
+ name: 'kafka-ts-test-topic',
303
306
  partitions: [
304
307
  { partitionIndex: 0, committedOffset: 1n, committedLeaderEpoch: 0, committedMetadata: null },
305
308
  ],
@@ -309,7 +312,7 @@ describe.sequential("Request handler", () => {
309
312
  expect(result).toMatchSnapshot();
310
313
  });
311
314
 
312
- it("should fetch offsets", async () => {
315
+ it('should fetch offsets', async () => {
313
316
  const result = await cluster.sendRequestToNode(coordinatorId)(API.OFFSET_FETCH, {
314
317
  groups: [
315
318
  {
@@ -318,7 +321,7 @@ describe.sequential("Request handler", () => {
318
321
  memberEpoch: 0,
319
322
  topics: [
320
323
  {
321
- name: "kafkats-test-topic",
324
+ name: 'kafka-ts-test-topic',
322
325
  partitionIndexes: [0],
323
326
  },
324
327
  ],
@@ -327,12 +330,12 @@ describe.sequential("Request handler", () => {
327
330
  requireStable: false,
328
331
  });
329
332
  result.groups.forEach((group) => {
330
- group.groupId = "Any<String>";
333
+ group.groupId = 'Any<String>';
331
334
  });
332
335
  expect(result).toMatchSnapshot();
333
336
  });
334
337
 
335
- it("should heartbeat", async () => {
338
+ it('should heartbeat', async () => {
336
339
  const result = await cluster.sendRequestToNode(coordinatorId)(API.HEARTBEAT, {
337
340
  groupId,
338
341
  generationId: 1,
@@ -342,24 +345,24 @@ describe.sequential("Request handler", () => {
342
345
  expect(result).toMatchSnapshot();
343
346
  });
344
347
 
345
- it("should leave group", async () => {
348
+ it('should leave group', async () => {
346
349
  const result = await cluster.sendRequestToNode(coordinatorId)(API.LEAVE_GROUP, {
347
350
  groupId,
348
351
  members: [{ memberId, groupInstanceId: null, reason: null }],
349
352
  });
350
353
  result.members.forEach((member) => {
351
- member.memberId = "Any<UUID>";
354
+ member.memberId = 'Any<UUID>';
352
355
  });
353
356
  expect(result).toMatchSnapshot();
354
357
  });
355
358
 
356
- it("should delete topics", async () => {
359
+ it('should delete topics', async () => {
357
360
  const result = await cluster.sendRequest(API.DELETE_TOPICS, {
358
- topics: [{ name: "kafkats-test-topic", topicId: null }],
361
+ topics: [{ name: 'kafka-ts-test-topic', topicId: null }],
359
362
  timeoutMs: 10000,
360
363
  });
361
364
  result.responses.forEach((response) => {
362
- response.topicId = "Any<UUID>";
365
+ response.topicId = 'Any<UUID>';
363
366
  });
364
367
  expect(result).toMatchSnapshot();
365
368
  });