chore: remove container registration name (#9137)
This commit is contained in:
committed by
GitHub
parent
ab4a422fc8
commit
950cf9af79
@@ -1,6 +1,5 @@
|
||||
export * from "./initialize"
|
||||
export * from "./migration"
|
||||
export * from "./types"
|
||||
export * from "./loaders"
|
||||
export * from "./migration"
|
||||
export * from "./services"
|
||||
export * from "./utils/compose-link-name"
|
||||
export * from "./types"
|
||||
|
||||
@@ -15,20 +15,17 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
composeLinkName,
|
||||
composeTableName,
|
||||
ContainerRegistrationKeys,
|
||||
lowerCaseFirst,
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
simpleHash,
|
||||
toPascalCase,
|
||||
} from "@medusajs/utils"
|
||||
import * as linkDefinitions from "../definitions"
|
||||
import { MigrationsExecutionPlanner } from "../migration"
|
||||
import { InitializeModuleInjectableDependencies } from "../types"
|
||||
import {
|
||||
composeLinkName,
|
||||
composeTableName,
|
||||
generateGraphQLSchema,
|
||||
} from "../utils"
|
||||
import { generateGraphQLSchema } from "../utils"
|
||||
import { getLinkModuleDefinition } from "./module-definition"
|
||||
|
||||
export const initialize = async (
|
||||
@@ -86,14 +83,12 @@ export const initialize = async (
|
||||
}
|
||||
|
||||
const serviceKey = !definition.isReadOnlyLink
|
||||
? lowerCaseFirst(
|
||||
definition.serviceName ??
|
||||
composeLinkName(
|
||||
primary.serviceName,
|
||||
primary.foreignKey,
|
||||
foreign.serviceName,
|
||||
foreign.foreignKey
|
||||
)
|
||||
? definition.serviceName ??
|
||||
composeLinkName(
|
||||
primary.serviceName,
|
||||
primary.foreignKey,
|
||||
foreign.serviceName,
|
||||
foreign.foreignKey
|
||||
)
|
||||
: simpleHash(JSON.stringify(definition.extends))
|
||||
|
||||
@@ -159,9 +154,8 @@ export const initialize = async (
|
||||
|
||||
const linkModuleDefinition: LinkModuleDefinition = {
|
||||
key: serviceKey,
|
||||
registrationName: serviceKey,
|
||||
label: serviceKey,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS],
|
||||
dependencies: [Modules.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: injectedDependencies?.[
|
||||
@@ -218,15 +212,14 @@ export function getMigrationPlanner(
|
||||
}
|
||||
|
||||
const [primary, foreign] = definition.relationships ?? []
|
||||
const serviceKey = lowerCaseFirst(
|
||||
const serviceKey =
|
||||
definition.serviceName ??
|
||||
composeLinkName(
|
||||
primary.serviceName,
|
||||
primary.foreignKey,
|
||||
foreign.serviceName,
|
||||
foreign.foreignKey
|
||||
)
|
||||
)
|
||||
composeLinkName(
|
||||
primary.serviceName,
|
||||
primary.foreignKey,
|
||||
foreign.serviceName,
|
||||
foreign.foreignKey
|
||||
)
|
||||
|
||||
if (allLinks.has(serviceKey)) {
|
||||
throw new Error(`Link module ${serviceKey} already exists.`)
|
||||
|
||||
@@ -7,10 +7,13 @@ import {
|
||||
ModuleJoinerConfig,
|
||||
ModulesSdkTypes,
|
||||
} from "@medusajs/types"
|
||||
import { lowerCaseFirst, simpleHash, toPascalCase } from "@medusajs/utils"
|
||||
import {
|
||||
composeLinkName,
|
||||
composeTableName,
|
||||
simpleHash,
|
||||
toPascalCase,
|
||||
} from "@medusajs/utils"
|
||||
import { asClass, asValue } from "awilix"
|
||||
import { composeLinkName, composeTableName } from "../utils"
|
||||
|
||||
export function containerLoader(entity, joinerConfig: ModuleJoinerConfig) {
|
||||
return async (
|
||||
{
|
||||
@@ -25,14 +28,12 @@ export function containerLoader(entity, joinerConfig: ModuleJoinerConfig) {
|
||||
const [primary, foreign] = joinerConfig.relationships!
|
||||
|
||||
const serviceName = !joinerConfig.isReadOnlyLink
|
||||
? lowerCaseFirst(
|
||||
joinerConfig.serviceName ??
|
||||
composeLinkName(
|
||||
primary.serviceName,
|
||||
primary.foreignKey,
|
||||
foreign.serviceName,
|
||||
foreign.foreignKey
|
||||
)
|
||||
? joinerConfig.serviceName ??
|
||||
composeLinkName(
|
||||
primary.serviceName,
|
||||
primary.foreignKey,
|
||||
foreign.serviceName,
|
||||
foreign.foreignKey
|
||||
)
|
||||
: simpleHash(JSON.stringify(joinerConfig.extends))
|
||||
|
||||
|
||||
@@ -13,12 +13,13 @@ import {
|
||||
CommonEvents,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isDefined,
|
||||
mapObjectTo,
|
||||
MapToConfig,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
Modules,
|
||||
ModulesSdkUtils,
|
||||
isDefined,
|
||||
mapObjectTo,
|
||||
} from "@medusajs/utils"
|
||||
import { LinkService } from "@services"
|
||||
import { shouldForceTransaction } from "../utils"
|
||||
@@ -26,12 +27,12 @@ import { shouldForceTransaction } from "../utils"
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
linkService: LinkService<any>
|
||||
eventBusModuleService?: IEventBusModuleService
|
||||
primaryKey: string | string[]
|
||||
foreignKey: string
|
||||
extraFields: string[]
|
||||
entityName: string
|
||||
serviceName: string
|
||||
[Modules.EVENT_BUS]?: IEventBusModuleService
|
||||
}
|
||||
|
||||
export default class LinkModuleService<TLink> implements ILinkModule {
|
||||
@@ -48,12 +49,12 @@ export default class LinkModuleService<TLink> implements ILinkModule {
|
||||
{
|
||||
baseRepository,
|
||||
linkService,
|
||||
eventBusModuleService,
|
||||
primaryKey,
|
||||
foreignKey,
|
||||
extraFields,
|
||||
entityName,
|
||||
serviceName,
|
||||
[Modules.EVENT_BUS]: eventBusModuleService,
|
||||
}: InjectedDependencies,
|
||||
readonly moduleDeclaration: InternalModuleDeclaration
|
||||
) {
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import { lowerCaseFirst, toPascalCase } from "@medusajs/utils"
|
||||
|
||||
export const composeLinkName = (...args) => {
|
||||
return lowerCaseFirst(toPascalCase(composeTableName(...args.concat("link"))))
|
||||
}
|
||||
|
||||
export const composeTableName = (...args) => {
|
||||
return args.map((name) => name.replace(/(_id|Service)$/gi, "")).join("_")
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
import { JoinerRelationship, ModuleJoinerConfig } from "@medusajs/types"
|
||||
import {
|
||||
SoftDeletableFilterKey,
|
||||
composeTableName,
|
||||
mikroOrmSoftDeletableFilterOptions,
|
||||
simpleHash,
|
||||
} from "@medusajs/utils"
|
||||
|
||||
import { EntitySchema } from "@mikro-orm/core"
|
||||
import { composeTableName } from "./compose-link-name"
|
||||
|
||||
function getClass(...properties) {
|
||||
return class LinkModel {
|
||||
|
||||
@@ -2,11 +2,11 @@ import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig, ModuleJoinerRelationship } from "@medusajs/types"
|
||||
import {
|
||||
camelToSnakeCase,
|
||||
composeTableName,
|
||||
isString,
|
||||
lowerCaseFirst,
|
||||
toPascalCase,
|
||||
} from "@medusajs/utils"
|
||||
import { composeTableName } from "./compose-link-name"
|
||||
|
||||
export function generateGraphQLSchema(
|
||||
joinerConfig: ModuleJoinerConfig,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { MODULE_RESOURCE_TYPE } from "@medusajs/modules-sdk"
|
||||
|
||||
export * from "./compose-link-name"
|
||||
export * from "./generate-entity"
|
||||
export * from "./generate-schema"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user