@mikro-orm/core 7.0.0-dev.15 → 7.0.0-dev.151

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 +81 -55
  2. package/EntityManager.js +292 -262
  3. package/MikroORM.d.ts +44 -35
  4. package/MikroORM.js +103 -143
  5. package/README.md +3 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +8 -7
  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 +16 -7
  13. package/connections/Connection.js +23 -14
  14. package/drivers/DatabaseDriver.d.ts +25 -16
  15. package/drivers/DatabaseDriver.js +80 -35
  16. package/drivers/IDatabaseDriver.d.ts +38 -17
  17. package/entity/BaseEntity.d.ts +2 -2
  18. package/entity/BaseEntity.js +0 -3
  19. package/entity/Collection.d.ts +94 -29
  20. package/entity/Collection.js +434 -97
  21. package/entity/EntityAssigner.d.ts +1 -1
  22. package/entity/EntityAssigner.js +26 -18
  23. package/entity/EntityFactory.d.ts +7 -0
  24. package/entity/EntityFactory.js +72 -53
  25. package/entity/EntityHelper.d.ts +2 -2
  26. package/entity/EntityHelper.js +35 -15
  27. package/entity/EntityLoader.d.ts +5 -5
  28. package/entity/EntityLoader.js +80 -70
  29. package/entity/EntityRepository.d.ts +6 -2
  30. package/entity/EntityRepository.js +8 -2
  31. package/entity/Reference.d.ts +6 -5
  32. package/entity/Reference.js +34 -9
  33. package/entity/WrappedEntity.d.ts +2 -7
  34. package/entity/WrappedEntity.js +3 -8
  35. package/entity/defineEntity.d.ts +575 -0
  36. package/entity/defineEntity.js +529 -0
  37. package/entity/index.d.ts +3 -2
  38. package/entity/index.js +3 -2
  39. package/entity/utils.d.ts +7 -0
  40. package/entity/utils.js +16 -4
  41. package/entity/validators.d.ts +11 -0
  42. package/entity/validators.js +65 -0
  43. package/enums.d.ts +21 -5
  44. package/enums.js +15 -1
  45. package/errors.d.ts +18 -9
  46. package/errors.js +44 -21
  47. package/events/EventManager.d.ts +2 -1
  48. package/events/EventManager.js +19 -11
  49. package/hydration/Hydrator.js +1 -2
  50. package/hydration/ObjectHydrator.d.ts +4 -4
  51. package/hydration/ObjectHydrator.js +50 -33
  52. package/index.d.ts +2 -2
  53. package/index.js +1 -2
  54. package/logging/DefaultLogger.d.ts +1 -1
  55. package/logging/DefaultLogger.js +1 -0
  56. package/logging/SimpleLogger.d.ts +1 -1
  57. package/logging/colors.d.ts +1 -1
  58. package/logging/colors.js +7 -6
  59. package/logging/index.d.ts +1 -0
  60. package/logging/index.js +1 -0
  61. package/logging/inspect.d.ts +2 -0
  62. package/logging/inspect.js +11 -0
  63. package/metadata/EntitySchema.d.ts +18 -22
  64. package/metadata/EntitySchema.js +50 -34
  65. package/metadata/MetadataDiscovery.d.ts +6 -10
  66. package/metadata/MetadataDiscovery.js +315 -304
  67. package/metadata/MetadataProvider.d.ts +11 -2
  68. package/metadata/MetadataProvider.js +46 -2
  69. package/metadata/MetadataStorage.d.ts +13 -11
  70. package/metadata/MetadataStorage.js +70 -37
  71. package/metadata/MetadataValidator.d.ts +11 -9
  72. package/metadata/MetadataValidator.js +50 -38
  73. package/metadata/discover-entities.d.ts +5 -0
  74. package/metadata/discover-entities.js +40 -0
  75. package/metadata/index.d.ts +1 -1
  76. package/metadata/index.js +1 -1
  77. package/metadata/types.d.ts +480 -0
  78. package/metadata/types.js +1 -0
  79. package/naming-strategy/AbstractNamingStrategy.d.ts +8 -4
  80. package/naming-strategy/AbstractNamingStrategy.js +8 -2
  81. package/naming-strategy/EntityCaseNamingStrategy.d.ts +3 -3
  82. package/naming-strategy/EntityCaseNamingStrategy.js +6 -5
  83. package/naming-strategy/MongoNamingStrategy.d.ts +3 -3
  84. package/naming-strategy/MongoNamingStrategy.js +6 -6
  85. package/naming-strategy/NamingStrategy.d.ts +14 -4
  86. package/naming-strategy/UnderscoreNamingStrategy.d.ts +3 -3
  87. package/naming-strategy/UnderscoreNamingStrategy.js +6 -6
  88. package/not-supported.d.ts +2 -0
  89. package/not-supported.js +4 -0
  90. package/package.json +18 -11
  91. package/platforms/ExceptionConverter.js +1 -1
  92. package/platforms/Platform.d.ts +6 -13
  93. package/platforms/Platform.js +17 -43
  94. package/serialization/EntitySerializer.d.ts +5 -0
  95. package/serialization/EntitySerializer.js +47 -27
  96. package/serialization/EntityTransformer.js +28 -18
  97. package/serialization/SerializationContext.d.ts +6 -6
  98. package/serialization/SerializationContext.js +16 -13
  99. package/types/ArrayType.d.ts +1 -1
  100. package/types/ArrayType.js +2 -3
  101. package/types/BigIntType.d.ts +8 -6
  102. package/types/BigIntType.js +1 -1
  103. package/types/BlobType.d.ts +0 -1
  104. package/types/BlobType.js +0 -3
  105. package/types/BooleanType.d.ts +2 -1
  106. package/types/BooleanType.js +3 -0
  107. package/types/DecimalType.d.ts +6 -4
  108. package/types/DecimalType.js +3 -3
  109. package/types/DoubleType.js +2 -2
  110. package/types/EnumArrayType.js +1 -2
  111. package/types/JsonType.d.ts +1 -1
  112. package/types/JsonType.js +7 -2
  113. package/types/TinyIntType.js +1 -1
  114. package/types/Type.d.ts +2 -4
  115. package/types/Type.js +3 -3
  116. package/types/Uint8ArrayType.d.ts +0 -1
  117. package/types/Uint8ArrayType.js +1 -4
  118. package/types/index.d.ts +1 -1
  119. package/typings.d.ts +158 -113
  120. package/typings.js +55 -42
  121. package/unit-of-work/ChangeSet.d.ts +2 -6
  122. package/unit-of-work/ChangeSet.js +4 -5
  123. package/unit-of-work/ChangeSetComputer.d.ts +1 -3
  124. package/unit-of-work/ChangeSetComputer.js +14 -12
  125. package/unit-of-work/ChangeSetPersister.d.ts +5 -4
  126. package/unit-of-work/ChangeSetPersister.js +70 -34
  127. package/unit-of-work/CommitOrderCalculator.d.ts +12 -10
  128. package/unit-of-work/CommitOrderCalculator.js +13 -13
  129. package/unit-of-work/UnitOfWork.d.ts +10 -3
  130. package/unit-of-work/UnitOfWork.js +141 -98
  131. package/utils/AbstractSchemaGenerator.d.ts +5 -5
  132. package/utils/AbstractSchemaGenerator.js +18 -16
  133. package/utils/AsyncContext.d.ts +6 -0
  134. package/utils/AsyncContext.js +42 -0
  135. package/utils/Configuration.d.ts +754 -207
  136. package/utils/Configuration.js +146 -190
  137. package/utils/ConfigurationLoader.d.ts +1 -54
  138. package/utils/ConfigurationLoader.js +1 -352
  139. package/utils/Cursor.d.ts +0 -3
  140. package/utils/Cursor.js +27 -11
  141. package/utils/DataloaderUtils.d.ts +15 -5
  142. package/utils/DataloaderUtils.js +64 -30
  143. package/utils/EntityComparator.d.ts +13 -9
  144. package/utils/EntityComparator.js +84 -42
  145. package/utils/QueryHelper.d.ts +14 -6
  146. package/utils/QueryHelper.js +87 -25
  147. package/utils/RawQueryFragment.d.ts +48 -25
  148. package/utils/RawQueryFragment.js +66 -70
  149. package/utils/RequestContext.js +2 -2
  150. package/utils/TransactionContext.js +2 -2
  151. package/utils/TransactionManager.d.ts +65 -0
  152. package/utils/TransactionManager.js +223 -0
  153. package/utils/Utils.d.ts +13 -120
  154. package/utils/Utils.js +100 -376
  155. package/utils/clone.js +8 -23
  156. package/utils/env-vars.d.ts +7 -0
  157. package/utils/env-vars.js +97 -0
  158. package/utils/fs-utils.d.ts +32 -0
  159. package/utils/fs-utils.js +178 -0
  160. package/utils/index.d.ts +2 -1
  161. package/utils/index.js +2 -1
  162. package/utils/upsert-utils.d.ts +9 -4
  163. package/utils/upsert-utils.js +55 -4
  164. package/decorators/Check.d.ts +0 -3
  165. package/decorators/Check.js +0 -13
  166. package/decorators/CreateRequestContext.d.ts +0 -3
  167. package/decorators/CreateRequestContext.js +0 -32
  168. package/decorators/Embeddable.d.ts +0 -8
  169. package/decorators/Embeddable.js +0 -11
  170. package/decorators/Embedded.d.ts +0 -12
  171. package/decorators/Embedded.js +0 -18
  172. package/decorators/Entity.d.ts +0 -18
  173. package/decorators/Entity.js +0 -12
  174. package/decorators/Enum.d.ts +0 -9
  175. package/decorators/Enum.js +0 -16
  176. package/decorators/Filter.d.ts +0 -2
  177. package/decorators/Filter.js +0 -8
  178. package/decorators/Formula.d.ts +0 -4
  179. package/decorators/Formula.js +0 -15
  180. package/decorators/Indexed.d.ts +0 -19
  181. package/decorators/Indexed.js +0 -20
  182. package/decorators/ManyToMany.d.ts +0 -40
  183. package/decorators/ManyToMany.js +0 -14
  184. package/decorators/ManyToOne.d.ts +0 -32
  185. package/decorators/ManyToOne.js +0 -14
  186. package/decorators/OneToMany.d.ts +0 -28
  187. package/decorators/OneToMany.js +0 -17
  188. package/decorators/OneToOne.d.ts +0 -26
  189. package/decorators/OneToOne.js +0 -7
  190. package/decorators/PrimaryKey.d.ts +0 -8
  191. package/decorators/PrimaryKey.js +0 -20
  192. package/decorators/Property.d.ts +0 -250
  193. package/decorators/Property.js +0 -32
  194. package/decorators/Transactional.d.ts +0 -13
  195. package/decorators/Transactional.js +0 -28
  196. package/decorators/hooks.d.ts +0 -16
  197. package/decorators/hooks.js +0 -47
  198. package/decorators/index.d.ts +0 -17
  199. package/decorators/index.js +0 -17
  200. package/entity/ArrayCollection.d.ts +0 -116
  201. package/entity/ArrayCollection.js +0 -402
  202. package/entity/EntityValidator.d.ts +0 -19
  203. package/entity/EntityValidator.js +0 -150
  204. package/exports.d.ts +0 -24
  205. package/exports.js +0 -23
  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, NoInfer, 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,13 +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
