@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,13 +1,10 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ArrayCollection = void 0;
4
- const node_util_1 = require("node:util");
5
- const Reference_1 = require("./Reference");
6
- const wrap_1 = require("./wrap");
7
- const errors_1 = require("../errors");
8
- const enums_1 = require("../enums");
9
- const Utils_1 = require("../utils/Utils");
10
- class ArrayCollection {
1
+ import { inspect } from 'node:util';
2
+ import { Reference } from './Reference.js';
3
+ import { helper, wrap } from './wrap.js';
4
+ import { MetadataError, ValidationError } from '../errors.js';
5
+ import { ReferenceKind } from '../enums.js';
6
+ import { Utils } from '../utils/Utils.js';
7
+ export class ArrayCollection {
11
8
  owner;
12
9
  items = new Set();
13
10
  initialized = true;
@@ -17,7 +14,7 @@ class ArrayCollection {
17
14
  _property;
18
15
  constructor(owner, items) {
19
16
  this.owner = owner;
20
- /* istanbul ignore next */
17
+ /* v8 ignore next 5 */
21
18
  if (items) {
22
19
  let i = 0;
23
20
  this.items = new Set(items);
@@ -36,28 +33,35 @@ class ArrayCollection {
36
33
  }
37
34
  const meta = this.property.targetMeta;
38
35
  const args = meta.toJsonParams.map(() => undefined);
39
- return this.map(item => (0, wrap_1.wrap)(item).toJSON(...args));
36
+ return this.map(item => wrap(item).toJSON(...args));
40
37
  }
41
38
  toJSON() {
42
39
  return this.toArray();
43
40
  }
44
41
  getIdentifiers(field) {
45
42
  const items = this.getItems();
43
+ const targetMeta = this.property.targetMeta;
46
44
  if (items.length === 0) {
47
45
  return [];
48
46
  }
49
- field ??= this.property.targetMeta.serializedPrimaryKey;
47
+ field ??= targetMeta.compositePK ? targetMeta.primaryKeys : targetMeta.serializedPrimaryKey;
48
+ const cb = (i, f) => {
49
+ if (Utils.isEntity(i[f], true)) {
50
+ return wrap(i[f], true).getPrimaryKey();
51
+ }
52
+ return i[f];
53
+ };
50
54
  return items.map(i => {
51
- if (Utils_1.Utils.isEntity(i[field], true)) {
52
- return (0, wrap_1.wrap)(i[field], true).getPrimaryKey();
55
+ if (Array.isArray(field)) {
56
+ return field.map(f => cb(i, f));
53
57
  }
54
- return i[field];
58
+ return cb(i, field);
55
59
  });
56
60
  }
57
61
  add(entity, ...entities) {
58
- entities = Utils_1.Utils.asArray(entity).concat(entities);
62
+ entities = Utils.asArray(entity).concat(entities);
59
63
  for (const item of entities) {
60
- const entity = Reference_1.Reference.unwrapReference(item);
64
+ const entity = Reference.unwrapReference(item);
61
65
  if (!this.contains(entity, false)) {
62
66
  this.incrementCount(1);
63
67
  this[this.items.size] = entity;
@@ -82,7 +86,7 @@ class ArrayCollection {
82
86
  this.initialized = true;
83
87
  this.snapshot = undefined;
84
88
  }
85
- if (this.compare(Utils_1.Utils.asArray(items).map(item => Reference_1.Reference.unwrapReference(item)))) {
89
+ if (this.compare(Utils.asArray(items).map(item => Reference.unwrapReference(item)))) {
86
90
  return;
87
91
  }
88
92
  this.remove(this.items);
@@ -120,13 +124,13 @@ class ArrayCollection {
120
124
  * which tells the ORM we don't want orphaned entities to exist, so we know those should be removed.
121
125
  */
122
126
  remove(entity, ...entities) {
123
- entities = Utils_1.Utils.asArray(entity).concat(entities);
127
+ entities = Utils.asArray(entity).concat(entities);
124
128
  let modified = false;
125
129
  for (const item of entities) {
126
130
  if (!item) {
127
131
  continue;
128
132
  }
129
- const entity = Reference_1.Reference.unwrapReference(item);
133
+ const entity = Reference.unwrapReference(item);
130
134
  if (this.items.delete(entity)) {
131
135
  this.incrementCount(-1);
132
136
  delete this[this.items.size]; // remove last item
@@ -164,7 +168,7 @@ class ArrayCollection {
164
168
  this.dirty = true;
165
169
  }
166
170
  contains(item, check) {
167
- const entity = Reference_1.Reference.unwrapReference(item);
171
+ const entity = Reference.unwrapReference(item);
168
172
  return this.items.has(entity);
169
173
  }
170
174
  /**
@@ -261,7 +265,7 @@ class ArrayCollection {
261
265
  return this.initialized;
262
266
  }
263
267
  for (const item of this.items) {
264
- if (!(0, wrap_1.helper)(item).__initialized) {
268
+ if (!helper(item).__initialized) {
265
269
  return false;
266
270
  }
267
271
  }
@@ -307,10 +311,10 @@ class ArrayCollection {
307
311
  */
308
312
  get property() {
309
313
  if (!this._property) {
310
- const meta = (0, wrap_1.wrap)(this.owner, true).__meta;
311
- /* istanbul ignore if */
314
+ const meta = wrap(this.owner, true).__meta;
315
+ /* v8 ignore next 3 */
312
316
  if (!meta) {
313
- throw errors_1.MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
317
+ throw MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
314
318
  }
315
319
  this._property = meta.relations.find(prop => this.owner[prop.name] === this);
316
320
  }
@@ -340,27 +344,27 @@ class ArrayCollection {
340
344
  propagateToOwningSide(item, method) {
341
345
  const mappedBy = this.property.mappedBy;
342
346
  const collection = item[mappedBy];
343
- if (this.property.kind === enums_1.ReferenceKind.MANY_TO_MANY) {
347
+ if (this.property.kind === ReferenceKind.MANY_TO_MANY) {
344
348
  if (this.shouldPropagateToCollection(collection, method)) {
345
349
  collection[method](this.owner);
346
350
  }
347
351
  }
348
- else if (this.property.kind === enums_1.ReferenceKind.ONE_TO_MANY && method !== 'takeSnapshot') {
352
+ else if (this.property.kind === ReferenceKind.ONE_TO_MANY && method !== 'takeSnapshot') {
349
353
  const prop2 = this.property.targetMeta.properties[mappedBy];
350
- const owner = prop2.mapToPk ? (0, wrap_1.helper)(this.owner).getPrimaryKey() : this.owner;
354
+ const owner = prop2.mapToPk ? helper(this.owner).getPrimaryKey() : this.owner;
351
355
  const value = method === 'add' ? owner : null;
352
356
  if (this.property.orphanRemoval && method === 'remove') {
353
357
  // cache the PK before we propagate, as its value might be needed when flushing
354
- (0, wrap_1.helper)(item).__pk = (0, wrap_1.helper)(item).getPrimaryKey();
358
+ helper(item).__pk = helper(item).getPrimaryKey();
355
359
  }
356
360
  if (!prop2.nullable && prop2.deleteRule !== 'cascade' && method === 'remove') {
357
361
  if (!this.property.orphanRemoval) {
358
- throw errors_1.ValidationError.cannotRemoveFromCollectionWithoutOrphanRemoval(this.owner, this.property);
362
+ throw ValidationError.cannotRemoveFromCollectionWithoutOrphanRemoval(this.owner, this.property);
359
363
  }
360
364
  return;
361
365
  }
362
366
  // skip if already propagated
363
- if (Reference_1.Reference.unwrapReference(item[mappedBy]) !== value) {
367
+ if (Reference.unwrapReference(item[mappedBy]) !== value) {
364
368
  item[mappedBy] = value;
365
369
  }
366
370
  }
@@ -384,16 +388,15 @@ class ArrayCollection {
384
388
  }
385
389
  }
386
390
  /** @ignore */
387
- [node_util_1.inspect.custom](depth = 2) {
391
+ [inspect.custom](depth = 2) {
388
392
  const object = { ...this };
389
393
  const hidden = ['items', 'owner', '_property', '_count', 'snapshot', '_populated', '_snapshot', '_lazyInitialized', '_em', 'readonly'];
390
394
  hidden.forEach(k => delete object[k]);
391
- const ret = (0, node_util_1.inspect)(object, { depth });
395
+ const ret = inspect(object, { depth });
392
396
  const name = `${this.constructor.name}<${this.property?.type ?? 'unknown'}>`;
393
397
  return ret === '[Object]' ? `[${name}]` : name + ' ' + ret;
394
398
  }
395
399
  }
396
- exports.ArrayCollection = ArrayCollection;
397
400
  Object.defineProperties(ArrayCollection.prototype, {
398
401
  __collection: { value: true, enumerable: false, writable: false },
399
402
  });
@@ -1,9 +1,9 @@
1
- import { type Ref } from './Reference';
2
- import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings';
3
- import { type AssignOptions } from './EntityAssigner';
4
- import type { EntityLoaderOptions } from './EntityLoader';
5
- import { type SerializeOptions } from '../serialization/EntitySerializer';
6
- import type { FindOneOptions } from '../drivers/IDatabaseDriver';
1
+ import { type Ref } from './Reference.js';
2
+ import type { AutoPath, EntityData, EntityDTO, Loaded, LoadedReference, AddEager, EntityKey, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
3
+ import { type AssignOptions } from './EntityAssigner.js';
4
+ import type { EntityLoaderOptions } from './EntityLoader.js';
5
+ import { type SerializeOptions } from '../serialization/EntitySerializer.js';
6
+ import type { FindOneOptions } from '../drivers/IDatabaseDriver.js';
7
7
  export declare abstract class BaseEntity {
8
8
  isInitialized(): boolean;
9
9
  isTouched(): boolean;
@@ -1,47 +1,43 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BaseEntity = void 0;
4
- const Reference_1 = require("./Reference");
5
- const EntityAssigner_1 = require("./EntityAssigner");
6
- const EntitySerializer_1 = require("../serialization/EntitySerializer");
7
- const wrap_1 = require("./wrap");
8
- class BaseEntity {
1
+ import { Reference } from './Reference.js';
2
+ import { EntityAssigner } from './EntityAssigner.js';
3
+ import { EntitySerializer } from '../serialization/EntitySerializer.js';
4
+ import { helper } from './wrap.js';
5
+ export class BaseEntity {
9
6
  isInitialized() {
10
- return (0, wrap_1.helper)(this).__initialized;
7
+ return helper(this).__initialized;
11
8
  }
12
9
  isTouched() {
13
- return (0, wrap_1.helper)(this).__touched;
10
+ return helper(this).__touched;
14
11
  }
15
12
  populated(populated = true) {
16
- (0, wrap_1.helper)(this).populated(populated);
13
+ helper(this).populated(populated);
17
14
  }
18
15
  async populate(populate, options = {}) {
19
- return (0, wrap_1.helper)(this).populate(populate, options);
16
+ return helper(this).populate(populate, options);
20
17
  }
21
18
  toReference() {
22
- return Reference_1.Reference.create(this);
19
+ return Reference.create(this);
23
20
  }
24
21
  toObject(ignoreFields) {
25
- return (0, wrap_1.helper)(this).toObject(ignoreFields);
22
+ return helper(this).toObject(ignoreFields);
26
23
  }
27
24
  toPOJO() {
28
- return (0, wrap_1.helper)(this).toPOJO();
25
+ return helper(this).toPOJO();
29
26
  }
30
27
  serialize(options) {
31
- return EntitySerializer_1.EntitySerializer.serialize(this, options);
28
+ return EntitySerializer.serialize(this, options);
32
29
  }
33
30
  assign(data, options = {}) {
34
- return EntityAssigner_1.EntityAssigner.assign(this, data, options);
31
+ return EntityAssigner.assign(this, data, options);
35
32
  }
36
33
  init(options) {
37
- return (0, wrap_1.helper)(this).init(options);
34
+ return helper(this).init(options);
38
35
  }
39
36
  getSchema() {
40
- return (0, wrap_1.helper)(this).getSchema();
37
+ return helper(this).getSchema();
41
38
  }
42
39
  setSchema(schema) {
43
- (0, wrap_1.helper)(this).setSchema(schema);
40
+ helper(this).setSchema(schema);
44
41
  }
45
42
  }
46
- exports.BaseEntity = BaseEntity;
47
43
  Object.defineProperty(BaseEntity.prototype, '__baseEntity', { value: true, writable: false, enumerable: false });
@@ -1,9 +1,9 @@
1
- import type { EntityDTO, EntityKey, FilterQuery, Loaded, LoadedCollection, Populate } from '../typings';
2
- import { ArrayCollection } from './ArrayCollection';
3
- import { Reference } from './Reference';
4
- import type { Transaction } from '../connections/Connection';
5
- import type { FindOptions, CountOptions } from '../drivers/IDatabaseDriver';
6
- import type { EntityLoaderOptions } from './EntityLoader';
1
+ import type { EntityDTO, EntityKey, FilterQuery, Loaded, LoadedCollection, Populate } from '../typings.js';
2
+ import { ArrayCollection } from './ArrayCollection.js';
3
+ import { Reference } from './Reference.js';
4
+ import type { Transaction } from '../connections/Connection.js';
5
+ import type { FindOptions, CountOptions } from '../drivers/IDatabaseDriver.js';
6
+ import type { EntityLoaderOptions } from './EntityLoader.js';
7
7
  export interface MatchingOptions<T extends object, P extends string = never> extends FindOptions<T, P> {
8
8
  where?: FilterQuery<T>;
9
9
  store?: boolean;
@@ -12,7 +12,6 @@ export interface MatchingOptions<T extends object, P extends string = never> ext
12
12
  export declare class Collection<T extends object, O extends object = object> extends ArrayCollection<T, O> {
13
13
  private readonly?;
14
14
  private _populated?;
15
- private _em?;
16
15
  private _snapshot?;
17
16
  constructor(owner: O, items?: T[], initialized?: boolean);
18
17
  /**
@@ -1,16 +1,12 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Collection = void 0;
4
- const ArrayCollection_1 = require("./ArrayCollection");
5
- const Utils_1 = require("../utils/Utils");
6
- const errors_1 = require("../errors");
7
- const enums_1 = require("../enums");
8
- const Reference_1 = require("./Reference");
9
- const wrap_1 = require("./wrap");
10
- class Collection extends ArrayCollection_1.ArrayCollection {
1
+ import { ArrayCollection } from './ArrayCollection.js';
2
+ import { Utils } from '../utils/Utils.js';
3
+ import { ValidationError } from '../errors.js';
4
+ import { ReferenceKind, DataloaderType } from '../enums.js';
5
+ import { Reference } from './Reference.js';
6
+ import { helper } from './wrap.js';
7
+ export class Collection extends ArrayCollection {
11
8
  readonly;
12
9
  _populated;
13
- _em;
14
10
  // this is for some reason needed for TS, otherwise it can fail with `Type instantiation is excessively deep and possibly infinite.`
15
11
  _snapshot;
16
12
  constructor(owner, items, initialized = true) {
@@ -22,7 +18,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
22
18
  */
23
19
  static create(owner, prop, items, initialized) {
24
20
  const coll = new Collection(owner, undefined, initialized);
25
- coll.property = (0, wrap_1.helper)(owner).__meta.properties[prop];
21
+ coll.property = helper(owner).__meta.properties[prop];
26
22
  owner[prop] = coll;
27
23
  if (items) {
28
24
  coll.set(items);
@@ -45,7 +41,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
45
41
  return this;
46
42
  }
47
43
  setSerializationContext(options) {
48
- (0, wrap_1.helper)(this.owner).setSerializationContext({
44
+ helper(this.owner).setSerializationContext({
49
45
  populate: Array.isArray(options.populate)
50
46
  ? options.populate.map(hint => `${this.property.name}.${hint}`)
51
47
  : options.populate ?? [this.property.name],
@@ -65,11 +61,11 @@ class Collection extends ArrayCollection_1.ArrayCollection {
65
61
  async loadCount(options = {}) {
66
62
  options = typeof options === 'boolean' ? { refresh: options } : options;
67
63
  const { refresh, where, ...countOptions } = options;
68
- if (!refresh && !where && Utils_1.Utils.isDefined(this._count)) {
64
+ if (!refresh && !where && Utils.isDefined(this._count)) {
69
65
  return this._count;
70
66
  }
71
67
  const em = this.getEntityManager();
72
- if (!em.getPlatform().usesPivotTable() && this.property.kind === enums_1.ReferenceKind.MANY_TO_MANY && this.property.owner) {
68
+ if (!em.getPlatform().usesPivotTable() && this.property.kind === ReferenceKind.MANY_TO_MANY && this.property.owner) {
73
69
  return this._count = this.length;
74
70
  }
75
71
  const cond = this.createLoadCountCondition(where ?? {});
@@ -84,10 +80,10 @@ class Collection extends ArrayCollection_1.ArrayCollection {
84
80
  const { where, ctx, ...opts } = options;
85
81
  opts.orderBy = this.createOrderBy(opts.orderBy);
86
82
  let items;
87
- if (this.property.kind === enums_1.ReferenceKind.MANY_TO_MANY && em.getPlatform().usesPivotTable()) {
83
+ if (this.property.kind === ReferenceKind.MANY_TO_MANY && em.getPlatform().usesPivotTable()) {
88
84
  const cond = await em.applyFilters(this.property.type, where, options.filters ?? {}, 'read');
89
- const map = await em.getDriver().loadFromPivotTable(this.property, [(0, wrap_1.helper)(this.owner).__primaryKeys], cond, opts.orderBy, ctx, options);
90
- items = map[(0, wrap_1.helper)(this.owner).getSerializedPrimaryKey()].map((item) => em.merge(this.property.type, item, { convertCustomTypes: true }));
85
+ const map = await em.getDriver().loadFromPivotTable(this.property, [helper(this.owner).__primaryKeys], cond, opts.orderBy, ctx, options);
86
+ items = map[helper(this.owner).getSerializedPrimaryKey()].map((item) => em.merge(this.property.type, item, { convertCustomTypes: true }));
91
87
  }
92
88
  else {
93
89
  items = await em.find(this.property.type, this.createCondition(where), opts);
@@ -116,8 +112,8 @@ class Collection extends ArrayCollection_1.ArrayCollection {
116
112
  return super.toJSON();
117
113
  }
118
114
  add(entity, ...entities) {
119
- entities = Utils_1.Utils.asArray(entity).concat(entities);
120
- const unwrapped = entities.map(i => Reference_1.Reference.unwrapReference(i));
115
+ entities = Utils.asArray(entity).concat(entities);
116
+ const unwrapped = entities.map(i => Reference.unwrapReference(i));
121
117
  unwrapped.forEach(entity => this.validateItemType(entity));
122
118
  this.modify('add', unwrapped);
123
119
  this.cancelOrphanRemoval(unwrapped);
@@ -134,8 +130,8 @@ class Collection extends ArrayCollection_1.ArrayCollection {
134
130
  }
135
131
  return;
136
132
  }
137
- entities = Utils_1.Utils.asArray(entity).concat(entities);
138
- const unwrapped = entities.map(i => Reference_1.Reference.unwrapReference(i));
133
+ entities = Utils.asArray(entity).concat(entities);
134
+ const unwrapped = entities.map(i => Reference.unwrapReference(i));
139
135
  this.modify('remove', unwrapped);
140
136
  const em = this.getEntityManager(unwrapped, false);
141
137
  if (this.property.orphanRemoval && em) {
@@ -221,11 +217,15 @@ class Collection extends ArrayCollection_1.ArrayCollection {
221
217
  return this;
222
218
  }
223
219
  const em = this.getEntityManager();
224
- if (options.dataloader ?? [enums_1.DataloaderType.ALL, enums_1.DataloaderType.COLLECTION].includes(em.config.getDataloaderType())) {
220
+ if (options.dataloader ?? [DataloaderType.ALL, DataloaderType.COLLECTION].includes(em.config.getDataloaderType())) {
225
221
  const order = [...this.items]; // copy order of references
226
- const customOrder = !!options.orderBy;
222
+ const orderBy = this.createOrderBy(options.orderBy);
223
+ const customOrder = orderBy.length > 0;
227
224
  // eslint-disable-next-line dot-notation
228
- const items = await em['colLoader'].load([this, options]);
225
+ const items = await em['colLoader'].load([
226
+ this,
227
+ { ...options, orderBy },
228
+ ]);
229
229
  if (!customOrder) {
230
230
  this.reorderItems(items, order);
231
231
  }
@@ -243,7 +243,7 @@ class Collection extends ArrayCollection_1.ArrayCollection {
243
243
  ? options.populate.map(f => f === '*' ? f : `${this.property.name}.${f}`)
244
244
  : [`${this.property.name}${options.ref ? ':ref' : ''}`];
245
245
  const schema = this.property.targetMeta.schema === '*'
246
- ? (0, wrap_1.helper)(this.owner).__schema
246
+ ? helper(this.owner).__schema
247
247
  : undefined;
248
248
  await em.populate(this.owner, populate, {
249
249
  refresh: true,
@@ -256,27 +256,24 @@ class Collection extends ArrayCollection_1.ArrayCollection {
256
256
  return this;
257
257
  }
258
258
  getEntityManager(items = [], required = true) {
259
- const wrapped = (0, wrap_1.helper)(this.owner);
260
- let em = (this._em ?? wrapped.__em);
259
+ const wrapped = helper(this.owner);
260
+ let em = wrapped.__em;
261
261
  if (!em) {
262
262
  for (const i of items) {
263
- if (i && (0, wrap_1.helper)(i).__em) {
264
- em = (0, wrap_1.helper)(i).__em;
263
+ if (i && helper(i).__em) {
264
+ em = helper(i).__em;
265
265
  break;
266
266
  }
267
267
  }
268
268
  }
269
- if (em) {
270
- Object.defineProperty(this, '_em', { value: em });
271
- }
272
269
  if (!em && required) {
273
- throw errors_1.ValidationError.entityNotManaged(this.owner);
270
+ throw ValidationError.entityNotManaged(this.owner);
274
271
  }
275
272
  return em;
276
273
  }
277
274
  createCondition(cond = {}) {
278
- if (this.property.kind === enums_1.ReferenceKind.ONE_TO_MANY) {
279
- cond[this.property.mappedBy] = (0, wrap_1.helper)(this.owner).getPrimaryKey();
275
+ if (this.property.kind === ReferenceKind.ONE_TO_MANY) {
276
+ cond[this.property.mappedBy] = helper(this.owner).getPrimaryKey();
280
277
  }
281
278
  else { // MANY_TO_MANY
282
279
  this.createManyToManyCondition(cond);
@@ -284,10 +281,10 @@ class Collection extends ArrayCollection_1.ArrayCollection {
284
281
  return cond;
285
282
  }
286
283
  createOrderBy(orderBy = []) {
287
- if (Utils_1.Utils.isEmpty(orderBy) && this.property.orderBy) {
284
+ if (Utils.isEmpty(orderBy) && this.property.orderBy) {
288
285
  orderBy = this.property.orderBy;
289
286
  }
290
- return Utils_1.Utils.asArray(orderBy);
287
+ return Utils.asArray(orderBy);
291
288
  }
292
289
  createManyToManyCondition(cond) {
293
290
  const dict = cond;
@@ -295,17 +292,17 @@ class Collection extends ArrayCollection_1.ArrayCollection {
295
292
  // we know there is at least one item as it was checked in load method
296
293
  const pk = this.property.targetMeta.primaryKeys[0];
297
294
  dict[pk] = { $in: [] };
298
- this.items.forEach(item => dict[pk].$in.push((0, wrap_1.helper)(item).getPrimaryKey()));
295
+ this.items.forEach(item => dict[pk].$in.push(helper(item).getPrimaryKey()));
299
296
  }
300
297
  else {
301
- dict[this.property.mappedBy] = (0, wrap_1.helper)(this.owner).getPrimaryKey();
298
+ dict[this.property.mappedBy] = helper(this.owner).getPrimaryKey();
302
299
  }
303
300
  }
304
301
  createLoadCountCondition(cond) {
305
- const wrapped = (0, wrap_1.helper)(this.owner);
302
+ const wrapped = helper(this.owner);
306
303
  const val = wrapped.__meta.compositePK ? { $in: wrapped.__primaryKeys } : wrapped.getPrimaryKey();
307
304
  const dict = cond;
308
- if (this.property.kind === enums_1.ReferenceKind.ONE_TO_MANY) {
305
+ if (this.property.kind === ReferenceKind.ONE_TO_MANY) {
309
306
  dict[this.property.mappedBy] = val;
310
307
  }
311
308
  else {
@@ -324,14 +321,14 @@ class Collection extends ArrayCollection_1.ArrayCollection {
324
321
  }
325
322
  checkInitialized() {
326
323
  if (!this.isInitialized()) {
327
- throw new Error(`Collection<${this.property.type}> of entity ${this.owner.constructor.name}[${(0, wrap_1.helper)(this.owner).getSerializedPrimaryKey()}] not initialized`);
324
+ throw new Error(`Collection<${this.property.type}> of entity ${this.owner.constructor.name}[${helper(this.owner).getSerializedPrimaryKey()}] not initialized`);
328
325
  }
329
326
  }
330
327
  /**
331
328
  * re-orders items after searching with `$in` operator
332
329
  */
333
330
  reorderItems(items, order) {
334
- if (this.property.kind === enums_1.ReferenceKind.MANY_TO_MANY && this.property.owner) {
331
+ if (this.property.kind === ReferenceKind.MANY_TO_MANY && this.property.owner) {
335
332
  items.sort((a, b) => order.indexOf(a) - order.indexOf(b));
336
333
  }
337
334
  }
@@ -345,31 +342,30 @@ class Collection extends ArrayCollection_1.ArrayCollection {
345
342
  }
346
343
  }
347
344
  validateItemType(item) {
348
- if (!Utils_1.Utils.isEntity(item)) {
349
- throw errors_1.ValidationError.notEntity(this.owner, this.property, item);
345
+ if (!Utils.isEntity(item)) {
346
+ throw ValidationError.notEntity(this.owner, this.property, item);
350
347
  }
351
348
  }
352
349
  validateModification(items) {
353
350
  if (this.readonly) {
354
- throw errors_1.ValidationError.cannotModifyReadonlyCollection(this.owner, this.property);
351
+ throw ValidationError.cannotModifyReadonlyCollection(this.owner, this.property);
355
352
  }
356
353
  // currently we allow persisting to inverse sides only in SQL drivers
357
354
  if (this.property.pivotTable || !this.property.mappedBy) {
358
355
  return;
359
356
  }
360
357
  const check = (item) => {
361
- if (!item || (0, wrap_1.helper)(item).__initialized) {
358
+ if (!item || helper(item).__initialized) {
362
359
  return false;
363
360
  }
364
- return !item[this.property.mappedBy] && this.property.kind === enums_1.ReferenceKind.MANY_TO_MANY;
361
+ return !item[this.property.mappedBy] && this.property.kind === ReferenceKind.MANY_TO_MANY;
365
362
  };
366
363
  // throw if we are modifying inverse side of M:N collection when owning side is initialized (would be ignored when persisting)
367
364
  if (items.find(item => check(item))) {
368
- throw errors_1.ValidationError.cannotModifyInverseCollection(this.owner, this.property);
365
+ throw ValidationError.cannotModifyInverseCollection(this.owner, this.property);
369
366
  }
370
367
  }
371
368
  }
372
- exports.Collection = Collection;
373
369
  Object.defineProperties(Collection.prototype, {
374
370
  $: { get() { return this; } },
375
371
  get: { get() { return () => this; } },
@@ -1,5 +1,5 @@
1
- import type { EntityManager } from '../EntityManager';
2
- import type { EntityData, EntityDTO, EntityProperty, FromEntityType, IsSubset, MergeSelected } from '../typings';
1
+ import type { EntityManager } from '../EntityManager.js';
2
+ import type { EntityData, EntityDTO, EntityProperty, FromEntityType, IsSubset, MergeSelected } from '../typings.js';
3
3
  export declare class EntityAssigner {
4
4
  static assign<Entity extends object, Naked extends FromEntityType<Entity> = FromEntityType<Entity>, Convert extends boolean = false, Data extends EntityData<Naked, Convert> | Partial<EntityDTO<Naked>> = EntityData<Naked, Convert> | Partial<EntityDTO<Naked>>>(entity: Entity, data: Data & IsSubset<EntityData<Naked, Convert>, Data>, options?: AssignOptions<Convert>): MergeSelected<Entity, Naked, keyof Data & string>;
5
5
  private static assignProperty;