-
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.
feat: add createPartition & deletePartition command
- Loading branch information
Showing
6 changed files
with
83 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 1,14 @@ | ||
|
||
import type { CommandResponse } from '../../tcp.client.js'; | ||
import type { Id } from '../identifier.utils.js'; | ||
import { serializePartitionParams } from './partition.utils.js'; | ||
|
||
export const CREATE_PARTITION = { | ||
code: 402, | ||
serialize: (streamId: Id, topicId: Id, partitionCount = 1) => { | ||
return serializePartitionParams(streamId, topicId, partitionCount); | ||
}, | ||
deserialize: (r: CommandResponse) => { | ||
return r.status === 0 && r.data.length === 0; | ||
} | ||
}; |
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,19 @@ | ||
|
||
import type { CommandResponse } from '../../tcp.client.js'; | ||
import type { Id } from '../identifier.utils.js'; | ||
import { serializePartitionParams } from './partition.utils.js'; | ||
|
||
|
||
export const DELETE_PARTITION = { | ||
code: 403, | ||
serialize: ( | ||
streamId: Id, | ||
topicId: Id, | ||
partitionCount: number, | ||
) => { | ||
return serializePartitionParams(streamId, topicId, partitionCount); | ||
}, | ||
deserialize: (r: CommandResponse) => { | ||
return r.status === 0 && r.data.length === 0; | ||
} | ||
}; |
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,21 @@ | ||
|
||
import { serializeIdentifier, type Id } from '../identifier.utils.js'; | ||
|
||
export const serializePartitionParams = ( | ||
streamId: Id, topicId: Id, partitionCount = 1, | ||
) => { | ||
|
||
if (partitionCount < 1 || partitionCount > 1000) | ||
throw new Error('Topic partition_count should be between 1 and 1000'); | ||
|
||
const streamIdentifier = serializeIdentifier(streamId); | ||
const topicIdentifier = serializeIdentifier(topicId); | ||
const b = Buffer.alloc(4); | ||
b.writeUInt32LE(partitionCount, 0); | ||
|
||
return Buffer.concat([ | ||
streamIdentifier, | ||
topicIdentifier, | ||
b, | ||
]) | ||
}; |