Skip to content

Commit

Permalink
Fix add types for Admin and fix some error type
Browse files Browse the repository at this point in the history
  • Loading branch information
xieweicheng committed Dec 30, 2020
1 parent fcc8aef commit 493eb54
Showing 1 changed file with 38 additions and 7 deletions.
45 changes: 38 additions & 7 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export class ConsumerGroupStream extends Readable {
close (cb: () => any): void;
}

export class ConsumerGroup {
export class ConsumerGroup extends EventEmitter{
generationId: number;
memberId: string;
client: KafkaClient;
Expand All @@ -92,9 +92,9 @@ export class ConsumerGroup {
close (force: boolean, cb: (error: Error) => any): void;
close (cb: (error: Error) => any): void;

on (eventName: 'message', cb: (message: Message) => any): void;
on (eventName: 'error' | 'offsetOutOfRange', cb: (error: any) => any): void;
on (eventName: 'rebalancing' | 'rebalanced' | 'connect', cb: () => any): void;
on (eventName: 'message', cb: (message: Message) => any): this;
on (eventName: 'error' | 'offsetOutOfRange', cb: (error: any) => any): this;
on (eventName: 'rebalancing' | 'rebalanced' | 'connect', cb: () => any): this;

addTopics (topics: string[] | Topic[], cb?: (error: any, added: string[] | Topic[]) => any): void;

Expand All @@ -112,11 +112,11 @@ export class ConsumerGroup {
resume (): void;
}

export class Offset {
export class Offset extends EventEmitter{
constructor (client: KafkaClient);

on (eventName: 'ready' | 'connect', cb: () => any): void;
on (eventName: 'error', cb: (error: any) => any): void;
on (eventName: 'ready' | 'connect', cb: () => any): this;
on (eventName: 'error', cb: (error: any) => any): this;

fetch (payloads: OffsetRequest[], cb: (error: any, data: any) => any): void;

Expand Down Expand Up @@ -145,6 +145,23 @@ export class ProducerStream extends Writable {
_writev (chunks: Chunk[], cb: (error: any, data: any) => any): void;
}

export class Admin extends EventEmitter {
constructor(kafkaClient: KafkaClient);

on (eventName: 'ready' | 'connect', cb: () => any): this;
on (eventName: 'error', cb: () => any): this;

listGroups (cb: (error: any, res: any) => any): void;

listTopics (cb: (error: any, res: any) => any): void;

describeGroups (consumerGroups: Array<string>, cb: (error: any, res: any) => any): void;

createTopics (topics: Array<CreateTopicRequest>, cb: (error: any, res: any) => any): void;

describeConfigs (payload: DescribeConfigsRequest, cb: (error: any, res: any) => any): void;
}

// # Interfaces

export interface Message {
Expand Down Expand Up @@ -348,3 +365,17 @@ export interface MetadataResponse extends Array<BrokerMetadataResponse|ClusterMe
0: BrokerMetadataResponse;
1: ClusterMetadataResponse;
}

export enum RESOURCE_TYPES {
topic = 'topic',
broker = 'broker'
}

export interface DescribeConfigsRequest {
resources: Array<{
resourceType: RESOURCE_TYPES,
resourceName: string,
configNames: Array<string>
}>,
includeSynonyms?: boolean
}

0 comments on commit 493eb54

Please sign in to comment.