fix(types): expose cooperative-sticky rebalance methods on KafkaConsumer#485
Open
Dvir Arad (dvirarad) wants to merge 1 commit into
Open
fix(types): expose cooperative-sticky rebalance methods on KafkaConsumer#485Dvir Arad (dvirarad) wants to merge 1 commit into
Dvir Arad (dvirarad) wants to merge 1 commit into
Conversation
The KafkaConsumer runtime (lib/kafka-consumer.js) exposes incrementalAssign, incrementalUnassign, assignmentLost and rebalanceProtocol — all required to implement cooperative-sticky rebalancing — but none of these are declared in types/rdkafka.d.ts. TypeScript consumers must cast to any. This change adds the four missing method signatures with JSDoc matching the runtime documentation. No runtime/source changes; types only. Closes confluentinc#469
There was a problem hiding this comment.
Copilot wasn't able to review any files in this pull request.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #469.
When
partition.assignment.strategy=cooperative-stickyis set, the rebalance callback needs to callincrementalAssign/incrementalUnassigninstead ofassign/unassign. The runtime exposes them (seelib/kafka-consumer.js):The stock rebalance handler in
lib/kafka-consumer.js(lines 68-79) even branches onrebalanceProtocol() === 'COOPERATIVE'to callincrementalAssign/incrementalUnassign. But none of those four methods are declared intypes/rdkafka.d.ts, so TypeScript consumers writing their own rebalance callback must fall back to(consumer as any).incrementalAssign(...)(the screenshot in #469 shows exactly this).Fix
Types-only change in
types/rdkafka.d.ts. Added four method declarations onKafkaConsumer, each with a JSDoc block mirroring the runtime documentation inlib/kafka-consumer.js:Assignmentis the existing aliasTopicPartition | TopicPartitionOffset, matching theassign(...)signature — the runtime maps both intoTopicPartitionviaTopicPartition.map(...).rebalanceProtocol()return is constrained to the three literal strings the runtime can produce ("NONE" | "COOPERATIVE" | "EAGER"), so user code can doif (c.rebalanceProtocol() === "COOPERATIVE")without a string cast.assignmentLost()returnsbooleanper the JS doc (@return {boolean} true if assignment was lost.).The original issue only mentions
incrementalAssign/incrementalUnassign, butassignmentLostandrebalanceProtocolare part of the same cooperative-sticky workflow and have the same missing-types problem — happy to scope the PR back to just the two if maintainers prefer.Test plan
tsc -p .(the existingnpm run test:typesscript) still passes — added declarations only.lib/kafka-consumer.js(see lines 305–308, 319–322, 342–344, 351–353 onmaster).assignmentLostandrebalanceProtocolaren’t already declared anywhere else intypes/*.d.ts.