@mikro-orm/entity-generator 7.0.13-dev.0 → 7.0.13-dev.10

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
@@ -397,8 +397,11 @@ export class SourceFile {
397
397
  const enumTypeName = this.namingStrategy.getEnumTypeName(prop.fieldNames[0], this.meta.collection, this.meta.schema);
398
398
  const padding = ' '.repeat(padLeft);
399
399
  const enumValues = prop.items;
400
+ // numeric enums arrive as strings; emit raw numbers so the generated TS reads `Foo: 1` not `Foo: '1'`
401
+ const allNumeric = enumValues.length > 0 && enumValues.every(item => /^-?\d+$/.test(item));
402
+ const formatValue = (item) => (allNumeric ? item : this.quote(item));
400
403
  if (enumMode === 'union-type') {
401
- return `export type ${enumTypeName} = ${enumValues.map(item => this.quote(item)).join(' | ')};\n`;
404
+ return `export type ${enumTypeName} = ${enumValues.map(formatValue).join(' | ')};\n`;
402
405
  }
403
406
  let ret = '';
404
407
  if (enumMode === 'dictionary') {
@@ -410,10 +413,10 @@ export class SourceFile {
410
413
  for (const enumValue of enumValues) {
411
414
  const enumName = this.namingStrategy.enumValueToEnumProperty(enumValue, prop.fieldNames[0], this.meta.collection, this.meta.schema);
412
415
  if (enumMode === 'dictionary') {
413
- ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)}: ${this.quote(enumValue)},\n`;
416
+ ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)}: ${formatValue(enumValue)},\n`;
414
417
  }
415
418
  else {
416
- ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)} = ${this.quote(enumValue)},\n`;
419
+ ret += `${padding}${identifierRegex.test(enumName) ? enumName : this.quote(enumName)} = ${formatValue(enumValue)},\n`;
417
420
  }
418
421
  }
419
422
  if (enumMode === 'dictionary') {
@@ -708,7 +711,9 @@ export class SourceFile {
708
711
  }
709
712
  if (prop.enum) {
710
713
  if (this.options.enumMode === 'union-type') {
711
- options.items = `[${prop.items.map(item => this.quote(item)).join(', ')}]`;
714
+ const items = prop.items;
715
+ const allNumeric = items.length > 0 && items.every(item => /^-?\d+$/.test(item));
716
+ options.items = `[${items.map(item => (allNumeric ? item : this.quote(item))).join(', ')}]`;
712
717
  }
713
718
  else if (prop.nativeEnumName) {
714
719
  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.0.13-dev.0",
3
+ "version": "7.0.13-dev.10",
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.0.13-dev.0"
50
+ "@mikro-orm/sql": "7.0.13-dev.10"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@mikro-orm/core": "^7.0.12"
54
54
  },
55
55
  "peerDependencies": {
56
- "@mikro-orm/core": "7.0.13-dev.0"
56
+ "@mikro-orm/core": "7.0.13-dev.10"
57
57
  },
58
58
  "engines": {
59
59
  "node": ">= 22.17.0"