@mikro-orm/core 7.0.0-dev.1 → 7.0.0-dev.100

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 (281) hide show
  1. package/EntityManager.d.ts +96 -58
  2. package/EntityManager.js +465 -395
  3. package/MikroORM.d.ts +45 -35
  4. package/MikroORM.js +109 -160
  5. package/README.md +3 -2
  6. package/cache/CacheAdapter.js +1 -2
  7. package/cache/FileCacheAdapter.d.ts +2 -2
  8. package/cache/FileCacheAdapter.js +20 -27
  9. package/cache/GeneratedCacheAdapter.d.ts +2 -3
  10. package/cache/GeneratedCacheAdapter.js +1 -7
  11. package/cache/MemoryCacheAdapter.d.ts +1 -1
  12. package/cache/MemoryCacheAdapter.js +1 -5
  13. package/cache/NullCacheAdapter.d.ts +1 -1
  14. package/cache/NullCacheAdapter.js +1 -5
  15. package/cache/index.d.ts +4 -5
  16. package/cache/index.js +4 -21
  17. package/connections/Connection.d.ts +22 -14
  18. package/connections/Connection.js +27 -23
  19. package/connections/index.d.ts +1 -1
  20. package/connections/index.js +1 -17
  21. package/drivers/DatabaseDriver.d.ts +25 -15
  22. package/drivers/DatabaseDriver.js +77 -64
  23. package/drivers/IDatabaseDriver.d.ts +40 -16
  24. package/drivers/IDatabaseDriver.js +1 -4
  25. package/drivers/index.d.ts +2 -2
  26. package/drivers/index.js +2 -18
  27. package/entity/BaseEntity.d.ts +6 -7
  28. package/entity/BaseEntity.js +16 -23
  29. package/entity/Collection.d.ts +98 -34
  30. package/entity/Collection.js +466 -131
  31. package/entity/EntityAssigner.d.ts +3 -3
  32. package/entity/EntityAssigner.js +67 -64
  33. package/entity/EntityFactory.d.ts +10 -3
  34. package/entity/EntityFactory.js +112 -91
  35. package/entity/EntityHelper.d.ts +2 -2
  36. package/entity/EntityHelper.js +66 -53
  37. package/entity/EntityIdentifier.d.ts +1 -1
  38. package/entity/EntityIdentifier.js +1 -5
  39. package/entity/EntityLoader.d.ts +8 -7
  40. package/entity/EntityLoader.js +161 -128
  41. package/entity/EntityRepository.d.ts +8 -8
  42. package/entity/EntityRepository.js +7 -11
  43. package/entity/Reference.d.ts +10 -13
  44. package/entity/Reference.js +64 -46
  45. package/entity/WrappedEntity.d.ts +12 -17
  46. package/entity/WrappedEntity.js +22 -31
  47. package/entity/defineEntity.d.ts +568 -0
  48. package/entity/defineEntity.js +529 -0
  49. package/entity/index.d.ts +14 -13
  50. package/entity/index.js +14 -29
  51. package/entity/utils.d.ts +8 -1
  52. package/entity/utils.js +22 -13
  53. package/entity/validators.d.ts +11 -0
  54. package/entity/validators.js +65 -0
  55. package/entity/wrap.d.ts +1 -1
  56. package/entity/wrap.js +2 -6
  57. package/enums.d.ts +24 -9
  58. package/enums.js +50 -41
  59. package/errors.d.ts +11 -3
  60. package/errors.js +42 -32
  61. package/events/EventManager.d.ts +5 -4
  62. package/events/EventManager.js +26 -22
  63. package/events/EventSubscriber.d.ts +8 -5
  64. package/events/EventSubscriber.js +1 -2
  65. package/events/TransactionEventBroadcaster.d.ts +3 -3
  66. package/events/TransactionEventBroadcaster.js +1 -5
  67. package/events/index.d.ts +3 -3
  68. package/events/index.js +3 -19
  69. package/exceptions.js +18 -39
  70. package/hydration/Hydrator.d.ts +5 -5
  71. package/hydration/Hydrator.js +2 -6
  72. package/hydration/ObjectHydrator.d.ts +7 -7
  73. package/hydration/ObjectHydrator.js +58 -50
  74. package/hydration/index.d.ts +2 -2
  75. package/hydration/index.js +2 -18
  76. package/index.d.ts +21 -21
  77. package/index.js +20 -46
  78. package/logging/DefaultLogger.d.ts +2 -2
  79. package/logging/DefaultLogger.js +10 -13
  80. package/logging/Logger.d.ts +1 -1
  81. package/logging/Logger.js +1 -2
  82. package/logging/SimpleLogger.d.ts +3 -3
  83. package/logging/SimpleLogger.js +2 -6
  84. package/logging/colors.js +1 -5
  85. package/logging/index.d.ts +5 -4
  86. package/logging/index.js +5 -20
  87. package/logging/inspect.d.ts +2 -0
  88. package/logging/inspect.js +16 -0
  89. package/metadata/EntitySchema.d.ts +14 -10
  90. package/metadata/EntitySchema.js +78 -64
  91. package/metadata/MetadataDiscovery.d.ts +11 -14
  92. package/metadata/MetadataDiscovery.js +278 -317
  93. package/metadata/MetadataProvider.d.ts +13 -4
  94. package/metadata/MetadataProvider.js +47 -8
  95. package/metadata/MetadataStorage.d.ts +2 -7
  96. package/metadata/MetadataStorage.js +19 -35
  97. package/metadata/MetadataValidator.d.ts +3 -10
  98. package/metadata/MetadataValidator.js +51 -64
  99. package/metadata/discover-entities.d.ts +5 -0
  100. package/metadata/discover-entities.js +40 -0
  101. package/metadata/index.d.ts +6 -6
  102. package/metadata/index.js +6 -22
  103. package/metadata/types.d.ts +480 -0
  104. package/metadata/types.js +1 -0
  105. package/naming-strategy/AbstractNamingStrategy.d.ts +7 -3
  106. package/naming-strategy/AbstractNamingStrategy.js +11 -9
  107. package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
  108. package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
  109. package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
  110. package/naming-strategy/MongoNamingStrategy.js +2 -6
  111. package/naming-strategy/NamingStrategy.d.ts +12 -2
  112. package/naming-strategy/NamingStrategy.js +1 -2
  113. package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
  114. package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
  115. package/naming-strategy/index.d.ts +5 -5
  116. package/naming-strategy/index.js +5 -21
  117. package/not-supported.d.ts +2 -0
  118. package/not-supported.js +4 -0
  119. package/package.json +19 -20
  120. package/platforms/ExceptionConverter.d.ts +2 -2
  121. package/platforms/ExceptionConverter.js +4 -8
  122. package/platforms/Platform.d.ts +15 -22
  123. package/platforms/Platform.js +58 -88
  124. package/platforms/index.d.ts +2 -2
  125. package/platforms/index.js +2 -18
  126. package/serialization/EntitySerializer.d.ts +4 -2
  127. package/serialization/EntitySerializer.js +64 -51
  128. package/serialization/EntityTransformer.d.ts +1 -1
  129. package/serialization/EntityTransformer.js +48 -42
  130. package/serialization/SerializationContext.d.ts +2 -2
  131. package/serialization/SerializationContext.js +24 -25
  132. package/serialization/index.d.ts +3 -3
  133. package/serialization/index.js +3 -19
  134. package/types/ArrayType.d.ts +3 -3
  135. package/types/ArrayType.js +6 -11
  136. package/types/BigIntType.d.ts +12 -9
  137. package/types/BigIntType.js +6 -6
  138. package/types/BlobType.d.ts +3 -4
  139. package/types/BlobType.js +2 -11
  140. package/types/BooleanType.d.ts +5 -4
  141. package/types/BooleanType.js +5 -6
  142. package/types/CharacterType.d.ts +3 -3
  143. package/types/CharacterType.js +2 -6
  144. package/types/DateTimeType.d.ts +3 -3
  145. package/types/DateTimeType.js +2 -6
  146. package/types/DateType.d.ts +3 -3
  147. package/types/DateType.js +2 -6
  148. package/types/DecimalType.d.ts +9 -7
  149. package/types/DecimalType.js +5 -8
  150. package/types/DoubleType.d.ts +3 -3
  151. package/types/DoubleType.js +4 -7
  152. package/types/EnumArrayType.d.ts +4 -4
  153. package/types/EnumArrayType.js +4 -10
  154. package/types/EnumType.d.ts +3 -3
  155. package/types/EnumType.js +2 -6
  156. package/types/FloatType.d.ts +3 -3
  157. package/types/FloatType.js +2 -6
  158. package/types/IntegerType.d.ts +3 -3
  159. package/types/IntegerType.js +2 -6
  160. package/types/IntervalType.d.ts +3 -3
  161. package/types/IntervalType.js +2 -6
  162. package/types/JsonType.d.ts +4 -4
  163. package/types/JsonType.js +9 -8
  164. package/types/MediumIntType.d.ts +3 -3
  165. package/types/MediumIntType.js +2 -6
  166. package/types/SmallIntType.d.ts +3 -3
  167. package/types/SmallIntType.js +2 -6
  168. package/types/StringType.d.ts +3 -3
  169. package/types/StringType.js +2 -6
  170. package/types/TextType.d.ts +3 -3
  171. package/types/TextType.js +2 -6
  172. package/types/TimeType.d.ts +3 -3
  173. package/types/TimeType.js +4 -8
  174. package/types/TinyIntType.d.ts +3 -3
  175. package/types/TinyIntType.js +3 -6
  176. package/types/Type.d.ts +4 -6
  177. package/types/Type.js +6 -10
  178. package/types/Uint8ArrayType.d.ts +3 -4
  179. package/types/Uint8ArrayType.js +3 -12
  180. package/types/UnknownType.d.ts +3 -3
  181. package/types/UnknownType.js +2 -6
  182. package/types/UuidType.d.ts +3 -3
  183. package/types/UuidType.js +2 -6
  184. package/types/index.d.ts +25 -25
  185. package/types/index.js +52 -79
  186. package/typings.d.ts +134 -93
  187. package/typings.js +67 -65
  188. package/unit-of-work/ChangeSet.d.ts +1 -4
  189. package/unit-of-work/ChangeSet.js +13 -17
  190. package/unit-of-work/ChangeSetComputer.d.ts +8 -9
  191. package/unit-of-work/ChangeSetComputer.js +36 -38
  192. package/unit-of-work/ChangeSetPersister.d.ts +11 -9
  193. package/unit-of-work/ChangeSetPersister.js +100 -65
  194. package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
  195. package/unit-of-work/CommitOrderCalculator.js +6 -10
  196. package/unit-of-work/IdentityMap.d.ts +1 -1
  197. package/unit-of-work/IdentityMap.js +1 -5
  198. package/unit-of-work/UnitOfWork.d.ts +16 -8
  199. package/unit-of-work/UnitOfWork.js +266 -209
  200. package/unit-of-work/index.d.ts +6 -6
  201. package/unit-of-work/index.js +6 -22
  202. package/utils/AbstractSchemaGenerator.d.ts +11 -11
  203. package/utils/AbstractSchemaGenerator.js +21 -20
  204. package/utils/Configuration.d.ts +774 -224
  205. package/utils/Configuration.js +166 -216
  206. package/utils/ConfigurationLoader.d.ts +1 -53
  207. package/utils/ConfigurationLoader.js +1 -367
  208. package/utils/Cursor.d.ts +6 -9
  209. package/utils/Cursor.js +25 -25
  210. package/utils/DataloaderUtils.d.ts +18 -8
  211. package/utils/DataloaderUtils.js +63 -21
  212. package/utils/EntityComparator.d.ts +9 -5
  213. package/utils/EntityComparator.js +155 -108
  214. package/utils/NullHighlighter.d.ts +1 -1
  215. package/utils/NullHighlighter.js +1 -5
  216. package/utils/QueryHelper.d.ts +12 -4
  217. package/utils/QueryHelper.js +110 -53
  218. package/utils/RawQueryFragment.d.ts +37 -14
  219. package/utils/RawQueryFragment.js +50 -33
  220. package/utils/RequestContext.d.ts +2 -2
  221. package/utils/RequestContext.js +3 -7
  222. package/utils/TransactionContext.d.ts +1 -1
  223. package/utils/TransactionContext.js +4 -8
  224. package/utils/TransactionManager.d.ts +65 -0
  225. package/utils/TransactionManager.js +223 -0
  226. package/utils/Utils.d.ts +16 -100
  227. package/utils/Utils.js +114 -332
  228. package/utils/clone.js +7 -11
  229. package/utils/env-vars.d.ts +3 -0
  230. package/utils/env-vars.js +87 -0
  231. package/utils/fs-utils.d.ts +12 -0
  232. package/utils/fs-utils.js +97 -0
  233. package/utils/index.d.ts +14 -13
  234. package/utils/index.js +14 -29
  235. package/utils/upsert-utils.d.ts +8 -3
  236. package/utils/upsert-utils.js +57 -10
  237. package/decorators/Check.d.ts +0 -3
  238. package/decorators/Check.js +0 -16
  239. package/decorators/CreateRequestContext.d.ts +0 -3
  240. package/decorators/CreateRequestContext.js +0 -33
  241. package/decorators/Embeddable.d.ts +0 -8
  242. package/decorators/Embeddable.js +0 -14
  243. package/decorators/Embedded.d.ts +0 -18
  244. package/decorators/Embedded.js +0 -20
  245. package/decorators/Entity.d.ts +0 -18
  246. package/decorators/Entity.js +0 -16
  247. package/decorators/Enum.d.ts +0 -9
  248. package/decorators/Enum.js +0 -19
  249. package/decorators/Filter.d.ts +0 -2
  250. package/decorators/Filter.js +0 -11
  251. package/decorators/Formula.d.ts +0 -5
  252. package/decorators/Formula.js +0 -18
  253. package/decorators/Indexed.d.ts +0 -17
  254. package/decorators/Indexed.js +0 -24
  255. package/decorators/ManyToMany.d.ts +0 -40
  256. package/decorators/ManyToMany.js +0 -16
  257. package/decorators/ManyToOne.d.ts +0 -30
  258. package/decorators/ManyToOne.js +0 -16
  259. package/decorators/OneToMany.d.ts +0 -28
  260. package/decorators/OneToMany.js +0 -20
  261. package/decorators/OneToOne.d.ts +0 -24
  262. package/decorators/OneToOne.js +0 -10
  263. package/decorators/PrimaryKey.d.ts +0 -9
  264. package/decorators/PrimaryKey.js +0 -23
  265. package/decorators/Property.d.ts +0 -250
  266. package/decorators/Property.js +0 -34
  267. package/decorators/Transactional.d.ts +0 -13
  268. package/decorators/Transactional.js +0 -31
  269. package/decorators/hooks.d.ts +0 -16
  270. package/decorators/hooks.js +0 -59
  271. package/decorators/index.d.ts +0 -17
  272. package/decorators/index.js +0 -36
  273. package/entity/ArrayCollection.d.ts +0 -116
  274. package/entity/ArrayCollection.js +0 -399
  275. package/entity/EntityValidator.d.ts +0 -19
  276. package/entity/EntityValidator.js +0 -154
  277. package/index.mjs +0 -199
  278. package/metadata/ReflectMetadataProvider.d.ts +0 -8
  279. package/metadata/ReflectMetadataProvider.js +0 -48
  280. package/utils/resolveContextProvider.d.ts +0 -10
  281. package/utils/resolveContextProvider.js +0 -31
