@mikro-orm/core 7.0.0-dev.321 → 7.0.0-dev.323

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 (53) hide show
  1. package/EntityManager.d.ts +2 -15
  2. package/EntityManager.js +155 -152
  3. package/MikroORM.d.ts +1 -3
  4. package/MikroORM.js +20 -20
  5. package/cache/FileCacheAdapter.d.ts +1 -5
  6. package/cache/FileCacheAdapter.js +22 -22
  7. package/cache/GeneratedCacheAdapter.d.ts +1 -1
  8. package/cache/GeneratedCacheAdapter.js +6 -6
  9. package/cache/MemoryCacheAdapter.d.ts +1 -2
  10. package/cache/MemoryCacheAdapter.js +8 -8
  11. package/entity/Collection.d.ts +2 -10
  12. package/entity/Collection.js +95 -105
  13. package/entity/EntityFactory.d.ts +1 -8
  14. package/entity/EntityFactory.js +48 -48
  15. package/entity/EntityLoader.d.ts +1 -3
  16. package/entity/EntityLoader.js +33 -34
  17. package/entity/Reference.d.ts +1 -2
  18. package/entity/Reference.js +11 -11
  19. package/events/EventManager.d.ts +1 -4
  20. package/events/EventManager.js +21 -21
  21. package/hydration/ObjectHydrator.d.ts +1 -2
  22. package/hydration/ObjectHydrator.js +11 -11
  23. package/metadata/MetadataDiscovery.d.ts +1 -9
  24. package/metadata/MetadataDiscovery.js +147 -144
  25. package/metadata/MetadataStorage.d.ts +1 -5
  26. package/metadata/MetadataStorage.js +36 -36
  27. package/naming-strategy/EntityCaseNamingStrategy.js +1 -1
  28. package/package.json +1 -1
  29. package/serialization/EntitySerializer.js +1 -1
  30. package/serialization/EntityTransformer.js +4 -1
  31. package/serialization/SerializationContext.d.ts +3 -7
  32. package/serialization/SerializationContext.js +20 -15
  33. package/unit-of-work/ChangeSetComputer.d.ts +1 -6
  34. package/unit-of-work/ChangeSetComputer.js +21 -21
  35. package/unit-of-work/ChangeSetPersister.d.ts +1 -9
  36. package/unit-of-work/ChangeSetPersister.js +51 -51
  37. package/unit-of-work/CommitOrderCalculator.d.ts +1 -4
  38. package/unit-of-work/CommitOrderCalculator.js +13 -13
  39. package/unit-of-work/IdentityMap.d.ts +2 -5
  40. package/unit-of-work/IdentityMap.js +18 -18
  41. package/unit-of-work/UnitOfWork.d.ts +5 -19
  42. package/unit-of-work/UnitOfWork.js +181 -173
  43. package/utils/AbstractMigrator.d.ts +1 -1
  44. package/utils/AbstractMigrator.js +6 -6
  45. package/utils/Configuration.d.ts +1 -6
  46. package/utils/Configuration.js +78 -78
  47. package/utils/Cursor.d.ts +1 -1
  48. package/utils/Cursor.js +3 -3
  49. package/utils/EntityComparator.d.ts +2 -11
  50. package/utils/EntityComparator.js +44 -44
  51. package/utils/TransactionManager.js +1 -2
  52. package/utils/Utils.js +1 -1
  53. package/utils/clone.js +1 -1
@@ -6,20 +6,20 @@ import { Raw } from './RawQueryFragment.js';
6
6
  import { EntityIdentifier } from '../entity/EntityIdentifier.js';
7
7
  import { PolymorphicRef } from '../entity/PolymorphicRef.js';
