@mikro-orm/core 6.6.3-dev.8 → 6.6.3
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/EntityManager.js
CHANGED
|
@@ -530,13 +530,13 @@ class EntityManager {
|
|
|
530
530
|
let found = false;
|
|
531
531
|
for (const e of fork.unitOfWork.getIdentityMap()) {
|
|
532
532
|
const ref = em.getReference(e.constructor.name, (0, entity_1.helper)(e).getPrimaryKey());
|
|
533
|
-
const data = (0, entity_1.helper)(e).serialize({ ignoreSerializers: true, includeHidden: true });
|
|
533
|
+
const data = (0, entity_1.helper)(e).serialize({ ignoreSerializers: true, includeHidden: true, convertCustomTypes: true });
|
|
534
534
|
em.config.getHydrator(this.metadata).hydrate(ref, (0, entity_1.helper)(ref).__meta, data, em.entityFactory, 'full', false, true);
|
|
535
535
|
utils_1.Utils.merge((0, entity_1.helper)(ref).__originalEntityData, this.comparator.prepareEntity(e));
|
|
536
536
|
found ||= ref === entity;
|
|
537
537
|
}
|
|
538
538
|
if (!found) {
|
|
539
|
-
const data = (0, entity_1.helper)(reloaded).serialize({ ignoreSerializers: true, includeHidden: true });
|
|
539
|
+
const data = (0, entity_1.helper)(reloaded).serialize({ ignoreSerializers: true, includeHidden: true, convertCustomTypes: true });
|
|
540
540
|
em.config.getHydrator(this.metadata).hydrate(entity, wrapped.__meta, data, em.entityFactory, 'full', false, true);
|
|
541
541
|
utils_1.Utils.merge(wrapped.__originalEntityData, this.comparator.prepareEntity(reloaded));
|
|
542
542
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "6.6.3
|
|
3
|
+
"version": "6.6.3",
|
|
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",
|
|
@@ -62,9 +62,9 @@
|
|
|
62
62
|
"dataloader": "2.2.3",
|
|
63
63
|
"dotenv": "17.2.3",
|
|
64
64
|
"esprima": "4.0.1",
|
|
65
|
-
"fs-extra": "11.3.
|
|
65
|
+
"fs-extra": "11.3.3",
|
|
66
66
|
"globby": "11.1.0",
|
|
67
|
-
"mikro-orm": "6.6.3
|
|
67
|
+
"mikro-orm": "6.6.3",
|
|
68
68
|
"reflect-metadata": "0.2.2"
|
|
69
69
|
}
|
|
70
70
|
}
|
|
@@ -4,6 +4,7 @@ export declare class EntitySerializer {
|
|
|
4
4
|
static serialize<T extends object, P extends string = never, E extends string = never>(entity: T, options?: SerializeOptions<T, P, E>): EntityDTO<Loaded<T, P>>;
|
|
5
5
|
private static propertyName;
|
|
6
6
|
private static processProperty;
|
|
7
|
+
private static processCustomType;
|
|
7
8
|
private static extractChildOptions;
|
|
8
9
|
private static processEntity;
|
|
9
10
|
private static processCollection;
|
|
@@ -23,6 +24,8 @@ export interface SerializeOptions<T, P extends string = never, E extends string
|
|
|
23
24
|
skipNull?: boolean;
|
|
24
25
|
/** Only include properties for a specific group. If a property does not specify any group, it will be included, otherwise only properties with a matching group are included. */
|
|
25
26
|
groups?: string[];
|
|
27
|
+
/** Convert custom types to their database representation. By default, the `Type.toJSON` method is invoked instead. */
|
|
28
|
+
convertCustomTypes?: boolean;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Converts entity instance to POJO, converting the `Collection`s to arrays and unwrapping the `Reference` wrapper, while respecting the serialization options.
|
|
@@ -144,12 +144,20 @@ class EntitySerializer {
|
|
|
144
144
|
return (0, wrap_1.helper)(value).toJSON();
|
|
145
145
|
}
|
|
146
146
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return customType.toJSON(value, wrapped.__platform);
|
|
147
|
+
if (property.customType) {
|
|
148
|
+
return this.processCustomType(value, property, wrapped.__platform, options.convertCustomTypes);
|
|
150
149
|
}
|
|
151
150
|
return wrapped.__platform.normalizePrimaryKey(value);
|
|
152
151
|
}
|
|
152
|
+
static processCustomType(value, prop, platform, convertCustomTypes) {
|
|
153
|
+
if (!prop.customType) {
|
|
154
|
+
return value;
|
|
155
|
+
}
|
|
156
|
+
if (convertCustomTypes) {
|
|
157
|
+
return prop.customType.convertToDatabaseValue(value, platform, { mode: 'serialization' });
|
|
158
|
+
}
|
|
159
|
+
return prop.customType.toJSON(value, platform);
|
|
160
|
+
}
|
|
153
161
|
static extractChildOptions(options, prop) {
|
|
154
162
|
return {
|
|
155
163
|
...options,
|
|
@@ -168,10 +176,7 @@ class EntitySerializer {
|
|
|
168
176
|
if (expand) {
|
|
169
177
|
return this.serialize(child, childOptions);
|
|
170
178
|
}
|
|
171
|
-
|
|
172
|
-
if (prop.customType) {
|
|
173
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
174
|
-
}
|
|
179
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
175
180
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
176
181
|
return Utils_1.Utils.primaryKeyToObject(meta, pk, visible);
|
|
177
182
|
}
|
|
@@ -195,10 +200,7 @@ class EntitySerializer {
|
|
|
195
200
|
if (populated || !wrapped.__managed) {
|
|
196
201
|
return this.serialize(item, this.extractChildOptions(options, prop.name));
|
|
197
202
|
}
|
|
198
|
-
|
|
199
|
-
if (prop.customType) {
|
|
200
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
201
|
-
}
|
|
203
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
202
204
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
203
205
|
return Utils_1.Utils.primaryKeyToObject(wrapped.__meta, pk);
|
|
204
206
|
}
|