-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: update message header type to match #39
base: dev_early_access_development_branch
Are you sure you want to change the base?
fix: update message header type to match #39
Conversation
The existing MessageHeader type is just a plain object and not an array of plain objects.
6dd05b2
to
9cd609b
Compare
Thanks for the PR. Two things:
|
@milindl Partially correct. Yes to add support for nulls and numbers as well as cleaning up the typings.
@milindl Done.
I can confirm and I have replicated this rather unexpected behavior.
Thank you! If I may make a recommendation, since this project is pre-GA, I would make all the breaking changes necessary to align with what would be considered expected behavior. In my opinion, the conversion of a primitive, like a number to a string, would not be considered expected behavior.
I feel as if there is a larger discussion that needs to be had around how headers are implemented. I would honestly like to see headers passed as a plain object or map instead of an array of plain objects with a single property. I am recommending this because of both syntax and performance. The performance of implementations performing lookup operations on an array of headers have a time complexity of Preferably I would like to see; export type MessageHeaderValue = Buffer | string | number | null;
export type MessageHeader = Record<string, MessageHeaderValue>;
export type MessageHeaders = MessageHeader | null | undefined; |
Thanks for the PR update. I've been thinking about the conversion thing. The Kafka protocol expects header values to be []bytes. Breaking a number into bytes might pose a slight issue for endianness, and since type information isn't passed within the headers, the receiver will only ever get bytes and will need to write code outside of the library to change it back to a number. Maybe we should remove the number type entirely, and leave the encoding of number -> []byte to the user too. Since we can make API changes, we should probably make use of this opportunity for number. Ideally, only the Buffer type should be permitted as the header value, but I think it's very reasonable that a string can be turned into a utf8 []bytes by the library. As for making the header an object, the keys are allowed to be repeated by the Kafka protocol. The type used by the kafkajs.d.ts is probably a good compromise, allowing key->[value] in the object that is passed. |
As for the the number type, I think removing the
That would be a great compromise and the functionality to support both shouldn't be too complicated to implement. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would be a great compromise and the functionality to support both shouldn't be too complicated to implement.
Regarding this, I'll create a separate issue after we merge this in. I think this is pretty reasonable as we would not need to break any existing functionality and it's just more reasonable.
I've made changes to the development branch also which fix a bunch of issues with the header conversions and adds validation so only strings and buffers can be sent.
@@ -118,7 +118,7 @@ export interface ProducerConstructorConfig extends ProducerGlobalConfig { | |||
} | |||
|
|||
export interface IHeaders { | |||
[key: string]: Buffer | string | (Buffer | string)[] | undefined | |||
[key: string]: Buffer | string | number | null | (Buffer | string | number)[] | undefined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's remove the number type as we discussed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've made the change within the C++ side, so now an error is thrown for numeric header values
537aada
to
7bf9da6
Compare
Cleans up the existing message headers type.