@mikro-orm/core 7.0.0-dev.33 → 7.0.0-dev.331

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 (218) hide show
  1. package/EntityManager.d.ts +70 -75
  2. package/EntityManager.js +487 -402
  3. package/MikroORM.d.ts +45 -38
  4. package/MikroORM.js +123 -156
  5. package/README.md +7 -4
  6. package/cache/FileCacheAdapter.d.ts +2 -7
  7. package/cache/FileCacheAdapter.js +35 -30
  8. package/cache/GeneratedCacheAdapter.d.ts +1 -2
  9. package/cache/GeneratedCacheAdapter.js +6 -8
  10. package/cache/MemoryCacheAdapter.d.ts +1 -2
  11. package/cache/MemoryCacheAdapter.js +8 -8
  12. package/cache/index.d.ts +1 -2
  13. package/cache/index.js +0 -2
  14. package/connections/Connection.d.ts +12 -5
  15. package/connections/Connection.js +37 -15
  16. package/drivers/DatabaseDriver.d.ts +25 -18
  17. package/drivers/DatabaseDriver.js +144 -45
  18. package/drivers/IDatabaseDriver.d.ts +118 -23
  19. package/entity/BaseEntity.d.ts +63 -4
  20. package/entity/BaseEntity.js +0 -3
  21. package/entity/Collection.d.ts +95 -31
  22. package/entity/Collection.js +487 -139
  23. package/entity/EntityAssigner.js +37 -25
  24. package/entity/EntityFactory.d.ts +8 -9
  25. package/entity/EntityFactory.js +152 -100
  26. package/entity/EntityHelper.d.ts +2 -2
  27. package/entity/EntityHelper.js +69 -27
  28. package/entity/EntityLoader.d.ts +12 -13
  29. package/entity/EntityLoader.js +286 -125
  30. package/entity/EntityRepository.d.ts +28 -8
  31. package/entity/EntityRepository.js +8 -2
  32. package/entity/PolymorphicRef.d.ts +12 -0
  33. package/entity/PolymorphicRef.js +18 -0
  34. package/entity/Reference.d.ts +3 -8
  35. package/entity/Reference.js +62 -29
  36. package/entity/WrappedEntity.d.ts +7 -10
  37. package/entity/WrappedEntity.js +6 -7
  38. package/entity/defineEntity.d.ts +472 -313
  39. package/entity/defineEntity.js +134 -290
  40. package/entity/index.d.ts +2 -2
  41. package/entity/index.js +2 -2
  42. package/entity/utils.d.ts +6 -1
  43. package/entity/utils.js +46 -11
  44. package/entity/validators.d.ts +11 -0
  45. package/entity/validators.js +66 -0
  46. package/enums.d.ts +8 -6
  47. package/enums.js +13 -17
  48. package/errors.d.ts +26 -16
  49. package/errors.js +63 -31
  50. package/events/EventManager.d.ts +3 -5
  51. package/events/EventManager.js +37 -26
  52. package/events/index.d.ts +1 -1
  53. package/events/index.js +0 -1
  54. package/exceptions.js +9 -2
  55. package/hydration/Hydrator.js +1 -2
  56. package/hydration/ObjectHydrator.d.ts +5 -6
  57. package/hydration/ObjectHydrator.js +109 -50
  58. package/index.d.ts +2 -2
  59. package/index.js +1 -2
  60. package/logging/DefaultLogger.d.ts +1 -1
  61. package/logging/DefaultLogger.js +3 -4
  62. package/logging/SimpleLogger.d.ts +1 -1
  63. package/logging/colors.d.ts +1 -1
  64. package/logging/colors.js +4 -6
  65. package/logging/index.d.ts +2 -1
  66. package/logging/index.js +1 -1
  67. package/logging/inspect.d.ts +2 -0
  68. package/logging/inspect.js +11 -0
  69. package/metadata/EntitySchema.d.ts +47 -23
  70. package/metadata/EntitySchema.js +103 -34
  71. package/metadata/MetadataDiscovery.d.ts +65 -18
  72. package/metadata/MetadataDiscovery.js +940 -424
  73. package/metadata/MetadataProvider.d.ts +11 -2
  74. package/metadata/MetadataProvider.js +71 -2
  75. package/metadata/MetadataStorage.d.ts +11 -13
  76. package/metadata/MetadataStorage.js +79 -48
  77. package/metadata/MetadataValidator.d.ts +32 -9
  78. package/metadata/MetadataValidator.js +214 -44
  79. package/metadata/discover-entities.d.ts +5 -0
  80. package/metadata/discover-entities.js +40 -0
  81. package/metadata/index.d.ts +1 -1
  82. package/metadata/index.js +0 -1
  83. package/metadata/types.d.ts +577 -0
  84. package/metadata/types.js +1 -0
  85. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  86. package/naming-strategy/AbstractNamingStrategy.js +26 -5
  87. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/EntityCaseNamingStrategy.js +7 -6
  89. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  90. package/naming-strategy/MongoNamingStrategy.js +6 -6
  91. package/naming-strategy/NamingStrategy.d.ts +28 -4
  92. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  93. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  94. package/naming-strategy/index.d.ts +1 -1
  95. package/naming-strategy/index.js +0 -1
  96. package/not-supported.d.ts +2 -0
  97. package/not-supported.js +8 -0
  98. package/package.json +47 -36
  99. package/platforms/ExceptionConverter.js +1 -1
  100. package/platforms/Platform.d.ts +33 -15
  101. package/platforms/Platform.js +125 -69
  102. package/serialization/EntitySerializer.d.ts +6 -3
  103. package/serialization/EntitySerializer.js +54 -30
  104. package/serialization/EntityTransformer.js +37 -22
  105. package/serialization/SerializationContext.d.ts +10 -14
  106. package/serialization/SerializationContext.js +24 -19
  107. package/types/ArrayType.d.ts +1 -1
  108. package/types/ArrayType.js +2 -3
  109. package/types/BigIntType.js +1 -1
  110. package/types/BlobType.d.ts +0 -1
  111. package/types/BlobType.js +0 -3
  112. package/types/BooleanType.d.ts +1 -0
  113. package/types/BooleanType.js +3 -0
  114. package/types/DecimalType.js +2 -2
  115. package/types/DoubleType.js +1 -1
  116. package/types/EnumArrayType.js +1 -2
  117. package/types/JsonType.d.ts +1 -1
  118. package/types/JsonType.js +7 -2
  119. package/types/TinyIntType.js +1 -1
  120. package/types/Type.d.ts +2 -4
  121. package/types/Type.js +3 -3
  122. package/types/Uint8ArrayType.d.ts +0 -1
  123. package/types/Uint8ArrayType.js +1 -4
  124. package/types/UuidType.d.ts +2 -0
  125. package/types/UuidType.js +14 -2
  126. package/types/index.d.ts +3 -2
  127. package/typings.d.ts +427 -170
  128. package/typings.js +100 -45
  129. package/unit-of-work/ChangeSet.d.ts +4 -6
  130. package/unit-of-work/ChangeSet.js +8 -9
  131. package/unit-of-work/ChangeSetComputer.d.ts +2 -12
  132. package/unit-of-work/ChangeSetComputer.js +61 -38
  133. package/unit-of-work/ChangeSetPersister.d.ts +10 -17
  134. package/unit-of-work/ChangeSetPersister.js +136 -73
  135. package/unit-of-work/CommitOrderCalculator.d.ts +13 -14
  136. package/unit-of-work/CommitOrderCalculator.js +22 -20
  137. package/unit-of-work/IdentityMap.d.ts +12 -3
  138. package/unit-of-work/IdentityMap.js +51 -13
  139. package/unit-of-work/UnitOfWork.d.ts +39 -23
  140. package/unit-of-work/UnitOfWork.js +441 -246
  141. package/utils/AbstractMigrator.d.ts +101 -0
  142. package/utils/AbstractMigrator.js +303 -0
  143. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  144. package/utils/AbstractSchemaGenerator.js +30 -18
  145. package/utils/AsyncContext.d.ts +6 -0
  146. package/utils/AsyncContext.js +42 -0
  147. package/utils/Configuration.d.ts +647 -185
  148. package/utils/Configuration.js +215 -252
  149. package/utils/ConfigurationLoader.d.ts +1 -52
  150. package/utils/ConfigurationLoader.js +1 -330
  151. package/utils/Cursor.d.ts +3 -6
  152. package/utils/Cursor.js +32 -17
  153. package/utils/DataloaderUtils.d.ts +10 -5
  154. package/utils/DataloaderUtils.js +42 -22
  155. package/utils/EntityComparator.d.ts +21 -21
  156. package/utils/EntityComparator.js +224 -118
  157. package/utils/QueryHelper.d.ts +34 -7
  158. package/utils/QueryHelper.js +183 -72
  159. package/utils/RawQueryFragment.d.ts +28 -34
  160. package/utils/RawQueryFragment.js +37 -72
  161. package/utils/RequestContext.js +2 -2
  162. package/utils/TransactionContext.js +2 -2
  163. package/utils/TransactionManager.js +11 -8
  164. package/utils/Utils.d.ts +16 -127
  165. package/utils/Utils.js +104 -402
  166. package/utils/clone.js +13 -23
  167. package/utils/env-vars.d.ts +7 -0
  168. package/utils/env-vars.js +98 -0
  169. package/utils/fs-utils.d.ts +20 -0
  170. package/utils/fs-utils.js +193 -0
  171. package/utils/index.d.ts +1 -3
  172. package/utils/index.js +1 -3
  173. package/utils/upsert-utils.d.ts +9 -4
  174. package/utils/upsert-utils.js +51 -5
  175. package/decorators/Check.d.ts +0 -3
  176. package/decorators/Check.js +0 -13
  177. package/decorators/CreateRequestContext.d.ts +0 -3
  178. package/decorators/CreateRequestContext.js +0 -32
  179. package/decorators/Embeddable.d.ts +0 -8
  180. package/decorators/Embeddable.js +0 -11
  181. package/decorators/Embedded.d.ts +0 -12
  182. package/decorators/Embedded.js +0 -18
  183. package/decorators/Entity.d.ts +0 -33
  184. package/decorators/Entity.js +0 -12
  185. package/decorators/Enum.d.ts +0 -9
  186. package/decorators/Enum.js +0 -16
  187. package/decorators/Filter.d.ts +0 -2
  188. package/decorators/Filter.js +0 -8
  189. package/decorators/Formula.d.ts +0 -4
  190. package/decorators/Formula.js +0 -15
  191. package/decorators/Indexed.d.ts +0 -19
  192. package/decorators/Indexed.js +0 -20
  193. package/decorators/ManyToMany.d.ts +0 -42
  194. package/decorators/ManyToMany.js +0 -14
  195. package/decorators/ManyToOne.d.ts +0 -34
  196. package/decorators/ManyToOne.js +0 -14
  197. package/decorators/OneToMany.d.ts +0 -28
  198. package/decorators/OneToMany.js +0 -17
  199. package/decorators/OneToOne.d.ts +0 -28
  200. package/decorators/OneToOne.js +0 -7
  201. package/decorators/PrimaryKey.d.ts +0 -8
  202. package/decorators/PrimaryKey.js +0 -20
  203. package/decorators/Property.d.ts +0 -250
  204. package/decorators/Property.js +0 -32
  205. package/decorators/Transactional.d.ts +0 -14
  206. package/decorators/Transactional.js +0 -28
  207. package/decorators/hooks.d.ts +0 -16
  208. package/decorators/hooks.js +0 -47
  209. package/decorators/index.d.ts +0 -17
  210. package/decorators/index.js +0 -17
  211. package/entity/ArrayCollection.d.ts +0 -118
  212. package/entity/ArrayCollection.js +0 -407
  213. package/entity/EntityValidator.d.ts +0 -19
  214. package/entity/EntityValidator.js +0 -150
  215. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  216. package/metadata/ReflectMetadataProvider.js +0 -44
  217. package/utils/resolveContextProvider.d.ts +0 -10
  218. package/utils/resolveContextProvider.js +0 -28
