@mikro-orm/core 6.2.10-dev.83 → 6.2.10-dev.85

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.
@@ -1,4 +1,5 @@
1
1
  import type { NamingStrategy } from './NamingStrategy';
2
+ import { type ReferenceKind } from '../enums';
2
3
  export declare abstract class AbstractNamingStrategy implements NamingStrategy {
3
4
  getClassName(file: string, separator?: string): string;
4
5
  classToMigrationName(timestamp: string, customMigrationName?: string): string;
@@ -17,6 +18,10 @@ export declare abstract class AbstractNamingStrategy implements NamingStrategy {
17
18
  */
18
19
  enumValueToEnumProperty(enumValue: string, columnName: string, tableName: string, schemaName?: string): string;
19
20
  aliasName(entityName: string, index: number): string;
21
+ /**
22
+ * @inheritDoc
23
+ */
24
+ inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
20
25
  abstract classToTableName(entityName: string): string;
21
26
  abstract joinColumnName(propertyName: string): string;
22
27
  abstract joinKeyColumnName(entityName: string, referencedColumnName?: string): string;
@@ -63,5 +63,18 @@ class AbstractNamingStrategy {
63
63
  // Take only the first letter of the prefix to keep character counts down since some engines have character limits
64
64
  return entityName.charAt(0).toLowerCase() + index;
65
65
  }
66
+ /**
67
+ * @inheritDoc
68
+ */
69
+ inverseSideName(entityName, propertyName, kind) {
70
+ if (kind === 'm:n') {
71
+ return propertyName + 'Inverse';
72
+ }
73
+ const suffix = kind === '1:m' && !entityName.endsWith('Collection') ? 'Collection' : '';
74
+ if (entityName.length === 1) {
75
+ return entityName[0].toLowerCase() + suffix;
76
+ }
77
+ return entityName[0].toLowerCase() + entityName.substring(1) + suffix;
78
+ }
66
79
  }
67
80
  exports.AbstractNamingStrategy = AbstractNamingStrategy;
@@ -1,3 +1,4 @@
1
+ import type { ReferenceKind } from '../enums';
1
2
  export interface NamingStrategy {
2
3
  /**
3
4
  * Return a name of the class based on its file name
@@ -62,7 +63,7 @@ export interface NamingStrategy {
62
63
  */
63
64
  joinKeyColumnName(entityName: string, referencedColumnName?: string, composite?: boolean): string;
64
65
  /**
65
- * Returns key/constraint name for given type. Some drivers might not support all the types (e.g. mysql and sqlite enforce the PK name).
66
+ * Returns key/constraint name for the given type. Some drivers might not support all the types (e.g. mysql and sqlite enforce the PK name).
66
67
  */
67
68
  indexName(tableName: string, columns: string[], type: 'primary' | 'foreign' | 'unique' | 'index' | 'sequence' | 'check'): string;
68
69
  /**
@@ -70,4 +71,8 @@ export interface NamingStrategy {
70
71
  * ensured via appended index parameter. It is optional to use it as long as you ensure it will be unique.
71
72
  */
72
73
  aliasName(entityName: string, index: number): string;
74
+ /**
75
+ * Returns the name of the inverse side property. Used in the `EntityGenerator` with `bidirectionalRelations` option.
76
+ */
77
+ inverseSideName(entityName: string, propertyName: string, kind: ReferenceKind): string;
73
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mikro-orm/core",
3
- "version": "6.2.10-dev.83",
3
+ "version": "6.2.10-dev.85",
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",
@@ -64,7 +64,7 @@
64
64
  "esprima": "4.0.1",
65
65
  "fs-extra": "11.2.0",
66
66
  "globby": "11.1.0",
67
- "mikro-orm": "6.2.10-dev.83",
67
+ "mikro-orm": "6.2.10-dev.85",
68
68
  "reflect-metadata": "0.2.2"
69
69
  }
70
70
  }
@@ -148,7 +148,7 @@ export declare abstract class Platform {
148
148
  getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
149
149
  convertsJsonAutomatically(): boolean;
150
150
  convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
151
- convertJsonToJSValue(value: unknown): unknown;
151
+ convertJsonToJSValue(value: unknown, prop: EntityProperty): unknown;
152
152
  convertDateToJSValue(value: string | Date): string;
153
153
  convertIntervalToJSValue(value: string): unknown;
154
154
  convertIntervalToDatabaseValue(value: unknown): unknown;
@@ -282,7 +282,11 @@ class Platform {
282
282
  convertJsonToDatabaseValue(value, context) {
283
283
  return JSON.stringify(value);
284
284
  }
285
- convertJsonToJSValue(value) {
285
+ convertJsonToJSValue(value, prop) {
286
+ const isObjectEmbedded = prop.embedded && prop.object;
287
+ if ((this.convertsJsonAutomatically() || isObjectEmbedded) && ['json', 'jsonb', this.getJsonDeclarationSQL()].includes(prop.columnTypes[0])) {
288
+ return value;
289
+ }
286
290
  return (0, Utils_1.parseJsonSafe)(value);
287
291
  }
288
292
  convertDateToJSValue(value) {
package/types/JsonType.js CHANGED
@@ -16,7 +16,7 @@ class JsonType extends Type_1.Type {
16
16
  return key + platform.castColumn(this.prop);
17
17
  }
18
18
  convertToJSValue(value, platform) {
19
- return platform.convertJsonToJSValue(value);
19
+ return platform.convertJsonToJSValue(value, this.prop);
20
20
  }
21
21
  getColumnType(prop, platform) {
22
22
  return platform.getJsonDeclarationSQL();