chore: make module loaders DML aware and auto generate joiner config (#7781)
* chore: make module loaders DML aware and auto generate joiner config * fixes and cleanup * improve dml entity check * add unit tests on load resources * cleanup deps * cleanup deps * cleanup Modules * finalise * fix modules-sdk jest * fix modules-sdk jest * fix import * fix import
This commit is contained in:
1 parent
03924a4ff6
commit
937a632eb6
191 files changed
+1105
-613
No files matched your search
+2
-3
@@ -1,7 +1,6 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { LinkWorkflowInput } from "@medusajs/types/src"
|
||||
import { ContainerRegistrationKeys, promiseAll } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ContainerRegistrationKeys, Modules, promiseAll } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const linkSalesChannelsToApiKeyStepId = "link-sales-channels-to-api-key"
|
||||
export const linkSalesChannelsToApiKeyStep = createStep(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
|
||||
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
|
||||
import { deleteApiKeysStep } from "../steps"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
links: {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { LinkModuleUtils, Modules } from "@medusajs/modules-sdk"
|
||||
import { LinkModuleUtils } from "@medusajs/modules-sdk"
|
||||
import { CartWorkflowDTO } from "@medusajs/types"
|
||||
import { isObject, remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { isObject, Modules, remoteQueryObjectFromString } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
cart_or_cart_id: string | CartWorkflowDTO
|
||||
|
||||
@@ -1,11 +1,7 @@
|
||||
import {
|
||||
LinkModuleUtils,
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { LinkModuleUtils, ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IPromotionModuleService } from "@medusajs/types"
|
||||
import { PromotionActions } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { Modules, PromotionActions } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
id: string
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
|
||||
import { deleteFulfillmentSetsStep } from "../steps"
|
||||
import { removeRemoteLinkStep } from "../../common"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export const deleteFulfillmentSetsWorkflowId =
|
||||
"delete-fulfillment-sets-workflow"
|
||||
|
||||
@@ -1,9 +1,5 @@
|
||||
import {
|
||||
DeleteEntityInput,
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { IInventoryService } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
|
||||
+6
-3
@@ -1,6 +1,9 @@
|
||||
import { ContainerRegistrationKeys, MedusaError } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
export const validateInventoryItemsForCreateStepId =
|
||||
"validate-inventory-items-for-create-step"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { deleteInventoryItemStep } from "../steps"
|
||||
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export const deleteInventoryItemWorkflowId = "delete-inventory-item-workflow"
|
||||
export const deleteInventoryItemWorkflow = createWorkflow(
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { FulfillmentDTO, OrderDTO, OrderWorkflow } from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { MedusaError, Modules } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { useRemoteQueryStep } from "../../common"
|
||||
import { cancelFulfillmentWorkflow } from "../../fulfillment"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
FulfillmentDTO,
|
||||
FulfillmentWorkflow,
|
||||
@@ -6,13 +5,13 @@ import {
|
||||
OrderWorkflow,
|
||||
ReservationItemDTO,
|
||||
} from "@medusajs/types"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { MedusaError, Modules } from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createRemoteLinkStep, useRemoteQueryStep } from "../../common"
|
||||
import { createFulfillmentWorkflow } from "../../fulfillment"
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
CreateOrderShippingMethodDTO,
|
||||
FulfillmentWorkflow,
|
||||
@@ -8,19 +7,20 @@ import {
|
||||
WithCalculatedPrice,
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
ContainerRegistrationKeys,
|
||||
isDefined,
|
||||
MathBN,
|
||||
MedusaError,
|
||||
arrayDifference,
|
||||
isDefined,
|
||||
Modules,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import {
|
||||
WorkflowData,
|
||||
createStep,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { createRemoteLinkStep, useRemoteQueryStep } from "../../common"
|
||||
import { createReturnFulfillmentWorkflow } from "../../fulfillment"
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
links: {
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
import { ModuleRegistrationName, Modules } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
import {
|
||||
arrayDifference,
|
||||
ContainerRegistrationKeys,
|
||||
MedusaError,
|
||||
arrayDifference,
|
||||
Modules,
|
||||
} from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
type StepInput = {
|
||||
ids: string[]
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { LinkDefinition, Modules } from "@medusajs/modules-sdk"
|
||||
import { LinkDefinition } from "@medusajs/modules-sdk"
|
||||
import { InventoryTypes, PricingTypes, ProductTypes } from "@medusajs/types"
|
||||
import {
|
||||
WorkflowData,
|
||||
@@ -11,6 +11,7 @@ import { createInventoryItemsWorkflow } from "../../inventory/workflows/create-i
|
||||
import { createPriceSetsStep } from "../../pricing"
|
||||
import { createProductVariantsStep } from "../steps/create-product-variants"
|
||||
import { createVariantPricingLinkStep } from "../steps/create-variant-pricing-link"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
// TODO: Create separate typings for the workflow input
|
||||
type WorkflowInput = {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
|
||||
import { deleteProductVariantsStep } from "../steps"
|
||||
import { removeRemoteLinkStep } from "../../common"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import {
|
||||
WorkflowData,
|
||||
createWorkflow,
|
||||
parallelize,
|
||||
transform,
|
||||
WorkflowData,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import { removeRemoteLinkStep } from "../../common"
|
||||
import { deleteProductsStep } from "../steps/delete-products"
|
||||
import { getProductsStep } from "../steps/get-products"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { updateProductsStep } from "../steps/update-products"
|
||||
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ProductTypes } from "@medusajs/types"
|
||||
import { arrayDifference } from "@medusajs/utils"
|
||||
import { arrayDifference, Modules } from "@medusajs/utils"
|
||||
import {
|
||||
createWorkflow,
|
||||
transform,
|
||||
|
||||
+2
-3
@@ -1,7 +1,6 @@
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
|
||||
interface StepInput {
|
||||
links: {
|
||||
|
||||
+1
-2
@@ -1,5 +1,4 @@
|
||||
import { Modules, RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Modules, RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
|
||||
interface StepInput {
|
||||
links: {
|
||||
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
links: {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { deleteSalesChannelsStep } from "../steps/delete-sales-channels"
|
||||
import { removeRemoteLinkStep } from "../../common/steps/remove-remote-links"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
type WorkflowInput = { ids: string[] }
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { WorkflowData, createWorkflow } from "@medusajs/workflows-sdk"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { createWorkflow, WorkflowData } from "@medusajs/workflows-sdk"
|
||||
|
||||
import { deleteShippingProfilesStep } from "../steps"
|
||||
import { removeRemoteLinkStep } from "../../common"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export const deleteShippingProfileWorkflowId =
|
||||
"delete-shipping-profile-workflow"
|
||||
|
||||
+2
-3
@@ -1,6 +1,5 @@
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { ContainerRegistrationKeys } from "@medusajs/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { ContainerRegistrationKeys, Modules } from "@medusajs/utils"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
|
||||
interface StepInput {
|
||||
input: {
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
DeleteEntityInput,
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
} from "@medusajs/modules-sdk"
|
||||
import { StepResponse, createStep } from "@medusajs/workflows-sdk"
|
||||
import { createStep, StepResponse } from "@medusajs/workflows-sdk"
|
||||
import { Modules } from "@medusajs/utils"
|
||||
|
||||
export const deleteStockLocationsStepId = "delete-stock-locations-step"
|
||||
export const deleteStockLocationsStep = createStep(
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
module.exports = {
|
||||
transform: { "^.+\\.[jt]s?$": "@swc/jest" },
|
||||
transform: {
|
||||
"^.+\\.[jt]s?$": [
|
||||
"@swc/jest",
|
||||
{
|
||||
jsc: {
|
||||
parser: { syntax: "typescript", decorators: true },
|
||||
transform: { decoratorMetadata: true },
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
testEnvironment: `node`,
|
||||
moduleFileExtensions: [`js`, `ts`],
|
||||
}
|
||||
@@ -21,6 +21,7 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/types": "^1.11.16",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"cross-env": "^5.2.1",
|
||||
"jest": "^29.7.0",
|
||||
"rimraf": "^5.0.1",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ModuleDefinition } from "@medusajs/types"
|
||||
import { upperCaseFirst } from "@medusajs/utils"
|
||||
import { Modules, upperCaseFirst } from "@medusajs/utils"
|
||||
import { MODULE_RESOURCE_TYPE, MODULE_SCOPE } from "./types"
|
||||
|
||||
export enum LinkModuleUtils {
|
||||
@@ -7,34 +7,6 @@ export enum LinkModuleUtils {
|
||||
REMOTE_LINK = "remoteLink",
|
||||
}
|
||||
|
||||
// TODO: Remove this enum and use the one from @medusajs/utils
|
||||
export enum Modules {
|
||||
AUTH = "auth",
|
||||
CACHE = "cacheService",
|
||||
CART = "cart",
|
||||
CUSTOMER = "customer",
|
||||
EVENT_BUS = "eventBus",
|
||||
INVENTORY = "inventoryService",
|
||||
LINK = "linkModules",
|
||||
PAYMENT = "payment",
|
||||
PRICING = "pricingService",
|
||||
PRODUCT = "productService",
|
||||
PROMOTION = "promotion",
|
||||
SALES_CHANNEL = "salesChannel",
|
||||
TAX = "tax",
|
||||
FULFILLMENT = "fulfillment",
|
||||
STOCK_LOCATION = "stockLocationService",
|
||||
USER = "user",
|
||||
WORKFLOW_ENGINE = "workflows",
|
||||
REGION = "region",
|
||||
ORDER = "order",
|
||||
API_KEY = "apiKey",
|
||||
STORE = "store",
|
||||
CURRENCY = "currency",
|
||||
FILE = "file",
|
||||
NOTIFICATION = "notification",
|
||||
}
|
||||
|
||||
export enum ModuleRegistrationName {
|
||||
AUTH = "authModuleService",
|
||||
CACHE = "cacheService",
|
||||
@@ -88,305 +60,306 @@ export const MODULE_PACKAGE_NAMES = {
|
||||
[Modules.NOTIFICATION]: "@medusajs/notification",
|
||||
}
|
||||
|
||||
export const ModulesDefinition: { [key: string | Modules]: ModuleDefinition } =
|
||||
{
|
||||
[Modules.EVENT_BUS]: {
|
||||
key: Modules.EVENT_BUS,
|
||||
registrationName: ModuleRegistrationName.EVENT_BUS,
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.EVENT_BUS],
|
||||
label: upperCaseFirst(ModuleRegistrationName.EVENT_BUS),
|
||||
isRequired: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
export const ModulesDefinition: {
|
||||
[key: string]: ModuleDefinition
|
||||
} = {
|
||||
[Modules.EVENT_BUS]: {
|
||||
key: Modules.EVENT_BUS,
|
||||
registrationName: ModuleRegistrationName.EVENT_BUS,
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.EVENT_BUS],
|
||||
label: upperCaseFirst(ModuleRegistrationName.EVENT_BUS),
|
||||
isRequired: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.STOCK_LOCATION]: {
|
||||
key: Modules.STOCK_LOCATION,
|
||||
registrationName: ModuleRegistrationName.STOCK_LOCATION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.STOCK_LOCATION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.STOCK_LOCATION]: {
|
||||
key: Modules.STOCK_LOCATION,
|
||||
registrationName: ModuleRegistrationName.STOCK_LOCATION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.STOCK_LOCATION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.INVENTORY]: {
|
||||
key: Modules.INVENTORY,
|
||||
registrationName: ModuleRegistrationName.INVENTORY,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.INVENTORY),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.INVENTORY]: {
|
||||
key: Modules.INVENTORY,
|
||||
registrationName: ModuleRegistrationName.INVENTORY,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.INVENTORY),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.CACHE]: {
|
||||
key: Modules.CACHE,
|
||||
registrationName: ModuleRegistrationName.CACHE,
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.CACHE],
|
||||
label: upperCaseFirst(ModuleRegistrationName.CACHE),
|
||||
isRequired: true,
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.CACHE]: {
|
||||
key: Modules.CACHE,
|
||||
registrationName: ModuleRegistrationName.CACHE,
|
||||
defaultPackage: MODULE_PACKAGE_NAMES[Modules.CACHE],
|
||||
label: upperCaseFirst(ModuleRegistrationName.CACHE),
|
||||
isRequired: true,
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.PRODUCT]: {
|
||||
key: Modules.PRODUCT,
|
||||
registrationName: ModuleRegistrationName.PRODUCT,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PRODUCT),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS, "logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.PRODUCT]: {
|
||||
key: Modules.PRODUCT,
|
||||
registrationName: ModuleRegistrationName.PRODUCT,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PRODUCT),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS, "logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.PRICING]: {
|
||||
key: Modules.PRICING,
|
||||
registrationName: ModuleRegistrationName.PRICING,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PRICING),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS, "logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.PRICING]: {
|
||||
key: Modules.PRICING,
|
||||
registrationName: ModuleRegistrationName.PRICING,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PRICING),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS, "logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.PROMOTION]: {
|
||||
key: Modules.PROMOTION,
|
||||
registrationName: ModuleRegistrationName.PROMOTION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PROMOTION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.PROMOTION]: {
|
||||
key: Modules.PROMOTION,
|
||||
registrationName: ModuleRegistrationName.PROMOTION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PROMOTION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.AUTH]: {
|
||||
key: Modules.AUTH,
|
||||
registrationName: ModuleRegistrationName.AUTH,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.AUTH),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.AUTH]: {
|
||||
key: Modules.AUTH,
|
||||
registrationName: ModuleRegistrationName.AUTH,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.AUTH),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.WORKFLOW_ENGINE]: {
|
||||
key: Modules.WORKFLOW_ENGINE,
|
||||
registrationName: ModuleRegistrationName.WORKFLOW_ENGINE,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.WORKFLOW_ENGINE),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.WORKFLOW_ENGINE]: {
|
||||
key: Modules.WORKFLOW_ENGINE,
|
||||
registrationName: ModuleRegistrationName.WORKFLOW_ENGINE,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.WORKFLOW_ENGINE),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.SALES_CHANNEL]: {
|
||||
key: Modules.SALES_CHANNEL,
|
||||
registrationName: ModuleRegistrationName.SALES_CHANNEL,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.SALES_CHANNEL),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.SALES_CHANNEL]: {
|
||||
key: Modules.SALES_CHANNEL,
|
||||
registrationName: ModuleRegistrationName.SALES_CHANNEL,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.SALES_CHANNEL),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.FULFILLMENT]: {
|
||||
key: Modules.FULFILLMENT,
|
||||
registrationName: ModuleRegistrationName.FULFILLMENT,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.FULFILLMENT),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger", ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.FULFILLMENT]: {
|
||||
key: Modules.FULFILLMENT,
|
||||
registrationName: ModuleRegistrationName.FULFILLMENT,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.FULFILLMENT),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger", ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.CART]: {
|
||||
key: Modules.CART,
|
||||
registrationName: ModuleRegistrationName.CART,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.CART),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.CART]: {
|
||||
key: Modules.CART,
|
||||
registrationName: ModuleRegistrationName.CART,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.CART),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.CUSTOMER]: {
|
||||
key: Modules.CUSTOMER,
|
||||
registrationName: ModuleRegistrationName.CUSTOMER,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.CUSTOMER),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.CUSTOMER]: {
|
||||
key: Modules.CUSTOMER,
|
||||
registrationName: ModuleRegistrationName.CUSTOMER,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.CUSTOMER),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.PAYMENT]: {
|
||||
key: Modules.PAYMENT,
|
||||
registrationName: ModuleRegistrationName.PAYMENT,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PAYMENT),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.PAYMENT]: {
|
||||
key: Modules.PAYMENT,
|
||||
registrationName: ModuleRegistrationName.PAYMENT,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.PAYMENT),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.USER]: {
|
||||
key: Modules.USER,
|
||||
registrationName: ModuleRegistrationName.USER,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.USER),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS, "logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.USER]: {
|
||||
key: Modules.USER,
|
||||
registrationName: ModuleRegistrationName.USER,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.USER),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: [ModuleRegistrationName.EVENT_BUS, "logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.REGION]: {
|
||||
key: Modules.REGION,
|
||||
registrationName: ModuleRegistrationName.REGION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.REGION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.REGION]: {
|
||||
key: Modules.REGION,
|
||||
registrationName: ModuleRegistrationName.REGION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.REGION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.ORDER]: {
|
||||
key: Modules.ORDER,
|
||||
registrationName: ModuleRegistrationName.ORDER,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.ORDER),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger", ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.ORDER]: {
|
||||
key: Modules.ORDER,
|
||||
registrationName: ModuleRegistrationName.ORDER,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.ORDER),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger", ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.TAX]: {
|
||||
key: Modules.TAX,
|
||||
registrationName: ModuleRegistrationName.TAX,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.TAX),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger", ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.TAX]: {
|
||||
key: Modules.TAX,
|
||||
registrationName: ModuleRegistrationName.TAX,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.TAX),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger", ModuleRegistrationName.EVENT_BUS],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.API_KEY]: {
|
||||
key: Modules.API_KEY,
|
||||
registrationName: ModuleRegistrationName.API_KEY,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.API_KEY),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.API_KEY]: {
|
||||
key: Modules.API_KEY,
|
||||
registrationName: ModuleRegistrationName.API_KEY,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.API_KEY),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.STORE]: {
|
||||
key: Modules.STORE,
|
||||
registrationName: ModuleRegistrationName.STORE,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.STORE),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.STORE]: {
|
||||
key: Modules.STORE,
|
||||
registrationName: ModuleRegistrationName.STORE,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.STORE),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.CURRENCY]: {
|
||||
key: Modules.CURRENCY,
|
||||
registrationName: ModuleRegistrationName.CURRENCY,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.CURRENCY),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.CURRENCY]: {
|
||||
key: Modules.CURRENCY,
|
||||
registrationName: ModuleRegistrationName.CURRENCY,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.CURRENCY),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.FILE]: {
|
||||
key: Modules.FILE,
|
||||
registrationName: ModuleRegistrationName.FILE,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.FILE),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.FILE]: {
|
||||
key: Modules.FILE,
|
||||
registrationName: ModuleRegistrationName.FILE,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.FILE),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
[Modules.NOTIFICATION]: {
|
||||
key: Modules.NOTIFICATION,
|
||||
registrationName: ModuleRegistrationName.NOTIFICATION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.NOTIFICATION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
},
|
||||
[Modules.NOTIFICATION]: {
|
||||
key: Modules.NOTIFICATION,
|
||||
registrationName: ModuleRegistrationName.NOTIFICATION,
|
||||
defaultPackage: false,
|
||||
label: upperCaseFirst(ModuleRegistrationName.NOTIFICATION),
|
||||
isRequired: false,
|
||||
isQueryable: true,
|
||||
dependencies: ["logger"],
|
||||
defaultModuleDeclaration: {
|
||||
scope: MODULE_SCOPE.INTERNAL,
|
||||
resources: MODULE_RESOURCE_TYPE.SHARED,
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
export const MODULE_DEFINITIONS: ModuleDefinition[] =
|
||||
Object.values(ModulesDefinition)
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export * as ModuleWithDmlMixedWithoutJoinerConfigFixtures from "./module-with-dml-mixed-without-joiner-config"
|
||||
export * as ModuleWithDmlWithoutJoinerConfigFixtures from "./module-with-dml-without-joiner-config"
|
||||
export * as ModuleWithoutJoinerConfigFixtures from "./module-without-joiner-config"
|
||||
export * as ModuleWithJoinerConfigFixtures from "./module-with-joiner-config"
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { ModuleService } from "./services/module-service"
|
||||
|
||||
const moduleExports: ModuleExports = {
|
||||
service: ModuleService,
|
||||
}
|
||||
|
||||
export * from "./models"
|
||||
export * from "./services/module-service"
|
||||
|
||||
export default moduleExports
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { model } from "@medusajs/utils"
|
||||
|
||||
export const dmlEntity = model.define("dmlEntity", {
|
||||
name: model.text(),
|
||||
})
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { Entity, Property } from "@mikro-orm/core"
|
||||
|
||||
@Entity()
|
||||
export class EntityModel {
|
||||
@Property({ columnType: "int" })
|
||||
id!: number
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./entity"
|
||||
export * from "./dml-entity"
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { IModuleService } from "@medusajs/types"
|
||||
|
||||
export class ModuleService implements IModuleService {}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { ModuleService } from "./services/module-service"
|
||||
|
||||
const moduleExports: ModuleExports = {
|
||||
service: ModuleService,
|
||||
}
|
||||
|
||||
export * from "./models"
|
||||
export * from "./services/module-service"
|
||||
|
||||
export default moduleExports
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { model } from "@medusajs/utils"
|
||||
|
||||
export const entityModel = model.define("entityModel", {
|
||||
name: model.text(),
|
||||
})
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
import { model } from "@medusajs/utils"
|
||||
|
||||
export const dmlEntity = model.define("dmlEntity", {
|
||||
name: model.text(),
|
||||
})
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./dml-entity"
|
||||
export * from "./dml-entity-model"
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { IModuleService } from "@medusajs/types"
|
||||
|
||||
export class ModuleService implements IModuleService {}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { ModuleService } from "./services/module-service"
|
||||
|
||||
const moduleExports: ModuleExports = {
|
||||
service: ModuleService,
|
||||
}
|
||||
|
||||
export * from "./models"
|
||||
export * from "./services/module-service"
|
||||
|
||||
export default moduleExports
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { Entity, Property } from "@mikro-orm/core"
|
||||
|
||||
@Entity()
|
||||
export class Entity2 {
|
||||
@Property({ columnType: "int" })
|
||||
id!: number
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { Entity, Property } from "@mikro-orm/core"
|
||||
|
||||
@Entity()
|
||||
export class EntityModel {
|
||||
@Property({ columnType: "int" })
|
||||
id!: number
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./entity"
|
||||
export * from "./entity-2"
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
import { IModuleService, ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { defineJoinerConfig } from "@medusajs/utils"
|
||||
|
||||
export class ModuleService implements IModuleService {
|
||||
__joinerConfig(): ModuleJoinerConfig {
|
||||
return defineJoinerConfig("module-service", {
|
||||
alias: [
|
||||
{
|
||||
name: ["custom_name"],
|
||||
args: {
|
||||
entity: "Custom",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
import { ModuleExports } from "@medusajs/types"
|
||||
import { ModuleService } from "./services/module-service"
|
||||
|
||||
const moduleExports: ModuleExports = {
|
||||
service: ModuleService,
|
||||
}
|
||||
|
||||
export * from "./models"
|
||||
export * from "./services/module-service"
|
||||
|
||||
export default moduleExports
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { Entity, Property } from "@mikro-orm/core"
|
||||
|
||||
@Entity()
|
||||
export class Entity2 {
|
||||
@Property({ columnType: "int" })
|
||||
id!: number
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
import { Entity, Property } from "@mikro-orm/core"
|
||||
|
||||
@Entity()
|
||||
export class EntityModel {
|
||||
@Property({ columnType: "int" })
|
||||
id!: number
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
export * from "./entity"
|
||||
export * from "./entity-2"
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
import { IModuleService } from "@medusajs/types"
|
||||
|
||||
export class ModuleService implements IModuleService {}
|
||||
@@ -0,0 +1,316 @@
|
||||
import { loadResources } from "../load-internal"
|
||||
import { IModuleService, ModuleResolution } from "@medusajs/types"
|
||||
import { join } from "path"
|
||||
import {
|
||||
ModuleWithDmlMixedWithoutJoinerConfigFixtures,
|
||||
ModuleWithDmlWithoutJoinerConfigFixtures,
|
||||
ModuleWithJoinerConfigFixtures,
|
||||
ModuleWithoutJoinerConfigFixtures,
|
||||
} from "../__fixtures__"
|
||||
import { upperCaseFirst } from "@medusajs/utils"
|
||||
|
||||
describe("load internal - load resources", () => {
|
||||
describe("when loading the module resources from a path", () => {
|
||||
test("should return the correct resources and generate the correct joiner config from a mix of DML entities and mikro orm entities", async () => {
|
||||
const { ModuleService, EntityModel, dmlEntity } =
|
||||
ModuleWithDmlMixedWithoutJoinerConfigFixtures
|
||||
|
||||
const moduleResolution: ModuleResolution = {
|
||||
resolutionPath: join(
|
||||
__dirname,
|
||||
"../__fixtures__/module-with-dml-mixed-without-joiner-config"
|
||||
),
|
||||
definition: {
|
||||
key: "module-with-dml-mixed-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module with DML mixed without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
scope: "internal",
|
||||
resources: "shared",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeUndefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
expect(resources.services[0]).toEqual(ModuleService)
|
||||
expect(resources.models).toHaveLength(2)
|
||||
expect(resources.models).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ name: upperCaseFirst(dmlEntity.name) }),
|
||||
expect.objectContaining({ name: upperCaseFirst(EntityModel.name) }),
|
||||
])
|
||||
)
|
||||
expect(resources.repositories).toHaveLength(0)
|
||||
expect(resources.loaders).toHaveLength(2)
|
||||
expect(resources.loaders).toEqual([
|
||||
expect.objectContaining({ name: "connectionLoader" }),
|
||||
expect.objectContaining({ name: "containerLoader" }),
|
||||
])
|
||||
expect(resources.moduleService).toEqual(ModuleService)
|
||||
|
||||
expect(
|
||||
(resources.moduleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeDefined()
|
||||
|
||||
const generatedJoinerConfig = (
|
||||
resources.moduleService.prototype as IModuleService
|
||||
).__joinerConfig()
|
||||
|
||||
expect(generatedJoinerConfig).toEqual({
|
||||
serviceName: "module-with-dml-mixed-without-joiner-config",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: {
|
||||
dml_entity_id: "DmlEntity",
|
||||
entity_model_id: "EntityModel",
|
||||
},
|
||||
alias: [
|
||||
{
|
||||
name: ["dml_entity", "dml_entities"],
|
||||
args: {
|
||||
entity: "DmlEntity",
|
||||
methodSuffix: "DmlEntities",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["entity_model", "entity_models"],
|
||||
args: {
|
||||
entity: "EntityModel",
|
||||
methodSuffix: "EntityModels",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
test("should return the correct resources and generate the correct joiner config from DML entities", async () => {
|
||||
const { ModuleService, entityModel, dmlEntity } =
|
||||
ModuleWithDmlWithoutJoinerConfigFixtures
|
||||
|
||||
const moduleResolution: ModuleResolution = {
|
||||
resolutionPath: join(
|
||||
__dirname,
|
||||
"../__fixtures__/module-with-dml-without-joiner-config"
|
||||
),
|
||||
definition: {
|
||||
key: "module-with-dml-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module with DML without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
scope: "internal",
|
||||
resources: "shared",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeUndefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
expect(resources.services[0]).toEqual(ModuleService)
|
||||
expect(resources.models).toHaveLength(2)
|
||||
expect(resources.models).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ name: upperCaseFirst(dmlEntity.name) }),
|
||||
expect.objectContaining({ name: upperCaseFirst(entityModel.name) }),
|
||||
])
|
||||
)
|
||||
expect(resources.repositories).toHaveLength(0)
|
||||
expect(resources.loaders).toHaveLength(2)
|
||||
expect(resources.loaders).toEqual([
|
||||
expect.objectContaining({ name: "connectionLoader" }),
|
||||
expect.objectContaining({ name: "containerLoader" }),
|
||||
])
|
||||
expect(resources.moduleService).toEqual(ModuleService)
|
||||
|
||||
expect(
|
||||
(resources.moduleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeDefined()
|
||||
|
||||
const generatedJoinerConfig = (
|
||||
resources.moduleService.prototype as IModuleService
|
||||
).__joinerConfig()
|
||||
|
||||
expect(generatedJoinerConfig).toEqual({
|
||||
serviceName: "module-with-dml-without-joiner-config",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: {
|
||||
entity_model_id: "EntityModel",
|
||||
dml_entity_id: "DmlEntity",
|
||||
},
|
||||
alias: [
|
||||
{
|
||||
name: ["entity_model", "entity_models"],
|
||||
args: {
|
||||
entity: "EntityModel",
|
||||
methodSuffix: "EntityModels",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["dml_entity", "dml_entities"],
|
||||
args: {
|
||||
entity: "DmlEntity",
|
||||
methodSuffix: "DmlEntities",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
test("should return the correct resources and generate the correct joiner config from mikro orm entities", async () => {
|
||||
const { ModuleService, EntityModel, Entity2 } =
|
||||
ModuleWithoutJoinerConfigFixtures
|
||||
|
||||
const moduleResolution: ModuleResolution = {
|
||||
resolutionPath: join(
|
||||
__dirname,
|
||||
"../__fixtures__/module-without-joiner-config"
|
||||
),
|
||||
definition: {
|
||||
key: "module-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
scope: "internal",
|
||||
resources: "shared",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeUndefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
expect(resources.services[0]).toEqual(ModuleService)
|
||||
expect(resources.models).toHaveLength(2)
|
||||
expect(resources.models).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ name: upperCaseFirst(EntityModel.name) }),
|
||||
expect.objectContaining({ name: upperCaseFirst(Entity2.name) }),
|
||||
])
|
||||
)
|
||||
expect(resources.repositories).toHaveLength(0)
|
||||
expect(resources.loaders).toHaveLength(2)
|
||||
expect(resources.loaders).toEqual([
|
||||
expect.objectContaining({ name: "connectionLoader" }),
|
||||
expect.objectContaining({ name: "containerLoader" }),
|
||||
])
|
||||
expect(resources.moduleService).toEqual(ModuleService)
|
||||
|
||||
expect(
|
||||
(resources.moduleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeDefined()
|
||||
|
||||
const generatedJoinerConfig = (
|
||||
resources.moduleService.prototype as IModuleService
|
||||
).__joinerConfig()
|
||||
|
||||
expect(generatedJoinerConfig).toEqual({
|
||||
serviceName: "module-without-joiner-config",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: {
|
||||
entity2_id: "Entity2",
|
||||
entity_model_id: "EntityModel",
|
||||
},
|
||||
alias: [
|
||||
{
|
||||
name: ["entity2", "entity2s"],
|
||||
args: {
|
||||
entity: "Entity2",
|
||||
methodSuffix: "Entity2s",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: ["entity_model", "entity_models"],
|
||||
args: {
|
||||
entity: "EntityModel",
|
||||
methodSuffix: "EntityModels",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
|
||||
test("should return the correct resources and use the given joiner config", async () => {
|
||||
const { ModuleService, EntityModel, Entity2 } =
|
||||
ModuleWithJoinerConfigFixtures
|
||||
|
||||
const moduleResolution: ModuleResolution = {
|
||||
resolutionPath: join(
|
||||
__dirname,
|
||||
"../__fixtures__/module-with-joiner-config"
|
||||
),
|
||||
definition: {
|
||||
key: "module-without-joiner-config",
|
||||
registrationName: "service",
|
||||
label: "Module without joiner config",
|
||||
defaultPackage: false,
|
||||
defaultModuleDeclaration: {
|
||||
scope: "internal",
|
||||
resources: "shared",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
expect(
|
||||
(ModuleService.prototype as IModuleService).__joinerConfig
|
||||
).toBeDefined()
|
||||
|
||||
const resources = await loadResources(moduleResolution)
|
||||
|
||||
expect(resources).toBeDefined()
|
||||
expect(resources.services).toHaveLength(1)
|
||||
expect(resources.services[0]).toEqual(ModuleService)
|
||||
expect(resources.models).toHaveLength(2)
|
||||
expect(resources.models).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({ name: upperCaseFirst(EntityModel.name) }),
|
||||
expect.objectContaining({ name: upperCaseFirst(Entity2.name) }),
|
||||
])
|
||||
)
|
||||
expect(resources.repositories).toHaveLength(0)
|
||||
expect(resources.loaders).toHaveLength(2)
|
||||
expect(resources.loaders).toEqual([
|
||||
expect.objectContaining({ name: "connectionLoader" }),
|
||||
expect.objectContaining({ name: "containerLoader" }),
|
||||
])
|
||||
expect(resources.moduleService).toEqual(ModuleService)
|
||||
|
||||
const generatedJoinerConfig = (
|
||||
resources.moduleService.prototype as IModuleService
|
||||
).__joinerConfig()
|
||||
|
||||
expect(generatedJoinerConfig).toEqual({
|
||||
serviceName: "module-service",
|
||||
primaryKeys: ["id"],
|
||||
linkableKeys: {},
|
||||
alias: [
|
||||
{
|
||||
name: ["custom_name"],
|
||||
args: {
|
||||
entity: "Custom",
|
||||
methodSuffix: "Customs",
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -10,9 +10,12 @@ import {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
createMedusaContainer,
|
||||
createMikrORMEntity,
|
||||
defineJoinerConfig,
|
||||
DmlEntity,
|
||||
MedusaModuleType,
|
||||
ModulesSdkUtils,
|
||||
createMedusaContainer,
|
||||
} from "@medusajs/utils"
|
||||
import { asFunction, asValue } from "awilix"
|
||||
import { statSync } from "fs"
|
||||
@@ -78,9 +81,9 @@ export async function loadInternalModule(
|
||||
|
||||
if (resolution.resolutionPath) {
|
||||
moduleResources = await loadResources(
|
||||
loadedModule?.loaders ?? [],
|
||||
resolution,
|
||||
logger
|
||||
logger,
|
||||
loadedModule?.loaders ?? []
|
||||
)
|
||||
}
|
||||
|
||||
@@ -180,9 +183,9 @@ export async function loadModuleMigrations(
|
||||
// Generate migration scripts if they are not present
|
||||
if (!runMigrations || !revertMigration) {
|
||||
const moduleResources = await loadResources(
|
||||
loadedModule?.loaders ?? [],
|
||||
resolution,
|
||||
console as unknown as Logger
|
||||
console as unknown as Logger,
|
||||
loadedModule?.loaders ?? []
|
||||
)
|
||||
|
||||
const migrationScriptOptions = {
|
||||
@@ -240,10 +243,10 @@ async function importAllFromDir(path: string) {
|
||||
})
|
||||
}
|
||||
|
||||
async function loadResources(
|
||||
loadedModuleLoaders: ModuleLoaderFunction[],
|
||||
export async function loadResources(
|
||||
moduleResolution: ModuleResolution,
|
||||
logger: Logger
|
||||
logger: Logger = console as unknown as Logger,
|
||||
loadedModuleLoaders?: ModuleLoaderFunction[]
|
||||
): Promise<ModuleResource> {
|
||||
let modulePath = moduleResolution.resolutionPath as string
|
||||
let normalizedPath = modulePath
|
||||
@@ -267,12 +270,21 @@ async function loadResources(
|
||||
),
|
||||
])
|
||||
|
||||
const entityBuilder = createMikrORMEntity()
|
||||
const cleanupResources = (resources) => {
|
||||
return Object.values(resources).filter(
|
||||
(resource): resource is Function => {
|
||||
return typeof resource === "function"
|
||||
}
|
||||
)
|
||||
return Object.values(resources)
|
||||
.map((resource) => {
|
||||
if (DmlEntity.isDmlEntity(resource)) {
|
||||
return entityBuilder(resource as DmlEntity<any>)
|
||||
}
|
||||
|
||||
if (typeof resource === "function") {
|
||||
return resource
|
||||
}
|
||||
|
||||
return null
|
||||
})
|
||||
.filter((v): v is Function => !!v)
|
||||
}
|
||||
|
||||
const potentialServices = [...new Set(cleanupResources(services))]
|
||||
@@ -288,6 +300,12 @@ async function loadResources(
|
||||
migrationPath: normalizedPath + "/migrations",
|
||||
})
|
||||
|
||||
generateJoinerConfigIfNecessary({
|
||||
moduleResolution,
|
||||
service: moduleService,
|
||||
models: potentialModels,
|
||||
})
|
||||
|
||||
return {
|
||||
services: potentialServices,
|
||||
models: potentialModels,
|
||||
@@ -342,7 +360,7 @@ async function runLoaders(
|
||||
}
|
||||
|
||||
function prepareLoaders({
|
||||
loadedModuleLoaders,
|
||||
loadedModuleLoaders = [] as ModuleLoaderFunction[],
|
||||
models,
|
||||
repositories,
|
||||
services,
|
||||
@@ -407,3 +425,23 @@ function prepareLoaders({
|
||||
|
||||
return finalLoaders
|
||||
}
|
||||
|
||||
function generateJoinerConfigIfNecessary({
|
||||
moduleResolution,
|
||||
service,
|
||||
models,
|
||||
}: {
|
||||
moduleResolution: ModuleResolution
|
||||
service: Constructor<IModuleService>
|
||||
models: Function[]
|
||||
}) {
|
||||
if (service.prototype.__joinerConfig) {
|
||||
return
|
||||
}
|
||||
|
||||
service.prototype.__joinerConfig = function () {
|
||||
return defineJoinerConfig(moduleResolution.definition.key, {
|
||||
entityQueryingConfig: models,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -18,19 +18,16 @@ import type {
|
||||
} from "@medusajs/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
ModulesSdkUtils,
|
||||
createMedusaContainer,
|
||||
isObject,
|
||||
isString,
|
||||
Modules,
|
||||
ModulesSdkUtils,
|
||||
promiseAll,
|
||||
} from "@medusajs/utils"
|
||||
import { asValue } from "awilix"
|
||||
import type { Knex } from "knex"
|
||||
import {
|
||||
MODULE_PACKAGE_NAMES,
|
||||
ModuleRegistrationName,
|
||||
Modules,
|
||||
} from "./definitions"
|
||||
import { MODULE_PACKAGE_NAMES, ModuleRegistrationName } from "./definitions"
|
||||
import { MedusaModule, RegisterModuleJoinerConfig } from "./medusa-module"
|
||||
import { RemoteLink } from "./remote-link"
|
||||
import { RemoteQuery } from "./remote-query"
|
||||
|
||||
@@ -4,8 +4,7 @@ import {
|
||||
ModuleJoinerRelationship,
|
||||
} from "@medusajs/types"
|
||||
|
||||
import { isObject, promiseAll, toPascalCase } from "@medusajs/utils"
|
||||
import { Modules } from "./definitions"
|
||||
import { isObject, Modules, promiseAll, toPascalCase } from "@medusajs/utils"
|
||||
import { MedusaModule } from "./medusa-module"
|
||||
import { convertRecordsToLinkDefinition } from "./utils/convert-data-to-link-definition"
|
||||
import { linkingErrorMessage } from "./utils/linking-error"
|
||||
|
||||
@@ -3,6 +3,7 @@ import { MetadataStorage } from "@mikro-orm/core"
|
||||
import { EntityConstructor } from "../types"
|
||||
import { EntityBuilder } from "../entity-builder"
|
||||
import { createMikrORMEntity } from "../helpers/create-mikro-orm-entity"
|
||||
import { DmlEntity } from "../entity"
|
||||
|
||||
describe("Entity builder", () => {
|
||||
beforeEach(() => {
|
||||
@@ -10,6 +11,21 @@ describe("Entity builder", () => {
|
||||
})
|
||||
|
||||
describe("Entity builder | properties", () => {
|
||||
test("should identify a DML entity correctly", () => {
|
||||
const model = new EntityBuilder()
|
||||
const user = model.define("user", {
|
||||
id: model.number(),
|
||||
username: model.text(),
|
||||
email: model.text(),
|
||||
})
|
||||
|
||||
expect(DmlEntity.isDmlEntity(user)).toBe(true)
|
||||
|
||||
const nonDmlEntity = new Object()
|
||||
|
||||
expect(DmlEntity.isDmlEntity(nonDmlEntity)).toBe(false)
|
||||
})
|
||||
|
||||
test("define an entity", () => {
|
||||
const model = new EntityBuilder()
|
||||
const user = model.define("user", {
|
||||
|
||||
@@ -10,9 +10,9 @@ import { BelongsTo } from "./relations/belongs-to"
|
||||
import { DateTimeProperty } from "./properties/date-time"
|
||||
import { ManyToMany } from "./relations/many-to-many"
|
||||
import type {
|
||||
PropertyType,
|
||||
RelationshipOptions,
|
||||
RelationshipType,
|
||||
PropertyType,
|
||||
} from "./types"
|
||||
import { NullableModifier } from "./properties/nullable"
|
||||
import { IdProperty } from "./properties/id"
|
||||
@@ -179,3 +179,5 @@ export class EntityBuilder {
|
||||
return new ManyToMany<T>(entityBuilder, options || {})
|
||||
}
|
||||
}
|
||||
|
||||
export const model = new EntityBuilder()
|
||||
@@ -1,11 +1,13 @@
|
||||
import { BelongsTo } from "./relations/belongs-to"
|
||||
import {
|
||||
PropertyType,
|
||||
EntityCascades,
|
||||
RelationshipType,
|
||||
ExtractEntityRelations,
|
||||
PropertyType,
|
||||
RelationshipType,
|
||||
} from "./types"
|
||||
|
||||
const IsDmlEntity = Symbol("isDmlEntity")
|
||||
|
||||
/**
|
||||
* Dml entity is a representation of a DML model with a unique
|
||||
* name, its schema and relationships.
|
||||
@@ -13,9 +15,26 @@ import {
|
||||
export class DmlEntity<
|
||||
Schema extends Record<string, PropertyType<any> | RelationshipType<any>>
|
||||
> {
|
||||
[IsDmlEntity] = true
|
||||
|
||||
#cascades: EntityCascades<string[]> = {}
|
||||
constructor(public name: string, public schema: Schema) {}
|
||||
|
||||
/**
|
||||
* A static method to check if an entity is an instance of DmlEntity.
|
||||
* It allows us to identify a specific object as being an instance of
|
||||
* DmlEntity.
|
||||
*
|
||||
* @param entity
|
||||
*/
|
||||
static isDmlEntity(entity: unknown): entity is DmlEntity<any> {
|
||||
return (
|
||||
!!entity &&
|
||||
(entity instanceof DmlEntity ||
|
||||
(typeof entity === "object" && entity[IsDmlEntity] === true))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse entity to get its underlying information
|
||||
*/
|
||||
|
||||
@@ -618,3 +618,5 @@ export function createMikrORMEntity() {
|
||||
) as Infer<T>
|
||||
}
|
||||
}
|
||||
|
||||
export const toMikroORMEntity = createMikrORMEntity()
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from "./entity-builder"
|
||||
export * from "./entity"
|
||||
export * from "./helpers/create-mikro-orm-entity"
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
} from "../common"
|
||||
import { InjectManager, MedusaContext } from "./decorators"
|
||||
import { ModuleRegistrationName } from "./definition"
|
||||
import { DmlEntity } from "../dml"
|
||||
|
||||
type BaseMethods =
|
||||
| "retrieve"
|
||||
@@ -83,16 +84,20 @@ type ExtractSingularName<T extends Record<any, any>, K = keyof T> = Capitalize<
|
||||
* @deprecated should all notion of singular and plural be removed once all modules are aligned with the convention
|
||||
* The pluralize will move to where it should be used instead
|
||||
*/
|
||||
type ExtractPluralName<T extends Record<any, any>, K = keyof T> = T[K] extends {
|
||||
plural?: string
|
||||
}
|
||||
? T[K]["plural"] & string
|
||||
: Pluralize<K & string>
|
||||
type ExtractPluralName<T extends Record<any, any>, K = keyof T> = Capitalize<
|
||||
T[K] extends {
|
||||
plural?: string
|
||||
}
|
||||
? T[K]["plural"] & string
|
||||
: Pluralize<K & string>
|
||||
>
|
||||
|
||||
// TODO: The future expected entry will be a DML object but in the meantime we have to maintain backward compatibility for ouw own modules and therefore we need to support Constructor<any> as well as this temporary object
|
||||
type TEntityEntries<Keys = string> = Record<
|
||||
Keys & string,
|
||||
Constructor<any> | { name?: string; singular?: string; plural?: string }
|
||||
| Constructor<any>
|
||||
| DmlEntity<any>
|
||||
| { name?: string; singular?: string; plural?: string }
|
||||
>
|
||||
|
||||
type ExtractKeysFromConfig<EntitiesConfig> = EntitiesConfig extends {
|
||||
|
||||
Reference in new issue
Block a user