@mikro-orm/core 7.0.8 → 7.0.9-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 +1899 -1926
  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 +180 -213
  23. package/entity/Collection.js +724 -730
  24. package/entity/EntityAssigner.d.ts +77 -88
  25. package/entity/EntityAssigner.js +230 -231
  26. package/entity/EntityFactory.d.ts +55 -67
  27. package/entity/EntityFactory.js +414 -455
  28. package/entity/EntityHelper.d.ts +23 -35
  29. package/entity/EntityHelper.js +279 -291
  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 +761 -792
  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 +83 -127
  39. package/entity/Reference.js +277 -281
  40. package/entity/WrappedEntity.d.ts +72 -115
  41. package/entity/WrappedEntity.js +166 -168
  42. package/entity/defineEntity.d.ts +654 -1359
  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 +418 -483
  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 +130 -214
  74. package/metadata/EntitySchema.js +412 -411
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1868 -1944
  77. package/metadata/MetadataProvider.d.ts +26 -29
  78. package/metadata/MetadataProvider.js +97 -95
  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 +303 -312
  100. package/platforms/Platform.js +644 -667
  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 +741 -1254
  160. package/typings.js +233 -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 +179 -187
  165. package/unit-of-work/ChangeSetPersister.d.ts +44 -63
  166. package/unit-of-work/ChangeSetPersister.js +423 -446
  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 +1222 -1236
  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 +82 -99
  186. package/utils/EntityComparator.js +737 -829
  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 +815 -815
  201. package/utils/clone.js +114 -105
  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,228 +1,195 @@
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 isCollection<T extends object, O extends object>(item: any): item is Collection<T, O>;
35
- static create<T extends object, O extends object = object>(
36
- owner: O,
37
- prop: EntityKey<O>,
38
- items: undefined | T[],
39
- initialized: boolean,
40
- ): Collection<T, O>;
41
- /**
42
- * Ensures the collection is loaded first (without reloading it if it already is loaded).
43
- * Returns the Collection instance (itself), works the same as `Reference.load()`.
44
- */
45
- load<TT extends T, P extends string = never>(
46
- options?: InitCollectionOptions<TT, P>,
47
- ): Promise<LoadedCollection<Loaded<TT, P>>>;
48
- private setSerializationContext;
49
- /**
50
- * Initializes the collection and returns the items
51
- */
52
- loadItems<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<Loaded<TT, P>[]>;
53
- /**
54
- * Gets the count of collection items from database instead of counting loaded items.
55
- * The value is cached (unless you use the `where` option), use `refresh: true` to force reload it.
56
- */
57
- loadCount(options?: LoadCountOptions<T> | boolean): Promise<number>;
58
- /** Queries a subset of the collection items from the database with custom filtering, ordering, and pagination. */
59
- matching<TT extends T, P extends string = never>(options: MatchingOptions<T, P>): Promise<Loaded<TT, P>[]>;
60
- /**
61
- * Returns the items (the collection must be initialized)
62
- */
63
- getItems(check?: boolean): T[];
64
- /** Serializes the collection items to plain JSON objects. Returns an empty array if not initialized. */
65
- toJSON<TT extends T>(): EntityDTO<TT>[];
66
- /** Adds one or more items to the collection, propagating the change to the inverse side. Returns the number of items added. */
67
- add<TT extends T>(
68
- entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>,
69
- ...entities: (TT | Reference<TT>)[]
70
- ): number;
71
- /**
72
- * Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
73
- * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
74
- * 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`,
75
- * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
76
- */
77
- remove<TT extends T>(
78
- entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean),
79
- ...entities: (TT | Reference<TT>)[]
80
- ): number;
81
- /** Checks whether the collection contains the given item. */
82
- contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
83
- /** Returns the number of items in the collection. Throws if the collection is not initialized. */
84
- count(): number;
85
- /** Returns true if the collection has no items. Throws if the collection is not initialized. */
86
- isEmpty(): boolean;
87
- /** Returns whether this collection should be included in serialization based on its populated state. */
88
- shouldPopulate(populated?: boolean): boolean;
89
- /** Marks the collection as populated or not for serialization purposes. */
90
- populated(populated?: boolean | undefined): void;
91
- /** Initializes the collection by loading its items from the database. */
92
- init<TT extends T, P extends string = never>(
93
- options?: InitCollectionOptions<TT, P>,
94
- ): Promise<LoadedCollection<Loaded<TT, P>>>;
95
- private getEntityManager;
96
- private createCondition;
97
- private createManyToManyCondition;
98
- private createLoadCountCondition;
99
- private checkInitialized;
100
- /**
101
- * re-orders items after searching with `$in` operator
102
- */
103
- private reorderItems;
104
- private cancelOrphanRemoval;
105
- private validateModification;
106
- /** Converts all items in the collection to plain DTO objects. */
107
- toArray<TT extends T>(): EntityDTO<TT>[];
108
- /** Returns the primary key values (or a specific field) of all items in the collection. */
109
- getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
110
- /**
111
- * @internal
112
- */
113
- addWithoutPropagation(entity: T): void;
114
- /** Replaces all items in the collection with the given items. */
115
- set(items: Iterable<T | Reference<T>>): void;
116
- private compare;
117
- /**
118
- * @internal
119
- */
120
- hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
121
- /**
122
- * Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
123
- * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
124
- * 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`,
125
- * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
126
- */
127
- removeAll(): void;
128
- /**
129
- * @internal
130
- */
131
- removeWithoutPropagation(entity: T): void;
132
- /**
133
- * Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
134
- * If end is null it returns all elements from start to the end of the collection.
135
- */
136
- slice(start?: number, end?: number): T[];
137
- /**
138
- * Tests for the existence of an element that satisfies the given predicate.
139
- */
140
- exists(cb: (item: T) => boolean): boolean;
141
- /**
142
- * Returns the first element of this collection that satisfies the predicate.
143
- */
144
- find<S extends T>(cb: (item: T, index: number) => item is S): S | undefined;
145
- /**
146
- * Returns the first element of this collection that satisfies the predicate.
147
- */
148
- find(cb: (item: T, index: number) => boolean): T | undefined;
149
- /**
150
- * Extracts a subset of the collection items.
151
- */
152
- filter<S extends T>(cb: (item: T, index: number) => item is S): S[];
153
- /**
154
- * Extracts a subset of the collection items.
155
- */
156
- filter(cb: (item: T, index: number) => boolean): T[];
157
- /**
158
- * Maps the collection items based on your provided mapper function.
159
- */
160
- map<R>(mapper: (item: T, index: number) => R): R[];
161
- /**
162
- * Maps the collection items based on your provided mapper function to a single object.
163
- */
164
- reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
165
- /**
166
- * Maps the collection items to a dictionary, indexed by the key you specify.
167
- * If there are more items with the same key, only the first one will be present.
168
- */
169
- indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
170
- /**
171
- * Maps the collection items to a dictionary, indexed by the key you specify.
172
- * If there are more items with the same key, only the first one will be present.
173
- */
174
- indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
175
- /** Returns whether the collection has been initialized. Pass `fully = true` to also check that all items are initialized. */
176
- isInitialized(fully?: boolean): boolean;
177
- isDirty(): boolean;
178
- /** Returns whether the collection was partially loaded (propagation is disabled for partial collections). */
179
- isPartial(): boolean;
180
- setDirty(dirty?: boolean): void;
181
- get length(): number;
182
- [Symbol.iterator](): IterableIterator<T>;
183
- /**
184
- * @internal
185
- */
186
- takeSnapshot(forcePropagate?: boolean): void;
187
- /**
188
- * @internal
189
- */
190
- getSnapshot(): T[] | undefined;
191
- /**
192
- * @internal
193
- */
194
- get property(): EntityProperty;
195
- /**
196
- * @internal
197
- */
198
- set property(prop: EntityProperty);
199
- protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
200
- protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
201
- protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
202
- protected shouldPropagateToCollection(
203
- collection: Collection<O, T>,
204
- method: 'add' | 'remove' | 'takeSnapshot',
205
- ): boolean;
206
- 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 isCollection<T extends object, O extends object>(item: any): item is Collection<T, O>;
25
+ static create<T extends object, O extends object = object>(owner: O, prop: EntityKey<O>, items: undefined | T[], initialized: boolean): Collection<T, O>;
26
+ /**
27
+ * Ensures the collection is loaded first (without reloading it if it already is loaded).
28
+ * Returns the Collection instance (itself), works the same as `Reference.load()`.
29
+ */
30
+ load<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
31
+ private setSerializationContext;
32
+ /**
33
+ * Initializes the collection and returns the items
34
+ */
35
+ loadItems<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<Loaded<TT, P>[]>;
36
+ /**
37
+ * Gets the count of collection items from database instead of counting loaded items.
38
+ * The value is cached (unless you use the `where` option), use `refresh: true` to force reload it.
39
+ */
40
+ loadCount(options?: LoadCountOptions<T> | boolean): Promise<number>;
41
+ /** Queries a subset of the collection items from the database with custom filtering, ordering, and pagination. */
42
+ matching<TT extends T, P extends string = never>(options: MatchingOptions<T, P>): Promise<Loaded<TT, P>[]>;
43
+ /**
44
+ * Returns the items (the collection must be initialized)
45
+ */
46
+ getItems(check?: boolean): T[];
47
+ /** Serializes the collection items to plain JSON objects. Returns an empty array if not initialized. */
48
+ toJSON<TT extends T>(): EntityDTO<TT>[];
49
+ /** Adds one or more items to the collection, propagating the change to the inverse side. Returns the number of items added. */
50
+ add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): number;
51
+ /**
52
+ * Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
53
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
54
+ * 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`,
55
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
56
+ */
57
+ remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): number;
58
+ /** Checks whether the collection contains the given item. */
59
+ contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
60
+ /** Returns the number of items in the collection. Throws if the collection is not initialized. */
61
+ count(): number;
62
+ /** Returns true if the collection has no items. Throws if the collection is not initialized. */
63
+ isEmpty(): boolean;
64
+ /** Returns whether this collection should be included in serialization based on its populated state. */
65
+ shouldPopulate(populated?: boolean): boolean;
66
+ /** Marks the collection as populated or not for serialization purposes. */
67
+ populated(populated?: boolean | undefined): void;
68
+ /** Initializes the collection by loading its items from the database. */
69
+ init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
70
+ private getEntityManager;
71
+ private createCondition;
72
+ private createManyToManyCondition;
73
+ private createLoadCountCondition;
74
+ private checkInitialized;
75
+ /**
76
+ * re-orders items after searching with `$in` operator
77
+ */
78
+ private reorderItems;
79
+ private cancelOrphanRemoval;
80
+ private validateModification;
81
+ /** Converts all items in the collection to plain DTO objects. */
82
+ toArray<TT extends T>(): EntityDTO<TT>[];
83
+ /** Returns the primary key values (or a specific field) of all items in the collection. */
84
+ getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
85
+ /**
86
+ * @internal
87
+ */
88
+ addWithoutPropagation(entity: T): void;
89
+ /** Replaces all items in the collection with the given items. */
90
+ set(items: Iterable<T | Reference<T>>): void;
91
+ private compare;
92
+ /**
93
+ * @internal
94
+ */
95
+ hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
96
+ /**
97
+ * Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
98
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
99
+ * 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`,
100
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
101
+ */
102
+ removeAll(): void;
103
+ /**
104
+ * @internal
105
+ */
106
+ removeWithoutPropagation(entity: T): void;
107
+ /**
108
+ * Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
109
+ * If end is null it returns all elements from start to the end of the collection.
110
+ */
111
+ slice(start?: number, end?: number): T[];
112
+ /**
113
+ * Tests for the existence of an element that satisfies the given predicate.
114
+ */
115
+ exists(cb: (item: T) => boolean): boolean;
116
+ /**
117
+ * Returns the first element of this collection that satisfies the predicate.
118
+ */
119
+ find<S extends T>(cb: (item: T, index: number) => item is S): S | undefined;
120
+ /**
121
+ * Returns the first element of this collection that satisfies the predicate.
122
+ */
123
+ find(cb: (item: T, index: number) => boolean): T | undefined;
124
+ /**
125
+ * Extracts a subset of the collection items.
126
+ */
127
+ filter<S extends T>(cb: (item: T, index: number) => item is S): S[];
128
+ /**
129
+ * Extracts a subset of the collection items.
130
+ */
131
+ filter(cb: (item: T, index: number) => boolean): T[];
132
+ /**
133
+ * Maps the collection items based on your provided mapper function.
134
+ */
135
+ map<R>(mapper: (item: T, index: number) => R): R[];
136
+ /**
137
+ * Maps the collection items based on your provided mapper function to a single object.
138
+ */
139
+ reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
140
+ /**
141
+ * Maps the collection items to a dictionary, indexed by the key you specify.
142
+ * If there are more items with the same key, only the first one will be present.
143
+ */
144
+ indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
145
+ /**
146
+ * Maps the collection items to a dictionary, indexed by the key you specify.
147
+ * If there are more items with the same key, only the first one will be present.
148
+ */
149
+ indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
150
+ /** Returns whether the collection has been initialized. Pass `fully = true` to also check that all items are initialized. */
151
+ isInitialized(fully?: boolean): boolean;
152
+ isDirty(): boolean;
153
+ /** Returns whether the collection was partially loaded (propagation is disabled for partial collections). */
154
+ isPartial(): boolean;
155
+ setDirty(dirty?: boolean): void;
156
+ get length(): number;
157
+ [Symbol.iterator](): IterableIterator<T>;
158
+ /**
159
+ * @internal
160
+ */
161
+ takeSnapshot(forcePropagate?: boolean): void;
162
+ /**
163
+ * @internal
164
+ */
165
+ getSnapshot(): T[] | undefined;
166
+ /**
167
+ * @internal
168
+ */
169
+ get property(): EntityProperty;
170
+ /**
171
+ * @internal
172
+ */
173
+ set property(prop: EntityProperty);
174
+ protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
175
+ protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
176
+ protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
177
+ protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
178
+ protected incrementCount(value: number): void;
207
179
  }
