@mikro-orm/core 7.0.4 → 7.0.5-dev.0

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.
Files changed (206) hide show
  1. package/EntityManager.d.ts +583 -884
  2. package/EntityManager.js +1895 -1922
  3. package/MikroORM.d.ts +74 -103
  4. package/MikroORM.js +179 -178
  5. package/README.md +1 -1
  6. package/cache/CacheAdapter.d.ts +36 -36
  7. package/cache/FileCacheAdapter.d.ts +24 -30
  8. package/cache/FileCacheAdapter.js +78 -80
  9. package/cache/GeneratedCacheAdapter.d.ts +20 -18
  10. package/cache/GeneratedCacheAdapter.js +30 -30
  11. package/cache/MemoryCacheAdapter.d.ts +20 -18
  12. package/cache/MemoryCacheAdapter.js +36 -35
  13. package/cache/NullCacheAdapter.d.ts +16 -16
  14. package/cache/NullCacheAdapter.js +24 -24
  15. package/connections/Connection.d.ts +84 -95
  16. package/connections/Connection.js +168 -165
  17. package/drivers/DatabaseDriver.d.ts +80 -186
  18. package/drivers/DatabaseDriver.js +443 -450
  19. package/drivers/IDatabaseDriver.d.ts +301 -440
  20. package/entity/BaseEntity.d.ts +83 -120
  21. package/entity/BaseEntity.js +43 -43
  22. package/entity/Collection.d.ts +179 -212
  23. package/entity/Collection.js +721 -727
  24. package/entity/EntityAssigner.d.ts +77 -88
  25. package/entity/EntityAssigner.js +230 -231
  26. package/entity/EntityFactory.d.ts +54 -66
  27. package/entity/EntityFactory.js +383 -425
  28. package/entity/EntityHelper.d.ts +22 -34
  29. package/entity/EntityHelper.js +267 -280
  30. package/entity/EntityIdentifier.d.ts +4 -4
  31. package/entity/EntityIdentifier.js +10 -10
  32. package/entity/EntityLoader.d.ts +72 -98
  33. package/entity/EntityLoader.js +723 -753
  34. package/entity/EntityRepository.d.ts +201 -316
  35. package/entity/EntityRepository.js +213 -213
  36. package/entity/PolymorphicRef.d.ts +5 -5
  37. package/entity/PolymorphicRef.js +10 -10
  38. package/entity/Reference.d.ts +82 -126
  39. package/entity/Reference.js +274 -278
  40. package/entity/WrappedEntity.d.ts +72 -115
  41. package/entity/WrappedEntity.js +166 -168
  42. package/entity/defineEntity.d.ts +636 -1315
  43. package/entity/defineEntity.js +518 -527
  44. package/entity/utils.d.ts +3 -13
  45. package/entity/utils.js +73 -71
  46. package/entity/validators.js +43 -43
  47. package/entity/wrap.js +8 -8
  48. package/enums.d.ts +253 -258
  49. package/enums.js +252 -251
  50. package/errors.d.ts +72 -114
  51. package/errors.js +253 -350
  52. package/events/EventManager.d.ts +14 -26
  53. package/events/EventManager.js +77 -79
  54. package/events/EventSubscriber.d.ts +29 -29
  55. package/events/TransactionEventBroadcaster.d.ts +8 -15
  56. package/events/TransactionEventBroadcaster.js +14 -14
  57. package/exceptions.d.ts +40 -23
  58. package/exceptions.js +52 -35
  59. package/hydration/Hydrator.d.ts +17 -42
  60. package/hydration/Hydrator.js +43 -43
  61. package/hydration/ObjectHydrator.d.ts +17 -50
  62. package/hydration/ObjectHydrator.js +416 -481
  63. package/index.d.ts +2 -116
  64. package/index.js +1 -10
  65. package/logging/DefaultLogger.d.ts +32 -34
  66. package/logging/DefaultLogger.js +86 -86
  67. package/logging/Logger.d.ts +41 -41
  68. package/logging/SimpleLogger.d.ts +11 -13
  69. package/logging/SimpleLogger.js +22 -22
  70. package/logging/colors.d.ts +6 -6
  71. package/logging/colors.js +10 -11
  72. package/logging/inspect.js +7 -7
  73. package/metadata/EntitySchema.d.ts +127 -211
  74. package/metadata/EntitySchema.js +398 -397
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1870 -1951
  77. package/metadata/MetadataProvider.d.ts +21 -24
  78. package/metadata/MetadataProvider.js +84 -82
  79. package/metadata/MetadataStorage.d.ts +32 -38
  80. package/metadata/MetadataStorage.js +118 -118
  81. package/metadata/MetadataValidator.d.ts +39 -39
  82. package/metadata/MetadataValidator.js +338 -381
  83. package/metadata/discover-entities.d.ts +2 -5
  84. package/metadata/discover-entities.js +37 -35
  85. package/metadata/types.d.ts +531 -615
  86. package/naming-strategy/AbstractNamingStrategy.d.ts +39 -54
  87. package/naming-strategy/AbstractNamingStrategy.js +85 -90
  88. package/naming-strategy/EntityCaseNamingStrategy.d.ts +6 -6
  89. package/naming-strategy/EntityCaseNamingStrategy.js +22 -22
  90. package/naming-strategy/MongoNamingStrategy.d.ts +6 -6
  91. package/naming-strategy/MongoNamingStrategy.js +18 -18
  92. package/naming-strategy/NamingStrategy.d.ts +99 -109
  93. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  94. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  95. package/not-supported.js +4 -7
  96. package/package.json +1 -1
  97. package/platforms/ExceptionConverter.d.ts +1 -1
  98. package/platforms/ExceptionConverter.js +4 -4
  99. package/platforms/Platform.d.ts +301 -310
  100. package/platforms/Platform.js +640 -663
  101. package/serialization/EntitySerializer.d.ts +26 -49
  102. package/serialization/EntitySerializer.js +218 -224
  103. package/serialization/EntityTransformer.d.ts +6 -10
  104. package/serialization/EntityTransformer.js +217 -219
  105. package/serialization/SerializationContext.d.ts +23 -27
  106. package/serialization/SerializationContext.js +105 -105
  107. package/types/ArrayType.d.ts +8 -8
  108. package/types/ArrayType.js +33 -33
  109. package/types/BigIntType.d.ts +10 -17
  110. package/types/BigIntType.js +37 -37
  111. package/types/BlobType.d.ts +3 -3
  112. package/types/BlobType.js +13 -13
  113. package/types/BooleanType.d.ts +4 -4
  114. package/types/BooleanType.js +12 -12
  115. package/types/CharacterType.d.ts +2 -2
  116. package/types/CharacterType.js +6 -6
  117. package/types/DateTimeType.d.ts +5 -5
  118. package/types/DateTimeType.js +15 -15
  119. package/types/DateType.d.ts +5 -5
  120. package/types/DateType.js +15 -15
  121. package/types/DecimalType.d.ts +7 -7
  122. package/types/DecimalType.js +26 -26
  123. package/types/DoubleType.d.ts +3 -3
  124. package/types/DoubleType.js +12 -12
  125. package/types/EnumArrayType.d.ts +5 -5
  126. package/types/EnumArrayType.js +24 -24
  127. package/types/EnumType.d.ts +3 -3
  128. package/types/EnumType.js +11 -11
  129. package/types/FloatType.d.ts +3 -3
  130. package/types/FloatType.js +9 -9
  131. package/types/IntegerType.d.ts +3 -3
  132. package/types/IntegerType.js +9 -9
  133. package/types/IntervalType.d.ts +4 -4
  134. package/types/IntervalType.js +12 -12
  135. package/types/JsonType.d.ts +8 -8
  136. package/types/JsonType.js +32 -32
  137. package/types/MediumIntType.d.ts +1 -1
  138. package/types/MediumIntType.js +3 -3
  139. package/types/SmallIntType.d.ts +3 -3
  140. package/types/SmallIntType.js +9 -9
  141. package/types/StringType.d.ts +4 -4
  142. package/types/StringType.js +12 -12
  143. package/types/TextType.d.ts +3 -3
  144. package/types/TextType.js +9 -9
  145. package/types/TimeType.d.ts +5 -5
  146. package/types/TimeType.js +17 -17
  147. package/types/TinyIntType.d.ts +3 -3
  148. package/types/TinyIntType.js +10 -10
  149. package/types/Type.d.ts +79 -83
  150. package/types/Type.js +82 -82
  151. package/types/Uint8ArrayType.d.ts +4 -4
  152. package/types/Uint8ArrayType.js +21 -21
  153. package/types/UnknownType.d.ts +4 -4
  154. package/types/UnknownType.js +12 -12
  155. package/types/UuidType.d.ts +5 -5
  156. package/types/UuidType.js +19 -19
  157. package/types/index.d.ts +49 -75
  158. package/types/index.js +26 -52
  159. package/typings.d.ts +737 -1250
  160. package/typings.js +231 -244
  161. package/unit-of-work/ChangeSet.d.ts +26 -26
  162. package/unit-of-work/ChangeSet.js +56 -56
  163. package/unit-of-work/ChangeSetComputer.d.ts +12 -12
  164. package/unit-of-work/ChangeSetComputer.js +170 -178
  165. package/unit-of-work/ChangeSetPersister.d.ts +44 -63
  166. package/unit-of-work/ChangeSetPersister.js +421 -442
  167. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  168. package/unit-of-work/CommitOrderCalculator.js +88 -89
  169. package/unit-of-work/IdentityMap.d.ts +31 -31
  170. package/unit-of-work/IdentityMap.js +105 -105
  171. package/unit-of-work/UnitOfWork.d.ts +141 -181
  172. package/unit-of-work/UnitOfWork.js +1183 -1200
  173. package/utils/AbstractMigrator.d.ts +91 -111
  174. package/utils/AbstractMigrator.js +275 -275
  175. package/utils/AbstractSchemaGenerator.d.ts +34 -43
  176. package/utils/AbstractSchemaGenerator.js +122 -121
  177. package/utils/AsyncContext.d.ts +3 -3
  178. package/utils/AsyncContext.js +35 -34
  179. package/utils/Configuration.d.ts +808 -852
  180. package/utils/Configuration.js +344 -359
  181. package/utils/Cursor.d.ts +22 -40
  182. package/utils/Cursor.js +127 -135
  183. package/utils/DataloaderUtils.d.ts +43 -58
  184. package/utils/DataloaderUtils.js +198 -203
  185. package/utils/EntityComparator.d.ts +81 -98
  186. package/utils/EntityComparator.js +732 -828
  187. package/utils/NullHighlighter.d.ts +1 -1
  188. package/utils/NullHighlighter.js +3 -3
  189. package/utils/QueryHelper.d.ts +51 -79
  190. package/utils/QueryHelper.js +361 -372
  191. package/utils/RawQueryFragment.d.ts +34 -50
  192. package/utils/RawQueryFragment.js +105 -107
  193. package/utils/RequestContext.d.ts +32 -32
  194. package/utils/RequestContext.js +53 -52
  195. package/utils/TransactionContext.d.ts +16 -16
  196. package/utils/TransactionContext.js +27 -27
  197. package/utils/TransactionManager.d.ts +58 -58
  198. package/utils/TransactionManager.js +197 -199
  199. package/utils/Utils.d.ts +145 -204
  200. package/utils/Utils.js +812 -812
  201. package/utils/clone.js +113 -104
  202. package/utils/env-vars.js +88 -90
  203. package/utils/fs-utils.d.ts +15 -15
  204. package/utils/fs-utils.js +181 -180
  205. package/utils/upsert-utils.d.ts +5 -20
  206. package/utils/upsert-utils.js +116 -114
