@mikro-orm/core 7.0.0-dev.23 → 7.0.0-dev.231

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 (209) hide show
  1. package/EntityManager.d.ts +91 -59
  2. package/EntityManager.js +303 -251
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +109 -143
  5. package/README.md +2 -0
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +17 -8
  8. package/cache/GeneratedCacheAdapter.d.ts +0 -1
  9. package/cache/GeneratedCacheAdapter.js +0 -2
  10. package/cache/index.d.ts +0 -1
  11. package/cache/index.js +0 -1
  12. package/connections/Connection.d.ts +12 -5
  13. package/connections/Connection.js +21 -12
  14. package/drivers/DatabaseDriver.d.ts +25 -16
  15. package/drivers/DatabaseDriver.js +118 -35
  16. package/drivers/IDatabaseDriver.d.ts +42 -19
  17. package/entity/BaseEntity.d.ts +61 -2
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +101 -29
  20. package/entity/Collection.js +436 -104
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +26 -18
  23. package/entity/EntityFactory.d.ts +7 -1
  24. package/entity/EntityFactory.js +83 -54
  25. package/entity/EntityHelper.d.ts +2 -2
  26. package/entity/EntityHelper.js +48 -15
  27. package/entity/EntityLoader.d.ts +7 -6
  28. package/entity/EntityLoader.js +221 -93
  29. package/entity/EntityRepository.d.ts +27 -7
  30. package/entity/EntityRepository.js +8 -2
  31. package/entity/PolymorphicRef.d.ts +12 -0
  32. package/entity/PolymorphicRef.js +18 -0
  33. package/entity/Reference.d.ts +1 -5
  34. package/entity/Reference.js +21 -12
  35. package/entity/WrappedEntity.d.ts +0 -5
  36. package/entity/WrappedEntity.js +2 -7
  37. package/entity/defineEntity.d.ts +380 -310
  38. package/entity/defineEntity.js +124 -273
  39. package/entity/index.d.ts +2 -2
  40. package/entity/index.js +2 -2
  41. package/entity/utils.js +1 -1
  42. package/entity/validators.d.ts +11 -0
  43. package/entity/validators.js +65 -0
  44. package/enums.d.ts +8 -6
  45. package/enums.js +2 -1
  46. package/errors.d.ts +20 -10
  47. package/errors.js +55 -23
  48. package/events/EventManager.d.ts +2 -1
  49. package/events/EventManager.js +19 -11
  50. package/hydration/Hydrator.js +1 -2
  51. package/hydration/ObjectHydrator.d.ts +4 -4
  52. package/hydration/ObjectHydrator.js +87 -35
  53. package/index.d.ts +2 -2
  54. package/index.js +1 -2
  55. package/logging/DefaultLogger.d.ts +1 -1
  56. package/logging/DefaultLogger.js +1 -0
  57. package/logging/SimpleLogger.d.ts +1 -1
  58. package/logging/colors.d.ts +1 -1
  59. package/logging/colors.js +7 -6
  60. package/logging/index.d.ts +1 -0
  61. package/logging/index.js +1 -0
  62. package/logging/inspect.d.ts +2 -0
  63. package/logging/inspect.js +11 -0
  64. package/metadata/EntitySchema.d.ts +47 -23
  65. package/metadata/EntitySchema.js +92 -33
  66. package/metadata/MetadataDiscovery.d.ts +64 -9
  67. package/metadata/MetadataDiscovery.js +778 -325
  68. package/metadata/MetadataProvider.d.ts +11 -2
  69. package/metadata/MetadataProvider.js +46 -2
  70. package/metadata/MetadataStorage.d.ts +13 -11
  71. package/metadata/MetadataStorage.js +70 -37
  72. package/metadata/MetadataValidator.d.ts +32 -9
  73. package/metadata/MetadataValidator.js +196 -41
  74. package/metadata/discover-entities.d.ts +5 -0
  75. package/metadata/discover-entities.js +40 -0
  76. package/metadata/index.d.ts +1 -1
  77. package/metadata/index.js +1 -1
  78. package/metadata/types.d.ts +526 -0
  79. package/metadata/types.js +1 -0
  80. package/naming-strategy/AbstractNamingStrategy.d.ts +16 -4
  81. package/naming-strategy/AbstractNamingStrategy.js +20 -2
  82. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  83. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  84. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  85. package/naming-strategy/MongoNamingStrategy.js +6 -6
  86. package/naming-strategy/NamingStrategy.d.ts +28 -4
  87. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  88. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  89. package/not-supported.d.ts +2 -0
  90. package/not-supported.js +4 -0
  91. package/package.json +19 -11
  92. package/platforms/ExceptionConverter.js +1 -1
  93. package/platforms/Platform.d.ts +7 -14
  94. package/platforms/Platform.js +20 -43
  95. package/serialization/EntitySerializer.d.ts +5 -0
  96. package/serialization/EntitySerializer.js +47 -27
  97. package/serialization/EntityTransformer.js +28 -18
  98. package/serialization/SerializationContext.d.ts +6 -6
  99. package/serialization/SerializationContext.js +3 -3
  100. package/types/ArrayType.d.ts +1 -1
  101. package/types/ArrayType.js +2 -3
  102. package/types/BigIntType.d.ts +8 -6
  103. package/types/BigIntType.js +1 -1
  104. package/types/BlobType.d.ts +0 -1
  105. package/types/BlobType.js +0 -3
  106. package/types/BooleanType.d.ts +1 -0
  107. package/types/BooleanType.js +3 -0
  108. package/types/DecimalType.d.ts +6 -4
  109. package/types/DecimalType.js +2 -2
  110. package/types/DoubleType.js +1 -1
  111. package/types/EnumArrayType.js +1 -2
  112. package/types/JsonType.d.ts +1 -1
  113. package/types/JsonType.js +7 -2
  114. package/types/TinyIntType.js +1 -1
  115. package/types/Type.d.ts +2 -4
  116. package/types/Type.js +3 -3
  117. package/types/Uint8ArrayType.d.ts +0 -1
  118. package/types/Uint8ArrayType.js +1 -4
  119. package/types/index.d.ts +1 -1
  120. package/typings.d.ts +381 -171
  121. package/typings.js +97 -44
  122. package/unit-of-work/ChangeSet.d.ts +4 -6
  123. package/unit-of-work/ChangeSet.js +4 -5
  124. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  125. package/unit-of-work/ChangeSetComputer.js +35 -14
  126. package/unit-of-work/ChangeSetPersister.d.ts +7 -3
  127. package/unit-of-work/ChangeSetPersister.js +83 -25
  128. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  129. package/unit-of-work/CommitOrderCalculator.js +13 -13
  130. package/unit-of-work/IdentityMap.d.ts +12 -0
  131. package/unit-of-work/IdentityMap.js +39 -1
  132. package/unit-of-work/UnitOfWork.d.ts +27 -3
  133. package/unit-of-work/UnitOfWork.js +258 -92
  134. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  135. package/utils/AbstractSchemaGenerator.js +28 -17
  136. package/utils/AsyncContext.d.ts +6 -0
  137. package/utils/AsyncContext.js +42 -0
  138. package/utils/Configuration.d.ts +795 -209
  139. package/utils/Configuration.js +150 -192
  140. package/utils/ConfigurationLoader.d.ts +1 -54
  141. package/utils/ConfigurationLoader.js +1 -352
  142. package/utils/Cursor.d.ts +0 -3
  143. package/utils/Cursor.js +24 -11
  144. package/utils/DataloaderUtils.d.ts +10 -5
  145. package/utils/DataloaderUtils.js +29 -12
  146. package/utils/EntityComparator.d.ts +16 -9
  147. package/utils/EntityComparator.js +158 -58
  148. package/utils/QueryHelper.d.ts +18 -6
  149. package/utils/QueryHelper.js +76 -23
  150. package/utils/RawQueryFragment.d.ts +28 -34
  151. package/utils/RawQueryFragment.js +35 -71
  152. package/utils/RequestContext.js +2 -2
  153. package/utils/TransactionContext.js +2 -2
  154. package/utils/TransactionManager.js +28 -4
  155. package/utils/Utils.d.ts +14 -127
  156. package/utils/Utils.js +85 -397
  157. package/utils/clone.js +8 -23
  158. package/utils/env-vars.d.ts +7 -0
  159. package/utils/env-vars.js +97 -0
  160. package/utils/fs-utils.d.ts +33 -0
  161. package/utils/fs-utils.js +192 -0
  162. package/utils/index.d.ts +1 -1
  163. package/utils/index.js +1 -1
  164. package/utils/upsert-utils.d.ts +9 -4
  165. package/utils/upsert-utils.js +46 -3
  166. package/decorators/Check.d.ts +0 -3
  167. package/decorators/Check.js +0 -13
  168. package/decorators/CreateRequestContext.d.ts +0 -3
  169. package/decorators/CreateRequestContext.js +0 -32
  170. package/decorators/Embeddable.d.ts +0 -8
  171. package/decorators/Embeddable.js +0 -11
  172. package/decorators/Embedded.d.ts +0 -12
  173. package/decorators/Embedded.js +0 -18
  174. package/decorators/Entity.d.ts +0 -33
  175. package/decorators/Entity.js +0 -12
  176. package/decorators/Enum.d.ts +0 -9
  177. package/decorators/Enum.js +0 -16
  178. package/decorators/Filter.d.ts +0 -2
  179. package/decorators/Filter.js +0 -8
  180. package/decorators/Formula.d.ts +0 -4
  181. package/decorators/Formula.js +0 -15
  182. package/decorators/Indexed.d.ts +0 -19
  183. package/decorators/Indexed.js +0 -20
  184. package/decorators/ManyToMany.d.ts +0 -42
  185. package/decorators/ManyToMany.js +0 -14
  186. package/decorators/ManyToOne.d.ts +0 -34
  187. package/decorators/ManyToOne.js +0 -14
  188. package/decorators/OneToMany.d.ts +0 -28
  189. package/decorators/OneToMany.js +0 -17
  190. package/decorators/OneToOne.d.ts +0 -28
  191. package/decorators/OneToOne.js +0 -7
  192. package/decorators/PrimaryKey.d.ts +0 -8
  193. package/decorators/PrimaryKey.js +0 -20
  194. package/decorators/Property.d.ts +0 -250
  195. package/decorators/Property.js +0 -32
  196. package/decorators/Transactional.d.ts +0 -14
  197. package/decorators/Transactional.js +0 -28
  198. package/decorators/hooks.d.ts +0 -16
  199. package/decorators/hooks.js +0 -47
  200. package/decorators/index.d.ts +0 -17
  201. package/decorators/index.js +0 -17
  202. package/entity/ArrayCollection.d.ts +0 -118
  203. package/entity/ArrayCollection.js +0 -407
  204. package/entity/EntityValidator.d.ts +0 -19
  205. package/entity/EntityValidator.js +0 -150
  206. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  207. package/metadata/ReflectMetadataProvider.js +0 -44
  208. package/utils/resolveContextProvider.d.ts +0 -10
  209. package/utils/resolveContextProvider.js +0 -28
