@mikro-orm/core 7.0.4-dev.9 → 7.0.4
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 +884 -583
- package/EntityManager.js +1922 -1895
- package/MikroORM.d.ts +103 -74
- package/MikroORM.js +178 -179
- package/README.md +1 -1
- package/cache/CacheAdapter.d.ts +36 -36
- package/cache/FileCacheAdapter.d.ts +30 -24
- package/cache/FileCacheAdapter.js +80 -78
- package/cache/GeneratedCacheAdapter.d.ts +18 -20
- package/cache/GeneratedCacheAdapter.js +30 -30
- package/cache/MemoryCacheAdapter.d.ts +18 -20
- package/cache/MemoryCacheAdapter.js +35 -36
- package/cache/NullCacheAdapter.d.ts +16 -16
- package/cache/NullCacheAdapter.js +24 -24
- package/connections/Connection.d.ts +95 -84
- package/connections/Connection.js +165 -168
- package/drivers/DatabaseDriver.d.ts +186 -80
- package/drivers/DatabaseDriver.js +450 -443
- package/drivers/IDatabaseDriver.d.ts +440 -301
- package/entity/BaseEntity.d.ts +120 -83
- package/entity/BaseEntity.js +43 -43
- package/entity/Collection.d.ts +212 -179
- package/entity/Collection.js +727 -721
- package/entity/EntityAssigner.d.ts +88 -77
- package/entity/EntityAssigner.js +231 -230
- package/entity/EntityFactory.d.ts +66 -54
- package/entity/EntityFactory.js +425 -383
- package/entity/EntityHelper.d.ts +34 -22
- package/entity/EntityHelper.js +280 -267
- package/entity/EntityIdentifier.d.ts +4 -4
- package/entity/EntityIdentifier.js +10 -10
- package/entity/EntityLoader.d.ts +98 -72
- package/entity/EntityLoader.js +753 -723
- package/entity/EntityRepository.d.ts +316 -201
- package/entity/EntityRepository.js +213 -213
- package/entity/PolymorphicRef.d.ts +5 -5
- package/entity/PolymorphicRef.js +10 -10
- package/entity/Reference.d.ts +126 -82
- package/entity/Reference.js +278 -274
- package/entity/WrappedEntity.d.ts +115 -72
- package/entity/WrappedEntity.js +168 -166
- package/entity/defineEntity.d.ts +1315 -636
- package/entity/defineEntity.js +527 -518
- package/entity/utils.d.ts +13 -3
- package/entity/utils.js +71 -73
- package/entity/validators.js +43 -43
- package/entity/wrap.js +8 -8
- package/enums.d.ts +258 -253
- package/enums.js +251 -252
- package/errors.d.ts +114 -72
- package/errors.js +350 -253
- package/events/EventManager.d.ts +26 -14
- package/events/EventManager.js +79 -77
- package/events/EventSubscriber.d.ts +29 -29
- package/events/TransactionEventBroadcaster.d.ts +15 -8
- package/events/TransactionEventBroadcaster.js +14 -14
- package/exceptions.d.ts +23 -40
- package/exceptions.js +35 -52
- package/hydration/Hydrator.d.ts +42 -17
- package/hydration/Hydrator.js +43 -43
- package/hydration/ObjectHydrator.d.ts +50 -17
- package/hydration/ObjectHydrator.js +481 -416
- package/index.d.ts +116 -2
- package/index.js +10 -1
- package/logging/DefaultLogger.d.ts +34 -32
- package/logging/DefaultLogger.js +86 -86
- package/logging/Logger.d.ts +41 -41
- package/logging/SimpleLogger.d.ts +13 -11
- package/logging/SimpleLogger.js +22 -22
- package/logging/colors.d.ts +6 -6
- package/logging/colors.js +11 -10
- package/logging/inspect.js +7 -7
- package/metadata/EntitySchema.d.ts +211 -127
- package/metadata/EntitySchema.js +397 -398
- package/metadata/MetadataDiscovery.d.ts +114 -114
- package/metadata/MetadataDiscovery.js +1951 -1863
- package/metadata/MetadataProvider.d.ts +24 -21
- package/metadata/MetadataProvider.js +82 -84
- package/metadata/MetadataStorage.d.ts +38 -32
- package/metadata/MetadataStorage.js +118 -118
- package/metadata/MetadataValidator.d.ts +39 -39
- package/metadata/MetadataValidator.js +381 -338
- package/metadata/discover-entities.d.ts +5 -2
- package/metadata/discover-entities.js +35 -27
- package/metadata/types.d.ts +615 -531
- package/naming-strategy/AbstractNamingStrategy.d.ts +54 -39
- package/naming-strategy/AbstractNamingStrategy.js +90 -85
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
- package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
- package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
- package/naming-strategy/MongoNamingStrategy.js +18 -18
- package/naming-strategy/NamingStrategy.d.ts +109 -99
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
- package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
- package/not-supported.js +7 -4
- package/package.json +1 -1
- package/platforms/ExceptionConverter.d.ts +1 -1
- package/platforms/ExceptionConverter.js +4 -4
- package/platforms/Platform.d.ts +310 -299
- package/platforms/Platform.js +663 -636
- package/serialization/EntitySerializer.d.ts +49 -26
- package/serialization/EntitySerializer.js +224 -218
- package/serialization/EntityTransformer.d.ts +10 -6
- package/serialization/EntityTransformer.js +219 -217
- package/serialization/SerializationContext.d.ts +27 -23
- package/serialization/SerializationContext.js +105 -105
- package/types/ArrayType.d.ts +8 -8
- package/types/ArrayType.js +33 -33
- package/types/BigIntType.d.ts +17 -10
- package/types/BigIntType.js +37 -37
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +13 -13
- package/types/BooleanType.d.ts +4 -4
- package/types/BooleanType.js +12 -12
- package/types/CharacterType.d.ts +2 -2
- package/types/CharacterType.js +6 -6
- package/types/DateTimeType.d.ts +5 -5
- package/types/DateTimeType.js +15 -15
- package/types/DateType.d.ts +5 -5
- package/types/DateType.js +15 -15
- package/types/DecimalType.d.ts +7 -7
- package/types/DecimalType.js +26 -26
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +12 -12
- package/types/EnumArrayType.d.ts +5 -5
- package/types/EnumArrayType.js +24 -24
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +11 -11
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +9 -9
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +9 -9
- package/types/IntervalType.d.ts +4 -4
- package/types/IntervalType.js +12 -12
- package/types/JsonType.d.ts +8 -8
- package/types/JsonType.js +32 -32
- package/types/MediumIntType.d.ts +1 -1
- package/types/MediumIntType.js +3 -3
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +9 -9
- package/types/StringType.d.ts +4 -4
- package/types/StringType.js +12 -12
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +9 -9
- package/types/TimeType.d.ts +5 -5
- package/types/TimeType.js +17 -17
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +10 -10
- package/types/Type.d.ts +83 -79
- package/types/Type.js +82 -82
- package/types/Uint8ArrayType.d.ts +4 -4
- package/types/Uint8ArrayType.js +21 -21
- package/types/UnknownType.d.ts +4 -4
- package/types/UnknownType.js +12 -12
- package/types/UuidType.d.ts +5 -5
- package/types/UuidType.js +19 -19
- package/types/index.d.ts +75 -49
- package/types/index.js +52 -26
- package/typings.d.ts +1250 -737
- package/typings.js +244 -231
- package/unit-of-work/ChangeSet.d.ts +26 -26
- package/unit-of-work/ChangeSet.js +56 -56
- package/unit-of-work/ChangeSetComputer.d.ts +12 -12
- package/unit-of-work/ChangeSetComputer.js +178 -170
- package/unit-of-work/ChangeSetPersister.d.ts +63 -44
- package/unit-of-work/ChangeSetPersister.js +442 -421
- package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
- package/unit-of-work/CommitOrderCalculator.js +89 -88
- package/unit-of-work/IdentityMap.d.ts +31 -31
- package/unit-of-work/IdentityMap.js +105 -105
- package/unit-of-work/UnitOfWork.d.ts +181 -141
- package/unit-of-work/UnitOfWork.js +1200 -1183
- package/utils/AbstractMigrator.d.ts +111 -91
- package/utils/AbstractMigrator.js +275 -275
- package/utils/AbstractSchemaGenerator.d.ts +43 -34
- package/utils/AbstractSchemaGenerator.js +121 -122
- package/utils/AsyncContext.d.ts +3 -3
- package/utils/AsyncContext.js +34 -35
- package/utils/Configuration.d.ts +852 -808
- package/utils/Configuration.js +359 -344
- package/utils/Cursor.d.ts +40 -22
- package/utils/Cursor.js +135 -127
- package/utils/DataloaderUtils.d.ts +58 -43
- package/utils/DataloaderUtils.js +203 -198
- package/utils/EntityComparator.d.ts +98 -81
- package/utils/EntityComparator.js +828 -728
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +3 -3
- package/utils/QueryHelper.d.ts +79 -51
- package/utils/QueryHelper.js +372 -361
- package/utils/RawQueryFragment.d.ts +50 -34
- package/utils/RawQueryFragment.js +107 -105
- package/utils/RequestContext.d.ts +32 -32
- package/utils/RequestContext.js +52 -53
- package/utils/TransactionContext.d.ts +16 -16
- package/utils/TransactionContext.js +27 -27
- package/utils/TransactionManager.d.ts +58 -58
- package/utils/TransactionManager.js +199 -197
- package/utils/Utils.d.ts +204 -145
- package/utils/Utils.js +812 -810
- package/utils/clone.js +104 -113
- package/utils/env-vars.js +90 -88
- package/utils/fs-utils.d.ts +15 -15
- package/utils/fs-utils.js +180 -181
- package/utils/upsert-utils.d.ts +20 -5
- package/utils/upsert-utils.js +114 -116
package/errors.js
CHANGED
|
@@ -2,273 +2,370 @@ import { inspect } from './logging/inspect.js';
|
|
|
2
2
|
import { Utils } from './utils/Utils.js';
|
|
3
3
|
/** Base error class for ORM validation errors such as invalid entity state or incorrect usage. */
|
|
4
4
|
export class ValidationError extends Error {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
err += ` Entity with this name was discovered, but not the prototype you are passing to the ORM. If using EntitySchema, be sure to point to the implementation via \`class\`.`;
|
|
47
|
-
}
|
|
48
|
-
return new ValidationError(err);
|
|
49
|
-
}
|
|
50
|
-
static invalidPropertyName(entityName, invalid) {
|
|
51
|
-
return new ValidationError(`Entity '${Utils.className(entityName)}' does not have property '${invalid}'`);
|
|
52
|
-
}
|
|
53
|
-
static invalidCollectionValues(entityName, propName, invalid) {
|
|
54
|
-
return new ValidationError(`Invalid collection values provided for '${entityName}.${propName}' in ${entityName}.assign(): ${inspect(invalid)}`);
|
|
55
|
-
}
|
|
56
|
-
static invalidEnumArrayItems(entityName, invalid) {
|
|
57
|
-
return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
|
|
58
|
-
}
|
|
59
|
-
static invalidType(type, value, mode) {
|
|
60
|
-
const valueType = /\[object (\w+)]/.exec(Object.prototype.toString.call(value))[1].toLowerCase();
|
|
61
|
-
if (value instanceof Date) {
|
|
62
|
-
value = value.toISOString();
|
|
63
|
-
}
|
|
64
|
-
return new ValidationError(`Could not convert ${mode} value '${value}' of type '${valueType}' to type ${type.name}`);
|
|
65
|
-
}
|
|
66
|
-
static propertyRequired(entity, property) {
|
|
67
|
-
const entityName = entity.__meta.className;
|
|
68
|
-
return new ValidationError(`Value for ${entityName}.${property.name} is required, '${entity[property.name]}' found\nentity: ${inspect(entity)}`, entity);
|
|
69
|
-
}
|
|
70
|
-
static cannotModifyInverseCollection(owner, property) {
|
|
71
|
-
const inverseCollection = `${owner.constructor.name}.${property.name}`;
|
|
72
|
-
const ownerCollection = `${property.type}.${property.mappedBy}`;
|
|
73
|
-
const error = `You cannot modify inverse side of M:N collection ${inverseCollection} when the owning side is not initialized. ` +
|
|
74
|
-
`Consider working with the owning side instead (${ownerCollection}).`;
|
|
75
|
-
return new ValidationError(error, owner);
|
|
76
|
-
}
|
|
77
|
-
static cannotModifyReadonlyCollection(owner, property) {
|
|
78
|
-
return new ValidationError(`You cannot modify collection ${owner.constructor.name}.${property.name} as it is marked as readonly.`, owner);
|
|
79
|
-
}
|
|
80
|
-
static cannotRemoveFromCollectionWithoutOrphanRemoval(owner, property) {
|
|
81
|
-
const options = [
|
|
82
|
-
' - add `orphanRemoval: true` to the collection options',
|
|
83
|
-
" - add `deleteRule: 'cascade'` to the owning side options",
|
|
84
|
-
' - add `nullable: true` to the owning side options',
|
|
85
|
-
].join('\n');
|
|
86
|
-
return new ValidationError(`Removing items from collection ${owner.constructor.name}.${property.name} without \`orphanRemoval: true\` would break non-null constraint on the owning side. You have several options: \n${options}`, owner);
|
|
87
|
-
}
|
|
88
|
-
static invalidCompositeIdentifier(meta) {
|
|
89
|
-
return new ValidationError(`Composite key required for entity ${meta.className}.`);
|
|
90
|
-
}
|
|
91
|
-
static cannotCommit() {
|
|
92
|
-
return new ValidationError('You cannot call em.flush() from inside lifecycle hook handlers');
|
|
93
|
-
}
|
|
94
|
-
static cannotUseGlobalContext() {
|
|
95
|
-
return new ValidationError("Using global EntityManager instance methods for context specific actions is disallowed. If you need to work with the global instance's identity map, use `allowGlobalContext` configuration option or `fork()` instead.");
|
|
96
|
-
}
|
|
97
|
-
static cannotUseOperatorsInsideEmbeddables(entityName, propName, payload) {
|
|
98
|
-
return new ValidationError(`Using operators inside embeddables is not allowed, move the operator above. (property: ${Utils.className(entityName)}.${propName}, payload: ${inspect(payload)})`);
|
|
99
|
-
}
|
|
100
|
-
static cannotUseGroupOperatorsInsideScalars(entityName, propName, payload) {
|
|
101
|
-
return new ValidationError(`Using group operators ($and/$or) inside scalar properties is not allowed, move the operator above. (property: ${Utils.className(entityName)}.${propName}, payload: ${inspect(payload)})`);
|
|
102
|
-
}
|
|
103
|
-
static invalidEmbeddableQuery(entityName, propName, embeddableType) {
|
|
104
|
-
return new ValidationError(`Invalid query for entity '${Utils.className(entityName)}', property '${propName}' does not exist in embeddable '${embeddableType}'`);
|
|
105
|
-
}
|
|
5
|
+
entity;
|
|
6
|
+
constructor(message, entity) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.entity = entity;
|
|
9
|
+
Error.captureStackTrace(this, this.constructor);
|
|
10
|
+
this.name = this.constructor.name;
|
|
11
|
+
this.message = message;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Gets instance of entity that caused this error.
|
|
15
|
+
*/
|
|
16
|
+
getEntity() {
|
|
17
|
+
return this.entity;
|
|
18
|
+
}
|
|
19
|
+
static fromWrongPropertyType(entity, property, expectedType, givenType, givenValue) {
|
|
20
|
+
const entityName = entity.constructor.name;
|
|
21
|
+
const msg = `Trying to set ${entityName}.${property} of type '${expectedType}' to ${inspect(givenValue)} of type '${givenType}'`;
|
|
22
|
+
return new ValidationError(msg);
|
|
23
|
+
}
|
|
24
|
+
static fromWrongRepositoryType(entityName, repoType, method) {
|
|
25
|
+
const msg = `Trying to use EntityRepository.${method}() with '${entityName}' entity while the repository is of type '${repoType}'`;
|
|
26
|
+
return new ValidationError(msg);
|
|
27
|
+
}
|
|
28
|
+
static fromMergeWithoutPK(meta) {
|
|
29
|
+
return new ValidationError(`You cannot merge entity '${meta.className}' without identifier!`);
|
|
30
|
+
}
|
|
31
|
+
static transactionRequired() {
|
|
32
|
+
return new ValidationError('An open transaction is required for this operation');
|
|
33
|
+
}
|
|
34
|
+
static entityNotManaged(entity) {
|
|
35
|
+
return new ValidationError(
|
|
36
|
+
`Entity ${entity.constructor.name} is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager.persist()`,
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
static notEntity(owner, prop, data) {
|
|
40
|
+
const type = /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
|
|
41
|
+
return new ValidationError(
|
|
42
|
+
`Entity of type ${prop.type} expected for property ${owner.constructor.name}.${prop.name}, ${inspect(data)} of type ${type} given. If you are using Object.assign(entity, data), use em.assign(entity, data) instead.`,
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
static notDiscoveredEntity(data, meta, action = 'persist') {
|
|
106
46
|
/* v8 ignore next */
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
47
|
+
const type = meta?.className ?? /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
|
|
48
|
+
let err = `Trying to ${action} not discovered entity of type ${type}.`;
|
|
49
|
+
if (meta) {
|
|
50
|
+
err += ` Entity with this name was discovered, but not the prototype you are passing to the ORM. If using EntitySchema, be sure to point to the implementation via \`class\`.`;
|
|
51
|
+
}
|
|
52
|
+
return new ValidationError(err);
|
|
53
|
+
}
|
|
54
|
+
static invalidPropertyName(entityName, invalid) {
|
|
55
|
+
return new ValidationError(`Entity '${Utils.className(entityName)}' does not have property '${invalid}'`);
|
|
56
|
+
}
|
|
57
|
+
static invalidCollectionValues(entityName, propName, invalid) {
|
|
58
|
+
return new ValidationError(
|
|
59
|
+
`Invalid collection values provided for '${entityName}.${propName}' in ${entityName}.assign(): ${inspect(invalid)}`,
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
static invalidEnumArrayItems(entityName, invalid) {
|
|
63
|
+
return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
|
|
64
|
+
}
|
|
65
|
+
static invalidType(type, value, mode) {
|
|
66
|
+
const valueType = /\[object (\w+)]/.exec(Object.prototype.toString.call(value))[1].toLowerCase();
|
|
67
|
+
if (value instanceof Date) {
|
|
68
|
+
value = value.toISOString();
|
|
69
|
+
}
|
|
70
|
+
return new ValidationError(
|
|
71
|
+
`Could not convert ${mode} value '${value}' of type '${valueType}' to type ${type.name}`,
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
static propertyRequired(entity, property) {
|
|
75
|
+
const entityName = entity.__meta.className;
|
|
76
|
+
return new ValidationError(
|
|
77
|
+
`Value for ${entityName}.${property.name} is required, '${entity[property.name]}' found\nentity: ${inspect(entity)}`,
|
|
78
|
+
entity,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
static cannotModifyInverseCollection(owner, property) {
|
|
82
|
+
const inverseCollection = `${owner.constructor.name}.${property.name}`;
|
|
83
|
+
const ownerCollection = `${property.type}.${property.mappedBy}`;
|
|
84
|
+
const error =
|
|
85
|
+
`You cannot modify inverse side of M:N collection ${inverseCollection} when the owning side is not initialized. ` +
|
|
86
|
+
`Consider working with the owning side instead (${ownerCollection}).`;
|
|
87
|
+
return new ValidationError(error, owner);
|
|
88
|
+
}
|
|
89
|
+
static cannotModifyReadonlyCollection(owner, property) {
|
|
90
|
+
return new ValidationError(
|
|
91
|
+
`You cannot modify collection ${owner.constructor.name}.${property.name} as it is marked as readonly.`,
|
|
92
|
+
owner,
|
|
93
|
+
);
|
|
94
|
+
}
|
|
95
|
+
static cannotRemoveFromCollectionWithoutOrphanRemoval(owner, property) {
|
|
96
|
+
const options = [
|
|
97
|
+
' - add `orphanRemoval: true` to the collection options',
|
|
98
|
+
" - add `deleteRule: 'cascade'` to the owning side options",
|
|
99
|
+
' - add `nullable: true` to the owning side options',
|
|
100
|
+
].join('\n');
|
|
101
|
+
return new ValidationError(
|
|
102
|
+
`Removing items from collection ${owner.constructor.name}.${property.name} without \`orphanRemoval: true\` would break non-null constraint on the owning side. You have several options: \n${options}`,
|
|
103
|
+
owner,
|
|
104
|
+
);
|
|
105
|
+
}
|
|
106
|
+
static invalidCompositeIdentifier(meta) {
|
|
107
|
+
return new ValidationError(`Composite key required for entity ${meta.className}.`);
|
|
108
|
+
}
|
|
109
|
+
static cannotCommit() {
|
|
110
|
+
return new ValidationError('You cannot call em.flush() from inside lifecycle hook handlers');
|
|
111
|
+
}
|
|
112
|
+
static cannotUseGlobalContext() {
|
|
113
|
+
return new ValidationError(
|
|
114
|
+
"Using global EntityManager instance methods for context specific actions is disallowed. If you need to work with the global instance's identity map, use `allowGlobalContext` configuration option or `fork()` instead.",
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
static cannotUseOperatorsInsideEmbeddables(entityName, propName, payload) {
|
|
118
|
+
return new ValidationError(
|
|
119
|
+
`Using operators inside embeddables is not allowed, move the operator above. (property: ${Utils.className(entityName)}.${propName}, payload: ${inspect(payload)})`,
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
static cannotUseGroupOperatorsInsideScalars(entityName, propName, payload) {
|
|
123
|
+
return new ValidationError(
|
|
124
|
+
`Using group operators ($and/$or) inside scalar properties is not allowed, move the operator above. (property: ${Utils.className(entityName)}.${propName}, payload: ${inspect(payload)})`,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
static invalidEmbeddableQuery(entityName, propName, embeddableType) {
|
|
128
|
+
return new ValidationError(
|
|
129
|
+
`Invalid query for entity '${Utils.className(entityName)}', property '${propName}' does not exist in embeddable '${embeddableType}'`,
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
/* v8 ignore next */
|
|
133
|
+
static invalidQueryCondition(cond) {
|
|
134
|
+
return new ValidationError(`Invalid query condition: ${inspect(cond, { depth: 5 })}`);
|
|
135
|
+
}
|
|
110
136
|
}
|
|
111
137
|
/** Error thrown when cursor-based pagination encounters missing or invalid cursor values. */
|
|
112
138
|
export class CursorError extends ValidationError {
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
139
|
+
static entityNotPopulated(entity, prop) {
|
|
140
|
+
return new CursorError(`Cannot create cursor, value for '${entity.constructor.name}.${prop}' is missing.`);
|
|
141
|
+
}
|
|
142
|
+
static missingValue(entityName, prop) {
|
|
143
|
+
return new CursorError(`Invalid cursor condition, value for '${entityName}.${prop}' is missing.`);
|
|
144
|
+
}
|
|
119
145
|
}
|
|
120
146
|
/** Error thrown when an optimistic lock conflict is detected during entity persistence. */
|
|
121
147
|
export class OptimisticLockError extends ValidationError {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
148
|
+
static notVersioned(meta) {
|
|
149
|
+
return new OptimisticLockError(`Cannot obtain optimistic lock on unversioned entity ${meta.className}`);
|
|
150
|
+
}
|
|
151
|
+
static lockFailed(entityOrName) {
|
|
152
|
+
const name = typeof entityOrName === 'string' ? entityOrName : entityOrName.constructor.name;
|
|
153
|
+
const entity = typeof entityOrName === 'string' ? undefined : entityOrName;
|
|
154
|
+
return new OptimisticLockError(`The optimistic lock on entity ${name} failed`, entity);
|
|
155
|
+
}
|
|
156
|
+
static lockFailedVersionMismatch(entity, expectedLockVersion, actualLockVersion) {
|
|
157
|
+
expectedLockVersion = expectedLockVersion instanceof Date ? expectedLockVersion.getTime() : expectedLockVersion;
|
|
158
|
+
actualLockVersion = actualLockVersion instanceof Date ? actualLockVersion.getTime() : actualLockVersion;
|
|
159
|
+
return new OptimisticLockError(
|
|
160
|
+
`The optimistic lock failed, version ${expectedLockVersion} was expected, but is actually ${actualLockVersion}`,
|
|
161
|
+
entity,
|
|
162
|
+
);
|
|
163
|
+
}
|
|
135
164
|
}
|
|
136
165
|
/** Error thrown when entity metadata is invalid, incomplete, or inconsistent. */
|
|
137
166
|
export class MetadataError extends ValidationError {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
167
|
+
static fromMissingPrimaryKey(meta) {
|
|
168
|
+
return new MetadataError(`${meta.className} entity is missing @PrimaryKey()`);
|
|
169
|
+
}
|
|
170
|
+
static fromWrongReference(meta, prop, key, owner) {
|
|
171
|
+
if (owner) {
|
|
172
|
+
return MetadataError.fromMessage(
|
|
173
|
+
meta,
|
|
174
|
+
prop,
|
|
175
|
+
`has wrong '${key}' reference type: ${owner.type} instead of ${meta.className}`,
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
return MetadataError.fromMessage(meta, prop, `has unknown '${key}' reference: ${prop.type}.${prop[key]}`);
|
|
179
|
+
}
|
|
180
|
+
static fromWrongForeignKey(meta, prop, key) {
|
|
181
|
+
return MetadataError.fromMessage(
|
|
182
|
+
meta,
|
|
183
|
+
prop,
|
|
184
|
+
`requires explicit '${key}' option, since the 'joinColumns' are not matching the length.`,
|
|
185
|
+
);
|
|
186
|
+
}
|
|
187
|
+
static fromWrongTypeDefinition(meta, prop) {
|
|
188
|
+
if (!prop.type) {
|
|
189
|
+
return MetadataError.fromMessage(meta, prop, `is missing type definition`);
|
|
190
|
+
}
|
|
191
|
+
return MetadataError.fromMessage(meta, prop, `has unknown type: ${prop.type}`);
|
|
192
|
+
}
|
|
193
|
+
static fromWrongOwnership(meta, prop, key) {
|
|
194
|
+
const type = key === 'inversedBy' ? 'owning' : 'inverse';
|
|
195
|
+
const other = key === 'inversedBy' ? 'mappedBy' : 'inversedBy';
|
|
196
|
+
return new MetadataError(
|
|
197
|
+
`Both ${meta.className}.${prop.name} and ${prop.type}.${prop[key]} are defined as ${type} sides, use '${other}' on one of them`,
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
static fromWrongReferenceKind(meta, owner, prop) {
|
|
201
|
+
return new MetadataError(
|
|
202
|
+
`${meta.className}.${prop.name} is of type ${prop.kind} which is incompatible with its owning side ${prop.type}.${owner.name} of type ${owner.kind}`,
|
|
203
|
+
);
|
|
204
|
+
}
|
|
205
|
+
static fromInversideSidePrimary(meta, owner, prop) {
|
|
206
|
+
return new MetadataError(
|
|
207
|
+
`${meta.className}.${prop.name} cannot be primary key as it is defined as inverse side. Maybe you should swap the use of 'inversedBy' and 'mappedBy'.`,
|
|
208
|
+
);
|
|
209
|
+
}
|
|
210
|
+
static unknownIndexProperty(meta, prop, type) {
|
|
211
|
+
return new MetadataError(
|
|
212
|
+
`Entity ${meta.className} has wrong ${type} definition: '${prop}' does not exist. You need to use property name, not column name.`,
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
static multipleVersionFields(meta, fields) {
|
|
216
|
+
return new MetadataError(
|
|
217
|
+
`Entity ${meta.className} has multiple version properties defined: '${fields.join("', '")}'. Only one version property is allowed per entity.`,
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
static invalidVersionFieldType(meta) {
|
|
221
|
+
const prop = meta.properties[meta.versionProperty];
|
|
222
|
+
return new MetadataError(
|
|
223
|
+
`Version property ${meta.className}.${prop.name} has unsupported type '${prop.type}'. Only 'number' and 'Date' are allowed.`,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
static fromUnknownEntity(entityName, source) {
|
|
227
|
+
return new MetadataError(
|
|
228
|
+
`Entity '${entityName}' was not discovered, please make sure to provide it in 'entities' array when initializing the ORM (used in ${source})`,
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
static noEntityDiscovered() {
|
|
232
|
+
return new MetadataError('No entities were discovered');
|
|
233
|
+
}
|
|
234
|
+
static onlyAbstractEntitiesDiscovered() {
|
|
235
|
+
return new MetadataError(
|
|
236
|
+
'Only abstract entities were discovered, maybe you forgot to use @Entity() decorator? This can also happen when you have multiple `@mikro-orm/core` packages installed side by side.',
|
|
237
|
+
);
|
|
238
|
+
}
|
|
239
|
+
static duplicateEntityDiscovered(paths) {
|
|
240
|
+
return new MetadataError(`Duplicate table names are not allowed: ${paths.join(', ')}`);
|
|
241
|
+
}
|
|
242
|
+
static duplicateFieldName(entityName, names) {
|
|
243
|
+
return new MetadataError(
|
|
244
|
+
`Duplicate fieldNames are not allowed: ${names.map(n => `${Utils.className(entityName)}.${n[0]} (fieldName: '${n[1]}')`).join(', ')}`,
|
|
245
|
+
);
|
|
246
|
+
}
|
|
247
|
+
static multipleDecorators(entityName, propertyName) {
|
|
248
|
+
return new MetadataError(`Multiple property decorators used on '${entityName}.${propertyName}' property`);
|
|
249
|
+
}
|
|
250
|
+
static missingMetadata(entity) {
|
|
251
|
+
return new MetadataError(`Metadata for entity ${entity} not found`);
|
|
252
|
+
}
|
|
253
|
+
static invalidPrimaryKey(meta, prop, requiredName) {
|
|
254
|
+
return this.fromMessage(meta, prop, `has wrong field name, '${requiredName}' is required in current driver`);
|
|
255
|
+
}
|
|
256
|
+
static invalidManyToManyWithPivotEntity(meta1, prop1, meta2, prop2) {
|
|
257
|
+
const p1 = `${meta1.className}.${prop1.name}`;
|
|
258
|
+
const p2 = `${meta2.className}.${prop2.name}`;
|
|
259
|
+
return new MetadataError(
|
|
260
|
+
`${p1} and ${p2} use the same 'pivotEntity', but don't form a bidirectional relation. Specify 'inversedBy' or 'mappedBy' to link them.`,
|
|
261
|
+
);
|
|
262
|
+
}
|
|
263
|
+
static targetIsAbstract(meta, prop) {
|
|
264
|
+
return this.fromMessage(
|
|
265
|
+
meta,
|
|
266
|
+
prop,
|
|
267
|
+
`targets abstract entity ${prop.type}. Maybe you forgot to put @Entity() decorator on the ${prop.type} class?`,
|
|
268
|
+
);
|
|
269
|
+
}
|
|
270
|
+
static nonPersistentCompositeProp(meta, prop) {
|
|
271
|
+
return this.fromMessage(
|
|
272
|
+
meta,
|
|
273
|
+
prop,
|
|
274
|
+
`is non-persistent relation which targets composite primary key. This is not supported and will cause issues, 'persist: false' should be added to the properties representing single columns instead.`,
|
|
275
|
+
);
|
|
276
|
+
}
|
|
277
|
+
static propertyTargetsEntityType(meta, prop, target) {
|
|
278
|
+
/* v8 ignore next */
|
|
279
|
+
const suggestion = target.embeddable ? 'Embedded' : 'ManyToOne';
|
|
280
|
+
return this.fromMessage(
|
|
281
|
+
meta,
|
|
282
|
+
prop,
|
|
283
|
+
`is defined as scalar @Property(), but its type is a discovered entity ${target.className}. Maybe you want to use @${suggestion}() decorator instead?`,
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
static fromMissingOption(meta, prop, option) {
|
|
287
|
+
return this.fromMessage(meta, prop, `is missing '${option}' option`);
|
|
288
|
+
}
|
|
289
|
+
static targetKeyOnManyToMany(meta, prop) {
|
|
290
|
+
return this.fromMessage(meta, prop, `uses 'targetKey' option which is not supported for ManyToMany relations`);
|
|
291
|
+
}
|
|
292
|
+
static targetKeyNotUnique(meta, prop, target) {
|
|
293
|
+
const targetName = target?.className ?? prop.type;
|
|
294
|
+
return this.fromMessage(
|
|
295
|
+
meta,
|
|
296
|
+
prop,
|
|
297
|
+
`has 'targetKey' set to '${prop.targetKey}', but ${targetName}.${prop.targetKey} is not marked as unique`,
|
|
298
|
+
);
|
|
299
|
+
}
|
|
300
|
+
static targetKeyNotFound(meta, prop, target) {
|
|
301
|
+
const targetName = target?.className ?? prop.type;
|
|
302
|
+
return this.fromMessage(
|
|
303
|
+
meta,
|
|
304
|
+
prop,
|
|
305
|
+
`has 'targetKey' set to '${prop.targetKey}', but ${targetName}.${prop.targetKey} does not exist`,
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
static incompatiblePolymorphicTargets(meta, prop, target1, target2, reason) {
|
|
309
|
+
return this.fromMessage(
|
|
310
|
+
meta,
|
|
311
|
+
prop,
|
|
312
|
+
`has incompatible polymorphic targets ${target1.className} and ${target2.className}: ${reason}`,
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
static dangerousPropertyName(meta, prop) {
|
|
316
|
+
return this.fromMessage(
|
|
317
|
+
meta,
|
|
318
|
+
prop,
|
|
319
|
+
`uses a dangerous property name '${prop.name}' which could lead to prototype pollution. Please use a different property name.`,
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
static viewEntityWithoutExpression(meta) {
|
|
323
|
+
return new MetadataError(
|
|
324
|
+
`View entity ${meta.className} is missing 'expression'. View entities must have an expression defining the SQL query.`,
|
|
325
|
+
);
|
|
326
|
+
}
|
|
327
|
+
static mixedInheritanceStrategies(root, child) {
|
|
328
|
+
return new MetadataError(
|
|
329
|
+
`Entity ${child.className} cannot mix STI (Single Table Inheritance) and TPT (Table-Per-Type) inheritance. Root entity ${root.className} uses STI (discriminatorColumn) but also has inheritance: 'tpt'. Choose one inheritance strategy per hierarchy.`,
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
static tptNotSupportedByDriver(meta) {
|
|
333
|
+
return new MetadataError(
|
|
334
|
+
`Entity ${meta.className} uses TPT (Table-Per-Type) inheritance which is not supported by the current driver. TPT requires SQL JOINs and is only available with SQL drivers.`,
|
|
335
|
+
);
|
|
336
|
+
}
|
|
337
|
+
static fromMessage(meta, prop, message) {
|
|
338
|
+
return new MetadataError(`${meta.className}.${prop.name} ${message}`);
|
|
339
|
+
}
|
|
249
340
|
}
|
|
250
341
|
/** Error thrown when an entity lookup fails to find the expected result. */
|
|
251
342
|
export class NotFoundError extends ValidationError {
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
343
|
+
static findOneFailed(name, where) {
|
|
344
|
+
return new NotFoundError(`${name} not found (${inspect(where)})`);
|
|
345
|
+
}
|
|
346
|
+
static findExactlyOneFailed(name, where) {
|
|
347
|
+
return new NotFoundError(
|
|
348
|
+
`Wrong number of ${name} entities found for query ${inspect(where)}, expected exactly one`,
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
static failedToLoadProperty(name, propName, where) {
|
|
352
|
+
const whereString = typeof where === 'object' ? inspect(where) : where;
|
|
353
|
+
return new NotFoundError(`${name} (${whereString}) failed to load property '${propName}'`);
|
|
354
|
+
}
|
|
262
355
|
}
|
|
263
356
|
/** Error thrown when a transaction propagation requirement is not satisfied. */
|
|
264
357
|
export class TransactionStateError extends ValidationError {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
358
|
+
static requiredTransactionNotFound(propagation) {
|
|
359
|
+
return new TransactionStateError(
|
|
360
|
+
`No existing transaction found for transaction marked with propagation "${propagation}"`,
|
|
361
|
+
);
|
|
362
|
+
}
|
|
363
|
+
static transactionNotAllowed(propagation) {
|
|
364
|
+
return new TransactionStateError(
|
|
365
|
+
`Existing transaction found for transaction marked with propagation "${propagation}"`,
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
static invalidPropagation(propagation) {
|
|
369
|
+
return new TransactionStateError(`Unsupported transaction propagation type: ${propagation}`);
|
|
370
|
+
}
|
|
274
371
|
}
|