@mikro-orm/core 7.0.10-dev.1 → 7.0.10-dev.10

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.
@@ -7,7 +7,12 @@ import { ReferenceKind } from '../enums.js';
7
7
  import { helper } from './wrap.js';
8
8
  import { inspect } from '../logging/inspect.js';
9
9
  import { getEnv } from '../utils/env-vars.js';
10
- const entitySymbol = Symbol('Entity');
10
+ // Globally registered so the marker survives the CJS/ESM dual-package hazard
11
+ // (#7515) — `tsx` registers both an ESM and a CJS hook for the CLI and ends up
12
+ // loading `@mikro-orm/core` twice. JSON payloads still cannot forge the marker
13
+ // because Symbol-keyed properties have no JSON representation, which is the
14
+ // threat model the symbol-vs-string switch in f7e59a5ce was guarding against.
15
+ const entitySymbol = Symbol.for('@mikro-orm/core/EntityHelper.entity');
11
16
  /**
12
17
  * @internal
13
18
  */
@@ -39,11 +44,6 @@ export class EntityHelper {
39
44
  // toJSON can be overridden
40
45
  Object.defineProperty(prototype, 'toJSON', {
41
46
  value: function (...args) {
42
- // Guard against being called on the prototype itself (e.g. by serializers
43
- // walking the object graph and calling toJSON on prototype objects)
44
- if (this === prototype) {
45
- return {};
46
- }
47
47
  return EntityTransformer.toObject(this, ...args);
48
48
  },
49
49
  writable: true,
@@ -51,6 +51,22 @@ export class EntityHelper {
51
51
  enumerable: false,
52
52
  });
53
53
  }
54
+ // Walkers / serializers reaching the prototype directly invoke its methods and
55
+ // accessors with `this === prototype`. Wrap each so that case is a no-op rather
56
+ // than throwing (when a user `@Property({ persist: false })` getter dereferences
57
+ // unhydrated instance state) or installing state on the prototype itself (#7151).
58
+ for (const name of Object.getOwnPropertyNames(prototype)) {
59
+ const desc = Object.getOwnPropertyDescriptor(prototype, name);
60
+ const fn = desc.get ?? desc.value;
61
+ if (name === 'constructor' || typeof fn !== 'function' || fn.__guarded) {
62
+ continue;
63
+ }
64
+ const guarded = function (...args) {
65
+ return this === prototype ? undefined : fn.apply(this, args);
66
+ };
67
+ guarded.__guarded = true;
68
+ Object.defineProperty(prototype, name, desc.get ? { ...desc, get: guarded } : { ...desc, value: guarded });
69
+ }
54
70
  }
