@mikro-orm/core 7.1.8-dev.1 → 7.1.8-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/EntityManager.js +1 -1
- package/entity/EntityAssigner.js +3 -1
- package/entity/EntityFactory.js +1 -1
- package/package.json +1 -1
- package/unit-of-work/IdentityMap.d.ts +5 -0
- package/unit-of-work/IdentityMap.js +7 -0
- package/unit-of-work/UnitOfWork.d.ts +1 -1
- package/unit-of-work/UnitOfWork.js +2 -2
- package/utils/EntityComparator.js +4 -0
- package/utils/TransactionManager.js +1 -1
- package/utils/Utils.js +1 -1
package/EntityManager.js
CHANGED
|
@@ -1432,7 +1432,7 @@ export class EntityManager {
|
|
|
1432
1432
|
options.validate ??= true;
|
|
1433
1433
|
options.cascade ??= true;
|
|
1434
1434
|
validatePrimaryKey(data, em.metadata.get(entityName));
|
|
1435
|
-
let entity = em.#unitOfWork.tryGetById(entityName, data, options.schema, false);
|
|
1435
|
+
let entity = em.#unitOfWork.tryGetById(entityName, data, options.schema, false, options.convertCustomTypes);
|
|
1436
1436
|
if (entity && helper(entity).__managed && helper(entity).__initialized && !options.refresh) {
|
|
1437
1437
|
return entity;
|
|
1438
1438
|
}
|
package/entity/EntityAssigner.js
CHANGED
|
@@ -187,7 +187,9 @@ export class EntityAssigner {
|
|
|
187
187
|
if (options.updateNestedEntities && options.updateByPrimaryKey && Utils.isPlainObject(item)) {
|
|
188
188
|
const pk = Utils.extractPK(item, prop.targetMeta);
|
|
189
189
|
if (pk && EntityAssigner.validateEM(em)) {
|
|
190
|
-
const ref = em
|
|
190
|
+
const ref = em
|
|
191
|
+
.getUnitOfWork()
|
|
192
|
+
.getById(prop.targetMeta.class, pk, options.schema, options.convertCustomTypes);
|
|
191
193
|
if (ref) {
|
|
192
194
|
return EntityAssigner.assign(ref, item, options);
|
|
193
195
|
}
|
package/entity/EntityFactory.js
CHANGED
|
@@ -421,7 +421,7 @@ export class EntityFactory {
|
|
|
421
421
|
const value = data[k];
|
|
422
422
|
if (prop && [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && value) {
|
|
423
423
|
const pk = Reference.unwrapReference(value);
|
|
424
|
-
const entity = this.unitOfWork.getById(prop.targetMeta.class, pk, options.schema,
|
|
424
|
+
const entity = this.unitOfWork.getById(prop.targetMeta.class, pk, options.schema, options.convertCustomTypes);
|
|
425
425
|
if (entity) {
|
|
426
426
|
return entity;
|
|
427
427
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.1.8-dev.
|
|
3
|
+
"version": "7.1.8-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",
|
|
@@ -12,6 +12,11 @@ export declare class IdentityMap {
|
|
|
12
12
|
storeByKey<T>(item: T, key: string, value: string, schema?: string): void;
|
|
13
13
|
/** Removes an entity and its alternate key entries from the identity map. */
|
|
14
14
|
delete<T>(item: T): void;
|
|
15
|
+
/**
|
|
16
|
+
* Retrieves the entity occupying the same slot as the given one, if any. Hashes the entity the same way `store()`
|
|
17
|
+
* does, so it matches regardless of the primary key shape — unlike hashing a primary key value obtained elsewhere.
|
|
18
|
+
*/
|
|
19
|
+
getByEntity<T>(item: T): T | undefined;
|
|
15
20
|
/** Retrieves an entity by its hash key from the identity map. */
|
|
16
21
|
getByHash<T>(meta: EntityMetadata<T>, hash: string): T | undefined;
|
|
17
22
|
/** Returns (or creates) the per-entity-class store within the identity map. */
|
|
@@ -40,6 +40,13 @@ export class IdentityMap {
|
|
|
40
40
|
this.#alternateKeys.delete(item);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* Retrieves the entity occupying the same slot as the given one, if any. Hashes the entity the same way `store()`
|
|
45
|
+
* does, so it matches regardless of the primary key shape — unlike hashing a primary key value obtained elsewhere.
|
|
46
|
+
*/
|
|
47
|
+
getByEntity(item) {
|
|
48
|
+
return this.getStore(item.__meta.root).get(this.getPkHash(item));
|
|
49
|
+
}
|
|
43
50
|
/** Retrieves an entity by its hash key from the identity map. */
|
|
44
51
|
getByHash(meta, hash) {
|
|
45
52
|
const store = this.getStore(meta);
|
|
@@ -48,7 +48,7 @@ export declare class UnitOfWork {
|
|
|
48
48
|
*/
|
|
49
49
|
storeByKey<T extends object>(entity: T, key: string, value: unknown, schema?: string, convertCustomTypes?: boolean): void;
|
|
50
50
|
/** Attempts to extract a primary key from the where condition and look up the entity in the identity map. */
|
|
51
|
-
tryGetById<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, schema?: string, strict?: boolean): T | null;
|
|
51
|
+
tryGetById<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, schema?: string, strict?: boolean, convertCustomTypes?: boolean): T | null;
|
|
52
52
|
/**
|
|
53
53
|
* Returns map of all managed entities.
|
|
54
54
|
*/
|
|
@@ -227,12 +227,12 @@ export class UnitOfWork {
|
|
|
227
227
|
this.#identityMap.storeByKey(entity, key, '' + value, schema);
|
|
228
228
|
}
|
|
229
229
|
/** Attempts to extract a primary key from the where condition and look up the entity in the identity map. */
|
|
230
|
-
tryGetById(entityName, where, schema, strict = true) {
|
|
230
|
+
tryGetById(entityName, where, schema, strict = true, convertCustomTypes) {
|
|
231
231
|
const pk = Utils.extractPK(where, this.#metadata.find(entityName), strict);
|
|
232
232
|
if (!pk) {
|
|
233
233
|
return null;
|
|
234
234
|
}
|
|
235
|
-
return this.getById(entityName, pk, schema);
|
|
235
|
+
return this.getById(entityName, pk, schema, convertCustomTypes);
|
|
236
236
|
}
|
|
237
237
|
/**
|
|
238
238
|
* Returns map of all managed entities.
|
|
@@ -172,6 +172,10 @@ export class EntityComparator {
|
|
|
172
172
|
if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
|
|
173
173
|
lines.push(` (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) ? entity${this.wrap(pk)}.__helper.getSerializedPrimaryKey() : entity${this.wrap(pk)},`);
|
|
174
174
|
}
|
|
175
|
+
else if (meta.properties[pk].customType) {
|
|
176
|
+
const convertorKey = this.registerCustomType(meta.properties[pk], context);
|
|
177
|
+
lines.push(` convertToDatabaseValue_${convertorKey}(entity${this.wrap(pk)}),`);
|
|
178
|
+
}
|
|
175
179
|
else {
|
|
176
180
|
lines.push(` entity${this.wrap(pk)},`);
|
|
177
181
|
}
|
|
@@ -162,7 +162,7 @@ export class TransactionManager {
|
|
|
162
162
|
for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
|
|
163
163
|
const wrapped = helper(entity);
|
|
164
164
|
const meta = wrapped.__meta;
|
|
165
|
-
const parentEntity = parentUoW.
|
|
165
|
+
const parentEntity = parentUoW.getIdentityMap().getByEntity(entity);
|
|
166
166
|
if (parentEntity && parentEntity !== entity) {
|
|
167
167
|
const parentWrapped = helper(parentEntity);
|
|
168
168
|
// Don't overwrite a fully-loaded entity with an uninitialized reference
|
package/utils/Utils.js
CHANGED
|
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
|
|
|
153
153
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
154
154
|
export class Utils {
|
|
155
155
|
static PK_SEPARATOR = '~~~';
|
|
156
|
-
static #ORM_VERSION = '7.1.8-dev.
|
|
156
|
+
static #ORM_VERSION = '7.1.8-dev.10';
|
|
157
157
|
/**
|
|
158
158
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
159
159
|
*/
|