kafka-ts 0.0.1-beta → 0.0.1-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (192) 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 +108 -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 +22 -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 +22 -15
  17. package/scripts/create-scram-user.sh +5 -0
  18. package/scripts/generate-certs.sh +1 -0
  19. package/scripts/kafka-local.properties +33 -0
  20. package/src/__snapshots__/request-handler.test.ts.snap +9 -718
  21. package/src/api/api-versions.ts +2 -2
  22. package/src/api/create-topics.ts +2 -2
  23. package/src/api/delete-topics.ts +2 -2
  24. package/src/api/fetch.ts +3 -3
  25. package/src/api/find-coordinator.ts +2 -2
  26. package/src/api/heartbeat.ts +2 -2
  27. package/src/api/index.ts +18 -18
  28. package/src/api/init-producer-id.ts +2 -2
  29. package/src/api/join-group.ts +3 -3
  30. package/src/api/leave-group.ts +2 -2
  31. package/src/api/list-offsets.ts +3 -3
  32. package/src/api/metadata.ts +3 -3
  33. package/src/api/offset-commit.ts +2 -2
  34. package/src/api/offset-fetch.ts +2 -2
  35. package/src/api/produce.ts +3 -3
  36. package/src/api/sasl-authenticate.ts +2 -2
  37. package/src/api/sasl-handshake.ts +2 -2
  38. package/src/api/sync-group.ts +2 -2
  39. package/src/broker.ts +83 -11
  40. package/src/client.ts +6 -6
  41. package/src/{request-handler.test.ts → cluster.test.ts} +72 -69
  42. package/src/cluster.ts +7 -7
  43. package/src/connection.ts +17 -15
  44. package/src/consumer/consumer-group.ts +14 -14
  45. package/src/consumer/consumer-metadata.ts +2 -2
  46. package/src/consumer/consumer.ts +84 -82
  47. package/src/consumer/fetch-manager.ts +179 -0
  48. package/src/consumer/fetcher.ts +57 -0
  49. package/src/consumer/offset-manager.ts +6 -6
  50. package/src/consumer/processor.ts +47 -0
  51. package/src/distributors/assignments-to-replicas.test.ts +7 -7
  52. package/src/distributors/assignments-to-replicas.ts +1 -1
  53. package/src/distributors/messages-to-topic-partition-leaders.test.ts +6 -6
  54. package/src/index.ts +4 -3
  55. package/src/metadata.ts +4 -4
  56. package/src/producer/producer.ts +8 -8
  57. package/src/types.ts +2 -0
  58. package/src/utils/api.ts +4 -4
  59. package/src/utils/crypto.ts +14 -0
  60. package/src/utils/debug.ts +2 -2
  61. package/src/utils/decoder.ts +4 -4
  62. package/src/utils/encoder.ts +6 -6
  63. package/src/utils/error.ts +3 -3
  64. package/src/utils/retrier.ts +1 -1
  65. package/src/utils/tracer.ts +7 -4
  66. package/tsconfig.json +16 -16
  67. package/dist/api/api-versions.d.ts +0 -9
  68. package/dist/api/api-versions.js +0 -24
  69. package/dist/api/create-topics.d.ts +0 -38
  70. package/dist/api/create-topics.js +0 -53
  71. package/dist/api/delete-topics.d.ts +0 -18
  72. package/dist/api/delete-topics.js +0 -33
  73. package/dist/api/fetch.d.ts +0 -77
  74. package/dist/api/fetch.js +0 -106
  75. package/dist/api/find-coordinator.d.ts +0 -21
  76. package/dist/api/find-coordinator.js +0 -39
  77. package/dist/api/heartbeat.d.ts +0 -11
  78. package/dist/api/heartbeat.js +0 -27
  79. package/dist/api/index.d.ts +0 -573
  80. package/dist/api/index.js +0 -164
  81. package/dist/api/init-producer-id.d.ts +0 -13
  82. package/dist/api/init-producer-id.js +0 -29
  83. package/dist/api/join-group.d.ts +0 -34
  84. package/dist/api/join-group.js +0 -51
  85. package/dist/api/leave-group.d.ts +0 -19
  86. package/dist/api/leave-group.js +0 -39
  87. package/dist/api/list-offsets.d.ts +0 -29
  88. package/dist/api/list-offsets.js +0 -48
  89. package/dist/api/metadata.d.ts +0 -40
  90. package/dist/api/metadata.js +0 -58
  91. package/dist/api/offset-commit.d.ts +0 -28
  92. package/dist/api/offset-commit.js +0 -48
  93. package/dist/api/offset-fetch.d.ts +0 -33
  94. package/dist/api/offset-fetch.js +0 -57
  95. package/dist/api/produce.d.ts +0 -53
  96. package/dist/api/produce.js +0 -129
  97. package/dist/api/sasl-authenticate.d.ts +0 -11
  98. package/dist/api/sasl-authenticate.js +0 -23
  99. package/dist/api/sasl-handshake.d.ts +0 -6
  100. package/dist/api/sasl-handshake.js +0 -19
  101. package/dist/api/sync-group.d.ts +0 -24
  102. package/dist/api/sync-group.js +0 -36
  103. package/dist/broker.d.ts +0 -29
  104. package/dist/broker.js +0 -60
  105. package/dist/client.d.ts +0 -23
  106. package/dist/client.js +0 -36
  107. package/dist/cluster.d.ts +0 -24
  108. package/dist/cluster.js +0 -72
  109. package/dist/connection.d.ts +0 -25
  110. package/dist/connection.js +0 -155
  111. package/dist/consumer/consumer-group.d.ts +0 -36
  112. package/dist/consumer/consumer-group.js +0 -182
  113. package/dist/consumer/consumer-metadata.d.ts +0 -7
  114. package/dist/consumer/consumer-metadata.js +0 -14
  115. package/dist/consumer/consumer.d.ts +0 -37
  116. package/dist/consumer/consumer.js +0 -178
  117. package/dist/consumer/metadata.d.ts +0 -24
  118. package/dist/consumer/metadata.js +0 -64
  119. package/dist/consumer/offset-manager.d.ts +0 -22
  120. package/dist/consumer/offset-manager.js +0 -56
  121. package/dist/distributors/assignments-to-replicas.d.ts +0 -17
  122. package/dist/distributors/assignments-to-replicas.js +0 -60
  123. package/dist/distributors/assignments-to-replicas.test.d.ts +0 -1
  124. package/dist/distributors/assignments-to-replicas.test.js +0 -40
  125. package/dist/distributors/messages-to-topic-partition-leaders.d.ts +0 -17
  126. package/dist/distributors/messages-to-topic-partition-leaders.js +0 -15
  127. package/dist/distributors/messages-to-topic-partition-leaders.test.d.ts +0 -1
  128. package/dist/distributors/messages-to-topic-partition-leaders.test.js +0 -30
  129. package/dist/examples/src/replicator.js +0 -34
  130. package/dist/examples/src/utils/json.js +0 -5
  131. package/dist/index.d.ts +0 -3
  132. package/dist/index.js +0 -19
  133. package/dist/metadata.d.ts +0 -24
  134. package/dist/metadata.js +0 -89
  135. package/dist/producer/producer.d.ts +0 -19
  136. package/dist/producer/producer.js +0 -111
  137. package/dist/request-handler.d.ts +0 -16
  138. package/dist/request-handler.js +0 -67
  139. package/dist/request-handler.test.d.ts +0 -1
  140. package/dist/request-handler.test.js +0 -340
  141. package/dist/src/api/api-versions.js +0 -18
  142. package/dist/src/api/create-topics.js +0 -46
  143. package/dist/src/api/delete-topics.js +0 -26
  144. package/dist/src/api/fetch.js +0 -95
  145. package/dist/src/api/find-coordinator.js +0 -34
  146. package/dist/src/api/heartbeat.js +0 -22
  147. package/dist/src/api/index.js +0 -38
  148. package/dist/src/api/init-producer-id.js +0 -24
  149. package/dist/src/api/join-group.js +0 -48
  150. package/dist/src/api/leave-group.js +0 -30
  151. package/dist/src/api/list-offsets.js +0 -39
  152. package/dist/src/api/metadata.js +0 -47
  153. package/dist/src/api/offset-commit.js +0 -39
  154. package/dist/src/api/offset-fetch.js +0 -44
  155. package/dist/src/api/produce.js +0 -119
  156. package/dist/src/api/sync-group.js +0 -31
  157. package/dist/src/broker.js +0 -35
  158. package/dist/src/connection.js +0 -21
  159. package/dist/src/consumer/consumer-group.js +0 -131
  160. package/dist/src/consumer/consumer.js +0 -103
  161. package/dist/src/consumer/metadata.js +0 -52
  162. package/dist/src/consumer/offset-manager.js +0 -23
  163. package/dist/src/index.js +0 -19
  164. package/dist/src/producer/producer.js +0 -84
  165. package/dist/src/request-handler.js +0 -57
  166. package/dist/src/request-handler.test.js +0 -321
  167. package/dist/src/types.js +0 -2
  168. package/dist/src/utils/api.js +0 -5
  169. package/dist/src/utils/decoder.js +0 -161
  170. package/dist/src/utils/encoder.js +0 -137
  171. package/dist/src/utils/error.js +0 -10
  172. package/dist/types.d.ts +0 -9
  173. package/dist/types.js +0 -2
  174. package/dist/utils/api.d.ts +0 -9
  175. package/dist/utils/api.js +0 -5
  176. package/dist/utils/debug.d.ts +0 -2
  177. package/dist/utils/debug.js +0 -11
  178. package/dist/utils/decoder.d.ts +0 -29
  179. package/dist/utils/decoder.js +0 -147
  180. package/dist/utils/delay.d.ts +0 -1
  181. package/dist/utils/delay.js +0 -5
  182. package/dist/utils/encoder.d.ts +0 -28
  183. package/dist/utils/encoder.js +0 -122
  184. package/dist/utils/error.d.ts +0 -11
  185. package/dist/utils/error.js +0 -27
  186. package/dist/utils/memo.d.ts +0 -1
  187. package/dist/utils/memo.js +0 -16
  188. package/dist/utils/retrier.d.ts +0 -10
  189. package/dist/utils/retrier.js +0 -22
  190. package/dist/utils/tracer.d.ts +0 -1
  191. package/dist/utils/tracer.js +0 -26
  192. package/examples/node_modules/.package-lock.json +0 -22
