chore(order): dml (#10292)
* ../../core/types/src/dml/index.ts * ../../core/types/src/dml/index.ts * fix: relationships mapping * handle nullable foreign keys types * handle nullable foreign keys types * handle nullable foreign keys types * continue to update product category repository * fix all product category repositories issues * fix product category service types * fix product module service types * fix product module service types * fix repository template type * refactor: use a singleton DMLToMikroORM factory instance Since the MikroORM MetadataStorage is global, we will also have to turn DML to MikroORM entities conversion use a global bucket as well * refactor: update product module to use DML in tests * wip: tests * WIP product linkable fixes * continue type fixing and start test fixing * test: fix more tests * fix repository * fix pivot table computaion + fix mikro orm repository * fix many to many management and configuration * fix many to many management and configuration * fix many to many management and configuration * update product tag relation configuration * Introduce experimental dml hooks to fix some issues with categories * more fixes * fix product tests * add missing id prefixes * fix product category handle management * test: fix more failing tests * test: make it all green * test: fix breaking tests * fix: build issues * fix: build issues * fix: more breaking tests * refactor: fix issues after merge * refactor: fix issues after merge * refactor: surpress types error * test: fix DML failing tests * improve many to many inference + tests * Wip fix columns from product entity * remove product model before create hook and manage handle validation and transformation at the service level * test: fix breaking unit tests * fix: product module service to not update handle on product update * fix define link and joiner config * test: fix joiner config test * test: fix joiner config test * fix joiner config primary keys * Fix joiner config builder * Fix joiner config builder * test: remove only modifier from test * refactor: remove hooks usage from product collection * refactor: remove hooks usage from product-option * refactor: remove hooks usage for computing category handle * refactor: remove hooks usage from productCategory model * refactor: remove hooks from DML * refactor: remove cruft * order dml * cleanup * re add foerign key indexes * wip * chore: remove unused types * wip * changes * rm raw * autoincrement * wip * rel * refactor: cleanup * migration and models configuration adjustments * cleanup * number searchable * fix random ordering * fix * test: fix product-category tests * test: update breaking DML tests * test: array assertion to not care about ordering * fix: temporarily apply id ordering for products * types * wip * WIP type improvements * update order models * partially fix types temporarely * rel * fix: recursive type issue * improve type inference breaks * improve type inference breaks * update models * rm nullable * default value * repository * update default value handling * fix unit tests * WIP * toMikroORM * fix relations * cascades * fix * experimental dml hooks * rm migration * serial * nullable autoincrement * fix model * model changes * fix one to one DML * order test * fix addresses * fix unit tests * Re align dml entity name inference * update model table name config * update model table name config * revert * update return relation * WIP * hasOne * models * fix * model * initial commit * cart service * order module * utils unit test * index engine * changeset * merge * fix hasOne with fk * update * free text filter per entity * tests * prod category * property string many to many * fix big number * link modules migration set names * merge * shipping option rules * serializer * unit test * fix test mikro orm init * fix test mikro orm init * Maintain merge object properties * fix test mikro orm init * prevent unit test from connecting to db * wip * fix test * fix test * link test * schema * models * auto increment * hook * model hooks * order * wip * orm version * request return field * fix return configuration on order model * workflows * core flows * unit test * test * base repo * test * base repo * test fix * inventory move * locking inventory * test * free text fix * rm timeout mock * migrate fulfillment values * v6.4.3 * cleanup * link-modules update sql * revert test * remove fake timers --------- Co-authored-by: adrien2p <adrien.deperetti@gmail.com> Co-authored-by: Harminder Virk <virk.officials@gmail.com> Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
178 files changed
+5490
-6879
No files matched your search
@@ -0,0 +1,41 @@
|
||||
---
|
||||
"@medusajs/locking-postgres": minor
|
||||
"@medusajs/workflow-engine-inmemory": minor
|
||||
"@medusajs/workflow-engine-redis": minor
|
||||
"@medusajs/stock-location": minor
|
||||
"@medusajs/sales-channel": minor
|
||||
"@medusajs/link-modules": minor
|
||||
"@medusajs/notification": minor
|
||||
"@medusajs/fulfillment": minor
|
||||
"@medusajs/orchestration": minor
|
||||
"@medusajs/workflows-sdk": minor
|
||||
"@medusajs/test-utils": minor
|
||||
"@medusajs/inventory": minor
|
||||
"@medusajs/promotion": minor
|
||||
"@medusajs/modules-sdk": minor
|
||||
"@medusajs/currency": minor
|
||||
"@medusajs/customer": minor
|
||||
"@medusajs/core-flows": minor
|
||||
"@medusajs/api-key": minor
|
||||
"@medusajs/locking": minor
|
||||
"@medusajs/payment": minor
|
||||
"@medusajs/pricing": minor
|
||||
"@medusajs/product": minor
|
||||
"@medusajs/cli": minor
|
||||
"@medusajs/framework": minor
|
||||
"@medusajs/region": minor
|
||||
"integration-tests-http": minor
|
||||
"@medusajs/index": minor
|
||||
"@medusajs/order": minor
|
||||
"@medusajs/store": minor
|
||||
"@medusajs/auth": minor
|
||||
"@medusajs/cart": minor
|
||||
"@medusajs/file": minor
|
||||
"@medusajs/user": minor
|
||||
"@medusajs/tax": minor
|
||||
"@medusajs/types": minor
|
||||
"@medusajs/utils": minor
|
||||
"@medusajs/medusa": minor
|
||||
---
|
||||
|
||||
chore: upgrade to mikro-orm 6
|
||||
@@ -388,7 +388,7 @@ medusaIntegrationTestRunner({
|
||||
rules: [
|
||||
{
|
||||
attribute: "enabled_in_store",
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
operator: "eq",
|
||||
},
|
||||
{
|
||||
@@ -1779,7 +1779,7 @@ medusaIntegrationTestRunner({
|
||||
rules: [
|
||||
{
|
||||
attribute: "enabled_in_store",
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
operator: "eq",
|
||||
},
|
||||
{
|
||||
@@ -2150,7 +2150,7 @@ medusaIntegrationTestRunner({
|
||||
rules: [
|
||||
{
|
||||
attribute: "enabled_in_store",
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
operator: "eq",
|
||||
},
|
||||
{
|
||||
|
||||
@@ -69,7 +69,6 @@ medusaIntegrationTestRunner({
|
||||
await api
|
||||
.post("/admin/customer-groups", payload, adminHeaders)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
// BREAKING: Duplicate error is now 400
|
||||
expect(err.response.status).toEqual(400)
|
||||
expect(err.response.data.type).toEqual("invalid_data")
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
Modules,
|
||||
RuleOperator,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
} from "../../../helpers/create-admin-user"
|
||||
import { setupTaxStructure } from "../../../modules/__tests__/fixtures/tax"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
jest.setTimeout(300000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ClaimType, Modules, RuleOperator } from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { ClaimType, Modules, RuleOperator } from "@medusajs/utils"
|
||||
import {
|
||||
adminHeaders,
|
||||
createAdminUser,
|
||||
@@ -7,7 +7,7 @@ import {
|
||||
import { setupTaxStructure } from "../../../../modules/__tests__/fixtures"
|
||||
import { createOrderSeeder } from "../../fixtures/order"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
jest.setTimeout(300000)
|
||||
|
||||
medusaIntegrationTestRunner({
|
||||
testSuite: ({ dbConnection, getContainer, api }) => {
|
||||
@@ -268,6 +268,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
items: [
|
||||
{
|
||||
title: "new ITEM",
|
||||
variant_id: order.items[0].variant_id,
|
||||
quantity: 1,
|
||||
},
|
||||
@@ -480,6 +481,7 @@ medusaIntegrationTestRunner({
|
||||
{
|
||||
items: [
|
||||
{
|
||||
title: "Test item 2",
|
||||
variant_id: order.items[0].variant_id,
|
||||
quantity: 1,
|
||||
},
|
||||
@@ -551,7 +553,7 @@ medusaIntegrationTestRunner({
|
||||
})
|
||||
)
|
||||
|
||||
inboundItem = orderResult.items[0]
|
||||
inboundItem = orderResult.items[1]
|
||||
|
||||
await api.post(
|
||||
`/admin/claims/${claimWithInboundAndOutbound.id}/inbound/items`,
|
||||
|
||||
@@ -968,6 +968,7 @@ medusaIntegrationTestRunner({
|
||||
sales_channel_id: expect.stringContaining("sc_"),
|
||||
currency_code: "usd",
|
||||
region_id: expect.stringContaining("reg_"),
|
||||
shipping_address: null,
|
||||
item_total: 0,
|
||||
total: 0,
|
||||
email: null,
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { getMigrationPlanner, initialize } from "@medusajs/link-modules"
|
||||
import { MedusaModule } from "@medusajs/modules-sdk"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import { ModuleJoinerConfig } from "@medusajs/types"
|
||||
|
||||
jest.setTimeout(5000000)
|
||||
|
||||
@@ -74,6 +74,7 @@ medusaIntegrationTestRunner({
|
||||
|
||||
const planner = getMigrationPlanner(dbConfig, linkDefinition)
|
||||
await planner.executePlan(await planner.createPlan())
|
||||
|
||||
links = await initialize(dbConfig, linkDefinition)
|
||||
})
|
||||
|
||||
|
||||
@@ -236,7 +236,7 @@ medusaIntegrationTestRunner({
|
||||
summary: expect.objectContaining({
|
||||
// TODO: add summary fields
|
||||
}),
|
||||
items: [
|
||||
items: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
title: "Test variant",
|
||||
subtitle: "Test product",
|
||||
@@ -335,7 +335,7 @@ medusaIntegrationTestRunner({
|
||||
value: "1",
|
||||
}),
|
||||
}),
|
||||
],
|
||||
]),
|
||||
shipping_address: expect.objectContaining({
|
||||
last_name: "Test",
|
||||
address_1: "Test",
|
||||
|
||||
@@ -362,6 +362,7 @@ medusaIntegrationTestRunner({
|
||||
metadata: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
},
|
||||
billing_address: {
|
||||
id: expect.any(String),
|
||||
@@ -379,6 +380,7 @@ medusaIntegrationTestRunner({
|
||||
metadata: null,
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
deleted_at: null,
|
||||
},
|
||||
shipping_methods: [
|
||||
expect.objectContaining({
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
createShippingOptionsWorkflow,
|
||||
orderClaimRequestItemReturnWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
FulfillmentWorkflow,
|
||||
IOrderModuleService,
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
@@ -186,7 +186,7 @@ async function prepareDataFixtures({ container }) {
|
||||
{
|
||||
attribute: "is_return",
|
||||
operator: RuleOperator.EQ,
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
orderExchangeAddNewItemWorkflow,
|
||||
orderExchangeRequestItemReturnWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
FulfillmentWorkflow,
|
||||
IRegionModuleService,
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
@@ -234,7 +234,7 @@ async function prepareDataFixtures({ container }) {
|
||||
{
|
||||
attribute: "is_return",
|
||||
operator: RuleOperator.EQ,
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ import {
|
||||
beginReturnOrderWorkflow,
|
||||
createShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
FulfillmentWorkflow,
|
||||
IOrderModuleService,
|
||||
@@ -17,7 +18,6 @@ import {
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
@@ -187,7 +187,7 @@ async function prepareDataFixtures({ container }) {
|
||||
{
|
||||
attribute: "is_return",
|
||||
operator: RuleOperator.EQ,
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
createShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { RemoteLink } from "@medusajs/modules-sdk"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
FulfillmentSetDTO,
|
||||
FulfillmentWorkflow,
|
||||
@@ -21,7 +22,6 @@ import {
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
@@ -190,7 +190,7 @@ async function prepareDataFixtures({ container }) {
|
||||
{
|
||||
attribute: "is_return",
|
||||
operator: RuleOperator.EQ,
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
createOrderFulfillmentWorkflow,
|
||||
createShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
FulfillmentWorkflow,
|
||||
IOrderModuleService,
|
||||
@@ -20,7 +21,6 @@ import {
|
||||
Modules,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
@@ -305,12 +305,15 @@ async function createOrderFixture({ container, product, location }) {
|
||||
|
||||
const inventoryModule = container.resolve(Modules.INVENTORY)
|
||||
|
||||
const itemWithInventory = order.items!.find(
|
||||
(o) => o.variant_sku === variantSkuWithInventory
|
||||
)!
|
||||
const reservation = await inventoryModule.createReservationItems([
|
||||
{
|
||||
line_item_id: order.items![0].id,
|
||||
line_item_id: itemWithInventory.id,
|
||||
inventory_item_id: inventoryItem.id,
|
||||
location_id: location.id,
|
||||
quantity: order.items![0].quantity,
|
||||
quantity: itemWithInventory.quantity,
|
||||
},
|
||||
])
|
||||
|
||||
@@ -440,7 +443,6 @@ medusaIntegrationTestRunner({
|
||||
id: order.id,
|
||||
},
|
||||
fields: [
|
||||
"*",
|
||||
"items.*",
|
||||
"shipping_methods.*",
|
||||
"total",
|
||||
@@ -458,14 +460,15 @@ medusaIntegrationTestRunner({
|
||||
)!
|
||||
|
||||
expect(orderFulfillAfterCancelled.fulfillments).toHaveLength(1)
|
||||
expect(orderFulfillItemWithInventory.detail.fulfilled_quantity).toEqual(
|
||||
0
|
||||
)
|
||||
expect(
|
||||
orderFulfillItemWithInventory.detail.fulfilled_quantity.valueOf()
|
||||
).toEqual(0)
|
||||
|
||||
const stockAvailabilityAfterCancelled =
|
||||
await inventoryModule.retrieveStockedQuantity(inventoryItem.id, [
|
||||
location.id,
|
||||
])
|
||||
|
||||
expect(stockAvailabilityAfterCancelled.valueOf()).toEqual(2)
|
||||
})
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import {
|
||||
createOrderShipmentWorkflow,
|
||||
createShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
FulfillmentWorkflow,
|
||||
IOrderModuleService,
|
||||
@@ -20,7 +21,6 @@ import {
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(500000)
|
||||
|
||||
@@ -177,7 +177,7 @@ async function prepareDataFixtures({ container }) {
|
||||
{
|
||||
attribute: "is_return",
|
||||
operator: RuleOperator.EQ,
|
||||
value: '"true"',
|
||||
value: "true",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
@@ -145,7 +145,9 @@ medusaIntegrationTestRunner({
|
||||
throwOnError: false,
|
||||
})
|
||||
|
||||
expect(error.error.message).toEqual(`Order id not found: ${order.id}`)
|
||||
expect(error.error.message).toEqual(
|
||||
`Return id not found: ${returnOrder.id}`
|
||||
)
|
||||
})
|
||||
|
||||
it("should throw an error if order change does not exist", async () => {
|
||||
|
||||
+3
-3
@@ -2,6 +2,7 @@ import {
|
||||
batchShippingOptionRulesWorkflow,
|
||||
createShippingOptionsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
import {
|
||||
BatchWorkflowInput,
|
||||
CreateShippingOptionRuleDTO,
|
||||
@@ -19,7 +20,6 @@ import {
|
||||
RuleOperator,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/utils"
|
||||
import { medusaIntegrationTestRunner } from "@medusajs/test-utils"
|
||||
|
||||
jest.setTimeout(100000)
|
||||
|
||||
@@ -249,7 +249,7 @@ medusaIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
attribute: "new_attribute",
|
||||
operator: "eq",
|
||||
value: 100,
|
||||
value: "100",
|
||||
})
|
||||
)
|
||||
expect(updatedRule).toEqual(
|
||||
@@ -345,7 +345,7 @@ medusaIntegrationTestRunner({
|
||||
expect.objectContaining({
|
||||
attribute: "total",
|
||||
operator: "eq",
|
||||
value: 100,
|
||||
value: "100",
|
||||
}),
|
||||
])
|
||||
)
|
||||
|
||||
@@ -21,10 +21,10 @@
|
||||
"scrypt-kdf": "^2.0.1",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"@medusajs/framework": "^1.0.1",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"ioredis": "^5.4.1",
|
||||
"pg": "^8.13.0",
|
||||
|
||||
@@ -32,10 +32,10 @@
|
||||
"author": "Sebastian Rindom",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"@types/yargs": "^15.0.15",
|
||||
@@ -72,10 +72,10 @@
|
||||
"yargs": "^15.3.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"pg": "^8.13.0"
|
||||
},
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { IInventoryService, InventoryTypes } from "@medusajs/framework/types"
|
||||
import { InventoryTypes } from "@medusajs/framework/types"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
import { MathBN, Modules } from "@medusajs/framework/utils"
|
||||
@@ -29,12 +29,13 @@ export const adjustInventoryLevelsStep = createStep(
|
||||
input: AdjustInventoryLevelsStepInput,
|
||||
{ container }
|
||||
) => {
|
||||
const inventoryService: IInventoryService = container.resolve(
|
||||
Modules.INVENTORY
|
||||
)
|
||||
const inventoryService = container.resolve(Modules.INVENTORY)
|
||||
const locking = container.resolve(Modules.LOCKING)
|
||||
const inventoryItemIds = input.map((item) => item.inventory_item_id)
|
||||
|
||||
const adjustedLevels: InventoryTypes.InventoryLevelDTO[] =
|
||||
await inventoryService.adjustInventory(
|
||||
await locking.execute(inventoryItemIds, async () => {
|
||||
return await inventoryService.adjustInventory(
|
||||
input.map((item) => {
|
||||
return {
|
||||
inventoryItemId: item.inventory_item_id,
|
||||
@@ -43,6 +44,7 @@ export const adjustInventoryLevelsStep = createStep(
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
return new StepResponse(
|
||||
adjustedLevels,
|
||||
@@ -55,11 +57,15 @@ export const adjustInventoryLevelsStep = createStep(
|
||||
)
|
||||
},
|
||||
async (adjustedLevels, { container }) => {
|
||||
if (!adjustedLevels) {
|
||||
if (!adjustedLevels?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const inventoryService = container.resolve(Modules.INVENTORY)
|
||||
const locking = container.resolve(Modules.LOCKING)
|
||||
const inventoryItemIds = adjustedLevels.map(
|
||||
(item) => item.inventory_item_id
|
||||
)
|
||||
|
||||
/**
|
||||
* @todo
|
||||
@@ -67,6 +73,7 @@ export const adjustInventoryLevelsStep = createStep(
|
||||
* "inventoryItemId" and "locationId" as snake case, whereas
|
||||
* the expected object needed these properties as camelCase
|
||||
*/
|
||||
await locking.execute(inventoryItemIds, async () => {
|
||||
await inventoryService.adjustInventory(
|
||||
adjustedLevels.map((level) => {
|
||||
return {
|
||||
@@ -76,5 +83,6 @@ export const adjustInventoryLevelsStep = createStep(
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
}
|
||||
)
|
||||
@@ -20,10 +20,10 @@ export const updateOrderClaimsStep = createStep(
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
|
||||
objectFields: ["metadata"],
|
||||
})
|
||||
const dataBeforeUpdate = await service.listOrderClaims(
|
||||
const dataBeforeUpdate = (await service.listOrderClaims(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations, select: selects }
|
||||
)
|
||||
)) as UpdateOrderClaimDTO[]
|
||||
|
||||
const updated = await service.updateOrderClaims(
|
||||
data.map((dt) => {
|
||||
|
||||
@@ -26,10 +26,10 @@ export const updateOrderExchangesStep = createStep(
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
|
||||
objectFields: ["metadata"],
|
||||
})
|
||||
const dataBeforeUpdate = await service.listOrderExchanges(
|
||||
const dataBeforeUpdate = (await service.listOrderExchanges(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations, select: selects }
|
||||
)
|
||||
)) as UpdateOrderExchangeDTO[]
|
||||
|
||||
const updated = await service.updateOrderExchanges(
|
||||
data.map((dt) => {
|
||||
|
||||
@@ -22,6 +22,7 @@ export * from "./exchange/create-exchange-items-from-actions"
|
||||
export * from "./exchange/delete-exchanges"
|
||||
export * from "./preview-order-change"
|
||||
export * from "./register-fulfillment"
|
||||
export * from "./register-order-changes"
|
||||
export * from "./register-shipment"
|
||||
export * from "./return/cancel-return"
|
||||
export * from "./return/create-complete-return"
|
||||
@@ -32,7 +33,5 @@ export * from "./return/update-returns"
|
||||
export * from "./set-tax-lines-for-items"
|
||||
export * from "./update-order-change-actions"
|
||||
export * from "./update-order-changes"
|
||||
export * from "./update-order-exchanges"
|
||||
export * from "./update-shipping-methods"
|
||||
export * from "./update-orders"
|
||||
export * from "./register-order-changes"
|
||||
export * from "./update-shipping-methods"
|
||||
@@ -13,7 +13,7 @@ import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
*/
|
||||
export type UpdateOrderChangesStepInput = UpdateOrderChangeDTO[]
|
||||
|
||||
export const updateOrderChangesStepId = "update-order-shopping-methods"
|
||||
export const updateOrderChangesStepId = "update-order-changes"
|
||||
/**
|
||||
* This step updates order change.
|
||||
*/
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
import {
|
||||
IOrderModuleService,
|
||||
UpdateOrderExchangeDTO,
|
||||
} from "@medusajs/framework/types"
|
||||
import {
|
||||
Modules,
|
||||
getSelectsAndRelationsFromObjectArray,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { StepResponse, createStep } from "@medusajs/framework/workflows-sdk"
|
||||
|
||||
/**
|
||||
* The order exchanges to update.
|
||||
*/
|
||||
export type UpdateOrderExchangesStepInput = UpdateOrderExchangeDTO[]
|
||||
|
||||
export const updateOrderExchangesStepId = "update-order-exchange"
|
||||
/**
|
||||
* This step update order changes.
|
||||
*/
|
||||
export const updateOrderExchangesStep = createStep(
|
||||
updateOrderExchangesStepId,
|
||||
async (data: UpdateOrderExchangesStepInput, { container }) => {
|
||||
const service = container.resolve<IOrderModuleService>(Modules.ORDER)
|
||||
|
||||
const { selects, relations } = getSelectsAndRelationsFromObjectArray(data, {
|
||||
objectFields: ["metadata"],
|
||||
})
|
||||
const dataBeforeUpdate = await service.listOrderExchanges(
|
||||
{ id: data.map((d) => d.id) },
|
||||
{ relations, select: selects }
|
||||
)
|
||||
|
||||
const updated = await service.updateOrderExchanges(
|
||||
data.map((dt) => {
|
||||
const { id, ...rest } = dt
|
||||
return {
|
||||
selector: { id },
|
||||
data: rest,
|
||||
}
|
||||
})
|
||||
)
|
||||
|
||||
return new StepResponse(updated, dataBeforeUpdate)
|
||||
},
|
||||
async (dataBeforeUpdate, { container }) => {
|
||||
if (!dataBeforeUpdate?.length) {
|
||||
return
|
||||
}
|
||||
|
||||
const service = container.resolve<IOrderModuleService>(Modules.ORDER)
|
||||
|
||||
await service.updateOrderExchanges(
|
||||
dataBeforeUpdate.map((dt) => {
|
||||
const { id, ...rest } = dt
|
||||
return {
|
||||
selector: { id },
|
||||
data: rest,
|
||||
}
|
||||
})
|
||||
)
|
||||
}
|
||||
)
|
||||
@@ -143,14 +143,16 @@ function prepareInventoryUpdate({
|
||||
}[] = []
|
||||
for (const item of fulfillment.items) {
|
||||
// if this is `null` this means that item is from variant that has `manage_inventory` false
|
||||
if (item.inventory_item_id) {
|
||||
if (!item.inventory_item_id) {
|
||||
continue
|
||||
}
|
||||
|
||||
inventoryAdjustment.push({
|
||||
inventory_item_id: item.inventory_item_id as string,
|
||||
location_id: fulfillment.location_id,
|
||||
adjustment: item.quantity,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
inventoryAdjustment,
|
||||
|
||||
@@ -223,16 +223,10 @@ export const orderClaimRequestItemReturnWorkflow = createWorkflow(
|
||||
when({ orderClaim }, ({ orderClaim }) => {
|
||||
return !orderClaim.return_id
|
||||
}).then(() => {
|
||||
const createdReturnId = transform(
|
||||
{ createdReturn },
|
||||
({ createdReturn }) => {
|
||||
return createdReturn?.[0]!.id
|
||||
}
|
||||
)
|
||||
updateOrderClaimsStep([
|
||||
{
|
||||
id: orderClaim.id,
|
||||
return_id: createdReturnId,
|
||||
return: createdReturn?.[0]!.id,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
@@ -327,6 +327,8 @@ export const confirmClaimRequestWorkflow = createWorkflow(
|
||||
fields: [
|
||||
"id",
|
||||
"status",
|
||||
"claim_id",
|
||||
"return_id",
|
||||
"actions.id",
|
||||
"actions.claim_id",
|
||||
"actions.return_id",
|
||||
|
||||
+1
-7
@@ -225,16 +225,10 @@ export const orderExchangeRequestItemReturnWorkflow = createWorkflow(
|
||||
when({ orderExchange }, ({ orderExchange }) => {
|
||||
return !orderExchange.return_id
|
||||
}).then(() => {
|
||||
const createdReturnId = transform(
|
||||
{ createdReturn },
|
||||
({ createdReturn }) => {
|
||||
return createdReturn?.[0]!.id
|
||||
}
|
||||
)
|
||||
updateOrderExchangesStep([
|
||||
{
|
||||
id: orderExchange.id,
|
||||
return_id: createdReturnId,
|
||||
return: createdReturn?.[0]!.id,
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
@@ -186,7 +186,17 @@ export const removeItemReturnActionWorkflow = createWorkflow(
|
||||
|
||||
const updatedOrderChange: OrderChangeDTO = useRemoteQueryStep({
|
||||
entry_point: "order_change",
|
||||
fields: ["actions.action", "actions.return_id", "actions.id"],
|
||||
fields: [
|
||||
"actions.id",
|
||||
"actions.action",
|
||||
"actions.order_id",
|
||||
"actions.return_id",
|
||||
"actions.claim_id",
|
||||
"actions.exchange_id",
|
||||
"actions.reference",
|
||||
"actions.reference_id",
|
||||
"actions.order_change_id",
|
||||
],
|
||||
variables: {
|
||||
filters: {
|
||||
order_id: orderReturn.order_id,
|
||||
|
||||
@@ -55,10 +55,10 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/cli": "^2.3.1",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"@types/cors": "^2.8.17",
|
||||
@@ -97,11 +97,11 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/cli": "^2.0.0",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"ioredis": "^5.4.1",
|
||||
"pg": "^8.13.0",
|
||||
|
||||
@@ -11,17 +11,15 @@
|
||||
* small, we should be okay with managing this wrapper.
|
||||
*/
|
||||
|
||||
import { isAbsolute, join } from "path"
|
||||
import { ConfigurationLoader } from "@mikro-orm/core"
|
||||
import { CLIConfigurator, CLIHelper } from "@mikro-orm/cli"
|
||||
import { ConfigurationLoader } from "@mikro-orm/core"
|
||||
import { isAbsolute, join } from "path"
|
||||
|
||||
/**
|
||||
* Monkey patching the TSNode registration of Mikro ORM to not use
|
||||
* hardcoded module system with TypeScript.
|
||||
*/
|
||||
ConfigurationLoader.registerTsNode = async function (
|
||||
configPath = "tsconfig.json"
|
||||
) {
|
||||
ConfigurationLoader.registerTsNode = function (configPath = "tsconfig.json") {
|
||||
const tsConfigPath = isAbsolute(configPath)
|
||||
? configPath
|
||||
: join(process.cwd(), configPath)
|
||||
|
||||
@@ -31,10 +31,10 @@
|
||||
"watch": "tsc --build --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
@@ -50,10 +50,10 @@
|
||||
"@medusajs/utils": "^2.3.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
@@ -43,10 +43,10 @@
|
||||
"@medusajs/utils": "^2.3.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
|
||||
@@ -10,7 +10,12 @@ export type DMLSchema = Record<
|
||||
PropertyType<any> | RelationshipType<any>
|
||||
>
|
||||
|
||||
export type IDmlEntityConfig = string | { name?: string; tableName: string }
|
||||
export type IDmlEntityConfig =
|
||||
| string
|
||||
| {
|
||||
name?: string
|
||||
tableName: string
|
||||
}
|
||||
|
||||
export type InferDmlEntityNameFromConfig<TConfig extends IDmlEntityConfig> =
|
||||
TConfig extends string
|
||||
|
||||
@@ -2727,6 +2727,21 @@ export interface FilterableOrderChangeProps
|
||||
*/
|
||||
order_id?: string | string[] | OperatorMap<string>
|
||||
|
||||
/**
|
||||
* Filter the changes by their associated return's ID.
|
||||
*/
|
||||
return_id?: string | string[] | OperatorMap<string>
|
||||
|
||||
/**
|
||||
* Filter the changes by their associated claim's ID.
|
||||
*/
|
||||
claim_id?: string | string[] | OperatorMap<string>
|
||||
|
||||
/**
|
||||
* Filter the changes by their associated exchange's ID.
|
||||
*/
|
||||
exchange_id?: string | string[] | OperatorMap<string>
|
||||
|
||||
/**
|
||||
* Filter the order changes by their status.
|
||||
*/
|
||||
|
||||
@@ -1738,7 +1738,7 @@ export interface UpdateOrderClaimDTO {
|
||||
* The associated return's ID, if the
|
||||
* claim's {@link type} is `replace`.
|
||||
*/
|
||||
return_id?: string
|
||||
return?: string
|
||||
|
||||
/**
|
||||
* The type of the claim.
|
||||
@@ -1778,7 +1778,7 @@ export interface UpdateOrderExchangeDTO {
|
||||
/**
|
||||
* The associated return's ID.
|
||||
*/
|
||||
return_id?: string
|
||||
return?: string
|
||||
|
||||
/**
|
||||
* Whether backorders are allowed on the exchange's items.
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"@types/express": "^4.17.21",
|
||||
@@ -59,10 +59,10 @@
|
||||
"ulid": "^2.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
|
||||
@@ -63,7 +63,7 @@ class ProductOptionValue {
|
||||
fieldName: "option_id",
|
||||
mapToPk: true,
|
||||
nullable: true,
|
||||
onDelete: "cascade",
|
||||
deleteRule: "cascade",
|
||||
})
|
||||
option_id: string | null
|
||||
|
||||
@@ -88,7 +88,7 @@ class ProductVariant {
|
||||
@ManyToOne(() => Product, {
|
||||
columnType: "text",
|
||||
nullable: true,
|
||||
onDelete: "cascade",
|
||||
deleteRule: "cascade",
|
||||
fieldName: "product_id",
|
||||
mapToPk: true,
|
||||
})
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Entity, MikroORM, OnInit, Property } from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { BaseEntity } from "../base-entity"
|
||||
|
||||
describe("BaseEntity", () => {
|
||||
@@ -10,11 +11,15 @@ describe("BaseEntity", () => {
|
||||
}
|
||||
}
|
||||
|
||||
const orm = await MikroORM.init({
|
||||
const orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [Entity1],
|
||||
dbName: "test",
|
||||
type: "postgresql",
|
||||
user: "postgres",
|
||||
password: "",
|
||||
connect: false,
|
||||
})
|
||||
)
|
||||
|
||||
const manager = orm.em.fork()
|
||||
const entity1 = manager.create(Entity1, {})
|
||||
@@ -28,11 +33,15 @@ describe("BaseEntity", () => {
|
||||
@Entity()
|
||||
class Entity1 extends BaseEntity {}
|
||||
|
||||
const orm = await MikroORM.init({
|
||||
const orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [Entity1],
|
||||
dbName: "test",
|
||||
type: "postgresql",
|
||||
user: "postgres",
|
||||
password: "",
|
||||
connect: false,
|
||||
})
|
||||
)
|
||||
|
||||
const manager = orm.em.fork()
|
||||
const entity1 = manager.create(Entity1, {})
|
||||
@@ -52,11 +61,15 @@ describe("BaseEntity", () => {
|
||||
@Entity()
|
||||
class ProductOptionValue extends BaseEntity {}
|
||||
|
||||
const orm = await MikroORM.init({
|
||||
const orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [ProductModel, ProductCategoryEntity, ProductOptionValue],
|
||||
dbName: "test",
|
||||
type: "postgresql",
|
||||
user: "postgres",
|
||||
password: "",
|
||||
connect: false,
|
||||
})
|
||||
)
|
||||
|
||||
const manager = orm.em.fork()
|
||||
|
||||
@@ -105,11 +118,15 @@ describe("BaseEntity", () => {
|
||||
}
|
||||
}
|
||||
|
||||
const orm = await MikroORM.init({
|
||||
const orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [ProductModel, ProductCategoryEntity, ProductOptionValue],
|
||||
dbName: "test",
|
||||
type: "postgresql",
|
||||
user: "postgres",
|
||||
password: "",
|
||||
connect: false,
|
||||
})
|
||||
)
|
||||
|
||||
const manager = orm.em.fork()
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import { Entity, MikroORM, PrimaryKey } from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { BigNumber } from "../../../totals/big-number"
|
||||
import { MikroOrmBigNumberProperty } from "../big-number-field"
|
||||
|
||||
@@ -23,11 +24,15 @@ describe("@MikroOrmBigNumberProperty", () => {
|
||||
let orm!: MikroORM
|
||||
|
||||
beforeEach(async () => {
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [TestAmount],
|
||||
dbName: "test",
|
||||
type: "postgresql",
|
||||
user: "postgres",
|
||||
password: "",
|
||||
connect: false,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -51,9 +56,7 @@ describe("@MikroOrmBigNumberProperty", () => {
|
||||
try {
|
||||
;(testAmount as any).amount = null
|
||||
} catch (e) {
|
||||
expect(e.message).toEqual(
|
||||
"Invalid BigNumber value: null. Should be one of: string, number, BigNumber (bignumber.js), BigNumberRawValue"
|
||||
)
|
||||
expect(e.message).toEqual("Cannot set value null for amount.")
|
||||
}
|
||||
|
||||
testAmount.nullable_amount = null
|
||||
|
||||
+11
-6
@@ -1,4 +1,5 @@
|
||||
import { MikroORM } from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { SearchableEntity1, SearchableEntity2 } from "../__fixtures__/utils"
|
||||
import { mikroOrmFreeTextSearchFilterOptionsFactory } from "../mikro-orm-free-text-search-filter"
|
||||
|
||||
@@ -6,21 +7,23 @@ describe("mikroOrmFreeTextSearchFilterOptionsFactory", () => {
|
||||
let orm
|
||||
|
||||
beforeEach(async () => {
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [SearchableEntity1, SearchableEntity2],
|
||||
user: "postgres",
|
||||
password: "",
|
||||
dbName: "test",
|
||||
type: "postgresql",
|
||||
connect: false,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should return a filter function that filters entities based on the free text search value", async () => {
|
||||
const entityManager = orm.em.fork()
|
||||
const freeTextSearchValue = "search"
|
||||
|
||||
const models = [SearchableEntity1, SearchableEntity2]
|
||||
|
||||
let filterConstraints = mikroOrmFreeTextSearchFilterOptionsFactory(
|
||||
models
|
||||
SearchableEntity1.name
|
||||
).cond(
|
||||
{
|
||||
value: freeTextSearchValue,
|
||||
@@ -51,7 +54,9 @@ describe("mikroOrmFreeTextSearchFilterOptionsFactory", () => {
|
||||
],
|
||||
})
|
||||
|
||||
filterConstraints = mikroOrmFreeTextSearchFilterOptionsFactory(models).cond(
|
||||
filterConstraints = mikroOrmFreeTextSearchFilterOptionsFactory(
|
||||
SearchableEntity2.name
|
||||
).cond(
|
||||
{
|
||||
value: freeTextSearchValue,
|
||||
fromEntity: SearchableEntity2.name,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { MikroORM } from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import {
|
||||
Entity1WithUnDecoratedProp,
|
||||
Entity2WithUnDecoratedProp,
|
||||
@@ -11,7 +12,8 @@ import { mikroOrmSerializer } from "../mikro-orm-serializer"
|
||||
|
||||
describe("mikroOrmSerializer", () => {
|
||||
beforeEach(async () => {
|
||||
await MikroORM.init({
|
||||
await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [
|
||||
Entity1WithUnDecoratedProp,
|
||||
Entity2WithUnDecoratedProp,
|
||||
@@ -20,9 +22,12 @@ describe("mikroOrmSerializer", () => {
|
||||
ProductOptionValue,
|
||||
ProductVariant,
|
||||
],
|
||||
user: "postgres",
|
||||
password: "",
|
||||
dbName: "test",
|
||||
type: "postgresql",
|
||||
connect: false,
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("should serialize an entity", async () => {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { CustomTsMigrationGenerator } from "../mikro-orm-create-connection"
|
||||
|
||||
function unwrapSql(sql: string) {
|
||||
return sql.match(/this.addSql\('(.*?)'\)/)?.[1]
|
||||
return sql.toString().match(/this.addSql\(`(.*?)`\)/)?.[1]
|
||||
}
|
||||
|
||||
describe("CustomTsMigrationGenerator", () => {
|
||||
|
||||
@@ -26,11 +26,12 @@ export function MikroOrmBigNumberProperty(
|
||||
set(value: BigNumberInput) {
|
||||
if (options?.nullable && !isPresent(value)) {
|
||||
this.__helper.__data[columnName] = null
|
||||
this.__helper.__data[rawColumnName]
|
||||
this.__helper.__data[rawColumnName] = null
|
||||
this[rawColumnName] = null
|
||||
} else {
|
||||
let bigNumber: BigNumber
|
||||
|
||||
try {
|
||||
if (value instanceof BigNumber) {
|
||||
bigNumber = value
|
||||
} else if (this[rawColumnName]) {
|
||||
@@ -41,6 +42,9 @@ export function MikroOrmBigNumberProperty(
|
||||
} else {
|
||||
bigNumber = new BigNumber(value)
|
||||
}
|
||||
} catch (e) {
|
||||
throw new Error(`Cannot set value ${value} for ${columnName}.`)
|
||||
}
|
||||
|
||||
const raw = bigNumber.raw!
|
||||
raw.value = trimZeros(raw.value as string)
|
||||
@@ -80,6 +84,7 @@ export function MikroOrmBigNumberProperty(
|
||||
type: "any",
|
||||
columnType: "numeric",
|
||||
trackChanges: false,
|
||||
runtimeType: "any",
|
||||
...options,
|
||||
})(target, columnName)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? "postgres"
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||
|
||||
export const pgGodCredentials = {
|
||||
|
||||
+8
-6
@@ -1,3 +1,4 @@
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import {
|
||||
BeforeCreate,
|
||||
Collection,
|
||||
@@ -13,11 +14,11 @@ import {
|
||||
Unique,
|
||||
wrap,
|
||||
} from "@mikro-orm/core"
|
||||
import { mikroOrmBaseRepositoryFactory } from "../../mikro-orm-repository"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import BigNumber from "bignumber.js"
|
||||
import { dropDatabase } from "pg-god"
|
||||
import { MikroOrmBigNumberProperty } from "../../big-number-field"
|
||||
import BigNumber from "bignumber.js"
|
||||
import { BigNumberRawValue } from "@medusajs/types"
|
||||
import { mikroOrmBaseRepositoryFactory } from "../../mikro-orm-repository"
|
||||
import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database"
|
||||
|
||||
const dbName = "mikroorm-integration-1"
|
||||
@@ -78,7 +79,7 @@ class Entity2 {
|
||||
nullable: true,
|
||||
mapToPk: true,
|
||||
fieldName: "entity1_id",
|
||||
onDelete: "set null",
|
||||
deleteRule: "set null",
|
||||
})
|
||||
entity1_id: string
|
||||
|
||||
@@ -143,11 +144,12 @@ describe("mikroOrmRepository", () => {
|
||||
pgGodCredentials
|
||||
)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [Entity1, Entity2],
|
||||
clientUrl: getDatabaseURL(dbName),
|
||||
type: "postgresql",
|
||||
})
|
||||
)
|
||||
|
||||
const generator = orm.getSchemaGenerator()
|
||||
await generator.ensureDatabase()
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { mikroOrmUpdateDeletedAtRecursively } from "../../utils"
|
||||
import { MikroORM } from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { defineConfig, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { dropDatabase } from "pg-god"
|
||||
import { mikroOrmUpdateDeletedAtRecursively } from "../../utils"
|
||||
import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database"
|
||||
import {
|
||||
DeepRecursiveEntity1,
|
||||
DeepRecursiveEntity2,
|
||||
@@ -12,8 +14,6 @@ import {
|
||||
RecursiveEntity1,
|
||||
RecursiveEntity2,
|
||||
} from "../__fixtures__/utils"
|
||||
import { dropDatabase } from "pg-god"
|
||||
import { getDatabaseURL, pgGodCredentials } from "../__fixtures__/database"
|
||||
|
||||
const dbName = "mikroorm-utils-integration-1"
|
||||
|
||||
@@ -38,7 +38,8 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
||||
pgGodCredentials
|
||||
)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [
|
||||
Entity1,
|
||||
Entity2,
|
||||
@@ -51,8 +52,8 @@ describe("mikroOrmUpdateDeletedAtRecursively", () => {
|
||||
InternalCircularDependencyEntity1,
|
||||
],
|
||||
clientUrl: getDatabaseURL(dbName),
|
||||
type: "postgresql",
|
||||
})
|
||||
)
|
||||
|
||||
const generator = orm.getSchemaGenerator()
|
||||
await generator.ensureDatabase()
|
||||
|
||||
@@ -45,8 +45,9 @@ export async function mikroOrmCreateConnection(
|
||||
schema = database.connection.context?.client?.config?.searchPath
|
||||
}
|
||||
|
||||
const { MikroORM } = await import("@mikro-orm/postgresql")
|
||||
return await MikroORM.init({
|
||||
const { MikroORM, defineConfig } = await import("@mikro-orm/postgresql")
|
||||
return await MikroORM.init(
|
||||
defineConfig({
|
||||
discovery: { disableDynamicFileAccess: true, warnWhenNoEntities: false },
|
||||
entities,
|
||||
debug: database.debug ?? process.env.NODE_ENV?.startsWith("dev") ?? false,
|
||||
@@ -55,8 +56,10 @@ export async function mikroOrmCreateConnection(
|
||||
schema,
|
||||
driverOptions,
|
||||
tsNode: process.env.APP_ENV === "development",
|
||||
type: "postgresql",
|
||||
filters: database.filters ?? {},
|
||||
assign: {
|
||||
convertCustomTypes: true,
|
||||
},
|
||||
migrations: {
|
||||
disableForeignKeys: false,
|
||||
path: pathToMigrations,
|
||||
@@ -75,4 +78,5 @@ export async function mikroOrmCreateConnection(
|
||||
...database.pool,
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
@@ -4,23 +4,20 @@ import type {
|
||||
FindOneOptions,
|
||||
FindOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { EntityMetadata, EntitySchema, ReferenceType } from "@mikro-orm/core"
|
||||
import { EntityMetadata, ReferenceKind } from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export const FreeTextSearchFilterKey = "freeTextSearch"
|
||||
export const FreeTextSearchFilterKeyPrefix = "freeTextSearch_"
|
||||
|
||||
interface FilterArgument {
|
||||
value: string
|
||||
fromEntity: string
|
||||
}
|
||||
|
||||
function getEntityProperties(entity: EntityClass<any> | EntitySchema): {
|
||||
function getEntityProperties(metadata: EntityMetadata<any>): {
|
||||
[key: string]: EntityProperty<any>
|
||||
} {
|
||||
return (
|
||||
(entity as EntityClass<any>)?.prototype.__meta?.properties ??
|
||||
(entity as EntitySchema).meta?.properties
|
||||
)
|
||||
return metadata.properties
|
||||
}
|
||||
|
||||
function retrieveRelationsConstraints(
|
||||
@@ -31,7 +28,7 @@ function retrieveRelationsConstraints(
|
||||
type: string
|
||||
name: string
|
||||
},
|
||||
models: (EntityClass<any> | EntitySchema)[],
|
||||
metadata: EntityMetadata<any>,
|
||||
searchValue: string,
|
||||
visited: Set<string> = new Set(),
|
||||
shouldStop: boolean = false
|
||||
@@ -46,13 +43,12 @@ function retrieveRelationsConstraints(
|
||||
|
||||
const relationFreeTextSearchWhere: any = []
|
||||
|
||||
const relationClass = models.find((m) => m.name === relation.type)!
|
||||
const relationProperties = getEntityProperties(relationClass)
|
||||
const relationProperties = getEntityProperties(metadata)
|
||||
|
||||
for (const propertyConfiguration of Object.values(relationProperties)) {
|
||||
if (
|
||||
!(propertyConfiguration as any).searchable ||
|
||||
propertyConfiguration.reference !== ReferenceType.SCALAR
|
||||
propertyConfiguration.kind !== ReferenceKind.SCALAR
|
||||
) {
|
||||
continue
|
||||
}
|
||||
@@ -69,9 +65,7 @@ function retrieveRelationsConstraints(
|
||||
})
|
||||
}
|
||||
|
||||
const innerRelations: EntityProperty[] =
|
||||
(relationClass as EntityClass<any>)?.prototype.__meta?.relations ??
|
||||
(relationClass as EntitySchema).meta?.relations
|
||||
const innerRelations: EntityProperty[] = metadata.relations
|
||||
|
||||
for (const innerRelation of innerRelations) {
|
||||
const branchVisited = new Set(Array.from(visited))
|
||||
@@ -108,7 +102,7 @@ function retrieveRelationsConstraints(
|
||||
mapToPk: innerRelation.mapToPk,
|
||||
type: innerRelation.type,
|
||||
},
|
||||
models,
|
||||
innerRelation.targetMeta!,
|
||||
searchValue,
|
||||
branchVisited,
|
||||
isSelfCircularDependency
|
||||
@@ -128,10 +122,9 @@ function retrieveRelationsConstraints(
|
||||
return relationFreeTextSearchWhere
|
||||
}
|
||||
|
||||
export const mikroOrmFreeTextSearchFilterOptionsFactory = (
|
||||
models: (EntityClass<any> | EntitySchema)[]
|
||||
) => {
|
||||
export const mikroOrmFreeTextSearchFilterOptionsFactory = (model: string) => {
|
||||
return {
|
||||
name: FreeTextSearchFilterKeyPrefix + model,
|
||||
cond: (
|
||||
freeTextSearchArgs: FilterArgument,
|
||||
operation: string,
|
||||
@@ -144,7 +137,7 @@ export const mikroOrmFreeTextSearchFilterOptionsFactory = (
|
||||
return {}
|
||||
}
|
||||
|
||||
const { value, fromEntity } = freeTextSearchArgs
|
||||
const { value } = freeTextSearchArgs
|
||||
|
||||
if (options?.visited?.size) {
|
||||
/**
|
||||
@@ -158,17 +151,17 @@ export const mikroOrmFreeTextSearchFilterOptionsFactory = (
|
||||
}
|
||||
}
|
||||
|
||||
const entityMetadata = manager.getDriver().getMetadata().get(fromEntity)
|
||||
const entityMetadata = manager.getDriver().getMetadata().get(model)
|
||||
|
||||
const freeTextSearchWhere = retrieveRelationsConstraints(
|
||||
{
|
||||
targetMeta: entityMetadata,
|
||||
mapToPk: false,
|
||||
searchable: true,
|
||||
type: fromEntity,
|
||||
type: model,
|
||||
name: entityMetadata.name!,
|
||||
},
|
||||
models,
|
||||
entityMetadata,
|
||||
value
|
||||
)
|
||||
|
||||
@@ -180,8 +173,5 @@ export const mikroOrmFreeTextSearchFilterOptionsFactory = (
|
||||
$or: freeTextSearchWhere,
|
||||
}
|
||||
},
|
||||
default: true,
|
||||
args: false,
|
||||
entity: models.map((m) => m.name) as string[],
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import {
|
||||
LoadStrategy,
|
||||
FilterQuery as MikroFilterQuery,
|
||||
FindOptions as MikroOptions,
|
||||
ReferenceType,
|
||||
ReferenceKind,
|
||||
} from "@mikro-orm/core"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import {
|
||||
@@ -245,24 +245,6 @@ export class MikroOrmBaseRepository<const T extends object = object>
|
||||
|
||||
return [entities, softDeletedEntitiesMap]
|
||||
}
|
||||
|
||||
applyFreeTextSearchFilters<T>(
|
||||
findOptions: DAL.FindOptions<T & { q?: string }>,
|
||||
retrieveConstraintsToApply: (q: string) => any[]
|
||||
): void {
|
||||
if (!("q" in findOptions.where) || !findOptions.where.q) {
|
||||
delete findOptions.where.q
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
const q = findOptions.where.q as string
|
||||
delete findOptions.where.q
|
||||
|
||||
findOptions.where = {
|
||||
$and: [findOptions.where, { $or: retrieveConstraintsToApply(q) }],
|
||||
} as unknown as DAL.FindOptions<T & { q?: string }>["where"]
|
||||
}
|
||||
}
|
||||
|
||||
export class MikroOrmBaseTreeRepository<
|
||||
@@ -391,7 +373,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
const relation = relations.find((relation) => relation.name === key)
|
||||
const shouldInit =
|
||||
relation &&
|
||||
relation.reference === ReferenceType.MANY_TO_MANY &&
|
||||
relation.kind === ReferenceKind.MANY_TO_MANY &&
|
||||
Array.isArray(update[key]) &&
|
||||
!update[key].length
|
||||
|
||||
@@ -434,7 +416,9 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
await this.initManyToManyToDetachAllItemsIfNeeded(data, context)
|
||||
|
||||
data.map((_, index) => {
|
||||
manager.assign(data[index].entity, data[index].update)
|
||||
manager.assign(data[index].entity, data[index].update, {
|
||||
mergeObjectProperties: true,
|
||||
})
|
||||
manager.persist(data[index].entity)
|
||||
})
|
||||
|
||||
@@ -578,7 +562,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
const existingEntity = existingEntitiesMap.get(key)
|
||||
if (existingEntity) {
|
||||
const updatedType = manager.assign(existingEntity, data_)
|
||||
updatedEntities.push(updatedType)
|
||||
updatedEntities.push(updatedType as any)
|
||||
} else {
|
||||
const newEntity = manager.create(this.entity, data_)
|
||||
createdEntities.push(newEntity as InferRepositoryReturnType<T>)
|
||||
@@ -698,8 +682,8 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
// TODO: Handle ONE_TO_ONE
|
||||
// One to one and Many to one are handled outside of the assignment as they need to happen before the main entity is created
|
||||
if (
|
||||
relation.reference === ReferenceType.ONE_TO_ONE ||
|
||||
relation.reference === ReferenceType.MANY_TO_ONE
|
||||
relation.kind === ReferenceKind.ONE_TO_ONE ||
|
||||
relation.kind === ReferenceKind.MANY_TO_ONE
|
||||
) {
|
||||
return
|
||||
}
|
||||
@@ -765,7 +749,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
return this.getEntityWithId(manager, relation.type, normalizedItem)
|
||||
})
|
||||
|
||||
if (relation.reference === ReferenceType.MANY_TO_MANY) {
|
||||
if (relation.kind === ReferenceKind.MANY_TO_MANY) {
|
||||
const currentPivotColumn = relation.inverseJoinColumns[0]
|
||||
const parentPivotColumn = relation.joinColumns[0]
|
||||
|
||||
@@ -805,7 +789,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
return { entities: normalizedData, performedActions }
|
||||
}
|
||||
|
||||
if (relation.reference === ReferenceType.ONE_TO_MANY) {
|
||||
if (relation.kind === ReferenceKind.ONE_TO_MANY) {
|
||||
const joinColumns =
|
||||
relation.targetMeta?.properties[relation.mappedBy]?.joinColumns
|
||||
|
||||
@@ -815,7 +799,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
joinColumnsConstraints[joinColumn] = data[referencedColumnName]
|
||||
})
|
||||
|
||||
const toDeleteEntities = await manager.find<any>(
|
||||
const toDeleteEntities = await manager.find<any, any, "id">(
|
||||
relation.type,
|
||||
{
|
||||
...joinColumnsConstraints,
|
||||
@@ -869,7 +853,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
}
|
||||
|
||||
// If it is a many-to-one we ensure the ID is set for when we want to set/unset an association
|
||||
if (relation.reference === ReferenceType.MANY_TO_ONE) {
|
||||
if (relation.kind === ReferenceKind.MANY_TO_ONE) {
|
||||
if (originalData === null) {
|
||||
entryCopy[relation.joinColumns[0]] = null
|
||||
return null
|
||||
@@ -927,7 +911,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
|
||||
.filter(
|
||||
([_, propDef]: any) =>
|
||||
propDef.persist === false &&
|
||||
propDef.reference === ReferenceType.MANY_TO_ONE
|
||||
propDef.kind === ReferenceKind.MANY_TO_ONE
|
||||
)
|
||||
.forEach(([key]) => {
|
||||
delete resp[key]
|
||||
|
||||
@@ -7,36 +7,45 @@ import {
|
||||
Loaded,
|
||||
Platform,
|
||||
Reference,
|
||||
ReferenceType,
|
||||
ReferenceKind,
|
||||
SerializationContext,
|
||||
SerializeOptions,
|
||||
Utils,
|
||||
} from "@mikro-orm/core"
|
||||
|
||||
type CustomSerializeOptions<T, P = any> = SerializeOptions<T, P & string> & {
|
||||
preventCircularRef?: boolean
|
||||
populate?: [keyof T][] | boolean
|
||||
}
|
||||
|
||||
function isVisible<T extends object>(
|
||||
meta: EntityMetadata<T>,
|
||||
propName: string,
|
||||
options: SerializeOptions<T, any> & { preventCircularRef?: boolean } = {}
|
||||
options: CustomSerializeOptions<T> = {}
|
||||
): boolean {
|
||||
if (options.populate === true) {
|
||||
return options.populate
|
||||
return true
|
||||
}
|
||||
|
||||
if (
|
||||
Array.isArray(options.populate) &&
|
||||
options.populate?.find(
|
||||
options.exclude?.find((item) => item === propName)
|
||||
) {
|
||||
return false
|
||||
}
|
||||
|
||||
if (
|
||||
Array.isArray(options.populate) &&
|
||||
(options.populate?.find(
|
||||
(item) => item === propName || item.startsWith(propName + ".")
|
||||
)
|
||||
) ||
|
||||
options.populate.includes("*"))
|
||||
) {
|
||||
return true
|
||||
}
|
||||
|
||||
if (options.exclude?.find((item) => item === propName)) {
|
||||
return false
|
||||
}
|
||||
|
||||
const prop = meta.properties[propName]
|
||||
const visible = prop && !prop.hidden
|
||||
const visible = (prop && !prop.hidden) || prop === undefined // allow unknown properties
|
||||
const prefixed = prop && !prop.primary && propName.startsWith("_") // ignore prefixed properties, if it's not a PK
|
||||
|
||||
return visible && !prefixed
|
||||
@@ -45,13 +54,14 @@ function isVisible<T extends object>(
|
||||
function isPopulated<T extends object>(
|
||||
entity: T,
|
||||
propName: string,
|
||||
options: SerializeOptions<T, any>
|
||||
options: CustomSerializeOptions<T>
|
||||
): boolean {
|
||||
if (
|
||||
typeof options.populate !== "boolean" &&
|
||||
options.populate?.find(
|
||||
Array.isArray(options.populate) &&
|
||||
(options.populate?.find(
|
||||
(item) => item === propName || item.startsWith(propName + ".")
|
||||
)
|
||||
) ||
|
||||
options.populate.includes("*"))
|
||||
) {
|
||||
return true
|
||||
}
|
||||
@@ -78,9 +88,7 @@ function filterEntityPropToSerialize({
|
||||
}: {
|
||||
propName: string
|
||||
meta: EntityMetadata
|
||||
options: SerializeOptions<object, any> & {
|
||||
preventCircularRef?: boolean
|
||||
}
|
||||
options: CustomSerializeOptions<any>
|
||||
parents?: string[]
|
||||
}): boolean {
|
||||
parents ??= []
|
||||
@@ -92,7 +100,7 @@ function filterEntityPropToSerialize({
|
||||
prop &&
|
||||
options.preventCircularRef &&
|
||||
isVisibleRes &&
|
||||
prop.reference !== ReferenceType.SCALAR
|
||||
prop.kind !== ReferenceKind.SCALAR
|
||||
) {
|
||||
// mapToPk would represent a foreign key and we want to keep them
|
||||
if (!!prop.mapToPk) {
|
||||
@@ -108,7 +116,7 @@ function filterEntityPropToSerialize({
|
||||
export class EntitySerializer {
|
||||
static serialize<T extends object, P extends string = never>(
|
||||
entity: T,
|
||||
options: SerializeOptions<T, P> & { preventCircularRef?: boolean } = {},
|
||||
options: CustomSerializeOptions<T, P> = {},
|
||||
parents: string[] = []
|
||||
): EntityDTO<Loaded<T, P>> {
|
||||
const parents_ = Array.from(new Set(parents))
|
||||
@@ -118,12 +126,11 @@ export class EntitySerializer {
|
||||
let contextCreated = false
|
||||
|
||||
if (!wrapped.__serializationContext.root) {
|
||||
const root = new SerializationContext<T>()
|
||||
const root = new SerializationContext<T>({} as any)
|
||||
SerializationContext.propagate(
|
||||
root,
|
||||
entity,
|
||||
(meta, prop) =>
|
||||
meta.properties[prop]?.reference !== ReferenceType.SCALAR
|
||||
(meta, prop) => meta.properties[prop]?.kind !== ReferenceKind.SCALAR
|
||||
)
|
||||
contextCreated = true
|
||||
}
|
||||
@@ -238,25 +245,25 @@ export class EntitySerializer {
|
||||
|
||||
private static propertyName<T>(
|
||||
meta: EntityMetadata<T>,
|
||||
prop: keyof T & string,
|
||||
prop: string,
|
||||
platform?: Platform
|
||||
): string {
|
||||
/* istanbul ignore next */
|
||||
if (meta.properties[prop]?.serializedName) {
|
||||
return meta.properties[prop].serializedName as keyof T & string
|
||||
return meta.properties[prop].serializedName as string
|
||||
}
|
||||
|
||||
if (meta.properties[prop]?.primary && platform) {
|
||||
return platform.getSerializedPrimaryKeyField(prop) as keyof T & string
|
||||
return platform.getSerializedPrimaryKeyField(prop) as string
|
||||
}
|
||||
|
||||
return prop
|
||||
}
|
||||
|
||||
private static processProperty<T extends object>(
|
||||
prop: keyof T & string,
|
||||
prop: string,
|
||||
entity: T,
|
||||
options: SerializeOptions<T, any>,
|
||||
options: CustomSerializeOptions<T>,
|
||||
parents: string[] = []
|
||||
): T[keyof T] | undefined {
|
||||
const parents_ = [...parents, entity.constructor.name]
|
||||
@@ -284,12 +291,17 @@ export class EntitySerializer {
|
||||
}
|
||||
|
||||
if (Utils.isCollection(entity[prop])) {
|
||||
return this.processCollection(prop, entity, options, parents_)
|
||||
return this.processCollection(
|
||||
prop as keyof T & string,
|
||||
entity,
|
||||
options,
|
||||
parents_
|
||||
)
|
||||
}
|
||||
|
||||
if (Utils.isEntity(entity[prop], true)) {
|
||||
return this.processEntity(
|
||||
prop,
|
||||
prop as keyof T & string,
|
||||
entity,
|
||||
wrapped.__platform,
|
||||
options,
|
||||
@@ -298,7 +310,7 @@ export class EntitySerializer {
|
||||
}
|
||||
|
||||
/* istanbul ignore next */
|
||||
if (property?.reference === ReferenceType.EMBEDDED) {
|
||||
if (property?.reference === ReferenceKind.EMBEDDED) {
|
||||
if (Array.isArray(entity[prop])) {
|
||||
return (entity[prop] as object[]).map((item) =>
|
||||
helper(item).toJSON()
|
||||
@@ -322,9 +334,9 @@ export class EntitySerializer {
|
||||
}
|
||||
|
||||
private static extractChildOptions<T extends object, U extends object>(
|
||||
options: SerializeOptions<T, any>,
|
||||
options: CustomSerializeOptions<T>,
|
||||
prop: keyof T & string
|
||||
): SerializeOptions<U, any> {
|
||||
): CustomSerializeOptions<U> {
|
||||
const extractChildElements = (items: string[]) => {
|
||||
return items
|
||||
.filter((field) => field.startsWith(`${prop}.`))
|
||||
@@ -333,20 +345,22 @@ export class EntitySerializer {
|
||||
|
||||
return {
|
||||
...options,
|
||||
populate: Array.isArray(options.populate)
|
||||
? extractChildElements(options.populate)
|
||||
populate:
|
||||
Array.isArray(options.populate) && !options.populate.includes("*")
|
||||
? extractChildElements(options.populate as unknown as string[])
|
||||
: options.populate,
|
||||
exclude: Array.isArray(options.exclude)
|
||||
exclude:
|
||||
Array.isArray(options.exclude) && !options.exclude.includes("*")
|
||||
? extractChildElements(options.exclude)
|
||||
: options.exclude,
|
||||
} as SerializeOptions<U, any>
|
||||
} as CustomSerializeOptions<U>
|
||||
}
|
||||
|
||||
private static processEntity<T extends object>(
|
||||
prop: keyof T & string,
|
||||
entity: T,
|
||||
platform: Platform,
|
||||
options: SerializeOptions<T, any>,
|
||||
options: CustomSerializeOptions<T>,
|
||||
parents: string[] = []
|
||||
): T[keyof T] | undefined {
|
||||
const parents_ = [...parents, entity.constructor.name]
|
||||
@@ -373,7 +387,7 @@ export class EntitySerializer {
|
||||
private static processCollection<T extends object>(
|
||||
prop: keyof T & string,
|
||||
entity: T,
|
||||
options: SerializeOptions<T, any>,
|
||||
options: CustomSerializeOptions<T>,
|
||||
parents: string[] = []
|
||||
): T[keyof T] | undefined {
|
||||
const parents_ = [...parents, entity.constructor.name]
|
||||
@@ -401,6 +415,7 @@ export const mikroOrmSerializer = <TOutput extends object>(
|
||||
data: any,
|
||||
options?: Parameters<typeof EntitySerializer.serialize>[1] & {
|
||||
preventCircularRef?: boolean
|
||||
populate?: string[] | boolean
|
||||
}
|
||||
): Promise<TOutput> => {
|
||||
return new Promise<TOutput>((resolve) => {
|
||||
@@ -422,10 +437,11 @@ export const mikroOrmSerializer = <TOutput extends object>(
|
||||
let result: any = forSerialization.map((entity) =>
|
||||
EntitySerializer.serialize(entity, {
|
||||
forceObject: true,
|
||||
populate: true,
|
||||
populate: ["*"],
|
||||
|
||||
preventCircularRef: true,
|
||||
...options,
|
||||
} as SerializeOptions<any, any>)
|
||||
} as CustomSerializeOptions<any>)
|
||||
) as TOutput[]
|
||||
|
||||
if (notForSerialization.length) {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -6,6 +6,7 @@ import {
|
||||
import { DmlEntity, DMLEntitySchemaBuilder } from "./entity"
|
||||
import { createBigNumberProperties } from "./helpers/entity-builder/create-big-number-properties"
|
||||
import { createDefaultProperties } from "./helpers/entity-builder/create-default-properties"
|
||||
import { FloatProperty } from "./properties"
|
||||
import { ArrayProperty } from "./properties/array"
|
||||
import { AutoIncrementProperty } from "./properties/autoincrement"
|
||||
import { BigNumberProperty } from "./properties/big-number"
|
||||
@@ -21,7 +22,6 @@ import { HasMany } from "./relations/has-many"
|
||||
import { HasOne } from "./relations/has-one"
|
||||
import { HasOneWithForeignKey } from "./relations/has-one-fk"
|
||||
import { ManyToMany } from "./relations/many-to-many"
|
||||
import { FloatProperty } from "./properties"
|
||||
|
||||
/**
|
||||
* The implicit properties added by EntityBuilder in every schema
|
||||
@@ -128,7 +128,7 @@ export class EntityBuilder {
|
||||
): DmlEntity<DMLEntitySchemaBuilder<Schema>, TConfig> {
|
||||
this.#disallowImplicitProperties(schema)
|
||||
|
||||
return new DmlEntity<Schema, TConfig>(nameOrConfig, {
|
||||
return new DmlEntity(nameOrConfig, {
|
||||
...schema,
|
||||
...createBigNumberProperties(schema),
|
||||
...createDefaultProperties(),
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
import {
|
||||
IDmlEntity,
|
||||
DMLSchema,
|
||||
EntityIndex,
|
||||
CheckConstraint,
|
||||
DMLSchema,
|
||||
EntityCascades,
|
||||
QueryCondition,
|
||||
IDmlEntityConfig,
|
||||
EntityIndex,
|
||||
ExtractEntityRelations,
|
||||
IDmlEntity,
|
||||
IDmlEntityConfig,
|
||||
InferDmlEntityNameFromConfig,
|
||||
QueryCondition,
|
||||
} from "@medusajs/types"
|
||||
import { isObject, isString, toCamelCase, upperCaseFirst } from "../common"
|
||||
import { transformIndexWhere } from "./helpers/entity-builder/build-indexes"
|
||||
import { DMLSchemaWithBigNumber } from "./helpers/entity-builder/create-big-number-properties"
|
||||
import { DMLSchemaDefaults } from "./helpers/entity-builder/create-default-properties"
|
||||
import { BelongsTo } from "./relations/belongs-to"
|
||||
import {
|
||||
DMLSchemaDefaults,
|
||||
DMLSchemaWithBigNumber,
|
||||
} from "./helpers/entity-builder"
|
||||
|
||||
const IsDmlEntity = Symbol.for("isDmlEntity")
|
||||
|
||||
@@ -68,7 +66,7 @@ function extractNameAndTableName<const Config extends IDmlEntityConfig>(
|
||||
* name, its schema and relationships.
|
||||
*/
|
||||
export class DmlEntity<
|
||||
Schema extends DMLSchema,
|
||||
const Schema extends DMLSchema,
|
||||
const TConfig extends IDmlEntityConfig
|
||||
> implements IDmlEntity<Schema, TConfig>
|
||||
{
|
||||
@@ -79,6 +77,7 @@ export class DmlEntity<
|
||||
|
||||
readonly #tableName: string
|
||||
#cascades: EntityCascades<string[], string[]> = {}
|
||||
|
||||
#indexes: EntityIndex<Schema>[] = []
|
||||
#checks: CheckConstraint<Schema>[] = []
|
||||
|
||||
@@ -251,8 +250,6 @@ export class DmlEntity<
|
||||
return this
|
||||
}
|
||||
|
||||
/**
|
||||
*/
|
||||
checks(checks: CheckConstraint<Schema>[]) {
|
||||
this.#checks = checks
|
||||
return this
|
||||
|
||||
@@ -8,15 +8,18 @@ import type {
|
||||
} from "@medusajs/types"
|
||||
import { Entity, Filter } from "@mikro-orm/core"
|
||||
|
||||
import {
|
||||
mikroOrmFreeTextSearchFilterOptionsFactory,
|
||||
mikroOrmSoftDeletableFilterOptions,
|
||||
} from "../../dal"
|
||||
import { DmlEntity } from "../entity"
|
||||
import { IdProperty } from "../properties/id"
|
||||
import { DuplicateIdPropertyError } from "../errors"
|
||||
import { applyChecks } from "./mikro-orm/apply-checks"
|
||||
import { mikroOrmSoftDeletableFilterOptions } from "../../dal"
|
||||
import { defineProperty } from "./entity-builder/define-property"
|
||||
import { IdProperty } from "../properties/id"
|
||||
import { applySearchable } from "./entity-builder/apply-searchable"
|
||||
import { parseEntityName } from "./entity-builder/parse-entity-name"
|
||||
import { defineProperty } from "./entity-builder/define-property"
|
||||
import { defineRelationship } from "./entity-builder/define-relationship"
|
||||
import { parseEntityName } from "./entity-builder/parse-entity-name"
|
||||
import { applyChecks } from "./mikro-orm/apply-checks"
|
||||
import { applyEntityIndexes, applyIndexes } from "./mikro-orm/apply-indexes"
|
||||
|
||||
/**
|
||||
@@ -48,8 +51,16 @@ function createMikrORMEntity() {
|
||||
function createEntity<T extends DmlEntity<any, any>>(entity: T): Infer<T> {
|
||||
class MikroORMEntity {}
|
||||
|
||||
const { schema, cascades, indexes: entityIndexes, checks } = entity.parse()
|
||||
const {
|
||||
schema,
|
||||
cascades,
|
||||
indexes: entityIndexes = [],
|
||||
//params,
|
||||
checks,
|
||||
} = entity.parse()
|
||||
|
||||
const { modelName, tableName } = parseEntityName(entity)
|
||||
|
||||
if (ENTITIES[modelName]) {
|
||||
return ENTITIES[modelName] as Infer<T>
|
||||
}
|
||||
@@ -102,6 +113,9 @@ function createMikrORMEntity() {
|
||||
/**
|
||||
* Converting class to a MikroORM entity
|
||||
*/
|
||||
Filter(mikroOrmFreeTextSearchFilterOptionsFactory(modelName))(
|
||||
MikroORMEntity
|
||||
)
|
||||
const RegisteredEntity = Entity({ tableName })(
|
||||
Filter(mikroOrmSoftDeletableFilterOptions)(MikroORMEntity)
|
||||
) as Infer<T>
|
||||
|
||||
@@ -12,7 +12,6 @@ import {
|
||||
PrimaryKey,
|
||||
Property,
|
||||
Utils,
|
||||
t as mikroOrmType,
|
||||
} from "@mikro-orm/core"
|
||||
import { generateEntityId, isDefined } from "../../../common"
|
||||
import { MikroOrmBigNumberProperty } from "../../../dal"
|
||||
@@ -122,7 +121,8 @@ export function defineProperty(
|
||||
) {
|
||||
const field = property.parse(propertyName)
|
||||
/**
|
||||
* Here we initialize nullable properties with a null value
|
||||
* Here we initialize all properties with their default values on before create
|
||||
* which means when persist is called but not necessarely flush
|
||||
*/
|
||||
if (isDefined(field.defaultValue) || field.nullable) {
|
||||
const defaultValueSetterHookName = `${field.fieldName}_setDefaultValueOnBeforeCreate`
|
||||
@@ -274,11 +274,12 @@ export function defineProperty(
|
||||
: Property
|
||||
|
||||
Prop({
|
||||
columnType: "serial",
|
||||
type: mikroOrmType.integer,
|
||||
nullable: true,
|
||||
autoincrement: true,
|
||||
type: "number",
|
||||
runtimeType: "number",
|
||||
nullable: field.nullable,
|
||||
fieldName: field.fieldName,
|
||||
serializer: Number,
|
||||
serializer: (value) => (value == null ? value : Number(value)),
|
||||
})(MikroORMEntity.prototype, field.fieldName)
|
||||
return
|
||||
}
|
||||
@@ -290,13 +291,14 @@ export function defineProperty(
|
||||
Property({
|
||||
columnType: "real",
|
||||
type: "number",
|
||||
runtimeType: "number",
|
||||
nullable: field.nullable,
|
||||
fieldName: field.fieldName,
|
||||
/**
|
||||
* Applying number serializer to convert value back to a
|
||||
* JavaScript number
|
||||
*/
|
||||
serializer: Number,
|
||||
serializer: (value) => (value == null ? value : Number(value)),
|
||||
/**
|
||||
* MikroORM does not ignore undefined values for default when generating
|
||||
* the database schema SQL. Conditionally add it here to prevent undefined
|
||||
|
||||
@@ -162,7 +162,7 @@ export function defineHasOneRelationship(
|
||||
entity: relatedModelName,
|
||||
...(relationship.nullable ? { nullable: relationship.nullable } : {}),
|
||||
...(mappedBy ? { mappedBy } : {}),
|
||||
onDelete: shouldRemoveRelated ? "cascade" : undefined,
|
||||
deleteRule: shouldRemoveRelated ? "cascade" : undefined,
|
||||
} as OneToOneOptions<any, any>
|
||||
|
||||
if (shouldRemoveRelated && !isOthersideBelongsTo) {
|
||||
@@ -322,7 +322,7 @@ export function defineBelongsToRelationship(
|
||||
/**
|
||||
* In DML the relationships are cascaded from parent to child. A belongsTo
|
||||
* relationship is always a child, therefore we look at the parent and
|
||||
* define a onDelete: cascade when we are included in the delete
|
||||
* define a deleteRule: cascade when we are included in the delete
|
||||
* list of parent cascade.
|
||||
*/
|
||||
const shouldCascade = !!relationCascades.delete?.includes(mappedBy)
|
||||
@@ -435,27 +435,33 @@ export function defineBelongsToRelationship(
|
||||
|
||||
if (DmlManyToMany.isManyToMany(otherSideRelation)) {
|
||||
Property({
|
||||
type: relatedModelName,
|
||||
type: "string",
|
||||
columnType: "text",
|
||||
fieldName: foreignKeyName,
|
||||
nullable: relationship.nullable,
|
||||
})(MikroORMEntity.prototype, foreignKeyName)
|
||||
|
||||
ManyToOne({
|
||||
const conf = {
|
||||
entity: relatedModelName,
|
||||
nullable: relationship.nullable,
|
||||
persist: false,
|
||||
onDelete: shouldCascade || detachCascade ? "cascade" : undefined,
|
||||
})(MikroORMEntity.prototype, relationship.name)
|
||||
}
|
||||
if (shouldCascade || detachCascade) {
|
||||
conf["deleteRule"] = "cascade"
|
||||
}
|
||||
ManyToOne(conf)(MikroORMEntity.prototype, relationship.name)
|
||||
} else {
|
||||
ManyToOne({
|
||||
const conf = {
|
||||
entity: relatedModelName,
|
||||
columnType: "text",
|
||||
mapToPk: true,
|
||||
fieldName: foreignKeyName,
|
||||
nullable: relationship.nullable,
|
||||
onDelete: shouldCascade ? "cascade" : undefined,
|
||||
})(MikroORMEntity.prototype, foreignKeyName)
|
||||
}
|
||||
if (shouldCascade) {
|
||||
conf["deleteRule"] = "cascade"
|
||||
}
|
||||
ManyToOne(conf)(MikroORMEntity.prototype, foreignKeyName)
|
||||
|
||||
ManyToOne({
|
||||
entity: relatedModelName,
|
||||
@@ -486,7 +492,6 @@ export function defineBelongsToRelationship(
|
||||
const foreignKeyName =
|
||||
relationship.options.foreignKeyName ??
|
||||
camelToSnakeCase(`${relationship.name}Id`)
|
||||
|
||||
Property({
|
||||
columnType: "text",
|
||||
type: "string",
|
||||
@@ -504,10 +509,10 @@ export function defineBelongsToRelationship(
|
||||
fieldName: foreignKeyName,
|
||||
owner: true,
|
||||
// orphanRemoval: true,
|
||||
onDelete: shouldCascade ? "cascade" : undefined,
|
||||
}
|
||||
|
||||
if (shouldCascade) {
|
||||
oneToOneOptions.deleteRule = "cascade"
|
||||
oneToOneOptions.cascade = [Cascade.PERSIST, "soft-remove"] as any
|
||||
}
|
||||
|
||||
@@ -741,8 +746,15 @@ export function defineManyToManyRelationship(
|
||||
: {}),
|
||||
...(pivotEntityName ? { pivotEntity: pivotEntityName } : {}),
|
||||
...({ [mappedByProp]: mappedByPropValue } as any),
|
||||
[joinColumnProp]: joinColumn ?? joinColumns,
|
||||
[inverseJoinColumnProp]: inverseJoinColumn ?? inverseJoinColumns,
|
||||
} as any
|
||||
|
||||
if (joinColumn || joinColumns) {
|
||||
manytoManyOptions[joinColumnProp] = joinColumn ?? joinColumns
|
||||
}
|
||||
|
||||
if (inverseJoinColumn || inverseJoinColumns) {
|
||||
manytoManyOptions[inverseJoinColumnProp] =
|
||||
inverseJoinColumn ?? inverseJoinColumns
|
||||
}
|
||||
|
||||
ManyToMany(manytoManyOptions)(MikroORMEntity.prototype, relationship.name)
|
||||
|
||||
@@ -4,3 +4,5 @@ export * from "./helpers/entity-builder/index"
|
||||
export * from "./helpers/create-mikro-orm-entity"
|
||||
export * from "./relations/index"
|
||||
export * from "./properties/index"
|
||||
|
||||
export * from "./helpers/entity-builder/index"
|
||||
@@ -1,15 +1,16 @@
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { MetadataStorage, MikroORM } from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { join } from "path"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { model } from "../../entity-builder"
|
||||
import {
|
||||
mikroORMEntityBuilder,
|
||||
toMikroOrmEntities,
|
||||
} from "../../helpers/create-mikro-orm-entity"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { pgGodCredentials } from "../utils"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { join } from "path"
|
||||
|
||||
export const fileSystem = new FileSystem(
|
||||
join(__dirname, "../../integration-tests-migrations-enum")
|
||||
@@ -40,19 +41,20 @@ describe("EntityBuilder", () => {
|
||||
|
||||
await createDatabase({ databaseName: dbName }, pgGodCredentials)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [User],
|
||||
tsNode: true,
|
||||
dbName,
|
||||
password: pgGodCredentials.password,
|
||||
host: pgGodCredentials.host,
|
||||
user: pgGodCredentials.user,
|
||||
type: "postgresql",
|
||||
migrations: {
|
||||
generator: CustomTsMigrationGenerator,
|
||||
path: fileSystem.basePath,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const migrator = orm.getMigrator()
|
||||
await migrator.createMigration()
|
||||
|
||||
@@ -1,19 +1,20 @@
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import {
|
||||
CheckConstraintViolationException,
|
||||
MetadataStorage,
|
||||
MikroORM,
|
||||
} from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { join } from "path"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { model } from "../../entity-builder"
|
||||
import {
|
||||
mikroORMEntityBuilder,
|
||||
toMikroOrmEntities,
|
||||
} from "../../helpers/create-mikro-orm-entity"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { pgGodCredentials } from "../utils"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { join } from "path"
|
||||
|
||||
export const fileSystem = new FileSystem(
|
||||
join(__dirname, "../../integration-tests-migrations-enum")
|
||||
@@ -43,19 +44,20 @@ describe("EntityBuilder | enum", () => {
|
||||
|
||||
await createDatabase({ databaseName: dbName }, pgGodCredentials)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [User],
|
||||
tsNode: true,
|
||||
dbName,
|
||||
password: pgGodCredentials.password,
|
||||
host: pgGodCredentials.host,
|
||||
user: pgGodCredentials.user,
|
||||
type: "postgresql",
|
||||
migrations: {
|
||||
generator: CustomTsMigrationGenerator,
|
||||
path: fileSystem.basePath,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const migrator = orm.getMigrator()
|
||||
await migrator.createMigration()
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { MetadataStorage, MikroORM } from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { join } from "path"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { model } from "../../entity-builder"
|
||||
import {
|
||||
mikroORMEntityBuilder,
|
||||
toMikroOrmEntities,
|
||||
} from "../../helpers/create-mikro-orm-entity"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { pgGodCredentials } from "../utils"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { join } from "path"
|
||||
|
||||
export const fileSystem = new FileSystem(
|
||||
join(__dirname, "../../integration-tests-migrations-has-one-belongs-to")
|
||||
@@ -45,19 +46,20 @@ describe("hasOne - belongTo", () => {
|
||||
|
||||
await createDatabase({ databaseName: dbName }, pgGodCredentials)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [Team, User],
|
||||
tsNode: true,
|
||||
dbName,
|
||||
password: pgGodCredentials.password,
|
||||
host: pgGodCredentials.host,
|
||||
user: pgGodCredentials.user,
|
||||
type: "postgresql",
|
||||
migrations: {
|
||||
generator: CustomTsMigrationGenerator,
|
||||
path: fileSystem.basePath,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const migrator = orm.getMigrator()
|
||||
await migrator.createMigration()
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { join } from "path"
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { MetadataStorage, MikroORM } from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { join } from "path"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { model } from "../../entity-builder"
|
||||
import {
|
||||
mikroORMEntityBuilder,
|
||||
toMikroOrmEntities,
|
||||
} from "../../helpers/create-mikro-orm-entity"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { CustomTsMigrationGenerator, mikroOrmSerializer } from "../../../dal"
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { pgGodCredentials } from "../utils"
|
||||
import { FileSystem } from "../../../common"
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -62,19 +63,20 @@ describe("manyToMany - manyToMany", () => {
|
||||
|
||||
await createDatabase({ databaseName: dbName }, pgGodCredentials)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [Team, User, Squad],
|
||||
tsNode: true,
|
||||
dbName,
|
||||
password: pgGodCredentials.password,
|
||||
host: pgGodCredentials.host,
|
||||
user: pgGodCredentials.user,
|
||||
type: "postgresql",
|
||||
migrations: {
|
||||
generator: CustomTsMigrationGenerator,
|
||||
path: fileSystem.basePath,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const migrator = orm.getMigrator()
|
||||
await migrator.createMigration()
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { MetadataStorage, MikroORM } from "@mikro-orm/core"
|
||||
import { model } from "../../entity-builder"
|
||||
import {
|
||||
mikroORMEntityBuilder,
|
||||
toMikroOrmEntities,
|
||||
} from "../../helpers/create-mikro-orm-entity"
|
||||
import { defineConfig, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { join } from "path"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { FileSystem } from "../../../common"
|
||||
import {
|
||||
CustomTsMigrationGenerator,
|
||||
mikroOrmSerializer,
|
||||
mikroOrmUpdateDeletedAtRecursively,
|
||||
SoftDeletableFilterKey,
|
||||
} from "../../../dal"
|
||||
import { EntityConstructor } from "@medusajs/types"
|
||||
import { model } from "../../entity-builder"
|
||||
import {
|
||||
mikroORMEntityBuilder,
|
||||
toMikroOrmEntities,
|
||||
} from "../../helpers/create-mikro-orm-entity"
|
||||
import { pgGodCredentials } from "../utils"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { join } from "path"
|
||||
import { SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
|
||||
export const fileSystem = new FileSystem(
|
||||
join(__dirname, "../../integration-tests-migrations-many-to-one")
|
||||
@@ -55,19 +55,20 @@ describe("manyToOne - belongTo", () => {
|
||||
|
||||
await createDatabase({ databaseName: dbName }, pgGodCredentials)
|
||||
|
||||
orm = await MikroORM.init({
|
||||
orm = await MikroORM.init(
|
||||
defineConfig({
|
||||
entities: [Team, User],
|
||||
tsNode: true,
|
||||
dbName,
|
||||
password: pgGodCredentials.password,
|
||||
host: pgGodCredentials.host,
|
||||
user: pgGodCredentials.user,
|
||||
type: "postgresql",
|
||||
migrations: {
|
||||
generator: CustomTsMigrationGenerator,
|
||||
path: fileSystem.basePath,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
const migrator = orm.getMigrator()
|
||||
await migrator.createMigration()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? "postgres"
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||
|
||||
export const pgGodCredentials = {
|
||||
|
||||
@@ -8,7 +8,10 @@ import { PrimaryKeyModifier } from "./primary-key"
|
||||
export class NumberProperty extends BaseProperty<number> {
|
||||
protected dataType: {
|
||||
name: "number"
|
||||
options: {}
|
||||
options: {
|
||||
primaryKey?: boolean
|
||||
searchable?: boolean
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,6 +33,27 @@ export class NumberProperty extends BaseProperty<number> {
|
||||
return new PrimaryKeyModifier<number, NumberProperty>(this)
|
||||
}
|
||||
|
||||
/**
|
||||
* This method indicates that a number property is searchable.
|
||||
*
|
||||
* @example
|
||||
* import { model } from "@medusajs/framework/utils"
|
||||
*
|
||||
* const MyCustom = model.define("my_custom", {
|
||||
* name: model.number().searchable(),
|
||||
* // ...
|
||||
* })
|
||||
*
|
||||
* export default MyCustom
|
||||
*
|
||||
* @customNamespace Property Configuration Methods
|
||||
*/
|
||||
searchable() {
|
||||
this.dataType.options.searchable = true
|
||||
|
||||
return this
|
||||
}
|
||||
|
||||
constructor(options?: { primaryKey?: boolean }) {
|
||||
super()
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import {
|
||||
MigrationResult,
|
||||
UmzugMigration,
|
||||
} from "@mikro-orm/migrations"
|
||||
import { PostgreSqlDriver } from "@mikro-orm/postgresql"
|
||||
import { defineConfig, PostgreSqlDriver } from "@mikro-orm/postgresql"
|
||||
import { EventEmitter } from "events"
|
||||
import { access, mkdir, writeFile } from "fs/promises"
|
||||
import { dirname } from "path"
|
||||
@@ -42,13 +42,15 @@ export class Migrations extends EventEmitter<MigrationsEvents> {
|
||||
return this.#configOrConnection as MikroORM<PostgreSqlDriver>
|
||||
}
|
||||
|
||||
return await MikroORM.init({
|
||||
...this.#configOrConnection,
|
||||
return await MikroORM.init(
|
||||
defineConfig({
|
||||
...(this.#configOrConnection as any),
|
||||
migrations: {
|
||||
...this.#configOrConnection.migrations,
|
||||
silent: true,
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+7
-7
@@ -1,13 +1,13 @@
|
||||
import { join } from "path"
|
||||
import { MikroORM } from "@mikro-orm/postgresql"
|
||||
import { MetadataStorage } from "@mikro-orm/core"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
import { TSMigrationGenerator } from "@mikro-orm/migrations"
|
||||
import { MikroORM } from "@mikro-orm/postgresql"
|
||||
import { join } from "path"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
|
||||
import { model } from "../../../dml"
|
||||
import { FileSystem } from "../../../common"
|
||||
import { Migrations, MigrationsEvents } from "../../index"
|
||||
import { model } from "../../../dml"
|
||||
import { defineMikroOrmCliConfig } from "../../../modules-sdk"
|
||||
import { Migrations, MigrationsEvents } from "../../index"
|
||||
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
@@ -22,8 +22,8 @@ const migrationFileNameGenerator = (_: string, name?: string) => {
|
||||
}
|
||||
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
user: DB_USERNAME ?? "postgres",
|
||||
password: DB_PASSWORD ?? "",
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@ const moduleName = "myTestServiceRun"
|
||||
const fs = new FileSystem(join(__dirname, "./migrations-run"))
|
||||
|
||||
const pgGodCredentials = {
|
||||
user: DB_USERNAME,
|
||||
password: DB_PASSWORD,
|
||||
user: DB_USERNAME ?? "postgres",
|
||||
password: DB_PASSWORD ?? "",
|
||||
host: DB_HOST,
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ describe("defineMikroOrmCliConfig", () => {
|
||||
|
||||
expect(config).toEqual({
|
||||
entities: [{}],
|
||||
type: "postgresql",
|
||||
driver: expect.any(Function),
|
||||
host: "127.0.0.1",
|
||||
user: "postgres",
|
||||
password: "",
|
||||
@@ -37,7 +37,7 @@ describe("defineMikroOrmCliConfig", () => {
|
||||
|
||||
expect(config).toEqual({
|
||||
entities: [{}],
|
||||
type: "postgresql",
|
||||
driver: expect.any(Function),
|
||||
dbName: "medusa-my-test",
|
||||
host: "127.0.0.1",
|
||||
user: "postgres",
|
||||
|
||||
@@ -2,11 +2,7 @@ import { Logger, MedusaContainer, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { PostgreSqlDriver, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import { asValue } from "awilix"
|
||||
import { ContainerRegistrationKeys, MedusaError } from "../../common"
|
||||
import {
|
||||
FreeTextSearchFilterKey,
|
||||
mikroOrmCreateConnection,
|
||||
mikroOrmFreeTextSearchFilterOptionsFactory,
|
||||
} from "../../dal"
|
||||
import { mikroOrmCreateConnection } from "../../dal"
|
||||
import { isSharedConnectionSymbol } from "../create-pg-connection"
|
||||
import { loadDatabaseConfig } from "../load-module-database-config"
|
||||
|
||||
@@ -39,9 +35,6 @@ export async function mikroOrmConnectionLoader({
|
||||
logger?: Logger
|
||||
pathToMigrations: string
|
||||
}) {
|
||||
const freeTextSearchGlobalFilter =
|
||||
mikroOrmFreeTextSearchFilterOptionsFactory(entities)
|
||||
|
||||
let manager = (
|
||||
options as ModulesSdkTypes.ModuleServiceInitializeCustomDataLayerOptions
|
||||
)?.manager
|
||||
@@ -68,9 +61,6 @@ export async function mikroOrmConnectionLoader({
|
||||
return await loadShared({
|
||||
database: {
|
||||
...dbConfig,
|
||||
filters: {
|
||||
[FreeTextSearchFilterKey as string]: freeTextSearchGlobalFilter,
|
||||
},
|
||||
},
|
||||
container,
|
||||
entities,
|
||||
@@ -98,9 +88,6 @@ export async function mikroOrmConnectionLoader({
|
||||
manager ??= await loadDefault({
|
||||
database: {
|
||||
...dbConfig,
|
||||
filters: {
|
||||
[FreeTextSearchFilterKey as string]: freeTextSearchGlobalFilter,
|
||||
},
|
||||
},
|
||||
entities,
|
||||
pathToMigrations,
|
||||
|
||||
@@ -2,9 +2,9 @@ import {
|
||||
BaseFilterable,
|
||||
Context,
|
||||
FilterQuery,
|
||||
FilterQuery as InternalFilterQuery,
|
||||
FindConfig,
|
||||
InferEntityType,
|
||||
FilterQuery as InternalFilterQuery,
|
||||
ModulesSdkTypes,
|
||||
PerformedActions,
|
||||
UpsertWithReplaceConfig,
|
||||
@@ -18,7 +18,7 @@ import {
|
||||
lowerCaseFirst,
|
||||
MedusaError,
|
||||
} from "../common"
|
||||
import { FreeTextSearchFilterKey } from "../dal"
|
||||
import { FreeTextSearchFilterKeyPrefix } from "../dal"
|
||||
import { DmlEntity, toMikroORMEntity } from "../dml"
|
||||
import { buildQuery } from "./build-query"
|
||||
import {
|
||||
@@ -67,7 +67,7 @@ export function MedusaInternalService<
|
||||
): void {
|
||||
if (isDefined(filters?.q)) {
|
||||
config.filters ??= {}
|
||||
config.filters[FreeTextSearchFilterKey] = {
|
||||
config.filters[FreeTextSearchFilterKeyPrefix + model.name] = {
|
||||
value: filters.q,
|
||||
fromEntity: model.name,
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import type {
|
||||
EntitySchema,
|
||||
MikroORMOptions,
|
||||
} from "@mikro-orm/core"
|
||||
import { defineConfig } from "@mikro-orm/postgresql"
|
||||
import { kebabCase } from "../common"
|
||||
import { CustomTsMigrationGenerator } from "../dal"
|
||||
import { DmlEntity, toMikroOrmEntities } from "../dml"
|
||||
@@ -21,7 +22,6 @@ type Options = Partial<Omit<MikroORMOptions, "entities" | "entitiesTs">> & {
|
||||
|
||||
type ReturnedOptions = Partial<MikroORMOptions> & {
|
||||
entities: MikroORMOptions["entities"]
|
||||
type: MikroORMOptions["type"]
|
||||
migrations: MikroORMOptions["migrations"]
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ export function defineMikroOrmCliConfig(
|
||||
|
||||
const dmlEntities = options.entities.filter(DmlEntity.isDmlEntity)
|
||||
const nonDmlEntities = options.entities.filter(
|
||||
(entity) => !DmlEntity.isDmlEntity(entity)
|
||||
(entity) => entity && !DmlEntity.isDmlEntity(entity)
|
||||
)
|
||||
|
||||
const entities = nonDmlEntities.concat(
|
||||
@@ -53,17 +53,16 @@ export function defineMikroOrmCliConfig(
|
||||
const normalizedModuleName = kebabCase(moduleName.replace("Service", ""))
|
||||
const databaseName = `medusa-${normalizedModuleName}`
|
||||
|
||||
return {
|
||||
type: "postgresql",
|
||||
return defineConfig({
|
||||
dbName: databaseName,
|
||||
host: "127.0.0.1",
|
||||
user: "postgres",
|
||||
password: "",
|
||||
...options,
|
||||
...(options as any),
|
||||
entities,
|
||||
migrations: {
|
||||
generator: CustomTsMigrationGenerator,
|
||||
...options.migrations,
|
||||
},
|
||||
}
|
||||
}) as ReturnedOptions
|
||||
}
|
||||
@@ -27,10 +27,10 @@
|
||||
"author": "Medusa",
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"awilix": "^8.0.1",
|
||||
@@ -47,10 +47,10 @@
|
||||
"ulid": "^2.3.0"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"express": "^4.21.0",
|
||||
"pg": "^8.13.0"
|
||||
|
||||
@@ -81,7 +81,7 @@
|
||||
"vitest": "^0.32.2"
|
||||
},
|
||||
"dependencies": {
|
||||
"@medusajs/icons": "^2.2.0",
|
||||
"@medusajs/icons": "^2.3.0",
|
||||
"@radix-ui/react-accordion": "1.2.0",
|
||||
"@radix-ui/react-alert-dialog": "1.1.1",
|
||||
"@radix-ui/react-avatar": "1.1.0",
|
||||
|
||||
@@ -26,10 +26,10 @@
|
||||
"license": "MIT",
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"jest": "^29.7.0",
|
||||
"pg": "^8.13.0",
|
||||
@@ -47,7 +47,7 @@
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@medusajs/medusa": "^2.0.0",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
},
|
||||
"peerDependenciesMeta": {
|
||||
|
||||
@@ -1,4 +1,9 @@
|
||||
import { MikroORM, Options, SqlEntityManager } from "@mikro-orm/postgresql"
|
||||
import {
|
||||
defineConfig,
|
||||
MikroORM,
|
||||
Options,
|
||||
SqlEntityManager,
|
||||
} from "@mikro-orm/postgresql"
|
||||
import { createDatabase, dropDatabase } from "pg-god"
|
||||
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
@@ -13,8 +18,8 @@ const pgGodCredentials = {
|
||||
|
||||
export function getDatabaseURL(dbName?: string): string {
|
||||
const DB_HOST = process.env.DB_HOST ?? "localhost"
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? ""
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD
|
||||
const DB_USERNAME = process.env.DB_USERNAME ?? "postgres"
|
||||
const DB_PASSWORD = process.env.DB_PASSWORD ?? ""
|
||||
const DB_NAME = dbName ?? process.env.DB_TEMP_NAME
|
||||
|
||||
return `postgres://${DB_USERNAME}${
|
||||
@@ -35,8 +40,7 @@ export function getMikroOrmConfig({
|
||||
}): Options {
|
||||
const DB_URL = clientUrl ?? getDatabaseURL()
|
||||
|
||||
return {
|
||||
type: "postgresql",
|
||||
return defineConfig({
|
||||
clientUrl: DB_URL,
|
||||
entities: Object.values(mikroOrmEntities),
|
||||
schema: schema ?? process.env.MEDUSA_DB_SCHEMA,
|
||||
@@ -48,7 +52,7 @@ export function getMikroOrmConfig({
|
||||
pathTs: pathToMigrations,
|
||||
silent: true,
|
||||
},
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export interface TestDatabase {
|
||||
|
||||
@@ -128,10 +128,10 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1",
|
||||
"yalc": "1.0.0-pre.53"
|
||||
},
|
||||
|
||||
@@ -2,18 +2,18 @@ import {
|
||||
removeItemReturnActionWorkflow,
|
||||
updateRequestItemReturnWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
refetchEntity,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config"
|
||||
import { AdminPostReturnsRequestItemsActionReqSchemaType } from "../../../../../returns/validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsRequestItemsActionReqSchemaType>,
|
||||
@@ -29,7 +29,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
@@ -67,7 +67,10 @@ export const DELETE = async (
|
||||
) => {
|
||||
const { id, action_id } = req.params
|
||||
|
||||
const claim = await refetchEntity("order_claim", id, req.scope, ["return_id"])
|
||||
const claim = await refetchEntity("order_claim", id, req.scope, [
|
||||
"id",
|
||||
"return_id",
|
||||
])
|
||||
|
||||
const { result: orderPreview } = await removeItemReturnActionWorkflow(
|
||||
req.scope
|
||||
|
||||
@@ -8,9 +8,9 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config"
|
||||
import { AdminPostReturnsRequestItemsReqSchemaType } from "../../../../returns/validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsRequestItemsReqSchemaType>,
|
||||
@@ -26,7 +26,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
@@ -41,10 +41,11 @@ export const POST = async (
|
||||
},
|
||||
})
|
||||
|
||||
const returnId = result.order_change.return_id
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id: claim.return_id,
|
||||
id: returnId,
|
||||
},
|
||||
fields: defaultAdminDetailsReturnFields,
|
||||
})
|
||||
|
||||
+6
-6
@@ -2,17 +2,17 @@ import {
|
||||
removeClaimShippingMethodWorkflow,
|
||||
updateReturnShippingMethodWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config"
|
||||
import { AdminPostClaimsShippingActionReqSchemaType } from "../../../../validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostClaimsShippingActionReqSchemaType>,
|
||||
@@ -28,7 +28,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
|
||||
@@ -8,9 +8,9 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config"
|
||||
import { AdminPostReturnsShippingReqSchemaType } from "../../../../returns/validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsShippingReqSchemaType>,
|
||||
@@ -26,7 +26,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
@@ -41,10 +41,11 @@ export const POST = async (
|
||||
},
|
||||
})
|
||||
|
||||
const returnId = result.order_change.return_id
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id: claim.return_id,
|
||||
id: returnId,
|
||||
},
|
||||
fields: defaultAdminDetailsReturnFields,
|
||||
})
|
||||
|
||||
@@ -2,16 +2,16 @@ import {
|
||||
removeItemReturnActionWorkflow,
|
||||
updateRequestItemReturnWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
refetchEntity,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config"
|
||||
import { AdminPostExchangesRequestItemsReturnActionReqSchemaType } from "../../../../validators"
|
||||
|
||||
@@ -29,7 +29,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
|
||||
@@ -8,9 +8,9 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config"
|
||||
import { AdminPostExchangesReturnRequestItemsReqSchemaType } from "../../../validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesReturnRequestItemsReqSchemaType>,
|
||||
@@ -26,7 +26,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
@@ -43,10 +43,11 @@ export const POST = async (
|
||||
},
|
||||
})
|
||||
|
||||
const returnId = result.order_change.return_id
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id: exchange.return_id,
|
||||
id: returnId,
|
||||
},
|
||||
fields: defaultAdminDetailsReturnFields,
|
||||
})
|
||||
|
||||
+7
-7
@@ -2,17 +2,17 @@ import {
|
||||
removeReturnShippingMethodWorkflow,
|
||||
updateReturnShippingMethodWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { AdminOrderPreview, HttpTypes } from "@medusajs/framework/types"
|
||||
import {
|
||||
ContainerRegistrationKeys,
|
||||
remoteQueryObjectFromString,
|
||||
} from "@medusajs/framework/utils"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../../returns/query-config"
|
||||
import { AdminPostExchangesShippingActionReqSchemaType } from "../../../../validators"
|
||||
import { AdminOrderPreview, HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostExchangesShippingActionReqSchemaType>,
|
||||
@@ -28,7 +28,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
@@ -76,7 +76,7 @@ export const DELETE = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
|
||||
@@ -8,9 +8,9 @@ import {
|
||||
AuthenticatedMedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/framework/http"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
import { defaultAdminDetailsReturnFields } from "../../../../returns/query-config"
|
||||
import { AdminPostReturnsShippingReqSchemaType } from "../../../../returns/validators"
|
||||
import { HttpTypes } from "@medusajs/framework/types"
|
||||
|
||||
export const POST = async (
|
||||
req: AuthenticatedMedusaRequest<AdminPostReturnsShippingReqSchemaType>,
|
||||
@@ -26,7 +26,7 @@ export const POST = async (
|
||||
variables: {
|
||||
id,
|
||||
},
|
||||
fields: ["return_id"],
|
||||
fields: ["id", "return_id"],
|
||||
}),
|
||||
{
|
||||
throwIfKeyNotFound: true,
|
||||
@@ -41,10 +41,11 @@ export const POST = async (
|
||||
},
|
||||
})
|
||||
|
||||
const returnId = result.order_change.return_id
|
||||
const queryObject = remoteQueryObjectFromString({
|
||||
entryPoint: "return",
|
||||
variables: {
|
||||
id: exchange.return_id,
|
||||
id: returnId,
|
||||
},
|
||||
fields: defaultAdminDetailsReturnFields,
|
||||
})
|
||||
|
||||
@@ -30,15 +30,15 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
|
||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -48,9 +48,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,18 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --runInBand --bail --passWithNoTests --forceExit -- src",
|
||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -51,9 +51,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,18 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --runInBand --bail --passWithNoTests --forceExit -- src",
|
||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -51,9 +51,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,18 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
|
||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -51,9 +51,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
@@ -30,19 +30,19 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --runInBand --bail --passWithNoTests --forceExit -- src",
|
||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:generate": "MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:generate",
|
||||
"migration:initial": "MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": "MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": "MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": "MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:generate": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:generate",
|
||||
"migration:initial": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": "MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -52,9 +52,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
@@ -30,18 +30,18 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --passWithNoTests --runInBand --bail --forceExit -- src/**/__tests__/**/*.ts",
|
||||
"test:integration": "jest --passWithNoTests --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
|
||||
+4
-4
@@ -137,7 +137,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
{
|
||||
attribute: "test-attribute",
|
||||
operator: "in",
|
||||
value: ["test"],
|
||||
value: ["true"],
|
||||
},
|
||||
],
|
||||
}),
|
||||
@@ -161,7 +161,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
{
|
||||
attribute: "test-attribute",
|
||||
operator: "eq",
|
||||
value: "test",
|
||||
value: "true",
|
||||
},
|
||||
{
|
||||
attribute: "test-attribute2.options",
|
||||
@@ -174,7 +174,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
|
||||
let listedOptions = await service.listShippingOptionsForContext({
|
||||
context: {
|
||||
"test-attribute": "test",
|
||||
"test-attribute": "true",
|
||||
"test-attribute2": {
|
||||
options: "test2",
|
||||
},
|
||||
@@ -774,7 +774,7 @@ moduleIntegrationTestRunner<IFulfillmentModuleService>({
|
||||
rules: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: existingRule.id,
|
||||
value: '"false"',
|
||||
value: "false",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
|
||||
@@ -30,18 +30,18 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --runInBand --bail --forceExit --passWithNoTests -- src",
|
||||
"test:integration": "jest --forceExit -- integration-tests/**/__tests__/**/*.spec.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial -n InitialSetupMigration",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial -n InitialSetupMigration",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -51,9 +51,9 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
@@ -154,6 +154,7 @@
|
||||
"keyName": "IDX_fulfillment_address_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_address_deleted_at\" ON \"fulfillment_address\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -164,12 +165,14 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {}
|
||||
"foreignKeys": {},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -232,6 +235,7 @@
|
||||
"keyName": "IDX_fulfillment_provider_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_provider_deleted_at\" ON \"fulfillment_provider\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -242,12 +246,14 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {}
|
||||
"foreignKeys": {},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -327,6 +333,7 @@
|
||||
"keyName": "IDX_fulfillment_set_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_set_deleted_at\" ON \"fulfillment_set\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -335,6 +342,7 @@
|
||||
"keyName": "IDX_fulfillment_set_name_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_fulfillment_set_name_unique\" ON \"fulfillment_set\" (name) WHERE deleted_at IS NULL"
|
||||
@@ -345,12 +353,14 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {}
|
||||
"foreignKeys": {},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -430,6 +440,7 @@
|
||||
"keyName": "IDX_service_zone_fulfillment_set_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_service_zone_fulfillment_set_id\" ON \"service_zone\" (fulfillment_set_id) WHERE deleted_at IS NULL"
|
||||
@@ -438,6 +449,7 @@
|
||||
"keyName": "IDX_service_zone_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_service_zone_deleted_at\" ON \"service_zone\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -446,6 +458,7 @@
|
||||
"keyName": "IDX_service_zone_name_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_service_zone_name_unique\" ON \"service_zone\" (name) WHERE deleted_at IS NULL"
|
||||
@@ -456,6 +469,7 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
@@ -475,7 +489,8 @@
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -598,6 +613,7 @@
|
||||
"keyName": "IDX_geo_zone_service_zone_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_service_zone_id\" ON \"geo_zone\" (service_zone_id) WHERE deleted_at IS NULL"
|
||||
@@ -606,6 +622,7 @@
|
||||
"keyName": "IDX_geo_zone_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_deleted_at\" ON \"geo_zone\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -614,6 +631,7 @@
|
||||
"keyName": "IDX_geo_zone_country_code",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_country_code\" ON \"geo_zone\" (country_code) WHERE deleted_at IS NULL"
|
||||
@@ -622,6 +640,7 @@
|
||||
"keyName": "IDX_geo_zone_province_code",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_province_code\" ON \"geo_zone\" (province_code) WHERE deleted_at IS NULL"
|
||||
@@ -630,6 +649,7 @@
|
||||
"keyName": "IDX_geo_zone_city",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_geo_zone_city\" ON \"geo_zone\" (city) WHERE deleted_at IS NULL"
|
||||
@@ -640,6 +660,7 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
@@ -659,7 +680,8 @@
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -739,6 +761,7 @@
|
||||
"keyName": "IDX_shipping_option_type_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_type_deleted_at\" ON \"shipping_option_type\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -749,12 +772,14 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {}
|
||||
"foreignKeys": {},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -834,6 +859,7 @@
|
||||
"keyName": "IDX_shipping_profile_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_profile_deleted_at\" ON \"shipping_profile\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -842,6 +868,7 @@
|
||||
"keyName": "IDX_shipping_profile_name_unique",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE UNIQUE INDEX IF NOT EXISTS \"IDX_shipping_profile_name_unique\" ON \"shipping_profile\" (name) WHERE deleted_at IS NULL"
|
||||
@@ -852,12 +879,14 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {}
|
||||
"foreignKeys": {},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -983,10 +1012,21 @@
|
||||
"name": "shipping_option",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"shipping_option_type_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "shipping_option_shipping_option_type_id_unique",
|
||||
"constraint": true,
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_service_zone_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_service_zone_id\" ON \"shipping_option\" (service_zone_id) WHERE deleted_at IS NULL"
|
||||
@@ -995,14 +1035,25 @@
|
||||
"keyName": "IDX_shipping_option_shipping_profile_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_shipping_profile_id\" ON \"shipping_option\" (shipping_profile_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_provider_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_provider_id\" ON \"shipping_option\" (provider_id) WHERE deleted_at IS NULL"
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_shipping_option_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_deleted_at\" ON \"shipping_option\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -1013,6 +1064,7 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
@@ -1044,8 +1096,34 @@
|
||||
"referencedTableName": "public.shipping_profile",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_provider_id_foreign": {
|
||||
"constraintName": "shipping_option_provider_id_foreign",
|
||||
"columnNames": [
|
||||
"provider_id"
|
||||
],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.fulfillment_provider",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"shipping_option_shipping_option_type_id_foreign": {
|
||||
"constraintName": "shipping_option_shipping_option_type_id_foreign",
|
||||
"columnNames": [
|
||||
"shipping_option_type_id"
|
||||
],
|
||||
"localTableName": "public.shipping_option",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.shipping_option_type",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -1144,6 +1222,7 @@
|
||||
"keyName": "IDX_shipping_option_rule_shipping_option_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_rule_shipping_option_id\" ON \"shipping_option_rule\" (shipping_option_id) WHERE deleted_at IS NULL"
|
||||
@@ -1152,6 +1231,7 @@
|
||||
"keyName": "IDX_shipping_option_rule_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_shipping_option_rule_deleted_at\" ON \"shipping_option_rule\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -1162,6 +1242,7 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
@@ -1181,7 +1262,8 @@
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -1352,10 +1434,31 @@
|
||||
"name": "fulfillment",
|
||||
"schema": "public",
|
||||
"indexes": [
|
||||
{
|
||||
"columnNames": [
|
||||
"provider_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "fulfillment_provider_id_unique",
|
||||
"constraint": true,
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"columnNames": [
|
||||
"delivery_address_id"
|
||||
],
|
||||
"composite": false,
|
||||
"keyName": "fulfillment_delivery_address_id_unique",
|
||||
"constraint": true,
|
||||
"primary": false,
|
||||
"unique": true
|
||||
},
|
||||
{
|
||||
"keyName": "IDX_fulfillment_shipping_option_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_shipping_option_id\" ON \"fulfillment\" (shipping_option_id) WHERE deleted_at IS NULL"
|
||||
@@ -1364,6 +1467,7 @@
|
||||
"keyName": "IDX_fulfillment_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_deleted_at\" ON \"fulfillment\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -1372,6 +1476,7 @@
|
||||
"keyName": "IDX_fulfillment_location_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_location_id\" ON \"fulfillment\" (location_id) WHERE deleted_at IS NULL"
|
||||
@@ -1382,12 +1487,26 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
],
|
||||
"checks": [],
|
||||
"foreignKeys": {
|
||||
"fulfillment_provider_id_foreign": {
|
||||
"constraintName": "fulfillment_provider_id_foreign",
|
||||
"columnNames": [
|
||||
"provider_id"
|
||||
],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.fulfillment_provider",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"fulfillment_shipping_option_id_foreign": {
|
||||
"constraintName": "fulfillment_shipping_option_id_foreign",
|
||||
"columnNames": [
|
||||
@@ -1400,8 +1519,22 @@
|
||||
"referencedTableName": "public.shipping_option",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
},
|
||||
"fulfillment_delivery_address_id_foreign": {
|
||||
"constraintName": "fulfillment_delivery_address_id_foreign",
|
||||
"columnNames": [
|
||||
"delivery_address_id"
|
||||
],
|
||||
"localTableName": "public.fulfillment",
|
||||
"referencedColumnNames": [
|
||||
"id"
|
||||
],
|
||||
"referencedTableName": "public.fulfillment_address",
|
||||
"deleteRule": "set null",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -1490,6 +1623,7 @@
|
||||
"keyName": "IDX_fulfillment_label_fulfillment_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_label_fulfillment_id\" ON \"fulfillment_label\" (fulfillment_id) WHERE deleted_at IS NULL"
|
||||
@@ -1498,6 +1632,7 @@
|
||||
"keyName": "IDX_fulfillment_label_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_label_deleted_at\" ON \"fulfillment_label\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -1508,6 +1643,7 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
@@ -1527,7 +1663,8 @@
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
},
|
||||
{
|
||||
"columns": {
|
||||
@@ -1652,6 +1789,7 @@
|
||||
"keyName": "IDX_fulfillment_item_fulfillment_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_fulfillment_id\" ON \"fulfillment_item\" (fulfillment_id) WHERE deleted_at IS NULL"
|
||||
@@ -1660,6 +1798,7 @@
|
||||
"keyName": "IDX_fulfillment_item_deleted_at",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_deleted_at\" ON \"fulfillment_item\" (deleted_at) WHERE deleted_at IS NULL"
|
||||
@@ -1668,6 +1807,7 @@
|
||||
"keyName": "IDX_fulfillment_item_inventory_item_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_inventory_item_id\" ON \"fulfillment_item\" (inventory_item_id) WHERE deleted_at IS NULL"
|
||||
@@ -1676,6 +1816,7 @@
|
||||
"keyName": "IDX_fulfillment_item_line_item_id",
|
||||
"columnNames": [],
|
||||
"composite": false,
|
||||
"constraint": false,
|
||||
"primary": false,
|
||||
"unique": false,
|
||||
"expression": "CREATE INDEX IF NOT EXISTS \"IDX_fulfillment_item_line_item_id\" ON \"fulfillment_item\" (line_item_id) WHERE deleted_at IS NULL"
|
||||
@@ -1686,6 +1827,7 @@
|
||||
"id"
|
||||
],
|
||||
"composite": false,
|
||||
"constraint": true,
|
||||
"primary": true,
|
||||
"unique": true
|
||||
}
|
||||
@@ -1705,7 +1847,9 @@
|
||||
"deleteRule": "cascade",
|
||||
"updateRule": "cascade"
|
||||
}
|
||||
},
|
||||
"nativeEnums": {}
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"nativeEnums": {}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20250113122235 extends Migration {
|
||||
override async up(): Promise<void> {
|
||||
this.addSql(`
|
||||
UPDATE shipping_option_rule
|
||||
SET value = 'true'::jsonb
|
||||
WHERE value = '"true"'::jsonb;
|
||||
`)
|
||||
this.addSql(`
|
||||
UPDATE shipping_option_rule
|
||||
SET value = 'false'::jsonb
|
||||
WHERE value = '"false"'::jsonb;
|
||||
`)
|
||||
}
|
||||
|
||||
override async down(): Promise<void> {
|
||||
this.addSql(`
|
||||
UPDATE shipping_option_rule
|
||||
SET value = '"true"'::jsonb
|
||||
WHERE value = 'true'::jsonb;
|
||||
`)
|
||||
this.addSql(`
|
||||
UPDATE shipping_option_rule
|
||||
SET value = '"false"'::jsonb
|
||||
WHERE value = 'false'::jsonb;
|
||||
`)
|
||||
}
|
||||
}
|
||||
@@ -146,12 +146,12 @@ export function validateRule(rule: Record<string, unknown>): boolean {
|
||||
}
|
||||
|
||||
export function normalizeRulesValue<T extends Partial<Rule>>(rules: T[]): void {
|
||||
rules.forEach((rule) => {
|
||||
rules.forEach((rule: any) => {
|
||||
/**
|
||||
* If a string is provided, then we don't want jsonb to convert to the primitive value based on the RFC
|
||||
* If a boolean is provided, then we convert to string
|
||||
*/
|
||||
if (rule.value === "true" || rule.value === "false") {
|
||||
rule.value = rule.value === "true" ? '"true"' : '"false"'
|
||||
if (rule.value === true || rule.value === false) {
|
||||
rule.value = rule.value === true ? "true" : "false"
|
||||
}
|
||||
|
||||
return rule
|
||||
|
||||
@@ -722,57 +722,11 @@ describe("IndexModuleService", function () {
|
||||
it("should consume all deleted events and delete the index entries", async () => {
|
||||
const indexEntries = await manager.find(toMikroORMEntity(IndexData), {})
|
||||
const indexRelationEntries = await manager.find(
|
||||
toMikroORMEntity(IndexRelation),
|
||||
{},
|
||||
{
|
||||
populate: ["parent", "child"],
|
||||
}
|
||||
toMikroORMEntity(IndexRelation)
|
||||
)
|
||||
|
||||
expect(indexEntries).toHaveLength(3)
|
||||
expect(indexRelationEntries).toHaveLength(2)
|
||||
|
||||
const linkIndexEntry = indexEntries.find((entry) => {
|
||||
return (
|
||||
entry.name === "LinkProductVariantPriceSet" && entry.id === linkId
|
||||
)
|
||||
})!
|
||||
|
||||
const priceSetIndexEntry = indexEntries.find((entry) => {
|
||||
return entry.name === "PriceSet" && entry.id === priceSetId
|
||||
})!
|
||||
|
||||
const priceIndexEntry = indexEntries.find((entry) => {
|
||||
return entry.name === "Price" && entry.id === priceId
|
||||
})!
|
||||
|
||||
const linkPriceSetIndexRelationEntry = indexRelationEntries.find(
|
||||
(entry) => {
|
||||
return (
|
||||
entry.parent_id === linkId &&
|
||||
entry.parent_name === "LinkProductVariantPriceSet" &&
|
||||
entry.child_id === priceSetId &&
|
||||
entry.child_name === "PriceSet"
|
||||
)
|
||||
}
|
||||
)!
|
||||
|
||||
expect(linkPriceSetIndexRelationEntry.parent).toEqual(linkIndexEntry)
|
||||
expect(linkPriceSetIndexRelationEntry.child).toEqual(priceSetIndexEntry)
|
||||
|
||||
const priceSetPriceIndexRelationEntry = indexRelationEntries.find(
|
||||
(entry) => {
|
||||
return (
|
||||
entry.parent_id === priceSetId &&
|
||||
entry.parent_name === "PriceSet" &&
|
||||
entry.child_id === priceId &&
|
||||
entry.child_name === "Price"
|
||||
)
|
||||
}
|
||||
)!
|
||||
|
||||
expect(priceSetPriceIndexRelationEntry.parent).toEqual(priceSetIndexEntry)
|
||||
expect(priceSetPriceIndexRelationEntry.child).toEqual(priceIndexEntry)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -30,19 +30,19 @@
|
||||
"build": "rimraf dist && tsc --build && npm run resolve:aliases",
|
||||
"test": "jest --passWithNoTests ./src",
|
||||
"test:integration": "jest --runInBand --forceExit -- integration-tests/**/__tests__/**/*.ts",
|
||||
"migration:initial": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
"migration:initial": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create --initial",
|
||||
"migration:create": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:create",
|
||||
"migration:up": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm migration:up",
|
||||
"orm:cache:clear": " MIKRO_ORM_CLI_CONFIG=./mikro-orm.config.dev.ts medusa-mikro-orm cache:clear"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@medusajs/framework": "^2.3.1",
|
||||
"@medusajs/test-utils": "^2.3.1",
|
||||
"@mikro-orm/cli": "5.9.7",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/cli": "6.4.3",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"@swc/core": "^1.7.28",
|
||||
"@swc/jest": "^0.2.36",
|
||||
"jest": "^29.7.0",
|
||||
@@ -52,10 +52,10 @@
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@medusajs/framework": "^2.0.0",
|
||||
"@mikro-orm/core": "5.9.7",
|
||||
"@mikro-orm/knex": "5.9.7",
|
||||
"@mikro-orm/migrations": "5.9.7",
|
||||
"@mikro-orm/postgresql": "5.9.7",
|
||||
"@mikro-orm/core": "6.4.3",
|
||||
"@mikro-orm/knex": "6.4.3",
|
||||
"@mikro-orm/migrations": "6.4.3",
|
||||
"@mikro-orm/postgresql": "6.4.3",
|
||||
"awilix": "^8.0.1"
|
||||
}
|
||||
}
|
||||
Loaded 100 of 178 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user