@mikro-orm/core 6.6.13-dev.1 → 6.6.13-dev.3

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.
@@ -40,11 +40,6 @@ class EntityHelper {
40
40
  if (!prototype.toJSON) { // toJSON can be overridden
41
41
  Object.defineProperty(prototype, 'toJSON', {
42
42
  value(...args) {
43
- // Guard against being called on the prototype itself (e.g. by serializers
44
- // walking the object graph and calling toJSON on prototype objects)
45
- if (this === prototype) {
46
- return {};
47
- }
48
43
  return EntityTransformer_1.EntityTransformer.toObject(this, ...args.slice(meta.toJsonParams.length));
49
44
  },
50
45
  writable: true,
@@ -52,6 +47,22 @@ class EntityHelper {
52
47
  enumerable: false,
53
48
  });
54
49
  }
50
+ // Walkers / serializers reaching the prototype directly invoke its methods and
51
+ // accessors with `this === prototype`. Wrap each so that case is a no-op rather
52
+ // than throwing (when a user `@Property({ persist: false })` getter dereferences
53
+ // unhydrated instance state) or installing state on the prototype itself (#7151).
54
+ for (const name of Object.getOwnPropertyNames(prototype)) {
55
+ const desc = Object.getOwnPropertyDescriptor(prototype, name);
56
+ const fn = desc.get ?? desc.value;
57
+ if (name === 'constructor' || typeof fn !== 'function' || fn.__guarded) {
58
+ continue;
59
+ }
60
+ const guarded = function (...args) {
61
+ return this === prototype ? undefined : fn.apply(this, args);
62
+ };
63
+ guarded.__guarded = true;
64
+ Object.defineProperty(prototype, name, desc.get ? { ...desc, get: guarded } : { ...desc, value: guarded });
65
+ }
55
66
  }
56
67
  /**
57
68
  * As a performance optimization, we create entity state methods in a lazy manner. We first add
@@ -409,7 +409,7 @@ class MetadataDiscovery {
409
409
  }
410
410
  if (prop.joinColumns.length > 1) {
411
411
  prop.ownColumns = prop.joinColumns.filter(col => {
412
- return !meta.props.find(p => p.name !== prop.name && (!p.fieldNames || p.fieldNames.includes(col)));
412
+ return !meta.props.find(p => p.name !== prop.name && p.fieldNames?.includes(col));
413
413
  });
414
414
  }
415
415
  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": "6.6.13-dev.1",
3
+ "version": "6.6.13-dev.3",
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
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.3.3",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.6.13-dev.1",
67
+ "mikro-orm": "6.6.13-dev.3",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }