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

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
@@ -136,6 +136,7 @@ export class EntityManager {
136
136
  await em.#entityLoader.populate(entityName, cached.data, populate, {
137
137
  ...options,
138
138
  ...em.getPopulateWhere(where, options),
139
+ orderBy: options.populateOrderBy ?? options.orderBy,
139
140
  ignoreLazyScalarProperties: true,
140
141
  lookup: false,
141
142
  });
@@ -166,6 +167,7 @@ export class EntityManager {
166
167
  await em.#entityLoader.populate(entityName, unique, populate, {
167
168
  ...options,
168
169
  ...em.getPopulateWhere(where, options),
170
+ orderBy: options.populateOrderBy ?? options.orderBy,
169
171
  ignoreLazyScalarProperties: true,
170
172
  lookup: false,
171
173
  });
@@ -1394,7 +1394,10 @@ export class MetadataDiscovery {
1394
1394
  // The primary key column is shared by every subtype, so it stays NOT NULL —
1395
1395
  // only subtype-specific columns become nullable for the rows of other subtypes.
1396
1396
  newProp.nullable = !newProp.primary;
1397
- newProp.inherited = !rootProp;
1397
+ // A subtype-specific property is `inherited` on the root so it is not pushed down to
1398
+ // sibling subtypes that don't declare it. When a second child redeclares the same
1399
+ // property, the root prop was already marked inherited by the first child, so keep it.
1400
+ newProp.inherited = !rootProp || !!rootProp.inherited;
1398
1401
  // For narrowed relation overrides, keep the root's declaration intact so
1399
1402
  // the full target union (e.g. `Food`) is preserved for populates from the
1400
1403
  // abstract root — otherwise the last child processed would win.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.1.5-dev.9",
3
+ "version": "7.1.5",
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",
@@ -993,21 +993,21 @@ export class UnitOfWork {
993
993
  const commitOrderReversed = [...commitOrder].reverse();
994
994
  // early delete - when we recreate entity in the same UoW, we need to issue those delete queries before inserts
995
995
  for (const meta of commitOrderReversed) {
996
- await this.commitDeleteChangeSets(groups[ChangeSetType.DELETE_EARLY].get(meta) ?? [], ctx);
996
+ await this.commitDeleteChangeSets(groups[ChangeSetType.DELETE_EARLY].get(meta._id) ?? [], ctx);
997
997
  }
998
998
  // early update - when we recreate entity in the same UoW, we need to issue those delete queries before inserts
999
999
  for (const meta of commitOrder) {
1000
- await this.commitUpdateChangeSets(groups[ChangeSetType.UPDATE_EARLY].get(meta) ?? [], ctx);
1000
+ await this.commitUpdateChangeSets(groups[ChangeSetType.UPDATE_EARLY].get(meta._id) ?? [], ctx);
1001
1001
  }
1002
1002
  // extra updates
1003
1003
  await this.commitExtraUpdates(ChangeSetType.UPDATE_EARLY, ctx);
1004
1004
  // create
1005
1005
  for (const meta of commitOrder) {
1006
- await this.commitCreateChangeSets(groups[ChangeSetType.CREATE].get(meta) ?? [], ctx);
1006
+ await this.commitCreateChangeSets(groups[ChangeSetType.CREATE].get(meta._id) ?? [], ctx);
1007
1007
  }
1008
1008
  // update
1009
1009
  for (const meta of commitOrder) {
1010
- await this.commitUpdateChangeSets(groups[ChangeSetType.UPDATE].get(meta) ?? [], ctx);
1010
+ await this.commitUpdateChangeSets(groups[ChangeSetType.UPDATE].get(meta._id) ?? [], ctx);
1011
1011
  }
1012
1012
  // extra updates
1013
1013
  await this.commitExtraUpdates(ChangeSetType.UPDATE, ctx);
@@ -1015,7 +1015,7 @@ export class UnitOfWork {
1015
1015
  await this.commitCollectionUpdates(ctx);
1016
1016
  // delete - entity deletions need to be in reverse commit order
1017
1017
  for (const meta of commitOrderReversed) {
1018
- await this.commitDeleteChangeSets(groups[ChangeSetType.DELETE].get(meta) ?? [], ctx);
1018
+ await this.commitDeleteChangeSets(groups[ChangeSetType.DELETE].get(meta._id) ?? [], ctx);
1019
1019
  }
1020
1020
  // take snapshots of all persisted collections
1021
1021
  const visited = new Set();
@@ -1209,7 +1209,10 @@ export class UnitOfWork {
1209
1209
  return;
1210
1210
  }
1211
1211
  const group = groups[cs.type];
1212
- const groupKey = cs.meta.inheritanceType === 'tpt' ? cs.meta : cs.rootMeta;
1212
+ // keyed by `_id` so the groups share keys with `getCommitOrder()`, which dedupes by `_id`;
1213
+ // two `EntityMetadata` instances with the same `_id` (shared metadata cache) must not split
1214
+ // a group between them, or the lookup in `persistToDatabase()` misses and drops it (GH #7903)
1215
+ const groupKey = cs.meta.inheritanceType === 'tpt' ? cs.meta._id : cs.rootMeta._id;
1213
1216
  const classGroup = group.get(groupKey) ?? [];
1214
1217
  classGroup.push(cs);
1215
1218
  if (!group.has(groupKey)) {
@@ -35,5 +35,7 @@ export declare abstract class AbstractSchemaGenerator<D extends IDatabaseDriver>
35
35
  execute(query: string): Promise<void>;
36
36
  ensureIndexes(): Promise<void>;
37
37
  protected getOrderedMetadata(schema?: string, includeWildcardSchema?: boolean): EntityMetadata[];
38
+ /** View entities are not backed by real tables, so they must be skipped when truncating/deleting during `clear()`. */
39
+ protected getOrderedMetadataForClear(schema?: string): EntityMetadata[];
38
40
  protected notImplemented(): never;
39
41
  }
@@ -39,7 +39,7 @@ export class AbstractSchemaGenerator {
39
39
  }
40
40
  }
41
41
  async clear(options) {
42
- for (const meta of this.getOrderedMetadata(options?.schema).reverse()) {
42
+ for (const meta of this.getOrderedMetadataForClear(options?.schema).reverse()) {
43
43
  await this.driver.nativeDelete(meta.class, {}, options);
44
44
  }
45
45
  if (options?.clearIdentityMap ?? true) {
@@ -123,6 +123,10 @@ export class AbstractSchemaGenerator {
123
123
  return schema ? [schema, '*'].includes(targetSchema) : meta.schema !== '*';
124
124
  });
125
125
  }
126
+ /** View entities are not backed by real tables, so they must be skipped when truncating/deleting during `clear()`. */
127
+ getOrderedMetadataForClear(schema) {
128
+ return this.getOrderedMetadata(schema).filter(meta => !meta.view);
129
+ }
126
130
  notImplemented() {
127
131
  throw new Error(`This method is not supported by ${this.driver.constructor.name} driver`);
128
132
  }
@@ -549,7 +549,13 @@ export class EntityComparator {
549
549
  }
550
550
  getPropertySnapshot(meta, prop, context, dataKey, entityKey, path, level = 1, object) {
551
551
  const unwrap = prop.ref ? '?.unwrap()' : '';
552
- let ret = ` if (${this.getPropertyCondition(path)}`;
552
+ let condition = this.getPropertyCondition(path);
553
+ // a getter may dereference state that only exists once hydrated, so when snapshotting an
554
+ // unhydrated reference we short-circuit the read behind the initialized check
555
+ if (prop.getter && !prop.setter && path.length === 1) {
556
+ condition = `entity.__helper.__initialized && ${condition}`;
557
+ }
558
+ let ret = ` if (${condition}`;
553
559
  if (prop.lazy && prop.ref) {
554
560
  ret += ` && entity${path.map(k => this.wrap(k)).join('')}?.isInitialized()`;
555
561
  }
@@ -1,5 +1,4 @@
1
- import type { EntityManager } from '../EntityManager.js';
2
- import { type LoggingOptions } from '../logging/Logger.js';
1
+ import type { EntityManager, ForkOptions } from '../EntityManager.js';
3
2
  /**
4
3
  * Uses `AsyncLocalStorage` to create async context that holds the current EM fork.
5
4
  */
@@ -35,8 +34,6 @@ export declare class RequestContext {
35
34
  static getEntityManager(name?: string): EntityManager | undefined;
36
35
  private static createContext;
37
36
  }
38
- /** Options for creating a new RequestContext, allowing schema and logger overrides. */
39
- export interface CreateContextOptions {
40
- schema?: string;
41
- loggerContext?: LoggingOptions;
37
+ /** Options for creating a new RequestContext, allowing global overrides. */
38
+ export interface CreateContextOptions extends Omit<ForkOptions, 'useContext' | 'disableContextResolution' | 'keepTransactionContext' | 'clear'> {
42
39
  }
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.5-dev.9';
144
+ static #ORM_VERSION = '7.1.5';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */
package/utils/clone.js CHANGED
@@ -33,6 +33,12 @@ export function clone(parent, respectCustomCloneMethod = true) {
33
33
  return parent;
34
34
  }
35
35
  if (respectCustomCloneMethod && 'clone' in parent && typeof parent.clone === 'function') {
36
+ // an async `clone()` signals a live stateful resource (e.g. a PGlite instance
37
+ // in `driverOptions`, whose `clone()` boots a second WASM database) — this sync
38
+ // function cannot await it, so keep the instance by reference instead
39
+ if (parent.clone.constructor.name === 'AsyncFunction') {
40
+ return parent;
41
+ }
36
42
  return parent.clone();
37
43
  }
38
44
  let child;