@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100
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 +96 -58
- package/EntityManager.js +465 -395
- package/MikroORM.d.ts +45 -35
- package/MikroORM.js +109 -160
- package/README.md +3 -2
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -2
- package/cache/FileCacheAdapter.js +20 -27
- package/cache/GeneratedCacheAdapter.d.ts +2 -3
- package/cache/GeneratedCacheAdapter.js +1 -7
- 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 +4 -5
- package/cache/index.js +4 -21
- package/connections/Connection.d.ts +22 -14
- package/connections/Connection.js +27 -23
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/drivers/DatabaseDriver.d.ts +25 -15
- package/drivers/DatabaseDriver.js +77 -64
- package/drivers/IDatabaseDriver.d.ts +40 -16
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/BaseEntity.d.ts +6 -7
- package/entity/BaseEntity.js +16 -23
- package/entity/Collection.d.ts +98 -34
- package/entity/Collection.js +466 -131
- package/entity/EntityAssigner.d.ts +3 -3
- package/entity/EntityAssigner.js +67 -64
- package/entity/EntityFactory.d.ts +10 -3
- package/entity/EntityFactory.js +112 -91
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +66 -53
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +8 -7
- package/entity/EntityLoader.js +161 -128
- package/entity/EntityRepository.d.ts +8 -8
- package/entity/EntityRepository.js +7 -11
- package/entity/Reference.d.ts +10 -13
- package/entity/Reference.js +64 -46
- package/entity/WrappedEntity.d.ts +12 -17
- package/entity/WrappedEntity.js +22 -31
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +14 -13
- package/entity/index.js +14 -29
- package/entity/utils.d.ts +8 -1
- package/entity/utils.js +22 -13
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +24 -9
- package/enums.js +50 -41
- package/errors.d.ts +11 -3
- package/errors.js +42 -32
- package/events/EventManager.d.ts +5 -4
- package/events/EventManager.js +26 -22
- 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 +2 -6
- package/hydration/ObjectHydrator.d.ts +7 -7
- package/hydration/ObjectHydrator.js +58 -50
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +20 -46
- package/logging/DefaultLogger.d.ts +2 -2
- package/logging/DefaultLogger.js +10 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +3 -3
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +5 -4
- package/logging/index.js +5 -20
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/EntitySchema.d.ts +14 -10
- package/metadata/EntitySchema.js +78 -64
- package/metadata/MetadataDiscovery.d.ts +11 -14
- package/metadata/MetadataDiscovery.js +278 -317
- package/metadata/MetadataProvider.d.ts +13 -4
- package/metadata/MetadataProvider.js +47 -8
- package/metadata/MetadataStorage.d.ts +2 -7
- package/metadata/MetadataStorage.js +19 -35
- package/metadata/MetadataValidator.d.ts +3 -10
- package/metadata/MetadataValidator.js +51 -64
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
- package/naming-strategy/AbstractNamingStrategy.js +11 -9
- 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 +12 -2
- 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/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -20
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +15 -22
- package/platforms/Platform.js +58 -88
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +4 -2
- package/serialization/EntitySerializer.js +64 -51
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +48 -42
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +24 -25
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +6 -11
- package/types/BigIntType.d.ts +12 -9
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -4
- package/types/BlobType.js +2 -11
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +5 -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 +9 -7
- package/types/DecimalType.js +5 -8
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +4 -7
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +4 -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 +4 -4
- package/types/JsonType.js +9 -8
- 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 +4 -6
- package/types/Type.js +6 -10
- package/types/Uint8ArrayType.d.ts +3 -4
- package/types/Uint8ArrayType.js +3 -12
- 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 +134 -93
- package/typings.js +67 -65
- package/unit-of-work/ChangeSet.d.ts +1 -4
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -9
- package/unit-of-work/ChangeSetComputer.js +36 -38
- package/unit-of-work/ChangeSetPersister.d.ts +11 -9
- package/unit-of-work/ChangeSetPersister.js +100 -65
- 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 +16 -8
- package/unit-of-work/UnitOfWork.js +266 -209
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +11 -11
- package/utils/AbstractSchemaGenerator.js +21 -20
- package/utils/Configuration.d.ts +774 -224
- package/utils/Configuration.js +166 -216
- package/utils/ConfigurationLoader.d.ts +1 -53
- package/utils/ConfigurationLoader.js +1 -367
- package/utils/Cursor.d.ts +6 -9
- package/utils/Cursor.js +25 -25
- package/utils/DataloaderUtils.d.ts +18 -8
- package/utils/DataloaderUtils.js +63 -21
- package/utils/EntityComparator.d.ts +9 -5
- package/utils/EntityComparator.js +155 -108
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +12 -4
- package/utils/QueryHelper.js +110 -53
- package/utils/RawQueryFragment.d.ts +37 -14
- package/utils/RawQueryFragment.js +50 -33
- 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/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -100
- package/utils/Utils.js +114 -332
- package/utils/clone.js +7 -11
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +97 -0
- package/utils/index.d.ts +14 -13
- package/utils/index.js +14 -29
- package/utils/upsert-utils.d.ts +8 -3
- package/utils/upsert-utils.js +57 -10
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -16
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -33
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -14
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -20
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -16
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -19
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -11
- package/decorators/Formula.d.ts +0 -5
- package/decorators/Formula.js +0 -18
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -24
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -16
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -16
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -20
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -10
- package/decorators/PrimaryKey.d.ts +0 -9
- package/decorators/PrimaryKey.js +0 -23
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -34
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -31
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -59
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -36
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -399
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -154
- package/index.mjs +0 -199
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -48
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -31
|
@@ -1,18 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { EntityManagerType, } from './IDatabaseDriver.js';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
import { Cursor } from '../utils/Cursor.js';
|
|
4
|
+
import { EntityComparator } from '../utils/EntityComparator.js';
|
|
5
|
+
import { isRaw, raw } from '../utils/RawQueryFragment.js';
|
|
6
|
+
import { QueryOrderNumeric, ReferenceKind } from '../enums.js';
|
|
7
|
+
import { EntityManager } from '../EntityManager.js';
|
|
8
|
+
import { CursorError, ValidationError } from '../errors.js';
|
|
9
|
+
import { DriverException } from '../exceptions.js';
|
|
10
|
+
import { helper } from '../entity/wrap.js';
|
|
11
|
+
import { JsonType } from '../types/JsonType.js';
|
|
12
|
+
import { MikroORM } from '../MikroORM.js';
|
|
13
|
+
export class DatabaseDriver {
|
|
13
14
|
config;
|
|
14
15
|
dependencies;
|
|
15
|
-
[
|
|
16
|
+
[EntityManagerType];
|
|
16
17
|
connection;
|
|
17
18
|
replicas = [];
|
|
18
19
|
platform;
|
|
@@ -28,14 +29,14 @@ class DatabaseDriver {
|
|
|
28
29
|
throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
|
|
29
30
|
}
|
|
30
31
|
createEntityManager(useContext) {
|
|
31
|
-
const EntityManagerClass = this.config.get('entityManager',
|
|
32
|
+
const EntityManagerClass = this.config.get('entityManager', EntityManager);
|
|
32
33
|
return new EntityManagerClass(this.config, this, this.metadata, useContext);
|
|
33
34
|
}
|
|
34
|
-
/*
|
|
35
|
+
/* v8 ignore next */
|
|
35
36
|
async findVirtual(entityName, where, options) {
|
|
36
37
|
throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
|
|
37
38
|
}
|
|
38
|
-
/*
|
|
39
|
+
/* v8 ignore next */
|
|
39
40
|
async countVirtual(entityName, where, options) {
|
|
40
41
|
throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
|
|
41
42
|
}
|
|
@@ -47,17 +48,18 @@ class DatabaseDriver {
|
|
|
47
48
|
}
|
|
48
49
|
async syncCollections(collections, options) {
|
|
49
50
|
for (const coll of collections) {
|
|
51
|
+
/* v8 ignore else */
|
|
50
52
|
if (!coll.property.owner) {
|
|
51
53
|
if (coll.getSnapshot() === undefined) {
|
|
52
|
-
throw
|
|
54
|
+
throw ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
|
|
53
55
|
}
|
|
54
56
|
continue;
|
|
55
57
|
}
|
|
56
|
-
/*
|
|
58
|
+
/* v8 ignore next */
|
|
57
59
|
{
|
|
58
60
|
const pk = coll.property.targetMeta.primaryKeys[0];
|
|
59
61
|
const data = { [coll.property.name]: coll.getIdentifiers(pk) };
|
|
60
|
-
await this.nativeUpdate(coll.owner.constructor.name,
|
|
62
|
+
await this.nativeUpdate(coll.owner.constructor.name, helper(coll.owner).getPrimaryKey(), data, options);
|
|
61
63
|
}
|
|
62
64
|
}
|
|
63
65
|
}
|
|
@@ -67,21 +69,21 @@ class DatabaseDriver {
|
|
|
67
69
|
}
|
|
68
70
|
return this.comparator.mapResult(meta.className, result);
|
|
69
71
|
}
|
|
70
|
-
async connect() {
|
|
71
|
-
await this.connection.connect();
|
|
72
|
+
async connect(options) {
|
|
73
|
+
await this.connection.connect(options);
|
|
72
74
|
await Promise.all(this.replicas.map(replica => replica.connect()));
|
|
73
75
|
return this.connection;
|
|
74
76
|
}
|
|
75
|
-
async reconnect() {
|
|
77
|
+
async reconnect(options) {
|
|
76
78
|
await this.close(true);
|
|
77
|
-
await this.connect();
|
|
79
|
+
await this.connect(options);
|
|
78
80
|
return this.connection;
|
|
79
81
|
}
|
|
80
82
|
getConnection(type = 'write') {
|
|
81
83
|
if (type === 'write' || this.replicas.length === 0) {
|
|
82
84
|
return this.connection;
|
|
83
85
|
}
|
|
84
|
-
const rand =
|
|
86
|
+
const rand = Utils.randomInt(0, this.replicas.length - 1);
|
|
85
87
|
return this.replicas[rand];
|
|
86
88
|
}
|
|
87
89
|
async close(force) {
|
|
@@ -93,7 +95,7 @@ class DatabaseDriver {
|
|
|
93
95
|
}
|
|
94
96
|
setMetadata(metadata) {
|
|
95
97
|
this.metadata = metadata;
|
|
96
|
-
this.comparator = new
|
|
98
|
+
this.comparator = new EntityComparator(this.metadata, this.platform);
|
|
97
99
|
this.connection.setMetadata(metadata);
|
|
98
100
|
this.connection.setPlatform(this.platform);
|
|
99
101
|
this.replicas.forEach(replica => {
|
|
@@ -107,11 +109,20 @@ class DatabaseDriver {
|
|
|
107
109
|
getDependencies() {
|
|
108
110
|
return this.dependencies;
|
|
109
111
|
}
|
|
112
|
+
isPopulated(meta, prop, hint, name) {
|
|
113
|
+
if (hint.field === prop.name || hint.field === name || hint.all) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (prop.embedded && hint.children && meta.properties[prop.embedded[0]].name === hint.field) {
|
|
117
|
+
return hint.children.some(c => this.isPopulated(meta, prop, c, prop.embedded[1]));
|
|
118
|
+
}
|
|
119
|
+
return false;
|
|
120
|
+
}
|
|
110
121
|
processCursorOptions(meta, options, orderBy) {
|
|
111
122
|
const { first, last, before, after, overfetch } = options;
|
|
112
123
|
const limit = first ?? last;
|
|
113
124
|
const isLast = !first && !!last;
|
|
114
|
-
const definition =
|
|
125
|
+
const definition = Cursor.getDefinition(meta, orderBy);
|
|
115
126
|
const $and = [];
|
|
116
127
|
// allow POJO as well, we care only about the correct key being present
|
|
117
128
|
const isCursor = (val, key) => {
|
|
@@ -119,15 +130,15 @@ class DatabaseDriver {
|
|
|
119
130
|
};
|
|
120
131
|
const createCursor = (val, key, inverse = false) => {
|
|
121
132
|
let def = isCursor(val, key) ? val[key] : val;
|
|
122
|
-
if (
|
|
123
|
-
def =
|
|
133
|
+
if (Utils.isPlainObject(def)) {
|
|
134
|
+
def = Cursor.for(meta, def, orderBy);
|
|
124
135
|
}
|
|
125
|
-
/*
|
|
126
|
-
const offsets = def ?
|
|
136
|
+
/* v8 ignore next */
|
|
137
|
+
const offsets = def ? Cursor.decode(def) : [];
|
|
127
138
|
if (definition.length === offsets.length) {
|
|
128
139
|
return this.createCursorCondition(definition, offsets, inverse, meta);
|
|
129
140
|
}
|
|
130
|
-
/*
|
|
141
|
+
/* v8 ignore next */
|
|
131
142
|
return {};
|
|
132
143
|
};
|
|
133
144
|
if (after) {
|
|
@@ -140,15 +151,15 @@ class DatabaseDriver {
|
|
|
140
151
|
options.limit = limit + (overfetch ? 1 : 0);
|
|
141
152
|
}
|
|
142
153
|
const createOrderBy = (prop, direction) => {
|
|
143
|
-
if (
|
|
144
|
-
const value =
|
|
154
|
+
if (Utils.isPlainObject(direction)) {
|
|
155
|
+
const value = Utils.keys(direction).reduce((o, key) => {
|
|
145
156
|
Object.assign(o, createOrderBy(key, direction[key]));
|
|
146
157
|
return o;
|
|
147
158
|
}, {});
|
|
148
159
|
return ({ [prop]: value });
|
|
149
160
|
}
|
|
150
|
-
const desc = direction ===
|
|
151
|
-
const dir =
|
|
161
|
+
const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
|
|
162
|
+
const dir = Utils.xor(desc, isLast) ? 'desc' : 'asc';
|
|
152
163
|
return ({ [prop]: dir });
|
|
153
164
|
};
|
|
154
165
|
return {
|
|
@@ -156,24 +167,23 @@ class DatabaseDriver {
|
|
|
156
167
|
where: ($and.length > 1 ? { $and } : { ...$and[0] }),
|
|
157
168
|
};
|
|
158
169
|
}
|
|
159
|
-
/* istanbul ignore next */
|
|
160
170
|
createCursorCondition(definition, offsets, inverse, meta) {
|
|
161
171
|
const createCondition = (prop, direction, offset, eq = false) => {
|
|
162
172
|
if (offset === null) {
|
|
163
|
-
throw
|
|
173
|
+
throw CursorError.missingValue(meta.className, prop);
|
|
164
174
|
}
|
|
165
|
-
if (
|
|
166
|
-
const value =
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
175
|
+
if (Utils.isPlainObject(direction)) {
|
|
176
|
+
const value = Utils.keys(direction).reduce((o, key) => {
|
|
177
|
+
if (Utils.isEmpty(offset[key])) {
|
|
178
|
+
throw CursorError.missingValue(meta.className, `${prop}.${key}`);
|
|
169
179
|
}
|
|
170
180
|
Object.assign(o, createCondition(key, direction[key], offset[key], eq));
|
|
171
181
|
return o;
|
|
172
182
|
}, {});
|
|
173
183
|
return ({ [prop]: value });
|
|
174
184
|
}
|
|
175
|
-
const desc = direction ===
|
|
176
|
-
const operator =
|
|
185
|
+
const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
|
|
186
|
+
const operator = Utils.xor(desc, inverse) ? '$lt' : '$gt';
|
|
177
187
|
return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
|
|
178
188
|
};
|
|
179
189
|
const [order, ...otherOrders] = definition;
|
|
@@ -222,7 +232,7 @@ class DatabaseDriver {
|
|
|
222
232
|
return;
|
|
223
233
|
}
|
|
224
234
|
if (prop.joinColumns && Array.isArray(data[k])) {
|
|
225
|
-
const copy =
|
|
235
|
+
const copy = Utils.flatten(data[k]);
|
|
226
236
|
delete data[k];
|
|
227
237
|
prop.joinColumns.forEach((joinColumn, idx) => data[joinColumn] = copy[idx]);
|
|
228
238
|
return;
|
|
@@ -232,49 +242,49 @@ class DatabaseDriver {
|
|
|
232
242
|
prop.ownColumns.forEach(joinColumn => data[joinColumn] = null);
|
|
233
243
|
return;
|
|
234
244
|
}
|
|
235
|
-
if (prop.customType && convertCustomTypes && !(prop.customType instanceof
|
|
245
|
+
if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType && object) && !isRaw(data[k])) {
|
|
236
246
|
data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, { fromQuery: true, key: k, mode: 'query-data' });
|
|
237
247
|
}
|
|
238
|
-
if (prop.hasConvertToDatabaseValueSQL && !prop.object && !
|
|
248
|
+
if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
|
|
239
249
|
const quoted = this.platform.quoteValue(data[k]);
|
|
240
250
|
const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
|
|
241
|
-
data[k] =
|
|
251
|
+
data[k] = raw(sql.replace(/\?/g, '\\?'));
|
|
242
252
|
}
|
|
243
253
|
if (prop.fieldNames) {
|
|
244
|
-
|
|
254
|
+
Utils.renameKey(data, k, prop.fieldNames[0]);
|
|
245
255
|
}
|
|
246
256
|
});
|
|
247
257
|
return data;
|
|
248
258
|
}
|
|
249
259
|
inlineEmbeddables(meta, data, where) {
|
|
250
|
-
/*
|
|
260
|
+
/* v8 ignore next */
|
|
251
261
|
if (data == null) {
|
|
252
262
|
return;
|
|
253
263
|
}
|
|
254
|
-
|
|
255
|
-
if (
|
|
256
|
-
|
|
264
|
+
Utils.keys(data).forEach(k => {
|
|
265
|
+
if (Utils.isOperator(k)) {
|
|
266
|
+
Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
|
|
257
267
|
}
|
|
258
268
|
});
|
|
259
269
|
meta.props.forEach(prop => {
|
|
260
|
-
if (prop.kind ===
|
|
270
|
+
if (prop.kind === ReferenceKind.EMBEDDED && prop.object && !where && Utils.isObject(data[prop.name])) {
|
|
261
271
|
return;
|
|
262
272
|
}
|
|
263
|
-
if (prop.kind ===
|
|
273
|
+
if (prop.kind === ReferenceKind.EMBEDDED && Utils.isObject(data[prop.name])) {
|
|
264
274
|
const props = prop.embeddedProps;
|
|
265
275
|
let unknownProp = false;
|
|
266
276
|
Object.keys(data[prop.name]).forEach(kk => {
|
|
267
277
|
// explicitly allow `$exists`, `$eq` and `$ne` operators here as they can't be misused this way
|
|
268
|
-
const operator = Object.keys(data[prop.name]).some(f =>
|
|
278
|
+
const operator = Object.keys(data[prop.name]).some(f => Utils.isOperator(f) && !['$exists', '$ne', '$eq'].includes(f));
|
|
269
279
|
if (operator) {
|
|
270
|
-
throw
|
|
280
|
+
throw ValidationError.cannotUseOperatorsInsideEmbeddables(meta.className, prop.name, data);
|
|
271
281
|
}
|
|
272
282
|
if (prop.object && where) {
|
|
273
283
|
const inline = (payload, sub, path) => {
|
|
274
|
-
if (sub.kind ===
|
|
284
|
+
if (sub.kind === ReferenceKind.EMBEDDED && Utils.isObject(payload[sub.embedded[1]])) {
|
|
275
285
|
return Object.keys(payload[sub.embedded[1]]).forEach(kkk => {
|
|
276
286
|
if (!sub.embeddedProps[kkk]) {
|
|
277
|
-
throw
|
|
287
|
+
throw ValidationError.invalidEmbeddableQuery(meta.className, kkk, sub.type);
|
|
278
288
|
}
|
|
279
289
|
inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.embedded[1]]);
|
|
280
290
|
});
|
|
@@ -284,7 +294,7 @@ class DatabaseDriver {
|
|
|
284
294
|
const parentPropName = kk.substring(0, kk.indexOf('.'));
|
|
285
295
|
// we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
|
|
286
296
|
if (props[kk]) {
|
|
287
|
-
/*
|
|
297
|
+
/* v8 ignore next */
|
|
288
298
|
inline(data[prop.name], props[kk] || props[parentPropName], [prop.name]);
|
|
289
299
|
}
|
|
290
300
|
else if (props[parentPropName]) {
|
|
@@ -298,7 +308,7 @@ class DatabaseDriver {
|
|
|
298
308
|
data[props[kk].name] = data[prop.name][props[kk].embedded[1]];
|
|
299
309
|
}
|
|
300
310
|
else {
|
|
301
|
-
throw
|
|
311
|
+
throw ValidationError.invalidEmbeddableQuery(meta.className, kk, prop.type);
|
|
302
312
|
}
|
|
303
313
|
});
|
|
304
314
|
if (!unknownProp) {
|
|
@@ -309,14 +319,14 @@ class DatabaseDriver {
|
|
|
309
319
|
}
|
|
310
320
|
getPrimaryKeyFields(entityName) {
|
|
311
321
|
const meta = this.metadata.find(entityName);
|
|
312
|
-
return meta ?
|
|
322
|
+
return meta ? Utils.flatten(meta.getPrimaryProps().map(pk => pk.fieldNames)) : [this.config.getNamingStrategy().referenceColumnName()];
|
|
313
323
|
}
|
|
314
324
|
createReplicas(cb) {
|
|
315
325
|
const replicas = this.config.get('replicas', []);
|
|
316
326
|
const ret = [];
|
|
317
327
|
const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'name', 'driverOptions'];
|
|
318
328
|
for (const conf of replicas) {
|
|
319
|
-
const replicaConfig =
|
|
329
|
+
const replicaConfig = Utils.copy(conf);
|
|
320
330
|
for (const prop of props) {
|
|
321
331
|
if (conf[prop]) {
|
|
322
332
|
continue;
|
|
@@ -341,7 +351,7 @@ class DatabaseDriver {
|
|
|
341
351
|
* @inheritDoc
|
|
342
352
|
*/
|
|
343
353
|
convertException(exception) {
|
|
344
|
-
if (exception instanceof
|
|
354
|
+
if (exception instanceof DriverException) {
|
|
345
355
|
return exception;
|
|
346
356
|
}
|
|
347
357
|
return this.platform.getExceptionConverter().convertException(exception);
|
|
@@ -375,5 +385,8 @@ class DatabaseDriver {
|
|
|
375
385
|
const schemaName = meta?.schema === '*' ? this.config.getSchema() : meta?.schema;
|
|
376
386
|
return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
|
|
377
387
|
}
|
|
388
|
+
/** @internal */
|
|
389
|
+
getORMClass() {
|
|
390
|
+
return MikroORM;
|
|
391
|
+
}
|
|
378
392
|
}
|
|
379
|
-
exports.DatabaseDriver = DatabaseDriver;
|
|
@@ -1,22 +1,26 @@
|
|
|
1
|
-
import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate } from '../typings';
|
|
2
|
-
import type { Connection, QueryResult, Transaction } from '../connections';
|
|
3
|
-
import type { FlushMode, LockMode, QueryOrderMap, QueryFlag, LoadStrategy, PopulateHint, PopulatePath } from '../enums';
|
|
4
|
-
import type { Platform } from '../platforms';
|
|
5
|
-
import type { MetadataStorage } from '../metadata';
|
|
6
|
-
import type { Collection } from '../entity/Collection';
|
|
7
|
-
import type { EntityManager } from '../EntityManager';
|
|
8
|
-
import type { DriverException } from '../exceptions';
|
|
9
|
-
import type { Configuration } from '../utils/Configuration';
|
|
10
|
-
import type { LoggingOptions, LogContext } from '../logging';
|
|
11
|
-
import type { RawQueryFragment } from '../utils/RawQueryFragment';
|
|
1
|
+
import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate, EntityName } from '../typings.js';
|
|
2
|
+
import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
|
|
3
|
+
import type { FlushMode, LockMode, QueryOrderMap, QueryFlag, LoadStrategy, PopulateHint, PopulatePath } from '../enums.js';
|
|
4
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
5
|
+
import type { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
6
|
+
import type { Collection } from '../entity/Collection.js';
|
|
7
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
8
|
+
import type { DriverException } from '../exceptions.js';
|
|
9
|
+
import type { Configuration } from '../utils/Configuration.js';
|
|
10
|
+
import type { LoggingOptions, LogContext } from '../logging/Logger.js';
|
|
11
|
+
import type { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
12
12
|
export declare const EntityManagerType: unique symbol;
|
|
13
13
|
export interface IDatabaseDriver<C extends Connection = Connection> {
|
|
14
14
|
[EntityManagerType]: EntityManager<this>;
|
|
15
15
|
readonly config: Configuration;
|
|
16
|
-
createEntityManager
|
|
17
|
-
connect(
|
|
16
|
+
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
17
|
+
connect(options?: {
|
|
18
|
+
skipOnConnect?: boolean;
|
|
19
|
+
}): Promise<C>;
|
|
18
20
|
close(force?: boolean): Promise<void>;
|
|
19
|
-
reconnect(
|
|
21
|
+
reconnect(options?: {
|
|
22
|
+
skipOnConnect?: boolean;
|
|
23
|
+
}): Promise<C>;
|
|
20
24
|
getConnection(type?: ConnectionType): C;
|
|
21
25
|
/**
|
|
22
26
|
* Finds selection of entities
|
|
@@ -27,6 +31,7 @@ export interface IDatabaseDriver<C extends Connection = Connection> {
|
|
|
27
31
|
*/
|
|
28
32
|
findOne<T extends object, P extends string = never, F extends string = '*', E extends string = never>(entityName: string, where: FilterQuery<T>, options?: FindOneOptions<T, P, F, E>): Promise<EntityData<T> | null>;
|
|
29
33
|
findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
|
|
34
|
+
stream<T extends object>(entityName: EntityName<T>, where: FilterQuery<T>, options: StreamOptions<T>): AsyncIterableIterator<T>;
|
|
30
35
|
nativeInsert<T extends object>(entityName: string, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
31
36
|
nativeInsertMany<T extends object>(entityName: string, data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>, transform?: (sql: string) => string): Promise<QueryResult<T>>;
|
|
32
37
|
nativeUpdate<T extends object>(entityName: string, where: FilterQuery<T>, data: EntityDictionary<T>, options?: NativeInsertUpdateOptions<T>): Promise<QueryResult<T>>;
|
|
@@ -68,6 +73,18 @@ export type OrderDefinition<T> = (QueryOrderMap<T> & {
|
|
|
68
73
|
export interface FindAllOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends FindOptions<T, P, F, E> {
|
|
69
74
|
where?: FilterQuery<T>;
|
|
70
75
|
}
|
|
76
|
+
export interface StreamOptions<Entity, Populate extends string = never, Fields extends string = '*', Exclude extends string = never> extends Omit<FindAllOptions<Entity, Populate, Fields, Exclude>, 'cache' | 'before' | 'after' | 'first' | 'last' | 'overfetch' | 'strategy'> {
|
|
77
|
+
/**
|
|
78
|
+
* When populating to-many relations, the ORM streams fully merged entities instead of yielding every row.
|
|
79
|
+
* You can opt out of this behavior by specifying `mergeResults: false`. This will yield every row from
|
|
80
|
+
* the SQL result, but still mapped to entities, meaning that to-many collections will contain at most
|
|
81
|
+
* a single item, and you will get duplicate root entities when they have multiple items in the populated
|
|
82
|
+
* collection.
|
|
83
|
+
*
|
|
84
|
+
* @default true
|
|
85
|
+
*/
|
|
86
|
+
mergeResults?: boolean;
|
|
87
|
+
}
|
|
71
88
|
export type FilterOptions = Dictionary<boolean | Dictionary> | string[] | boolean;
|
|
72
89
|
export interface LoadHint<Entity, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never> {
|
|
73
90
|
populate?: Populate<Entity, Hint>;
|
|
@@ -146,10 +163,13 @@ export interface FindOptions<Entity, Hint extends string = never, Fields extends
|
|
|
146
163
|
hintComments?: string | string[];
|
|
147
164
|
loggerContext?: LogContext;
|
|
148
165
|
logging?: LoggingOptions;
|
|
166
|
+
/** @internal used to apply filters to the auto-joined relations */
|
|
167
|
+
em?: EntityManager;
|
|
149
168
|
}
|
|
150
|
-
export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
|
|
169
|
+
export interface FindByCursorOptions<T extends object, P extends string = never, F extends string = '*', E extends string = never, I extends boolean = true> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'offset'> {
|
|
170
|
+
includeCount?: I;
|
|
151
171
|
}
|
|
152
|
-
export interface FindOneOptions<T
|
|
172
|
+
export interface FindOneOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends Omit<FindOptions<T, P, F, E>, 'limit' | 'lockMode'> {
|
|
153
173
|
lockMode?: LockMode;
|
|
154
174
|
lockVersion?: number | Date;
|
|
155
175
|
}
|
|
@@ -163,6 +183,7 @@ export interface NativeInsertUpdateOptions<T> {
|
|
|
163
183
|
schema?: string;
|
|
164
184
|
/** `nativeUpdate()` only option */
|
|
165
185
|
upsert?: boolean;
|
|
186
|
+
loggerContext?: LogContext;
|
|
166
187
|
}
|
|
167
188
|
export interface NativeInsertUpdateManyOptions<T> extends NativeInsertUpdateOptions<T> {
|
|
168
189
|
processCollections?: boolean;
|
|
@@ -197,6 +218,8 @@ export interface CountOptions<T extends object, P extends string = never> {
|
|
|
197
218
|
hintComments?: string | string[];
|
|
198
219
|
loggerContext?: LogContext;
|
|
199
220
|
logging?: LoggingOptions;
|
|
221
|
+
/** @internal used to apply filters to the auto-joined relations */
|
|
222
|
+
em?: EntityManager;
|
|
200
223
|
}
|
|
201
224
|
export interface UpdateOptions<T> {
|
|
202
225
|
filters?: FilterOptions;
|
|
@@ -218,6 +241,7 @@ export interface LockOptions extends DriverMethodOptions {
|
|
|
218
241
|
export interface DriverMethodOptions {
|
|
219
242
|
ctx?: Transaction;
|
|
220
243
|
schema?: string;
|
|
244
|
+
loggerContext?: LogContext;
|
|
221
245
|
}
|
|
222
246
|
export interface GetReferenceOptions {
|
|
223
247
|
wrapped?: boolean;
|
package/drivers/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './IDatabaseDriver';
|
|
2
|
-
export * from './DatabaseDriver';
|
|
1
|
+
export * from './IDatabaseDriver.js';
|
|
2
|
+
export * from './DatabaseDriver.js';
|
package/drivers/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./IDatabaseDriver"), exports);
|
|
18
|
-
__exportStar(require("./DatabaseDriver"), exports);
|
|
1
|
+
export * from './IDatabaseDriver.js';
|
|
2
|
+
export * from './DatabaseDriver.js';
|
package/entity/BaseEntity.d.ts
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import { type Ref } from './Reference';
|
|
2
|
-
import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings';
|
|
3
|
-
import { type AssignOptions } from './EntityAssigner';
|
|
4
|
-
import type { EntityLoaderOptions } from './EntityLoader';
|
|
5
|
-
import { type SerializeOptions } from '../serialization/EntitySerializer';
|
|
6
|
-
import type { FindOneOptions } from '../drivers/IDatabaseDriver';
|
|
1
|
+
import { type Ref } from './Reference.js';
|
|
2
|
+
import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
|
|
3
|
+
import { type AssignOptions } from './EntityAssigner.js';
|
|
4
|
+
import type { EntityLoaderOptions } from './EntityLoader.js';
|
|
5
|
+
import { type SerializeOptions } from '../serialization/EntitySerializer.js';
|
|
6
|
+
import type { FindOneOptions } from '../drivers/IDatabaseDriver.js';
|
|
7
7
|
export declare abstract class BaseEntity {
|
|
8
8
|
isInitialized(): boolean;
|
|
9
|
-
isTouched(): boolean;
|
|
10
9
|
populated(populated?: boolean): void;
|
|
11
10
|
populate<Entity extends this = this, Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
12
11
|
toReference<Entity extends this = this>(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
package/entity/BaseEntity.js
CHANGED
|
@@ -1,47 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const EntitySerializer_1 = require("../serialization/EntitySerializer");
|
|
7
|
-
const wrap_1 = require("./wrap");
|
|
8
|
-
class BaseEntity {
|
|
1
|
+
import { Reference } from './Reference.js';
|
|
2
|
+
import { EntityAssigner } from './EntityAssigner.js';
|
|
3
|
+
import { EntitySerializer } from '../serialization/EntitySerializer.js';
|
|
4
|
+
import { helper } from './wrap.js';
|
|
5
|
+
export class BaseEntity {
|
|
9
6
|
isInitialized() {
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
isTouched() {
|
|
13
|
-
return (0, wrap_1.helper)(this).__touched;
|
|
7
|
+
return helper(this).__initialized;
|
|
14
8
|
}
|
|
15
9
|
populated(populated = true) {
|
|
16
|
-
|
|
10
|
+
helper(this).populated(populated);
|
|
17
11
|
}
|
|
18
12
|
async populate(populate, options = {}) {
|
|
19
|
-
return
|
|
13
|
+
return helper(this).populate(populate, options);
|
|
20
14
|
}
|
|
21
15
|
toReference() {
|
|
22
|
-
return
|
|
16
|
+
return Reference.create(this);
|
|
23
17
|
}
|
|
24
18
|
toObject(ignoreFields) {
|
|
25
|
-
return
|
|
19
|
+
return helper(this).toObject(ignoreFields);
|
|
26
20
|
}
|
|
27
21
|
toPOJO() {
|
|
28
|
-
return
|
|
22
|
+
return helper(this).toPOJO();
|
|
29
23
|
}
|
|
30
24
|
serialize(options) {
|
|
31
|
-
return
|
|
25
|
+
return EntitySerializer.serialize(this, options);
|
|
32
26
|
}
|
|
33
27
|
assign(data, options = {}) {
|
|
34
|
-
return
|
|
28
|
+
return EntityAssigner.assign(this, data, options);
|
|
35
29
|
}
|
|
36
30
|
init(options) {
|
|
37
|
-
return
|
|
31
|
+
return helper(this).init(options);
|
|
38
32
|
}
|
|
39
33
|
getSchema() {
|
|
40
|
-
return
|
|
34
|
+
return helper(this).getSchema();
|
|
41
35
|
}
|
|
42
36
|
setSchema(schema) {
|
|
43
|
-
|
|
37
|
+
helper(this).setSchema(schema);
|
|
44
38
|
}
|
|
45
39
|
}
|
|
46
|
-
exports.BaseEntity = BaseEntity;
|
|
47
40
|
Object.defineProperty(BaseEntity.prototype, '__baseEntity', { value: true, writable: false, enumerable: false });
|