@mikro-orm/knex 6.1.7-dev.0 → 6.1.7-dev.2
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 +2 -2
- package/query/ArrayCriteriaNode.d.ts +1 -1
- package/query/ArrayCriteriaNode.js +2 -2
- package/query/CriteriaNode.d.ts +1 -1
- package/query/CriteriaNode.js +1 -1
- package/query/ObjectCriteriaNode.d.ts +1 -1
- package/query/ObjectCriteriaNode.js +16 -4
- package/query/QueryBuilder.js +1 -1
- package/query/QueryBuilderHelper.js +1 -1
- package/query/ScalarCriteriaNode.d.ts +1 -1
- package/query/ScalarCriteriaNode.js +1 -1
- package/typings.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/knex",
|
|
3
|
-
"version": "6.1.7-dev.
|
|
3
|
+
"version": "6.1.7-dev.2",
|
|
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.6"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
|
-
"@mikro-orm/core": "6.1.7-dev.
|
|
69
|
+
"@mikro-orm/core": "6.1.7-dev.2"
|
|
70
70
|
}
|
|
71
71
|
}
|
|
@@ -6,5 +6,5 @@ import type { IQueryBuilder, ICriteriaNodeProcessOptions } from '../typings';
|
|
|
6
6
|
export declare class ArrayCriteriaNode<T extends object> extends CriteriaNode<T> {
|
|
7
7
|
process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any;
|
|
8
8
|
unwrap(): any;
|
|
9
|
-
willAutoJoin(qb: IQueryBuilder<T>, alias?: string): any;
|
|
9
|
+
willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): any;
|
|
10
10
|
}
|
|
@@ -16,9 +16,9 @@ class ArrayCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
16
16
|
return node.unwrap();
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
-
willAutoJoin(qb, alias) {
|
|
19
|
+
willAutoJoin(qb, alias, options) {
|
|
20
20
|
return this.payload.some((node) => {
|
|
21
|
-
return node.willAutoJoin(qb, alias);
|
|
21
|
+
return node.willAutoJoin(qb, alias, options);
|
|
22
22
|
});
|
|
23
23
|
}
|
|
24
24
|
}
|
package/query/CriteriaNode.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare class CriteriaNode<T extends object> implements ICriteriaNode<T>
|
|
|
19
19
|
process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any;
|
|
20
20
|
unwrap(): any;
|
|
21
21
|
shouldInline(payload: any): boolean;
|
|
22
|
-
willAutoJoin(qb: IQueryBuilder<T>, alias?: string): boolean;
|
|
22
|
+
willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
|
|
23
23
|
shouldRename(payload: any): boolean;
|
|
24
24
|
renameFieldToPK<T>(qb: IQueryBuilder<T>): string;
|
|
25
25
|
getPath(addIndex?: boolean): string;
|
package/query/CriteriaNode.js
CHANGED
|
@@ -6,7 +6,7 @@ import type { ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings';
|
|
|
6
6
|
export declare class ObjectCriteriaNode<T extends object> extends CriteriaNode<T> {
|
|
7
7
|
process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any;
|
|
8
8
|
unwrap(): any;
|
|
9
|
-
willAutoJoin(qb: IQueryBuilder<T>, alias?: string): boolean;
|
|
9
|
+
willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
|
|
10
10
|
shouldInline(payload: any): boolean;
|
|
11
11
|
private inlineChildPayload;
|
|
12
12
|
private shouldAutoJoin;
|
|
@@ -18,9 +18,18 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
18
18
|
}
|
|
19
19
|
if (this.shouldAutoJoin(qb, nestedAlias)) {
|
|
20
20
|
if (keys.some(k => ['$some', '$none', '$every'].includes(k))) {
|
|
21
|
+
if (![core_1.ReferenceKind.MANY_TO_MANY, core_1.ReferenceKind.ONE_TO_MANY].includes(this.prop.kind)) {
|
|
22
|
+
// ignore collection operators when used on a non-relational property - this can happen when they get into
|
|
23
|
+
// populateWhere via `infer` on m:n properties with select-in strategy
|
|
24
|
+
if (this.parent?.parent) { // we validate only usage on top level
|
|
25
|
+
return {};
|
|
26
|
+
}
|
|
27
|
+
throw new Error(`Collection operators can be used only inside a collection property context, but it was used for ${this.getPath()}.`);
|
|
28
|
+
}
|
|
21
29
|
const $and = [];
|
|
30
|
+
const knownKey = [core_1.ReferenceKind.SCALAR, core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.EMBEDDED].includes(this.prop.kind) || (this.prop.kind === core_1.ReferenceKind.ONE_TO_ONE && this.prop.owner);
|
|
22
31
|
const primaryKeys = this.metadata.find(this.entityName).primaryKeys.map(pk => {
|
|
23
|
-
return [enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type) ? `${alias}.${pk}` : pk;
|
|
32
|
+
return [enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type) ? `${knownKey ? alias : ownerAlias}.${pk}` : pk;
|
|
24
33
|
});
|
|
25
34
|
for (const key of keys) {
|
|
26
35
|
if (!['$some', '$none', '$every'].includes(key)) {
|
|
@@ -82,8 +91,8 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
82
91
|
return o;
|
|
83
92
|
}, {});
|
|
84
93
|
}
|
|
85
|
-
willAutoJoin(qb, alias) {
|
|
86
|
-
const nestedAlias = qb.getAliasForJoinPath(this.getPath());
|
|
94
|
+
willAutoJoin(qb, alias, options) {
|
|
95
|
+
const nestedAlias = qb.getAliasForJoinPath(this.getPath(), options);
|
|
87
96
|
const ownerAlias = alias || qb.alias;
|
|
88
97
|
const keys = Object.keys(this.payload);
|
|
89
98
|
if (nestedAlias) {
|
|
@@ -94,7 +103,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
94
103
|
}
|
|
95
104
|
return keys.some(field => {
|
|
96
105
|
const childNode = this.payload[field];
|
|
97
|
-
return childNode.willAutoJoin(qb, this.prop ? alias : ownerAlias);
|
|
106
|
+
return childNode.willAutoJoin(qb, this.prop ? alias : ownerAlias, options);
|
|
98
107
|
});
|
|
99
108
|
}
|
|
100
109
|
shouldInline(payload) {
|
|
@@ -148,6 +157,9 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
|
|
|
148
157
|
if (keys.every(k => k.includes('.') && k.startsWith(`${qb.alias}.`))) {
|
|
149
158
|
return false;
|
|
150
159
|
}
|
|
160
|
+
if (keys.some(k => ['$some', '$none', '$every'].includes(k))) {
|
|
161
|
+
return true;
|
|
162
|
+
}
|
|
151
163
|
const meta = this.metadata.find(this.entityName);
|
|
152
164
|
const embeddable = this.prop.kind === core_1.ReferenceKind.EMBEDDED;
|
|
153
165
|
const knownKey = [core_1.ReferenceKind.SCALAR, core_1.ReferenceKind.MANY_TO_ONE, core_1.ReferenceKind.EMBEDDED].includes(this.prop.kind) || (this.prop.kind === core_1.ReferenceKind.ONE_TO_ONE && this.prop.owner);
|
package/query/QueryBuilder.js
CHANGED
|
@@ -267,7 +267,7 @@ class QueryBuilder {
|
|
|
267
267
|
const topLevel = !op || !core_1.Utils.hasObjectKeys(this._cond);
|
|
268
268
|
const criteriaNode = CriteriaNodeFactory_1.CriteriaNodeFactory.createNode(this.metadata, this.mainAlias.entityName, cond);
|
|
269
269
|
const ignoreBranching = this.__populateWhere === 'infer';
|
|
270
|
-
if ([enums_1.QueryType.UPDATE, enums_1.QueryType.DELETE].includes(this.type) && criteriaNode.willAutoJoin(this)) {
|
|
270
|
+
if ([enums_1.QueryType.UPDATE, enums_1.QueryType.DELETE].includes(this.type) && criteriaNode.willAutoJoin(this, undefined, { ignoreBranching })) {
|
|
271
271
|
// use sub-query to support joining
|
|
272
272
|
this.setFlag(this.type === enums_1.QueryType.UPDATE ? core_1.QueryFlag.UPDATE_SUB_QUERY : core_1.QueryFlag.DELETE_SUB_QUERY);
|
|
273
273
|
this.select(this.mainAlias.metadata.primaryKeys, true);
|
|
@@ -427,7 +427,7 @@ class QueryBuilderHelper {
|
|
|
427
427
|
const op = Object.keys(core_1.QueryOperator).find(op => op in value);
|
|
428
428
|
/* istanbul ignore next */
|
|
429
429
|
if (!op) {
|
|
430
|
-
throw new Error(`Invalid query condition: ${(0, util_1.inspect)(cond)}`);
|
|
430
|
+
throw new Error(`Invalid query condition: ${(0, util_1.inspect)(cond, { depth: 5 })}`);
|
|
431
431
|
}
|
|
432
432
|
const replacement = this.getOperatorReplacement(op, value);
|
|
433
433
|
const fields = core_1.Utils.splitPrimaryKeys(key);
|
|
@@ -5,6 +5,6 @@ import type { IQueryBuilder, ICriteriaNodeProcessOptions } from '../typings';
|
|
|
5
5
|
*/
|
|
6
6
|
export declare class ScalarCriteriaNode<T extends object> extends CriteriaNode<T> {
|
|
7
7
|
process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any;
|
|
8
|
-
willAutoJoin<T>(qb: IQueryBuilder<T>, alias?: string): boolean;
|
|
8
|
+
willAutoJoin<T>(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
|
|
9
9
|
shouldJoin(): boolean;
|
|
10
10
|
}
|
package/typings.d.ts
CHANGED
|
@@ -165,7 +165,7 @@ export interface ICriteriaNode<T extends object> {
|
|
|
165
165
|
index?: number;
|
|
166
166
|
process(qb: IQueryBuilder<T>, options?: ICriteriaNodeProcessOptions): any;
|
|
167
167
|
shouldInline(payload: any): boolean;
|
|
168
|
-
willAutoJoin(qb: IQueryBuilder<T>, alias?: string): boolean;
|
|
168
|
+
willAutoJoin(qb: IQueryBuilder<T>, alias?: string, options?: ICriteriaNodeProcessOptions): boolean;
|
|
169
169
|
shouldRename(payload: any): boolean;
|
|
170
170
|
renameFieldToPK<T>(qb: IQueryBuilder<T>): string;
|
|
171
171
|
getPath(addIndex?: boolean): string;
|