@@ -1,20 +1,79 @@
1
1
  import { type Ref } from './Reference.js';
2
- import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
2
+ import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected, SerializeDTO } from '../typings.js';
3
3
  import { type AssignOptions } from './EntityAssigner.js';
4
4
  import type { EntityLoaderOptions } from './EntityLoader.js';
5
5
  import { type SerializeOptions } from '../serialization/EntitySerializer.js';
6
6
  import type { FindOneOptions } from '../drivers/IDatabaseDriver.js';
7
+ import type { PopulatePath } from '../enums.js';
7
8
  export declare abstract class BaseEntity {
8
9
  isInitialized(): boolean;
9
- isTouched(): boolean;
10
10
  populated(populated?: boolean): void;
11
- populate<Entity extends this = this, Hint extends string = never>(populate: AutoPath<Entity, Hint>[] | false, options?: EntityLoaderOptions<Entity>): Promise<Loaded<Entity, Hint>>;
11
+ populate<Entity extends this = this, Hint extends string = never, Fields extends string = never>(populate: AutoPath<Entity, Hint, PopulatePath.ALL>[] | false, options?: EntityLoaderOptions<Entity, Fields>): Promise<Loaded<Entity, Hint>>;
12
12
  toReference<Entity extends this = this>(): Ref<Entity> & LoadedReference<Loaded<Entity, AddEager<Entity>>>;
13
+ /**
14
+ * Converts the entity to a plain object representation.
15
+ *
16
+ * **Note on typing with `Loaded` entities:** When called on a `Loaded<Entity, 'relation'>` type,
17
+ * the return type will be `EntityDTO<Entity>` (with relations as primary keys), not
18
+ * `EntityDTO<Loaded<Entity, 'relation'>>` (with loaded relations as nested objects).
19
+ * This is a TypeScript limitation - the `this` type resolves to the class, not the `Loaded` wrapper.
20
+ *
21
+ * For correct typing that reflects loaded relations, use `wrap()`:
22
+ * ```ts
23
+ * const result = await em.find(User, {}, { populate: ['profile'] });
24
+ * // Type: EntityDTO<User> (profile is number)
25
+ * const obj1 = result[0].toObject();
26
+ * // Type: EntityDTO<Loaded<User, 'profile'>> (profile is nested object)
27
+ * const obj2 = wrap(result[0]).toObject();
28
+ * ```
29
+ *
30
+ * Runtime values are correct in both cases - only the static types differ.
31
+ */
13
32
  toObject<Entity extends this = this>(): EntityDTO<Entity>;
33
+ /**
34
+ * Converts the entity to a plain object representation.
35
+ *
36
+ * **Note on typing with `Loaded` entities:** When called on a `Loaded<Entity, 'relation'>` type,
37
+ * the return type will be `EntityDTO<Entity>` (with relations as primary keys), not
38
+ * `EntityDTO<Loaded<Entity, 'relation'>>` (with loaded relations as nested objects).
39
+ * This is a TypeScript limitation - the `this` type resolves to the class, not the `Loaded` wrapper.
40
+ *
41
+ * For correct typing that reflects loaded relations, use `wrap()`:
42
+ * ```ts
43
+ * const result = await em.find(User, {}, { populate: ['profile'] });
44
+ * // Type: EntityDTO<User> (profile is number)
45
+ * const obj1 = result[0].toObject();
46
+ * // Type: EntityDTO<Loaded<User, 'profile'>> (profile is nested object)
47
+ * const obj2 = wrap(result[0]).toObject();
48
+ * ```
49
+ *
50
+ * Runtime values are correct in both cases - only the static types differ.
51
+ */
14
52
  toObject<Entity extends this = this>(ignoreFields: never[]): EntityDTO<Entity>;
53
+ /**
54
+ * Converts the entity to a plain object representation.
55
+ *
56
+ * **Note on typing with `Loaded` entities:** When called on a `Loaded<Entity, 'relation'>` type,
57
+ * the return type will be `EntityDTO<Entity>` (with relations as primary keys), not
58
+ * `EntityDTO<Loaded<Entity, 'relation'>>` (with loaded relations as nested objects).
59
+ * This is a TypeScript limitation - the `this` type resolves to the class, not the `Loaded` wrapper.
60
+ *
61
+ * For correct typing that reflects loaded relations, use `wrap()`:
62
+ * ```ts
63
+ * const result = await em.find(User, {}, { populate: ['profile'] });
64
+ * // Type: EntityDTO<User> (profile is number)
65
+ * const obj1 = result[0].toObject();
66
+ * // Type: EntityDTO<Loaded<User, 'profile'>> (profile is nested object)
67
+ * const obj2 = wrap(result[0]).toObject();
68
+ * ```
69
+ *
70
+ * Runtime values are correct in both cases - only the static types differ.
71
+ *
72
+ * @param ignoreFields - Array of field names to omit from the result.
73
+ */
15
74
  toObject<Entity extends this = this, Ignored extends EntityKey<Entity> = never>(ignoreFields: Ignored[]): Omit<EntityDTO<Entity>, Ignored>;
16
75
  toPOJO<Entity extends this = this>(): EntityDTO<Entity>;
17
- serialize<Entity extends this = this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): EntityDTO<Loaded<Naked, Hint>>;
76
+ serialize<Entity extends this = this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Exclude extends string = never>(options?: SerializeOptions<Naked, Hint, Exclude>): SerializeDTO<Naked, Hint, Exclude>;
18
77
  assign<Entity extends this, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
