@mikro-orm/core 7.0.2-dev.9 → 7.0.2
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 +883 -579
- package/EntityManager.js +1897 -1865
- package/MikroORM.d.ts +103 -72
- package/MikroORM.js +178 -177
- package/README.md +128 -294
- package/cache/CacheAdapter.d.ts +38 -36
- package/cache/FileCacheAdapter.d.ts +30 -24
- package/cache/FileCacheAdapter.js +80 -78
- package/cache/GeneratedCacheAdapter.d.ts +19 -20
- package/cache/GeneratedCacheAdapter.js +31 -30
- package/cache/MemoryCacheAdapter.d.ts +19 -20
- package/cache/MemoryCacheAdapter.js +36 -36
- package/cache/NullCacheAdapter.d.ts +17 -16
- package/cache/NullCacheAdapter.js +25 -24
- package/connections/Connection.d.ts +99 -75
- package/connections/Connection.js +166 -160
- package/drivers/DatabaseDriver.d.ts +187 -69
- package/drivers/DatabaseDriver.js +451 -432
- package/drivers/IDatabaseDriver.d.ts +464 -281
- package/drivers/IDatabaseDriver.js +1 -0
- package/entity/BaseEntity.d.ts +121 -73
- package/entity/BaseEntity.js +44 -33
- package/entity/Collection.d.ts +216 -157
- package/entity/Collection.js +728 -707
- package/entity/EntityAssigner.d.ts +90 -76
- package/entity/EntityAssigner.js +232 -229
- package/entity/EntityFactory.d.ts +68 -40
- package/entity/EntityFactory.js +427 -366
- package/entity/EntityHelper.d.ts +34 -22
- package/entity/EntityHelper.js +280 -267
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +105 -56
- package/entity/EntityLoader.js +754 -722
- package/entity/EntityRepository.d.ts +317 -200
- package/entity/EntityRepository.js +214 -212
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +130 -66
- package/entity/Reference.js +280 -260
- package/entity/WrappedEntity.d.ts +116 -53
- package/entity/WrappedEntity.js +169 -147
- package/entity/defineEntity.d.ts +1290 -614
- package/entity/defineEntity.js +521 -511
- package/entity/utils.d.ts +13 -3
- package/entity/utils.js +71 -73
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +275 -138
- package/enums.js +268 -137
- package/errors.d.ts +120 -72
- package/errors.js +356 -253
- package/events/EventManager.d.ts +27 -10
- package/events/EventManager.js +80 -73
- package/events/EventSubscriber.d.ts +33 -29
- package/events/TransactionEventBroadcaster.d.ts +16 -7
- package/events/TransactionEventBroadcaster.js +15 -13
- package/exceptions.d.ts +23 -40
- package/exceptions.js +35 -52
- package/hydration/Hydrator.d.ts +43 -16
- package/hydration/Hydrator.js +44 -42
- package/hydration/ObjectHydrator.d.ts +51 -17
- package/hydration/ObjectHydrator.js +480 -416
- package/index.d.ts +116 -2
- package/index.js +10 -1
- package/logging/DefaultLogger.d.ts +35 -30
- package/logging/DefaultLogger.js +87 -84
- package/logging/Logger.d.ts +45 -40
- package/logging/SimpleLogger.d.ts +13 -11
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +11 -10
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +214 -108
- package/metadata/EntitySchema.js +398 -379
- package/metadata/MetadataDiscovery.d.ts +115 -111
- package/metadata/MetadataDiscovery.js +1948 -1857
- package/metadata/MetadataProvider.d.ts +25 -14
- package/metadata/MetadataProvider.js +83 -77
- package/metadata/MetadataStorage.d.ts +39 -19
- package/metadata/MetadataStorage.js +119 -106
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +381 -338
- package/metadata/discover-entities.d.ts +5 -2
- package/metadata/discover-entities.js +27 -27
- package/metadata/types.d.ts +615 -531
- package/naming-strategy/AbstractNamingStrategy.d.ts +55 -39
- package/naming-strategy/AbstractNamingStrategy.js +91 -85
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +7 -6
- package/naming-strategy/MongoNamingStrategy.js +19 -18
- package/naming-strategy/NamingStrategy.d.ts +109 -99
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +8 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +22 -21
- package/not-supported.js +7 -4
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +2 -1
- package/platforms/ExceptionConverter.js +5 -4
- package/platforms/Platform.d.ts +310 -236
- package/platforms/Platform.js +661 -573
- package/serialization/EntitySerializer.d.ts +49 -25
- package/serialization/EntitySerializer.js +224 -216
- package/serialization/EntityTransformer.d.ts +11 -5
- package/serialization/EntityTransformer.js +220 -216
- package/serialization/SerializationContext.d.ts +27 -18
- package/serialization/SerializationContext.js +105 -100
- package/types/ArrayType.d.ts +9 -8
- package/types/ArrayType.js +34 -33
- package/types/BigIntType.d.ts +17 -10
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +4 -3
- package/types/BlobType.js +14 -13
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +13 -12
- package/types/CharacterType.d.ts +3 -2
- package/types/CharacterType.js +7 -6
- package/types/DateTimeType.d.ts +6 -5
- package/types/DateTimeType.js +16 -15
- package/types/DateType.d.ts +6 -5
- package/types/DateType.js +16 -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 +6 -5
- package/types/EnumArrayType.js +25 -24
- package/types/EnumType.d.ts +4 -3
- package/types/EnumType.js +12 -11
- package/types/FloatType.d.ts +4 -3
- package/types/FloatType.js +10 -9
- package/types/IntegerType.d.ts +4 -3
- package/types/IntegerType.js +10 -9
- package/types/IntervalType.d.ts +5 -4
- package/types/IntervalType.js +13 -12
- package/types/JsonType.d.ts +9 -8
- package/types/JsonType.js +33 -32
- package/types/MediumIntType.d.ts +2 -1
- package/types/MediumIntType.js +4 -3
- package/types/SmallIntType.d.ts +4 -3
- package/types/SmallIntType.js +10 -9
- package/types/StringType.d.ts +5 -4
- package/types/StringType.js +13 -12
- package/types/TextType.d.ts +4 -3
- package/types/TextType.js +10 -9
- package/types/TimeType.d.ts +6 -5
- package/types/TimeType.js +18 -17
- package/types/TinyIntType.d.ts +4 -3
- package/types/TinyIntType.js +11 -10
- package/types/Type.d.ts +88 -73
- package/types/Type.js +85 -74
- package/types/Uint8ArrayType.d.ts +5 -4
- package/types/Uint8ArrayType.js +22 -21
- package/types/UnknownType.d.ts +5 -4
- package/types/UnknownType.js +13 -12
- package/types/UuidType.d.ts +6 -5
- package/types/UuidType.js +20 -19
- package/types/index.d.ts +77 -49
- package/types/index.js +64 -26
- package/typings.d.ts +1388 -729
- package/typings.js +255 -231
- package/unit-of-work/ChangeSet.d.ts +28 -24
- package/unit-of-work/ChangeSet.js +58 -54
- package/unit-of-work/ChangeSetComputer.d.ts +13 -11
- package/unit-of-work/ChangeSetComputer.js +180 -159
- package/unit-of-work/ChangeSetPersister.d.ts +64 -41
- package/unit-of-work/ChangeSetPersister.js +443 -418
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +89 -88
- package/unit-of-work/IdentityMap.d.ts +32 -25
- package/unit-of-work/IdentityMap.js +106 -99
- package/unit-of-work/UnitOfWork.d.ts +182 -127
- package/unit-of-work/UnitOfWork.js +1201 -1169
- package/utils/AbstractMigrator.d.ts +111 -91
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +43 -34
- package/utils/AbstractSchemaGenerator.js +121 -122
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +34 -35
- package/utils/Configuration.d.ts +853 -801
- package/utils/Configuration.js +360 -337
- package/utils/Cursor.d.ts +40 -22
- package/utils/Cursor.js +135 -127
- package/utils/DataloaderUtils.d.ts +58 -43
- package/utils/DataloaderUtils.js +203 -198
- package/utils/EntityComparator.d.ts +99 -80
- package/utils/EntityComparator.js +825 -727
- package/utils/NullHighlighter.d.ts +2 -1
- package/utils/NullHighlighter.js +4 -3
- package/utils/QueryHelper.d.ts +79 -51
- package/utils/QueryHelper.js +372 -361
- package/utils/RawQueryFragment.d.ts +54 -28
- package/utils/RawQueryFragment.js +110 -99
- package/utils/RequestContext.d.ts +33 -32
- package/utils/RequestContext.js +52 -53
- package/utils/TransactionContext.d.ts +17 -16
- package/utils/TransactionContext.js +28 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +199 -197
- package/utils/Utils.d.ts +210 -145
- package/utils/Utils.js +820 -813
- package/utils/clone.js +104 -113
- package/utils/env-vars.js +90 -88
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +180 -181
- package/utils/upsert-utils.d.ts +20 -5
- package/utils/upsert-utils.js +114 -116
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { EntityManagerType
|
|
1
|
+
import { EntityManagerType } from './IDatabaseDriver.js';
|
|
2
2
|
import { Utils } from '../utils/Utils.js';
|
|
3
3
|
import { Cursor } from '../utils/Cursor.js';
|
|
4
4
|
import { EntityComparator } from '../utils/EntityComparator.js';
|
|
@@ -11,464 +11,483 @@ import { helper } from '../entity/wrap.js';
|
|
|
11
11
|
import { PolymorphicRef } from '../entity/PolymorphicRef.js';
|
|
12
12
|
import { JsonType } from '../types/JsonType.js';
|
|
13
13
|
import { MikroORM } from '../MikroORM.js';
|
|
14
|
+
/** Abstract base class for all database drivers, implementing common driver logic. */
|
|
14
15
|
export class DatabaseDriver {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
/* v8 ignore next */
|
|
58
|
-
{
|
|
59
|
-
const pk = coll.property.targetMeta.primaryKeys[0];
|
|
60
|
-
const data = { [coll.property.name]: coll.getIdentifiers(pk) };
|
|
61
|
-
await this.nativeUpdate(coll.owner.constructor, helper(coll.owner).getPrimaryKey(), data, options);
|
|
62
|
-
}
|
|
16
|
+
config;
|
|
17
|
+
dependencies;
|
|
18
|
+
[EntityManagerType];
|
|
19
|
+
connection;
|
|
20
|
+
replicas = [];
|
|
21
|
+
platform;
|
|
22
|
+
comparator;
|
|
23
|
+
metadata;
|
|
24
|
+
constructor(config, dependencies) {
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.dependencies = dependencies;
|
|
27
|
+
}
|
|
28
|
+
async nativeUpdateMany(entityName, where, data, options) {
|
|
29
|
+
throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
|
|
30
|
+
}
|
|
31
|
+
/** Creates a new EntityManager instance bound to this driver. */
|
|
32
|
+
createEntityManager(useContext) {
|
|
33
|
+
const EntityManagerClass = this.config.get('entityManager', EntityManager);
|
|
34
|
+
return new EntityManagerClass(this.config, this, this.metadata, useContext);
|
|
35
|
+
}
|
|
36
|
+
/* v8 ignore next */
|
|
37
|
+
async findVirtual(entityName, where, options) {
|
|
38
|
+
throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
|
|
39
|
+
}
|
|
40
|
+
/* v8 ignore next */
|
|
41
|
+
async countVirtual(entityName, where, options) {
|
|
42
|
+
throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
|
|
43
|
+
}
|
|
44
|
+
async aggregate(entityName, pipeline) {
|
|
45
|
+
throw new Error(`Aggregations are not supported by ${this.constructor.name} driver`);
|
|
46
|
+
}
|
|
47
|
+
async loadFromPivotTable(prop, owners, where, orderBy, ctx, options, pivotJoin) {
|
|
48
|
+
throw new Error(`${this.constructor.name} does not use pivot tables`);
|
|
49
|
+
}
|
|
50
|
+
async syncCollections(collections, options) {
|
|
51
|
+
for (const coll of collections) {
|
|
52
|
+
/* v8 ignore else */
|
|
53
|
+
if (!coll.property.owner) {
|
|
54
|
+
if (coll.getSnapshot() === undefined) {
|
|
55
|
+
throw ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
|
|
63
56
|
}
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
/* v8 ignore next */
|
|
60
|
+
{
|
|
61
|
+
const pk = coll.property.targetMeta.primaryKeys[0];
|
|
62
|
+
const data = { [coll.property.name]: coll.getIdentifiers(pk) };
|
|
63
|
+
await this.nativeUpdate(coll.owner.constructor, helper(coll.owner).getPrimaryKey(), data, options);
|
|
64
|
+
}
|
|
64
65
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
71
|
-
async connect(options) {
|
|
72
|
-
await this.connection.connect(options);
|
|
73
|
-
await Promise.all(this.replicas.map(replica => replica.connect()));
|
|
74
|
-
return this.connection;
|
|
75
|
-
}
|
|
76
|
-
async reconnect(options) {
|
|
77
|
-
await this.close(true);
|
|
78
|
-
await this.connect(options);
|
|
79
|
-
return this.connection;
|
|
66
|
+
}
|
|
67
|
+
/** Maps raw database result to entity data, converting column names to property names. */
|
|
68
|
+
mapResult(result, meta, populate = []) {
|
|
69
|
+
if (!result || !meta) {
|
|
70
|
+
return result ?? null;
|
|
80
71
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
72
|
+
return this.comparator.mapResult(meta, result);
|
|
73
|
+
}
|
|
74
|
+
/** Opens the primary connection and all read replicas. */
|
|
75
|
+
async connect(options) {
|
|
76
|
+
await this.connection.connect(options);
|
|
77
|
+
await Promise.all(this.replicas.map(replica => replica.connect()));
|
|
78
|
+
return this.connection;
|
|
79
|
+
}
|
|
80
|
+
/** Closes all connections and re-establishes them. */
|
|
81
|
+
async reconnect(options) {
|
|
82
|
+
await this.close(true);
|
|
83
|
+
await this.connect(options);
|
|
84
|
+
return this.connection;
|
|
85
|
+
}
|
|
86
|
+
/** Returns the write connection or a random read replica. */
|
|
87
|
+
getConnection(type = 'write') {
|
|
88
|
+
if (type === 'write' || this.replicas.length === 0) {
|
|
89
|
+
return this.connection;
|
|
87
90
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
+
const rand = Utils.randomInt(0, this.replicas.length - 1);
|
|
92
|
+
return this.replicas[rand];
|
|
93
|
+
}
|
|
94
|
+
/** Closes the primary connection and all read replicas. */
|
|
95
|
+
async close(force) {
|
|
96
|
+
await Promise.all(this.replicas.map(replica => replica.close(force)));
|
|
97
|
+
await this.connection.close(force);
|
|
98
|
+
}
|
|
99
|
+
/** Returns the database platform abstraction for this driver. */
|
|
100
|
+
getPlatform() {
|
|
101
|
+
return this.platform;
|
|
102
|
+
}
|
|
103
|
+
/** Sets the metadata storage and initializes the comparator for all connections. */
|
|
104
|
+
setMetadata(metadata) {
|
|
105
|
+
this.metadata = metadata;
|
|
106
|
+
this.comparator = new EntityComparator(this.metadata, this.platform);
|
|
107
|
+
this.connection.setMetadata(metadata);
|
|
108
|
+
this.connection.setPlatform(this.platform);
|
|
109
|
+
this.replicas.forEach(replica => {
|
|
110
|
+
replica.setMetadata(metadata);
|
|
111
|
+
replica.setPlatform(this.platform);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/** Returns the metadata storage used by this driver. */
|
|
115
|
+
getMetadata() {
|
|
116
|
+
return this.metadata;
|
|
117
|
+
}
|
|
118
|
+
/** Returns the names of native database dependencies required by this driver. */
|
|
119
|
+
getDependencies() {
|
|
120
|
+
return this.dependencies;
|
|
121
|
+
}
|
|
122
|
+
isPopulated(meta, prop, hint, name) {
|
|
123
|
+
if (hint.field === prop.name || hint.field === name || hint.all) {
|
|
124
|
+
return true;
|
|
91
125
|
}
|
|
92
|
-
|
|
93
|
-
|
|
126
|
+
if (prop.embedded && hint.children && meta.properties[prop.embedded[0]].name === hint.field) {
|
|
127
|
+
return hint.children.some(c => this.isPopulated(meta, prop, c, prop.embedded[1]));
|
|
94
128
|
}
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
processCursorOptions(meta, options, orderBy) {
|
|
132
|
+
const { first, last, before, after, overfetch } = options;
|
|
133
|
+
const limit = first ?? last;
|
|
134
|
+
const isLast = !first && !!last;
|
|
135
|
+
const definition = Cursor.getDefinition(meta, orderBy);
|
|
136
|
+
const $and = [];
|
|
137
|
+
// allow POJO as well, we care only about the correct key being present
|
|
138
|
+
const isCursor = (val, key) => {
|
|
139
|
+
return !!val && typeof val === 'object' && key in val;
|
|
140
|
+
};
|
|
141
|
+
const createCursor = (val, key, inverse = false) => {
|
|
142
|
+
let def = isCursor(val, key) ? val[key] : val;
|
|
143
|
+
if (Utils.isPlainObject(def)) {
|
|
144
|
+
def = Cursor.for(meta, def, orderBy);
|
|
145
|
+
}
|
|
146
|
+
/* v8 ignore next */
|
|
147
|
+
const offsets = def ? Cursor.decode(def) : [];
|
|
148
|
+
if (definition.length === offsets.length) {
|
|
149
|
+
return this.createCursorCondition(definition, offsets, inverse, meta);
|
|
150
|
+
}
|
|
151
|
+
/* v8 ignore next */
|
|
152
|
+
return {};
|
|
153
|
+
};
|
|
154
|
+
if (after) {
|
|
155
|
+
$and.push(createCursor(after, 'endCursor'));
|
|
104
156
|
}
|
|
105
|
-
|
|
106
|
-
|
|
157
|
+
if (before) {
|
|
158
|
+
$and.push(createCursor(before, 'startCursor', true));
|
|
107
159
|
}
|
|
108
|
-
|
|
109
|
-
|
|
160
|
+
if (limit != null) {
|
|
161
|
+
options.limit = limit + (overfetch ? 1 : 0);
|
|
110
162
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
163
|
+
const createOrderBy = (prop, direction) => {
|
|
164
|
+
if (Utils.isPlainObject(direction)) {
|
|
165
|
+
const value = Utils.getObjectQueryKeys(direction).reduce((o, key) => {
|
|
166
|
+
Object.assign(o, createOrderBy(key, direction[key]));
|
|
167
|
+
return o;
|
|
168
|
+
}, {});
|
|
169
|
+
return { [prop]: value };
|
|
170
|
+
}
|
|
171
|
+
const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
|
|
172
|
+
const dir = Utils.xor(desc, isLast) ? 'desc' : 'asc';
|
|
173
|
+
return { [prop]: dir };
|
|
174
|
+
};
|
|
175
|
+
return {
|
|
176
|
+
orderBy: definition.map(([prop, direction]) => createOrderBy(prop, direction)),
|
|
177
|
+
where: $and.length > 1 ? { $and } : { ...$and[0] },
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
createCursorCondition(definition, offsets, inverse, meta) {
|
|
181
|
+
const createCondition = (prop, direction, offset, eq = false, path = prop) => {
|
|
182
|
+
if (Utils.isPlainObject(direction)) {
|
|
183
|
+
if (offset === undefined) {
|
|
184
|
+
throw CursorError.missingValue(meta.className, path);
|
|
114
185
|
}
|
|
115
|
-
|
|
116
|
-
|
|
186
|
+
const value = Utils.keys(direction).reduce((o, key) => {
|
|
187
|
+
Object.assign(o, createCondition(key, direction[key], offset?.[key], eq, `${path}.${key}`));
|
|
188
|
+
return o;
|
|
189
|
+
}, {});
|
|
190
|
+
return { [prop]: value };
|
|
191
|
+
}
|
|
192
|
+
const isDesc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
|
|
193
|
+
const dirStr = direction.toString().toLowerCase();
|
|
194
|
+
let nullsFirst;
|
|
195
|
+
if (dirStr.includes('nulls first')) {
|
|
196
|
+
nullsFirst = true;
|
|
197
|
+
} else if (dirStr.includes('nulls last')) {
|
|
198
|
+
nullsFirst = false;
|
|
199
|
+
} else {
|
|
200
|
+
// Default: NULLS LAST for ASC, NULLS FIRST for DESC (matches most databases)
|
|
201
|
+
nullsFirst = isDesc;
|
|
202
|
+
}
|
|
203
|
+
const operator = Utils.xor(isDesc, inverse) ? '$lt' : '$gt';
|
|
204
|
+
// For leaf-level properties, undefined means missing value
|
|
205
|
+
if (offset === undefined) {
|
|
206
|
+
throw CursorError.missingValue(meta.className, path);
|
|
207
|
+
}
|
|
208
|
+
// Handle null offset (intentional null cursor value)
|
|
209
|
+
if (offset === null) {
|
|
210
|
+
if (eq) {
|
|
211
|
+
// Equal to null
|
|
212
|
+
return { [prop]: null };
|
|
117
213
|
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
const isLast = !first && !!last;
|
|
124
|
-
const definition = Cursor.getDefinition(meta, orderBy);
|
|
125
|
-
const $and = [];
|
|
126
|
-
// allow POJO as well, we care only about the correct key being present
|
|
127
|
-
const isCursor = (val, key) => {
|
|
128
|
-
return !!val && typeof val === 'object' && key in val;
|
|
129
|
-
};
|
|
130
|
-
const createCursor = (val, key, inverse = false) => {
|
|
131
|
-
let def = isCursor(val, key) ? val[key] : val;
|
|
132
|
-
if (Utils.isPlainObject(def)) {
|
|
133
|
-
def = Cursor.for(meta, def, orderBy);
|
|
134
|
-
}
|
|
135
|
-
/* v8 ignore next */
|
|
136
|
-
const offsets = def ? Cursor.decode(def) : [];
|
|
137
|
-
if (definition.length === offsets.length) {
|
|
138
|
-
return this.createCursorCondition(definition, offsets, inverse, meta);
|
|
139
|
-
}
|
|
140
|
-
/* v8 ignore next */
|
|
141
|
-
return {};
|
|
142
|
-
};
|
|
143
|
-
if (after) {
|
|
144
|
-
$and.push(createCursor(after, 'endCursor'));
|
|
214
|
+
// Strict comparison with null cursor value
|
|
215
|
+
// hasItemsAfterNull: forward + nullsFirst, or backward + nullsLast
|
|
216
|
+
const hasItemsAfterNull = Utils.xor(nullsFirst, inverse);
|
|
217
|
+
if (hasItemsAfterNull) {
|
|
218
|
+
return { [prop]: { $ne: null } };
|
|
145
219
|
}
|
|
146
|
-
|
|
147
|
-
|
|
220
|
+
// No items after null in this direction, return impossible condition
|
|
221
|
+
return { [prop]: [] };
|
|
222
|
+
}
|
|
223
|
+
// Non-null offset
|
|
224
|
+
return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
|
|
225
|
+
};
|
|
226
|
+
const [order, ...otherOrders] = definition;
|
|
227
|
+
const [offset, ...otherOffsets] = offsets;
|
|
228
|
+
const [prop, direction] = order;
|
|
229
|
+
if (!otherOrders.length) {
|
|
230
|
+
return createCondition(prop, direction, offset);
|
|
231
|
+
}
|
|
232
|
+
return {
|
|
233
|
+
...createCondition(prop, direction, offset, true),
|
|
234
|
+
$or: [
|
|
235
|
+
createCondition(prop, direction, offset),
|
|
236
|
+
this.createCursorCondition(otherOrders, otherOffsets, inverse, meta),
|
|
237
|
+
],
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
/** @internal */
|
|
241
|
+
mapDataToFieldNames(data, stringifyJsonArrays, properties, convertCustomTypes, object) {
|
|
242
|
+
if (!properties || data == null) {
|
|
243
|
+
return data;
|
|
244
|
+
}
|
|
245
|
+
data = Object.assign({}, data); // copy first
|
|
246
|
+
Object.keys(data).forEach(k => {
|
|
247
|
+
const prop = properties[k];
|
|
248
|
+
if (!prop) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
if (prop.embeddedProps && !prop.object && !object) {
|
|
252
|
+
const copy = data[k];
|
|
253
|
+
delete data[k];
|
|
254
|
+
Object.assign(
|
|
255
|
+
data,
|
|
256
|
+
this.mapDataToFieldNames(copy, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes),
|
|
257
|
+
);
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
260
|
+
if (prop.embeddedProps && (object || prop.object)) {
|
|
261
|
+
const copy = data[k];
|
|
262
|
+
delete data[k];
|
|
263
|
+
if (prop.array) {
|
|
264
|
+
data[prop.fieldNames[0]] = copy?.map(item =>
|
|
265
|
+
this.mapDataToFieldNames(item, stringifyJsonArrays, prop.embeddedProps, convertCustomTypes, true),
|
|
266
|
+
);
|
|
267
|
+
} else {
|
|
268
|
+
data[prop.fieldNames[0]] = this.mapDataToFieldNames(
|
|
269
|
+
copy,
|
|
270
|
+
stringifyJsonArrays,
|
|
271
|
+
prop.embeddedProps,
|
|
272
|
+
convertCustomTypes,
|
|
273
|
+
true,
|
|
274
|
+
);
|
|
148
275
|
}
|
|
149
|
-
if (
|
|
150
|
-
|
|
276
|
+
if (stringifyJsonArrays && prop.array && !object) {
|
|
277
|
+
data[prop.fieldNames[0]] = this.platform.convertJsonToDatabaseValue(data[prop.fieldNames[0]]);
|
|
151
278
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return o;
|
|
178
|
-
}, {});
|
|
179
|
-
return { [prop]: value };
|
|
180
|
-
}
|
|
181
|
-
const isDesc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
|
|
182
|
-
const dirStr = direction.toString().toLowerCase();
|
|
183
|
-
let nullsFirst;
|
|
184
|
-
if (dirStr.includes('nulls first')) {
|
|
185
|
-
nullsFirst = true;
|
|
186
|
-
}
|
|
187
|
-
else if (dirStr.includes('nulls last')) {
|
|
188
|
-
nullsFirst = false;
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
// Default: NULLS LAST for ASC, NULLS FIRST for DESC (matches most databases)
|
|
192
|
-
nullsFirst = isDesc;
|
|
193
|
-
}
|
|
194
|
-
const operator = Utils.xor(isDesc, inverse) ? '$lt' : '$gt';
|
|
195
|
-
// For leaf-level properties, undefined means missing value
|
|
196
|
-
if (offset === undefined) {
|
|
197
|
-
throw CursorError.missingValue(meta.className, path);
|
|
198
|
-
}
|
|
199
|
-
// Handle null offset (intentional null cursor value)
|
|
200
|
-
if (offset === null) {
|
|
201
|
-
if (eq) {
|
|
202
|
-
// Equal to null
|
|
203
|
-
return { [prop]: null };
|
|
204
|
-
}
|
|
205
|
-
// Strict comparison with null cursor value
|
|
206
|
-
// hasItemsAfterNull: forward + nullsFirst, or backward + nullsLast
|
|
207
|
-
const hasItemsAfterNull = Utils.xor(nullsFirst, inverse);
|
|
208
|
-
if (hasItemsAfterNull) {
|
|
209
|
-
return { [prop]: { $ne: null } };
|
|
210
|
-
}
|
|
211
|
-
// No items after null in this direction, return impossible condition
|
|
212
|
-
return { [prop]: [] };
|
|
213
|
-
}
|
|
214
|
-
// Non-null offset
|
|
215
|
-
return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
|
|
216
|
-
};
|
|
217
|
-
const [order, ...otherOrders] = definition;
|
|
218
|
-
const [offset, ...otherOffsets] = offsets;
|
|
219
|
-
const [prop, direction] = order;
|
|
220
|
-
if (!otherOrders.length) {
|
|
221
|
-
return createCondition(prop, direction, offset);
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
// Handle polymorphic relations - convert tuple or PolymorphicRef to separate columns
|
|
282
|
+
// Tuple format: ['discriminator', id] or ['discriminator', id1, id2] for composite keys
|
|
283
|
+
// Must be checked BEFORE joinColumns array handling since polymorphic uses fieldNames (includes discriminator)
|
|
284
|
+
if (prop.polymorphic && prop.fieldNames && prop.fieldNames.length >= 2) {
|
|
285
|
+
let discriminator;
|
|
286
|
+
let ids;
|
|
287
|
+
if (Array.isArray(data[k]) && typeof data[k][0] === 'string' && prop.discriminatorMap?.[data[k][0]]) {
|
|
288
|
+
// Tuple format: ['discriminator', ...ids]
|
|
289
|
+
const [disc, ...rest] = data[k];
|
|
290
|
+
discriminator = disc;
|
|
291
|
+
ids = rest;
|
|
292
|
+
} else if (data[k] instanceof PolymorphicRef) {
|
|
293
|
+
// PolymorphicRef wrapper (internal use)
|
|
294
|
+
discriminator = data[k].discriminator;
|
|
295
|
+
const polyId = data[k].id;
|
|
296
|
+
// Handle object-style composite key IDs like { tenantId: 1, orgId: 100 }
|
|
297
|
+
if (polyId && typeof polyId === 'object' && !Array.isArray(polyId)) {
|
|
298
|
+
const targetEntity = prop.discriminatorMap?.[discriminator];
|
|
299
|
+
const targetMeta = this.metadata.get(targetEntity);
|
|
300
|
+
ids = targetMeta.primaryKeys.map(pk => polyId[pk]);
|
|
301
|
+
} else {
|
|
302
|
+
ids = Utils.asArray(polyId);
|
|
303
|
+
}
|
|
222
304
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
mapDataToFieldNames(data, stringifyJsonArrays, properties, convertCustomTypes, object) {
|
|
233
|
-
if (!properties || data == null) {
|
|
234
|
-
return data;
|
|
305
|
+
if (discriminator) {
|
|
306
|
+
const discriminatorColumn = prop.fieldNames[0];
|
|
307
|
+
const idColumns = prop.fieldNames.slice(1);
|
|
308
|
+
delete data[k];
|
|
309
|
+
data[discriminatorColumn] = discriminator;
|
|
310
|
+
idColumns.forEach((col, idx) => {
|
|
311
|
+
data[col] = ids[idx];
|
|
312
|
+
});
|
|
313
|
+
return;
|
|
235
314
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
data[prop.fieldNames[0]] = this.platform.convertJsonToDatabaseValue(data[prop.fieldNames[0]]);
|
|
259
|
-
}
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
// Handle polymorphic relations - convert tuple or PolymorphicRef to separate columns
|
|
263
|
-
// Tuple format: ['discriminator', id] or ['discriminator', id1, id2] for composite keys
|
|
264
|
-
// Must be checked BEFORE joinColumns array handling since polymorphic uses fieldNames (includes discriminator)
|
|
265
|
-
if (prop.polymorphic && prop.fieldNames && prop.fieldNames.length >= 2) {
|
|
266
|
-
let discriminator;
|
|
267
|
-
let ids;
|
|
268
|
-
if (Array.isArray(data[k]) && typeof data[k][0] === 'string' && prop.discriminatorMap?.[data[k][0]]) {
|
|
269
|
-
// Tuple format: ['discriminator', ...ids]
|
|
270
|
-
const [disc, ...rest] = data[k];
|
|
271
|
-
discriminator = disc;
|
|
272
|
-
ids = rest;
|
|
273
|
-
}
|
|
274
|
-
else if (data[k] instanceof PolymorphicRef) {
|
|
275
|
-
// PolymorphicRef wrapper (internal use)
|
|
276
|
-
discriminator = data[k].discriminator;
|
|
277
|
-
const polyId = data[k].id;
|
|
278
|
-
// Handle object-style composite key IDs like { tenantId: 1, orgId: 100 }
|
|
279
|
-
if (polyId && typeof polyId === 'object' && !Array.isArray(polyId)) {
|
|
280
|
-
const targetEntity = prop.discriminatorMap?.[discriminator];
|
|
281
|
-
const targetMeta = this.metadata.get(targetEntity);
|
|
282
|
-
ids = targetMeta.primaryKeys.map(pk => polyId[pk]);
|
|
283
|
-
}
|
|
284
|
-
else {
|
|
285
|
-
ids = Utils.asArray(polyId);
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
if (discriminator) {
|
|
289
|
-
const discriminatorColumn = prop.fieldNames[0];
|
|
290
|
-
const idColumns = prop.fieldNames.slice(1);
|
|
291
|
-
delete data[k];
|
|
292
|
-
data[discriminatorColumn] = discriminator;
|
|
293
|
-
idColumns.forEach((col, idx) => {
|
|
294
|
-
data[col] = ids[idx];
|
|
295
|
-
});
|
|
296
|
-
return;
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
if (prop.joinColumns && Array.isArray(data[k])) {
|
|
300
|
-
const copy = Utils.flatten(data[k]);
|
|
301
|
-
delete data[k];
|
|
302
|
-
prop.joinColumns.forEach((joinColumn, idx) => (data[joinColumn] = copy[idx]));
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
if (prop.joinColumns?.length > 1 && data[k] == null) {
|
|
306
|
-
delete data[k];
|
|
307
|
-
prop.ownColumns.forEach(joinColumn => (data[joinColumn] = null));
|
|
308
|
-
return;
|
|
309
|
-
}
|
|
310
|
-
if (prop.customType &&
|
|
311
|
-
convertCustomTypes &&
|
|
312
|
-
!(prop.customType instanceof JsonType && object) &&
|
|
313
|
-
!isRaw(data[k])) {
|
|
314
|
-
data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, {
|
|
315
|
-
fromQuery: true,
|
|
316
|
-
key: k,
|
|
317
|
-
mode: 'query-data',
|
|
318
|
-
});
|
|
319
|
-
}
|
|
320
|
-
if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
|
|
321
|
-
const quoted = this.platform.quoteValue(data[k]);
|
|
322
|
-
const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
|
|
323
|
-
data[k] = raw(sql.replace(/\?/g, '\\?'));
|
|
324
|
-
}
|
|
325
|
-
if (prop.fieldNames) {
|
|
326
|
-
Utils.renameKey(data, k, prop.fieldNames[0]);
|
|
327
|
-
}
|
|
315
|
+
}
|
|
316
|
+
if (prop.joinColumns && Array.isArray(data[k])) {
|
|
317
|
+
const copy = Utils.flatten(data[k]);
|
|
318
|
+
delete data[k];
|
|
319
|
+
prop.joinColumns.forEach((joinColumn, idx) => (data[joinColumn] = copy[idx]));
|
|
320
|
+
return;
|
|
321
|
+
}
|
|
322
|
+
if (prop.joinColumns?.length > 1 && data[k] == null) {
|
|
323
|
+
delete data[k];
|
|
324
|
+
prop.ownColumns.forEach(joinColumn => (data[joinColumn] = null));
|
|
325
|
+
return;
|
|
326
|
+
}
|
|
327
|
+
if (
|
|
328
|
+
prop.customType &&
|
|
329
|
+
convertCustomTypes &&
|
|
330
|
+
!(prop.customType instanceof JsonType && object) &&
|
|
331
|
+
!isRaw(data[k])
|
|
332
|
+
) {
|
|
333
|
+
data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, {
|
|
334
|
+
fromQuery: true,
|
|
335
|
+
key: k,
|
|
336
|
+
mode: 'query-data',
|
|
328
337
|
});
|
|
329
|
-
|
|
338
|
+
}
|
|
339
|
+
if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
|
|
340
|
+
const quoted = this.platform.quoteValue(data[k]);
|
|
341
|
+
const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
|
|
342
|
+
data[k] = raw(sql.replace(/\?/g, '\\?'));
|
|
343
|
+
}
|
|
344
|
+
if (prop.fieldNames) {
|
|
345
|
+
Utils.renameKey(data, k, prop.fieldNames[0]);
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
return data;
|
|
349
|
+
}
|
|
350
|
+
inlineEmbeddables(meta, data, where) {
|
|
351
|
+
/* v8 ignore next */
|
|
352
|
+
if (data == null) {
|
|
353
|
+
return;
|
|
330
354
|
}
|
|
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
|
-
throw ValidationError.invalidEmbeddableQuery(meta.class, kkk, sub.type);
|
|
360
|
-
}
|
|
361
|
-
inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.fieldNames[0]]);
|
|
362
|
-
});
|
|
363
|
-
}
|
|
364
|
-
data[`${path.join('.')}.${sub.fieldNames[0]}`] = payload[sub.embedded[1]];
|
|
365
|
-
};
|
|
366
|
-
const parentPropName = kk.substring(0, kk.indexOf('.'));
|
|
367
|
-
// we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
|
|
368
|
-
if (props[kk]) {
|
|
369
|
-
/* v8 ignore next */
|
|
370
|
-
inline(data[prop.name], props[kk] || props[parentPropName], [prop.fieldNames[0]]);
|
|
371
|
-
}
|
|
372
|
-
else if (props[parentPropName]) {
|
|
373
|
-
data[`${prop.fieldNames[0]}.${kk}`] = data[prop.name][kk];
|
|
374
|
-
}
|
|
375
|
-
else {
|
|
376
|
-
unknownProp = true;
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
else if (props[kk]) {
|
|
380
|
-
data[props[kk].fieldNames[0]] = data[prop.name][props[kk].embedded[1]];
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
throw ValidationError.invalidEmbeddableQuery(meta.class, kk, prop.type);
|
|
384
|
-
}
|
|
355
|
+
Utils.keys(data).forEach(k => {
|
|
356
|
+
if (Utils.isOperator(k)) {
|
|
357
|
+
Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
|
|
358
|
+
}
|
|
359
|
+
});
|
|
360
|
+
meta.props.forEach(prop => {
|
|
361
|
+
if (prop.kind === ReferenceKind.EMBEDDED && prop.object && !where && Utils.isObject(data[prop.name])) {
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
if (prop.kind === ReferenceKind.EMBEDDED && Utils.isObject(data[prop.name])) {
|
|
365
|
+
const props = prop.embeddedProps;
|
|
366
|
+
let unknownProp = false;
|
|
367
|
+
Object.keys(data[prop.name]).forEach(kk => {
|
|
368
|
+
// explicitly allow `$exists`, `$eq`, `$ne` and `$elemMatch` operators here as they can't be misused this way
|
|
369
|
+
const operator = Object.keys(data[prop.name]).some(
|
|
370
|
+
f => Utils.isOperator(f) && !['$exists', '$ne', '$eq', '$elemMatch'].includes(f),
|
|
371
|
+
);
|
|
372
|
+
if (operator) {
|
|
373
|
+
throw ValidationError.cannotUseOperatorsInsideEmbeddables(meta.class, prop.name, data);
|
|
374
|
+
}
|
|
375
|
+
if (prop.object && where) {
|
|
376
|
+
const inline = (payload, sub, path) => {
|
|
377
|
+
if (sub.kind === ReferenceKind.EMBEDDED && Utils.isObject(payload[sub.embedded[1]])) {
|
|
378
|
+
return Object.keys(payload[sub.embedded[1]]).forEach(kkk => {
|
|
379
|
+
if (!sub.embeddedProps[kkk]) {
|
|
380
|
+
throw ValidationError.invalidEmbeddableQuery(meta.class, kkk, sub.type);
|
|
381
|
+
}
|
|
382
|
+
inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.fieldNames[0]]);
|
|
385
383
|
});
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
384
|
+
}
|
|
385
|
+
data[`${path.join('.')}.${sub.fieldNames[0]}`] = payload[sub.embedded[1]];
|
|
386
|
+
};
|
|
387
|
+
const parentPropName = kk.substring(0, kk.indexOf('.'));
|
|
388
|
+
// we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
|
|
389
|
+
if (props[kk]) {
|
|
390
|
+
/* v8 ignore next */
|
|
391
|
+
inline(data[prop.name], props[kk] || props[parentPropName], [prop.fieldNames[0]]);
|
|
392
|
+
} else if (props[parentPropName]) {
|
|
393
|
+
data[`${prop.fieldNames[0]}.${kk}`] = data[prop.name][kk];
|
|
394
|
+
} else {
|
|
395
|
+
unknownProp = true;
|
|
389
396
|
}
|
|
397
|
+
} else if (props[kk]) {
|
|
398
|
+
data[props[kk].fieldNames[0]] = data[prop.name][props[kk].embedded[1]];
|
|
399
|
+
} else {
|
|
400
|
+
throw ValidationError.invalidEmbeddableQuery(meta.class, kk, prop.type);
|
|
401
|
+
}
|
|
390
402
|
});
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
return meta.getPrimaryProps().flatMap(pk => pk.fieldNames);
|
|
394
|
-
}
|
|
395
|
-
createReplicas(cb) {
|
|
396
|
-
const replicas = this.config.get('replicas', []);
|
|
397
|
-
const ret = [];
|
|
398
|
-
const props = [
|
|
399
|
-
'dbName',
|
|
400
|
-
'clientUrl',
|
|
401
|
-
'host',
|
|
402
|
-
'port',
|
|
403
|
-
'user',
|
|
404
|
-
'password',
|
|
405
|
-
'multipleStatements',
|
|
406
|
-
'pool',
|
|
407
|
-
'name',
|
|
408
|
-
'driverOptions',
|
|
409
|
-
];
|
|
410
|
-
for (const conf of replicas) {
|
|
411
|
-
const replicaConfig = Utils.copy(conf);
|
|
412
|
-
for (const prop of props) {
|
|
413
|
-
if (conf[prop]) {
|
|
414
|
-
continue;
|
|
415
|
-
}
|
|
416
|
-
// do not copy options that can be inferred from explicitly provided `clientUrl`
|
|
417
|
-
if (conf.clientUrl && ['clientUrl', 'host', 'port', 'user', 'password'].includes(prop)) {
|
|
418
|
-
continue;
|
|
419
|
-
}
|
|
420
|
-
if (conf.clientUrl && prop === 'dbName' && new URL(conf.clientUrl).pathname) {
|
|
421
|
-
continue;
|
|
422
|
-
}
|
|
423
|
-
replicaConfig[prop] = this.config.get(prop);
|
|
424
|
-
}
|
|
425
|
-
ret.push(cb(replicaConfig));
|
|
403
|
+
if (!unknownProp) {
|
|
404
|
+
delete data[prop.name];
|
|
426
405
|
}
|
|
427
|
-
|
|
428
|
-
}
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
406
|
+
}
|
|
407
|
+
});
|
|
408
|
+
}
|
|
409
|
+
getPrimaryKeyFields(meta) {
|
|
410
|
+
return meta.getPrimaryProps().flatMap(pk => pk.fieldNames);
|
|
411
|
+
}
|
|
412
|
+
createReplicas(cb) {
|
|
413
|
+
const replicas = this.config.get('replicas', []);
|
|
414
|
+
const ret = [];
|
|
415
|
+
const props = [
|
|
416
|
+
'dbName',
|
|
417
|
+
'clientUrl',
|
|
418
|
+
'host',
|
|
419
|
+
'port',
|
|
420
|
+
'user',
|
|
421
|
+
'password',
|
|
422
|
+
'multipleStatements',
|
|
423
|
+
'pool',
|
|
424
|
+
'name',
|
|
425
|
+
'driverOptions',
|
|
426
|
+
];
|
|
427
|
+
for (const conf of replicas) {
|
|
428
|
+
const replicaConfig = Utils.copy(conf);
|
|
429
|
+
for (const prop of props) {
|
|
430
|
+
if (conf[prop]) {
|
|
431
|
+
continue;
|
|
432
|
+
}
|
|
433
|
+
// do not copy options that can be inferred from explicitly provided `clientUrl`
|
|
434
|
+
if (conf.clientUrl && ['clientUrl', 'host', 'port', 'user', 'password'].includes(prop)) {
|
|
435
|
+
continue;
|
|
438
436
|
}
|
|
439
|
-
|
|
437
|
+
if (conf.clientUrl && prop === 'dbName' && new URL(conf.clientUrl).pathname) {
|
|
438
|
+
continue;
|
|
439
|
+
}
|
|
440
|
+
replicaConfig[prop] = this.config.get(prop);
|
|
441
|
+
}
|
|
442
|
+
ret.push(cb(replicaConfig));
|
|
440
443
|
}
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
444
|
+
return ret;
|
|
445
|
+
}
|
|
446
|
+
/** Acquires a pessimistic lock on the given entity. */
|
|
447
|
+
async lockPessimistic(entity, options) {
|
|
448
|
+
throw new Error(`Pessimistic locks are not supported by ${this.constructor.name} driver`);
|
|
449
|
+
}
|
|
450
|
+
/**
|
|
451
|
+
* @inheritDoc
|
|
452
|
+
*/
|
|
453
|
+
convertException(exception) {
|
|
454
|
+
if (exception instanceof DriverException) {
|
|
455
|
+
return exception;
|
|
445
456
|
}
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
457
|
+
return this.platform.getExceptionConverter().convertException(exception);
|
|
458
|
+
}
|
|
459
|
+
rethrow(promise) {
|
|
460
|
+
return promise.catch(e => {
|
|
461
|
+
throw this.convertException(e);
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
/**
|
|
465
|
+
* @internal
|
|
466
|
+
*/
|
|
467
|
+
getTableName(meta, options, quote = true) {
|
|
468
|
+
const schema = this.getSchemaName(meta, options);
|
|
469
|
+
const tableName =
|
|
470
|
+
schema && schema !== this.platform.getDefaultSchemaName() ? `${schema}.${meta.tableName}` : meta.tableName;
|
|
471
|
+
if (quote) {
|
|
472
|
+
return this.platform.quoteIdentifier(tableName);
|
|
456
473
|
}
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
return this.config.get('schema');
|
|
466
|
-
}
|
|
467
|
-
const schemaName = meta?.schema === '*' ? this.config.getSchema() : meta?.schema;
|
|
468
|
-
return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
|
|
474
|
+
return tableName;
|
|
475
|
+
}
|
|
476
|
+
/**
|
|
477
|
+
* @internal
|
|
478
|
+
*/
|
|
479
|
+
getSchemaName(meta, options) {
|
|
480
|
+
if (meta?.schema && meta.schema !== '*') {
|
|
481
|
+
return meta.schema;
|
|
469
482
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
return MikroORM;
|
|
483
|
+
if (options?.schema === '*') {
|
|
484
|
+
return this.config.get('schema');
|
|
473
485
|
}
|
|
486
|
+
const schemaName = meta?.schema === '*' ? this.config.getSchema() : meta?.schema;
|
|
487
|
+
return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
|
|
488
|
+
}
|
|
489
|
+
/** @internal */
|
|
490
|
+
getORMClass() {
|
|
491
|
+
return MikroORM;
|
|
492
|
+
}
|
|
474
493
|
}
|