@mikro-orm/core 7.0.11-dev.1 → 7.0.11-dev.11

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.
@@ -248,6 +248,7 @@ export interface NativeInsertUpdateOptions<T> {
248
248
  /** `nativeUpdate()` only option */
249
249
  upsert?: boolean;
250
250
  loggerContext?: LogContext;
251
+ logging?: LoggingOptions;
251
252
  /** sql only */
252
253
  unionWhere?: ObjectQuery<T>[];
253
254
  /** sql only */
@@ -310,6 +311,8 @@ export interface UpdateOptions<T> {
310
311
  filters?: FilterOptions;
311
312
  schema?: string;
312
313
  ctx?: Transaction;
314
+ loggerContext?: LogContext;
315
+ logging?: LoggingOptions;
313
316
  /** sql only */
314
317
  unionWhere?: ObjectQuery<T>[];
315
318
  /** sql only */
@@ -347,6 +350,7 @@ export interface DriverMethodOptions {
347
350
  ctx?: Transaction;
348
351
  schema?: string;
349
352
  loggerContext?: LogContext;
353
+ logging?: LoggingOptions;
350
354
  }
351
355
  /** MongoDB-style collation options for locale-aware string comparison. */
352
356
  export interface CollationOptions {
@@ -139,12 +139,6 @@ export class EntityFactory {
139
139
  const existsData = this.#comparator.prepareEntity(entity);
140
140
  const originalEntityData = helper(entity).__originalEntityData ?? {};
141
141
  const diff = this.#comparator.diffEntities(meta.class, originalEntityData, existsData);
142
- // version properties are not part of entity snapshots
143
- if (meta.versionProperty &&
144
- data[meta.versionProperty] &&
145
- data[meta.versionProperty] !== originalEntityData[meta.versionProperty]) {
146
- diff[meta.versionProperty] = data[meta.versionProperty];
147
- }
148
142
  const diff2 = this.#comparator.diffEntities(meta.class, existsData, data, { includeInverseSides: true });
149
143
  // do not override values changed by user; for uninitialized entities,
150
144
  // the diff may include stale snapshot entries (value is undefined) — skip those
@@ -167,10 +161,11 @@ export class EntityFactory {
167
161
  return diff2[key] === undefined;
168
162
  })
169
163
  .forEach(key => delete diff2[key]);
170
- // but always add collection properties, formulas, and generated columns if they are part of the `data`,
171
- // as these are excluded from `comparableProps` and won't appear in the diff
164
+ // but always add collection properties, formulas, generated columns, and version properties if they
165
+ // are part of the `data`, as these are excluded from `comparableProps` and won't appear in the diff
172
166
  Utils.keys(data)
173
167
  .filter(key => meta.properties[key]?.formula ||
168
+ meta.properties[key]?.version ||
174
169
  (meta.properties[key]?.generated && !meta.properties[key]?.primary) ||
175
170
  [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(meta.properties[key]?.kind))
176
171
  .forEach(key => (diff2[key] = data[key]));
@@ -47,7 +47,12 @@ export class EntityLoader {
47
47
  throw ValidationError.invalidPropertyName(entityName, invalid.field);
48
48
  }
49
49
  this.setSerializationContext(entities, populate, options);
50
+ const addedToVisited = [];
50
51
  for (const entity of entities) {
52
+ if (visited.has(entity)) {
53
+ continue;
54
+ }
55
+ addedToVisited.push(entity);
51
56
  visited.add(entity);
52
57
  }
53
58
  for (const pop of populate) {
@@ -79,7 +84,7 @@ export class EntityLoader {
79
84
  });
80
85
  }
81
86
  }
82
- for (const entity of entities) {
87
+ for (const entity of addedToVisited) {
83
88
  visited.delete(entity);
84
89
  }
85
90
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.11-dev.1",
3
+ "version": "7.0.11-dev.11",
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/typings.d.ts CHANGED
@@ -441,12 +441,13 @@ type RequiredNullableKeys<T> = {
441
441
  [K in keyof T]: Exclude<T[K], null> extends RequiredNullable.Brand ? K : never;
442
442
  }[keyof T];
443
443
  type ProbablyOptionalProps<T> = PrimaryProperty<T> | ExplicitlyOptionalProps<T> | Exclude<NonNullable<NullableKeys<T, null | undefined>>, RequiredNullableKeys<T>>;
444
+ type RestoreOptUnknown<T> = [Exclude<T, null | undefined>] extends [Opt.Brand] ? [Opt.Brand] extends [Exclude<T, null | undefined>] ? unknown : T : T;
444
445
  type IsOptional<T, K extends keyof T, I> = T[K] extends CollectionShape ? true : ExtractType<T[K]> extends I ? true : K extends ProbablyOptionalProps<T> ? true : false;
445
446
  type RequiredKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? CleanKeys<T, K> : never;
446
447
  type OptionalKeys<T, K extends keyof T, I> = IsOptional<T, K, I> extends false ? never : CleanKeys<T, K>;
447
448
  /** Data shape for creating or updating entities. All properties are optional. Used in `em.create()` and `em.assign()`. */
448
449
  export type EntityData<T, C extends boolean = false> = {
449
- [K in EntityKey<T>]?: EntityDataItem<T[K] & {}, C>;
450
+ [K in EntityKey<T>]?: RestoreOptUnknown<T[K]> | EntityDataItem<T[K] & {}, C>;
450
451
  };
451
452
  /**
452
453
  * Data shape for `em.create()` with required/optional distinction based on entity metadata.
@@ -454,9 +455,9 @@ export type EntityData<T, C extends boolean = false> = {
454
455
  * `I` excludes additional types from being required (used for inverse side of relations).
455
456
  */
456
457
  export type RequiredEntityData<T, I = never, C extends boolean = false> = {
457
- [K in keyof T as RequiredKeys<T, K, I>]: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw;
458
+ [K in keyof T as RequiredKeys<T, K, I>]: RestoreOptUnknown<T[K]> | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw;
458
459
  } & {
459
- [K in keyof T as OptionalKeys<T, K, I>]?: T[K] | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw | null;
460
+ [K in keyof T as OptionalKeys<T, K, I>]?: RestoreOptUnknown<T[K]> | RequiredEntityDataProp<T[K], T, C> | Primary<T[K]> | PolymorphicPrimary<T[K]> | Raw | null;
460
461
  };
461
462
  /** `EntityData<T>` extended with an index signature, allowing arbitrary additional properties. */
462
463
  export type EntityDictionary<T> = EntityData<T> & Record<any, any>;
@@ -494,7 +495,9 @@ type PrimaryOrObject<T, U, C extends TypeConfig> = PreferExplicitConfig<C, Extra
494
495
  } : Primary<U>;
495
496
  type DTOWrapper<T, C extends TypeConfig, Flat extends boolean> = Flat extends true ? EntityDTOFlat<T, C> : EntityDTO<T, C>;
496
497
  /** Resolves the serialized (DTO) type for a single entity property. Unwraps references, collections, and custom serialized types. */
497
- export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar ? T : T extends ScalarReference<infer U> ? U : T extends {
498
+ export type EntityDTOProp<E, T, C extends TypeConfig = never, Flat extends boolean = false> = T extends Scalar ? T extends {
499
+ __serialized?: infer U;
500
+ } ? IsUnknown<U> extends false ? U : T : T : T extends ScalarReference<infer U> ? U : T extends {
498
501
  __serialized?: infer U;
499
502
  } ? IsUnknown<U> extends false ? U : T : T extends LoadedReferenceShape<infer U> ? DTOWrapper<U, C, Flat> : T extends ReferenceShape<infer U> ? PrimaryOrObject<E, U, C> : T extends LoadedCollectionShape<infer U> ? DTOWrapper<U & object, C, Flat>[] : T extends CollectionShape<infer U> ? PrimaryOrObject<E, U & object, C>[] : T extends readonly (infer U)[] ? U extends Scalar ? T : EntityDTOProp<E, U, C, Flat>[] : T extends Relation<T> ? DTOWrapper<T, C, Flat> : T;
500
503
  type UnwrapLoadedEntity<T> = T extends {
@@ -327,6 +327,10 @@ export class ChangeSetPersister {
327
327
  const primaryKeys = meta.primaryKeys.concat(...meta.concurrencyCheckKeys);
328
328
  options = this.prepareOptions(meta, options, {
329
329
  fields: primaryKeys,
330
+ orderBy: meta.primaryKeys.reduce((o, pk) => {
331
+ o[pk] = 'asc';
332
+ return o;
333
+ }, {}),
330
334
  });
331
335
  const res = await this.#driver.find(meta.root.class, { $or }, options);
332
336
  if (res.length !== changeSets.length) {
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.0.11-dev.1';
144
+ static #ORM_VERSION = '7.0.11-dev.11';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */