@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntityManager.d.ts +70 -75
- package/EntityManager.js +487 -402
- package/MikroORM.d.ts +45 -38
- package/MikroORM.js +123 -156
- package/README.md +7 -4
- package/cache/FileCacheAdapter.d.ts +2 -7
- package/cache/FileCacheAdapter.js +35 -30
- package/cache/GeneratedCacheAdapter.d.ts +1 -2
- package/cache/GeneratedCacheAdapter.js +6 -8
- package/cache/MemoryCacheAdapter.d.ts +1 -2
- package/cache/MemoryCacheAdapter.js +8 -8
- package/cache/index.d.ts +1 -2
- package/cache/index.js +0 -2
- package/connections/Connection.d.ts +12 -5
- package/connections/Connection.js +37 -15
- package/drivers/DatabaseDriver.d.ts +25 -18
- package/drivers/DatabaseDriver.js +144 -45
- package/drivers/IDatabaseDriver.d.ts +118 -23
- package/entity/BaseEntity.d.ts +63 -4
- package/entity/BaseEntity.js +0 -3
- package/entity/Collection.d.ts +95 -31
- package/entity/Collection.js +487 -139
- package/entity/EntityAssigner.js +37 -25
- package/entity/EntityFactory.d.ts +8 -9
- package/entity/EntityFactory.js +152 -100
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +69 -27
- package/entity/EntityLoader.d.ts +12 -13
- package/entity/EntityLoader.js +286 -125
- package/entity/EntityRepository.d.ts +28 -8
- package/entity/EntityRepository.js +8 -2
- package/entity/PolymorphicRef.d.ts +12 -0
- package/entity/PolymorphicRef.js +18 -0
- package/entity/Reference.d.ts +3 -8
- package/entity/Reference.js +62 -29
- package/entity/WrappedEntity.d.ts +7 -10
- package/entity/WrappedEntity.js +6 -7
- package/entity/defineEntity.d.ts +472 -313
- package/entity/defineEntity.js +134 -290
- package/entity/index.d.ts +2 -2
- package/entity/index.js +2 -2
- package/entity/utils.d.ts +6 -1
- package/entity/utils.js +46 -11
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +66 -0
- package/enums.d.ts +8 -6
- package/enums.js +13 -17
- package/errors.d.ts +26 -16
- package/errors.js +63 -31
- package/events/EventManager.d.ts +3 -5
- package/events/EventManager.js +37 -26
- package/events/index.d.ts +1 -1
- package/events/index.js +0 -1
- package/exceptions.js +9 -2
- package/hydration/Hydrator.js +1 -2
- package/hydration/ObjectHydrator.d.ts +5 -6
- package/hydration/ObjectHydrator.js +109 -50
- package/index.d.ts +2 -2
- package/index.js +1 -2
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +3 -4
- package/logging/SimpleLogger.d.ts +1 -1
- package/logging/colors.d.ts +1 -1
- package/logging/colors.js +4 -6
- package/logging/index.d.ts +2 -1
- package/logging/index.js +1 -1
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +11 -0
- package/metadata/EntitySchema.d.ts +47 -23
- package/metadata/EntitySchema.js +103 -34
- package/metadata/MetadataDiscovery.d.ts +65 -18
- package/metadata/MetadataDiscovery.js +940 -424
- package/metadata/MetadataProvider.d.ts +11 -2
- package/metadata/MetadataProvider.js +71 -2
- package/metadata/MetadataStorage.d.ts +11 -13
- package/metadata/MetadataStorage.js +79 -48
- package/metadata/MetadataValidator.d.ts +32 -9
- package/metadata/MetadataValidator.js +214 -44
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +1 -1
- package/metadata/index.js +0 -1
- package/metadata/types.d.ts +577 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
- package/naming-strategy/AbstractNamingStrategy.js +26 -5
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
- package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
- package/naming-strategy/MongoNamingStrategy.js +6 -6
- package/naming-strategy/NamingStrategy.d.ts +28 -4
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
- package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
- package/naming-strategy/index.d.ts +1 -1
- package/naming-strategy/index.js +0 -1
- package/not-supported.d.ts +2 -0
- package/not-supported.js +8 -0
- package/package.json +47 -36
- package/platforms/ExceptionConverter.js +1 -1
- package/platforms/Platform.d.ts +33 -15
- package/platforms/Platform.js +125 -69
- package/serialization/EntitySerializer.d.ts +6 -3
- package/serialization/EntitySerializer.js +54 -30
- package/serialization/EntityTransformer.js +37 -22
- package/serialization/SerializationContext.d.ts +10 -14
- package/serialization/SerializationContext.js +24 -19
- package/types/ArrayType.d.ts +1 -1
- package/types/ArrayType.js +2 -3
- package/types/BigIntType.js +1 -1
- package/types/BlobType.d.ts +0 -1
- package/types/BlobType.js +0 -3
- package/types/BooleanType.d.ts +1 -0
- package/types/BooleanType.js +3 -0
- package/types/DecimalType.js +2 -2
- package/types/DoubleType.js +1 -1
- package/types/EnumArrayType.js +1 -2
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/TinyIntType.js +1 -1
- package/types/Type.d.ts +2 -4
- package/types/Type.js +3 -3
- package/types/Uint8ArrayType.d.ts +0 -1
- package/types/Uint8ArrayType.js +1 -4
- package/types/UuidType.d.ts +2 -0
- package/types/UuidType.js +14 -2
- package/types/index.d.ts +3 -2
- package/typings.d.ts +427 -170
- package/typings.js +100 -45
- package/unit-of-work/ChangeSet.d.ts +4 -6
- package/unit-of-work/ChangeSet.js +8 -9
- package/unit-of-work/ChangeSetComputer.d.ts +2 -12
- package/unit-of-work/ChangeSetComputer.js +61 -38
- package/unit-of-work/ChangeSetPersister.d.ts +10 -17
- package/unit-of-work/ChangeSetPersister.js +136 -73
- package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
- package/unit-of-work/CommitOrderCalculator.js +22 -20
- package/unit-of-work/IdentityMap.d.ts +12 -3
- package/unit-of-work/IdentityMap.js +51 -13
- package/unit-of-work/UnitOfWork.d.ts +39 -23
- package/unit-of-work/UnitOfWork.js +441 -246
- package/utils/AbstractMigrator.d.ts +101 -0
- package/utils/AbstractMigrator.js +303 -0
- package/utils/AbstractSchemaGenerator.d.ts +5 -5
- package/utils/AbstractSchemaGenerator.js +30 -18
- package/utils/AsyncContext.d.ts +6 -0
- package/utils/AsyncContext.js +42 -0
- package/utils/Configuration.d.ts +647 -185
- package/utils/Configuration.js +215 -252
- package/utils/ConfigurationLoader.d.ts +1 -52
- package/utils/ConfigurationLoader.js +1 -330
- package/utils/Cursor.d.ts +3 -6
- package/utils/Cursor.js +32 -17
- package/utils/DataloaderUtils.d.ts +10 -5
- package/utils/DataloaderUtils.js +42 -22
- package/utils/EntityComparator.d.ts +21 -21
- package/utils/EntityComparator.js +224 -118
- package/utils/QueryHelper.d.ts +34 -7
- package/utils/QueryHelper.js +183 -72
- package/utils/RawQueryFragment.d.ts +28 -34
- package/utils/RawQueryFragment.js +37 -72
- package/utils/RequestContext.js +2 -2
- package/utils/TransactionContext.js +2 -2
- package/utils/TransactionManager.js +11 -8
- package/utils/Utils.d.ts +16 -127
- package/utils/Utils.js +104 -402
- package/utils/clone.js +13 -23
- package/utils/env-vars.d.ts +7 -0
- package/utils/env-vars.js +98 -0
- package/utils/fs-utils.d.ts +20 -0
- package/utils/fs-utils.js +193 -0
- package/utils/index.d.ts +1 -3
- package/utils/index.js +1 -3
- package/utils/upsert-utils.d.ts +9 -4
- package/utils/upsert-utils.js +51 -5
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -13
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -32
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -11
- package/decorators/Embedded.d.ts +0 -12
- package/decorators/Embedded.js +0 -18
- package/decorators/Entity.d.ts +0 -33
- package/decorators/Entity.js +0 -12
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -16
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -8
- package/decorators/Formula.d.ts +0 -4
- package/decorators/Formula.js +0 -15
- package/decorators/Indexed.d.ts +0 -19
- package/decorators/Indexed.js +0 -20
- package/decorators/ManyToMany.d.ts +0 -42
- package/decorators/ManyToMany.js +0 -14
- package/decorators/ManyToOne.d.ts +0 -34
- package/decorators/ManyToOne.js +0 -14
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -17
- package/decorators/OneToOne.d.ts +0 -28
- package/decorators/OneToOne.js +0 -7
- package/decorators/PrimaryKey.d.ts +0 -8
- package/decorators/PrimaryKey.js +0 -20
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -32
- package/decorators/Transactional.d.ts +0 -14
- package/decorators/Transactional.js +0 -28
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -47
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -17
- package/entity/ArrayCollection.d.ts +0 -118
- package/entity/ArrayCollection.js +0 -407
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -150
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -44
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -28
package/entity/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export * from './EntityRepository.js';
|
|
2
2
|
export * from './EntityIdentifier.js';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './PolymorphicRef.js';
|
|
4
4
|
export * from './EntityAssigner.js';
|
|
5
5
|
export * from './EntityHelper.js';
|
|
6
6
|
export * from './EntityFactory.js';
|
|
7
|
-
export * from './ArrayCollection.js';
|
|
8
7
|
export * from './Collection.js';
|
|
9
8
|
export * from './EntityLoader.js';
|
|
10
9
|
export * from './Reference.js';
|
|
11
10
|
export * from './BaseEntity.js';
|
|
12
11
|
export * from './WrappedEntity.js';
|
|
12
|
+
export * from './validators.js';
|
|
13
13
|
export * from './wrap.js';
|
|
14
14
|
export * from './defineEntity.js';
|
|
15
15
|
export * from './utils.js';
|
package/entity/index.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
export * from './EntityRepository.js';
|
|
2
2
|
export * from './EntityIdentifier.js';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './PolymorphicRef.js';
|
|
4
4
|
export * from './EntityAssigner.js';
|
|
5
5
|
export * from './EntityHelper.js';
|
|
6
6
|
export * from './EntityFactory.js';
|
|
7
|
-
export * from './ArrayCollection.js';
|
|
8
7
|
export * from './Collection.js';
|
|
9
8
|
export * from './EntityLoader.js';
|
|
10
9
|
export * from './Reference.js';
|
|
11
10
|
export * from './BaseEntity.js';
|
|
12
11
|
export * from './WrappedEntity.js';
|
|
12
|
+
export * from './validators.js';
|
|
13
13
|
export * from './wrap.js';
|
|
14
14
|
export * from './defineEntity.js';
|
|
15
15
|
export * from './utils.js';
|
package/entity/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { EntityMetadata, PopulateOptions } from '../typings.js';
|
|
1
|
+
import type { EntityMetadata, PopulateHintOptions, PopulateOptions } from '../typings.js';
|
|
2
2
|
import { LoadStrategy, ReferenceKind } from '../enums.js';
|
|
3
3
|
/**
|
|
4
4
|
* @internal
|
|
@@ -10,3 +10,8 @@ export declare function expandDotPaths<Entity>(meta: EntityMetadata<Entity>, pop
|
|
|
10
10
|
* @internal
|
|
11
11
|
*/
|
|
12
12
|
export declare function getLoadingStrategy(strategy: LoadStrategy | `${LoadStrategy}`, kind: ReferenceKind): LoadStrategy.SELECT_IN | LoadStrategy.JOINED;
|
|
13
|
+
/**
|
|
14
|
+
* Applies per-relation overrides from `populateHints` to the normalized populate tree.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyPopulateHints<Entity>(populate: PopulateOptions<Entity>[], hints: Record<string, PopulateHintOptions>): void;
|
package/entity/utils.js
CHANGED
|
@@ -17,15 +17,17 @@ function expandNestedPopulate(parentProp, parts, strategy, all) {
|
|
|
17
17
|
* @internal
|
|
18
18
|
*/
|
|
19
19
|
export function expandDotPaths(meta, populate, normalized = false) {
|
|
20
|
-
const ret = normalized
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
20
|
+
const ret = normalized
|
|
21
|
+
? populate
|
|
22
|
+
: Utils.asArray(populate).map(field => {
|
|
23
|
+
if (typeof field === 'string') {
|
|
24
|
+
return { field };
|
|
25
|
+
}
|
|
26
|
+
/* v8 ignore next */
|
|
27
|
+
return typeof field === 'boolean' || field.field === PopulatePath.ALL
|
|
28
|
+
? { all: !!field, field: meta.primaryKeys[0] }
|
|
29
|
+
: field;
|
|
30
|
+
});
|
|
29
31
|
for (const p of ret) {
|
|
30
32
|
if (!p.field.includes('.')) {
|
|
31
33
|
continue;
|
|
@@ -35,8 +37,8 @@ export function expandDotPaths(meta, populate, normalized = false) {
|
|
|
35
37
|
p.children ??= [];
|
|
36
38
|
const prop = meta.properties[p.field];
|
|
37
39
|
if (parts[0] === PopulatePath.ALL) {
|
|
38
|
-
prop
|
|
39
|
-
.filter(prop => prop.lazy || prop.kind !== ReferenceKind.SCALAR)
|
|
40
|
+
prop
|
|
41
|
+
.targetMeta.props.filter(prop => prop.lazy || prop.kind !== ReferenceKind.SCALAR)
|
|
40
42
|
.forEach(prop => p.children.push({ field: prop.name, strategy: p.strategy }));
|
|
41
43
|
}
|
|
42
44
|
else if (prop.kind === ReferenceKind.EMBEDDED) {
|
|
@@ -67,3 +69,36 @@ export function getLoadingStrategy(strategy, kind) {
|
|
|
67
69
|
}
|
|
68
70
|
return strategy;
|
|
69
71
|
}
|
|
72
|
+
function findPopulateEntry(populate, parts) {
|
|
73
|
+
let current = populate;
|
|
74
|
+
for (let i = 0; i < parts.length; i++) {
|
|
75
|
+
const entry = current.find(p => p.field.split(':')[0] === parts[i]);
|
|
76
|
+
if (!entry) {
|
|
77
|
+
return undefined;
|
|
78
|
+
}
|
|
79
|
+
if (i === parts.length - 1) {
|
|
80
|
+
return entry;
|
|
81
|
+
}
|
|
82
|
+
current = (entry.children ?? []);
|
|
83
|
+
}
|
|
84
|
+
/* v8 ignore next */
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Applies per-relation overrides from `populateHints` to the normalized populate tree.
|
|
89
|
+
* @internal
|
|
90
|
+
*/
|
|
91
|
+
export function applyPopulateHints(populate, hints) {
|
|
92
|
+
for (const [path, hint] of Object.entries(hints)) {
|
|
93
|
+
const entry = findPopulateEntry(populate, path.split('.'));
|
|
94
|
+
if (!entry) {
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (hint.strategy != null) {
|
|
98
|
+
entry.strategy = hint.strategy;
|
|
99
|
+
}
|
|
100
|
+
if (hint.joinType != null) {
|
|
101
|
+
entry.joinType = hint.joinType;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EntityData, EntityMetadata, EntityProperty, FilterQuery } from '../typings.js';
|
|
2
|
+
/** @internal */
|
|
3
|
+
export declare function validateProperty<T extends object>(prop: EntityProperty, givenValue: any, entity: T): void;
|
|
4
|
+
/** @internal */
|
|
5
|
+
export declare function validateEntity<T extends object>(entity: T, meta: EntityMetadata<T>): void;
|
|
6
|
+
/** @internal */
|
|
7
|
+
export declare function validateParams(params: any, type?: string, field?: string): void;
|
|
8
|
+
/** @internal */
|
|
9
|
+
export declare function validatePrimaryKey<T>(entity: EntityData<T>, meta: EntityMetadata<T>): void;
|
|
10
|
+
/** @internal */
|
|
11
|
+
export declare function validateEmptyWhere<T>(where: FilterQuery<T>): void;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Utils } from '../utils/Utils.js';
|
|
2
|
+
import { ValidationError } from '../errors.js';
|
|
3
|
+
import { isRaw, Raw } from '../utils/RawQueryFragment.js';
|
|
4
|
+
import { SCALAR_TYPES } from '../enums.js';
|
|
5
|
+
/** @internal */
|
|
6
|
+
export function validateProperty(prop, givenValue, entity) {
|
|
7
|
+
if (givenValue == null || isRaw(givenValue)) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
const expectedType = prop.runtimeType;
|
|
11
|
+
const propName = prop.embedded ? prop.name.replace(/~/g, '.') : prop.name;
|
|
12
|
+
const givenType = Utils.getObjectType(givenValue);
|
|
13
|
+
if (prop.enum && prop.items) {
|
|
14
|
+
/* v8 ignore next */
|
|
15
|
+
if (!prop.items.some(it => it === givenValue)) {
|
|
16
|
+
throw ValidationError.fromWrongPropertyType(entity, propName, expectedType, givenType, givenValue);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
if (givenType !== expectedType && SCALAR_TYPES.has(expectedType)) {
|
|
21
|
+
throw ValidationError.fromWrongPropertyType(entity, propName, expectedType, givenType, givenValue);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function getValue(o, prop) {
|
|
26
|
+
if (prop.embedded && prop.embedded[0] in o) {
|
|
27
|
+
return o[prop.embedded[0]]?.[prop.embedded[1]];
|
|
28
|
+
}
|
|
29
|
+
/* v8 ignore next */
|
|
30
|
+
if (prop.ref) {
|
|
31
|
+
return o[prop.name]?.unwrap();
|
|
32
|
+
}
|
|
33
|
+
return o[prop.name];
|
|
34
|
+
}
|
|
35
|
+
/** @internal */
|
|
36
|
+
export function validateEntity(entity, meta) {
|
|
37
|
+
for (const prop of meta.validateProps) {
|
|
38
|
+
validateProperty(prop, getValue(entity, prop), entity);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/** @internal */
|
|
42
|
+
export function validateParams(params, type = 'search condition', field) {
|
|
43
|
+
if (Utils.isPrimaryKey(params) || Utils.isEntity(params)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
if (Array.isArray(params)) {
|
|
47
|
+
return params.forEach(item => validateParams(item, type, field));
|
|
48
|
+
}
|
|
49
|
+
if (Utils.isPlainObject(params)) {
|
|
50
|
+
Object.keys(params).forEach(k => validateParams(params[k], type, k));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/** @internal */
|
|
54
|
+
export function validatePrimaryKey(entity, meta) {
|
|
55
|
+
const pkExists = meta.primaryKeys.every(pk => entity[pk] != null) ||
|
|
56
|
+
(meta.serializedPrimaryKey && entity[meta.serializedPrimaryKey] != null);
|
|
57
|
+
if (!entity || !pkExists) {
|
|
58
|
+
throw ValidationError.fromMergeWithoutPK(meta);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/** @internal */
|
|
62
|
+
export function validateEmptyWhere(where) {
|
|
63
|
+
if (Utils.isEmpty(where) && !Raw.hasObjectFragments(where)) {
|
|
64
|
+
throw new Error(`You cannot call 'EntityManager.findOne()' with empty 'where' parameter`);
|
|
65
|
+
}
|
|
66
|
+
}
|
package/enums.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { EntityKey, ExpandProperty } from './typings.js';
|
|
2
2
|
import type { Transaction } from './connections/Connection.js';
|
|
3
3
|
import type { LogContext } from './logging/Logger.js';
|
|
4
4
|
export declare enum FlushMode {
|
|
@@ -42,6 +42,7 @@ export declare enum QueryOperator {
|
|
|
42
42
|
$none = "none",// collection operators, sql only
|
|
43
43
|
$some = "some",// collection operators, sql only
|
|
44
44
|
$every = "every",// collection operators, sql only
|
|
45
|
+
$size = "size",// collection operators, sql only
|
|
45
46
|
$hasKey = "?",// postgres only, json
|
|
46
47
|
$hasKeys = "?&",// postgres only, json
|
|
47
48
|
$hasSomeKeys = "?|"
|
|
@@ -71,7 +72,6 @@ export type QueryOrderKeys<T> = QueryOrderKeysFlat | QueryOrderMap<T>;
|
|
|
71
72
|
export type QueryOrderMap<T> = {
|
|
72
73
|
[K in EntityKey<T>]?: QueryOrderKeys<ExpandProperty<T[K]>>;
|
|
73
74
|
};
|
|
74
|
-
export type QBQueryOrderMap<T> = QueryOrderMap<T> | Dictionary;
|
|
75
75
|
export interface FlatQueryOrderMap {
|
|
76
76
|
[x: string]: QueryOrderKeysFlat;
|
|
77
77
|
}
|
|
@@ -89,7 +89,7 @@ export declare enum QueryFlag {
|
|
|
89
89
|
IDENTITY_INSERT = "IDENTITY_INSERT",// mssql only
|
|
90
90
|
OUTPUT_TABLE = "OUTPUT_TABLE"
|
|
91
91
|
}
|
|
92
|
-
export declare const SCALAR_TYPES: string
|
|
92
|
+
export declare const SCALAR_TYPES: Set<string>;
|
|
93
93
|
export declare enum ReferenceKind {
|
|
94
94
|
SCALAR = "scalar",
|
|
95
95
|
ONE_TO_ONE = "1:1",
|
|
@@ -170,11 +170,11 @@ export declare enum TransactionPropagation {
|
|
|
170
170
|
}
|
|
171
171
|
export interface TransactionOptions {
|
|
172
172
|
ctx?: Transaction;
|
|
173
|
-
propagation?: TransactionPropagation
|
|
174
|
-
isolationLevel?: IsolationLevel
|
|
173
|
+
propagation?: TransactionPropagation | `${TransactionPropagation}`;
|
|
174
|
+
isolationLevel?: IsolationLevel | `${IsolationLevel}`;
|
|
175
175
|
readOnly?: boolean;
|
|
176
176
|
clear?: boolean;
|
|
177
|
-
flushMode?: FlushMode
|
|
177
|
+
flushMode?: FlushMode | `${FlushMode}`;
|
|
178
178
|
ignoreNestedTransactions?: boolean;
|
|
179
179
|
loggerContext?: LogContext;
|
|
180
180
|
}
|
|
@@ -184,3 +184,5 @@ export declare enum DeferMode {
|
|
|
184
184
|
INITIALLY_IMMEDIATE = "immediate",
|
|
185
185
|
INITIALLY_DEFERRED = "deferred"
|
|
186
186
|
}
|
|
187
|
+
/** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
|
|
188
|
+
export type EmbeddedPrefixMode = 'absolute' | 'relative';
|
package/enums.js
CHANGED
|
@@ -44,26 +44,13 @@ export var QueryOperator;
|
|
|
44
44
|
QueryOperator["$none"] = "none";
|
|
45
45
|
QueryOperator["$some"] = "some";
|
|
46
46
|
QueryOperator["$every"] = "every";
|
|
47
|
+
QueryOperator["$size"] = "size";
|
|
47
48
|
QueryOperator["$hasKey"] = "?";
|
|
48
49
|
QueryOperator["$hasKeys"] = "?&";
|
|
49
50
|
QueryOperator["$hasSomeKeys"] = "?|";
|
|
50
51
|
})(QueryOperator || (QueryOperator = {}));
|
|
51
|
-
export const ARRAY_OPERATORS = [
|
|
52
|
-
|
|
53
|
-
'$gt',
|
|
54
|
-
'$gte',
|
|
55
|
-
'$lt',
|
|
56
|
-
'$lte',
|
|
57
|
-
'$ne',
|
|
58
|
-
'$overlap',
|
|
59
|
-
'$contains',
|
|
60
|
-
'$contained',
|
|
61
|
-
];
|
|
62
|
-
export const JSON_KEY_OPERATORS = [
|
|
63
|
-
'$hasKey',
|
|
64
|
-
'$hasKeys',
|
|
65
|
-
'$hasSomeKeys',
|
|
66
|
-
];
|
|
52
|
+
export const ARRAY_OPERATORS = ['$eq', '$gt', '$gte', '$lt', '$lte', '$ne', '$overlap', '$contains', '$contained'];
|
|
53
|
+
export const JSON_KEY_OPERATORS = ['$hasKey', '$hasKeys', '$hasSomeKeys'];
|
|
67
54
|
export var QueryOrder;
|
|
68
55
|
(function (QueryOrder) {
|
|
69
56
|
QueryOrder["ASC"] = "ASC";
|
|
@@ -99,7 +86,16 @@ export var QueryFlag;
|
|
|
99
86
|
QueryFlag["IDENTITY_INSERT"] = "IDENTITY_INSERT";
|
|
100
87
|
QueryFlag["OUTPUT_TABLE"] = "OUTPUT_TABLE";
|
|
101
88
|
})(QueryFlag || (QueryFlag = {}));
|
|
102
|
-
export const SCALAR_TYPES = [
|
|
89
|
+
export const SCALAR_TYPES = new Set([
|
|
90
|
+
'string',
|
|
91
|
+
'number',
|
|
92
|
+
'boolean',
|
|
93
|
+
'bigint',
|
|
94
|
+
'Uint8Array',
|
|
95
|
+
'Date',
|
|
96
|
+
'Buffer',
|
|
97
|
+
'RegExp',
|
|
98
|
+
]);
|
|
103
99
|
export var ReferenceKind;
|
|
104
100
|
(function (ReferenceKind) {
|
|
105
101
|
ReferenceKind["SCALAR"] = "scalar";
|
package/errors.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AnyEntity, Constructor, Dictionary, EntityMetadata, EntityProperty, IPrimaryKey } from './typings.js';
|
|
1
|
+
import type { AnyEntity, Constructor, Dictionary, EntityMetadata, EntityName, EntityProperty, IPrimaryKey } from './typings.js';
|
|
2
2
|
export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Error {
|
|
3
3
|
readonly entity?: T | undefined;
|
|
4
4
|
constructor(message: string, entity?: T | undefined);
|
|
@@ -8,13 +8,14 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
8
8
|
getEntity(): AnyEntity | undefined;
|
|
9
9
|
static fromWrongPropertyType(entity: AnyEntity, property: string, expectedType: string, givenType: string, givenValue: string): ValidationError;
|
|
10
10
|
static fromWrongRepositoryType(entityName: string, repoType: string, method: string): ValidationError;
|
|
11
|
-
static fromCollectionNotInitialized(entity: AnyEntity, prop: EntityProperty): ValidationError;
|
|
12
11
|
static fromMergeWithoutPK(meta: EntityMetadata): ValidationError;
|
|
13
12
|
static transactionRequired(): ValidationError;
|
|
14
13
|
static entityNotManaged(entity: AnyEntity): ValidationError;
|
|
15
14
|
static notEntity(owner: AnyEntity, prop: EntityProperty, data: any): ValidationError;
|
|
16
15
|
static notDiscoveredEntity(data: any, meta?: EntityMetadata, action?: string): ValidationError;
|
|
17
|
-
static invalidPropertyName(entityName:
|
|
16
|
+
static invalidPropertyName(entityName: EntityName, invalid: string): ValidationError;
|
|
17
|
+
static invalidCollectionValues(entityName: string, propName: string, invalid: unknown): ValidationError;
|
|
18
|
+
static invalidEnumArrayItems(entityName: string, invalid: unknown): ValidationError;
|
|
18
19
|
static invalidType(type: Constructor<any>, value: any, mode: string): ValidationError;
|
|
19
20
|
static propertyRequired(entity: AnyEntity, property: EntityProperty): ValidationError;
|
|
20
21
|
static cannotModifyInverseCollection(owner: AnyEntity, property: EntityProperty): ValidationError;
|
|
@@ -23,9 +24,10 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
|
|
|
23
24
|
static invalidCompositeIdentifier(meta: EntityMetadata): ValidationError;
|
|
24
25
|
static cannotCommit(): ValidationError;
|
|
25
26
|
static cannotUseGlobalContext(): ValidationError;
|
|
26
|
-
static cannotUseOperatorsInsideEmbeddables(
|
|
27
|
-
static cannotUseGroupOperatorsInsideScalars(
|
|
28
|
-
static invalidEmbeddableQuery(
|
|
27
|
+
static cannotUseOperatorsInsideEmbeddables(entityName: EntityName, propName: string, payload: unknown): ValidationError;
|
|
28
|
+
static cannotUseGroupOperatorsInsideScalars(entityName: EntityName, propName: string, payload: unknown): ValidationError;
|
|
29
|
+
static invalidEmbeddableQuery(entityName: EntityName, propName: string, embeddableType: string): ValidationError;
|
|
30
|
+
static invalidQueryCondition(cond: unknown): ValidationError;
|
|
29
31
|
}
|
|
30
32
|
export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
31
33
|
static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError;
|
|
@@ -44,28 +46,36 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
|
|
|
44
46
|
static fromWrongOwnership(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy'): MetadataError;
|
|
45
47
|
static fromWrongReferenceKind(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
|
|
46
48
|
static fromInversideSidePrimary(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
|
|
47
|
-
static entityNotFound(name: string, path: string): MetadataError;
|
|
48
49
|
static unknownIndexProperty(meta: EntityMetadata, prop: string, type: string): MetadataError;
|
|
49
50
|
static multipleVersionFields(meta: EntityMetadata, fields: string[]): MetadataError;
|
|
50
51
|
static invalidVersionFieldType(meta: EntityMetadata): MetadataError;
|
|
51
|
-
static fromUnknownEntity(
|
|
52
|
+
static fromUnknownEntity(entityName: string, source: string): MetadataError;
|
|
52
53
|
static noEntityDiscovered(): MetadataError;
|
|
53
54
|
static onlyAbstractEntitiesDiscovered(): MetadataError;
|
|
54
|
-
static duplicateEntityDiscovered(paths: string[]
|
|
55
|
-
static duplicateFieldName(
|
|
55
|
+
static duplicateEntityDiscovered(paths: string[]): MetadataError;
|
|
56
|
+
static duplicateFieldName(entityName: EntityName, names: [string, string][]): MetadataError;
|
|
56
57
|
static multipleDecorators(entityName: string, propertyName: string): MetadataError;
|
|
57
58
|
static missingMetadata(entity: string): MetadataError;
|
|
58
|
-
static invalidPrimaryKey(meta: EntityMetadata, prop: EntityProperty, requiredName: string): MetadataError
|
|
59
|
-
static invalidManyToManyWithPivotEntity(meta1: EntityMetadata, prop1: EntityProperty, meta2: EntityMetadata, prop2: EntityProperty): MetadataError
|
|
60
|
-
static targetIsAbstract(meta: EntityMetadata, prop: EntityProperty): MetadataError
|
|
61
|
-
static nonPersistentCompositeProp(meta: EntityMetadata, prop: EntityProperty): MetadataError
|
|
62
|
-
static propertyTargetsEntityType(meta: EntityMetadata, prop: EntityProperty, target: EntityMetadata): MetadataError
|
|
63
|
-
static fromMissingOption(meta: EntityMetadata, prop: EntityProperty, option: string): MetadataError
|
|
59
|
+
static invalidPrimaryKey(meta: EntityMetadata, prop: EntityProperty, requiredName: string): MetadataError;
|
|
60
|
+
static invalidManyToManyWithPivotEntity(meta1: EntityMetadata, prop1: EntityProperty, meta2: EntityMetadata, prop2: EntityProperty): MetadataError;
|
|
61
|
+
static targetIsAbstract(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
62
|
+
static nonPersistentCompositeProp(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
63
|
+
static propertyTargetsEntityType(meta: EntityMetadata, prop: EntityProperty, target: EntityMetadata): MetadataError;
|
|
64
|
+
static fromMissingOption(meta: EntityMetadata, prop: EntityProperty, option: string): MetadataError;
|
|
65
|
+
static targetKeyOnManyToMany(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
66
|
+
static targetKeyNotUnique(meta: EntityMetadata, prop: EntityProperty, target?: EntityMetadata): MetadataError;
|
|
67
|
+
static targetKeyNotFound(meta: EntityMetadata, prop: EntityProperty, target?: EntityMetadata): MetadataError;
|
|
68
|
+
static incompatiblePolymorphicTargets(meta: EntityMetadata, prop: EntityProperty, target1: EntityMetadata, target2: EntityMetadata, reason: string): MetadataError;
|
|
69
|
+
static dangerousPropertyName(meta: EntityMetadata, prop: EntityProperty): MetadataError;
|
|
70
|
+
static viewEntityWithoutExpression(meta: EntityMetadata): MetadataError;
|
|
71
|
+
static mixedInheritanceStrategies(root: EntityMetadata, child: EntityMetadata): MetadataError;
|
|
72
|
+
static tptNotSupportedByDriver(meta: EntityMetadata): MetadataError;
|
|
64
73
|
private static fromMessage;
|
|
65
74
|
}
|
|
66
75
|
export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
|
|
67
76
|
static findOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
|
|
68
77
|
static findExactlyOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
|
|
78
|
+
static failedToLoadProperty(name: string, propName: string, where: unknown): NotFoundError;
|
|
69
79
|
}
|
|
70
80
|
export declare class TransactionStateError extends ValidationError {
|
|
71
81
|
static requiredTransactionNotFound(propagation: string): TransactionStateError;
|
package/errors.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { inspect } from '
|
|
1
|
+
import { inspect } from './logging/inspect.js';
|
|
2
|
+
import { Utils } from './utils/Utils.js';
|
|
2
3
|
export class ValidationError extends Error {
|
|
3
4
|
entity;
|
|
4
5
|
constructor(message, entity) {
|
|
@@ -23,11 +24,6 @@ export class ValidationError extends Error {
|
|
|
23
24
|
const msg = `Trying to use EntityRepository.${method}() with '${entityName}' entity while the repository is of type '${repoType}'`;
|
|
24
25
|
return new ValidationError(msg);
|
|
25
26
|
}
|
|
26
|
-
static fromCollectionNotInitialized(entity, prop) {
|
|
27
|
-
const entityName = entity.constructor.name;
|
|
28
|
-
const msg = `${entityName}.${prop.name} is not initialized, define it as '${prop.name} = new Collection<${prop.type}>(this);'`;
|
|
29
|
-
return new ValidationError(msg);
|
|
30
|
-
}
|
|
31
27
|
static fromMergeWithoutPK(meta) {
|
|
32
28
|
return new ValidationError(`You cannot merge entity '${meta.className}' without identifier!`);
|
|
33
29
|
}
|
|
@@ -38,12 +34,12 @@ export class ValidationError extends Error {
|
|
|
38
34
|
return new ValidationError(`Entity ${entity.constructor.name} is not managed. An entity is managed if its fetched from the database or registered as new through EntityManager.persist()`);
|
|
39
35
|
}
|
|
40
36
|
static notEntity(owner, prop, data) {
|
|
41
|
-
const type = Object.prototype.toString.call(data)
|
|
37
|
+
const type = /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
|
|
42
38
|
return new ValidationError(`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
39
|
}
|
|
44
40
|
static notDiscoveredEntity(data, meta, action = 'persist') {
|
|
45
41
|
/* v8 ignore next */
|
|
46
|
-
const type = meta?.className ?? Object.prototype.toString.call(data)
|
|
42
|
+
const type = meta?.className ?? /\[object (\w+)]/.exec(Object.prototype.toString.call(data))[1].toLowerCase();
|
|
47
43
|
let err = `Trying to ${action} not discovered entity of type ${type}.`;
|
|
48
44
|
if (meta) {
|
|
49
45
|
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,10 +47,16 @@ export class ValidationError extends Error {
|
|
|
51
47
|
return new ValidationError(err);
|
|
52
48
|
}
|
|
53
49
|
static invalidPropertyName(entityName, invalid) {
|
|
54
|
-
return new ValidationError(`Entity '${entityName}' does not have property '${invalid}'`);
|
|
50
|
+
return new ValidationError(`Entity '${Utils.className(entityName)}' does not have property '${invalid}'`);
|
|
51
|
+
}
|
|
52
|
+
static invalidCollectionValues(entityName, propName, invalid) {
|
|
53
|
+
return new ValidationError(`Invalid collection values provided for '${entityName}.${propName}' in ${entityName}.assign(): ${inspect(invalid)}`);
|
|
54
|
+
}
|
|
55
|
+
static invalidEnumArrayItems(entityName, invalid) {
|
|
56
|
+
return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
|
|
55
57
|
}
|
|
56
58
|
static invalidType(type, value, mode) {
|
|
57
|
-
const valueType = Object.prototype.toString.call(value)
|
|
59
|
+
const valueType = /\[object (\w+)]/.exec(Object.prototype.toString.call(value))[1].toLowerCase();
|
|
58
60
|
if (value instanceof Date) {
|
|
59
61
|
value = value.toISOString();
|
|
60
62
|
}
|
|
@@ -67,8 +69,8 @@ export class ValidationError extends Error {
|
|
|
67
69
|
static cannotModifyInverseCollection(owner, property) {
|
|
68
70
|
const inverseCollection = `${owner.constructor.name}.${property.name}`;
|
|
69
71
|
const ownerCollection = `${property.type}.${property.mappedBy}`;
|
|
70
|
-
const error = `You cannot modify inverse side of M:N collection ${inverseCollection} when the owning side is not initialized. `
|
|
71
|
-
|
|
72
|
+
const error = `You cannot modify inverse side of M:N collection ${inverseCollection} when the owning side is not initialized. ` +
|
|
73
|
+
`Consider working with the owning side instead (${ownerCollection}).`;
|
|
72
74
|
return new ValidationError(error, owner);
|
|
73
75
|
}
|
|
74
76
|
static cannotModifyReadonlyCollection(owner, property) {
|
|
@@ -77,7 +79,7 @@ export class ValidationError extends Error {
|
|
|
77
79
|
static cannotRemoveFromCollectionWithoutOrphanRemoval(owner, property) {
|
|
78
80
|
const options = [
|
|
79
81
|
' - add `orphanRemoval: true` to the collection options',
|
|
80
|
-
|
|
82
|
+
" - add `deleteRule: 'cascade'` to the owning side options",
|
|
81
83
|
' - add `nullable: true` to the owning side options',
|
|
82
84
|
].join('\n');
|
|
83
85
|
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);
|
|
@@ -89,16 +91,20 @@ export class ValidationError extends Error {
|
|
|
89
91
|
return new ValidationError('You cannot call em.flush() from inside lifecycle hook handlers');
|
|
90
92
|
}
|
|
91
93
|
static cannotUseGlobalContext() {
|
|
92
|
-
return new ValidationError(
|
|
94
|
+
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.");
|
|
95
|
+
}
|
|
96
|
+
static cannotUseOperatorsInsideEmbeddables(entityName, propName, payload) {
|
|
97
|
+
return new ValidationError(`Using operators inside embeddables is not allowed, move the operator above. (property: ${Utils.className(entityName)}.${propName}, payload: ${inspect(payload)})`);
|
|
93
98
|
}
|
|
94
|
-
static
|
|
95
|
-
return new ValidationError(`Using operators inside
|
|
99
|
+
static cannotUseGroupOperatorsInsideScalars(entityName, propName, payload) {
|
|
100
|
+
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)})`);
|
|
96
101
|
}
|
|
97
|
-
static
|
|
98
|
-
return new ValidationError(`
|
|
102
|
+
static invalidEmbeddableQuery(entityName, propName, embeddableType) {
|
|
103
|
+
return new ValidationError(`Invalid query for entity '${Utils.className(entityName)}', property '${propName}' does not exist in embeddable '${embeddableType}'`);
|
|
99
104
|
}
|
|
100
|
-
|
|
101
|
-
|
|
105
|
+
/* v8 ignore next */
|
|
106
|
+
static invalidQueryCondition(cond) {
|
|
107
|
+
return new ValidationError(`Invalid query condition: ${inspect(cond, { depth: 5 })}`);
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
110
|
export class CursorError extends ValidationError {
|
|
@@ -154,22 +160,18 @@ export class MetadataError extends ValidationError {
|
|
|
154
160
|
static fromInversideSidePrimary(meta, owner, prop) {
|
|
155
161
|
return new MetadataError(`${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'.`);
|
|
156
162
|
}
|
|
157
|
-
/* v8 ignore next 3 */
|
|
158
|
-
static entityNotFound(name, path) {
|
|
159
|
-
return new MetadataError(`Entity '${name}' not found in ${path}`);
|
|
160
|
-
}
|
|
161
163
|
static unknownIndexProperty(meta, prop, type) {
|
|
162
164
|
return new MetadataError(`Entity ${meta.className} has wrong ${type} definition: '${prop}' does not exist. You need to use property name, not column name.`);
|
|
163
165
|
}
|
|
164
166
|
static multipleVersionFields(meta, fields) {
|
|
165
|
-
return new MetadataError(`Entity ${meta.className} has multiple version properties defined: '${fields.join('
|
|
167
|
+
return new MetadataError(`Entity ${meta.className} has multiple version properties defined: '${fields.join("', '")}'. Only one version property is allowed per entity.`);
|
|
166
168
|
}
|
|
167
169
|
static invalidVersionFieldType(meta) {
|
|
168
170
|
const prop = meta.properties[meta.versionProperty];
|
|
169
171
|
return new MetadataError(`Version property ${meta.className}.${prop.name} has unsupported type '${prop.type}'. Only 'number' and 'Date' are allowed.`);
|
|
170
172
|
}
|
|
171
|
-
static fromUnknownEntity(
|
|
172
|
-
return new MetadataError(`Entity '${
|
|
173
|
+
static fromUnknownEntity(entityName, source) {
|
|
174
|
+
return new MetadataError(`Entity '${entityName}' was not discovered, please make sure to provide it in 'entities' array when initializing the ORM (used in ${source})`);
|
|
173
175
|
}
|
|
174
176
|
static noEntityDiscovered() {
|
|
175
177
|
return new MetadataError('No entities were discovered');
|
|
@@ -177,11 +179,11 @@ export class MetadataError extends ValidationError {
|
|
|
177
179
|
static onlyAbstractEntitiesDiscovered() {
|
|
178
180
|
return new MetadataError('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.');
|
|
179
181
|
}
|
|
180
|
-
static duplicateEntityDiscovered(paths
|
|
181
|
-
return new MetadataError(`Duplicate
|
|
182
|
+
static duplicateEntityDiscovered(paths) {
|
|
183
|
+
return new MetadataError(`Duplicate table names are not allowed: ${paths.join(', ')}`);
|
|
182
184
|
}
|
|
183
|
-
static duplicateFieldName(
|
|
184
|
-
return new MetadataError(`Duplicate fieldNames are not allowed: ${names.map(n => `${className}.${n[0]} (fieldName: '${n[1]}')`).join(', ')}`);
|
|
185
|
+
static duplicateFieldName(entityName, names) {
|
|
186
|
+
return new MetadataError(`Duplicate fieldNames are not allowed: ${names.map(n => `${Utils.className(entityName)}.${n[0]} (fieldName: '${n[1]}')`).join(', ')}`);
|
|
185
187
|
}
|
|
186
188
|
static multipleDecorators(entityName, propertyName) {
|
|
187
189
|
return new MetadataError(`Multiple property decorators used on '${entityName}.${propertyName}' property`);
|
|
@@ -211,6 +213,32 @@ export class MetadataError extends ValidationError {
|
|
|
211
213
|
static fromMissingOption(meta, prop, option) {
|
|
212
214
|
return this.fromMessage(meta, prop, `is missing '${option}' option`);
|
|
213
215
|
}
|
|
216
|
+
static targetKeyOnManyToMany(meta, prop) {
|
|
217
|
+
return this.fromMessage(meta, prop, `uses 'targetKey' option which is not supported for ManyToMany relations`);
|
|
218
|
+
}
|
|
219
|
+
static targetKeyNotUnique(meta, prop, target) {
|
|
220
|
+
const targetName = target?.className ?? prop.type;
|
|
221
|
+
return this.fromMessage(meta, prop, `has 'targetKey' set to '${prop.targetKey}', but ${targetName}.${prop.targetKey} is not marked as unique`);
|
|
222
|
+
}
|
|
223
|
+
static targetKeyNotFound(meta, prop, target) {
|
|
224
|
+
const targetName = target?.className ?? prop.type;
|
|
225
|
+
return this.fromMessage(meta, prop, `has 'targetKey' set to '${prop.targetKey}', but ${targetName}.${prop.targetKey} does not exist`);
|
|
226
|
+
}
|
|
227
|
+
static incompatiblePolymorphicTargets(meta, prop, target1, target2, reason) {
|
|
228
|
+
return this.fromMessage(meta, prop, `has incompatible polymorphic targets ${target1.className} and ${target2.className}: ${reason}`);
|
|
229
|
+
}
|
|
230
|
+
static dangerousPropertyName(meta, prop) {
|
|
231
|
+
return this.fromMessage(meta, prop, `uses a dangerous property name '${prop.name}' which could lead to prototype pollution. Please use a different property name.`);
|
|
232
|
+
}
|
|
233
|
+
static viewEntityWithoutExpression(meta) {
|
|
234
|
+
return new MetadataError(`View entity ${meta.className} is missing 'expression'. View entities must have an expression defining the SQL query.`);
|
|
235
|
+
}
|
|
236
|
+
static mixedInheritanceStrategies(root, child) {
|
|
237
|
+
return new MetadataError(`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.`);
|
|
238
|
+
}
|
|
239
|
+
static tptNotSupportedByDriver(meta) {
|
|
240
|
+
return new MetadataError(`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.`);
|
|
241
|
+
}
|
|
214
242
|
static fromMessage(meta, prop, message) {
|
|
215
243
|
return new MetadataError(`${meta.className}.${prop.name} ${message}`);
|
|
216
244
|
}
|
|
@@ -222,6 +250,10 @@ export class NotFoundError extends ValidationError {
|
|
|
222
250
|
static findExactlyOneFailed(name, where) {
|
|
223
251
|
return new NotFoundError(`Wrong number of ${name} entities found for query ${inspect(where)}, expected exactly one`);
|
|
224
252
|
}
|
|
253
|
+
static failedToLoadProperty(name, propName, where) {
|
|
254
|
+
const whereString = typeof where === 'object' ? inspect(where) : where;
|
|
255
|
+
return new NotFoundError(`${name} (${whereString}) failed to load property '${propName}'`);
|
|
256
|
+
}
|
|
225
257
|
}
|
|
226
258
|
export class TransactionStateError extends ValidationError {
|
|
227
259
|
static requiredTransactionNotFound(propagation) {
|
package/events/EventManager.d.ts
CHANGED
|
@@ -2,12 +2,10 @@ import type { EntityMetadata } from '../typings.js';
|
|
|
2
2
|
import type { EventArgs, EventSubscriber, FlushEventArgs, TransactionEventArgs } from './EventSubscriber.js';
|
|
3
3
|
import { EventType, type TransactionEventType } from '../enums.js';
|
|
4
4
|
export declare class EventManager {
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
private readonly cache;
|
|
8
|
-
private readonly subscribers;
|
|
9
|
-
constructor(subscribers: EventSubscriber[]);
|
|
5
|
+
#private;
|
|
6
|
+
constructor(subscribers: Iterable<EventSubscriber>);
|
|
10
7
|
registerSubscriber(subscriber: EventSubscriber): void;
|
|
8
|
+
getSubscribers(): Set<EventSubscriber>;
|
|
11
9
|
dispatchEvent<T extends object>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
|
|
12
10
|
dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
|
|
13
11
|
dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;
|