@mikro-orm/core 7.1.2-dev.8 → 7.1.2
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 +1 -1
- package/platforms/Platform.d.ts +9 -0
- package/platforms/Platform.js +17 -0
- package/types/DecimalType.d.ts +0 -1
- package/types/DecimalType.js +1 -9
- package/utils/Utils.js +1 -1
- package/utils/upsert-utils.js +4 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.1.2
|
|
3
|
+
"version": "7.1.2",
|
|
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",
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -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;
|
|
@@ -277,6 +284,8 @@ export declare abstract class Platform {
|
|
|
277
284
|
isNumericColumn(mappedType: Type<unknown>): boolean;
|
|
278
285
|
/** Whether the platform supports unsigned integer columns. */
|
|
279
286
|
supportsUnsigned(): boolean;
|
|
287
|
+
/** Whether the platform persists table/column comments (so they round-trip through introspection). */
|
|
288
|
+
supportsComments(): boolean;
|
|
280
289
|
/**
|
|
281
290
|
* Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
|
|
282
291
|
* Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
|
package/platforms/Platform.js
CHANGED
|
@@ -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);
|
|
@@ -629,6 +642,10 @@ export class Platform {
|
|
|
629
642
|
supportsUnsigned() {
|
|
630
643
|
return false;
|
|
631
644
|
}
|
|
645
|
+
/** Whether the platform persists table/column comments (so they round-trip through introspection). */
|
|
646
|
+
supportsComments() {
|
|
647
|
+
return true;
|
|
648
|
+
}
|
|
632
649
|
/**
|
|
633
650
|
* Maximum length of identifiers (table, column, index, constraint, …) the platform supports.
|
|
634
651
|
* Names produced by {@link getIndexName} above this limit are hash-truncated. Defaults to
|
package/types/DecimalType.d.ts
CHANGED
|
@@ -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
|
}
|
package/types/DecimalType.js
CHANGED
|
@@ -16,15 +16,7 @@ export class DecimalType extends Type {
|
|
|
16
16
|
return String(value);
|
|
17
17
|
}
|
|
18
18
|
compareValues(a, b) {
|
|
19
|
-
return this.
|
|
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);
|
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
|
|
144
|
+
static #ORM_VERSION = '7.1.2';
|
|
145
145
|
/**
|
|
146
146
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
147
147
|
*/
|
package/utils/upsert-utils.js
CHANGED
|
@@ -86,7 +86,10 @@ export function getOnConflictReturningFields(meta, data, uniqueFields, options)
|
|
|
86
86
|
if (p.autoincrement) {
|
|
87
87
|
return true;
|
|
88
88
|
}
|
|
89
|
-
|
|
89
|
+
// for a raw `onConflictFields` fragment we can't introspect which columns form the conflict
|
|
90
|
+
// target, so we keep every comparable prop (returning the unique key columns is harmless) –
|
|
91
|
+
// otherwise the non-merged columns would never be reloaded and the entity would diverge from db
|
|
92
|
+
return !Array.isArray(uniqueFields) || !uniqueFields.includes(p.name);
|
|
90
93
|
})
|
|
91
94
|
.map(p => p.name);
|
|
92
95
|
if (meta.versionProperty) {
|