@mikro-orm/core 6.4.17-dev.21 → 6.4.17-dev.23
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/EntityManager.js +1 -1
- package/drivers/IDatabaseDriver.d.ts +2 -0
- package/entity/EntityFactory.js +1 -1
- package/entity/EntityHelper.js +1 -1
- package/entity/EntityLoader.js +1 -1
- package/entity/WrappedEntity.js +1 -1
- package/package.json +2 -2
- package/typings.js +1 -1
- package/unit-of-work/UnitOfWork.js +2 -2
- package/utils/QueryHelper.js +2 -2
- package/utils/Utils.d.ts +2 -2
- package/utils/Utils.js +24 -5
package/EntityManager.js
CHANGED
|
@@ -1267,7 +1267,7 @@ class EntityManager {
|
|
|
1267
1267
|
if (cached?.data !== undefined) {
|
|
1268
1268
|
return cached.data;
|
|
1269
1269
|
}
|
|
1270
|
-
const count = await em.driver.count(entityName, where, { ctx: em.transactionContext, ...options });
|
|
1270
|
+
const count = await em.driver.count(entityName, where, { ctx: em.transactionContext, em, ...options });
|
|
1271
1271
|
await em.storeCache(options.cache, cached, () => +count);
|
|
1272
1272
|
return +count;
|
|
1273
1273
|
}
|
|
@@ -200,6 +200,8 @@ export interface CountOptions<T extends object, P extends string = never> {
|
|
|
200
200
|
hintComments?: string | string[];
|
|
201
201
|
loggerContext?: LogContext;
|
|
202
202
|
logging?: LoggingOptions;
|
|
203
|
+
/** @internal used to apply filters to the auto-joined relations */
|
|
204
|
+
em?: EntityManager;
|
|
203
205
|
}
|
|
204
206
|
export interface UpdateOptions<T> {
|
|
205
207
|
filters?: FilterOptions;
|
package/entity/EntityFactory.js
CHANGED
|
@@ -74,7 +74,7 @@ class EntityFactory {
|
|
|
74
74
|
continue;
|
|
75
75
|
}
|
|
76
76
|
if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils_1.Utils.isPlainObject(data[prop.name])) {
|
|
77
|
-
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta
|
|
77
|
+
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta, true);
|
|
78
78
|
}
|
|
79
79
|
data[prop.name] = prop.customType.convertToDatabaseValue(data[prop.name], this.platform, { key: prop.name, mode: 'hydration' });
|
|
80
80
|
}
|
package/entity/EntityHelper.js
CHANGED
|
@@ -155,7 +155,7 @@ class EntityHelper {
|
|
|
155
155
|
wrapped.__data[prop.name] = Reference_1.Reference.wrapReference(val, prop);
|
|
156
156
|
// when propagation from inside hydration, we set the FK to the entity data immediately
|
|
157
157
|
if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
|
|
158
|
-
wrapped.__originalEntityData[prop.name] = Utils_1.Utils.getPrimaryKeyValues(wrapped.__data[prop.name], prop.targetMeta
|
|
158
|
+
wrapped.__originalEntityData[prop.name] = Utils_1.Utils.getPrimaryKeyValues(wrapped.__data[prop.name], prop.targetMeta, true);
|
|
159
159
|
}
|
|
160
160
|
else {
|
|
161
161
|
wrapped.__touched = !hydrator.isRunning();
|
package/entity/EntityLoader.js
CHANGED
|
@@ -154,7 +154,7 @@ class EntityLoader {
|
|
|
154
154
|
}
|
|
155
155
|
async populateScalar(meta, filtered, options) {
|
|
156
156
|
const pk = Utils_1.Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
157
|
-
const ids = Utils_1.Utils.unique(filtered.map(e => Utils_1.Utils.getPrimaryKeyValues(e, meta
|
|
157
|
+
const ids = Utils_1.Utils.unique(filtered.map(e => Utils_1.Utils.getPrimaryKeyValues(e, meta, true)));
|
|
158
158
|
const where = this.mergePrimaryCondition(ids, pk, options, meta, this.metadata, this.driver.getPlatform());
|
|
159
159
|
const { filters, convertCustomTypes, lockMode, strategy, populateWhere, connectionType, logging, fields } = options;
|
|
160
160
|
await this.em.find(meta.className, where, {
|
package/entity/WrappedEntity.js
CHANGED
|
@@ -153,7 +153,7 @@ class WrappedEntity {
|
|
|
153
153
|
return this.__em?.config ?? this.entity.__config;
|
|
154
154
|
}
|
|
155
155
|
get __primaryKeys() {
|
|
156
|
-
return Utils_1.Utils.getPrimaryKeyValues(this.entity, this.__meta
|
|
156
|
+
return Utils_1.Utils.getPrimaryKeyValues(this.entity, this.__meta);
|
|
157
157
|
}
|
|
158
158
|
/** @ignore */
|
|
159
159
|
[node_util_1.inspect.custom]() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.17-dev.
|
|
3
|
+
"version": "6.4.17-dev.23",
|
|
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
|
"main": "index.js",
|
|
6
6
|
"module": "index.mjs",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
65
|
"fs-extra": "11.3.0",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.4.17-dev.
|
|
67
|
+
"mikro-orm": "6.4.17-dev.23",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/typings.js
CHANGED
|
@@ -115,7 +115,7 @@ class EntityMetadata {
|
|
|
115
115
|
wrapped.__data[prop.name] = entity_1.Reference.wrapReference(val, prop);
|
|
116
116
|
// when propagation from inside hydration, we set the FK to the entity data immediately
|
|
117
117
|
if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
|
|
118
|
-
wrapped.__originalEntityData[prop.name] = Utils_1.Utils.getPrimaryKeyValues(val, prop.targetMeta
|
|
118
|
+
wrapped.__originalEntityData[prop.name] = Utils_1.Utils.getPrimaryKeyValues(val, prop.targetMeta, true);
|
|
119
119
|
}
|
|
120
120
|
else {
|
|
121
121
|
wrapped.__touched = !hydrator.isRunning();
|
|
@@ -88,7 +88,7 @@ class UnitOfWork {
|
|
|
88
88
|
}
|
|
89
89
|
wrapped.__loadedProperties.add(key);
|
|
90
90
|
if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils_1.Utils.isPlainObject(data[prop.name])) {
|
|
91
|
-
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta
|
|
91
|
+
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta, true);
|
|
92
92
|
}
|
|
93
93
|
else if (prop.kind === enums_1.ReferenceKind.EMBEDDED && !prop.object && Utils_1.Utils.isPlainObject(data[prop.name])) {
|
|
94
94
|
for (const p of prop.targetMeta.props) {
|
|
@@ -96,7 +96,7 @@ class UnitOfWork {
|
|
|
96
96
|
const prefix = prop.prefix === false ? '' : prop.prefix === true ? prop.name + '_' : prop.prefix;
|
|
97
97
|
data[prefix + p.name] = data[prop.name][p.name];
|
|
98
98
|
}
|
|
99
|
-
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta
|
|
99
|
+
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta, true);
|
|
100
100
|
}
|
|
101
101
|
if (forceUndefined) {
|
|
102
102
|
if (data[key] === null) {
|
package/utils/QueryHelper.js
CHANGED
|
@@ -40,7 +40,7 @@ class QueryHelper {
|
|
|
40
40
|
if (Array.isArray(where)) {
|
|
41
41
|
where.forEach((item, i) => {
|
|
42
42
|
if (this.inlinePrimaryKeyObjects(item, meta, metadata, key)) {
|
|
43
|
-
where[i] = Utils_1.Utils.getPrimaryKeyValues(item, meta
|
|
43
|
+
where[i] = Utils_1.Utils.getPrimaryKeyValues(item, meta, false);
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
}
|
|
@@ -61,7 +61,7 @@ class QueryHelper {
|
|
|
61
61
|
Object.keys(where).forEach(k => {
|
|
62
62
|
const meta2 = metadata.find(meta.properties[k]?.type) || meta;
|
|
63
63
|
if (this.inlinePrimaryKeyObjects(where[k], meta2, metadata, k)) {
|
|
64
|
-
where[k] = Utils_1.Utils.getPrimaryKeyValues(where[k], meta2
|
|
64
|
+
where[k] = Utils_1.Utils.getPrimaryKeyValues(where[k], meta2, true);
|
|
65
65
|
}
|
|
66
66
|
});
|
|
67
67
|
return false;
|
package/utils/Utils.d.ts
CHANGED
|
@@ -134,14 +134,14 @@ export declare class Utils {
|
|
|
134
134
|
static getCompositeKeyHash<T>(data: EntityData<T>, meta: EntityMetadata<T>, convertCustomTypes?: boolean, platform?: Platform, flat?: boolean): string;
|
|
135
135
|
static getPrimaryKeyHash(pks: (string | Buffer | Date)[]): string;
|
|
136
136
|
static splitPrimaryKeys<T extends object>(key: string): EntityKey<T>[];
|
|
137
|
-
static getPrimaryKeyValues<T>(entity: T, primaryKeys: string[]
|
|
137
|
+
static getPrimaryKeyValues<T>(entity: T, primaryKeys: string[] | EntityMetadata<T>, allowScalar?: boolean, convertCustomTypes?: boolean): any;
|
|
138
138
|
static getPrimaryKeyCond<T>(entity: T, primaryKeys: EntityKey<T>[]): Record<string, Primary<T>> | null;
|
|
139
139
|
/**
|
|
140
140
|
* Maps nested FKs from `[1, 2, 3]` to `[1, [2, 3]]`.
|
|
141
141
|
*/
|
|
142
142
|
static mapFlatCompositePrimaryKey(fk: Primary<any>[], prop: EntityProperty, fieldNames?: string[], idx?: number): Primary<any> | Primary<any>[];
|
|
143
143
|
static getPrimaryKeyCondFromArray<T extends object>(pks: Primary<T>[], meta: EntityMetadata<T>): Record<string, Primary<T>>;
|
|
144
|
-
static getOrderedPrimaryKeys<T>(id: Primary<T> | Record<string, Primary<T>>, meta: EntityMetadata<T>, platform?: Platform, convertCustomTypes?: boolean): Primary<T>[];
|
|
144
|
+
static getOrderedPrimaryKeys<T>(id: Primary<T> | Record<string, Primary<T>>, meta: EntityMetadata<T>, platform?: Platform, convertCustomTypes?: boolean, allowScalar?: boolean): Primary<T>[];
|
|
145
145
|
/**
|
|
146
146
|
* Checks whether given object is an entity instance.
|
|
147
147
|
*/
|
package/utils/Utils.js
CHANGED
|
@@ -498,6 +498,7 @@ class Utils {
|
|
|
498
498
|
static splitPrimaryKeys(key) {
|
|
499
499
|
return key.split(this.PK_SEPARATOR);
|
|
500
500
|
}
|
|
501
|
+
// TODO v7: remove support for `primaryKeys: string[]`
|
|
501
502
|
static getPrimaryKeyValues(entity, primaryKeys, allowScalar = false, convertCustomTypes = false) {
|
|
502
503
|
/* istanbul ignore next */
|
|
503
504
|
if (entity == null) {
|
|
@@ -509,9 +510,24 @@ class Utils {
|
|
|
509
510
|
}
|
|
510
511
|
return val;
|
|
511
512
|
}
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
513
|
+
const meta = Array.isArray(primaryKeys) ? undefined : primaryKeys;
|
|
514
|
+
primaryKeys = Array.isArray(primaryKeys) ? primaryKeys : meta.primaryKeys;
|
|
515
|
+
let pk;
|
|
516
|
+
if (Utils.isEntity(entity, true)) {
|
|
517
|
+
pk = (0, wrap_1.helper)(entity).getPrimaryKey(convertCustomTypes);
|
|
518
|
+
}
|
|
519
|
+
else {
|
|
520
|
+
pk = primaryKeys.reduce((o, pk) => {
|
|
521
|
+
const targetMeta = meta?.properties[pk].targetMeta;
|
|
522
|
+
if (targetMeta && Utils.isPlainObject(entity[pk])) {
|
|
523
|
+
o[pk] = Utils.getPrimaryKeyValues(entity[pk], targetMeta, allowScalar, convertCustomTypes);
|
|
524
|
+
}
|
|
525
|
+
else {
|
|
526
|
+
o[pk] = entity[pk];
|
|
527
|
+
}
|
|
528
|
+
return o;
|
|
529
|
+
}, {});
|
|
530
|
+
}
|
|
515
531
|
if (primaryKeys.length > 1) {
|
|
516
532
|
return toArray(pk);
|
|
517
533
|
}
|
|
@@ -561,7 +577,7 @@ class Utils {
|
|
|
561
577
|
return o;
|
|
562
578
|
}, {});
|
|
563
579
|
}
|
|
564
|
-
static getOrderedPrimaryKeys(id, meta, platform, convertCustomTypes = false) {
|
|
580
|
+
static getOrderedPrimaryKeys(id, meta, platform, convertCustomTypes = false, allowScalar = false) {
|
|
565
581
|
const data = (Utils.isPrimaryKey(id) ? { [meta.primaryKeys[0]]: id } : id);
|
|
566
582
|
const pks = meta.primaryKeys.map((pk, idx) => {
|
|
567
583
|
const prop = meta.properties[pk];
|
|
@@ -571,11 +587,14 @@ class Utils {
|
|
|
571
587
|
value = prop.customType.convertToJSValue(value, platform);
|
|
572
588
|
}
|
|
573
589
|
if (prop.kind !== enums_1.ReferenceKind.SCALAR && prop.targetMeta) {
|
|
574
|
-
const value2 = this.getOrderedPrimaryKeys(value, prop.targetMeta, platform, convertCustomTypes);
|
|
590
|
+
const value2 = this.getOrderedPrimaryKeys(value, prop.targetMeta, platform, convertCustomTypes, allowScalar);
|
|
575
591
|
value = value2.length > 1 ? value2 : value2[0];
|
|
576
592
|
}
|
|
577
593
|
return value;
|
|
578
594
|
});
|
|
595
|
+
if (allowScalar && pks.length === 1) {
|
|
596
|
+
return pks[0];
|
|
597
|
+
}
|
|
579
598
|
// we need to flatten the PKs as composite PKs can be build from another composite PKs
|
|
580
599
|
// and this method is used to get the PK hash in identity map, that expects flat array
|
|
581
600
|
return Utils.flatten(pks);
|