@mikro-orm/core 7.2.0-dev.1 → 7.2.0-dev.11
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.d.ts +12 -6
- package/EntityManager.js +41 -27
- package/MikroORM.d.ts +4 -0
- package/MikroORM.js +6 -0
- package/cache/CacheAdapter.d.ts +6 -4
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +7 -2
- package/connections/Connection.d.ts +7 -0
- package/connections/Connection.js +9 -0
- package/drivers/DatabaseDriver.d.ts +7 -0
- package/drivers/DatabaseDriver.js +72 -9
- package/entity/EntityRepository.d.ts +4 -5
- package/entity/EntityRepository.js +2 -1
- package/hydration/ObjectHydrator.js +3 -0
- package/metadata/EntitySchema.js +5 -2
- package/metadata/MetadataDiscovery.js +34 -11
- package/metadata/MetadataProvider.js +1 -1
- package/metadata/MetadataStorage.d.ts +4 -3
- package/metadata/MetadataStorage.js +15 -1
- package/metadata/Routine.js +4 -1
- package/naming-strategy/AbstractNamingStrategy.js +2 -1
- package/naming-strategy/NamingStrategy.d.ts +2 -1
- package/package.json +1 -1
- package/platforms/Platform.d.ts +2 -0
- package/platforms/Platform.js +4 -0
- package/typings.d.ts +2 -0
- package/unit-of-work/ChangeSet.js +10 -7
- package/unit-of-work/ChangeSetPersister.js +15 -7
- package/utils/AbstractMigrator.d.ts +1 -1
- package/utils/AbstractMigrator.js +3 -2
- package/utils/Configuration.d.ts +6 -0
- package/utils/Configuration.js +3 -1
- package/utils/Cursor.js +1 -6
- package/utils/EntityComparator.js +4 -1
- package/utils/QueryHelper.d.ts +5 -0
- package/utils/QueryHelper.js +25 -0
- package/utils/RawQueryFragment.d.ts +6 -0
- package/utils/RawQueryFragment.js +15 -6
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +11 -2
- package/utils/TransactionManager.d.ts +6 -0
- package/utils/TransactionManager.js +35 -2
- package/utils/Utils.js +6 -3
- package/utils/clone.js +6 -0
- package/utils/env-vars.js +1 -0
|
@@ -169,19 +169,52 @@ export class TransactionManager {
|
|
|
169
169
|
if (!wrapped.__initialized && parentWrapped.__initialized) {
|
|
170
170
|
continue;
|
|
171
171
|
}
|
|
172
|
-
|
|
173
|
-
|
|
172
|
+
const parentData = parentWrapped.__data;
|
|
173
|
+
const parentSnapshot = parentWrapped.__originalEntityData;
|
|
174
|
+
parentWrapped.__data = { ...wrapped.__data };
|
|
175
|
+
const originalEntityData = { ...wrapped.__originalEntityData };
|
|
174
176
|
for (const prop of meta.hydrateProps) {
|
|
177
|
+
const tracked = this.getTrackedValues(prop, entity[prop.name]);
|
|
178
|
+
// the fork entity can be partially loaded, and propagating a property it does not know about
|
|
179
|
+
// would clobber the parent state, so we restore both its value and its snapshot entries
|
|
180
|
+
if (!tracked.every(([key, value]) => value !== undefined || wrapped.__loadedProperties.has(key))) {
|
|
181
|
+
this.restore(parentWrapped.__data, parentData, prop.name);
|
|
182
|
+
tracked.forEach(([key]) => this.restore(originalEntityData, parentSnapshot, key));
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
175
185
|
if (prop.kind === ReferenceKind.SCALAR) {
|
|
176
186
|
parentEntity[prop.name] = entity[prop.name];
|
|
177
187
|
}
|
|
178
188
|
}
|
|
189
|
+
if (wrapped.__originalEntityData) {
|
|
190
|
+
parentWrapped.__originalEntityData = originalEntityData;
|
|
191
|
+
}
|
|
179
192
|
}
|
|
180
193
|
else {
|
|
181
194
|
parentUoW.merge(entity, new Set([entity]));
|
|
182
195
|
}
|
|
183
196
|
}
|
|
184
197
|
}
|
|
198
|
+
/**
|
|
199
|
+
* Returns the property names a given property is tracked and snapshotted under, paired with their values.
|
|
200
|
+
* Inlined embeddables are hydrated as a single object, so only their leaves tell whether it is complete.
|
|
201
|
+
*/
|
|
202
|
+
getTrackedValues(prop, value) {
|
|
203
|
+
if (prop.kind === ReferenceKind.EMBEDDED && !prop.object) {
|
|
204
|
+
return Object.values(prop.embeddedProps).flatMap(child => {
|
|
205
|
+
return this.getTrackedValues(child, value?.[child.embedded[1]]);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return [[prop.name, value]];
|
|
209
|
+
}
|
|
210
|
+
restore(target, source, key) {
|
|
211
|
+
if (source && key in source) {
|
|
212
|
+
target[key] = source[key];
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
delete target[key];
|
|
216
|
+
}
|
|
217
|
+
}
|
|
185
218
|
/**
|
|
186
219
|
* Registers a deletion handler to unset entity identities after flush.
|
|
187
220
|
*/
|
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.2.0-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.0-dev.11';
|
|
157
157
|
/**
|
|
158
158
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
159
159
|
*/
|
|
@@ -402,7 +402,8 @@ export class Utils {
|
|
|
402
402
|
static getCompositeKeyHash(data, meta, convertCustomTypes = false, platform, flat = false) {
|
|
403
403
|
let pks = this.getCompositeKeyValue(data, meta, convertCustomTypes, platform);
|
|
404
404
|
if (flat) {
|
|
405
|
-
|
|
405
|
+
// deep flatten, nested composite PKs produce nested arrays that would be comma-joined by the hash
|
|
406
|
+
pks = Utils.flatten(pks, true);
|
|
406
407
|
}
|
|
407
408
|
return Utils.getPrimaryKeyHash(pks);
|
|
408
409
|
}
|
|
@@ -462,7 +463,9 @@ export class Utils {
|
|
|
462
463
|
}
|
|
463
464
|
static getPrimaryKeyCond(entity, primaryKeys) {
|
|
464
465
|
const cond = primaryKeys.reduce((o, pk) => {
|
|
465
|
-
|
|
466
|
+
const value = entity[pk];
|
|
467
|
+
// FKs pointing to a composite PK are arrays, which `extractPK` rejects
|
|
468
|
+
o[pk] = Utils.isPrimaryKey(value, true) ? value : Utils.extractPK(value);
|
|
466
469
|
return o;
|
|
467
470
|
}, {});
|
|
468
471
|
if (Object.values(cond).some(v => v === null)) {
|
package/utils/clone.js
CHANGED
|
@@ -112,6 +112,12 @@ export function clone(parent, respectCustomCloneMethod = true) {
|
|
|
112
112
|
});
|
|
113
113
|
}
|
|
114
114
|
for (const i in parent) {
|
|
115
|
+
// an own `__proto__` key (as produced by `JSON.parse`) has no own counterpart on
|
|
116
|
+
// `child` to shadow the inherited accessor, so assigning it would replace the
|
|
117
|
+
// clone's prototype instead of copying the value
|
|
118
|
+
if (i === '__proto__') {
|
|
119
|
+
continue;
|
|
120
|
+
}
|
|
115
121
|
let attrs;
|
|
116
122
|
if (proto) {
|
|
117
123
|
attrs = getPropertyDescriptor(proto, i);
|
package/utils/env-vars.js
CHANGED