@@ -1,16 +1,13 @@
1
- import { inspect } from 'node:util';
2
- import DataLoader from 'dataloader';
3
1
  import { type Configuration } from './utils/Configuration.js';
4
2
  import { Cursor } from './utils/Cursor.js';
5
3
  import { EntityFactory } from './entity/EntityFactory.js';
6
4
  import { type AssignOptions } from './entity/EntityAssigner.js';
7
- import { EntityValidator } from './entity/EntityValidator.js';
8
5
  import { type EntityRepository } from './entity/EntityRepository.js';
9
6
  import { EntityLoader, type EntityLoaderOptions } from './entity/EntityLoader.js';
10
7
  import { Reference } from './entity/Reference.js';
11
8
  import { UnitOfWork } from './unit-of-work/UnitOfWork.js';
12
- import type { CountOptions, DeleteOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers/IDatabaseDriver.js';
13
- import type { AnyEntity, AnyString, ArrayElement, AutoPath, ConnectionType, Dictionary, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MaybePromise, MergeLoaded, MergeSelected, NoInfer, ObjectQuery, Primary, Ref, RequiredEntityData, UnboxArray } from './typings.js';
9
+ import type { CountOptions, DeleteOptions, FilterOptions, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, StreamOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers/IDatabaseDriver.js';
10
+ import type { AnyString, ArrayElement, AutoPath, ConnectionType, Dictionary, EntityClass, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterDef, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MergeLoaded, MergeSelected, ObjectQuery, PopulateOptions, Primary, Ref, RequiredEntityData, UnboxArray } from './typings.js';
14
11
  import { FlushMode, LockMode, PopulatePath, type TransactionOptions } from './enums.js';
15
12
  import type { MetadataStorage } from './metadata/MetadataStorage.js';
16
13
  import type { Transaction } from './connections/Connection.js';
@@ -27,14 +24,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
27
24
  protected readonly metadata: MetadataStorage;
28
25
  protected readonly useContext: boolean;
29
26
  protected readonly eventManager: EventManager;
27
+ /** @internal */
28
+ readonly '~entities'?: unknown;
30
29
  private static counter;
31
30
  readonly _id: number;
32
31
  readonly global = false;
33
32
  readonly name: string;
34
- protected readonly refLoader: DataLoader<[Reference<any>, (Omit<import("./entity/Reference.js").LoadReferenceOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [Reference<any>, (Omit<import("./entity/Reference.js").LoadReferenceOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
35
- protected readonly colLoader: DataLoader<[import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
36
- protected readonly colLoaderMtoN: DataLoader<[import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [import("./index.js").Collection<any, object>, (Omit<import("./index.js").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
37
- private readonly validator;
33
+ private readonly loaders;
38
34
  private readonly repositoryMap;
39
35
  private readonly entityLoader;
40
36
  protected readonly comparator: EntityComparator;
@@ -73,14 +69,28 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
73
69
  * Shortcut for `em.getRepository()`.
74
70
  */
75
71
  repo<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(entityName: EntityName<Entity>): GetRepository<Entity, Repository>;
76
- /**
77
- * Gets EntityValidator instance
78
- */
79
- getValidator(): EntityValidator;
80
72
  /**
81
73
  * Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
82
74
  */
83
75
  find<Entity extends object, Hint extends string = never, Fields extends string = PopulatePath.ALL, Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options?: FindOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes>[]>;
76
+ /**
77
+ * Finds all entities and returns an async iterable (async generator) that yields results one by one.
78
+ * The results are merged and mapped to entity instances, without adding them to the identity map.
79
+ * You can disable merging by passing the options `{ mergeResults: false }`.
80
+ * With `mergeResults` disabled, to-many collections will contain at most one item, and you will get duplicate
81
+ * root entities when there are multiple items in the populated collection.
82
+ * This is useful for processing large datasets without loading everything into memory at once.
83
+ *
84
+ * ```ts
85
+ * const stream = em.stream(Book, { populate: ['author'] });
86
+ *
87
+ * for await (const book of stream) {
88
+ * // book is an instance of Book entity
89
+ * console.log(book.title, book.author.name);
90
+ * }
91
+ * ```
92
+ */
93
+ stream<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, options?: StreamOptions<NoInfer<Entity>, Hint, Fields, Excludes>): AsyncIterableIterator<Loaded<Entity, Hint, Fields, Excludes>>;
84
94
  /**
85
95
  * Finds all entities of given type, optionally matching the `where` condition provided in the `options` parameter.
86
96
  */
@@ -89,19 +99,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
89
99
  /**
90
100
  * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
91
101
  */
92
- addFilter<T1>(name: string, cond: FilterQuery<T1> | ((args: Dictionary) => MaybePromise<FilterQuery<T1>>), entityName?: EntityName<T1> | [EntityName<T1>], enabled?: boolean): void;
93
- /**
94
- * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
95
- */
96
- addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | T2> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2>>), entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void;
97
- /**
98
- * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
99
- */
100
- addFilter<T1, T2, T3>(name: string, cond: FilterQuery<T1 | T2 | T3> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2 | T3>>), entityName?: [EntityName<T1>, EntityName<T2>, EntityName<T3>], enabled?: boolean): void;
101
- /**
102
- * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
103
- */
104
- addFilter(name: string, cond: Dictionary | ((args: Dictionary) => MaybePromise<FilterQuery<AnyEntity>>), entityName?: EntityName<AnyEntity> | EntityName<AnyEntity>[], enabled?: boolean): void;
102
+ addFilter<T extends EntityName | readonly EntityName[]>(options: FilterDef<T>): void;
105
103
  /**
106
104
  * Sets filter parameter values globally inside context defined by this entity manager.
107
105
  * If you want to set shared value for all contexts, be sure to use the root entity manager.
@@ -121,19 +119,22 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
121
119
  getLoggerContext<T extends Dictionary = Dictionary>(options?: {
122
120
  disableContextResolution?: boolean;
123
121
  }): T;
124
- setFlushMode(flushMode?: FlushMode): void;
125
- protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: string, where: FilterQuery<Entity>, options: FindOptions<Entity, Hint, Fields, Excludes> | FindOneOptions<Entity, Hint, Fields, Excludes>, type: 'read' | 'update' | 'delete'): Promise<FilterQuery<Entity>>;
126
- protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
122
+ setFlushMode(flushMode?: FlushMode | `${FlushMode}`): void;
123
+ protected processWhere<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, options: FindOptions<Entity, Hint, Fields, Excludes> | FindOneOptions<Entity, Hint, Fields, Excludes>, type: 'read' | 'update' | 'delete'): Promise<FilterQuery<Entity>>;
124
+ protected applyDiscriminatorCondition<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>): FilterQuery<Entity>;
127
125
  protected createPopulateWhere<Entity extends object>(cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any> | CountOptions<Entity, any>): ObjectQuery<Entity>;
128
- protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity>>;
126
+ protected getJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity> | undefined>;
129
127
  /**
130
128
  * When filters are active on M:1 or 1:1 relations, we need to ref join them eagerly as they might affect the FK value.
131
129
  */
132
- protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>): Promise<void>;
130
+ protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>, parent?: {
131
+ class: EntityClass;
132
+ propName: string;
133
+ }): Promise<void>;
133
134
  /**
134
135
  * @internal
135
136
  */
136
- applyFilters<Entity extends object>(entityName: string, where: FilterQuery<Entity> | undefined, options: Dictionary<boolean | Dictionary> | string[] | boolean, type: 'read' | 'update' | 'delete', findOptions?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): Promise<FilterQuery<Entity> | undefined>;
137
+ applyFilters<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity> | undefined, options: FilterOptions | undefined, type: 'read' | 'update' | 'delete', findOptions?: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): Promise<FilterQuery<Entity> | undefined>;
137
138
  /**
138
139
  * Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
139
140
  * where the first element is the array of entities, and the second is the count.
@@ -153,21 +154,21 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
153
154
  * - POJO/entity instance
154
155
  *
155
156
  * ```ts
156
- * const currentCursor = await em.findByCursor(User, {}, {
157
+ * const currentCursor = await em.findByCursor(User, {
157
158
  * first: 10,
158
159
  * after: previousCursor, // cursor instance
159
160
  * orderBy: { id: 'desc' },
160
161
  * });
161
162
  *
162
163
  * // to fetch next page
163
- * const nextCursor = await em.findByCursor(User, {}, {
164
+ * const nextCursor = await em.findByCursor(User, {
164
165
  * first: 10,
165
166
  * after: currentCursor.endCursor, // opaque string
166
167
  * orderBy: { id: 'desc' },
167
168
  * });
168
169
  *
169
170
  * // to fetch next page
170
- * const nextCursor2 = await em.findByCursor(User, {}, {
171
+ * const nextCursor2 = await em.findByCursor(User, {
171
172
  * first: 10,
172
173
  * after: { id: lastSeenId }, // entity-like POJO
173
174
  * orderBy: { id: 'desc' },
@@ -195,7 +196,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
195
196
  * }
196
197
  * ```
197
198
  */
198
- findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>, where: FilterQuery<NoInfer<Entity>>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
199
+ findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never, IncludeCount extends boolean = true>(entityName: EntityName<Entity>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes, IncludeCount>): Promise<Cursor<Entity, Hint, Fields, Excludes, IncludeCount>>;
199
200
  /**
200
201
  * Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
201
202
  * persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
@@ -270,6 +271,29 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
270
271
  upsertMany<Entity extends object, Fields extends string = any>(entityNameOrEntity: EntityName<Entity> | Entity[], data?: (EntityData<Entity> | NoInfer<Entity>)[], options?: UpsertManyOptions<Entity, Fields>): Promise<Entity[]>;
271
272
  /**
272
273
  * Runs your callback wrapped inside a database transaction.
274
+ *
275
+ * If a transaction is already active, a new savepoint (nested transaction) will be created by default. This behavior
276
+ * can be controlled via the `propagation` option. Use the provided EntityManager instance for all operations that
277
+ * should be part of the transaction. You can safely use a global EntityManager instance from a DI container, as this
278
+ * method automatically creates an async context for the transaction.
279
+ *
280
+ * **Concurrency note:** When running multiple transactions concurrently (e.g. in parallel requests or jobs), use the
281
+ * `clear: true` option. This ensures the callback runs in a clear fork of the EntityManager, providing full isolation
282
+ * between concurrent transactional handlers. Using `clear: true` is an alternative to forking explicitly and calling
283
+ * the method on the new fork – it already provides the necessary isolation for safe concurrent usage.
284
+ *
285
+ * **Propagation note:** Changes made within a transaction (whether top-level or nested) are always propagated to the
286
+ * parent context, unless the parent context is a global one. If you want to avoid that, fork the EntityManager first
287
+ * and then call this method on the fork.
288
+ *
289
+ * **Example:**
290
+ * ```ts
291
+ * await em.transactional(async (em) => {
292
+ * const author = new Author('Jon');
293
+ * em.persist(author);
294
+ * // flush is called automatically at the end of the callback
295
+ * });
296
+ * ```
273
297
  */
274
298
  transactional<T>(cb: (em: this) => T | Promise<T>, options?: TransactionOptions): Promise<T>;
275
299
  /**
@@ -335,7 +359,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
335
359
  * The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
336
360
  * behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
337
361
  */
338
- create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: RequiredEntityData<Entity, never, Convert>, options?: CreateOptions<Convert>): Entity;
362
+ create<Entity extends object, Convert extends boolean = false, Data extends RequiredEntityData<Entity, never, Convert> = RequiredEntityData<Entity, never, Convert>>(entityName: EntityName<Entity>, data: Data & IsSubset<RequiredEntityData<Entity, never, Convert>, Data>, options?: CreateOptions<Convert>): Entity;
339
363
  /**
340
364
  * Creates new instance of given entity and populates it with given data.
341
365
  * The entity constructor will be used unless you provide `{ managed: true }` in the `options` parameter.
@@ -351,17 +375,33 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
351
375
  * The newly created entity will be automatically marked for persistence via `em.persist` unless you disable this
352
376
  * behavior, either locally via `persist: false` option, or globally via `persistOnCreate` ORM config option.
353
377
  */
354
- create<Entity extends object, Convert extends boolean = false>(entityName: EntityName<Entity>, data: EntityData<Entity, Convert>, options: CreateOptions<Convert> & {
378
+ create<Entity extends object, Convert extends boolean = false, Data extends EntityData<Entity, Convert> = EntityData<Entity, Convert>>(entityName: EntityName<Entity>, data: Data & IsSubset<EntityData<Entity, Convert>, Data>, options: CreateOptions<Convert> & {
355
379
  partial: true;
356
380
  }): Entity;
357
381
  /**
358
382
  * Shortcut for `wrap(entity).assign(data, { em })`
359
383
  */
360
384
  assign<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(entity: Entity | Partial<Entity>, data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
385
+ /**
386
+ * Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
387
+ * The key option specifies which property to use for identity map lookup instead of the primary key.
388
+ */
389
+ getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key' | 'wrapped'> & {
390
+ key: K;
391
+ wrapped: true;
392
+ }): Ref<Entity>;
393
+ /**
394
+ * Gets a reference to the entity identified by the given type and alternate key property without actually loading it.
395
+ * The key option specifies which property to use for identity map lookup instead of the primary key.
396
+ */
397
+ getReference<Entity extends object, K extends string & keyof Entity>(entityName: EntityName<Entity>, id: Entity[K], options: Omit<GetReferenceOptions, 'key'> & {
398
+ key: K;
399
+ wrapped?: false;
400
+ }): Entity;
361
401
  /**
362
402
  * Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
363
403
  */
364
- getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
404
+ getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
365
405
  wrapped: true;
366
406
  }): Ref<Entity>;
367
407
  /**
@@ -371,7 +411,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
371
411
  /**
372
412
  * Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
373
413
  */
374
- getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
414
+ getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped' | 'key'> & {
375
415
  wrapped: false;
376
416
  }): Entity;