@@ -0,0 +1,11 @@
1
+ import type { EntityData, EntityMetadata, EntityProperty, FilterQuery } from '../typings.js';
2
+ /** @internal */
3
+ export declare function validateProperty<T extends object>(prop: EntityProperty, givenValue: any, entity: T): void;
4
+ /** @internal */
5
+ export declare function validateEntity<T extends object>(entity: T, meta: EntityMetadata<T>): void;
6
+ /** @internal */
7
+ export declare function validateParams(params: any, type?: string, field?: string): void;
8
+ /** @internal */
9
+ export declare function validatePrimaryKey<T>(entity: EntityData<T>, meta: EntityMetadata<T>): void;
10
+ /** @internal */
11
+ export declare function validateEmptyWhere<T>(where: FilterQuery<T>): void;
@@ -0,0 +1,65 @@
1
+ import { Utils } from '../utils/Utils.js';
2
+ import { ValidationError } from '../errors.js';
3
+ import { isRaw } from '../utils/RawQueryFragment.js';
4
+ import { SCALAR_TYPES } from '../enums.js';
5
+ /** @internal */
6
+ export function validateProperty(prop, givenValue, entity) {
7
+ if (givenValue == null || isRaw(givenValue)) {
8
+ return;
9
+ }
10
+ const expectedType = prop.runtimeType;
11
+ const propName = prop.embedded ? prop.name.replace(/~/g, '.') : prop.name;
12
+ const givenType = Utils.getObjectType(givenValue);
13
+ if (prop.enum && prop.items) {
14
+ /* v8 ignore next */
15
+ if (!prop.items.some(it => it === givenValue)) {
16
+ throw ValidationError.fromWrongPropertyType(entity, propName, expectedType, givenType, givenValue);
17
+ }
18
+ }
19
+ else {
20
+ if (givenType !== expectedType && SCALAR_TYPES.has(expectedType)) {
21
+ throw ValidationError.fromWrongPropertyType(entity, propName, expectedType, givenType, givenValue);
22
+ }
23
+ }
24
+ }
25
+ function getValue(o, prop) {
26
+ if (prop.embedded && prop.embedded[0] in o) {
27
+ return o[prop.embedded[0]]?.[prop.embedded[1]];
28
+ }
29
+ /* v8 ignore next */
30
+ if (prop.ref) {
31
+ return o[prop.name]?.unwrap();
32
+ }
33
+ return o[prop.name];
34
+ }
35
+ /** @internal */
36
+ export function validateEntity(entity, meta) {
37
+ for (const prop of meta.validateProps) {
38
+ validateProperty(prop, getValue(entity, prop), entity);
39
+ }
40
+ }
41
+ /** @internal */
42
+ export function validateParams(params, type = 'search condition', field) {
43
+ if (Utils.isPrimaryKey(params) || Utils.isEntity(params)) {
44
+ return;
45
+ }
46
+ if (Array.isArray(params)) {
47
+ return params.forEach(item => validateParams(item, type, field));
48
+ }
49
+ if (Utils.isPlainObject(params)) {
50
+ Object.keys(params).forEach(k => validateParams(params[k], type, k));
51
+ }
52
+ }
53
+ /** @internal */
54
+ export function validatePrimaryKey(entity, meta) {
55
+ const pkExists = meta.primaryKeys.every(pk => entity[pk] != null) || (meta.serializedPrimaryKey && entity[meta.serializedPrimaryKey] != null);
56
+ if (!entity || !pkExists) {
57
+ throw ValidationError.fromMergeWithoutPK(meta);
58
+ }
59
+ }
60
+ /** @internal */
61
+ export function validateEmptyWhere(where) {
62
+ if (Utils.isEmpty(where)) {
63
+ throw new Error(`You cannot call 'EntityManager.findOne()' with empty 'where' parameter`);
64
+ }
65
+ }
package/entity/wrap.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { IWrappedEntity, IWrappedEntityInternal } from '../typings';
1
+ import type { IWrappedEntity, IWrappedEntityInternal } from '../typings.js';
2
2
  /**
3
3
  * returns WrappedEntity instance associated with this entity. This includes all the internal properties like `__meta` or `__em`.
4
4
  */
