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:
Carlos R. L. Rodrigues
2024-02-05 11:59:10 +00:00
committed by GitHub
parent 73fd92a1af
commit 884428a1b5
66 changed files with 1407 additions and 749 deletions
@@ -0,0 +1,30 @@
export function InjectIntoContext(
properties: Record<string, unknown | Function>
): MethodDecorator {
return function (
target: any,
propertyKey: string | symbol,
descriptor: any
): void {
if (!target.MedusaContextIndex_) {
throw new Error(
`To apply @InjectIntoContext you have to flag a parameter using @MedusaContext`
)
}
const argIndex = target.MedusaContextIndex_[propertyKey]
const original = descriptor.value
descriptor.value = async function (...args: any[]) {
for (const key of Object.keys(properties)) {
args[argIndex] = args[argIndex] ?? {}
args[argIndex][key] =
args[argIndex][key] ??
(typeof properties[key] === "function"
? (properties[key] as Function).apply(this, args)
: properties[key])
}
return await original.apply(this, args)
}
}
}