@mikro-orm/core 6.4.17-dev.87 → 6.4.17-dev.89
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/EntityFactory.js
CHANGED
|
@@ -116,7 +116,7 @@ class EntityFactory {
|
|
|
116
116
|
if (meta.versionProperty && data[meta.versionProperty] && data[meta.versionProperty] !== originalEntityData[meta.versionProperty]) {
|
|
117
117
|
diff[meta.versionProperty] = data[meta.versionProperty];
|
|
118
118
|
}
|
|
119
|
-
const diff2 = this.comparator.diffEntities(meta.className, existsData, data);
|
|
119
|
+
const diff2 = this.comparator.diffEntities(meta.className, existsData, data, { includeInverseSides: true });
|
|
120
120
|
// do not override values changed by user
|
|
121
121
|
Utils_1.Utils.keys(diff).forEach(key => delete diff2[key]);
|
|
122
122
|
Utils_1.Utils.keys(diff2).filter(key => {
|
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.89",
|
|
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.1",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.4.17-dev.
|
|
67
|
+
"mikro-orm": "6.4.17-dev.89",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { EntityData, EntityDictionary, EntityMetadata, EntityProperty, IMetadataStorage } from '../typings';
|
|
2
2
|
import type { Platform } from '../platforms';
|
|
3
|
-
type Comparator<T> = (a: T, b: T
|
|
3
|
+
type Comparator<T> = (a: T, b: T, options?: {
|
|
4
|
+
includeInverseSides?: boolean;
|
|
5
|
+
}) => EntityData<T>;
|
|
4
6
|
type ResultMapper<T> = (result: EntityData<T>) => EntityData<T> | null;
|
|
5
7
|
type SnapshotGenerator<T> = (entity: T) => EntityData<T>;
|
|
6
8
|
type CompositeKeyPart = string | CompositeKeyPart[];
|
|
@@ -18,7 +20,9 @@ export declare class EntityComparator {
|
|
|
18
20
|
/**
|
|
19
21
|
* Computes difference between two entities.
|
|
20
22
|
*/
|
|
21
|
-
diffEntities<T>(entityName: string, a: EntityData<T>, b: EntityData<T
|
|
23
|
+
diffEntities<T>(entityName: string, a: EntityData<T>, b: EntityData<T>, options?: {
|
|
24
|
+
includeInverseSides?: boolean;
|
|
25
|
+
}): EntityData<T>;
|
|
22
26
|
matching<T>(entityName: string, a: EntityData<T>, b: EntityData<T>): boolean;
|
|
23
27
|
/**
|
|
24
28
|
* Removes ORM specific code from entities and prepares it for serializing. Used before change set computation.
|
|
@@ -23,9 +23,9 @@ class EntityComparator {
|
|
|
23
23
|
/**
|
|
24
24
|
* Computes difference between two entities.
|
|
25
25
|
*/
|
|
26
|
-
diffEntities(entityName, a, b) {
|
|
26
|
+
diffEntities(entityName, a, b, options) {
|
|
27
27
|
const comparator = this.getEntityComparator(entityName);
|
|
28
|
-
return Utils_1.Utils.callCompiledFunction(comparator, a, b);
|
|
28
|
+
return Utils_1.Utils.callCompiledFunction(comparator, a, b, options);
|
|
29
29
|
}
|
|
30
30
|
matching(entityName, a, b) {
|
|
31
31
|
const diff = this.diffEntities(entityName, a, b);
|
|
@@ -540,8 +540,16 @@ class EntityComparator {
|
|
|
540
540
|
lines.push(this.getPropertyComparator(prop, context));
|
|
541
541
|
}
|
|
542
542
|
}
|
|
543
|
+
// also compare 1:1 inverse sides, important for `factory.mergeData`
|
|
544
|
+
lines.push(`if (options?.includeInverseSides) {`);
|
|
545
|
+
for (const prop of meta.bidirectionalRelations) {
|
|
546
|
+
if (prop.kind === enums_1.ReferenceKind.ONE_TO_ONE && !prop.owner && prop.hydrate !== false) {
|
|
547
|
+
lines.push(this.getPropertyComparator(prop, context));
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
lines.push(`}`);
|
|
543
551
|
const code = `// compiled comparator for entity ${meta.className}\n`
|
|
544
|
-
+ `return function(last, current) {\n const diff = {};\n${lines.join('\n')}\n return diff;\n}`;
|
|
552
|
+
+ `return function(last, current, options) {\n const diff = {};\n${lines.join('\n')}\n return diff;\n}`;
|
|
545
553
|
const comparator = Utils_1.Utils.createFunction(context, code);
|
|
546
554
|
this.comparators.set(entityName, comparator);
|
|
547
555
|
return comparator;
|