feat: Fulfillment module basic structure (#6319)
**What** Scafold the fulfillment module basic structure **Bonus** Simplified module scaffolding with new factories and less directories to manage - mikro orm connection loader factory - initialize factory FIXES CORE-1709 FIXES CORE-1710
This commit is contained in:
committed by
GitHub
parent
2104843826
commit
12054f5c01
@@ -1,2 +1,3 @@
|
||||
export * from "./clean-graphql-schema"
|
||||
export * from "./graphql-schema-to-fields"
|
||||
export * from "./initialize-factory"
|
||||
|
||||
44
packages/modules-sdk/src/utils/initialize-factory.ts
Normal file
44
packages/modules-sdk/src/utils/initialize-factory.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
InternalModuleDeclaration,
|
||||
ModuleExports,
|
||||
ModuleServiceInitializeCustomDataLayerOptions,
|
||||
ModuleServiceInitializeOptions,
|
||||
} from "@medusajs/types"
|
||||
import { MODULE_PACKAGE_NAMES } from "../definitions"
|
||||
import { MedusaModule } from "../medusa-module"
|
||||
|
||||
/**
|
||||
* Generate a initialize module factory that is exported by the module to be initialized manually
|
||||
*
|
||||
* @param moduleName
|
||||
* @param moduleDefinition
|
||||
*/
|
||||
export function initializeFactory<T>({
|
||||
moduleName,
|
||||
moduleDefinition,
|
||||
}: {
|
||||
moduleName: string
|
||||
moduleDefinition: ModuleExports
|
||||
}) {
|
||||
return async (
|
||||
options?:
|
||||
| ModuleServiceInitializeOptions
|
||||
| ModuleServiceInitializeCustomDataLayerOptions
|
||||
| ExternalModuleDeclaration
|
||||
| InternalModuleDeclaration,
|
||||
injectedDependencies?: any
|
||||
) => {
|
||||
const loaded = await MedusaModule.bootstrap<T>({
|
||||
moduleKey: moduleName,
|
||||
defaultPath: MODULE_PACKAGE_NAMES[moduleName],
|
||||
declaration: options as
|
||||
| InternalModuleDeclaration
|
||||
| ExternalModuleDeclaration,
|
||||
injectedDependencies,
|
||||
moduleExports: moduleDefinition,
|
||||
})
|
||||
|
||||
return loaded[moduleName] as T
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user