kafka-ts 1.1.8 → 1.1.9

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 (51) hide show
  1. package/dist/consumer/consumer-group.js +84 -99
  2. package/dist/consumer/consumer.js +16 -25
  3. package/dist/producer/producer.js +5 -12
  4. package/dist/utils/retry.d.ts +1 -0
  5. package/dist/utils/retry.js +19 -0
  6. package/package.json +1 -1
  7. package/dist/consumer/metadata.d.ts +0 -24
  8. package/dist/consumer/metadata.js +0 -64
  9. package/dist/examples/src/replicator.js +0 -34
  10. package/dist/examples/src/utils/json.js +0 -5
  11. package/dist/request-handler.d.ts +0 -16
  12. package/dist/request-handler.js +0 -67
  13. package/dist/request-handler.test.d.ts +0 -1
  14. package/dist/request-handler.test.js +0 -340
  15. package/dist/src/api/api-versions.js +0 -18
  16. package/dist/src/api/create-topics.js +0 -46
  17. package/dist/src/api/delete-topics.js +0 -26
  18. package/dist/src/api/fetch.js +0 -95
  19. package/dist/src/api/find-coordinator.js +0 -34
  20. package/dist/src/api/heartbeat.js +0 -22
  21. package/dist/src/api/index.js +0 -38
  22. package/dist/src/api/init-producer-id.js +0 -24
  23. package/dist/src/api/join-group.js +0 -48
  24. package/dist/src/api/leave-group.js +0 -30
  25. package/dist/src/api/list-offsets.js +0 -39
  26. package/dist/src/api/metadata.js +0 -47
  27. package/dist/src/api/offset-commit.js +0 -39
  28. package/dist/src/api/offset-fetch.js +0 -44
  29. package/dist/src/api/produce.js +0 -119
  30. package/dist/src/api/sync-group.js +0 -31
  31. package/dist/src/broker.js +0 -35
  32. package/dist/src/connection.js +0 -21
  33. package/dist/src/consumer/consumer-group.js +0 -131
  34. package/dist/src/consumer/consumer.js +0 -103
  35. package/dist/src/consumer/metadata.js +0 -52
  36. package/dist/src/consumer/offset-manager.js +0 -23
  37. package/dist/src/index.js +0 -19
  38. package/dist/src/producer/producer.js +0 -84
  39. package/dist/src/request-handler.js +0 -57
  40. package/dist/src/request-handler.test.js +0 -321
  41. package/dist/src/types.js +0 -2
  42. package/dist/src/utils/api.js +0 -5
  43. package/dist/src/utils/decoder.js +0 -161
  44. package/dist/src/utils/encoder.js +0 -137
  45. package/dist/src/utils/error.js +0 -10
  46. package/dist/utils/debug.d.ts +0 -2
  47. package/dist/utils/debug.js +0 -11
  48. package/dist/utils/memo.d.ts +0 -1
  49. package/dist/utils/memo.js +0 -16
  50. package/dist/utils/mutex.d.ts +0 -3
  51. package/dist/utils/mutex.js +0 -32
