@mikro-orm/core 7.0.0-dev.0 → 7.0.0-dev.2
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 +18 -13
- package/EntityManager.js +202 -202
- package/MikroORM.d.ts +7 -6
- package/MikroORM.js +33 -45
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +1 -1
- package/cache/FileCacheAdapter.js +18 -26
- package/cache/GeneratedCacheAdapter.d.ts +2 -2
- package/cache/GeneratedCacheAdapter.js +1 -5
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +5 -5
- package/cache/index.js +5 -21
- package/connections/Connection.d.ts +7 -7
- package/connections/Connection.js +8 -12
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/decorators/Check.d.ts +1 -1
- package/decorators/Check.js +5 -8
- package/decorators/CreateRequestContext.d.ts +1 -1
- package/decorators/CreateRequestContext.js +9 -13
- package/decorators/Embeddable.d.ts +1 -1
- package/decorators/Embeddable.js +3 -6
- package/decorators/Embedded.d.ts +1 -1
- package/decorators/Embedded.js +10 -12
- package/decorators/Entity.d.ts +2 -2
- package/decorators/Entity.js +5 -8
- package/decorators/Enum.d.ts +2 -2
- package/decorators/Enum.js +7 -10
- package/decorators/Filter.d.ts +1 -1
- package/decorators/Filter.js +3 -6
- package/decorators/Formula.d.ts +2 -2
- package/decorators/Formula.js +7 -10
- package/decorators/Indexed.d.ts +2 -2
- package/decorators/Indexed.js +6 -10
- package/decorators/ManyToMany.d.ts +3 -3
- package/decorators/ManyToMany.js +10 -12
- package/decorators/ManyToOne.d.ts +3 -3
- package/decorators/ManyToOne.js +10 -12
- package/decorators/OneToMany.d.ts +3 -3
- package/decorators/OneToMany.js +11 -14
- package/decorators/OneToOne.d.ts +4 -4
- package/decorators/OneToOne.js +4 -7
- package/decorators/PrimaryKey.d.ts +2 -2
- package/decorators/PrimaryKey.js +10 -13
- package/decorators/Property.d.ts +5 -5
- package/decorators/Property.js +10 -12
- package/decorators/Transactional.d.ts +2 -2
- package/decorators/Transactional.js +7 -10
- package/decorators/hooks.js +23 -35
- package/decorators/index.d.ts +17 -17
- package/decorators/index.js +17 -36
- package/drivers/DatabaseDriver.d.ts +13 -12
- package/drivers/DatabaseDriver.js +60 -64
- package/drivers/IDatabaseDriver.d.ts +12 -12
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/ArrayCollection.d.ts +2 -2
- package/entity/ArrayCollection.js +29 -33
- package/entity/BaseEntity.d.ts +6 -6
- package/entity/BaseEntity.js +17 -21
- package/entity/Collection.d.ts +6 -6
- package/entity/Collection.js +40 -44
- package/entity/EntityAssigner.d.ts +2 -2
- package/entity/EntityAssigner.js +58 -63
- package/entity/EntityFactory.d.ts +3 -3
- package/entity/EntityFactory.js +58 -62
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +41 -45
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +5 -5
- package/entity/EntityLoader.js +92 -96
- package/entity/EntityRepository.d.ts +7 -7
- package/entity/EntityRepository.js +7 -11
- package/entity/EntityValidator.d.ts +1 -1
- package/entity/EntityValidator.js +25 -29
- package/entity/Reference.d.ts +2 -2
- package/entity/Reference.js +35 -42
- package/entity/WrappedEntity.d.ts +12 -12
- package/entity/WrappedEntity.js +23 -27
- package/entity/index.d.ts +13 -13
- package/entity/index.js +13 -29
- package/entity/utils.d.ts +1 -1
- package/entity/utils.js +9 -12
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +3 -3
- package/enums.js +37 -41
- package/errors.d.ts +1 -1
- package/errors.js +15 -24
- package/events/EventManager.d.ts +3 -3
- package/events/EventManager.js +8 -12
- package/events/EventSubscriber.d.ts +5 -4
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +3 -6
- package/hydration/ObjectHydrator.d.ts +3 -3
- package/hydration/ObjectHydrator.js +25 -28
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +21 -46
- package/logging/DefaultLogger.d.ts +1 -1
- package/logging/DefaultLogger.js +9 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +2 -2
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +4 -4
- package/logging/index.js +4 -20
- package/metadata/EntitySchema.d.ts +12 -4
- package/metadata/EntitySchema.js +41 -45
- package/metadata/MetadataDiscovery.d.ts +7 -7
- package/metadata/MetadataDiscovery.js +174 -177
- package/metadata/MetadataProvider.d.ts +2 -2
- package/metadata/MetadataProvider.js +4 -7
- package/metadata/MetadataStorage.d.ts +2 -2
- package/metadata/MetadataStorage.js +15 -19
- package/metadata/MetadataValidator.d.ts +4 -4
- package/metadata/MetadataValidator.js +49 -53
- package/metadata/ReflectMetadataProvider.d.ts +2 -2
- package/metadata/ReflectMetadataProvider.js +8 -12
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
- package/naming-strategy/AbstractNamingStrategy.js +4 -8
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +1 -1
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/package.json +5 -14
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +10 -10
- package/platforms/Platform.js +57 -61
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +2 -2
- package/serialization/EntitySerializer.js +36 -41
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +27 -31
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +10 -14
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +7 -11
- package/types/BigIntType.d.ts +3 -3
- package/types/BigIntType.js +3 -6
- package/types/BlobType.d.ts +3 -3
- package/types/BlobType.js +2 -8
- package/types/BooleanType.d.ts +3 -3
- package/types/BooleanType.js +2 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +3 -3
- package/types/DecimalType.js +4 -7
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +3 -6
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +5 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +3 -3
- package/types/JsonType.js +2 -6
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +2 -2
- package/types/Type.js +5 -9
- package/types/Uint8ArrayType.d.ts +3 -3
- package/types/Uint8ArrayType.js +3 -9
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +22 -20
- package/typings.js +34 -38
- package/unit-of-work/ChangeSet.d.ts +1 -1
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -7
- package/unit-of-work/ChangeSetComputer.js +26 -30
- package/unit-of-work/ChangeSetPersister.d.ts +7 -6
- package/unit-of-work/ChangeSetPersister.js +44 -47
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +8 -7
- package/unit-of-work/UnitOfWork.js +171 -172
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +6 -6
- package/utils/AbstractSchemaGenerator.js +7 -11
- package/utils/Configuration.d.ts +26 -27
- package/utils/Configuration.js +50 -55
- package/utils/ConfigurationLoader.d.ts +9 -8
- package/utils/ConfigurationLoader.js +71 -86
- package/utils/Cursor.d.ts +3 -3
- package/utils/Cursor.js +22 -25
- package/utils/DataloaderUtils.d.ts +4 -4
- package/utils/DataloaderUtils.js +12 -16
- package/utils/EntityComparator.d.ts +2 -2
- package/utils/EntityComparator.js +48 -52
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +3 -3
- package/utils/QueryHelper.js +47 -51
- package/utils/RawQueryFragment.d.ts +1 -1
- package/utils/RawQueryFragment.js +16 -24
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/Utils.d.ts +16 -12
- package/utils/Utils.js +89 -93
- package/utils/clone.js +8 -11
- package/utils/index.d.ts +13 -13
- package/utils/index.js +13 -29
- package/utils/resolveContextProvider.d.ts +3 -3
- package/utils/resolveContextProvider.js +9 -12
- package/utils/upsert-utils.d.ts +3 -3
- package/utils/upsert-utils.js +5 -9
- package/index.mjs +0 -199
package/decorators/index.js
CHANGED
|
@@ -1,36 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/* istanbul ignore file */
|
|
19
|
-
__exportStar(require("./PrimaryKey"), exports);
|
|
20
|
-
__exportStar(require("./Entity"), exports);
|
|
21
|
-
__exportStar(require("./OneToOne"), exports);
|
|
22
|
-
__exportStar(require("./ManyToOne"), exports);
|
|
23
|
-
__exportStar(require("./ManyToMany"), exports);
|
|
24
|
-
var OneToMany_1 = require("./OneToMany");
|
|
25
|
-
Object.defineProperty(exports, "OneToMany", { enumerable: true, get: function () { return OneToMany_1.OneToMany; } });
|
|
26
|
-
__exportStar(require("./Property"), exports);
|
|
27
|
-
__exportStar(require("./Check"), exports);
|
|
28
|
-
__exportStar(require("./Enum"), exports);
|
|
29
|
-
__exportStar(require("./Formula"), exports);
|
|
30
|
-
__exportStar(require("./Indexed"), exports);
|
|
31
|
-
__exportStar(require("./Embeddable"), exports);
|
|
32
|
-
__exportStar(require("./Embedded"), exports);
|
|
33
|
-
__exportStar(require("./Filter"), exports);
|
|
34
|
-
__exportStar(require("./CreateRequestContext"), exports);
|
|
35
|
-
__exportStar(require("./hooks"), exports);
|
|
36
|
-
__exportStar(require("./Transactional"), exports);
|
|
1
|
+
export * from './PrimaryKey.js';
|
|
2
|
+
export * from './Entity.js';
|
|
3
|
+
export * from './OneToOne.js';
|
|
4
|
+
export * from './ManyToOne.js';
|
|
5
|
+
export * from './ManyToMany.js';
|
|
6
|
+
export { OneToMany } from './OneToMany.js';
|
|
7
|
+
export * from './Property.js';
|
|
8
|
+
export * from './Check.js';
|
|
9
|
+
export * from './Enum.js';
|
|
10
|
+
export * from './Formula.js';
|
|
11
|
+
export * from './Indexed.js';
|
|
12
|
+
export * from './Embeddable.js';
|
|
13
|
+
export * from './Embedded.js';
|
|
14
|
+
export * from './Filter.js';
|
|
15
|
+
export * from './CreateRequestContext.js';
|
|
16
|
+
export * from './hooks.js';
|
|
17
|
+
export * from './Transactional.js';
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition } from './IDatabaseDriver';
|
|
2
|
-
import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings';
|
|
3
|
-
import type { MetadataStorage } from '../metadata';
|
|
4
|
-
import type { Connection, QueryResult, Transaction } from '../connections';
|
|
5
|
-
import { type Configuration, type ConnectionOptions
|
|
6
|
-
import {
|
|
7
|
-
import type
|
|
8
|
-
import type {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
1
|
+
import { type CountOptions, type DeleteOptions, type DriverMethodOptions, EntityManagerType, type FindOneOptions, type FindOptions, type IDatabaseDriver, type LockOptions, type NativeInsertUpdateManyOptions, type NativeInsertUpdateOptions, type OrderDefinition } from './IDatabaseDriver.js';
|
|
2
|
+
import type { ConnectionType, Dictionary, EntityData, EntityDictionary, EntityMetadata, EntityProperty, FilterQuery, PopulateOptions, Primary } from '../typings.js';
|
|
3
|
+
import type { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
4
|
+
import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
|
|
5
|
+
import { type Configuration, type ConnectionOptions } from '../utils/Configuration.js';
|
|
6
|
+
import { EntityComparator } from '../utils/EntityComparator.js';
|
|
7
|
+
import { type QueryOrder } from '../enums.js';
|
|
8
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
9
|
+
import type { Collection } from '../entity/Collection.js';
|
|
10
|
+
import { EntityManager } from '../EntityManager.js';
|
|
11
|
+
import { DriverException } from '../exceptions.js';
|
|
12
|
+
import type { Logger } from '../logging/Logger.js';
|
|
12
13
|
export declare abstract class DatabaseDriver<C extends Connection> implements IDatabaseDriver<C> {
|
|
13
14
|
readonly config: Configuration;
|
|
14
15
|
protected readonly dependencies: string[];
|
|
@@ -28,7 +29,7 @@ export declare abstract class DatabaseDriver<C extends Connection> implements ID
|
|
|
28
29
|
nativeUpdateMany<T extends object>(entityName: string, where: FilterQuery<T>[], data: EntityDictionary<T>[], options?: NativeInsertUpdateManyOptions<T>): Promise<QueryResult<T>>;
|
|
29
30
|
abstract nativeDelete<T extends object>(entityName: string, where: FilterQuery<T>, options?: DeleteOptions<T>): Promise<QueryResult<T>>;
|
|
30
31
|
abstract count<T extends object, P extends string = never>(entityName: string, where: FilterQuery<T>, options?: CountOptions<T, P>): Promise<number>;
|
|
31
|
-
createEntityManager
|
|
32
|
+
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
32
33
|
findVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: FindOptions<T, any, any, any>): Promise<EntityData<T>[]>;
|
|
33
34
|
countVirtual<T extends object>(entityName: string, where: FilterQuery<T>, options: CountOptions<T, any>): Promise<number>;
|
|
34
35
|
aggregate(entityName: string, pipeline: any[]): Promise<any[]>;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class DatabaseDriver {
|
|
1
|
+
import { EntityManagerType, } from './IDatabaseDriver.js';
|
|
2
|
+
import { Utils } from '../utils/Utils.js';
|
|
3
|
+
import { Cursor } from '../utils/Cursor.js';
|
|
4
|
+
import { EntityComparator } from '../utils/EntityComparator.js';
|
|
5
|
+
import { isRaw, raw } from '../utils/RawQueryFragment.js';
|
|
6
|
+
import { QueryOrderNumeric, ReferenceKind } from '../enums.js';
|
|
7
|
+
import { EntityManager } from '../EntityManager.js';
|
|
8
|
+
import { CursorError, ValidationError } from '../errors.js';
|
|
9
|
+
import { DriverException } from '../exceptions.js';
|
|
10
|
+
import { helper } from '../entity/wrap.js';
|
|
11
|
+
import { JsonType } from '../types/JsonType.js';
|
|
12
|
+
export class DatabaseDriver {
|
|
13
13
|
config;
|
|
14
14
|
dependencies;
|
|
15
|
-
[
|
|
15
|
+
[EntityManagerType];
|
|
16
16
|
connection;
|
|
17
17
|
replicas = [];
|
|
18
18
|
platform;
|
|
@@ -28,14 +28,14 @@ class DatabaseDriver {
|
|
|
28
28
|
throw new Error(`Batch updates are not supported by ${this.constructor.name} driver`);
|
|
29
29
|
}
|
|
30
30
|
createEntityManager(useContext) {
|
|
31
|
-
const EntityManagerClass = this.config.get('entityManager',
|
|
31
|
+
const EntityManagerClass = this.config.get('entityManager', EntityManager);
|
|
32
32
|
return new EntityManagerClass(this.config, this, this.metadata, useContext);
|
|
33
33
|
}
|
|
34
|
-
/*
|
|
34
|
+
/* v8 ignore next 3 */
|
|
35
35
|
async findVirtual(entityName, where, options) {
|
|
36
36
|
throw new Error(`Virtual entities are not supported by ${this.constructor.name} driver.`);
|
|
37
37
|
}
|
|
38
|
-
/*
|
|
38
|
+
/* v8 ignore next 3 */
|
|
39
39
|
async countVirtual(entityName, where, options) {
|
|
40
40
|
throw new Error(`Counting virtual entities is not supported by ${this.constructor.name} driver.`);
|
|
41
41
|
}
|
|
@@ -49,16 +49,14 @@ class DatabaseDriver {
|
|
|
49
49
|
for (const coll of collections) {
|
|
50
50
|
if (!coll.property.owner) {
|
|
51
51
|
if (coll.getSnapshot() === undefined) {
|
|
52
|
-
throw
|
|
52
|
+
throw ValidationError.cannotModifyInverseCollection(coll.owner, coll.property);
|
|
53
53
|
}
|
|
54
54
|
continue;
|
|
55
55
|
}
|
|
56
|
-
/*
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
await this.nativeUpdate(coll.owner.constructor.name, (0, wrap_1.helper)(coll.owner).getPrimaryKey(), data, options);
|
|
61
|
-
}
|
|
56
|
+
/* v8 ignore next 3 */
|
|
57
|
+
const pk = coll.property.targetMeta.primaryKeys[0];
|
|
58
|
+
const data = { [coll.property.name]: coll.getIdentifiers(pk) };
|
|
59
|
+
await this.nativeUpdate(coll.owner.constructor.name, helper(coll.owner).getPrimaryKey(), data, options);
|
|
62
60
|
}
|
|
63
61
|
}
|
|
64
62
|
mapResult(result, meta, populate = []) {
|
|
@@ -81,7 +79,7 @@ class DatabaseDriver {
|
|
|
81
79
|
if (type === 'write' || this.replicas.length === 0) {
|
|
82
80
|
return this.connection;
|
|
83
81
|
}
|
|
84
|
-
const rand =
|
|
82
|
+
const rand = Utils.randomInt(0, this.replicas.length - 1);
|
|
85
83
|
return this.replicas[rand];
|
|
86
84
|
}
|
|
87
85
|
async close(force) {
|
|
@@ -93,7 +91,7 @@ class DatabaseDriver {
|
|
|
93
91
|
}
|
|
94
92
|
setMetadata(metadata) {
|
|
95
93
|
this.metadata = metadata;
|
|
96
|
-
this.comparator = new
|
|
94
|
+
this.comparator = new EntityComparator(this.metadata, this.platform);
|
|
97
95
|
this.connection.setMetadata(metadata);
|
|
98
96
|
this.connection.setPlatform(this.platform);
|
|
99
97
|
this.replicas.forEach(replica => {
|
|
@@ -111,7 +109,7 @@ class DatabaseDriver {
|
|
|
111
109
|
const { first, last, before, after, overfetch } = options;
|
|
112
110
|
const limit = first ?? last;
|
|
113
111
|
const isLast = !first && !!last;
|
|
114
|
-
const definition =
|
|
112
|
+
const definition = Cursor.getDefinition(meta, orderBy);
|
|
115
113
|
const $and = [];
|
|
116
114
|
// allow POJO as well, we care only about the correct key being present
|
|
117
115
|
const isCursor = (val, key) => {
|
|
@@ -119,15 +117,15 @@ class DatabaseDriver {
|
|
|
119
117
|
};
|
|
120
118
|
const createCursor = (val, key, inverse = false) => {
|
|
121
119
|
let def = isCursor(val, key) ? val[key] : val;
|
|
122
|
-
if (
|
|
123
|
-
def =
|
|
120
|
+
if (Utils.isPlainObject(def)) {
|
|
121
|
+
def = Cursor.for(meta, def, orderBy);
|
|
124
122
|
}
|
|
125
|
-
/*
|
|
126
|
-
const offsets = def ?
|
|
123
|
+
/* v8 ignore next */
|
|
124
|
+
const offsets = def ? Cursor.decode(def) : [];
|
|
127
125
|
if (definition.length === offsets.length) {
|
|
128
126
|
return this.createCursorCondition(definition, offsets, inverse, meta);
|
|
129
127
|
}
|
|
130
|
-
/*
|
|
128
|
+
/* v8 ignore next */
|
|
131
129
|
return {};
|
|
132
130
|
};
|
|
133
131
|
if (after) {
|
|
@@ -140,15 +138,15 @@ class DatabaseDriver {
|
|
|
140
138
|
options.limit = limit + (overfetch ? 1 : 0);
|
|
141
139
|
}
|
|
142
140
|
const createOrderBy = (prop, direction) => {
|
|
143
|
-
if (
|
|
144
|
-
const value =
|
|
141
|
+
if (Utils.isPlainObject(direction)) {
|
|
142
|
+
const value = Utils.keys(direction).reduce((o, key) => {
|
|
145
143
|
Object.assign(o, createOrderBy(key, direction[key]));
|
|
146
144
|
return o;
|
|
147
145
|
}, {});
|
|
148
146
|
return ({ [prop]: value });
|
|
149
147
|
}
|
|
150
|
-
const desc = direction ===
|
|
151
|
-
const dir =
|
|
148
|
+
const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
|
|
149
|
+
const dir = Utils.xor(desc, isLast) ? 'desc' : 'asc';
|
|
152
150
|
return ({ [prop]: dir });
|
|
153
151
|
};
|
|
154
152
|
return {
|
|
@@ -156,24 +154,23 @@ class DatabaseDriver {
|
|
|
156
154
|
where: ($and.length > 1 ? { $and } : { ...$and[0] }),
|
|
157
155
|
};
|
|
158
156
|
}
|
|
159
|
-
/* istanbul ignore next */
|
|
160
157
|
createCursorCondition(definition, offsets, inverse, meta) {
|
|
161
158
|
const createCondition = (prop, direction, offset, eq = false) => {
|
|
162
159
|
if (offset === null) {
|
|
163
|
-
throw
|
|
160
|
+
throw CursorError.missingValue(meta.className, prop);
|
|
164
161
|
}
|
|
165
|
-
if (
|
|
166
|
-
const value =
|
|
167
|
-
if (
|
|
168
|
-
throw
|
|
162
|
+
if (Utils.isPlainObject(direction)) {
|
|
163
|
+
const value = Utils.keys(direction).reduce((o, key) => {
|
|
164
|
+
if (Utils.isEmpty(offset[key])) {
|
|
165
|
+
throw CursorError.missingValue(meta.className, `${prop}.${key}`);
|
|
169
166
|
}
|
|
170
167
|
Object.assign(o, createCondition(key, direction[key], offset[key], eq));
|
|
171
168
|
return o;
|
|
172
169
|
}, {});
|
|
173
170
|
return ({ [prop]: value });
|
|
174
171
|
}
|
|
175
|
-
const desc = direction ===
|
|
176
|
-
const operator =
|
|
172
|
+
const desc = direction === QueryOrderNumeric.DESC || direction.toString().toLowerCase() === 'desc';
|
|
173
|
+
const operator = Utils.xor(desc, inverse) ? '$lt' : '$gt';
|
|
177
174
|
return { [prop]: { [operator + (eq ? 'e' : '')]: offset } };
|
|
178
175
|
};
|
|
179
176
|
const [order, ...otherOrders] = definition;
|
|
@@ -222,7 +219,7 @@ class DatabaseDriver {
|
|
|
222
219
|
return;
|
|
223
220
|
}
|
|
224
221
|
if (prop.joinColumns && Array.isArray(data[k])) {
|
|
225
|
-
const copy =
|
|
222
|
+
const copy = Utils.flatten(data[k]);
|
|
226
223
|
delete data[k];
|
|
227
224
|
prop.joinColumns.forEach((joinColumn, idx) => data[joinColumn] = copy[idx]);
|
|
228
225
|
return;
|
|
@@ -232,49 +229,49 @@ class DatabaseDriver {
|
|
|
232
229
|
prop.ownColumns.forEach(joinColumn => data[joinColumn] = null);
|
|
233
230
|
return;
|
|
234
231
|
}
|
|
235
|
-
if (prop.customType && convertCustomTypes && !(prop.customType instanceof
|
|
232
|
+
if (prop.customType && convertCustomTypes && !(prop.customType instanceof JsonType && object) && !isRaw(data[k])) {
|
|
236
233
|
data[k] = prop.customType.convertToDatabaseValue(data[k], this.platform, { fromQuery: true, key: k, mode: 'query-data' });
|
|
237
234
|
}
|
|
238
|
-
if (prop.hasConvertToDatabaseValueSQL && !prop.object && !
|
|
235
|
+
if (prop.hasConvertToDatabaseValueSQL && !prop.object && !isRaw(data[k])) {
|
|
239
236
|
const quoted = this.platform.quoteValue(data[k]);
|
|
240
237
|
const sql = prop.customType.convertToDatabaseValueSQL(quoted, this.platform);
|
|
241
|
-
data[k] =
|
|
238
|
+
data[k] = raw(sql.replace(/\?/g, '\\?'));
|
|
242
239
|
}
|
|
243
240
|
if (prop.fieldNames) {
|
|
244
|
-
|
|
241
|
+
Utils.renameKey(data, k, prop.fieldNames[0]);
|
|
245
242
|
}
|
|
246
243
|
});
|
|
247
244
|
return data;
|
|
248
245
|
}
|
|
249
246
|
inlineEmbeddables(meta, data, where) {
|
|
250
|
-
/*
|
|
247
|
+
/* v8 ignore next 3 */
|
|
251
248
|
if (data == null) {
|
|
252
249
|
return;
|
|
253
250
|
}
|
|
254
|
-
|
|
255
|
-
if (
|
|
256
|
-
|
|
251
|
+
Utils.keys(data).forEach(k => {
|
|
252
|
+
if (Utils.isOperator(k)) {
|
|
253
|
+
Utils.asArray(data[k]).forEach(payload => this.inlineEmbeddables(meta, payload, where));
|
|
257
254
|
}
|
|
258
255
|
});
|
|
259
256
|
meta.props.forEach(prop => {
|
|
260
|
-
if (prop.kind ===
|
|
257
|
+
if (prop.kind === ReferenceKind.EMBEDDED && prop.object && !where && Utils.isObject(data[prop.name])) {
|
|
261
258
|
return;
|
|
262
259
|
}
|
|
263
|
-
if (prop.kind ===
|
|
260
|
+
if (prop.kind === ReferenceKind.EMBEDDED && Utils.isObject(data[prop.name])) {
|
|
264
261
|
const props = prop.embeddedProps;
|
|
265
262
|
let unknownProp = false;
|
|
266
263
|
Object.keys(data[prop.name]).forEach(kk => {
|
|
267
264
|
// explicitly allow `$exists`, `$eq` and `$ne` operators here as they can't be misused this way
|
|
268
|
-
const operator = Object.keys(data[prop.name]).some(f =>
|
|
265
|
+
const operator = Object.keys(data[prop.name]).some(f => Utils.isOperator(f) && !['$exists', '$ne', '$eq'].includes(f));
|
|
269
266
|
if (operator) {
|
|
270
|
-
throw
|
|
267
|
+
throw ValidationError.cannotUseOperatorsInsideEmbeddables(meta.className, prop.name, data);
|
|
271
268
|
}
|
|
272
269
|
if (prop.object && where) {
|
|
273
270
|
const inline = (payload, sub, path) => {
|
|
274
|
-
if (sub.kind ===
|
|
271
|
+
if (sub.kind === ReferenceKind.EMBEDDED && Utils.isObject(payload[sub.embedded[1]])) {
|
|
275
272
|
return Object.keys(payload[sub.embedded[1]]).forEach(kkk => {
|
|
276
273
|
if (!sub.embeddedProps[kkk]) {
|
|
277
|
-
throw
|
|
274
|
+
throw ValidationError.invalidEmbeddableQuery(meta.className, kkk, sub.type);
|
|
278
275
|
}
|
|
279
276
|
inline(payload[sub.embedded[1]], sub.embeddedProps[kkk], [...path, sub.embedded[1]]);
|
|
280
277
|
});
|
|
@@ -284,7 +281,7 @@ class DatabaseDriver {
|
|
|
284
281
|
const parentPropName = kk.substring(0, kk.indexOf('.'));
|
|
285
282
|
// we might be using some native JSON operator, e.g. with mongodb's `$geoWithin` or `$exists`
|
|
286
283
|
if (props[kk]) {
|
|
287
|
-
/*
|
|
284
|
+
/* v8 ignore next */
|
|
288
285
|
inline(data[prop.name], props[kk] || props[parentPropName], [prop.name]);
|
|
289
286
|
}
|
|
290
287
|
else if (props[parentPropName]) {
|
|
@@ -298,7 +295,7 @@ class DatabaseDriver {
|
|
|
298
295
|
data[props[kk].name] = data[prop.name][props[kk].embedded[1]];
|
|
299
296
|
}
|
|
300
297
|
else {
|
|
301
|
-
throw
|
|
298
|
+
throw ValidationError.invalidEmbeddableQuery(meta.className, kk, prop.type);
|
|
302
299
|
}
|
|
303
300
|
});
|
|
304
301
|
if (!unknownProp) {
|
|
@@ -309,14 +306,14 @@ class DatabaseDriver {
|
|
|
309
306
|
}
|
|
310
307
|
getPrimaryKeyFields(entityName) {
|
|
311
308
|
const meta = this.metadata.find(entityName);
|
|
312
|
-
return meta ?
|
|
309
|
+
return meta ? Utils.flatten(meta.getPrimaryProps().map(pk => pk.fieldNames)) : [this.config.getNamingStrategy().referenceColumnName()];
|
|
313
310
|
}
|
|
314
311
|
createReplicas(cb) {
|
|
315
312
|
const replicas = this.config.get('replicas', []);
|
|
316
313
|
const ret = [];
|
|
317
314
|
const props = ['dbName', 'clientUrl', 'host', 'port', 'user', 'password', 'multipleStatements', 'pool', 'name', 'driverOptions'];
|
|
318
315
|
for (const conf of replicas) {
|
|
319
|
-
const replicaConfig =
|
|
316
|
+
const replicaConfig = Utils.copy(conf);
|
|
320
317
|
for (const prop of props) {
|
|
321
318
|
if (conf[prop]) {
|
|
322
319
|
continue;
|
|
@@ -341,7 +338,7 @@ class DatabaseDriver {
|
|
|
341
338
|
* @inheritDoc
|
|
342
339
|
*/
|
|
343
340
|
convertException(exception) {
|
|
344
|
-
if (exception instanceof
|
|
341
|
+
if (exception instanceof DriverException) {
|
|
345
342
|
return exception;
|
|
346
343
|
}
|
|
347
344
|
return this.platform.getExceptionConverter().convertException(exception);
|
|
@@ -376,4 +373,3 @@ class DatabaseDriver {
|
|
|
376
373
|
return options?.schema ?? options?.parentSchema ?? schemaName ?? this.config.getSchema();
|
|
377
374
|
}
|
|
378
375
|
}
|
|
379
|
-
exports.DatabaseDriver = DatabaseDriver;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate } from '../typings';
|
|
2
|
-
import type { Connection, QueryResult, Transaction } from '../connections';
|
|
3
|
-
import type { FlushMode, LockMode, QueryOrderMap, QueryFlag, LoadStrategy, PopulateHint, PopulatePath } from '../enums';
|
|
4
|
-
import type { Platform } from '../platforms';
|
|
5
|
-
import type { MetadataStorage } from '../metadata';
|
|
6
|
-
import type { Collection } from '../entity/Collection';
|
|
7
|
-
import type { EntityManager } from '../EntityManager';
|
|
8
|
-
import type { DriverException } from '../exceptions';
|
|
9
|
-
import type { Configuration } from '../utils/Configuration';
|
|
10
|
-
import type { LoggingOptions, LogContext } from '../logging';
|
|
11
|
-
import type { RawQueryFragment } from '../utils/RawQueryFragment';
|
|
1
|
+
import type { ConnectionType, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary, Dictionary, QBFilterQuery, IPrimaryKey, PopulateOptions, EntityDictionary, AutoPath, ObjectQuery, FilterObject, Populate } from '../typings.js';
|
|
2
|
+
import type { Connection, QueryResult, Transaction } from '../connections/Connection.js';
|
|
3
|
+
import type { FlushMode, LockMode, QueryOrderMap, QueryFlag, LoadStrategy, PopulateHint, PopulatePath } from '../enums.js';
|
|
4
|
+
import type { Platform } from '../platforms/Platform.js';
|
|
5
|
+
import type { MetadataStorage } from '../metadata/MetadataStorage.js';
|
|
6
|
+
import type { Collection } from '../entity/Collection.js';
|
|
7
|
+
import type { EntityManager } from '../EntityManager.js';
|
|
8
|
+
import type { DriverException } from '../exceptions.js';
|
|
9
|
+
import type { Configuration } from '../utils/Configuration.js';
|
|
10
|
+
import type { LoggingOptions, LogContext } from '../logging/Logger.js';
|
|
11
|
+
import type { RawQueryFragment } from '../utils/RawQueryFragment.js';
|
|
12
12
|
export declare const EntityManagerType: unique symbol;
|
|
13
13
|
export interface IDatabaseDriver<C extends Connection = Connection> {
|
|
14
14
|
[EntityManagerType]: EntityManager<this>;
|
|
15
15
|
readonly config: Configuration;
|
|
16
|
-
createEntityManager
|
|
16
|
+
createEntityManager(useContext?: boolean): this[typeof EntityManagerType];
|
|
17
17
|
connect(): Promise<C>;
|
|
18
18
|
close(force?: boolean): Promise<void>;
|
|
19
19
|
reconnect(): Promise<C>;
|
package/drivers/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from './IDatabaseDriver';
|
|
2
|
-
export * from './DatabaseDriver';
|
|
1
|
+
export * from './IDatabaseDriver.js';
|
|
2
|
+
export * from './DatabaseDriver.js';
|
package/drivers/index.js
CHANGED
|
@@ -1,18 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./IDatabaseDriver"), exports);
|
|
18
|
-
__exportStar(require("./DatabaseDriver"), exports);
|
|
1
|
+
export * from './IDatabaseDriver.js';
|
|
2
|
+
export * from './DatabaseDriver.js';
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inspect } from 'node:util';
|
|
2
|
-
import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings';
|
|
3
|
-
import { Reference } from './Reference';
|
|
2
|
+
import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings.js';
|
|
3
|
+
import { Reference } from './Reference.js';
|
|
4
4
|
export declare class ArrayCollection<T extends object, O extends object> {
|
|
5
5
|
readonly owner: O;
|
|
6
6
|
protected readonly items: Set<T>;
|
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const enums_1 = require("../enums");
|
|
9
|
-
const Utils_1 = require("../utils/Utils");
|
|
10
|
-
class ArrayCollection {
|
|
1
|
+
import { inspect } from 'node:util';
|
|
2
|
+
import { Reference } from './Reference.js';
|
|
3
|
+
import { helper, wrap } from './wrap.js';
|
|
4
|
+
import { MetadataError, ValidationError } from '../errors.js';
|
|
5
|
+
import { ReferenceKind } from '../enums.js';
|
|
6
|
+
import { Utils } from '../utils/Utils.js';
|
|
7
|
+
export class ArrayCollection {
|
|
11
8
|
owner;
|
|
12
9
|
items = new Set();
|
|
13
10
|
initialized = true;
|
|
@@ -17,7 +14,7 @@ class ArrayCollection {
|
|
|
17
14
|
_property;
|
|
18
15
|
constructor(owner, items) {
|
|
19
16
|
this.owner = owner;
|
|
20
|
-
/*
|
|
17
|
+
/* v8 ignore next 5 */
|
|
21
18
|
if (items) {
|
|
22
19
|
let i = 0;
|
|
23
20
|
this.items = new Set(items);
|
|
@@ -36,7 +33,7 @@ class ArrayCollection {
|
|
|
36
33
|
}
|
|
37
34
|
const meta = this.property.targetMeta;
|
|
38
35
|
const args = meta.toJsonParams.map(() => undefined);
|
|
39
|
-
return this.map(item =>
|
|
36
|
+
return this.map(item => wrap(item).toJSON(...args));
|
|
40
37
|
}
|
|
41
38
|
toJSON() {
|
|
42
39
|
return this.toArray();
|
|
@@ -48,16 +45,16 @@ class ArrayCollection {
|
|
|
48
45
|
}
|
|
49
46
|
field ??= this.property.targetMeta.serializedPrimaryKey;
|
|
50
47
|
return items.map(i => {
|
|
51
|
-
if (
|
|
52
|
-
return
|
|
48
|
+
if (Utils.isEntity(i[field], true)) {
|
|
49
|
+
return wrap(i[field], true).getPrimaryKey();
|
|
53
50
|
}
|
|
54
51
|
return i[field];
|
|
55
52
|
});
|
|
56
53
|
}
|
|
57
54
|
add(entity, ...entities) {
|
|
58
|
-
entities =
|
|
55
|
+
entities = Utils.asArray(entity).concat(entities);
|
|
59
56
|
for (const item of entities) {
|
|
60
|
-
const entity =
|
|
57
|
+
const entity = Reference.unwrapReference(item);
|
|
61
58
|
if (!this.contains(entity, false)) {
|
|
62
59
|
this.incrementCount(1);
|
|
63
60
|
this[this.items.size] = entity;
|
|
@@ -82,7 +79,7 @@ class ArrayCollection {
|
|
|
82
79
|
this.initialized = true;
|
|
83
80
|
this.snapshot = undefined;
|
|
84
81
|
}
|
|
85
|
-
if (this.compare(
|
|
82
|
+
if (this.compare(Utils.asArray(items).map(item => Reference.unwrapReference(item)))) {
|
|
86
83
|
return;
|
|
87
84
|
}
|
|
88
85
|
this.remove(this.items);
|
|
@@ -120,13 +117,13 @@ class ArrayCollection {
|
|
|
120
117
|
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
121
118
|
*/
|
|
122
119
|
remove(entity, ...entities) {
|
|
123
|
-
entities =
|
|
120
|
+
entities = Utils.asArray(entity).concat(entities);
|
|
124
121
|
let modified = false;
|
|
125
122
|
for (const item of entities) {
|
|
126
123
|
if (!item) {
|
|
127
124
|
continue;
|
|
128
125
|
}
|
|
129
|
-
const entity =
|
|
126
|
+
const entity = Reference.unwrapReference(item);
|
|
130
127
|
if (this.items.delete(entity)) {
|
|
131
128
|
this.incrementCount(-1);
|
|
132
129
|
delete this[this.items.size]; // remove last item
|
|
@@ -164,7 +161,7 @@ class ArrayCollection {
|
|
|
164
161
|
this.dirty = true;
|
|
165
162
|
}
|
|
166
163
|
contains(item, check) {
|
|
167
|
-
const entity =
|
|
164
|
+
const entity = Reference.unwrapReference(item);
|
|
168
165
|
return this.items.has(entity);
|
|
169
166
|
}
|
|
170
167
|
/**
|
|
@@ -261,7 +258,7 @@ class ArrayCollection {
|
|
|
261
258
|
return this.initialized;
|
|
262
259
|
}
|
|
263
260
|
for (const item of this.items) {
|
|
264
|
-
if (!
|
|
261
|
+
if (!helper(item).__initialized) {
|
|
265
262
|
return false;
|
|
266
263
|
}
|
|
267
264
|
}
|
|
@@ -307,10 +304,10 @@ class ArrayCollection {
|
|
|
307
304
|
*/
|
|
308
305
|
get property() {
|
|
309
306
|
if (!this._property) {
|
|
310
|
-
const meta =
|
|
311
|
-
/*
|
|
307
|
+
const meta = wrap(this.owner, true).__meta;
|
|
308
|
+
/* v8 ignore next 3 */
|
|
312
309
|
if (!meta) {
|
|
313
|
-
throw
|
|
310
|
+
throw MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
|
|
314
311
|
}
|
|
315
312
|
this._property = meta.relations.find(prop => this.owner[prop.name] === this);
|
|
316
313
|
}
|
|
@@ -340,27 +337,27 @@ class ArrayCollection {
|
|
|
340
337
|
propagateToOwningSide(item, method) {
|
|
341
338
|
const mappedBy = this.property.mappedBy;
|
|
342
339
|
const collection = item[mappedBy];
|
|
343
|
-
if (this.property.kind ===
|
|
340
|
+
if (this.property.kind === ReferenceKind.MANY_TO_MANY) {
|
|
344
341
|
if (this.shouldPropagateToCollection(collection, method)) {
|
|
345
342
|
collection[method](this.owner);
|
|
346
343
|
}
|
|
347
344
|
}
|
|
348
|
-
else if (this.property.kind ===
|
|
345
|
+
else if (this.property.kind === ReferenceKind.ONE_TO_MANY && method !== 'takeSnapshot') {
|
|
349
346
|
const prop2 = this.property.targetMeta.properties[mappedBy];
|
|
350
|
-
const owner = prop2.mapToPk ?
|
|
347
|
+
const owner = prop2.mapToPk ? helper(this.owner).getPrimaryKey() : this.owner;
|
|
351
348
|
const value = method === 'add' ? owner : null;
|
|
352
349
|
if (this.property.orphanRemoval && method === 'remove') {
|
|
353
350
|
// cache the PK before we propagate, as its value might be needed when flushing
|
|
354
|
-
|
|
351
|
+
helper(item).__pk = helper(item).getPrimaryKey();
|
|
355
352
|
}
|
|
356
353
|
if (!prop2.nullable && prop2.deleteRule !== 'cascade' && method === 'remove') {
|
|
357
354
|
if (!this.property.orphanRemoval) {
|
|
358
|
-
throw
|
|
355
|
+
throw ValidationError.cannotRemoveFromCollectionWithoutOrphanRemoval(this.owner, this.property);
|
|
359
356
|
}
|
|
360
357
|
return;
|
|
361
358
|
}
|
|
362
359
|
// skip if already propagated
|
|
363
|
-
if (
|
|
360
|
+
if (Reference.unwrapReference(item[mappedBy]) !== value) {
|
|
364
361
|
item[mappedBy] = value;
|
|
365
362
|
}
|
|
366
363
|
}
|
|
@@ -384,16 +381,15 @@ class ArrayCollection {
|
|
|
384
381
|
}
|
|
385
382
|
}
|
|
386
383
|
/** @ignore */
|
|
387
|
-
[
|
|
384
|
+
[inspect.custom](depth = 2) {
|
|
388
385
|
const object = { ...this };
|
|
389
386
|
const hidden = ['items', 'owner', '_property', '_count', 'snapshot', '_populated', '_snapshot', '_lazyInitialized', '_em', 'readonly'];
|
|
390
387
|
hidden.forEach(k => delete object[k]);
|
|
391
|
-
const ret =
|
|
388
|
+
const ret = inspect(object, { depth });
|
|
392
389
|
const name = `${this.constructor.name}<${this.property?.type ?? 'unknown'}>`;
|
|
393
390
|
return ret === '[Object]' ? `[${name}]` : name + ' ' + ret;
|
|
394
391
|
}
|
|
395
392
|
}
|
|
396
|
-
exports.ArrayCollection = ArrayCollection;
|
|
397
393
|
Object.defineProperties(ArrayCollection.prototype, {
|
|
398
394
|
__collection: { value: true, enumerable: false, writable: false },
|
|
399
395
|
});
|