chore(): Handle medusa service base methods events (#9179)
* chore(): Handle medusa service base methods events * cleanup * cleanup * fix import * fix decorator order * fixes * apply default event emition * fix binding * fix binding * align tests with new event emition
This commit is contained in:
@@ -15,6 +15,10 @@ export class MessageAggregator implements IMessageAggregator {
|
||||
this.messages = []
|
||||
}
|
||||
|
||||
count(): number {
|
||||
return this.messages.length
|
||||
}
|
||||
|
||||
save(msg: Message | Message[]): void {
|
||||
if (!msg || (Array.isArray(msg) && msg.length === 0)) {
|
||||
return
|
||||
|
||||
@@ -28,6 +28,25 @@ type ReturnType<TNames extends string[]> = {
|
||||
>}_DETACHED`]: `${KebabCase<K & string>}.detached`
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a conventional event name from the object name and the action and the prefix if provided
|
||||
* @param prefix
|
||||
* @param objectName
|
||||
* @param action
|
||||
*/
|
||||
export function buildModuleResourceEventName({
|
||||
prefix,
|
||||
objectName,
|
||||
action,
|
||||
}: {
|
||||
prefix?: string
|
||||
objectName: string
|
||||
action: string
|
||||
}): string {
|
||||
const kebabCaseName = lowerCaseFirst(kebabCase(objectName))
|
||||
return `${prefix ? `${prefix}.` : ""}${kebabCaseName}.${action}`
|
||||
}
|
||||
|
||||
/**
|
||||
* From the given strings it will produce the event names accordingly.
|
||||
* the result will look like:
|
||||
@@ -43,6 +62,7 @@ type ReturnType<TNames extends string[]> = {
|
||||
* }
|
||||
*
|
||||
* @param names
|
||||
* @param prefix
|
||||
*/
|
||||
export function buildEventNamesFromEntityName<TNames extends string[]>(
|
||||
names: TNames,
|
||||
@@ -53,13 +73,15 @@ export function buildEventNamesFromEntityName<TNames extends string[]>(
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i]
|
||||
const snakedCaseName = camelToSnakeCase(name).toUpperCase()
|
||||
const kebabCaseName = lowerCaseFirst(kebabCase(name))
|
||||
|
||||
for (const event of Object.values(CommonEvents) as string[]) {
|
||||
const upperCasedEvent = event.toUpperCase()
|
||||
events[`${snakedCaseName}_${upperCasedEvent}`] = `${
|
||||
prefix ? prefix + "." : ""
|
||||
}${kebabCaseName}.${event}` as `${KebabCase<typeof name>}.${typeof event}`
|
||||
events[`${snakedCaseName}_${upperCasedEvent}`] =
|
||||
buildModuleResourceEventName({
|
||||
prefix,
|
||||
objectName: name,
|
||||
action: event,
|
||||
}) as `${KebabCase<typeof name>}.${typeof event}`
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user