@mikro-orm/core 7.2.6-dev.41 → 7.2.6-dev.43
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.d.ts +7 -0
- package/entity/EntityFactory.js +37 -0
- package/package.json +1 -1
- package/utils/Utils.js +1 -1
|
@@ -38,6 +38,13 @@ export declare class EntityFactory {
|
|
|
38
38
|
constructor(em: EntityManager);
|
|
39
39
|
/** Creates a new entity instance or returns an existing one from the identity map, hydrating it with the provided data. */
|
|
40
40
|
create<T extends object, P extends string = string>(entityName: EntityName<T>, data: EntityData<T>, options?: FactoryOptions): New<T, P>;
|
|
41
|
+
/**
|
|
42
|
+
* Whether merging `data` into an initialized entity would change nothing: every key is a scalar the entity already
|
|
43
|
+
* holds by identity, and keys `mergeData` always re-applies (formula, version, generated, discriminator) match the snapshot.
|
|
44
|
+
*/
|
|
45
|
+
private isNoopMerge;
|
|
46
|
+
/** Whether hydrating `value` into `prop` would leave `current` as is, mirroring the hydrator's Date and boolean coercion. */
|
|
47
|
+
private holdsValue;
|
|
41
48
|
/** Merges new data into an existing entity, preserving user-modified properties. */
|
|
42
49
|
mergeData<T extends object>(meta: EntityMetadata<T>, entity: T, data: EntityData<T>, options?: FactoryOptions): void;
|
|
43
50
|
/** Creates or retrieves an uninitialized entity reference by its primary key or alternate key. */
|
package/entity/EntityFactory.js
CHANGED
|
@@ -149,8 +149,45 @@ export class EntityFactory {
|
|
|
149
149
|
wrapped.__processing = false;
|
|
150
150
|
return entity;
|
|
151
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* Whether merging `data` into an initialized entity would change nothing: every key is a scalar the entity already
|
|
154
|
+
* holds by identity, and keys `mergeData` always re-applies (formula, version, generated, discriminator) match the snapshot.
|
|
155
|
+
*/
|
|
156
|
+
isNoopMerge(meta, entity, data, options) {
|
|
157
|
+
const wrapped = helper(entity);
|
|
158
|
+
if (!wrapped.__initialized || options.normalizeAccessors) {
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
for (const key of Utils.keys(data)) {
|
|
162
|
+
const prop = meta.properties[key];
|
|
163
|
+
const value = data[key];
|
|
164
|
+
// custom types are left to the full merge, as their JS and database values can differ
|
|
165
|
+
if (!prop || prop.customType || value === undefined || !this.holdsValue(prop, entity[key], value)) {
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
const reapplied = prop.formula || prop.version || prop.generated || key === meta.root.discriminatorColumn;
|
|
169
|
+
if (reapplied && (wrapped.__originalEntityData?.[key] !== value || !wrapped.__loadedProperties.has(key))) {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
/** Whether hydrating `value` into `prop` would leave `current` as is, mirroring the hydrator's Date and boolean coercion. */
|
|
176
|
+
holdsValue(prop, current, value) {
|
|
177
|
+
if (current instanceof Date && value instanceof Date) {
|
|
178
|
+
return current.getTime() === value.getTime();
|
|
179
|
+
}
|
|
180
|
+
if (prop.runtimeType === 'boolean' && value != null) {
|
|
181
|
+
return current === !!value;
|
|
182
|
+
}
|
|
183
|
+
return current === value;
|
|
184
|
+
}
|
|
152
185
|
/** Merges new data into an existing entity, preserving user-modified properties. */
|
|
153
186
|
mergeData(meta, entity, data, options = {}) {
|
|
187
|
+
// joined rows often repeat exactly what the entity already holds, skip the snapshot and diffing then
|
|
188
|
+
if (this.isNoopMerge(meta, entity, data, options)) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
154
191
|
// merge unchanged properties automatically
|
|
155
192
|
data = QueryHelper.processParams(data);
|
|
156
193
|
const existsData = this.#comparator.prepareEntity(entity);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mikro-orm/core",
|
|
3
|
-
"version": "7.2.6-dev.
|
|
3
|
+
"version": "7.2.6-dev.43",
|
|
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",
|
package/utils/Utils.js
CHANGED
|
@@ -153,7 +153,7 @@ export function parseJsonSafe(value) {
|
|
|
153
153
|
/** Collection of general-purpose utility methods used throughout the ORM. */
|
|
154
154
|
export class Utils {
|
|
155
155
|
static PK_SEPARATOR = '~~~';
|
|
156
|
-
static #ORM_VERSION = '7.2.6-dev.
|
|
156
|
+
static #ORM_VERSION = '7.2.6-dev.43';
|
|
157
157
|
/** Default session variable name backing an RLS filter argument (`current_setting('mikro.<filter>.<arg>')`). */
|
|
158
158
|
static getRlsSettingName(filterName, argName) {
|
|
159
159
|
return `mikro.${filterName}.${argName}`;
|