chore(): Upgrade mikro orm (#13390)

* chore(): Upgrade mikro orm

* handle 'null' value for big number props

* 6.5.2

* remove only

* fix pricing module rule value

* switch select in strategy for balances

* revert to select in strategy for order module

* fix defining DML ManyToOne

* fix define relationship

* test fix

* more fixes

* change order strategy to balanced

* change order strategy to balanced

* prevent unnecessary manager fork

* revert generated www changes

* remove unnecessary changes

* Create real-cobras-deny.md

* address feedback

---------

Co-authored-by: Oli Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
Adrien de Peretti
2025-09-08 21:10:44 +02:00
committed by GitHub
co-authored by Oli Juhl
parent fc4d5f0ac9
commit a095245d71
60 changed files with 863 additions and 712 deletions
@@ -1,6 +1,6 @@
import { BigNumberInput } from "@medusajs/types"
import { Property } from "@mikro-orm/core"
import { isDefined, isPresent, trimZeros } from "../../common"
import { EntityProperty, Platform, Property, Type } from "@mikro-orm/core"
import { isDefined, isObject, isPresent, trimZeros } from "../../common"
import { BigNumber } from "../../totals/big-number"
export function MikroOrmBigNumberProperty(
@@ -24,6 +24,11 @@ export function MikroOrmBigNumberProperty(
return value
},
set(value: BigNumberInput) {
// convert 'null' to null
if (value === "null") {
value = null as unknown as BigNumberInput
}
if (options?.nullable && !isPresent(value)) {
this.__helper.__data[columnName] = null
this.__helper.__data[rawColumnName] = null
@@ -89,7 +94,7 @@ export function MikroOrmBigNumberProperty(
})
Property({
type: "any",
type: BigNumberNumeric,
columnType: "numeric",
trackChanges: false,
runtimeType: "any",
@@ -97,3 +102,43 @@ export function MikroOrmBigNumberProperty(
})(target, columnName)
}
}
class BigNumberNumeric extends Type<string | number, string> {
constructor(public mode?: "number" | "string") {
super()
}
override convertToJSValue(value: string): number | string {
if ((this.mode ?? this.prop?.runtimeType) === "number") {
return +value
}
if (isObject(value)) {
return value // Special case for BigNumberRawValue because the setter will manage the dispatch automatically at a later stage
}
return String(value)
}
override compareValues(a: string, b: string): boolean {
return this.format(a) === this.format(b)
}
private format(val: string | number) {
/* istanbul ignore next */
if (this.prop?.scale == null) {
return +val
}
const base = Math.pow(10, this.prop.scale)
return Math.round((+val + Number.EPSILON) * base) / base
}
override getColumnType(prop: EntityProperty, platform: Platform) {
return platform.getDecimalTypeDeclarationSQL(prop)
}
override compareAsType(): string {
return this.mode ?? this.prop?.runtimeType ?? "string"
}
}
@@ -64,11 +64,9 @@ export class MikroOrmBase {
transaction?: TManager
} = {}
): Promise<any> {
const freshManager = this.getFreshManager
? this.getFreshManager()
: this.manager_
this.manager_.global = true // this prevent mikro orm from synchronising the transaction manager entity map back to the manager. Also, it will save us from always forking the manager for each transaction while the transacation manager will fork it again for transaction purpose
return await transactionWrapper(freshManager, task, options).catch(
return await transactionWrapper(this.manager_, task, options).catch(
dbErrorMapper
)
}
@@ -467,11 +465,7 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
if (!("strategy" in findOptions_.options)) {
if (findOptions_.options.limit != null || findOptions_.options.offset) {
Object.assign(findOptions_.options, {
strategy: LoadStrategy.SELECT_IN,
})
} else {
Object.assign(findOptions_.options, {
strategy: LoadStrategy.JOINED,
strategy: LoadStrategy.BALANCED,
})
}
}