@@ -0,0 +1,14 @@
1
+ import { createHash, createHmac, pbkdf2, randomBytes } from 'crypto';
2
+
3
+ export const generateNonce = () => randomBytes(16).toString('base64').replace(/[\/=]/g, '');
4
+
5
+ export const saltPassword = (password: string, salt: string, iterations: number, keyLength: number, digest: string) =>
6
+ new Promise<Buffer>((resolve, reject) =>
7
+ pbkdf2(password, salt, iterations, keyLength, digest, (err, key) => (err ? reject(err) : resolve(key))),
8
+ );
9
+
10
+ export const base64Encode = (input: Buffer | string) => Buffer.from(input).toString('base64');
11
+ export const base64Decode = (input: string) => Buffer.from(input, 'base64').toString();
12
+ export const hash = (data: Buffer) => createHash('sha256').update(data).digest();
13
+ export const hmac = (key: Buffer, data: Buffer | string) => createHmac('sha256', key).update(data).digest();
14
+ export const xor = (a: Buffer, b: Buffer) => Buffer.from(a.map((byte, i) => byte ^ b[i]));
@@ -1,7 +1,7 @@
1
- export const serializer = (_: string, value: unknown) => (typeof value === "bigint" ? value.toString() : value);
1
+ export const serializer = (_: string, value: unknown) => (typeof value === 'bigint' ? value.toString() : value);
2
2
 
