@mikro-orm/core 7.0.0-dev.21 → 7.0.0-dev.210
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 +99 -57
- package/EntityManager.js +302 -276
- package/MikroORM.d.ts +44 -35
- package/MikroORM.js +103 -143
- package/README.md +3 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +8 -7
- package/cache/GeneratedCacheAdapter.d.ts +0 -1
- package/cache/GeneratedCacheAdapter.js +0 -2
- package/cache/index.d.ts +0 -1
- package/cache/index.js +0 -1
- package/connections/Connection.d.ts +16 -7
- package/connections/Connection.js +23 -14
- package/drivers/DatabaseDriver.d.ts +25 -16
- package/drivers/DatabaseDriver.js +80 -35
- package/drivers/IDatabaseDriver.d.ts +44 -17
- package/entity/BaseEntity.d.ts +2 -2
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +94 -29
- package/entity/Collection.js +434 -97
- package/entity/EntityAssigner.d.ts +1 -1
- package/entity/EntityAssigner.js +26 -18
- package/entity/EntityFactory.d.ts +13 -1
- package/entity/EntityFactory.js +84 -53
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +35 -15
- package/entity/EntityLoader.d.ts +6 -6
- package/entity/EntityLoader.js +119 -82
- package/entity/EntityRepository.d.ts +24 -4
- package/entity/EntityRepository.js +8 -2
- package/entity/Reference.d.ts +6 -5
- package/entity/Reference.js +34 -9
- package/entity/WrappedEntity.d.ts +2 -7
- package/entity/WrappedEntity.js +3 -8
- package/entity/defineEntity.d.ts +594 -0
- package/entity/defineEntity.js +533 -0
- package/entity/index.d.ts +3 -2
- package/entity/index.js +3 -2
- package/entity/utils.d.ts +7 -0
- package/entity/utils.js +16 -4
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/enums.d.ts +21 -5
- package/enums.js +15 -1
- package/errors.d.ts +23 -9
- package/errors.js +59 -21
- package/events/EventManager.d.ts +2 -1
- package/events/EventManager.js +19 -11
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +4 -4
- package/hydration/ObjectHydrator.js +52 -33
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +1 -0
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +7 -6
- package/logging/index.d.ts +1 -0
- package/logging/index.js +1 -0
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +40 -23
- package/metadata/EntitySchema.js +81 -34
- package/metadata/MetadataDiscovery.d.ts +7 -10
- package/metadata/MetadataDiscovery.js +391 -331
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +46 -2
- package/metadata/MetadataStorage.d.ts +13 -11
- package/metadata/MetadataStorage.js +70 -37
- package/metadata/MetadataValidator.d.ts +17 -9
- package/metadata/MetadataValidator.js +97 -40
- 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 +1 -1
- package/metadata/types.d.ts +502 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +12 -4
- package/naming-strategy/AbstractNamingStrategy.js +14 -2
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +24 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +18 -11
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +7 -13
- package/platforms/Platform.js +20 -43
- package/serialization/EntitySerializer.d.ts +5 -0
- package/serialization/EntitySerializer.js +47 -27
- package/serialization/EntityTransformer.js +28 -18
- package/serialization/SerializationContext.d.ts +6 -6
- package/serialization/SerializationContext.js +16 -13
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.d.ts +8 -6
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +2 -1
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.d.ts +6 -4
- package/types/DecimalType.js +3 -3
- package/types/DoubleType.js +2 -2
- 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/index.d.ts +1 -1
- package/typings.d.ts +290 -137
- package/typings.js +59 -44
- package/unit-of-work/ChangeSet.d.ts +2 -6
- package/unit-of-work/ChangeSet.js +4 -5
- package/unit-of-work/ChangeSetComputer.d.ts +1 -3
- package/unit-of-work/ChangeSetComputer.js +26 -13
- package/unit-of-work/ChangeSetPersister.d.ts +5 -4
- package/unit-of-work/ChangeSetPersister.js +70 -34
- package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
- package/unit-of-work/CommitOrderCalculator.js +13 -13
- package/unit-of-work/IdentityMap.d.ts +12 -0
- package/unit-of-work/IdentityMap.js +39 -1
- package/unit-of-work/UnitOfWork.d.ts +23 -3
- package/unit-of-work/UnitOfWork.js +175 -98
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +18 -16
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +785 -207
- package/utils/Configuration.js +147 -190
- package/utils/ConfigurationLoader.d.ts +1 -54
- package/utils/ConfigurationLoader.js +1 -352
- package/utils/Cursor.d.ts +0 -3
- package/utils/Cursor.js +27 -11
- package/utils/DataloaderUtils.d.ts +15 -5
- package/utils/DataloaderUtils.js +64 -30
- package/utils/EntityComparator.d.ts +13 -9
- package/utils/EntityComparator.js +101 -42
- package/utils/QueryHelper.d.ts +14 -6
- package/utils/QueryHelper.js +87 -25
- package/utils/RawQueryFragment.d.ts +48 -25
- package/utils/RawQueryFragment.js +66 -70
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +13 -126
- package/utils/Utils.js +100 -391
- package/utils/clone.js +8 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +97 -0
- package/utils/fs-utils.d.ts +32 -0
- package/utils/fs-utils.js +178 -0
- package/utils/index.d.ts +2 -1
- package/utils/index.js +2 -1
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +55 -4
- 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 -18
- 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 -40
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -32
- 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 -26
- 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 -13
- 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 -116
- package/entity/ArrayCollection.js +0 -402
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/exports.d.ts +0 -24
- package/exports.js +0 -23
- 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
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
import { ReferenceKind } from '../enums.js';
|
|
2
|
-
import { Utils } from '../utils/Utils.js';
|
|
3
|
-
import { ValidationError } from '../errors.js';
|
|
4
|
-
import { helper } from './wrap.js';
|
|
5
|
-
import { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
6
|
-
export class EntityValidator {
|
|
7
|
-
strict;
|
|
8
|
-
KNOWN_TYPES = new Set(['string', 'number', 'boolean', 'bigint', 'Uint8Array', 'Date', 'Buffer', 'RegExp']);
|
|
9
|
-
constructor(strict) {
|
|
10
|
-
this.strict = strict;
|
|
11
|
-
}
|
|
12
|
-
validate(entity, payload, meta) {
|
|
13
|
-
meta.props.forEach(prop => {
|
|
14
|
-
if (prop.inherited) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
if ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind)) {
|
|
18
|
-
this.validateCollection(entity, prop);
|
|
19
|
-
}
|
|
20
|
-
const SCALAR_TYPES = ['string', 'number', 'boolean', 'Date'];
|
|
21
|
-
if (prop.kind !== ReferenceKind.SCALAR || !SCALAR_TYPES.includes(prop.type)) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
|
-
const newValue = this.validateProperty(prop, this.getValue(payload, prop), entity);
|
|
25
|
-
if (this.getValue(payload, prop) === newValue) {
|
|
26
|
-
return;
|
|
27
|
-
}
|
|
28
|
-
this.setValue(payload, prop, newValue);
|
|
29
|
-
if (entity[prop.name]) {
|
|
30
|
-
entity[prop.name] = payload[prop.name];
|
|
31
|
-
}
|
|
32
|
-
});
|
|
33
|
-
}
|
|
34
|
-
validateRequired(entity) {
|
|
35
|
-
const wrapped = helper(entity);
|
|
36
|
-
for (const prop of wrapped.__meta.props) {
|
|
37
|
-
if (!prop.nullable &&
|
|
38
|
-
!prop.autoincrement &&
|
|
39
|
-
!prop.default &&
|
|
40
|
-
!prop.defaultRaw &&
|
|
41
|
-
!prop.onCreate &&
|
|
42
|
-
!prop.generated &&
|
|
43
|
-
!prop.embedded &&
|
|
44
|
-
![ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind) &&
|
|
45
|
-
prop.name !== wrapped.__meta.root.discriminatorColumn &&
|
|
46
|
-
prop.type.toLowerCase() !== 'objectid' &&
|
|
47
|
-
prop.persist !== false &&
|
|
48
|
-
entity[prop.name] == null) {
|
|
49
|
-
throw ValidationError.propertyRequired(entity, prop);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
validateProperty(prop, givenValue, entity) {
|
|
54
|
-
if (givenValue == null || givenValue instanceof RawQueryFragment) {
|
|
55
|
-
return givenValue;
|
|
56
|
-
}
|
|
57
|
-
const expectedType = prop.runtimeType;
|
|
58
|
-
const propName = prop.embedded ? prop.name.replace(/~/g, '.') : prop.name;
|
|
59
|
-
let givenType = Utils.getObjectType(givenValue);
|
|
60
|
-
let ret = givenValue;
|
|
61
|
-
if (!this.strict) {
|
|
62
|
-
ret = this.fixTypes(expectedType, givenType, givenValue);
|
|
63
|
-
givenType = Utils.getObjectType(ret);
|
|
64
|
-
}
|
|
65
|
-
if (prop.enum && prop.items) {
|
|
66
|
-
/* v8 ignore next 3 */
|
|
67
|
-
if (!prop.items.some(it => it === givenValue)) {
|
|
68
|
-
throw ValidationError.fromWrongPropertyType(entity, propName, expectedType, givenType, givenValue);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
else {
|
|
72
|
-
if (givenType !== expectedType && this.KNOWN_TYPES.has(expectedType)) {
|
|
73
|
-
throw ValidationError.fromWrongPropertyType(entity, propName, expectedType, givenType, givenValue);
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
return ret;
|
|
77
|
-
}
|
|
78
|
-
validateParams(params, type = 'search condition', field) {
|
|
79
|
-
if (Utils.isPrimaryKey(params) || Utils.isEntity(params)) {
|
|
80
|
-
return;
|
|
81
|
-
}
|
|
82
|
-
if (Array.isArray(params)) {
|
|
83
|
-
return params.forEach(item => this.validateParams(item, type, field));
|
|
84
|
-
}
|
|
85
|
-
if (Utils.isPlainObject(params)) {
|
|
86
|
-
Object.keys(params).forEach(k => {
|
|
87
|
-
this.validateParams(params[k], type, k);
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
validatePrimaryKey(entity, meta) {
|
|
92
|
-
const pkExists = meta.primaryKeys.every(pk => entity[pk] != null) || entity[meta.serializedPrimaryKey] != null;
|
|
93
|
-
if (!entity || !pkExists) {
|
|
94
|
-
throw ValidationError.fromMergeWithoutPK(meta);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
validateEmptyWhere(where) {
|
|
98
|
-
if (Utils.isEmpty(where)) {
|
|
99
|
-
throw new Error(`You cannot call 'EntityManager.findOne()' with empty 'where' parameter`);
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
getValue(o, prop) {
|
|
103
|
-
if (prop.embedded && prop.embedded[0] in o) {
|
|
104
|
-
return o[prop.embedded[0]]?.[prop.embedded[1]];
|
|
105
|
-
}
|
|
106
|
-
return o[prop.name];
|
|
107
|
-
}
|
|
108
|
-
setValue(o, prop, v) {
|
|
109
|
-
/* v8 ignore next 3 */
|
|
110
|
-
if (prop.embedded && prop.embedded[0] in o) {
|
|
111
|
-
return o[prop.embedded[0]][prop.embedded[1]] = v;
|
|
112
|
-
}
|
|
113
|
-
o[prop.name] = v;
|
|
114
|
-
}
|
|
115
|
-
validateCollection(entity, prop) {
|
|
116
|
-
if (prop.hydrate !== false && helper(entity).__initialized && !entity[prop.name]) {
|
|
117
|
-
throw ValidationError.fromCollectionNotInitialized(entity, prop);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
fixTypes(expectedType, givenType, givenValue) {
|
|
121
|
-
if (expectedType === 'Date' && ['string', 'number'].includes(givenType)) {
|
|
122
|
-
givenValue = this.fixDateType(givenValue);
|
|
123
|
-
}
|
|
124
|
-
if (expectedType === 'number' && givenType === 'string') {
|
|
125
|
-
givenValue = this.fixNumberType(givenValue);
|
|
126
|
-
}
|
|
127
|
-
if (expectedType === 'boolean' && givenType === 'number') {
|
|
128
|
-
givenValue = this.fixBooleanType(givenValue);
|
|
129
|
-
}
|
|
130
|
-
return givenValue;
|
|
131
|
-
}
|
|
132
|
-
fixDateType(givenValue) {
|
|
133
|
-
let date;
|
|
134
|
-
if (Utils.isString(givenValue) && givenValue.match(/^-?\d+(\.\d+)?$/)) {
|
|
135
|
-
date = new Date(+givenValue);
|
|
136
|
-
}
|
|
137
|
-
else {
|
|
138
|
-
date = new Date(givenValue);
|
|
139
|
-
}
|
|
140
|
-
return date.toString() !== 'Invalid Date' ? date : givenValue;
|
|
141
|
-
}
|
|
142
|
-
fixNumberType(givenValue) {
|
|
143
|
-
const num = +givenValue;
|
|
144
|
-
return '' + num === givenValue ? num : givenValue;
|
|
145
|
-
}
|
|
146
|
-
fixBooleanType(givenValue) {
|
|
147
|
-
const bool = !!givenValue;
|
|
148
|
-
return +bool === givenValue ? bool : givenValue;
|
|
149
|
-
}
|
|
150
|
-
}
|
package/exports.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
* @module core
|
|
4
|
-
*/
|
|
5
|
-
export { Constructor, ConnectionType, Dictionary, PrimaryKeyProp, Primary, IPrimaryKey, ObjectQuery, FilterQuery, IWrappedEntity, EntityName, EntityData, Highlighter, MaybePromise, AnyEntity, EntityClass, EntityProperty, EntityMetadata, QBFilterQuery, PopulateOptions, Populate, Loaded, New, LoadedReference, LoadedCollection, IMigrator, IMigrationGenerator, MigratorEvent, GetRepository, EntityRepositoryType, MigrationObject, DeepPartial, PrimaryProperty, Cast, IsUnknown, EntityDictionary, EntityDTO, MigrationDiff, GenerateOptions, FilterObject, IEntityGenerator, ISeedManager, EntityClassGroup, OptionalProps, EagerProps, HiddenProps, RequiredEntityData, CheckCallback, SimpleColumnMeta, Rel, Ref, ScalarRef, EntityRef, ISchemaGenerator, UmzugMigration, MigrateOptions, MigrationResult, MigrationRow, EntityKey, EntityValue, EntityDataValue, FilterKey, Opt, EntityType, FromEntityType, Selected, IsSubset, NoInfer, EntityProps, ExpandProperty, ExpandScalar, FilterItemValue, ExpandQuery, Scalar, ExpandHint, Hidden, FilterValue, MergeLoaded, MergeSelected, Config, DefineConfig, TypeConfig, ClearDatabaseOptions, CreateSchemaOptions, EnsureDatabaseOptions, UpdateSchemaOptions, DropSchemaOptions, RefreshDatabaseOptions, AutoPath, UnboxArray, MetadataProcessor, ImportsResolver, } from './typings.js';
|
|
6
|
-
export * from './enums.js';
|
|
7
|
-
export * from './errors.js';
|
|
8
|
-
export * from './exceptions.js';
|
|
9
|
-
export * from './entity/index.js';
|
|
10
|
-
export * from './serialization/index.js';
|
|
11
|
-
export * from './events/index.js';
|
|
12
|
-
export { CreateOptions, MergeOptions, ForkOptions } from './EntityManager.js';
|
|
13
|
-
export * from './unit-of-work/index.js';
|
|
14
|
-
export * from './utils/index.js';
|
|
15
|
-
export * from './logging/index.js';
|
|
16
|
-
export * from './hydration/index.js';
|
|
17
|
-
export * from './drivers/index.js';
|
|
18
|
-
export * from './connections/index.js';
|
|
19
|
-
export * from './platforms/index.js';
|
|
20
|
-
export * from './types/index.js';
|
|
21
|
-
export * from './naming-strategy/index.js';
|
|
22
|
-
export * from './metadata/index.js';
|
|
23
|
-
export * from './cache/index.js';
|
|
24
|
-
export * from './decorators/index.js';
|
package/exports.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @packageDocumentation
|
|
3
|
-
* @module core
|
|
4
|
-
*/
|
|
5
|
-
export { PrimaryKeyProp, EntityMetadata, EntityRepositoryType, OptionalProps, EagerProps, HiddenProps, Config, } from './typings.js';
|
|
6
|
-
export * from './enums.js';
|
|
7
|
-
export * from './errors.js';
|
|
8
|
-
export * from './exceptions.js';
|
|
9
|
-
export * from './entity/index.js';
|
|
10
|
-
export * from './serialization/index.js';
|
|
11
|
-
export * from './events/index.js';
|
|
12
|
-
export * from './unit-of-work/index.js';
|
|
13
|
-
export * from './utils/index.js';
|
|
14
|
-
export * from './logging/index.js';
|
|
15
|
-
export * from './hydration/index.js';
|
|
16
|
-
export * from './drivers/index.js';
|
|
17
|
-
export * from './connections/index.js';
|
|
18
|
-
export * from './platforms/index.js';
|
|
19
|
-
export * from './types/index.js';
|
|
20
|
-
export * from './naming-strategy/index.js';
|
|
21
|
-
export * from './metadata/index.js';
|
|
22
|
-
export * from './cache/index.js';
|
|
23
|
-
export * from './decorators/index.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import type { EntityMetadata, EntityProperty } from '../typings.js';
|
|
3
|
-
import { MetadataProvider } from './MetadataProvider.js';
|
|
4
|
-
export declare class ReflectMetadataProvider extends MetadataProvider {
|
|
5
|
-
loadEntityMetadata(meta: EntityMetadata, name: string): void;
|
|
6
|
-
protected initProperties(meta: EntityMetadata): void;
|
|
7
|
-
protected initPropertyType(meta: EntityMetadata, prop: EntityProperty): void;
|
|
8
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import 'reflect-metadata';
|
|
2
|
-
import { MetadataProvider } from './MetadataProvider.js';
|
|
3
|
-
import { ReferenceKind } from '../enums.js';
|
|
4
|
-
import { Utils } from '../utils/Utils.js';
|
|
5
|
-
export class ReflectMetadataProvider extends MetadataProvider {
|
|
6
|
-
loadEntityMetadata(meta, name) {
|
|
7
|
-
this.initProperties(meta);
|
|
8
|
-
}
|
|
9
|
-
initProperties(meta) {
|
|
10
|
-
// load types and column names
|
|
11
|
-
for (const prop of meta.props) {
|
|
12
|
-
if (typeof prop.entity === 'string') {
|
|
13
|
-
prop.type = prop.entity;
|
|
14
|
-
}
|
|
15
|
-
else if (prop.entity) {
|
|
16
|
-
const tmp = prop.entity();
|
|
17
|
-
prop.type = Array.isArray(tmp) ? tmp.map(t => Utils.className(t)).sort().join(' | ') : Utils.className(tmp);
|
|
18
|
-
}
|
|
19
|
-
else {
|
|
20
|
-
this.initPropertyType(meta, prop);
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
initPropertyType(meta, prop) {
|
|
25
|
-
const type = Reflect.getMetadata('design:type', meta.prototype, prop.name);
|
|
26
|
-
if (!prop.type && (!type || (type === Object && prop.kind !== ReferenceKind.SCALAR)) && !(prop.enum && (prop.items?.length ?? 0) > 0)) {
|
|
27
|
-
throw new Error(`Please provide either 'type' or 'entity' attribute in ${meta.className}.${prop.name}. If you are using decorators, ensure you have 'emitDecoratorMetadata' enabled in your tsconfig.json.`);
|
|
28
|
-
}
|
|
29
|
-
// Force mapping to UnknownType which is a string when we see just `Object`, as that often means failed inference.
|
|
30
|
-
// This is to prevent defaulting to JSON column type, which can often be hard to revert and cause hard to understand issues with PKs.
|
|
31
|
-
// If there are explicitly provided `columnTypes`, we use those instead for the inference, this way
|
|
32
|
-
// we can have things like `columnType: 'timestamp'` be respected as `type: 'Date'`.
|
|
33
|
-
if (prop.kind === ReferenceKind.SCALAR && type === Object && !prop.columnTypes) {
|
|
34
|
-
prop.type ??= 'any';
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
let typeName = type?.name;
|
|
38
|
-
if (typeName && ['string', 'number', 'boolean', 'array', 'object'].includes(typeName.toLowerCase())) {
|
|
39
|
-
typeName = typeName.toLowerCase();
|
|
40
|
-
}
|
|
41
|
-
prop.type ??= typeName;
|
|
42
|
-
prop.runtimeType ??= typeName;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { EntityManager } from '../EntityManager.js';
|
|
2
|
-
import { MikroORM } from '../MikroORM.js';
|
|
3
|
-
import type { ContextProvider, MaybePromise } from '../typings.js';
|
|
4
|
-
/**
|
|
5
|
-
* Find `EntityManager` in provided context, or else in instance's `orm` or `em` properties.
|
|
6
|
-
*/
|
|
7
|
-
export declare function resolveContextProvider<T>(caller: T & {
|
|
8
|
-
orm?: MaybePromise<MikroORM>;
|
|
9
|
-
em?: MaybePromise<EntityManager>;
|
|
10
|
-
}, provider?: ContextProvider<T>): Promise<EntityManager | undefined>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { EntityRepository } from '../entity/EntityRepository.js';
|
|
2
|
-
import { EntityManager } from '../EntityManager.js';
|
|
3
|
-
import { MikroORM } from '../MikroORM.js';
|
|
4
|
-
function getEntityManager(caller, context) {
|
|
5
|
-
if (context instanceof EntityManager) {
|
|
6
|
-
return context;
|
|
7
|
-
}
|
|
8
|
-
if (context instanceof EntityRepository) {
|
|
9
|
-
return context.getEntityManager();
|
|
10
|
-
}
|
|
11
|
-
if (context instanceof MikroORM) {
|
|
12
|
-
return context.em;
|
|
13
|
-
}
|
|
14
|
-
if (caller.em instanceof EntityManager) {
|
|
15
|
-
return caller.em;
|
|
16
|
-
}
|
|
17
|
-
if (caller.orm instanceof MikroORM) {
|
|
18
|
-
return caller.orm.em;
|
|
19
|
-
}
|
|
20
|
-
return undefined;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Find `EntityManager` in provided context, or else in instance's `orm` or `em` properties.
|
|
24
|
-
*/
|
|
25
|
-
export async function resolveContextProvider(caller, provider) {
|
|
26
|
-
const context = typeof provider === 'function' ? await provider(caller) : await provider;
|
|
27
|
-
return getEntityManager({ orm: await caller.orm, em: await caller.em }, context);
|
|
28
|
-
}
|