@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/EntityManager.d.ts +96 -58
- package/EntityManager.js +465 -395
- package/MikroORM.d.ts +45 -35
- package/MikroORM.js +109 -160
- package/README.md +3 -2
- package/cache/CacheAdapter.js +1 -2
- package/cache/FileCacheAdapter.d.ts +2 -2
- package/cache/FileCacheAdapter.js +20 -27
- package/cache/GeneratedCacheAdapter.d.ts +2 -3
- package/cache/GeneratedCacheAdapter.js +1 -7
- package/cache/MemoryCacheAdapter.d.ts +1 -1
- package/cache/MemoryCacheAdapter.js +1 -5
- package/cache/NullCacheAdapter.d.ts +1 -1
- package/cache/NullCacheAdapter.js +1 -5
- package/cache/index.d.ts +4 -5
- package/cache/index.js +4 -21
- package/connections/Connection.d.ts +22 -14
- package/connections/Connection.js +27 -23
- package/connections/index.d.ts +1 -1
- package/connections/index.js +1 -17
- package/drivers/DatabaseDriver.d.ts +25 -15
- package/drivers/DatabaseDriver.js +77 -64
- package/drivers/IDatabaseDriver.d.ts +40 -16
- package/drivers/IDatabaseDriver.js +1 -4
- package/drivers/index.d.ts +2 -2
- package/drivers/index.js +2 -18
- package/entity/BaseEntity.d.ts +6 -7
- package/entity/BaseEntity.js +16 -23
- package/entity/Collection.d.ts +98 -34
- package/entity/Collection.js +466 -131
- package/entity/EntityAssigner.d.ts +3 -3
- package/entity/EntityAssigner.js +67 -64
- package/entity/EntityFactory.d.ts +10 -3
- package/entity/EntityFactory.js +112 -91
- package/entity/EntityHelper.d.ts +2 -2
- package/entity/EntityHelper.js +66 -53
- package/entity/EntityIdentifier.d.ts +1 -1
- package/entity/EntityIdentifier.js +1 -5
- package/entity/EntityLoader.d.ts +8 -7
- package/entity/EntityLoader.js +161 -128
- package/entity/EntityRepository.d.ts +8 -8
- package/entity/EntityRepository.js +7 -11
- package/entity/Reference.d.ts +10 -13
- package/entity/Reference.js +64 -46
- package/entity/WrappedEntity.d.ts +12 -17
- package/entity/WrappedEntity.js +22 -31
- package/entity/defineEntity.d.ts +568 -0
- package/entity/defineEntity.js +529 -0
- package/entity/index.d.ts +14 -13
- package/entity/index.js +14 -29
- package/entity/utils.d.ts +8 -1
- package/entity/utils.js +22 -13
- package/entity/validators.d.ts +11 -0
- package/entity/validators.js +65 -0
- package/entity/wrap.d.ts +1 -1
- package/entity/wrap.js +2 -6
- package/enums.d.ts +24 -9
- package/enums.js +50 -41
- package/errors.d.ts +11 -3
- package/errors.js +42 -32
- package/events/EventManager.d.ts +5 -4
- package/events/EventManager.js +26 -22
- package/events/EventSubscriber.d.ts +8 -5
- package/events/EventSubscriber.js +1 -2
- package/events/TransactionEventBroadcaster.d.ts +3 -3
- package/events/TransactionEventBroadcaster.js +1 -5
- package/events/index.d.ts +3 -3
- package/events/index.js +3 -19
- package/exceptions.js +18 -39
- package/hydration/Hydrator.d.ts +5 -5
- package/hydration/Hydrator.js +2 -6
- package/hydration/ObjectHydrator.d.ts +7 -7
- package/hydration/ObjectHydrator.js +58 -50
- package/hydration/index.d.ts +2 -2
- package/hydration/index.js +2 -18
- package/index.d.ts +21 -21
- package/index.js +20 -46
- package/logging/DefaultLogger.d.ts +2 -2
- package/logging/DefaultLogger.js +10 -13
- package/logging/Logger.d.ts +1 -1
- package/logging/Logger.js +1 -2
- package/logging/SimpleLogger.d.ts +3 -3
- package/logging/SimpleLogger.js +2 -6
- package/logging/colors.js +1 -5
- package/logging/index.d.ts +5 -4
- package/logging/index.js +5 -20
- package/logging/inspect.d.ts +2 -0
- package/logging/inspect.js +16 -0
- package/metadata/EntitySchema.d.ts +14 -10
- package/metadata/EntitySchema.js +78 -64
- package/metadata/MetadataDiscovery.d.ts +11 -14
- package/metadata/MetadataDiscovery.js +278 -317
- package/metadata/MetadataProvider.d.ts +13 -4
- package/metadata/MetadataProvider.js +47 -8
- package/metadata/MetadataStorage.d.ts +2 -7
- package/metadata/MetadataStorage.js +19 -35
- package/metadata/MetadataValidator.d.ts +3 -10
- package/metadata/MetadataValidator.js +51 -64
- package/metadata/discover-entities.d.ts +5 -0
- package/metadata/discover-entities.js +40 -0
- package/metadata/index.d.ts +6 -6
- package/metadata/index.js +6 -22
- package/metadata/types.d.ts +480 -0
- package/metadata/types.js +1 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
- package/naming-strategy/AbstractNamingStrategy.js +11 -9
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
- package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
- package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
- package/naming-strategy/MongoNamingStrategy.js +2 -6
- package/naming-strategy/NamingStrategy.d.ts +12 -2
- package/naming-strategy/NamingStrategy.js +1 -2
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
- package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
- package/naming-strategy/index.d.ts +5 -5
- package/naming-strategy/index.js +5 -21
- package/not-supported.d.ts +2 -0
- package/not-supported.js +4 -0
- package/package.json +19 -20
- package/platforms/ExceptionConverter.d.ts +2 -2
- package/platforms/ExceptionConverter.js +4 -8
- package/platforms/Platform.d.ts +15 -22
- package/platforms/Platform.js +58 -88
- package/platforms/index.d.ts +2 -2
- package/platforms/index.js +2 -18
- package/serialization/EntitySerializer.d.ts +4 -2
- package/serialization/EntitySerializer.js +64 -51
- package/serialization/EntityTransformer.d.ts +1 -1
- package/serialization/EntityTransformer.js +48 -42
- package/serialization/SerializationContext.d.ts +2 -2
- package/serialization/SerializationContext.js +24 -25
- package/serialization/index.d.ts +3 -3
- package/serialization/index.js +3 -19
- package/types/ArrayType.d.ts +3 -3
- package/types/ArrayType.js +6 -11
- package/types/BigIntType.d.ts +12 -9
- package/types/BigIntType.js +6 -6
- package/types/BlobType.d.ts +3 -4
- package/types/BlobType.js +2 -11
- package/types/BooleanType.d.ts +5 -4
- package/types/BooleanType.js +5 -6
- package/types/CharacterType.d.ts +3 -3
- package/types/CharacterType.js +2 -6
- package/types/DateTimeType.d.ts +3 -3
- package/types/DateTimeType.js +2 -6
- package/types/DateType.d.ts +3 -3
- package/types/DateType.js +2 -6
- package/types/DecimalType.d.ts +9 -7
- package/types/DecimalType.js +5 -8
- package/types/DoubleType.d.ts +3 -3
- package/types/DoubleType.js +4 -7
- package/types/EnumArrayType.d.ts +4 -4
- package/types/EnumArrayType.js +4 -10
- package/types/EnumType.d.ts +3 -3
- package/types/EnumType.js +2 -6
- package/types/FloatType.d.ts +3 -3
- package/types/FloatType.js +2 -6
- package/types/IntegerType.d.ts +3 -3
- package/types/IntegerType.js +2 -6
- package/types/IntervalType.d.ts +3 -3
- package/types/IntervalType.js +2 -6
- package/types/JsonType.d.ts +4 -4
- package/types/JsonType.js +9 -8
- package/types/MediumIntType.d.ts +3 -3
- package/types/MediumIntType.js +2 -6
- package/types/SmallIntType.d.ts +3 -3
- package/types/SmallIntType.js +2 -6
- package/types/StringType.d.ts +3 -3
- package/types/StringType.js +2 -6
- package/types/TextType.d.ts +3 -3
- package/types/TextType.js +2 -6
- package/types/TimeType.d.ts +3 -3
- package/types/TimeType.js +4 -8
- package/types/TinyIntType.d.ts +3 -3
- package/types/TinyIntType.js +3 -6
- package/types/Type.d.ts +4 -6
- package/types/Type.js +6 -10
- package/types/Uint8ArrayType.d.ts +3 -4
- package/types/Uint8ArrayType.js +3 -12
- package/types/UnknownType.d.ts +3 -3
- package/types/UnknownType.js +2 -6
- package/types/UuidType.d.ts +3 -3
- package/types/UuidType.js +2 -6
- package/types/index.d.ts +25 -25
- package/types/index.js +52 -79
- package/typings.d.ts +134 -93
- package/typings.js +67 -65
- package/unit-of-work/ChangeSet.d.ts +1 -4
- package/unit-of-work/ChangeSet.js +13 -17
- package/unit-of-work/ChangeSetComputer.d.ts +8 -9
- package/unit-of-work/ChangeSetComputer.js +36 -38
- package/unit-of-work/ChangeSetPersister.d.ts +11 -9
- package/unit-of-work/ChangeSetPersister.js +100 -65
- package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
- package/unit-of-work/CommitOrderCalculator.js +6 -10
- package/unit-of-work/IdentityMap.d.ts +1 -1
- package/unit-of-work/IdentityMap.js +1 -5
- package/unit-of-work/UnitOfWork.d.ts +16 -8
- package/unit-of-work/UnitOfWork.js +266 -209
- package/unit-of-work/index.d.ts +6 -6
- package/unit-of-work/index.js +6 -22
- package/utils/AbstractSchemaGenerator.d.ts +11 -11
- package/utils/AbstractSchemaGenerator.js +21 -20
- package/utils/Configuration.d.ts +774 -224
- package/utils/Configuration.js +166 -216
- package/utils/ConfigurationLoader.d.ts +1 -53
- package/utils/ConfigurationLoader.js +1 -367
- package/utils/Cursor.d.ts +6 -9
- package/utils/Cursor.js +25 -25
- package/utils/DataloaderUtils.d.ts +18 -8
- package/utils/DataloaderUtils.js +63 -21
- package/utils/EntityComparator.d.ts +9 -5
- package/utils/EntityComparator.js +155 -108
- package/utils/NullHighlighter.d.ts +1 -1
- package/utils/NullHighlighter.js +1 -5
- package/utils/QueryHelper.d.ts +12 -4
- package/utils/QueryHelper.js +110 -53
- package/utils/RawQueryFragment.d.ts +37 -14
- package/utils/RawQueryFragment.js +50 -33
- package/utils/RequestContext.d.ts +2 -2
- package/utils/RequestContext.js +3 -7
- package/utils/TransactionContext.d.ts +1 -1
- package/utils/TransactionContext.js +4 -8
- package/utils/TransactionManager.d.ts +65 -0
- package/utils/TransactionManager.js +223 -0
- package/utils/Utils.d.ts +16 -100
- package/utils/Utils.js +114 -332
- package/utils/clone.js +7 -11
- package/utils/env-vars.d.ts +3 -0
- package/utils/env-vars.js +87 -0
- package/utils/fs-utils.d.ts +12 -0
- package/utils/fs-utils.js +97 -0
- package/utils/index.d.ts +14 -13
- package/utils/index.js +14 -29
- package/utils/upsert-utils.d.ts +8 -3
- package/utils/upsert-utils.js +57 -10
- package/decorators/Check.d.ts +0 -3
- package/decorators/Check.js +0 -16
- package/decorators/CreateRequestContext.d.ts +0 -3
- package/decorators/CreateRequestContext.js +0 -33
- package/decorators/Embeddable.d.ts +0 -8
- package/decorators/Embeddable.js +0 -14
- package/decorators/Embedded.d.ts +0 -18
- package/decorators/Embedded.js +0 -20
- package/decorators/Entity.d.ts +0 -18
- package/decorators/Entity.js +0 -16
- package/decorators/Enum.d.ts +0 -9
- package/decorators/Enum.js +0 -19
- package/decorators/Filter.d.ts +0 -2
- package/decorators/Filter.js +0 -11
- package/decorators/Formula.d.ts +0 -5
- package/decorators/Formula.js +0 -18
- package/decorators/Indexed.d.ts +0 -17
- package/decorators/Indexed.js +0 -24
- package/decorators/ManyToMany.d.ts +0 -40
- package/decorators/ManyToMany.js +0 -16
- package/decorators/ManyToOne.d.ts +0 -30
- package/decorators/ManyToOne.js +0 -16
- package/decorators/OneToMany.d.ts +0 -28
- package/decorators/OneToMany.js +0 -20
- package/decorators/OneToOne.d.ts +0 -24
- package/decorators/OneToOne.js +0 -10
- package/decorators/PrimaryKey.d.ts +0 -9
- package/decorators/PrimaryKey.js +0 -23
- package/decorators/Property.d.ts +0 -250
- package/decorators/Property.js +0 -34
- package/decorators/Transactional.d.ts +0 -13
- package/decorators/Transactional.js +0 -31
- package/decorators/hooks.d.ts +0 -16
- package/decorators/hooks.js +0 -59
- package/decorators/index.d.ts +0 -17
- package/decorators/index.js +0 -36
- package/entity/ArrayCollection.d.ts +0 -116
- package/entity/ArrayCollection.js +0 -399
- package/entity/EntityValidator.d.ts +0 -19
- package/entity/EntityValidator.js +0 -154
- package/index.mjs +0 -199
- package/metadata/ReflectMetadataProvider.d.ts +0 -8
- package/metadata/ReflectMetadataProvider.js +0 -48
- package/utils/resolveContextProvider.d.ts +0 -10
- package/utils/resolveContextProvider.js +0 -31
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Transactional = Transactional;
|
|
4
|
-
const RequestContext_1 = require("../utils/RequestContext");
|
|
5
|
-
const resolveContextProvider_1 = require("../utils/resolveContextProvider");
|
|
6
|
-
const TransactionContext_1 = require("../utils/TransactionContext");
|
|
7
|
-
/**
|
|
8
|
-
* This decorator wraps the method with `em.transactional()`, so you can provide `TransactionOptions` just like with `em.transactional()`.
|
|
9
|
-
* The difference is that you can specify the context in which the transaction begins by providing `context` option,
|
|
10
|
-
* and if omitted, the transaction will begin in the current context implicitly.
|
|
11
|
-
* It works on async functions and can be nested with `em.transactional()`.
|
|
12
|
-
*/
|
|
13
|
-
function Transactional(options = {}) {
|
|
14
|
-
return function (target, propertyKey, descriptor) {
|
|
15
|
-
const originalMethod = descriptor.value;
|
|
16
|
-
if (originalMethod.constructor.name !== 'AsyncFunction') {
|
|
17
|
-
throw new Error('@Transactional() should be use with async functions');
|
|
18
|
-
}
|
|
19
|
-
descriptor.value = async function (...args) {
|
|
20
|
-
const { context, ...txOptions } = options;
|
|
21
|
-
const em = await (0, resolveContextProvider_1.resolveContextProvider)(this, context)
|
|
22
|
-
|| TransactionContext_1.TransactionContext.getEntityManager()
|
|
23
|
-
|| RequestContext_1.RequestContext.getEntityManager();
|
|
24
|
-
if (!em) {
|
|
25
|
-
throw new Error(`@Transactional() decorator can only be applied to methods of classes with \`orm: MikroORM\` property, \`em: EntityManager\` property, or with a callback parameter like \`@Transactional(() => orm)\` that returns one of those types. The parameter will contain a reference to current \`this\`. Returning an EntityRepository from it is also supported.`);
|
|
26
|
-
}
|
|
27
|
-
return em.transactional(() => originalMethod.apply(this, args), txOptions);
|
|
28
|
-
};
|
|
29
|
-
return descriptor;
|
|
30
|
-
};
|
|
31
|
-
}
|
package/decorators/hooks.d.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
export declare function BeforeCreate(): (target: any, method: string) => void;
|
|
2
|
-
export declare function AfterCreate(): (target: any, method: string) => void;
|
|
3
|
-
export declare function BeforeUpdate(): (target: any, method: string) => void;
|
|
4
|
-
export declare function AfterUpdate(): (target: any, method: string) => void;
|
|
5
|
-
export declare function BeforeUpsert(): (target: any, method: string) => void;
|
|
6
|
-
export declare function AfterUpsert(): (target: any, method: string) => void;
|
|
7
|
-
export declare function OnInit(): (target: any, method: string) => void;
|
|
8
|
-
export declare function OnLoad(): (target: any, method: string) => void;
|
|
9
|
-
/**
|
|
10
|
-
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
11
|
-
*/
|
|
12
|
-
export declare function BeforeDelete(): (target: any, method: string) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
15
|
-
*/
|
|
16
|
-
export declare function AfterDelete(): (target: any, method: string) => void;
|
package/decorators/hooks.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.BeforeCreate = BeforeCreate;
|
|
4
|
-
exports.AfterCreate = AfterCreate;
|
|
5
|
-
exports.BeforeUpdate = BeforeUpdate;
|
|
6
|
-
exports.AfterUpdate = AfterUpdate;
|
|
7
|
-
exports.BeforeUpsert = BeforeUpsert;
|
|
8
|
-
exports.AfterUpsert = AfterUpsert;
|
|
9
|
-
exports.OnInit = OnInit;
|
|
10
|
-
exports.OnLoad = OnLoad;
|
|
11
|
-
exports.BeforeDelete = BeforeDelete;
|
|
12
|
-
exports.AfterDelete = AfterDelete;
|
|
13
|
-
const metadata_1 = require("../metadata");
|
|
14
|
-
const enums_1 = require("../enums");
|
|
15
|
-
function hook(type) {
|
|
16
|
-
return function (target, method) {
|
|
17
|
-
const meta = metadata_1.MetadataStorage.getMetadataFromDecorator(target.constructor);
|
|
18
|
-
if (!meta.hooks[type]) {
|
|
19
|
-
meta.hooks[type] = [];
|
|
20
|
-
}
|
|
21
|
-
meta.hooks[type].push(method);
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
function BeforeCreate() {
|
|
25
|
-
return hook(enums_1.EventType.beforeCreate);
|
|
26
|
-
}
|
|
27
|
-
function AfterCreate() {
|
|
28
|
-
return hook(enums_1.EventType.afterCreate);
|
|
29
|
-
}
|
|
30
|
-
function BeforeUpdate() {
|
|
31
|
-
return hook(enums_1.EventType.beforeUpdate);
|
|
32
|
-
}
|
|
33
|
-
function AfterUpdate() {
|
|
34
|
-
return hook(enums_1.EventType.afterUpdate);
|
|
35
|
-
}
|
|
36
|
-
function BeforeUpsert() {
|
|
37
|
-
return hook(enums_1.EventType.beforeUpsert);
|
|
38
|
-
}
|
|
39
|
-
function AfterUpsert() {
|
|
40
|
-
return hook(enums_1.EventType.afterUpsert);
|
|
41
|
-
}
|
|
42
|
-
function OnInit() {
|
|
43
|
-
return hook(enums_1.EventType.onInit);
|
|
44
|
-
}
|
|
45
|
-
function OnLoad() {
|
|
46
|
-
return hook(enums_1.EventType.onLoad);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Called before deleting entity, but only when providing initialized entity to EM#remove()
|
|
50
|
-
*/
|
|
51
|
-
function BeforeDelete() {
|
|
52
|
-
return hook(enums_1.EventType.beforeDelete);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Called after deleting entity, but only when providing initialized entity to EM#remove()
|
|
56
|
-
*/
|
|
57
|
-
function AfterDelete() {
|
|
58
|
-
return hook(enums_1.EventType.afterDelete);
|
|
59
|
-
}
|
package/decorators/index.d.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
export * from './PrimaryKey';
|
|
2
|
-
export * from './Entity';
|
|
3
|
-
export * from './OneToOne';
|
|
4
|
-
export * from './ManyToOne';
|
|
5
|
-
export * from './ManyToMany';
|
|
6
|
-
export { OneToMany, OneToManyOptions } from './OneToMany';
|
|
7
|
-
export * from './Property';
|
|
8
|
-
export * from './Check';
|
|
9
|
-
export * from './Enum';
|
|
10
|
-
export * from './Formula';
|
|
11
|
-
export * from './Indexed';
|
|
12
|
-
export * from './Embeddable';
|
|
13
|
-
export * from './Embedded';
|
|
14
|
-
export * from './Filter';
|
|
15
|
-
export * from './CreateRequestContext';
|
|
16
|
-
export * from './hooks';
|
|
17
|
-
export * from './Transactional';
|
package/decorators/index.js
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
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
|
-
exports.OneToMany = void 0;
|
|
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,116 +0,0 @@
|
|
|
1
|
-
import { inspect } from 'node:util';
|
|
2
|
-
import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings';
|
|
3
|
-
import { Reference } from './Reference';
|
|
4
|
-
export declare class ArrayCollection<T extends object, O extends object> {
|
|
5
|
-
readonly owner: O;
|
|
6
|
-
protected readonly items: Set<T>;
|
|
7
|
-
protected initialized: boolean;
|
|
8
|
-
protected dirty: boolean;
|
|
9
|
-
protected snapshot: T[] | undefined;
|
|
10
|
-
protected _count?: number;
|
|
11
|
-
private _property?;
|
|
12
|
-
constructor(owner: O, items?: T[]);
|
|
13
|
-
loadCount(): Promise<number>;
|
|
14
|
-
getItems(): T[];
|
|
15
|
-
toArray<TT extends T>(): EntityDTO<TT>[];
|
|
16
|
-
toJSON(): EntityDTO<T>[];
|
|
17
|
-
getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string): U[];
|
|
18
|
-
add(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void;
|
|
19
|
-
/**
|
|
20
|
-
* @internal
|
|
21
|
-
*/
|
|
22
|
-
addWithoutPropagation(entity: T): void;
|
|
23
|
-
set(items: Iterable<T | Reference<T>>): void;
|
|
24
|
-
private compare;
|
|
25
|
-
/**
|
|
26
|
-
* @internal
|
|
27
|
-
*/
|
|
28
|
-
hydrate(items: T[], forcePropagate?: boolean): void;
|
|
29
|
-
/**
|
|
30
|
-
* Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
|
|
31
|
-
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
32
|
-
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
33
|
-
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
34
|
-
*/
|
|
35
|
-
remove(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void;
|
|
36
|
-
/**
|
|
37
|
-
* Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
|
|
38
|
-
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
39
|
-
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
40
|
-
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
41
|
-
*/
|
|
42
|
-
removeAll(): void;
|
|
43
|
-
/**
|
|
44
|
-
* @internal
|
|
45
|
-
*/
|
|
46
|
-
removeWithoutPropagation(entity: T): void;
|
|
47
|
-
contains(item: T | Reference<T>, check?: boolean): boolean;
|
|
48
|
-
/**
|
|
49
|
-
* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
|
|
50
|
-
* If end is null it returns all elements from start to the end of the collection.
|
|
51
|
-
*/
|
|
52
|
-
slice(start?: number, end?: number): T[];
|
|
53
|
-
/**
|
|
54
|
-
* Tests for the existence of an element that satisfies the given predicate.
|
|
55
|
-
*/
|
|
56
|
-
exists(cb: (item: T) => boolean): boolean;
|
|
57
|
-
/**
|
|
58
|
-
* Returns the first element of this collection that satisfies the predicate.
|
|
59
|
-
*/
|
|
60
|
-
find(cb: (item: T, index: number) => boolean): T | undefined;
|
|
61
|
-
/**
|
|
62
|
-
* Extracts a subset of the collection items.
|
|
63
|
-
*/
|
|
64
|
-
filter(cb: (item: T, index: number) => boolean): T[];
|
|
65
|
-
/**
|
|
66
|
-
* Maps the collection items based on your provided mapper function.
|
|
67
|
-
*/
|
|
68
|
-
map<R>(mapper: (item: T, index: number) => R): R[];
|
|
69
|
-
/**
|
|
70
|
-
* Maps the collection items based on your provided mapper function to a single object.
|
|
71
|
-
*/
|
|
72
|
-
reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
|
|
73
|
-
/**
|
|
74
|
-
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
75
|
-
* If there are more items with the same key, only the first one will be present.
|
|
76
|
-
*/
|
|
77
|
-
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
|
|
78
|
-
/**
|
|
79
|
-
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
80
|
-
* If there are more items with the same key, only the first one will be present.
|
|
81
|
-
*/
|
|
82
|
-
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
|
|
83
|
-
count(): number;
|
|
84
|
-
isInitialized(fully?: boolean): boolean;
|
|
85
|
-
isDirty(): boolean;
|
|
86
|
-
isEmpty(): boolean;
|
|
87
|
-
setDirty(dirty?: boolean): void;
|
|
88
|
-
get length(): number;
|
|
89
|
-
[Symbol.iterator](): IterableIterator<T>;
|
|
90
|
-
/**
|
|
91
|
-
* @internal
|
|
92
|
-
*/
|
|
93
|
-
takeSnapshot(forcePropagate?: boolean): void;
|
|
94
|
-
/**
|
|
95
|
-
* @internal
|
|
96
|
-
*/
|
|
97
|
-
getSnapshot(): T[] | undefined;
|
|
98
|
-
/**
|
|
99
|
-
* @internal
|
|
100
|
-
*/
|
|
101
|
-
get property(): EntityProperty;
|
|
102
|
-
/**
|
|
103
|
-
* @internal
|
|
104
|
-
*/
|
|
105
|
-
set property(prop: EntityProperty);
|
|
106
|
-
protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
107
|
-
protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
108
|
-
protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
109
|
-
protected shouldPropagateToCollection(collection: ArrayCollection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
|
|
110
|
-
protected incrementCount(value: number): void;
|
|
111
|
-
/** @ignore */
|
|
112
|
-
[inspect.custom](depth?: number): string;
|
|
113
|
-
}
|
|
114
|
-
export interface ArrayCollection<T, O> {
|
|
115
|
-
[k: number]: T;
|
|
116
|
-
}
|
|
@@ -1,399 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.ArrayCollection = void 0;
|
|
4
|
-
const node_util_1 = require("node:util");
|
|
5
|
-
const Reference_1 = require("./Reference");
|
|
6
|
-
const wrap_1 = require("./wrap");
|
|
7
|
-
const errors_1 = require("../errors");
|
|
8
|
-
const enums_1 = require("../enums");
|
|
9
|
-
const Utils_1 = require("../utils/Utils");
|
|
10
|
-
class ArrayCollection {
|
|
11
|
-
owner;
|
|
12
|
-
items = new Set();
|
|
13
|
-
initialized = true;
|
|
14
|
-
dirty = false;
|
|
15
|
-
snapshot = []; // used to create a diff of the collection at commit time, undefined marks overridden values so we need to wipe when flushing
|
|
16
|
-
_count;
|
|
17
|
-
_property;
|
|
18
|
-
constructor(owner, items) {
|
|
19
|
-
this.owner = owner;
|
|
20
|
-
/* istanbul ignore next */
|
|
21
|
-
if (items) {
|
|
22
|
-
let i = 0;
|
|
23
|
-
this.items = new Set(items);
|
|
24
|
-
this.items.forEach(item => this[i++] = item);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
async loadCount() {
|
|
28
|
-
return this.items.size;
|
|
29
|
-
}
|
|
30
|
-
getItems() {
|
|
31
|
-
return [...this.items];
|
|
32
|
-
}
|
|
33
|
-
toArray() {
|
|
34
|
-
if (this.items.size === 0) {
|
|
35
|
-
return [];
|
|
36
|
-
}
|
|
37
|
-
const meta = this.property.targetMeta;
|
|
38
|
-
const args = meta.toJsonParams.map(() => undefined);
|
|
39
|
-
return this.map(item => (0, wrap_1.wrap)(item).toJSON(...args));
|
|
40
|
-
}
|
|
41
|
-
toJSON() {
|
|
42
|
-
return this.toArray();
|
|
43
|
-
}
|
|
44
|
-
getIdentifiers(field) {
|
|
45
|
-
const items = this.getItems();
|
|
46
|
-
if (items.length === 0) {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
field ??= this.property.targetMeta.serializedPrimaryKey;
|
|
50
|
-
return items.map(i => {
|
|
51
|
-
if (Utils_1.Utils.isEntity(i[field], true)) {
|
|
52
|
-
return (0, wrap_1.wrap)(i[field], true).getPrimaryKey();
|
|
53
|
-
}
|
|
54
|
-
return i[field];
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
add(entity, ...entities) {
|
|
58
|
-
entities = Utils_1.Utils.asArray(entity).concat(entities);
|
|
59
|
-
for (const item of entities) {
|
|
60
|
-
const entity = Reference_1.Reference.unwrapReference(item);
|
|
61
|
-
if (!this.contains(entity, false)) {
|
|
62
|
-
this.incrementCount(1);
|
|
63
|
-
this[this.items.size] = entity;
|
|
64
|
-
this.items.add(entity);
|
|
65
|
-
this.propagate(entity, 'add');
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* @internal
|
|
71
|
-
*/
|
|
72
|
-
addWithoutPropagation(entity) {
|
|
73
|
-
if (!this.contains(entity, false)) {
|
|
74
|
-
this.incrementCount(1);
|
|
75
|
-
this[this.items.size] = entity;
|
|
76
|
-
this.items.add(entity);
|
|
77
|
-
this.dirty = true;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
set(items) {
|
|
81
|
-
if (!this.initialized) {
|
|
82
|
-
this.initialized = true;
|
|
83
|
-
this.snapshot = undefined;
|
|
84
|
-
}
|
|
85
|
-
if (this.compare(Utils_1.Utils.asArray(items).map(item => Reference_1.Reference.unwrapReference(item)))) {
|
|
86
|
-
return;
|
|
87
|
-
}
|
|
88
|
-
this.remove(this.items);
|
|
89
|
-
this.add(items);
|
|
90
|
-
}
|
|
91
|
-
compare(items) {
|
|
92
|
-
if (items.length !== this.items.size) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
let idx = 0;
|
|
96
|
-
for (const item of this.items) {
|
|
97
|
-
if (item !== items[idx++]) {
|
|
98
|
-
return false;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
/**
|
|
104
|
-
* @internal
|
|
105
|
-
*/
|
|
106
|
-
hydrate(items, forcePropagate) {
|
|
107
|
-
for (let i = 0; i < this.items.size; i++) {
|
|
108
|
-
delete this[i];
|
|
109
|
-
}
|
|
110
|
-
this.initialized = true;
|
|
111
|
-
this.items.clear();
|
|
112
|
-
this._count = 0;
|
|
113
|
-
this.add(items);
|
|
114
|
-
this.takeSnapshot(forcePropagate);
|
|
115
|
-
}
|
|
116
|
-
/**
|
|
117
|
-
* Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
|
|
118
|
-
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
119
|
-
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
120
|
-
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
121
|
-
*/
|
|
122
|
-
remove(entity, ...entities) {
|
|
123
|
-
entities = Utils_1.Utils.asArray(entity).concat(entities);
|
|
124
|
-
let modified = false;
|
|
125
|
-
for (const item of entities) {
|
|
126
|
-
if (!item) {
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
const entity = Reference_1.Reference.unwrapReference(item);
|
|
130
|
-
if (this.items.delete(entity)) {
|
|
131
|
-
this.incrementCount(-1);
|
|
132
|
-
delete this[this.items.size]; // remove last item
|
|
133
|
-
this.propagate(entity, 'remove');
|
|
134
|
-
modified = true;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
if (modified) {
|
|
138
|
-
Object.assign(this, [...this.items]); // reassign array access
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
|
|
143
|
-
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
144
|
-
* is not the same as `em.remove()`. If we want to delete the entity by removing it from collection, we need to enable `orphanRemoval: true`,
|
|
145
|
-
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
146
|
-
*/
|
|
147
|
-
removeAll() {
|
|
148
|
-
if (!this.initialized) {
|
|
149
|
-
this.initialized = true;
|
|
150
|
-
this.snapshot = undefined;
|
|
151
|
-
}
|
|
152
|
-
this.remove(this.items);
|
|
153
|
-
}
|
|
154
|
-
/**
|
|
155
|
-
* @internal
|
|
156
|
-
*/
|
|
157
|
-
removeWithoutPropagation(entity) {
|
|
158
|
-
if (!this.items.delete(entity)) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
this.incrementCount(-1);
|
|
162
|
-
delete this[this.items.size];
|
|
163
|
-
Object.assign(this, [...this.items]);
|
|
164
|
-
this.dirty = true;
|
|
165
|
-
}
|
|
166
|
-
contains(item, check) {
|
|
167
|
-
const entity = Reference_1.Reference.unwrapReference(item);
|
|
168
|
-
return this.items.has(entity);
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
|
|
172
|
-
* If end is null it returns all elements from start to the end of the collection.
|
|
173
|
-
*/
|
|
174
|
-
slice(start = 0, end) {
|
|
175
|
-
let index = 0;
|
|
176
|
-
end ??= this.items.size;
|
|
177
|
-
const items = [];
|
|
178
|
-
for (const item of this.items) {
|
|
179
|
-
if (index === end) {
|
|
180
|
-
break;
|
|
181
|
-
}
|
|
182
|
-
if (index >= start && index < end) {
|
|
183
|
-
items.push(item);
|
|
184
|
-
}
|
|
185
|
-
index++;
|
|
186
|
-
}
|
|
187
|
-
return items;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
* Tests for the existence of an element that satisfies the given predicate.
|
|
191
|
-
*/
|
|
192
|
-
exists(cb) {
|
|
193
|
-
for (const item of this.items) {
|
|
194
|
-
if (cb(item)) {
|
|
195
|
-
return true;
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return false;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Returns the first element of this collection that satisfies the predicate.
|
|
202
|
-
*/
|
|
203
|
-
find(cb) {
|
|
204
|
-
let index = 0;
|
|
205
|
-
for (const item of this.items) {
|
|
206
|
-
if (cb(item, index++)) {
|
|
207
|
-
return item;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
return undefined;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Extracts a subset of the collection items.
|
|
214
|
-
*/
|
|
215
|
-
filter(cb) {
|
|
216
|
-
const items = [];
|
|
217
|
-
let index = 0;
|
|
218
|
-
for (const item of this.items) {
|
|
219
|
-
if (cb(item, index++)) {
|
|
220
|
-
items.push(item);
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
return items;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Maps the collection items based on your provided mapper function.
|
|
227
|
-
*/
|
|
228
|
-
map(mapper) {
|
|
229
|
-
const items = [];
|
|
230
|
-
let index = 0;
|
|
231
|
-
for (const item of this.items) {
|
|
232
|
-
items.push(mapper(item, index++));
|
|
233
|
-
}
|
|
234
|
-
return items;
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Maps the collection items based on your provided mapper function to a single object.
|
|
238
|
-
*/
|
|
239
|
-
reduce(cb, initial = {}) {
|
|
240
|
-
let index = 0;
|
|
241
|
-
for (const item of this.items) {
|
|
242
|
-
initial = cb(initial, item, index++);
|
|
243
|
-
}
|
|
244
|
-
return initial;
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
248
|
-
* If there are more items with the same key, only the first one will be present.
|
|
249
|
-
*/
|
|
250
|
-
indexBy(key, valueKey) {
|
|
251
|
-
return this.reduce((obj, item) => {
|
|
252
|
-
obj[item[key]] ??= valueKey ? item[valueKey] : item;
|
|
253
|
-
return obj;
|
|
254
|
-
}, {});
|
|
255
|
-
}
|
|
256
|
-
count() {
|
|
257
|
-
return this.items.size;
|
|
258
|
-
}
|
|
259
|
-
isInitialized(fully = false) {
|
|
260
|
-
if (!this.initialized || !fully) {
|
|
261
|
-
return this.initialized;
|
|
262
|
-
}
|
|
263
|
-
for (const item of this.items) {
|
|
264
|
-
if (!(0, wrap_1.helper)(item).__initialized) {
|
|
265
|
-
return false;
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
return true;
|
|
269
|
-
}
|
|
270
|
-
isDirty() {
|
|
271
|
-
return this.dirty;
|
|
272
|
-
}
|
|
273
|
-
isEmpty() {
|
|
274
|
-
return this.count() === 0;
|
|
275
|
-
}
|
|
276
|
-
setDirty(dirty = true) {
|
|
277
|
-
this.dirty = dirty;
|
|
278
|
-
}
|
|
279
|
-
get length() {
|
|
280
|
-
return this.count();
|
|
281
|
-
}
|
|
282
|
-
*[Symbol.iterator]() {
|
|
283
|
-
for (const item of this.getItems()) {
|
|
284
|
-
yield item;
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* @internal
|
|
289
|
-
*/
|
|
290
|
-
takeSnapshot(forcePropagate) {
|
|
291
|
-
this.snapshot = [...this.items];
|
|
292
|
-
this.setDirty(false);
|
|
293
|
-
if (this.property.owner || forcePropagate) {
|
|
294
|
-
this.items.forEach(item => {
|
|
295
|
-
this.propagate(item, 'takeSnapshot');
|
|
296
|
-
});
|
|
297
|
-
}
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* @internal
|
|
301
|
-
*/
|
|
302
|
-
getSnapshot() {
|
|
303
|
-
return this.snapshot;
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* @internal
|
|
307
|
-
*/
|
|
308
|
-
get property() {
|
|
309
|
-
if (!this._property) {
|
|
310
|
-
const meta = (0, wrap_1.wrap)(this.owner, true).__meta;
|
|
311
|
-
/* istanbul ignore if */
|
|
312
|
-
if (!meta) {
|
|
313
|
-
throw errors_1.MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
|
|
314
|
-
}
|
|
315
|
-
this._property = meta.relations.find(prop => this.owner[prop.name] === this);
|
|
316
|
-
}
|
|
317
|
-
return this._property;
|
|
318
|
-
}
|
|
319
|
-
/**
|
|
320
|
-
* @internal
|
|
321
|
-
*/
|
|
322
|
-
set property(prop) {
|
|
323
|
-
this._property = prop;
|
|
324
|
-
}
|
|
325
|
-
propagate(item, method) {
|
|
326
|
-
if (this.property.owner && this.property.inversedBy) {
|
|
327
|
-
this.propagateToInverseSide(item, method);
|
|
328
|
-
}
|
|
329
|
-
else if (!this.property.owner && this.property.mappedBy) {
|
|
330
|
-
this.propagateToOwningSide(item, method);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
propagateToInverseSide(item, method) {
|
|
334
|
-
const collection = item[this.property.inversedBy];
|
|
335
|
-
if (this.shouldPropagateToCollection(collection, method)) {
|
|
336
|
-
method = method === 'takeSnapshot' ? method : (method + 'WithoutPropagation');
|
|
337
|
-
collection[method](this.owner);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
propagateToOwningSide(item, method) {
|
|
341
|
-
const mappedBy = this.property.mappedBy;
|
|
342
|
-
const collection = item[mappedBy];
|
|
343
|
-
if (this.property.kind === enums_1.ReferenceKind.MANY_TO_MANY) {
|
|
344
|
-
if (this.shouldPropagateToCollection(collection, method)) {
|
|
345
|
-
collection[method](this.owner);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
else if (this.property.kind === enums_1.ReferenceKind.ONE_TO_MANY && method !== 'takeSnapshot') {
|
|
349
|
-
const prop2 = this.property.targetMeta.properties[mappedBy];
|
|
350
|
-
const owner = prop2.mapToPk ? (0, wrap_1.helper)(this.owner).getPrimaryKey() : this.owner;
|
|
351
|
-
const value = method === 'add' ? owner : null;
|
|
352
|
-
if (this.property.orphanRemoval && method === 'remove') {
|
|
353
|
-
// cache the PK before we propagate, as its value might be needed when flushing
|
|
354
|
-
(0, wrap_1.helper)(item).__pk = (0, wrap_1.helper)(item).getPrimaryKey();
|
|
355
|
-
}
|
|
356
|
-
if (!prop2.nullable && prop2.deleteRule !== 'cascade' && method === 'remove') {
|
|
357
|
-
if (!this.property.orphanRemoval) {
|
|
358
|
-
throw errors_1.ValidationError.cannotRemoveFromCollectionWithoutOrphanRemoval(this.owner, this.property);
|
|
359
|
-
}
|
|
360
|
-
return;
|
|
361
|
-
}
|
|
362
|
-
// skip if already propagated
|
|
363
|
-
if (Reference_1.Reference.unwrapReference(item[mappedBy]) !== value) {
|
|
364
|
-
item[mappedBy] = value;
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
shouldPropagateToCollection(collection, method) {
|
|
369
|
-
if (!collection) {
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
|
-
switch (method) {
|
|
373
|
-
case 'add':
|
|
374
|
-
return !collection.contains(this.owner, false);
|
|
375
|
-
case 'remove':
|
|
376
|
-
return collection.isInitialized() && collection.contains(this.owner, false);
|
|
377
|
-
case 'takeSnapshot':
|
|
378
|
-
return collection.isDirty();
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
incrementCount(value) {
|
|
382
|
-
if (typeof this._count === 'number' && this.initialized) {
|
|
383
|
-
this._count += value;
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
/** @ignore */
|
|
387
|
-
[node_util_1.inspect.custom](depth = 2) {
|
|
388
|
-
const object = { ...this };
|
|
389
|
-
const hidden = ['items', 'owner', '_property', '_count', 'snapshot', '_populated', '_snapshot', '_lazyInitialized', '_em', 'readonly'];
|
|
390
|
-
hidden.forEach(k => delete object[k]);
|
|
391
|
-
const ret = (0, node_util_1.inspect)(object, { depth });
|
|
392
|
-
const name = `${this.constructor.name}<${this.property?.type ?? 'unknown'}>`;
|
|
393
|
-
return ret === '[Object]' ? `[${name}]` : name + ' ' + ret;
|
|
394
|
-
}
|
|
395
|
-
}
|
|
396
|
-
exports.ArrayCollection = ArrayCollection;
|
|
397
|
-
Object.defineProperties(ArrayCollection.prototype, {
|
|
398
|
-
__collection: { value: true, enumerable: false, writable: false },
|
|
399
|
-
});
|