@mikro-orm/entity-generator 7.1.0-dev.20 → 7.1.0-dev.21

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.
Files changed (2) hide show
  1. package/SourceFile.js +9 -4
  2. package/package.json +3 -3
package/SourceFile.js CHANGED
@@ -403,8 +403,11 @@ export class SourceFile {
403
403
  const enumTypeName = this.namingStrategy.getEnumTypeName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
404
404
  const padding = ' '.repeat(padLeft);
405
405
  const enumValues = prop.items;
406
+ // numeric enums arrive as strings; emit raw numbers so the generated TS reads `Foo: 1` not `Foo: '1'`
407
+ const allNumeric = enumValues.length > 0 && enumValues.every(item => /^-?\d+$/.test(item));
408
+ const formatValue = (item) => (allNumeric ? item : this.quote(item));
406
409
  if (enumMode === 'union-type') {
407
- return `export type ${enumTypeName} = ${enumValues.map(item => this.quote(item)).join(' | ')};\n`;
410
+ return `export type ${enumTypeName} = ${enumValues.map(formatValue).join(' | ')};\n`;
408
411
  }
409
412
  let ret = '';
410
413
  if (enumMode === 'dictionary') {
@@ -416,10 +419,10 @@ export class SourceFile {
416
419
  for (const enumValue of enumValues) {
417
420
  const enumName = this.namingStrategy.enumValueToEnumProperty(enumValue, prop.fieldNames[0], this.meta.collection, this.meta.schema);
418
421
  if (enumMode === 'dictionary') {
419
- ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)}: ${this.quote(enumValue)},\n`;
422
+ ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)}: ${formatValue(enumValue)},\n`;
420
423
  }
421
424
  else {
422
- ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)} = ${this.quote(enumValue)},\n`;
425
+ ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)} = ${formatValue(enumValue)},\n`;
423
426
  }
424
427
  }
425
428
  if (enumMode === 'dictionary') {
@@ -751,7 +754,9 @@ export class SourceFile {
751
754
  }
752
755
  if (prop.enum) {
753
756
  if (this.options.enumMode === 'union-type') {
754
- options.items = `[${prop.items.map(item => this.quote(item)).join(', ')}]`;
757
+ const items = prop.items;
758
+ const allNumeric = items.length > 0 && items.every(item => /^-?\d+$/.test(item));
759
+ options.items = `[${items.map(item => (allNumeric ? item : this.quote(item))).join(', ')}]`;
755
760
  }
756
761
  else if (prop.nativeEnumName) {
757
762
  const enumClassName = this.namingStrategy.getEnumClassName(prop.nativeEnumName, undefined, this.meta.schema);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/entity-generator",
3
- "version": "7.1.0-dev.20",
3
+ "version": "7.1.0-dev.21",
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
  "keywords": [
6
6
  "data-mapper",
@@ -47,13 +47,13 @@
47
47
  "copy": "node ../../scripts/copy.mjs"
48
48
  },
49
49
  "dependencies": {
50
- "@mikro-orm/sql": "7.1.0-dev.20"
50
+ "@mikro-orm/sql": "7.1.0-dev.21"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@mikro-orm/core": "^7.0.12"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.1.0-dev.20"
56
+ "@mikro-orm/core": "7.1.0-dev.21"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"