kafka-console 1.2.60 → 1.3.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.
- package/LICENSE +1 -1
- package/README.md +2 -1
- package/build/commands/consume.js +3 -2
- package/build/commands/fetchTopicOffsets.js +45 -0
- package/build/index.js +8 -2
- package/build/utils/kafka.js +10 -13
- package/package.json +11 -11
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -41,6 +41,7 @@ npm install -g kafka-console
|
|
|
41
41
|
-b, --brokers <brokers> bootstrap server host (default: "localhost:9092")
|
|
42
42
|
-l, --log-level <logLevel> log level
|
|
43
43
|
-t, --timeout <timeout> set a timeout of operation (default: "0")
|
|
44
|
+
-p, --pretty pretty print json
|
|
44
45
|
--ssl enable ssl (default: false)
|
|
45
46
|
--mechanism <mechanism> sasl mechanism
|
|
46
47
|
--username <username> sasl username
|
|
@@ -170,7 +171,7 @@ export interface Formatter<T> {
|
|
|
170
171
|
|
|
171
172
|
## License
|
|
172
173
|
License [The MIT License](http://opensource.org/licenses/MIT)
|
|
173
|
-
Copyright (c)
|
|
174
|
+
Copyright (c) 2023 Ivan Zakharchanka
|
|
174
175
|
|
|
175
176
|
[npm-url]: https://www.npmjs.com/package/kafka-console
|
|
176
177
|
[downloads-image]: https://img.shields.io/npm/dw/kafka-console.svg?maxAge=43200
|
|
@@ -56,7 +56,7 @@ const formatters_1 = require("../utils/formatters");
|
|
|
56
56
|
function consume(topic, opts, { parent }) {
|
|
57
57
|
var _a, e_1, _b, _c;
|
|
58
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
const _d = Object.assign(Object.assign({}, parent.opts()), opts), { group, format, fromBeginning, count, skip, filename, brokers, logLevel, timeout, ssl } = _d, saslOptions = __rest(_d, ["group", "format", "fromBeginning", "count", "skip", "filename", "brokers", "logLevel", "timeout", "ssl"]);
|
|
59
|
+
const _d = Object.assign(Object.assign({}, parent.opts()), opts), { group, format, fromBeginning, count, skip, filename, brokers, logLevel, timeout, ssl, pretty } = _d, saslOptions = __rest(_d, ["group", "format", "fromBeginning", "count", "skip", "filename", "brokers", "logLevel", "timeout", "ssl", "pretty"]);
|
|
60
60
|
const sasl = (0, kafka_1.getSASL)(saslOptions);
|
|
61
61
|
const client = (0, kafka_1.createClient)(brokers, ssl, sasl, logLevel);
|
|
62
62
|
const output = filename ? Fs.createWriteStream(filename) : process.stdout;
|
|
@@ -78,7 +78,8 @@ function consume(topic, opts, { parent }) {
|
|
|
78
78
|
return Object.assign(Object.assign({}, result), { [key]: value.toString() });
|
|
79
79
|
}, {});
|
|
80
80
|
const message = { headers: parsedHeaders, key: key === null || key === void 0 ? void 0 : key.toString(), value: yield formatter.decode(value) };
|
|
81
|
-
|
|
81
|
+
const space = pretty ? 2 : 0;
|
|
82
|
+
output.write(JSON.stringify(message, null, space) + '\n');
|
|
82
83
|
}
|
|
83
84
|
finally {
|
|
84
85
|
_e = true;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
const kafka_1 = require("../utils/kafka");
|
|
24
|
+
function fetchTopicOffset(topic, timestamp, opts, { parent }) {
|
|
25
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
const _a = Object.assign(Object.assign({}, parent.opts()), opts), { brokers, logLevel, ssl } = _a, rest = __rest(_a, ["brokers", "logLevel", "ssl"]);
|
|
27
|
+
const sasl = (0, kafka_1.getSASL)(rest);
|
|
28
|
+
const client = (0, kafka_1.createClient)(brokers, ssl, sasl, logLevel);
|
|
29
|
+
const admin = yield (0, kafka_1.createAdmin)(client);
|
|
30
|
+
if (timestamp) {
|
|
31
|
+
const unixTimestamp = new Date(timestamp).getTime();
|
|
32
|
+
if (Number.isNaN(unixTimestamp)) {
|
|
33
|
+
throw new Error(`Invalid timestamp "${timestamp}"`);
|
|
34
|
+
}
|
|
35
|
+
const topicOffsets = yield admin.fetchTopicOffsetsByTimestamp(topic, unixTimestamp);
|
|
36
|
+
console.log(topicOffsets);
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const topicOffsets = yield admin.fetchTopicOffsets(topic);
|
|
40
|
+
console.log(topicOffsets);
|
|
41
|
+
}
|
|
42
|
+
yield admin.disconnect();
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
exports.default = fetchTopicOffset;
|
package/build/index.js
CHANGED
|
@@ -13,6 +13,7 @@ const list_1 = __importDefault(require("./commands/list"));
|
|
|
13
13
|
const config_1 = __importDefault(require("./commands/config"));
|
|
14
14
|
const createTopic_1 = __importDefault(require("./commands/createTopic"));
|
|
15
15
|
const deleteTopic_1 = __importDefault(require("./commands/deleteTopic"));
|
|
16
|
+
const fetchTopicOffsets_1 = __importDefault(require("./commands/fetchTopicOffsets"));
|
|
16
17
|
const { version } = require('../package.json');
|
|
17
18
|
function collect(value, result) {
|
|
18
19
|
return result.concat([value]);
|
|
@@ -27,6 +28,7 @@ commander
|
|
|
27
28
|
.option('-b, --brokers <brokers>', 'bootstrap server host', process.env.KAFKA_BROKERS || 'localhost:9092')
|
|
28
29
|
.option('-l, --log-level <logLevel>', 'log level')
|
|
29
30
|
.option('-t, --timeout <timeout>', 'set a timeout of operation', toInt, process.env.KAFKA_TIMEOUT || '0')
|
|
31
|
+
.option('-p, --pretty', 'pretty print', false)
|
|
30
32
|
.option('--ssl', 'enable ssl', false)
|
|
31
33
|
.option('--mechanism <mechanism>', 'sasl mechanism', process.env.KAFKA_MECHANISM)
|
|
32
34
|
.option('--username <username>', 'sasl username', process.env.KAFKA_USERNAME)
|
|
@@ -72,13 +74,17 @@ commander
|
|
|
72
74
|
.description('Describes config for specific resource')
|
|
73
75
|
.action(config_1.default);
|
|
74
76
|
commander
|
|
75
|
-
.command('create <topic>')
|
|
77
|
+
.command('topic:create <topic>')
|
|
76
78
|
.description('Creates kafka topic')
|
|
77
79
|
.action(createTopic_1.default);
|
|
78
80
|
commander
|
|
79
|
-
.command('delete <topic>')
|
|
81
|
+
.command('topic:delete <topic>')
|
|
80
82
|
.description('Deletes kafka topic')
|
|
81
83
|
.action(deleteTopic_1.default);
|
|
84
|
+
commander
|
|
85
|
+
.command('topic:offsets <topic> [timestamp]')
|
|
86
|
+
.description('Shows kafka topic offsets')
|
|
87
|
+
.action(fetchTopicOffsets_1.default);
|
|
82
88
|
commander.on('--help', function () {
|
|
83
89
|
[
|
|
84
90
|
'',
|
package/build/utils/kafka.js
CHANGED
|
@@ -40,24 +40,21 @@ function logLevelParser(level) {
|
|
|
40
40
|
exports.logLevelParser = logLevelParser;
|
|
41
41
|
function resourceParser(resource) {
|
|
42
42
|
if (/^any$/i.test(resource)) {
|
|
43
|
-
return kafkajs_1.
|
|
43
|
+
return kafkajs_1.ConfigResourceTypes.UNKNOWN;
|
|
44
44
|
}
|
|
45
45
|
if (/^topic$/i.test(resource)) {
|
|
46
|
-
return kafkajs_1.
|
|
46
|
+
return kafkajs_1.ConfigResourceTypes.TOPIC;
|
|
47
47
|
}
|
|
48
|
-
if (/^
|
|
49
|
-
return kafkajs_1.
|
|
48
|
+
if (/^broker$/i.test(resource)) {
|
|
49
|
+
return kafkajs_1.ConfigResourceTypes.BROKER;
|
|
50
50
|
}
|
|
51
|
-
if (/^
|
|
52
|
-
return kafkajs_1.
|
|
51
|
+
if (/^broker_logger$/i.test(resource)) {
|
|
52
|
+
return kafkajs_1.ConfigResourceTypes.BROKER_LOGGER;
|
|
53
53
|
}
|
|
54
|
-
if (/^
|
|
55
|
-
return kafkajs_1.
|
|
54
|
+
if (/^logger$/i.test(resource)) {
|
|
55
|
+
return kafkajs_1.ConfigResourceTypes.BROKER_LOGGER;
|
|
56
56
|
}
|
|
57
|
-
|
|
58
|
-
return kafkajs_1.ResourceTypes.DELEGATION_TOKEN;
|
|
59
|
-
}
|
|
60
|
-
return kafkajs_1.ResourceTypes.UNKNOWN;
|
|
57
|
+
return kafkajs_1.ConfigResourceTypes.UNKNOWN;
|
|
61
58
|
}
|
|
62
59
|
exports.resourceParser = resourceParser;
|
|
63
60
|
const SASLMap = {
|
|
@@ -114,7 +111,7 @@ function createConsumer(client, group, topic, fromBeginning = false, poolOptions
|
|
|
114
111
|
groupId: group,
|
|
115
112
|
};
|
|
116
113
|
const consumerOptions = {
|
|
117
|
-
topic,
|
|
114
|
+
topics: [topic],
|
|
118
115
|
fromBeginning,
|
|
119
116
|
};
|
|
120
117
|
const consumer = client.consumer(consumerConfig);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kafka-console",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Kafka CLI tool",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"bin": {
|
|
@@ -33,19 +33,19 @@
|
|
|
33
33
|
"homepage": "https://github.com/3axap4eHko/kafka-console#readme",
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@types/commander": "^2.12.2",
|
|
36
|
-
"@types/jest": "^
|
|
36
|
+
"@types/jest": "^29.5.0",
|
|
37
37
|
"@types/js-yaml": "^4.0.5",
|
|
38
|
-
"@types/node": "^
|
|
38
|
+
"@types/node": "^18.15.3",
|
|
39
39
|
"@types/winston": "^2.4.4",
|
|
40
|
-
"dotenv": "^
|
|
41
|
-
"jest": "^
|
|
42
|
-
"ts-jest": "^
|
|
43
|
-
"ts-node": "^10.
|
|
44
|
-
"typescript": "^
|
|
40
|
+
"dotenv": "^16.0.3",
|
|
41
|
+
"jest": "^29.5.0",
|
|
42
|
+
"ts-jest": "^29.0.5",
|
|
43
|
+
"ts-node": "^10.9.1",
|
|
44
|
+
"typescript": "^5.0.2"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"commander": "^
|
|
48
|
-
"evnty": "^0.
|
|
49
|
-
"kafkajs": "^
|
|
47
|
+
"commander": "^10.0.0",
|
|
48
|
+
"evnty": "^0.9.0",
|
|
49
|
+
"kafkajs": "^2.2.4"
|
|
50
50
|
}
|
|
51
51
|
}
|