@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.
Files changed (45) hide show
  1. package/EntityManager.d.ts +12 -6
  2. package/EntityManager.js +41 -27
  3. package/MikroORM.d.ts +4 -0
  4. package/MikroORM.js +6 -0
  5. package/cache/CacheAdapter.d.ts +6 -4
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +7 -2
  8. package/connections/Connection.d.ts +7 -0
  9. package/connections/Connection.js +9 -0
  10. package/drivers/DatabaseDriver.d.ts +7 -0
  11. package/drivers/DatabaseDriver.js +72 -9
  12. package/entity/EntityRepository.d.ts +4 -5
  13. package/entity/EntityRepository.js +2 -1
  14. package/hydration/ObjectHydrator.js +3 -0
  15. package/metadata/EntitySchema.js +5 -2
  16. package/metadata/MetadataDiscovery.js +34 -11
  17. package/metadata/MetadataProvider.js +1 -1
  18. package/metadata/MetadataStorage.d.ts +4 -3
  19. package/metadata/MetadataStorage.js +15 -1
  20. package/metadata/Routine.js +4 -1
  21. package/naming-strategy/AbstractNamingStrategy.js +2 -1
  22. package/naming-strategy/NamingStrategy.d.ts +2 -1
  23. package/package.json +1 -1
  24. package/platforms/Platform.d.ts +2 -0
  25. package/platforms/Platform.js +4 -0
  26. package/typings.d.ts +2 -0
  27. package/unit-of-work/ChangeSet.js +10 -7
  28. package/unit-of-work/ChangeSetPersister.js +15 -7
  29. package/utils/AbstractMigrator.d.ts +1 -1
  30. package/utils/AbstractMigrator.js +3 -2
  31. package/utils/Configuration.d.ts +6 -0
  32. package/utils/Configuration.js +3 -1
  33. package/utils/Cursor.js +1 -6
  34. package/utils/EntityComparator.js +4 -1
  35. package/utils/QueryHelper.d.ts +5 -0
  36. package/utils/QueryHelper.js +25 -0
  37. package/utils/RawQueryFragment.d.ts +6 -0
  38. package/utils/RawQueryFragment.js +15 -6
  39. package/utils/RequestContext.d.ts +2 -2
  40. package/utils/RequestContext.js +11 -2
  41. package/utils/TransactionManager.d.ts +6 -0
  42. package/utils/TransactionManager.js +35 -2
  43. package/utils/Utils.js +6 -3
  44. package/utils/clone.js +6 -0
  45. 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
- parentWrapped.__data = wrapped.__data;
173
- parentWrapped.__originalEntityData = wrapped.__originalEntityData;
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.1';
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
- pks = Utils.flatten(pks);
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
- o[pk] = Utils.extractPK(entity[pk]);
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
@@ -79,6 +79,7 @@ export function loadEnvironmentVars() {
79
79
  read2('silent', bool);
80
80
  read2('emit');
81
81
  read2('snapshot', bool);
82
+ read2('snapshotOnMigrate', bool);
82
83
  read2('snapshotName');
83
84
  cleanup(ret, 'migrations');
84
85
  ret.schemaGenerator = {};