8
8
  export class EntityComparator {
9
- metadata;
10
- platform;
11
- config;
12
- comparators = new Map();
13
- mappers = new Map();
14
- snapshotGenerators = new Map();
15
- pkGetters = new Map();
16
- pkGettersConverted = new Map();
17
- pkSerializers = new Map();
18
- tmpIndex = 0;
9
+ #comparators = new Map();
10
+ #mappers = new Map();
11
+ #snapshotGenerators = new Map();
12
+ #pkGetters = new Map();
13
+ #pkGettersConverted = new Map();
14
+ #pkSerializers = new Map();
15
+ #tmpIndex = 0;
16
+ #metadata;
17
+ #platform;
18
+ #config;
19
19
  constructor(metadata, platform, config) {
20
- this.metadata = metadata;
21
- this.platform = platform;
22
- this.config = config;
20
+ this.#metadata = metadata;
21
+ this.#platform = platform;
22
+ this.#config = config;
23
23
  }
24
24
  /**
25
25
  * Computes difference between two entities.
@@ -51,7 +51,7 @@ export class EntityComparator {
51
51
  * @internal Highly performance-sensitive method.
52
52
  */
53
53
  getPkGetter(meta) {
54
- const exists = this.pkGetters.get(meta);
54
+ const exists = this.#pkGetters.get(meta);
55
55
  /* v8 ignore next */
56
56
  if (exists) {
57
57
  return exists;
@@ -93,15 +93,15 @@ export class EntityComparator {
93
93
  }
94
94
  const code = `// compiled pk getter for entity ${meta.className}\n` + `return function(entity) {\n${lines.join('\n')}\n}`;
95
95
  const fnKey = `pkGetter-${meta.uniqueName}`;
96
- const pkSerializer = Utils.createFunction(context, code, this.config?.get('compiledFunctions'), fnKey);
97
- this.pkGetters.set(meta, pkSerializer);
96
+ const pkSerializer = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
97
+ this.#pkGetters.set(meta, pkSerializer);
98
98
  return pkSerializer;
99
99
  }
100
100
  /**
101
101
  * @internal Highly performance-sensitive method.
102
102
  */
103
103
  getPkGetterConverted(meta) {
104
- const exists = this.pkGettersConverted.get(meta);
104
+ const exists = this.#pkGettersConverted.get(meta);
105
105
  /* v8 ignore next */
106
106
  if (exists) {
107
107
  return exists;
@@ -144,22 +144,22 @@ export class EntityComparator {
144
144
  const code = `// compiled pk getter (with converted custom types) for entity ${meta.className}\n` +
145
145
  `return function(entity) {\n${lines.join('\n')}\n}`;
146
146
  const fnKey = `pkGetterConverted-${meta.uniqueName}`;
147
- const pkSerializer = Utils.createFunction(context, code, this.config?.get('compiledFunctions'), fnKey);
148
- this.pkGettersConverted.set(meta, pkSerializer);
147
+ const pkSerializer = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
148
+ this.#pkGettersConverted.set(meta, pkSerializer);
149
149
  return pkSerializer;
150
150
  }
151
151
  /**
152
152
  * @internal Highly performance-sensitive method.
153
153
  */
154
154
  getPkSerializer(meta) {
155
- const exists = this.pkSerializers.get(meta);
155
+ const exists = this.#pkSerializers.get(meta);
156
156
  /* v8 ignore next */
157
157
  if (exists) {
158
158
  return exists;
159
159
  }
160
160
  const lines = [];
161
161
  const context = new Map();
162
- context.set('getCompositeKeyValue', (val) => Utils.flatten(Utils.getCompositeKeyValue(val, meta, 'convertToDatabaseValue', this.platform)));
162
+ context.set('getCompositeKeyValue', (val) => Utils.flatten(Utils.getCompositeKeyValue(val, meta, 'convertToDatabaseValue', this.#platform)));
163
163
  context.set('getPrimaryKeyHash', (val) => Utils.getPrimaryKeyHash(Utils.asArray(val)));
164
164
  if (meta.primaryKeys.length > 1) {
165
165
  lines.push(` const pks = entity.__helper.__pk ? getCompositeKeyValue(entity.__helper.__pk) : [`);
@@ -186,7 +186,7 @@ export class EntityComparator {
186
186
  }
187
187
  else if (prop.customType) {
188
188
  const convertorKey = this.registerCustomType(meta.properties[pk], context);
189
- const idx = this.tmpIndex++;
189
+ const idx = this.#tmpIndex++;
190
190
  lines.push(` const val_${idx} = convertToDatabaseValue_${convertorKey}(entity${this.wrap(pk)});`);
191
191
  lines.push(` return getPrimaryKeyHash(val_${idx});`);
192
192
  }
@@ -196,23 +196,23 @@ export class EntityComparator {
196
196
  }
197
197
  const code = `// compiled pk serializer for entity ${meta.className}\n` + `return function(entity) {\n${lines.join('\n')}\n}`;
198
198
  const fnKey = `pkSerializer-${meta.uniqueName}`;
199
- const pkSerializer = Utils.createFunction(context, code, this.config?.get('compiledFunctions'), fnKey);
200
- this.pkSerializers.set(meta, pkSerializer);
199
+ const pkSerializer = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
200
+ this.#pkSerializers.set(meta, pkSerializer);
201
201
  return pkSerializer;
202
202
  }
203
203
  /**
204
204
  * @internal Highly performance-sensitive method.
205
205
  */
206
206
  getSnapshotGenerator(entityName) {
207
- const meta = this.metadata.find(entityName);
208
- const exists = this.snapshotGenerators.get(meta);
207
+ const meta = this.#metadata.find(entityName);
208
+ const exists = this.#snapshotGenerators.get(meta);
209
209
  if (exists) {
210
210
  return exists;
211
211
  }
212
212
  const lines = [];
213
213
  const context = new Map();
214
214
  context.set('clone', clone);
215
- context.set('cloneEmbeddable', (o) => this.platform.cloneEmbeddable(o)); // do not clone prototypes
215
+ context.set('cloneEmbeddable', (o) => this.#platform.cloneEmbeddable(o)); // do not clone prototypes
216
216
  if (meta.root.inheritanceType === 'sti' && meta.discriminatorValue) {
217
217
  lines.push(` ret${this.wrap(meta.root.discriminatorColumn)} = '${meta.discriminatorValue}'`);
218
218
  }
@@ -226,8 +226,8 @@ export class EntityComparator {
226
226
  .forEach(prop => lines.push(this.getPropertySnapshot(meta, prop, context, this.wrap(prop.name), this.wrap(prop.name), [prop.name])));
227
227
  const code = `return function(entity) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
228
228
  const fnKey = `snapshotGenerator-${meta.uniqueName}`;
229
- const snapshotGenerator = Utils.createFunction(context, code, this.config?.get('compiledFunctions'), fnKey);
230
- this.snapshotGenerators.set(meta, snapshotGenerator);
229
+ const snapshotGenerator = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
230
+ this.#snapshotGenerators.set(meta, snapshotGenerator);
231
231
  return snapshotGenerator;
232
232
  }
233
233
  /**
@@ -278,14 +278,14 @@ export class EntityComparator {
278
278
  * @internal Highly performance-sensitive method.
279
279
  */
280
280
  getResultMapper(meta) {
281
- const exists = this.mappers.get(meta);
281
+ const exists = this.#mappers.get(meta);
282
282
  if (exists) {
283
283
  return exists;
284
284
  }
285
285
  const lines = [];
286
286
  const context = new Map();
287
287
  context.set('PolymorphicRef', PolymorphicRef);
288
- const tz = this.platform.getTimezone();
288
+ const tz = this.#platform.getTimezone();
289
289
  const parseDate = (key, value, padding = '') => {
290
290
  lines.push(`${padding} if (${value} == null || ${value} instanceof Date) {`);
291
291
  lines.push(`${padding} ${key} = ${value};`);
@@ -345,15 +345,15 @@ export class EntityComparator {
345
345
  lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
346
346
  lines.push(`${padding} }`);
347
347
  }
348
- else if (prop.runtimeType === 'Date' && !this.platform.isNumericProperty(prop)) {
348
+ else if (prop.runtimeType === 'Date' && !this.#platform.isNumericProperty(prop)) {
349
349
  lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
350
- context.set('parseDate', (value) => this.platform.parseDate(value));
350
+ context.set('parseDate', (value) => this.#platform.parseDate(value));
351
351
  parseDate('ret' + this.wrap(prop.name), this.propName(prop.fieldNames[0]), padding);
352
352
  lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
353
353
  lines.push(`${padding} }`);
354
354
  }
355
355
  else if (prop.kind === ReferenceKind.EMBEDDED && (prop.object || meta.embeddable)) {
356
- const idx = this.tmpIndex++;
356
+ const idx = this.#tmpIndex++;
357
357
  context.set(`mapEmbeddedResult_${idx}`, (data) => {
358
358
  const item = parseJsonSafe(data);
359
359
  if (Array.isArray(item)) {
@@ -392,8 +392,8 @@ export class EntityComparator {
392
392
  const code = `// compiled mapper for entity ${meta.className}\n` +
393
393
  `return function(result) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;
394
394
  const fnKey = `resultMapper-${meta.uniqueName}`;
395
- const resultMapper = Utils.createFunction(context, code, this.config?.get('compiledFunctions'), fnKey);
396
- this.mappers.set(meta, resultMapper);
395
+ const resultMapper = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
396
+ this.#mappers.set(meta, resultMapper);
397
397
  return resultMapper;
398
398
  }
399
399
  getPropertyCondition(path) {
@@ -419,7 +419,7 @@ export class EntityComparator {
419
419
  const entityKey = path.map(k => this.wrap(k)).join('');
420
420
  const ret = [];
421
421
  const padding = ' '.repeat(level * 2);
422
- const idx = this.tmpIndex++;
422
+ const idx = this.#tmpIndex++;
423
423
  ret.push(`${padding}if (Array.isArray(entity${entityKey})) {`);
424
424
  ret.push(`${padding} ret${dataKey} = [];`);
425
425
  ret.push(`${padding} entity${entityKey}.forEach((_, idx_${idx}) => {`);
@@ -517,7 +517,7 @@ export class EntityComparator {
517
517
  if (Raw.isKnownFragment(val)) {
518
518
  return val;
519
519
  }
520
- return prop.customType.convertToDatabaseValue(val, this.platform, { mode: 'serialization' });
520
+ return prop.customType.convertToDatabaseValue(val, this.#platform, { mode: 'serialization' });
521
521
  });
522
522
  return convertorKey;
523
523
  }
@@ -602,7 +602,7 @@ export class EntityComparator {
602
602
  return (ret + ` ret${dataKey} = clone(convertToDatabaseValue_${convertorKey}(entity${entityKey}${unwrap}));\n }\n`);
603
603
  }
604
604
  if (prop.runtimeType === 'Date') {
605
- context.set('processDateProperty', this.platform.processDateProperty.bind(this.platform));
605
+ context.set('processDateProperty', this.#platform.processDateProperty.bind(this.#platform));
606
606
  return ret + ` ret${dataKey} = clone(processDateProperty(entity${entityKey}${unwrap}));\n }\n`;
607
607
  }
608
608
  return ret + ` ret${dataKey} = clone(entity${entityKey}${unwrap});\n }\n`;
@@ -611,8 +611,8 @@ export class EntityComparator {
611
611
  * @internal Highly performance-sensitive method.
612
612
  */
613
613
  getEntityComparator(entityName) {
614
- const meta = this.metadata.find(entityName);
615
- const exists = this.comparators.get(meta);
614
+ const meta = this.#metadata.find(entityName);
615
+ const exists = this.#comparators.get(meta);
616
616
  if (exists) {
617
617
  return exists;
618
618
  }
@@ -637,8 +637,8 @@ export class EntityComparator {
637
637
  const code = `// compiled comparator for entity ${meta.className}\n` +
638
638
  `return function(last, current, options) {\n const diff = {};\n${lines.join('\n')}\n return diff;\n}`;
639
639
  const fnKey = `comparator-${meta.uniqueName}`;
640
- const comparator = Utils.createFunction(context, code, this.config?.get('compiledFunctions'), fnKey);
641
- this.comparators.set(meta, comparator);
640
+ const comparator = Utils.createFunction(context, code, this.#config?.get('compiledFunctions'), fnKey);
641
+ this.#comparators.set(meta, comparator);
642
642
  return comparator;
643
643
  }
644
644
  getGenericComparator(prop, cond) {
@@ -669,7 +669,7 @@ export class EntityComparator {
669
669
  }
670
670
  if (prop.customType) {
671
671
  if (prop.customType.compareValues) {
672
- const idx = this.tmpIndex++;
672
+ const idx = this.#tmpIndex++;
673
673
  context.set(`compareValues_${idx}`, (a, b) => {
674
674
  if (Raw.isKnownFragment(a) || Raw.isKnownFragment(b)) {
675
675
  return Raw.getKnownFragment(a) === Raw.getKnownFragment(b);
@@ -160,8 +160,7 @@ export class TransactionManager {
160
160
  for (const entity of fork.getUnitOfWork(false).getIdentityMap()) {
161
161
  const wrapped = helper(entity);
162
162
  const meta = wrapped.__meta;
163
- // eslint-disable-next-line dot-notation
164
- const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(), parent['_schema'], true);
163
+ const parentEntity = parentUoW.getById(meta.class, wrapped.getPrimaryKey(), parent.schema, true);
165
164
  if (parentEntity && parentEntity !== entity) {
166
165
  const parentWrapped = helper(parentEntity);
167
166
  parentWrapped.__data = wrapped.__data;
package/utils/Utils.js CHANGED
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
123
123
  }
124
124
  export class Utils {
125
125
  static PK_SEPARATOR = '~~~';
126
- static #ORM_VERSION = '7.0.0-dev.321';
126
+ static #ORM_VERSION = '7.0.0-dev.323';
127
127
  /**
128
128
  * Checks if the argument is instance of `Object`. Returns false for arrays.
129
129
  */
package/utils/clone.js CHANGED
@@ -76,7 +76,7 @@ export function clone(parent, respectCustomCloneMethod = true) {
76
76
  return child;
77
77
  }
78
78
  else if (parent instanceof TypedArray) {
79
- child = parent.copyWithin(0);
79
+ child = parent.slice();
80
80
  return child;
81
81
  }
82
82
  else if (parent instanceof Error) {