19
78
  init<Entity extends this = this, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
20
79
  getSchema(): string | undefined;
@@ -6,9 +6,6 @@ export class BaseEntity {
6
6
  isInitialized() {
7
7
  return helper(this).__initialized;
8
8
  }
9
- isTouched() {
10
- return helper(this).__touched;
11
- }
12
9
  populated(populated = true) {
13
10
  helper(this).populated(populated);
14
11
  }
@@ -1,5 +1,4 @@
1
- import type { EntityDTO, EntityKey, FilterQuery, Loaded, LoadedCollection, Populate } from '../typings.js';
2
- import { ArrayCollection } from './ArrayCollection.js';
1
+ import type { EntityDTO, EntityKey, EntityProperty, FilterQuery, IPrimaryKey, Loaded, LoadedCollection, Populate, Primary } from '../typings.js';
3
2
  import { Reference } from './Reference.js';
4
3
  import type { Transaction } from '../connections/Connection.js';
5
4
  import type { CountOptions, FindOptions } from '../drivers/IDatabaseDriver.js';
@@ -9,10 +8,10 @@ export interface MatchingOptions<T extends object, P extends string = never> ext
9
8
  store?: boolean;
10
9
  ctx?: Transaction;
11
10
  }
12
- export declare class Collection<T extends object, O extends object = object> extends ArrayCollection<T, O> {
13
- private readonly?;
14
- private _populated?;
15
- private _snapshot?;
11
+ export declare class Collection<T extends object, O extends object = object> {
12
+ #private;
13
+ readonly owner: O;
14
+ [k: number]: T;
16
15
  constructor(owner: O, items?: T[], initialized?: boolean);
17
16
  /**
18
17
  * Creates new Collection instance, assigns it to the owning entity and sets the items to it (propagating them to their inverse sides)
@@ -39,59 +38,124 @@ export declare class Collection<T extends object, O extends object = object> ext
39
38
  */
40
39
  getItems(check?: boolean): T[];
41
40
  toJSON<TT extends T>(): EntityDTO<TT>[];
42
- add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): void;
41
+ add<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>>, ...entities: (TT | Reference<TT>)[]): number;
43
42
  /**
44
- * @inheritDoc
43
+ * Remove specified item(s) from the collection. Note that removing item from collection does not necessarily imply deleting the target entity,
44
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
45
+ * 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`,
46
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
45
47
  */
46
- remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): void;
48
+ remove<TT extends T>(entity: TT | Reference<TT> | Iterable<TT | Reference<TT>> | ((item: TT) => boolean), ...entities: (TT | Reference<TT>)[]): number;
47
49
  contains<TT extends T>(item: TT | Reference<TT>, check?: boolean): boolean;
48
50
  count(): number;
49
51
  isEmpty(): boolean;
52
+ shouldPopulate(populated?: boolean): boolean;
53
+ populated(populated?: boolean | undefined): void;
54
+ init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
55
+ private getEntityManager;
56
+ private createCondition;
57
+ private createManyToManyCondition;
58
+ private createLoadCountCondition;
59
+ private checkInitialized;
50
60
  /**
51
- * @inheritDoc
61
+ * re-orders items after searching with `$in` operator
62
+ */
63
+ private reorderItems;
64
+ private cancelOrphanRemoval;
65
+ private validateModification;
66
+ toArray<TT extends T>(): EntityDTO<TT>[];
67
+ getIdentifiers<U extends IPrimaryKey = Primary<T> & IPrimaryKey>(field?: string | string[]): U[];
68
+ /**
69
+ * @internal
70
+ */
71
+ addWithoutPropagation(entity: T): void;
72
+ set(items: Iterable<T | Reference<T>>): void;
73
+ private compare;
74
+ /**
75
+ * @internal
76
+ */
77
+ hydrate(items: T[], forcePropagate?: boolean, partial?: boolean): void;
78
+ /**
79
+ * Remove all items from the collection. Note that removing items from collection does not necessarily imply deleting the target entity,
80
+ * it means we are disconnecting the relation - removing items from collection, not removing entities from database - `Collection.remove()`
81
+ * 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`,
82
+ * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
83
+ */
84
+ removeAll(): void;
85
+ /**
86
+ * @internal
87
+ */
88
+ removeWithoutPropagation(entity: T): void;
89
+ /**
90
+ * Extracts a slice of the collection items starting at position start to end (exclusive) of the collection.
91
+ * If end is null it returns all elements from start to the end of the collection.
52
92
  */
53
93
  slice(start?: number, end?: number): T[];
54
94
  /**
55
- * @inheritDoc
95
+ * Tests for the existence of an element that satisfies the given predicate.
56
96
  */
57
97
  exists(cb: (item: T) => boolean): boolean;
58
98
  /**
59
- * @inheritDoc
99
+ * Returns the first element of this collection that satisfies the predicate.
100
+ */
101
+ find<S extends T>(cb: (item: T, index: number) => item is S): S | undefined;
102
+ /**
103
+ * Returns the first element of this collection that satisfies the predicate.
60
104
  */
61
105
  find(cb: (item: T, index: number) => boolean): T | undefined;
62
106
  /**
63
- * @inheritDoc
107
+ * Extracts a subset of the collection items.
108
+ */
109
+ filter<S extends T>(cb: (item: T, index: number) => item is S): S[];
110
+ /**
111
+ * Extracts a subset of the collection items.
64
112
  */
65
113
  filter(cb: (item: T, index: number) => boolean): T[];
66
114
  /**
67
- * @inheritDoc
115
+ * Maps the collection items based on your provided mapper function.
68
116
  */
69
117
  map<R>(mapper: (item: T, index: number) => R): R[];
70
118
  /**
71
- * @inheritDoc
119
+ * Maps the collection items based on your provided mapper function to a single object.
120
+ */
121
+ reduce<R>(cb: (obj: R, item: T, index: number) => R, initial?: R): R;
122
+ /**
123
+ * Maps the collection items to a dictionary, indexed by the key you specify.
124
+ * If there are more items with the same key, only the first one will be present.
72
125
  */