- private readonly validator;
33
+ private readonly loaders;
37
34
  private readonly repositoryMap;
38
35
  private readonly entityLoader;
39
36
  protected readonly comparator: EntityComparator;
@@ -72,14 +69,28 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
72
69
  * Shortcut for `em.getRepository()`.
73
70
  */
74
71
  repo<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(entityName: EntityName<Entity>): GetRepository<Entity, Repository>;
75
- /**
76
- * Gets EntityValidator instance
77
- */
78
- getValidator(): EntityValidator;
79
72
  /**
80
73
  * Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
81
74
  */
82
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>>;
83
94
  /**
84
95
  * Finds all entities of given type, optionally matching the `where` condition provided in the `options` parameter.
85
96
  */
@@ -88,19 +99,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
88
99
  /**
89
100
  * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
90
101
  */
91
- addFilter<T1>(name: string, cond: FilterQuery<T1> | ((args: Dictionary) => MaybePromise<FilterQuery<T1>>), entityName?: EntityName<T1> | [EntityName<T1>], enabled?: boolean): void;
92
- /**
93
- * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
94
- */
95
- addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | T2> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2>>), entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void;
96
- /**
97
- * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
98
- */
99
- 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;
100
- /**
101
- * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
102
- */
103
- 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;
104
103
  /**
105
104
  * Sets filter parameter values globally inside context defined by this entity manager.
106
105
  * If you want to set shared value for all contexts, be sure to use the root entity manager.
@@ -117,20 +116,25 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
117
116
  /**
118
117
  * Gets logger context for this entity manager.
119
118
  */
