@yandjin-mikro-orm/core 6.1.4-rc-sti-changes-1

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 (264) hide show
  1. package/EntityManager.d.ts +553 -0
  2. package/EntityManager.js +1736 -0
  3. package/LICENSE +21 -0
  4. package/MikroORM.d.ts +102 -0
  5. package/MikroORM.js +258 -0
  6. package/README.md +383 -0
  7. package/cache/CacheAdapter.d.ts +40 -0
  8. package/cache/CacheAdapter.js +2 -0
  9. package/cache/FileCacheAdapter.d.ts +31 -0
  10. package/cache/FileCacheAdapter.js +90 -0
  11. package/cache/GeneratedCacheAdapter.d.ts +25 -0
  12. package/cache/GeneratedCacheAdapter.js +38 -0
  13. package/cache/MemoryCacheAdapter.d.ts +24 -0
  14. package/cache/MemoryCacheAdapter.js +44 -0
  15. package/cache/NullCacheAdapter.d.ts +19 -0
  16. package/cache/NullCacheAdapter.js +30 -0
  17. package/cache/index.d.ts +5 -0
  18. package/cache/index.js +21 -0
  19. package/connections/Connection.d.ts +85 -0
  20. package/connections/Connection.js +128 -0
  21. package/connections/index.d.ts +1 -0
  22. package/connections/index.js +17 -0
  23. package/decorators/Check.d.ts +3 -0
  24. package/decorators/Check.js +17 -0
  25. package/decorators/CreateRequestContext.d.ts +2 -0
  26. package/decorators/CreateRequestContext.js +31 -0
  27. package/decorators/Embeddable.d.ts +8 -0
  28. package/decorators/Embeddable.js +15 -0
  29. package/decorators/Embedded.d.ts +13 -0
  30. package/decorators/Embedded.js +21 -0
  31. package/decorators/EnsureRequestContext.d.ts +2 -0
  32. package/decorators/EnsureRequestContext.js +26 -0
  33. package/decorators/Entity.d.ts +18 -0
  34. package/decorators/Entity.js +17 -0
  35. package/decorators/Enum.d.ts +9 -0
  36. package/decorators/Enum.js +20 -0
  37. package/decorators/Filter.d.ts +2 -0
  38. package/decorators/Filter.js +12 -0
  39. package/decorators/Formula.d.ts +5 -0
  40. package/decorators/Formula.js +19 -0
  41. package/decorators/Indexed.d.ts +12 -0
  42. package/decorators/Indexed.js +25 -0
  43. package/decorators/ManyToMany.d.ts +21 -0
  44. package/decorators/ManyToMany.js +17 -0
  45. package/decorators/ManyToOne.d.ts +15 -0
  46. package/decorators/ManyToOne.js +17 -0
  47. package/decorators/OneToMany.d.ts +18 -0
  48. package/decorators/OneToMany.js +21 -0
  49. package/decorators/OneToOne.d.ts +12 -0
  50. package/decorators/OneToOne.js +11 -0
  51. package/decorators/PrimaryKey.d.ts +8 -0
  52. package/decorators/PrimaryKey.js +24 -0
  53. package/decorators/Property.d.ts +218 -0
  54. package/decorators/Property.js +35 -0
  55. package/decorators/Subscriber.d.ts +1 -0
  56. package/decorators/Subscriber.js +2 -0
  57. package/decorators/hooks.d.ts +16 -0
  58. package/decorators/hooks.js +60 -0
  59. package/decorators/index.d.ts +17 -0
  60. package/decorators/index.js +36 -0
  61. package/drivers/DatabaseDriver.d.ts +72 -0
  62. package/drivers/DatabaseDriver.js +358 -0
  63. package/drivers/IDatabaseDriver.d.ts +193 -0
  64. package/drivers/IDatabaseDriver.js +4 -0
  65. package/drivers/index.d.ts +2 -0
  66. package/drivers/index.js +18 -0
  67. package/entity/ArrayCollection.d.ts +113 -0
  68. package/entity/ArrayCollection.js +386 -0
  69. package/entity/BaseEntity.d.ts +22 -0
  70. package/entity/BaseEntity.js +47 -0
  71. package/entity/Collection.d.ts +104 -0
  72. package/entity/Collection.js +373 -0
  73. package/entity/EntityAssigner.d.ts +28 -0
  74. package/entity/EntityAssigner.js +226 -0
  75. package/entity/EntityFactory.d.ts +41 -0
  76. package/entity/EntityFactory.js +302 -0
  77. package/entity/EntityHelper.d.ts +29 -0
  78. package/entity/EntityHelper.js +250 -0
  79. package/entity/EntityIdentifier.d.ts +10 -0
  80. package/entity/EntityIdentifier.js +19 -0
  81. package/entity/EntityLoader.d.ts +65 -0
  82. package/entity/EntityLoader.js +579 -0
  83. package/entity/EntityRepository.d.ts +161 -0
  84. package/entity/EntityRepository.js +207 -0
  85. package/entity/EntityValidator.d.ts +19 -0
  86. package/entity/EntityValidator.js +152 -0
  87. package/entity/Reference.d.ts +89 -0
  88. package/entity/Reference.js +242 -0
  89. package/entity/WrappedEntity.d.ts +67 -0
  90. package/entity/WrappedEntity.js +146 -0
  91. package/entity/index.d.ts +13 -0
  92. package/entity/index.js +29 -0
  93. package/entity/wrap.d.ts +15 -0
  94. package/entity/wrap.js +26 -0
  95. package/enums.d.ts +160 -0
  96. package/enums.js +169 -0
  97. package/errors.d.ts +65 -0
  98. package/errors.js +222 -0
  99. package/events/EventManager.d.ts +17 -0
  100. package/events/EventManager.js +77 -0
  101. package/events/EventSubscriber.d.ts +39 -0
  102. package/events/EventSubscriber.js +2 -0
  103. package/events/TransactionEventBroadcaster.d.ts +11 -0
  104. package/events/TransactionEventBroadcaster.js +17 -0
  105. package/events/index.d.ts +3 -0
  106. package/events/index.js +19 -0
  107. package/exceptions.d.ts +104 -0
  108. package/exceptions.js +130 -0
  109. package/hydration/Hydrator.d.ts +23 -0
  110. package/hydration/Hydrator.js +51 -0
  111. package/hydration/ObjectHydrator.d.ts +24 -0
  112. package/hydration/ObjectHydrator.js +332 -0
  113. package/hydration/index.d.ts +2 -0
  114. package/hydration/index.js +18 -0
  115. package/index.d.ts +25 -0
  116. package/index.js +50 -0
  117. package/index.mjs +192 -0
  118. package/logging/DefaultLogger.d.ts +32 -0
  119. package/logging/DefaultLogger.js +90 -0
  120. package/logging/Logger.d.ts +56 -0
  121. package/logging/Logger.js +2 -0
  122. package/logging/SimpleLogger.d.ts +17 -0
  123. package/logging/SimpleLogger.js +31 -0
  124. package/logging/colors.d.ts +9 -0
  125. package/logging/colors.js +20 -0
  126. package/logging/index.d.ts +4 -0
  127. package/logging/index.js +20 -0
  128. package/metadata/EntitySchema.d.ts +74 -0
  129. package/metadata/EntitySchema.js +293 -0
  130. package/metadata/MetadataDiscovery.d.ts +71 -0
  131. package/metadata/MetadataDiscovery.js +1244 -0
  132. package/metadata/MetadataProvider.d.ts +11 -0
  133. package/metadata/MetadataProvider.js +23 -0
  134. package/metadata/MetadataStorage.d.ts +22 -0
  135. package/metadata/MetadataStorage.js +87 -0
  136. package/metadata/MetadataValidator.d.ts +24 -0
  137. package/metadata/MetadataValidator.js +213 -0
  138. package/metadata/ReflectMetadataProvider.d.ts +8 -0
  139. package/metadata/ReflectMetadataProvider.js +48 -0
  140. package/metadata/index.d.ts +6 -0
  141. package/metadata/index.js +22 -0
  142. package/naming-strategy/AbstractNamingStrategy.d.ts +18 -0
  143. package/naming-strategy/AbstractNamingStrategy.js +48 -0
  144. package/naming-strategy/EntityCaseNamingStrategy.d.ts +12 -0
  145. package/naming-strategy/EntityCaseNamingStrategy.js +32 -0
  146. package/naming-strategy/MongoNamingStrategy.d.ts +9 -0
  147. package/naming-strategy/MongoNamingStrategy.js +25 -0
  148. package/naming-strategy/NamingStrategy.d.ts +52 -0
  149. package/naming-strategy/NamingStrategy.js +2 -0
  150. package/naming-strategy/UnderscoreNamingStrategy.d.ts +10 -0
  151. package/naming-strategy/UnderscoreNamingStrategy.js +28 -0
  152. package/naming-strategy/index.d.ts +5 -0
  153. package/naming-strategy/index.js +21 -0
  154. package/package.json +70 -0
  155. package/platforms/ExceptionConverter.d.ts +5 -0
  156. package/platforms/ExceptionConverter.js +11 -0
  157. package/platforms/Platform.d.ts +201 -0
  158. package/platforms/Platform.js +452 -0
  159. package/platforms/index.d.ts +2 -0
  160. package/platforms/index.js +18 -0
  161. package/serialization/EntitySerializer.d.ts +34 -0
  162. package/serialization/EntitySerializer.js +206 -0
  163. package/serialization/EntityTransformer.d.ts +8 -0
  164. package/serialization/EntityTransformer.js +192 -0
  165. package/serialization/SerializationContext.d.ts +30 -0
  166. package/serialization/SerializationContext.js +111 -0
  167. package/serialization/index.d.ts +3 -0
  168. package/serialization/index.js +19 -0
  169. package/types/ArrayType.d.ts +13 -0
  170. package/types/ArrayType.js +47 -0
  171. package/types/BigIntType.d.ts +16 -0
  172. package/types/BigIntType.js +45 -0
  173. package/types/BlobType.d.ts +10 -0
  174. package/types/BlobType.js +27 -0
  175. package/types/BooleanType.d.ts +8 -0
  176. package/types/BooleanType.js +16 -0
  177. package/types/DateTimeType.d.ts +8 -0
  178. package/types/DateTimeType.js +16 -0
  179. package/types/DateType.d.ts +8 -0
  180. package/types/DateType.js +16 -0
  181. package/types/DecimalType.d.ts +11 -0
  182. package/types/DecimalType.js +22 -0
  183. package/types/DoubleType.d.ts +11 -0
  184. package/types/DoubleType.js +22 -0
  185. package/types/EnumArrayType.d.ts +9 -0
  186. package/types/EnumArrayType.js +32 -0
  187. package/types/EnumType.d.ts +8 -0
  188. package/types/EnumType.js +16 -0
  189. package/types/FloatType.d.ts +8 -0
  190. package/types/FloatType.js +16 -0
  191. package/types/IntegerType.d.ts +8 -0
  192. package/types/IntegerType.js +16 -0
  193. package/types/IntervalType.d.ts +8 -0
  194. package/types/IntervalType.js +16 -0
  195. package/types/JsonType.d.ts +13 -0
  196. package/types/JsonType.js +34 -0
  197. package/types/MediumIntType.d.ts +6 -0
  198. package/types/MediumIntType.js +10 -0
  199. package/types/SmallIntType.d.ts +8 -0
  200. package/types/SmallIntType.js +16 -0
  201. package/types/StringType.d.ts +8 -0
  202. package/types/StringType.js +16 -0
  203. package/types/TextType.d.ts +8 -0
  204. package/types/TextType.js +16 -0
  205. package/types/TimeType.d.ts +9 -0
  206. package/types/TimeType.js +23 -0
  207. package/types/TinyIntType.d.ts +8 -0
  208. package/types/TinyIntType.js +16 -0
  209. package/types/Type.d.ts +64 -0
  210. package/types/Type.js +84 -0
  211. package/types/Uint8ArrayType.d.ts +11 -0
  212. package/types/Uint8ArrayType.js +37 -0
  213. package/types/UnknownType.d.ts +7 -0
  214. package/types/UnknownType.js +13 -0
  215. package/types/UuidType.d.ts +7 -0
  216. package/types/UuidType.js +13 -0
  217. package/types/index.d.ts +75 -0
  218. package/types/index.js +77 -0
  219. package/typings.d.ts +767 -0
  220. package/typings.js +198 -0
  221. package/unit-of-work/ChangeSet.d.ts +34 -0
  222. package/unit-of-work/ChangeSet.js +62 -0
  223. package/unit-of-work/ChangeSetComputer.d.ts +26 -0
  224. package/unit-of-work/ChangeSetComputer.js +153 -0
  225. package/unit-of-work/ChangeSetPersister.d.ts +50 -0
  226. package/unit-of-work/ChangeSetPersister.js +361 -0
  227. package/unit-of-work/CommitOrderCalculator.d.ts +62 -0
  228. package/unit-of-work/CommitOrderCalculator.js +113 -0
  229. package/unit-of-work/IdentityMap.d.ts +17 -0
  230. package/unit-of-work/IdentityMap.js +84 -0
  231. package/unit-of-work/UnitOfWork.d.ts +124 -0
  232. package/unit-of-work/UnitOfWork.js +1013 -0
  233. package/unit-of-work/index.d.ts +6 -0
  234. package/unit-of-work/index.js +22 -0
  235. package/utils/AbstractSchemaGenerator.d.ts +38 -0
  236. package/utils/AbstractSchemaGenerator.js +101 -0
  237. package/utils/Configuration.d.ts +390 -0
  238. package/utils/Configuration.js +357 -0
  239. package/utils/ConfigurationLoader.d.ts +29 -0
  240. package/utils/ConfigurationLoader.js +282 -0
  241. package/utils/Cursor.d.ts +77 -0
  242. package/utils/Cursor.js +169 -0
  243. package/utils/DataloaderUtils.d.ts +43 -0
  244. package/utils/DataloaderUtils.js +194 -0
  245. package/utils/EntityComparator.d.ts +73 -0
  246. package/utils/EntityComparator.js +568 -0
  247. package/utils/NullHighlighter.d.ts +4 -0
  248. package/utils/NullHighlighter.js +9 -0
  249. package/utils/QueryHelper.d.ts +28 -0
  250. package/utils/QueryHelper.js +228 -0
  251. package/utils/RawQueryFragment.d.ts +96 -0
  252. package/utils/RawQueryFragment.js +188 -0
  253. package/utils/RequestContext.d.ts +34 -0
  254. package/utils/RequestContext.js +54 -0
  255. package/utils/TransactionContext.d.ts +19 -0
  256. package/utils/TransactionContext.js +34 -0
  257. package/utils/Utils.d.ts +274 -0
  258. package/utils/Utils.js +1073 -0
  259. package/utils/clone.d.ts +6 -0
  260. package/utils/clone.js +127 -0
  261. package/utils/index.d.ts +13 -0
  262. package/utils/index.js +29 -0
  263. package/utils/upsert-utils.d.ts +6 -0
  264. package/utils/upsert-utils.js +33 -0
