@mikro-orm/core 7.0.14 → 7.0.15-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 +584 -885
- package/EntityManager.js +1908 -1935
- package/MikroORM.d.ts +74 -103
- package/MikroORM.js +178 -177
- 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 +305 -444
- package/entity/BaseEntity.d.ts +83 -120
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +181 -215
- package/entity/Collection.js +724 -730
- package/entity/EntityAssigner.d.ts +77 -88
- package/entity/EntityAssigner.js +230 -231
- package/entity/EntityFactory.d.ts +55 -67
- package/entity/EntityFactory.js +413 -454
- package/entity/EntityHelper.d.ts +23 -35
- package/entity/EntityHelper.js +290 -302
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +72 -98
- package/entity/EntityLoader.js +786 -815
- 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 +83 -127
- package/entity/Reference.js +277 -281
- package/entity/WrappedEntity.d.ts +72 -115
- package/entity/WrappedEntity.js +166 -168
- package/entity/defineEntity.d.ts +654 -1359
- 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 +418 -483
- package/index.d.ts +2 -118
- 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 +130 -214
- package/metadata/EntitySchema.js +412 -411
- package/metadata/MetadataDiscovery.d.ts +115 -115
- package/metadata/MetadataDiscovery.js +1931 -2013
- package/metadata/MetadataProvider.d.ts +26 -29
- package/metadata/MetadataProvider.js +97 -95
- package/metadata/MetadataStorage.d.ts +32 -38
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +340 -385
- 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 +303 -312
- package/platforms/Platform.js +695 -715
- 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 +743 -1264
- package/typings.js +233 -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 +179 -187
- package/unit-of-work/ChangeSetPersister.d.ts +50 -69
- package/unit-of-work/ChangeSetPersister.js +446 -469
- 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 +1226 -1240
- package/utils/AbstractMigrator.d.ts +92 -112
- package/utils/AbstractMigrator.js +287 -285
- 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 +82 -99
- package/utils/EntityComparator.js +744 -836
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +57 -85
- package/utils/QueryHelper.js +392 -404
- package/utils/RawQueryFragment.d.ts +34 -50
- package/utils/RawQueryFragment.js +121 -122
- 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 +200 -202
- package/utils/Utils.d.ts +145 -204
- package/utils/Utils.js +826 -826
- package/utils/clone.js +114 -105
- package/utils/env-vars.js +88 -90
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +182 -181
- package/utils/upsert-utils.d.ts +5 -20
- package/utils/upsert-utils.js +116 -114
package/utils/QueryHelper.js
CHANGED
|
@@ -6,425 +6,413 @@ 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
|
-
static processParams(params) {
|
|
27
|
-
if (Reference.isReference(params)) {
|
|
28
|
-
params = params.unwrap();
|
|
29
|
-
}
|
|
30
|
-
if (Utils.isEntity(params)) {
|
|
31
|
-
if (helper(params).__meta.compositePK) {
|
|
32
|
-
return helper(params).__primaryKeys;
|
|
33
|
-
}
|
|
34
|
-
return helper(params).getPrimaryKey();
|
|
35
|
-
}
|
|
36
|
-
if (params === undefined) {
|
|
37
|
-
return null;
|
|
38
|
-
}
|
|
39
|
-
if (Array.isArray(params)) {
|
|
40
|
-
return params.map(item => QueryHelper.processParams(item));
|
|
9
|
+
static SUPPORTED_OPERATORS = ['>', '<', '<=', '>=', '!', '!='];
|
|
10
|
+
/**
|
|
11
|
+
* Finds the discriminator value (key) for a given entity class in a discriminator map.
|
|
12
|
+
* Walks up the prototype chain so TPT subclasses resolve to their root's key.
|
|
13
|
+
*/
|
|
14
|
+
static findDiscriminatorValue(discriminatorMap, targetClass) {
|
|
15
|
+
const entries = Object.entries(discriminatorMap);
|
|
16
|
+
let current = targetClass;
|
|
17
|
+
while (current != null) {
|
|
18
|
+
const hit = entries.find(([, cls]) => cls === current)?.[0];
|
|
19
|
+
if (hit) {
|
|
20
|
+
return hit;
|
|
21
|
+
}
|
|
22
|
+
current = Object.getPrototypeOf(current);
|
|
23
|
+
}
|
|
24
|
+
return undefined;
|
|
41
25
|
}
|
|
42
|
-
|
|
43
|
-
|
|
26
|
+
static processParams(params) {
|
|
27
|
+
if (Reference.isReference(params)) {
|
|
28
|
+
params = params.unwrap();
|
|
29
|
+
}
|
|
30
|
+
if (Utils.isEntity(params)) {
|
|
31
|
+
if (helper(params).__meta.compositePK) {
|
|
32
|
+
return helper(params).__primaryKeys;
|
|
33
|
+
}
|
|
34
|
+
return helper(params).getPrimaryKey();
|
|
35
|
+
}
|
|
36
|
+
if (params === undefined) {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(params)) {
|
|
40
|
+
return params.map(item => QueryHelper.processParams(item));
|
|
41
|
+
}
|
|
42
|
+
if (Utils.isPlainObject(params)) {
|
|
43
|
+
QueryHelper.processObjectParams(params);
|
|
44
|
+
}
|
|
45
|
+
return params;
|
|
44
46
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
static processObjectParams(params = {}) {
|
|
48
|
+
Utils.getObjectQueryKeys(params).forEach(k => {
|
|
49
|
+
params[k] = QueryHelper.processParams(params[k]);
|
|
50
|
+
});
|
|
51
|
+
return params;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* converts `{ account: { $or: [ [Object], [Object] ] } }`
|
|
55
|
+
* to `{ $or: [ { account: [Object] }, { account: [Object] } ] }`
|
|
56
|
+
*/
|
|
57
|
+
static liftGroupOperators(where, meta, metadata, key) {
|
|
58
|
+
if (!Utils.isPlainObject(where)) {
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
const keys = Object.keys(where);
|
|
62
|
+
const groupOperator = keys.find(k => {
|
|
63
|
+
return (k in GroupOperator &&
|
|
64
|
+
Array.isArray(where[k]) &&
|
|
65
|
+
where[k].every(cond => {
|
|
66
|
+
return (Utils.isPlainObject(cond) &&
|
|
67
|
+
Object.keys(cond).every(k2 => {
|
|
68
|
+
if (Utils.isOperator(k2, false)) {
|
|
69
|
+
if (k2 === '$not') {
|
|
70
|
+
return Object.keys(cond[k2]).every(k3 => meta.primaryKeys.includes(k3));
|
|
71
|
+
}
|
|
72
|
+
/* v8 ignore next */
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
return meta.primaryKeys.includes(k2);
|
|
76
|
+
}));
|
|
77
|
+
}));
|
|
78
|
+
});
|
|
79
|
+
if (groupOperator) {
|
|
80
|
+
return groupOperator;
|
|
81
|
+
}
|
|
82
|
+
for (const k of keys) {
|
|
83
|
+
const value = where[k];
|
|
84
|
+
const prop = meta.properties[k];
|
|
85
|
+
// Polymorphic relations use multiple columns (discriminator + FK), so they cannot
|
|
86
|
+
// participate in the standard single-column FK expansion. Query by discriminator
|
|
87
|
+
// column directly instead, e.g. { likeableType: 'post', likeableId: 1 }.
|
|
88
|
+
if (!prop || ![ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) || prop.polymorphic) {
|
|
89
|
+
continue;
|
|
90
|
+
}
|
|
91
|
+
const op = this.liftGroupOperators(value, prop.targetMeta, metadata, k);
|
|
92
|
+
if (op) {
|
|
93
|
+
delete where[k];
|
|
94
|
+
where[op] = value[op].map((v) => {
|
|
95
|
+
return { [k]: v };
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return undefined;
|
|
60
100
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
where[k].every(cond => {
|
|
67
|
-
return (
|
|
68
|
-
Utils.isPlainObject(cond) &&
|
|
69
|
-
Object.keys(cond).every(k2 => {
|
|
70
|
-
if (Utils.isOperator(k2, false)) {
|
|
71
|
-
if (k2 === '$not') {
|
|
72
|
-
return Object.keys(cond[k2]).every(k3 => meta.primaryKeys.includes(k3));
|
|
101
|
+
static inlinePrimaryKeyObjects(where, meta, metadata, key) {
|
|
102
|
+
if (Array.isArray(where)) {
|
|
103
|
+
where.forEach((item, i) => {
|
|
104
|
+
if (this.inlinePrimaryKeyObjects(item, meta, metadata, key)) {
|
|
105
|
+
where[i] = Utils.getPrimaryKeyValues(item, meta, false);
|
|
73
106
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
if (!Utils.isPlainObject(where) || (key && meta.properties[key]?.customType instanceof JsonType)) {
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
if (meta.primaryKeys.every(pk => pk in where) && Utils.getObjectKeysSize(where) === meta.primaryKeys.length) {
|
|
113
|
+
return (!!key &&
|
|
114
|
+
!GroupOperator[key] &&
|
|
115
|
+
key !== '$not' &&
|
|
116
|
+
Object.keys(where).every(k => !Utils.isPlainObject(where[k]) ||
|
|
117
|
+
Object.keys(where[k]).every(v => {
|
|
118
|
+
if (Utils.isOperator(v, false)) {
|
|
119
|
+
// multi-value operators (e.g. `$in`/`$nin`) cannot be inlined into a composite
|
|
120
|
+
// PK tuple — `getPrimaryKeyValues` would flatten the operator's array alongside
|
|
121
|
+
// the sibling PK values, producing a malformed `(col1, col2) IN ((a, b))` clause
|
|
122
|
+
return !meta.compositePK || !Array.isArray(where[k][v]);
|
|
123
|
+
}
|
|
124
|
+
if (meta.properties[k].primary &&
|
|
125
|
+
[ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(meta.properties[k].kind)) {
|
|
126
|
+
return this.inlinePrimaryKeyObjects(where[k], meta.properties[k].targetMeta, metadata, v);
|
|
127
|
+
}
|
|
128
|
+
/* v8 ignore next */
|
|
129
|
+
return true;
|
|
130
|
+
})));
|
|
131
|
+
}
|
|
132
|
+
Object.keys(where).forEach(k => {
|
|
133
|
+
const meta2 = metadata.find(meta.properties[k]?.targetMeta?.class) || meta;
|
|
134
|
+
if (this.inlinePrimaryKeyObjects(where[k], meta2, metadata, k)) {
|
|
135
|
+
where[k] = Utils.getPrimaryKeyValues(where[k], meta2, true);
|
|
136
|
+
}
|
|
100
137
|
});
|
|
101
|
-
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
if (
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (meta && Utils.isPrimaryKey(where, meta.compositePK)) {
|
|
172
|
-
where = { [Utils.getPrimaryKeyHash(meta.primaryKeys)]: where };
|
|
173
|
-
}
|
|
174
|
-
if (Array.isArray(where) && root) {
|
|
175
|
-
const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : Utils.className(entityName);
|
|
176
|
-
let cond = { [rootPrimaryKey]: { $in: where } };
|
|
177
|
-
// @ts-ignore
|
|
178
|
-
// detect tuple comparison, use `$or` in case the number of constituents don't match
|
|
179
|
-
if (
|
|
180
|
-
meta &&
|
|
181
|
-
!where.every(
|
|
182
|
-
c =>
|
|
183
|
-
Utils.isPrimaryKey(c) ||
|
|
184
|
-
(Array.isArray(c) && c.length === meta.primaryKeys.length && c.every(i => Utils.isPrimaryKey(i))),
|
|
185
|
-
)
|
|
186
|
-
) {
|
|
187
|
-
cond = { $or: where };
|
|
188
|
-
}
|
|
189
|
-
return QueryHelper.processWhere({ ...options, where: cond, root: false });
|
|
190
|
-
}
|
|
191
|
-
if (!Utils.isPlainObject(where)) {
|
|
192
|
-
return where;
|
|
193
|
-
}
|
|
194
|
-
return Utils.getObjectQueryKeys(where).reduce((o, key) => {
|
|
195
|
-
let value = where[key];
|
|
196
|
-
const customExpression = Raw.isKnownFragmentSymbol(key);
|
|
197
|
-
if (Array.isArray(value) && value.length === 0 && customExpression) {
|
|
198
|
-
o[key] = value;
|
|
199
|
-
return o;
|
|
200
|
-
}
|
|
201
|
-
if (key in GroupOperator) {
|
|
202
|
-
o[key] = value.map(sub => QueryHelper.processWhere({ ...options, where: sub, root }));
|
|
203
|
-
return o;
|
|
204
|
-
}
|
|
205
|
-
// wrap top level operators (except platform allowed operators) with PK
|
|
206
|
-
if (Utils.isOperator(key) && root && meta && !platform.isAllowedTopLevelOperator(key)) {
|
|
207
|
-
const rootPrimaryKey = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
208
|
-
o[rootPrimaryKey] = { [key]: QueryHelper.processWhere({ ...options, where: value, root: false }) };
|
|
209
|
-
return o;
|
|
210
|
-
}
|
|
211
|
-
const prop = customExpression ? null : this.findProperty(key, options);
|
|
212
|
-
const keys = prop?.joinColumns?.length ?? 0;
|
|
213
|
-
const composite = keys > 1;
|
|
214
|
-
if (prop?.customType && convertCustomTypes && !isRaw(value)) {
|
|
215
|
-
value = QueryHelper.processCustomType(prop, value, platform, undefined, true);
|
|
216
|
-
}
|
|
217
|
-
// oxfmt-ignore
|
|
218
|
-
const isJsonProperty = prop?.customType instanceof JsonType && !isRaw(value) && (Utils.isPlainObject(value) ? !['$eq', '$elemMatch'].includes(Object.keys(value)[0]) : !Array.isArray(value));
|
|
219
|
-
if (isJsonProperty && prop?.kind !== ReferenceKind.EMBEDDED) {
|
|
220
|
-
return this.processJsonCondition(o, value, [prop.fieldNames[0]], platform, aliased);
|
|
221
|
-
}
|
|
222
|
-
// oxfmt-ignore
|
|
223
|
-
if (Array.isArray(value) && !Utils.isOperator(key) && !QueryHelper.isSupportedOperator(key) && !(customExpression && Raw.getKnownFragment(key).params.length > 0) && options.type !== 'orderBy') {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
static processWhere(options) {
|
|
141
|
+
// eslint-disable-next-line prefer-const
|
|
142
|
+
let { where, entityName, metadata, platform, aliased = true, convertCustomTypes = true, root = true } = options;
|
|
143
|
+
const meta = metadata.find(entityName);
|
|
144
|
+
// inline PK-only objects in M:N queries, so we don't join the target entity when not needed
|
|
145
|
+
if (meta && root) {
|
|
146
|
+
QueryHelper.liftGroupOperators(where, meta, metadata);
|
|
147
|
+
QueryHelper.inlinePrimaryKeyObjects(where, meta, metadata);
|
|
148
|
+
}
|
|
149
|
+
if (meta && root) {
|
|
150
|
+
QueryHelper.convertCompositeEntityRefs(where, meta);
|
|
151
|
+
}
|
|
152
|
+
if (platform.getConfig().get('ignoreUndefinedInQuery') && where && typeof where === 'object') {
|
|
153
|
+
Utils.dropUndefinedProperties(where);
|
|
154
|
+
}
|
|
155
|
+
where = QueryHelper.processParams(where) ?? {};
|
|
156
|
+
/* v8 ignore next */
|
|
157
|
+
if (!root && Utils.isPrimaryKey(where)) {
|
|
158
|
+
return where;
|
|
159
|
+
}
|
|
160
|
+
if (meta && Utils.isPrimaryKey(where, meta.compositePK)) {
|
|
161
|
+
where = { [Utils.getPrimaryKeyHash(meta.primaryKeys)]: where };
|
|
162
|
+
}
|
|
163
|
+
if (Array.isArray(where) && root) {
|
|
164
|
+
const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : Utils.className(entityName);
|
|
165
|
+
let cond = { [rootPrimaryKey]: { $in: where } };
|
|
166
|
+
// @ts-ignore
|
|
167
|
+
// detect tuple comparison, use `$or` in case the number of constituents don't match
|
|
168
|
+
if (meta &&
|
|
169
|
+
!where.every(c => Utils.isPrimaryKey(c) ||
|
|
170
|
+
(Array.isArray(c) && c.length === meta.primaryKeys.length && c.every(i => Utils.isPrimaryKey(i))))) {
|
|
171
|
+
cond = { $or: where };
|
|
172
|
+
}
|
|
173
|
+
return QueryHelper.processWhere({ ...options, where: cond, root: false });
|
|
174
|
+
}
|
|
175
|
+
if (!Utils.isPlainObject(where)) {
|
|
176
|
+
return where;
|
|
177
|
+
}
|
|
178
|
+
return Utils.getObjectQueryKeys(where).reduce((o, key) => {
|
|
179
|
+
let value = where[key];
|
|
180
|
+
const customExpression = Raw.isKnownFragmentSymbol(key);
|
|
181
|
+
if (Array.isArray(value) && value.length === 0 && customExpression) {
|
|
182
|
+
o[key] = value;
|
|
183
|
+
return o;
|
|
184
|
+
}
|
|
185
|
+
if (key in GroupOperator) {
|
|
186
|
+
o[key] = value.map((sub) => QueryHelper.processWhere({ ...options, where: sub, root }));
|
|
187
|
+
return o;
|
|
188
|
+
}
|
|
189
|
+
// wrap top level operators (except platform allowed operators) with PK
|
|
190
|
+
if (Utils.isOperator(key) && root && meta && !platform.isAllowedTopLevelOperator(key)) {
|
|
191
|
+
const rootPrimaryKey = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
192
|
+
o[rootPrimaryKey] = { [key]: QueryHelper.processWhere({ ...options, where: value, root: false }) };
|
|
193
|
+
return o;
|
|
194
|
+
}
|
|
195
|
+
const prop = customExpression ? null : this.findProperty(key, options);
|
|
196
|
+
const keys = prop?.joinColumns?.length ?? 0;
|
|
197
|
+
const composite = keys > 1;
|
|
198
|
+
if (prop?.customType && convertCustomTypes && !isRaw(value)) {
|
|
199
|
+
value = QueryHelper.processCustomType(prop, value, platform, undefined, true);
|
|
200
|
+
}
|
|
201
|
+
// oxfmt-ignore
|
|
202
|
+
const isJsonProperty = prop?.customType instanceof JsonType && !isRaw(value) && (Utils.isPlainObject(value) ? !['$eq', '$elemMatch'].includes(Object.keys(value)[0]) : !Array.isArray(value));
|
|
203
|
+
if (isJsonProperty && prop?.kind !== ReferenceKind.EMBEDDED) {
|
|
204
|
+
return this.processJsonCondition(o, value, [prop.fieldNames[0]], platform, aliased);
|
|
205
|
+
}
|
|
206
|
+
// oxfmt-ignore
|
|
207
|
+
if (Array.isArray(value) && !Utils.isOperator(key) && !QueryHelper.isSupportedOperator(key) && !(customExpression && Raw.getKnownFragment(key).params.length > 0) && options.type !== 'orderBy') {
|
|
224
208
|
// comparing single composite key - use $eq instead of $in
|
|
225
209
|
const op = composite && !value.every(v => Array.isArray(v)) ? '$eq' : '$in';
|
|
226
210
|
o[key] = { [op]: value };
|
|
227
211
|
return o;
|
|
228
212
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
static getActiveFilters(meta, options, filters) {
|
|
243
|
-
if (options === false) {
|
|
244
|
-
return [];
|
|
245
|
-
}
|
|
246
|
-
const opts = {};
|
|
247
|
-
if (Array.isArray(options)) {
|
|
248
|
-
options.forEach(filter => (opts[filter] = true));
|
|
249
|
-
} else if (Utils.isPlainObject(options)) {
|
|
250
|
-
Object.keys(options).forEach(filter => (opts[filter] = options[filter]));
|
|
251
|
-
}
|
|
252
|
-
return Object.keys(filters)
|
|
253
|
-
.filter(f => QueryHelper.isFilterActive(meta, f, filters[f], opts))
|
|
254
|
-
.map(f => {
|
|
255
|
-
filters[f].name = f;
|
|
256
|
-
return filters[f];
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
static mergePropertyFilters(propFilters, options) {
|
|
260
|
-
if (!options || !propFilters || options === true || propFilters === true) {
|
|
261
|
-
return options ?? propFilters;
|
|
262
|
-
}
|
|
263
|
-
if (Array.isArray(propFilters)) {
|
|
264
|
-
propFilters = propFilters.reduce((o, item) => {
|
|
265
|
-
o[item] = true;
|
|
266
|
-
return o;
|
|
267
|
-
}, {});
|
|
268
|
-
}
|
|
269
|
-
if (Array.isArray(options)) {
|
|
270
|
-
options = options.reduce((o, item) => {
|
|
271
|
-
o[item] = true;
|
|
272
|
-
return o;
|
|
273
|
-
}, {});
|
|
274
|
-
}
|
|
275
|
-
return Utils.mergeConfig({}, propFilters, options);
|
|
276
|
-
}
|
|
277
|
-
static isFilterActive(meta, filterName, filter, options) {
|
|
278
|
-
if (filter.entity && !filter.entity.includes(meta.className)) {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
281
|
-
if (options[filterName] === false) {
|
|
282
|
-
return false;
|
|
283
|
-
}
|
|
284
|
-
return filter.default || filterName in options;
|
|
285
|
-
}
|
|
286
|
-
static processCustomType(prop, cond, platform, key, fromQuery) {
|
|
287
|
-
if (Utils.isPlainObject(cond)) {
|
|
288
|
-
return Utils.getObjectQueryKeys(cond).reduce((o, k) => {
|
|
289
|
-
if (!Raw.isKnownFragmentSymbol(k) && (Utils.isOperator(k, true) || prop.referencedPKs?.includes(k))) {
|
|
290
|
-
o[k] = QueryHelper.processCustomType(prop, cond[k], platform, k, fromQuery);
|
|
291
|
-
} else {
|
|
292
|
-
o[k] = cond[k];
|
|
293
|
-
}
|
|
294
|
-
return o;
|
|
295
|
-
}, {});
|
|
296
|
-
}
|
|
297
|
-
if (key && JSON_KEY_OPERATORS.includes(key)) {
|
|
298
|
-
return Array.isArray(cond) ? platform.marshallArray(cond) : cond;
|
|
213
|
+
if (Utils.isPlainObject(value)) {
|
|
214
|
+
o[key] = QueryHelper.processWhere({
|
|
215
|
+
...options,
|
|
216
|
+
where: value,
|
|
217
|
+
entityName: prop?.targetMeta?.class ?? entityName,
|
|
218
|
+
root: false,
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
o[key] = value;
|
|
223
|
+
}
|
|
224
|
+
return o;
|
|
225
|
+
}, {});
|
|
299
226
|
}
|
|
300
|
-
|
|
301
|
-
|
|
227
|
+
static getActiveFilters(meta, options, filters) {
|
|
228
|
+
if (options === false) {
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
const opts = {};
|
|
232
|
+
if (Array.isArray(options)) {
|
|
233
|
+
options.forEach(filter => (opts[filter] = true));
|
|
234
|
+
}
|
|
235
|
+
else if (Utils.isPlainObject(options)) {
|
|
236
|
+
Object.keys(options).forEach(filter => (opts[filter] = options[filter]));
|
|
237
|
+
}
|
|
238
|
+
return Object.keys(filters)
|
|
239
|
+
.filter(f => QueryHelper.isFilterActive(meta, f, filters[f], opts))
|
|
240
|
+
.map(f => {
|
|
241
|
+
filters[f].name = f;
|
|
242
|
+
return filters[f];
|
|
243
|
+
});
|
|
302
244
|
}
|
|
303
|
-
|
|
304
|
-
|
|
245
|
+
static mergePropertyFilters(propFilters, options) {
|
|
246
|
+
if (!options || !propFilters || options === true || propFilters === true) {
|
|
247
|
+
return options ?? propFilters;
|
|
248
|
+
}
|
|
249
|
+
if (Array.isArray(propFilters)) {
|
|
250
|
+
propFilters = propFilters.reduce((o, item) => {
|
|
251
|
+
o[item] = true;
|
|
252
|
+
return o;
|
|
253
|
+
}, {});
|
|
254
|
+
}
|
|
255
|
+
if (Array.isArray(options)) {
|
|
256
|
+
options = options.reduce((o, item) => {
|
|
257
|
+
o[item] = true;
|
|
258
|
+
return o;
|
|
259
|
+
}, {});
|
|
260
|
+
}
|
|
261
|
+
return Utils.mergeConfig({}, propFilters, options);
|
|
305
262
|
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
static findProperty(fieldName, options) {
|
|
315
|
-
const parts = fieldName.split('.');
|
|
316
|
-
const propName = parts.pop();
|
|
317
|
-
const alias = parts.length > 0 ? parts.join('.') : undefined;
|
|
318
|
-
const entityName = alias ? options.aliasMap?.[alias] : options.entityName;
|
|
319
|
-
const meta = entityName ? options.metadata.find(entityName) : undefined;
|
|
320
|
-
return meta?.properties[propName];
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* Converts entity references for composite FK properties into flat arrays
|
|
324
|
-
* of correctly-ordered join column values, before processParams flattens them
|
|
325
|
-
* incorrectly due to shared FK columns.
|
|
326
|
-
*/
|
|
327
|
-
static convertCompositeEntityRefs(where, meta) {
|
|
328
|
-
if (!Utils.isPlainObject(where)) {
|
|
329
|
-
return;
|
|
263
|
+
static isFilterActive(meta, filterName, filter, options) {
|
|
264
|
+
if (filter.entity && !filter.entity.includes(meta.className)) {
|
|
265
|
+
return false;
|
|
266
|
+
}
|
|
267
|
+
if (options[filterName] === false) {
|
|
268
|
+
return false;
|
|
269
|
+
}
|
|
270
|
+
return filter.default || filterName in options;
|
|
330
271
|
}
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
272
|
+
static processCustomType(prop, cond, platform, key, fromQuery) {
|
|
273
|
+
if (Utils.isPlainObject(cond)) {
|
|
274
|
+
return Utils.getObjectQueryKeys(cond).reduce((o, k) => {
|
|
275
|
+
if (!Raw.isKnownFragmentSymbol(k) && (Utils.isOperator(k, true) || prop.referencedPKs?.includes(k))) {
|
|
276
|
+
o[k] = QueryHelper.processCustomType(prop, cond[k], platform, k, fromQuery);
|
|
277
|
+
}
|
|
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;
|
|
286
|
+
}
|
|
287
|
+
if (Array.isArray(cond) && !(key && ARRAY_OPERATORS.includes(key))) {
|
|
288
|
+
return cond.map(v => QueryHelper.processCustomType(prop, v, platform, key, fromQuery));
|
|
289
|
+
}
|
|
290
|
+
if (isRaw(cond)) {
|
|
291
|
+
return cond;
|
|
292
|
+
}
|
|
293
|
+
return prop.customType.convertToDatabaseValue(cond, platform, { fromQuery, key, mode: 'query' });
|
|
294
|
+
}
|
|
295
|
+
static isSupportedOperator(key) {
|
|
296
|
+
return !!QueryHelper.SUPPORTED_OPERATORS.find(op => key === op);
|
|
297
|
+
}
|
|
298
|
+
static processJsonCondition(o, value, path, platform, alias) {
|
|
299
|
+
return platform.processJsonCondition(o, value, path, alias);
|
|
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;
|
|
317
|
+
}
|
|
318
|
+
for (const k of Object.keys(where)) {
|
|
319
|
+
if (k in GroupOperator) {
|
|
320
|
+
if (Array.isArray(where[k])) {
|
|
321
|
+
where[k].forEach((sub) => this.convertCompositeEntityRefs(sub, meta));
|
|
322
|
+
}
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
if (k === '$not') {
|
|
326
|
+
this.convertCompositeEntityRefs(where[k], meta);
|
|
327
|
+
continue;
|
|
328
|
+
}
|
|
329
|
+
const prop = meta.properties[k];
|
|
330
|
+
const polymorphic = !!prop?.polymorphic && (prop.fieldNames?.length ?? 0) > 1;
|
|
331
|
+
const composite = (prop?.joinColumns?.length ?? 0) > 1;
|
|
332
|
+
if (!polymorphic && !composite) {
|
|
333
|
+
continue;
|
|
334
|
+
}
|
|
335
|
+
const expand = (entity) => polymorphic
|
|
336
|
+
? this.extractPolymorphicJoinColumnValues(entity, prop)
|
|
337
|
+
: this.extractJoinColumnValues(entity, prop);
|
|
338
|
+
const expandItem = (item) => {
|
|
339
|
+
const entity = Reference.isReference(item) ? item.unwrap() : item;
|
|
340
|
+
return Utils.isEntity(entity) ? expand(entity) : item;
|
|
341
|
+
};
|
|
342
|
+
const w = where[k];
|
|
343
|
+
const expanded = expandItem(w);
|
|
344
|
+
if (expanded !== w) {
|
|
345
|
+
where[k] = expanded;
|
|
346
|
+
}
|
|
347
|
+
else if (Utils.isPlainObject(w)) {
|
|
348
|
+
for (const op of Object.keys(w)) {
|
|
349
|
+
if (!Utils.isOperator(op, false)) {
|
|
350
|
+
continue;
|
|
351
|
+
}
|
|
352
|
+
w[op] = Array.isArray(w[op]) ? w[op].map(expandItem) : expandItem(w[op]);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
368
356
|
}
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
});
|
|
378
|
-
}
|
|
379
|
-
/**
|
|
380
|
-
* Expands a polymorphic entity reference to `[discriminatorValue, ...joinColumnValues]`,
|
|
381
|
-
* matching the column order of `prop.fieldNames`.
|
|
382
|
-
*/
|
|
383
|
-
static extractPolymorphicJoinColumnValues(entity, prop) {
|
|
384
|
-
const discriminator = this.findDiscriminatorValue(prop.discriminatorMap, entity.constructor);
|
|
385
|
-
return [discriminator, ...this.extractJoinColumnValues(entity, prop)];
|
|
386
|
-
}
|
|
387
|
-
/**
|
|
388
|
-
* Extracts the value for a specific column from an entity by finding which PK property
|
|
389
|
-
* owns that column and recursively traversing FK references.
|
|
390
|
-
*/
|
|
391
|
-
static extractColumnValue(entity, meta, columnName) {
|
|
392
|
-
for (const pk of meta.primaryKeys) {
|
|
393
|
-
const pkProp = meta.properties[pk];
|
|
394
|
-
const colIdx = pkProp.fieldNames.indexOf(columnName);
|
|
395
|
-
if (colIdx !== -1) {
|
|
396
|
-
const value = entity[pk];
|
|
397
|
-
if (pkProp.targetMeta && Utils.isEntity(value, true)) {
|
|
398
|
-
const refCol = pkProp.referencedColumnNames[colIdx];
|
|
399
|
-
return this.extractColumnValue(value, pkProp.targetMeta, refCol);
|
|
400
|
-
}
|
|
401
|
-
return value;
|
|
402
|
-
}
|
|
357
|
+
/**
|
|
358
|
+
* Extracts values for a FK's join columns from an entity by traversing the FK chain.
|
|
359
|
+
* Handles shared FK columns (e.g., tenant_id referenced by multiple FKs) correctly.
|
|
360
|
+
*/
|
|
361
|
+
static extractJoinColumnValues(entity, prop) {
|
|
362
|
+
return prop.referencedColumnNames.map(refCol => {
|
|
363
|
+
return this.extractColumnValue(entity, prop.targetMeta, refCol);
|
|
364
|
+
});
|
|
403
365
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
366
|
+
/**
|
|
367
|
+
* Expands a polymorphic entity reference to `[discriminatorValue, ...joinColumnValues]`,
|
|
368
|
+
* matching the column order of `prop.fieldNames`.
|
|
369
|
+
*/
|
|
370
|
+
static extractPolymorphicJoinColumnValues(entity, prop) {
|
|
371
|
+
const discriminator = this.findDiscriminatorValue(prop.discriminatorMap, entity.constructor);
|
|
372
|
+
return [discriminator, ...this.extractJoinColumnValues(entity, prop)];
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Extracts the value for a specific column from an entity by finding which PK property
|
|
376
|
+
* owns that column and recursively traversing FK references.
|
|
377
|
+
*/
|
|
378
|
+
static extractColumnValue(entity, meta, columnName) {
|
|
379
|
+
for (const pk of meta.primaryKeys) {
|
|
380
|
+
const pkProp = meta.properties[pk];
|
|
381
|
+
const colIdx = pkProp.fieldNames.indexOf(columnName);
|
|
382
|
+
if (colIdx !== -1) {
|
|
383
|
+
const value = entity[pk];
|
|
384
|
+
if (pkProp.targetMeta && Utils.isEntity(value, true)) {
|
|
385
|
+
const refCol = pkProp.referencedColumnNames[colIdx];
|
|
386
|
+
return this.extractColumnValue(value, pkProp.targetMeta, refCol);
|
|
387
|
+
}
|
|
388
|
+
return value;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return null;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* Merges multiple orderBy sources with key-level deduplication (first-seen key wins).
|
|
395
|
+
* RawQueryFragment symbol keys are never deduped (each is unique).
|
|
396
|
+
*/
|
|
397
|
+
static mergeOrderBy(...sources) {
|
|
398
|
+
const result = [];
|
|
399
|
+
const seenKeys = new Set();
|
|
400
|
+
for (const source of sources) {
|
|
401
|
+
if (source == null) {
|
|
402
|
+
continue;
|
|
403
|
+
}
|
|
404
|
+
for (const item of Utils.asArray(source)) {
|
|
405
|
+
for (const key of Utils.getObjectQueryKeys(item)) {
|
|
406
|
+
if (typeof key === 'symbol') {
|
|
407
|
+
result.push({ [key]: item[key] });
|
|
408
|
+
}
|
|
409
|
+
else if (!seenKeys.has(key)) {
|
|
410
|
+
seenKeys.add(key);
|
|
411
|
+
result.push({ [key]: item[key] });
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
return result;
|
|
427
417
|
}
|
|
428
|
-
return result;
|
|
429
|
-
}
|
|
430
418
|
}
|