120
- getLoggerContext<T extends Dictionary = Dictionary>(): T;
121
- setFlushMode(flushMode?: FlushMode): void;
122
- 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>>;
123
- protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
119
+ getLoggerContext<T extends Dictionary = Dictionary>(options?: {
120
+ disableContextResolution?: boolean;
121
+ }): T;
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>;
124
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>;
125
- 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>;
126
127
  /**
127
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.
128
129
  */
129
- 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>;
130
134
  /**
131
135
  * @internal
132
136
  */
133
- 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>;
134
138
  /**
135
139
  * Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
136
140
  * where the first element is the array of entities, and the second is the count.
@@ -150,21 +154,21 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
150
154
  * - POJO/entity instance
151
155
  *
152
156
  * ```ts
153
- * const currentCursor = await em.findByCursor(User, {}, {
157
+ * const currentCursor = await em.findByCursor(User, {
154
158
  * first: 10,
155
159
  * after: previousCursor, // cursor instance
156
160
  * orderBy: { id: 'desc' },
157
161
  * });
158
162
  *
159
163
  * // to fetch next page
160
- * const nextCursor = await em.findByCursor(User, {}, {
164
+ * const nextCursor = await em.findByCursor(User, {
161
165
  * first: 10,
162
166
  * after: currentCursor.endCursor, // opaque string
163
167
  * orderBy: { id: 'desc' },
164
168
  * });
165
169
  *
166
170
  * // to fetch next page
167
- * const nextCursor2 = await em.findByCursor(User, {}, {
171
+ * const nextCursor2 = await em.findByCursor(User, {
168
172
  * first: 10,
169
173
  * after: { id: lastSeenId }, // entity-like POJO
170
174
  * orderBy: { id: 'desc' },
@@ -192,7 +196,7 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
192
196
  * }
193
197
  * ```
194
198
  */
