@yandjin-mikro-orm/core 6.1.4-rc-sti-changes-1
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 +553 -0
- package/EntityManager.js +1736 -0
- package/LICENSE +21 -0
- package/MikroORM.d.ts +102 -0
- package/MikroORM.js +258 -0
- package/README.md +383 -0
- package/cache/CacheAdapter.d.ts +40 -0
- package/cache/CacheAdapter.js +2 -0
- package/cache/FileCacheAdapter.d.ts +31 -0
- package/cache/FileCacheAdapter.js +90 -0
- package/cache/GeneratedCacheAdapter.d.ts +25 -0
- package/cache/GeneratedCacheAdapter.js +38 -0
- package/cache/MemoryCacheAdapter.d.ts +24 -0
- package/cache/MemoryCacheAdapter.js +44 -0
- package/cache/NullCacheAdapter.d.ts +19 -0
- package/cache/NullCacheAdapter.js +30 -0
- package/cache/index.d.ts +5 -0
- package/cache/index.js +21 -0
- package/connections/Connection.d.ts +85 -0
- package/connections/Connection.js +128 -0
- package/connections/index.d.ts +1 -0
- package/connections/index.js +17 -0
- package/decorators/Check.d.ts +3 -0
- package/decorators/Check.js +17 -0
- package/decorators/CreateRequestContext.d.ts +2 -0
- package/decorators/CreateRequestContext.js +31 -0
- package/decorators/Embeddable.d.ts +8 -0
- package/decorators/Embeddable.js +15 -0
- package/decorators/Embedded.d.ts +13 -0
- package/decorators/Embedded.js +21 -0
- package/decorators/EnsureRequestContext.d.ts +2 -0
- package/decorators/EnsureRequestContext.js +26 -0
- package/decorators/Entity.d.ts +18 -0
- package/decorators/Entity.js +17 -0
- package/decorators/Enum.d.ts +9 -0
- package/decorators/Enum.js +20 -0
- package/decorators/Filter.d.ts +2 -0
- package/decorators/Filter.js +12 -0
- package/decorators/Formula.d.ts +5 -0
- package/decorators/Formula.js +19 -0
- package/decorators/Indexed.d.ts +12 -0
- package/decorators/Indexed.js +25 -0
- package/decorators/ManyToMany.d.ts +21 -0
- package/decorators/ManyToMany.js +17 -0
- package/decorators/ManyToOne.d.ts +15 -0
- package/decorators/ManyToOne.js +17 -0
- package/decorators/OneToMany.d.ts +18 -0
- package/decorators/OneToMany.js +21 -0
- package/decorators/OneToOne.d.ts +12 -0
- package/decorators/OneToOne.js +11 -0
- package/decorators/PrimaryKey.d.ts +8 -0
- package/decorators/PrimaryKey.js +24 -0
- package/decorators/Property.d.ts +218 -0
- package/decorators/Property.js +35 -0
- package/decorators/Subscriber.d.ts +1 -0
- package/decorators/Subscriber.js +2 -0
- package/decorators/hooks.d.ts +16 -0
- package/decorators/hooks.js +60 -0
- package/decorators/index.d.ts +17 -0
- package/decorators/index.js +36 -0
- package/drivers/DatabaseDriver.d.ts +72 -0
- package/drivers/DatabaseDriver.js +358 -0
- package/drivers/IDatabaseDriver.d.ts +193 -0
- package/drivers/IDatabaseDriver.js +4 -0
- package/drivers/index.d.ts +2 -0
- package/drivers/index.js +18 -0
- package/entity/ArrayCollection.d.ts +113 -0
- package/entity/ArrayCollection.js +386 -0
- package/entity/BaseEntity.d.ts +22 -0
- package/entity/BaseEntity.js +47 -0
- package/entity/Collection.d.ts +104 -0
- package/entity/Collection.js +373 -0
- package/entity/EntityAssigner.d.ts +28 -0
- package/entity/EntityAssigner.js +226 -0
- package/entity/EntityFactory.d.ts +41 -0
- package/entity/EntityFactory.js +302 -0
- package/entity/EntityHelper.d.ts +29 -0
- package/entity/EntityHelper.js +250 -0
- package/entity/EntityIdentifier.d.ts +10 -0
- package/entity/EntityIdentifier.js +19 -0
- package/entity/EntityLoader.d.ts +65 -0
- package/entity/EntityLoader.js +579 -0
- package/entity/EntityRepository.d.ts +161 -0
- package/entity/EntityRepository.js +207 -0
- package/entity/EntityValidator.d.ts +19 -0
- package/entity/EntityValidator.js +152 -0
- package/entity/Reference.d.ts +89 -0
- package/entity/Reference.js +242 -0
- package/entity/WrappedEntity.d.ts +67 -0
- package/entity/WrappedEntity.js +146 -0
- package/entity/index.d.ts +13 -0
- package/entity/index.js +29 -0
- package/entity/wrap.d.ts +15 -0
- package/entity/wrap.js +26 -0
- package/enums.d.ts +160 -0
- package/enums.js +169 -0
- package/errors.d.ts +65 -0
- package/errors.js +222 -0
- package/events/EventManager.d.ts +17 -0
- package/events/EventManager.js +77 -0
- package/events/EventSubscriber.d.ts +39 -0
- package/events/EventSubscriber.js +2 -0
- package/events/TransactionEventBroadcaster.d.ts +11 -0
- package/events/TransactionEventBroadcaster.js +17 -0
- package/events/index.d.ts +3 -0
- package/events/index.js +19 -0
- package/exceptions.d.ts +104 -0
- package/exceptions.js +130 -0
- package/hydration/Hydrator.d.ts +23 -0
- package/hydration/Hydrator.js +51 -0
- package/hydration/ObjectHydrator.d.ts +24 -0
- package/hydration/ObjectHydrator.js +332 -0
- package/hydration/index.d.ts +2 -0
- package/hydration/index.js +18 -0
- package/index.d.ts +25 -0
- package/index.js +50 -0
- package/index.mjs +192 -0
- package/logging/DefaultLogger.d.ts +32 -0
- package/logging/DefaultLogger.js +90 -0
- package/logging/Logger.d.ts +56 -0
- package/logging/Logger.js +2 -0
- package/logging/SimpleLogger.d.ts +17 -0
- package/logging/SimpleLogger.js +31 -0
- package/logging/colors.d.ts +9 -0
- package/logging/colors.js +20 -0
- package/logging/index.d.ts +4 -0
- package/logging/index.js +20 -0
- package/metadata/EntitySchema.d.ts +74 -0
- package/metadata/EntitySchema.js +293 -0
- package/metadata/MetadataDiscovery.d.ts +71 -0
- package/metadata/MetadataDiscovery.js +1244 -0
- package/metadata/MetadataProvider.d.ts +11 -0
- package/metadata/MetadataProvider.js +23 -0
- package/metadata/MetadataStorage.d.ts +22 -0
- package/metadata/MetadataStorage.js +87 -0
- package/metadata/MetadataValidator.d.ts +24 -0
- package/metadata/MetadataValidator.js +213 -0
- package/metadata/ReflectMetadataProvider.d.ts +8 -0
- package/metadata/ReflectMetadataProvider.js +48 -0
- package/metadata/index.d.ts +6 -0
- package/metadata/index.js +22 -0
- package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
- package/naming-strategy/AbstractNamingStrategy.js +48 -0
- package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
- package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
- package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
- package/naming-strategy/MongoNamingStrategy.js +25 -0
- package/naming-strategy/NamingStrategy.d.ts +52 -0
- package/naming-strategy/NamingStrategy.js +2 -0
- package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
- package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
- package/naming-strategy/index.d.ts +5 -0
- package/naming-strategy/index.js +21 -0
- package/package.json +70 -0
- package/platforms/ExceptionConverter.d.ts +5 -0
- package/platforms/ExceptionConverter.js +11 -0
- package/platforms/Platform.d.ts +201 -0
- package/platforms/Platform.js +452 -0
- package/platforms/index.d.ts +2 -0
- package/platforms/index.js +18 -0
- package/serialization/EntitySerializer.d.ts +34 -0
- package/serialization/EntitySerializer.js +206 -0
- package/serialization/EntityTransformer.d.ts +8 -0
- package/serialization/EntityTransformer.js +192 -0
- package/serialization/SerializationContext.d.ts +30 -0
- package/serialization/SerializationContext.js +111 -0
- package/serialization/index.d.ts +3 -0
- package/serialization/index.js +19 -0
- package/types/ArrayType.d.ts +13 -0
- package/types/ArrayType.js +47 -0
- package/types/BigIntType.d.ts +16 -0
- package/types/BigIntType.js +45 -0
- package/types/BlobType.d.ts +10 -0
- package/types/BlobType.js +27 -0
- package/types/BooleanType.d.ts +8 -0
- package/types/BooleanType.js +16 -0
- package/types/DateTimeType.d.ts +8 -0
- package/types/DateTimeType.js +16 -0
- package/types/DateType.d.ts +8 -0
- package/types/DateType.js +16 -0
- package/types/DecimalType.d.ts +11 -0
- package/types/DecimalType.js +22 -0
- package/types/DoubleType.d.ts +11 -0
- package/types/DoubleType.js +22 -0
- package/types/EnumArrayType.d.ts +9 -0
- package/types/EnumArrayType.js +32 -0
- package/types/EnumType.d.ts +8 -0
- package/types/EnumType.js +16 -0
- package/types/FloatType.d.ts +8 -0
- package/types/FloatType.js +16 -0
- package/types/IntegerType.d.ts +8 -0
- package/types/IntegerType.js +16 -0
- package/types/IntervalType.d.ts +8 -0
- package/types/IntervalType.js +16 -0
- package/types/JsonType.d.ts +13 -0
- package/types/JsonType.js +34 -0
- package/types/MediumIntType.d.ts +6 -0
- package/types/MediumIntType.js +10 -0
- package/types/SmallIntType.d.ts +8 -0
- package/types/SmallIntType.js +16 -0
- package/types/StringType.d.ts +8 -0
- package/types/StringType.js +16 -0
- package/types/TextType.d.ts +8 -0
- package/types/TextType.js +16 -0
- package/types/TimeType.d.ts +9 -0
- package/types/TimeType.js +23 -0
- package/types/TinyIntType.d.ts +8 -0
- package/types/TinyIntType.js +16 -0
- package/types/Type.d.ts +64 -0
- package/types/Type.js +84 -0
- package/types/Uint8ArrayType.d.ts +11 -0
- package/types/Uint8ArrayType.js +37 -0
- package/types/UnknownType.d.ts +7 -0
- package/types/UnknownType.js +13 -0
- package/types/UuidType.d.ts +7 -0
- package/types/UuidType.js +13 -0
- package/types/index.d.ts +75 -0
- package/types/index.js +77 -0
- package/typings.d.ts +767 -0
- package/typings.js +198 -0
- package/unit-of-work/ChangeSet.d.ts +34 -0
- package/unit-of-work/ChangeSet.js +62 -0
- package/unit-of-work/ChangeSetComputer.d.ts +26 -0
- package/unit-of-work/ChangeSetComputer.js +153 -0
- package/unit-of-work/ChangeSetPersister.d.ts +50 -0
- package/unit-of-work/ChangeSetPersister.js +361 -0
- package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
- package/unit-of-work/CommitOrderCalculator.js +113 -0
- package/unit-of-work/IdentityMap.d.ts +17 -0
- package/unit-of-work/IdentityMap.js +84 -0
- package/unit-of-work/UnitOfWork.d.ts +124 -0
- package/unit-of-work/UnitOfWork.js +1013 -0
- package/unit-of-work/index.d.ts +6 -0
- package/unit-of-work/index.js +22 -0
- package/utils/AbstractSchemaGenerator.d.ts +38 -0
- package/utils/AbstractSchemaGenerator.js +101 -0
- package/utils/Configuration.d.ts +390 -0
- package/utils/Configuration.js +357 -0
- package/utils/ConfigurationLoader.d.ts +29 -0
- package/utils/ConfigurationLoader.js +282 -0
- package/utils/Cursor.d.ts +77 -0
- package/utils/Cursor.js +169 -0
- package/utils/DataloaderUtils.d.ts +43 -0
- package/utils/DataloaderUtils.js +194 -0
- package/utils/EntityComparator.d.ts +73 -0
- package/utils/EntityComparator.js +568 -0
- package/utils/NullHighlighter.d.ts +4 -0
- package/utils/NullHighlighter.js +9 -0
- package/utils/QueryHelper.d.ts +28 -0
- package/utils/QueryHelper.js +228 -0
- package/utils/RawQueryFragment.d.ts +96 -0
- package/utils/RawQueryFragment.js +188 -0
- package/utils/RequestContext.d.ts +34 -0
- package/utils/RequestContext.js +54 -0
- package/utils/TransactionContext.d.ts +19 -0
- package/utils/TransactionContext.js +34 -0
- package/utils/Utils.d.ts +274 -0
- package/utils/Utils.js +1073 -0
- package/utils/clone.d.ts +6 -0
- package/utils/clone.js +127 -0
- package/utils/index.d.ts +13 -0
- package/utils/index.js +29 -0
- package/utils/upsert-utils.d.ts +6 -0
- package/utils/upsert-utils.js +33 -0
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { inspect } from 'util';
|
|
3
|
+
import type { EntityDTO, EntityProperty, IPrimaryKey, Primary } from '../typings';
|
|
4
|
+
import { Reference } from './Reference';
|
|
5
|
+
export declare class ArrayCollection<T extends object, O extends object> {
|
|
6
|
+
readonly owner: O;
|
|
7
|
+
protected readonly items: Set<T>;
|
|
8
|
+
protected initialized: boolean;
|
|
9
|
+
protected dirty: boolean;
|
|
10
|
+
protected snapshot: T[] | undefined;
|
|
11
|
+
protected _count?: number;
|
|
12
|
+
private _property?;
|
|
13
|
+
constructor(owner: O, items?: T[]);
|
|
14
|
+
loadCount(): Promise<number>;
|
|
15
|
+
getItems(): T[];
|
|
16
|
+
toArray<TT extends T>(): EntityDTO<TT>[];
|
|
17
|
+
toJSON(): EntityDTO<T>[];
|
|
18
|
+
getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string): U[];
|
|
19
|
+
add(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void;
|
|
20
|
+
set(items: Iterable<T | Reference<T>>): void;
|
|
21
|
+
private compare;
|
|
22
|
+
/**
|
|
23
|
+
* @internal
|
|
24
|
+
*/
|
|
25
|
+
hydrate(items: T[], forcePropagate?: boolean): void;
|
|
26
|
+
/**
|
|
27
|
+
* Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
|
|
28
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
29
|
+
* 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`,
|
|
30
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
31
|
+
*/
|
|
32
|
+
remove(entity: T | Reference<T> | Iterable<T | Reference<T>>, ...entities: (T | Reference<T>)[]): void;
|
|
33
|
+
/**
|
|
34
|
+
* Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
|
|
35
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
36
|
+
* 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`,
|
|
37
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
38
|
+
*/
|
|
39
|
+
removeAll(): void;
|
|
40
|
+
/**
|
|
41
|
+
* @internal
|
|
42
|
+
*/
|
|
43
|
+
removeWithoutPropagation(entity: T): void;
|
|
44
|
+
contains(item: T | Reference<T>, check?: boolean): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
|
|
47
|
+
* If end is null it returns all elements from start to the end of the collection.
|
|
48
|
+
*/
|
|
49
|
+
slice(start?: number, end?: number): T[];
|
|
50
|
+
/**
|
|
51
|
+
* Tests for the existence of an element that satisfies the given predicate.
|
|
52
|
+
*/
|
|
53
|
+
exists(cb: (item: T) => boolean): boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Returns the first element of this collection that satisfies the predicate.
|
|
56
|
+
*/
|
|
57
|
+
find(cb: (item: T, index: number) => boolean): T | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Extracts a subset of the collection items.
|
|
60
|
+
*/
|
|
61
|
+
filter(cb: (item: T, index: number) => boolean): T[];
|
|
62
|
+
/**
|
|
63
|
+
* Maps the collection items based on your provided mapper function.
|
|
64
|
+
*/
|
|
65
|
+
map<R>(mapper: (item: T, index: number) => R): R[];
|
|
66
|
+
/**
|
|
67
|
+
* Maps the collection items based on your provided mapper function to a single object.
|
|
68
|
+
*/
|
|
69
|
+
reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
|
|
70
|
+
/**
|
|
71
|
+
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
72
|
+
* If there are more items with the same key, only the first one will be present.
|
|
73
|
+
*/
|
|
74
|
+
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
|
|
75
|
+
/**
|
|
76
|
+
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
77
|
+
* If there are more items with the same key, only the first one will be present.
|
|
78
|
+
*/
|
|
79
|
+
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
|
|
80
|
+
count(): number;
|
|
81
|
+
isInitialized(fully?: boolean): boolean;
|
|
82
|
+
isDirty(): boolean;
|
|
83
|
+
isEmpty(): boolean;
|
|
84
|
+
setDirty(dirty?: boolean): void;
|
|
85
|
+
get length(): number;
|
|
86
|
+
[Symbol.iterator](): IterableIterator<T>;
|
|
87
|
+
/**
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
takeSnapshot(forcePropagate?: boolean): void;
|
|
91
|
+
/**
|
|
92
|
+
* @internal
|
|
93
|
+
*/
|
|
94
|
+
getSnapshot(): T[] | undefined;
|
|
95
|
+
/**
|
|
96
|
+
* @internal
|
|
97
|
+
*/
|
|
98
|
+
get property(): EntityProperty;
|
|
99
|
+
/**
|
|
100
|
+
* @internal
|
|
101
|
+
*/
|
|
102
|
+
set property(prop: EntityProperty);
|
|
103
|
+
protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
104
|
+
protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
105
|
+
protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
|
|
106
|
+
protected shouldPropagateToCollection(collection: ArrayCollection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
|
|
107
|
+
protected incrementCount(value: number): void;
|
|
108
|
+
/** @ignore */
|
|
109
|
+
[inspect.custom](depth: number): string;
|
|
110
|
+
}
|
|
111
|
+
export interface ArrayCollection<T, O> {
|
|
112
|
+
[k: number]: T;
|
|
113
|
+
}
|
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArrayCollection = void 0;
|
|
4
|
+
const util_1 = require("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
|
+
set(items) {
|
|
70
|
+
if (!this.initialized) {
|
|
71
|
+
this.initialized = true;
|
|
72
|
+
this.snapshot = undefined;
|
|
73
|
+
}
|
|
74
|
+
if (this.compare(Utils_1.Utils.asArray(items).map(item => Reference_1.Reference.unwrapReference(item)))) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
this.remove(this.items);
|
|
78
|
+
this.add(items);
|
|
79
|
+
}
|
|
80
|
+
compare(items) {
|
|
81
|
+
if (items.length !== this.items.size) {
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
let idx = 0;
|
|
85
|
+
for (const item of this.items) {
|
|
86
|
+
if (item !== items[idx++]) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
hydrate(items, forcePropagate) {
|
|
96
|
+
for (let i = 0; i < this.items.size; i++) {
|
|
97
|
+
delete this[i];
|
|
98
|
+
}
|
|
99
|
+
this.initialized = true;
|
|
100
|
+
this.items.clear();
|
|
101
|
+
this._count = 0;
|
|
102
|
+
this.add(items);
|
|
103
|
+
this.takeSnapshot(forcePropagate);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
|
|
107
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
108
|
+
* 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`,
|
|
109
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
110
|
+
*/
|
|
111
|
+
remove(entity, ...entities) {
|
|
112
|
+
entities = Utils_1.Utils.asArray(entity).concat(entities);
|
|
113
|
+
let modified = false;
|
|
114
|
+
for (const item of entities) {
|
|
115
|
+
if (!item) {
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
const entity = Reference_1.Reference.unwrapReference(item);
|
|
119
|
+
if (this.items.delete(entity)) {
|
|
120
|
+
this.incrementCount(-1);
|
|
121
|
+
delete this[this.items.size]; // remove last item
|
|
122
|
+
this.propagate(entity, 'remove');
|
|
123
|
+
modified = true;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (modified) {
|
|
127
|
+
Object.assign(this, [...this.items]); // reassign array access
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
|
|
132
|
+
* it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
|
|
133
|
+
* 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`,
|
|
134
|
+
* which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
|
|
135
|
+
*/
|
|
136
|
+
removeAll() {
|
|
137
|
+
if (!this.initialized) {
|
|
138
|
+
this.initialized = true;
|
|
139
|
+
this.snapshot = undefined;
|
|
140
|
+
}
|
|
141
|
+
this.remove(this.items);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* @internal
|
|
145
|
+
*/
|
|
146
|
+
removeWithoutPropagation(entity) {
|
|
147
|
+
if (!this.items.delete(entity)) {
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.incrementCount(-1);
|
|
151
|
+
delete this[this.items.size];
|
|
152
|
+
Object.assign(this, [...this.items]);
|
|
153
|
+
}
|
|
154
|
+
contains(item, check) {
|
|
155
|
+
const entity = Reference_1.Reference.unwrapReference(item);
|
|
156
|
+
return this.items.has(entity);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
|
|
160
|
+
* If end is null it returns all elements from start to the end of the collection.
|
|
161
|
+
*/
|
|
162
|
+
slice(start = 0, end) {
|
|
163
|
+
let index = 0;
|
|
164
|
+
end ??= this.items.size;
|
|
165
|
+
const items = [];
|
|
166
|
+
for (const item of this.items) {
|
|
167
|
+
if (index === end) {
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
if (index >= start && index < end) {
|
|
171
|
+
items.push(item);
|
|
172
|
+
}
|
|
173
|
+
index++;
|
|
174
|
+
}
|
|
175
|
+
return items;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Tests for the existence of an element that satisfies the given predicate.
|
|
179
|
+
*/
|
|
180
|
+
exists(cb) {
|
|
181
|
+
for (const item of this.items) {
|
|
182
|
+
if (cb(item)) {
|
|
183
|
+
return true;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return false;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Returns the first element of this collection that satisfies the predicate.
|
|
190
|
+
*/
|
|
191
|
+
find(cb) {
|
|
192
|
+
let index = 0;
|
|
193
|
+
for (const item of this.items) {
|
|
194
|
+
if (cb(item, index++)) {
|
|
195
|
+
return item;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return undefined;
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Extracts a subset of the collection items.
|
|
202
|
+
*/
|
|
203
|
+
filter(cb) {
|
|
204
|
+
const items = [];
|
|
205
|
+
let index = 0;
|
|
206
|
+
for (const item of this.items) {
|
|
207
|
+
if (cb(item, index++)) {
|
|
208
|
+
items.push(item);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
return items;
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Maps the collection items based on your provided mapper function.
|
|
215
|
+
*/
|
|
216
|
+
map(mapper) {
|
|
217
|
+
const items = [];
|
|
218
|
+
let index = 0;
|
|
219
|
+
for (const item of this.items) {
|
|
220
|
+
items.push(mapper(item, index++));
|
|
221
|
+
}
|
|
222
|
+
return items;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Maps the collection items based on your provided mapper function to a single object.
|
|
226
|
+
*/
|
|
227
|
+
reduce(cb, initial = {}) {
|
|
228
|
+
let index = 0;
|
|
229
|
+
for (const item of this.items) {
|
|
230
|
+
initial = cb(initial, item, index++);
|
|
231
|
+
}
|
|
232
|
+
return initial;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Maps the collection items to a dictionary, indexed by the key you specify.
|
|
236
|
+
* If there are more items with the same key, only the first one will be present.
|
|
237
|
+
*/
|
|
238
|
+
indexBy(key, valueKey) {
|
|
239
|
+
return this.reduce((obj, item) => {
|
|
240
|
+
obj[item[key]] ??= valueKey ? item[valueKey] : item;
|
|
241
|
+
return obj;
|
|
242
|
+
}, {});
|
|
243
|
+
}
|
|
244
|
+
count() {
|
|
245
|
+
return this.items.size;
|
|
246
|
+
}
|
|
247
|
+
isInitialized(fully = false) {
|
|
248
|
+
if (!this.initialized || !fully) {
|
|
249
|
+
return this.initialized;
|
|
250
|
+
}
|
|
251
|
+
for (const item of this.items) {
|
|
252
|
+
if (!(0, wrap_1.helper)(item).__initialized) {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
isDirty() {
|
|
259
|
+
return this.dirty;
|
|
260
|
+
}
|
|
261
|
+
isEmpty() {
|
|
262
|
+
return this.count() === 0;
|
|
263
|
+
}
|
|
264
|
+
setDirty(dirty = true) {
|
|
265
|
+
this.dirty = dirty;
|
|
266
|
+
}
|
|
267
|
+
get length() {
|
|
268
|
+
return this.count();
|
|
269
|
+
}
|
|
270
|
+
*[Symbol.iterator]() {
|
|
271
|
+
for (const item of this.getItems()) {
|
|
272
|
+
yield item;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* @internal
|
|
277
|
+
*/
|
|
278
|
+
takeSnapshot(forcePropagate) {
|
|
279
|
+
this.snapshot = [...this.items];
|
|
280
|
+
this.setDirty(false);
|
|
281
|
+
if (this.property.owner || forcePropagate) {
|
|
282
|
+
this.items.forEach(item => {
|
|
283
|
+
this.propagate(item, 'takeSnapshot');
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* @internal
|
|
289
|
+
*/
|
|
290
|
+
getSnapshot() {
|
|
291
|
+
return this.snapshot;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* @internal
|
|
295
|
+
*/
|
|
296
|
+
get property() {
|
|
297
|
+
if (!this._property) {
|
|
298
|
+
const meta = (0, wrap_1.helper)(this.owner).__meta;
|
|
299
|
+
/* istanbul ignore if */
|
|
300
|
+
if (!meta) {
|
|
301
|
+
throw errors_1.MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
|
|
302
|
+
}
|
|
303
|
+
this._property = meta.relations.find(prop => this.owner[prop.name] === this);
|
|
304
|
+
}
|
|
305
|
+
return this._property;
|
|
306
|
+
}
|
|
307
|
+
/**
|
|
308
|
+
* @internal
|
|
309
|
+
*/
|
|
310
|
+
set property(prop) {
|
|
311
|
+
this._property = prop;
|
|
312
|
+
}
|
|
313
|
+
propagate(item, method) {
|
|
314
|
+
if (this.property.owner && this.property.inversedBy) {
|
|
315
|
+
this.propagateToInverseSide(item, method);
|
|
316
|
+
}
|
|
317
|
+
else if (!this.property.owner && this.property.mappedBy) {
|
|
318
|
+
this.propagateToOwningSide(item, method);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
propagateToInverseSide(item, method) {
|
|
322
|
+
const collection = item[this.property.inversedBy];
|
|
323
|
+
if (this.shouldPropagateToCollection(collection, method)) {
|
|
324
|
+
collection[method](this.owner);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
propagateToOwningSide(item, method) {
|
|
328
|
+
const mappedBy = this.property.mappedBy;
|
|
329
|
+
const collection = item[mappedBy];
|
|
330
|
+
if (this.property.kind === enums_1.ReferenceKind.MANY_TO_MANY) {
|
|
331
|
+
if (this.shouldPropagateToCollection(collection, method)) {
|
|
332
|
+
collection[method](this.owner);
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
else if (this.property.kind === enums_1.ReferenceKind.ONE_TO_MANY && method !== 'takeSnapshot') {
|
|
336
|
+
const prop2 = this.property.targetMeta.properties[mappedBy];
|
|
337
|
+
const owner = prop2.mapToPk ? (0, wrap_1.helper)(this.owner).getPrimaryKey() : this.owner;
|
|
338
|
+
const value = method === 'add' ? owner : null;
|
|
339
|
+
if (this.property.orphanRemoval && method === 'remove') {
|
|
340
|
+
// cache the PK before we propagate, as its value might be needed when flushing
|
|
341
|
+
(0, wrap_1.helper)(item).__pk = (0, wrap_1.helper)(item).getPrimaryKey();
|
|
342
|
+
}
|
|
343
|
+
if (!prop2.nullable && prop2.deleteRule !== 'cascade' && method === 'remove') {
|
|
344
|
+
if (!this.property.orphanRemoval) {
|
|
345
|
+
throw errors_1.ValidationError.cannotRemoveFromCollectionWithoutOrphanRemoval(this.owner, this.property);
|
|
346
|
+
}
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
// skip if already propagated
|
|
350
|
+
if (Reference_1.Reference.unwrapReference(item[mappedBy]) !== value) {
|
|
351
|
+
item[mappedBy] = value;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
shouldPropagateToCollection(collection, method) {
|
|
356
|
+
if (!collection) {
|
|
357
|
+
return false;
|
|
358
|
+
}
|
|
359
|
+
switch (method) {
|
|
360
|
+
case 'add':
|
|
361
|
+
return !collection.contains(this.owner, false);
|
|
362
|
+
case 'remove':
|
|
363
|
+
return collection.isInitialized() && collection.contains(this.owner, false);
|
|
364
|
+
case 'takeSnapshot':
|
|
365
|
+
return collection.isDirty();
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
incrementCount(value) {
|
|
369
|
+
if (typeof this._count === 'number' && this.initialized) {
|
|
370
|
+
this._count += value;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
/** @ignore */
|
|
374
|
+
[util_1.inspect.custom](depth) {
|
|
375
|
+
const object = { ...this };
|
|
376
|
+
const hidden = ['items', 'owner', '_property', '_count', 'snapshot', '_populated', '_snapshot', '_lazyInitialized', '_em', 'readonly'];
|
|
377
|
+
hidden.forEach(k => delete object[k]);
|
|
378
|
+
const ret = (0, util_1.inspect)(object, { depth });
|
|
379
|
+
const name = `${this.constructor.name}<${this.property?.type ?? 'unknown'}>`;
|
|
380
|
+
return ret === '[Object]' ? `[${name}]` : name + ' ' + ret;
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
exports.ArrayCollection = ArrayCollection;
|
|
384
|
+
Object.defineProperties(ArrayCollection.prototype, {
|
|
385
|
+
__collection: { value: true, enumerable: false, writable: false },
|
|
386
|
+
});
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type Ref } from './Reference';
|
|
2
|
+
import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings';
|
|
3
|
+
import { type AssignOptions } from './EntityAssigner';
|
|
4
|
+
import type { EntityLoaderOptions } from './EntityLoader';
|
|
5
|
+
import { type SerializeOptions } from '../serialization/EntitySerializer';
|
|
6
|
+
import type { FindOneOptions } from '../drivers/IDatabaseDriver';
|
|
7
|
+
export declare abstract class BaseEntity {
|
|
8
|
+
isInitialized(): boolean;
|
|
9
|
+
isTouched(): boolean;
|
|
10
|
+
populated(populated?: boolean): void;
|
|
11
|
+
populate<Entity extends this = this, Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
|
|
12
|
+
toReference<Entity extends this = this>(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
|
|
13
|
+
toObject<Entity extends this = this>(): EntityDTO<Entity>;
|
|
14
|
+
toObject<Entity extends this = this>(ignoreFields: never[]): EntityDTO<Entity>;
|
|
15
|
+
toObject<Entity extends this = this, Ignored extends EntityKey<Entity> = never>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
|
|
16
|
+
toPOJO<Entity extends this = this>(): EntityDTO<Entity>;
|
|
17
|
+
serialize<Entity extends this = this, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Entity, Hint, Exclude>): EntityDTO<Loaded<Entity, Hint>>;
|
|
18
|
+
assign<Entity extends this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Data extends EntityData<Naked> | Partial<EntityDTO<Naked>> = EntityData<Naked> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions): MergeSelected<Entity, Naked, keyof Data & string>;
|
|
19
|
+
init<Entity extends this = this, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
|
|
20
|
+
getSchema(): string | undefined;
|
|
21
|
+
setSchema(schema?: string): void;
|
|
22
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.BaseEntity = void 0;
|
|
4
|
+
const Reference_1 = require("./Reference");
|
|
5
|
+
const EntityAssigner_1 = require("./EntityAssigner");
|
|
6
|
+
const EntitySerializer_1 = require("../serialization/EntitySerializer");
|
|
7
|
+
const wrap_1 = require("./wrap");
|
|
8
|
+
class BaseEntity {
|
|
9
|
+
isInitialized() {
|
|
10
|
+
return (0, wrap_1.helper)(this).__initialized;
|
|
11
|
+
}
|
|
12
|
+
isTouched() {
|
|
13
|
+
return (0, wrap_1.helper)(this).__touched;
|
|
14
|
+
}
|
|
15
|
+
populated(populated = true) {
|
|
16
|
+
(0, wrap_1.helper)(this).populated(populated);
|
|
17
|
+
}
|
|
18
|
+
async populate(populate, options = {}) {
|
|
19
|
+
return (0, wrap_1.helper)(this).populate(populate, options);
|
|
20
|
+
}
|
|
21
|
+
toReference() {
|
|
22
|
+
return Reference_1.Reference.create(this);
|
|
23
|
+
}
|
|
24
|
+
toObject(ignoreFields) {
|
|
25
|
+
return (0, wrap_1.helper)(this).toObject(ignoreFields);
|
|
26
|
+
}
|
|
27
|
+
toPOJO() {
|
|
28
|
+
return (0, wrap_1.helper)(this).toPOJO();
|
|
29
|
+
}
|
|
30
|
+
serialize(options) {
|
|
31
|
+
return EntitySerializer_1.EntitySerializer.serialize(this, options);
|
|
32
|
+
}
|
|
33
|
+
assign(data, options = {}) {
|
|
34
|
+
return EntityAssigner_1.EntityAssigner.assign(this, data, options);
|
|
35
|
+
}
|
|
36
|
+
init(options) {
|
|
37
|
+
return (0, wrap_1.helper)(this).init(options);
|
|
38
|
+
}
|
|
39
|
+
getSchema() {
|
|
40
|
+
return (0, wrap_1.helper)(this).getSchema();
|
|
41
|
+
}
|
|
42
|
+
setSchema(schema) {
|
|
43
|
+
(0, wrap_1.helper)(this).setSchema(schema);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.BaseEntity = BaseEntity;
|
|
47
|
+
Object.defineProperty(BaseEntity.prototype, '__baseEntity', { value: true, writable: false, enumerable: false });
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { EntityDTO, EntityKey, FilterQuery, Loaded, LoadedCollection, Populate } from '../typings';
|
|
2
|
+
import { ArrayCollection } from './ArrayCollection';
|
|
3
|
+
import { Reference } from './Reference';
|
|
4
|
+
import type { Transaction } from '../connections/Connection';
|
|
5
|
+
import type { FindOptions, CountOptions } from '../drivers/IDatabaseDriver';
|
|
6
|
+
import type { EntityLoaderOptions } from './EntityLoader';
|
|
7
|
+
export interface MatchingOptions<T extends object, P extends string = never> extends FindOptions<T, P> {
|
|
8
|
+
where?: FilterQuery<T>;
|
|
9
|
+
store?: boolean;
|
|
10
|
+
ctx?: Transaction;
|
|
11
|
+
}
|
|
12
|
+
export declare class Collection<T extends object, O extends object = object> extends ArrayCollection<T, O> {
|
|
13
|
+
private readonly?;
|
|
14
|
+
private _populated?;
|
|
15
|
+
private _em?;
|
|
16
|
+
private _snapshot?;
|
|
17
|
+
constructor(owner: O, items?: T[], initialized?: boolean);
|
|
18
|
+
/**
|
|
19
|
+
* Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
|
|
20
|
+
*/
|
|
21
|
+
static create<T extends object, O extends object = object>(owner: O, prop: EntityKey<O>, items: undefined | T[], initialized: boolean): Collection<T, O>;
|
|
22
|
+
/**
|
|
23
|
+
* Ensures the collection is loaded first (without reloading it if it already is loaded).
|
|
24
|
+
* Returns the Collection instance (itself), works the same as `Reference.load()`.
|
|
25
|
+
*/
|
|
26
|
+
load<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
|
|
27
|
+
/**
|
|
28
|
+
* Initializes the collection and returns the items
|
|
29
|
+
*/
|
|
30
|
+
loadItems<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<Loaded<TT, P>[]>;
|
|
31
|
+
/**
|
|
32
|
+
* Gets the count of collection items from database instead of counting loaded items.
|
|
33
|
+
* The value is cached (unless you use the `where` option), use `refresh: true` to force reload it.
|
|
34
|
+
*/
|
|
35
|
+
loadCount(options?: LoadCountOptions<T> | boolean): Promise<number>;
|
|
36
|
+
matching<TT extends T, P extends string = never>(options: MatchingOptions<T, P>): Promise<Loaded<TT, P>[]>;
|
|
37
|
+
/**
|
|
38
|
+
* Returns the items (the collection must be initialized)
|
|
39
|
+
*/
|
|
40
|
+
getItems(check?: boolean): T[];
|
|
41
|
+
toJSON<TT extends T>(): EntityDTO<TT>[];
|
|
42
|
+
add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): void;
|
|
43
|
+
/**
|
|
44
|
+
* @inheritDoc
|
|
45
|
+
*/
|
|
46
|
+
remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): void;
|
|
47
|
+
contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
|
|
48
|
+
count(): number;
|
|
49
|
+
isEmpty(): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* @inheritDoc
|
|
52
|
+
*/
|
|
53
|
+
slice(start?: number, end?: number): T[];
|
|
54
|
+
/**
|
|
55
|
+
* @inheritDoc
|
|
56
|
+
*/
|
|
57
|
+
exists(cb: (item: T) => boolean): boolean;
|
|
58
|
+
/**
|
|
59
|
+
* @inheritDoc
|
|
60
|
+
*/
|
|
61
|
+
find(cb: (item: T, index: number) => boolean): T | undefined;
|
|
62
|
+
/**
|
|
63
|
+
* @inheritDoc
|
|
64
|
+
*/
|
|
65
|
+
filter(cb: (item: T, index: number) => boolean): T[];
|
|
66
|
+
/**
|
|
67
|
+
* @inheritDoc
|
|
68
|
+
*/
|
|
69
|
+
map<R>(mapper: (item: T, index: number) => R): R[];
|
|
70
|
+
/**
|
|
71
|
+
* @inheritDoc
|
|
72
|
+
*/
|
|
73
|
+
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
|
|
74
|
+
/**
|
|
75
|
+
* @inheritDoc
|
|
76
|
+
*/
|
|
77
|
+
indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
|
|
78
|
+
shouldPopulate(populated?: boolean): boolean;
|
|
79
|
+
populated(populated?: boolean | undefined): void;
|
|
80
|
+
init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
|
|
81
|
+
private getEntityManager;
|
|
82
|
+
private createCondition;
|
|
83
|
+
private createOrderBy;
|
|
84
|
+
private createManyToManyCondition;
|
|
85
|
+
private createLoadCountCondition;
|
|
86
|
+
private modify;
|
|
87
|
+
private checkInitialized;
|
|
88
|
+
/**
|
|
89
|
+
* re-orders items after searching with `$in` operator
|
|
90
|
+
*/
|
|
91
|
+
private reorderItems;
|
|
92
|
+
private cancelOrphanRemoval;
|
|
93
|
+
private validateItemType;
|
|
94
|
+
private validateModification;
|
|
95
|
+
}
|
|
96
|
+
export interface InitCollectionOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends EntityLoaderOptions<T, F, E> {
|
|
97
|
+
dataloader?: boolean;
|
|
98
|
+
populate?: Populate<T, P>;
|
|
99
|
+
ref?: boolean;
|
|
100
|
+
}
|
|
101
|
+
export interface LoadCountOptions<T extends object> extends CountOptions<T, '*'> {
|
|
102
|
+
refresh?: boolean;
|
|
103
|
+
where?: FilterQuery<T>;
|
|
104
|
+
}
|