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

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 (261) hide show
  1. package/EntityManager.d.ts +25 -16
  2. package/EntityManager.js +219 -209
  3. package/MikroORM.d.ts +7 -6
  4. package/MikroORM.js +33 -45
  5. package/cache/CacheAdapter.js +1 -2
  6. package/cache/FileCacheAdapter.d.ts +1 -1
  7. package/cache/FileCacheAdapter.js +18 -26
  8. package/cache/GeneratedCacheAdapter.d.ts +2 -2
  9. package/cache/GeneratedCacheAdapter.js +1 -5
  10. package/cache/MemoryCacheAdapter.d.ts +1 -1
  11. package/cache/MemoryCacheAdapter.js +1 -5
  12. package/cache/NullCacheAdapter.d.ts +1 -1
  13. package/cache/NullCacheAdapter.js +1 -5
  14. package/cache/index.d.ts +5 -5
  15. package/cache/index.js +5 -21
  16. package/connections/Connection.d.ts +7 -7
  17. package/connections/Connection.js +8 -12
  18. package/connections/index.d.ts +1 -1
  19. package/connections/index.js +1 -17
  20. package/decorators/Check.d.ts +2 -2
  21. package/decorators/Check.js +5 -8
  22. package/decorators/CreateRequestContext.d.ts +1 -1
  23. package/decorators/CreateRequestContext.js +13 -14
  24. package/decorators/Embeddable.d.ts +5 -5
  25. package/decorators/Embeddable.js +4 -7
  26. package/decorators/Embedded.d.ts +3 -3
  27. package/decorators/Embedded.js +10 -12
  28. package/decorators/Entity.d.ts +6 -6
  29. package/decorators/Entity.js +5 -9
  30. package/decorators/Enum.d.ts +3 -3
  31. package/decorators/Enum.js +7 -10
  32. package/decorators/Filter.d.ts +1 -1
  33. package/decorators/Filter.js +3 -6
  34. package/decorators/Formula.d.ts +2 -3
  35. package/decorators/Formula.js +7 -10
  36. package/decorators/Indexed.d.ts +10 -8
  37. package/decorators/Indexed.js +7 -11
  38. package/decorators/ManyToMany.d.ts +4 -4
  39. package/decorators/ManyToMany.js +10 -12
  40. package/decorators/ManyToOne.d.ts +4 -4
  41. package/decorators/ManyToOne.js +10 -12
  42. package/decorators/OneToMany.d.ts +6 -6
  43. package/decorators/OneToMany.js +11 -14
  44. package/decorators/OneToOne.d.ts +4 -4
  45. package/decorators/OneToOne.js +4 -7
  46. package/decorators/PrimaryKey.d.ts +3 -4
  47. package/decorators/PrimaryKey.js +10 -13
  48. package/decorators/Property.d.ts +6 -6
  49. package/decorators/Property.js +10 -12
  50. package/decorators/Transactional.d.ts +2 -2
  51. package/decorators/Transactional.js +7 -10
  52. package/decorators/hooks.js +23 -35
  53. package/decorators/index.d.ts +17 -17
  54. package/decorators/index.js +17 -36
  55. package/drivers/DatabaseDriver.d.ts +13 -12
  56. package/drivers/DatabaseDriver.js +60 -64
  57. package/drivers/IDatabaseDriver.d.ts +16 -13
  58. package/drivers/IDatabaseDriver.js +1 -4
  59. package/drivers/index.d.ts +2 -2
  60. package/drivers/index.js +2 -18
  61. package/entity/ArrayCollection.d.ts +3 -3
  62. package/entity/ArrayCollection.js +38 -35
  63. package/entity/BaseEntity.d.ts +6 -6
  64. package/entity/BaseEntity.js +17 -21
  65. package/entity/Collection.d.ts +6 -7
  66. package/entity/Collection.js +47 -51
  67. package/entity/EntityAssigner.d.ts +2 -2
  68. package/entity/EntityAssigner.js +58 -63
  69. package/entity/EntityFactory.d.ts +3 -3
  70. package/entity/EntityFactory.js +62 -63
  71. package/entity/EntityHelper.d.ts +2 -2
  72. package/entity/EntityHelper.js +44 -45
  73. package/entity/EntityIdentifier.d.ts +1 -1
  74. package/entity/EntityIdentifier.js +1 -5
  75. package/entity/EntityLoader.d.ts +5 -5
  76. package/entity/EntityLoader.js +106 -98
  77. package/entity/EntityRepository.d.ts +7 -7
  78. package/entity/EntityRepository.js +7 -11
  79. package/entity/EntityValidator.d.ts +1 -1
  80. package/entity/EntityValidator.js +25 -29
  81. package/entity/Reference.d.ts +4 -8
  82. package/entity/Reference.js +35 -42
  83. package/entity/WrappedEntity.d.ts +12 -12
  84. package/entity/WrappedEntity.js +23 -27
  85. package/entity/index.d.ts +13 -13
  86. package/entity/index.js +13 -29
  87. package/entity/utils.d.ts +1 -1
  88. package/entity/utils.js +9 -12
  89. package/entity/wrap.d.ts +1 -1
  90. package/entity/wrap.js +2 -6
  91. package/enums.d.ts +3 -3
  92. package/enums.js +37 -41
  93. package/errors.d.ts +1 -1
  94. package/errors.js +15 -24
  95. package/events/EventManager.d.ts +3 -3
  96. package/events/EventManager.js +8 -12
  97. package/events/EventSubscriber.d.ts +8 -5
  98. package/events/EventSubscriber.js +1 -2
  99. package/events/TransactionEventBroadcaster.d.ts +3 -3
  100. package/events/TransactionEventBroadcaster.js +1 -5
  101. package/events/index.d.ts +3 -3
  102. package/events/index.js +3 -19
  103. package/exceptions.js +18 -39
  104. package/hydration/Hydrator.d.ts +5 -5
  105. package/hydration/Hydrator.js +3 -6
  106. package/hydration/ObjectHydrator.d.ts +3 -3
  107. package/hydration/ObjectHydrator.js +26 -28
  108. package/hydration/index.d.ts +2 -2
  109. package/hydration/index.js +2 -18
  110. package/index.d.ts +21 -21
  111. package/index.js +21 -46
  112. package/logging/DefaultLogger.d.ts +1 -1
  113. package/logging/DefaultLogger.js +9 -13
  114. package/logging/Logger.d.ts +1 -1
  115. package/logging/Logger.js +1 -2
  116. package/logging/SimpleLogger.d.ts +2 -2
  117. package/logging/SimpleLogger.js +2 -6
  118. package/logging/colors.js +1 -5
  119. package/logging/index.d.ts +4 -4
  120. package/logging/index.js +4 -20
  121. package/metadata/EntitySchema.d.ts +14 -6
  122. package/metadata/EntitySchema.js +41 -45
  123. package/metadata/MetadataDiscovery.d.ts +7 -7
  124. package/metadata/MetadataDiscovery.js +181 -180
  125. package/metadata/MetadataProvider.d.ts +2 -2
  126. package/metadata/MetadataProvider.js +4 -7
  127. package/metadata/MetadataStorage.d.ts +2 -2
  128. package/metadata/MetadataStorage.js +15 -19
  129. package/metadata/MetadataValidator.d.ts +4 -4
  130. package/metadata/MetadataValidator.js +52 -55
  131. package/metadata/ReflectMetadataProvider.d.ts +2 -2
  132. package/metadata/ReflectMetadataProvider.js +8 -12
  133. package/metadata/index.d.ts +6 -6
  134. package/metadata/index.js +6 -22
  135. package/naming-strategy/AbstractNamingStrategy.d.ts +2 -2
  136. package/naming-strategy/AbstractNamingStrategy.js +4 -8
  137. package/naming-strategy/EntityCaseNamingStrategy.d.ts +1 -1
  138. package/naming-strategy/EntityCaseNamingStrategy.js +2 -6
  139. package/naming-strategy/MongoNamingStrategy.d.ts +1 -1
  140. package/naming-strategy/MongoNamingStrategy.js +2 -6
  141. package/naming-strategy/NamingStrategy.d.ts +1 -1
  142. package/naming-strategy/NamingStrategy.js +1 -2
  143. package/naming-strategy/UnderscoreNamingStrategy.d.ts +1 -1
  144. package/naming-strategy/UnderscoreNamingStrategy.js +2 -6
  145. package/naming-strategy/index.d.ts +5 -5
  146. package/naming-strategy/index.js +5 -21
  147. package/package.json +6 -15
  148. package/platforms/ExceptionConverter.d.ts +2 -2
  149. package/platforms/ExceptionConverter.js +4 -8
  150. package/platforms/Platform.d.ts +10 -10
  151. package/platforms/Platform.js +57 -61
  152. package/platforms/index.d.ts +2 -2
  153. package/platforms/index.js +2 -18
  154. package/serialization/EntitySerializer.d.ts +2 -2
  155. package/serialization/EntitySerializer.js +36 -41
  156. package/serialization/EntityTransformer.d.ts +1 -1
  157. package/serialization/EntityTransformer.js +27 -31
  158. package/serialization/SerializationContext.d.ts +2 -2
  159. package/serialization/SerializationContext.js +10 -14
  160. package/serialization/index.d.ts +3 -3
  161. package/serialization/index.js +3 -19
  162. package/types/ArrayType.d.ts +3 -3
  163. package/types/ArrayType.js +7 -11
  164. package/types/BigIntType.d.ts +4 -3
  165. package/types/BigIntType.js +6 -6
  166. package/types/BlobType.d.ts +3 -3
  167. package/types/BlobType.js +2 -8
  168. package/types/BooleanType.d.ts +3 -3
  169. package/types/BooleanType.js +2 -6
  170. package/types/CharacterType.d.ts +3 -3
  171. package/types/CharacterType.js +2 -6
  172. package/types/DateTimeType.d.ts +3 -3
  173. package/types/DateTimeType.js +2 -6
  174. package/types/DateType.d.ts +3 -3
  175. package/types/DateType.js +2 -6
  176. package/types/DecimalType.d.ts +3 -3
  177. package/types/DecimalType.js +4 -7
  178. package/types/DoubleType.d.ts +3 -3
  179. package/types/DoubleType.js +3 -6
  180. package/types/EnumArrayType.d.ts +4 -4
  181. package/types/EnumArrayType.js +5 -10
  182. package/types/EnumType.d.ts +3 -3
  183. package/types/EnumType.js +2 -6
  184. package/types/FloatType.d.ts +3 -3
  185. package/types/FloatType.js +2 -6
  186. package/types/IntegerType.d.ts +3 -3
  187. package/types/IntegerType.js +2 -6
  188. package/types/IntervalType.d.ts +3 -3
  189. package/types/IntervalType.js +2 -6
  190. package/types/JsonType.d.ts +3 -3
  191. package/types/JsonType.js +2 -6
  192. package/types/MediumIntType.d.ts +3 -3
  193. package/types/MediumIntType.js +2 -6
  194. package/types/SmallIntType.d.ts +3 -3
  195. package/types/SmallIntType.js +2 -6
  196. package/types/StringType.d.ts +3 -3
  197. package/types/StringType.js +2 -6
  198. package/types/TextType.d.ts +3 -3
  199. package/types/TextType.js +2 -6
  200. package/types/TimeType.d.ts +3 -3
  201. package/types/TimeType.js +4 -8
  202. package/types/TinyIntType.d.ts +3 -3
  203. package/types/TinyIntType.js +3 -6
  204. package/types/Type.d.ts +2 -2
  205. package/types/Type.js +5 -9
  206. package/types/Uint8ArrayType.d.ts +3 -3
  207. package/types/Uint8ArrayType.js +3 -9
  208. package/types/UnknownType.d.ts +3 -3
  209. package/types/UnknownType.js +2 -6
  210. package/types/UuidType.d.ts +3 -3
  211. package/types/UuidType.js +2 -6
  212. package/types/index.d.ts +25 -25
  213. package/types/index.js +52 -79
  214. package/typings.d.ts +33 -28
  215. package/typings.js +37 -38
  216. package/unit-of-work/ChangeSet.d.ts +1 -1
  217. package/unit-of-work/ChangeSet.js +13 -17
  218. package/unit-of-work/ChangeSetComputer.d.ts +8 -7
  219. package/unit-of-work/ChangeSetComputer.js +26 -30
  220. package/unit-of-work/ChangeSetPersister.d.ts +7 -6
  221. package/unit-of-work/ChangeSetPersister.js +51 -48
  222. package/unit-of-work/CommitOrderCalculator.d.ts +1 -1
  223. package/unit-of-work/CommitOrderCalculator.js +6 -10
  224. package/unit-of-work/IdentityMap.d.ts +1 -1
  225. package/unit-of-work/IdentityMap.js +1 -5
  226. package/unit-of-work/UnitOfWork.d.ts +8 -7
  227. package/unit-of-work/UnitOfWork.js +193 -178
  228. package/unit-of-work/index.d.ts +6 -6
  229. package/unit-of-work/index.js +6 -22
  230. package/utils/AbstractSchemaGenerator.d.ts +6 -6
  231. package/utils/AbstractSchemaGenerator.js +12 -13
  232. package/utils/Configuration.d.ts +26 -27
  233. package/utils/Configuration.js +50 -55
  234. package/utils/ConfigurationLoader.d.ts +9 -8
  235. package/utils/ConfigurationLoader.js +71 -86
  236. package/utils/Cursor.d.ts +6 -6
  237. package/utils/Cursor.js +22 -25
  238. package/utils/DataloaderUtils.d.ts +4 -4
  239. package/utils/DataloaderUtils.js +12 -16
  240. package/utils/EntityComparator.d.ts +2 -2
  241. package/utils/EntityComparator.js +109 -97
  242. package/utils/NullHighlighter.d.ts +1 -1
  243. package/utils/NullHighlighter.js +1 -5
  244. package/utils/QueryHelper.d.ts +3 -3
  245. package/utils/QueryHelper.js +47 -51
  246. package/utils/RawQueryFragment.d.ts +1 -1
  247. package/utils/RawQueryFragment.js +22 -25
  248. package/utils/RequestContext.d.ts +2 -2
  249. package/utils/RequestContext.js +3 -7
  250. package/utils/TransactionContext.d.ts +1 -1
  251. package/utils/TransactionContext.js +4 -8
  252. package/utils/Utils.d.ts +16 -12
  253. package/utils/Utils.js +96 -95
  254. package/utils/clone.js +8 -11
  255. package/utils/index.d.ts +13 -13
  256. package/utils/index.js +13 -29
  257. package/utils/resolveContextProvider.d.ts +3 -3
  258. package/utils/resolveContextProvider.js +9 -12
  259. package/utils/upsert-utils.d.ts +3 -3
  260. package/utils/upsert-utils.js +5 -9
  261. package/index.mjs +0 -199
