@mikro-orm/core 7.1.2-dev.1 → 7.1.2-dev.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.2-dev.1",
3
+ "version": "7.1.2-dev.10",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "keywords": [
6
6
  "data-mapper",
@@ -167,6 +167,13 @@ export declare abstract class Platform {
167
167
  precision?: number;
168
168
  scale?: number;
169
169
  }): string;
170
+ /**
171
+ * Rounds a decimal value to the column's scale and returns it as a number. Used to compare
172
+ * decimal values across representations — `EntityComparator` for `compareValues`, and the
173
+ * schema layer for collapsing snapshot defaults like `0` / `0.00` to the same canonical form
174
+ * so databases that pad to scale (mysql) don't churn no-op migrations.
175
+ */
176
+ formatDecimal(value: string | number, scale?: number): number;
170
177
  getUuidTypeDeclarationSQL(column: {
171
178
  length?: number;
172
179
  }): string;
@@ -232,6 +232,19 @@ export class Platform {
232
232
  const scale = column.scale ?? 0;
233
233
  return `numeric(${precision},${scale})`;
234
234
  }
235
+ /**
236
+ * Rounds a decimal value to the column's scale and returns it as a number. Used to compare
237
+ * decimal values across representations — `EntityComparator` for `compareValues`, and the
238
+ * schema layer for collapsing snapshot defaults like `0` / `0.00` to the same canonical form
239
+ * so databases that pad to scale (mysql) don't churn no-op migrations.
240
+ */
241
+ formatDecimal(value, scale) {
242
+ if (scale == null) {
243
+ return +value;
244
+ }
245
+ const base = Math.pow(10, scale);
246
+ return Math.round((+value + Number.EPSILON) * base) / base;
247
+ }
235
248
  getUuidTypeDeclarationSQL(column) {
236
249
  column.length ??= 36;
237
250
  return this.getVarcharTypeDeclarationSQL(column);
@@ -9,7 +9,6 @@ export declare class DecimalType<Mode extends 'number' | 'string' = 'string'> ex
9
9
  constructor(mode?: Mode | undefined);
10
10
  convertToJSValue(value: string): JSTypeByMode<Mode>;
11
11
  compareValues(a: string, b: string): boolean;
12
- private format;
13
12
  getColumnType(prop: EntityProperty, platform: Platform): string;
14
13
  compareAsType(): string;
15
14
  }
@@ -16,15 +16,7 @@ export class DecimalType extends Type {
16
16
  return String(value);
17
17
  }
18
18
  compareValues(a, b) {
19
- return this.format(a) === this.format(b);
20
- }
21
- format(val) {
22
- /* v8 ignore next */
23
- if (this.prop?.scale == null) {
24
- return +val;
25
- }
26
- const base = Math.pow(10, this.prop.scale);
27
- return Math.round((+val + Number.EPSILON) * base) / base;
19
+ return this.platform.formatDecimal(a, this.prop?.scale) === this.platform.formatDecimal(b, this.prop?.scale);
28
20
  }
29
21
  getColumnType(prop, platform) {
30
22
  return platform.getDecimalTypeDeclarationSQL(prop);
@@ -75,7 +75,10 @@ export class QueryHelper {
75
75
  }
76
76
  const keys = Object.keys(where);
77
77
  const groupOperator = keys.find(k => {
78
- return (k in GroupOperator &&
78
+ return (
79
+ // sole-key only: caller drops the parent, so siblings would be silently lost
80
+ keys.length === 1 &&
81
+ k in GroupOperator &&
79
82
  Array.isArray(where[k]) &&
80
83
  where[k].every(cond => {
81
84
  return (Utils.isPlainObject(cond) &&
package/utils/Utils.js CHANGED
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.1.2-dev.1';
144
+ static #ORM_VERSION = '7.1.2-dev.10';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */