@mikro-orm/core 6.6.13-dev.2 → 6.6.13-dev.4
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/entity/EntityHelper.js +16 -5
- package/package.json +2 -2
- package/utils/QueryHelper.js +4 -1
package/entity/EntityHelper.js
CHANGED
|
@@ -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
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.6.13-dev.
|
|
3
|
+
"version": "6.6.13-dev.4",
|
|
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.
|
|
67
|
+
"mikro-orm": "6.6.13-dev.4",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/utils/QueryHelper.js
CHANGED
|
@@ -92,7 +92,10 @@ class QueryHelper {
|
|
|
92
92
|
if (meta.primaryKeys.every(pk => pk in where) && Utils_1.Utils.getObjectKeysSize(where) === meta.primaryKeys.length) {
|
|
93
93
|
return !!key && !enums_1.GroupOperator[key] && key !== '$not' && Object.keys(where).every(k => !Utils_1.Utils.isPlainObject(where[k]) || Object.keys(where[k]).every(v => {
|
|
94
94
|
if (Utils_1.Utils.isOperator(v, false)) {
|
|
95
|
-
|
|
95
|
+
// multi-value operators (e.g. `$in`/`$nin`) cannot be inlined into a composite
|
|
96
|
+
// PK tuple — `getPrimaryKeyValues` would flatten the operator's array alongside
|
|
97
|
+
// the sibling PK values, producing a malformed `(col1, col2) IN ((a, b))` clause
|
|
98
|
+
return !meta.compositePK || !Array.isArray(where[k][v]);
|
|
96
99
|
}
|
|
97
100
|
if (meta.properties[k].primary && [enums_1.ReferenceKind.ONE_TO_ONE, enums_1.ReferenceKind.MANY_TO_ONE].includes(meta.properties[k].kind)) {
|
|
98
101
|
return this.inlinePrimaryKeyObjects(where[k], meta.properties[k].targetMeta, metadata, v);
|