@mikro-orm/core 6.3.13-dev.0 → 6.3.13-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.
package/MikroORM.d.ts CHANGED
@@ -66,7 +66,7 @@ export declare class MikroORM<D extends IDatabaseDriver = IDatabaseDriver, EM ex
66
66
  /**
67
67
  * Allows dynamically discovering new entity by reference, handy for testing schema diffing.
68
68
  */
69
- discoverEntity<T extends Constructor | EntitySchema>(entities: T | T[]): void;
69
+ discoverEntity<T extends Constructor | EntitySchema>(entities: T | T[], reset?: string | string[]): void;
70
70
  /**
71
71
  * Gets the SchemaGenerator.
72
72
  */
package/MikroORM.js CHANGED
@@ -186,8 +186,12 @@ class MikroORM {
186
186
  /**
187
187
  * Allows dynamically discovering new entity by reference, handy for testing schema diffing.
188
188
  */
189
- discoverEntity(entities) {
189
+ discoverEntity(entities, reset) {
190
190
  entities = utils_1.Utils.asArray(entities);
191
+ for (const className of utils_1.Utils.asArray(reset)) {
192
+ this.metadata.reset(className);
193
+ this.discovery.reset(className);
194
+ }
191
195
  const tmp = this.discovery.discoverReferences(entities);
192
196
  const options = this.config.get('discovery');
193
197
  new metadata_1.MetadataValidator().validateDiscovered([...Object.values(this.metadata.getAll()), ...tmp], options);
@@ -307,7 +307,7 @@ class ArrayCollection {
307
307
  */
308
308
  get property() {
309
309
  if (!this._property) {
310
- const meta = (0, wrap_1.helper)(this.owner).__meta;
310
+ const meta = (0, wrap_1.wrap)(this.owner, true).__meta;
311
311
  /* istanbul ignore if */
312
312
  if (!meta) {
313
313
  throw errors_1.MetadataError.fromUnknownEntity(this.owner.constructor.name, 'Collection.property getter, maybe you just forgot to initialize the ORM?');
@@ -481,6 +481,9 @@ class EntityLoader {
481
481
  }
482
482
  const [f, ...r] = field.split('.');
483
483
  if (wrapped.__loadedProperties.has(f) && wrapped.__meta.properties[f]?.targetMeta) {
484
+ if ([enums_1.ReferenceKind.ONE_TO_MANY, enums_1.ReferenceKind.MANY_TO_MANY].includes(wrapped.__meta.properties[f].kind)) {
485
+ return entity[f].getItems(false).every((item) => this.isPropertyLoaded(item, r.join('.')));
486
+ }
484
487
  return this.isPropertyLoaded(entity[f], r.join('.'));
485
488
  }
486
489
  /* istanbul ignore next */
package/errors.js CHANGED
@@ -173,7 +173,7 @@ class MetadataError extends ValidationError {
173
173
  return new MetadataError('No entities were discovered');
174
174
  }
175
175
  static onlyAbstractEntitiesDiscovered() {
176
- return new MetadataError('Only abstract entities were discovered, maybe you forgot to use @Entity() decorator?');
176
+ return new MetadataError('Only abstract entities were discovered, maybe you forgot to use @Entity() decorator? This can also happen when you have multiple `@mikro-orm/core` packages installed side by side.');
177
177
  }
178
178
  static duplicateEntityDiscovered(paths, subject = 'entity names') {
179
179
  return new MetadataError(`Duplicate ${subject} are not allowed: ${paths.join(', ')}`);
@@ -24,6 +24,7 @@ export declare class MetadataDiscovery {
24
24
  private tryDiscoverTargets;
25
25
  private discoverDirectories;
26
26
  discoverReferences<T>(refs: (Constructor<T> | EntitySchema<T>)[]): EntityMetadata<T>[];
27
+ reset(className: string): void;
27
28
  private prepare;
28
29
  private getSchema;
29
30
  private discoverEntity;
@@ -242,6 +242,13 @@ class MetadataDiscovery {
242
242
  }
243
243
  return this.discovered.filter(meta => found.find(m => m.name === meta.className));
244
244
  }
245
+ reset(className) {
246
+ const exists = this.discovered.findIndex(m => m.className === className);
247
+ if (exists !== -1) {
248
+ this.metadata.reset(this.discovered[exists].className);
249
+ this.discovered.splice(exists, 1);
250
+ }
251
+ }
245
252
  prepare(entity) {
246
253
  if ('schema' in entity && entity.schema instanceof EntitySchema_1.EntitySchema) {
247
254
  return entity.schema;
@@ -1132,7 +1139,12 @@ class MetadataDiscovery {
1132
1139
  }
1133
1140
  }
1134
1141
  if (prop.kind === enums_1.ReferenceKind.SCALAR && !(mappedType instanceof types_1.UnknownType)) {
1135
- prop.columnTypes ??= [mappedType.getColumnType(prop, this.platform)];
1142
+ if (!prop.columnTypes && prop.nativeEnumName && meta.schema !== this.platform.getDefaultSchemaName() && meta.schema && !prop.nativeEnumName.includes('.')) {
1143
+ prop.columnTypes = [`${meta.schema}.${prop.nativeEnumName}`];
1144
+ }
1145
+ else {
1146
+ prop.columnTypes ??= [mappedType.getColumnType(prop, this.platform)];
1147
+ }
1136
1148
  // use only custom types provided by user, we don't need to use the ones provided by ORM,
1137
1149
  // with exception for ArrayType and JsonType, those two are handled in
1138
1150
  if (!Object.values(types_1.t).some(type => type === mappedType.constructor)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.3.13-dev.0",
3
+ "version": "6.3.13-dev.10",
4
4
  "description": "TypeScript ORM for Node.js based on Data Mapper, Unit of Work and Identity Map patterns. Supports MongoDB, MySQL, PostgreSQL and SQLite databases as well as usage with vanilla JavaScript.",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.2.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.3.13-dev.0",
67
+ "mikro-orm": "6.3.13-dev.10",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
package/typings.d.ts CHANGED
@@ -90,8 +90,8 @@ export type Scalar = boolean | number | string | bigint | symbol | Date | RegExp
90
90
  };
91
91
  export type ExpandScalar<T> = null | (T extends string ? T | RegExp : T extends Date ? Date | string : T extends bigint ? bigint | string | number : T);
92
92
  export type OperatorMap<T> = {
93
- $and?: readonly ExpandQuery<T>[];
94
- $or?: readonly ExpandQuery<T>[];
93
+ $and?: ExpandQuery<T>[];
94
+ $or?: ExpandQuery<T>[];
95
95
  $eq?: ExpandScalar<T> | readonly ExpandScalar<T>[];
96
96
  $ne?: ExpandScalar<T>;
97
97
  $in?: readonly ExpandScalar<T>[];
@@ -180,14 +180,20 @@ class ChangeSetPersister {
180
180
  convertCustomTypes: false,
181
181
  processCollections: false,
182
182
  });
183
- const cond = changeSets.map(cs => cs.getPrimaryKey(true));
184
- changeSets.forEach((changeSet, idx) => {
185
- this.checkConcurrencyKeys(meta, changeSet, cond[idx]);
186
- });
187
- const res = await this.driver.nativeUpdateMany(meta.className, cond, changeSets.map(cs => cs.payload), options);
183
+ const cond = [];
184
+ const payload = [];
185
+ for (const changeSet of changeSets) {
186
+ const where = changeSet.getPrimaryKey(true);
187
+ this.checkConcurrencyKeys(meta, changeSet, where);
188
+ cond.push(where);
189
+ payload.push(changeSet.payload);
190
+ }
191
+ const res = await this.driver.nativeUpdateMany(meta.className, cond, payload, options);
192
+ const map = new Map();
193
+ res.rows?.forEach(item => map.set(utils_1.Utils.getCompositeKeyHash(item, meta, true, this.platform, true), item));
188
194
  for (const changeSet of changeSets) {
189
195
  if (res.rows) {
190
- const row = res.rows.find(row => utils_1.Utils.equals(utils_1.Utils.extractPK(row, meta), changeSet.getPrimaryKey()));
196
+ const row = map.get((0, entity_1.helper)(changeSet.entity).getSerializedPrimaryKey());
191
197
  this.mapReturnedValues(changeSet.entity, changeSet.payload, row, meta);
192
198
  }
193
199
  changeSet.persisted = true;
@@ -401,7 +401,9 @@ class EntityComparator {
401
401
  }
402
402
  return true;
403
403
  }
404
- ret += meta.props.filter(p => p.embedded?.[0] === prop.name).map(childProp => {
404
+ ret += meta.props.filter(p => p.embedded?.[0] === prop.name
405
+ // object for JSON embeddable
406
+ && (p.object || (p.persist !== false))).map(childProp => {
405
407
  const childDataKey = meta.embeddable || prop.object ? dataKey + this.wrap(childProp.embedded[1]) : this.wrap(childProp.name);
406
408
  const childEntityKey = [...path, childProp.embedded[1]].map(k => this.wrap(k)).join('');
407
409
  const childCond = `typeof entity${childEntityKey} !== 'undefined'`;