208
180
  /** Options for initializing a collection via `init()` or `load()`. */
209
- export interface InitCollectionOptions<
210
- T,
211
- P extends string = never,
212
- F extends string = never,
213
- E extends string = never,
214
- > extends EntityLoaderOptions<T, F, E> {
215
- /** Whether to use the dataloader for batching collection loads. */
216
- dataloader?: boolean;
217
- /** Relations to populate on the loaded items. */
218
- populate?: Populate<T, P>;
219
- /** Populate only references (without loading full entities). Works only with M:N collections that use pivot table. */
220
- ref?: boolean;
181
+ export interface InitCollectionOptions<T, P extends string = never, F extends string = never, E extends string = never> extends EntityLoaderOptions<T, F, E> {
182
+ /** Whether to use the dataloader for batching collection loads. */
183
+ dataloader?: boolean;
184
+ /** Relations to populate on the loaded items. */
185
+ populate?: Populate<T, P>;
186
+ /** Populate only references (without loading full entities). Works only with M:N collections that use pivot table. */
187
+ ref?: boolean;
221
188
  }
222
189
  /** Options for the `Collection.loadCount()` method. */
223
190
  export interface LoadCountOptions<T extends object> extends CountOptions<T, '*'> {
224
- /** Whether to reload the count from the database even if it is already cached. */
225
- refresh?: boolean;
226
- /** Additional filtering conditions for the count query. */
227
- where?: FilterQuery<T>;
191
+ /** Whether to reload the count from the database even if it is already cached. */
192
+ refresh?: boolean;
193
+ /** Additional filtering conditions for the count query. */
194
+ where?: FilterQuery<T>;
228
195
  }