@@ -1,227 +1,194 @@
1
- import type {
2
- EntityDTO,
3
- EntityKey,
4
- EntityProperty,
5
- FilterQuery,
6
- IPrimaryKey,
7
- Loaded,
8
- LoadedCollection,
9
- Populate,
10
- Primary,
11
- } from '../typings.js';
1
+ import type { EntityDTO, EntityKey, EntityProperty, FilterQuery, IPrimaryKey, Loaded, LoadedCollection, Populate, Primary } from '../typings.js';
12
2
  import { Reference } from './Reference.js';
13
3
  import type { Transaction } from '../connections/Connection.js';
14
4
  import type { CountOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
15
5
  import type { EntityLoaderOptions } from './EntityLoader.js';
16
6
  /** Options for the `Collection.matching()` method to query a subset of collection items from the database. */
17
7
  export interface MatchingOptions<T extends object, P extends string = never> extends FindOptions<T, P> {
18
- /** Additional filtering conditions for the query. */
19
- where?: FilterQuery<T>;
20
- /** Whether to store the matched items in the collection (makes it read-only). */
21
- store?: boolean;
22
- /** Transaction context for the query. */
23
- ctx?: Transaction;
8
+ /** Additional filtering conditions for the query. */
9
+ where?: FilterQuery<T>;
10
+ /** Whether to store the matched items in the collection (makes it read-only). */
11
+ store?: boolean;
12
+ /** Transaction context for the query. */
13
+ ctx?: Transaction;
24
14
  }
25
15
  /** Represents a to-many relation (1:m or m:n) as an iterable, managed collection of entities. */
26
16
  export declare class Collection<T extends object, O extends object = object> {
27
- #private;
28
- readonly owner: O;
29
- [k: number]: T;
30
- constructor(owner: O, items?: T[], initialized?: boolean);
31
- /**
32
- * Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
33
- */
34
- static create<T extends object, O extends object = object>(
35
- owner: O,
36
- prop: EntityKey<O>,
37
- items: undefined | T[],
38
- initialized: boolean,
39
- ): Collection<T, O>;
40
- /**
41
- * Ensures the collection is loaded first (without reloading it if it already is loaded).
42
- * Returns the Collection instance (itself), works the same as `Reference.load()`.
43
- */
44
- load<TT extends T, P extends string = never>(
45
- options?: InitCollectionOptions<TT, P>,
46
- ): Promise<LoadedCollection<Loaded<TT, P>>>;
47
- private setSerializationContext;
48
- /**
49
- * Initializes the collection and returns the items
50
- */
51
- loadItems<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<Loaded<TT, P>[]>;
52
- /**
53
- * Gets the count of collection items from database instead of counting loaded items.
54
- * The value is cached (unless you use the `where` option), use `refresh: true` to force reload it.
55
- */
56
- loadCount(options?: LoadCountOptions<T> | boolean): Promise<number>;
57
- /** Queries a subset of the collection items from the database with custom filtering, ordering, and pagination. */
58
- matching<TT extends T, P extends string = never>(options: MatchingOptions<T, P>): Promise<Loaded<TT, P>[]>;
59
- /**
60
- * Returns the items (the collection must be initialized)
61
- */
62
- getItems(check?: boolean): T[];
63
- /** Serializes the collection items to plain JSON objects. Returns an empty array if not initialized. */
64
- toJSON<TT extends T>(): EntityDTO<TT>[];
65
- /** Adds one or more items to the collection, propagating the change to the inverse side. Returns the number of items added. */
66
- add<TT extends T>(
67
- entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>,
68
- ...entities: (TT | Reference<TT>)[]
69
- ): number;
70
- /**
71
- * Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
72
- * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
73
- * 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`,
74
- * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
75
- */
76
- remove<TT extends T>(
77
- entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean),
78
- ...entities: (TT | Reference<TT>)[]
79
- ): number;
80
- /** Checks whether the collection contains the given item. */
81
- contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
82
- /** Returns the number of items in the collection. Throws if the collection is not initialized. */
83
- count(): number;
84
- /** Returns true if the collection has no items. Throws if the collection is not initialized. */
85
- isEmpty(): boolean;
86
- /** Returns whether this collection should be included in serialization based on its populated state. */
87
- shouldPopulate(populated?: boolean): boolean;
88
- /** Marks the collection as populated or not for serialization purposes. */
89
- populated(populated?: boolean | undefined): void;
90
- /** Initializes the collection by loading its items from the database. */
91
- init<TT extends T, P extends string = never>(
92
- options?: InitCollectionOptions<TT, P>,
93
- ): Promise<LoadedCollection<Loaded<TT, P>>>;
94
- private getEntityManager;
95
- private createCondition;
96
- private createManyToManyCondition;
97
- private createLoadCountCondition;
98
- private checkInitialized;
99
- /**
100
- * re-orders items after searching with `$in` operator
101
- */
102
- private reorderItems;
103
- private cancelOrphanRemoval;
104
- private validateModification;
105
- /** Converts all items in the collection to plain DTO objects. */
106
- toArray<TT extends T>(): EntityDTO<TT>[];
107
- /** Returns the primary key values (or a specific field) of all items in the collection. */
108
- getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
109
- /**
110
- * @internal
111
- */
112
- addWithoutPropagation(entity: T): void;
113
- /** Replaces all items in the collection with the given items. */
114
- set(items: Iterable<T | Reference<T>>): void;
115
- private compare;
116
- /**
117
- * @internal
118
- */
119
- hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
120
- /**
121
- * Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
122
- * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
123
- * 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`,
124
- * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
125
- */
126
- removeAll(): void;
127
- /**
128
- * @internal
129
- */
130
- removeWithoutPropagation(entity: T): void;
131
- /**
132
- * Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
133
- * If end is null it returns all elements from start to the end of the collection.
134
- */
135
- slice(start?: number, end?: number): T[];
136
- /**
137
- * Tests for the existence of an element that satisfies the given predicate.
138
- */
139
- exists(cb: (item: T) => boolean): boolean;
140
- /**
141
- * Returns the first element of this collection that satisfies the predicate.
142
- */
143
- find<S extends T>(cb: (item: T, index: number) => item is S): S | undefined;
144
- /**
145
- * Returns the first element of this collection that satisfies the predicate.
146
- */
147
- find(cb: (item: T, index: number) => boolean): T | undefined;
148
- /**
149
- * Extracts a subset of the collection items.
150
- */
151
- filter<S extends T>(cb: (item: T, index: number) => item is S): S[];
152
- /**
153
- * Extracts a subset of the collection items.
154
- */
155
- filter(cb: (item: T, index: number) => boolean): T[];
156
- /**
157
- * Maps the collection items based on your provided mapper function.
158
- */
159
- map<R>(mapper: (item: T, index: number) => R): R[];
160
- /**
161
- * Maps the collection items based on your provided mapper function to a single object.
162
- */
163
- reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
164
- /**
165
- * Maps the collection items to a dictionary, indexed by the key you specify.
166
- * If there are more items with the same key, only the first one will be present.
167
- */
168
- indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
169
- /**
170
- * Maps the collection items to a dictionary, indexed by the key you specify.
171
- * If there are more items with the same key, only the first one will be present.
172
- */
173
- indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
174
- /** Returns whether the collection has been initialized. Pass `fully = true` to also check that all items are initialized. */
175
- isInitialized(fully?: boolean): boolean;
176
- isDirty(): boolean;
177
- /** Returns whether the collection was partially loaded (propagation is disabled for partial collections). */
178
- isPartial(): boolean;
179
- setDirty(dirty?: boolean): void;
180
- get length(): number;
181
- [Symbol.iterator](): IterableIterator<T>;
182
- /**
183
- * @internal
184
- */
185
- takeSnapshot(forcePropagate?: boolean): void;
186
- /**
187
- * @internal
188
- */
189
- getSnapshot(): T[] | undefined;
190
- /**
191
- * @internal
192
- */
193
- get property(): EntityProperty;
194
- /**
195
- * @internal
196
- */
197
- set property(prop: EntityProperty);
198
- protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
199
- protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
200
- protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
201
- protected shouldPropagateToCollection(
202
- collection: Collection<O, T>,
203
- method: 'add' | 'remove' | 'takeSnapshot',
204
- ): boolean;
205
- protected incrementCount(value: number): void;
17
+ #private;
18
+ readonly owner: O;
19
+ [k: number]: T;
20
+ constructor(owner: O, items?: T[], initialized?: boolean);
21
+ /**
22
+ * Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
23
+ */
24
+ static create<T extends object, O extends object = object>(owner: O, prop: EntityKey<O>, items: undefined | T[], initialized: boolean): Collection<T, O>;
25
+ /**
26
+ * Ensures the collection is loaded first (without reloading it if it already is loaded).
27
+ * Returns the Collection instance (itself), works the same as `Reference.load()`.
28
+ */
29
+ load<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
30
+ private setSerializationContext;
31
+ /**
32
+ * Initializes the collection and returns the items
33
+ */
34
+ loadItems<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<Loaded<TT, P>[]>;
35
+ /**
36
+ * Gets the count of collection items from database instead of counting loaded items.
37
+ * The value is cached (unless you use the `where` option), use `refresh: true` to force reload it.
38
+ */
39
+ loadCount(options?: LoadCountOptions<T> | boolean): Promise<number>;
40
+ /** Queries a subset of the collection items from the database with custom filtering, ordering, and pagination. */
41
+ matching<TT extends T, P extends string = never>(options: MatchingOptions<T, P>): Promise<Loaded<TT, P>[]>;
42
+ /**
43
+ * Returns the items (the collection must be initialized)
44
+ */
45
+ getItems(check?: boolean): T[];
46
+ /** Serializes the collection items to plain JSON objects. Returns an empty array if not initialized. */
47
+ toJSON<TT extends T>(): EntityDTO<TT>[];
48
+ /** Adds one or more items to the collection, propagating the change to the inverse side. Returns the number of items added. */
49
+ add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): number;
50
+ /**
51
+ * Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
52
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
53
+ * 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`,
54
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
55
+ */
56
+ remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): number;
57
+ /** Checks whether the collection contains the given item. */
58
+ contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
59
+ /** Returns the number of items in the collection. Throws if the collection is not initialized. */
60
+ count(): number;
61
+ /** Returns true if the collection has no items. Throws if the collection is not initialized. */
62
+ isEmpty(): boolean;
63
+ /** Returns whether this collection should be included in serialization based on its populated state. */
64
+ shouldPopulate(populated?: boolean): boolean;
65
+ /** Marks the collection as populated or not for serialization purposes. */
66
+ populated(populated?: boolean | undefined): void;
67
+ /** Initializes the collection by loading its items from the database. */
68
+ init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
69
+ private getEntityManager;
70
+ private createCondition;
71
+ private createManyToManyCondition;
72
+ private createLoadCountCondition;
73
+ private checkInitialized;
74
+ /**
75
+ * re-orders items after searching with `$in` operator
76
+ */
77
+ private reorderItems;
78
+ private cancelOrphanRemoval;
79
+ private validateModification;
80
+ /** Converts all items in the collection to plain DTO objects. */
81
+ toArray<TT extends T>(): EntityDTO<TT>[];
82
+ /** Returns the primary key values (or a specific field) of all items in the collection. */
83
+ getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
84
+ /**
85
+ * @internal
86
+ */
87
+ addWithoutPropagation(entity: T): void;
88
+ /** Replaces all items in the collection with the given items. */
89
+ set(items: Iterable<T | Reference<T>>): void;
90
+ private compare;
91
+ /**
92
+ * @internal
93
+ */
94
+ hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
95
+ /**
96
+ * Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
97
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
98
+ * 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`,
99
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
100
+ */
101
+ removeAll(): void;
102
+ /**
103
+ * @internal
104
+ */
105
+ removeWithoutPropagation(entity: T): void;
106
+ /**
107
+ * Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
108
+ * If end is null it returns all elements from start to the end of the collection.
109
+ */
110
+ slice(start?: number, end?: number): T[];
111
+ /**
112
+ * Tests for the existence of an element that satisfies the given predicate.
113
+ */
114
+ exists(cb: (item: T) => boolean): boolean;
115
+ /**
116
+ * Returns the first element of this collection that satisfies the predicate.
117
+ */
118
+ find<S extends T>(cb: (item: T, index: number) => item is S): S | undefined;
119
+ /**
120
+ * Returns the first element of this collection that satisfies the predicate.
121
+ */
122
+ find(cb: (item: T, index: number) => boolean): T | undefined;
123
+ /**
124
+ * Extracts a subset of the collection items.
125
+ */
126
+ filter<S extends T>(cb: (item: T, index: number) => item is S): S[];
127
+ /**
128
+ * Extracts a subset of the collection items.
129
+ */
130
+ filter(cb: (item: T, index: number) => boolean): T[];
131
+ /**
132
+ * Maps the collection items based on your provided mapper function.
133
+ */
134
+ map<R>(mapper: (item: T, index: number) => R): R[];
135
+ /**
136
+ * Maps the collection items based on your provided mapper function to a single object.
137
+ */
138
+ reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
139
+ /**
140
+ * Maps the collection items to a dictionary, indexed by the key you specify.
141
+ * If there are more items with the same key, only the first one will be present.
142
+ */
143
+ indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
144
+ /**
145
+ * Maps the collection items to a dictionary, indexed by the key you specify.
146
+ * If there are more items with the same key, only the first one will be present.
147
+ */
148
+ indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
149
+ /** Returns whether the collection has been initialized. Pass `fully = true` to also check that all items are initialized. */
150
+ isInitialized(fully?: boolean): boolean;
151
+ isDirty(): boolean;
152
+ /** Returns whether the collection was partially loaded (propagation is disabled for partial collections). */
153
+ isPartial(): boolean;
154
+ setDirty(dirty?: boolean): void;
155
+ get length(): number;
156
+ [Symbol.iterator](): IterableIterator<T>;
157
+ /**
158
+ * @internal
159
+ */
160
+ takeSnapshot(forcePropagate?: boolean): void;
161
+ /**
162
+ * @internal
163
+ */
164
+ getSnapshot(): T[] | undefined;
165
+ /**
166
+ * @internal
167
+ */
168
+ get property(): EntityProperty;
169
+ /**
170
+ * @internal
171
+ */
172
+ set property(prop: EntityProperty);
173
+ protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
174
+ protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
175
+ protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
176
+ protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
177
+ protected incrementCount(value: number): void;
206
178
  }
