@mikro-orm/core 7.0.7-dev.9 → 7.0.7

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 +884 -583
  2. package/EntityManager.js +1926 -1899
  3. package/MikroORM.d.ts +103 -74
  4. package/MikroORM.js +178 -179
  5. package/README.md +1 -1
  6. package/cache/CacheAdapter.d.ts +36 -36
  7. package/cache/FileCacheAdapter.d.ts +30 -24
  8. package/cache/FileCacheAdapter.js +80 -78
  9. package/cache/GeneratedCacheAdapter.d.ts +18 -20
  10. package/cache/GeneratedCacheAdapter.js +30 -30
  11. package/cache/MemoryCacheAdapter.d.ts +18 -20
  12. package/cache/MemoryCacheAdapter.js +35 -36
  13. package/cache/NullCacheAdapter.d.ts +16 -16
  14. package/cache/NullCacheAdapter.js +24 -24
  15. package/connections/Connection.d.ts +95 -84
  16. package/connections/Connection.js +165 -168
  17. package/drivers/DatabaseDriver.d.ts +186 -80
  18. package/drivers/DatabaseDriver.js +450 -443
  19. package/drivers/IDatabaseDriver.d.ts +440 -301
  20. package/entity/BaseEntity.d.ts +120 -83
  21. package/entity/BaseEntity.js +43 -43
  22. package/entity/Collection.d.ts +213 -180
  23. package/entity/Collection.js +730 -724
  24. package/entity/EntityAssigner.d.ts +88 -77
  25. package/entity/EntityAssigner.js +231 -230
  26. package/entity/EntityFactory.d.ts +67 -55
  27. package/entity/EntityFactory.js +455 -383
  28. package/entity/EntityHelper.d.ts +35 -23
  29. package/entity/EntityHelper.js +289 -267
  30. package/entity/EntityIdentifier.d.ts +4 -4
  31. package/entity/EntityIdentifier.js +10 -10
  32. package/entity/EntityLoader.d.ts +98 -72
  33. package/entity/EntityLoader.js +760 -723
  34. package/entity/EntityRepository.d.ts +316 -201
  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 +127 -83
  39. package/entity/Reference.js +281 -277
  40. package/entity/WrappedEntity.d.ts +115 -72
  41. package/entity/WrappedEntity.js +168 -166
  42. package/entity/defineEntity.d.ts +1347 -637
  43. package/entity/defineEntity.js +527 -518
  44. package/entity/utils.d.ts +13 -3
  45. package/entity/utils.js +71 -73
  46. package/entity/validators.js +43 -43
  47. package/entity/wrap.js +8 -8
  48. package/enums.d.ts +258 -253
  49. package/enums.js +251 -252
  50. package/errors.d.ts +114 -72
  51. package/errors.js +350 -253
  52. package/events/EventManager.d.ts +26 -14
  53. package/events/EventManager.js +79 -77
  54. package/events/EventSubscriber.d.ts +29 -29
  55. package/events/TransactionEventBroadcaster.d.ts +15 -8
  56. package/events/TransactionEventBroadcaster.js +14 -14
  57. package/exceptions.d.ts +23 -40
  58. package/exceptions.js +35 -52
  59. package/hydration/Hydrator.d.ts +42 -17
  60. package/hydration/Hydrator.js +43 -43
  61. package/hydration/ObjectHydrator.d.ts +50 -17
  62. package/hydration/ObjectHydrator.js +483 -418
  63. package/index.d.ts +116 -2
  64. package/index.js +10 -1
  65. package/logging/DefaultLogger.d.ts +34 -32
  66. package/logging/DefaultLogger.js +86 -86
  67. package/logging/Logger.d.ts +41 -41
  68. package/logging/SimpleLogger.d.ts +13 -11
  69. package/logging/SimpleLogger.js +22 -22
  70. package/logging/colors.d.ts +6 -6
  71. package/logging/colors.js +11 -10
  72. package/logging/inspect.js +7 -7
  73. package/metadata/EntitySchema.d.ts +214 -130
  74. package/metadata/EntitySchema.js +411 -412
  75. package/metadata/MetadataDiscovery.d.ts +114 -114
  76. package/metadata/MetadataDiscovery.js +1944 -1870
  77. package/metadata/MetadataProvider.d.ts +29 -26
  78. package/metadata/MetadataProvider.js +95 -97
  79. package/metadata/MetadataStorage.d.ts +38 -32
  80. package/metadata/MetadataStorage.js +118 -118
  81. package/metadata/MetadataValidator.d.ts +39 -39
  82. package/metadata/MetadataValidator.js +381 -338
  83. package/metadata/discover-entities.d.ts +5 -2
  84. package/metadata/discover-entities.js +35 -37
  85. package/metadata/types.d.ts +615 -531
  86. package/naming-strategy/AbstractNamingStrategy.d.ts +54 -39
  87. package/naming-strategy/AbstractNamingStrategy.js +90 -85
  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 +109 -99
  93. package/naming-strategy/UnderscoreNamingStrategy.d.ts +7 -7
  94. package/naming-strategy/UnderscoreNamingStrategy.js +21 -21
  95. package/not-supported.js +7 -4
  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 +312 -303
  100. package/platforms/Platform.js +667 -644
  101. package/serialization/EntitySerializer.d.ts +49 -26
  102. package/serialization/EntitySerializer.js +224 -218
  103. package/serialization/EntityTransformer.d.ts +10 -6
  104. package/serialization/EntityTransformer.js +219 -217
  105. package/serialization/SerializationContext.d.ts +27 -23
  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 +17 -10
  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 +83 -79
  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 +75 -49
  158. package/types/index.js +52 -26
  159. package/typings.d.ts +1254 -737
  160. package/typings.js +244 -233
  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 +187 -179
  165. package/unit-of-work/ChangeSetPersister.d.ts +63 -44
  166. package/unit-of-work/ChangeSetPersister.js +446 -421
  167. package/unit-of-work/CommitOrderCalculator.d.ts +40 -40
  168. package/unit-of-work/CommitOrderCalculator.js +89 -88
  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 +181 -141
  172. package/unit-of-work/UnitOfWork.js +1200 -1183
  173. package/utils/AbstractMigrator.d.ts +111 -91
  174. package/utils/AbstractMigrator.js +275 -275
  175. package/utils/AbstractSchemaGenerator.d.ts +43 -34
  176. package/utils/AbstractSchemaGenerator.js +121 -122
  177. package/utils/AsyncContext.d.ts +3 -3
  178. package/utils/AsyncContext.js +34 -35
  179. package/utils/Configuration.d.ts +852 -808
  180. package/utils/Configuration.js +359 -344
  181. package/utils/Cursor.d.ts +40 -22
  182. package/utils/Cursor.js +135 -127
  183. package/utils/DataloaderUtils.d.ts +58 -43
  184. package/utils/DataloaderUtils.js +203 -198
  185. package/utils/EntityComparator.d.ts +98 -81
  186. package/utils/EntityComparator.js +829 -735
  187. package/utils/NullHighlighter.d.ts +1 -1
  188. package/utils/NullHighlighter.js +3 -3
  189. package/utils/QueryHelper.d.ts +79 -51
  190. package/utils/QueryHelper.js +372 -361
  191. package/utils/RawQueryFragment.d.ts +50 -34
  192. package/utils/RawQueryFragment.js +107 -105
  193. package/utils/RequestContext.d.ts +32 -32
  194. package/utils/RequestContext.js +52 -53
  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 +199 -197
  199. package/utils/Utils.d.ts +204 -145
  200. package/utils/Utils.js +815 -815
  201. package/utils/clone.js +105 -114
  202. package/utils/env-vars.js +90 -88
  203. package/utils/fs-utils.d.ts +15 -15
  204. package/utils/fs-utils.js +180 -181
  205. package/utils/upsert-utils.d.ts +20 -5
  206. package/utils/upsert-utils.js +114 -116
@@ -1,195 +1,228 @@
1
- import type { EntityDTO, EntityKey, EntityProperty, FilterQuery, IPrimaryKey, Loaded, LoadedCollection, Populate, Primary } from '../typings.js';
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';
2
12
  import { Reference } from './Reference.js';
3
13
  import type { Transaction } from '../connections/Connection.js';
4
14
  import type { CountOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
5
15
  import type { EntityLoaderOptions } from './EntityLoader.js';
6
16
  /** Options for the `Collection.matching()` method to query a subset of collection items from the database. */
7
17
  export interface MatchingOptions<T extends object, P extends string = never> extends FindOptions<T, P> {
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;
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;
14
24
  }
15
25
  /** Represents a to-many relation (1:m or m:n) as an iterable, managed collection of entities. */
16
26
  export declare class Collection<T extends object, O extends object = object> {
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;
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;
179
207
  }
180
208
  /** Options for initializing a collection via `init()` or `load()`. */
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;
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;
188
221
  }
189
222
  /** Options for the `Collection.loadCount()` method. */
190
223
  export interface LoadCountOptions<T extends object> extends CountOptions<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>;
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>;
195
228
  }