@mikro-orm/core 6.4.10-dev.9 → 6.4.11-dev.0
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.
|
@@ -258,6 +258,7 @@ class ObjectHydrator extends Hydrator_1.Hydrator {
|
|
|
258
258
|
...prop2,
|
|
259
259
|
name: childProp.name,
|
|
260
260
|
embedded: childProp.embedded,
|
|
261
|
+
embeddedProps: childProp.embeddedProps,
|
|
261
262
|
};
|
|
262
263
|
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
|
263
264
|
ret.push(...hydrateProperty(prop3, childProp.object, [...path, childProp.embedded[1]], childDataKey).map(l => ' ' + l));
|
|
@@ -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;
|
|
@@ -925,7 +926,7 @@ class MetadataDiscovery {
|
|
|
925
926
|
}
|
|
926
927
|
let i = 1;
|
|
927
928
|
Object.values(meta.properties).forEach(prop => {
|
|
928
|
-
const newProp =
|
|
929
|
+
const newProp = { ...prop };
|
|
929
930
|
if (meta.root.properties[prop.name] && meta.root.properties[prop.name].type !== prop.type) {
|
|
930
931
|
const name = newProp.name;
|
|
931
932
|
this.initFieldName(newProp, newProp.object);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.4.
|
|
3
|
+
"version": "6.4.11-dev.0",
|
|
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.
|
|
67
|
+
"mikro-orm": "6.4.11-dev.0",
|
|
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
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
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
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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}`;
|