chore: remove internal module resources option (#9582)
What: * removes resouces type "shared" or "isolated" from internal modules. * modules can have an isolated database connection by providing a database config as part of their options on `medusa-config` CLOSES: FRMW-2593
This commit is contained in:
committed by
GitHub
parent
b07dd33a57
commit
902ac12f73
@@ -31,3 +31,5 @@ export function createPgConnection(options: Options) {
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export const isSharedConnectionSymbol = Symbol.for("isSharedConnection")
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import { Context } from "@medusajs/types"
|
||||
import { isString } from "../../common"
|
||||
import { MedusaContextType } from "./context-parameter"
|
||||
|
||||
export function InjectTransactionManager(
|
||||
shouldForceTransactionOrManagerProperty:
|
||||
| string
|
||||
| ((target: any) => boolean) = () => false,
|
||||
managerProperty?: string
|
||||
): MethodDecorator {
|
||||
return function (
|
||||
@@ -22,22 +18,14 @@ export function InjectTransactionManager(
|
||||
}
|
||||
|
||||
const originalMethod = descriptor.value
|
||||
const shouldForceTransaction = !isString(
|
||||
shouldForceTransactionOrManagerProperty
|
||||
)
|
||||
? shouldForceTransactionOrManagerProperty
|
||||
: () => false
|
||||
managerProperty = isString(shouldForceTransactionOrManagerProperty)
|
||||
? shouldForceTransactionOrManagerProperty
|
||||
: managerProperty ?? "baseRepository_"
|
||||
managerProperty ??= "baseRepository_"
|
||||
|
||||
const argIndex = target.MedusaContextIndex_[propertyKey]
|
||||
descriptor.value = async function (...args: any[]) {
|
||||
const shouldForceTransactionRes = shouldForceTransaction(target)
|
||||
const context: Context = args[argIndex] ?? {}
|
||||
const originalContext = args[argIndex] ?? {}
|
||||
|
||||
if (!shouldForceTransactionRes && context?.transactionManager) {
|
||||
if (context?.transactionManager) {
|
||||
return await originalMethod.apply(this, args)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import {
|
||||
mikroOrmCreateConnection,
|
||||
mikroOrmFreeTextSearchFilterOptionsFactory,
|
||||
} from "../../dal"
|
||||
import { isSharedConnectionSymbol } from "../create-pg-connection"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
|
||||
/**
|
||||
@@ -53,10 +54,11 @@ export async function mikroOrmConnectionLoader({
|
||||
return
|
||||
}
|
||||
|
||||
if (
|
||||
moduleDeclaration?.scope === "internal" &&
|
||||
moduleDeclaration.resources === "shared"
|
||||
) {
|
||||
const moduleOptions = options as any
|
||||
const reuseSharedConnection =
|
||||
moduleOptions[isSharedConnectionSymbol] || !moduleOptions?.database
|
||||
|
||||
if (moduleDeclaration?.scope === "internal" && reuseSharedConnection) {
|
||||
const shouldSwallowError = true
|
||||
const dbConfig = loadDatabaseConfig(
|
||||
moduleName,
|
||||
|
||||
@@ -11,14 +11,12 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import type { EntityClass, EntitySchema } from "@mikro-orm/core"
|
||||
import {
|
||||
doNotForceTransaction,
|
||||
isDefined,
|
||||
isObject,
|
||||
isPresent,
|
||||
isString,
|
||||
lowerCaseFirst,
|
||||
MedusaError,
|
||||
shouldForceTransaction,
|
||||
} from "../common"
|
||||
import { FreeTextSearchFilterKey } from "../dal"
|
||||
import { DmlEntity, toMikroORMEntity } from "../dml"
|
||||
@@ -209,7 +207,7 @@ export function MedusaInternalService<
|
||||
sharedContext?: Context
|
||||
): Promise<InferEntityType<TEntity>[]>
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
||||
@InjectTransactionManager(propertyRepositoryName)
|
||||
async create(
|
||||
data: any | any[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -246,7 +244,7 @@ export function MedusaInternalService<
|
||||
sharedContext?: Context
|
||||
): Promise<InferEntityType<TEntity>[]>
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, propertyRepositoryName)
|
||||
@InjectTransactionManager(propertyRepositoryName)
|
||||
async update(
|
||||
input: any | any[] | SelectorAndData | SelectorAndData[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -364,7 +362,7 @@ export function MedusaInternalService<
|
||||
sharedContext?: Context
|
||||
): Promise<void>
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, propertyRepositoryName)
|
||||
@InjectTransactionManager(propertyRepositoryName)
|
||||
async delete(
|
||||
idOrSelector:
|
||||
| string
|
||||
|
||||
Reference in New Issue
Block a user