195
- 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>>;
196
200
  /**
197
201
  * Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
198
202
  * persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
@@ -267,6 +271,29 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
267
271
  upsertMany<Entity extends object, Fields extends string = any>(entityNameOrEntity: EntityName<Entity> | Entity[], data?: (EntityData<Entity> | NoInfer<Entity>)[], options?: UpsertManyOptions<Entity, Fields>): Promise<Entity[]>;
268
272
  /**
269
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
+ * ```
270
297
  */
271
298
  transactional<T>(cb: (em: this) => T | Promise<T>, options?: TransactionOptions): Promise<T>;
272
299
  /**
@@ -384,11 +411,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
384
411
  * The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
385
412
  */
386
413
  persist<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
387
- /**
388
- * Persists your entity immediately, flushing all not yet persisted changes to the database too.
389
- * Equivalent to `em.persist(e).flush()`.
390
- */
391
- persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
392
414
  /**
393
415
  * Marks entity for removal.
394
416
  * A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
@@ -396,11 +418,6 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
396
418
  * To remove entities by condition, use `em.nativeDelete()`.
397
419
  */
398
420
  remove<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
399
- /**
400
- * Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
401
- * Equivalent to `em.remove(e).flush()`
402
- */
403
- removeAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
404
421
  /**
405
422
  * Flushes all changes to objects that have been queued up to now to the database.
406
423
  * This effectively synchronizes the in-memory state of managed objects with the database.
@@ -481,30 +498,31 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
481
498
  private checkLockRequirements;
482
499
  private lockAndPopulate;
483
500
  private buildFields;
484
- private preparePopulate;
501
+ /** @internal */
502
+ preparePopulate<Entity extends object>(entityName: EntityName<Entity>, options: Pick<FindOptions<Entity, any, any>, 'populate' | 'strategy' | 'fields' | 'flags' | 'filters'>, validate?: boolean): Promise<PopulateOptions<Entity>[]>;
485
503
  /**
486
504
  * when the entity is found in identity map, we check if it was partially loaded or we are trying to populate
487
505
  * some additional lazy properties, if so, we reload and merge the data from database
488
506
  */
