-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: allow to overwrite event id strategy
- Loading branch information
Showing
5 changed files
with
40 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { IEvent } from '../interfaces'; | ||
import { EVENT_METADATA } from '../decorators/constants'; | ||
import { Type } from '@nestjs/common'; | ||
import { EventIdProvider } from '../interfaces'; | ||
|
||
class DefaultEventIdProvider<EventBase extends IEvent = IEvent> | ||
implements EventIdProvider<EventBase> | ||
{ | ||
getEventId(event: EventBase): string | null { | ||
const { constructor } = Object.getPrototypeOf(event); | ||
|
||
return this.reflectEventId(constructor); | ||
} | ||
|
||
reflectEventId(event: Type<EventBase>): string | null { | ||
return Reflect.getMetadata(EVENT_METADATA, event)?.id ?? null; | ||
} | ||
} | ||
|
||
export const defaultEventIdProvider = new DefaultEventIdProvider(); |
This file was deleted.
Oops, something went wrong.
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,10 @@ | ||
import { IEvent } from './event.interface'; | ||
import { Type } from '@nestjs/common'; | ||
|
||
export interface EventIdProvider<EventBase extends IEvent = IEvent> { | ||
/** | ||
* Null if the published class is not connected to any handler | ||
*/ | ||
getEventId(event: EventBase): string | null; | ||
reflectEventId(event: Type<EventBase>): string | null; | ||
} |
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