@mikro-orm/entity-generator 7.0.0-dev.63 → 7.0.0-dev.65

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.d.ts CHANGED
@@ -9,6 +9,7 @@ export declare class SourceFile {
9
9
  protected readonly platform: Platform;
10
10
  protected readonly options: GenerateOptions;
11
11
  protected readonly coreImports: Set<string>;
12
+ protected readonly decoratorImports: Set<string>;
12
13
  protected readonly entityImports: Set<string>;
13
14
  protected readonly enumImports: Map<string, string[]>;
14
15
  constructor(meta: EntityMetadata, namingStrategy: NamingStrategy, platform: Platform, options: GenerateOptions);
@@ -38,4 +39,5 @@ export declare class SourceFile {
38
39
  protected getForeignKeyDecoratorOptions(options: OneToOneOptions<any, any>, prop: EntityProperty): void;
39
40
  protected getDecoratorType(prop: EntityProperty): string;
40
41
  protected referenceCoreImport(identifier: string): string;
42
+ protected referenceDecoratorImport(identifier: string): string;
41
43
  }
package/SourceFile.js CHANGED
@@ -13,6 +13,7 @@ export class SourceFile {
13
13
  platform;
14
14
  options;
15
15
  coreImports = new Set();
16
+ decoratorImports = new Set();
16
17
  entityImports = new Set();
17
18
  enumImports = new Map();
18
19
  constructor(meta, namingStrategy, platform, options) {
@@ -26,24 +27,24 @@ export class SourceFile {
26
27
  if (this.meta.embeddable || this.meta.collection) {
27
28
  if (this.meta.embeddable) {
28
29
  const options = this.getEmbeddableDeclOptions();
29
- ret += `@${this.referenceCoreImport('Embeddable')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
30
+ ret += `@${this.referenceDecoratorImport('Embeddable')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
30
31
  }
31
32
  else {
32
33
  const options = this.getEntityDeclOptions();
33
- ret += `@${this.referenceCoreImport('Entity')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
34
+ ret += `@${this.referenceDecoratorImport('Entity')}(${Utils.hasObjectKeys(options) ? this.serializeObject(options) : ''})\n`;
34
35
  }
35
36
  }
36
37
  for (const index of this.meta.indexes) {
37
38
  if (index.properties?.length === 1 && typeof this.meta.properties[index.properties[0]] !== 'undefined') {
38
39
  continue;
39
40
  }
40
- ret += `@${this.referenceCoreImport('Index')}(${this.serializeObject(this.getIndexOptions(index))})\n`;
41
+ ret += `@${this.referenceDecoratorImport('Index')}(${this.serializeObject(this.getIndexOptions(index))})\n`;
41
42
  }
42
43
  for (const index of this.meta.uniques) {
43
44
  if (index.properties?.length === 1 && typeof this.meta.properties[index.properties[0]] !== 'undefined') {
44
45
  continue;
45
46
  }
46
- ret += `@${this.referenceCoreImport('Unique')}(${this.serializeObject(this.getUniqueOptions(index))})\n`;
47
+ ret += `@${this.referenceDecoratorImport('Unique')}(${this.serializeObject(this.getUniqueOptions(index))})\n`;
47
48
  }
48
49
  let classHead = '';
49
50
  if (this.meta.className === this.options.customBaseEntityName) {
@@ -145,6 +146,17 @@ export class SourceFile {
145
146
  return ret;
146
147
  }).join(', '))} } from '@mikro-orm/core';`);
147
148
  }
149
+ if (this.decoratorImports.size > 0) {
150
+ const type = this.options.decorators;
151
+ imports.add(`import { ${([...this.decoratorImports].sort().map(t => {
152
+ let ret = t;
153
+ if (this.options.coreImportsPrefix) {
154
+ const resolvedIdentifier = `${this.options.coreImportsPrefix}${t}`;
155
+ ret += ` as ${resolvedIdentifier}`;
156
+ }
157
+ return ret;
158
+ }).join(', '))} } from '@mikro-orm/decorators/${type}';`);
159
+ }
148
160
  const extension = this.options.esmImport ? '.js' : '';
149
161
  const { dir, base } = parse(`${this.options.path ?? '.'}/${this.getBaseName()}`);
150
162
  const basePath = relative(dir, this.options.path ?? '.') || '.';
@@ -422,7 +434,7 @@ export class SourceFile {
422
434
  getPropertyDecorator(prop, padLeft) {
423
435
  const padding = ' '.repeat(padLeft);
424
436
  const options = {};
425
- let decorator = `@${this.referenceCoreImport(this.getDecoratorType(prop))}`;
437
+ let decorator = `@${this.referenceDecoratorImport(this.getDecoratorType(prop))}`;
426
438
  if (prop.kind === ReferenceKind.MANY_TO_MANY) {
427
439
  this.getManyToManyDecoratorOptions(options, prop);
428
440
  }
@@ -472,26 +484,26 @@ export class SourceFile {
472
484
  let propIndexIsNonTrivialIndex = false;
473
485
  const nonTrivialIndexes = this.meta.indexes.filter(i => i.properties?.length === 1 && i.properties[0] === prop.name);
474
486
  for (const i of nonTrivialIndexes) {
475
- ret.push(`@${this.referenceCoreImport('Index')}(${this.serializeObject(this.getIndexOptions(i, false))})`);
487
+ ret.push(`@${this.referenceDecoratorImport('Index')}(${this.serializeObject(this.getIndexOptions(i, false))})`);
476
488
  if (prop.index === i.name) {
477
489
  propIndexIsNonTrivialIndex = true;
478
490
  delete options.index;
479
491
  }
480
492
  }
481
493
  if (prop.index && !options.index && !propIndexIsNonTrivialIndex) {
482
- ret.push(`@${this.referenceCoreImport('Index')}(${typeof prop.index === 'string' ? `{ name: ${this.quote(prop.index)} }` : ''})`);
494
+ ret.push(`@${this.referenceDecoratorImport('Index')}(${typeof prop.index === 'string' ? `{ name: ${this.quote(prop.index)} }` : ''})`);
483
495
  }
484
496
  let propIndexIsNonTrivialUnique = false;
485
497
  const nonTrivialUnique = this.meta.uniques.filter(i => i.properties?.length === 1 && i.properties[0] === prop.name);
486
498
  for (const i of nonTrivialUnique) {
487
- ret.push(`@${this.referenceCoreImport('Unique')}(${this.serializeObject(this.getUniqueOptions(i, false))})`);
499
+ ret.push(`@${this.referenceDecoratorImport('Unique')}(${this.serializeObject(this.getUniqueOptions(i, false))})`);
488
500
  if (prop.unique === i.name) {
489
501
  propIndexIsNonTrivialUnique = true;
490
502
  delete options.unique;
491
503
  }
492
504
  }
493
505
  if (prop.unique && !options.unique && !propIndexIsNonTrivialUnique) {
494
- ret.push(`@${this.referenceCoreImport('Unique')}(${typeof prop.unique === 'string' ? `{ name: ${this.quote(prop.unique)} }` : ''})`);
506
+ ret.push(`@${this.referenceDecoratorImport('Unique')}(${typeof prop.unique === 'string' ? `{ name: ${this.quote(prop.unique)} }` : ''})`);
495
507
  }
496
508
  return ret;
497
509
  }
@@ -830,4 +842,10 @@ export class SourceFile {
830
842
  ? `${this.options.coreImportsPrefix}${identifier}`
831
843
  : identifier;
832
844
  }
845
+ referenceDecoratorImport(identifier) {
846
+ this.decoratorImports.add(identifier);
847
+ return this.options.coreImportsPrefix
848
+ ? `${this.options.coreImportsPrefix}${identifier}`
849
+ : identifier;
850
+ }
833
851
  }
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.63",
4
+ "version": "7.0.0-dev.65",
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",
@@ -50,12 +50,12 @@
50
50
  "access": "public"
51
51
  },
52
52
  "dependencies": {
53
- "@mikro-orm/knex": "7.0.0-dev.63"
53
+ "@mikro-orm/knex": "7.0.0-dev.65"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@mikro-orm/core": "^6.6.1"
57
57
  },
58
58
  "peerDependencies": {
59
- "@mikro-orm/core": "7.0.0-dev.63"
59
+ "@mikro-orm/core": "7.0.0-dev.65"
60
60
  }
61
61
  }