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

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.
@@ -122,7 +122,11 @@ export class EntityFactory {
122
122
  newEntity: options.newEntity,
123
123
  loaded: options.initialized,
124
124
  });
125
- if (options.recomputeSnapshot) {
125
+ // A reference seeded from a raw scalar PK with `convertCustomTypes: false` (e.g. `em.getReference()` or a to-one
126
+ // relation assigned a raw scalar in `em.create()`) keeps its snapshot in JS-form, while `prepareEntity()` derives
127
+ // DB-form — so for a custom type mapping between different shapes (e.g. ULID <-> UUID) they always diff, yielding a
128
+ // spurious PK update on every flush. Recompute the snapshot from the entity to keep it in DB-form (GH #7966).
129
+ if (options.recomputeSnapshot || (!options.convertCustomTypes && !options.initialized)) {
126
130
  wrapped.__originalEntityData = this.#comparator.prepareEntity(entity);
127
131
  }
128
132
  }
@@ -189,8 +193,7 @@ export class EntityFactory {
189
193
  [ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE, ReferenceKind.SCALAR].includes(prop.kind) &&
190
194
  prop.customType?.ensureComparable(meta, prop) &&
191
195
  diff2[key] != null) {
192
- const converted = prop.customType.convertToJSValue(diff2[key], this.#platform, { force: true });
193
- diff2[key] = prop.customType.convertToDatabaseValue(converted, this.#platform, { fromQuery: true });
196
+ diff2[key] = prop.customType.convertToDatabaseValue(diff2[key], this.#platform, { fromQuery: true });
194
197
  }
195
198
  originalEntityData[key] = diff2[key] === null ? nullVal : diff2[key];
196
199
  helper(entity).__loadedProperties.add(key);
@@ -691,6 +691,9 @@ export interface EntityMetadataWithProperties<TName extends string, TTableName e
691
691
  }
692
692
  /** Defines an entity schema using property builders, with full type inference from the property definitions. */
693
693
  export declare function defineEntity<const TName extends string, const TTableName extends string, const TProperties extends Record<string, any>, const TPK extends (keyof TProperties)[] | undefined = undefined, const TBase = never, const TRepository = never, const TForceObject extends boolean = false, const TDiscriminatorColumn extends string | undefined = undefined, const TDiscriminatorValue extends string | number | undefined = undefined, const TBaseDiscriminatorColumn extends string | undefined = undefined>(meta: EntityMetadataWithProperties<TName, TTableName, TProperties, TPK, TBase, TRepository, TForceObject, TDiscriminatorColumn, TDiscriminatorValue, TBaseDiscriminatorColumn>): EntitySchemaWithMeta<TName, TTableName, InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject, TBaseDiscriminatorColumn, TDiscriminatorValue>, TBase, TProperties, EntityCtor<InferEntityFromProperties<TProperties, TPK, TBase, TRepository, TForceObject, TBaseDiscriminatorColumn, TDiscriminatorValue>>, TDiscriminatorColumn>;
694
+ export declare namespace defineEntity {
695
+ export { propertyBuilders as properties };
696
+ }
694
697
  /** Defines an entity schema for an existing class, combining the class with property builders. */
695
698
  export declare function defineEntity<const TEntity = any, const TProperties extends Record<string, any> = Record<string, any>, const TClassName extends string = string, const TTableName extends string = string, const TBase = never, const TClass extends EntityCtor = EntityCtor<TEntity>>(meta: Omit<Partial<EntityMetadata<TEntity>>, 'properties' | 'extends' | 'className' | 'tableName' | 'hooks'> & {
696
699
  class: TClass;
@@ -700,9 +703,6 @@ export declare function defineEntity<const TEntity = any, const TProperties exte
700
703
  properties: TProperties | ((properties: PropertyBuilders) => TProperties);
701
704
  hooks?: DefineEntityHooks<TEntity>;
702
705
  }): EntitySchemaWithMeta<TClassName, TTableName, TEntity, TBase, TProperties, TClass>;
703
- export declare namespace defineEntity {
704
- var properties: PropertyBuilders;
705
- }
706
706
  /** Shorthand alias for `defineEntity.properties` - the property builders for use in `defineEntity()`. */
707
707
  export { propertyBuilders as p };
708
708
  type EntityHookValue<T, K extends keyof EventSubscriber<T>> = (keyof T | NonNullable<EventSubscriber<T>[K]>)[];
@@ -44,6 +44,9 @@ export class MetadataProvider {
44
44
  }
45
45
  /** Merges cached metadata into the given entity metadata, preserving function expressions. */
46
46
  loadFromCache(meta, cache) {
47
+ // `_id` is a process-local runtime counter; a cached value comes from a different discovery
48
+ // run and can collide with ids assigned in the current process, collapsing distinct entities.
49
+ Reflect.deleteProperty(cache, '_id');
47
50
  Object.values(cache.properties).forEach(prop => {
48
51
  const metaProp = meta.properties[prop.name];
49
52
  /* v8 ignore next */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.6-dev.9",
3
+ "version": "7.1.6",
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
@@ -141,7 +141,7 @@ export function parseJsonSafe(value) {
141
141
  /** Collection of general-purpose utility methods used throughout the ORM. */
142
142
  export class Utils {
143
143
  static PK_SEPARATOR = '~~~';
144
- static #ORM_VERSION = '7.1.6-dev.9';
144
+ static #ORM_VERSION = '7.1.6';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */