committed by
GitHub
parent
ae33f4825f
commit
f12299deb1
@@ -1,10 +1,9 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
JoinerServiceConfig,
|
||||
LoadedModule,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
ModuleDefinition,
|
||||
ModuleExports,
|
||||
ModuleResolution,
|
||||
} from "@medusajs/types"
|
||||
@@ -27,7 +26,10 @@ const logger: any = {
|
||||
|
||||
declare global {
|
||||
interface MedusaModule {
|
||||
getLoadedModules(): Map<string, any>
|
||||
getLoadedModules(
|
||||
aliases?: Map<string, string>
|
||||
): { [key: string]: LoadedModule }[]
|
||||
getModuleInstance(moduleKey: string, alias?: string): LoadedModule
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,14 +45,16 @@ export class MedusaModule {
|
||||
private static modules_: Map<string, ModuleAlias[]> = new Map()
|
||||
private static loading_: Map<string, Promise<any>> = new Map()
|
||||
|
||||
public static getLoadedModules(): Map<
|
||||
string,
|
||||
any & {
|
||||
__joinerConfig: JoinerServiceConfig
|
||||
__definition: ModuleDefinition
|
||||
}
|
||||
> {
|
||||
return MedusaModule.instances_
|
||||
public static getLoadedModules(
|
||||
aliases?: Map<string, string>
|
||||
): { [key: string]: LoadedModule }[] {
|
||||
return [...MedusaModule.modules_.entries()].map(([key]) => {
|
||||
if (aliases?.has(key)) {
|
||||
return MedusaModule.getModuleInstance(key, aliases.get(key))
|
||||
}
|
||||
|
||||
return MedusaModule.getModuleInstance(key)
|
||||
})
|
||||
}
|
||||
|
||||
public static clearInstances(): void {
|
||||
@@ -267,3 +271,6 @@ export class MedusaModule {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
global.MedusaModule ??= MedusaModule
|
||||
exports.MedusaModule = global.MedusaModule
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import {
|
||||
JoinerRelationship,
|
||||
JoinerServiceConfig,
|
||||
ModuleDefinition,
|
||||
LoadedModule,
|
||||
RemoteExpandProperty,
|
||||
} from "@medusajs/types"
|
||||
|
||||
@@ -11,13 +11,10 @@ import { toPascalCase } from "@medusajs/utils"
|
||||
|
||||
export class RemoteQuery {
|
||||
private remoteJoiner: RemoteJoiner
|
||||
private modulesMap: Map<string, any> = new Map()
|
||||
private modulesMap: Map<string, LoadedModule> = new Map()
|
||||
|
||||
constructor(
|
||||
modulesLoaded?: (any & {
|
||||
__joinerConfig: JoinerServiceConfig
|
||||
__definition: ModuleDefinition
|
||||
})[],
|
||||
modulesLoaded?: LoadedModule[],
|
||||
remoteFetchData?: (
|
||||
expand: RemoteExpandProperty,
|
||||
keyField: string,
|
||||
@@ -29,8 +26,8 @@ export class RemoteQuery {
|
||||
}>
|
||||
) {
|
||||
if (!modulesLoaded?.length) {
|
||||
modulesLoaded = [...MedusaModule.getLoadedModules().entries()].map(
|
||||
([, mod]) => mod
|
||||
modulesLoaded = MedusaModule.getLoadedModules().map(
|
||||
(mod) => Object.values(mod)[0]
|
||||
)
|
||||
}
|
||||
|
||||
@@ -130,7 +127,7 @@ export class RemoteQuery {
|
||||
path?: string
|
||||
}> {
|
||||
const serviceConfig = expand.serviceConfig
|
||||
const service = this.modulesMap.get(serviceConfig.serviceName)
|
||||
const service = this.modulesMap.get(serviceConfig.serviceName)!
|
||||
|
||||
let filters = {}
|
||||
const options = {
|
||||
|
||||
Reference in New Issue
Block a user