feat(index): Index module foundation (#9095)
**What** Index module foundation Co-authored-by: Carlos R. L. Rodrigues <37986729+carlos-r-l-rodrigues@users.noreply.github.com>
This commit is contained in:
co-authored by
Carlos R. L. Rodrigues
parent
3cfcd075ae
commit
58167b5dfa
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
EventBusTypes,
|
||||
IEventBusModuleService,
|
||||
Message,
|
||||
Subscriber,
|
||||
} from "@medusajs/types"
|
||||
|
||||
export class EventBusServiceMock implements IEventBusModuleService {
|
||||
protected readonly subscribers_: Map<string | symbol, Set<Subscriber>> =
|
||||
new Map()
|
||||
|
||||
async emit<T>(
|
||||
messages: Message<T> | Message<T>[],
|
||||
options?: Record<string, unknown>
|
||||
): Promise<void> {
|
||||
const messages_ = Array.isArray(messages) ? messages : [messages]
|
||||
|
||||
for (const message of messages_) {
|
||||
const subscribers = this.subscribers_.get(message.name)
|
||||
|
||||
for (const subscriber of subscribers ?? []) {
|
||||
const { options, ...payload } = message
|
||||
await subscriber(payload)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
subscribe(event: string | symbol, subscriber: Subscriber): this {
|
||||
this.subscribers_.set(event, new Set([subscriber]))
|
||||
return this
|
||||
}
|
||||
|
||||
unsubscribe(
|
||||
event: string | symbol,
|
||||
subscriber: Subscriber,
|
||||
context?: EventBusTypes.SubscriberContext
|
||||
): this {
|
||||
return this
|
||||
}
|
||||
|
||||
releaseGroupedEvents(eventGroupId: string): Promise<void> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
clearGroupedEvents(eventGroupId: string): Promise<void> {
|
||||
throw new Error("Method not implemented.")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user