@@ -1,161 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDecoder = void 0;
4
- const createDecoder = ({ buffer, offset = 0 }) => {
5
- const readInt8 = () => {
6
- const value = buffer.readInt8(offset);
7
- offset += 1;
8
- return value;
9
- };
10
- const readInt16 = () => {
11
- const value = buffer.readInt16BE(offset);
12
- offset += 2;
13
- return value;
14
- };
15
- const readInt32 = () => {
16
- const value = buffer.readInt32BE(offset);
17
- offset += 4;
18
- return value;
19
- };
20
- const readUInt32 = () => {
21
- const value = buffer.readUInt32BE(offset);
22
- offset += 4;
23
- return value;
24
- };
25
- const readInt64 = () => {
26
- const value = buffer.readBigInt64BE(offset);
27
- offset += 8;
28
- return value;
29
- };
30
- const readString = () => {
31
- const length = readInt16();
32
- if (length === -1) {
33
- return null;
34
- }
35
- const value = buffer.toString('utf-8', offset, offset + length);
36
- offset += length;
37
- return value;
38
- };
39
- const readCompactString = () => {
40
- const length = readUVarInt() - 1;
41
- if (length < 0) {
42
- return null;
43
- }
44
- const value = buffer.toString('utf-8', offset, offset + length);
45
- offset += length;
46
- return value;
47
- };
48
- const readVarInt = () => {
49
- let currentByte;
50
- let result = 0;
51
- let i = 0;
52
- while (((currentByte = buffer[offset++]) & 0x80) !== 0) {
53
- result |= (currentByte & 0x7f) << i;
54
- i += 7;
55
- if (i > 28) {
56
- throw new Error("Invalid VarInt, must contain 5 bytes or less");
57
- }
58
- }
59
- result |= currentByte << i;
60
- return result;
61
- };
62
- const readUVarInt = () => {
63
- const result = readVarInt();
64
- return result >>> 0;
65
- };
66
- const readVarLong = () => {
67
- let currentByte;
68
- let result = BigInt(0);
69
- let i = 0;
70
- while (((currentByte = buffer[offset++]) & 0x80) !== 0) {
71
- result |= BigInt(currentByte & 0x7f) << BigInt(i);
72
- i += 7;
73
- if (i > 63) {
74
- throw new Error("Invalid VarLong, must contain 9 bytes or less");
75
- }
76
- }
77
- result |= BigInt(currentByte) << BigInt(i);
78
- return result;
79
- };
80
- const readUUID = () => {
81
- const value = buffer.toString("hex", offset, offset + 16);
82
- offset += 16;
83
- return value;
84
- };
85
- const readBoolean = () => {
86
- const value = buffer.readInt8(offset) === 1;
87
- offset += 1;
88
- return value;
89
- };
90
- const readArray = (callback) => {
91
- const length = readInt32();
92
- const decoder = (0, exports.createDecoder)({ buffer, offset });
93
- const results = Array.from({ length }).map(() => callback(decoder));
94
- offset = decoder.offset;
95
- return results;
96
- };
97
- const readCompactArray = (callback) => {
98
- const length = readUVarInt() - 1;
99
- const decoder = (0, exports.createDecoder)({ buffer, offset });
100
- const results = Array.from({ length }).map(() => callback(decoder));
101
- offset = decoder.offset;
102
- return results;
103
- };
104
- const readRecords = (callback) => {
105
- const length = readInt32();
106
- return Array.from({ length }).map(() => {
107
- const size = Math.ceil((readVarInt() - 1) / 2);
108
- const child = (0, exports.createDecoder)({ buffer: buffer.subarray(offset, offset + size) });
109
- offset += size;
110
- return callback(child);
111
- });
112
- };
113
- const read = (length) => {
114
- const value = buffer.subarray(offset, offset + length);
115
- offset += length;
116
- return value;
117
- };
118
- const readBytes = () => {
119
- const length = readInt32();
120
- return read(length);
121
- };
122
- const readCompactBytes = (divide = false) => {
123
- let length = readUVarInt() - 1;
124
- if (length < 0) {
125
- return null;
126
- }
127
- if (divide) {
128
- length = Math.round(length / 2);
129
- }
130
- return read(length);
131
- };
132
- const readTagBuffer = () => {
133
- readUVarInt();
134
- };
135
- return {
136
- readInt8,
137
- readInt16,
138
- readInt32,
139
- readInt64,
140
- readUInt32,
141
- readVarInt,
142
- readUVarInt,
143
- readVarLong,
144
- readString,
145
- readBytes,
146
- readCompactString,
147
- readUUID,
148
- readBoolean,
149
- readArray,
150
- readCompactArray,
151
- read,
152
- readCompactBytes,
153
- readTagBuffer,
154
- readRecords,
155
- buffer,
156
- get offset() {
157
- return offset;
158
- },
159
- };
160
- };
161
- exports.createDecoder = createDecoder;
@@ -1,137 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createEncoder = void 0;
4
- const createEncoder = ({ buffer = Buffer.alloc(0) } = {}) => {
5
- const write = (rightBuffer) => (0, exports.createEncoder)({ buffer: Buffer.concat([buffer, rightBuffer]) });
6
- const writeInt8 = (value) => {
7
- const buffer = Buffer.alloc(1);
8
- buffer.writeInt8(value);
9
- return write(buffer);
10
- };
11
- const writeInt16 = (value) => {
12
- const buffer = Buffer.alloc(2);
13
- buffer.writeInt16BE(value);
14
- return write(buffer);
15
- };
16
- const writeInt32 = (value) => {
17
- const buffer = Buffer.alloc(4);
18
- buffer.writeInt32BE(value);
19
- return write(buffer);
20
- };
21
- const writeUInt32 = (value) => {
22
- const buffer = Buffer.alloc(4);
23
- buffer.writeUInt32BE(value);
24
- return write(buffer);
25
- };
26
- const writeInt64 = (value) => {
27
- const buffer = Buffer.alloc(8);
28
- buffer.writeBigInt64BE(value);
29
- return write(buffer);
30
- };
31
- const writeString = (value) => {
32
- if (value === null) {
33
- return writeInt16(-1);
34
- }
35
- const byteLength = Buffer.byteLength(value, "utf-8");
36
- const buffer = Buffer.alloc(2 + byteLength);
37
- buffer.writeInt16BE(byteLength);
38
- buffer.write(value, 2, byteLength, "utf-8");
39
- return write(buffer);
40
- };
41
- const writeUVarInt = (value) => {
42
- const byteArray = [];
43
- while ((value & 0xffffffff) !== 0) {
44
- byteArray.push((value & 0x7f) | 0x80);
45
- value >>>= 7;
46
- }
47
- byteArray.push(value & 0x7f);
48
- return write(Buffer.from(byteArray));
49
- };
50
- const writeVarInt = (value) => {
51
- const encodedValue = (value << 1) ^ (value >> 31);
52
- return writeUVarInt(encodedValue);
53
- };
54
- const writeUVarLong = (value) => {
55
- const byteArray = [];
56
- while ((value & BigInt(0xffffffffffffffff)) !== BigInt(0)) {
57
- byteArray.push(Number(value & BigInt(0x7f) | BigInt(0x80)));
58
- value = value >> BigInt(7);
59
- }
60
- byteArray.push(Number(value));
61
- return write(Buffer.from(byteArray));
62
- };
63
- const writeVarLong = (value) => {
64
- const encodedValue = (value << BigInt(1)) ^ (value >> BigInt(63));
65
- return writeUVarLong(encodedValue);
66
- };
67
- // const writeVarLong = (value: bigint) => {
68
- // const encodedValue = (value << BigInt(1)) ^ (value >> BigInt(63));
69
- // return writeUVarInt(Number(encodedValue));
70
- // };
71
- const writeCompactString = (value) => {
72
- if (value === null) {
73
- return writeUVarInt(0);
74
- }
75
- const byteLength = Buffer.byteLength(value, "utf-8");
76
- const buffer = Buffer.alloc(byteLength);
77
- buffer.write(value, 0, byteLength, "utf-8");
78
- return writeUVarInt(byteLength + 1).write(buffer);
79
- };
80
- const writeVarIntString = (value) => {
81
- if (value === null) {
82
- return writeVarInt(-1);
83
- }
84
- return writeVarInt(Buffer.byteLength(value, 'utf-8')).write(Buffer.from(value, 'utf-8'));
85
- };
86
- const writeUUID = (value) => {
87
- if (value === null) {
88
- return write(Buffer.alloc(16));
89
- }
90
- return write(Buffer.from(value, "hex"));
91
- };
92
- const writeCompactArray = (arr, callback) => {
93
- if (arr === null) {
94
- return writeUVarInt(0);
95
- }
96
- const buffers = arr.map((item) => callback((0, exports.createEncoder)(), item).value());
97
- return writeUVarInt(buffers.length + 1).write(Buffer.concat(buffers));
98
- };
99
- const writeArray = (arr, callback) => {
100
- const buffers = arr.map((item) => callback((0, exports.createEncoder)(), item).value());
101
- return writeInt32(arr.length).write(Buffer.concat(buffers));
102
- };
103
- const writeBoolean = (value) => {
104
- const buffer = Buffer.alloc(1);
105
- buffer.writeInt8(value ? 1 : 0);
106
- return write(buffer);
107
- };
108
- const writeBytes = (value) => {
109
- return writeInt32(value.length).write(value);
110
- };
111
- const writeCompactBytes = (value) => {
112
- return writeUVarInt(value.length + 1).write(value);
113
- };
114
- const value = () => buffer;
115
- return {
116
- write,
117
- writeInt8,
118
- writeInt16,
119
- writeInt32,
120
- writeUInt32,
121
- writeInt64,
122
- writeCompactString,
123
- writeVarIntString,
124
- writeString,
125
- writeUVarInt,
126
- writeVarInt,
127
- writeVarLong,
128
- writeUUID,
129
- writeCompactArray,
130
- writeArray,
131
- writeBoolean,
132
- writeBytes,
133
- writeCompactBytes,
134
- value,
135
- };
136
- };
137
- exports.createEncoder = createEncoder;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.KafkaTSError = void 0;
4
- class KafkaTSError extends Error {
5
- constructor(message) {
6
- super(message);
7
- this.name = "KafkaTSError";
8
- }
9
- }
10
- exports.KafkaTSError = KafkaTSError;
@@ -1,2 +0,0 @@
1
- export declare const serializer: (_: string, value: unknown) => unknown;
2
- export declare const createDebugger: (module: string) => (func: string, message: string, data?: unknown) => void;
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createDebugger = exports.serializer = void 0;
4
- const serializer = (_, value) => (typeof value === 'bigint' ? value.toString() : value);
5
- exports.serializer = serializer;
6
- const createDebugger = (module) => (func, message, data) => {
7
- if (!process.env.DEBUG?.includes('kafka-ts'))
8
- return;
9
- console.debug(`[${module}] ${func}: ${message}`, data && `(${data instanceof Error ? data : JSON.stringify(data, exports.serializer, 4)})`);
10
- };
11
- exports.createDebugger = createDebugger;
@@ -1 +0,0 @@
1
- export declare const memo: <T extends (...args: any[]) => any>(fn: T) => (...args: Parameters<T>) => ReturnType<T>;
@@ -1,16 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.memo = void 0;
4
- const memo = (fn) => {
5
- const cache = {};
6
- return (...args) => {
7
- const key = JSON.stringify(args);
8
- if (cache[key]) {
9
- return cache[key];
10
- }
11
- const result = fn(...args);
12
- cache[key] = result;
13
- return result;
14
- };
15
- };
16
- exports.memo = memo;
@@ -1,3 +0,0 @@
1
- export declare const createMutex: () => {
2
- exclusive: (fn: () => Promise<void>) => Promise<void>;
3
- };
@@ -1,32 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.createMutex = void 0;
4
- const createMutex = () => {
5
- const queue = [];
6
- let isLocked = false;
7
- const acquire = () => {
8
- return new Promise((resolve) => {
9
- if (!isLocked) {
10
- isLocked = true;
11
- return resolve();
12
- }
13
- queue.push(resolve);
14
- });
15
- };
16
- const release = () => {
17
- isLocked = false;
18
- const next = queue.shift();
19
- next && next();
20
- };
21
- const exclusive = async (fn) => {
22
- await acquire();
23
- try {
24
- await fn();
25
- }
26
- finally {
27
- release();
28
- }
29
- };
30
- return { exclusive };
31
- };
32
- exports.createMutex = createMutex;