package/entity/wrap.js CHANGED
@@ -1,12 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrap = wrap;
4
- exports.helper = helper;
5
1
  /**
6
2
  * wraps entity type with WrappedEntity internal properties and helpers like init/isInitialized/populated/toJSON
7
3
  * use `preferHelper = true` to have access to the internal `__` properties like `__meta` or `__em`
8
4
  */
9
- function wrap(entity, preferHelper = false) {
5
+ export function wrap(entity, preferHelper = false) {
10
6
  if (!entity) {
11
7
  return entity;
12
8
  }
@@ -20,6 +16,6 @@ function wrap(entity, preferHelper = false) {
20
16
  * use `preferHelper = true` to have access to the internal `__` properties like `__meta` or `__em`
21
17
  * @internal
22
18
  */
23
- function helper(entity) {
19
+ export function helper(entity) {
24
20
  return entity.__helper;
25
21
  }
package/enums.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import type { Dictionary, EntityKey, ExpandProperty } from './typings';
2
- import type { Transaction } from './connections';
3
- import type { LogContext } from './logging';
1
+ import type { Dictionary, EntityKey, ExpandProperty } from './typings.js';
2
+ import type { Transaction } from './connections/Connection.js';
3
+ import type { LogContext } from './logging/Logger.js';
4
4
  export declare enum FlushMode {
5
5
  /** The `EntityManager` delays the flush until the current Transaction is committed. */
6
6
  COMMIT = "commit",
@@ -66,7 +66,7 @@ export declare enum QueryOrderNumeric {
66
66
  ASC = 1,
67
67
  DESC = -1
68
68
  }
69
- export type QueryOrderKeysFlat = QueryOrder | QueryOrderNumeric | keyof typeof QueryOrder;
69
+ export type QueryOrderKeysFlat = QueryOrder | QueryOrderNumeric | `${QueryOrder}`;
70
70
  export type QueryOrderKeys<T> = QueryOrderKeysFlat | QueryOrderMap<T>;
71
71
  export type QueryOrderMap<T> = {
72
72
  [K in EntityKey<T>]?: QueryOrderKeys<ExpandProperty<T[K]>>;
@@ -85,9 +85,11 @@ export declare enum QueryFlag {
85
85
  INCLUDE_LAZY_FORMULAS = "INCLUDE_LAZY_FORMULAS",
86
86
  AUTO_JOIN_ONE_TO_ONE_OWNER = "AUTO_JOIN_ONE_TO_ONE_OWNER",
87
87
  INFER_POPULATE = "INFER_POPULATE",
88
- IDENTITY_INSERT = "IDENTITY_INSERT"
88
+ DISABLE_NESTED_INNER_JOIN = "DISABLE_NESTED_INNER_JOIN",
89
+ IDENTITY_INSERT = "IDENTITY_INSERT",// mssql only
90
+ OUTPUT_TABLE = "OUTPUT_TABLE"
89
91
  }
90
- export declare const SCALAR_TYPES: string[];
92
+ export declare const SCALAR_TYPES: Set<string>;
91
93
  export declare enum ReferenceKind {
92
94
  SCALAR = "scalar",
93
95
  ONE_TO_ONE = "1:1",
@@ -108,7 +110,8 @@ export declare enum Cascade {
108
110
  }
109
111
  export declare enum LoadStrategy {
110
112
  SELECT_IN = "select-in",
111
- JOINED = "joined"
113
+ JOINED = "joined",
114
+ BALANCED = "balanced"
112
115
  }
113
116
  export declare enum DataloaderType {
114
117
  NONE = 0,
@@ -156,12 +159,22 @@ export declare enum EventType {
156
159
  }
157
160
  export declare const EventTypeMap: Record<EventType, number>;
158
161
  export type TransactionEventType = EventType.beforeTransactionStart | EventType.afterTransactionStart | EventType.beforeTransactionCommit | EventType.afterTransactionCommit | EventType.beforeTransactionRollback | EventType.afterTransactionRollback;
162
+ export declare enum TransactionPropagation {
163
+ REQUIRED = "required",
164
+ REQUIRES_NEW = "requires_new",
165
+ NESTED = "nested",
166
+ NOT_SUPPORTED = "not_supported",
167
+ SUPPORTS = "supports",
168
+ MANDATORY = "mandatory",
169
+ NEVER = "never"
170
+ }
159
171
  export interface TransactionOptions {
160
172
  ctx?: Transaction;
161
- isolationLevel?: IsolationLevel;
173
+ propagation?: TransactionPropagation | `${TransactionPropagation}`;
174
+ isolationLevel?: IsolationLevel | `${IsolationLevel}`;
162
175
  readOnly?: boolean;
163
176
  clear?: boolean;
164
- flushMode?: FlushMode;
177
+ flushMode?: FlushMode | `${FlushMode}`;
165
178
  ignoreNestedTransactions?: boolean;
166
179
  loggerContext?: LogContext;
167
180
  }
@@ -171,3 +184,5 @@ export declare enum DeferMode {
171
184
  INITIALLY_IMMEDIATE = "immediate",
172
185
  INITIALLY_DEFERRED = "deferred"
173
186
  }
187
+ /** With `absolute` the prefix is set at the root of the entity (regardless of the nesting level) */
188
+ export type EmbeddedPrefixMode = 'absolute' | 'relative';
package/enums.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeferMode = exports.PlainObject = exports.EventTypeMap = exports.EventType = exports.IsolationLevel = exports.LockMode = exports.DataloaderType = exports.LoadStrategy = exports.Cascade = exports.ReferenceKind = exports.SCALAR_TYPES = exports.QueryFlag = exports.QueryOrderNumeric = exports.QueryOrder = exports.JSON_KEY_OPERATORS = exports.ARRAY_OPERATORS = exports.QueryOperator = exports.GroupOperator = exports.PopulatePath = exports.PopulateHint = exports.FlushMode = void 0;
4
- var FlushMode;
1
+ export var FlushMode;
5
2
  (function (FlushMode) {
6
3
  /** The `EntityManager` delays the flush until the current Transaction is committed. */
7
4
  FlushMode["COMMIT"] = "commit";
@@ -9,23 +6,23 @@ var FlushMode;
9
6
  FlushMode["AUTO"] = "auto";
10
7
  /** Flushes the `EntityManager` before every query. */
11
8
  FlushMode["ALWAYS"] = "always";
12
- })(FlushMode || (exports.FlushMode = FlushMode = {}));
13
- var PopulateHint;
9
+ })(FlushMode || (FlushMode = {}));
10
+ export var PopulateHint;
14
11
  (function (PopulateHint) {
15
12
  PopulateHint["INFER"] = "infer";
16
13
  PopulateHint["ALL"] = "all";
17
- })(PopulateHint || (exports.PopulateHint = PopulateHint = {}));
18
- var PopulatePath;
14
+ })(PopulateHint || (PopulateHint = {}));
15
+ export var PopulatePath;
19
16
  (function (PopulatePath) {
20
17
  PopulatePath["INFER"] = "$infer";
21
18
  PopulatePath["ALL"] = "*";
22
- })(PopulatePath || (exports.PopulatePath = PopulatePath = {}));
23
- var GroupOperator;
19
+ })(PopulatePath || (PopulatePath = {}));
20
+ export var GroupOperator;
24
21
  (function (GroupOperator) {
25
22
  GroupOperator["$and"] = "and";
26
23
  GroupOperator["$or"] = "or";
27
- })(GroupOperator || (exports.GroupOperator = GroupOperator = {}));
28
- var QueryOperator;
24
+ })(GroupOperator || (GroupOperator = {}));
25
+ export var QueryOperator;
29
26
  (function (QueryOperator) {
30
27
  QueryOperator["$eq"] = "=";
31
28
  QueryOperator["$in"] = "in";
@@ -50,8 +47,8 @@ var QueryOperator;
50
47
  QueryOperator["$hasKey"] = "?";
51
48
  QueryOperator["$hasKeys"] = "?&";
52
49
  QueryOperator["$hasSomeKeys"] = "?|";
53
- })(QueryOperator || (exports.QueryOperator = QueryOperator = {}));
54
- exports.ARRAY_OPERATORS = [
50
+ })(QueryOperator || (QueryOperator = {}));
51
+ export const ARRAY_OPERATORS = [
55
52
  '$eq',
56
53
  '$gt',
57
54
  '$gte',
@@ -62,12 +59,12 @@ exports.ARRAY_OPERATORS = [
62
59
  '$contains',
63
60
  '$contained',
64
61
  ];
65
- exports.JSON_KEY_OPERATORS = [
62
+ export const JSON_KEY_OPERATORS = [
66
63
  '$hasKey',
67
64
  '$hasKeys',
68
65
  '$hasSomeKeys',
69
66
  ];
70
- var QueryOrder;
67
+ export var QueryOrder;
71
68
  (function (QueryOrder) {
72
69
  QueryOrder["ASC"] = "ASC";
73
70
  QueryOrder["ASC_NULLS_LAST"] = "ASC NULLS LAST";
@@ -81,13 +78,13 @@ var QueryOrder;
81
78
  QueryOrder["desc"] = "desc";
82
79
  QueryOrder["desc_nulls_last"] = "desc nulls last";
83
80
  QueryOrder["desc_nulls_first"] = "desc nulls first";
84
- })(QueryOrder || (exports.QueryOrder = QueryOrder = {}));
85
- var QueryOrderNumeric;
81
+ })(QueryOrder || (QueryOrder = {}));
82
+ export var QueryOrderNumeric;
86
83
  (function (QueryOrderNumeric) {
87
84
  QueryOrderNumeric[QueryOrderNumeric["ASC"] = 1] = "ASC";
88
85
  QueryOrderNumeric[QueryOrderNumeric["DESC"] = -1] = "DESC";
89
- })(QueryOrderNumeric || (exports.QueryOrderNumeric = QueryOrderNumeric = {}));
90
- var QueryFlag;
86
+ })(QueryOrderNumeric || (QueryOrderNumeric = {}));
87
+ export var QueryFlag;
91
88
  (function (QueryFlag) {
92
89
  QueryFlag["DISTINCT"] = "DISTINCT";
93
90
  QueryFlag["PAGINATE"] = "PAGINATE";
@@ -98,10 +95,12 @@ var QueryFlag;
98
95
  QueryFlag["INCLUDE_LAZY_FORMULAS"] = "INCLUDE_LAZY_FORMULAS";
99
96
  QueryFlag["AUTO_JOIN_ONE_TO_ONE_OWNER"] = "AUTO_JOIN_ONE_TO_ONE_OWNER";
100
97
  QueryFlag["INFER_POPULATE"] = "INFER_POPULATE";
98
+ QueryFlag["DISABLE_NESTED_INNER_JOIN"] = "DISABLE_NESTED_INNER_JOIN";
101
99
  QueryFlag["IDENTITY_INSERT"] = "IDENTITY_INSERT";
102
- })(QueryFlag || (exports.QueryFlag = QueryFlag = {}));
103
- exports.SCALAR_TYPES = ['string', 'number', 'boolean', 'bigint', 'Date', 'Buffer', 'RegExp'];
104
- var ReferenceKind;
100
+ QueryFlag["OUTPUT_TABLE"] = "OUTPUT_TABLE";
101
+ })(QueryFlag || (QueryFlag = {}));
102
+ export const SCALAR_TYPES = new Set(['string', 'number', 'boolean', 'bigint', 'Uint8Array', 'Date', 'Buffer', 'RegExp']);
103
+ export var ReferenceKind;
105
104
  (function (ReferenceKind) {
106
105
  ReferenceKind["SCALAR"] = "scalar";
107
106
  ReferenceKind["ONE_TO_ONE"] = "1:1";
@@ -109,8 +108,8 @@ var ReferenceKind;
109
108
  ReferenceKind["MANY_TO_ONE"] = "m:1";
110
109
  ReferenceKind["MANY_TO_MANY"] = "m:n";
111
110
  ReferenceKind["EMBEDDED"] = "embedded";
112
- })(ReferenceKind || (exports.ReferenceKind = ReferenceKind = {}));
113
- var Cascade;
111
+ })(ReferenceKind || (ReferenceKind = {}));
112
+ export var Cascade;
114
113
  (function (Cascade) {
115
114
  Cascade["PERSIST"] = "persist";
116
115
  Cascade["MERGE"] = "merge";
@@ -120,20 +119,21 @@ var Cascade;
120
119
  Cascade["SCHEDULE_ORPHAN_REMOVAL"] = "schedule_orphan_removal";
121
120
  /** @internal */
122
121
  Cascade["CANCEL_ORPHAN_REMOVAL"] = "cancel_orphan_removal";
123
- })(Cascade || (exports.Cascade = Cascade = {}));
124
- var LoadStrategy;
122
+ })(Cascade || (Cascade = {}));
123
+ export var LoadStrategy;
125
124
  (function (LoadStrategy) {
126
125
  LoadStrategy["SELECT_IN"] = "select-in";
127
126
  LoadStrategy["JOINED"] = "joined";
128
- })(LoadStrategy || (exports.LoadStrategy = LoadStrategy = {}));
129
- var DataloaderType;
127
+ LoadStrategy["BALANCED"] = "balanced";
128
+ })(LoadStrategy || (LoadStrategy = {}));
129
+ export var DataloaderType;
130
130
  (function (DataloaderType) {
131
131
  DataloaderType[DataloaderType["NONE"] = 0] = "NONE";
132
132
  DataloaderType[DataloaderType["REFERENCE"] = 1] = "REFERENCE";
133
133
  DataloaderType[DataloaderType["COLLECTION"] = 2] = "COLLECTION";
134
134
  DataloaderType[DataloaderType["ALL"] = 3] = "ALL";
135
- })(DataloaderType || (exports.DataloaderType = DataloaderType = {}));
136
- var LockMode;
135
+ })(DataloaderType || (DataloaderType = {}));
136
+ export var LockMode;
137
137
  (function (LockMode) {
138
138
  LockMode[LockMode["NONE"] = 0] = "NONE";
139
139
  LockMode[LockMode["OPTIMISTIC"] = 1] = "OPTIMISTIC";
@@ -143,16 +143,16 @@ var LockMode;
143
143
  LockMode[LockMode["PESSIMISTIC_WRITE_OR_FAIL"] = 5] = "PESSIMISTIC_WRITE_OR_FAIL";
144
144
  LockMode[LockMode["PESSIMISTIC_PARTIAL_READ"] = 6] = "PESSIMISTIC_PARTIAL_READ";
145
145
  LockMode[LockMode["PESSIMISTIC_READ_OR_FAIL"] = 7] = "PESSIMISTIC_READ_OR_FAIL";
146
- })(LockMode || (exports.LockMode = LockMode = {}));
147
- var IsolationLevel;
146
+ })(LockMode || (LockMode = {}));
147
+ export var IsolationLevel;
148
148
  (function (IsolationLevel) {
149
149
  IsolationLevel["READ_UNCOMMITTED"] = "read uncommitted";
150
150
  IsolationLevel["READ_COMMITTED"] = "read committed";
151
151
  IsolationLevel["SNAPSHOT"] = "snapshot";
152
152
  IsolationLevel["REPEATABLE_READ"] = "repeatable read";
153
153
  IsolationLevel["SERIALIZABLE"] = "serializable";
154
- })(IsolationLevel || (exports.IsolationLevel = IsolationLevel = {}));
155
- var EventType;
154
+ })(IsolationLevel || (IsolationLevel = {}));
155
+ export var EventType;
156
156
  (function (EventType) {
157
157
  EventType["onInit"] = "onInit";
158
158
  EventType["onLoad"] = "onLoad";
@@ -173,16 +173,25 @@ var EventType;
173
173
  EventType["afterTransactionCommit"] = "afterTransactionCommit";
174
174
  EventType["beforeTransactionRollback"] = "beforeTransactionRollback";
175
175
  EventType["afterTransactionRollback"] = "afterTransactionRollback";
176
- })(EventType || (exports.EventType = EventType = {}));
177
- exports.EventTypeMap = Object.keys(EventType).reduce((a, b, i) => {
176
+ })(EventType || (EventType = {}));
177
+ export const EventTypeMap = Object.keys(EventType).reduce((a, b, i) => {
178
178
  a[b] = i;
179
179
  return a;
180
180
  }, {});
