@mikro-orm/core 7.0.4 → 7.0.5-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/EntityManager.d.ts +583 -884
- package/EntityManager.js +1895 -1922
- package/MikroORM.d.ts +74 -103
- package/MikroORM.js +179 -178
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +24 -30
- package/cache/FileCacheAdapter.js +78 -80
- package/cache/GeneratedCacheAdapter.d.ts +20 -18
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +20 -18
- package/cache/MemoryCacheAdapter.js +36 -35
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +84 -95
- package/connections/Connection.js +168 -165
- package/drivers/DatabaseDriver.d.ts +80 -186
- package/drivers/DatabaseDriver.js +443 -450
- package/drivers/IDatabaseDriver.d.ts +301 -440
- package/entity/BaseEntity.d.ts +83 -120
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +179 -212
- package/entity/Collection.js +721 -727
- package/entity/EntityAssigner.d.ts +77 -88
- package/entity/EntityAssigner.js +230 -231
- package/entity/EntityFactory.d.ts +54 -66
- package/entity/EntityFactory.js +383 -425
- package/entity/EntityHelper.d.ts +22 -34
- package/entity/EntityHelper.js +267 -280
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +72 -98
- package/entity/EntityLoader.js +723 -753
- package/entity/EntityRepository.d.ts +201 -316
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +82 -126
- package/entity/Reference.js +274 -278
- package/entity/WrappedEntity.d.ts +72 -115
- package/entity/WrappedEntity.js +166 -168
- package/entity/defineEntity.d.ts +636 -1315
- package/entity/defineEntity.js +518 -527
- package/entity/utils.d.ts +3 -13
- package/entity/utils.js +73 -71
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +253 -258
- package/enums.js +252 -251
- package/errors.d.ts +72 -114
- package/errors.js +253 -350
- package/events/EventManager.d.ts +14 -26
- package/events/EventManager.js +77 -79
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +8 -15
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +40 -23
- package/exceptions.js +52 -35
- package/hydration/Hydrator.d.ts +17 -42
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +17 -50
- package/hydration/ObjectHydrator.js +416 -481
- package/index.d.ts +2 -116
- package/index.js +1 -10
- package/logging/DefaultLogger.d.ts +32 -34
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +11 -13
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +10 -11
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +127 -211
- package/metadata/EntitySchema.js +398 -397
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1870 -1951
- package/metadata/MetadataProvider.d.ts +21 -24
- package/metadata/MetadataProvider.js +84 -82
- package/metadata/MetadataStorage.d.ts +32 -38
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +338 -381
- package/metadata/discover-entities.d.ts +2 -5
- package/metadata/discover-entities.js +37 -35
- package/metadata/types.d.ts +531 -615
- package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
- package/naming-strategy/AbstractNamingStrategy.js +85 -90
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
- package/naming-strategy/MongoNamingStrategy.js +18 -18
- package/naming-strategy/NamingStrategy.d.ts +99 -109
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +4 -7
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +301 -310
- package/platforms/Platform.js +640 -663
- package/serialization/EntitySerializer.d.ts +26 -49
- package/serialization/EntitySerializer.js +218 -224
- package/serialization/EntityTransformer.d.ts +6 -10
- package/serialization/EntityTransformer.js +217 -219
- package/serialization/SerializationContext.d.ts +23 -27
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +10 -17
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +13 -13
- package/types/BooleanType.d.ts +4 -4
- package/types/BooleanType.js +12 -12
- package/types/CharacterType.d.ts +2 -2
- package/types/CharacterType.js +6 -6
- package/types/DateTimeType.d.ts +5 -5
- package/types/DateTimeType.js +15 -15
- package/types/DateType.d.ts +5 -5
- package/types/DateType.js +15 -15
- package/types/DecimalType.d.ts +7 -7
- package/types/DecimalType.js +26 -26
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +12 -12
- package/types/EnumArrayType.d.ts +5 -5
- package/types/EnumArrayType.js +24 -24
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +11 -11
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +9 -9
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +9 -9
- package/types/IntervalType.d.ts +4 -4
- package/types/IntervalType.js +12 -12
- package/types/JsonType.d.ts +8 -8
- package/types/JsonType.js +32 -32
- package/types/MediumIntType.d.ts +1 -1
- package/types/MediumIntType.js +3 -3
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +9 -9
- package/types/StringType.d.ts +4 -4
- package/types/StringType.js +12 -12
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +9 -9
- package/types/TimeType.d.ts +5 -5
- package/types/TimeType.js +17 -17
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +10 -10
- package/types/Type.d.ts +79 -83
- package/types/Type.js +82 -82
- package/types/Uint8ArrayType.d.ts +4 -4
- package/types/Uint8ArrayType.js +21 -21
- package/types/UnknownType.d.ts +4 -4
- package/types/UnknownType.js +12 -12
- package/types/UuidType.d.ts +5 -5
- package/types/UuidType.js +19 -19
- package/types/index.d.ts +49 -75
- package/types/index.js +26 -52
- package/typings.d.ts +737 -1250
- package/typings.js +231 -244
- package/unit-of-work/ChangeSet.d.ts +26 -26
- package/unit-of-work/ChangeSet.js +56 -56
- package/unit-of-work/ChangeSetComputer.d.ts +12 -12
- package/unit-of-work/ChangeSetComputer.js +170 -178
- package/unit-of-work/ChangeSetPersister.d.ts +44 -63
- package/unit-of-work/ChangeSetPersister.js +421 -442
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +88 -89
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +141 -181
- package/unit-of-work/UnitOfWork.js +1183 -1200
- package/utils/AbstractMigrator.d.ts +91 -111
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +34 -43
- package/utils/AbstractSchemaGenerator.js +122 -121
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +35 -34
- package/utils/Configuration.d.ts +808 -852
- package/utils/Configuration.js +344 -359
- package/utils/Cursor.d.ts +22 -40
- package/utils/Cursor.js +127 -135
- package/utils/DataloaderUtils.d.ts +43 -58
- package/utils/DataloaderUtils.js +198 -203
- package/utils/EntityComparator.d.ts +81 -98
- package/utils/EntityComparator.js +732 -828
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +51 -79
- package/utils/QueryHelper.js +361 -372
- package/utils/RawQueryFragment.d.ts +34 -50
- package/utils/RawQueryFragment.js +105 -107
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +53 -52
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +197 -199
- package/utils/Utils.d.ts +145 -204
- package/utils/Utils.js +812 -812
- package/utils/clone.js +113 -104
- package/utils/env-vars.js +88 -90
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +181 -180
- package/utils/upsert-utils.d.ts +5 -20
- package/utils/upsert-utils.js +116 -114
package/utils/QueryHelper.js
CHANGED
|
@@ -6,392 +6,381 @@ import { helper } from '../entity/wrap.js';
|
|
|
6
6
|
import { isRaw, Raw } from './RawQueryFragment.js';
|
|
7
7
|
/** @internal */
|
|
8
8
|
export class QueryHelper {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
9
|
+
static SUPPORTED_OPERATORS = ['>', '<', '<=', '>=', '!', '!='];
|
|
10
|
+
/**
|
|
11
|
+
* Finds the discriminator value (key) for a given entity class in a discriminator map.
|
|
12
|
+
*/
|
|
13
|
+
static findDiscriminatorValue(discriminatorMap, targetClass) {
|
|
14
|
+
return Object.entries(discriminatorMap).find(([, cls]) => cls === targetClass)?.[0];
|
|
15
|
+
}
|
|
16
|
+
static processParams(params) {
|
|
17
|
+
if (Reference.isReference(params)) {
|
|
18
|
+
params = params.unwrap();
|
|
19
|
+
}
|
|
20
|
+
if (Utils.isEntity(params)) {
|
|
21
|
+
if (helper(params).__meta.compositePK) {
|
|
22
|
+
return helper(params).__primaryKeys;
|
|
23
|
+
}
|
|
24
|
+
return helper(params).getPrimaryKey();
|
|
25
|
+
}
|
|
26
|
+
if (params === undefined) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if (Array.isArray(params)) {
|
|
30
|
+
return params.map(item => QueryHelper.processParams(item));
|
|
31
|
+
}
|
|
32
|
+
if (Utils.isPlainObject(params)) {
|
|
33
|
+
QueryHelper.processObjectParams(params);
|
|
34
|
+
}
|
|
35
|
+
return params;
|
|
34
36
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
37
|
+
static processObjectParams(params = {}) {
|
|
38
|
+
Utils.getObjectQueryKeys(params).forEach(k => {
|
|
39
|
+
params[k] = QueryHelper.processParams(params[k]);
|
|
40
|
+
});
|
|
41
|
+
return params;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* converts `{ account: { $or: [ [Object], [Object] ] } }`
|
|
45
|
+
* to `{ $or: [ { account: [Object] }, { account: [Object] } ] }`
|
|
46
|
+
*/
|
|
47
|
+
static liftGroupOperators(where, meta, metadata, key) {
|
|
48
|
+
if (!Utils.isPlainObject(where)) {
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
const keys = Object.keys(where);
|
|
52
|
+
const groupOperator = keys.find(k => {
|
|
53
|
+
return (k in GroupOperator &&
|
|
54
|
+
Array.isArray(where[k]) &&
|
|
55
|
+
where[k].every(cond => {
|
|
56
|
+
return (Utils.isPlainObject(cond) &&
|
|
57
|
+
Object.keys(cond).every(k2 => {
|
|
58
|
+
if (Utils.isOperator(k2, false)) {
|
|
59
|
+
if (k2 === '$not') {
|
|
60
|
+
return Object.keys(cond[k2]).every(k3 => meta.primaryKeys.includes(k3));
|
|
61
|
+
}
|
|
62
|
+
/* v8 ignore next */
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
return meta.primaryKeys.includes(k2);
|
|
66
|
+
}));
|
|
67
|
+
}));
|
|
68
|
+
});
|
|
69
|
+
if (groupOperator) {
|
|
70
|
+
return groupOperator;
|
|
71
|
+
}
|
|
72
|
+
for (const k of keys) {
|
|
73
|
+
const value = where[k];
|
|
74
|
+
const prop = meta.properties[k];
|
|
75
|
+
// Polymorphic relations use multiple columns (discriminator + FK), so they cannot
|
|
76
|
+
// participate in the standard single-column FK expansion. Query by discriminator
|
|
77
|
+
// column directly instead, e.g. { likeableType: 'post', likeableId: 1 }.
|
|
78
|
+
if (!prop || ![ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) || prop.polymorphic) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
const op = this.liftGroupOperators(value, prop.targetMeta, metadata, k);
|
|
82
|
+
if (op) {
|
|
83
|
+
delete where[k];
|
|
84
|
+
where[op] = value[op].map((v) => {
|
|
85
|
+
return { [k]: v };
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return undefined;
|
|
50
90
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
where[k].every(cond => {
|
|
57
|
-
return (
|
|
58
|
-
Utils.isPlainObject(cond) &&
|
|
59
|
-
Object.keys(cond).every(k2 => {
|
|
60
|
-
if (Utils.isOperator(k2, false)) {
|
|
61
|
-
if (k2 === '$not') {
|
|
62
|
-
return Object.keys(cond[k2]).every(k3 => meta.primaryKeys.includes(k3));
|
|
91
|
+
static inlinePrimaryKeyObjects(where, meta, metadata, key) {
|
|
92
|
+
if (Array.isArray(where)) {
|
|
93
|
+
where.forEach((item, i) => {
|
|
94
|
+
if (this.inlinePrimaryKeyObjects(item, meta, metadata, key)) {
|
|
95
|
+
where[i] = Utils.getPrimaryKeyValues(item, meta, false);
|
|
63
96
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
if (!Utils.isPlainObject(where) || (key && meta.properties[key]?.customType instanceof JsonType)) {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
if (meta.primaryKeys.every(pk => pk in where) && Utils.getObjectKeysSize(where) === meta.primaryKeys.length) {
|
|
103
|
+
return (!!key &&
|
|
104
|
+
!GroupOperator[key] &&
|
|
105
|
+
key !== '$not' &&
|
|
106
|
+
Object.keys(where).every(k => !Utils.isPlainObject(where[k]) ||
|
|
107
|
+
Object.keys(where[k]).every(v => {
|
|
108
|
+
if (Utils.isOperator(v, false)) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if (meta.properties[k].primary &&
|
|
112
|
+
[ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(meta.properties[k].kind)) {
|
|
113
|
+
return this.inlinePrimaryKeyObjects(where[k], meta.properties[k].targetMeta, metadata, v);
|
|
114
|
+
}
|
|
115
|
+
/* v8 ignore next */
|
|
116
|
+
return true;
|
|
117
|
+
})));
|
|
118
|
+
}
|
|
119
|
+
Object.keys(where).forEach(k => {
|
|
120
|
+
const meta2 = metadata.find(meta.properties[k]?.targetMeta?.class) || meta;
|
|
121
|
+
if (this.inlinePrimaryKeyObjects(where[k], meta2, metadata, k)) {
|
|
122
|
+
where[k] = Utils.getPrimaryKeyValues(where[k], meta2, true);
|
|
123
|
+
}
|
|
90
124
|
});
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
if (
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
if (Array.isArray(where) && root) {
|
|
162
|
-
const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : Utils.className(entityName);
|
|
163
|
-
let cond = { [rootPrimaryKey]: { $in: where } };
|
|
164
|
-
// @ts-ignore
|
|
165
|
-
// detect tuple comparison, use `$or` in case the number of constituents don't match
|
|
166
|
-
if (
|
|
167
|
-
meta &&
|
|
168
|
-
!where.every(
|
|
169
|
-
c =>
|
|
170
|
-
Utils.isPrimaryKey(c) ||
|
|
171
|
-
(Array.isArray(c) && c.length === meta.primaryKeys.length && c.every(i => Utils.isPrimaryKey(i))),
|
|
172
|
-
)
|
|
173
|
-
) {
|
|
174
|
-
cond = { $or: where };
|
|
175
|
-
}
|
|
176
|
-
return QueryHelper.processWhere({ ...options, where: cond, root: false });
|
|
177
|
-
}
|
|
178
|
-
if (!Utils.isPlainObject(where)) {
|
|
179
|
-
return where;
|
|
180
|
-
}
|
|
181
|
-
return Utils.getObjectQueryKeys(where).reduce((o, key) => {
|
|
182
|
-
let value = where[key];
|
|
183
|
-
const customExpression = Raw.isKnownFragmentSymbol(key);
|
|
184
|
-
if (Array.isArray(value) && value.length === 0 && customExpression) {
|
|
185
|
-
o[key] = value;
|
|
186
|
-
return o;
|
|
187
|
-
}
|
|
188
|
-
if (key in GroupOperator) {
|
|
189
|
-
o[key] = value.map(sub => QueryHelper.processWhere({ ...options, where: sub, root }));
|
|
190
|
-
return o;
|
|
191
|
-
}
|
|
192
|
-
// wrap top level operators (except platform allowed operators) with PK
|
|
193
|
-
if (Utils.isOperator(key) && root && meta && !platform.isAllowedTopLevelOperator(key)) {
|
|
194
|
-
const rootPrimaryKey = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
195
|
-
o[rootPrimaryKey] = { [key]: QueryHelper.processWhere({ ...options, where: value, root: false }) };
|
|
196
|
-
return o;
|
|
197
|
-
}
|
|
198
|
-
const prop = customExpression ? null : this.findProperty(key, options);
|
|
199
|
-
const keys = prop?.joinColumns?.length ?? 0;
|
|
200
|
-
const composite = keys > 1;
|
|
201
|
-
if (prop?.customType && convertCustomTypes && !isRaw(value)) {
|
|
202
|
-
value = QueryHelper.processCustomType(prop, value, platform, undefined, true);
|
|
203
|
-
}
|
|
204
|
-
// oxfmt-ignore
|
|
205
|
-
const isJsonProperty = prop?.customType instanceof JsonType && !isRaw(value) && (Utils.isPlainObject(value) ? !['$eq', '$elemMatch'].includes(Object.keys(value)[0]) : !Array.isArray(value));
|
|
206
|
-
if (isJsonProperty && prop?.kind !== ReferenceKind.EMBEDDED) {
|
|
207
|
-
return this.processJsonCondition(o, value, [prop.fieldNames[0]], platform, aliased);
|
|
208
|
-
}
|
|
209
|
-
// oxfmt-ignore
|
|
210
|
-
if (Array.isArray(value) && !Utils.isOperator(key) && !QueryHelper.isSupportedOperator(key) && !(customExpression && Raw.getKnownFragment(key).params.length > 0) && options.type !== 'orderBy') {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
static processWhere(options) {
|
|
128
|
+
// eslint-disable-next-line prefer-const
|
|
129
|
+
let { where, entityName, metadata, platform, aliased = true, convertCustomTypes = true, root = true } = options;
|
|
130
|
+
const meta = metadata.find(entityName);
|
|
131
|
+
// inline PK-only objects in M:N queries, so we don't join the target entity when not needed
|
|
132
|
+
if (meta && root) {
|
|
133
|
+
QueryHelper.liftGroupOperators(where, meta, metadata);
|
|
134
|
+
QueryHelper.inlinePrimaryKeyObjects(where, meta, metadata);
|
|
135
|
+
}
|
|
136
|
+
if (meta && root) {
|
|
137
|
+
QueryHelper.convertCompositeEntityRefs(where, meta);
|
|
138
|
+
}
|
|
139
|
+
if (platform.getConfig().get('ignoreUndefinedInQuery') && where && typeof where === 'object') {
|
|
140
|
+
Utils.dropUndefinedProperties(where);
|
|
141
|
+
}
|
|
142
|
+
where = QueryHelper.processParams(where) ?? {};
|
|
143
|
+
/* v8 ignore next */
|
|
144
|
+
if (!root && Utils.isPrimaryKey(where)) {
|
|
145
|
+
return where;
|
|
146
|
+
}
|
|
147
|
+
if (meta && Utils.isPrimaryKey(where, meta.compositePK)) {
|
|
148
|
+
where = { [Utils.getPrimaryKeyHash(meta.primaryKeys)]: where };
|
|
149
|
+
}
|
|
150
|
+
if (Array.isArray(where) && root) {
|
|
151
|
+
const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : Utils.className(entityName);
|
|
152
|
+
let cond = { [rootPrimaryKey]: { $in: where } };
|
|
153
|
+
// @ts-ignore
|
|
154
|
+
// detect tuple comparison, use `$or` in case the number of constituents don't match
|
|
155
|
+
if (meta &&
|
|
156
|
+
!where.every(c => Utils.isPrimaryKey(c) ||
|
|
157
|
+
(Array.isArray(c) && c.length === meta.primaryKeys.length && c.every(i => Utils.isPrimaryKey(i))))) {
|
|
158
|
+
cond = { $or: where };
|
|
159
|
+
}
|
|
160
|
+
return QueryHelper.processWhere({ ...options, where: cond, root: false });
|
|
161
|
+
}
|
|
162
|
+
if (!Utils.isPlainObject(where)) {
|
|
163
|
+
return where;
|
|
164
|
+
}
|
|
165
|
+
return Utils.getObjectQueryKeys(where).reduce((o, key) => {
|
|
166
|
+
let value = where[key];
|
|
167
|
+
const customExpression = Raw.isKnownFragmentSymbol(key);
|
|
168
|
+
if (Array.isArray(value) && value.length === 0 && customExpression) {
|
|
169
|
+
o[key] = value;
|
|
170
|
+
return o;
|
|
171
|
+
}
|
|
172
|
+
if (key in GroupOperator) {
|
|
173
|
+
o[key] = value.map((sub) => QueryHelper.processWhere({ ...options, where: sub, root }));
|
|
174
|
+
return o;
|
|
175
|
+
}
|
|
176
|
+
// wrap top level operators (except platform allowed operators) with PK
|
|
177
|
+
if (Utils.isOperator(key) && root && meta && !platform.isAllowedTopLevelOperator(key)) {
|
|
178
|
+
const rootPrimaryKey = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
179
|
+
o[rootPrimaryKey] = { [key]: QueryHelper.processWhere({ ...options, where: value, root: false }) };
|
|
180
|
+
return o;
|
|
181
|
+
}
|
|
182
|
+
const prop = customExpression ? null : this.findProperty(key, options);
|
|
183
|
+
const keys = prop?.joinColumns?.length ?? 0;
|
|
184
|
+
const composite = keys > 1;
|
|
185
|
+
if (prop?.customType && convertCustomTypes && !isRaw(value)) {
|
|
186
|
+
value = QueryHelper.processCustomType(prop, value, platform, undefined, true);
|
|
187
|
+
}
|
|
188
|
+
// oxfmt-ignore
|
|
189
|
+
const isJsonProperty = prop?.customType instanceof JsonType && !isRaw(value) && (Utils.isPlainObject(value) ? !['$eq', '$elemMatch'].includes(Object.keys(value)[0]) : !Array.isArray(value));
|
|
190
|
+
if (isJsonProperty && prop?.kind !== ReferenceKind.EMBEDDED) {
|
|
191
|
+
return this.processJsonCondition(o, value, [prop.fieldNames[0]], platform, aliased);
|
|
192
|
+
}
|
|
193
|
+
// oxfmt-ignore
|
|
194
|
+
if (Array.isArray(value) && !Utils.isOperator(key) && !QueryHelper.isSupportedOperator(key) && !(customExpression && Raw.getKnownFragment(key).params.length > 0) && options.type !== 'orderBy') {
|
|
211
195
|
// comparing single composite key - use $eq instead of $in
|
|
212
196
|
const op = composite && !value.every(v => Array.isArray(v)) ? '$eq' : '$in';
|
|
213
197
|
o[key] = { [op]: value };
|
|
214
198
|
return o;
|
|
215
199
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
static getActiveFilters(meta, options, filters) {
|
|
230
|
-
if (options === false) {
|
|
231
|
-
return [];
|
|
232
|
-
}
|
|
233
|
-
const opts = {};
|
|
234
|
-
if (Array.isArray(options)) {
|
|
235
|
-
options.forEach(filter => (opts[filter] = true));
|
|
236
|
-
} else if (Utils.isPlainObject(options)) {
|
|
237
|
-
Object.keys(options).forEach(filter => (opts[filter] = options[filter]));
|
|
238
|
-
}
|
|
239
|
-
return Object.keys(filters)
|
|
240
|
-
.filter(f => QueryHelper.isFilterActive(meta, f, filters[f], opts))
|
|
241
|
-
.map(f => {
|
|
242
|
-
filters[f].name = f;
|
|
243
|
-
return filters[f];
|
|
244
|
-
});
|
|
245
|
-
}
|
|
246
|
-
static mergePropertyFilters(propFilters, options) {
|
|
247
|
-
if (!options || !propFilters || options === true || propFilters === true) {
|
|
248
|
-
return options ?? propFilters;
|
|
249
|
-
}
|
|
250
|
-
if (Array.isArray(propFilters)) {
|
|
251
|
-
propFilters = propFilters.reduce((o, item) => {
|
|
252
|
-
o[item] = true;
|
|
253
|
-
return o;
|
|
254
|
-
}, {});
|
|
255
|
-
}
|
|
256
|
-
if (Array.isArray(options)) {
|
|
257
|
-
options = options.reduce((o, item) => {
|
|
258
|
-
o[item] = true;
|
|
259
|
-
return o;
|
|
260
|
-
}, {});
|
|
261
|
-
}
|
|
262
|
-
return Utils.mergeConfig({}, propFilters, options);
|
|
263
|
-
}
|
|
264
|
-
static isFilterActive(meta, filterName, filter, options) {
|
|
265
|
-
if (filter.entity && !filter.entity.includes(meta.className)) {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
if (options[filterName] === false) {
|
|
269
|
-
return false;
|
|
270
|
-
}
|
|
271
|
-
return filter.default || filterName in options;
|
|
272
|
-
}
|
|
273
|
-
static processCustomType(prop, cond, platform, key, fromQuery) {
|
|
274
|
-
if (Utils.isPlainObject(cond)) {
|
|
275
|
-
return Utils.getObjectQueryKeys(cond).reduce((o, k) => {
|
|
276
|
-
if (!Raw.isKnownFragmentSymbol(k) && (Utils.isOperator(k, true) || prop.referencedPKs?.includes(k))) {
|
|
277
|
-
o[k] = QueryHelper.processCustomType(prop, cond[k], platform, k, fromQuery);
|
|
278
|
-
} else {
|
|
279
|
-
o[k] = cond[k];
|
|
280
|
-
}
|
|
281
|
-
return o;
|
|
282
|
-
}, {});
|
|
283
|
-
}
|
|
284
|
-
if (key && JSON_KEY_OPERATORS.includes(key)) {
|
|
285
|
-
return Array.isArray(cond) ? platform.marshallArray(cond) : cond;
|
|
200
|
+
if (Utils.isPlainObject(value)) {
|
|
201
|
+
o[key] = QueryHelper.processWhere({
|
|
202
|
+
...options,
|
|
203
|
+
where: value,
|
|
204
|
+
entityName: prop?.targetMeta?.class ?? entityName,
|
|
205
|
+
root: false,
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
o[key] = value;
|
|
210
|
+
}
|
|
211
|
+
return o;
|
|
212
|
+
}, {});
|
|
286
213
|
}
|
|
287
|
-
|
|
288
|
-
|
|
214
|
+
static getActiveFilters(meta, options, filters) {
|
|
215
|
+
if (options === false) {
|
|
216
|
+
return [];
|
|
217
|
+
}
|
|
218
|
+
const opts = {};
|
|
219
|
+
if (Array.isArray(options)) {
|
|
220
|
+
options.forEach(filter => (opts[filter] = true));
|
|
221
|
+
}
|
|
222
|
+
else if (Utils.isPlainObject(options)) {
|
|
223
|
+
Object.keys(options).forEach(filter => (opts[filter] = options[filter]));
|
|
224
|
+
}
|
|
225
|
+
return Object.keys(filters)
|
|
226
|
+
.filter(f => QueryHelper.isFilterActive(meta, f, filters[f], opts))
|
|
227
|
+
.map(f => {
|
|
228
|
+
filters[f].name = f;
|
|
229
|
+
return filters[f];
|
|
230
|
+
});
|
|
289
231
|
}
|
|
290
|
-
|
|
291
|
-
|
|
232
|
+
static mergePropertyFilters(propFilters, options) {
|
|
233
|
+
if (!options || !propFilters || options === true || propFilters === true) {
|
|
234
|
+
return options ?? propFilters;
|
|
235
|
+
}
|
|
236
|
+
if (Array.isArray(propFilters)) {
|
|
237
|
+
propFilters = propFilters.reduce((o, item) => {
|
|
238
|
+
o[item] = true;
|
|
239
|
+
return o;
|
|
240
|
+
}, {});
|
|
241
|
+
}
|
|
242
|
+
if (Array.isArray(options)) {
|
|
243
|
+
options = options.reduce((o, item) => {
|
|
244
|
+
o[item] = true;
|
|
245
|
+
return o;
|
|
246
|
+
}, {});
|
|
247
|
+
}
|
|
248
|
+
return Utils.mergeConfig({}, propFilters, options);
|
|
292
249
|
}
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
static findProperty(fieldName, options) {
|
|
302
|
-
const parts = fieldName.split('.');
|
|
303
|
-
const propName = parts.pop();
|
|
304
|
-
const alias = parts.length > 0 ? parts.join('.') : undefined;
|
|
305
|
-
const entityName = alias ? options.aliasMap?.[alias] : options.entityName;
|
|
306
|
-
const meta = entityName ? options.metadata.find(entityName) : undefined;
|
|
307
|
-
return meta?.properties[propName];
|
|
308
|
-
}
|
|
309
|
-
/**
|
|
310
|
-
* Converts entity references for composite FK properties into flat arrays
|
|
311
|
-
* of correctly-ordered join column values, before processParams flattens them
|
|
312
|
-
* incorrectly due to shared FK columns.
|
|
313
|
-
*/
|
|
314
|
-
static convertCompositeEntityRefs(where, meta) {
|
|
315
|
-
if (!Utils.isPlainObject(where)) {
|
|
316
|
-
return;
|
|
250
|
+
static isFilterActive(meta, filterName, filter, options) {
|
|
251
|
+
if (filter.entity && !filter.entity.includes(meta.className)) {
|
|
252
|
+
return false;
|
|
253
|
+
}
|
|
254
|
+
if (options[filterName] === false) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
return filter.default || filterName in options;
|
|
317
258
|
}
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
259
|
+
static processCustomType(prop, cond, platform, key, fromQuery) {
|
|
260
|
+
if (Utils.isPlainObject(cond)) {
|
|
261
|
+
return Utils.getObjectQueryKeys(cond).reduce((o, k) => {
|
|
262
|
+
if (!Raw.isKnownFragmentSymbol(k) && (Utils.isOperator(k, true) || prop.referencedPKs?.includes(k))) {
|
|
263
|
+
o[k] = QueryHelper.processCustomType(prop, cond[k], platform, k, fromQuery);
|
|
264
|
+
}
|
|
265
|
+
else {
|
|
266
|
+
o[k] = cond[k];
|
|
267
|
+
}
|
|
268
|
+
return o;
|
|
269
|
+
}, {});
|
|
270
|
+
}
|
|
271
|
+
if (key && JSON_KEY_OPERATORS.includes(key)) {
|
|
272
|
+
return Array.isArray(cond) ? platform.marshallArray(cond) : cond;
|
|
273
|
+
}
|
|
274
|
+
if (Array.isArray(cond) && !(key && ARRAY_OPERATORS.includes(key))) {
|
|
275
|
+
return cond.map(v => QueryHelper.processCustomType(prop, v, platform, key, fromQuery));
|
|
276
|
+
}
|
|
277
|
+
if (isRaw(cond)) {
|
|
278
|
+
return cond;
|
|
279
|
+
}
|
|
280
|
+
return prop.customType.convertToDatabaseValue(cond, platform, { fromQuery, key, mode: 'query' });
|
|
281
|
+
}
|
|
282
|
+
static isSupportedOperator(key) {
|
|
283
|
+
return !!QueryHelper.SUPPORTED_OPERATORS.find(op => key === op);
|
|
284
|
+
}
|
|
285
|
+
static processJsonCondition(o, value, path, platform, alias) {
|
|
286
|
+
return platform.processJsonCondition(o, value, path, alias);
|
|
287
|
+
}
|
|
288
|
+
static findProperty(fieldName, options) {
|
|
289
|
+
const parts = fieldName.split('.');
|
|
290
|
+
const propName = parts.pop();
|
|
291
|
+
const alias = parts.length > 0 ? parts.join('.') : undefined;
|
|
292
|
+
const entityName = alias ? options.aliasMap?.[alias] : options.entityName;
|
|
293
|
+
const meta = entityName ? options.metadata.find(entityName) : undefined;
|
|
294
|
+
return meta?.properties[propName];
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Converts entity references for composite FK properties into flat arrays
|
|
298
|
+
* of correctly-ordered join column values, before processParams flattens them
|
|
299
|
+
* incorrectly due to shared FK columns.
|
|
300
|
+
*/
|
|
301
|
+
static convertCompositeEntityRefs(where, meta) {
|
|
302
|
+
if (!Utils.isPlainObject(where)) {
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
for (const k of Object.keys(where)) {
|
|
306
|
+
if (k in GroupOperator) {
|
|
307
|
+
if (Array.isArray(where[k])) {
|
|
308
|
+
where[k].forEach((sub) => this.convertCompositeEntityRefs(sub, meta));
|
|
309
|
+
}
|
|
310
|
+
continue;
|
|
311
|
+
}
|
|
312
|
+
if (k === '$not') {
|
|
313
|
+
this.convertCompositeEntityRefs(where[k], meta);
|
|
314
|
+
continue;
|
|
315
|
+
}
|
|
316
|
+
const prop = meta.properties[k];
|
|
317
|
+
if (!prop?.joinColumns || prop.joinColumns.length <= 1) {
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
320
|
+
const w = where[k];
|
|
321
|
+
if (Utils.isEntity(w)) {
|
|
322
|
+
where[k] = this.extractJoinColumnValues(w, prop);
|
|
323
|
+
}
|
|
324
|
+
else if (Utils.isPlainObject(w)) {
|
|
325
|
+
for (const op of Object.keys(w)) {
|
|
326
|
+
if (Utils.isOperator(op, false) && Array.isArray(w[op])) {
|
|
327
|
+
w[op] = w[op].map((item) => Utils.isEntity(item) ? this.extractJoinColumnValues(item, prop) : item);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
343
332
|
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
/**
|
|
355
|
-
* Extracts the value for a specific column from an entity by finding which PK property
|
|
356
|
-
* owns that column and recursively traversing FK references.
|
|
357
|
-
*/
|
|
358
|
-
static extractColumnValue(entity, meta, columnName) {
|
|
359
|
-
for (const pk of meta.primaryKeys) {
|
|
360
|
-
const pkProp = meta.properties[pk];
|
|
361
|
-
const colIdx = pkProp.fieldNames.indexOf(columnName);
|
|
362
|
-
if (colIdx !== -1) {
|
|
363
|
-
const value = entity[pk];
|
|
364
|
-
if (pkProp.targetMeta && Utils.isEntity(value, true)) {
|
|
365
|
-
const refCol = pkProp.referencedColumnNames[colIdx];
|
|
366
|
-
return this.extractColumnValue(value, pkProp.targetMeta, refCol);
|
|
367
|
-
}
|
|
368
|
-
return value;
|
|
369
|
-
}
|
|
333
|
+
/**
|
|
334
|
+
* Extracts values for a FK's join columns from an entity by traversing the FK chain.
|
|
335
|
+
* Handles shared FK columns (e.g., tenant_id referenced by multiple FKs) correctly.
|
|
336
|
+
*/
|
|
337
|
+
static extractJoinColumnValues(entity, prop) {
|
|
338
|
+
return prop.referencedColumnNames.map(refCol => {
|
|
339
|
+
return this.extractColumnValue(entity, prop.targetMeta, refCol);
|
|
340
|
+
});
|
|
370
341
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
342
|
+
/**
|
|
343
|
+
* Extracts the value for a specific column from an entity by finding which PK property
|
|
344
|
+
* owns that column and recursively traversing FK references.
|
|
345
|
+
*/
|
|
346
|
+
static extractColumnValue(entity, meta, columnName) {
|
|
347
|
+
for (const pk of meta.primaryKeys) {
|
|
348
|
+
const pkProp = meta.properties[pk];
|
|
349
|
+
const colIdx = pkProp.fieldNames.indexOf(columnName);
|
|
350
|
+
if (colIdx !== -1) {
|
|
351
|
+
const value = entity[pk];
|
|
352
|
+
if (pkProp.targetMeta && Utils.isEntity(value, true)) {
|
|
353
|
+
const refCol = pkProp.referencedColumnNames[colIdx];
|
|
354
|
+
return this.extractColumnValue(value, pkProp.targetMeta, refCol);
|
|
355
|
+
}
|
|
356
|
+
return value;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
/**
|
|
362
|
+
* Merges multiple orderBy sources with key-level deduplication (first-seen key wins).
|
|
363
|
+
* RawQueryFragment symbol keys are never deduped (each is unique).
|
|
364
|
+
*/
|
|
365
|
+
static mergeOrderBy(...sources) {
|
|
366
|
+
const result = [];
|
|
367
|
+
const seenKeys = new Set();
|
|
368
|
+
for (const source of sources) {
|
|
369
|
+
if (source == null) {
|
|
370
|
+
continue;
|
|
371
|
+
}
|
|
372
|
+
for (const item of Utils.asArray(source)) {
|
|
373
|
+
for (const key of Utils.getObjectQueryKeys(item)) {
|
|
374
|
+
if (typeof key === 'symbol') {
|
|
375
|
+
result.push({ [key]: item[key] });
|
|
376
|
+
}
|
|
377
|
+
else if (!seenKeys.has(key)) {
|
|
378
|
+
seenKeys.add(key);
|
|
379
|
+
result.push({ [key]: item[key] });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
return result;
|
|
394
385
|
}
|
|
395
|
-
return result;
|
|
396
|
-
}
|
|
397
386
|
}
|