3
3
  export const createDebugger = (module: string) => (func: string, message: string, data?: unknown) => {
4
- if (!process.env.DEBUG?.includes("kafkats")) return;
4
+ if (!process.env.DEBUG?.includes('kafka-ts')) return;
5
5
  console.debug(
6
6
  `[${module}] ${func}: ${message}`,
7
7
  data && `(${data instanceof Error ? data : JSON.stringify(data, serializer, 4)})`,
@@ -81,7 +81,7 @@ export class Decoder {
81
81
  return null;
82
82
  }
83
83
 
84
- const value = this.buffer.toString("utf-8", this.offset, this.offset + length);
84
+ const value = this.buffer.toString('utf-8', this.offset, this.offset + length);
85
85
  this.offset += length;
86
86
  return value;
87
87
  }
@@ -92,7 +92,7 @@ export class Decoder {
92
92
  return null;
93
93
  }
94
94
 
95
- const value = this.buffer.toString("utf-8", this.offset, this.offset + length);
95
+ const value = this.buffer.toString('utf-8', this.offset, this.offset + length);
96
96
  this.offset += length;
97
97
  return value;
98
98
  }
@@ -103,13 +103,13 @@ export class Decoder {
103
103
  return null;
104
104
  }
105
105
 
106
- const value = this.buffer.toString("utf-8", this.offset, this.offset + length);
106
+ const value = this.buffer.toString('utf-8', this.offset, this.offset + length);
107
107
  this.offset += length;
108
108
  return value;
109
109
  }
110
110
 
111
111
  public readUUID() {
112
- const value = this.buffer.toString("hex", this.offset, this.offset + 16);
112
+ const value = this.buffer.toString('hex', this.offset, this.offset + 16);
113
113
  this.offset += 16;
114
114
  return value;
115
115
  }