377
417
  /**
@@ -387,11 +427,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
387
427
  * The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
388
428
  */
389
429
  persist<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
390
- /**
391
- * Persists your entity immediately, flushing all not yet persisted changes to the database too.
392
- * Equivalent to `em.persist(e).flush()`.
393
- */
394
- persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
395
430
  /**
396
431
  * Marks entity for removal.
397
432
  * A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
@@ -399,11 +434,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
399
434
  * To remove entities by condition, use `em.nativeDelete()`.
400
435
  */
401
436
  remove<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
402
- /**
403
- * Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
404
- * Equivalent to `em.remove(e).flush()`
405
- */
406
- removeAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
407
437
  /**
408
438
  * Flushes all changes to objects that have been queued up to now to the database.
409
439
  * This effectively synchronizes the in-memory state of managed objects with the database.
@@ -484,7 +514,8 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
484
514
  private checkLockRequirements;
485
515
  private lockAndPopulate;
486
516
  private buildFields;
487
- private preparePopulate;
517
+ /** @internal */
518
+ preparePopulate<Entity extends object>(entityName: EntityName<Entity>, options: Pick<FindOptions<Entity, any, any, any>, 'populate' | 'strategy' | 'fields' | 'flags' | 'filters' | 'exclude'>, validate?: boolean): Promise<PopulateOptions<Entity>[]>;
488
519
  /**
489
520
  * when the entity is found in identity map, we check if it was partially loaded or we are trying to populate
490
521
  * some additional lazy properties, if so, we reload and merge the data from database
@@ -494,20 +525,20 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
494
525
  /**
495
526
  * @internal
496
527
  */
