@mikro-orm/entity-generator 6.3.5-dev.14 → 6.3.5-dev.16

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/README.md CHANGED
@@ -163,6 +163,7 @@ You can find example integrations for some popular frameworks in the [`mikro-orm
163
163
  - [NextJS + MySQL](https://github.com/jonahallibone/mikro-orm-nextjs)
164
164
  - [Accounts.js REST and GraphQL authentication + SQLite](https://github.com/darkbasic/mikro-orm-accounts-example)
165
165
  - [Nest + Shopify + PostgreSQL + GraphQL](https://github.com/Cloudshelf/Shopify_CSConnector)
166
+ - [Elysia.js + libSQL + Bun](https://github.com/mikro-orm/elysia-bun-example-app)
166
167
 
167
168
  ### JavaScript Examples
168
169
 
package/SourceFile.d.ts CHANGED
@@ -28,6 +28,8 @@ export declare class SourceFile {
28
28
  private getPropertyDecorator;
29
29
  protected getPropertyIndexes(prop: EntityProperty, options: Dictionary): string[];
30
30
  protected getCommonDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
31
+ private propTypeBreakdowns;
32
+ private breakdownOfIType;
31
33
  protected getScalarPropertyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
32
34
  protected getManyToManyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
33
35
  protected getOneToManyDecoratorOptions(options: Dictionary, prop: EntityProperty): void;
package/SourceFile.js CHANGED
@@ -215,31 +215,16 @@ class SourceFile {
215
215
  if (prop.enum) {
216
216
  return prop.runtimeType;
217
217
  }
218
- const mappedDeclaredType = this.platform.getMappedType(prop.type);
219
- const mappedRawType = (prop.customTypes?.[0] ?? ((prop.type !== 'unknown' && mappedDeclaredType instanceof core_1.UnknownType)
220
- ? this.platform.getMappedType(prop.columnTypes[0])
221
- : mappedDeclaredType));
222
- const rawType = mappedRawType.runtimeType;
223
- const serializedType = (prop.customType ?? mappedRawType).runtimeType;
224
- // Add non-lib imports where needed.
225
- for (const typeSpec of [prop.runtimeType, rawType, serializedType]) {
226
- const simplePropType = typeSpec.replace(/\[]+$/, '');
227
- if (!primitivesAndLibs.includes(simplePropType)) {
228
- this.entityImports.add(simplePropType);
229
- }
230
- }
231
- if (prop.runtimeType !== rawType || rawType !== serializedType) {
218
+ const breakdownOfIType = this.breakdownOfIType(prop);
219
+ if (typeof breakdownOfIType !== 'undefined') {
232
220
  hasITypeWrapper = true;
233
- if (rawType !== serializedType) {
234
- return `${this.referenceCoreImport('IType')}<${prop.runtimeType}, ${rawType}, ${serializedType}>`;
235
- }
236
- return `${this.referenceCoreImport('IType')}<${prop.runtimeType}, ${rawType}>`;
221
+ return `${this.referenceCoreImport('IType')}<${breakdownOfIType.join(', ')}>`;
237
222
  }
238
223
  return prop.runtimeType;
239
224
  }
240
225
  return prop.type;
241
226
  })();
242
- const useDefault = prop.default != null;
227
+ const useDefault = prop.default != null && (propType !== 'unknown');
243
228
  const optional = prop.nullable ? '?' : (useDefault ? '' : '!');
244
229
  let ret = `${propName}${optional}: ${prop.ref ? `${this.referenceCoreImport('Ref')}<${propType}>` : `${(this.options.esmImport && !isScalar) ? `${this.referenceCoreImport('Rel')}<${propType}>` : propType}`}`;
245
230
  if (prop.array && (prop.kind === core_1.ReferenceKind.EMBEDDED || prop.enum)) {
@@ -249,7 +234,7 @@ class SourceFile {
249
234
  if (useDefault || (prop.optional && !prop.nullable)) {
250
235
  ret += ` & ${this.referenceCoreImport('Opt')}`;
251
236
  }
252
- if (!useDefault || hasITypeWrapper) {
237
+ if (!useDefault || hasITypeWrapper || prop.type === 'unknown') {
253
238
  return `${padding}${ret};\n`;
254
239
  }
255
240
  if (prop.enum && typeof prop.default === 'string') {
@@ -462,15 +447,7 @@ class SourceFile {
462
447
  prop.defaultRaw !== (typeof prop.default === 'string' ? this.quote(prop.default) : `${prop.default}`)) {
463
448
  options.defaultRaw = `\`${prop.defaultRaw}\``;
464
449
  }
