@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331
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 +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/entity/EntityHelper.d.ts
CHANGED
|
@@ -6,9 +6,9 @@ import { type EntityMetadata, type EntityProperty, type IHydrator } from '../typ
|
|
|
6
6
|
export declare class EntityHelper {
|
|
7
7
|
static decorate<T extends object>(meta: EntityMetadata<T>, em: EntityManager): void;
|
|
8
8
|
/**
|
|
9
|
-
* As a performance optimization, we create entity state methods
|
|
9
|
+
* As a performance optimization, we create entity state methods lazily. We first add
|
|
10
10
|
* the `null` value to the prototype to reserve space in memory. Then we define a setter on the
|
|
11
|
-
* prototype
|
|
11
|
+
* prototype that will be executed exactly once per entity instance. There we redefine the given
|
|
12
12
|
* property on the entity instance, so shadowing the prototype setter.
|
|
13
13
|
*/
|
|
14
14
|
private static defineBaseProperties;
|
package/entity/EntityHelper.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { EagerProps, EntityRepositoryType, HiddenProps, OptionalProps, PrimaryKeyProp, } from '../typings.js';
|
|
1
|
+
import { EagerProps, EntityName, EntityRepositoryType, HiddenProps, OptionalProps, PrimaryKeyProp, } from '../typings.js';
|
|
3
2
|
import { EntityTransformer } from '../serialization/EntityTransformer.js';
|
|
4
3
|
import { Reference } from './Reference.js';
|
|
5
4
|
import { Utils } from '../utils/Utils.js';
|
|
6
5
|
import { WrappedEntity } from './WrappedEntity.js';
|
|
7
6
|
import { ReferenceKind } from '../enums.js';
|
|
8
7
|
import { helper } from './wrap.js';
|
|
8
|
+
import { inspect } from '../logging/inspect.js';
|
|
9
|
+
import { getEnv } from '../utils/env-vars.js';
|
|
9
10
|
/**
|
|
10
11
|
* @internal
|
|
11
12
|
*/
|
|
@@ -30,19 +31,31 @@ export class EntityHelper {
|
|
|
30
31
|
EntityHelper.defineProperties(meta, fork);
|
|
31
32
|
}
|
|
32
33
|
const prototype = meta.prototype;
|
|
33
|
-
if (!prototype.toJSON) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
if (!prototype.toJSON) {
|
|
35
|
+
// toJSON can be overridden
|
|
36
|
+
Object.defineProperty(prototype, 'toJSON', {
|
|
37
|
+
value: function (...args) {
|
|
38
|
+
// Guard against being called on the prototype itself (e.g. by serializers
|
|
39
|
+
// walking the object graph and calling toJSON on prototype objects)
|
|
40
|
+
if (this === prototype) {
|
|
41
|
+
return {};
|
|
42
|
+
}
|
|
43
|
+
return EntityTransformer.toObject(this, ...args);
|
|
44
|
+
},
|
|
45
|
+
writable: true,
|
|
46
|
+
configurable: true,
|
|
47
|
+
enumerable: false,
|
|
48
|
+
});
|
|
37
49
|
}
|
|
38
50
|
}
|
|
39
51
|
/**
|
|
40
|
-
* As a performance optimization, we create entity state methods
|
|
52
|
+
* As a performance optimization, we create entity state methods lazily. We first add
|
|
41
53
|
* the `null` value to the prototype to reserve space in memory. Then we define a setter on the
|
|
42
|
-
* prototype
|
|
54
|
+
* prototype that will be executed exactly once per entity instance. There we redefine the given
|
|
43
55
|
* property on the entity instance, so shadowing the prototype setter.
|
|
44
56
|
*/
|
|
45
57
|
static defineBaseProperties(meta, prototype, em) {
|
|
58
|
+
// oxfmt-ignore
|
|
46
59
|
const helperParams = meta.embeddable || meta.virtual ? [] : [em.getComparator().getPkGetter(meta), em.getComparator().getPkSerializer(meta), em.getComparator().getPkGetterConverted(meta)];
|
|
47
60
|
Object.defineProperties(prototype, {
|
|
48
61
|
__entity: { value: !meta.embeddable, configurable: true },
|
|
@@ -72,10 +85,9 @@ export class EntityHelper {
|
|
|
72
85
|
* than on its prototype. Thanks to this we still have those properties enumerable (e.g. part of `Object.keys(entity)`).
|
|
73
86
|
*/
|
|
74
87
|
static defineProperties(meta, em) {
|
|
75
|
-
Object
|
|
76
|
-
.values(meta.properties)
|
|
77
|
-
.forEach(prop => {
|
|
88
|
+
Object.values(meta.properties).forEach(prop => {
|
|
78
89
|
const isCollection = [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind);
|
|
90
|
+
// oxfmt-ignore
|
|
79
91
|
const isReference = [ReferenceKind.ONE_TO_ONE, ReferenceKind.MANY_TO_ONE].includes(prop.kind) && (prop.inversedBy || prop.mappedBy) && !prop.mapToPk;
|
|
80
92
|
if (isReference) {
|
|
81
93
|
Object.defineProperty(meta.prototype, prop.name, {
|
|
@@ -87,7 +99,7 @@ export class EntityHelper {
|
|
|
87
99
|
});
|
|
88
100
|
return;
|
|
89
101
|
}
|
|
90
|
-
if (prop.inherited || prop.primary || prop.
|
|
102
|
+
if (prop.inherited || prop.primary || prop.accessor || prop.persist === false || prop.embedded || isCollection) {
|
|
91
103
|
return;
|
|
92
104
|
}
|
|
93
105
|
Object.defineProperty(meta.prototype, prop.name, {
|
|
@@ -98,13 +110,11 @@ export class EntityHelper {
|
|
|
98
110
|
},
|
|
99
111
|
set(val) {
|
|
100
112
|
this.__helper.__data[prop.name] = val;
|
|
101
|
-
this.__helper.__touched = !this.__helper.hydrator.isRunning();
|
|
102
113
|
},
|
|
103
114
|
enumerable: true,
|
|
104
115
|
configurable: true,
|
|
105
116
|
});
|
|
106
117
|
this.__helper.__data[prop.name] = val;
|
|
107
|
-
this.__helper.__touched = !this.__helper.hydrator.isRunning();
|
|
108
118
|
},
|
|
109
119
|
configurable: true,
|
|
110
120
|
});
|
|
@@ -112,16 +122,25 @@ export class EntityHelper {
|
|
|
112
122
|
}
|
|
113
123
|
static defineCustomInspect(meta) {
|
|
114
124
|
// @ts-ignore
|
|
115
|
-
meta.prototype[inspect.custom] ??= function (depth = 2) {
|
|
116
|
-
const object = {
|
|
125
|
+
meta.prototype[Symbol.for('nodejs.util.inspect.custom')] ??= function (depth = 2) {
|
|
126
|
+
const object = {};
|
|
127
|
+
const keys = new Set(Utils.keys(this));
|
|
128
|
+
for (const prop of meta.props) {
|
|
129
|
+
if (keys.has(prop.name) || (prop.getter && prop.accessor === prop.name)) {
|
|
130
|
+
object[prop.name] = this[prop.name];
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
for (const key of keys) {
|
|
134
|
+
if (!meta.properties[key]) {
|
|
135
|
+
object[key] = this[key];
|
|
136
|
+
}
|
|
137
|
+
}
|
|
117
138
|
// ensure we dont have internal symbols in the POJO
|
|
118
|
-
[OptionalProps, EntityRepositoryType, PrimaryKeyProp, EagerProps, HiddenProps].forEach(sym => delete object[sym]);
|
|
119
|
-
meta.props
|
|
120
|
-
.filter(prop => object[prop.name] === undefined)
|
|
121
|
-
.forEach(prop => delete object[prop.name]);
|
|
139
|
+
[OptionalProps, EntityRepositoryType, PrimaryKeyProp, EagerProps, HiddenProps, EntityName].forEach(sym => delete object[sym]);
|
|
140
|
+
meta.props.filter(prop => object[prop.name] === undefined).forEach(prop => delete object[prop.name]);
|
|
122
141
|
const ret = inspect(object, { depth });
|
|
123
|
-
let name =
|
|
124
|
-
const showEM = ['true', 't', '1'].includes(
|
|
142
|
+
let name = this.constructor.name;
|
|
143
|
+
const showEM = ['true', 't', '1'].includes(getEnv('MIKRO_ORM_LOG_EM_ID')?.toLowerCase() ?? '');
|
|
125
144
|
if (showEM) {
|
|
126
145
|
if (helper(this).__em) {
|
|
127
146
|
name += ` [managed by ${helper(this).__em.id}]`;
|
|
@@ -146,6 +165,7 @@ export class EntityHelper {
|
|
|
146
165
|
set(val) {
|
|
147
166
|
const entity = Reference.unwrapReference(val ?? wrapped.__data[prop.name]);
|
|
148
167
|
const old = Reference.unwrapReference(wrapped.__data[prop.name]);
|
|
168
|
+
// oxfmt-ignore
|
|
149
169
|
if (old && old !== entity && prop.kind === ReferenceKind.MANY_TO_ONE && prop.inversedBy && old[prop.inversedBy]) {
|
|
150
170
|
old[prop.inversedBy].removeWithoutPropagation(this);
|
|
151
171
|
}
|
|
@@ -154,9 +174,6 @@ export class EntityHelper {
|
|
|
154
174
|
if (val && hydrator.isRunning() && wrapped.__originalEntityData && prop.owner) {
|
|
155
175
|
wrapped.__originalEntityData[prop.name] = Utils.getPrimaryKeyValues(wrapped.__data[prop.name], prop.targetMeta, true);
|
|
156
176
|
}
|
|
157
|
-
else {
|
|
158
|
-
wrapped.__touched = !hydrator.isRunning();
|
|
159
|
-
}
|
|
160
177
|
EntityHelper.propagate(meta, entity, this, prop, Reference.unwrapReference(val), old);
|
|
161
178
|
},
|
|
162
179
|
enumerable: true,
|
|
@@ -164,14 +181,31 @@ export class EntityHelper {
|
|
|
164
181
|
});
|
|
165
182
|
}
|
|
166
183
|
static propagate(meta, entity, owner, prop, value, old) {
|
|
167
|
-
|
|
184
|
+
// For polymorphic relations, get bidirectional relations from the actual entity's metadata
|
|
185
|
+
let bidirectionalRelations;
|
|
186
|
+
if (prop.polymorphic && prop.polymorphTargets?.length) {
|
|
187
|
+
// For polymorphic relations, we need to get the bidirectional relations from the actual value's metadata
|
|
188
|
+
if (!value) {
|
|
189
|
+
return; // No value means no propagation needed
|
|
190
|
+
}
|
|
191
|
+
bidirectionalRelations = helper(value).__meta.bidirectionalRelations;
|
|
192
|
+
}
|
|
193
|
+
else {
|
|
194
|
+
bidirectionalRelations = prop.targetMeta.bidirectionalRelations;
|
|
195
|
+
}
|
|
196
|
+
for (const prop2 of bidirectionalRelations) {
|
|
168
197
|
if ((prop2.inversedBy || prop2.mappedBy) !== prop.name) {
|
|
169
198
|
continue;
|
|
170
199
|
}
|
|
200
|
+
// oxfmt-ignore
|
|
171
201
|
if (prop2.targetMeta.abstract ? prop2.targetMeta.root.class !== meta.root.class : prop2.targetMeta.class !== meta.class) {
|
|
172
202
|
continue;
|
|
173
203
|
}
|
|
174
204
|
const inverse = value?.[prop2.name];
|
|
205
|
+
if (prop.ref && owner[prop.name]) {
|
|
206
|
+
// eslint-disable-next-line dot-notation
|
|
207
|
+
owner[prop.name]['property'] = prop;
|
|
208
|
+
}
|
|
175
209
|
if (Utils.isCollection(inverse) && inverse.isPartial()) {
|
|
176
210
|
continue;
|
|
177
211
|
}
|
|
@@ -195,13 +229,21 @@ export class EntityHelper {
|
|
|
195
229
|
static propagateOneToOne(entity, owner, prop, prop2, value, old) {
|
|
196
230
|
helper(entity).__pk = helper(entity).getPrimaryKey();
|
|
197
231
|
// the inverse side will be changed on the `value` too, so we need to clean-up and schedule orphan removal there too
|
|
198
|
-
if (!prop.primary &&
|
|
232
|
+
if (!prop.primary &&
|
|
233
|
+
!prop2.mapToPk &&
|
|
234
|
+
value?.[prop2.name] != null &&
|
|
235
|
+
Reference.unwrapReference(value[prop2.name]) !== entity) {
|
|
199
236
|
const other = Reference.unwrapReference(value[prop2.name]);
|
|
200
237
|
delete helper(other).__data[prop.name];
|
|
201
238
|
if (prop2.orphanRemoval) {
|
|
202
239
|
helper(other).__em?.getUnitOfWork().scheduleOrphanRemoval(other);
|
|
203
240
|
}
|
|
204
241
|
}
|
|
242
|
+
// Skip setting the inverse side to null if it's a primary key - the entity will be removed via orphan removal
|
|
243
|
+
// Setting a primary key to null would corrupt the entity and cause validation errors
|
|
244
|
+
if (value == null && prop.orphanRemoval && prop2.primary) {
|
|
245
|
+
return;
|
|
246
|
+
}
|
|
205
247
|
if (value == null) {
|
|
206
248
|
entity[prop2.name] = value;
|
|
207
249
|
}
|
package/entity/EntityLoader.d.ts
CHANGED
|
@@ -1,37 +1,35 @@
|
|
|
1
|
-
import type { AnyEntity, ConnectionType,
|
|
1
|
+
import type { AnyEntity, AutoPath, ConnectionType, EntityName, EntityProperty, FilterQuery, PopulateOptions } from '../typings.js';
|
|
2
2
|
import type { EntityManager } from '../EntityManager.js';
|
|
3
3
|
import { LoadStrategy, type LockMode, type PopulateHint, PopulatePath, type QueryOrderMap } from '../enums.js';
|
|
4
|
-
import type {
|
|
4
|
+
import type { FilterOptions } from '../drivers/IDatabaseDriver.js';
|
|
5
5
|
import type { LoggingOptions } from '../logging/Logger.js';
|
|
6
|
-
export
|
|
6
|
+
export interface EntityLoaderOptions<Entity, Fields extends string = PopulatePath.ALL, Excludes extends string = never> {
|
|
7
|
+
fields?: readonly AutoPath<Entity, Fields, `${PopulatePath.ALL}`>[];
|
|
8
|
+
exclude?: readonly AutoPath<Entity, Excludes>[];
|
|
7
9
|
where?: FilterQuery<Entity>;
|
|
8
10
|
populateWhere?: PopulateHint | `${PopulateHint}`;
|
|
9
|
-
fields?: readonly EntityField<Entity, Fields>[];
|
|
10
|
-
exclude?: readonly EntityField<Entity, Excludes>[];
|
|
11
11
|
orderBy?: QueryOrderMap<Entity> | QueryOrderMap<Entity>[];
|
|
12
12
|
refresh?: boolean;
|
|
13
13
|
validate?: boolean;
|
|
14
14
|
lookup?: boolean;
|
|
15
15
|
convertCustomTypes?: boolean;
|
|
16
16
|
ignoreLazyScalarProperties?: boolean;
|
|
17
|
-
filters?:
|
|
18
|
-
strategy?: LoadStrategy
|
|
17
|
+
filters?: FilterOptions;
|
|
18
|
+
strategy?: LoadStrategy | `${LoadStrategy}`;
|
|
19
19
|
lockMode?: Exclude<LockMode, LockMode.OPTIMISTIC>;
|
|
20
20
|
schema?: string;
|
|
21
21
|
connectionType?: ConnectionType;
|
|
22
22
|
logging?: LoggingOptions;
|
|
23
|
-
}
|
|
23
|
+
}
|
|
24
24
|
export declare class EntityLoader {
|
|
25
|
-
private
|
|
26
|
-
private readonly metadata;
|
|
27
|
-
private readonly driver;
|
|
25
|
+
#private;
|
|
28
26
|
constructor(em: EntityManager);
|
|
29
27
|
/**
|
|
30
28
|
* Loads specified relations in batch.
|
|
31
29
|
* This will execute one query for each relation, that will populate it on all the specified entities.
|
|
32
30
|
*/
|
|
33
|
-
populate<Entity extends object, Fields extends string = PopulatePath.ALL>(entityName:
|
|
34
|
-
normalizePopulate<Entity>(entityName:
|
|
31
|
+
populate<Entity extends object, Fields extends string = PopulatePath.ALL>(entityName: EntityName<Entity>, entities: Entity[], populate: PopulateOptions<Entity>[] | boolean, options: EntityLoaderOptions<Entity, Fields>): Promise<void>;
|
|
32
|
+
normalizePopulate<Entity>(entityName: EntityName<Entity>, populate: (PopulateOptions<Entity> | boolean)[] | PopulateOptions<Entity> | boolean, strategy?: LoadStrategy, lookup?: boolean, exclude?: string[]): PopulateOptions<Entity>[];
|
|
35
33
|
private setSerializationContext;
|
|
36
34
|
/**
|
|
37
35
|
* Merge multiple populates for the same entity with different children. Also skips `*` fields, those can come from
|
|
@@ -43,6 +41,7 @@ export declare class EntityLoader {
|
|
|
43
41
|
*/
|
|
44
42
|
private populateMany;
|
|
45
43
|
private populateScalar;
|
|
44
|
+
private populatePolymorphic;
|
|
46
45
|
private initializeCollections;
|
|
47
46
|
private initializeOneToMany;
|
|
48
47
|
private initializeManyToMany;
|