@mikro-orm/knex 6.0.0-dev.216 → 6.0.0-dev.219

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.0.0-dev.216",
3
+ "version": "6.0.0-dev.219",
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": "^5.9.2"
67
67
  },
68
68
  "peerDependencies": {
69
- "@mikro-orm/core": "6.0.0-dev.216"
69
+ "@mikro-orm/core": "6.0.0-dev.219"
70
70
  }
71
71
  }
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import { inspect } from 'util';
3
- import { type EntityProperty, type MetadataStorage, type EntityKey } from '@mikro-orm/core';
3
+ import { type EntityKey, type EntityProperty, type MetadataStorage } from '@mikro-orm/core';
4
4
  import type { ICriteriaNode, ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings';
5
5
  /**
6
6
  * Helper for working with deeply nested where/orderBy/having criteria. Uses composite pattern to build tree from the payload.
@@ -28,5 +28,4 @@ export declare class CriteriaNode<T extends object> implements ICriteriaNode<T>
28
28
  aliased(field: string, alias?: string): string;
29
29
  /** @ignore */
30
30
  [inspect.custom](): string;
31
- static isCustomExpression(field: string): boolean;
32
31
  }
@@ -31,7 +31,7 @@ class CriteriaNode {
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
- if (validate && !isProp && !k.includes('.') && !k.includes('::') && !core_1.Utils.isOperator(k) && !CriteriaNode.isCustomExpression(k)) {
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
  });
@@ -52,7 +52,7 @@ class CriteriaNode {
52
52
  shouldRename(payload) {
53
53
  const type = this.prop ? this.prop.kind : null;
54
54
  const composite = this.prop?.joinColumns ? this.prop.joinColumns.length > 1 : false;
55
- const customExpression = CriteriaNode.isCustomExpression(this.key);
55
+ const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
56
56
  const scalar = payload === null || core_1.Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
57
57
  const plainObject = core_1.Utils.isPlainObject(payload);
58
58
  const keys = plainObject ? Object.keys(payload) : [];
@@ -98,7 +98,7 @@ class CriteriaNode {
98
98
  if (!this.key || !this.prop) {
99
99
  return false;
100
100
  }
101
- const customExpression = CriteriaNode.isCustomExpression(this.key);
101
+ const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
102
102
  const scalar = this.payload === null || core_1.Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || customExpression;
103
103
  const operator = core_1.Utils.isObject(this.payload) && Object.keys(this.payload).every(k => core_1.Utils.isOperator(k, false));
104
104
  return this.prop.kind === core_1.ReferenceKind.MANY_TO_MANY && (scalar || operator);
@@ -117,8 +117,5 @@ class CriteriaNode {
117
117
  .forEach(k => o[k] = this[k]);
118
118
  return `${this.constructor.name} ${(0, util_1.inspect)(o)}`;
119
119
  }
120
- static isCustomExpression(field) {
121
- return !!field.match(/[ ?<>=()]|^\d/);
122
- }
123
120
  }
124
121
  exports.CriteriaNode = CriteriaNode;
@@ -1,4 +1,4 @@
1
- import { type Dictionary, type EntityMetadata, type MetadataStorage, type EntityKey } from '@mikro-orm/core';
1
+ import { type Dictionary, type EntityKey, type EntityMetadata, type MetadataStorage } from '@mikro-orm/core';
2
2
  import type { ICriteriaNode } from '../typings';
3
3
  /**
4
4
  * @internal
@@ -5,13 +5,12 @@ const core_1 = require("@mikro-orm/core");
5
5
  const ObjectCriteriaNode_1 = require("./ObjectCriteriaNode");
6
6
  const ArrayCriteriaNode_1 = require("./ArrayCriteriaNode");
7
7
  const ScalarCriteriaNode_1 = require("./ScalarCriteriaNode");
8
- const CriteriaNode_1 = require("./CriteriaNode");
9
8
  /**
10
9
  * @internal
11
10
  */
12
11
  class CriteriaNodeFactory {
13
12
  static createNode(metadata, entityName, payload, parent, key) {
14
- const customExpression = CriteriaNode_1.CriteriaNode.isCustomExpression(key || '');
13
+ const customExpression = core_1.RawQueryFragment.isKnownFragment(key || '');
15
14
  const scalar = core_1.Utils.isPrimaryKey(payload) || core_1.Utils.isRawSql(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
16
15
  if (Array.isArray(payload) && !scalar) {
17
16
  return this.createArrayNode(metadata, entityName, payload, parent, key);
@@ -1,5 +1,5 @@
1
1
  import { CriteriaNode } from './CriteriaNode';
2
- import type { IQueryBuilder, ICriteriaNodeProcessOptions } from '../typings';
2
+ import type { ICriteriaNodeProcessOptions, IQueryBuilder } from '../typings';
3
3
  /**
4
4
  * @internal
5
5
  */
@@ -95,7 +95,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
95
95
  });
96
96
  }
97
97
  shouldInline(payload) {
98
- const customExpression = ObjectCriteriaNode.isCustomExpression(this.key);
98
+ const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
99
99
  const scalar = core_1.Utils.isPrimaryKey(payload) || payload instanceof RegExp || payload instanceof Date || customExpression;
100
100
  const operator = core_1.Utils.isObject(payload) && Object.keys(payload).every(k => core_1.Utils.isOperator(k, false));
101
101
  return !!this.prop && this.prop.kind !== core_1.ReferenceKind.SCALAR && !scalar && !operator;
@@ -128,7 +128,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
128
128
  o[key] = payload[k];
129
129
  }
130
130
  }
131
- else if (ObjectCriteriaNode.isCustomExpression(k)) {
131
+ else if (core_1.RawQueryFragment.isKnownFragment(k)) {
132
132
  o[k] = payload[k];
133
133
  }
134
134
  else {
@@ -158,7 +158,7 @@ class ObjectCriteriaNode extends CriteriaNode_1.CriteriaNode {
158
158
  }
159
159
  autoJoin(qb, alias) {
160
160
  const nestedAlias = qb.getNextAlias(this.prop?.pivotTable ?? this.entityName);
161
- const customExpression = ObjectCriteriaNode.isCustomExpression(this.key);
161
+ const customExpression = core_1.RawQueryFragment.isKnownFragment(this.key);
162
162
  const scalar = core_1.Utils.isPrimaryKey(this.payload) || this.payload instanceof RegExp || this.payload instanceof Date || customExpression;
163
163
  const operator = core_1.Utils.isPlainObject(this.payload) && Object.keys(this.payload).every(k => core_1.Utils.isOperator(k, false));
164
164
  const field = `${alias}.${this.prop.name}`;