forked from tulios/kafkajs
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves: tulios#1549
- Loading branch information
Showing
11 changed files
with
204 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
const versions = { | ||
0: ({ groupId, topics }) => { | ||
const request = require('./v0/request') | ||
const response = require('./v0/response') | ||
return { request: request({ groupId, topics }), response } | ||
}, | ||
} | ||
|
||
module.exports = { | ||
versions: Object.keys(versions), | ||
protocol: ({ version }) => versions[version], | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
const Encoder = require('../../../encoder') | ||
const { OffsetDelete: apiKey } = require('../../apiKeys') | ||
|
||
/** | ||
* OffsetDelete Request (Version: 0) => group_id [topics] | ||
* group_id => STRING | ||
* topics => name [partitions] | ||
* name => STRING | ||
* partitions => partition_index | ||
* partition_index => INT32 | ||
*/ | ||
module.exports = ({ groupId, topics }) => ({ | ||
apiKey, | ||
apiVersion: 0, | ||
apiName: 'OffsetDelete', | ||
encode: async () => { | ||
return new Encoder() | ||
.writeString(groupId) | ||
.writeArray(topics === null ? topics : topics.map(encodeTopics)) | ||
}, | ||
}) | ||
|
||
const encodeTopics = ({ topic, partitions }) => { | ||
return new Encoder().writeString(topic).writeArray(partitions.map(encodePartitions)) | ||
} | ||
|
||
const encodePartitions = partition => { | ||
return new Encoder().writeInt32(partition) | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('Protocol > Requests > OffsetDelete > v0', () => { | ||
test('request', () => { | ||
throw new Error('TODO') | ||
}) | ||
}) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
const { KafkaJSAggregateError, KafkaJSOffsetDeleteError } = require('../../../../errors') | ||
const Decoder = require('../../../decoder') | ||
const { failure, createErrorFromCode } = require('../../../error') | ||
|
||
/** | ||
* OffsetDelete Response (Version: 0) => error_code throttle_time_ms [topics] | ||
* error_code => INT16 | ||
* throttle_time_ms => INT32 | ||
* topics => name [partitions] | ||
* name => STRING | ||
* partitions => partition_index error_code | ||
* partition_index => INT32 | ||
* error_code => INT16 | ||
*/ | ||
|
||
/** | ||
* @param {Decoder} decoder | ||
*/ | ||
const decodePartition = decoder => { | ||
const partition = { | ||
partition: decoder.readInt32(), | ||
errorCode: decoder.readInt16(), | ||
} | ||
|
||
return partition | ||
} | ||
|
||
/** | ||
* @param {Decoder} decoder | ||
*/ | ||
const decodeTopics = decoder => { | ||
const topic = { | ||
topic: decoder.readString(), | ||
partitions: decoder.readArray(decodePartition), | ||
} | ||
|
||
return topic | ||
} | ||
|
||
const decode = async rawData => { | ||
const decoder = new Decoder(rawData) | ||
|
||
const errorCode = decoder.readInt16() | ||
const throttleTime = decoder.readInt32() | ||
return { | ||
errorCode, | ||
throttleTime, | ||
topics: decoder.readArray(decodeTopics), | ||
} | ||
} | ||
|
||
const parse = async data => { | ||
if (failure(data.errorCode)) { | ||
throw createErrorFromCode(data.errorCode) | ||
} | ||
|
||
const topicPartitionsWithError = data.topics.flatMap(({ topic, partitions }) => | ||
partitions | ||
.filter(partition => failure(partition.errorCode)) | ||
.map(partition => ({ | ||
...partition, | ||
topic, | ||
})) | ||
) | ||
|
||
if (topicPartitionsWithError.length > 0) { | ||
throw new KafkaJSAggregateError( | ||
'Errors deleting offsets', | ||
topicPartitionsWithError.map( | ||
({ topic, partition, errorCode }) => | ||
new KafkaJSOffsetDeleteError(createErrorFromCode(errorCode), topic, partition) | ||
) | ||
) | ||
} | ||
|
||
return data | ||
} | ||
|
||
module.exports = { | ||
decode, | ||
parse, | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
describe('Protocol > Requests > OffsetDelete > v0', () => { | ||
test('response', () => { | ||
throw new Error('TODO') | ||
}) | ||
}) |
This file contains 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