181
- class PlainObject {
181
+ export var TransactionPropagation;
182
+ (function (TransactionPropagation) {
183
+ TransactionPropagation["REQUIRED"] = "required";
184
+ TransactionPropagation["REQUIRES_NEW"] = "requires_new";
185
+ TransactionPropagation["NESTED"] = "nested";
186
+ TransactionPropagation["NOT_SUPPORTED"] = "not_supported";
187
+ TransactionPropagation["SUPPORTS"] = "supports";
188
+ TransactionPropagation["MANDATORY"] = "mandatory";
189
+ TransactionPropagation["NEVER"] = "never";
190
+ })(TransactionPropagation || (TransactionPropagation = {}));
191
+ export class PlainObject {
182
192
  }
183
- exports.PlainObject = PlainObject;
184
- var DeferMode;
193
+ export var DeferMode;
185
194
  (function (DeferMode) {
186
195
  DeferMode["INITIALLY_IMMEDIATE"] = "immediate";
187
196
  DeferMode["INITIALLY_DEFERRED"] = "deferred";
188
- })(DeferMode || (exports.DeferMode = DeferMode = {}));
197
+ })(DeferMode || (DeferMode = {}));
package/errors.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { AnyEntity, Constructor, Dictionary, EntityMetadata, EntityProperty, IPrimaryKey } from './typings';
1
+ import type { AnyEntity, Constructor, Dictionary, EntityMetadata, EntityProperty, IPrimaryKey } from './typings.js';
2
2
  export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Error {
3
3
  readonly entity?: T | undefined;
4
4
  constructor(message: string, entity?: T | undefined);
@@ -8,13 +8,14 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
8
8
  getEntity(): AnyEntity | undefined;
9
9
  static fromWrongPropertyType(entity: AnyEntity, property: string, expectedType: string, givenType: string, givenValue: string): ValidationError;
10
10
  static fromWrongRepositoryType(entityName: string, repoType: string, method: string): ValidationError;
11
- static fromCollectionNotInitialized(entity: AnyEntity, prop: EntityProperty): ValidationError;
12
11
  static fromMergeWithoutPK(meta: EntityMetadata): ValidationError;
13
12
  static transactionRequired(): ValidationError;
14
13
  static entityNotManaged(entity: AnyEntity): ValidationError;
15
14
  static notEntity(owner: AnyEntity, prop: EntityProperty, data: any): ValidationError;
16
15
  static notDiscoveredEntity(data: any, meta?: EntityMetadata, action?: string): ValidationError;
17
16
  static invalidPropertyName(entityName: string, invalid: string): ValidationError;
17
+ static invalidCollectionValues(entityName: string, propName: string, invalid: unknown): ValidationError;
18
+ static invalidEnumArrayItems(entityName: string, invalid: unknown): ValidationError;
18
19
  static invalidType(type: Constructor<any>, value: any, mode: string): ValidationError;
19
20
  static propertyRequired(entity: AnyEntity, property: EntityProperty): ValidationError;
20
21
  static cannotModifyInverseCollection(owner: AnyEntity, property: EntityProperty): ValidationError;
@@ -24,7 +25,9 @@ export declare class ValidationError<T extends AnyEntity = AnyEntity> extends Er
24
25
  static cannotCommit(): ValidationError;
25
26
  static cannotUseGlobalContext(): ValidationError;
26
27
  static cannotUseOperatorsInsideEmbeddables(className: string, propName: string, payload: unknown): ValidationError;
28
+ static cannotUseGroupOperatorsInsideScalars(className: string, propName: string, payload: unknown): ValidationError;
27
29
  static invalidEmbeddableQuery(className: string, propName: string, embeddableType: string): ValidationError;
30
+ static invalidQueryCondition(cond: unknown): ValidationError;
28
31
  }
