feat: event aggregator (#6218)
What: - Event Aggregator Util - Preparation for normalizing event in a new format (backward compatible with the current format) - GQL Schema to joiner config and some Entities configured - Link modules emmiting events
This commit is contained in:
@@ -69,7 +69,8 @@ export type LinkModuleBootstrapOptions = {
|
||||
}
|
||||
|
||||
export class MedusaModule {
|
||||
private static instances_: Map<string, any> = new Map()
|
||||
private static instances_: Map<string, { [key: string]: IModuleService }> =
|
||||
new Map()
|
||||
private static modules_: Map<string, ModuleAlias[]> = new Map()
|
||||
private static loading_: Map<string, Promise<any>> = new Map()
|
||||
private static joinerConfig_: Map<string, ModuleJoinerConfig> = new Map()
|
||||
@@ -87,12 +88,15 @@ export class MedusaModule {
|
||||
})
|
||||
}
|
||||
|
||||
public static onApplicationStart(): void {
|
||||
public static onApplicationStart(onApplicationStartCb?: () => void): void {
|
||||
for (const instances of MedusaModule.instances_.values()) {
|
||||
for (const instance of Object.values(instances) as IModuleService[]) {
|
||||
if (instance?.__hooks) {
|
||||
instance.__hooks?.onApplicationStart
|
||||
?.bind(instance)()
|
||||
.then(() => {
|
||||
onApplicationStartCb?.()
|
||||
})
|
||||
.catch(() => {
|
||||
// The module should handle this and log it
|
||||
return void 0
|
||||
@@ -217,7 +221,9 @@ export class MedusaModule {
|
||||
)
|
||||
|
||||
if (MedusaModule.instances_.has(hashKey)) {
|
||||
return MedusaModule.instances_.get(hashKey)
|
||||
return MedusaModule.instances_.get(hashKey)! as {
|
||||
[key: string]: T
|
||||
}
|
||||
}
|
||||
|
||||
if (MedusaModule.loading_.has(hashKey)) {
|
||||
@@ -249,7 +255,12 @@ export class MedusaModule {
|
||||
}
|
||||
}
|
||||
|
||||
const container = createMedusaContainer({}, sharedContainer)
|
||||
// TODO: Only do that while legacy modules sharing the manager exists then remove the ternary in favor of createMedusaContainer({}, globalContainer)
|
||||
const container =
|
||||
modDeclaration.scope === MODULE_SCOPE.INTERNAL &&
|
||||
modDeclaration.resources === MODULE_RESOURCE_TYPE.SHARED
|
||||
? sharedContainer ?? createMedusaContainer()
|
||||
: createMedusaContainer({}, sharedContainer)
|
||||
|
||||
if (injectedDependencies) {
|
||||
for (const service in injectedDependencies) {
|
||||
|
||||
Reference in New Issue
Block a user