497
- cacheKey<T extends object>(entityName: string, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any> | CountOptions<T, any>, method: string, where: FilterQuery<T>): unknown[];
528
+ cacheKey<T extends object>(entityName: EntityName<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any> | CountOptions<T, any>, method: string, where: FilterQuery<T>): unknown[];
498
529
  /**
499
530
  * @internal
500
531
  */
501
- tryCache<T extends object, R>(entityName: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
532
+ tryCache<T extends object, R>(entityName: EntityName<T>, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
502
533
  data?: R | null;
503
534
  key: string;
504
535
  } | undefined>;
505
536
  /**
506
537
  * @internal
507
538
  */
508
- storeCache(config: boolean | number | [string, number] | undefined, key: {
539
+ storeCache<T>(config: boolean | number | [string, number] | undefined, key: {
509
540
  key: string;
510
- }, data: unknown | (() => unknown)): Promise<void>;
541
+ }, data: T | (() => T)): Promise<void>;
511
542
  /**
512
543
  * Clears result cache for given cache key. If we want to be able to call this method,
513
544
  * we need to set the cache key explicitly when storing the cache.
@@ -531,13 +562,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
531
562
  * if executed inside request context handler.
532
563
  */
533
564
  set schema(schema: string | null | undefined);
565
+ /** @internal */
566
+ getDataLoader(type: 'ref' | '1:m' | 'm:n'): Promise<any>;
534
567
  /**
535
568
  * Returns the ID of this EntityManager. Respects the context, so global EM will give you the contextual ID
536
569
  * if executed inside request context handler.
537
570
  */
538
571
  get id(): number;
539
- /** @ignore */
540
- [inspect.custom](): string;
541
572
  }
542
573
  export interface CreateOptions<Convert extends boolean> {
543
574
  /** creates a managed entity instance instead, bypassing the constructor call */
@@ -561,7 +592,8 @@ export interface MergeOptions {
561
592
  convertCustomTypes?: boolean;
562
593
  schema?: string;
563
594
  disableContextResolution?: boolean;
564
- keepIdentity?: boolean;
595
+ validate?: boolean;
596
+ cascade?: boolean; /** @default true */
565
597
  }
566
598
  export interface ForkOptions {
567
599
  /** do we want a clear identity map? defaults to true */
@@ -575,7 +607,7 @@ export interface ForkOptions {
575
607
  /** use this flag to ignore the current async context - this is required if we want to call `em.fork()` inside the `getContext` handler */
576
608
  disableContextResolution?: boolean;
577
609
  /** set flush mode for this fork, overrides the global option can be overridden locally via FindOptions */
578
- flushMode?: FlushMode;
610
+ flushMode?: FlushMode | `${FlushMode}`;
579
611
  /** disable transactions for this fork */
580
612
  disableTransactions?: boolean;
581
613
  /** should we keep the transaction context of the parent EM? */