@@ -74,9 +74,9 @@ export class Encoder {
74
74
  if (value === null) {
75
75
  return this.writeInt16(-1);
76
76
  }
77
- const byteLength = Buffer.byteLength(value, "utf-8");
77
+ const byteLength = Buffer.byteLength(value, 'utf-8');
78
78
  const buffer = Buffer.alloc(byteLength);
79
- buffer.write(value, 0, byteLength, "utf-8");
79
+ buffer.write(value, 0, byteLength, 'utf-8');
80
80
  return this.writeInt16(byteLength).write(buffer);
81
81
  }
82
82
 
@@ -85,9 +85,9 @@ export class Encoder {
85
85
  return this.writeUVarInt(0);
86
86
  }
87
87
 
88
- const byteLength = Buffer.byteLength(value, "utf-8");
88
+ const byteLength = Buffer.byteLength(value, 'utf-8');
89
89
  const buffer = Buffer.alloc(byteLength);
90
- buffer.write(value, 0, byteLength, "utf-8");
90
+ buffer.write(value, 0, byteLength, 'utf-8');
91
91
  return this.writeUVarInt(byteLength + 1).write(buffer);
92
92
  }
93
93
 
@@ -95,14 +95,14 @@ export class Encoder {
95
95
  if (value === null) {
96
96
  return this.writeVarInt(-1);
97
97
  }
98
- return this.writeVarInt(Buffer.byteLength(value, "utf-8")).write(Buffer.from(value, "utf-8"));
98
+ return this.writeVarInt(Buffer.byteLength(value, 'utf-8')).write(Buffer.from(value, 'utf-8'));
99
99
  }
100
100
 
101
101
  public writeUUID(value: string | null) {
102
102
  if (value === null) {
103
103
  return this.write(Buffer.alloc(16));
104
104
  }
105
- return this.write(Buffer.from(value, "hex"));
105
+ return this.write(Buffer.from(value, 'hex'));
106
106
  }
107
107
 
