From 902ac12f7321abedf2fc5ac5d6f805676e66fd55 Mon Sep 17 00:00:00 2001 From: "Carlos R. L. Rodrigues" <37986729+carlos-r-l-rodrigues@users.noreply.github.com> Date: Thu, 17 Oct 2024 18:31:46 -0300 Subject: [PATCH] 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 --- integration-tests/api/medusa-config.js | 1 - integration-tests/modules/medusa-config.js | 1 - .../src/__mocks__/inventory-module.ts | 1 - .../inventory-stock-location-link.ts | 1 - .../src/__mocks__/product-inventory-link.ts | 1 - .../src/__mocks__/product-module.ts | 1 - .../src/__mocks__/stock-location-module.ts | 1 - packages/core/modules-sdk/src/definitions.ts | 27 +--------- .../src/loaders/__tests__/medusa-module.ts | 19 +------ .../src/loaders/__tests__/module-loader.ts | 50 +------------------ .../src/loaders/__tests__/register-modules.ts | 15 ++---- .../modules-sdk/src/loaders/module-loader.ts | 7 +-- .../src/loaders/register-modules.ts | 4 +- .../utils/__tests__/load-internal.spec.ts | 14 ++---- .../src/loaders/utils/load-internal.ts | 19 +++---- packages/core/modules-sdk/src/medusa-app.ts | 20 ++++---- .../core/modules-sdk/src/medusa-module.ts | 17 ++----- packages/core/modules-sdk/src/types/index.ts | 5 -- packages/core/types/src/common/index.ts | 6 +-- packages/core/types/src/modules-sdk/index.ts | 1 - packages/core/utils/src/common/index.ts | 9 ++-- .../transaction/do-not-force-transaction.ts | 3 -- .../utils/src/common/transaction/index.ts | 2 - .../transaction/should-force-transaction.ts | 3 -- .../src/modules-sdk/create-pg-connection.ts | 2 + .../decorators/inject-transaction-manager.ts | 16 +----- .../loaders/mikro-orm-connection-loader.ts | 10 ++-- .../modules-sdk/medusa-internal-service.ts | 8 ++- .../src/module-test-runner.ts | 2 + .../src/services/__tests__/event-bus.ts | 6 --- .../fulfillment-module-service/index.spec.ts | 4 +- .../index/src/services/postgres-provider.ts | 14 +++--- .../link-modules/src/initialize/index.ts | 11 +--- .../src/services/link-module-service.ts | 11 ++-- .../modules/link-modules/src/services/link.ts | 11 ++-- .../modules/link-modules/src/utils/index.ts | 10 ---- 36 files changed, 75 insertions(+), 258 deletions(-) delete mode 100644 packages/core/utils/src/common/transaction/do-not-force-transaction.ts delete mode 100644 packages/core/utils/src/common/transaction/index.ts delete mode 100644 packages/core/utils/src/common/transaction/should-force-transaction.ts diff --git a/integration-tests/api/medusa-config.js b/integration-tests/api/medusa-config.js index 299d7f31e8561..6c257852003fc 100644 --- a/integration-tests/api/medusa-config.js +++ b/integration-tests/api/medusa-config.js @@ -42,7 +42,6 @@ module.exports = { [Modules.AUTH]: true, [Modules.USER]: { scope: "internal", - resources: "shared", resolve: "@medusajs/user", options: { jwt_secret: "test", diff --git a/integration-tests/modules/medusa-config.js b/integration-tests/modules/medusa-config.js index b6c8ba073ef39..bc20e5f1f0137 100644 --- a/integration-tests/modules/medusa-config.js +++ b/integration-tests/modules/medusa-config.js @@ -52,7 +52,6 @@ module.exports = { }, [Modules.USER]: { scope: "internal", - resources: "shared", resolve: "@medusajs/user", options: { jwt_secret: "test", diff --git a/packages/core/modules-sdk/src/__mocks__/inventory-module.ts b/packages/core/modules-sdk/src/__mocks__/inventory-module.ts index 8af1b7b0fb5c0..92831def503c8 100644 --- a/packages/core/modules-sdk/src/__mocks__/inventory-module.ts +++ b/packages/core/modules-sdk/src/__mocks__/inventory-module.ts @@ -9,7 +9,6 @@ export const InventoryModule = { dependencies: [], defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, __joinerConfig: { diff --git a/packages/core/modules-sdk/src/__mocks__/inventory-stock-location-link.ts b/packages/core/modules-sdk/src/__mocks__/inventory-stock-location-link.ts index c25a79a8f6d92..e45ba450f5825 100644 --- a/packages/core/modules-sdk/src/__mocks__/inventory-stock-location-link.ts +++ b/packages/core/modules-sdk/src/__mocks__/inventory-stock-location-link.ts @@ -8,7 +8,6 @@ export const InventoryStockLocationLink = { isQueryable: true, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, __joinerConfig: { diff --git a/packages/core/modules-sdk/src/__mocks__/product-inventory-link.ts b/packages/core/modules-sdk/src/__mocks__/product-inventory-link.ts index 9c24013631752..03f385d0210e9 100644 --- a/packages/core/modules-sdk/src/__mocks__/product-inventory-link.ts +++ b/packages/core/modules-sdk/src/__mocks__/product-inventory-link.ts @@ -8,7 +8,6 @@ export const ProductInventoryLinkModule = { isQueryable: true, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, __joinerConfig: { diff --git a/packages/core/modules-sdk/src/__mocks__/product-module.ts b/packages/core/modules-sdk/src/__mocks__/product-module.ts index ea645407814b3..1a40b37e23d86 100644 --- a/packages/core/modules-sdk/src/__mocks__/product-module.ts +++ b/packages/core/modules-sdk/src/__mocks__/product-module.ts @@ -9,7 +9,6 @@ export const ProductModule = { dependencies: ["eventBusModuleService"], defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, __joinerConfig: { diff --git a/packages/core/modules-sdk/src/__mocks__/stock-location-module.ts b/packages/core/modules-sdk/src/__mocks__/stock-location-module.ts index 6b2d6c3995f00..045768a9f34a6 100644 --- a/packages/core/modules-sdk/src/__mocks__/stock-location-module.ts +++ b/packages/core/modules-sdk/src/__mocks__/stock-location-module.ts @@ -9,7 +9,6 @@ export const StockLocationModule = { dependencies: ["eventBusModuleService"], defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, __joinerConfig: { diff --git a/packages/core/modules-sdk/src/definitions.ts b/packages/core/modules-sdk/src/definitions.ts index ccf7f9e65d538..00fd617168d03 100644 --- a/packages/core/modules-sdk/src/definitions.ts +++ b/packages/core/modules-sdk/src/definitions.ts @@ -5,7 +5,7 @@ import { Modules, upperCaseFirst, } from "@medusajs/utils" -import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types" +import { MODULE_SCOPE } from "./types" export const ModulesDefinition: { [key: string]: ModuleDefinition @@ -19,7 +19,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.STOCK_LOCATION]: { @@ -31,7 +30,6 @@ export const ModulesDefinition: { dependencies: [Modules.EVENT_BUS], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.INVENTORY]: { @@ -43,7 +41,6 @@ export const ModulesDefinition: { dependencies: [Modules.EVENT_BUS], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.CACHE]: { @@ -54,7 +51,6 @@ export const ModulesDefinition: { isQueryable: false, defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.PRODUCT]: { @@ -66,7 +62,6 @@ export const ModulesDefinition: { dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.PRICING]: { @@ -78,7 +73,6 @@ export const ModulesDefinition: { dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.PROMOTION]: { @@ -90,7 +84,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.AUTH]: { @@ -102,7 +95,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.WORKFLOW_ENGINE]: { @@ -115,7 +107,6 @@ export const ModulesDefinition: { __passSharedContainer: true, defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.SALES_CHANNEL]: { @@ -127,7 +118,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.FULFILLMENT]: { @@ -139,7 +129,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER, Modules.EVENT_BUS], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.CART]: { @@ -151,7 +140,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.CUSTOMER]: { @@ -163,7 +151,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.PAYMENT]: { @@ -175,7 +162,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.USER]: { @@ -187,7 +173,6 @@ export const ModulesDefinition: { dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.REGION]: { @@ -199,7 +184,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.ORDER]: { @@ -211,7 +195,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER, Modules.EVENT_BUS], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.TAX]: { @@ -223,7 +206,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER, Modules.EVENT_BUS], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.API_KEY]: { @@ -235,7 +217,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.STORE]: { @@ -247,7 +228,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.CURRENCY]: { @@ -259,7 +239,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.FILE]: { @@ -271,7 +250,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.NOTIFICATION]: { @@ -283,7 +261,6 @@ export const ModulesDefinition: { dependencies: [Modules.EVENT_BUS, ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.INDEX]: { @@ -300,7 +277,6 @@ export const ModulesDefinition: { ], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, [Modules.LOCKING]: { @@ -312,7 +288,6 @@ export const ModulesDefinition: { dependencies: [ContainerRegistrationKeys.LOGGER], defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } diff --git a/packages/core/modules-sdk/src/loaders/__tests__/medusa-module.ts b/packages/core/modules-sdk/src/loaders/__tests__/medusa-module.ts index 35ebc32d1923e..0ce88427ddbb1 100644 --- a/packages/core/modules-sdk/src/loaders/__tests__/medusa-module.ts +++ b/packages/core/modules-sdk/src/loaders/__tests__/medusa-module.ts @@ -1,5 +1,5 @@ import { InternalModuleDeclaration } from "@medusajs/types" -import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types" +import { MODULE_SCOPE } from "../../types" import { asValue } from "awilix" import { MedusaModule } from "../../medusa-module" @@ -12,7 +12,6 @@ const mockRegisterMedusaModule = jest.fn().mockImplementation(() => { }, moduleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } @@ -47,7 +46,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", options: { abc: 123, @@ -63,7 +61,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", options: { abc: 123, @@ -76,7 +73,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", options: { different_options: "abc", @@ -98,7 +94,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", options: { abc: 123, @@ -121,7 +116,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", options: { abc: 123, @@ -134,7 +128,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", options: { different_options: "abc", @@ -151,7 +144,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", options: { abc: 123, @@ -164,7 +156,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", main: true, options: { @@ -182,7 +173,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", alias: "mod_A", options: { @@ -196,7 +186,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", main: true, alias: "mod_B", @@ -211,7 +200,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", alias: "mod_C", options: { @@ -240,7 +228,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", alias: "mod_A", options: { @@ -254,7 +241,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", main: true, alias: "mod_B", @@ -269,7 +255,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", main: true, alias: "mod_C", @@ -290,7 +275,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", alias: "module_alias", options: { @@ -304,7 +288,6 @@ describe("Medusa Modules", () => { defaultPath: "@path", declaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: "@path", alias: "module_alias", options: { diff --git a/packages/core/modules-sdk/src/loaders/__tests__/module-loader.ts b/packages/core/modules-sdk/src/loaders/__tests__/module-loader.ts index 8ac573edc2c41..3064069e00880 100644 --- a/packages/core/modules-sdk/src/loaders/__tests__/module-loader.ts +++ b/packages/core/modules-sdk/src/loaders/__tests__/module-loader.ts @@ -1,6 +1,6 @@ import { ModuleResolution } from "@medusajs/types" import { createMedusaContainer } from "@medusajs/utils" -import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types" +import { MODULE_SCOPE } from "../../types" import { moduleLoader } from "../module-loader" const logger = { @@ -29,12 +29,10 @@ describe("modules loader", () => { label: "TestService", defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, moduleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } @@ -57,12 +55,10 @@ describe("modules loader", () => { label: "TestService", defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, moduleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } @@ -97,12 +93,10 @@ describe("modules loader", () => { label: "TestService", defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, moduleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } @@ -122,12 +116,10 @@ describe("modules loader", () => { label: "TestService", defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, moduleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } @@ -150,12 +142,10 @@ describe("modules loader", () => { isRequired: true, defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, moduleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } @@ -179,12 +169,10 @@ describe("modules loader", () => { isRequired: true, defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, moduleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, } @@ -210,13 +198,10 @@ describe("modules loader", () => { isRequired: true, defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, }, // @ts-ignore - moduleDeclaration: { - resources: MODULE_RESOURCE_TYPE.SHARED, - }, + moduleDeclaration: {}, }, } @@ -228,35 +213,4 @@ describe("modules loader", () => { ) } }) - - it("should throw an error if the resources is not set when scope is defined as internal", async () => { - expect.assertions(1) - const moduleResolutions: Record = { - testService: { - resolutionPath: "@modules/no-service", - definition: { - key: "testService", - defaultPackage: "testService", - label: "TestService", - isRequired: true, - defaultModuleDeclaration: { - scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, - }, - }, - // @ts-ignore - moduleDeclaration: { - scope: MODULE_SCOPE.INTERNAL, - }, - } as any, - } - - try { - await moduleLoader({ container, moduleResolutions, logger }) - } catch (err) { - expect(err.message).toEqual( - "The module TestService is missing its resources config" - ) - } - }) }) diff --git a/packages/core/modules-sdk/src/loaders/__tests__/register-modules.ts b/packages/core/modules-sdk/src/loaders/__tests__/register-modules.ts index f62d3b7000586..2b0f586ec0c7c 100644 --- a/packages/core/modules-sdk/src/loaders/__tests__/register-modules.ts +++ b/packages/core/modules-sdk/src/loaders/__tests__/register-modules.ts @@ -1,6 +1,6 @@ import { InternalModuleDeclaration, ModuleDefinition } from "@medusajs/types" import { ModulesDefinition } from "../../definitions" -import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../../types" +import { MODULE_SCOPE } from "../../types" import { registerMedusaModule } from "../register-modules" const testServiceResolved = require.resolve( @@ -16,7 +16,6 @@ describe("module definitions loader", () => { isRequired: false, defaultModuleDeclaration: { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.SHARED, }, } @@ -45,7 +44,6 @@ describe("module definitions loader", () => { options: {}, moduleDeclaration: { scope: "internal", - resources: "shared", }, }) ) @@ -67,7 +65,6 @@ describe("module definitions loader", () => { label: "Custom: customModulesABC", }), moduleDeclaration: { - resources: "shared", scope: "internal", }, options: { @@ -130,7 +127,6 @@ describe("module definitions loader", () => { options: {}, moduleDeclaration: { scope: "internal", - resources: "shared", }, }) ) @@ -154,7 +150,6 @@ describe("module definitions loader", () => { options: {}, moduleDeclaration: { scope: "internal", - resources: "shared", }, }) ) @@ -170,7 +165,6 @@ describe("module definitions loader", () => { const res = registerMedusaModule(defaultDefinition.key, { scope: MODULE_SCOPE.INTERNAL, resolve: defaultDefinition.defaultPackage, - resources: MODULE_RESOURCE_TYPE.ISOLATED, } as InternalModuleDeclaration) expect(res[defaultDefinition.key]).toEqual( @@ -180,7 +174,7 @@ describe("module definitions loader", () => { options: {}, moduleDeclaration: { scope: "internal", - resources: "isolated", + resolve: defaultDefinition.defaultPackage, }, }) @@ -203,7 +197,7 @@ describe("module definitions loader", () => { options: { test: 123 }, moduleDeclaration: { scope: "internal", - resources: "shared", + options: { test: 123 }, }, }) @@ -219,7 +213,6 @@ describe("module definitions loader", () => { resolve: defaultDefinition.defaultPackage, options: { test: 123 }, scope: "internal", - resources: "isolated", } as any) expect(res[defaultDefinition.key]).toEqual( @@ -229,7 +222,7 @@ describe("module definitions loader", () => { options: { test: 123 }, moduleDeclaration: { scope: "internal", - resources: "isolated", + resolve: defaultDefinition.defaultPackage, options: { test: 123 }, }, diff --git a/packages/core/modules-sdk/src/loaders/module-loader.ts b/packages/core/modules-sdk/src/loaders/module-loader.ts index c0ec8b24f1222..3beac7197f0a0 100644 --- a/packages/core/modules-sdk/src/loaders/module-loader.ts +++ b/packages/core/modules-sdk/src/loaders/module-loader.ts @@ -50,7 +50,7 @@ async function loadModule( } const keyName = modDefinition.key - const { scope, resources } = resolution.moduleDeclaration ?? ({} as any) + const { scope } = resolution.moduleDeclaration ?? ({} as any) const canSkip = !resolution.resolutionPath && @@ -63,11 +63,8 @@ async function loadModule( throw new Error("External Modules are not supported yet.") } - if (!scope || (scope === MODULE_SCOPE.INTERNAL && !resources)) { + if (!scope) { let message = `The module ${resolution.definition.label} has to define its scope (internal | external)` - if (scope === MODULE_SCOPE.INTERNAL && !resources) { - message = `The module ${resolution.definition.label} is missing its resources config` - } container.register(keyName, asValue(undefined)) diff --git a/packages/core/modules-sdk/src/loaders/register-modules.ts b/packages/core/modules-sdk/src/loaders/register-modules.ts index 43379e573434c..3cc95283cb822 100644 --- a/packages/core/modules-sdk/src/loaders/register-modules.ts +++ b/packages/core/modules-sdk/src/loaders/register-modules.ts @@ -12,7 +12,7 @@ import { normalizeImportPathWithSource, } from "@medusajs/utils" import { ModulesDefinition } from "../definitions" -import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "../types" +import { MODULE_SCOPE } from "../types" export const registerMedusaModule = ( moduleKey: string, @@ -86,12 +86,10 @@ function getCustomModuleResolution( defaultPackage: "", dependencies, defaultModuleDeclaration: { - resources: MODULE_RESOURCE_TYPE.SHARED, scope: MODULE_SCOPE.INTERNAL, }, }, moduleDeclaration: { - resources: conf?.resources ?? MODULE_RESOURCE_TYPE.SHARED, scope: MODULE_SCOPE.INTERNAL, }, dependencies, diff --git a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts index cef3444c607c6..aab66b84d8d62 100644 --- a/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts +++ b/packages/core/modules-sdk/src/loaders/utils/__tests__/load-internal.spec.ts @@ -7,14 +7,14 @@ import { ModuleWithJoinerConfigFixtures, ModuleWithoutJoinerConfigFixtures, } from "../__fixtures__" +import { ModuleService as ModuleServiceWithProvider } from "../__fixtures__/module-with-providers" +import { ModuleProviderService as ModuleServiceWithProviderProvider1 } from "../__fixtures__/module-with-providers/provider-1" +import { ModuleProvider2Service as ModuleServiceWithProviderProvider2 } from "../__fixtures__/module-with-providers/provider-2" import { getProviderRegistrationKey, loadInternalModule, loadResources, } from "../load-internal" -import { ModuleProviderService as ModuleServiceWithProviderProvider1 } from "../__fixtures__/module-with-providers/provider-1" -import { ModuleProvider2Service as ModuleServiceWithProviderProvider2 } from "../__fixtures__/module-with-providers/provider-2" -import { ModuleService as ModuleServiceWithProvider } from "../__fixtures__/module-with-providers" describe("load internal", () => { describe("loadResources", () => { @@ -34,7 +34,6 @@ describe("load internal", () => { defaultPackage: false, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, } @@ -117,7 +116,6 @@ describe("load internal", () => { defaultPackage: false, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, } @@ -200,7 +198,6 @@ describe("load internal", () => { defaultPackage: false, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, } @@ -282,7 +279,6 @@ describe("load internal", () => { defaultPackage: false, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, } @@ -346,7 +342,6 @@ describe("load internal", () => { ), moduleDeclaration: { scope: "internal", - resources: "shared", }, definition: { key: "module-with-providers", @@ -354,7 +349,6 @@ describe("load internal", () => { defaultPackage: false, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, options: { @@ -399,7 +393,6 @@ describe("load internal", () => { ), moduleDeclaration: { scope: "internal", - resources: "shared", }, definition: { key: "module-with-providers", @@ -407,7 +400,6 @@ describe("load internal", () => { defaultPackage: false, defaultModuleDeclaration: { scope: "internal", - resources: "shared", }, }, options: { diff --git a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts index 2f5ff62bf889f..cd9ec01845794 100644 --- a/packages/core/modules-sdk/src/loaders/utils/load-internal.ts +++ b/packages/core/modules-sdk/src/loaders/utils/load-internal.ts @@ -28,7 +28,6 @@ import { asFunction, asValue } from "awilix" import { statSync } from "fs" import { readdir } from "fs/promises" import { dirname, join, resolve } from "path" -import { MODULE_RESOURCE_TYPE } from "../../types" type ModuleResource = { services: Function[] @@ -192,9 +191,6 @@ export async function loadInternalModule(args: { ? resolution.definition.key : resolution.definition.key + "__loaderOnly" - const { resources } = - resolution.moduleDeclaration as InternalModuleDeclaration - const loadedModule = await resolveModuleExports({ resolution }) if ("error" in loadedModule) { @@ -232,14 +228,13 @@ export async function loadInternalModule(args: { const localContainer = createMedusaContainer() const dependencies = resolution?.dependencies ?? [] - if (resources === MODULE_RESOURCE_TYPE.SHARED) { - dependencies.push( - ContainerRegistrationKeys.MANAGER, - ContainerRegistrationKeys.CONFIG_MODULE, - ContainerRegistrationKeys.LOGGER, - ContainerRegistrationKeys.PG_CONNECTION - ) - } + + dependencies.push( + ContainerRegistrationKeys.MANAGER, + ContainerRegistrationKeys.CONFIG_MODULE, + ContainerRegistrationKeys.LOGGER, + ContainerRegistrationKeys.PG_CONNECTION + ) for (const dependency of dependencies) { localContainer.register( diff --git a/packages/core/modules-sdk/src/medusa-app.ts b/packages/core/modules-sdk/src/medusa-app.ts index 0c737fbe7dd62..f58d703dd4270 100644 --- a/packages/core/modules-sdk/src/medusa-app.ts +++ b/packages/core/modules-sdk/src/medusa-app.ts @@ -18,6 +18,7 @@ import { dynamicImport, GraphQLUtils, isObject, + isSharedConnectionSymbol, isString, MedusaError, MODULE_PACKAGE_NAMES, @@ -34,7 +35,7 @@ import { } from "./medusa-module" import { RemoteLink } from "./remote-link" import { createQuery, RemoteQuery } from "./remote-query" -import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types" +import { MODULE_SCOPE } from "./types" const LinkModulePackage = MODULE_PACKAGE_NAMES[Modules.LINK] @@ -123,15 +124,14 @@ export async function loadModules(args: { } declaration.scope ??= MODULE_SCOPE.INTERNAL - if (declaration.scope === MODULE_SCOPE.INTERNAL && !declaration.resources) { - declaration.resources = MODULE_RESOURCE_TYPE.SHARED - } - if ( - declaration.scope === MODULE_SCOPE.INTERNAL && - declaration.resources === MODULE_RESOURCE_TYPE.SHARED - ) { + if (declaration.scope === MODULE_SCOPE.INTERNAL) { declaration.options ??= {} + + if (!declaration.options.database) { + declaration.options[isSharedConnectionSymbol] = true + } + declaration.options.database ??= { ...sharedResourcesConfig?.database, } @@ -493,9 +493,7 @@ async function MedusaApp_({ for (const { resolution: moduleResolution } of moduleResolutions) { if ( !moduleResolution.options?.database && - moduleResolution.moduleDeclaration?.scope === MODULE_SCOPE.INTERNAL && - moduleResolution.moduleDeclaration?.resources === - MODULE_RESOURCE_TYPE.SHARED + moduleResolution.moduleDeclaration?.scope === MODULE_SCOPE.INTERNAL ) { moduleResolution.options ??= {} moduleResolution.options.database = { diff --git a/packages/core/modules-sdk/src/medusa-module.ts b/packages/core/modules-sdk/src/medusa-module.ts index a23a536d98167..27898e9d72f64 100644 --- a/packages/core/modules-sdk/src/medusa-module.ts +++ b/packages/core/modules-sdk/src/medusa-module.ts @@ -26,7 +26,7 @@ import { registerMedusaModule, } from "./loaders" import { loadModuleMigrations } from "./loaders/utils" -import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types" +import { MODULE_SCOPE } from "./types" const logger: any = { log: (a) => console.log(a), @@ -439,9 +439,6 @@ class MedusaModule { if (declaration?.scope !== MODULE_SCOPE.EXTERNAL) { modDeclaration = { scope: declaration?.scope || MODULE_SCOPE.INTERNAL, - resources: - (declaration as InternalModuleDeclaration)?.resources || - MODULE_RESOURCE_TYPE.ISOLATED, resolve: defaultPath, options: declaration?.options ?? declaration, dependencies: @@ -449,15 +446,10 @@ class MedusaModule { alias: declaration?.alias, main: declaration?.main, worker_mode: workerMode, - } as any + } as InternalModuleDeclaration } - // TODO: Only do that while legacy modules sharing the manager exists then remove the ternary in favor of createMedusaContainer({}, globalContainer) - const container = - modDeclaration.scope === MODULE_SCOPE.INTERNAL && - modDeclaration.resources === MODULE_RESOURCE_TYPE.SHARED - ? sharedContainer ?? createMedusaContainer() - : createMedusaContainer({}, sharedContainer) + const container = sharedContainer ?? createMedusaContainer() if (injectedDependencies) { for (const service in injectedDependencies) { @@ -750,7 +742,6 @@ class MedusaModule { }: MigrationOptions): Promise { const moduleResolutions = registerMedusaModule(moduleKey, { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: modulePath, options, }) @@ -787,7 +778,6 @@ class MedusaModule { }: MigrationOptions): Promise { const moduleResolutions = registerMedusaModule(moduleKey, { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: modulePath, options, }) @@ -824,7 +814,6 @@ class MedusaModule { }: MigrationOptions): Promise { const moduleResolutions = registerMedusaModule(moduleKey, { scope: MODULE_SCOPE.INTERNAL, - resources: MODULE_RESOURCE_TYPE.ISOLATED, resolve: modulePath, options, }) diff --git a/packages/core/modules-sdk/src/types/index.ts b/packages/core/modules-sdk/src/types/index.ts index 8f816756e5add..d3468fc59b513 100644 --- a/packages/core/modules-sdk/src/types/index.ts +++ b/packages/core/modules-sdk/src/types/index.ts @@ -2,8 +2,3 @@ export enum MODULE_SCOPE { INTERNAL = "internal", EXTERNAL = "external", } - -export enum MODULE_RESOURCE_TYPE { - SHARED = "shared", - ISOLATED = "isolated", -} diff --git a/packages/core/types/src/common/index.ts b/packages/core/types/src/common/index.ts index d72d11179f66d..521bab841f126 100644 --- a/packages/core/types/src/common/index.ts +++ b/packages/core/types/src/common/index.ts @@ -1,8 +1,8 @@ -export * from "./common" -export * from "./rule" export * from "./batch" +export * from "./camel-case" +export * from "./common" export * from "./config-module" export * from "./medusa-cli" export * from "./medusa-container" +export * from "./rule" export * from "./with-calculated" -export * from "./camel-case" diff --git a/packages/core/types/src/modules-sdk/index.ts b/packages/core/types/src/modules-sdk/index.ts index 6713449154873..8f39fb3e33773 100644 --- a/packages/core/types/src/modules-sdk/index.ts +++ b/packages/core/types/src/modules-sdk/index.ts @@ -46,7 +46,6 @@ export type CustomModuleDefinition = { export type InternalModuleDeclaration = { scope: "internal" - resources: "shared" | "isolated" dependencies?: string[] definition?: CustomModuleDefinition // That represent the definition of the module, such as the one we have for the medusa supported modules. This property is used for custom made modules. resolve?: string | ModuleExports diff --git a/packages/core/utils/src/common/index.ts b/packages/core/utils/src/common/index.ts index beaa70c27adde..e95c559184d64 100644 --- a/packages/core/utils/src/common/index.ts +++ b/packages/core/utils/src/common/index.ts @@ -2,7 +2,6 @@ export * from "./alter-columns-helper" export * from "./array-difference" export * from "./array-intersection" export * from "./build-query" -export * from "./remove-undefined-properties" export * from "./build-regexp-if-valid" export * from "./camel-to-snake-case" export * from "./container" @@ -15,6 +14,7 @@ export * from "./deep-equal-obj" export * from "./deep-flat-map" export * from "./deep-merge" export * from "./define-config" +export * from "./dynamic-import" export * from "./env-editor" export * from "./errors" export * from "./file-system" @@ -45,6 +45,7 @@ export * from "./medusa-container" export * from "./normalize-import-path-with-source" export * from "./object-from-string-path" export * from "./object-to-string-path" +export * from "./omit-deep" export * from "./optional-numeric-serializer" export * from "./parse-cors-origins" export * from "./partition-array" @@ -57,6 +58,8 @@ export * from "./remote-query-object-from-string" export * from "./remote-query-object-to-string" export * from "./remove-nullisih" export * from "./remove-undefined" +export * from "./remove-undefined-properties" +export * from "./resolve-exports" export * from "./rules" export * from "./selector-constraints-to-string" export * from "./set-metadata" @@ -67,11 +70,7 @@ export * from "./to-camel-case" export * from "./to-handle" export * from "./to-kebab-case" export * from "./to-pascal-case" -export * from "./transaction" export * from "./trim-zeros" export * from "./upper-case-first" export * from "./validate-handle" export * from "./wrap-handler" -export * from "./resolve-exports" -export * from "./dynamic-import" -export * from "./omit-deep" diff --git a/packages/core/utils/src/common/transaction/do-not-force-transaction.ts b/packages/core/utils/src/common/transaction/do-not-force-transaction.ts deleted file mode 100644 index a6bfce23f8008..0000000000000 --- a/packages/core/utils/src/common/transaction/do-not-force-transaction.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function doNotForceTransaction(): boolean { - return false -} diff --git a/packages/core/utils/src/common/transaction/index.ts b/packages/core/utils/src/common/transaction/index.ts deleted file mode 100644 index 08a9e0d6a4591..0000000000000 --- a/packages/core/utils/src/common/transaction/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./do-not-force-transaction" -export * from "./should-force-transaction" diff --git a/packages/core/utils/src/common/transaction/should-force-transaction.ts b/packages/core/utils/src/common/transaction/should-force-transaction.ts deleted file mode 100644 index b9963157ffdc0..0000000000000 --- a/packages/core/utils/src/common/transaction/should-force-transaction.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function shouldForceTransaction(target: any): boolean { - return target.moduleDeclaration?.resources === "isolated" -} diff --git a/packages/core/utils/src/modules-sdk/create-pg-connection.ts b/packages/core/utils/src/modules-sdk/create-pg-connection.ts index cea6fb0148033..2d4d5aa240201 100644 --- a/packages/core/utils/src/modules-sdk/create-pg-connection.ts +++ b/packages/core/utils/src/modules-sdk/create-pg-connection.ts @@ -31,3 +31,5 @@ export function createPgConnection(options: Options) { }, }) } + +export const isSharedConnectionSymbol = Symbol.for("isSharedConnection") diff --git a/packages/core/utils/src/modules-sdk/decorators/inject-transaction-manager.ts b/packages/core/utils/src/modules-sdk/decorators/inject-transaction-manager.ts index 48883894801b3..ab5b864077e02 100644 --- a/packages/core/utils/src/modules-sdk/decorators/inject-transaction-manager.ts +++ b/packages/core/utils/src/modules-sdk/decorators/inject-transaction-manager.ts @@ -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) } diff --git a/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts b/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts index 6ba462801db38..94a671c71ccf9 100644 --- a/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts +++ b/packages/core/utils/src/modules-sdk/loaders/mikro-orm-connection-loader.ts @@ -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, diff --git a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts index a7229c0d31a58..cdd358c38e28e 100644 --- a/packages/core/utils/src/modules-sdk/medusa-internal-service.ts +++ b/packages/core/utils/src/modules-sdk/medusa-internal-service.ts @@ -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[]> - @InjectTransactionManager(shouldForceTransaction, propertyRepositoryName) + @InjectTransactionManager(propertyRepositoryName) async create( data: any | any[], @MedusaContext() sharedContext: Context = {} @@ -246,7 +244,7 @@ export function MedusaInternalService< sharedContext?: Context ): Promise[]> - @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 - @InjectTransactionManager(doNotForceTransaction, propertyRepositoryName) + @InjectTransactionManager(propertyRepositoryName) async delete( idOrSelector: | string diff --git a/packages/medusa-test-utils/src/module-test-runner.ts b/packages/medusa-test-utils/src/module-test-runner.ts index fe60fde7436d3..84fd403c93633 100644 --- a/packages/medusa-test-utils/src/module-test-runner.ts +++ b/packages/medusa-test-utils/src/module-test-runner.ts @@ -1,6 +1,7 @@ import { ContainerRegistrationKeys, DmlEntity, + isSharedConnectionSymbol, loadModels, Modules, ModulesSdkUtils, @@ -118,6 +119,7 @@ export function moduleIntegrationTestRunner({ options: { database: dbConfig, ...moduleOptions, + [isSharedConnectionSymbol]: true, }, }, } diff --git a/packages/modules/event-bus-redis/src/services/__tests__/event-bus.ts b/packages/modules/event-bus-redis/src/services/__tests__/event-bus.ts index 7c929000ccdfd..a9907512a6d42 100644 --- a/packages/modules/event-bus-redis/src/services/__tests__/event-bus.ts +++ b/packages/modules/event-bus-redis/src/services/__tests__/event-bus.ts @@ -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", }) }) diff --git a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts index 7834566d0052a..e6600f4e1ab18 100644 --- a/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts +++ b/packages/modules/fulfillment/integration-tests/__tests__/fulfillment-module-service/index.spec.ts @@ -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() + diff --git a/packages/modules/index/src/services/postgres-provider.ts b/packages/modules/index/src/services/postgres-provider.ts index 2858f646c6e5d..e5bbb20ecefae 100644 --- a/packages/modules/index/src/services/postgres-provider.ts +++ b/packages/modules/index/src/services/postgres-provider.ts @@ -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( config: IndexTypes.IndexQueryConfig, @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 } >( diff --git a/packages/modules/link-modules/src/initialize/index.ts b/packages/modules/link-modules/src/initialize/index.ts index e12d7709d2d17..cd8fb441005f5 100644 --- a/packages/modules/link-modules/src/initialize/index.ts +++ b/packages/modules/link-modules/src/initialize/index.ts @@ -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, }, } diff --git a/packages/modules/link-modules/src/services/link-module-service.ts b/packages/modules/link-modules/src/services/link-module-service.ts index c716b5d432ae9..4c81182b02239 100644 --- a/packages/modules/link-modules/src/services/link-module-service.ts +++ b/packages/modules/link-modules/src/services/link-module-service.ts @@ -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 = {} diff --git a/packages/modules/link-modules/src/services/link.ts b/packages/modules/link-modules/src/services/link.ts index fbc02ddfc6e66..cf7f752adab29 100644 --- a/packages/modules/link-modules/src/services/link.ts +++ b/packages/modules/link-modules/src/services/link.ts @@ -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 { 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 { }) } - @InjectTransactionManager(doNotForceTransaction, "linkRepository_") + @InjectTransactionManager("linkRepository_") async dismiss( data: unknown[], @MedusaContext() sharedContext: Context = {} @@ -75,7 +74,7 @@ export default class LinkService { return rows } - @InjectTransactionManager(doNotForceTransaction, "linkRepository_") + @InjectTransactionManager("linkRepository_") async delete( data: unknown, @MedusaContext() sharedContext: Context = {} @@ -85,7 +84,7 @@ export default class LinkService { }) } - @InjectTransactionManager(doNotForceTransaction, "linkRepository_") + @InjectTransactionManager("linkRepository_") async softDelete( data: any[], @MedusaContext() sharedContext: Context = {} @@ -109,7 +108,7 @@ export default class LinkService { }) } - @InjectTransactionManager(doNotForceTransaction, "linkRepository_") + @InjectTransactionManager("linkRepository_") async restore( data: any, @MedusaContext() sharedContext: Context = {} diff --git a/packages/modules/link-modules/src/utils/index.ts b/packages/modules/link-modules/src/utils/index.ts index 3885bea721ca8..b798fed41c9fd 100644 --- a/packages/modules/link-modules/src/utils/index.ts +++ b/packages/modules/link-modules/src/utils/index.ts @@ -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 -}