@mikro-orm/core 7.1.2-dev.0 → 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/entity/defineEntity.d.ts +5 -2
- package/package.json +1 -1
- package/platforms/Platform.d.ts +7 -0
- package/platforms/Platform.js +13 -0
- package/types/DecimalType.d.ts +0 -1
- package/types/DecimalType.js +1 -9
- package/utils/QueryHelper.js +4 -1
- package/utils/Utils.js +1 -1
package/entity/defineEntity.d.ts
CHANGED
|
@@ -614,6 +614,9 @@ export type PropertyBuilders = {
|
|
|
614
614
|
};
|
|
615
615
|
/** Own keys + base entity keys (when TBase is not `never`). Guards against `keyof never = string | number | symbol`. */
|
|
616
616
|
type AllKeys<TProperties, TBase> = keyof TProperties | (IsNever<TBase> extends true ? never : keyof TBase);
|
|
617
|
+
type PartialWhere<TProperties, TBase> = string | FilterQuery<{
|
|
618
|
+
[K in AllKeys<TProperties, TBase> & string]?: unknown;
|
|
619
|
+
}>;
|
|
617
620
|
/** Metadata descriptor for `defineEntity()`, combining entity options with property definitions. */
|
|
618
621
|
export interface EntityMetadataWithProperties<TName extends string, TTableName extends string, TProperties extends Record<string, any>, TPK extends (keyof TProperties)[] | undefined = undefined, TBase = never, TRepository = never, TForceObject extends boolean = false, TDiscriminatorColumn extends string | undefined = undefined, TDiscriminatorValue extends string | number | undefined = undefined, TBaseDiscriminatorColumn extends string | undefined = undefined> extends Omit<Partial<EntityMetadata<InferEntityFromProperties<TProperties, TPK, TBase, TRepository>>>, 'properties' | 'extends' | 'primaryKeys' | 'hooks' | 'discriminator' | 'discriminatorColumn' | 'discriminatorValue' | 'versionProperty' | 'concurrencyCheckKeys' | 'serializedPrimaryKey' | 'indexes' | 'uniques' | 'triggers' | 'repository' | 'filters' | 'orderBy'> {
|
|
619
622
|
name: TName;
|
|
@@ -656,7 +659,7 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
656
659
|
type?: string;
|
|
657
660
|
options?: Dictionary;
|
|
658
661
|
expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK, TBase>>;
|
|
659
|
-
where?:
|
|
662
|
+
where?: PartialWhere<TProperties, TBase>;
|
|
660
663
|
columns?: IndexColumnOptions[];
|
|
661
664
|
include?: NoInfer<AllKeys<TProperties, TBase>> | NoInfer<AllKeys<TProperties, TBase>>[];
|
|
662
665
|
fillFactor?: number;
|
|
@@ -669,7 +672,7 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
|
|
|
669
672
|
name?: string;
|
|
670
673
|
options?: Dictionary;
|
|
671
674
|
expression?: string | IndexCallback<InferEntityFromProperties<TProperties, TPK, TBase>>;
|
|
672
|
-
where?:
|
|
675
|
+
where?: PartialWhere<TProperties, TBase>;
|
|
673
676
|
deferMode?: DeferMode | `${DeferMode}`;
|
|
674
677
|
columns?: IndexColumnOptions[];
|
|
675
678
|
include?: NoInfer<AllKeys<TProperties, TBase>> | NoInfer<AllKeys<TProperties, TBase>>[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.1.2-dev.
|
|
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",
|
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;
|
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);
|
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/QueryHelper.js
CHANGED
|
@@ -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 (
|
|
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.
|
|
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
|
*/
|