489
507
  protected shouldRefresh<T extends object, P extends string = never, F extends string = '*', E extends string = never>(meta: EntityMetadata<T>, entity: T, options: FindOneOptions<T, P, F, E>): boolean;
490
- protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): void;
508
+ protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any> | CountOptions<any, any>): void;
491
509
  /**
492
510
  * @internal
493
511
  */
494
- 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[];
512
+ 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[];
495
513
  /**
496
514
  * @internal
497
515
  */
498
- tryCache<T extends object, R>(entityName: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
516
+ tryCache<T extends object, R>(entityName: EntityName<T>, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
499
517
  data?: R | null;
500
518
  key: string;
501
519
  } | undefined>;
502
520
  /**
503
521
  * @internal
504
522
  */
505
- storeCache(config: boolean | number | [string, number] | undefined, key: {
523
+ storeCache<T>(config: boolean | number | [string, number] | undefined, key: {
506
524
  key: string;
507
- }, data: unknown | (() => unknown)): Promise<void>;
525
+ }, data: T | (() => T)): Promise<void>;
508
526
  /**
509
527
  * Clears result cache for given cache key. If we want to be able to call this method,
510
528
  * we need to set the cache key explicitly when storing the cache.
@@ -528,13 +546,13 @@ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDri
528
546
  * if executed inside request context handler.
529
547
  */
530
548
  set schema(schema: string | null | undefined);
549
+ /** @internal */
550
+ getDataLoader(type: 'ref' | '1:m' | 'm:n'): Promise<any>;
531
551
  /**
532
552
  * Returns the ID of this EntityManager. Respects the context, so global EM will give you the contextual ID
533
553
  * if executed inside request context handler.
534
554
  */
535
555
  get id(): number;
536
- /** @ignore */
537
- [inspect.custom](): string;
538
556
  }
539
557
  export interface CreateOptions<Convert extends boolean> {
540
558
  /** creates a managed entity instance instead, bypassing the constructor call */
@@ -547,11 +565,19 @@ export interface CreateOptions<Convert extends boolean> {
547
565
  partial?: boolean;
548
566
  /** convert raw database values based on mapped types (by default, already converted values are expected) */
549
567
  convertCustomTypes?: Convert;
568
+ /**
569
+ * Property `onCreate` hooks are normally executed during `flush` operation.
570
+ * With this option, they will be processed early inside `em.create()` method.
571
+ */
572
+ processOnCreateHooksEarly?: boolean;
550
573
  }
551
574
  export interface MergeOptions {
552
575
  refresh?: boolean;
553
576
  convertCustomTypes?: boolean;
554
577
  schema?: string;
578
+ disableContextResolution?: boolean;
579
+ validate?: boolean;
580
+ cascade?: boolean; /** @default true */
555
581
  }
556
582
  export interface ForkOptions {
557
583
  /** do we want a clear identity map? defaults to true */
@@ -565,7 +591,7 @@ export interface ForkOptions {
565
591
  /** use this flag to ignore the current async context - this is required if we want to call `em.fork()` inside the `getContext` handler */
566
592
  disableContextResolution?: boolean;
567
593
  /** set flush mode for this fork, overrides the global option can be overridden locally via FindOptions */
568
- flushMode?: FlushMode;
594
+ flushMode?: FlushMode | `${FlushMode}`;
569
595
  /** disable transactions for this fork */
570
596
  disableTransactions?: boolean;
571
597
  /** should we keep the transaction context of the parent EM? */