@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,5 +1,5 @@
|
|
|
1
|
-
import type { EntityManager } from '../EntityManager';
|
|
2
|
-
import type { EntityData, EntityDTO, EntityProperty, FromEntityType, IsSubset, MergeSelected } from '../typings';
|
|
1
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
2
|
+
import type { EntityData, EntityDTO, EntityProperty, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
|
|
3
3
|
export declare class EntityAssigner {
|
|
4
4
|
static assign<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(entity: Entity, data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
5
5
|
private static assignProperty;
|
|
@@ -36,7 +36,7 @@ export interface AssignOptions<Convert extends boolean> {
|
|
|
36
36
|
*/
|
|
37
37
|
onlyProperties?: boolean;
|
|
38
38
|
/**
|
|
39
|
-
* With `onlyOwnProperties` enabled, to-many relations are skipped, and payloads of
|
|
39
|
+
* With `onlyOwnProperties` enabled, inverse sides of to-many relations are skipped, and payloads of other relations are converted
|
|
40
40
|
* to foreign keys. Defaults to `false`.
|
|
41
41
|
*/
|
|
42
42
|
onlyOwnProperties?: boolean;
|
package/entity/EntityAssigner.js
CHANGED
|
@@ -1,25 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const wrap_1 = require("./wrap");
|
|
11
|
-
const EntityHelper_1 = require("./EntityHelper");
|
|
12
|
-
const validator = new EntityValidator_1.EntityValidator(false);
|
|
13
|
-
class EntityAssigner {
|
|
1
|
+
import { Collection } from './Collection.js';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
import { Reference } from './Reference.js';
|
|
4
|
+
import { ReferenceKind, SCALAR_TYPES } from '../enums.js';
|
|
5
|
+
import { validateProperty } from './validators.js';
|
|
6
|
+
import { helper, wrap } from './wrap.js';
|
|
7
|
+
import { EntityHelper } from './EntityHelper.js';
|
|
8
|
+
import { ValidationError } from '../errors.js';
|
|
9
|
+
export class EntityAssigner {
|
|
14
10
|
static assign(entity, data, options = {}) {
|
|
15
11
|
let opts = options;
|
|
16
12
|
if (opts.visited?.has(entity)) {
|
|
17
13
|
return entity;
|
|
18
14
|
}
|
|
19
|
-
|
|
15
|
+
EntityHelper.ensurePropagation(entity);
|
|
20
16
|
opts.visited ??= new Set();
|
|
21
17
|
opts.visited.add(entity);
|
|
22
|
-
const wrapped =
|
|
18
|
+
const wrapped = helper(entity);
|
|
23
19
|
opts = {
|
|
24
20
|
...wrapped.__config.get('assign'),
|
|
25
21
|
schema: wrapped.__schema,
|
|
@@ -45,37 +41,45 @@ class EntityAssigner {
|
|
|
45
41
|
}
|
|
46
42
|
const prop = { ...props[propName], name: propName };
|
|
47
43
|
if (prop && options.onlyOwnProperties) {
|
|
48
|
-
if ([
|
|
44
|
+
if ([ReferenceKind.ONE_TO_MANY].includes(prop.kind)) {
|
|
49
45
|
return;
|
|
50
46
|
}
|
|
51
|
-
if ([
|
|
52
|
-
|
|
47
|
+
if ([ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
|
|
48
|
+
if (!prop.owner) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
else if (value?.map) {
|
|
52
|
+
value = value.map((v) => Utils.extractPK(v, prop.targetMeta));
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
|
|
56
|
+
value = Utils.extractPK(value, prop.targetMeta);
|
|
53
57
|
}
|
|
54
58
|
}
|
|
55
59
|
if (propName in props && !prop.nullable && value == null) {
|
|
56
60
|
throw new Error(`You must pass a non-${value} value to the property ${propName} of entity ${entity.constructor.name}.`);
|
|
57
61
|
}
|
|
58
62
|
// create collection instance if its missing so old items can be deleted with orphan removal
|
|
59
|
-
if ([
|
|
60
|
-
entity[prop.name] =
|
|
63
|
+
if ([ReferenceKind.MANY_TO_MANY, ReferenceKind.ONE_TO_MANY].includes(prop?.kind) && entity[prop.name] == null) {
|
|
64
|
+
entity[prop.name] = Collection.create(entity, prop.name, undefined, helper(entity).isInitialized());
|
|
61
65
|
}
|
|
62
|
-
if (prop &&
|
|
66
|
+
if (prop && Utils.isCollection(entity[prop.name])) {
|
|
63
67
|
return EntityAssigner.assignCollection(entity, entity[prop.name], value, prop, options.em, options);
|
|
64
68
|
}
|
|
65
69
|
const customType = prop?.customType;
|
|
66
|
-
if (options.convertCustomTypes && customType && prop.kind ===
|
|
70
|
+
if (options.convertCustomTypes && customType && prop.kind === ReferenceKind.SCALAR && !Utils.isEntity(data)) {
|
|
67
71
|
value = customType.convertToJSValue(value, options.platform);
|
|
68
72
|
}
|
|
69
|
-
if ([
|
|
70
|
-
if (options.updateNestedEntities && Object.hasOwn(entity, propName) &&
|
|
71
|
-
const unwrappedEntity =
|
|
72
|
-
const wrapped =
|
|
73
|
+
if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop?.kind) && value != null) {
|
|
74
|
+
if (options.updateNestedEntities && Object.hasOwn(entity, propName) && Utils.isEntity(entity[propName], true) && Utils.isPlainObject(value)) {
|
|
75
|
+
const unwrappedEntity = Reference.unwrapReference(entity[propName]);
|
|
76
|
+
const wrapped = helper(unwrappedEntity);
|
|
73
77
|
if (options.updateByPrimaryKey) {
|
|
74
|
-
const pk =
|
|
78
|
+
const pk = Utils.extractPK(value, prop.targetMeta);
|
|
75
79
|
if (pk) {
|
|
76
80
|
const ref = options.em.getReference(prop.type, pk, options);
|
|
77
81
|
// if the PK differs, we want to change the target entity, not update it
|
|
78
|
-
const wrappedChild =
|
|
82
|
+
const wrappedChild = helper(ref);
|
|
79
83
|
const sameTarget = wrappedChild.getSerializedPrimaryKey() === wrapped.getSerializedPrimaryKey();
|
|
80
84
|
if (wrappedChild.__managed && wrappedChild.isInitialized() && sameTarget) {
|
|
81
85
|
return EntityAssigner.assign(ref, value, options);
|
|
@@ -83,21 +87,22 @@ class EntityAssigner {
|
|
|
83
87
|
}
|
|
84
88
|
return EntityAssigner.assignReference(entity, value, prop, options.em, options);
|
|
85
89
|
}
|
|
86
|
-
if (wrapped.__managed &&
|
|
90
|
+
if (wrapped.__managed && wrap(unwrappedEntity).isInitialized()) {
|
|
87
91
|
return EntityAssigner.assign(unwrappedEntity, value, options);
|
|
88
92
|
}
|
|
89
93
|
}
|
|
90
94
|
return EntityAssigner.assignReference(entity, value, prop, options.em, options);
|
|
91
95
|
}
|
|
92
|
-
if (prop.kind ===
|
|
93
|
-
|
|
96
|
+
if (prop.kind === ReferenceKind.SCALAR && SCALAR_TYPES.has(prop.runtimeType) && (prop.setter || !prop.getter)) {
|
|
97
|
+
validateProperty(prop, value, entity);
|
|
98
|
+
return entity[prop.name] = value;
|
|
94
99
|
}
|
|
95
|
-
if (prop.kind ===
|
|
100
|
+
if (prop.kind === ReferenceKind.EMBEDDED && EntityAssigner.validateEM(options.em)) {
|
|
96
101
|
return EntityAssigner.assignEmbeddable(entity, value, prop, options.em, options);
|
|
97
102
|
}
|
|
98
|
-
if (options.mergeObjectProperties &&
|
|
103
|
+
if (options.mergeObjectProperties && Utils.isPlainObject(entity[propName]) && Utils.isPlainObject(value)) {
|
|
99
104
|
entity[propName] ??= {};
|
|
100
|
-
entity[propName] =
|
|
105
|
+
entity[propName] = Utils.merge({}, entity[propName], value);
|
|
101
106
|
}
|
|
102
107
|
else if (!prop || prop.setter || !prop.getter) {
|
|
103
108
|
entity[propName] = value;
|
|
@@ -110,18 +115,18 @@ class EntityAssigner {
|
|
|
110
115
|
*/
|
|
111
116
|
static autoWireOneToOne(prop, entity) {
|
|
112
117
|
const ref = entity[prop.name];
|
|
113
|
-
if (prop.kind !==
|
|
118
|
+
if (prop.kind !== ReferenceKind.ONE_TO_ONE || !Utils.isEntity(ref)) {
|
|
114
119
|
return;
|
|
115
120
|
}
|
|
116
|
-
const meta2 =
|
|
121
|
+
const meta2 = helper(ref).__meta;
|
|
117
122
|
const prop2 = meta2.properties[prop.inversedBy || prop.mappedBy];
|
|
118
|
-
/*
|
|
123
|
+
/* v8 ignore next */
|
|
119
124
|
if (prop2 && !ref[prop2.name]) {
|
|
120
|
-
if (
|
|
121
|
-
ref.unwrap()[prop2.name] =
|
|
125
|
+
if (Reference.isReference(ref)) {
|
|
126
|
+
ref.unwrap()[prop2.name] = Reference.wrapReference(entity, prop2);
|
|
122
127
|
}
|
|
123
128
|
else {
|
|
124
|
-
ref[prop2.name] =
|
|
129
|
+
ref[prop2.name] = Reference.wrapReference(entity, prop2);
|
|
125
130
|
}
|
|
126
131
|
}
|
|
127
132
|
}
|
|
@@ -132,17 +137,17 @@ class EntityAssigner {
|
|
|
132
137
|
return true;
|
|
133
138
|
}
|
|
134
139
|
static assignReference(entity, value, prop, em, options) {
|
|
135
|
-
if (
|
|
136
|
-
entity[prop.name] =
|
|
140
|
+
if (Utils.isEntity(value, true)) {
|
|
141
|
+
entity[prop.name] = Reference.wrapReference(value, prop);
|
|
137
142
|
}
|
|
138
|
-
else if (
|
|
139
|
-
entity[prop.name] = prop.mapToPk ? value :
|
|
143
|
+
else if (Utils.isPrimaryKey(value, true) && EntityAssigner.validateEM(em)) {
|
|
144
|
+
entity[prop.name] = prop.mapToPk ? value : Reference.wrapReference(em.getReference(prop.type, value, options), prop);
|
|
140
145
|
}
|
|
141
|
-
else if (
|
|
142
|
-
entity[prop.name] =
|
|
146
|
+
else if (Utils.isPlainObject(value) && options.merge && EntityAssigner.validateEM(em)) {
|
|
147
|
+
entity[prop.name] = Reference.wrapReference(em.merge(prop.type, value, options), prop);
|
|
143
148
|
}
|
|
144
|
-
else if (
|
|
145
|
-
entity[prop.name] =
|
|
149
|
+
else if (Utils.isPlainObject(value) && EntityAssigner.validateEM(em)) {
|
|
150
|
+
entity[prop.name] = Reference.wrapReference(em.create(prop.type, value, options), prop);
|
|
146
151
|
}
|
|
147
152
|
else {
|
|
148
153
|
const name = entity.constructor.name;
|
|
@@ -152,32 +157,31 @@ class EntityAssigner {
|
|
|
152
157
|
}
|
|
153
158
|
static assignCollection(entity, collection, value, prop, em, options) {
|
|
154
159
|
const invalid = [];
|
|
155
|
-
const items =
|
|
160
|
+
const items = Utils.asArray(value).map((item, idx) => {
|
|
156
161
|
// try to propagate missing owning side reference to the payload first
|
|
157
162
|
const prop2 = prop.targetMeta?.properties[prop.mappedBy];
|
|
158
|
-
if (
|
|
159
|
-
item = { ...item, [prop2.name]:
|
|
163
|
+
if (Utils.isPlainObject(item) && prop2 && item[prop2.name] == null) {
|
|
164
|
+
item = { ...item, [prop2.name]: Reference.wrapReference(entity, prop2) };
|
|
160
165
|
}
|
|
161
|
-
if (options.updateNestedEntities && options.updateByPrimaryKey &&
|
|
162
|
-
const pk =
|
|
166
|
+
if (options.updateNestedEntities && options.updateByPrimaryKey && Utils.isPlainObject(item)) {
|
|
167
|
+
const pk = Utils.extractPK(item, prop.targetMeta);
|
|
163
168
|
if (pk && EntityAssigner.validateEM(em)) {
|
|
164
169
|
const ref = em.getUnitOfWork().getById(prop.type, pk, options.schema);
|
|
165
|
-
/* istanbul ignore else */
|
|
166
170
|
if (ref) {
|
|
167
171
|
return EntityAssigner.assign(ref, item, options);
|
|
168
172
|
}
|
|
169
173
|
}
|
|
170
174
|
return this.createCollectionItem(item, em, prop, invalid, options);
|
|
171
175
|
}
|
|
172
|
-
/*
|
|
173
|
-
if (options.updateNestedEntities && !options.updateByPrimaryKey && collection[idx] &&
|
|
176
|
+
/* v8 ignore next */
|
|
177
|
+
if (options.updateNestedEntities && !options.updateByPrimaryKey && collection[idx] && helper(collection[idx])?.isInitialized()) {
|
|
174
178
|
return EntityAssigner.assign(collection[idx], item, options);
|
|
175
179
|
}
|
|
176
180
|
return this.createCollectionItem(item, em, prop, invalid, options);
|
|
177
181
|
});
|
|
178
182
|
if (invalid.length > 0) {
|
|
179
183
|
const name = entity.constructor.name;
|
|
180
|
-
throw
|
|
184
|
+
throw ValidationError.invalidCollectionValues(name, prop.name, invalid);
|
|
181
185
|
}
|
|
182
186
|
if (Array.isArray(value)) {
|
|
183
187
|
collection.set(items);
|
|
@@ -197,7 +201,7 @@ class EntityAssigner {
|
|
|
197
201
|
entity[propName] = [];
|
|
198
202
|
}
|
|
199
203
|
if (prop.array) {
|
|
200
|
-
return
|
|
204
|
+
return Utils.asArray(value).forEach(item => {
|
|
201
205
|
const tmp = {};
|
|
202
206
|
this.assignEmbeddable(tmp, item, { ...prop, array: false }, em, options);
|
|
203
207
|
entity[propName].push(...Object.values(tmp));
|
|
@@ -213,21 +217,20 @@ class EntityAssigner {
|
|
|
213
217
|
});
|
|
214
218
|
}
|
|
215
219
|
static createCollectionItem(item, em, prop, invalid, options) {
|
|
216
|
-
if (
|
|
220
|
+
if (Utils.isEntity(item)) {
|
|
217
221
|
return item;
|
|
218
222
|
}
|
|
219
|
-
if (
|
|
223
|
+
if (Utils.isPrimaryKey(item) && EntityAssigner.validateEM(em)) {
|
|
220
224
|
return em.getReference(prop.type, item, options);
|
|
221
225
|
}
|
|
222
|
-
if (
|
|
226
|
+
if (Utils.isPlainObject(item) && options.merge && EntityAssigner.validateEM(em)) {
|
|
223
227
|
return em.merge(prop.type, item, options);
|
|
224
228
|
}
|
|
225
|
-
if (
|
|
229
|
+
if (Utils.isPlainObject(item) && EntityAssigner.validateEM(em)) {
|
|
226
230
|
return em.create(prop.type, item, options);
|
|
227
231
|
}
|
|
228
232
|
invalid.push(item);
|
|
229
233
|
return item;
|
|
230
234
|
}
|
|
231
235
|
}
|
|
232
|
-
|
|
233
|
-
exports.assign = EntityAssigner.assign;
|
|
236
|
+
export const assign = EntityAssigner.assign;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
|
-
import type { EntityData, EntityMetadata, EntityName, New, Primary } from '../typings';
|
|
2
|
-
import type { EntityManager } from '../EntityManager';
|
|
3
|
-
import type { EntityComparator } from '../utils/EntityComparator';
|
|
1
|
+
import type { EntityData, EntityMetadata, EntityName, New, Primary } from '../typings.js';
|
|
2
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
3
|
+
import type { EntityComparator } from '../utils/EntityComparator.js';
|
|
4
4
|
export interface FactoryOptions {
|
|
5
5
|
initialized?: boolean;
|
|
6
6
|
newEntity?: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Property `onCreate` hooks are normally executed during `flush` operation.
|
|
9
|
+
* With this option, they will be processed early inside `em.create()` method.
|
|
10
|
+
*/
|
|
11
|
+
processOnCreateHooksEarly?: boolean;
|
|
7
12
|
merge?: boolean;
|
|
8
13
|
refresh?: boolean;
|
|
9
14
|
convertCustomTypes?: boolean;
|
|
10
15
|
recomputeSnapshot?: boolean;
|
|
11
16
|
schema?: string;
|
|
12
17
|
parentSchema?: string;
|
|
18
|
+
normalizeAccessors?: boolean;
|
|
13
19
|
}
|
|
14
20
|
export declare class EntityFactory {
|
|
15
21
|
private readonly em;
|
|
@@ -27,6 +33,7 @@ export declare class EntityFactory {
|
|
|
27
33
|
createEmbeddable<T extends object>(entityName: EntityName<T>, data: EntityData<T>, options?: Pick<FactoryOptions, 'newEntity' | 'convertCustomTypes'>): T;
|
|
28
34
|
getComparator(): EntityComparator;
|
|
29
35
|
private createEntity;
|
|
36
|
+
private assignDefaultValues;
|
|
30
37
|
private hydrate;
|
|
31
38
|
private findEntity;
|
|
32
39
|
private processDiscriminatorColumn;
|