@mikro-orm/knex 6.1.7-dev.0 → 6.1.7-dev.1

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.7-dev.0",
3
+ "version": "6.1.7-dev.1",
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.0"
69
+ "@mikro-orm/core": "6.1.7-dev.1"
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
  }
@@ -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;
@@ -46,7 +46,7 @@ class CriteriaNode {
46
46
  shouldInline(payload) {
47
47
  return false;
48
48
  }
49
- willAutoJoin(qb, alias) {
49
+ willAutoJoin(qb, alias, options) {
50
50
  return false;
51
51
  }
52
52
  shouldRename(payload) {
@@ -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,15 @@ 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
+ // ignore collection operators when used on a non-relational property - this can happen when they get into
22
+ // populateWhere via `infer` on m:n properties with select-in strategy
23
+ if (!this.prop?.targetMeta) {
24
+ return {};
25
+ }
21
26
  const $and = [];
27
+ 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
28
  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;
29
+ return [enums_1.QueryType.SELECT, enums_1.QueryType.COUNT].includes(qb.type) ? `${knownKey ? alias : ownerAlias}.${pk}` : pk;
24
30
  });
25
31
  for (const key of keys) {
26
32
  if (!['$some', '$none', '$every'].includes(key)) {
@@ -82,8 +88,8 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
82
88
  return o;
83
89
  }, {});
84
90
  }
85
- willAutoJoin(qb, alias) {
86
- const nestedAlias = qb.getAliasForJoinPath(this.getPath());
91
+ willAutoJoin(qb, alias, options) {
92
+ const nestedAlias = qb.getAliasForJoinPath(this.getPath(), options);
87
93
  const ownerAlias = alias || qb.alias;
88
94
  const keys = Object.keys(this.payload);
89
95
  if (nestedAlias) {
@@ -94,7 +100,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
94
100
  }
95
101
  return keys.some(field => {
96
102
  const childNode = this.payload[field];
97
- return childNode.willAutoJoin(qb, this.prop ? alias : ownerAlias);
103
+ return childNode.willAutoJoin(qb, this.prop ? alias : ownerAlias, options);
98
104
  });
99
105
  }
100
106
  shouldInline(payload) {
@@ -148,6 +154,9 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
148
154
  if (keys.every(k => k.includes('.') && k.startsWith(`${qb.alias}.`))) {
149
155
  return false;
150
156
  }
157
+ if (keys.some(k => ['$some', '$none', '$every'].includes(k))) {
158
+ return true;
159
+ }
151
160
  const meta = this.metadata.find(this.entityName);
152
161
  const embeddable = this.prop.kind === core_1.ReferenceKind.EMBEDDED;
153
162
  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);
@@ -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
  }
@@ -29,7 +29,7 @@ class ScalarCriteriaNode extends CriteriaNode_1.CriteriaNode {
29
29
  }
30
30
  return this.payload;
31
31
  }
32
- willAutoJoin(qb, alias) {
32
+ willAutoJoin(qb, alias, options) {
33
33
  return this.shouldJoin();
34
34
  }
35
35
  shouldJoin() {
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;