@mikro-orm/entity-generator 6.3.14-dev.4 → 6.3.14-dev.41

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.
@@ -15,7 +15,6 @@ export declare class EntityGenerator {
15
15
  generate(options?: GenerateOptions): Promise<string[]>;
16
16
  private getEntityMetadata;
17
17
  private matchName;
18
- private isTableNameAllowed;
19
18
  private detectManyToManyRelations;
20
19
  private generateBidirectionalRelations;
21
20
  private generateIdentifiedReferences;
@@ -31,7 +31,7 @@ class EntityGenerator {
31
31
  }
32
32
  async generate(options = {}) {
33
33
  options = core_1.Utils.mergeConfig({}, this.config.get('entityGenerator'), options);
34
- const schema = await knex_1.DatabaseSchema.create(this.connection, this.platform, this.config);
34
+ const schema = await knex_1.DatabaseSchema.create(this.connection, this.platform, this.config, undefined, undefined, options.takeTables, options.skipTables);
35
35
  const metadata = await this.getEntityMetadata(schema, options);
36
36
  const defaultPath = `${this.config.get('baseDir')}/generated-entities`;
37
37
  const baseDir = core_1.Utils.normalizePath(options.path ?? defaultPath);
@@ -59,9 +59,9 @@ class EntityGenerator {
59
59
  return this.sources.map(file => file.generate());
60
60
  }
61
61
  async getEntityMetadata(schema, options) {
62
- let metadata = schema.getTables()
62
+ const metadata = schema.getTables()
63
63
  .filter(table => !options.schema || table.schema === options.schema)
64
- .sort((a, b) => a.name.localeCompare(b.name))
64
+ .sort((a, b) => `${a.schema}.${a.name}`.localeCompare(`${b.schema}.${b.name}`))
65
65
  .map(table => {
66
66
  const skipColumns = options.skipColumns?.[table.getShortestName()];
67
67
  if (skipColumns) {
@@ -75,7 +75,7 @@ class EntityGenerator {
75
75
  });
76
76
  for (const meta of metadata) {
77
77
  for (const prop of meta.relations) {
78
- if (!this.isTableNameAllowed(prop.referencedTableName, options)) {
78
+ if (!metadata.some(otherMeta => prop.referencedTableName === otherMeta.collection || prop.referencedTableName === `${otherMeta.schema ?? schema.name}.${otherMeta.collection}`)) {
79
79
  prop.kind = core_1.ReferenceKind.SCALAR;
80
80
  const mappedTypes = prop.columnTypes.map((t, i) => this.platform.getMappedType(t));
81
81
  const runtimeTypes = mappedTypes.map(t => t.runtimeType);
@@ -84,7 +84,6 @@ class EntityGenerator {
84
84
  }
85
85
  }
86
86
  }
87
- metadata = metadata.filter(table => this.isTableNameAllowed(table.tableName, options));
88
87
  await options.onInitialMetadata?.(metadata, this.platform);
89
88
  // enforce schema usage in class names only on duplicates
90
89
  const duplicates = core_1.Utils.findDuplicates(metadata.map(meta => meta.className));
@@ -100,7 +99,7 @@ class EntityGenerator {
100
99
  }
101
100
  this.detectManyToManyRelations(metadata, options.onlyPurePivotTables, options.readOnlyPivotTables, options.outputPurePivotTables);
102
101
  if (options.bidirectionalRelations) {
103
- this.generateBidirectionalRelations(metadata);
102
+ this.generateBidirectionalRelations(metadata, options.outputPurePivotTables);
104
103
  }
105
104
  if (options.identifiedReferences) {
106
105
  this.generateIdentifiedReferences(metadata);
@@ -119,10 +118,6 @@ class EntityGenerator {
119
118
  ? name.toLocaleLowerCase() === nameToMatch.toLocaleLowerCase()
120
119
  : nameToMatch.test(name);
121
120
  }
122
- isTableNameAllowed(tableName, { takeTables, skipTables }) {
123
- return ((takeTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? true) &&
124
- !(skipTables?.some(tableNameToMatch => this.matchName(tableName, tableNameToMatch)) ?? false));
125
- }
126
121
  detectManyToManyRelations(metadata, onlyPurePivotTables, readOnlyPivotTables, outputPurePivotTables) {
127
122
  for (const meta of metadata) {
128
123
  const isReferenced = metadata.some(m => {
@@ -211,8 +206,11 @@ class EntityGenerator {
211
206
  owner.addProperty(ownerProp);
212
207
  }
213
208
  }
214
- generateBidirectionalRelations(metadata) {
215
- for (const meta of metadata.filter(m => !m.pivotTable || this.referencedEntities.has(m))) {
209
+ generateBidirectionalRelations(metadata, includeUnreferencedPurePivotTables) {
210
+ const filteredMetadata = includeUnreferencedPurePivotTables
211
+ ? metadata
212
+ : metadata.filter(m => !m.pivotTable || this.referencedEntities.has(m));
213
+ for (const meta of filteredMetadata) {
216
214
  for (const prop of meta.relations) {
217
215
  const targetMeta = metadata.find(m => m.className === prop.type);
218
216
  const newProp = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/entity-generator",
3
- "version": "6.3.14-dev.4",
3
+ "version": "6.3.14-dev.41",
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",
@@ -58,13 +58,13 @@
58
58
  "access": "public"
59
59
  },
60
60
  "dependencies": {
61
- "@mikro-orm/knex": "6.3.14-dev.4",
61
+ "@mikro-orm/knex": "6.3.14-dev.41",
62
62
  "fs-extra": "11.2.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@mikro-orm/core": "^6.3.13"
66
66
  },
67
67
  "peerDependencies": {
68
- "@mikro-orm/core": "6.3.14-dev.4"
68
+ "@mikro-orm/core": "6.3.14-dev.41"
69
69
  }
70
70
  }