@mikro-orm/core 6.4.10-dev.10 → 6.4.10-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.
@@ -768,6 +768,7 @@ class MetadataDiscovery {
768
768
  delete prop.default;
769
769
  if (properties[prop.name] && properties[prop.name].type !== prop.type) {
770
770
  properties[prop.name].type = `${properties[prop.name].type} | ${prop.type}`;
771
+ properties[prop.name].runtimeType = 'any';
771
772
  return properties[prop.name];
772
773
  }
773
774
  return properties[prop.name] = prop;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.4.10-dev.10",
3
+ "version": "6.4.10-dev.11",
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.3.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.4.10-dev.10",
67
+ "mikro-orm": "6.4.10-dev.11",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -289,56 +289,72 @@ class EntityComparator {
289
289
  lines.push(`${padding} }`);
290
290
  };
291
291
  lines.push(` const mapped = {};`);
292
- meta.props.forEach(prop => {
293
- if (!prop.fieldNames) {
294
- return;
295
- }
296
- if (prop.targetMeta && prop.fieldNames.length > 1) {
297
- lines.push(` if (${prop.fieldNames.map(field => `typeof ${this.propName(field)} === 'undefined'`).join(' && ')}) {`);
298
- lines.push(` } else if (${prop.fieldNames.map(field => `${this.propName(field)} != null`).join(' && ')}) {`);
299
- lines.push(` ret${this.wrap(prop.name)} = ${this.createCompositeKeyArray(prop)};`);
300
- lines.push(...prop.fieldNames.map(field => ` ${this.propName(field, 'mapped')} = true;`));
301
- lines.push(` } else if (${prop.fieldNames.map(field => `${this.propName(field)} == null`).join(' && ')}) {\n ret${this.wrap(prop.name)} = null;`);
302
- lines.push(...prop.fieldNames.map(field => ` ${this.propName(field, 'mapped')} = true;`), ' }');
303
- return;
304
- }
305
- if (prop.embedded && (meta.embeddable || meta.properties[prop.embedded[0]].object)) {
306
- return;
307
- }
308
- if (prop.runtimeType === 'boolean') {
309
- lines.push(` if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
310
- lines.push(` ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])} == null ? ${this.propName(prop.fieldNames[0])} : !!${this.propName(prop.fieldNames[0])};`);
311
- lines.push(` ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
312
- lines.push(` }`);
313
- }
314
- else if (prop.runtimeType === 'Date' && !this.platform.isNumericProperty(prop)) {
315
- lines.push(` if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
316
- context.set('parseDate', (value) => this.platform.parseDate(value));
317
- parseDate('ret' + this.wrap(prop.name), this.propName(prop.fieldNames[0]));
318
- lines.push(` ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
319
- lines.push(` }`);
320
- }
321
- else if (prop.kind === enums_1.ReferenceKind.EMBEDDED && (prop.object || meta.embeddable)) {
322
- const idx = this.tmpIndex++;
323
- context.set(`mapEmbeddedResult_${idx}`, (data) => {
324
- const item = (0, Utils_1.parseJsonSafe)(data);
325
- if (Array.isArray(item)) {
326
- return item.map(row => row == null ? row : this.getResultMapper(prop.type)(row));
327
- }
328
- return item == null ? item : this.getResultMapper(prop.type)(item);
329
- });
330
- lines.push(` if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
331
- lines.push(` ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])} == null ? ${this.propName(prop.fieldNames[0])} : mapEmbeddedResult_${idx}(${this.propName(prop.fieldNames[0])});`);
332
- lines.push(` ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
333
- lines.push(` }`);
292
+ const mapEntityProperties = (meta, padding = '') => {
293
+ for (const prop of meta.props) {
294
+ if (!prop.fieldNames) {
295
+ continue;
296
+ }
297
+ if (prop.targetMeta && prop.fieldNames.length > 1) {
298
+ lines.push(`${padding} if (${prop.fieldNames.map(field => `typeof ${this.propName(field)} === 'undefined'`).join(' && ')}) {`);
299
+ lines.push(`${padding} } else if (${prop.fieldNames.map(field => `${this.propName(field)} != null`).join(' && ')}) {`);
300
+ lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.createCompositeKeyArray(prop)};`);
301
+ lines.push(...prop.fieldNames.map(field => `${padding} ${this.propName(field, 'mapped')} = true;`));
302
+ lines.push(`${padding} } else if (${prop.fieldNames.map(field => `${this.propName(field)} == null`).join(' && ')}) {\n ret${this.wrap(prop.name)} = null;`);
303
+ lines.push(...prop.fieldNames.map(field => `${padding} ${this.propName(field, 'mapped')} = true;`), ' }');
304
+ continue;
305
+ }
306
+ if (prop.embedded && (meta.embeddable || meta.properties[prop.embedded[0]].object)) {
307
+ continue;
308
+ }
309
+ if (prop.runtimeType === 'boolean') {
310
+ lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
311
+ lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])} == null ? ${this.propName(prop.fieldNames[0])} : !!${this.propName(prop.fieldNames[0])};`);
312
+ lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
313
+ lines.push(`${padding} }`);
314
+ }
315
+ else if (prop.runtimeType === 'Date' && !this.platform.isNumericProperty(prop)) {
316
+ lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
317
+ context.set('parseDate', (value) => this.platform.parseDate(value));
318
+ parseDate('ret' + this.wrap(prop.name), this.propName(prop.fieldNames[0]), padding);
319
+ lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
320
+ lines.push(`${padding} }`);
321
+ }
322
+ else if (prop.kind === enums_1.ReferenceKind.EMBEDDED && (prop.object || meta.embeddable)) {
323
+ const idx = this.tmpIndex++;
324
+ context.set(`mapEmbeddedResult_${idx}`, (data) => {
325
+ const item = (0, Utils_1.parseJsonSafe)(data);
326
+ if (Array.isArray(item)) {
327
+ return item.map(row => row == null ? row : this.getResultMapper(prop.type)(row));
328
+ }
329
+ return item == null ? item : this.getResultMapper(prop.type)(item);
330
+ });
331
+ lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
332
+ lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])} == null ? ${this.propName(prop.fieldNames[0])} : mapEmbeddedResult_${idx}(${this.propName(prop.fieldNames[0])});`);
333
+ lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
334
+ lines.push(`${padding} }`);
335
+ }
336
+ else if (prop.kind !== enums_1.ReferenceKind.EMBEDDED) {
337
+ lines.push(`${padding} if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
338
+ lines.push(`${padding} ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])};`);
339
+ lines.push(`${padding} ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
340
+ lines.push(`${padding} }`);
341
+ }
334
342
  }
335
- else if (prop.kind !== enums_1.ReferenceKind.EMBEDDED) {
336
- lines.push(` if (typeof ${this.propName(prop.fieldNames[0])} !== 'undefined') {`);
337
- lines.push(` ret${this.wrap(prop.name)} = ${this.propName(prop.fieldNames[0])};`);
338
- lines.push(` ${this.propName(prop.fieldNames[0], 'mapped')} = true;`);
343
+ };
344
+ if (meta.polymorphs && meta.discriminatorColumn) {
345
+ for (const polymorph of meta.polymorphs) {
346
+ const first = polymorph === meta.polymorphs[0];
347
+ lines.push(` ${first ? '' : 'else '}if (${this.propName(meta.discriminatorColumn)} == '${polymorph.discriminatorValue}') {`);
348
+ mapEntityProperties(polymorph, ' ');
339
349
  lines.push(` }`);
340
350
  }
341
- });
351
+ lines.push(` else {`);
352
+ mapEntityProperties(meta, ' ');
353
+ lines.push(` }`);
354
+ }
355
+ else {
356
+ mapEntityProperties(meta);
357
+ }
342
358
  lines.push(` for (let k in result) { if (Object.hasOwn(result, k) && !mapped[k]) ret[k] = result[k]; }`);
343
359
  const code = `// compiled mapper for entity ${meta.className}\n`
344
360
  + `return function(result) {\n const ret = {};\n${lines.join('\n')}\n return ret;\n}`;