@mikro-orm/core 6.6.14-dev.2 → 6.6.14

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 CHANGED
@@ -1066,9 +1066,6 @@ class EntityManager {
1066
1066
  (0, entity_1.helper)(data).setSchema(options.schema);
1067
1067
  }
1068
1068
  if (!(0, entity_1.helper)(data).__managed) {
1069
- // the entity might have been created via `em.create()`, which adds it to the persist stack automatically
1070
- em.unitOfWork.getPersistStack().delete(data);
1071
- // it can be also in the identity map if it had a PK value already
1072
1069
  em.unitOfWork.unsetIdentity(data);
1073
1070
  }
1074
1071
  const meta = (0, entity_1.helper)(data).__meta;
@@ -1106,9 +1103,6 @@ class EntityManager {
1106
1103
  (0, entity_1.helper)(row).setSchema(options.schema);
1107
1104
  }
1108
1105
  if (!(0, entity_1.helper)(row).__managed) {
1109
- // the entity might have been created via `em.create()`, which adds it to the persist stack automatically
1110
- em.unitOfWork.getPersistStack().delete(row);
1111
- // it can be also in the identity map if it had a PK value already
1112
1106
  em.unitOfWork.unsetIdentity(row);
1113
1107
  }
1114
1108
  const payload = em.comparator.prepareEntity(row);
@@ -1589,8 +1583,13 @@ class EntityManager {
1589
1583
  return [];
1590
1584
  }
1591
1585
  const meta = this.metadata.find(entityName);
1592
- // infer populate hint if only `fields` are available
1593
- if (!options.populate && options.fields) {
1586
+ // infer populate hints from `fields` when present; merge with explicit `populate` if both are set
1587
+ const fields = options.fields ? this.buildFields(options.fields) : undefined;
1588
+ const populateArray = Array.isArray(options.populate) ? options.populate : undefined;
1589
+ const hasNestedFields = fields?.some(f => f.includes('.')) ?? false;
1590
+ const shouldInfer = fields !== undefined && options.populate === undefined;
1591
+ const shouldMerge = fields !== undefined && populateArray !== undefined && populateArray.length > 0 && hasNestedFields;
1592
+ if (shouldInfer || shouldMerge) {
1594
1593
  // we need to prune the `populate` hint from to-one relations, as partially loading them does not require their population, we want just the FK
1595
1594
  const pruneToOneRelations = (meta, fields) => {
1596
1595
  const ret = [];
@@ -1621,7 +1620,16 @@ class EntityManager {
1621
1620
  }
1622
1621
  return utils_1.Utils.unique(ret);
1623
1622
  };
1624
- options.populate = pruneToOneRelations(meta, this.buildFields(options.fields));
1623
+ const fromFields = pruneToOneRelations(meta, fields);
1624
+ if (shouldInfer) {
1625
+ options.populate = fromFields;
1626
+ }
1627
+ else {
1628
+ // with an explicit populate, only nested paths (e.g. `item.id`) need to be merged in — they
1629
+ // require a JOIN to access sub-fields, whereas bare names are already handled by the driver
1630
+ const extras = fromFields.filter(f => f.includes('.'));
1631
+ options.populate = [...populateArray, ...extras];
1632
+ }
1625
1633
  }
1626
1634
  if (!options.populate) {
1627
1635
  const populate = this.entityLoader.normalizePopulate(entityName, [], options.strategy, true, options.exclude);
@@ -247,6 +247,9 @@ class EntityFactory {
247
247
  }
248
248
  assignDefaultValues(entity, meta) {
249
249
  for (const prop of meta.props) {
250
+ if (prop.getter && !prop.setter) {
251
+ continue;
252
+ }
250
253
  if (prop.onCreate) {
251
254
  entity[prop.name] ??= prop.onCreate(entity, this.em);
252
255
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.6.14-dev.2",
3
+ "version": "6.6.14",
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.3",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.6.14-dev.2",
67
+ "mikro-orm": "6.6.14",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -12,7 +12,7 @@ function isVisible(meta, propName, options) {
12
12
  if (options.groups && prop?.groups) {
13
13
  return prop.groups.some(g => options.groups.includes(g));
14
14
  }
15
- if (Array.isArray(options.populate) && options.populate?.find(item => item === propName || item.startsWith(propName + '.') || item === '*')) {
15
+ if (Array.isArray(options.populate) && options.populate?.find(item => item === propName || item.startsWith(propName + '.'))) {
16
16
  return true;
17
17
  }
18
18
  if (options.exclude?.find(item => item === propName)) {
@@ -381,6 +381,9 @@ class UnitOfWork {
381
381
  }
382
382
  unsetIdentity(entity) {
383
383
  this.identityMap.delete(entity);
384
+ this.persistStack.delete(entity);
385
+ this.removeStack.delete(entity);
386
+ this.orphanRemoveStack.delete(entity);
384
387
  const wrapped = (0, entity_1.helper)(entity);
385
388
  const serializedPK = wrapped.getSerializedPrimaryKey();
386
389
  // remove references of this entity in all managed entities, otherwise flushing could reinsert the entity
package/utils/Utils.js CHANGED
@@ -688,8 +688,9 @@ class Utils {
688
688
  // In some situations (e.g. swc 1.3.4+), the presence of a source map can obscure the call to
689
689
  // __decorate(), replacing it with the constructor name. To support these cases we look for
690
690
  // Reflect.decorate() as well. Also when babel is used, we need to check
691
- // the `_applyDecoratedDescriptor` method instead.
692
- let line = stack.findIndex(line => line.match(/__decorate|Reflect\.decorate|_applyDecoratedDescriptor/));
691
+ // the `_applyDecoratedDescriptor` method instead. TypeScript 5+ emits `__esDecorate`
692
+ // (inlined into the user file) for TC39 stage-3 native decorators.
693
+ let line = stack.findIndex(line => line.match(/__decorate|__esDecorate|Reflect\.decorate|_applyDecoratedDescriptor/));
693
694
  // bun does not have those lines at all, only the DecorateProperty/DecorateConstructor,
694
695
  // but those are also present in node, so we need to check this only if they weren't found.
695
696
  if (line === -1) {