@mikro-orm/knex 6.1.11-dev.7 → 6.1.11-dev.8
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.1.11-dev.
|
|
3
|
+
"version": "6.1.11-dev.8",
|
|
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",
|
|
@@ -66,6 +66,6 @@
|
|
|
66
66
|
"@mikro-orm/core": "^6.1.10"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.1.11-dev.
|
|
69
|
+
"@mikro-orm/core": "6.1.11-dev.8"
|
|
70
70
|
}
|
|
71
71
|
}
|
package/query/CriteriaNode.js
CHANGED
|
@@ -27,14 +27,14 @@ class CriteriaNode {
|
|
|
27
27
|
if (pks.length > 1) {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
|
-
|
|
30
|
+
for (const k of pks) {
|
|
31
31
|
this.prop = meta.props.find(prop => prop.name === k || (prop.fieldNames?.length === 1 && prop.fieldNames[0] === k));
|
|
32
32
|
const isProp = this.prop || meta.props.find(prop => (prop.fieldNames || []).includes(k));
|
|
33
33
|
// do not validate if the key is prefixed or type casted (e.g. `k::text`)
|
|
34
34
|
if (validate && !isProp && !k.includes('.') && !k.includes('::') && !core_1.Utils.isOperator(k) && !core_1.RawQueryFragment.isKnownFragment(k)) {
|
|
35
35
|
throw new Error(`Trying to query by not existing property ${entityName}.${k}`);
|
|
36
36
|
}
|
|
37
|
-
}
|
|
37
|
+
}
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
process(qb, options) {
|
|
@@ -8,7 +8,10 @@ export declare class ObjectCriteriaNode<T extends object> extends CriteriaNode<T
|
|
|
8
8
|
unwrap(): any;
|
|
9
9
|
willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
|
|
10
10
|
shouldInline(payload: any): boolean;
|
|
11
|
+
private getChildKey;
|
|
12
|
+
private inlineArrayChildPayload;
|
|
11
13
|
private inlineChildPayload;
|
|
14
|
+
private inlineCondition;
|
|
12
15
|
private shouldAutoJoin;
|
|
13
16
|
private autoJoin;
|
|
14
17
|
private isPrefixed;
|
|
@@ -112,6 +112,24 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
112
112
|
const operator = core_1.Utils.isObject(payload) && Object.keys(payload).every(k => core_1.Utils.isOperator(k, false));
|
|
113
113
|
return !!this.prop && this.prop.kind !== core_1.ReferenceKind.SCALAR && !scalar && !operator;
|
|
114
114
|
}
|
|
115
|
+
getChildKey(k, prop, childAlias) {
|
|
116
|
+
const idx = prop.referencedPKs.indexOf(k);
|
|
117
|
+
return idx !== -1 && !childAlias && ![core_1.ReferenceKind.ONE_TO_MANY, core_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind) ? prop.joinColumns[idx] : k;
|
|
118
|
+
}
|
|
119
|
+
inlineArrayChildPayload(obj, payload, k, prop, childAlias) {
|
|
120
|
+
const key = this.getChildKey(k, prop, childAlias);
|
|
121
|
+
const value = payload.map((child) => Object.keys(child).reduce((inner, childKey) => {
|
|
122
|
+
if (core_1.Utils.isGroupOperator(childKey) && Array.isArray(child[childKey])) {
|
|
123
|
+
this.inlineArrayChildPayload(child, child[childKey], childKey, prop, childAlias);
|
|
124
|
+
}
|
|
125
|
+
else {
|
|
126
|
+
const key = (this.isPrefixed(childKey) || core_1.Utils.isOperator(childKey)) ? childKey : this.aliased(childKey, childAlias);
|
|
127
|
+
inner[key] = child[childKey];
|
|
128
|
+
}
|
|
129
|
+
return inner;
|
|
130
|
+
}, {}));
|
|
131
|
+
this.inlineCondition(key, obj, value);
|
|
132
|
+
}
|
|
115
133
|
inlineChildPayload(o, payload, field, alias, childAlias) {
|
|
116
134
|
const prop = this.metadata.find(this.entityName).properties[field];
|
|
117
135
|
for (const k of Object.keys(payload)) {
|
|
@@ -120,25 +138,12 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
120
138
|
delete payload[k];
|
|
121
139
|
o[this.aliased(field, alias)] = { [k]: tmp, ...o[this.aliased(field, alias)] };
|
|
122
140
|
}
|
|
141
|
+
else if (core_1.Utils.isGroupOperator(k) && Array.isArray(payload[k])) {
|
|
142
|
+
this.inlineArrayChildPayload(o, payload[k], k, prop, childAlias);
|
|
143
|
+
}
|
|
123
144
|
else if (this.isPrefixed(k) || core_1.Utils.isOperator(k) || !childAlias) {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
if (key in o) {
|
|
127
|
-
const $and = o.$and ?? [];
|
|
128
|
-
$and.push({ [key]: o[key] }, { [key]: payload[k] });
|
|
129
|
-
delete o[key];
|
|
130
|
-
o.$and = $and;
|
|
131
|
-
}
|
|
132
|
-
else if (core_1.Utils.isOperator(k) && Array.isArray(payload[k])) {
|
|
133
|
-
o[key] = payload[k].map((child) => Object.keys(child).reduce((o, childKey) => {
|
|
134
|
-
const key = (this.isPrefixed(childKey) || core_1.Utils.isOperator(childKey)) ? childKey : this.aliased(childKey, childAlias);
|
|
135
|
-
o[key] = child[childKey];
|
|
136
|
-
return o;
|
|
137
|
-
}, {}));
|
|
138
|
-
}
|
|
139
|
-
else {
|
|
140
|
-
o[key] = payload[k];
|
|
141
|
-
}
|
|
145
|
+
const key = this.getChildKey(k, prop, childAlias);
|
|
146
|
+
this.inlineCondition(key, o, payload[k]);
|
|
142
147
|
}
|
|
143
148
|
else if (core_1.RawQueryFragment.isKnownFragment(k)) {
|
|
144
149
|
o[k] = payload[k];
|
|
@@ -149,6 +154,17 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
149
154
|
}
|
|
150
155
|
}
|
|
151
156
|
}
|
|
157
|
+
inlineCondition(key, o, value) {
|
|
158
|
+
if (key in o) {
|
|
159
|
+
const $and = o.$and ?? [];
|
|
160
|
+
$and.push({ [key]: o[key] }, { [key]: value });
|
|
161
|
+
delete o[key];
|
|
162
|
+
o.$and = $and;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
o[key] = value;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
152
168
|
shouldAutoJoin(qb, nestedAlias) {
|
|
153
169
|
if (!this.prop || !this.parent) {
|
|
154
170
|
return false;
|