@mikro-orm/core 7.1.8-dev.7 → 7.1.8-dev.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.8-dev.7",
3
+ "version": "7.1.8-dev.8",
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",
@@ -12,6 +12,11 @@ export declare class IdentityMap {
12
12
  storeByKey<T>(item: T, key: string, value: string, schema?: string): void;
13
13
  /** Removes an entity and its alternate key entries from the identity map. */
14
14
  delete<T>(item: T): void;
15
+ /**
16
+ * Retrieves the entity occupying the same slot as the given one, if any. Hashes the entity the same way `store()`
17
+ * does, so it matches regardless of the primary key shape — unlike hashing a primary key value obtained elsewhere.
18
+ */
19
+ getByEntity<T>(item: T): T | undefined;
15
20
  /** Retrieves an entity by its hash key from the identity map. */
16
21
  getByHash<T>(meta: EntityMetadata<T>, hash: string): T | undefined;
17
22
  /** Returns (or creates) the per-entity-class store within the identity map. */
@@ -40,6 +40,13 @@ export class IdentityMap {
40
40
  this.#alternateKeys.delete(item);
41
41
  }
42
42
  }
43
+ /**
44
+ * Retrieves the entity occupying the same slot as the given one, if any. Hashes the entity the same way `store()`
45
+ * does, so it matches regardless of the primary key shape — unlike hashing a primary key value obtained elsewhere.
46
+ */
47
+ getByEntity(item) {
48
+ return this.getStore(item.__meta.root).get(this.getPkHash(item));
49
+ }
43
50
  /** Retrieves an entity by its hash key from the identity map. */
44
51
  getByHash(meta, hash) {
45
52
  const store = this.getStore(meta);
@@ -172,6 +172,10 @@ export class EntityComparator {
172
172
  if (meta.properties[pk].kind !== ReferenceKind.SCALAR) {
173
173
  lines.push(` (entity${this.wrap(pk)} != null && isEntityOrRef(entity${this.wrap(pk)})) ? entity${this.wrap(pk)}.__helper.getSerializedPrimaryKey() : entity${this.wrap(pk)},`);
174
174
  }
175
+ else if (meta.properties[pk].customType) {
176
+ const convertorKey = this.registerCustomType(meta.properties[pk], context);
177
+ lines.push(` convertToDatabaseValue_${convertorKey}(entity${this.wrap(pk)}),`);
178
+ }
175
179
  else {
176
180
  lines.push(` entity${this.wrap(pk)},`);
177
181
  }
@@ -162,8 +162,7 @@ export class TransactionManager {
162
162
  for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
163
163
  const wrapped = helper(entity);
164
164
  const meta = wrapped.__meta;
165
- // the identity map is keyed by the database form, so the lookup has to use it too
166
- const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(true), parent.schema, true);
165
+ const parentEntity = parentUoW.getIdentityMap().getByEntity(entity);
167
166
  if (parentEntity && parentEntity !== entity) {
168
167
  const parentWrapped = helper(parentEntity);
169
168
  // Don't overwrite a fully-loaded entity with an uninitialized reference
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.1.8-dev.7';
156
+ static #ORM_VERSION = '7.1.8-dev.8';
157
157
  /**
158
158
  * Checks if the argument is instance of `Object`. Returns false for arrays.
159
159
  */