@mikro-orm/core 6.5.8 → 6.5.9-dev.1
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/entity/EntityFactory.js +4 -0
- package/package.json +2 -2
- package/platforms/Platform.d.ts +1 -1
- package/platforms/Platform.js +1 -5
- package/types/JsonType.d.ts +1 -1
- package/types/JsonType.js +7 -2
- package/types/Type.d.ts +2 -1
- package/types/Type.js +1 -1
- package/unit-of-work/UnitOfWork.js +2 -2
package/entity/EntityFactory.js
CHANGED
|
@@ -139,6 +139,10 @@ class EntityFactory {
|
|
|
139
139
|
if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE].includes(prop.kind) && Utils_1.Utils.isPlainObject(data[prop.name])) {
|
|
140
140
|
diff2[key] = entity[prop.name] ? (0, wrap_1.helper)(entity[prop.name]).getPrimaryKey(options.convertCustomTypes) : null;
|
|
141
141
|
}
|
|
142
|
+
if ([enums_1.ReferenceKind.MANY_TO_ONE, enums_1.ReferenceKind.ONE_TO_ONE, enums_1.ReferenceKind.SCALAR].includes(prop.kind) && prop.customType?.ensureComparable(meta, prop) && diff2[key] != null) {
|
|
143
|
+
const converted = prop.customType.convertToJSValue(diff2[key], this.platform, { force: true });
|
|
144
|
+
diff2[key] = prop.customType.convertToDatabaseValue(converted, this.platform, { fromQuery: true });
|
|
145
|
+
}
|
|
142
146
|
originalEntityData[key] = diff2[key] === null ? nullVal : diff2[key];
|
|
143
147
|
(0, wrap_1.helper)(entity).__loadedProperties.add(key);
|
|
144
148
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.5.
|
|
3
|
+
"version": "6.5.9-dev.1",
|
|
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.3.2",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.5.
|
|
67
|
+
"mikro-orm": "6.5.9-dev.1",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
package/platforms/Platform.d.ts
CHANGED
|
@@ -156,7 +156,7 @@ export declare abstract class Platform {
|
|
|
156
156
|
getFullTextIndexExpression(indexName: string, schemaName: string | undefined, tableName: string, columns: SimpleColumnMeta[]): string;
|
|
157
157
|
convertsJsonAutomatically(): boolean;
|
|
158
158
|
convertJsonToDatabaseValue(value: unknown, context?: TransformContext): unknown;
|
|
159
|
-
convertJsonToJSValue(value: unknown,
|
|
159
|
+
convertJsonToJSValue(value: unknown, context?: TransformContext): unknown;
|
|
160
160
|
convertDateToJSValue(value: string | Date): string;
|
|
161
161
|
convertIntervalToJSValue(value: string): unknown;
|
|
162
162
|
convertIntervalToDatabaseValue(value: unknown): unknown;
|
package/platforms/Platform.js
CHANGED
|
@@ -288,11 +288,7 @@ class Platform {
|
|
|
288
288
|
convertJsonToDatabaseValue(value, context) {
|
|
289
289
|
return JSON.stringify(value);
|
|
290
290
|
}
|
|
291
|
-
convertJsonToJSValue(value,
|
|
292
|
-
const isObjectEmbedded = prop.embedded && prop.object;
|
|
293
|
-
if ((this.convertsJsonAutomatically() || isObjectEmbedded) && ['json', 'jsonb', this.getJsonDeclarationSQL()].includes(prop.columnTypes[0])) {
|
|
294
|
-
return value;
|
|
295
|
-
}
|
|
291
|
+
convertJsonToJSValue(value, context) {
|
|
296
292
|
return (0, Utils_1.parseJsonSafe)(value);
|
|
297
293
|
}
|
|
298
294
|
convertDateToJSValue(value) {
|
package/types/JsonType.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare class JsonType extends Type<unknown, string | null> {
|
|
|
5
5
|
convertToDatabaseValue(value: unknown, platform: Platform, context?: TransformContext): string | null;
|
|
6
6
|
convertToJSValueSQL(key: string, platform: Platform): string;
|
|
7
7
|
convertToDatabaseValueSQL(key: string, platform: Platform): string;
|
|
8
|
-
convertToJSValue(value: string | unknown, platform: Platform): unknown;
|
|
8
|
+
convertToJSValue(value: string | unknown, platform: Platform, context?: TransformContext): unknown;
|
|
9
9
|
getColumnType(prop: EntityProperty, platform: Platform): string;
|
|
10
10
|
ensureComparable<T extends object>(meta: EntityMetadata<T>, prop: EntityProperty<T>): boolean;
|
|
11
11
|
compareAsType(): string;
|
package/types/JsonType.js
CHANGED
|
@@ -15,8 +15,13 @@ class JsonType extends Type_1.Type {
|
|
|
15
15
|
convertToDatabaseValueSQL(key, platform) {
|
|
16
16
|
return key + platform.castColumn(this.prop);
|
|
17
17
|
}
|
|
18
|
-
convertToJSValue(value, platform) {
|
|
19
|
-
|
|
18
|
+
convertToJSValue(value, platform, context) {
|
|
19
|
+
const isJsonColumn = ['json', 'jsonb', platform.getJsonDeclarationSQL()].includes(this.prop.columnTypes[0]);
|
|
20
|
+
const isObjectEmbedded = this.prop.embedded && this.prop.object;
|
|
21
|
+
if ((platform.convertsJsonAutomatically() || isObjectEmbedded) && isJsonColumn && !context?.force) {
|
|
22
|
+
return value;
|
|
23
|
+
}
|
|
24
|
+
return platform.convertJsonToJSValue(value, context);
|
|
20
25
|
}
|
|
21
26
|
getColumnType(prop, platform) {
|
|
22
27
|
return platform.getJsonDeclarationSQL();
|
package/types/Type.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import type { Platform } from '../platforms';
|
|
|
3
3
|
import type { Constructor, EntityMetadata, EntityProperty } from '../typings';
|
|
4
4
|
export interface TransformContext {
|
|
5
5
|
fromQuery?: boolean;
|
|
6
|
+
force?: boolean;
|
|
6
7
|
key?: string;
|
|
7
8
|
mode?: 'hydration' | 'query' | 'query-data' | 'discovery' | 'serialization';
|
|
8
9
|
}
|
|
@@ -23,7 +24,7 @@ export declare abstract class Type<JSType = string, DBType = JSType> {
|
|
|
23
24
|
/**
|
|
24
25
|
* Converts a value from its database representation to its JS representation of this type.
|
|
25
26
|
*/
|
|
26
|
-
convertToJSValue(value: DBType, platform: Platform): JSType;
|
|
27
|
+
convertToJSValue(value: DBType, platform: Platform, context?: TransformContext): JSType;
|
|
27
28
|
/**
|
|
28
29
|
* Converts a value from its JS representation to its database representation of this type.
|
|
29
30
|
*/
|
package/types/Type.js
CHANGED
|
@@ -99,8 +99,8 @@ class UnitOfWork {
|
|
|
99
99
|
data[prop.name] = Utils_1.Utils.getPrimaryKeyValues(data[prop.name], prop.targetMeta, true);
|
|
100
100
|
}
|
|
101
101
|
if (prop.hydrate === false && prop.customType?.ensureComparable(wrapped.__meta, prop)) {
|
|
102
|
-
const converted = prop.customType.convertToJSValue(data[key], this.platform);
|
|
103
|
-
data[key] = prop.customType.convertToDatabaseValue(converted, this.platform);
|
|
102
|
+
const converted = prop.customType.convertToJSValue(data[key], this.platform, { key, mode: 'hydration', force: true });
|
|
103
|
+
data[key] = prop.customType.convertToDatabaseValue(converted, this.platform, { key, mode: 'hydration' });
|
|
104
104
|
}
|
|
105
105
|
if (forceUndefined) {
|
|
106
106
|
if (data[key] === null) {
|