55
71
  /**
56
72
  * As a performance optimization, we create entity state methods lazily. We first add
@@ -393,7 +393,7 @@ export class MetadataDiscovery {
393
393
  }
394
394
  if (prop.joinColumns.length > 1) {
395
395
  prop.ownColumns = prop.joinColumns.filter(col => {
396
- return !meta.props.find(p => p.name !== prop.name && (!p.fieldNames || p.fieldNames.includes(col)));
396
+ return !meta.props.find(p => p.name !== prop.name && p.fieldNames?.includes(col));
397
397
  });
398
398
  }
399
399
  if (!prop.ownColumns || prop.ownColumns.length === 0) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "7.0.10-dev.1",
3
+ "version": "7.0.10-dev.10",
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",
@@ -1188,20 +1188,21 @@ export class UnitOfWork {
1188
1188
  }
1189
1189
  getCommitOrder() {
1190
1190
  const calc = new CommitOrderCalculator();
1191
- const set = new Set();
1191
+ // keyed by `_id` so we return the SAME instances as the change set groups (GH #7511)
1192
+ const metaById = new Map();
1192
1193
  this.#changeSets.forEach(cs => {
1193
1194
  if (cs.meta.inheritanceType === 'tpt') {
1194
- set.add(cs.meta);
1195
+ metaById.set(cs.meta._id, cs.meta);
1195
1196
  for (const parentCs of cs.tptChangeSets ?? []) {
1196
- set.add(parentCs.meta);
1197
+ metaById.set(parentCs.meta._id, parentCs.meta);
1197
1198
  }
1198
1199
  }
1199
1200
  else {
1200
- set.add(cs.rootMeta);
1201
+ metaById.set(cs.rootMeta._id, cs.rootMeta);
1201
1202
  }
1202
1203
  });
1203
- set.forEach(meta => calc.addNode(meta._id));
1204
- for (const meta of set) {
1204
+ metaById.forEach(meta => calc.addNode(meta._id));
1205
+ for (const meta of metaById.values()) {
1205
1206
  for (const prop of meta.relations) {
1206
1207
  if (prop.polymorphTargets) {
1207
1208
  for (const targetMeta of prop.polymorphTargets) {
@@ -1213,11 +1214,11 @@ export class UnitOfWork {
1213
1214
  }
1214
1215
  }
1215
1216
  // For TPT, parent table must be inserted BEFORE child tables
1216
- if (meta.inheritanceType === 'tpt' && meta.tptParent && set.has(meta.tptParent)) {
1217
+ if (meta.inheritanceType === 'tpt' && meta.tptParent && metaById.has(meta.tptParent._id)) {
1217
1218
  calc.addDependency(meta.tptParent._id, meta._id, 1);
1218
1219
  }
1219
1220
  }
1220
- return calc.sort().map(id => this.#metadata.getById(id));
1221
+ return calc.sort().map(id => metaById.get(id));
1221
1222
  }
1222
1223
  resetTransaction(oldTx) {
1223
1224
  if (oldTx) {
@@ -106,7 +106,10 @@ export class QueryHelper {
106
106
  Object.keys(where).every(k => !Utils.isPlainObject(where[k]) ||
107
107
  Object.keys(where[k]).every(v => {
108
108
  if (Utils.isOperator(v, false)) {
109
- return true;
109
+ // multi-value operators (e.g. `$in`/`$nin`) cannot be inlined into a composite
110
+ // PK tuple — `getPrimaryKeyValues` would flatten the operator's array alongside
111
+ // the sibling PK values, producing a malformed `(col1, col2) IN ((a, b))` clause
112
+ return !meta.compositePK || !Array.isArray(where[k][v]);
110
113
  }
111
114
  if (meta.properties[k].primary &&
112
115
  [ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(meta.properties[k].kind)) {
package/utils/Utils.js CHANGED
@@ -132,7 +132,7 @@ export function parseJsonSafe(value) {
132
132
  /** Collection of general-purpose utility methods used throughout the ORM. */
133
133
  export class Utils {
134
134
  static PK_SEPARATOR = '~~~';
135
- static #ORM_VERSION = '7.0.10-dev.1';
135
+ static #ORM_VERSION = '7.0.10-dev.10';
136
136
  /**
137
137
  * Checks if the argument is instance of `Object`. Returns false for arrays.
138
138
  */
@@ -647,8 +647,10 @@ export class Utils {
647
647
  * Extracts all possible values of a TS enum. Works with both string and numeric enums.
648
648
  */
649
649
  static extractEnumValues(target) {
650
- const keys = Object.keys(target);
651
- const values = Object.values(target);
650
+ // skip namespace-merged functions (GH #7500)
651
+ const entries = Object.entries(target).filter(([, v]) => typeof v !== 'function');
652
+ const keys = entries.map(([k]) => k);
653
+ const values = entries.map(([, v]) => v);
652
654
  const numeric = !!values.find(v => typeof v === 'number');
653
655
  const constEnum = values.length % 2 === 0 && // const enum will have even number of items
654
656
  values.slice(0, values.length / 2).every(v => typeof v === 'string') && // first half are strings
package/utils/fs-utils.js CHANGED
@@ -14,10 +14,11 @@ export const fs = {
14
14
  if (tinyGlobby) {
15
15
  globSync = (patterns, options) => {
16
16
  patterns = Utils.asArray(patterns).map(p => p.replace(/\\/g, '/'));
17
- if (options?.cwd) {
18
- options = { ...options, cwd: options.cwd.replace(/\\/g, '/') };
19
- }
20
- return tinyGlobby.globSync(patterns, { ...options, expandDirectories: false });
17
+ // never forward `cwd: undefined` — tinyglobby >= 0.2.16 calls `path.resolve(undefined)` and throws
18
+ return tinyGlobby.globSync(patterns, {
19
+ expandDirectories: false,
20
+ ...(options?.cwd && { cwd: options.cwd.replace(/\\/g, '/') }),
21
+ });
21
22
  };
22
23
  }
23
24
  },