Chore/rm main entity concept (#7709)
**What** Update the `MedusaService` class, factory and types to remove the concept of main modules. The idea being that all method will be explicitly named and suffixes to represent the object you are trying to manipulate. This pr also includes various fixes in different modules Co-authored-by: Stevche Radevski <4820812+sradevski@users.noreply.github.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
2895ccfba8
commit
48963f55ef
@@ -1,3 +1,9 @@
|
||||
import { moduleDefinition } from "./module-definition"
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { AuthModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
|
||||
const moduleDefinition: ModuleExports = {
|
||||
service: AuthModuleService,
|
||||
loaders: [loadProviders] as any,
|
||||
}
|
||||
export default moduleDefinition
|
||||
|
||||
@@ -1,31 +1,14 @@
|
||||
import { AuthIdentity } from "@models"
|
||||
import { MapToConfig } from "@medusajs/utils"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import {
|
||||
buildEntitiesNameToLinkableKeysMap,
|
||||
defineJoinerConfig,
|
||||
MapToConfig,
|
||||
} from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
|
||||
export const LinkableKeys = {
|
||||
auth_identity_id: AuthIdentity.name,
|
||||
}
|
||||
|
||||
const entityLinkableKeysMap: MapToConfig = {}
|
||||
Object.entries(LinkableKeys).forEach(([key, value]) => {
|
||||
entityLinkableKeysMap[value] ??= []
|
||||
entityLinkableKeysMap[value].push({
|
||||
mapTo: key,
|
||||
valueFrom: key.split("_").pop()!,
|
||||
})
|
||||
export const joinerConfig = defineJoinerConfig(Modules.AUTH, {
|
||||
entityQueryingConfig: [AuthIdentity],
|
||||
})
|
||||
|
||||
export const entityNameToLinkableKeysMap: MapToConfig = entityLinkableKeysMap
|
||||
|
||||
export const joinerConfig: ModuleJoinerConfig = {
|
||||
serviceName: Modules.AUTH,
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: LinkableKeys,
|
||||
alias: {
|
||||
name: ["auth_identity", "auth_identities"],
|
||||
args: {
|
||||
entity: AuthIdentity.name,
|
||||
},
|
||||
},
|
||||
}
|
||||
export const entityNameToLinkableKeysMap: MapToConfig =
|
||||
buildEntitiesNameToLinkableKeysMap(joinerConfig.linkableKeys)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { AuthModuleService } from "@services"
|
||||
import loadProviders from "./loaders/providers"
|
||||
|
||||
const service = AuthModuleService
|
||||
const loaders = [loadProviders] as any
|
||||
|
||||
export const moduleDefinition: ModuleExports = {
|
||||
service,
|
||||
loaders,
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export { MikroOrmBaseRepository as BaseRepository } from "@medusajs/utils"
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
InjectManager,
|
||||
MedusaContext,
|
||||
MedusaError,
|
||||
ModulesSdkUtils,
|
||||
MedusaService,
|
||||
} from "@medusajs/utils"
|
||||
import AuthProviderService from "./auth-provider"
|
||||
|
||||
@@ -28,25 +28,16 @@ type InjectedDependencies = {
|
||||
providerIdentityService: ModulesSdkTypes.IMedusaInternalService<any>
|
||||
authProviderService: AuthProviderService
|
||||
}
|
||||
|
||||
const generateMethodForModels = { AuthIdentity, ProviderIdentity }
|
||||
|
||||
export default class AuthModuleService<
|
||||
TAuthIdentity extends AuthIdentity = AuthIdentity,
|
||||
TProviderIdentity extends ProviderIdentity = ProviderIdentity
|
||||
>
|
||||
extends ModulesSdkUtils.MedusaService<
|
||||
AuthTypes.AuthIdentityDTO,
|
||||
{
|
||||
AuthIdentity: { dto: AuthTypes.AuthIdentityDTO }
|
||||
ProviderIdentity: { dto: AuthTypes.ProviderIdentityDTO }
|
||||
}
|
||||
>(AuthIdentity, generateMethodForModels, entityNameToLinkableKeysMap)
|
||||
export default class AuthModuleService
|
||||
extends MedusaService<{
|
||||
AuthIdentity: { dto: AuthTypes.AuthIdentityDTO }
|
||||
ProviderIdentity: { dto: AuthTypes.ProviderIdentityDTO }
|
||||
}>({ AuthIdentity, ProviderIdentity }, entityNameToLinkableKeysMap)
|
||||
implements AuthTypes.IAuthModuleService
|
||||
{
|
||||
protected baseRepository_: DAL.RepositoryService
|
||||
protected authIdentityService_: ModulesSdkTypes.IMedusaInternalService<TAuthIdentity>
|
||||
protected providerIdentityService_: ModulesSdkTypes.IMedusaInternalService<TProviderIdentity>
|
||||
protected authIdentityService_: ModulesSdkTypes.IMedusaInternalService<AuthIdentity>
|
||||
protected providerIdentityService_: ModulesSdkTypes.IMedusaInternalService<ProviderIdentity>
|
||||
protected readonly authProviderService_: AuthProviderService
|
||||
|
||||
constructor(
|
||||
@@ -71,18 +62,19 @@ export default class AuthModuleService<
|
||||
return joinerConfig
|
||||
}
|
||||
|
||||
create(
|
||||
// @ts-expect-error
|
||||
createAuthIdentities(
|
||||
data: AuthTypes.CreateAuthIdentityDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<AuthTypes.AuthIdentityDTO[]>
|
||||
|
||||
create(
|
||||
createAuthIdentities(
|
||||
data: AuthTypes.CreateAuthIdentityDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<AuthTypes.AuthIdentityDTO>
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
async create(
|
||||
async createAuthIdentities(
|
||||
data: AuthTypes.CreateAuthIdentityDTO[] | AuthTypes.CreateAuthIdentityDTO,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<AuthTypes.AuthIdentityDTO | AuthTypes.AuthIdentityDTO[]> {
|
||||
@@ -99,19 +91,19 @@ export default class AuthModuleService<
|
||||
)
|
||||
}
|
||||
|
||||
update(
|
||||
// TODO: Update to follow convention
|
||||
updateAuthIdentites(
|
||||
data: AuthTypes.UpdateAuthIdentityDTO[],
|
||||
sharedContext?: Context
|
||||
): Promise<AuthTypes.AuthIdentityDTO[]>
|
||||
|
||||
update(
|
||||
updateAuthIdentites(
|
||||
data: AuthTypes.UpdateAuthIdentityDTO,
|
||||
sharedContext?: Context
|
||||
): Promise<AuthTypes.AuthIdentityDTO>
|
||||
|
||||
// TODO: should be pluralized, see convention about the methods naming or the abstract module service interface definition @engineering
|
||||
@InjectManager("baseRepository_")
|
||||
async update(
|
||||
async updateAuthIdentites(
|
||||
data: AuthTypes.UpdateAuthIdentityDTO | AuthTypes.UpdateAuthIdentityDTO[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
): Promise<AuthTypes.AuthIdentityDTO | AuthTypes.AuthIdentityDTO[]> {
|
||||
|
||||
Reference in New Issue
Block a user