29
32
  export declare class CursorError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
30
33
  static entityNotPopulated(entity: AnyEntity, prop: string): ValidationError;
@@ -43,7 +46,6 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
43
46
  static fromWrongOwnership(meta: EntityMetadata, prop: EntityProperty, key: 'inversedBy' | 'mappedBy'): MetadataError;
44
47
  static fromWrongReferenceKind(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
45
48
  static fromInversideSidePrimary(meta: EntityMetadata, owner: EntityProperty, prop: EntityProperty): MetadataError;
46
- static entityNotFound(name: string, path: string): MetadataError;
47
49
  static unknownIndexProperty(meta: EntityMetadata, prop: string, type: string): MetadataError;
48
50
  static multipleVersionFields(meta: EntityMetadata, fields: string[]): MetadataError;
49
51
  static invalidVersionFieldType(meta: EntityMetadata): MetadataError;
@@ -65,4 +67,10 @@ export declare class MetadataError<T extends AnyEntity = AnyEntity> extends Vali
65
67
  export declare class NotFoundError<T extends AnyEntity = AnyEntity> extends ValidationError<T> {
66
68
  static findOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
67
69
  static findExactlyOneFailed(name: string, where: Dictionary | IPrimaryKey): NotFoundError;
70
+ static failedToLoadProperty(name: string, propName: string, where: unknown): NotFoundError;
71
+ }
72
+ export declare class TransactionStateError extends ValidationError {
73
+ static requiredTransactionNotFound(propagation: string): TransactionStateError;
74
+ static transactionNotAllowed(propagation: string): TransactionStateError;
75
+ static invalidPropagation(propagation: string): TransactionStateError;
68
76
  }
package/errors.js CHANGED
@@ -1,8 +1,5 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.NotFoundError = exports.MetadataError = exports.OptimisticLockError = exports.CursorError = exports.ValidationError = void 0;
4
- const node_util_1 = require("node:util");
5
- class ValidationError extends Error {
1
+ import { inspect } from './logging/inspect.js';
2
+ export class ValidationError extends Error {
6
3
  entity;
7
4
  constructor(message, entity) {
8
5
  super(message);
@@ -19,18 +16,13 @@ class ValidationError extends Error {
19
16
  }
20
17
  static fromWrongPropertyType(entity, property, expectedType, givenType, givenValue) {
21
18
  const entityName = entity.constructor.name;
22
- const msg = `Trying to set ${entityName}.${property} of type '${expectedType}' to ${(0, node_util_1.inspect)(givenValue)} of type '${givenType}'`;
19
+ const msg = `Trying to set ${entityName}.${property} of type '${expectedType}' to ${inspect(givenValue)} of type '${givenType}'`;
23
20
  return new ValidationError(msg);
24
21
  }
25
22
  static fromWrongRepositoryType(entityName, repoType, method) {
26
23
  const msg = `Trying to use EntityRepository.${method}() with '${entityName}' entity while the repository is of type '${repoType}'`;
27
24
  return new ValidationError(msg);
28
25
  }
29
- static fromCollectionNotInitialized(entity, prop) {
30
- const entityName = entity.constructor.name;
31
- const msg = `${entityName}.${prop.name} is not initialized, define it as '${prop.name} = new Collection<${prop.type}>(this);'`;
32
- return new ValidationError(msg);
33
- }
34
26
  static fromMergeWithoutPK(meta) {
35
27
  return new ValidationError(`You cannot merge entity '${meta.className}' without identifier!`);
36
28
  }
@@ -42,13 +34,12 @@ class ValidationError extends Error {
42
34
  }
43
35
  static notEntity(owner, prop, data) {
44
36
  const type = Object.prototype.toString.call(data).match(/\[object (\w+)]/)[1].toLowerCase();
45
- return new ValidationError(`Entity of type ${prop.type} expected for property ${owner.constructor.name}.${prop.name}, ${(0, node_util_1.inspect)(data)} of type ${type} given. If you are using Object.assign(entity, data), use em.assign(entity, data) instead.`);
37
+ return new ValidationError(`Entity of type ${prop.type} expected for property ${owner.constructor.name}.${prop.name}, ${inspect(data)} of type ${type} given. If you are using Object.assign(entity, data), use em.assign(entity, data) instead.`);
46
38
  }
47
39
  static notDiscoveredEntity(data, meta, action = 'persist') {
48
- /* istanbul ignore next */
40
+ /* v8 ignore next */
49
41
  const type = meta?.className ?? Object.prototype.toString.call(data).match(/\[object (\w+)]/)[1].toLowerCase();
50
42
  let err = `Trying to ${action} not discovered entity of type ${type}.`;
51
- /* istanbul ignore else */
52
43
  if (meta) {
53
44
  err += ` Entity with this name was discovered, but not the prototype you are passing to the ORM. If using EntitySchema, be sure to point to the implementation via \`class\`.`;
54
45
  }
@@ -57,6 +48,12 @@ class ValidationError extends Error {
57
48
  static invalidPropertyName(entityName, invalid) {
58
49
  return new ValidationError(`Entity '${entityName}' does not have property '${invalid}'`);
59
50
  }
51
+ static invalidCollectionValues(entityName, propName, invalid) {
52
+ return new ValidationError(`Invalid collection values provided for '${entityName}.${propName}' in ${entityName}.assign(): ${inspect(invalid)}`);
53
+ }
54
+ static invalidEnumArrayItems(entityName, invalid) {
55
+ return new ValidationError(`Invalid enum array items provided in ${entityName}: ${inspect(invalid)}`);
56
+ }
60
57
  static invalidType(type, value, mode) {
61
58
  const valueType = Object.prototype.toString.call(value).match(/\[object (\w+)]/)[1].toLowerCase();
62
59
  if (value instanceof Date) {
@@ -66,7 +63,7 @@ class ValidationError extends Error {
66
63
  }
67
64
  static propertyRequired(entity, property) {
68
65
  const entityName = entity.__meta.className;
69
- return new ValidationError(`Value for ${entityName}.${property.name} is required, '${entity[property.name]}' found\nentity: ${(0, node_util_1.inspect)(entity)}`, entity);
66
+ return new ValidationError(`Value for ${entityName}.${property.name} is required, '${entity[property.name]}' found\nentity: ${inspect(entity)}`, entity);
70
67
  }
71
68
  static cannotModifyInverseCollection(owner, property) {
72
69
  const inverseCollection = `${owner.constructor.name}.${property.name}`;
@@ -96,14 +93,20 @@ class ValidationError extends Error {
96
93
  return new ValidationError('Using global EntityManager instance methods for context specific actions is disallowed. If you need to work with the global instance\'s identity map, use `allowGlobalContext` configuration option or `fork()` instead.');
97
94
  }
98
95
  static cannotUseOperatorsInsideEmbeddables(className, propName, payload) {
99
- return new ValidationError(`Using operators inside embeddables is not allowed, move the operator above. (property: ${className}.${propName}, payload: ${(0, node_util_1.inspect)(payload)})`);
96
+ return new ValidationError(`Using operators inside embeddables is not allowed, move the operator above. (property: ${className}.${propName}, payload: ${inspect(payload)})`);
97
+ }
98
+ static cannotUseGroupOperatorsInsideScalars(className, propName, payload) {
99
+ return new ValidationError(`Using group operators ($and/$or) inside scalar properties is not allowed, move the operator above. (property: ${className}.${propName}, payload: ${inspect(payload)})`);
100
100
  }
101
101
  static invalidEmbeddableQuery(className, propName, embeddableType) {
102
102
  return new ValidationError(`Invalid query for entity '${className}', property '${propName}' does not exist in embeddable '${embeddableType}'`);
103
103
  }
104
+ /* v8 ignore next */
105
+ static invalidQueryCondition(cond) {
106
+ return new ValidationError(`Invalid query condition: ${inspect(cond, { depth: 5 })}`);
107
+ }
104
108
  }
105
- exports.ValidationError = ValidationError;
106
- class CursorError extends ValidationError {
109
+ export class CursorError extends ValidationError {
107
110
  static entityNotPopulated(entity, prop) {
108
111
  return new CursorError(`Cannot create cursor, value for '${entity.constructor.name}.${prop}' is missing.`);
109
112
  }
@@ -111,8 +114,7 @@ class CursorError extends ValidationError {
111
114
  return new CursorError(`Invalid cursor condition, value for '${entityName}.${prop}' is missing.`);
112
115
  }
113
116
  }
114
- exports.CursorError = CursorError;
115
- class OptimisticLockError extends ValidationError {
117
+ export class OptimisticLockError extends ValidationError {
116
118
  static notVersioned(meta) {
117
119
  return new OptimisticLockError(`Cannot obtain optimistic lock on unversioned entity ${meta.className}`);
118
120
  }
@@ -127,8 +129,7 @@ class OptimisticLockError extends ValidationError {
127
129
  return new OptimisticLockError(`The optimistic lock failed, version ${expectedLockVersion} was expected, but is actually ${actualLockVersion}`, entity);
128
130
  }
129
131
  }
130
- exports.OptimisticLockError = OptimisticLockError;
131
- class MetadataError extends ValidationError {
132
+ export class MetadataError extends ValidationError {
132
133
  static fromMissingPrimaryKey(meta) {
133
134
  return new MetadataError(`${meta.className} entity is missing @PrimaryKey()`);
134
135
  }
@@ -158,10 +159,6 @@ class MetadataError extends ValidationError {
158
159
  static fromInversideSidePrimary(meta, owner, prop) {
159
160
  return new MetadataError(`${meta.className}.${prop.name} cannot be primary key as it is defined as inverse side. Maybe you should swap the use of 'inversedBy' and 'mappedBy'.`);
160
161
  }
161
- /* istanbul ignore next */
162
- static entityNotFound(name, path) {
163
- return new MetadataError(`Entity '${name}' not found in ${path}`);
164
- }
165
162
  static unknownIndexProperty(meta, prop, type) {
166
163
  return new MetadataError(`Entity ${meta.className} has wrong ${type} definition: '${prop}' does not exist. You need to use property name, not column name.`);
167
164
  }
@@ -208,7 +205,7 @@ class MetadataError extends ValidationError {
208
205
  return this.fromMessage(meta, prop, `is non-persistent relation which targets composite primary key. This is not supported and will cause issues, 'persist: false' should be added to the properties representing single columns instead.`);
209
206
  }
210
207
  static propertyTargetsEntityType(meta, prop, target) {
211
- /* istanbul ignore next */
208
+ /* v8 ignore next */
212
209
  const suggestion = target.embeddable ? 'Embedded' : 'ManyToOne';
213
210
  return this.fromMessage(meta, prop, `is defined as scalar @Property(), but its type is a discovered entity ${target.className}. Maybe you want to use @${suggestion}() decorator instead?`);
214
211
  }
@@ -219,13 +216,26 @@ class MetadataError extends ValidationError {
219
216
  return new MetadataError(`${meta.className}.${prop.name} ${message}`);
220
217
  }
221
218
  }
222
- exports.MetadataError = MetadataError;
223
- class NotFoundError extends ValidationError {
219
+ export class NotFoundError extends ValidationError {
224
220
  static findOneFailed(name, where) {
225
- return new NotFoundError(`${name} not found (${(0, node_util_1.inspect)(where)})`);
221
+ return new NotFoundError(`${name} not found (${inspect(where)})`);
226
222
  }
227
223
  static findExactlyOneFailed(name, where) {
228
- return new NotFoundError(`Wrong number of ${name} entities found for query ${(0, node_util_1.inspect)(where)}, expected exactly one`);
224
+ return new NotFoundError(`Wrong number of ${name} entities found for query ${inspect(where)}, expected exactly one`);
225
+ }
226
+ static failedToLoadProperty(name, propName, where) {
227
+ const whereString = typeof where === 'object' ? inspect(where) : where;
228
+ return new NotFoundError(`${name} (${whereString}) failed to load property '${propName}'`);
229
+ }
230
+ }
231
+ export class TransactionStateError extends ValidationError {
232
+ static requiredTransactionNotFound(propagation) {
233
+ return new TransactionStateError(`No existing transaction found for transaction marked with propagation "${propagation}"`);
234
+ }
235
+ static transactionNotAllowed(propagation) {
236
+ return new TransactionStateError(`Existing transaction found for transaction marked with propagation "${propagation}"`);
237
+ }
238
+ static invalidPropagation(propagation) {
239
+ return new TransactionStateError(`Unsupported transaction propagation type: ${propagation}`);
229
240
  }
230
241
  }
231
- exports.NotFoundError = NotFoundError;
@@ -1,13 +1,14 @@
1
- import type { EntityMetadata } from '../typings';
2
- import type { EventArgs, EventSubscriber, FlushEventArgs, TransactionEventArgs } from './EventSubscriber';
3
- import { EventType, type TransactionEventType } from '../enums';
1
+ import type { EntityMetadata } from '../typings.js';
2
+ import type { EventArgs, EventSubscriber, FlushEventArgs, TransactionEventArgs } from './EventSubscriber.js';
3
+ import { EventType, type TransactionEventType } from '../enums.js';
4
4
  export declare class EventManager {
5
5
  private readonly listeners;
6
6
  private readonly entities;
7
7
  private readonly cache;
8
8
  private readonly subscribers;
9
- constructor(subscribers: EventSubscriber[]);
9
+ constructor(subscribers: Iterable<EventSubscriber>);
10
10
  registerSubscriber(subscriber: EventSubscriber): void;
11
+ getSubscribers(): Set<EventSubscriber>;
11
12
  dispatchEvent<T extends object>(event: TransactionEventType, args: TransactionEventArgs, meta?: EntityMetadata<T>): unknown;
12
13
  dispatchEvent<T extends object>(event: EventType.onInit, args: Partial<EventArgs<T>>, meta?: EntityMetadata<T>): unknown;
13
14
  dispatchEvent<T extends object>(event: EventType, args: Partial<EventArgs<T> | FlushEventArgs>, meta?: EntityMetadata<T>): Promise<unknown>;