@mikro-orm/core 6.4.12-dev.9 → 6.4.12

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.
@@ -48,6 +48,7 @@ class EntityFactory {
48
48
  let wrapped = exists && (0, wrap_1.helper)(exists);
49
49
  if (wrapped && !options.refresh) {
50
50
  wrapped.__processing = true;
51
+ Utils_1.Utils.dropUndefinedProperties(data);
51
52
  this.mergeData(meta2, exists, data, options);
52
53
  wrapped.__processing = false;
53
54
  if (wrapped.isInitialized()) {
@@ -149,6 +149,9 @@ class EntityHelper {
149
149
  set(val) {
150
150
  const entity = Reference_1.Reference.unwrapReference(val ?? wrapped.__data[prop.name]);
151
151
  const old = Reference_1.Reference.unwrapReference(wrapped.__data[prop.name]);
152
+ if (old && old !== entity && prop.kind === enums_1.ReferenceKind.MANY_TO_ONE && prop.inversedBy && old[prop.inversedBy]) {
153
+ old[prop.inversedBy].removeWithoutPropagation(this);
154
+ }
152
155
  wrapped.__data[prop.name] = Reference_1.Reference.wrapReference(val, prop);
153
156
  // when propagation from inside hydration, we set the FK to the entity data immediately
154
157
  if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
@@ -315,7 +315,14 @@ class EntityLoader {
315
315
  .map(orderBy => orderBy[prop.name]);
316
316
  const { refresh, filters, ignoreLazyScalarProperties, populateWhere, connectionType, logging, schema } = options;
317
317
  const exclude = Array.isArray(options.exclude) ? Utils_1.Utils.extractChildElements(options.exclude, prop.name) : options.exclude;
318
- const filtered = Utils_1.Utils.unique(children.filter(e => !options.visited.has(e)));
318
+ const visited = options.visited;
319
+ for (const entity of entities) {
320
+ visited.delete(entity);
321
+ }
322
+ const filtered = Utils_1.Utils.unique(children.filter(e => !visited.has(e)));
323
+ for (const entity of entities) {
324
+ visited.add(entity);
325
+ }
319
326
  await this.populate(prop.type, filtered, populate.children ?? populate.all, {
320
327
  where: await this.extractChildCondition(options, prop, false),
321
328
  orderBy: innerOrderBy,
@@ -1124,7 +1124,7 @@ class MetadataDiscovery {
1124
1124
  }
1125
1125
  const mappedType = this.getMappedType(prop);
1126
1126
  if (prop.fieldNames?.length === 1 && !prop.customType) {
1127
- [types_1.BigIntType, types_1.DoubleType, types_1.DecimalType, types_1.IntervalType]
1127
+ [types_1.BigIntType, types_1.DoubleType, types_1.DecimalType, types_1.IntervalType, types_1.DateType]
1128
1128
  .filter(type => mappedType instanceof type)
1129
1129
  .forEach(type => prop.customType = new type());
1130
1130
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.12-dev.9",
3
+ "version": "6.4.12",
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.12-dev.9",
67
+ "mikro-orm": "6.4.12",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/typings.d.ts CHANGED
@@ -168,7 +168,7 @@ export interface IWrappedEntityInternal<Entity extends object> extends IWrappedE
168
168
  __touched: boolean;
169
169
  __originalEntityData?: EntityData<Entity>;
170
170
  __loadedProperties: Set<string>;
171
- __identifier?: EntityIdentifier;
171
+ __identifier?: EntityIdentifier | EntityIdentifier[];
172
172
  __managed: boolean;
173
173
  __processing: boolean;
174
174
  __schema?: string;
package/typings.js CHANGED
@@ -109,6 +109,9 @@ class EntityMetadata {
109
109
  const hydrator = wrapped.hydrator;
110
110
  const entity = entity_1.Reference.unwrapReference(val ?? wrapped.__data[prop.name]);
111
111
  const old = entity_1.Reference.unwrapReference(wrapped.__data[prop.name]);
112
+ if (old && old !== entity && prop.kind === enums_1.ReferenceKind.MANY_TO_ONE && prop.inversedBy && old[prop.inversedBy]) {
113
+ old[prop.inversedBy].removeWithoutPropagation(this);
114
+ }
112
115
  wrapped.__data[prop.name] = entity_1.Reference.wrapReference(val, prop);
113
116
  // when propagation from inside hydration, we set the FK to the entity data immediately
114
117
  if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
@@ -211,7 +211,9 @@ class ChangeSetPersister {
211
211
  // of using the raw value from db, we convert it back to the db value explicitly
212
212
  value = prop.customType ? prop.customType.convertToDatabaseValue(insertId, this.platform, { mode: 'serialization' }) : value;
213
213
  changeSet.payload[wrapped.__meta.primaryKeys[0]] = value;
214
- wrapped.__identifier?.setValue(value);
214
+ if (wrapped.__identifier && !Array.isArray(wrapped.__identifier)) {
215
+ wrapped.__identifier.setValue(value);
216
+ }
215
217
  }
216
218
  /**
217
219
  * Sets populate flag to new entities so they are serialized like if they were loaded from the db
@@ -339,6 +341,10 @@ class ChangeSetPersister {
339
341
  changeSet.payload[prop.name] = value.getValue();
340
342
  return;
341
343
  }
344
+ if (Array.isArray(value) && value.every(item => item instanceof entity_1.EntityIdentifier)) {
345
+ changeSet.payload[prop.name] = value.map(item => item.getValue());
346
+ return;
347
+ }
342
348
  if (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && Array.isArray(value)) {
343
349
  changeSet.payload[prop.name] = value.map(val => val instanceof entity_1.EntityIdentifier ? val.getValue() : val);
344
350
  return;
@@ -542,13 +542,22 @@ class UnitOfWork {
542
542
  if (!wrapped || wrapped.__identifier || wrapped.hasPrimaryKey()) {
543
543
  return;
544
544
  }
545
- const pk = wrapped.__meta.getPrimaryProps()[0];
546
- if (pk.kind === enums_1.ReferenceKind.SCALAR) {
547
- wrapped.__identifier = new entity_1.EntityIdentifier();
545
+ const pks = wrapped.__meta.getPrimaryProps();
546
+ const idents = [];
547
+ for (const pk of pks) {
548
+ if (pk.kind === enums_1.ReferenceKind.SCALAR) {
549
+ idents.push(new entity_1.EntityIdentifier(entity[pk.name]));
550
+ }
551
+ else if (entity[pk.name]) {
552
+ this.initIdentifier(entity[pk.name]);
553
+ idents.push((0, entity_1.helper)(entity[pk.name])?.__identifier);
554
+ }
555
+ }
556
+ if (pks.length === 1) {
557
+ wrapped.__identifier = idents[0];
548
558
  }
549
- else if (entity[pk.name]) {
550
- this.initIdentifier(entity[pk.name]);
551
- wrapped.__identifier = (0, entity_1.helper)(entity[pk.name])?.__identifier;
559
+ else {
560
+ wrapped.__identifier = idents;
552
561
  }
553
562
  }
554
563
  processReference(parent, prop, kind, visited, processed, idx) {
@@ -600,8 +609,15 @@ class UnitOfWork {
600
609
  const diff = this.comparator.diffEntities(changeSet.name, copy, current);
601
610
  Object.assign(changeSet.payload, diff);
602
611
  const wrapped = (0, entity_1.helper)(changeSet.entity);
603
- if (wrapped.__identifier && diff[wrapped.__meta.primaryKeys[0]]) {
604
- wrapped.__identifier.setValue(diff[wrapped.__meta.primaryKeys[0]]);
612
+ if (wrapped.__identifier) {
613
+ const idents = Utils_1.Utils.asArray(wrapped.__identifier);
614
+ let i = 0;
615
+ for (const pk of wrapped.__meta.primaryKeys) {
616
+ if (diff[pk]) {
617
+ idents[i].setValue(diff[pk]);
618
+ }
619
+ i++;
620
+ }
605
621
  }
606
622
  }
607
623
  postCommitCleanup() {