@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.11
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 +25 -16
- package/EntityManager.js +219 -209
- package/MikroORM.d.ts +7 -6
- package/MikroORM.js +33 -45
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +18 -26
- package/cache/GeneratedCacheAdapter.d.ts +2 -2
- package/cache/GeneratedCacheAdapter.js +1 -5
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +5 -5
- package/cache/index.js +5 -21
- package/connections/Connection.d.ts +7 -7
- package/connections/Connection.js +8 -12
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/decorators/Check.d.ts +2 -2
- package/decorators/Check.js +5 -8
- package/decorators/CreateRequestContext.d.ts +1 -1
- package/decorators/CreateRequestContext.js +13 -14
- package/decorators/Embeddable.d.ts +5 -5
- package/decorators/Embeddable.js +4 -7
- package/decorators/Embedded.d.ts +3 -3
- package/decorators/Embedded.js +10 -12
- package/decorators/Entity.d.ts +6 -6
- package/decorators/Entity.js +5 -9
- package/decorators/Enum.d.ts +3 -3
- package/decorators/Enum.js +7 -10
- package/decorators/Filter.d.ts +1 -1
- package/decorators/Filter.js +3 -6
- package/decorators/Formula.d.ts +2 -3
- package/decorators/Formula.js +7 -10
- package/decorators/Indexed.d.ts +10 -8
- package/decorators/Indexed.js +7 -11
- package/decorators/ManyToMany.d.ts +4 -4
- package/decorators/ManyToMany.js +10 -12
- package/decorators/ManyToOne.d.ts +4 -4
- package/decorators/ManyToOne.js +10 -12
- package/decorators/OneToMany.d.ts +6 -6
- package/decorators/OneToMany.js +11 -14
- package/decorators/OneToOne.d.ts +4 -4
- package/decorators/OneToOne.js +4 -7
- package/decorators/PrimaryKey.d.ts +3 -4
- package/decorators/PrimaryKey.js +10 -13
- package/decorators/Property.d.ts +6 -6
- package/decorators/Property.js +10 -12
- package/decorators/Transactional.d.ts +2 -2
- package/decorators/Transactional.js +7 -10
- package/decorators/hooks.js +23 -35
- package/decorators/index.d.ts +17 -17
- package/decorators/index.js +17 -36
- package/drivers/DatabaseDriver.d.ts +13 -12
- package/drivers/DatabaseDriver.js +60 -64
- package/drivers/IDatabaseDriver.d.ts +16 -13
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/ArrayCollection.d.ts +3 -3
- package/entity/ArrayCollection.js +38 -35
- package/entity/BaseEntity.d.ts +6 -6
- package/entity/BaseEntity.js +17 -21
- package/entity/Collection.d.ts +6 -7
- package/entity/Collection.js +47 -51
- package/entity/EntityAssigner.d.ts +2 -2
- package/entity/EntityAssigner.js +58 -63
- package/entity/EntityFactory.d.ts +3 -3
- package/entity/EntityFactory.js +62 -63
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +44 -45
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +5 -5
- package/entity/EntityLoader.js +106 -98
- package/entity/EntityRepository.d.ts +7 -7
- package/entity/EntityRepository.js +7 -11
- package/entity/EntityValidator.d.ts +1 -1
- package/entity/EntityValidator.js +25 -29
- package/entity/Reference.d.ts +4 -8
- package/entity/Reference.js +35 -42
- package/entity/WrappedEntity.d.ts +12 -12
- package/entity/WrappedEntity.js +23 -27
- package/entity/index.d.ts +13 -13
- package/entity/index.js +13 -29
- package/entity/utils.d.ts +1 -1
- package/entity/utils.js +9 -12
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +3 -3
- package/enums.js +37 -41
- package/errors.d.ts +1 -1
- package/errors.js +15 -24
- package/events/EventManager.d.ts +3 -3
- package/events/EventManager.js +8 -12
- package/events/EventSubscriber.d.ts +8 -5
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +3 -6
- package/hydration/ObjectHydrator.d.ts +3 -3
- package/hydration/ObjectHydrator.js +26 -28
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +21 -46
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +9 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +2 -2
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +4 -4
- package/logging/index.js +4 -20
- package/metadata/EntitySchema.d.ts +14 -6
- package/metadata/EntitySchema.js +41 -45
- package/metadata/MetadataDiscovery.d.ts +7 -7
- package/metadata/MetadataDiscovery.js +181 -180
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +4 -7
- package/metadata/MetadataStorage.d.ts +2 -2
- package/metadata/MetadataStorage.js +15 -19
- package/metadata/MetadataValidator.d.ts +4 -4
- package/metadata/MetadataValidator.js +52 -55
- package/metadata/ReflectMetadataProvider.d.ts +2 -2
- package/metadata/ReflectMetadataProvider.js +8 -12
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +4 -8
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +1 -1
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/package.json +6 -15
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +10 -10
- package/platforms/Platform.js +57 -61
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +2 -2
- package/serialization/EntitySerializer.js +36 -41
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +27 -31
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +10 -14
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +7 -11
- package/types/BigIntType.d.ts +4 -3
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +2 -8
- package/types/BooleanType.d.ts +3 -3
- package/types/BooleanType.js +2 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +3 -3
- package/types/DecimalType.js +4 -7
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +3 -6
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +5 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +3 -3
- package/types/JsonType.js +2 -6
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +2 -2
- package/types/Type.js +5 -9
- package/types/Uint8ArrayType.d.ts +3 -3
- package/types/Uint8ArrayType.js +3 -9
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +33 -28
- package/typings.js +37 -38
- package/unit-of-work/ChangeSet.d.ts +1 -1
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -7
- package/unit-of-work/ChangeSetComputer.js +26 -30
- package/unit-of-work/ChangeSetPersister.d.ts +7 -6
- package/unit-of-work/ChangeSetPersister.js +51 -48
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +8 -7
- package/unit-of-work/UnitOfWork.js +193 -178
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +6 -6
- package/utils/AbstractSchemaGenerator.js +12 -13
- package/utils/Configuration.d.ts +26 -27
- package/utils/Configuration.js +50 -55
- package/utils/ConfigurationLoader.d.ts +9 -8
- package/utils/ConfigurationLoader.js +71 -86
- package/utils/Cursor.d.ts +6 -6
- package/utils/Cursor.js +22 -25
- package/utils/DataloaderUtils.d.ts +4 -4
- package/utils/DataloaderUtils.js +12 -16
- package/utils/EntityComparator.d.ts +2 -2
- package/utils/EntityComparator.js +109 -97
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +3 -3
- package/utils/QueryHelper.js +47 -51
- package/utils/RawQueryFragment.d.ts +1 -1
- package/utils/RawQueryFragment.js +22 -25
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/Utils.d.ts +16 -12
- package/utils/Utils.js +96 -95
- package/utils/clone.js +8 -11
- package/utils/index.d.ts +13 -13
- package/utils/index.js +13 -29
- package/utils/resolveContextProvider.d.ts +3 -3
- package/utils/resolveContextProvider.js +9 -12
- package/utils/upsert-utils.d.ts +3 -3
- package/utils/upsert-utils.js +5 -9
- package/index.mjs +0 -199
package/utils/QueryHelper.js
CHANGED
|
@@ -1,23 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const wrap_1 = require("../entity/wrap");
|
|
9
|
-
const RawQueryFragment_1 = require("./RawQueryFragment");
|
|
10
|
-
class QueryHelper {
|
|
1
|
+
import { Reference } from '../entity/Reference.js';
|
|
2
|
+
import { Utils } from './Utils.js';
|
|
3
|
+
import { GroupOperator, ReferenceKind } from '../enums.js';
|
|
4
|
+
import { JsonType } from '../types/JsonType.js';
|
|
5
|
+
import { helper } from '../entity/wrap.js';
|
|
6
|
+
import { RawQueryFragment, isRaw } from './RawQueryFragment.js';
|
|
7
|
+
export class QueryHelper {
|
|
11
8
|
static SUPPORTED_OPERATORS = ['>', '<', '<=', '>=', '!', '!='];
|
|
12
9
|
static processParams(params) {
|
|
13
|
-
if (
|
|
10
|
+
if (Reference.isReference(params)) {
|
|
14
11
|
params = params.unwrap();
|
|
15
12
|
}
|
|
16
|
-
if (
|
|
17
|
-
if (
|
|
18
|
-
return
|
|
13
|
+
if (Utils.isEntity(params)) {
|
|
14
|
+
if (helper(params).__meta.compositePK) {
|
|
15
|
+
return helper(params).__primaryKeys;
|
|
19
16
|
}
|
|
20
|
-
return
|
|
17
|
+
return helper(params).getPrimaryKey();
|
|
21
18
|
}
|
|
22
19
|
if (params === undefined) {
|
|
23
20
|
return null;
|
|
@@ -25,13 +22,13 @@ class QueryHelper {
|
|
|
25
22
|
if (Array.isArray(params)) {
|
|
26
23
|
return params.map(item => QueryHelper.processParams(item));
|
|
27
24
|
}
|
|
28
|
-
if (
|
|
25
|
+
if (Utils.isPlainObject(params)) {
|
|
29
26
|
QueryHelper.processObjectParams(params);
|
|
30
27
|
}
|
|
31
28
|
return params;
|
|
32
29
|
}
|
|
33
30
|
static processObjectParams(params = {}) {
|
|
34
|
-
|
|
31
|
+
Utils.keys(params).forEach(k => {
|
|
35
32
|
params[k] = QueryHelper.processParams(params[k]);
|
|
36
33
|
});
|
|
37
34
|
return params;
|
|
@@ -40,19 +37,19 @@ class QueryHelper {
|
|
|
40
37
|
if (Array.isArray(where)) {
|
|
41
38
|
where.forEach((item, i) => {
|
|
42
39
|
if (this.inlinePrimaryKeyObjects(item, meta, metadata, key)) {
|
|
43
|
-
where[i] =
|
|
40
|
+
where[i] = Utils.getPrimaryKeyValues(item, meta.primaryKeys, false);
|
|
44
41
|
}
|
|
45
42
|
});
|
|
46
43
|
}
|
|
47
|
-
if (!
|
|
44
|
+
if (!Utils.isPlainObject(where) || (key && meta.properties[key]?.customType instanceof JsonType)) {
|
|
48
45
|
return false;
|
|
49
46
|
}
|
|
50
|
-
if (meta.primaryKeys.every(pk => pk in where) &&
|
|
51
|
-
return !!key && !
|
|
52
|
-
if (
|
|
47
|
+
if (meta.primaryKeys.every(pk => pk in where) && Utils.getObjectKeysSize(where) === meta.primaryKeys.length) {
|
|
48
|
+
return !!key && !GroupOperator[key] && key !== '$not' && Object.keys(where).every(k => !Utils.isPlainObject(where[k]) || Object.keys(where[k]).every(v => {
|
|
49
|
+
if (Utils.isOperator(v, false)) {
|
|
53
50
|
return false;
|
|
54
51
|
}
|
|
55
|
-
if (meta.properties[k].primary && [
|
|
52
|
+
if (meta.properties[k].primary && [ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(meta.properties[k].kind)) {
|
|
56
53
|
return this.inlinePrimaryKeyObjects(where[k], meta.properties[k].targetMeta, metadata, v);
|
|
57
54
|
}
|
|
58
55
|
return true;
|
|
@@ -61,7 +58,7 @@ class QueryHelper {
|
|
|
61
58
|
Object.keys(where).forEach(k => {
|
|
62
59
|
const meta2 = metadata.find(meta.properties[k]?.type) || meta;
|
|
63
60
|
if (this.inlinePrimaryKeyObjects(where[k], meta2, metadata, k)) {
|
|
64
|
-
where[k] =
|
|
61
|
+
where[k] = Utils.getPrimaryKeyValues(where[k], meta2.primaryKeys, true);
|
|
65
62
|
}
|
|
66
63
|
});
|
|
67
64
|
return false;
|
|
@@ -75,27 +72,27 @@ class QueryHelper {
|
|
|
75
72
|
QueryHelper.inlinePrimaryKeyObjects(where, meta, metadata);
|
|
76
73
|
}
|
|
77
74
|
if (platform.getConfig().get('ignoreUndefinedInQuery') && where && typeof where === 'object') {
|
|
78
|
-
|
|
75
|
+
Utils.dropUndefinedProperties(where);
|
|
79
76
|
}
|
|
80
77
|
where = QueryHelper.processParams(where) ?? {};
|
|
81
|
-
/*
|
|
82
|
-
if (!root &&
|
|
78
|
+
/* v8 ignore next 3 */
|
|
79
|
+
if (!root && Utils.isPrimaryKey(where)) {
|
|
83
80
|
return where;
|
|
84
81
|
}
|
|
85
|
-
if (meta &&
|
|
86
|
-
where = { [
|
|
82
|
+
if (meta && Utils.isPrimaryKey(where, meta.compositePK)) {
|
|
83
|
+
where = { [Utils.getPrimaryKeyHash(meta.primaryKeys)]: where };
|
|
87
84
|
}
|
|
88
85
|
if (Array.isArray(where) && root) {
|
|
89
|
-
const rootPrimaryKey = meta ?
|
|
86
|
+
const rootPrimaryKey = meta ? Utils.getPrimaryKeyHash(meta.primaryKeys) : entityName;
|
|
90
87
|
let cond = { [rootPrimaryKey]: { $in: where } };
|
|
91
88
|
// @ts-ignore
|
|
92
89
|
// detect tuple comparison, use `$or` in case the number of constituents don't match
|
|
93
|
-
if (meta && !where.every(c =>
|
|
90
|
+
if (meta && !where.every(c => Utils.isPrimaryKey(c) || (Array.isArray(c) && c.length === meta.primaryKeys.length && c.every(i => Utils.isPrimaryKey(i))))) {
|
|
94
91
|
cond = { $or: where };
|
|
95
92
|
}
|
|
96
93
|
return QueryHelper.processWhere({ ...options, where: cond, root: false });
|
|
97
94
|
}
|
|
98
|
-
if (!
|
|
95
|
+
if (!Utils.isPlainObject(where)) {
|
|
99
96
|
return where;
|
|
100
97
|
}
|
|
101
98
|
return Object.keys(where).reduce((o, key) => {
|
|
@@ -103,34 +100,34 @@ class QueryHelper {
|
|
|
103
100
|
const prop = this.findProperty(key, options);
|
|
104
101
|
const keys = prop?.joinColumns?.length ?? 0;
|
|
105
102
|
const composite = keys > 1;
|
|
106
|
-
if (Array.isArray(value) && value.length === 0 &&
|
|
103
|
+
if (Array.isArray(value) && value.length === 0 && RawQueryFragment.isKnownFragment(key)) {
|
|
107
104
|
o[key] = value;
|
|
108
105
|
return o;
|
|
109
106
|
}
|
|
110
|
-
if (key in
|
|
107
|
+
if (key in GroupOperator) {
|
|
111
108
|
o[key] = value.map((sub) => QueryHelper.processWhere({ ...options, where: sub, root }));
|
|
112
109
|
return o;
|
|
113
110
|
}
|
|
114
111
|
// wrap top level operators (except platform allowed operators) with PK
|
|
115
|
-
if (
|
|
116
|
-
const rootPrimaryKey =
|
|
112
|
+
if (Utils.isOperator(key) && root && meta && !platform.isAllowedTopLevelOperator(key)) {
|
|
113
|
+
const rootPrimaryKey = Utils.getPrimaryKeyHash(meta.primaryKeys);
|
|
117
114
|
o[rootPrimaryKey] = { [key]: QueryHelper.processWhere({ ...options, where: value, root: false }) };
|
|
118
115
|
return o;
|
|
119
116
|
}
|
|
120
|
-
if (prop?.customType && convertCustomTypes && !
|
|
117
|
+
if (prop?.customType && convertCustomTypes && !isRaw(value)) {
|
|
121
118
|
value = QueryHelper.processCustomType(prop, value, platform, undefined, true);
|
|
122
119
|
}
|
|
123
|
-
const isJsonProperty = prop?.customType instanceof
|
|
120
|
+
const isJsonProperty = prop?.customType instanceof JsonType && Utils.isPlainObject(value) && !isRaw(value) && Object.keys(value)[0] !== '$eq';
|
|
124
121
|
if (isJsonProperty) {
|
|
125
122
|
return this.processJsonCondition(o, value, [prop.fieldNames[0]], platform, aliased);
|
|
126
123
|
}
|
|
127
|
-
if (Array.isArray(value) && !
|
|
124
|
+
if (Array.isArray(value) && !Utils.isOperator(key) && !QueryHelper.isSupportedOperator(key) && !key.includes('?') && options.type !== 'orderBy') {
|
|
128
125
|
// comparing single composite key - use $eq instead of $in
|
|
129
126
|
const op = composite && !value.every(v => Array.isArray(v)) ? '$eq' : '$in';
|
|
130
127
|
o[key] = { [op]: value };
|
|
131
128
|
return o;
|
|
132
129
|
}
|
|
133
|
-
if (
|
|
130
|
+
if (Utils.isPlainObject(value)) {
|
|
134
131
|
o[key] = QueryHelper.processWhere({
|
|
135
132
|
...options,
|
|
136
133
|
where: value,
|
|
@@ -152,7 +149,7 @@ class QueryHelper {
|
|
|
152
149
|
if (Array.isArray(options)) {
|
|
153
150
|
options.forEach(filter => opts[filter] = true);
|
|
154
151
|
}
|
|
155
|
-
else if (
|
|
152
|
+
else if (Utils.isPlainObject(options)) {
|
|
156
153
|
Object.keys(options).forEach(filter => opts[filter] = options[filter]);
|
|
157
154
|
}
|
|
158
155
|
return Object.keys(filters)
|
|
@@ -172,9 +169,9 @@ class QueryHelper {
|
|
|
172
169
|
return filter.default || filterName in options;
|
|
173
170
|
}
|
|
174
171
|
static processCustomType(prop, cond, platform, key, fromQuery) {
|
|
175
|
-
if (
|
|
176
|
-
return
|
|
177
|
-
if (
|
|
172
|
+
if (Utils.isPlainObject(cond)) {
|
|
173
|
+
return Utils.keys(cond).reduce((o, k) => {
|
|
174
|
+
if (Utils.isOperator(k, true) || prop.referencedPKs?.includes(k)) {
|
|
178
175
|
o[k] = QueryHelper.processCustomType(prop, cond[k], platform, k, fromQuery);
|
|
179
176
|
}
|
|
180
177
|
else {
|
|
@@ -183,15 +180,15 @@ class QueryHelper {
|
|
|
183
180
|
return o;
|
|
184
181
|
}, {});
|
|
185
182
|
}
|
|
186
|
-
if (key &&
|
|
183
|
+
if (key && Utils.isJsonKeyOperator(key)) {
|
|
187
184
|
return Array.isArray(cond)
|
|
188
185
|
? platform.marshallArray(cond)
|
|
189
186
|
: cond;
|
|
190
187
|
}
|
|
191
|
-
if (Array.isArray(cond) && !(key &&
|
|
188
|
+
if (Array.isArray(cond) && !(key && Utils.isArrayOperator(key))) {
|
|
192
189
|
return cond.map(v => QueryHelper.processCustomType(prop, v, platform, key, fromQuery));
|
|
193
190
|
}
|
|
194
|
-
if (
|
|
191
|
+
if (isRaw(cond)) {
|
|
195
192
|
return cond;
|
|
196
193
|
}
|
|
197
194
|
return prop.customType.convertToDatabaseValue(cond, platform, { fromQuery, key, mode: 'query' });
|
|
@@ -200,8 +197,8 @@ class QueryHelper {
|
|
|
200
197
|
return !!QueryHelper.SUPPORTED_OPERATORS.find(op => key === op);
|
|
201
198
|
}
|
|
202
199
|
static processJsonCondition(o, value, path, platform, alias) {
|
|
203
|
-
if (
|
|
204
|
-
|
|
200
|
+
if (Utils.isPlainObject(value) && !Object.keys(value).some(k => Utils.isOperator(k))) {
|
|
201
|
+
Utils.keys(value).forEach(k => {
|
|
205
202
|
this.processJsonCondition(o, value[k], [...path, k], platform, alias);
|
|
206
203
|
});
|
|
207
204
|
return o;
|
|
@@ -219,7 +216,7 @@ class QueryHelper {
|
|
|
219
216
|
if (Array.isArray(value)) {
|
|
220
217
|
return typeof value[0];
|
|
221
218
|
}
|
|
222
|
-
if (
|
|
219
|
+
if (Utils.isPlainObject(value) && Object.keys(value).every(k => Utils.isOperator(k))) {
|
|
223
220
|
return this.getValueType(Object.values(value)[0]);
|
|
224
221
|
}
|
|
225
222
|
return typeof value;
|
|
@@ -233,4 +230,3 @@ class QueryHelper {
|
|
|
233
230
|
return meta?.properties[propName];
|
|
234
231
|
}
|
|
235
232
|
}
|
|
236
|
-
exports.QueryHelper = QueryHelper;
|
|
@@ -1,18 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.raw = raw;
|
|
6
|
-
exports.sql = sql;
|
|
7
|
-
exports.createSqlFunction = createSqlFunction;
|
|
8
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
9
|
-
const node_util_1 = require("node:util");
|
|
10
|
-
const Utils_1 = require("./Utils");
|
|
11
|
-
class RawQueryFragment {
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
import { inspect } from 'node:util';
|
|
3
|
+
import { Utils } from './Utils.js';
|
|
4
|
+
export class RawQueryFragment {
|
|
12
5
|
sql;
|
|
13
6
|
params;
|
|
14
7
|
static #rawQueryCache = new Map();
|
|
15
|
-
static #storage = new
|
|
8
|
+
static #storage = new AsyncLocalStorage();
|
|
16
9
|
static #index = 0n;
|
|
17
10
|
static cloneRegistry;
|
|
18
11
|
#assigned = false;
|
|
@@ -24,7 +17,12 @@ class RawQueryFragment {
|
|
|
24
17
|
this.#key = `[raw]: ${this.sql} (#${RawQueryFragment.#index++})`;
|
|
25
18
|
}
|
|
26
19
|
as(alias) {
|
|
27
|
-
|
|
20
|
+
// TODO: to be removed in v7
|
|
21
|
+
/* istanbul ignore next */
|
|
22
|
+
if (alias.startsWith('`') || alias.startsWith('"')) {
|
|
23
|
+
return new RawQueryFragment(`${this.sql} as ${alias}`, this.params);
|
|
24
|
+
}
|
|
25
|
+
return new RawQueryFragment(`${this.sql} as ??`, [...this.params, alias]);
|
|
28
26
|
}
|
|
29
27
|
valueOf() {
|
|
30
28
|
throw new Error(`Trying to modify raw SQL fragment: '${this.sql}'`);
|
|
@@ -93,27 +91,26 @@ class RawQueryFragment {
|
|
|
93
91
|
}
|
|
94
92
|
}
|
|
95
93
|
}
|
|
96
|
-
/*
|
|
94
|
+
/* v8 ignore next 8 */
|
|
97
95
|
/** @ignore */
|
|
98
|
-
[
|
|
96
|
+
[inspect.custom]() {
|
|
99
97
|
if (this.params) {
|
|
100
98
|
return { sql: this.sql, params: this.params };
|
|
101
99
|
}
|
|
102
100
|
return { sql: this.sql };
|
|
103
101
|
}
|
|
104
102
|
}
|
|
105
|
-
|
|
106
|
-
exports.Raw = RawQueryFragment;
|
|
103
|
+
export { RawQueryFragment as Raw };
|
|
107
104
|
Object.defineProperties(RawQueryFragment.prototype, {
|
|
108
105
|
__raw: { value: true, enumerable: false },
|
|
109
106
|
});
|
|
110
|
-
function isRaw(value) {
|
|
107
|
+
export function isRaw(value) {
|
|
111
108
|
return typeof value === 'object' && value !== null && '__raw' in value;
|
|
112
109
|
}
|
|
113
110
|
/** @internal */
|
|
114
|
-
|
|
111
|
+
export const ALIAS_REPLACEMENT = '[::alias::]';
|
|
115
112
|
/** @internal */
|
|
116
|
-
|
|
113
|
+
export const ALIAS_REPLACEMENT_RE = '\\[::alias::\\]';
|
|
117
114
|
/**
|
|
118
115
|
* Creates raw SQL query fragment that can be assigned to a property or part of a filter. This fragment is represented
|
|
119
116
|
* by `RawQueryFragment` class instance that can be serialized to a string, so it can be used both as an object value
|
|
@@ -151,19 +148,19 @@ exports.ALIAS_REPLACEMENT_RE = '\\[::alias::\\]';
|
|
|
151
148
|
* @Filter({ name: 'long', cond: () => ({ [raw('length(perex)')]: { $gt: 10000 } }) })
|
|
152
149
|
* ```
|
|
153
150
|
*/
|
|
154
|
-
function raw(sql, params) {
|
|
151
|
+
export function raw(sql, params) {
|
|
155
152
|
if (sql instanceof RawQueryFragment) {
|
|
156
153
|
return sql;
|
|
157
154
|
}
|
|
158
155
|
if (sql instanceof Function) {
|
|
159
|
-
sql = sql(
|
|
156
|
+
sql = sql(ALIAS_REPLACEMENT);
|
|
160
157
|
}
|
|
161
158
|
if (sql === '??' && Array.isArray(params)) {
|
|
162
159
|
return new RawQueryFragment(sql, params);
|
|
163
160
|
}
|
|
164
161
|
if (Array.isArray(sql)) {
|
|
165
162
|
// for composite FK we return just a simple string
|
|
166
|
-
return
|
|
163
|
+
return Utils.getPrimaryKeyHash(sql);
|
|
167
164
|
}
|
|
168
165
|
if (typeof params === 'object' && !Array.isArray(params)) {
|
|
169
166
|
const pairs = Object.entries(params);
|
|
@@ -191,14 +188,14 @@ function raw(sql, params) {
|
|
|
191
188
|
* await em.find(User, { [sql`(select 1 = 1)`]: [] });
|
|
192
189
|
* ```
|
|
193
190
|
*/
|
|
194
|
-
function sql(sql, ...values) {
|
|
191
|
+
export function sql(sql, ...values) {
|
|
195
192
|
return raw(sql.reduce((query, queryPart, i) => {
|
|
196
193
|
const valueExists = i < values.length;
|
|
197
194
|
const text = query + queryPart;
|
|
198
195
|
return valueExists ? text + '?' : text;
|
|
199
196
|
}, ''), values);
|
|
200
197
|
}
|
|
201
|
-
function createSqlFunction(func, key) {
|
|
198
|
+
export function createSqlFunction(func, key) {
|
|
202
199
|
if (typeof key === 'string') {
|
|
203
200
|
return raw(`${func}(${key})`);
|
|
204
201
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { EntityManager } from '../EntityManager';
|
|
2
|
-
import { type LoggingOptions } from '../logging/Logger';
|
|
1
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
2
|
+
import { type LoggingOptions } from '../logging/Logger.js';
|
|
3
3
|
/**
|
|
4
4
|
* Uses `AsyncLocalStorage` to create async context that holds the current EM fork.
|
|
5
5
|
*/
|
package/utils/RequestContext.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RequestContext = void 0;
|
|
4
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
5
2
|
/**
|
|
6
3
|
* Uses `AsyncLocalStorage` to create async context that holds the current EM fork.
|
|
7
4
|
*/
|
|
8
|
-
class RequestContext {
|
|
5
|
+
export class RequestContext {
|
|
9
6
|
map;
|
|
10
|
-
static storage = new
|
|
7
|
+
static storage = new AsyncLocalStorage();
|
|
11
8
|
static counter = 1;
|
|
12
9
|
id = RequestContext.counter++;
|
|
13
10
|
constructor(map) {
|
|
@@ -61,4 +58,3 @@ class RequestContext {
|
|
|
61
58
|
return new RequestContext(forks);
|
|
62
59
|
}
|
|
63
60
|
}
|
|
64
|
-
exports.RequestContext = RequestContext;
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.TransactionContext = void 0;
|
|
4
|
-
const node_async_hooks_1 = require("node:async_hooks");
|
|
5
|
-
class TransactionContext {
|
|
1
|
+
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
2
|
+
export class TransactionContext {
|
|
6
3
|
em;
|
|
7
|
-
static storage = new
|
|
4
|
+
static storage = new AsyncLocalStorage();
|
|
8
5
|
id;
|
|
9
6
|
constructor(em) {
|
|
10
7
|
this.em = em;
|
|
@@ -26,9 +23,8 @@ class TransactionContext {
|
|
|
26
23
|
/**
|
|
27
24
|
* Returns current EntityManager (if available).
|
|
28
25
|
*/
|
|
29
|
-
static getEntityManager(name =
|
|
26
|
+
static getEntityManager(name = 'default') {
|
|
30
27
|
const context = TransactionContext.currentTransactionContext();
|
|
31
28
|
return context?.em.name === name ? context.em : undefined;
|
|
32
29
|
}
|
|
33
30
|
}
|
|
34
|
-
exports.TransactionContext = TransactionContext;
|
package/utils/Utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { type GlobbyOptions } from 'globby';
|
|
2
|
-
import type { Dictionary, EntityData, EntityDictionary, EntityKey, EntityMetadata, EntityName, EntityProperty, IMetadataStorage, Primary } from '../typings';
|
|
3
|
-
import type { Collection } from '../entity/Collection';
|
|
4
|
-
import type { Platform } from '../platforms';
|
|
5
|
-
import type { ScalarReference } from '../entity/Reference';
|
|
2
|
+
import type { Dictionary, EntityData, EntityDictionary, EntityKey, EntityMetadata, EntityName, EntityProperty, IMetadataStorage, Primary } from '../typings.js';
|
|
3
|
+
import type { Collection } from '../entity/Collection.js';
|
|
4
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
5
|
+
import type { ScalarReference } from '../entity/Reference.js';
|
|
6
6
|
export declare const ObjectBindingPattern: unique symbol;
|
|
7
7
|
export declare function compareObjects(a: any, b: any): boolean;
|
|
8
8
|
export declare function compareArrays(a: any[] | string, b: any[] | string): boolean;
|
|
@@ -153,7 +153,9 @@ export declare class Utils {
|
|
|
153
153
|
/**
|
|
154
154
|
* Checks whether the argument is ObjectId instance
|
|
155
155
|
*/
|
|
156
|
-
static isObjectID(key: any):
|
|
156
|
+
static isObjectID(key: any): key is {
|
|
157
|
+
toHexString: () => string;
|
|
158
|
+
};
|
|
157
159
|
/**
|
|
158
160
|
* Checks whether the argument is empty (array without items, object without keys or falsy value).
|
|
159
161
|
*/
|
|
@@ -164,9 +166,9 @@ export declare class Utils {
|
|
|
164
166
|
static className<T>(classOrName: EntityName<T>): string;
|
|
165
167
|
static extractChildElements(items: string[], prefix: string, allSymbol?: string): string[];
|
|
166
168
|
/**
|
|
167
|
-
* Tries to detect
|
|
169
|
+
* Tries to detect TypeScript support.
|
|
168
170
|
*/
|
|
169
|
-
static
|
|
171
|
+
static detectTypeScriptSupport(): boolean;
|
|
170
172
|
/**
|
|
171
173
|
* Uses some dark magic to get source path to caller where decorator is used.
|
|
172
174
|
* Analyses stack trace of error created inside the function call.
|
|
@@ -230,6 +232,9 @@ export declare class Utils {
|
|
|
230
232
|
static requireFrom<T extends Dictionary>(id: string, from?: string): T;
|
|
231
233
|
static dynamicImport<T = any>(id: string): Promise<T>;
|
|
232
234
|
static setDynamicImportProvider(provider: (id: string) => Promise<unknown>): void;
|
|
235
|
+
static ensureDir(path: string): void;
|
|
236
|
+
static pathExistsSync(path: string): boolean;
|
|
237
|
+
static readJSONSync(path: string): Dictionary;
|
|
233
238
|
static getORMVersion(): string;
|
|
234
239
|
static createFunction(context: Map<string, any>, code: string): any;
|
|
235
240
|
static callCompiledFunction<T extends unknown[], R>(fn: (...args: T) => R, ...args: T): R;
|
|
@@ -245,6 +250,10 @@ export declare class Utils {
|
|
|
245
250
|
from?: string;
|
|
246
251
|
allowError?: string;
|
|
247
252
|
}): T | undefined;
|
|
253
|
+
static tryImport<T extends Dictionary = any>({ module, warning }: {
|
|
254
|
+
module: string;
|
|
255
|
+
warning: string;
|
|
256
|
+
}): Promise<T | undefined>;
|
|
248
257
|
static stripRelativePath(str: string): string;
|
|
249
258
|
/**
|
|
250
259
|
* simple process.argv parser, supports only properties with long names, prefixed with `--`
|
|
@@ -254,10 +263,5 @@ export declare class Utils {
|
|
|
254
263
|
static keys<T extends object>(obj: T): (keyof T)[];
|
|
255
264
|
static values<T extends object>(obj: T): T[keyof T][];
|
|
256
265
|
static entries<T extends object>(obj: T): [keyof T, T[keyof T]][];
|
|
257
|
-
static isRawSql<T = {
|
|
258
|
-
sql: string;
|
|
259
|
-
params: unknown[];
|
|
260
|
-
use: () => void;
|
|
261
|
-
}>(value: unknown): value is T;
|
|
262
266
|
static primaryKeyToObject<T>(meta: EntityMetadata<T>, primaryKey: Primary<T> | T, visible?: (keyof T)[]): T;
|
|
263
267
|
}
|