@mikro-orm/entity-generator 7.0.0-rc.2 → 7.0.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.
- package/DefineEntitySourceFile.js +37 -6
- package/EntityGenerator.d.ts +1 -9
- package/EntityGenerator.js +56 -48
- package/EntitySchemaSourceFile.js +7 -3
- package/NativeEnumSourceFile.d.ts +1 -5
- package/README.md +5 -4
- package/SourceFile.d.ts +1 -1
- package/SourceFile.js +112 -68
- package/package.json +31 -31
- package/tsconfig.build.tsbuildinfo +0 -1
package/SourceFile.js
CHANGED
|
@@ -177,7 +177,8 @@ export class SourceFile {
|
|
|
177
177
|
uniqueOpt.properties = Utils.asArray(index.properties).map(prop => this.quote('' + prop));
|
|
178
178
|
}
|
|
179
179
|
if (index.deferMode) {
|
|
180
|
-
uniqueOpt.deferMode =
|
|
180
|
+
uniqueOpt.deferMode =
|
|
181
|
+
`${this.referenceCoreImport('DeferMode')}.INITIALLY_${index.deferMode.toUpperCase()}`;
|
|
181
182
|
}
|
|
182
183
|
const columns = this.getColumnOptions(index.columns);
|
|
183
184
|
if (columns) {
|
|
@@ -197,25 +198,31 @@ export class SourceFile {
|
|
|
197
198
|
generateImports() {
|
|
198
199
|
const imports = new Set();
|
|
199
200
|
if (this.coreImports.size > 0) {
|
|
200
|
-
imports.add(`import { ${
|
|
201
|
+
imports.add(`import { ${[...this.coreImports]
|
|
202
|
+
.sort()
|
|
203
|
+
.map(t => {
|
|
201
204
|
let ret = POSSIBLE_TYPE_IMPORTS.includes(t) ? `type ${t}` : t;
|
|
202
205
|
if (this.options.coreImportsPrefix) {
|
|
203
206
|
const resolvedIdentifier = `${this.options.coreImportsPrefix}${t}`;
|
|
204
207
|
ret += ` as ${resolvedIdentifier}`;
|
|
205
208
|
}
|
|
206
209
|
return ret;
|
|
207
|
-
})
|
|
210
|
+
})
|
|
211
|
+
.join(', ')} } from '@mikro-orm/core';`);
|
|
208
212
|
}
|
|
209
213
|
if (this.decoratorImports.size > 0) {
|
|
210
214
|
const type = this.options.decorators;
|
|
211
|
-
imports.add(`import { ${
|
|
215
|
+
imports.add(`import { ${[...this.decoratorImports]
|
|
216
|
+
.sort()
|
|
217
|
+
.map(t => {
|
|
212
218
|
let ret = t;
|
|
213
219
|
if (this.options.coreImportsPrefix) {
|
|
214
220
|
const resolvedIdentifier = `${this.options.coreImportsPrefix}${t}`;
|
|
215
221
|
ret += ` as ${resolvedIdentifier}`;
|
|
216
222
|
}
|
|
217
223
|
return ret;
|
|
218
|
-
})
|
|
224
|
+
})
|
|
225
|
+
.join(', ')} } from '@mikro-orm/decorators/${type}';`);
|
|
219
226
|
}
|
|
220
227
|
const extension = this.options.esmImport ? '.js' : '';
|
|
221
228
|
const { dir, base } = parse(`${this.options.path ?? '.'}/${this.getBaseName()}`);
|
|
@@ -325,22 +332,28 @@ export class SourceFile {
|
|
|
325
332
|
}
|
|
326
333
|
return prop.type;
|
|
327
334
|
})();
|
|
328
|
-
const hasUsableNullDefault =
|
|
329
|
-
const useDefault = hasUsableNullDefault ||
|
|
330
|
-
|
|
335
|
+
const hasUsableNullDefault = prop.nullable && !this.options.forceUndefined && prop.default === null;
|
|
336
|
+
const useDefault = hasUsableNullDefault ||
|
|
337
|
+
(!(typeof prop.default === 'undefined' || prop.default === null) &&
|
|
338
|
+
propType !== 'unknown' &&
|
|
339
|
+
typeof breakdownOfIType === 'undefined');
|
|
340
|
+
const optional = prop.nullable && (this.options.forceUndefined || prop.optional) ? '?' : useDefault ? '' : '!';
|
|
331
341
|
let ret = `${propName}${optional}: `;
|
|
332
342
|
const isArray = prop.array && (prop.kind === ReferenceKind.EMBEDDED || prop.enum);
|
|
333
343
|
const complexType = isArray ? `${propType}[]` : propType;
|
|
334
344
|
let wrappedType = prop.ref
|
|
335
|
-
? `${this.referenceCoreImport('Ref')}<${complexType}${
|
|
336
|
-
:
|
|
337
|
-
|
|
345
|
+
? `${this.referenceCoreImport('Ref')}<${complexType}${isScalar && prop.nullable && !this.options.forceUndefined ? ' | null' : ''}>`
|
|
346
|
+
: this.options.esmImport && !isScalar
|
|
347
|
+
? `${this.referenceCoreImport('Rel')}<${complexType}>`
|
|
348
|
+
: complexType;
|
|
349
|
+
if (prop.nullable &&
|
|
350
|
+
!this.options.forceUndefined &&
|
|
351
|
+
(!isScalar || (!prop.ref && !wrappedType.includes(' | null')))) {
|
|
338
352
|
wrappedType += ' | null';
|
|
339
353
|
}
|
|
340
|
-
const optionalType =
|
|
341
|
-
|
|
342
|
-
:
|
|
343
|
-
ret += (!this.options.forceUndefined && prop.nullable && (hiddenType || optionalType)) ? `(${wrappedType})` : wrappedType;
|
|
354
|
+
const optionalType = optional !== '?' && prop.optional ? ` & ${this.referenceCoreImport('Opt')}` : '';
|
|
355
|
+
ret +=
|
|
356
|
+
!this.options.forceUndefined && prop.nullable && (hiddenType || optionalType) ? `(${wrappedType})` : wrappedType;
|
|
344
357
|
ret += hiddenType;
|
|
345
358
|
ret += optionalType;
|
|
346
359
|
if (!useDefault) {
|
|
@@ -424,17 +437,19 @@ export class SourceFile {
|
|
|
424
437
|
return res;
|
|
425
438
|
}
|
|
426
439
|
}
|
|
427
|
-
const nextWordwrap = typeof wordwrap === 'number' ? 80 - (spaces ?? 0) -
|
|
440
|
+
const nextWordwrap = typeof wordwrap === 'number' ? 80 - (spaces ?? 0) - level * 2 : undefined;
|
|
428
441
|
const sep = typeof spaces === 'undefined' ? ', ' : `,\n${' '.repeat(spaces)}`;
|
|
429
442
|
const doIndent = typeof spaces !== 'undefined';
|
|
430
443
|
if (Array.isArray(options)) {
|
|
431
|
-
return `[${doIndent ? `\n${' '.repeat(spaces)}` : ''}${options.map(val => `${doIndent ? ' '.repeat(
|
|
444
|
+
return `[${doIndent ? `\n${' '.repeat(spaces)}` : ''}${options.map(val => `${doIndent ? ' '.repeat(level * 2 + (spaces + 2)) : ''}${this.serializeValue(val, typeof nextWordwrap === 'number' ? nextWordwrap : undefined, doIndent ? spaces : undefined, level + 1)}`).join(sep)}${doIndent ? `${options.length > 0 ? ',\n' : ''}${' '.repeat(spaces + level * 2)}` : ''}]`;
|
|
432
445
|
}
|
|
433
446
|
const entries = Object.entries(options);
|
|
434
|
-
return `{${doIndent ? `\n${' '.repeat(spaces)}` : ' '}${entries
|
|
447
|
+
return `{${doIndent ? `\n${' '.repeat(spaces)}` : ' '}${entries
|
|
448
|
+
.map(([opt, val]) => {
|
|
435
449
|
const key = identifierRegex.test(opt) ? opt : this.quote(opt);
|
|
436
|
-
return `${doIndent ? ' '.repeat(
|
|
437
|
-
})
|
|
450
|
+
return `${doIndent ? ' '.repeat(level * 2 + (spaces + 2)) : ''}${key}: ${this.serializeValue(val, typeof nextWordwrap === 'number' ? nextWordwrap - key.length - 2 /* ': '.length*/ : undefined, doIndent ? spaces : undefined, level + 1)}`;
|
|
451
|
+
})
|
|
452
|
+
.join(sep)}${doIndent ? `${entries.length > 0 ? ',\n' : ''}${' '.repeat(spaces + level * 2)}` : ' '}}`;
|
|
438
453
|
}
|
|
439
454
|
serializeValue(val, wordwrap, spaces, level = 1) {
|
|
440
455
|
if (typeof val === 'object' && val !== null) {
|
|
@@ -473,21 +488,31 @@ export class SourceFile {
|
|
|
473
488
|
}
|
|
474
489
|
getEmbeddableDeclOptions() {
|
|
475
490
|
const options = {};
|
|
476
|
-
|
|
491
|
+
const result = this.getCollectionDecl(options);
|
|
492
|
+
if (result.discriminatorColumn) {
|
|
493
|
+
result.discriminator = result.discriminatorColumn;
|
|
494
|
+
delete result.discriminatorColumn;
|
|
495
|
+
}
|
|
496
|
+
return result;
|
|
477
497
|
}
|
|
478
498
|
getCollectionDecl(options) {
|
|
479
499
|
if (this.meta.abstract) {
|
|
480
500
|
options.abstract = true;
|
|
481
501
|
}
|
|
482
502
|
if (this.meta.discriminatorValue) {
|
|
483
|
-
options.discriminatorValue =
|
|
503
|
+
options.discriminatorValue =
|
|
504
|
+
typeof this.meta.discriminatorValue === 'string'
|
|
505
|
+
? this.quote(this.meta.discriminatorValue)
|
|
506
|
+
: this.meta.discriminatorValue;
|
|
484
507
|
}
|
|
485
508
|
if (this.meta.discriminatorColumn) {
|
|
486
509
|
options.discriminatorColumn = this.quote(this.meta.discriminatorColumn);
|
|
487
510
|
}
|
|
488
511
|
if (this.meta.discriminatorMap) {
|
|
489
|
-
options.discriminatorMap = Object.fromEntries(Object.entries(this.meta.discriminatorMap)
|
|
490
|
-
|
|
512
|
+
options.discriminatorMap = Object.fromEntries(Object.entries(this.meta.discriminatorMap).map(([discriminatorValue, cls]) => [
|
|
513
|
+
discriminatorValue,
|
|
514
|
+
this.quote(Utils.className(cls)),
|
|
515
|
+
]));
|
|
491
516
|
}
|
|
492
517
|
return options;
|
|
493
518
|
}
|
|
@@ -518,7 +543,7 @@ export class SourceFile {
|
|
|
518
543
|
decoratorArgs.push(prop.formula.toString());
|
|
519
544
|
}
|
|
520
545
|
if (Utils.hasObjectKeys(options)) {
|
|
521
|
-
decoratorArgs.push(
|
|
546
|
+
decoratorArgs.push(this.serializeObject(options));
|
|
522
547
|
}
|
|
523
548
|
return `${decorator}(${decoratorArgs.join(', ')})\n`;
|
|
524
549
|
}
|
|
@@ -529,7 +554,7 @@ export class SourceFile {
|
|
|
529
554
|
return;
|
|
530
555
|
}
|
|
531
556
|
const defaultName = this.platform.getIndexName(this.meta.collection, prop.fieldNames, type);
|
|
532
|
-
options[type] =
|
|
557
|
+
options[type] = propType === true || defaultName === propType ? 'true' : this.quote(propType);
|
|
533
558
|
const expected = {
|
|
534
559
|
index: this.platform.indexForeignKeys(),
|
|
535
560
|
unique: prop.kind === ReferenceKind.ONE_TO_ONE,
|
|
@@ -574,12 +599,10 @@ export class SourceFile {
|
|
|
574
599
|
if (prop.primary && (prop.enum || !(typeof prop.kind === 'undefined' || prop.kind === ReferenceKind.SCALAR))) {
|
|
575
600
|
options.primary = true;
|
|
576
601
|
}
|
|
577
|
-
['persist', 'hydrate']
|
|
578
|
-
.filter(key => prop[key] === false)
|
|
579
|
-
.forEach(key => options[key] = false);
|
|
602
|
+
['persist', 'hydrate'].filter(key => prop[key] === false).forEach(key => (options[key] = false));
|
|
580
603
|
['onCreate', 'onUpdate', 'serializer']
|
|
581
604
|
.filter(key => typeof prop[key] === 'function')
|
|
582
|
-
.forEach(key => options[key] = `${prop[key]}`);
|
|
605
|
+
.forEach(key => (options[key] = `${prop[key]}`));
|
|
583
606
|
if (typeof prop.serializedName === 'string') {
|
|
584
607
|
options.serializedName = this.quote(prop.serializedName);
|
|
585
608
|
}
|
|
@@ -588,7 +611,7 @@ export class SourceFile {
|
|
|
588
611
|
}
|
|
589
612
|
['hidden', 'version', 'concurrencyCheck', 'eager', 'lazy', 'orphanRemoval']
|
|
590
613
|
.filter(key => prop[key])
|
|
591
|
-
.forEach(key => options[key] = true);
|
|
614
|
+
.forEach(key => (options[key] = true));
|
|
592
615
|
if (prop.cascade && (prop.cascade.length !== 1 || prop.cascade[0] !== Cascade.PERSIST)) {
|
|
593
616
|
options.cascade = `[${prop.cascade.map(value => `${this.referenceCoreImport('Cascade')}.${value.toUpperCase()}`).join(', ')}]`;
|
|
594
617
|
}
|
|
@@ -597,11 +620,17 @@ export class SourceFile {
|
|
|
597
620
|
}
|
|
598
621
|
// TODO: Composite FKs with default values require additions to default/defaultRaw that are not yet supported.
|
|
599
622
|
if (prop.fieldNames?.length <= 1) {
|
|
600
|
-
if (typeof prop.defaultRaw !== 'undefined' &&
|
|
623
|
+
if (typeof prop.defaultRaw !== 'undefined' &&
|
|
624
|
+
prop.defaultRaw !== 'null' &&
|
|
625
|
+
prop.defaultRaw !== '' &&
|
|
601
626
|
prop.defaultRaw !== (typeof prop.default === 'string' ? this.quote(prop.default) : `${prop.default}`)) {
|
|
602
627
|
options.defaultRaw = `\`${prop.defaultRaw}\``;
|
|
603
628
|
}
|
|
604
|
-
else if (!(typeof prop.default === 'undefined' || prop.default === null) &&
|
|
629
|
+
else if (!(typeof prop.default === 'undefined' || prop.default === null) &&
|
|
630
|
+
(prop.ref ||
|
|
631
|
+
(!prop.enum &&
|
|
632
|
+
(typeof prop.kind === 'undefined' || prop.kind === ReferenceKind.SCALAR) &&
|
|
633
|
+
(prop.type === 'unknown' || typeof this.breakdownOfIType(prop) !== 'undefined')))) {
|
|
605
634
|
options.default = typeof prop.default === 'string' ? this.quote(prop.default) : prop.default;
|
|
606
635
|
}
|
|
607
636
|
}
|
|
@@ -616,17 +645,18 @@ export class SourceFile {
|
|
|
616
645
|
options.ignoreSchemaChanges.push(...prop.ignoreSchemaChanges.map(v => this.quote(v)));
|
|
617
646
|
}
|
|
618
647
|
}
|
|
619
|
-
propTypeBreakdowns = new WeakMap();
|
|
648
|
+
#propTypeBreakdowns = new WeakMap();
|
|
620
649
|
breakdownOfIType(prop) {
|
|
621
|
-
if (this
|
|
622
|
-
return this
|
|
650
|
+
if (this.#propTypeBreakdowns.has(prop)) {
|
|
651
|
+
return this.#propTypeBreakdowns.get(prop);
|
|
623
652
|
}
|
|
624
653
|
const mappedDeclaredType = this.platform.getMappedType(prop.type);
|
|
625
|
-
const mappedRawType =
|
|
626
|
-
|
|
627
|
-
|
|
654
|
+
const mappedRawType = prop.customTypes?.[0] ??
|
|
655
|
+
(prop.type !== 'unknown' && mappedDeclaredType instanceof UnknownType
|
|
656
|
+
? this.platform.getMappedType(prop.columnTypes[0])
|
|
657
|
+
: mappedDeclaredType);
|
|
628
658
|
const rawType = mappedRawType.runtimeType;
|
|
629
|
-
const mappedSerializedType =
|
|
659
|
+
const mappedSerializedType = prop.customType ?? mappedRawType;
|
|
630
660
|
const serializedType = mappedSerializedType.runtimeType;
|
|
631
661
|
// Add non-lib imports where needed.
|
|
632
662
|
for (const typeSpec of [prop.runtimeType, rawType, serializedType]) {
|
|
@@ -640,10 +670,12 @@ export class SourceFile {
|
|
|
640
670
|
mappedRawType.prop?.nullable ?? prop.nullable ?? false,
|
|
641
671
|
mappedSerializedType.prop?.nullable ?? prop.nullable ?? false,
|
|
642
672
|
];
|
|
643
|
-
const hasMixedNullability =
|
|
673
|
+
const hasMixedNullability = new Set(nullables).size > 1;
|
|
644
674
|
if (prop.runtimeType !== rawType || rawType !== serializedType || hasMixedNullability) {
|
|
645
675
|
const nullType = this.options.forceUndefined ? ' | undefined' : ' | null';
|
|
646
|
-
if (rawType !== serializedType ||
|
|
676
|
+
if (rawType !== serializedType ||
|
|
677
|
+
nullables[1] !== nullables[2] ||
|
|
678
|
+
(prop.hidden && nullables[0] !== nullables[1])) {
|
|
647
679
|
const r = [prop.runtimeType, rawType, serializedType];
|
|
648
680
|
if (hasMixedNullability || prop.hidden) {
|
|
649
681
|
for (let i = r.length - 1; i >= 0; --i) {
|
|
@@ -655,7 +687,7 @@ export class SourceFile {
|
|
|
655
687
|
r[2] = `(${r[2]}) & ${this.referenceCoreImport('Hidden')}`;
|
|
656
688
|
}
|
|
657
689
|
}
|
|
658
|
-
this
|
|
690
|
+
this.#propTypeBreakdowns.set(prop, r);
|
|
659
691
|
return r;
|
|
660
692
|
}
|
|
661
693
|
const r = [prop.runtimeType, rawType];
|
|
@@ -666,11 +698,11 @@ export class SourceFile {
|
|
|
666
698
|
}
|
|
667
699
|
}
|
|
668
700
|
}
|
|
669
|
-
this
|
|
701
|
+
this.#propTypeBreakdowns.set(prop, r);
|
|
670
702
|
return r;
|
|
671
703
|
}
|
|
672
704
|
const r = undefined;
|
|
673
|
-
this
|
|
705
|
+
this.#propTypeBreakdowns.set(prop, r);
|
|
674
706
|
return r;
|
|
675
707
|
}
|
|
676
708
|
getScalarPropertyDecoratorOptions(options, prop, quote = true) {
|
|
@@ -708,14 +740,19 @@ export class SourceFile {
|
|
|
708
740
|
options.type = prop.type;
|
|
709
741
|
}
|
|
710
742
|
else {
|
|
711
|
-
if (this.options.scalarTypeInDecorator // always output type if forced by the generator options
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
743
|
+
if (this.options.scalarTypeInDecorator || // always output type if forced by the generator options
|
|
744
|
+
(prop.nullable && !this.options.forceUndefined) || // also when there is the "| null" type modifier (because reflect-metadata can't extract the base)
|
|
745
|
+
prop.hidden || // also when there is the "& Hidden" type modifier (because reflect-metadata can't extract the base)
|
|
746
|
+
new Set([
|
|
747
|
+
mappedRuntimeType.name,
|
|
748
|
+
mappedColumnType.name,
|
|
749
|
+
mappedDeclaredType.name,
|
|
750
|
+
this.platform.getMappedType(prop.runtimeType === 'Date' ? 'datetime' : prop.runtimeType).name,
|
|
751
|
+
]).size > 1 || // also, if there's any ambiguity in the type
|
|
752
|
+
(() => {
|
|
753
|
+
const hasUsableNullDefault = prop.nullable && !this.options.forceUndefined && prop.default === null;
|
|
717
754
|
const useDefault = hasUsableNullDefault || !(typeof prop.default === 'undefined' || prop.default === null);
|
|
718
|
-
return (
|
|
755
|
+
return (useDefault && !hasUsableNullDefault) || (prop.optional && !prop.nullable);
|
|
719
756
|
})() // also when there is the "| Opt" type modifier (because reflect-metadata can't extract the base)
|
|
720
757
|
) {
|
|
721
758
|
options.type = quote ? this.quote(prop.type) : prop.type;
|
|
@@ -725,13 +762,16 @@ export class SourceFile {
|
|
|
725
762
|
const columnTypeFromMappedColumnType = mappedColumnType.getColumnType({ ...prop, autoincrement: false }, this.platform);
|
|
726
763
|
const columnTypeFromMappedDeclaredType = mappedDeclaredType.getColumnType({ ...prop, autoincrement: false }, this.platform);
|
|
727
764
|
const needsExplicitColumnType = () => {
|
|
728
|
-
if (isTypeStringMissingFromMap ||
|
|
765
|
+
if (isTypeStringMissingFromMap ||
|
|
766
|
+
[mappedRuntimeType, mappedColumnType, columnTypeFromMappedDeclaredType].some(t => t instanceof UnknownType)) {
|
|
729
767
|
return true;
|
|
730
768
|
}
|
|
731
|
-
if (this.platform.normalizeColumnType(prop.columnTypes[0], prop) !==
|
|
769
|
+
if (this.platform.normalizeColumnType(prop.columnTypes[0], prop) !==
|
|
770
|
+
this.platform.normalizeColumnType(columnTypeFromMappedColumnType, prop)) {
|
|
732
771
|
return prop.columnTypes[0] !== columnTypeFromMappedColumnType;
|
|
733
772
|
}
|
|
734
|
-
return columnTypeFromMappedRuntimeType !== columnTypeFromMappedColumnType ||
|
|
773
|
+
return (columnTypeFromMappedRuntimeType !== columnTypeFromMappedColumnType ||
|
|
774
|
+
columnTypeFromMappedDeclaredType !== columnTypeFromMappedColumnType);
|
|
735
775
|
};
|
|
736
776
|
if (needsExplicitColumnType()) {
|
|
737
777
|
options.columnType = this.quote(prop.columnTypes[0]);
|
|
@@ -741,7 +781,9 @@ export class SourceFile {
|
|
|
741
781
|
options[key] = prop[key];
|
|
742
782
|
}
|
|
743
783
|
};
|
|
744
|
-
if (!options.columnType &&
|
|
784
|
+
if (!options.columnType &&
|
|
785
|
+
(typeof mappedColumnType.getDefaultLength === 'undefined' ||
|
|
786
|
+
mappedColumnType.getDefaultLength(this.platform) !== prop.length)) {
|
|
745
787
|
assign('length');
|
|
746
788
|
}
|
|
747
789
|
// those are already included in the `columnType` in most cases, and when that option is present, they would be ignored anyway
|
|
@@ -756,11 +798,15 @@ export class SourceFile {
|
|
|
756
798
|
assign('unsigned');
|
|
757
799
|
}
|
|
758
800
|
if (prop.autoincrement) {
|
|
759
|
-
if (!prop.primary ||
|
|
801
|
+
if (!prop.primary ||
|
|
802
|
+
!this.platform.isNumericColumn(mappedColumnType) ||
|
|
803
|
+
this.meta.getPrimaryProps().length !== 1) {
|
|
760
804
|
options.autoincrement = true;
|
|
761
805
|
}
|
|
762
806
|
}
|
|
763
|
-
else if (prop.primary &&
|
|
807
|
+
else if (prop.primary &&
|
|
808
|
+
this.platform.isNumericColumn(mappedColumnType) &&
|
|
809
|
+
this.meta.getPrimaryProps().length === 1) {
|
|
764
810
|
options.autoincrement = false;
|
|
765
811
|
}
|
|
766
812
|
if (prop.generated) {
|
|
@@ -777,7 +823,8 @@ export class SourceFile {
|
|
|
777
823
|
options.mappedBy = this.quote(prop.mappedBy);
|
|
778
824
|
return;
|
|
779
825
|
}
|
|
780
|
-
if (prop.pivotTable !==
|
|
826
|
+
if (prop.pivotTable !==
|
|
827
|
+
this.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name, this.meta.tableName)) {
|
|
781
828
|
options.pivotTable = this.quote(prop.pivotTable);
|
|
782
829
|
}
|
|
783
830
|
if (prop.pivotEntity && Utils.className(prop.pivotEntity) !== prop.pivotTable) {
|
|
@@ -788,13 +835,13 @@ export class SourceFile {
|
|
|
788
835
|
options.joinColumn = this.quote(prop.joinColumns[0]);
|
|
789
836
|
}
|
|
790
837
|
else {
|
|
791
|
-
options.joinColumns = `[${prop.joinColumns.map(this.quote).join(', ')}]`;
|
|
838
|
+
options.joinColumns = `[${prop.joinColumns.map(c => this.quote(c)).join(', ')}]`;
|
|
792
839
|
}
|
|
793
840
|
if (prop.inverseJoinColumns.length === 1) {
|
|
794
841
|
options.inverseJoinColumn = this.quote(prop.inverseJoinColumns[0]);
|
|
795
842
|
}
|
|
796
843
|
else {
|
|
797
|
-
options.inverseJoinColumns = `[${prop.inverseJoinColumns.map(this.quote).join(', ')}]`;
|
|
844
|
+
options.inverseJoinColumns = `[${prop.inverseJoinColumns.map(c => this.quote(c)).join(', ')}]`;
|
|
798
845
|
}
|
|
799
846
|
if (prop.fixedOrder) {
|
|
800
847
|
options.fixedOrder = true;
|
|
@@ -843,7 +890,8 @@ export class SourceFile {
|
|
|
843
890
|
}
|
|
844
891
|
}
|
|
845
892
|
else {
|
|
846
|
-
if (prop.fieldNames.length > 1 &&
|
|
893
|
+
if (prop.fieldNames.length > 1 &&
|
|
894
|
+
prop.fieldNames.some((fieldName, i) => fieldName !== this.namingStrategy.joinKeyColumnName(prop.name, prop.referencedColumnNames[i]))) {
|
|
847
895
|
options.fieldNames = prop.fieldNames.map(fieldName => this.quote(fieldName));
|
|
848
896
|
}
|
|
849
897
|
}
|
|
@@ -896,14 +944,10 @@ export class SourceFile {
|
|
|
896
944
|
}
|
|
897
945
|
referenceCoreImport(identifier) {
|
|
898
946
|
this.coreImports.add(identifier);
|
|
899
|
-
return this.options.coreImportsPrefix
|
|
900
|
-
? `${this.options.coreImportsPrefix}${identifier}`
|
|
901
|
-
: identifier;
|
|
947
|
+
return this.options.coreImportsPrefix ? `${this.options.coreImportsPrefix}${identifier}` : identifier;
|
|
902
948
|
}
|
|
903
949
|
referenceDecoratorImport(identifier) {
|
|
904
950
|
this.decoratorImports.add(identifier);
|
|
905
|
-
return this.options.coreImportsPrefix
|
|
906
|
-
? `${this.options.coreImportsPrefix}${identifier}`
|
|
907
|
-
: identifier;
|
|
951
|
+
return this.options.coreImportsPrefix ? `${this.options.coreImportsPrefix}${identifier}` : identifier;
|
|
908
952
|
}
|
|
909
953
|
}
|
package/package.json
CHANGED
|
@@ -1,44 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/entity-generator",
|
|
3
|
-
"
|
|
4
|
-
"version": "7.0.0-rc.2",
|
|
3
|
+
"version": "7.0.0",
|
|
5
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.",
|
|
6
|
-
"exports": {
|
|
7
|
-
"./package.json": "./package.json",
|
|
8
|
-
".": "./index.js"
|
|
9
|
-
},
|
|
10
|
-
"repository": {
|
|
11
|
-
"type": "git",
|
|
12
|
-
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
13
|
-
},
|
|
14
5
|
"keywords": [
|
|
15
|
-
"
|
|
6
|
+
"data-mapper",
|
|
7
|
+
"ddd",
|
|
8
|
+
"entity",
|
|
9
|
+
"identity-map",
|
|
10
|
+
"javascript",
|
|
11
|
+
"js",
|
|
12
|
+
"mariadb",
|
|
13
|
+
"mikro-orm",
|
|
16
14
|
"mongo",
|
|
17
15
|
"mongodb",
|
|
18
16
|
"mysql",
|
|
19
|
-
"
|
|
17
|
+
"orm",
|
|
20
18
|
"postgresql",
|
|
21
19
|
"sqlite",
|
|
22
20
|
"sqlite3",
|
|
23
21
|
"ts",
|
|
24
22
|
"typescript",
|
|
25
|
-
"
|
|
26
|
-
"javascript",
|
|
27
|
-
"entity",
|
|
28
|
-
"ddd",
|
|
29
|
-
"mikro-orm",
|
|
30
|
-
"unit-of-work",
|
|
31
|
-
"data-mapper",
|
|
32
|
-
"identity-map"
|
|
23
|
+
"unit-of-work"
|
|
33
24
|
],
|
|
34
|
-
"
|
|
35
|
-
"license": "MIT",
|
|
25
|
+
"homepage": "https://mikro-orm.io",
|
|
36
26
|
"bugs": {
|
|
37
27
|
"url": "https://github.com/mikro-orm/mikro-orm/issues"
|
|
38
28
|
},
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
|
|
29
|
+
"license": "MIT",
|
|
30
|
+
"author": "Martin Adámek",
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "git+ssh://git@github.com/mikro-orm/mikro-orm.git"
|
|
34
|
+
},
|
|
35
|
+
"type": "module",
|
|
36
|
+
"exports": {
|
|
37
|
+
"./package.json": "./package.json",
|
|
38
|
+
".": "./index.js"
|
|
39
|
+
},
|
|
40
|
+
"publishConfig": {
|
|
41
|
+
"access": "public"
|
|
42
42
|
},
|
|
43
43
|
"scripts": {
|
|
44
44
|
"build": "yarn compile && yarn copy",
|
|
@@ -46,16 +46,16 @@
|
|
|
46
46
|
"compile": "yarn run -T tsc -p tsconfig.build.json",
|
|
47
47
|
"copy": "node ../../scripts/copy.mjs"
|
|
48
48
|
},
|
|
49
|
-
"publishConfig": {
|
|
50
|
-
"access": "public"
|
|
51
|
-
},
|
|
52
49
|
"dependencies": {
|
|
53
|
-
"@mikro-orm/sql": "7.0.0
|
|
50
|
+
"@mikro-orm/sql": "7.0.0"
|
|
54
51
|
},
|
|
55
52
|
"devDependencies": {
|
|
56
|
-
"@mikro-orm/core": "^
|
|
53
|
+
"@mikro-orm/core": "^7.0.0"
|
|
57
54
|
},
|
|
58
55
|
"peerDependencies": {
|
|
59
|
-
"@mikro-orm/core": "
|
|
56
|
+
"@mikro-orm/core": "^6.0.0"
|
|
57
|
+
},
|
|
58
|
+
"engines": {
|
|
59
|
+
"node": ">= 22.17.0"
|
|
60
60
|
}
|
|
61
61
|
}
|