73
126
  indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1): Record<T[K1] & PropertyKey, T>;
74
127
  /**
75
- * @inheritDoc
128
+ * Maps the collection items to a dictionary, indexed by the key you specify.
129
+ * If there are more items with the same key, only the first one will be present.
76
130
  */
77
131
  indexBy<K1 extends keyof T, K2 extends keyof T = never>(key: K1, valueKey: K2): Record<T[K1] & PropertyKey, T[K2]>;
78
- shouldPopulate(populated?: boolean): boolean;
79
- populated(populated?: boolean | undefined): void;
80
- init<TT extends T, P extends string = never>(options?: InitCollectionOptions<TT, P>): Promise<LoadedCollection<Loaded<TT, P>>>;
81
- private getEntityManager;
82
- private createCondition;
83
- private createOrderBy;
84
- private createManyToManyCondition;
85
- private createLoadCountCondition;
86
- private modify;
87
- private checkInitialized;
132
+ isInitialized(fully?: boolean): boolean;
133
+ isDirty(): boolean;
134
+ isPartial(): boolean;
135
+ setDirty(dirty?: boolean): void;
136
+ get length(): number;
137
+ [Symbol.iterator](): IterableIterator<T>;
88
138
  /**
89
- * re-orders items after searching with `$in` operator
139
+ * @internal
90
140
  */
91
- private reorderItems;
92
- private cancelOrphanRemoval;
93
- private validateItemType;
94
- private validateModification;
141
+ takeSnapshot(forcePropagate?: boolean): void;
142
+ /**
143
+ * @internal
144
+ */
145
+ getSnapshot(): T[] | undefined;
146
+ /**
147
+ * @internal
148
+ */
149
+ get property(): EntityProperty;
150
+ /**
151
+ * @internal
152
+ */
153
+ set property(prop: EntityProperty);
154
+ protected propagate(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
155
+ protected propagateToInverseSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
156
+ protected propagateToOwningSide(item: T, method: 'add' | 'remove' | 'takeSnapshot'): void;
157
+ protected shouldPropagateToCollection(collection: Collection<O, T>, method: 'add' | 'remove' | 'takeSnapshot'): boolean;
158
+ protected incrementCount(value: number): void;
95
159
  }
96
160
  export interface InitCollectionOptions<T, P extends string = never, F extends string = '*', E extends string = never> extends EntityLoaderOptions<T, F, E> {
97
161
  dataloader?: boolean;