@mikro-orm/entity-generator 7.0.0-dev.2 → 7.0.0-dev.200

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/SourceFile.js CHANGED
@@ -1,18 +1,20 @@
1
- import { Cascade, Config, DecimalType, ReferenceKind, SCALAR_TYPES, UnknownType, Utils, } from '@mikro-orm/core';
1
+ import { Cascade, Config, DecimalType, ReferenceKind, SCALAR_TYPES, UnknownType, Utils, inspect, } from '@mikro-orm/core';
2
2
  import { parse, relative } from 'node:path';
3
3
  import { POSSIBLE_TYPE_IMPORTS } from './CoreImportsHelper.js';
4
4
  /**
5
5
  * @see https://github.com/tc39/proposal-regexp-unicode-property-escapes#other-examples
6
6
  */
7
7
  export const identifierRegex = /^(?:[$_\p{ID_Start}])(?:[$\u200C\u200D\p{ID_Continue}])*$/u;
8
- const primitivesAndLibs = [...SCALAR_TYPES, 'bigint', 'Uint8Array', 'unknown', 'object', 'any'];
8
+ const primitivesAndLibs = [...SCALAR_TYPES, 'unknown', 'object', 'any'];
9
9
  export class SourceFile {
10
10
  meta;
11
11
  namingStrategy;
12
12
  platform;
13
13
  options;
14
14
  coreImports = new Set();
15
+ decoratorImports = new Set();
15
16
  entityImports = new Set();
17
+ enumImports = new Map();
16
18
  constructor(meta, namingStrategy, platform, options) {
17
19
  this.meta = meta;
18
20
  this.namingStrategy = namingStrategy;
@@ -24,24 +26,24 @@ export class SourceFile {
24
26
  if (this.meta.embeddable || this.meta.collection) {
25
27
  if (this.meta.embeddable) {
26
28
  const options = this.getEmbeddableDeclOptions();
27
- ret += `@${this.referenceCoreImport('Embeddable')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
29
+ ret += `@${this.referenceDecoratorImport('Embeddable')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
28
30
  }
29
31
  else {
30
32
  const options = this.getEntityDeclOptions();
31
- ret += `@${this.referenceCoreImport('Entity')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
33
+ ret += `@${this.referenceDecoratorImport('Entity')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
32
34
  }
33
35
  }
34
36
  for (const index of this.meta.indexes) {
35
37
  if (index.properties?.length === 1 && typeof this.meta.properties[index.properties[0]] !== 'undefined') {
36
38
  continue;
37
39
  }
38
- ret += `@${this.referenceCoreImport('Index')}(${this.serializeObject(this.getIndexOptions(index))})\n`;
40
+ ret += `@${this.referenceDecoratorImport('Index')}(${this.serializeObject(this.getIndexOptions(index))})\n`;
39
41
  }
40
42
  for (const index of this.meta.uniques) {
41
43
  if (index.properties?.length === 1 && typeof this.meta.properties[index.properties[0]] !== 'undefined') {
42
44
  continue;
43
45
  }
44
- ret += `@${this.referenceCoreImport('Unique')}(${this.serializeObject(this.getUniqueOptions(index))})\n`;
46
+ ret += `@${this.referenceDecoratorImport('Unique')}(${this.serializeObject(this.getUniqueOptions(index))})\n`;
45
47
  }
46
48
  let classHead = '';
47
49
  if (this.meta.className === this.options.customBaseEntityName) {
@@ -64,7 +66,10 @@ export class SourceFile {
64
66
  classBody += definition;
65
67
  classBody += '\n';
66
68
  if (prop.enum) {
67
- enumDefinitions.push(this.getEnumClassDefinition(prop, 2));
69
+ const def = this.getEnumClassDefinition(prop, 2);
70
+ if (def.length) {
71
+ enumDefinitions.push(def);
72
+ }
68
73
  }
69
74
  if (prop.eager) {
70
75
  eagerProperties.push(prop);
@@ -98,9 +103,12 @@ export class SourceFile {
98
103
  if (typeof index.name === 'string') {
99
104
  indexOpt.name = this.quote(index.name);
100
105
  }
101
- if (index.expression) {
106
+ if (typeof index.expression === 'string') {
102
107
  indexOpt.expression = this.quote(index.expression);
103
108
  }
109
+ else if (typeof index.expression === 'function') {
110
+ indexOpt.expression = `${index.expression}`.replace(')=>`', ') => `');
111
+ }
104
112
  if (isAtEntityLevel && index.properties) {
105
113
  indexOpt.properties = Utils.asArray(index.properties).map(prop => this.quote('' + prop));
106
114
  }
@@ -111,9 +119,12 @@ export class SourceFile {
111
119
  if (typeof index.name === 'string') {
112
120
  uniqueOpt.name = this.quote(index.name);
113
121
  }
114
- if (index.expression) {
122
+ if (typeof index.expression === 'string') {
115
123
  uniqueOpt.expression = this.quote(index.expression);
116
124
  }
125
+ else if (typeof index.expression === 'function') {
126
+ uniqueOpt.expression = `${index.expression}`.replace(')=>`', ') => `');
127
+ }
117
128
  if (isAtEntityLevel && index.properties) {
118
129
  uniqueOpt.properties = Utils.asArray(index.properties).map(prop => this.quote('' + prop));
119
130
  }
@@ -134,37 +145,61 @@ export class SourceFile {
134
145
  return ret;
135
146
  }).join(', '))} } from '@mikro-orm/core';`);
136
147
  }
148
+ if (this.decoratorImports.size > 0) {
149
+ const type = this.options.decorators;
150
+ imports.add(`import { ${([...this.decoratorImports].sort().map(t => {
151
+ let ret = t;
152
+ if (this.options.coreImportsPrefix) {
153
+ const resolvedIdentifier = `${this.options.coreImportsPrefix}${t}`;
154
+ ret += ` as ${resolvedIdentifier}`;
155
+ }
156
+ return ret;
157
+ }).join(', '))} } from '@mikro-orm/decorators/${type}';`);
158
+ }
137
159
  const extension = this.options.esmImport ? '.js' : '';
138
160
  const { dir, base } = parse(`${this.options.path ?? '.'}/${this.getBaseName()}`);
139
161
  const basePath = relative(dir, this.options.path ?? '.') || '.';
140
162
  (this.options.extraImports?.(basePath, base) ?? []).forEach(v => this.entityImports.add(v));
141
163
  const entityImports = [...this.entityImports].filter(e => e !== this.meta.className);
142
- entityImports.sort().forEach(entity => {
164
+ const importMap = new Map();
165
+ for (const entity of entityImports) {
143
166
  const file = this.options.onImport?.(entity, basePath, extension, base) ?? {
144
167
  path: `${basePath}/${this.options.fileName(entity)}${extension}`,
145
168
  name: entity,
146
169
  };
147
170
  if (file.path === '') {
148
171
  if (file.name === '') {
149
- return;
172
+ continue;
150
173
  }
151
- imports.add(`import ${this.quote(file.name)};`);
152
- return;
174
+ importMap.set(file.path, `import ${this.quote(file.name)};`);
175
+ continue;
153
176
  }
154
177
  if (file.name === '') {
155
- imports.add(`import * as ${entity} from ${this.quote(file.path)};`);
156
- return;
178
+ importMap.set(file.path, `import * as ${entity} from ${this.quote(file.path)};`);
179
+ continue;
157
180
  }
158
181
  if (file.name === 'default') {
159
- imports.add(`import ${entity} from ${this.quote(file.path)};`);
160
- return;
182
+ importMap.set(file.path, `import ${entity} from ${this.quote(file.path)};`);
183
+ continue;
161
184
  }
162
185
  if (file.name === entity) {
163
- imports.add(`import { ${entity} } from ${this.quote(file.path)};`);
164
- return;
186
+ importMap.set(file.path, `import { ${entity} } from ${this.quote(file.path)};`);
187
+ continue;
165
188
  }
166
- imports.add(`import { ${identifierRegex.test(file.name) ? file.name : this.quote(file.name)} as ${entity} } from ${this.quote(file.path)};`);
167
- });
189
+ importMap.set(file.path, `import { ${identifierRegex.test(file.name) ? file.name : this.quote(file.name)} as ${entity} } from ${this.quote(file.path)};`);
190
+ }
191
+ if (this.enumImports.size) {
192
+ for (const [name, exports] of this.enumImports.entries()) {
193
+ const file = this.options.onImport?.(name, basePath, extension, base) ?? {
194
+ path: `${basePath}/${this.options.fileName(name)}${extension}`,
195
+ name,
196
+ };
197
+ importMap.set(file.path, `import { ${exports.join(', ')} } from ${this.quote(file.path)};`);
198
+ }
199
+ }
200
+ for (const key of [...importMap.keys()].sort()) {
201
+ imports.add(importMap.get(key));
202
+ }
168
203
  return Array.from(imports.values()).join('\n');
169
204
  }
170
205
  getEntityClass(classBody) {
@@ -174,8 +209,8 @@ export class SourceFile {
174
209
  }
175
210
  ret += `class ${this.meta.className}`;
176
211
  if (this.meta.extends) {
177
- this.entityImports.add(this.meta.extends);
178
- ret += ` extends ${this.meta.extends}`;
212
+ this.entityImports.add(Utils.className(this.meta.extends));
213
+ ret += ` extends ${Utils.className(this.meta.extends)}`;
179
214
  }
180
215
  else if (this.options.useCoreBaseEntity) {
181
216
  ret += ` extends ${this.referenceCoreImport('BaseEntity')}`;
@@ -194,6 +229,7 @@ export class SourceFile {
194
229
  getPropertyDefinition(prop, padLeft) {
195
230
  const padding = ' '.repeat(padLeft);
196
231
  const propName = identifierRegex.test(prop.name) ? prop.name : this.quote(prop.name);
232
+ const enumMode = this.options.enumMode;
197
233
  let hiddenType = '';
198
234
  if (prop.hidden) {
199
235
  hiddenType += ` & ${this.referenceCoreImport('Hidden')}`;
@@ -211,7 +247,11 @@ export class SourceFile {
211
247
  : (() => {
212
248
  if (isScalar) {
213
249
  if (prop.enum) {
214
- return prop.runtimeType;
250
+ const method = enumMode === 'ts-enum' ? 'getEnumClassName' : 'getEnumTypeName';
251
+ if (prop.nativeEnumName) {
252
+ return this.namingStrategy[method](prop.nativeEnumName, undefined, this.meta.schema);
253
+ }
254
+ return this.namingStrategy[method](prop.fieldNames[0], this.meta.collection, this.meta.schema);
215
255
  }
216
256
  breakdownOfIType = this.breakdownOfIType(prop);
217
257
  if (typeof breakdownOfIType !== 'undefined') {
@@ -246,8 +286,14 @@ export class SourceFile {
246
286
  return `${padding}${ret};\n`;
247
287
  }
248
288
  if (prop.enum && typeof prop.default === 'string') {
289
+ if (enumMode === 'union-type') {
290
+ return `${padding}${ret} = ${this.quote(prop.default)};\n`;
291
+ }
292
+ const enumClassName = prop.nativeEnumName
293
+ ? this.namingStrategy.getEnumClassName(prop.nativeEnumName, undefined, this.meta.schema)
294
+ : this.namingStrategy.getEnumClassName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
249
295
  const enumVal = this.namingStrategy.enumValueToEnumProperty(prop.default, prop.fieldNames[0], this.meta.collection, this.meta.schema);
250
- return `${padding}${ret} = ${propType}${identifierRegex.test(enumVal) ? `.${enumVal}` : `[${this.quote(enumVal)}]`};\n`;
296
+ return `${padding}${ret} = ${enumClassName}${identifierRegex.test(enumVal) ? `.${enumVal}` : `[${this.quote(enumVal)}]`};\n`;
251
297
  }
252
298
  if (prop.fieldNames?.length > 1) {
253
299
  // TODO: Composite FKs with default values require additions to default/defaultRaw that are not yet supported.
@@ -263,15 +309,51 @@ export class SourceFile {
263
309
  return `${padding}${ret} = ${prop.ref ? this.referenceCoreImport('ref') : this.referenceCoreImport('rel')}(${propType}, ${defaultVal});\n`;
264
310
  }
265
311
  getEnumClassDefinition(prop, padLeft) {
312
+ const enumMode = this.options.enumMode;
313
+ if (prop.nativeEnumName) {
314
+ const imports = [];
315
+ if (enumMode !== 'union-type') {
316
+ imports.push(prop.runtimeType);
317
+ }
318
+ if (!this.options.inferEntityType && enumMode !== 'ts-enum') {
319
+ const enumTypeName = this.namingStrategy.getEnumTypeName(prop.nativeEnumName, undefined, this.meta.schema);
320
+ imports.push(enumTypeName);
321
+ }
322
+ this.enumImports.set(prop.runtimeType, imports);
323
+ return '';
324
+ }
266
325
  const enumClassName = this.namingStrategy.getEnumClassName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
326
+ const enumTypeName = this.namingStrategy.getEnumTypeName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
267
327
  const padding = ' '.repeat(padLeft);
268
- let ret = `export enum ${enumClassName} {\n`;
269
328
  const enumValues = prop.items;
329
+ if (enumMode === 'union-type') {
330
+ return `export type ${enumTypeName} = ${enumValues.map(item => this.quote(item)).join(' | ')};\n`;
331
+ }
332
+ let ret = '';
333
+ if (enumMode === 'dictionary') {
334
+ ret += `export const ${enumClassName} = {\n`;
335
+ }
336
+ else {
337
+ ret += `export enum ${enumClassName} {\n`;
338
+ }
270
339
  for (const enumValue of enumValues) {
271
340
  const enumName = this.namingStrategy.enumValueToEnumProperty(enumValue, prop.fieldNames[0], this.meta.collection, this.meta.schema);
272
- ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)} = ${this.quote(enumValue)},\n`;
341
+ if (enumMode === 'dictionary') {
342
+ ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)}: ${this.quote(enumValue)},\n`;
343
+ }
344
+ else {
345
+ ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)} = ${this.quote(enumValue)},\n`;
346
+ }
347
+ }
348
+ if (enumMode === 'dictionary') {
349
+ ret += '} as const;\n';
350
+ }
351
+ else {
352
+ ret += '}\n';
353
+ }
354
+ if (enumMode === 'dictionary') {
355
+ ret += `\nexport type ${enumTypeName} = (typeof ${enumClassName})[keyof typeof ${enumClassName}];\n`;
273
356
  }
274
- ret += '}\n';
275
357
  return ret;
276
358
  }
277
359
  serializeObject(options, wordwrap, spaces, level = 0) {
@@ -301,8 +383,8 @@ export class SourceFile {
301
383
  }
302
384
  getEntityDeclOptions() {
303
385
  const options = {};
304
- if (this.meta.collection !== this.namingStrategy.classToTableName(this.meta.className)) {
305
- options.tableName = this.quote(this.meta.collection);
386
+ if (this.meta.tableName !== this.namingStrategy.classToTableName(this.meta.className)) {
387
+ options.tableName = this.quote(this.meta.tableName);
306
388
  }
307
389
  if (this.meta.schema && this.meta.schema !== this.platform.getDefaultSchemaName()) {
308
390
  options.schema = this.quote(this.meta.schema);
@@ -311,7 +393,7 @@ export class SourceFile {
311
393
  options.expression = this.quote(this.meta.expression);
312
394
  }
313
395
  else if (typeof this.meta.expression === 'function') {
314
- options.expression = `${this.meta.expression}`;
396
+ options.expression = this.meta.expression.toString();
315
397
  }
316
398
  if (this.meta.repositoryClass) {
317
399
  this.entityImports.add(this.meta.repositoryClass);
@@ -344,14 +426,14 @@ export class SourceFile {
344
426
  }
345
427
  if (this.meta.discriminatorMap) {
346
428
  options.discriminatorMap = Object.fromEntries(Object.entries(this.meta.discriminatorMap)
347
- .map(([discriminatorValue, className]) => [discriminatorValue, this.quote(className)]));
429
+ .map(([discriminatorValue, cls]) => [discriminatorValue, this.quote(Utils.className(cls))]));
348
430
  }
349
431
  return options;
350
432
  }
351
433
  getPropertyDecorator(prop, padLeft) {
352
434
  const padding = ' '.repeat(padLeft);
353
435
  const options = {};
354
- let decorator = `@${this.referenceCoreImport(this.getDecoratorType(prop))}`;
436
+ let decorator = `@${this.referenceDecoratorImport(this.getDecoratorType(prop))}`;
355
437
  if (prop.kind === ReferenceKind.MANY_TO_MANY) {
356
438
  this.getManyToManyDecoratorOptions(options, prop);
357
439
  }
@@ -372,7 +454,7 @@ export class SourceFile {
372
454
  decorator = [...indexes.sort(), decorator].map(d => padding + d).join('\n');
373
455
  const decoratorArgs = [];
374
456
  if (prop.formula) {
375
- decoratorArgs.push(`${prop.formula}`);
457
+ decoratorArgs.push(prop.formula.toString());
376
458
  }
377
459
  if (Utils.hasObjectKeys(options)) {
378
460
  decoratorArgs.push(`${this.serializeObject(options)}`);
@@ -401,26 +483,26 @@ export class SourceFile {
401
483
  let propIndexIsNonTrivialIndex = false;
402
484
  const nonTrivialIndexes = this.meta.indexes.filter(i => i.properties?.length === 1 && i.properties[0] === prop.name);
403
485
  for (const i of nonTrivialIndexes) {
404
- ret.push(`@${this.referenceCoreImport('Index')}(${this.serializeObject(this.getIndexOptions(i, false))})`);
486
+ ret.push(`@${this.referenceDecoratorImport('Index')}(${this.serializeObject(this.getIndexOptions(i, false))})`);
405
487
  if (prop.index === i.name) {
406
488
  propIndexIsNonTrivialIndex = true;
407
489
  delete options.index;
408
490
  }
409
491
  }
410
492
  if (prop.index && !options.index && !propIndexIsNonTrivialIndex) {
411
- ret.push(`@${this.referenceCoreImport('Index')}(${typeof prop.index === 'string' ? `{ name: ${this.quote(prop.index)} }` : ''})`);
493
+ ret.push(`@${this.referenceDecoratorImport('Index')}(${typeof prop.index === 'string' ? `{ name: ${this.quote(prop.index)} }` : ''})`);
412
494
  }
413
495
  let propIndexIsNonTrivialUnique = false;
414
496
  const nonTrivialUnique = this.meta.uniques.filter(i => i.properties?.length === 1 && i.properties[0] === prop.name);
415
497
  for (const i of nonTrivialUnique) {
416
- ret.push(`@${this.referenceCoreImport('Unique')}(${this.serializeObject(this.getUniqueOptions(i, false))})`);
498
+ ret.push(`@${this.referenceDecoratorImport('Unique')}(${this.serializeObject(this.getUniqueOptions(i, false))})`);
417
499
  if (prop.unique === i.name) {
418
500
  propIndexIsNonTrivialUnique = true;
419
501
  delete options.unique;
420
502
  }
421
503
  }
422
504
  if (prop.unique && !options.unique && !propIndexIsNonTrivialUnique) {
423
- ret.push(`@${this.referenceCoreImport('Unique')}(${typeof prop.unique === 'string' ? `{ name: ${this.quote(prop.unique)} }` : ''})`);
505
+ ret.push(`@${this.referenceDecoratorImport('Unique')}(${typeof prop.unique === 'string' ? `{ name: ${this.quote(prop.unique)} }` : ''})`);
424
506
  }
425
507
  return ret;
426
508
  }
@@ -431,7 +513,7 @@ export class SourceFile {
431
513
  if (prop.primary && (prop.enum || !(typeof prop.kind === 'undefined' || prop.kind === ReferenceKind.SCALAR))) {
432
514
  options.primary = true;
433
515
  }
434
- ['persist', 'hydrate', 'trackChanges']
516
+ ['persist', 'hydrate']
435
517
  .filter(key => prop[key] === false)
436
518
  .forEach(key => options[key] = false);
437
519
  ['onCreate', 'onUpdate', 'serializer']
@@ -530,12 +612,23 @@ export class SourceFile {
530
612
  this.propTypeBreakdowns.set(prop, r);
531
613
  return r;
532
614
  }
533
- getScalarPropertyDecoratorOptions(options, prop) {
615
+ getScalarPropertyDecoratorOptions(options, prop, quote = true) {
534
616
  if (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {
535
617
  options.fieldName = this.quote(prop.fieldNames[0]);
536
618
  }
537
619
  if (prop.enum) {
538
- options.items = `() => ${prop.runtimeType}`;
620
+ if (this.options.enumMode === 'union-type') {
621
+ options.items = `[${prop.items.map(item => this.quote(item)).join(', ')}]`;
622
+ }
623
+ else if (prop.nativeEnumName) {
624
+ const enumClassName = this.namingStrategy.getEnumClassName(prop.nativeEnumName, undefined, this.meta.schema);
625
+ options.items = `() => ${enumClassName}`;
626
+ options.nativeEnumName = this.quote(prop.nativeEnumName);
627
+ }
628
+ else {
629
+ const enumClassName = this.namingStrategy.getEnumClassName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
630
+ options.items = `() => ${enumClassName}`;
631
+ }
539
632
  }
540
633
  // For enum properties, we don't need a column type
541
634
  // or the property length or other information in the decorator.
@@ -564,7 +657,7 @@ export class SourceFile {
564
657
  return ((useDefault && !hasUsableNullDefault) || (prop.optional && !prop.nullable));
565
658
  })() // also when there is the "| Opt" type modifier (because reflect-metadata can't extract the base)
566
659
  ) {
567
- options.type = this.quote(prop.type);
660
+ options.type = quote ? this.quote(prop.type) : prop.type;
568
661
  }
569
662
  }
570
663
  const columnTypeFromMappedRuntimeType = mappedRuntimeType.getColumnType({ ...prop, autoincrement: false }, this.platform);
@@ -591,7 +684,7 @@ export class SourceFile {
591
684
  assign('length');
592
685
  }
593
686
  // those are already included in the `columnType` in most cases, and when that option is present, they would be ignored anyway
594
- /* v8 ignore next 4 */
687
+ /* v8 ignore next */
595
688
  if (mappedColumnType instanceof DecimalType && !options.columnType) {
596
689
  assign('precision');
597
690
  assign('scale');
@@ -618,16 +711,19 @@ export class SourceFile {
618
711
  getManyToManyDecoratorOptions(options, prop) {
619
712
  this.entityImports.add(prop.type);
620
713
  options.entity = `() => ${prop.type}`;
714
+ if (prop.orderBy) {
715
+ options.orderBy = inspect(prop.orderBy);
716
+ }
621
717
  if (prop.mappedBy) {
622
718
  options.mappedBy = this.quote(prop.mappedBy);
623
719
  return;
624
720
  }
625
- if (prop.pivotTable !== this.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name)) {
721
+ if (prop.pivotTable !== this.namingStrategy.joinTableName(this.meta.collection, prop.type, prop.name, this.meta.tableName)) {
626
722
  options.pivotTable = this.quote(prop.pivotTable);
627
723
  }
628
- if (prop.pivotEntity && prop.pivotEntity !== prop.pivotTable) {
629
- this.entityImports.add(prop.pivotEntity);
630
- options.pivotEntity = `() => ${prop.pivotEntity}`;
724
+ if (prop.pivotEntity && Utils.className(prop.pivotEntity) !== prop.pivotTable) {
725
+ this.entityImports.add(Utils.className(prop.pivotEntity));
726
+ options.pivotEntity = `() => ${Utils.className(prop.pivotEntity)}`;
631
727
  }
632
728
  if (prop.joinColumns.length === 1) {
633
729
  options.joinColumn = this.quote(prop.joinColumns[0]);
@@ -652,6 +748,9 @@ export class SourceFile {
652
748
  this.entityImports.add(prop.type);
653
749
  options.entity = `() => ${prop.type}`;
654
750
  options.mappedBy = this.quote(prop.mappedBy);
751
+ if (prop.orderBy) {
752
+ options.orderBy = inspect(prop.orderBy);
753
+ }
655
754
  }
656
755
  getEmbeddedPropertyDeclarationOptions(options, prop) {
657
756
  this.entityImports.add(prop.type);
@@ -659,7 +758,7 @@ export class SourceFile {
659
758
  if (prop.array) {
660
759
  options.array = true;
661
760
  }
662
- if (prop.object) {
761
+ if (prop.object && !prop.array) {
663
762
  options.object = true;
664
763
  }
665
764
  if (prop.prefix === false || typeof prop.prefix === 'string') {
@@ -692,10 +791,10 @@ export class SourceFile {
692
791
  if (prop.ownColumns && prop.ownColumns.length !== prop.fieldNames.length) {
693
792
  options.referencedColumnNames = prop.referencedColumnNames.map(fieldName => this.quote(fieldName));
694
793
  }
695
- if (!['no action', 'restrict'].includes(prop.updateRule.toLowerCase())) {
794
+ if (prop.updateRule) {
696
795
  options.updateRule = this.quote(prop.updateRule);
697
796
  }
698
- if (!['no action', 'restrict'].includes(prop.deleteRule.toLowerCase())) {
797
+ if (prop.deleteRule) {
699
798
  options.deleteRule = this.quote(prop.deleteRule);
700
799
  }
701
800
  if (prop.primary) {
@@ -742,4 +841,10 @@ export class SourceFile {
742
841
  ? `${this.options.coreImportsPrefix}${identifier}`
743
842
  : identifier;
744
843
  }
844
+ referenceDecoratorImport(identifier) {
845
+ this.decoratorImports.add(identifier);
846
+ return this.options.coreImportsPrefix
847
+ ? `${this.options.coreImportsPrefix}${identifier}`
848
+ : identifier;
849
+ }
745
850
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mikro-orm/entity-generator",
3
3
  "type": "module",
4
- "version": "7.0.0-dev.2",
4
+ "version": "7.0.0-dev.200",
5
5
  "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
6
  "exports": {
7
7
  "./package.json": "./package.json",
@@ -38,10 +38,10 @@
38
38
  },
39
39
  "homepage": "https://mikro-orm.io",
40
40
  "engines": {
41
- "node": ">= 22.11.0"
41
+ "node": ">= 22.17.0"
42
42
  },
43
43
  "scripts": {
44
- "build": "yarn clean && yarn compile && yarn copy",
44
+ "build": "yarn compile && yarn copy",
45
45
  "clean": "yarn run -T rimraf ./dist",
46
46
  "compile": "yarn run -T tsc -p tsconfig.build.json",
47
47
  "copy": "node ../../scripts/copy.mjs"
@@ -50,12 +50,12 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@mikro-orm/knex": "7.0.0-dev.2"
53
+ "@mikro-orm/sql": "7.0.0-dev.200"
54
54
  },
55
55
  "devDependencies": {
56
- "@mikro-orm/core": "^6.4.5"
56
+ "@mikro-orm/core": "^6.6.4"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.0.0-dev.2"
59
+ "@mikro-orm/core": "7.0.0-dev.200"
60
60
  }
61
61
  }