465
- else if (prop.default != null && (prop.ref || (!prop.enum && (typeof prop.kind === 'undefined' || prop.kind === core_1.ReferenceKind.SCALAR) && (() => {
466
- const mappedDeclaredType = this.platform.getMappedType(prop.type);
467
- const mappedRawType = (prop.customTypes?.[0] ?? ((prop.type !== 'unknown' && mappedDeclaredType instanceof core_1.UnknownType)
468
- ? this.platform.getMappedType(prop.columnTypes[0])
469
- : mappedDeclaredType));
470
- const rawType = mappedRawType.runtimeType;
471
- const serializedType = (prop.customType ?? mappedRawType).runtimeType;
472
- return prop.runtimeType !== rawType || rawType !== serializedType;
473
- })()))) {
450
+ else if (prop.default != null && (prop.ref || (!prop.enum && (typeof prop.kind === 'undefined' || prop.kind === core_1.ReferenceKind.SCALAR) && (prop.type === 'unknown' || typeof this.breakdownOfIType(prop) !== 'undefined')))) {
474
451
  options.default = typeof prop.default === 'string' ? this.quote(prop.default) : prop.default;
475
452
  }
476
453
  }
@@ -480,6 +457,42 @@ class SourceFile {
480
457
  if (prop.deferMode) {
481
458
  options.deferMode = `${this.referenceCoreImport('DeferMode')}.INITIALLY_${prop.deferMode.toUpperCase()}`;
482
459
  }
460
+ if (typeof prop.ignoreSchemaChanges !== 'undefined') {
461
+ options.ignoreSchemaChanges ??= [];
462
+ options.ignoreSchemaChanges.push(...prop.ignoreSchemaChanges.map(v => this.quote(v)));
463
+ }
464
+ }
465
+ propTypeBreakdowns = new WeakMap();
466
+ breakdownOfIType(prop) {
467
+ if (this.propTypeBreakdowns.has(prop)) {
468
+ return this.propTypeBreakdowns.get(prop);
469
+ }
470
+ const mappedDeclaredType = this.platform.getMappedType(prop.type);
471
+ const mappedRawType = (prop.customTypes?.[0] ?? ((prop.type !== 'unknown' && mappedDeclaredType instanceof core_1.UnknownType)
472
+ ? this.platform.getMappedType(prop.columnTypes[0])
473
+ : mappedDeclaredType));
474
+ const rawType = mappedRawType.runtimeType;
475
+ const serializedType = (prop.customType ?? mappedRawType).runtimeType;
476
+ // Add non-lib imports where needed.
477
+ for (const typeSpec of [prop.runtimeType, rawType, serializedType]) {
478
+ const simplePropType = typeSpec.replace(/\[]+$/, '');
479
+ if (!primitivesAndLibs.includes(simplePropType)) {
480
+ this.entityImports.add(simplePropType);
481
+ }
482
+ }
483
+ if (prop.runtimeType !== rawType || rawType !== serializedType) {
484
+ if (rawType !== serializedType) {
485
+ const r = [prop.runtimeType, rawType, serializedType];
486
+ this.propTypeBreakdowns.set(prop, r);
487
+ return r;
488
+ }
489
+ const r = [prop.runtimeType, rawType];
490
+ this.propTypeBreakdowns.set(prop, r);
491
+ return r;
492
+ }
493
+ const r = undefined;
494
+ this.propTypeBreakdowns.set(prop, r);
495
+ return r;
483
496
  }
484
497
  getScalarPropertyDecoratorOptions(options, prop) {
485
498
  if (prop.fieldNames[0] !== this.namingStrategy.propertyToColumnName(prop.name)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/entity-generator",
3
- "version": "6.3.5-dev.14",
3
+ "version": "6.3.5-dev.16",
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.5-dev.14",
61
+ "@mikro-orm/knex": "6.3.5-dev.16",
62
62
  "fs-extra": "11.2.0"
63
63
  },
64
64
  "devDependencies": {
65
65
  "@mikro-orm/core": "^6.3.4"
66
66
  },
67
67
  "peerDependencies": {
68
- "@mikro-orm/core": "6.3.5-dev.14"
68
+ "@mikro-orm/core": "6.3.5-dev.16"
69
69
  }
70
70
  }