@@ -1,20 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UnitOfWork = void 0;
4
- const node_async_hooks_1 = require("node:async_hooks");
5
- const entity_1 = require("../entity");
6
- const ChangeSet_1 = require("./ChangeSet");
7
- const ChangeSetComputer_1 = require("./ChangeSetComputer");
8
- const ChangeSetPersister_1 = require("./ChangeSetPersister");
9
- const CommitOrderCalculator_1 = require("./CommitOrderCalculator");
10
- const Utils_1 = require("../utils/Utils");
11
- const enums_1 = require("../enums");
12
- const errors_1 = require("../errors");
13
- const events_1 = require("../events");
14
- const IdentityMap_1 = require("./IdentityMap");
1
+ import { AsyncLocalStorage } from 'node:async_hooks';
2
+ import { Collection } from '../entity/Collection.js';
3
+ import { EntityHelper } from '../entity/EntityHelper.js';
4
+ import { helper } from '../entity/wrap.js';
5
+ import { Reference } from '../entity/Reference.js';
6
+ import { EntityIdentifier } from '../entity/EntityIdentifier.js';
7
+ import { ChangeSet, ChangeSetType } from './ChangeSet.js';
8
+ import { ChangeSetComputer } from './ChangeSetComputer.js';
9
+ import { ChangeSetPersister } from './ChangeSetPersister.js';
10
+ import { CommitOrderCalculator } from './CommitOrderCalculator.js';
11
+ import { Utils } from '../utils/Utils.js';
12
+ import { Cascade, DeferMode, EventType, LockMode, ReferenceKind } from '../enums.js';
13
+ import { OptimisticLockError, ValidationError } from '../errors.js';
14
+ import { TransactionEventBroadcaster } from '../events/TransactionEventBroadcaster.js';
15
+ import { IdentityMap } from './IdentityMap.js';
15
16
  // to deal with validation for flush inside flush hooks and `Promise.all`
