@mikro-orm/core 7.0.0-dev.115 → 7.0.0-dev.116
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
|
@@ -571,13 +571,13 @@ export class EntityManager {
|
|
|
571
571
|
let found = false;
|
|
572
572
|
for (const e of fork.unitOfWork.getIdentityMap()) {
|
|
573
573
|
const ref = em.getReference(e.constructor, helper(e).getPrimaryKey());
|
|
574
|
-
const data = helper(e).serialize({ ignoreSerializers: true, includeHidden: true });
|
|
574
|
+
const data = helper(e).serialize({ ignoreSerializers: true, includeHidden: true, convertCustomTypes: true });
|
|
575
575
|
em.config.getHydrator(this.metadata).hydrate(ref, helper(ref).__meta, data, em.entityFactory, 'full', false, true);
|
|
576
576
|
Utils.merge(helper(ref).__originalEntityData, this.comparator.prepareEntity(e));
|
|
577
577
|
found ||= ref === entity;
|
|
578
578
|
}
|
|
579
579
|
if (!found) {
|
|
580
|
-
const data = helper(reloaded).serialize({ ignoreSerializers: true, includeHidden: true });
|
|
580
|
+
const data = helper(reloaded).serialize({ ignoreSerializers: true, includeHidden: true, convertCustomTypes: true });
|
|
581
581
|
em.config.getHydrator(this.metadata).hydrate(entity, wrapped.__meta, data, em.entityFactory, 'full', false, true);
|
|
582
582
|
Utils.merge(wrapped.__originalEntityData, this.comparator.prepareEntity(reloaded));
|
|
583
583
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "7.0.0-dev.
|
|
4
|
+
"version": "7.0.0-dev.116",
|
|
5
5
|
"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.",
|
|
6
6
|
"exports": {
|
|
7
7
|
"./package.json": "./package.json",
|
|
@@ -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.
|
|
@@ -159,12 +159,20 @@ export class EntitySerializer {
|
|
|
159
159
|
return helper(value).toJSON();
|
|
160
160
|
}
|
|
161
161
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return customType.toJSON(value, wrapped.__platform);
|
|
162
|
+
if (property.customType) {
|
|
163
|
+
return this.processCustomType(value, property, wrapped.__platform, options.convertCustomTypes);
|
|
165
164
|
}
|
|
166
165
|
return wrapped.__platform.normalizePrimaryKey(value);
|
|
167
166
|
}
|
|
167
|
+
static processCustomType(value, prop, platform, convertCustomTypes) {
|
|
168
|
+
if (!prop.customType) {
|
|
169
|
+
return value;
|
|
170
|
+
}
|
|
171
|
+
if (convertCustomTypes) {
|
|
172
|
+
return prop.customType.convertToDatabaseValue(value, platform, { mode: 'serialization' });
|
|
173
|
+
}
|
|
174
|
+
return prop.customType.toJSON(value, platform);
|
|
175
|
+
}
|
|
168
176
|
static extractChildOptions(options, prop) {
|
|
169
177
|
return {
|
|
170
178
|
...options,
|
|
@@ -183,10 +191,7 @@ export class EntitySerializer {
|
|
|
183
191
|
if (expand) {
|
|
184
192
|
return this.serialize(child, childOptions);
|
|
185
193
|
}
|
|
186
|
-
|
|
187
|
-
if (prop.customType) {
|
|
188
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
189
|
-
}
|
|
194
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
190
195
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
191
196
|
return Utils.primaryKeyToObject(meta, pk, visible);
|
|
192
197
|
}
|
|
@@ -210,10 +215,7 @@ export class EntitySerializer {
|
|
|
210
215
|
if (populated || !wrapped.__managed) {
|
|
211
216
|
return this.serialize(item, this.extractChildOptions(options, prop.name));
|
|
212
217
|
}
|
|
213
|
-
|
|
214
|
-
if (prop.customType) {
|
|
215
|
-
pk = prop.customType.toJSON(pk, wrapped.__platform);
|
|
216
|
-
}
|
|
218
|
+
const pk = this.processCustomType(wrapped.getPrimaryKey(), prop, wrapped.__platform, options.convertCustomTypes);
|
|
217
219
|
if (options.forceObject || wrapped.__config.get('serialization').forceObject) {
|
|
218
220
|
return Utils.primaryKeyToObject(wrapped.__meta, pk);
|
|
219
221
|
}
|
|
@@ -3,6 +3,7 @@ import { ReferenceKind } from '../enums.js';
|
|
|
3
3
|
import { compareArrays, compareBooleans, compareBuffers, compareObjects, equals, parseJsonSafe, Utils } from './Utils.js';
|
|
4
4
|
import { JsonType } from '../types/JsonType.js';
|
|
5
5
|
import { Raw } from './RawQueryFragment.js';
|
|
6
|
+
import { EntityIdentifier } from '../entity/EntityIdentifier.js';
|
|
6
7
|
export class EntityComparator {
|
|
7
8
|
metadata;
|
|
8
9
|
platform;
|
|
@@ -517,8 +518,11 @@ export class EntityComparator {
|
|
|
517
518
|
return val;
|
|
518
519
|
};
|
|
519
520
|
context.set('toArray', toArray);
|
|
521
|
+
context.set('EntityIdentifier', EntityIdentifier);
|
|
520
522
|
ret += ` if (entity${entityKey} === null) {\n`;
|
|
521
523
|
ret += ` ret${dataKey} = null;\n`;
|
|
524
|
+
ret += ` } else if (entity${entityKey}?.__helper.__identifier && !entity${entityKey}.__helper.hasPrimaryKey()) {\n`;
|
|
525
|
+
ret += ` ret${dataKey} = entity${entityKey}?.__helper.__identifier;\n`;
|
|
522
526
|
ret += ` } else if (typeof entity${entityKey} !== 'undefined') {\n`;
|
|
523
527
|
ret += ` ret${dataKey} = toArray(entity${entityKey}.__helper.getPrimaryKey(true));\n`;
|
|
524
528
|
ret += ` }\n`;
|
package/utils/Utils.js
CHANGED
|
@@ -123,7 +123,7 @@ export function parseJsonSafe(value) {
|
|
|
123
123
|
}
|
|
124
124
|
export class Utils {
|
|
125
125
|
static PK_SEPARATOR = '~~~';
|
|
126
|
-
static #ORM_VERSION = '7.0.0-dev.
|
|
126
|
+
static #ORM_VERSION = '7.0.0-dev.116';
|
|
127
127
|
/**
|
|
128
128
|
* Checks if the argument is instance of `Object`. Returns false for arrays.
|
|
129
129
|
*/
|