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:
@@ -46,7 +46,6 @@ describe("RedisEventBusService", () => {
|
||||
|
||||
eventBus = new RedisEventBusService(moduleDeps, simpleModuleOptions, {
|
||||
scope: "internal",
|
||||
resources: "shared",
|
||||
})
|
||||
})
|
||||
|
||||
@@ -71,7 +70,6 @@ describe("RedisEventBusService", () => {
|
||||
it("Throws on isolated module declaration", () => {
|
||||
try {
|
||||
eventBus = new RedisEventBusService(moduleDeps, simpleModuleOptions, {
|
||||
resources: "isolated",
|
||||
scope: "internal",
|
||||
})
|
||||
} catch (error) {
|
||||
@@ -89,7 +87,6 @@ describe("RedisEventBusService", () => {
|
||||
|
||||
eventBus = new RedisEventBusService(moduleDeps, simpleModuleOptions, {
|
||||
scope: "internal",
|
||||
resources: "shared",
|
||||
})
|
||||
|
||||
queue = (eventBus as any).queue_
|
||||
@@ -154,7 +151,6 @@ describe("RedisEventBusService", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
resources: "shared",
|
||||
scope: "internal",
|
||||
}
|
||||
)
|
||||
@@ -199,7 +195,6 @@ describe("RedisEventBusService", () => {
|
||||
},
|
||||
},
|
||||
{
|
||||
resources: "shared",
|
||||
scope: "internal",
|
||||
}
|
||||
)
|
||||
@@ -344,7 +339,6 @@ describe("RedisEventBusService", () => {
|
||||
jest.clearAllMocks()
|
||||
|
||||
eventBus = new RedisEventBusService(moduleDeps, simpleModuleOptions, {
|
||||
resources: "shared",
|
||||
scope: "internal",
|
||||
})
|
||||
})
|
||||
|
||||
+2
-2
@@ -260,7 +260,7 @@ moduleIntegrationTestRunner({
|
||||
[Modules.FULFILLMENT]: {
|
||||
definition: ModulesDefinition[Modules.FULFILLMENT],
|
||||
options: {
|
||||
databaseConfig,
|
||||
database: databaseConfig,
|
||||
providers: Object.keys(providersConfig).map((id) => ({
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
@@ -310,7 +310,7 @@ moduleIntegrationTestRunner({
|
||||
[Modules.FULFILLMENT]: {
|
||||
definition: ModulesDefinition[Modules.FULFILLMENT],
|
||||
options: {
|
||||
databaseConfig,
|
||||
database: databaseConfig,
|
||||
providers: Object.keys(providersConfig2).map((id) => ({
|
||||
resolve: resolve(
|
||||
process.cwd() +
|
||||
|
||||
@@ -6,12 +6,12 @@ import {
|
||||
Subscriber,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
MikroOrmBaseRepository as BaseRepository,
|
||||
ContainerRegistrationKeys,
|
||||
InjectManager,
|
||||
InjectTransactionManager,
|
||||
isDefined,
|
||||
MedusaContext,
|
||||
MikroOrmBaseRepository as BaseRepository,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { EntityManager, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { IndexData, IndexRelation } from "@models"
|
||||
@@ -227,7 +227,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
}
|
||||
}
|
||||
|
||||
@InjectManager("baseRepository_")
|
||||
@InjectManager()
|
||||
async query<const TEntry extends string>(
|
||||
config: IndexTypes.IndexQueryConfig<TEntry>,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -320,7 +320,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
* @param sharedContext
|
||||
* @protected
|
||||
*/
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
protected async onCreate<
|
||||
TData extends { id: string; [key: string]: unknown }
|
||||
>(
|
||||
@@ -414,7 +414,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
* @param sharedContext
|
||||
* @protected
|
||||
*/
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
protected async onUpdate<
|
||||
TData extends { id: string; [key: string]: unknown }
|
||||
>(
|
||||
@@ -461,7 +461,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
* @param sharedContext
|
||||
* @protected
|
||||
*/
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
protected async onDelete<
|
||||
TData extends { id: string; [key: string]: unknown }
|
||||
>(
|
||||
@@ -515,7 +515,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
* @param schemaEntityObjectRepresentation
|
||||
* @protected
|
||||
*/
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
protected async onAttach<
|
||||
TData extends { id: string; [key: string]: unknown }
|
||||
>(
|
||||
@@ -636,7 +636,7 @@ export class PostgresProvider implements IndexTypes.StorageProvider {
|
||||
* @param sharedContext
|
||||
* @protected
|
||||
*/
|
||||
@InjectTransactionManager("baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
protected async onDetach<
|
||||
TData extends { id: string; [key: string]: unknown }
|
||||
>(
|
||||
|
||||
@@ -1,8 +1,4 @@
|
||||
import {
|
||||
MedusaModule,
|
||||
MODULE_RESOURCE_TYPE,
|
||||
MODULE_SCOPE,
|
||||
} from "@medusajs/framework/modules-sdk"
|
||||
import { MedusaModule, MODULE_SCOPE } from "@medusajs/framework/modules-sdk"
|
||||
import {
|
||||
ExternalModuleDeclaration,
|
||||
ILinkModule,
|
||||
@@ -158,11 +154,6 @@ export const initialize = async (
|
||||
dependencies: [Modules.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: injectedDependencies?.[
|
||||
ContainerRegistrationKeys.PG_CONNECTION
|
||||
]
|
||||
? MODULE_RESOURCE_TYPE.SHARED
|
||||
: MODULE_RESOURCE_TYPE.ISOLATED,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
ModulesSdkUtils,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { LinkService } from "@services"
|
||||
import { shouldForceTransaction } from "../utils"
|
||||
|
||||
type InjectedDependencies = {
|
||||
baseRepository: DAL.RepositoryService
|
||||
@@ -173,7 +172,7 @@ export default class LinkModuleService implements ILinkModule {
|
||||
return [rows.map((row) => row.toJSON()), count]
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
async create(
|
||||
primaryKeyOrBulkData:
|
||||
| string
|
||||
@@ -222,7 +221,7 @@ export default class LinkModuleService implements ILinkModule {
|
||||
return links.map((row) => row.toJSON())
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
async dismiss(
|
||||
primaryKeyOrBulkData: string | string[] | [string | string[], string][],
|
||||
foreignKeyData?: string,
|
||||
@@ -247,7 +246,7 @@ export default class LinkModuleService implements ILinkModule {
|
||||
return links.map((row) => row.toJSON())
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
async delete(
|
||||
data: any,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -322,7 +321,7 @@ export default class LinkModuleService implements ILinkModule {
|
||||
return mappedCascadedEntitiesMap ? mappedCascadedEntitiesMap : void 0
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
protected async softDelete_(
|
||||
data: any[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -380,7 +379,7 @@ export default class LinkModuleService implements ILinkModule {
|
||||
return mappedCascadedEntitiesMap ? mappedCascadedEntitiesMap : void 0
|
||||
}
|
||||
|
||||
@InjectTransactionManager(shouldForceTransaction, "baseRepository_")
|
||||
@InjectTransactionManager()
|
||||
async restore_(
|
||||
data: any,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
|
||||
@@ -5,7 +5,6 @@ import {
|
||||
MedusaContext,
|
||||
ModulesSdkUtils,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { doNotForceTransaction } from "../utils"
|
||||
|
||||
type InjectedDependencies = {
|
||||
linkRepository: any
|
||||
@@ -41,7 +40,7 @@ export default class LinkService<TEntity> {
|
||||
return await this.linkRepository_.findAndCount(queryOptions, sharedContext)
|
||||
}
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, "linkRepository_")
|
||||
@InjectTransactionManager("linkRepository_")
|
||||
async create(
|
||||
data: unknown[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -51,7 +50,7 @@ export default class LinkService<TEntity> {
|
||||
})
|
||||
}
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, "linkRepository_")
|
||||
@InjectTransactionManager("linkRepository_")
|
||||
async dismiss(
|
||||
data: unknown[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -75,7 +74,7 @@ export default class LinkService<TEntity> {
|
||||
return rows
|
||||
}
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, "linkRepository_")
|
||||
@InjectTransactionManager("linkRepository_")
|
||||
async delete(
|
||||
data: unknown,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -85,7 +84,7 @@ export default class LinkService<TEntity> {
|
||||
})
|
||||
}
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, "linkRepository_")
|
||||
@InjectTransactionManager("linkRepository_")
|
||||
async softDelete(
|
||||
data: any[],
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
@@ -109,7 +108,7 @@ export default class LinkService<TEntity> {
|
||||
})
|
||||
}
|
||||
|
||||
@InjectTransactionManager(doNotForceTransaction, "linkRepository_")
|
||||
@InjectTransactionManager("linkRepository_")
|
||||
async restore(
|
||||
data: any,
|
||||
@MedusaContext() sharedContext: Context = {}
|
||||
|
||||
@@ -1,12 +1,2 @@
|
||||
import { MODULE_RESOURCE_TYPE } from "@medusajs/framework/modules-sdk"
|
||||
|
||||
export * from "./generate-entity"
|
||||
export * from "./generate-schema"
|
||||
|
||||
export function shouldForceTransaction(target: any): boolean {
|
||||
return target.moduleDeclaration?.resources === MODULE_RESOURCE_TYPE.ISOLATED
|
||||
}
|
||||
|
||||
export function doNotForceTransaction(): boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user