@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
package/metadata/EntitySchema.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const utils_1 = require("../utils");
|
|
9
|
-
const EnumArrayType_1 = require("../types/EnumArrayType");
|
|
10
|
-
class EntitySchema {
|
|
1
|
+
import { EntityMetadata, } from '../typings.js';
|
|
2
|
+
import { BaseEntity } from '../entity/BaseEntity.js';
|
|
3
|
+
import { Cascade, ReferenceKind } from '../enums.js';
|
|
4
|
+
import { Type } from '../types/Type.js';
|
|
5
|
+
import { Utils } from '../utils/Utils.js';
|
|
6
|
+
import { EnumArrayType } from '../types/EnumArrayType.js';
|
|
7
|
+
export class EntitySchema {
|
|
11
8
|
/**
|
|
12
9
|
* When schema links the entity class via `class` option, this registry allows the lookup from opposite side,
|
|
13
10
|
* so we can use the class in `entities` option just like the EntitySchema instance.
|
|
14
11
|
*/
|
|
15
12
|
static REGISTRY = new Map();
|
|
16
|
-
_meta = new
|
|
13
|
+
_meta = new EntityMetadata();
|
|
17
14
|
internal = false;
|
|
18
15
|
initialized = false;
|
|
19
16
|
constructor(meta) {
|
|
@@ -25,7 +22,7 @@ class EntitySchema {
|
|
|
25
22
|
EntitySchema.REGISTRY.set(meta.class, this);
|
|
26
23
|
}
|
|
27
24
|
if (meta.tableName || meta.collection) {
|
|
28
|
-
|
|
25
|
+
Utils.renameKey(meta, 'tableName', 'collection');
|
|
29
26
|
meta.tableName = meta.collection;
|
|
30
27
|
}
|
|
31
28
|
Object.assign(this._meta, { className: meta.name }, meta);
|
|
@@ -37,29 +34,13 @@ class EntitySchema {
|
|
|
37
34
|
return schema;
|
|
38
35
|
}
|
|
39
36
|
addProperty(name, type, options = {}) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
options[to] = [options[from]];
|
|
44
|
-
// @ts-ignore
|
|
45
|
-
delete options[from];
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
if (name !== options.name) {
|
|
49
|
-
utils_1.Utils.renameKey(options, 'name', 'fieldName');
|
|
50
|
-
}
|
|
51
|
-
rename(options, 'fieldName', 'fieldNames');
|
|
52
|
-
rename(options, 'ref', 'ref');
|
|
53
|
-
rename(options, 'joinColumn', 'joinColumns');
|
|
54
|
-
rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
|
|
55
|
-
rename(options, 'referenceColumnName', 'referencedColumnNames');
|
|
56
|
-
rename(options, 'columnType', 'columnTypes');
|
|
57
|
-
const prop = { name, kind: enums_1.ReferenceKind.SCALAR, ...options, type: this.normalizeType(options, type) };
|
|
58
|
-
if (type && types_1.Type.isMappedType(type.prototype)) {
|
|
37
|
+
this.renameCompositeOptions(name, options);
|
|
38
|
+
const prop = { name, kind: ReferenceKind.SCALAR, ...options, type: this.normalizeType(options, type) };
|
|
39
|
+
if (type && Type.isMappedType(type.prototype)) {
|
|
59
40
|
prop.type = type;
|
|
60
41
|
}
|
|
61
|
-
if (
|
|
62
|
-
const formula = prop.formula;
|
|
42
|
+
if (typeof prop.formula === 'string') {
|
|
43
|
+
const formula = prop.formula;
|
|
63
44
|
prop.formula = () => formula;
|
|
64
45
|
}
|
|
65
46
|
if (prop.formula) {
|
|
@@ -69,11 +50,11 @@ class EntitySchema {
|
|
|
69
50
|
}
|
|
70
51
|
addEnum(name, type, options = {}) {
|
|
71
52
|
if (options.items instanceof Function) {
|
|
72
|
-
options.items =
|
|
53
|
+
options.items = Utils.extractEnumValues(options.items());
|
|
73
54
|
}
|
|
74
55
|
// enum arrays are simple numeric/string arrays, the constraint is enforced in the custom type only
|
|
75
56
|
if (options.array && !options.type) {
|
|
76
|
-
options.type = new
|
|
57
|
+
options.type = new EnumArrayType(`${this._meta.className}.${name}`, options.items);
|
|
77
58
|
options.enum = false;
|
|
78
59
|
}
|
|
79
60
|
const prop = { enum: true, ...options };
|
|
@@ -94,22 +75,23 @@ class EntitySchema {
|
|
|
94
75
|
}
|
|
95
76
|
addSerializedPrimaryKey(name, type, options = {}) {
|
|
96
77
|
this._meta.serializedPrimaryKey = name;
|
|
97
|
-
this.addProperty(name, type, options);
|
|
78
|
+
this.addProperty(name, type, { serializedPrimaryKey: true, ...options });
|
|
98
79
|
}
|
|
99
80
|
addEmbedded(name, options) {
|
|
100
|
-
|
|
81
|
+
this.renameCompositeOptions(name, options);
|
|
82
|
+
Utils.defaultValue(options, 'prefix', true);
|
|
101
83
|
if (options.array) {
|
|
102
84
|
options.object = true; // force object mode for arrays
|
|
103
85
|
}
|
|
104
86
|
this._meta.properties[name] = {
|
|
105
87
|
name,
|
|
106
88
|
type: this.normalizeType(options),
|
|
107
|
-
kind:
|
|
89
|
+
kind: ReferenceKind.EMBEDDED,
|
|
108
90
|
...options,
|
|
109
91
|
};
|
|
110
92
|
}
|
|
111
93
|
addManyToOne(name, type, options) {
|
|
112
|
-
const prop = this.createProperty(
|
|
94
|
+
const prop = this.createProperty(ReferenceKind.MANY_TO_ONE, options);
|
|
113
95
|
prop.owner = true;
|
|
114
96
|
if (prop.joinColumns && !prop.fieldNames) {
|
|
115
97
|
prop.fieldNames = prop.joinColumns;
|
|
@@ -117,6 +99,8 @@ class EntitySchema {
|
|
|
117
99
|
if (prop.fieldNames && !prop.joinColumns) {
|
|
118
100
|
prop.joinColumns = prop.fieldNames;
|
|
119
101
|
}
|
|
102
|
+
// By default, the foreign key constraint is created on the relation
|
|
103
|
+
Utils.defaultValue(prop, 'createForeignKeyConstraint', true);
|
|
120
104
|
this.addProperty(name, type, prop);
|
|
121
105
|
}
|
|
122
106
|
addManyToMany(name, type, options) {
|
|
@@ -125,21 +109,27 @@ class EntitySchema {
|
|
|
125
109
|
options.owner = true;
|
|
126
110
|
}
|
|
127
111
|
if (options.owner) {
|
|
128
|
-
|
|
112
|
+
Utils.renameKey(options, 'mappedBy', 'inversedBy');
|
|
113
|
+
// By default, the foreign key constraint is created on the relation
|
|
114
|
+
Utils.defaultValue(options, 'createForeignKeyConstraint', true);
|
|
129
115
|
}
|
|
130
|
-
const prop = this.createProperty(
|
|
116
|
+
const prop = this.createProperty(ReferenceKind.MANY_TO_MANY, options);
|
|
131
117
|
this.addProperty(name, type, prop);
|
|
132
118
|
}
|
|
133
119
|
addOneToMany(name, type, options) {
|
|
134
|
-
const prop = this.createProperty(
|
|
120
|
+
const prop = this.createProperty(ReferenceKind.ONE_TO_MANY, options);
|
|
135
121
|
this.addProperty(name, type, prop);
|
|
136
122
|
}
|
|
137
123
|
addOneToOne(name, type, options) {
|
|
138
|
-
const prop = this.createProperty(
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (prop.owner
|
|
142
|
-
|
|
124
|
+
const prop = this.createProperty(ReferenceKind.ONE_TO_ONE, options);
|
|
125
|
+
Utils.defaultValue(prop, 'owner', !!prop.inversedBy || !prop.mappedBy);
|
|
126
|
+
Utils.defaultValue(prop, 'unique', prop.owner);
|
|
127
|
+
if (prop.owner) {
|
|
128
|
+
if (options.mappedBy) {
|
|
129
|
+
Utils.renameKey(prop, 'mappedBy', 'inversedBy');
|
|
130
|
+
}
|
|
131
|
+
// By default, the foreign key constraint is created on the relation
|
|
132
|
+
Utils.defaultValue(prop, 'createForeignKeyConstraint', true);
|
|
143
133
|
}
|
|
144
134
|
if (prop.joinColumns && !prop.fieldNames) {
|
|
145
135
|
prop.fieldNames = prop.joinColumns;
|
|
@@ -167,14 +157,12 @@ class EntitySchema {
|
|
|
167
157
|
this._meta.prototype = proto.prototype;
|
|
168
158
|
this._meta.className = proto.name;
|
|
169
159
|
if (!sameClass || !this._meta.constructorParams) {
|
|
170
|
-
|
|
171
|
-
this._meta.constructorParams = utils_1.Utils.getParamNames(tokens, 'constructor');
|
|
172
|
-
this._meta.toJsonParams = utils_1.Utils.getParamNames(tokens, 'toJSON').filter(p => p !== '...args');
|
|
160
|
+
this._meta.constructorParams = Utils.getConstructorParams(proto);
|
|
173
161
|
}
|
|
174
162
|
if (!this.internal) {
|
|
175
163
|
EntitySchema.REGISTRY.set(proto, this);
|
|
176
164
|
}
|
|
177
|
-
if (Object.getPrototypeOf(proto) !==
|
|
165
|
+
if (Object.getPrototypeOf(proto) !== BaseEntity) {
|
|
178
166
|
this._meta.extends = this._meta.extends || Object.getPrototypeOf(proto).name || undefined;
|
|
179
167
|
}
|
|
180
168
|
}
|
|
@@ -184,6 +172,12 @@ class EntitySchema {
|
|
|
184
172
|
get name() {
|
|
185
173
|
return this._meta.className;
|
|
186
174
|
}
|
|
175
|
+
get tableName() {
|
|
176
|
+
return this._meta.tableName;
|
|
177
|
+
}
|
|
178
|
+
get properties() {
|
|
179
|
+
return this._meta.properties;
|
|
180
|
+
}
|
|
187
181
|
/**
|
|
188
182
|
* @internal
|
|
189
183
|
*/
|
|
@@ -208,29 +202,29 @@ class EntitySchema {
|
|
|
208
202
|
this.initProperties();
|
|
209
203
|
this.initPrimaryKeys();
|
|
210
204
|
this._meta.props = Object.values(this._meta.properties);
|
|
211
|
-
this._meta.relations = this._meta.props.filter(prop => typeof prop.kind !== 'undefined' && prop.kind !==
|
|
205
|
+
this._meta.relations = this._meta.props.filter(prop => typeof prop.kind !== 'undefined' && prop.kind !== ReferenceKind.SCALAR && prop.kind !== ReferenceKind.EMBEDDED);
|
|
212
206
|
this.initialized = true;
|
|
213
207
|
return this;
|
|
214
208
|
}
|
|
215
209
|
initProperties() {
|
|
216
|
-
|
|
217
|
-
if (
|
|
210
|
+
Utils.entries(this._meta.properties).forEach(([name, options]) => {
|
|
211
|
+
if (Type.isMappedType(options.type)) {
|
|
218
212
|
options.type ??= options.type.constructor.name;
|
|
219
213
|
}
|
|
220
214
|
switch (options.kind) {
|
|
221
|
-
case
|
|
215
|
+
case ReferenceKind.ONE_TO_ONE:
|
|
222
216
|
this.addOneToOne(name, options.type, options);
|
|
223
217
|
break;
|
|
224
|
-
case
|
|
218
|
+
case ReferenceKind.ONE_TO_MANY:
|
|
225
219
|
this.addOneToMany(name, options.type, options);
|
|
226
220
|
break;
|
|
227
|
-
case
|
|
221
|
+
case ReferenceKind.MANY_TO_ONE:
|
|
228
222
|
this.addManyToOne(name, options.type, options);
|
|
229
223
|
break;
|
|
230
|
-
case
|
|
224
|
+
case ReferenceKind.MANY_TO_MANY:
|
|
231
225
|
this.addManyToMany(name, options.type, options);
|
|
232
226
|
break;
|
|
233
|
-
case
|
|
227
|
+
case ReferenceKind.EMBEDDED:
|
|
234
228
|
this.addEmbedded(name, options);
|
|
235
229
|
break;
|
|
236
230
|
default:
|
|
@@ -257,7 +251,7 @@ class EntitySchema {
|
|
|
257
251
|
if (pks.length > 0) {
|
|
258
252
|
this._meta.primaryKeys = pks.map(prop => prop.name);
|
|
259
253
|
this._meta.compositePK = pks.length > 1;
|
|
260
|
-
this._meta.simplePK = !this._meta.compositePK && pks[0].kind ===
|
|
254
|
+
this._meta.simplePK = !this._meta.compositePK && pks[0].kind === ReferenceKind.SCALAR && !pks[0].customType;
|
|
261
255
|
}
|
|
262
256
|
if (pks.length === 1 && ['number', 'bigint'].includes(pks[0].type)) {
|
|
263
257
|
pks[0].autoincrement ??= true;
|
|
@@ -269,12 +263,12 @@ class EntitySchema {
|
|
|
269
263
|
}
|
|
270
264
|
normalizeType(options, type) {
|
|
271
265
|
if ('entity' in options) {
|
|
272
|
-
if (
|
|
266
|
+
if (typeof options.entity === 'string') {
|
|
273
267
|
type = options.type = options.entity;
|
|
274
268
|
}
|
|
275
269
|
else if (options.entity) {
|
|
276
270
|
const tmp = options.entity();
|
|
277
|
-
type = options.type = Array.isArray(tmp) ? tmp.map(t =>
|
|
271
|
+
type = options.type = Array.isArray(tmp) ? tmp.map(t => Utils.className(t)).sort().join(' | ') : Utils.className(tmp);
|
|
278
272
|
}
|
|
279
273
|
}
|
|
280
274
|
if (type instanceof Function) {
|
|
@@ -288,9 +282,29 @@ class EntitySchema {
|
|
|
288
282
|
createProperty(kind, options) {
|
|
289
283
|
return {
|
|
290
284
|
kind,
|
|
291
|
-
cascade: [
|
|
285
|
+
cascade: [Cascade.PERSIST],
|
|
292
286
|
...options,
|
|
293
287
|
};
|
|
294
288
|
}
|
|
289
|
+
rename(data, from, to) {
|
|
290
|
+
if (from in data && !(to in data)) {
|
|
291
|
+
// @ts-ignore
|
|
292
|
+
data[to] = [data[from]];
|
|
293
|
+
// @ts-ignore
|
|
294
|
+
delete data[from];
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
renameCompositeOptions(name, options = {}) {
|
|
298
|
+
if (name !== options.name && !options.fieldNames) {
|
|
299
|
+
Utils.renameKey(options, 'name', 'fieldName');
|
|
300
|
+
}
|
|
301
|
+
else if (options.name && (options.fieldNames?.length ?? 0) > 1) {
|
|
302
|
+
delete options.name;
|
|
303
|
+
}
|
|
304
|
+
this.rename(options, 'fieldName', 'fieldNames');
|
|
305
|
+
this.rename(options, 'joinColumn', 'joinColumns');
|
|
306
|
+
this.rename(options, 'inverseJoinColumn', 'inverseJoinColumns');
|
|
307
|
+
this.rename(options, 'referenceColumnName', 'referencedColumnNames');
|
|
308
|
+
this.rename(options, 'columnType', 'columnTypes');
|
|
309
|
+
}
|
|
295
310
|
}
|
|
296
|
-
exports.EntitySchema = EntitySchema;
|
|
@@ -1,34 +1,33 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type { Configuration } from '../utils/Configuration';
|
|
3
|
-
import { MetadataStorage } from './MetadataStorage';
|
|
4
|
-
import { EntitySchema } from './EntitySchema';
|
|
5
|
-
import type { Platform } from '../platforms';
|
|
1
|
+
import { type EntityClass, EntityMetadata } from '../typings.js';
|
|
2
|
+
import type { Configuration } from '../utils/Configuration.js';
|
|
3
|
+
import { MetadataStorage } from './MetadataStorage.js';
|
|
4
|
+
import { EntitySchema } from './EntitySchema.js';
|
|
5
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
6
6
|
export declare class MetadataDiscovery {
|
|
7
7
|
private readonly metadata;
|
|
8
8
|
private readonly platform;
|
|
9
9
|
private readonly config;
|
|
10
10
|
private readonly namingStrategy;
|
|
11
11
|
private readonly metadataProvider;
|
|
12
|
-
private readonly cache;
|
|
13
12
|
private readonly logger;
|
|
14
13
|
private readonly schemaHelper;
|
|
15
14
|
private readonly validator;
|
|
16
15
|
private readonly discovered;
|
|
17
16
|
constructor(metadata: MetadataStorage, platform: Platform, config: Configuration);
|
|
18
|
-
discover(
|
|
19
|
-
discoverSync(
|
|
17
|
+
discover(preferTs?: boolean): Promise<MetadataStorage>;
|
|
18
|
+
discoverSync(): MetadataStorage;
|
|
19
|
+
validateDiscovered(metadata: EntityMetadata[]): void;
|
|
20
20
|
private mapDiscoveredEntities;
|
|
21
|
+
private initAccessors;
|
|
21
22
|
processDiscoveredEntities(discovered: EntityMetadata[]): EntityMetadata[];
|
|
22
23
|
private findEntities;
|
|
23
24
|
private discoverMissingTargets;
|
|
24
25
|
private tryDiscoverTargets;
|
|
25
|
-
|
|
26
|
-
discoverReferences<T>(refs: (Constructor<T> | EntitySchema<T>)[]): EntityMetadata<T>[];
|
|
26
|
+
discoverReferences<T>(refs: Iterable<EntityClass<T> | EntitySchema<T>>, validate?: boolean): EntityMetadata<T>[];
|
|
27
27
|
reset(className: string): void;
|
|
28
|
-
private prepare;
|
|
29
28
|
private getSchema;
|
|
29
|
+
private getRootEntity;
|
|
30
30
|
private discoverEntity;
|
|
31
|
-
private saveToCache;
|
|
32
31
|
private initNullability;
|
|
33
32
|
private applyNamingStrategy;
|
|
34
33
|
private initOwnColumns;
|
|
@@ -54,7 +53,6 @@ export declare class MetadataDiscovery {
|
|
|
54
53
|
private initAutoincrement;
|
|
55
54
|
private initCheckConstraints;
|
|
56
55
|
private initGeneratedColumn;
|
|
57
|
-
private createColumnMappingObject;
|
|
58
56
|
private getDefaultVersionValue;
|
|
59
57
|
private inferDefaultValue;
|
|
60
58
|
private initDefaultValue;
|
|
@@ -67,6 +65,5 @@ export declare class MetadataDiscovery {
|
|
|
67
65
|
private getPrefix;
|
|
68
66
|
private initUnsigned;
|
|
69
67
|
private initIndexes;
|
|
70
|
-
private getEntityClassOrSchema;
|
|
71
68
|
private shouldForceConstructorUsage;
|
|
72
69
|
}
|