108
108
  public writeBoolean(value: boolean) {
@@ -1,4 +1,4 @@
1
- import { API_ERROR } from "../api";
1
+ import { API_ERROR } from '../api';
2
2
 
3
3
  export class KafkaTSError extends Error {
4
4
  constructor(message: string) {
@@ -13,8 +13,8 @@ export class KafkaTSApiError<T = any> extends KafkaTSError {
13
13
  public errorMessage: string | null,
14
14
  public response: T,
15
15
  ) {
16
- const [errorName] = Object.entries(API_ERROR).find(([, value]) => value === errorCode) ?? ["UNKNOWN"];
17
- super(`${errorName}${errorMessage ? `: ${errorMessage}` : ""}`);
16
+ const [errorName] = Object.entries(API_ERROR).find(([, value]) => value === errorCode) ?? ['UNKNOWN'];
17
+ super(`${errorName}${errorMessage ? `: ${errorMessage}` : ''}`);
18
18
  }
19
19
  }
20
20
 
@@ -1,4 +1,4 @@
1
- import { delay } from "./delay";
1
+ import { delay } from './delay';
2
2
 
3
3
  export type Retrier = (func: () => unknown) => Promise<void>;
4
4
 
@@ -1,9 +1,10 @@
1
- import { serializer } from "./debug";
1
+ import { serializer } from './debug';
2
2
 
3
- export const trace =
3
+ export const createTracer =
4
+ (module: string, attributes?: Record<string, unknown>) =>
4
5
  (fn?: (...args: any[]) => Record<string, unknown> | undefined) =>
5
6
  (target: any, propertyKey: string, descriptor: PropertyDescriptor) => {
6
- if (!process.env.DEBUG?.includes("kafkats")) return;
7
+ if (!process.env.DEBUG?.includes('kafka-ts')) return;
7
8
 
8
9
  const original = descriptor.value;
9
10
  descriptor.value = function (...args: any[]) {
@@ -12,7 +13,7 @@ export const trace =
12
13
 
13
14
  const onEnd = <T>(result: T): T => {
14
15
  console.log(
15
- `[${propertyKey}] +${Date.now() - startTime}ms ${JSON.stringify({ ...metadata, result }, serializer)}`,
16
+ `[${module}.${propertyKey}] +${Date.now() - startTime}ms ${JSON.stringify({ ...attributes, ...metadata, result }, serializer)}`,
16
17
  );
17
18
  return result;
18
19
  };
@@ -26,3 +27,5 @@ export const trace =
26
27
  }
27
28
  };
28
29
  };
30
+
31
+ export const trace = createTracer('GLOBAL');
package/tsconfig.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
- "compilerOptions": {
3
- "lib": ["es2023"],
4
- "target": "es2022",
5
- "module": "node16",
6
- "strict": true,
7
- "forceConsistentCasingInFileNames": true,
8
- "esModuleInterop": true,
9
- "skipLibCheck": true,
10
- "moduleResolution": "node16",
11
- "outDir": "dist",
12
- "declaration": true,
13
- "emitDecoratorMetadata": true,
14
- "experimentalDecorators": true
15
- },
16
- "include": ["src/**/*"],
17
- }
2
+ "compilerOptions": {
3
+ "lib": ["es2023"],
4
+ "target": "es2022",
5
+ "module": "node16",
6
+ "strict": true,
7
+ "forceConsistentCasingInFileNames": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "moduleResolution": "node16",
11
+ "outDir": "dist",
12
+ "declaration": true,
13
+ "emitDecoratorMetadata": true,
14
+ "experimentalDecorators": true
15
+ },
16
+ "include": ["src/**/*"]
17
+ }
@@ -1,9 +0,0 @@
1
- export declare const API_VERSIONS: import("../utils/api.js").Api<unknown, {
2
- errorCode: number;
3
- versions: {
4
- apiKey: number;
5
- minVersion: number;
6
- maxVersion: number;
7
- }[];
8
- throttleTimeMs: number;
9
- }>;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.API_VERSIONS = void 0;
4
- const api_js_1 = require("../utils/api.js");
5
- const error_js_1 = require("../utils/error.js");
6
- exports.API_VERSIONS = (0, api_js_1.createApi)({
7
- apiKey: 18,
8
- apiVersion: 2,
9
- request: (encoder) => encoder,
10
- response: (decoder) => {
11
- const result = {
12
- errorCode: decoder.readInt16(),
13
- versions: decoder.readArray((version) => ({
14
- apiKey: version.readInt16(),
15
- minVersion: version.readInt16(),
16
- maxVersion: version.readInt16(),
17
- })),
18
- throttleTimeMs: decoder.readInt32(),
19
- };
20
- if (result.errorCode)
21
- throw new error_js_1.KafkaTSApiError(result.errorCode, null, result);
22
- return result;
23
- },
24
- });
@@ -1,38 +0,0 @@
1
- export declare const CREATE_TOPICS: import("../utils/api").Api<{
2
- topics: {
3
- name: string;
4
- numPartitions: number;
5
- replicationFactor: number;
6
- assignments: {
7
- partitionIndex: number;
8
- brokerIds: number[];
9
- }[];
10
- configs: {
11
- name: string;
12
- value: string | null;
13
- }[];
14
- }[];
15
- timeoutMs: number;
16
- validateOnly: boolean;
17
- }, {
18
- _tag: void;
19
- throttleTimeMs: number;
20
- topics: {
21
- name: string | null;
22
- topicId: string;
23
- errorCode: number;
24
- errorMessage: string | null;
25
- numPartitions: number;
26
- replicationFactor: number;
27
- configs: {
28
- name: string | null;
29
- value: string | null;
30
- readOnly: boolean;
31
- configSource: number;
32
- isSensitive: boolean;
33
- _tag: void;
34
- }[];
35
- _tag: void;
36
- }[];
37
- _tag2: void;
38
- }>;
@@ -1,53 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CREATE_TOPICS = void 0;
4
- const api_1 = require("../utils/api");
5
- const error_1 = require("../utils/error");
6
- exports.CREATE_TOPICS = (0, api_1.createApi)({
7
- apiKey: 19,
8
- apiVersion: 7,
9
- request: (encoder, data) => encoder
10
- .writeUVarInt(0)
11
- .writeCompactArray(data.topics, (encoder, topic) => encoder
12
- .writeCompactString(topic.name)
13
- .writeInt32(topic.numPartitions)
14
- .writeInt16(topic.replicationFactor)
15
- .writeCompactArray(topic.assignments, (encoder, assignment) => encoder
16
- .writeInt32(assignment.partitionIndex)
17
- .writeCompactArray(assignment.brokerIds, (encoder, brokerId) => encoder.writeInt32(brokerId))
18
- .writeUVarInt(0))
19
- .writeCompactArray(topic.configs, (encoder, config) => encoder.writeCompactString(config.name).writeCompactString(config.value).writeUVarInt(0))
20
- .writeUVarInt(0))
21
- .writeInt32(data.timeoutMs)
22
- .writeBoolean(data.validateOnly)
23
- .writeUVarInt(0),
24
- response: (decoder) => {
25
- const result = {
26
- _tag: decoder.readTagBuffer(),
27
- throttleTimeMs: decoder.readInt32(),
28
- topics: decoder.readCompactArray((topic) => ({
29
- name: topic.readCompactString(),
30
- topicId: topic.readUUID(),
31
- errorCode: topic.readInt16(),
32
- errorMessage: topic.readCompactString(),
33
- numPartitions: topic.readInt32(),
34
- replicationFactor: topic.readInt16(),
35
- configs: topic.readCompactArray((config) => ({
36
- name: config.readCompactString(),
37
- value: config.readCompactString(),
38
- readOnly: config.readBoolean(),
39
- configSource: config.readInt8(),
40
- isSensitive: config.readBoolean(),
41
- _tag: config.readTagBuffer(),
42
- })),
43
- _tag: topic.readTagBuffer(),
44
- })),
45
- _tag2: decoder.readTagBuffer(),
46
- };
47
- result.topics.forEach((topic) => {
48
- if (topic.errorCode)
49
- throw new error_1.KafkaTSApiError(topic.errorCode, topic.errorMessage, result);
50
- });
51
- return result;
52
- },
53
- });
@@ -1,18 +0,0 @@
1
- export declare const DELETE_TOPICS: import("../utils/api").Api<{
2
- topics: {
3
- name: string | null;
4
- topicId: string | null;
5
- }[];
6
- timeoutMs: number;
7
- }, {
8
- _tag: void;
9
- throttleTimeMs: number;
10
- responses: {
11
- name: string | null;
12
- topicId: string;
13
- errorCode: number;
14
- errorMessage: string | null;
15
- _tag: void;
16
- }[];
17
- _tag2: void;
18
- }>;
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DELETE_TOPICS = void 0;
4
- const api_1 = require("../utils/api");
5
- const error_1 = require("../utils/error");
6
- exports.DELETE_TOPICS = (0, api_1.createApi)({
7
- apiKey: 20,
8
- apiVersion: 6,
9
- request: (encoder, data) => encoder
10
- .writeUVarInt(0)
11
- .writeCompactArray(data.topics, (encoder, topic) => encoder.writeCompactString(topic.name).writeUUID(topic.topicId).writeUVarInt(0))
12
- .writeInt32(data.timeoutMs)
13
- .writeUVarInt(0),
14
- response: (decoder) => {
15
- const result = {
16
- _tag: decoder.readTagBuffer(),
17
- throttleTimeMs: decoder.readInt32(),
18
- responses: decoder.readCompactArray((decoder) => ({
19
- name: decoder.readCompactString(),
20
- topicId: decoder.readUUID(),
21
- errorCode: decoder.readInt16(),
22
- errorMessage: decoder.readCompactString(),
23
- _tag: decoder.readTagBuffer(),
24
- })),
25
- _tag2: decoder.readTagBuffer(),
26
- };
27
- result.responses.forEach((response) => {
28
- if (response.errorCode)
29
- throw new error_1.KafkaTSApiError(response.errorCode, response.errorMessage, result);
30
- });
31
- return result;
32
- },
33
- });
@@ -1,77 +0,0 @@
1
- export declare const enum IsolationLevel {
2
- READ_UNCOMMITTED = 0,
3
- READ_COMMITTED = 1
4
- }
5
- export declare const FETCH: import("../utils/api").Api<{
6
- maxWaitMs: number;
7
- minBytes: number;
8
- maxBytes: number;
9
- isolationLevel: IsolationLevel;
10
- sessionId: number;
11
- sessionEpoch: number;
12
- topics: {
13
- topicId: string;
14
- partitions: {
15
- partition: number;
16
- currentLeaderEpoch: number;
17
- fetchOffset: bigint;
18
- lastFetchedEpoch: number;
19
- logStartOffset: bigint;
20
- partitionMaxBytes: number;
21
- }[];
22
- }[];
23
- forgottenTopicsData: {
24
- topicId: string;
25
- partitions: number[];
26
- }[];
27
- rackId: string;
28
- }, {
29
- _tag: void;
30
- throttleTimeMs: number;
31
- errorCode: number;
32
- sessionId: number;
33
- responses: {
34
- topicId: string;
35
- partitions: {
36
- partitionIndex: number;
37
- errorCode: number;
38
- highWatermark: bigint;
39
- lastStableOffset: bigint;
40
- logStartOffset: bigint;
41
- abortedTransactions: {
42
- producerId: bigint;
43
- firstOffset: bigint;
44
- _tag: void;
45
- }[];
46
- preferredReadReplica: number;
47
- records: {
48
- baseOffset: bigint;
49
- batchLength: number;
50
- partitionLeaderEpoch: number;
51
- magic: number;
52
- crc: number;
53
- attributes: number;
54
- lastOffsetDelta: number;
55
- baseTimestamp: bigint;
56
- maxTimestamp: bigint;
57
- producerId: bigint;
58
- producerEpoch: number;
59
- baseSequence: number;
60
- records: {
61
- attributes: number;
62
- timestampDelta: bigint;
63
- offsetDelta: number;
64
- key: string | null;
65
- value: string | null;
66
- headers: {
67
- key: string | null;
68
- value: string | null;
69
- }[];
70
- }[];
71
- }[];
72
- _tag: void;
73
- }[];
74
- _tag: void;
75
- }[];
76
- _tag2: void;
77
- }>;
package/dist/api/fetch.js DELETED
@@ -1,106 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FETCH = void 0;
4
- const api_1 = require("../utils/api");
5
- const error_1 = require("../utils/error");
6
- exports.FETCH = (0, api_1.createApi)({
7
- apiKey: 1,
8
- apiVersion: 16,
9
- request: (encoder, data) => encoder
10
- .writeUVarInt(0)
11
- .writeInt32(data.maxWaitMs)
12
- .writeInt32(data.minBytes)
13
- .writeInt32(data.maxBytes)
14
- .writeInt8(data.isolationLevel)
15
- .writeInt32(data.sessionId)
16
- .writeInt32(data.sessionEpoch)
17
- .writeCompactArray(data.topics, (encoder, topic) => encoder
18
- .writeUUID(topic.topicId)
19
- .writeCompactArray(topic.partitions, (encoder, partition) => encoder
20
- .writeInt32(partition.partition)
21
- .writeInt32(partition.currentLeaderEpoch)
22
- .writeInt64(partition.fetchOffset)
23
- .writeInt32(partition.lastFetchedEpoch)
24
- .writeInt64(partition.logStartOffset)
25
- .writeInt32(partition.partitionMaxBytes)
26
- .writeUVarInt(0))
27
- .writeUVarInt(0))
28
- .writeCompactArray(data.forgottenTopicsData, (encoder, forgottenTopic) => encoder
29
- .writeUUID(forgottenTopic.topicId)
30
- .writeCompactArray(forgottenTopic.partitions, (encoder, partition) => encoder.writeInt32(partition))
31
- .writeUVarInt(0))
32
- .writeCompactString(data.rackId)
33
- .writeUVarInt(0),
34
- response: (decoder) => {
35
- const result = {
36
- _tag: decoder.readTagBuffer(),
37
- throttleTimeMs: decoder.readInt32(),
38
- errorCode: decoder.readInt16(),
39
- sessionId: decoder.readInt32(),
40
- responses: decoder.readCompactArray((response) => ({
41
- topicId: response.readUUID(),
42
- partitions: response.readCompactArray((partition) => ({
43
- partitionIndex: partition.readInt32(),
44
- errorCode: partition.readInt16(),
45
- highWatermark: partition.readInt64(),
46
- lastStableOffset: partition.readInt64(),
47
- logStartOffset: partition.readInt64(),
48
- abortedTransactions: partition.readCompactArray((abortedTransaction) => ({
49
- producerId: abortedTransaction.readInt64(),
50
- firstOffset: abortedTransaction.readInt64(),
51
- _tag: abortedTransaction.readTagBuffer(),
52
- })),
53
- preferredReadReplica: partition.readInt32(),
54
- records: decodeRecords(partition),
55
- _tag: partition.readTagBuffer(),
56
- })),
57
- _tag: response.readTagBuffer(),
58
- })),
59
- _tag2: decoder.readTagBuffer(),
60
- };
61
- if (result.errorCode)
62
- throw new error_1.KafkaTSApiError(result.errorCode, null, result);
63
- result.responses.forEach((response) => {
64
- response.partitions.forEach((partition) => {
65
- if (partition.errorCode)
66
- throw new error_1.KafkaTSApiError(partition.errorCode, null, result);
67
- });
68
- });
69
- return result;
70
- },
71
- });
72
- const decodeRecords = (decoder) => {
73
- const size = decoder.readUVarInt() - 1;
74
- if (size <= 0) {
75
- return [];
76
- }
77
- const results = [];
78
- while (decoder.getBufferLength() > decoder.getOffset() + 49) {
79
- results.push({
80
- baseOffset: decoder.readInt64(),
81
- batchLength: decoder.readInt32(),
82
- partitionLeaderEpoch: decoder.readInt32(),
83
- magic: decoder.readInt8(),
84
- crc: decoder.readUInt32(),
85
- attributes: decoder.readInt16(),
86
- lastOffsetDelta: decoder.readInt32(),
87
- baseTimestamp: decoder.readInt64(),
88
- maxTimestamp: decoder.readInt64(),
89
- producerId: decoder.readInt64(),
90
- producerEpoch: decoder.readInt16(),
91
- baseSequence: decoder.readInt32(),
92
- records: decoder.readRecords((record) => ({
93
- attributes: record.readInt8(),
94
- timestampDelta: record.readVarLong(),
95
- offsetDelta: record.readVarInt(),
96
- key: record.readVarIntString(),
97
- value: record.readVarIntString(),
98
- headers: record.readCompactArray((header) => ({
99
- key: header.readVarIntString(),
100
- value: header.readVarIntString(),
101
- })),
102
- })),
103
- });
104
- }
105
- return results;
106
- };
@@ -1,21 +0,0 @@
1
- export declare const KEY_TYPE: {
2
- GROUP: number;
3
- TRANSACTION: number;
4
- };
5
- export declare const FIND_COORDINATOR: import("../utils/api").Api<{
6
- keyType: number;
7
- keys: string[];
8
- }, {
9
- _tag: void;
10
- throttleTimeMs: number;
11
- coordinators: {
12
- key: string | null;
13
- nodeId: number;
14
- host: string;
15
- port: number;
16
- errorCode: number;
17
- errorMessage: string | null;
18
- _tag: void;
19
- }[];
20
- _tag2: void;
21
- }>;
@@ -1,39 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.FIND_COORDINATOR = exports.KEY_TYPE = void 0;
4
- const api_1 = require("../utils/api");
5
- const error_1 = require("../utils/error");
6
- exports.KEY_TYPE = {
7
- GROUP: 0,
8
- TRANSACTION: 1,
9
- };
10
- exports.FIND_COORDINATOR = (0, api_1.createApi)({
11
- apiKey: 10,
12
- apiVersion: 4,
13
- request: (encoder, data) => encoder
14
- .writeUVarInt(0)
15
- .writeInt8(data.keyType)
16
- .writeCompactArray(data.keys, (encoder, key) => encoder.writeCompactString(key))
17
- .writeUVarInt(0),
18
- response: (decoder) => {
19
- const result = {
20
- _tag: decoder.readTagBuffer(),
21
- throttleTimeMs: decoder.readInt32(),
22
- coordinators: decoder.readCompactArray((decoder) => ({
23
- key: decoder.readCompactString(),
24
- nodeId: decoder.readInt32(),
25
- host: decoder.readCompactString(),
26
- port: decoder.readInt32(),
27
- errorCode: decoder.readInt16(),
28
- errorMessage: decoder.readCompactString(),
29
- _tag: decoder.readTagBuffer(),
30
- })),
31
- _tag2: decoder.readTagBuffer(),
32
- };
33
- result.coordinators.forEach((coordinator) => {
34
- if (coordinator.errorCode)
35
- throw new error_1.KafkaTSApiError(coordinator.errorCode, coordinator.errorMessage, result);
36
- });
37
- return result;
38
- },
39
- });
@@ -1,11 +0,0 @@
1
- export declare const HEARTBEAT: import("../utils/api").Api<{
2
- groupId: string;
3
- generationId: number;
4
- memberId: string;
5
- groupInstanceId: string | null;
6
- }, {
7
- _tag: void;
8
- throttleTimeMs: number;
9
- errorCode: number;
10
- _tag2: void;
11
- }>;
@@ -1,27 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.HEARTBEAT = void 0;
4
- const api_1 = require("../utils/api");
5
- const error_1 = require("../utils/error");
6
- exports.HEARTBEAT = (0, api_1.createApi)({
7
- apiKey: 12,
8
- apiVersion: 4,
9
- request: (encoder, data) => encoder
10
- .writeUVarInt(0)
11
- .writeCompactString(data.groupId)
12
- .writeInt32(data.generationId)
13
- .writeCompactString(data.memberId)
14
- .writeCompactString(data.groupInstanceId)
15
- .writeUVarInt(0),
16
- response: (decoder) => {
17
- const result = {
18
- _tag: decoder.readTagBuffer(),
19
- throttleTimeMs: decoder.readInt32(),
20
- errorCode: decoder.readInt16(),
21
- _tag2: decoder.readTagBuffer(),
22
- };
23
- if (result.errorCode)
24
- throw new error_1.KafkaTSApiError(result.errorCode, null, result);
25
- return result;
26
- },
27
- });