@@ -0,0 +1,553 @@
1
+ /// <reference types="node" />
2
+ import { inspect } from 'util';
3
+ import DataLoader from 'dataloader';
4
+ import { type Configuration, Cursor } from './utils';
5
+ import { type AssignOptions, EntityFactory, type EntityLoaderOptions, type EntityRepository, EntityValidator, Reference } from './entity';
6
+ import { UnitOfWork } from './unit-of-work';
7
+ import type { CountOptions, DeleteOptions, EntityManagerType, FindAllOptions, FindByCursorOptions, FindOneOptions, FindOneOrFailOptions, FindOptions, GetReferenceOptions, IDatabaseDriver, LockOptions, NativeInsertUpdateOptions, UpdateOptions, UpsertManyOptions, UpsertOptions } from './drivers';
8
+ import type { AnyEntity, AnyString, ArrayElement, AutoPath, ConnectionType, Dictionary, EntityData, EntityDictionary, EntityDTO, EntityMetadata, EntityName, FilterQuery, FromEntityType, GetRepository, IHydrator, IsSubset, Loaded, MaybePromise, MergeLoaded, MergeSelected, ObjectQuery, Primary, Ref, RequiredEntityData, UnboxArray } from './typings';
9
+ import { FlushMode, LockMode, type TransactionOptions } from './enums';
10
+ import type { MetadataStorage } from './metadata';
11
+ import type { Transaction } from './connections';
12
+ import { EventManager } from './events';
13
+ import type { EntityComparator } from './utils/EntityComparator';
14
+ /**
15
+ * The EntityManager is the central access point to ORM functionality. It is a facade to all different ORM subsystems
16
+ * such as UnitOfWork, Query Language, and Repository API.
17
+ * @template {IDatabaseDriver} Driver current driver type
18
+ */
19
+ export declare class EntityManager<Driver extends IDatabaseDriver = IDatabaseDriver> {
20
+ readonly config: Configuration;
21
+ protected readonly driver: Driver;
22
+ protected readonly metadata: MetadataStorage;
23
+ protected readonly useContext: boolean;
24
+ protected readonly eventManager: EventManager;
25
+ private static counter;
26
+ readonly _id: number;
27
+ readonly global = false;
28
+ readonly name: string;
29
+ protected readonly refLoader: DataLoader<[Reference<any>, (Omit<import("./entity").LoadReferenceOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [Reference<any>, (Omit<import("./entity").LoadReferenceOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
30
+ protected readonly colLoader: DataLoader<[import("./entity").Collection<any, object>, (Omit<import("./entity").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?], any, [import("./entity").Collection<any, object>, (Omit<import("./entity").InitCollectionOptions<any, any, "*", never>, "dataloader"> | undefined)?]>;
31
+ private readonly validator;
32
+ private readonly repositoryMap;
33
+ private readonly entityLoader;
34
+ protected readonly comparator: EntityComparator;
35
+ private readonly entityFactory;
36
+ private readonly unitOfWork;
37
+ private readonly resultCache;
38
+ private filters;
39
+ private filterParams;
40
+ protected loggerContext?: Dictionary;
41
+ private transactionContext?;
42
+ private disableTransactions;
43
+ private flushMode?;
44
+ private _schema?;
45
+ /**
46
+ * @internal
47
+ */
48
+ constructor(config: Configuration, driver: Driver, metadata: MetadataStorage, useContext?: boolean, eventManager?: EventManager);
49
+ /**
50
+ * Gets the Driver instance used by this EntityManager.
51
+ * Driver is singleton, for one MikroORM instance, only one driver is created.
52
+ */
53
+ getDriver(): Driver;
54
+ /**
55
+ * Gets the Connection instance, by default returns write connection
56
+ */
57
+ getConnection(type?: ConnectionType): ReturnType<Driver['getConnection']>;
58
+ /**
59
+ * Gets the platform instance. Just like the driver, platform is singleton, one for a MikroORM instance.
60
+ */
61
+ getPlatform(): ReturnType<Driver['getPlatform']>;
62
+ /**
63
+ * Gets repository for given entity. You can pass either string name or entity class reference.
64
+ */
65
+ getRepository<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(entityName: EntityName<Entity>): GetRepository<Entity, Repository>;
66
+ /**
67
+ * Shortcut for `em.getRepository()`.
68
+ */
69
+ repo<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(entityName: EntityName<Entity>): GetRepository<Entity, Repository>;
70
+ /**
71
+ * Gets EntityValidator instance
72
+ */
73
+ getValidator(): EntityValidator;
74
+ /**
75
+ * Finds all entities matching your `where` query. You can pass additional options via the `options` parameter.
76
+ */
77
+ find<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>): Promise<Loaded<Entity, Hint, Fields, Excludes>[]>;
78
+ /**
79
+ * Finds all entities of given type, optionally matching the `where` condition provided in the `options` parameter.
80
+ */
81
+ findAll<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, options?: FindAllOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes>[]>;
82
+ private getPopulateWhere;
83
+ /**
84
+ * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
85
+ */
86
+ addFilter<T1>(name: string, cond: FilterQuery<T1> | ((args: Dictionary) => MaybePromise<FilterQuery<T1>>), entityName?: EntityName<T1> | [EntityName<T1>], enabled?: boolean): void;
87
+ /**
88
+ * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
89
+ */
90
+ addFilter<T1, T2>(name: string, cond: FilterQuery<T1 | T2> | ((args: Dictionary) => MaybePromise<FilterQuery<T1 | T2>>), entityName?: [EntityName<T1>, EntityName<T2>], enabled?: boolean): void;
91
+ /**
92
+ * Registers global filter to this entity manager. Global filters are enabled by default (unless disabled via last parameter).
93
+ */
94
+ 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;
95
+ /**
96
+ * Sets filter parameter values globally inside context defined by this entity manager.
97
+ * If you want to set shared value for all contexts, be sure to use the root entity manager.
98
+ */
99
+ setFilterParams(name: string, args: Dictionary): void;
100
+ /**
101
+ * Returns filter parameters for given filter set in this context.
102
+ */
103
+ getFilterParams<T extends Dictionary = Dictionary>(name: string): T;
104
+ /**
105
+ * Sets logger context for this entity manager.
106
+ */
107
+ setLoggerContext(context: Dictionary): void;
108
+ /**
109
+ * Gets logger context for this entity manager.
110
+ */
111
+ getLoggerContext<T extends Dictionary = Dictionary>(): T;
112
+ setFlushMode(flushMode?: FlushMode): void;
113
+ 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>>;
114
+ protected applyDiscriminatorCondition<Entity extends object>(entityName: string, where: FilterQuery<Entity>): FilterQuery<Entity>;
115
+ protected applyJoinedFilters<Entity extends object>(meta: EntityMetadata<Entity>, cond: ObjectQuery<Entity>, options: FindOptions<Entity, any, any, any> | FindOneOptions<Entity, any, any, any>): Promise<ObjectQuery<Entity>>;
116
+ /**
117
+ * 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.
118
+ */
119
+ protected autoJoinRefsForFilters<T extends object>(meta: EntityMetadata<T>, options: FindOptions<T, any, any, any> | FindOneOptions<T, any, any, any>): Promise<void>;
120
+ /**
121
+ * @internal
122
+ */
123
+ 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>;
124
+ /**
125
+ * Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as tuple
126
+ * where the first element is the array of entities, and the second is the count.
127
+ */
128
+ findAndCount<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>): Promise<[Loaded<Entity, Hint, Fields, Excludes>[], number]>;
129
+ /**
130
+ * Calls `em.find()` and `em.count()` with the same arguments (where applicable) and returns the results as {@apilink Cursor} object.
131
+ * Supports `before`, `after`, `first` and `last` options while disallowing `limit` and `offset`. Explicit `orderBy` option
132
+ * is required.
133
+ *
134
+ * Use `first` and `after` for forward pagination, or `last` and `before` for backward pagination.
135
+ *
136
+ * - `first` and `last` are numbers and serve as an alternative to `offset`, those options are mutually exclusive, use only one at a time
137
+ * - `before` and `after` specify the previous cursor value, it can be one of the:
138
+ * - `Cursor` instance
139
+ * - opaque string provided by `startCursor/endCursor` properties
140
+ * - POJO/entity instance
141
+ *
142
+ * ```ts
143
+ * const currentCursor = await em.findByCursor(User, {}, {
144
+ * first: 10,
145
+ * after: previousCursor, // cursor instance
146
+ * orderBy: { id: 'desc' },
147
+ * });
148
+ *
149
+ * // to fetch next page
150
+ * const nextCursor = await em.findByCursor(User, {}, {
151
+ * first: 10,
152
+ * after: currentCursor.endCursor, // opaque string
153
+ * orderBy: { id: 'desc' },
154
+ * });
155
+ *
156
+ * // to fetch next page
157
+ * const nextCursor2 = await em.findByCursor(User, {}, {
158
+ * first: 10,
159
+ * after: { id: lastSeenId }, // entity-like POJO
160
+ * orderBy: { id: 'desc' },
161
+ * });
162
+ * ```
163
+ *
164
+ * The `Cursor` object provides the following interface:
165
+ *
166
+ * ```ts
167
+ * Cursor<User> {
168
+ * items: [
169
+ * User { ... },
170
+ * User { ... },
171
+ * User { ... },
172
+ * ],
173
+ * totalCount: 50,
174
+ * startCursor: 'WzRd',
175
+ * endCursor: 'WzZd',
176
+ * hasPrevPage: true,
177
+ * hasNextPage: true,
178
+ * }
179
+ * ```
180
+ */
181
+ findByCursor<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, options: FindByCursorOptions<Entity, Hint, Fields, Excludes>): Promise<Cursor<Entity, Hint, Fields, Excludes>>;
182
+ /**
183
+ * Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
184
+ * persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
185
+ * in database, the method throws an error just like `em.findOneOrFail()` (and respects the same config options).
186
+ */
187
+ refreshOrFail<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entity: Entity, options?: FindOneOrFailOptions<Entity, Hint, Fields, Excludes>): Promise<MergeLoaded<Entity, Naked, Hint, Fields, Excludes, true>>;
188
+ /**
189
+ * Refreshes the persistent state of an entity from the database, overriding any local changes that have not yet been
190
+ * persisted. Returns the same entity instance (same object reference), but re-hydrated. If the entity is no longer
191
+ * in database, the method returns `null`.
192
+ */
193
+ refresh<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entity: Entity, options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<MergeLoaded<Entity, Naked, Hint, Fields, Excludes, true> | null>;
194
+ /**
195
+ * Finds first entity matching your `where` query.
196
+ */
197
+ findOne<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, options?: FindOneOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes> | null>;
198
+ /**
199
+ * Finds first entity matching your `where` query. If nothing found, it will throw an error.
200
+ * If the `strict` option is specified and nothing is found or more than one matching entity is found, it will throw an error.
201
+ * You can override the factory for creating this method via `options.failHandler` locally
202
+ * or via `Configuration.findOneOrFailHandler` (`findExactlyOneOrFailHandler` when specifying `strict`) globally.
203
+ */
204
+ findOneOrFail<Entity extends object, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, options?: FindOneOrFailOptions<Entity, Hint, Fields, Excludes>): Promise<Loaded<Entity, Hint, Fields, Excludes>>;
205
+ /**
206
+ * Creates or updates the entity, based on whether it is already present in the database.
207
+ * This method performs an `insert on conflict merge` query ensuring the database is in sync, returning a managed
208
+ * entity instance. The method accepts either `entityName` together with the entity `data`, or just entity instance.
209
+ *
210
+ * ```ts
211
+ * // insert into "author" ("age", "email") values (33, 'foo@bar.com') on conflict ("email") do update set "age" = 41
212
+ * const author = await em.upsert(Author, { email: 'foo@bar.com', age: 33 });
213
+ * ```
214
+ *
215
+ * The entity data needs to contain either the primary key, or any other unique property. Let's consider the following example, where `Author.email` is a unique property:
216
+ *
217
+ * ```ts
218
+ * // insert into "author" ("age", "email") values (33, 'foo@bar.com') on conflict ("email") do update set "age" = 41
219
+ * // select "id" from "author" where "email" = 'foo@bar.com'
220
+ * const author = await em.upsert(Author, { email: 'foo@bar.com', age: 33 });
221
+ * ```
222
+ *
223
+ * Depending on the driver support, this will either use a returning query, or a separate select query, to fetch the primary key if it's missing from the `data`.
224
+ *
225
+ * If the entity is already present in current context, there won't be any queries - instead, the entity data will be assigned and an explicit `flush` will be required for those changes to be persisted.
226
+ */
227
+ upsert<Entity extends object>(entityNameOrEntity: EntityName<Entity> | Entity, data?: EntityData<Entity> | Entity, options?: UpsertOptions<Entity>): Promise<Entity>;
228
+ /**
229
+ * Creates or updates the entity, based on whether it is already present in the database.
230
+ * This method performs an `insert on conflict merge` query ensuring the database is in sync, returning a managed
231
+ * entity instance. The method accepts either `entityName` together with the entity `data`, or just entity instance.
232
+ *
233
+ * ```ts
234
+ * // insert into "author" ("age", "email") values (33, 'foo@bar.com') on conflict ("email") do update set "age" = 41
235
+ * const authors = await em.upsertMany(Author, [{ email: 'foo@bar.com', age: 33 }, ...]);
236
+ * ```
237
+ *
238
+ * The entity data needs to contain either the primary key, or any other unique property. Let's consider the following example, where `Author.email` is a unique property:
239
+ *
240
+ * ```ts
241
+ * // insert into "author" ("age", "email") values (33, 'foo@bar.com'), (666, 'lol@lol.lol') on conflict ("email") do update set "age" = excluded."age"
242
+ * // select "id" from "author" where "email" = 'foo@bar.com'
243
+ * const author = await em.upsertMany(Author, [
244
+ * { email: 'foo@bar.com', age: 33 },
245
+ * { email: 'lol@lol.lol', age: 666 },
246
+ * ]);
247
+ * ```
248
+ *
249
+ * Depending on the driver support, this will either use a returning query, or a separate select query, to fetch the primary key if it's missing from the `data`.
250
+ *
251
+ * If the entity is already present in current context, there won't be any queries - instead, the entity data will be assigned and an explicit `flush` will be required for those changes to be persisted.
252
+ */
253
+ upsertMany<Entity extends object>(entityNameOrEntity: EntityName<Entity> | Entity[], data?: (EntityData<Entity> | Entity)[], options?: UpsertManyOptions<Entity>): Promise<Entity[]>;
254
+ /**
255
+ * Runs your callback wrapped inside a database transaction.
256
+ */
257
+ transactional<T>(cb: (em: Driver[typeof EntityManagerType]) => Promise<T>, options?: TransactionOptions): Promise<T>;
258
+ /**
259
+ * Starts new transaction bound to this EntityManager. Use `ctx` parameter to provide the parent when nesting transactions.
260
+ */
261
+ begin(options?: Omit<TransactionOptions, 'ignoreNestedTransactions'>): Promise<void>;
262
+ /**
263
+ * Commits the transaction bound to this EntityManager. Flushes before doing the actual commit query.
264
+ */
265
+ commit(): Promise<void>;
266
+ /**
267
+ * Rollbacks the transaction bound to this EntityManager.
268
+ */
269
+ rollback(): Promise<void>;
270
+ /**
271
+ * Runs your callback wrapped inside a database transaction.
272
+ */
273
+ lock<T extends object>(entity: T, lockMode: LockMode, options?: LockOptions | number | Date): Promise<void>;
274
+ /**
275
+ * Fires native insert query. Calling this has no side effects on the context (identity map).
276
+ */
277
+ insert<Entity extends object>(entityNameOrEntity: EntityName<Entity> | Entity, data?: RequiredEntityData<Entity> | Entity, options?: NativeInsertUpdateOptions<Entity>): Promise<Primary<Entity>>;
278
+ /**
279
+ * Fires native multi-insert query. Calling this has no side effects on the context (identity map).
280
+ */
281
+ insertMany<Entity extends object>(entityNameOrEntities: EntityName<Entity> | Entity[], data?: RequiredEntityData<Entity>[] | Entity[], options?: NativeInsertUpdateOptions<Entity>): Promise<Primary<Entity>[]>;
282
+ /**
283
+ * Fires native update query. Calling this has no side effects on the context (identity map).
284
+ */
285
+ nativeUpdate<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, data: EntityData<Entity>, options?: UpdateOptions<Entity>): Promise<number>;
286
+ /**
287
+ * Fires native delete query. Calling this has no side effects on the context (identity map).
288
+ */
289
+ nativeDelete<Entity extends object>(entityName: EntityName<Entity>, where: FilterQuery<Entity>, options?: DeleteOptions<Entity>): Promise<number>;
290
+ /**
291
+ * Maps raw database result to an entity and merges it to this EntityManager.
292
+ */
293
+ map<Entity extends object>(entityName: EntityName<Entity>, result: EntityDictionary<Entity>, options?: {
294
+ schema?: string;
295
+ }): Entity;
296
+ /**
297
+ * Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities
298
+ * via second parameter. By default, it will return already loaded entities without modifying them.
299
+ */
300
+ merge<Entity extends object>(entity: Entity, options?: MergeOptions): Entity;
301
+ /**
302
+ * Merges given entity to this EntityManager so it becomes managed. You can force refreshing of existing entities
303
+ * via second parameter. By default, it will return already loaded entities without modifying them.
304
+ */
305
+ merge<Entity extends object>(entityName: EntityName<Entity>, data: EntityData<Entity> | EntityDTO<Entity>, options?: MergeOptions): Entity;
306
+ /**
307
+ * Creates new instance of given entity and populates it with given data.
308
+ * The entity constructor will be used unless you provide `{ managed: true }` in the options parameter.
309
+ * The constructor will be given parameters based on the defined constructor of the entity. If the constructor
310
+ * parameter matches a property name, its value will be extracted from `data`. If no matching property exists,
311
+ * the whole `data` parameter will be passed. This means we can also define `constructor(data: Partial<T>)` and
312
+ * `em.create()` will pass the data into it (unless we have a property named `data` too).
313
+ *
314
+ * The parameters are strictly checked, you need to provide all required properties. You can use `OptionalProps`
315
+ * symbol to omit some properties from this check without making them optional. Alternatively, use `partial: true`
316
+ * in the options to disable the strict checks for required properties. This option has no effect on runtime.
317
+ */
318
+ create<Entity extends object>(entityName: EntityName<Entity>, data: RequiredEntityData<Entity>, options?: CreateOptions): Entity;
319
+ /**
320
+ * Creates new instance of given entity and populates it with given data.
321
+ * The entity constructor will be used unless you provide `{ managed: true }` in the options parameter.
322
+ * The constructor will be given parameters based on the defined constructor of the entity. If the constructor
323
+ * parameter matches a property name, its value will be extracted from `data`. If no matching property exists,
324
+ * the whole `data` parameter will be passed. This means we can also define `constructor(data: Partial<T>)` and
325
+ * `em.create()` will pass the data into it (unless we have a property named `data` too).
326
+ *
327
+ * The parameters are strictly checked, you need to provide all required properties. You can use `OptionalProps`
328
+ * symbol to omit some properties from this check without making them optional. Alternatively, use `partial: true`
329
+ * in the options to disable the strict checks for required properties. This option has no effect on runtime.
330
+ */
331
+ create<Entity extends object>(entityName: EntityName<Entity>, data: EntityData<Entity>, options: CreateOptions & {
332
+ partial: true;
333
+ }): Entity;
334
+ /**
335
+ * Shortcut for `wrap(entity).assign(data, { em })`
336
+ */
337
+ assign<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Data extends EntityData<Naked> | Partial<EntityDTO<Naked>> = EntityData<Naked> | Partial<EntityDTO<Naked>>>(entity: Entity | Partial<Entity>, data: Data & IsSubset<EntityData<Naked>, Data>, options?: AssignOptions): MergeSelected<Entity, Naked, keyof Data & string>;
338
+ /**
339
+ * Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
340
+ */
341
+ getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
342
+ wrapped: true;
343
+ }): Ref<Entity>;
344
+ /**
345
+ * Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
346
+ */
347
+ getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity> | Primary<Entity>[]): Entity;
348
+ /**
349
+ * Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
350
+ */
351
+ getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options: Omit<GetReferenceOptions, 'wrapped'> & {
352
+ wrapped: false;
353
+ }): Entity;
354
+ /**
355
+ * Gets a reference to the entity identified by the given type and identifier without actually loading it, if the entity is not yet loaded
356
+ */
357
+ getReference<Entity extends object>(entityName: EntityName<Entity>, id: Primary<Entity>, options?: GetReferenceOptions): Entity | Reference<Entity>;
358
+ /**
359
+ * Returns total number of entities matching your `where` query.
360
+ */
361
+ count<Entity extends object, Hint extends string = never>(entityName: EntityName<Entity>, where?: FilterQuery<Entity>, options?: CountOptions<Entity, Hint>): Promise<number>;
362
+ /**
363
+ * Tells the EntityManager to make an instance managed and persistent.
364
+ * The entity will be entered into the database at or before transaction commit or as a result of the flush operation.
365
+ */
366
+ persist<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
367
+ /**
368
+ * Persists your entity immediately, flushing all not yet persisted changes to the database too.
369
+ * Equivalent to `em.persist(e).flush()`.
370
+ */
371
+ persistAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
372
+ /**
373
+ * Marks entity for removal.
374
+ * A removed entity will be removed from the database at or before transaction commit or as a result of the flush operation.
375
+ *
376
+ * To remove entities by condition, use `em.nativeDelete()`.
377
+ */
378
+ remove<Entity extends object>(entity: Entity | Reference<Entity> | Iterable<Entity | Reference<Entity>>): this;
379
+ /**
380
+ * Removes an entity instance immediately, flushing all not yet persisted changes to the database too.
381
+ * Equivalent to `em.remove(e).flush()`
382
+ */
383
+ removeAndFlush(entity: AnyEntity | Reference<AnyEntity> | Iterable<AnyEntity | Reference<AnyEntity>>): Promise<void>;
384
+ /**
385
+ * Flushes all changes to objects that have been queued up to now to the database.
386
+ * This effectively synchronizes the in-memory state of managed objects with the database.
387
+ */
388
+ flush(): Promise<void>;
389
+ /**
390
+ * @internal
391
+ */
392
+ tryFlush<Entity extends object>(entityName: EntityName<Entity>, options: {
393
+ flushMode?: FlushMode | AnyString;
394
+ }): Promise<void>;
395
+ /**
396
+ * Clears the EntityManager. All entities that are currently managed by this EntityManager become detached.
397
+ */
398
+ clear(): void;
399
+ /**
400
+ * Checks whether given property can be populated on the entity.
401
+ */
402
+ canPopulate<Entity extends object>(entityName: EntityName<Entity>, property: string): boolean;
403
+ /**
404
+ * Loads specified relations in batch. This will execute one query for each relation, that will populate it on all the specified entities.
405
+ */
406
+ populate<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Hint extends string = never, Fields extends string = '*', Excludes extends string = never>(entities: Entity, populate: AutoPath<UnboxArray<Entity>, Hint, '*'>[] | false, options?: EntityLoaderOptions<UnboxArray<Entity>, Fields, Excludes>): Promise<Entity extends object[] ? MergeLoaded<ArrayElement<Entity>, Naked, Hint, Fields, Excludes>[] : MergeLoaded<Entity, Naked, Hint, Fields, Excludes>>;
407
+ /**
408
+ * Returns new EntityManager instance with its own identity map
409
+ */
410
+ fork(options?: ForkOptions): Driver[typeof EntityManagerType];
411
+ /**
412
+ * Gets the UnitOfWork used by the EntityManager to coordinate operations.
413
+ */
414
+ getUnitOfWork(useContext?: boolean): UnitOfWork;
415
+ /**
416
+ * Gets the EntityFactory used by the EntityManager.
417
+ */
418
+ getEntityFactory(): EntityFactory;
419
+ /**
420
+ * Gets the Hydrator used by the EntityManager.
421
+ */
422
+ getHydrator(): IHydrator;
423
+ /**
424
+ * Gets the EntityManager based on current transaction/request context.
425
+ * @internal
426
+ */
427
+ getContext(validate?: boolean): this;
428
+ getEventManager(): EventManager;
429
+ /**
430
+ * Checks whether this EntityManager is currently operating inside a database transaction.
431
+ */
432
+ isInTransaction(): boolean;
433
+ /**
434
+ * Gets the transaction context (driver dependent object used to make sure queries are executed on same connection).
435
+ */
436
+ getTransactionContext<T extends Transaction = Transaction>(): T | undefined;
437
+ /**
438
+ * Sets the transaction context.
439
+ */
440
+ setTransactionContext(ctx: Transaction): void;
441
+ /**
442
+ * Resets the transaction context.
443
+ */
444
+ resetTransactionContext(): void;
445
+ /**
446
+ * Gets the `MetadataStorage`.
447
+ */
448
+ getMetadata(): MetadataStorage;
449
+ /**
450
+ * Gets the `EntityMetadata` instance when provided with the `entityName` parameter.
451
+ */
452
+ getMetadata<Entity extends object>(entityName: EntityName<Entity>): EntityMetadata<Entity>;
453
+ /**
454
+ * Gets the EntityComparator.
455
+ */
456
+ getComparator(): EntityComparator;
457
+ private checkLockRequirements;
458
+ private lockAndPopulate;
459
+ private buildFields;
460
+ private preparePopulate;
461
+ /**
462
+ * returns all the EntityMetadata that extends the passed EntityMetadata in the context of single table inheritance
463
+ */
464
+ getSTIExtendingMetadata<T>(meta: EntityMetadata<T>, metadata?: EntityMetadata[]): EntityMetadata[];
465
+ /**
466
+ * when the entity is found in identity map, we check if it was partially loaded or we are trying to populate
467
+ * some additional lazy properties, if so, we reload and merge the data from database
468
+ */
469
+ 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;
470
+ protected prepareOptions(options: FindOptions<any, any, any, any> | FindOneOptions<any, any, any, any>): void;
471
+ /**
472
+ * @internal
473
+ */
474
+ 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[];
475
+ /**
476
+ * @internal
477
+ */
478
+ tryCache<T extends object, R>(entityName: string, config: boolean | number | [string, number] | undefined, key: unknown, refresh?: boolean, merge?: boolean): Promise<{
479
+ data?: R;
480
+ key: string;
481
+ } | undefined>;
482
+ /**
483
+ * @internal
484
+ */
485
+ storeCache(config: boolean | number | [string, number] | undefined, key: {
486
+ key: string;
487
+ }, data: unknown | (() => unknown)): Promise<void>;
488
+ /**
489
+ * Clears result cache for given cache key. If we want to be able to call this method,
490
+ * we need to set the cache key explicitly when storing the cache.
491
+ *
492
+ * ```ts
493
+ * // set the cache key to 'book-cache-key', with expiration of 60s
494
+ * const res = await em.find(Book, { ... }, { cache: ['book-cache-key', 60_000] });
495
+ *
496
+ * // clear the cache key by name
497
+ * await em.clearCache('book-cache-key');
498
+ * ```
499
+ */
500
+ clearCache(cacheKey: string): Promise<void>;
501
+ /**
502
+ * Returns the default schema of this EntityManager. Respects the context, so global EM will give you the contextual schema
503
+ * if executed inside request context handler.
504
+ */
505
+ get schema(): string | undefined;
506
+ /**
507
+ * Sets the default schema of this EntityManager. Respects the context, so global EM will set the contextual schema
508
+ * if executed inside request context handler.
509
+ */
510
+ set schema(schema: string | null | undefined);
511
+ /**
512
+ * Returns the ID of this EntityManager. Respects the context, so global EM will give you the contextual ID
513
+ * if executed inside request context handler.
514
+ */
515
+ get id(): number;
516
+ /** @ignore */
517
+ [inspect.custom](): string;
518
+ }
519
+ export interface CreateOptions {
520
+ /** creates a managed entity instance instead, bypassing the constructor call */
521
+ managed?: boolean;
522
+ /** create entity in a specific schema - alternatively, use `wrap(entity).setSchema()` */
523
+ schema?: string;
524
+ /** persist the entity automatically - this is the default behavior and is also configurable globally via `persistOnCreate` option */
525
+ persist?: boolean;
526
+ /** this option disables the strict typing which requires all mandatory properties to have value, it has no effect on runtime */
527
+ partial?: boolean;
528
+ }
529
+ export interface MergeOptions {
530
+ refresh?: boolean;
531
+ convertCustomTypes?: boolean;
532
+ schema?: string;
533
+ }
534
+ export interface ForkOptions {
535
+ /** do we want a clear identity map? defaults to true */
536
+ clear?: boolean;
537
+ /** use request context? should be used only for top level request scope EM, defaults to false */
538
+ useContext?: boolean;
539
+ /** do we want to use fresh EventManager instance? defaults to false (global instance) */
540
+ freshEventManager?: boolean;
541
+ /** do we want to clone current EventManager instance? defaults to false (global instance) */
542
+ cloneEventManager?: boolean;
543
+ /** use this flag to ignore the current async context - this is required if we want to call `em.fork()` inside the `getContext` handler */
544
+ disableContextResolution?: boolean;
545
+ /** set flush mode for this fork, overrides the global option can be overridden locally via FindOptions */
546
+ flushMode?: FlushMode;
547
+ /** disable transactions for this fork */
548
+ disableTransactions?: boolean;
549
+ /** default schema to use for this fork */
550
+ schema?: string;
551
+ /** default logger context, can be overridden via {@apilink FindOptions} */
552
+ loggerContext?: Dictionary;
553
+ }