kafka-ts 0.0.5 → 0.0.6-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/connection.js +11 -3
- package/dist/consumer/offset-manager.js +8 -2
- package/dist/producer/producer.d.ts +1 -1
- package/dist/producer/producer.js +5 -3
- package/dist/utils/error.d.ts +1 -0
- package/dist/utils/error.js +1 -0
- package/dist/utils/logger.js +7 -1
- package/package.json +2 -2
package/README.md
CHANGED
package/dist/connection.js
CHANGED
|
@@ -112,9 +112,17 @@ class Connection {
|
|
|
112
112
|
}
|
|
113
113
|
});
|
|
114
114
|
clearTimeout(timeout);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
try {
|
|
116
|
+
const response = await api.response(responseDecoder);
|
|
117
|
+
(0, assert_1.default)(responseDecoder.getOffset() - 4 === responseSize, `Buffer not correctly consumed: ${responseDecoder.getOffset() - 4} !== ${responseSize}`);
|
|
118
|
+
return response;
|
|
119
|
+
}
|
|
120
|
+
catch (error) {
|
|
121
|
+
if (error instanceof error_1.KafkaTSApiError) {
|
|
122
|
+
error.request = JSON.stringify(body, logger_1.jsonSerializer);
|
|
123
|
+
}
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
118
126
|
}
|
|
119
127
|
write(buffer) {
|
|
120
128
|
return new Promise((resolve, reject) => {
|
|
@@ -49,7 +49,13 @@ class OffsetManager {
|
|
|
49
49
|
.flatMap(([topic, partitions]) => partitions.map((partition) => ({ topic, partition })))
|
|
50
50
|
.map(({ topic, partition }) => ({
|
|
51
51
|
name: topic,
|
|
52
|
-
partitions: [
|
|
52
|
+
partitions: [
|
|
53
|
+
{
|
|
54
|
+
partitionIndex: partition,
|
|
55
|
+
currentLeaderEpoch: -1,
|
|
56
|
+
timestamp: fromBeginning ? -2n : -1n,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
53
59
|
})),
|
|
54
60
|
});
|
|
55
61
|
const topicPartitions = {};
|
|
@@ -57,7 +63,7 @@ class OffsetManager {
|
|
|
57
63
|
topicPartitions[name] ??= new Set();
|
|
58
64
|
partitions.forEach(({ partitionIndex, offset }) => {
|
|
59
65
|
topicPartitions[name].add(partitionIndex);
|
|
60
|
-
this.resolve(name, partitionIndex,
|
|
66
|
+
this.resolve(name, partitionIndex, offset);
|
|
61
67
|
});
|
|
62
68
|
});
|
|
63
69
|
this.flush(topicPartitions);
|
|
@@ -61,7 +61,7 @@ class Producer {
|
|
|
61
61
|
maxTimestamp = timestamp;
|
|
62
62
|
}
|
|
63
63
|
});
|
|
64
|
-
const baseSequence = this.
|
|
64
|
+
const baseSequence = this.getBaseSequence(topic, partitionIndex, messages.length);
|
|
65
65
|
return {
|
|
66
66
|
index: partitionIndex,
|
|
67
67
|
baseOffset: 0n,
|
|
@@ -116,10 +116,12 @@ class Producer {
|
|
|
116
116
|
throw error;
|
|
117
117
|
}
|
|
118
118
|
}
|
|
119
|
-
|
|
119
|
+
getBaseSequence(topic, partition, messagesCount) {
|
|
120
120
|
this.sequences[topic] ??= {};
|
|
121
121
|
this.sequences[topic][partition] ??= 0;
|
|
122
|
-
|
|
122
|
+
const baseSequence = this.sequences[topic][partition];
|
|
123
|
+
this.sequences[topic][partition] += messagesCount;
|
|
124
|
+
return baseSequence;
|
|
123
125
|
}
|
|
124
126
|
}
|
|
125
127
|
exports.Producer = Producer;
|
package/dist/utils/error.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare class KafkaTSApiError<T = any> extends KafkaTSError {
|
|
|
5
5
|
errorCode: number;
|
|
6
6
|
errorMessage: string | null;
|
|
7
7
|
response: T;
|
|
8
|
+
request: string | undefined;
|
|
8
9
|
constructor(errorCode: number, errorMessage: string | null, response: T);
|
|
9
10
|
}
|
|
10
11
|
export declare class ConnectionError extends KafkaTSError {
|
package/dist/utils/error.js
CHANGED
|
@@ -13,6 +13,7 @@ class KafkaTSApiError extends KafkaTSError {
|
|
|
13
13
|
errorCode;
|
|
14
14
|
errorMessage;
|
|
15
15
|
response;
|
|
16
|
+
request;
|
|
16
17
|
constructor(errorCode, errorMessage, response) {
|
|
17
18
|
const [errorName] = Object.entries(api_1.API_ERROR).find(([, value]) => value === errorCode) ?? ['UNKNOWN'];
|
|
18
19
|
super(`${errorName}${errorMessage ? `: ${errorMessage}` : ''}`);
|
package/dist/utils/logger.js
CHANGED
|
@@ -3,7 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.setLogger = exports.log = exports.jsonSerializer = void 0;
|
|
4
4
|
const jsonSerializer = (_, v) => {
|
|
5
5
|
if (v instanceof Error) {
|
|
6
|
-
return
|
|
6
|
+
return Object.getOwnPropertyNames(v).reduce((acc, key) => {
|
|
7
|
+
acc[key] = v[key];
|
|
8
|
+
return acc;
|
|
9
|
+
}, {});
|
|
10
|
+
}
|
|
11
|
+
if (Buffer.isBuffer(v)) {
|
|
12
|
+
return v.toString();
|
|
7
13
|
}
|
|
8
14
|
if (typeof v === 'bigint') {
|
|
9
15
|
return v.toString();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-ts",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6-beta.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"author": "Priit Käärd",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
12
|
"start": "docker-compose down && KAFKA_VERSION=3.7.1 docker-compose up -d && sleep 5 && bash ./scripts/create-scram-user.sh",
|
|
13
|
-
"version:
|
|
13
|
+
"version:prerelease": "npm version prerelease",
|
|
14
14
|
"version:patch": "npm version patch",
|
|
15
15
|
"format": "prettier --write .",
|
|
16
16
|
"build": "tsc",
|