| 1 | import type { EventStream } from './enum/event-stream.enum' |
| 2 | import type { EventTopic } from './enum/event-topic.enum' |
| 3 | |
| 4 | export interface OnEventStreamOptions { |
| 5 | streams?: EventStream[] |
| 6 | group?: string |
| 7 | consumer?: string |
| 8 | maxRetries?: number |
| 9 | pollInterval?: number |
| 10 | } |
| 11 | |
| 12 | export interface EventStreamHandlerMetadata { |
| 13 | topics: EventTopic[] |
| 14 | options: OnEventStreamOptions |
| 15 | } |
| 16 | |
| 17 | export const ON_EVENT_STREAM_METADATA = Symbol('ON_EVENT_STREAM_METADATA') |
| 18 | |
| 19 | export function OnEventStream( |
| 20 | topic: EventTopic | EventTopic[], |
| 21 | options: OnEventStreamOptions = {}, |
| 22 | ): MethodDecorator { |
| 23 | return (_target, _propertyKey, descriptor) => { |
| 24 | Reflect.defineMetadata(ON_EVENT_STREAM_METADATA, { |
| 25 | topics: Array.isArray(topic) ? topic : [topic], |
| 26 | options, |
| 27 | } satisfies EventStreamHandlerMetadata, descriptor.value!) |
| 28 | } |
| 29 | } |
| 30 |