Skip to content

Commit 2471567

Browse files
authored
Re-setup docs generation from code (#202)
* Update packages, configurations etc for documentation gen * Update documentation for jsdoc * Add docs generation to semaphore pipeline * Fix merge conflict related doc change
1 parent c8b4c17 commit 2471567

26 files changed

+968
-472
lines changed

.npmignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ deps/librdkafka/config.h
1616
/e2e
1717
/bench
1818
/ci
19-
/proto
19+
/proto
20+
/docs

.semaphore/semaphore.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ blocks:
8787
- npm run install-from-source
8888
- make test
8989

90-
- name: "Linux amd64: Build, test, lint"
90+
- name: "Linux amd64: Build, test, lint, docs"
9191
dependencies: [ ]
9292
task:
9393
agent:
@@ -110,6 +110,9 @@ blocks:
110110
- name: "ESLint"
111111
commands:
112112
- npx eslint lib/kafkajs
113+
- name: "Docs"
114+
commands:
115+
- make docs
113116

114117
- name: "Linux amd64: Performance"
115118
dependencies: [ ]

Makefile

+1-8
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,7 @@ define release
7474
endef
7575

7676
docs: node_modules/.dirstamp
77-
@rm -rf docs
78-
@./node_modules/jsdoc/jsdoc.js --debug --destination docs \
79-
--recurse -R ./README.md \
80-
-c ./jsdoc.conf \
81-
--tutorials examples/ ./lib
82-
83-
gh-pages: node_modules/.dirstamp
84-
@./make_docs.sh
77+
@./util/generate-docs.sh
8578

8679
release-patch:
8780
@$(call release,patch)

jsdoc.conf

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
11
{
2-
"plugins": [],
2+
"plugins": [
3+
"plugins/markdown"
4+
],
35
"recurseDepth": 10,
46
"source": {
5-
"includePattern": ".+\\.js(doc|x)?$"
7+
"include": ["lib"],
8+
"exclude": ["lib/kafkajs/_common.js"],
9+
"includePattern": ".+\\.js?$",
10+
"excludePattern": ""
611
},
712
"sourceType": "module",
813
"tags": {
914
"allowUnknownTags": true,
1015
"dictionaries": ["jsdoc","closure"]
1116
},
1217
"templates": {
13-
"cleverLinks": false,
14-
"monospaceLinks": false
18+
"default": {
19+
"useLongnameInNav": true,
20+
"outputSourceFiles": false
21+
}
1522
}
1623
}

lib/admin.js

+92-64
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,29 @@
1313
* hardcoded list.
1414
* New additions won't be automatically added to this list.
1515
*/
16-
const ConsumerGroupStates = Object.seal({
16+
17+
/**
18+
* A list of consumer group states.
19+
* @enum {number}
20+
* @readonly
21+
* @memberof RdKafka
22+
*/
23+
const ConsumerGroupStates = {
1724
UNKNOWN: 0,
1825
PREPARING_REBALANCE: 1,
1926
COMPLETING_REBALANCE: 2,
2027
STABLE: 3,
2128
DEAD: 4,
2229
EMPTY: 5,
23-
});
30+
};
2431

25-
const AclOperationTypes = Object.seal({
32+
/**
33+
* A list of ACL operation types.
34+
* @enum {number}
35+
* @readonly
36+
* @memberof RdKafka
37+
*/
38+
const AclOperationTypes = {
2639
UNKNOWN: 0,
2740
ANY: 1,
2841
ALL: 2,
@@ -36,7 +49,7 @@ const AclOperationTypes = Object.seal({
3649
DESCRIBE_CONFIGS: 10,
3750
ALTER_CONFIGS: 11,
3851
IDEMPOTENT_WRITE: 12,
39-
});
52+
};
4053

4154
/**
4255
* A list of isolation levels.
@@ -80,8 +93,8 @@ OffsetSpec.LATEST = new OffsetSpec(-1);
8093
module.exports = {
8194
create: createAdminClient,
8295
createFrom: createAdminClientFrom,
83-
ConsumerGroupStates,
84-
AclOperationTypes,
96+
ConsumerGroupStates: Object.freeze(ConsumerGroupStates),
97+
AclOperationTypes: Object.freeze(AclOperationTypes),
8598
IsolationLevel: Object.freeze(IsolationLevel),
8699
OffsetSpec,
87100
};
@@ -95,14 +108,15 @@ var { shallowCopy } = require('./util');
95108
util.inherits(AdminClient, Client);
96109

97110
/**
98-
* Create a new AdminClient for making topics, partitions, and more.
111+
* Create a new AdminClient using the provided configuration.
99112
*
100113
* This is a factory method because it immediately starts an
101114
* active handle with the brokers.
102115
*
103-
* @param {object} conf - Key value pairs to configure the admin client
104-
* @param {object} eventHandlers - optional key value pairs of event handlers to attach to the client
105-
*
116+
* @param {object} conf - Key value pairs to configure the admin client.
117+
* @param {object?} eventHandlers - Optional key value pairs of event handlers to attach to the client.
118+
* @memberof RdKafka
119+
* @alias RdKafka.AdminClient.create
106120
*/
107121
function createAdminClient(conf, eventHandlers) {
108122
var client = new AdminClient(conf);
@@ -126,11 +140,14 @@ function createAdminClient(conf, eventHandlers) {
126140
* This is a factory method because it immediately starts an
127141
* active handle with the brokers.
128142
*
129-
* The producer or consumer being used must be connected.
130-
* The client can only be used while the producer or consumer is connected.
143+
* The producer or consumer being used must be connected before creating the admin client,
144+
* and the admin client can only be used while the producer or consumer is connected.
145+
*
131146
* Logging and other events from this client will be emitted on the producer or consumer.
132-
* @param {import('../types/rdkafka').Producer | import('../types/rdkafka').KafkaConsumer} existingClient a producer or consumer to create the admin client from
133-
* @param {object} eventHandlers optional key value pairs of event handlers to attach to the client
147+
* @param {RdKafka.Producer | RdKafka.KafkaConsumer} existingClient - A producer or consumer to create the admin client from.
148+
* @param {object?} eventHandlers - Optional key value pairs of event handlers to attach to the client.
149+
* @memberof RdKafka
150+
* @alias RdKafka.AdminClient.createFrom
134151
*/
135152
function createAdminClientFrom(existingClient, eventHandlers) {
136153
var client = new AdminClient(null, existingClient);
@@ -148,25 +165,25 @@ function createAdminClientFrom(existingClient, eventHandlers) {
148165
}
149166

150167
/**
151-
* AdminClient class for administering Kafka
168+
* AdminClient class for administering Kafka clusters (promise-based, async API).
152169
*
153170
* This client is the way you can interface with the Kafka Admin APIs.
154171
* This class should not be made using the constructor, but instead
155-
* should be made using the factory method.
156-
*
157-
* <code>
158-
* var client = AdminClient.create({ ... }); // From configuration
159-
* var client = AdminClient.createFrom(existingClient); // From existing producer or consumer
160-
* </code>
172+
* should be made using the factory methods (see {@link RdKafka.AdminClient.create}
173+
* and {@link RdKafka.AdminClient.createFrom}).
161174
*
162175
* Once you instantiate this object, it will have a handle to the kafka broker.
163176
* Unlike the other confluent-kafka-javascript classes, this class does not ensure that
164177
* it is connected to the upstream broker. Instead, making an action will
165178
* validate that.
166179
*
167-
* @param {object} conf - Key value pairs to configure the admin client
168-
* topic configuration
169-
* @param {import('../types/rdkafka').Producer | import('../types/rdkafka').KafkaConsumer | null} existingClient
180+
* @example
181+
* var client = AdminClient.create({ ... }); // From configuration
182+
* var client = AdminClient.createFrom(existingClient); // From existing producer or consumer
183+
*
184+
* @param {object|null} conf - Key value pairs to configure the admin client
185+
* @param {RdKafka.Producer | RdKafka.KafkaConsumer | null} existingClient - An existing producer or consumer to create the admin client from (optional).
186+
* @memberof RdKafka
170187
* @constructor
171188
*/
172189
function AdminClient(conf, existingClient) {
@@ -197,6 +214,7 @@ function AdminClient(conf, existingClient) {
197214
* need to be called outside.
198215
*
199216
* Unlike the other connect methods, this one is synchronous.
217+
* @private
200218
*/
201219
AdminClient.prototype.connect = function () {
202220
if (!this._hasUnderlyingClient) {
@@ -213,7 +231,7 @@ AdminClient.prototype.connect = function () {
213231
* Disconnect the admin client.
214232
*
215233
* This is a synchronous method, but all it does is clean up
216-
* some memory and shut some threads down
234+
* some memory and shut some threads down.
217235
*/
218236
AdminClient.prototype.disconnect = function () {
219237
if (this._hasUnderlyingClient) {
@@ -231,9 +249,13 @@ AdminClient.prototype.disconnect = function () {
231249
/**
232250
* Create a topic with a given config.
233251
*
234-
* @param {NewTopic} topic - Topic to create.
235-
* @param {number} timeout - Number of milliseconds to wait while trying to create the topic.
236-
* @param {function} cb - The callback to be executed when finished
252+
* @param {object} topic - Topic to create.
253+
* @param {string} topic.topic - The name of the topic to create.
254+
* @param {number} topic.num_partitions - The number of partitions for the topic.
255+
* @param {number} topic.replication_factor - The replication factor for the topic.
256+
* @param {object?} topic.config - The topic configuration. The keys of this object denote the keys of the configuration.
257+
* @param {number?} timeout - Number of milliseconds to wait while trying to create the topic. Set to 5000 by default.
258+
* @param {function} cb - The callback to be executed when finished.
237259
*/
238260
AdminClient.prototype.createTopic = function (topic, timeout, cb) {
239261
if (!this._isConnected) {
@@ -267,8 +289,8 @@ AdminClient.prototype.createTopic = function (topic, timeout, cb) {
267289
* Delete a topic.
268290
*
269291
* @param {string} topic - The topic to delete, by name.
270-
* @param {number} timeout - Number of milliseconds to wait while trying to delete the topic.
271-
* @param {function} cb - The callback to be executed when finished
292+
* @param {number?} timeout - Number of milliseconds to wait while trying to delete the topic. Set to 5000 by default.
293+
* @param {function} cb - The callback to be executed when finished.
272294
*/
273295
AdminClient.prototype.deleteTopic = function (topic, timeout, cb) {
274296
if (!this._isConnected) {
@@ -303,9 +325,9 @@ AdminClient.prototype.deleteTopic = function (topic, timeout, cb) {
303325
*
304326
* @param {string} topic - The topic to add partitions to, by name.
305327
* @param {number} totalPartitions - The total number of partitions the topic should have
306-
* after the request
307-
* @param {number} timeout - Number of milliseconds to wait while trying to create the partitions.
308-
* @param {function} cb - The callback to be executed when finished
328+
* after the request.
329+
* @param {number?} timeout - Number of milliseconds to wait while trying to create the partitions. Set to 5000 by default.
330+
* @param {function} cb - The callback to be executed when finished.
309331
*/
310332
AdminClient.prototype.createPartitions = function (topic, totalPartitions, timeout, cb) {
311333
if (!this._isConnected) {
@@ -337,16 +359,17 @@ AdminClient.prototype.createPartitions = function (topic, totalPartitions, timeo
337359

338360
/**
339361
* List consumer groups.
362+
*
340363
* @param {any} options
341364
* @param {number?} options.timeout - The request timeout in milliseconds.
342-
* May be unset (default: 5000)
343-
* @param {import("../").ConsumerGroupStates[]?} options.matchConsumerGroupStates -
365+
* May be unset (default: 5000).
366+
* @param {Array<RdKafka.ConsumerGroupStates>?} options.matchConsumerGroupStates -
344367
* A list of consumer group states to match. May be unset, fetches all states (default: unset).
345368
* @param {function} cb - The callback to be executed when finished.
346-
*
347-
* Valid ways to call this function:
348-
* listGroups(cb)
349-
* listGroups(options, cb)
369+
* @example
370+
* // Valid ways to call this function:
371+
* listGroups(cb);
372+
* listGroups(options, cb);
350373
*/
351374
AdminClient.prototype.listGroups = function (options, cb) {
352375
if (!this._isConnected) {
@@ -378,14 +401,15 @@ AdminClient.prototype.listGroups = function (options, cb) {
378401

379402
/**
380403
* Describe consumer groups.
381-
* @param {string[]} groups - The names of the groups to describe.
382-
* @param {any?} options
404+
* @param {Array<string>} groups - The names of the groups to describe.
405+
* @param {object} options
383406
* @param {number?} options.timeout - The request timeout in milliseconds.
384-
* May be unset (default: 5000)
407+
* May be unset (default: 5000).
385408
* @param {boolean?} options.includeAuthorizedOperations - If true, include operations allowed on the group by the calling client (default: false).
386409
* @param {function} cb - The callback to be executed when finished.
387410
*
388-
* Valid ways to call this function:
411+
* @example
412+
* // Valid ways to call this function:
389413
* describeGroups(groups, cb)
390414
* describeGroups(groups, options, cb)
391415
*/
@@ -420,12 +444,13 @@ AdminClient.prototype.describeGroups = function (groups, options, cb) {
420444
/**
421445
* Delete consumer groups.
422446
* @param {string[]} groups - The names of the groups to delete.
423-
* @param {any?} options
447+
* @param {object} options
424448
* @param {number?} options.timeout - The request timeout in milliseconds.
425-
* May be unset (default: 5000)
449+
* May be unset (default: 5000).
426450
* @param {function} cb - The callback to be executed when finished.
427451
*
428-
* Valid ways to call this function:
452+
* @example
453+
* // Valid ways to call this function:
429454
* deleteGroups(groups, cb)
430455
* deleteGroups(groups, options, cb)
431456
*/
@@ -460,12 +485,13 @@ AdminClient.prototype.deleteGroups = function (groups, options, cb) {
460485
/**
461486
* List topics.
462487
*
463-
* @param {any?} options
488+
* @param {object} options
464489
* @param {number?} options.timeout - The request timeout in milliseconds.
465-
* May be unset (default: 5000)
490+
* May be unset (default: 5000).
466491
* @param {function} cb - The callback to be executed when finished.
467492
*
468-
* Valid ways to call this function:
493+
* @example
494+
* // Valid ways to call this function:
469495
* listTopics(cb)
470496
* listTopics(options, cb)
471497
*/
@@ -516,13 +542,14 @@ AdminClient.prototype.listTopics = function (options, cb) {
516542
/**
517543
* List offsets for topic partition(s) for consumer group(s).
518544
*
519-
* @param {import("../../types/rdkafka").ListGroupOffsets} listGroupOffsets - The list of groupId, partitions to fetch offsets for.
520-
* If partitions is null, list offsets for all partitions
521-
* in the group.
545+
* @param {{groupId: string, partitions: Array<number>|null}} listGroupOffsets
546+
* The list of groupId, partitions to fetch offsets for. If partitions is null, list offsets for all partitions
547+
* in the group.
548+
* @param {object} options
522549
* @param {number?} options.timeout - The request timeout in milliseconds.
523-
* May be unset (default: 5000)
550+
* May be unset (default: 5000).
524551
* @param {boolean?} options.requireStableOffsets - Whether broker should return stable offsets
525-
* (transaction-committed). (default: false)
552+
* (transaction-committed). (default: false).
526553
*
527554
* @param {function} cb - The callback to be executed when finished.
528555
*/
@@ -564,15 +591,15 @@ AdminClient.prototype.listConsumerGroupOffsets = function (listGroupOffsets, opt
564591

565592
/**
566593
* Deletes records (messages) in topic partitions older than the offsets provided.
567-
* Provide Topic.OFFSET_END or -1 as offset to delete all records.
594+
* Provide Topic.OFFSET_END or -1 as the offset to delete all records.
568595
*
569-
* @param {import("../../types/rdkafka").TopicPartitionOffset[]} delRecords - The list of topic partitions and
570-
* offsets to delete records up to.
596+
* @param {Array<{topic: string, partition: number, offset: number}>} delRecords
597+
* The list of topic partitions and offsets to delete records up to.
598+
* @param {object} options
571599
* @param {number?} options.operationTimeout - The operation timeout in milliseconds.
572-
* May be unset (default: 60000)
600+
* May be unset (default: 60000).
573601
* @param {number?} options.timeout - The request timeout in milliseconds.
574-
* May be unset (default: 5000)
575-
*
602+
* May be unset (default: 5000).
576603
* @param {function} cb - The callback to be executed when finished.
577604
*/
578605
AdminClient.prototype.deleteRecords = function (delRecords, options, cb) {
@@ -611,13 +638,14 @@ AdminClient.prototype.deleteRecords = function (delRecords, options, cb) {
611638
};
612639

613640
/**
614-
* Describe Topics.
641+
* Describe topics.
615642
*
616-
* @param {string[]} topics - The names of the topics to describe.
643+
* @param {Array<string>} topics - The names of the topics to describe.
644+
* @param {object} options
617645
* @param {number?} options.timeout - The request timeout in milliseconds.
618-
* May be unset (default: 5000)
646+
* May be unset (default: 5000).
619647
* @param {boolean?} options.includeAuthorizedOperations - If true, include operations allowed on the topic by the calling client.
620-
* (default: false)
648+
* (default: false).
621649
* @param {function} cb - The callback to be executed when finished.
622650
*/
623651
AdminClient.prototype.describeTopics = function (topics, options, cb) {

0 commit comments

Comments
 (0)