@@ -141,34 +141,36 @@ type KafkaClientEvents = 'disconnected' | 'ready' | 'connection.failure' | 'even
141
141
type KafkaConsumerEvents = 'data' | 'partition.eof' | 'rebalance' | 'rebalance.error' | 'subscribed' | 'unsubscribed' | 'unsubscribe' | 'offset.commit' | KafkaClientEvents ;
142
142
type KafkaProducerEvents = 'delivery-report' | KafkaClientEvents ;
143
143
144
- type EventListener < K > =
145
- // ### Client
146
- // connectivity events
147
- 'disconnected' extends K ? ( metrics : ClientMetrics ) => void :
148
- 'ready' extends K ? ( info : ReadyInfo , metadata : Metadata ) => void :
149
- 'connection.failure' extends K ? ( error : LibrdKafkaError , metrics : ClientMetrics ) => void :
150
- // event messages
151
- 'event.error' extends K ? ( error : LibrdKafkaError ) => void :
152
- 'event.stats' extends K ? ( eventData : any ) => void :
153
- 'event.log' extends K ? ( eventData : any ) => void :
154
- 'event.event' extends K ? ( eventData : any ) => void :
155
- 'event.throttle' extends K ? ( eventData : any ) => void :
156
- // ### Consumer only
157
- // domain events
158
- 'data' extends K ? ( arg : Message ) => void :
159
- 'partition.eof' extends K ? ( arg : EofEvent ) => void :
160
- 'rebalance' extends K ? ( err : LibrdKafkaError , assignments : TopicPartition [ ] ) => void :
161
- 'rebalance.error' extends K ? ( err : Error ) => void :
162
- // connectivity events
163
- 'subscribed' extends K ? ( topics : SubscribeTopicList ) => void :
164
- 'unsubscribe' extends K ? ( ) => void :
165
- 'unsubscribed' extends K ? ( ) => void :
166
- // offsets
167
- 'offset.commit' extends K ? ( error : LibrdKafkaError , topicPartitions : TopicPartitionOffset [ ] ) => void :
168
- // ### Producer only
169
- // delivery
170
- 'delivery-report' extends K ? ( error : LibrdKafkaError , report : DeliveryReport ) => void :
171
- never ;
144
+ type EventListenerMap = {
145
+ // ### Client
146
+ // connectivity events
147
+ 'disconnected' : ( metrics : ClientMetrics ) => void ,
148
+ 'ready' : ( info : ReadyInfo , metadata : Metadata ) => void ,
149
+ 'connection.failure' : ( error : LibrdKafkaError , metrics : ClientMetrics ) => void ,
150
+ // event messages
151
+ 'event.error' : ( error : LibrdKafkaError ) => void ,
152
+ 'event.stats' : ( eventData : any ) => void ,
153
+ 'event.log' : ( eventData : any ) => void ,
154
+ 'event.event' : ( eventData : any ) => void ,
155
+ 'event.throttle' : ( eventData : any ) => void ,
156
+ // ### Consumer only
157
+ // domain events
158
+ 'data' : ( arg : Message ) => void ,
159
+ 'partition.eof' : ( arg : EofEvent ) => void ,
160
+ 'rebalance' : ( err : LibrdKafkaError , assignments : TopicPartition [ ] ) => void ,
161
+ 'rebalance.error' : ( err : Error ) => void ,
162
+ // connectivity events
163
+ 'subscribed' : ( topics : SubscribeTopicList ) => void ,
164
+ 'unsubscribe' : ( ) => void ,
165
+ 'unsubscribed' : ( ) => void ,
166
+ // offsets
167
+ 'offset.commit' : ( error : LibrdKafkaError , topicPartitions : TopicPartitionOffset [ ] ) => void ,
168
+ // ### Producer only
169
+ // delivery
170
+ 'delivery-report' : ( error : LibrdKafkaError , report : DeliveryReport ) => void ,
171
+ }
172
+
173
+ type EventListener < K extends string > = K extends keyof EventListenerMap ? EventListenerMap [ K ] : never ;
172
174
173
175
export abstract class Client < Events extends string > extends EventEmitter {
174
176
constructor ( globalConf : GlobalConfig , SubClientType : any , topicConf : TopicConfig ) ;
0 commit comments