Skip to content

Commit

Permalink
fix header func (#8)
Browse files Browse the repository at this point in the history
* fix header func

* fix test

* fix linting

* adjust code

* update version
  • Loading branch information
nick-zh committed Jul 13, 2023
1 parent 2e4788c commit 7f752d8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,4 @@ jobs:
- run: yarn workspaces focus --production
env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false
- run: yarn workspaces foreach --exclude kafka-lib npm publish --access public --tag beta
- run: yarn workspaces foreach --exclude kafka-lib npm publish --access public
10 changes: 5 additions & 5 deletions packages/kafka-avro-lib/__tests__/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ import { HeaderNames, MessageHeaders } from '../types';
import { getMessageHeaderValue } from '../utils';

describe('getHeaderValue', () => {
const emptyHeaders: MessageHeaders = {};
const exampleHeaders: MessageHeaders = {
Action: Buffer.from('create'),
foo: Buffer.from('bar'),
};
const emptyHeaders: MessageHeaders[] = [];
const exampleHeaders: MessageHeaders[] = [
{ Action: Buffer.from('create') },
{ foo: Buffer.from('bar') },
];

it('header is missing', () => {
expect(getMessageHeaderValue(emptyHeaders, 'bla')).toBe(null);
Expand Down
2 changes: 1 addition & 1 deletion packages/kafka-avro-lib/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@func-fun/kafka-avro-lib",
"version": "1.0.0-beta.1",
"version": "1.0.0",
"type": "module",
"repository": {
"type": "git",
Expand Down
8 changes: 4 additions & 4 deletions packages/kafka-avro-lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { HeaderNames, MessageHeaders } from './types';

export const getMessageHeaderValue = (headers: MessageHeaders, header: HeaderNames | string): string | null => {
for (const key in headers) {
const headerValue = headers[header as keyof MessageHeaders];
export const getMessageHeaderValue = (headers: MessageHeaders[], header: HeaderNames | string): string | null => {
for (const headerEntry of headers) {
const headerValue = headerEntry[header as keyof MessageHeaders];

if (header === key && undefined !== headerValue) {
if (undefined !== headerValue) {
return Buffer.from(headerValue).toString();
}
}
Expand Down

0 comments on commit 7f752d8

Please sign in to comment.