chore(): upgrade mikro orm (#13450)

This commit is contained in:
Adrien de Peretti
2025-09-19 21:39:18 +02:00
committed by GitHub
parent 4c1c1dd4c0
commit 8ece06d8ed
64 changed files with 836 additions and 700 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"
}
}
@@ -59,15 +59,15 @@ export class MikroOrmBase {
async transaction<TManager = unknown>(
task: (transactionManager: TManager) => Promise<any>,
options: {
manager?: TManager
isolationLevel?: string
enableNestedTransactions?: boolean
transaction?: TManager
} = {}
): Promise<any> {
this.manager_.global = true
return await transactionWrapper(this.manager_, task, options).catch(
dbErrorMapper
)
const manager = this.getFreshManager()
return await transactionWrapper(manager, task, options).catch(dbErrorMapper)
}
async serialize<TOutput extends object | object[]>(
@@ -463,12 +463,9 @@ export function mikroOrmBaseRepositoryFactory<const T extends object>(
if (!("strategy" in findOptions_.options)) {
if (findOptions_.options.limit != null || findOptions_.options.offset) {
// TODO: from 7+ it will be the default strategy
Object.assign(findOptions_.options, {
strategy: LoadStrategy.SELECT_IN,
})
} else {
Object.assign(findOptions_.options, {
strategy: LoadStrategy.JOINED,
strategy: LoadStrategy.BALANCED,
})
}
}