16
- const insideFlush = new node_async_hooks_1.AsyncLocalStorage();
17
- class UnitOfWork {
17
+ const insideFlush = new AsyncLocalStorage();
18
+ export class UnitOfWork {
18
19
  em;
19
20
  /** map of references to managed entities */
20
21
  identityMap;
@@ -38,14 +39,14 @@ class UnitOfWork {
38
39
  this.em = em;
39
40
  this.metadata = this.em.getMetadata();
40
41
  this.platform = this.em.getPlatform();
41
- this.identityMap = new IdentityMap_1.IdentityMap(this.platform.getDefaultSchemaName());
42
+ this.identityMap = new IdentityMap(this.platform.getDefaultSchemaName());
42
43
  this.eventManager = this.em.getEventManager();
43
44
  this.comparator = this.em.getComparator();
44
- this.changeSetComputer = new ChangeSetComputer_1.ChangeSetComputer(this.em.getValidator(), this.collectionUpdates, this.metadata, this.platform, this.em.config, this.em);
45
- this.changeSetPersister = new ChangeSetPersister_1.ChangeSetPersister(this.em.getDriver(), this.metadata, this.em.config.getHydrator(this.metadata), this.em.getEntityFactory(), this.em.getValidator(), this.em.config);
45
+ this.changeSetComputer = new ChangeSetComputer(this.em.getValidator(), this.collectionUpdates, this.metadata, this.platform, this.em.config, this.em);
46
+ this.changeSetPersister = new ChangeSetPersister(this.em.getDriver(), this.metadata, this.em.config.getHydrator(this.metadata), this.em.getEntityFactory(), this.em.getValidator(), this.em.config);
46
47
  }
47
48
  merge(entity, visited) {
48
- const wrapped = (0, entity_1.helper)(entity);
49
+ const wrapped = helper(entity);
49
50
  wrapped.__em = this.em;
50
51
  if (!wrapped.hasPrimaryKey()) {
51
52
  return;
@@ -62,41 +63,41 @@ class UnitOfWork {
62
63
  wrapped.__originalEntityData = this.comparator.prepareEntity(entity);
63
64
  wrapped.__touched = false;
64
65
  }
65
- this.cascade(entity, enums_1.Cascade.MERGE, visited ?? new Set());
66
+ this.cascade(entity, Cascade.MERGE, visited ?? new Set());
66
67
  }
67
68
  /**
68
69
  * @internal
69
70
  */
70
71
  register(entity, data, options) {
71
72
  this.identityMap.store(entity);
72
- entity_1.EntityHelper.ensurePropagation(entity);
73
+ EntityHelper.ensurePropagation(entity);
73
74
  if (options?.newEntity) {
74
75
  return entity;
75
76
  }
76
77
  const forceUndefined = this.em.config.get('forceUndefined');
77
- const wrapped = (0, entity_1.helper)(entity);
78
+ const wrapped = helper(entity);
78
79
  if (options?.loaded && wrapped.__initialized && !wrapped.__onLoadFired) {
79
80
  this.loadedEntities.add(entity);
80
81
  }
81
82
  wrapped.__em ??= this.em;
82
83
  wrapped.__managed = true;
83
84
  if (data && (options?.refresh || !wrapped.__originalEntityData)) {
84
- for (const key of Utils_1.Utils.keys(data)) {
85
+ for (const key of Utils.keys(data)) {
85
86
  const prop = wrapped.__meta.properties[key];
86
87
  if (!prop) {
87
88
  continue;
88
89
  }
89
90
  wrapped.__loadedProperties.add(key);
90
- if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils_1.Utils.isPlainObject(data[prop.name])) {
91
- data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta.primaryKeys, true);
91
+ if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils.isPlainObject(data[prop.name])) {
92
+ data[prop.name] = Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta.primaryKeys, true);
92
93
  }
93
- else if (prop.kind === enums_1.ReferenceKind.EMBEDDED && !prop.object && Utils_1.Utils.isPlainObject(data[prop.name])) {
94
+ else if (prop.kind === ReferenceKind.EMBEDDED && !prop.object && Utils.isPlainObject(data[prop.name])) {
94
95
  for (const p of prop.targetMeta.props) {
95
- /* istanbul ignore next */
96
+ /* v8 ignore next */
96
97
  const prefix = prop.prefix === false ? '' : prop.prefix === true ? prop.name + '_' : prop.prefix;
97
98
  data[prefix + p.name] = data[prop.name][p.name];
98
99
  }
99
- data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta.primaryKeys, true);
100
+ data[prop.name] = Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta.primaryKeys, true);
100
101
  }
101
102
  if (forceUndefined) {
102
103
  if (data[key] === null) {
@@ -114,9 +115,9 @@ class UnitOfWork {
114
115
  */
115
116
  async dispatchOnLoadEvent() {
116
117
  for (const entity of this.loadedEntities) {
117
- if (this.eventManager.hasListeners(enums_1.EventType.onLoad, entity.__meta)) {
118
- await this.eventManager.dispatchEvent(enums_1.EventType.onLoad, { entity, meta: entity.__meta, em: this.em });
119
- (0, entity_1.helper)(entity).__onLoadFired = true;
118
+ if (this.eventManager.hasListeners(EventType.onLoad, entity.__meta)) {
119
+ await this.eventManager.dispatchEvent(EventType.onLoad, { entity, meta: entity.__meta, em: this.em });
120
+ helper(entity).__onLoadFired = true;
120
121
  }
121
122
  }
122
123
  this.loadedEntities.clear();
@@ -134,8 +135,8 @@ class UnitOfWork {
134
135
  hash = '' + id;
135
136
  }
136
137
  else {
137
- const keys = Array.isArray(id) ? Utils_1.Utils.flatten(id) : [id];
138
- hash = Utils_1.Utils.getPrimaryKeyHash(keys);
138
+ const keys = Array.isArray(id) ? Utils.flatten(id) : [id];
139
+ hash = Utils.getPrimaryKeyHash(keys);
139
140
  }
140
141
  schema ??= meta.schema ?? this.em.config.getSchema();
141
142
  if (schema) {
@@ -144,7 +145,7 @@ class UnitOfWork {
144
145
  return this.identityMap.getByHash(meta, hash);
145
146
  }
146
147
  tryGetById(entityName, where, schema, strict = true) {
147
- const pk = Utils_1.Utils.extractPK(where, this.metadata.find(entityName), strict);
148
+ const pk = Utils.extractPK(where, this.metadata.find(entityName), strict);
148
149
  if (!pk) {
149
150
  return null;
150
151
  }
@@ -160,7 +161,7 @@ class UnitOfWork {
160
161
  * Returns stored snapshot of entity state that is used for change set computation.
161
162
  */
162
163
  getOriginalEntityData(entity) {
163
- return (0, entity_1.helper)(entity).__originalEntityData;
164
+ return helper(entity).__originalEntityData;
164
165
  }
165
166
  getPersistStack() {
166
167
  return this.persistStack;
@@ -185,7 +186,7 @@ class UnitOfWork {
185
186
  return true;
186
187
  }
187
188
  for (const entity of this.identityMap.getStore(meta).values()) {
188
- if ((0, entity_1.helper)(entity).__initialized && (0, entity_1.helper)(entity).isTouched()) {
189
+ if (helper(entity).__initialized && helper(entity).isTouched()) {
189
190
  return true;
190
191
  }
191
192
  }
@@ -195,9 +196,9 @@ class UnitOfWork {
195
196
  this.queuedActions.clear();
196
197
  }
197
198
  computeChangeSet(entity, type) {
198
- const wrapped = (0, entity_1.helper)(entity);
199
+ const wrapped = helper(entity);
199
200
  if (type) {
200
- this.changeSets.set(entity, new ChangeSet_1.ChangeSet(entity, type, {}, wrapped.__meta));
201
+ this.changeSets.set(entity, new ChangeSet(entity, type, {}, wrapped.__meta));
201
202
  return;
202
203
  }
203
204
  const cs = this.changeSetComputer.computeChangeSet(entity);
@@ -216,19 +217,18 @@ class UnitOfWork {
216
217
  return;
217
218
  }
218
219
  const cs = this.changeSetComputer.computeChangeSet(entity);
219
- /* istanbul ignore else */
220
220
  if (cs && !this.checkUniqueProps(cs)) {
221
221
  Object.assign(changeSet.payload, cs.payload);
222
- (0, entity_1.helper)(entity).__originalEntityData = this.comparator.prepareEntity(entity);
223
- (0, entity_1.helper)(entity).__touched = false;
222
+ helper(entity).__originalEntityData = this.comparator.prepareEntity(entity);
223
+ helper(entity).__touched = false;
224
224
  }
225
225
  }
226
226
  persist(entity, visited, options = {}) {
227
- entity_1.EntityHelper.ensurePropagation(entity);
227
+ EntityHelper.ensurePropagation(entity);
228
228
  if (options.checkRemoveStack && this.removeStack.has(entity)) {
229
229
  return;
230
230
  }
231
- const wrapped = (0, entity_1.helper)(entity);
231
+ const wrapped = helper(entity);
232
232
  this.persistStack.add(entity);
233
233
  this.queuedActions.add(wrapped.__meta.className);
234
234
  this.removeStack.delete(entity);
@@ -236,43 +236,43 @@ class UnitOfWork {
236
236
  this.identityMap.store(entity);
237
237
  }
238
238
  if (options.cascade ?? true) {
239
- this.cascade(entity, enums_1.Cascade.PERSIST, visited, options);
239
+ this.cascade(entity, Cascade.PERSIST, visited, options);
240
240
  }
241
241
  }
242
242
  remove(entity, visited, options = {}) {
243
243
  // allow removing not managed entities if they are not part of the persist stack
244
- if ((0, entity_1.helper)(entity).__managed || !this.persistStack.has(entity)) {
244
+ if (helper(entity).__managed || !this.persistStack.has(entity)) {
245
245
  this.removeStack.add(entity);
246
- this.queuedActions.add((0, entity_1.helper)(entity).__meta.className);
246
+ this.queuedActions.add(helper(entity).__meta.className);
247
247
  }
248
248
  else {
249
249
  this.persistStack.delete(entity);
250
250
  this.identityMap.delete(entity);
251
251
  }
252
252
  // remove from referencing relations that are nullable
253
- for (const prop of (0, entity_1.helper)(entity).__meta.bidirectionalRelations) {
253
+ for (const prop of helper(entity).__meta.bidirectionalRelations) {
254
254
  const inverseProp = prop.mappedBy || prop.inversedBy;
255
- const relation = entity_1.Reference.unwrapReference(entity[prop.name]);
255
+ const relation = Reference.unwrapReference(entity[prop.name]);
256
256
  const prop2 = prop.targetMeta.properties[inverseProp];
257
- if (prop.kind === enums_1.ReferenceKind.ONE_TO_MANY && prop2.nullable && Utils_1.Utils.isCollection(relation)) {
257
+ if (prop.kind === ReferenceKind.ONE_TO_MANY && prop2.nullable && Utils.isCollection(relation)) {
258
258
  for (const item of relation.getItems(false)) {
259
259
  delete item[inverseProp];
260
260
  }
261
261
  continue;
262
262
  }
263
263
  const target = relation && relation[inverseProp];
264
- if (relation && Utils_1.Utils.isCollection(target)) {
264
+ if (relation && Utils.isCollection(target)) {
265
265
  target.removeWithoutPropagation(entity);
266
266
  }
267
267
  }
268
268
  if (options.cascade ?? true) {
269
- this.cascade(entity, enums_1.Cascade.REMOVE, visited);
269
+ this.cascade(entity, Cascade.REMOVE, visited);
270
270
  }
271
271
  }
272
272
  async commit() {
273
273
  if (this.working) {
274
274
  if (insideFlush.getStore()) {
275
- throw errors_1.ValidationError.cannotCommit();
275
+ throw ValidationError.cannotCommit();
276
276
  }
277
277
  return new Promise((resolve, reject) => {
278
278
  this.flushQueue.push(() => {
@@ -297,15 +297,15 @@ class UnitOfWork {
297
297
  async doCommit() {
298
298
  const oldTx = this.em.getTransactionContext();
299
299
  try {
300
- await this.eventManager.dispatchEvent(enums_1.EventType.beforeFlush, { em: this.em, uow: this });
300
+ await this.eventManager.dispatchEvent(EventType.beforeFlush, { em: this.em, uow: this });
301
301
  this.computeChangeSets();
302
302
  for (const cs of this.changeSets.values()) {
303
303
  cs.entity.__helper.__processing = true;
304
304
  }
305
- await this.eventManager.dispatchEvent(enums_1.EventType.onFlush, { em: this.em, uow: this });
305
+ await this.eventManager.dispatchEvent(EventType.onFlush, { em: this.em, uow: this });
306
306
  // nothing to do, do not start transaction
307
307
  if (this.changeSets.size === 0 && this.collectionUpdates.size === 0 && this.extraUpdates.size === 0) {
308
- return void await this.eventManager.dispatchEvent(enums_1.EventType.afterFlush, { em: this.em, uow: this });
308
+ return void (await this.eventManager.dispatchEvent(EventType.afterFlush, { em: this.em, uow: this }));
309
309
  }
310
310
  const groups = this.getChangeSetGroups();
311
311
  const platform = this.em.getPlatform();
@@ -313,7 +313,7 @@ class UnitOfWork {
313
313
  if (runInTransaction) {
314
314
  await this.em.getConnection('write').transactional(trx => this.persistToDatabase(groups, trx), {
315
315
  ctx: oldTx,
316
- eventBroadcaster: new events_1.TransactionEventBroadcaster(this.em),
316
+ eventBroadcaster: new TransactionEventBroadcaster(this.em),
317
317
  });
318
318
  }
319
319
  else {
@@ -323,18 +323,18 @@ class UnitOfWork {
323
323
  for (const cs of this.changeSets.values()) {
324
324
  cs.entity.__helper.__processing = false;
325
325
  }
326
- await this.eventManager.dispatchEvent(enums_1.EventType.afterFlush, { em: this.em, uow: this });
326
+ await this.eventManager.dispatchEvent(EventType.afterFlush, { em: this.em, uow: this });
327
327
  }
328
328
  finally {
329
329
  this.resetTransaction(oldTx);
330
330
  }
331
331
  }
332
332
  async lock(entity, options) {
333
- if (!this.getById(entity.constructor.name, (0, entity_1.helper)(entity).__primaryKeys, (0, entity_1.helper)(entity).__schema)) {
334
- throw errors_1.ValidationError.entityNotManaged(entity);
333
+ if (!this.getById(entity.constructor.name, helper(entity).__primaryKeys, helper(entity).__schema)) {
334
+ throw ValidationError.entityNotManaged(entity);
335
335
  }
336
336
  const meta = this.metadata.find(entity.constructor.name);
337
- if (options.lockMode === enums_1.LockMode.OPTIMISTIC) {
337
+ if (options.lockMode === LockMode.OPTIMISTIC) {
338
338
  await this.lockOptimistic(entity, meta, options.lockVersion);
339
339
  }
340
340
  else if (options.lockMode != null) {
@@ -348,21 +348,21 @@ class UnitOfWork {
348
348
  }
349
349
  unsetIdentity(entity) {
350
350
  this.identityMap.delete(entity);
351
- const wrapped = (0, entity_1.helper)(entity);
351
+ const wrapped = helper(entity);
352
352
  const serializedPK = wrapped.getSerializedPrimaryKey();
353
353
  // remove references of this entity in all managed entities, otherwise flushing could reinsert the entity
354
354
  for (const { meta, prop } of wrapped.__meta.referencingProperties) {
355
355
  for (const referrer of this.identityMap.getStore(meta).values()) {
356
- const rel = entity_1.Reference.unwrapReference(referrer[prop.name]);
357
- if (Utils_1.Utils.isCollection(rel)) {
356
+ const rel = Reference.unwrapReference(referrer[prop.name]);
357
+ if (Utils.isCollection(rel)) {
358
358
  rel.removeWithoutPropagation(entity);
359
359
  }
360
- else if (rel && (prop.mapToPk ? (0, entity_1.helper)(this.em.getReference(prop.type, rel)).getSerializedPrimaryKey() === serializedPK : rel === entity)) {
360
+ else if (rel && (prop.mapToPk ? helper(this.em.getReference(prop.type, rel)).getSerializedPrimaryKey() === serializedPK : rel === entity)) {
361
361
  if (prop.formula) {
362
362
  delete referrer[prop.name];
363
363
  }
364
364
  else {
365
- delete (0, entity_1.helper)(referrer).__data[prop.name];
365
+ delete helper(referrer).__data[prop.name];
366
366
  }
367
367
  }
368
368
  }
@@ -376,15 +376,15 @@ class UnitOfWork {
376
376
  this.changeSets.clear();
377
377
  const visited = new Set();
378
378
  for (const entity of this.removeStack) {
379
- this.cascade(entity, enums_1.Cascade.REMOVE, visited);
379
+ this.cascade(entity, Cascade.REMOVE, visited);
380
380
  }
381
381
  visited.clear();
382
382
  for (const entity of this.persistStack) {
383
- this.cascade(entity, enums_1.Cascade.PERSIST, visited, { checkRemoveStack: true });
383
+ this.cascade(entity, Cascade.PERSIST, visited, { checkRemoveStack: true });
384
384
  }
385
385
  for (const entity of this.identityMap) {
386
386
  if (!this.removeStack.has(entity) && !this.persistStack.has(entity) && !this.orphanRemoveStack.has(entity)) {
387
- this.cascade(entity, enums_1.Cascade.PERSIST, visited, { checkRemoveStack: true });
387
+ this.cascade(entity, Cascade.PERSIST, visited, { checkRemoveStack: true });
388
388
  }
389
389
  }
390
390
  visited.clear();
@@ -392,34 +392,34 @@ class UnitOfWork {
392
392
  this.findNewEntities(entity, visited);
393
393
  }
394
394
  for (const entity of this.orphanRemoveStack) {
395
- if (!(0, entity_1.helper)(entity).__processing) {
395
+ if (!helper(entity).__processing) {
396
396
  this.removeStack.add(entity);
397
397
  }
398
398
  }
399
399
  // Check insert stack if there are any entities matching something from delete stack. This can happen when recreating entities.
400
400
  const inserts = {};
401
401
  for (const cs of this.changeSets.values()) {
402
- if (cs.type === ChangeSet_1.ChangeSetType.CREATE) {
402
+ if (cs.type === ChangeSetType.CREATE) {
403
403
  inserts[cs.meta.className] ??= [];
404
404
  inserts[cs.meta.className].push(cs);
405
405
  }
406
406
  }
407
407
  for (const cs of this.changeSets.values()) {
408
- if (cs.type === ChangeSet_1.ChangeSetType.UPDATE) {
408
+ if (cs.type === ChangeSetType.UPDATE) {
409
409
  this.findEarlyUpdates(cs, inserts[cs.meta.className]);
410
410
  }
411
411
  }
412
412
  for (const entity of this.removeStack) {
413
- const wrapped = (0, entity_1.helper)(entity);
414
- /* istanbul ignore next */
413
+ const wrapped = helper(entity);
414
+ /* v8 ignore next 3 */
415
415
  if (wrapped.__processing) {
416
416
  continue;
417
417
  }
418
418
  const deletePkHash = [wrapped.getSerializedPrimaryKey(), ...this.expandUniqueProps(entity)];
419
- let type = ChangeSet_1.ChangeSetType.DELETE;
419
+ let type = ChangeSetType.DELETE;
420
420
  for (const cs of inserts[wrapped.__meta.className] ?? []) {
421
421
  if (deletePkHash.some(hash => hash === cs.getSerializedPrimaryKey() || this.expandUniqueProps(cs.entity).find(child => hash === child))) {
422
- type = ChangeSet_1.ChangeSetType.DELETE_EARLY;
422
+ type = ChangeSetType.DELETE_EARLY;
423
423
  }
424
424
  }
425
425
  this.computeChangeSet(entity, type);
@@ -430,7 +430,7 @@ class UnitOfWork {
430
430
  return;
431
431
  }
432
432
  let conflicts = false;
433
- let type = ChangeSet_1.ChangeSetType.UPDATE;
433
+ let type = ChangeSetType.UPDATE;
434
434
  if (!props.some(prop => prop.name in changeSet.payload)) {
435
435
  return;
436
436
  }
@@ -439,7 +439,7 @@ class UnitOfWork {
439
439
  if (prop.name in cs.payload && cs.rootName === changeSet.rootName && cs.type === changeSet.type) {
440
440
  conflicts = true;
441
441
  if (changeSet.payload[prop.name] == null) {
442
- type = ChangeSet_1.ChangeSetType.UPDATE_EARLY;
442
+ type = ChangeSetType.UPDATE_EARLY;
443
443
  }
444
444
  }
445
445
  }
@@ -455,15 +455,15 @@ class UnitOfWork {
455
455
  }
456
456
  scheduleOrphanRemoval(entity, visited) {
457
457
  if (entity) {
458
- (0, entity_1.helper)(entity).__em = this.em;
458
+ helper(entity).__em = this.em;
459
459
  this.orphanRemoveStack.add(entity);
460
460
  this.queuedActions.add(entity.__meta.className);
461
- this.cascade(entity, enums_1.Cascade.SCHEDULE_ORPHAN_REMOVAL, visited);
461
+ this.cascade(entity, Cascade.SCHEDULE_ORPHAN_REMOVAL, visited);
462
462
  }
463
463
  }
464
464
  cancelOrphanRemoval(entity, visited) {
465
465
  this.orphanRemoveStack.delete(entity);
466
- this.cascade(entity, enums_1.Cascade.CANCEL_ORPHAN_REMOVAL, visited);
466
+ this.cascade(entity, Cascade.CANCEL_ORPHAN_REMOVAL, visited);
467
467
  }
468
468
  getOrphanRemoveStack() {
469
469
  return this.orphanRemoveStack;
@@ -477,7 +477,7 @@ class UnitOfWork {
477
477
  }
478
478
  visited.add(entity);
479
479
  processed.add(entity);
480
- const wrapped = (0, entity_1.helper)(entity);
480
+ const wrapped = helper(entity);
481
481
  if (wrapped.__processing || this.removeStack.has(entity) || this.orphanRemoveStack.has(entity)) {
482
482
  return;
483
483
  }
@@ -485,9 +485,9 @@ class UnitOfWork {
485
485
  wrapped.__schema ??= this.em.schema;
486
486
  this.initIdentifier(entity);
487
487
  for (const prop of wrapped.__meta.relations) {
488
- const targets = Utils_1.Utils.unwrapProperty(entity, wrapped.__meta, prop);
488
+ const targets = Utils.unwrapProperty(entity, wrapped.__meta, prop);
489
489
  for (const [target] of targets) {
490
- const kind = entity_1.Reference.unwrapReference(target);
490
+ const kind = Reference.unwrapReference(target);
491
491
  this.processReference(entity, prop, kind, visited, processed, idx);
492
492
  }
493
493
  }
@@ -500,37 +500,37 @@ class UnitOfWork {
500
500
  * Returns `true` when the change set should be skipped as it will be empty after the extra update.
501
501
  */
502
502
  checkUniqueProps(changeSet) {
503
- if (changeSet.type !== ChangeSet_1.ChangeSetType.UPDATE) {
503
+ if (changeSet.type !== ChangeSetType.UPDATE) {
504
504
  return false;
505
505
  }
506
506
  // when changing a unique nullable property (or a 1:1 relation), we can't do it in a single
507
507
  // query as it would cause unique constraint violations
508
508
  const uniqueProps = changeSet.meta.uniqueProps.filter(prop => {
509
- return (prop.nullable || changeSet.type !== ChangeSet_1.ChangeSetType.CREATE);
509
+ return (prop.nullable || changeSet.type !== ChangeSetType.CREATE);
510
510
  });
511
511
  this.scheduleExtraUpdate(changeSet, uniqueProps);
512
- return changeSet.type === ChangeSet_1.ChangeSetType.UPDATE && !Utils_1.Utils.hasObjectKeys(changeSet.payload);
512
+ return changeSet.type === ChangeSetType.UPDATE && !Utils.hasObjectKeys(changeSet.payload);
513
513
  }
514
514
  expandUniqueProps(entity) {
515
- const wrapped = (0, entity_1.helper)(entity);
515
+ const wrapped = helper(entity);
516
516
  if (!wrapped.__meta.hasUniqueProps) {
517
517
  return [];
518
518
  }
519
519
  const simpleUniqueHashes = wrapped.__meta.uniqueProps.map(prop => {
520
520
  if (entity[prop.name] != null) {
521
- return prop.kind === enums_1.ReferenceKind.SCALAR || prop.mapToPk ? entity[prop.name] : (0, entity_1.helper)(entity[prop.name]).getSerializedPrimaryKey();
521
+ return prop.kind === ReferenceKind.SCALAR || prop.mapToPk ? entity[prop.name] : helper(entity[prop.name]).getSerializedPrimaryKey();
522
522
  }
523
523
  if (wrapped.__originalEntityData?.[prop.name] != null) {
524
- return Utils_1.Utils.getPrimaryKeyHash(Utils_1.Utils.asArray(wrapped.__originalEntityData[prop.name]));
524
+ return Utils.getPrimaryKeyHash(Utils.asArray(wrapped.__originalEntityData[prop.name]));
525
525
  }
526
526
  return undefined;
527
527
  }).filter(i => i);
528
528
  const compoundUniqueHashes = wrapped.__meta.uniques.map(unique => {
529
- const props = Utils_1.Utils.asArray(unique.properties);
529
+ const props = Utils.asArray(unique.properties);
530
530
  if (props.every(prop => entity[prop] != null)) {
531
- return Utils_1.Utils.getPrimaryKeyHash(props.map(p => {
531
+ return Utils.getPrimaryKeyHash(props.map(p => {
532
532
  const prop = wrapped.__meta.properties[p];
533
- return prop.kind === enums_1.ReferenceKind.SCALAR || prop.mapToPk ? entity[prop.name] : (0, entity_1.helper)(entity[prop.name]).getSerializedPrimaryKey();
533
+ return prop.kind === ReferenceKind.SCALAR || prop.mapToPk ? entity[prop.name] : helper(entity[prop.name]).getSerializedPrimaryKey();
534
534
  }));
535
535
  }
536
536
  return undefined;
@@ -538,32 +538,41 @@ class UnitOfWork {
538
538
  return simpleUniqueHashes.concat(compoundUniqueHashes);
539
539
  }
540
540
  initIdentifier(entity) {
541
- const wrapped = entity && (0, entity_1.helper)(entity);
541
+ const wrapped = entity && helper(entity);
542
542
  if (!wrapped || wrapped.__identifier || wrapped.hasPrimaryKey()) {
543
543
  return;
544
544
  }
545
- const pk = wrapped.__meta.getPrimaryProps()[0];
546
- if (pk.kind === enums_1.ReferenceKind.SCALAR) {
547
- wrapped.__identifier = new entity_1.EntityIdentifier();
545
+ const pks = wrapped.__meta.getPrimaryProps();
546
+ const idents = [];
547
+ for (const pk of pks) {
548
+ if (pk.kind === ReferenceKind.SCALAR) {
549
+ idents.push(new EntityIdentifier(entity[pk.name]));
550
+ }
551
+ else if (entity[pk.name]) {
552
+ this.initIdentifier(entity[pk.name]);
553
+ idents.push(helper(entity[pk.name])?.__identifier);
554
+ }
555
+ }
556
+ if (pks.length === 1) {
557
+ wrapped.__identifier = idents[0];
548
558
  }
549
- else if (entity[pk.name]) {
550
- this.initIdentifier(entity[pk.name]);
551
- wrapped.__identifier = (0, entity_1.helper)(entity[pk.name])?.__identifier;
559
+ else {
560
+ wrapped.__identifier = idents;
552
561
  }
553
562
  }
554
563
  processReference(parent, prop, kind, visited, processed, idx) {
555
- const isToOne = prop.kind === enums_1.ReferenceKind.MANY_TO_ONE || prop.kind === enums_1.ReferenceKind.ONE_TO_ONE;
556
- if (isToOne && Utils_1.Utils.isEntity(kind)) {
564
+ const isToOne = prop.kind === ReferenceKind.MANY_TO_ONE || prop.kind === ReferenceKind.ONE_TO_ONE;
565
+ if (isToOne && Utils.isEntity(kind)) {
557
566
  return this.processToOneReference(kind, visited, processed, idx);
558
567
  }
559
- if (Utils_1.Utils.isCollection(kind)) {
568
+ if (Utils.isCollection(kind)) {
560
569
  kind.getItems(false)
561
570
  .filter(item => !item.__helper.__originalEntityData)
562
571
  .forEach(item => {
563
572
  // propagate schema from parent
564
- item.__helper.__schema ??= (0, entity_1.helper)(parent).__schema;
573
+ item.__helper.__schema ??= helper(parent).__schema;
565
574
  });
566
- if (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && kind.isDirty()) {
575
+ if (prop.kind === ReferenceKind.MANY_TO_MANY && kind.isDirty()) {
567
576
  this.processToManyReference(kind, visited, processed, parent, prop);
568
577
  }
569
578
  }
@@ -575,8 +584,8 @@ class UnitOfWork {
575
584
  }
576
585
  processToManyReference(collection, visited, processed, parent, prop) {
577
586
  if (this.isCollectionSelfReferenced(collection, processed)) {
578
- this.extraUpdates.add([parent, prop.name, collection, undefined, ChangeSet_1.ChangeSetType.UPDATE]);
579
- const coll = new entity_1.Collection(parent);
587
+ this.extraUpdates.add([parent, prop.name, collection, undefined, ChangeSetType.UPDATE]);
588
+ const coll = new Collection(parent);
580
589
  coll.property = prop;
581
590
  parent[prop.name] = coll;
582
591
  return;
@@ -599,14 +608,21 @@ class UnitOfWork {
599
608
  const current = this.comparator.prepareEntity(changeSet.entity);
600
609
  const diff = this.comparator.diffEntities(changeSet.name, copy, current);
601
610
  Object.assign(changeSet.payload, diff);
602
- const wrapped = (0, entity_1.helper)(changeSet.entity);
603
- if (wrapped.__identifier && diff[wrapped.__meta.primaryKeys[0]]) {
604
- wrapped.__identifier.setValue(diff[wrapped.__meta.primaryKeys[0]]);
611
+ const wrapped = helper(changeSet.entity);
612
+ if (wrapped.__identifier) {
613
+ const idents = Utils.asArray(wrapped.__identifier);
614
+ let i = 0;
615
+ for (const pk of wrapped.__meta.primaryKeys) {
616
+ if (diff[pk]) {
617
+ idents[i].setValue(diff[pk]);
618
+ }
619
+ i++;
620
+ }
605
621
  }
606
622
  }
607
623
  postCommitCleanup() {
608
624
  for (const cs of this.changeSets.values()) {
609
- const wrapped = (0, entity_1.helper)(cs.entity);
625
+ const wrapped = helper(cs.entity);
610
626
  wrapped.__processing = false;
611
627
  delete wrapped.__pk;
612
628
  }
@@ -625,23 +641,23 @@ class UnitOfWork {
625
641
  }
626
642
  visited.add(entity);
627
643
  switch (type) {
628
- case enums_1.Cascade.PERSIST:
644
+ case Cascade.PERSIST:
629
645
  this.persist(entity, visited, options);
630
646
  break;
631
- case enums_1.Cascade.MERGE:
647
+ case Cascade.MERGE:
632
648
  this.merge(entity, visited);
633
649
  break;
634
- case enums_1.Cascade.REMOVE:
650
+ case Cascade.REMOVE:
635
651
  this.remove(entity, visited, options);
636
652
  break;
637
- case enums_1.Cascade.SCHEDULE_ORPHAN_REMOVAL:
653
+ case Cascade.SCHEDULE_ORPHAN_REMOVAL:
638
654
  this.scheduleOrphanRemoval(entity, visited);
639
655
  break;
640
- case enums_1.Cascade.CANCEL_ORPHAN_REMOVAL:
656
+ case Cascade.CANCEL_ORPHAN_REMOVAL:
641
657
  this.cancelOrphanRemoval(entity, visited);
642
658
  break;
643
659
  }
644
- for (const prop of (0, entity_1.helper)(entity).__meta.relations) {
660
+ for (const prop of helper(entity).__meta.relations) {
645
661
  this.cascadeReference(entity, prop, type, visited, options);
646
662
  }
647
663
  }
@@ -650,72 +666,72 @@ class UnitOfWork {
650
666
  if (!this.shouldCascade(prop, type)) {
651
667
  return;
652
668
  }
653
- const kind = entity_1.Reference.unwrapReference(entity[prop.name]);
654
- if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils_1.Utils.isEntity(kind)) {
669
+ const kind = Reference.unwrapReference(entity[prop.name]);
670
+ if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils.isEntity(kind)) {
655
671
  return this.cascade(kind, type, visited, options);
656
672
  }
657
673
  const collection = kind;
658
- if ([enums_1.ReferenceKind.ONE_TO_MANY, enums_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind) && collection) {
674
+ if ([ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind) && collection) {
659
675
  for (const item of collection.getItems(false)) {
660
676
  this.cascade(item, type, visited, options);
661
677
  }
662
678
  }
663
679
  }
664
680
  isCollectionSelfReferenced(collection, processed) {
665
- const filtered = collection.getItems(false).filter(item => !(0, entity_1.helper)(item).__originalEntityData);
681
+ const filtered = collection.getItems(false).filter(item => !helper(item).__originalEntityData);
666
682
  return filtered.some(items => processed.has(items));
667
683
  }
668
684
  shouldCascade(prop, type) {
669
- if ([enums_1.Cascade.REMOVE, enums_1.Cascade.SCHEDULE_ORPHAN_REMOVAL, enums_1.Cascade.CANCEL_ORPHAN_REMOVAL, enums_1.Cascade.ALL].includes(type) && prop.orphanRemoval) {
685
+ if ([Cascade.REMOVE, Cascade.SCHEDULE_ORPHAN_REMOVAL, Cascade.CANCEL_ORPHAN_REMOVAL, Cascade.ALL].includes(type) && prop.orphanRemoval) {
670
686
  return true;
671
687
  }
672
688
  // ignore user settings for merge, it is kept only for back compatibility, this should have never been configurable
673
- if (type === enums_1.Cascade.MERGE) {
689
+ if (type === Cascade.MERGE) {
674
690
  return true;
675
691
  }
676
- return prop.cascade && (prop.cascade.includes(type) || prop.cascade.includes(enums_1.Cascade.ALL));
692
+ return prop.cascade && (prop.cascade.includes(type) || prop.cascade.includes(Cascade.ALL));
677
693
  }
678
694
  async lockPessimistic(entity, options) {
679
695
  if (!this.em.isInTransaction()) {
680
- throw errors_1.ValidationError.transactionRequired();
696
+ throw ValidationError.transactionRequired();
681
697
  }
682
698
  await this.em.getDriver().lockPessimistic(entity, { ctx: this.em.getTransactionContext(), ...options });
683
699
  }
684
700
  async lockOptimistic(entity, meta, version) {
685
701
  if (!meta.versionProperty) {
686
- throw errors_1.OptimisticLockError.notVersioned(meta);
702
+ throw OptimisticLockError.notVersioned(meta);
687
703
  }
688
- if (!Utils_1.Utils.isDefined(version)) {
704
+ if (!Utils.isDefined(version)) {
689
705
  return;
690
706
  }
691
- const wrapped = (0, entity_1.helper)(entity);
707
+ const wrapped = helper(entity);
692
708
  if (!wrapped.__initialized) {
693
709
  await wrapped.init();
694
710
  }
695
711
  const previousVersion = entity[meta.versionProperty];
696
712
  if (previousVersion !== version) {
697
- throw errors_1.OptimisticLockError.lockFailedVersionMismatch(entity, version, previousVersion);
713
+ throw OptimisticLockError.lockFailedVersionMismatch(entity, version, previousVersion);
698
714
  }
699
715
  }
700
716
  fixMissingReference(entity, prop) {
701
717
  const reference = entity[prop.name];
702
- const kind = entity_1.Reference.unwrapReference(reference);
703
- if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && kind && !prop.mapToPk) {
704
- if (!Utils_1.Utils.isEntity(kind)) {
718
+ const kind = Reference.unwrapReference(reference);
719
+ if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind) && kind && !prop.mapToPk) {
720
+ if (!Utils.isEntity(kind)) {
705
721
  entity[prop.name] = this.em.getReference(prop.type, kind, { wrapped: !!prop.ref });
706
722
  }
707
- else if (!(0, entity_1.helper)(kind).__initialized && !(0, entity_1.helper)(kind).__em) {
708
- const pk = (0, entity_1.helper)(kind).getPrimaryKey();
723
+ else if (!helper(kind).__initialized && !helper(kind).__em) {
724
+ const pk = helper(kind).getPrimaryKey();
709
725
  entity[prop.name] = this.em.getReference(prop.type, pk, { wrapped: !!prop.ref });
710
726
  }
711
727
  }
712
728
  // perf: set the `Collection._property` to skip the getter, as it can be slow when there is a lot of relations
713
- if (Utils_1.Utils.isCollection(kind)) {
729
+ if (Utils.isCollection(kind)) {
714
730
  kind.property = prop;
715
731
  }
716
- const isCollection = [enums_1.ReferenceKind.ONE_TO_MANY, enums_1.ReferenceKind.MANY_TO_MANY].includes(prop.kind);
732
+ const isCollection = [ReferenceKind.ONE_TO_MANY, ReferenceKind.MANY_TO_MANY].includes(prop.kind);
717
733
  if (isCollection && Array.isArray(kind)) {
718
- const collection = new entity_1.Collection(entity);
734
+ const collection = new Collection(entity);
719
735
  collection.property = prop;
720
736
  entity[prop.name] = collection;
721
737
  collection.set(kind);
@@ -729,29 +745,29 @@ class UnitOfWork {
729
745
  const commitOrderReversed = [...commitOrder].reverse();
730
746
  // early delete - when we recreate entity in the same UoW, we need to issue those delete queries before inserts
731
747
  for (const name of commitOrderReversed) {
732
- await this.commitDeleteChangeSets(groups[ChangeSet_1.ChangeSetType.DELETE_EARLY].get(name) ?? [], ctx);
748
+ await this.commitDeleteChangeSets(groups[ChangeSetType.DELETE_EARLY].get(name) ?? [], ctx);
733
749
  }
734
750
  // early update - when we recreate entity in the same UoW, we need to issue those delete queries before inserts
735
751
  for (const name of commitOrder) {
736
- await this.commitUpdateChangeSets(groups[ChangeSet_1.ChangeSetType.UPDATE_EARLY].get(name) ?? [], ctx);
752
+ await this.commitUpdateChangeSets(groups[ChangeSetType.UPDATE_EARLY].get(name) ?? [], ctx);
737
753
  }
738
754
  // extra updates
739
- await this.commitExtraUpdates(ChangeSet_1.ChangeSetType.UPDATE_EARLY, ctx);
755
+ await this.commitExtraUpdates(ChangeSetType.UPDATE_EARLY, ctx);
740
756
  // create
741
757
  for (const name of commitOrder) {
742
- await this.commitCreateChangeSets(groups[ChangeSet_1.ChangeSetType.CREATE].get(name) ?? [], ctx);
758
+ await this.commitCreateChangeSets(groups[ChangeSetType.CREATE].get(name) ?? [], ctx);
743
759
  }
744
760
  // update
745
761
  for (const name of commitOrder) {
746
- await this.commitUpdateChangeSets(groups[ChangeSet_1.ChangeSetType.UPDATE].get(name) ?? [], ctx);
762
+ await this.commitUpdateChangeSets(groups[ChangeSetType.UPDATE].get(name) ?? [], ctx);
747
763
  }
748
764
  // extra updates
749
- await this.commitExtraUpdates(ChangeSet_1.ChangeSetType.UPDATE, ctx);
765
+ await this.commitExtraUpdates(ChangeSetType.UPDATE, ctx);
750
766
  // collection updates
751
767
  await this.commitCollectionUpdates(ctx);
752
768
  // delete - entity deletions need to be in reverse commit order
753
769
  for (const name of commitOrderReversed) {
754
- await this.commitDeleteChangeSets(groups[ChangeSet_1.ChangeSetType.DELETE].get(name) ?? [], ctx);
770
+ await this.commitDeleteChangeSets(groups[ChangeSetType.DELETE].get(name) ?? [], ctx);
755
771
  }
756
772
  // take snapshots of all persisted collections
757
773
  const visited = new Set();
@@ -764,30 +780,30 @@ class UnitOfWork {
764
780
  return;
765
781
  }
766
782
  const props = changeSets[0].meta.root.relations.filter(prop => {
767
- return (prop.kind === enums_1.ReferenceKind.ONE_TO_ONE && prop.owner)
768
- || prop.kind === enums_1.ReferenceKind.MANY_TO_ONE
769
- || (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && prop.owner && !this.platform.usesPivotTable());
783
+ return (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner)
784
+ || prop.kind === ReferenceKind.MANY_TO_ONE
785
+ || (prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner && !this.platform.usesPivotTable());
770
786
  });
771
787
  for (const changeSet of changeSets) {
772
788
  this.findExtraUpdates(changeSet, props);
773
- await this.runHooks(enums_1.EventType.beforeCreate, changeSet, true);
789
+ await this.runHooks(EventType.beforeCreate, changeSet, true);
774
790
  }
775
791
  await this.changeSetPersister.executeInserts(changeSets, { ctx });
776
792
  for (const changeSet of changeSets) {
777
793
  this.register(changeSet.entity, changeSet.payload, { refresh: true });
778
- await this.runHooks(enums_1.EventType.afterCreate, changeSet);
794
+ await this.runHooks(EventType.afterCreate, changeSet);
779
795
  }
780
796
  }
781
797
  findExtraUpdates(changeSet, props) {
782
798
  for (const prop of props) {
783
799
  const ref = changeSet.entity[prop.name];
784
- if (!ref || prop.deferMode === enums_1.DeferMode.INITIALLY_DEFERRED) {
800
+ if (!ref || prop.deferMode === DeferMode.INITIALLY_DEFERRED) {
785
801
  continue;
786
802
  }
787
- if (Utils_1.Utils.isCollection(ref)) {
803
+ if (Utils.isCollection(ref)) {
788
804
  ref.getItems(false).some(item => {
789
- const cs = this.changeSets.get(entity_1.Reference.unwrapReference(item));
790
- const isScheduledForInsert = cs && cs.type === ChangeSet_1.ChangeSetType.CREATE && !cs.persisted;
805
+ const cs = this.changeSets.get(Reference.unwrapReference(item));
806
+ const isScheduledForInsert = cs && cs.type === ChangeSetType.CREATE && !cs.persisted;
791
807
  if (isScheduledForInsert) {
792
808
  this.scheduleExtraUpdate(changeSet, [prop]);
793
809
  return true;
@@ -795,8 +811,8 @@ class UnitOfWork {
795
811
  return false;
796
812
  });
797
813
  }
798
- const cs = this.changeSets.get(entity_1.Reference.unwrapReference(ref));
799
- const isScheduledForInsert = cs && cs.type === ChangeSet_1.ChangeSetType.CREATE && !cs.persisted;
814
+ const cs = this.changeSets.get(Reference.unwrapReference(ref));
815
+ const isScheduledForInsert = cs && cs.type === ChangeSetType.CREATE && !cs.persisted;
800
816
  if (isScheduledForInsert) {
801
817
  this.scheduleExtraUpdate(changeSet, [prop]);
802
818
  }
@@ -805,14 +821,14 @@ class UnitOfWork {
805
821
  findEarlyUpdates(changeSet, inserts = []) {
806
822
  const props = changeSet.meta.uniqueProps;
807
823
  for (const prop of props) {
808
- const insert = inserts.find(c => Utils_1.Utils.equals(c.payload[prop.name], changeSet.originalEntity[prop.name]));
824
+ const insert = inserts.find(c => Utils.equals(c.payload[prop.name], changeSet.originalEntity[prop.name]));
809
825
  const propEmpty = changeSet.payload[prop.name] === null || changeSet.payload[prop.name] === undefined;
810
826
  if (prop.name in changeSet.payload &&
811
827
  insert &&
812
828
  // We only want to update early if the unique property on the changeset is going to be empty, so that
813
829
  // the previous unique value can be set on a different entity without constraint issues
814
830
  propEmpty) {
815
- changeSet.type = ChangeSet_1.ChangeSetType.UPDATE_EARLY;
831
+ changeSet.type = ChangeSetType.UPDATE_EARLY;
816
832
  }
817
833
  }
818
834
  }
@@ -821,14 +837,14 @@ class UnitOfWork {
821
837
  return;
822
838
  }
823
839
  for (const changeSet of changeSets) {
824
- await this.runHooks(enums_1.EventType.beforeUpdate, changeSet, true);
840
+ await this.runHooks(EventType.beforeUpdate, changeSet, true);
825
841
  }
826
842
  await this.changeSetPersister.executeUpdates(changeSets, batched, { ctx });
827
843
  for (const changeSet of changeSets) {
828
- (0, entity_1.helper)(changeSet.entity).__originalEntityData = this.comparator.prepareEntity(changeSet.entity);
829
- (0, entity_1.helper)(changeSet.entity).__touched = false;
830
- (0, entity_1.helper)(changeSet.entity).__initialized = true;
831
- await this.runHooks(enums_1.EventType.afterUpdate, changeSet);
844
+ helper(changeSet.entity).__originalEntityData = this.comparator.prepareEntity(changeSet.entity);
845
+ helper(changeSet.entity).__touched = false;
846
+ helper(changeSet.entity).__initialized = true;
847
+ await this.runHooks(EventType.afterUpdate, changeSet);
832
848
  }
833
849
  }
834
850
  async commitDeleteChangeSets(changeSets, ctx) {
@@ -836,12 +852,12 @@ class UnitOfWork {
836
852
  return;
837
853
  }
838
854
  for (const changeSet of changeSets) {
839
- await this.runHooks(enums_1.EventType.beforeDelete, changeSet, true);
855
+ await this.runHooks(EventType.beforeDelete, changeSet, true);
840
856
  }
841
857
  await this.changeSetPersister.executeDeletes(changeSets, { ctx });
842
858
  for (const changeSet of changeSets) {
843
859
  this.unsetIdentity(changeSet.entity);
844
- await this.runHooks(enums_1.EventType.afterDelete, changeSet);
860
+ await this.runHooks(EventType.afterDelete, changeSet);
845
861
  }
846
862
  }
847
863
  async commitExtraUpdates(type, ctx) {
@@ -877,14 +893,14 @@ class UnitOfWork {
877
893
  collectionUpdates.push(coll);
878
894
  }
879
895
  }
880
- else if (coll.property.kind === enums_1.ReferenceKind.ONE_TO_MANY && coll.getSnapshot() === undefined) {
896
+ else if (coll.property.kind === ReferenceKind.ONE_TO_MANY && coll.getSnapshot() === undefined) {
881
897
  collectionUpdates.push(coll);
882
898
  }
883
- else if (coll.property.kind === enums_1.ReferenceKind.MANY_TO_MANY && !coll.property.owner) {
899
+ else if (coll.property.kind === ReferenceKind.MANY_TO_MANY && !coll.property.owner) {
884
900
  collectionUpdates.push(coll);
885
901
  }
886
902
  }
887
- await this.em.getDriver().syncCollections(collectionUpdates, { ctx });
903
+ await this.em.getDriver().syncCollections(collectionUpdates, { ctx, schema: this.em.schema });
888
904
  for (const coll of this.collectionUpdates) {
889
905
  coll.takeSnapshot();
890
906
  }
@@ -894,11 +910,11 @@ class UnitOfWork {
894
910
  */
895
911
  getChangeSetGroups() {
896
912
  const groups = {
897
- [ChangeSet_1.ChangeSetType.CREATE]: new Map(),
898
- [ChangeSet_1.ChangeSetType.UPDATE]: new Map(),
899
- [ChangeSet_1.ChangeSetType.DELETE]: new Map(),
900
- [ChangeSet_1.ChangeSetType.UPDATE_EARLY]: new Map(),
901
- [ChangeSet_1.ChangeSetType.DELETE_EARLY]: new Map(),
913
+ [ChangeSetType.CREATE]: new Map(),
914
+ [ChangeSetType.UPDATE]: new Map(),
915
+ [ChangeSetType.DELETE]: new Map(),
916
+ [ChangeSetType.UPDATE_EARLY]: new Map(),
917
+ [ChangeSetType.DELETE_EARLY]: new Map(),
902
918
  };
903
919
  for (const cs of this.changeSets.values()) {
904
920
  const group = groups[cs.type];
@@ -911,7 +927,7 @@ class UnitOfWork {
911
927
  return groups;
912
928
  }
913
929
  getCommitOrder() {
914
- const calc = new CommitOrderCalculator_1.CommitOrderCalculator();
930
+ const calc = new CommitOrderCalculator();
915
931
  const set = new Set();
916
932
  this.changeSets.forEach(cs => set.add(cs.rootName));
917
933
  set.forEach(entityName => calc.addNode(entityName));
@@ -938,16 +954,15 @@ class UnitOfWork {
938
954
  return;
939
955
  }
940
956
  visited.add(entity);
941
- (0, entity_1.helper)(entity)?.__meta.relations.forEach(prop => {
957
+ helper(entity)?.__meta.relations.forEach(prop => {
942
958
  const value = entity[prop.name];
943
- if (Utils_1.Utils.isCollection(value)) {
959
+ if (Utils.isCollection(value)) {
944
960
  value.takeSnapshot();
945
961
  }
946
962
  // cascade to m:1 relations as we need to snapshot the 1:m inverse side (for `removeAll()` with orphan removal)
947
- if (prop.kind === enums_1.ReferenceKind.MANY_TO_ONE && value) {
948
- this.takeCollectionSnapshots(entity_1.Reference.unwrapReference(value), visited);
963
+ if (prop.kind === ReferenceKind.MANY_TO_ONE && value) {
964
+ this.takeCollectionSnapshots(Reference.unwrapReference(value), visited);
949
965
  }
950
966
  });
951
967
  }
952
968
  }
953
- exports.UnitOfWork = UnitOfWork;