@mikro-orm/core 7.0.11-dev.9 → 7.0.12-dev.0

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 {
@@ -555,7 +555,12 @@ export class EntityLoader {
555
555
  };
556
556
  if (prop.polymorphic && prop.polymorphTargets) {
557
557
  await Promise.all(prop.polymorphTargets.map(async (targetMeta) => {
558
- const targetChildren = unique.filter(child => helper(child).__meta.className === targetMeta.className);
558
+ const targetChildren = unique.filter(child => {
559
+ const childMeta = helper(child).__meta;
560
+ // Use root.className for TPT entities: a Dog (root: Animal) should match
561
+ // targetMeta Animal. For non-TPT entities, root === self.
562
+ return childMeta.root.className === targetMeta.root.className;
563
+ });
559
564
  if (targetChildren.length > 0) {
560
565
  await populateChildren(targetMeta, targetChildren);
561
566
  }
@@ -1592,7 +1592,10 @@ export class MetadataDiscovery {
1592
1592
  prop.defaultRaw = this.#platform.formatQuery(raw.sql, raw.params);
1593
1593
  return;
1594
1594
  }
1595
- if (Array.isArray(prop.default) && prop.customType) {
1595
+ // TODO(v8): always convert the default via the custom type — the `compareAsType() !== 'any'`
1596
+ // guard preserves the legacy convention where JSON defaults are passed pre-stringified.
1597
+ // Array defaults are converted unconditionally (e.g. `default: []` on a JSON-backed embedded array).
1598
+ if (prop.customType && (Array.isArray(prop.default) || prop.customType.compareAsType() !== 'any')) {
1596
1599
  val = prop.customType.convertToDatabaseValue(prop.default, this.#platform);
1597
1600
  }
1598
1601
  prop.defaultRaw = typeof val === 'string' ? `'${val}'` : '' + val;
@@ -283,8 +283,10 @@ export class MetadataValidator {
283
283
  validateIndexes(meta, indexes, type) {
284
284
  for (const index of indexes) {
285
285
  for (const propName of Utils.asArray(index.properties)) {
286
- const prop = meta.root.properties[propName];
287
- if (!prop && !Object.values(meta.root.properties).some(p => propName.startsWith(p.name + '.'))) {
286
+ const prop = meta.properties[propName] ?? meta.root.properties[propName];
287
+ if (!prop &&
288
+ !Object.values(meta.properties).some(p => propName.startsWith(p.name + '.')) &&
289
+ !Object.values(meta.root.properties).some(p => propName.startsWith(p.name + '.'))) {
288
290
  throw MetadataError.unknownIndexProperty(meta, propName, type);
289
291
  }
290
292
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.11-dev.9",
3
+ "version": "7.0.12-dev.0",
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",
@@ -72,6 +72,7 @@ export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implem
72
72
  down(options?: string | string[] | Omit<MigrateOptions, 'from'>): Promise<MigrationInfo[]>;
73
73
  abstract getStorage(): IMigratorStorage;
74
74
  protected init(): Promise<void>;
75
+ protected initPaths(): Promise<void>;
75
76
  protected initServices(): void;
76
77
  protected resolve(params: {
77
78
  name: string;
@@ -89,7 +90,7 @@ export declare abstract class AbstractMigrator<D extends IDatabaseDriver> implem
89
90
  private detectSourceFolder;
90
91
  private registerDefaultListeners;
91
92
  private emit;
92
- private discoverMigrations;
93
+ protected discoverMigrations(): Promise<RunnableMigration[]>;
93
94
  private executeMigrations;
94
95
  private filterUp;
95
96
  private filterDown;
@@ -68,14 +68,24 @@ export class AbstractMigrator {
68
68
  return;
69
69
  }
70
70
  this.initialized = true;
71
- if (!this.options.migrationsList) {
72
- const { fs } = await import('@mikro-orm/core/fs-utils');
73
- this.detectSourceFolder(fs);
74
- /* v8 ignore next */
75
- const key = this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs ? 'pathTs' : 'path';
76
- this.absolutePath = fs.absolutePath(this.options[key], this.config.get('baseDir'));
71
+ await this.initPaths();
72
+ }
73
+ async initPaths() {
74
+ if (this.absolutePath || this.options.migrationsList) {
75
+ return;
76
+ }
77
+ const { fs } = await import('@mikro-orm/core/fs-utils');
78
+ this.detectSourceFolder(fs);
79
+ /* v8 ignore next */
80
+ const key = this.config.get('preferTs', Utils.detectTypeScriptSupport()) && this.options.pathTs ? 'pathTs' : 'path';
81
+ this.absolutePath = fs.absolutePath(this.options[key], this.config.get('baseDir'));
82
+ try {
77
83
  fs.ensureDir(this.absolutePath);
78
84
  }
85
+ catch {
86
+ // read-only filesystem — read-only operations (e.g. `getPending` with a
87
+ // snapshot) may still succeed; write operations will fail on their own
88
+ }
79
89
  }
80
90
  initServices() {
81
91
  this.runner = this.createRunner();
@@ -569,7 +569,14 @@ export class EntityComparator {
569
569
  ret += ` ret${dataKey} = null;\n`;
570
570
  ret += ` } else if (typeof entity${entityKey} !== 'undefined') {\n`;
571
571
  ret += ` const val${level} = entity${entityKey}${unwrap};\n`;
572
- ret += ` const discriminator = ${discriminatorMapKey}.get(val${level}?.constructor);\n`;
572
+ // walk up the prototype chain so TPT subclasses resolve to their root's discriminator
573
+ ret += ` let __cls${level} = val${level}?.constructor;\n`;
574
+ ret += ` let discriminator;\n`;
575
+ ret += ` while (__cls${level} != null) {\n`;
576
+ ret += ` discriminator = ${discriminatorMapKey}.get(__cls${level});\n`;
577
+ ret += ` if (discriminator !== undefined) break;\n`;
578
+ ret += ` __cls${level} = Object.getPrototypeOf(__cls${level});\n`;
579
+ ret += ` }\n`;
573
580
  ret += ` const pk = val${level}?.__helper?.__identifier && !val${level}?.__helper?.hasPrimaryKey()\n`;
574
581
  ret += ` ? val${level}.__helper.__identifier\n`;
575
582
  ret += ` : toArray(val${level}?.__helper?.getPrimaryKey(true));\n`;
@@ -8,6 +8,7 @@ export declare class QueryHelper {
8
8
  static readonly SUPPORTED_OPERATORS: string[];
9
9
  /**
10
10
  * Finds the discriminator value (key) for a given entity class in a discriminator map.
11
+ * Walks up the prototype chain so TPT subclasses resolve to their root's key.
11
12
  */
12
13
  static findDiscriminatorValue<T>(discriminatorMap: Dictionary<T>, targetClass: T): string | undefined;
13
14
  static processParams(params: unknown): any;
@@ -9,9 +9,19 @@ export class QueryHelper {
9
9
  static SUPPORTED_OPERATORS = ['>', '<', '<=', '>=', '!', '!='];
10
10
  /**
11
11
  * Finds the discriminator value (key) for a given entity class in a discriminator map.
12
+ * Walks up the prototype chain so TPT subclasses resolve to their root's key.
12
13
  */
13
14
  static findDiscriminatorValue(discriminatorMap, targetClass) {
14
- return Object.entries(discriminatorMap).find(([, cls]) => cls === targetClass)?.[0];
15
+ const entries = Object.entries(discriminatorMap);
16
+ let current = targetClass;
17
+ while (current != null) {
18
+ const hit = entries.find(([, cls]) => cls === current)?.[0];
19
+ if (hit) {
20
+ return hit;
21
+ }
22
+ current = Object.getPrototypeOf(current);
23
+ }
24
+ return undefined;
15
25
  }
16
26
  static processParams(params) {
17
27
  if (Reference.isReference(params)) {
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.9';
144
+ static #ORM_VERSION = '7.0.12-dev.0';
145
145
  /**
146
146
  * Checks if the argument is instance of `Object`. Returns false for arrays.
147
147
  */