207
179
  /** Options for initializing a collection via `init()` or `load()`. */
208
- export interface InitCollectionOptions<
209
- T,
210
- P extends string = never,
211
- F extends string = never,
212
- E extends string = never,
213
- > extends EntityLoaderOptions<T, F, E> {
214
- /** Whether to use the dataloader for batching collection loads. */
215
- dataloader?: boolean;
216
- /** Relations to populate on the loaded items. */
217
- populate?: Populate<T, P>;
218
- /** Populate only references (without loading full entities). Works only with M:N collections that use pivot table. */
219
- ref?: boolean;
180
+ export interface InitCollectionOptions<T, P extends string = never, F extends string = never, E extends string = never> extends EntityLoaderOptions<T, F, E> {
181
+ /** Whether to use the dataloader for batching collection loads. */
182
+ dataloader?: boolean;
183
+ /** Relations to populate on the loaded items. */
184
+ populate?: Populate<T, P>;
185
+ /** Populate only references (without loading full entities). Works only with M:N collections that use pivot table. */
186
+ ref?: boolean;
220
187
  }
221
188
  /** Options for the `Collection.loadCount()` method. */
222
189
  export interface LoadCountOptions<T extends object> extends CountOptions<T, '*'> {
223
- /** Whether to reload the count from the database even if it is already cached. */
224
- refresh?: boolean;
225
- /** Additional filtering conditions for the count query. */
226
- where?: FilterQuery<T>;
190
+ /** Whether to reload the count from the database even if it is already cached. */
191
+ refresh?: boolean;
192
+ /** Additional filtering conditions for the count query. */
193
+ where?: FilterQuery<T>;
227
194
  }