@mikro-orm/core 7.0.0-dev.0 → 7.0.0-dev.10

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,11 +1,8 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChangeSetComputer = void 0;
4
- const Utils_1 = require("../utils/Utils");
5
- const ChangeSet_1 = require("./ChangeSet");
6
- const entity_1 = require("../entity");
7
- const enums_1 = require("../enums");
8
- class ChangeSetComputer {
1
+ import { Utils } from '../utils/Utils.js';
2
+ import { ChangeSet, ChangeSetType } from './ChangeSet.js';
3
+ import { helper } from '../entity/wrap.js';
4
+ import { ReferenceKind } from '../enums.js';
5
+ export class ChangeSetComputer {
9
6
  validator;
10
7
  collectionUpdates;
11
8
  metadata;
@@ -27,20 +24,20 @@ class ChangeSetComputer {
27
24
  if (meta.readonly) {
28
25
  return null;
29
26
  }
30
- const wrapped = (0, entity_1.helper)(entity);
31
- const type = wrapped.__originalEntityData ? ChangeSet_1.ChangeSetType.UPDATE : ChangeSet_1.ChangeSetType.CREATE;
27
+ const wrapped = helper(entity);
28
+ const type = wrapped.__originalEntityData ? ChangeSetType.UPDATE : ChangeSetType.CREATE;
32
29
  const map = new Map();
33
30
  // Execute `onCreate` and `onUpdate` on properties recursively, saves `onUpdate` results
34
31
  // to the `map` as we want to apply those only if something else changed.
35
- if (type === ChangeSet_1.ChangeSetType.CREATE) { // run update hooks only after we know there are other changes
32
+ if (type === ChangeSetType.CREATE) { // run update hooks only after we know there are other changes
36
33
  for (const prop of meta.hydrateProps) {
37
34
  this.processPropertyInitializers(entity, prop, type, map);
38
35
  }
39
36
  }
40
- if (type === ChangeSet_1.ChangeSetType.UPDATE && !wrapped.__initialized && !wrapped.isTouched()) {
37
+ if (type === ChangeSetType.UPDATE && !wrapped.__initialized && !wrapped.isTouched()) {
41
38
  return null;
42
39
  }
43
- const changeSet = new ChangeSet_1.ChangeSet(entity, type, this.computePayload(entity), meta);
40
+ const changeSet = new ChangeSet(entity, type, this.computePayload(entity), meta);
44
41
  changeSet.originalEntity = wrapped.__originalEntityData;
45
42
  if (this.config.get('validate')) {
46
43
  this.validator.validate(changeSet.entity, changeSet.payload, meta);
@@ -48,12 +45,12 @@ class ChangeSetComputer {
48
45
  for (const prop of meta.relations.filter(prop => prop.persist !== false || prop.userDefined === false)) {
49
46
  this.processProperty(changeSet, prop);
50
47
  }
51
- if (changeSet.type === ChangeSet_1.ChangeSetType.UPDATE && !Utils_1.Utils.hasObjectKeys(changeSet.payload)) {
48
+ if (changeSet.type === ChangeSetType.UPDATE && !Utils.hasObjectKeys(changeSet.payload)) {
52
49
  return null;
53
50
  }
54
51
  // Execute `onCreate` and `onUpdate` on properties recursively, saves `onUpdate` results
55
52
  // to the `map` as we want to apply those only if something else changed.
56
- if (type === ChangeSet_1.ChangeSetType.UPDATE) {
53
+ if (type === ChangeSetType.UPDATE) {
57
54
  for (const prop of meta.hydrateProps) {
58
55
  this.processPropertyInitializers(entity, prop, type, map);
59
56
  }
@@ -66,7 +63,7 @@ class ChangeSetComputer {
66
63
  }
67
64
  // Recompute the changeset, we need to merge this as here we ignore relations.
68
65
  const diff = this.computePayload(entity, true);
69
- Utils_1.Utils.merge(changeSet.payload, diff);
66
+ Utils.merge(changeSet.payload, diff);
70
67
  }
71
68
  return changeSet;
72
69
  }
@@ -75,17 +72,17 @@ class ChangeSetComputer {
75
72
  */
76
73
  processPropertyInitializers(entity, prop, type, map, nested) {
77
74
  if (prop.onCreate
78
- && type === ChangeSet_1.ChangeSetType.CREATE
75
+ && type === ChangeSetType.CREATE
79
76
  && (entity[prop.name] == null
80
- || (Utils_1.Utils.isScalarReference(entity[prop.name]) && entity[prop.name].unwrap() == null))) {
77
+ || (Utils.isScalarReference(entity[prop.name]) && entity[prop.name].unwrap() == null))) {
81
78
  entity[prop.name] = prop.onCreate(entity, this.em);
82
79
  }
83
- if (prop.onUpdate && type === ChangeSet_1.ChangeSetType.UPDATE) {
80
+ if (prop.onUpdate && type === ChangeSetType.UPDATE) {
84
81
  const pairs = map.get(entity) ?? [];
85
82
  pairs.push([prop.name, prop.onUpdate(entity, this.em)]);
86
83
  map.set(entity, pairs);
87
84
  }
88
- if (prop.kind === enums_1.ReferenceKind.EMBEDDED && entity[prop.name]) {
85
+ if (prop.kind === ReferenceKind.EMBEDDED && entity[prop.name]) {
89
86
  for (const embeddedProp of prop.targetMeta.hydrateProps) {
90
87
  this.processPropertyInitializers(entity[prop.name], embeddedProp, type, map, nested || prop.object);
91
88
  }
@@ -93,7 +90,7 @@ class ChangeSetComputer {
93
90
  }
94
91
  computePayload(entity, ignoreUndefined = false) {
95
92
  const data = this.comparator.prepareEntity(entity);
96
- const wrapped = (0, entity_1.helper)(entity);
93
+ const wrapped = helper(entity);
97
94
  const entityName = wrapped.__meta.className;
98
95
  const originalEntityData = wrapped.__originalEntityData;
99
96
  if (!wrapped.__initialized) {
@@ -106,7 +103,7 @@ class ChangeSetComputer {
106
103
  const comparator = this.comparator.getEntityComparator(entityName);
107
104
  const diff = comparator(originalEntityData, data);
108
105
  if (ignoreUndefined) {
109
- Utils_1.Utils.keys(diff)
106
+ Utils.keys(diff)
110
107
  .filter(k => diff[k] === undefined)
111
108
  .forEach(k => delete diff[k]);
112
109
  }
@@ -116,32 +113,32 @@ class ChangeSetComputer {
116
113
  }
117
114
  processProperty(changeSet, prop, target) {
118
115
  if (!target) {
119
- const targets = Utils_1.Utils.unwrapProperty(changeSet.entity, changeSet.meta, prop);
116
+ const targets = Utils.unwrapProperty(changeSet.entity, changeSet.meta, prop);
120
117
  targets.forEach(([t]) => this.processProperty(changeSet, prop, t));
121
118
  return;
122
119
  }
123
- if (Utils_1.Utils.isCollection(target)) { // m:n or 1:m
120
+ if (Utils.isCollection(target)) { // m:n or 1:m
124
121
  this.processToMany(prop, changeSet);
125
122
  }
126
- if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
123
+ if ([ReferenceKind.MANY_TO_ONE, ReferenceKind.ONE_TO_ONE].includes(prop.kind)) {
127
124
  this.processToOne(prop, changeSet);
128
125
  }
129
126
  }
130
127
  processToOne(prop, changeSet) {
131
- const isToOneOwner = prop.kind === enums_1.ReferenceKind.MANY_TO_ONE || (prop.kind === enums_1.ReferenceKind.ONE_TO_ONE && prop.owner);
128
+ const isToOneOwner = prop.kind === ReferenceKind.MANY_TO_ONE || (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner);
132
129
  if (!isToOneOwner || prop.mapToPk) {
133
130
  return;
134
131
  }
135
- const targets = Utils_1.Utils.unwrapProperty(changeSet.entity, changeSet.meta, prop);
132
+ const targets = Utils.unwrapProperty(changeSet.entity, changeSet.meta, prop);
136
133
  targets.forEach(([target, idx]) => {
137
134
  if (!target.__helper.hasPrimaryKey()) {
138
- Utils_1.Utils.setPayloadProperty(changeSet.payload, this.metadata.find(changeSet.name), prop, target.__helper.__identifier, idx);
135
+ Utils.setPayloadProperty(changeSet.payload, this.metadata.find(changeSet.name), prop, target.__helper.__identifier, idx);
139
136
  }
140
137
  });
141
138
  }
142
139
  processToMany(prop, changeSet) {
143
140
  const target = changeSet.entity[prop.name];
144
- if (!target.isDirty() && changeSet.type !== ChangeSet_1.ChangeSetType.CREATE) {
141
+ if (!target.isDirty() && changeSet.type !== ChangeSetType.CREATE) {
145
142
  return;
146
143
  }
147
144
  this.collectionUpdates.add(target);
@@ -150,4 +147,3 @@ class ChangeSetComputer {
150
147
  }
151
148
  }
152
149
  }
153
- exports.ChangeSetComputer = ChangeSetComputer;
@@ -1,9 +1,10 @@
1
- import type { MetadataStorage } from '../metadata';
2
- import type { Dictionary, EntityDictionary, EntityMetadata, IHydrator } from '../typings';
3
- import { type EntityFactory, type EntityValidator } from '../entity';
4
- import { type ChangeSet } from './ChangeSet';
5
- import { type Configuration } from '../utils/Configuration';
6
- import type { DriverMethodOptions, IDatabaseDriver } from '../drivers';
1
+ import type { MetadataStorage } from '../metadata/MetadataStorage.js';
2
+ import type { Dictionary, EntityDictionary, EntityMetadata, IHydrator } from '../typings.js';
3
+ import { type EntityFactory } from '../entity/EntityFactory.js';
4
+ import { type EntityValidator } from '../entity/EntityValidator.js';
5
+ import { type ChangeSet } from './ChangeSet.js';
6
+ import { type Configuration } from '../utils/Configuration.js';
7
+ import type { DriverMethodOptions, IDatabaseDriver } from '../drivers/IDatabaseDriver.js';
7
8
  export declare class ChangeSetPersister {
8
9
  private readonly driver;
9
10
  private readonly metadata;
@@ -1,13 +1,11 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChangeSetPersister = void 0;
4
- const entity_1 = require("../entity");
5
- const ChangeSet_1 = require("./ChangeSet");
6
- const RawQueryFragment_1 = require("../utils/RawQueryFragment");
7
- const Utils_1 = require("../utils/Utils");
8
- const errors_1 = require("../errors");
9
- const enums_1 = require("../enums");
10
- class ChangeSetPersister {
1
+ import { EntityIdentifier } from '../entity/EntityIdentifier.js';
2
+ import { helper } from '../entity/wrap.js';
3
+ import { ChangeSetType } from './ChangeSet.js';
4
+ import { isRaw } from '../utils/RawQueryFragment.js';
5
+ import { Utils } from '../utils/Utils.js';
6
+ import { OptimisticLockError } from '../errors.js';
7
+ import { ReferenceKind } from '../enums.js';
8
+ export class ChangeSetPersister {
11
9
  driver;
12
10
  metadata;
13
11
  hydrator;
@@ -60,7 +58,7 @@ class ChangeSetPersister {
60
58
  }
61
59
  const size = this.config.get('batchSize');
62
60
  const meta = changeSets[0].meta;
63
- const pk = Utils_1.Utils.getPrimaryKeyHash(meta.primaryKeys);
61
+ const pk = Utils.getPrimaryKeyHash(meta.primaryKeys);
64
62
  for (let i = 0; i < changeSets.length; i += size) {
65
63
  const chunk = changeSets.slice(i, i + size);
66
64
  const pks = chunk.map(cs => cs.getPrimaryKey());
@@ -86,12 +84,12 @@ class ChangeSetPersister {
86
84
  for (const prop of meta.relations) {
87
85
  this.processProperty(changeSet, prop);
88
86
  }
89
- if (changeSet.type === ChangeSet_1.ChangeSetType.CREATE && this.config.get('validateRequired')) {
87
+ if (changeSet.type === ChangeSetType.CREATE && this.config.get('validateRequired')) {
90
88
  this.validator.validateRequired(changeSet.entity);
91
89
  }
92
90
  }
93
91
  async persistNewEntity(meta, changeSet, options) {
94
- const wrapped = (0, entity_1.helper)(changeSet.entity);
92
+ const wrapped = helper(changeSet.entity);
95
93
  options = this.propagateSchemaFromMetadata(meta, options, {
96
94
  convertCustomTypes: false,
97
95
  });
@@ -133,7 +131,7 @@ class ChangeSetPersister {
133
131
  const res = await this.driver.nativeInsertMany(meta.className, changeSets.map(cs => cs.payload), options);
134
132
  for (let i = 0; i < changeSets.length; i++) {
135
133
  const changeSet = changeSets[i];
136
- const wrapped = (0, entity_1.helper)(changeSet.entity);
134
+ const wrapped = helper(changeSet.entity);
137
135
  if (!wrapped.hasPrimaryKey()) {
138
136
  const field = meta.getPrimaryProps()[0].fieldNames[0];
139
137
  this.mapPrimaryKey(meta, res.rows[i][field], changeSet);
@@ -172,7 +170,7 @@ class ChangeSetPersister {
172
170
  }
173
171
  }
174
172
  if (tmp.length === 0 && meta.concurrencyCheckKeys.size > 0) {
175
- throw errors_1.OptimisticLockError.lockFailed(changeSet.entity);
173
+ throw OptimisticLockError.lockFailed(changeSet.entity);
176
174
  }
177
175
  }
178
176
  async persistManagedEntitiesBatch(meta, changeSets, options) {
@@ -191,10 +189,10 @@ class ChangeSetPersister {
191
189
  }
192
190
  const res = await this.driver.nativeUpdateMany(meta.className, cond, payload, options);
193
191
  const map = new Map();
194
- res.rows?.forEach(item => map.set(Utils_1.Utils.getCompositeKeyHash(item, meta, true, this.platform, true), item));
192
+ res.rows?.forEach(item => map.set(Utils.getCompositeKeyHash(item, meta, true, this.platform, true), item));
195
193
  for (const changeSet of changeSets) {
196
194
  if (res.rows) {
197
- const row = map.get((0, entity_1.helper)(changeSet.entity).getSerializedPrimaryKey());
195
+ const row = map.get(helper(changeSet.entity).getSerializedPrimaryKey());
198
196
  this.mapReturnedValues(changeSet.entity, changeSet.payload, row, meta);
199
197
  }
200
198
  changeSet.persisted = true;
@@ -203,7 +201,7 @@ class ChangeSetPersister {
203
201
  mapPrimaryKey(meta, value, changeSet) {
204
202
  const prop = meta.properties[meta.primaryKeys[0]];
205
203
  const insertId = prop.customType ? prop.customType.convertToJSValue(value, this.platform) : value;
206
- const wrapped = (0, entity_1.helper)(changeSet.entity);
204
+ const wrapped = helper(changeSet.entity);
207
205
  if (!wrapped.hasPrimaryKey()) {
208
206
  wrapped.setPrimaryKey(insertId);
209
207
  }
@@ -212,23 +210,25 @@ class ChangeSetPersister {
212
210
  // of using the raw value from db, we convert it back to the db value explicitly
213
211
  value = prop.customType ? prop.customType.convertToDatabaseValue(insertId, this.platform, { mode: 'serialization' }) : value;
214
212
  changeSet.payload[wrapped.__meta.primaryKeys[0]] = value;
215
- wrapped.__identifier?.setValue(value);
213
+ if (wrapped.__identifier && !Array.isArray(wrapped.__identifier)) {
214
+ wrapped.__identifier.setValue(value);
215
+ }
216
216
  }
217
217
  /**
218
218
  * Sets populate flag to new entities so they are serialized like if they were loaded from the db
219
219
  */
220
220
  markAsPopulated(changeSet, meta) {
221
- (0, entity_1.helper)(changeSet.entity).__schema = this.driver.getSchemaName(meta, changeSet);
221
+ helper(changeSet.entity).__schema = this.driver.getSchemaName(meta, changeSet);
222
222
  if (!this.config.get('populateAfterFlush')) {
223
223
  return;
224
224
  }
225
- (0, entity_1.helper)(changeSet.entity).populated();
225
+ helper(changeSet.entity).populated();
226
226
  meta.relations.forEach(prop => {
227
227
  const value = changeSet.entity[prop.name];
228
- if (Utils_1.Utils.isEntity(value, true)) {
228
+ if (Utils.isEntity(value, true)) {
229
229
  value.__helper.populated();
230
230
  }
231
- else if (Utils_1.Utils.isCollection(value)) {
231
+ else if (Utils.isCollection(value)) {
232
232
  value.populated();
233
233
  }
234
234
  });
@@ -252,9 +252,9 @@ class ChangeSetPersister {
252
252
  return;
253
253
  }
254
254
  // skip entity references as they don't have version values loaded
255
- changeSets = changeSets.filter(cs => (0, entity_1.helper)(cs.entity).__initialized);
255
+ changeSets = changeSets.filter(cs => helper(cs.entity).__initialized);
256
256
  const $or = changeSets.map(cs => {
257
- const cond = Utils_1.Utils.getPrimaryKeyCond(cs.originalEntity, meta.primaryKeys.concat(...meta.concurrencyCheckKeys));
257
+ const cond = Utils.getPrimaryKeyCond(cs.originalEntity, meta.primaryKeys.concat(...meta.concurrencyCheckKeys));
258
258
  if (meta.versionProperty) {
259
259
  // @ts-ignore
260
260
  cond[meta.versionProperty] = this.platform.quoteVersionValue(cs.entity[meta.versionProperty], meta.properties[meta.versionProperty]);
@@ -269,14 +269,14 @@ class ChangeSetPersister {
269
269
  if (res.length !== changeSets.length) {
270
270
  const compare = (a, b, keys) => keys.every(k => a[k] === b[k]);
271
271
  const entity = changeSets.find(cs => {
272
- return !res.some(row => compare(Utils_1.Utils.getPrimaryKeyCond(cs.entity, primaryKeys), row, primaryKeys));
272
+ return !res.some(row => compare(Utils.getPrimaryKeyCond(cs.entity, primaryKeys), row, primaryKeys));
273
273
  }).entity;
274
- throw errors_1.OptimisticLockError.lockFailed(entity);
274
+ throw OptimisticLockError.lockFailed(entity);
275
275
  }
276
276
  }
277
277
  checkOptimisticLock(meta, changeSet, res) {
278
278
  if ((meta.versionProperty || meta.concurrencyCheckKeys.size > 0) && res && !res.affectedRows) {
279
- throw errors_1.OptimisticLockError.lockFailed(changeSet.entity);
279
+ throw OptimisticLockError.lockFailed(changeSet.entity);
280
280
  }
281
281
  }
282
282
  /**
@@ -285,18 +285,18 @@ class ChangeSetPersister {
285
285
  */
286
286
  async reloadVersionValues(meta, changeSets, options) {
287
287
  const reloadProps = meta.versionProperty && !this.usesReturningStatement ? [meta.properties[meta.versionProperty]] : [];
288
- if (changeSets[0].type === ChangeSet_1.ChangeSetType.CREATE) {
288
+ if (changeSets[0].type === ChangeSetType.CREATE) {
289
289
  // do not reload things that already had a runtime value
290
290
  meta.props
291
291
  .filter(prop => prop.persist !== false && (prop.autoincrement || prop.generated || prop.defaultRaw))
292
- .filter(prop => (changeSets[0].entity[prop.name] == null && prop.defaultRaw !== 'null') || (0, RawQueryFragment_1.isRaw)(changeSets[0].entity[prop.name]))
292
+ .filter(prop => (changeSets[0].entity[prop.name] == null && prop.defaultRaw !== 'null') || isRaw(changeSets[0].entity[prop.name]))
293
293
  .forEach(prop => reloadProps.push(prop));
294
294
  }
295
- if (changeSets[0].type === ChangeSet_1.ChangeSetType.UPDATE) {
295
+ if (changeSets[0].type === ChangeSetType.UPDATE) {
296
296
  const returning = new Set();
297
297
  changeSets.forEach(cs => {
298
- Utils_1.Utils.keys(cs.payload).forEach(k => {
299
- if ((0, RawQueryFragment_1.isRaw)(cs.payload[k]) && (0, RawQueryFragment_1.isRaw)(cs.entity[k])) {
298
+ Utils.keys(cs.payload).forEach(k => {
299
+ if (isRaw(cs.payload[k]) && isRaw(cs.entity[k])) {
300
300
  returning.add(meta.properties[k]);
301
301
  }
302
302
  });
@@ -313,22 +313,22 @@ class ChangeSetPersister {
313
313
  return;
314
314
  }
315
315
  reloadProps.unshift(...meta.getPrimaryProps());
316
- const pk = Utils_1.Utils.getPrimaryKeyHash(meta.primaryKeys);
316
+ const pk = Utils.getPrimaryKeyHash(meta.primaryKeys);
317
317
  const pks = changeSets.map(cs => {
318
- const val = (0, entity_1.helper)(cs.entity).getPrimaryKey(true);
319
- if (Utils_1.Utils.isPlainObject(val)) {
320
- return Utils_1.Utils.getCompositeKeyValue(val, meta, false, this.platform);
318
+ const val = helper(cs.entity).getPrimaryKey(true);
319
+ if (Utils.isPlainObject(val)) {
320
+ return Utils.getCompositeKeyValue(val, meta, false, this.platform);
321
321
  }
322
322
  return val;
323
323
  });
324
324
  options = this.propagateSchemaFromMetadata(meta, options, {
325
- fields: Utils_1.Utils.unique(reloadProps.map(prop => prop.name)),
325
+ fields: Utils.unique(reloadProps.map(prop => prop.name)),
326
326
  });
327
327
  const data = await this.driver.find(meta.className, { [pk]: { $in: pks } }, options);
328
328
  const map = new Map();
329
- data.forEach(item => map.set(Utils_1.Utils.getCompositeKeyHash(item, meta, true, this.platform, true), item));
329
+ data.forEach(item => map.set(Utils.getCompositeKeyHash(item, meta, true, this.platform, true), item));
330
330
  for (const changeSet of changeSets) {
331
- const data = map.get((0, entity_1.helper)(changeSet.entity).getSerializedPrimaryKey());
331
+ const data = map.get(helper(changeSet.entity).getSerializedPrimaryKey());
332
332
  this.hydrator.hydrate(changeSet.entity, meta, data, this.factory, 'full', false, true);
333
333
  Object.assign(changeSet.payload, data); // merge to the changeset payload, so it gets saved to the entity snapshot
334
334
  }
@@ -336,21 +336,25 @@ class ChangeSetPersister {
336
336
  processProperty(changeSet, prop) {
337
337
  const meta = this.metadata.find(changeSet.name);
338
338
  const value = changeSet.payload[prop.name]; // for inline embeddables
339
- if (value instanceof entity_1.EntityIdentifier) {
339
+ if (value instanceof EntityIdentifier) {
340
340
  changeSet.payload[prop.name] = value.getValue();
341
341
  return;
342
342
  }
343
- if (prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && Array.isArray(value)) {
344
- changeSet.payload[prop.name] = value.map(val => val instanceof entity_1.EntityIdentifier ? val.getValue() : val);
343
+ if (Array.isArray(value) && value.every(item => item instanceof EntityIdentifier)) {
344
+ changeSet.payload[prop.name] = value.map(item => item.getValue());
345
+ return;
346
+ }
347
+ if (prop.kind === ReferenceKind.MANY_TO_MANY && Array.isArray(value)) {
348
+ changeSet.payload[prop.name] = value.map(val => val instanceof EntityIdentifier ? val.getValue() : val);
345
349
  return;
346
350
  }
347
351
  if (prop.name in changeSet.payload) {
348
352
  return;
349
353
  }
350
- const values = Utils_1.Utils.unwrapProperty(changeSet.payload, meta, prop, true); // for object embeddables
354
+ const values = Utils.unwrapProperty(changeSet.payload, meta, prop, true); // for object embeddables
351
355
  values.forEach(([value, indexes]) => {
352
- if (value instanceof entity_1.EntityIdentifier) {
353
- Utils_1.Utils.setPayloadProperty(changeSet.payload, meta, prop, value.getValue(), indexes);
356
+ if (value instanceof EntityIdentifier) {
357
+ Utils.setPayloadProperty(changeSet.payload, meta, prop, value.getValue(), indexes);
354
358
  }
355
359
  });
356
360
  }
@@ -360,7 +364,7 @@ class ChangeSetPersister {
360
364
  * We do need to map to the change set payload too, as it will be used in the originalEntityData for new entities.
361
365
  */
362
366
  mapReturnedValues(entity, payload, row, meta, upsert = false) {
363
- if ((!this.usesReturningStatement && !upsert) || !row || !Utils_1.Utils.hasObjectKeys(row)) {
367
+ if ((!this.usesReturningStatement && !upsert) || !row || !Utils.hasObjectKeys(row)) {
364
368
  return;
365
369
  }
366
370
  const mapped = this.comparator.mapResult(meta.className, row);
@@ -377,4 +381,3 @@ class ChangeSetPersister {
377
381
  Object.assign(payload, mapped);
378
382
  }
379
383
  }
380
- exports.ChangeSetPersister = ChangeSetPersister;
@@ -1,4 +1,4 @@
1
- import type { Dictionary, EntityProperty } from '../typings';
1
+ import type { Dictionary, EntityProperty } from '../typings.js';
2
2
  export declare const enum NodeState {
3
3
  NOT_VISITED = 0,
4
4
  IN_PROGRESS = 1,
@@ -1,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CommitOrderCalculator = exports.NodeState = void 0;
4
- const enums_1 = require("../enums");
5
- var NodeState;
1
+ import { ReferenceKind } from '../enums.js';
2
+ export var NodeState;
6
3
  (function (NodeState) {
7
4
  NodeState[NodeState["NOT_VISITED"] = 0] = "NOT_VISITED";
8
5
  NodeState[NodeState["IN_PROGRESS"] = 1] = "IN_PROGRESS";
9
6
  NodeState[NodeState["VISITED"] = 2] = "VISITED";
10
- })(NodeState || (exports.NodeState = NodeState = {}));
7
+ })(NodeState || (NodeState = {}));
11
8
  /**
12
9
  * CommitOrderCalculator implements topological sorting, which is an ordering
13
10
  * algorithm for directed graphs (DG) and/or directed acyclic graphs (DAG) by
@@ -18,7 +15,7 @@ var NodeState;
18
15
  * Based on https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/Internal/CommitOrderCalculator.php
19
16
  * @internal
20
17
  */
21
- class CommitOrderCalculator {
18
+ export class CommitOrderCalculator {
22
19
  /** Matrix of nodes, keys are provided hashes and values are the node definition objects. */
23
20
  nodes = {};
24
21
  /** Volatile variable holding calculated nodes during sorting process. */
@@ -42,8 +39,8 @@ class CommitOrderCalculator {
42
39
  this.nodes[from].dependencies[to] = { from, to, weight };
43
40
  }
44
41
  discoverProperty(prop, entityName) {
45
- const toOneOwner = (prop.kind === enums_1.ReferenceKind.ONE_TO_ONE && prop.owner) || prop.kind === enums_1.ReferenceKind.MANY_TO_ONE;
46
- const toManyOwner = prop.kind === enums_1.ReferenceKind.MANY_TO_MANY && prop.owner && !prop.pivotEntity;
42
+ const toOneOwner = (prop.kind === ReferenceKind.ONE_TO_ONE && prop.owner) || prop.kind === ReferenceKind.MANY_TO_ONE;
43
+ const toManyOwner = prop.kind === ReferenceKind.MANY_TO_MANY && prop.owner && !prop.pivotEntity;
47
44
  if (!toOneOwner && !toManyOwner) {
48
45
  return;
49
46
  }
@@ -110,4 +107,3 @@ class CommitOrderCalculator {
110
107
  this.sortedNodeList.push(target.hash);
111
108
  }
112
109
  }
113
- exports.CommitOrderCalculator = CommitOrderCalculator;
@@ -1,4 +1,4 @@
1
- import type { AnyEntity, EntityMetadata } from '../typings';
1
+ import type { AnyEntity, EntityMetadata } from '../typings.js';
2
2
  export declare class IdentityMap {
3
3
  private readonly defaultSchema?;
4
4
  constructor(defaultSchema?: string | undefined);
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IdentityMap = void 0;
4
- class IdentityMap {
1
+ export class IdentityMap {
5
2
  defaultSchema;
6
3
  constructor(defaultSchema) {
7
4
  this.defaultSchema = defaultSchema;
@@ -73,4 +70,3 @@ class IdentityMap {
73
70
  return hash;
74
71
  }
75
72
  }
76
- exports.IdentityMap = IdentityMap;
@@ -1,10 +1,11 @@
1
- import type { AnyEntity, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary } from '../typings';
2
- import { Collection, Reference } from '../entity';
3
- import { ChangeSet, ChangeSetType } from './ChangeSet';
4
- import { ChangeSetPersister } from './ChangeSetPersister';
5
- import type { EntityManager } from '../EntityManager';
6
- import { IdentityMap } from './IdentityMap';
7
- import type { LockOptions } from '../drivers/IDatabaseDriver';
1
+ import type { AnyEntity, EntityData, EntityMetadata, EntityProperty, FilterQuery, Primary } from '../typings.js';
2
+ import { Collection } from '../entity/Collection.js';
3
+ import { Reference } from '../entity/Reference.js';
4
+ import { ChangeSet, ChangeSetType } from './ChangeSet.js';
5
+ import { ChangeSetPersister } from './ChangeSetPersister.js';
6
+ import type { EntityManager } from '../EntityManager.js';
7
+ import { IdentityMap } from './IdentityMap.js';
8
+ import type { LockOptions } from '../drivers/IDatabaseDriver.js';
8
9
  export declare class UnitOfWork {
9
10
  private readonly em;
10
11
  /** map of references to managed entities */