chore: Ensure the events are emitted with the same shape all accross (#8063)

* chore: Ensure the events are emitted with the same shape all accross

* fixes:

* rm unsues type

* types

* fix tests
This commit is contained in:
Adrien de Peretti
2024-07-10 19:34:28 +02:00
committed by GitHub
parent 95f29358d1
commit e778870c68
9 changed files with 42 additions and 30 deletions
@@ -1,9 +1,10 @@
import {
IEventBusModuleService,
MedusaContainer,
MessageBody,
Subscriber,
} from "@medusajs/types"
import { ModuleRegistrationName, kebabCase } from "@medusajs/utils"
import { kebabCase, ModuleRegistrationName } from "@medusajs/utils"
import { readdir } from "fs/promises"
import { extname, join, sep } from "path"
@@ -131,7 +132,7 @@ export class SubscriberLoader {
const fullPath = join(dirPath, entry.name)
if (entry.isDirectory()) {
return this.createMap(fullPath)
return await this.createMap(fullPath)
}
return await this.createDescriptor(fullPath, entry.name)
@@ -172,7 +173,7 @@ export class SubscriberLoader {
return kebabCase(idFromFile)
}
private createSubscriber<T>({
private createSubscriber<T = unknown>({
fileName,
config,
handler,
@@ -192,8 +193,8 @@ export class SubscriberLoader {
const subscriberId = this.inferIdentifier(fileName, config, handler)
for (const e of events) {
const subscriber = async (data: T) => {
return handler({
const subscriber = async (data: MessageBody<T>) => {
return await handler({
eventName: e,
data,
container: this.container_,
+1 -1
View File
@@ -10,7 +10,7 @@ export type SubscriberConfig = {
}
export type SubscriberArgs<T = unknown> = {
data: T | MessageBody<T>
data: MessageBody<T>
eventName: string
container: MedusaContainer
pluginOptions: Record<string, unknown>