@mikro-orm/core 7.2.5-dev.2 → 7.2.5-dev.4

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
@@ -781,14 +781,36 @@ export class EntityManager {
781
781
  em.#unitOfWork.unsetIdentity(entity);
782
782
  return null;
783
783
  }
784
+ // `serialize()` applies `Type.toJSON()` and `serializedName`, take only relations and embeddables from it, scalars from the entity
785
+ const getData = (e, data = helper(e).serialize({
786
+ ignoreSerializers: true,
787
+ includeHidden: true,
788
+ convertCustomTypes: false,
789
+ })) => {
790
+ for (const prop of helper(e).__meta.props) {
791
+ if (prop.kind === ReferenceKind.SCALAR && !prop.ref) {
792
+ data[prop.name] = e[prop.name];
793
+ continue;
794
+ }
795
+ if (prop.serializedName && prop.serializedName in data) {
796
+ data[prop.name] = data[prop.serializedName];
797
+ }
798
+ if (prop.kind === ReferenceKind.EMBEDDED && e[prop.name] != null) {
799
+ Utils.asArray(e[prop.name]).forEach((item, i) => getData(item, prop.array ? data[prop.name][i] : data[prop.name]));
800
+ }
801
+ }
802
+ return data;
803
+ };
804
+ const hydrate = (target, source) => {
805
+ em.config
806
+ .getHydrator(this.metadata)
807
+ .hydrate(target, helper(target).__meta, getData(source), em.#entityFactory, 'full', false, false);
808
+ Utils.merge(helper(target).__originalEntityData, this.#comparator.prepareEntity(source));
809
+ };
784
810
  let found = false;
785
811
  for (const e of fork.#unitOfWork.getIdentityMap()) {
786
812
  const ref = em.getReference(e.constructor, helper(e).getPrimaryKey());
787
- const data = helper(e).serialize({ ignoreSerializers: true, includeHidden: true, convertCustomTypes: false });
788
- em.config
789
- .getHydrator(this.metadata)
790
- .hydrate(ref, helper(ref).__meta, data, em.#entityFactory, 'full', false, false);
791
- Utils.merge(helper(ref).__originalEntityData, this.#comparator.prepareEntity(e));
813
+ hydrate(ref, e);
792
814
  // index a refreshed `targetKey` value, `getByKey` ignores the old one as stale
793
815
  if (helper(ref).__meta.root.targetKeys) {
794
816
  em.#unitOfWork.getIdentityMap().store(ref);
@@ -796,15 +818,7 @@ export class EntityManager {
796
818
  found ||= ref === entity;
797
819
  }
798
820
  if (!found) {
799
- const data = helper(reloaded).serialize({
800
- ignoreSerializers: true,
801
- includeHidden: true,
802
- convertCustomTypes: false,
803
- });
804
- em.config
805
- .getHydrator(this.metadata)
806
- .hydrate(entity, wrapped.__meta, data, em.#entityFactory, 'full', false, false);
807
- Utils.merge(wrapped.__originalEntityData, this.#comparator.prepareEntity(reloaded));
821
+ hydrate(entity, reloaded);
808
822
  }
809
823
  return entity;
810
824
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.2.5-dev.2",
3
+ "version": "7.2.5-dev.4",
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
  "keywords": [
6
6
  "data-mapper",
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.5-dev.2';
156
+ static #ORM_VERSION = '7.2.5-dev.4';
157
157
  /** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
158
158
  static getRlsSettingName(filterName, argName) {
159
159
  return `mikro.${filterName}.${argName}`;